akhauriyash/Code-Regression huggingface dataset:
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
    return a * a;
}

template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
    ll N;
    cin >> N;
    ll A[N];
    for (ll i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A, A + N);

    ll ans = 0, sum = 0;
    // sum = i匹目までの大きさの総和

    for (ll i = 0; i < N; ++i) {
        if (sum * 2 < A[i]) {
            ans = 0;
        }
        sum += A[i];
        ++ans;
    }

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


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

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

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

ll cnt[10] = {0ll};
ll h,w,n,a,b;
map<pii,int> f;


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

void change(int a,int b){
  FOR(i,-1,2){
    FOR(j,-1,2){
      pii tmp = pii(i+a,j+b);
      if(i+a<1||i+a>=h-1||j+b<1||j+b>=w-1) continue;
      if(f.count(tmp) == 0){
        cnt[0]--;
        cnt[1]++;
        f[tmp] = 1;
        continue;
      }
      cnt[f[tmp]]--;
      f[tmp]++;
      cnt[f[tmp]]++;
    }
  }
  cout << endl;
}

int main(){
  cin >> h>>w>>n;
  cnt[0] = (h-2)*(w-2);
  REP(q,n){
    cin >> a>>b;
    change(a-1,b-1);
  }
  REP(i,10){
    cout << cnt[i] <<endl;
  }
}


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

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int cnt = 0;
    for (int r = 0; R * r <= N; r++) {
        for (int g = 0; G * g <= N; g++) {
            if (N < R * r + G * g) continue;
            if ((N - R * r - G * g) % B == 0) cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_CARD_MAX		100000									// 最大カード数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1GNo[D_CARD_MAX];									// グループ番号[カード] 0～
static int siCCnt;												// カード数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// 出力
int
fOut(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// グループ番号 - 取得
int
fGetGNo(
	int piCNo					// <I> カード
)
{
	if (piCNo == si1GNo[piCNo]) {
		return piCNo;
	}

	si1GNo[piCNo] = fGetGNo(si1GNo[piCNo]);

	return si1GNo[piCNo];
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// カード数・結合数 - 取得
	int liCCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siCCnt, &liCCnt);

	// グループ番号 - 初期化
	for (i = 0; i < siCCnt; i++) {
		si1GNo[i] = i;
	}

	// 結合 - 取得
	for (i = 0; i < liCCnt; i++) {
		int liCNo1, liCNo2;
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d", &liCNo1, &liCNo2);
		liCNo1--;
		liCNo2--;

		// グループ番号 - 取得
		int liGNo1 = fGetGNo(liCNo1);
		int liGNo2 = fGetGNo(liCNo2);

		// グループ番号 - 更新
		if (liGNo1 != liGNo2) {
			si1GNo[liGNo1] = liGNo2;
		}
	}

	// グループ数 - 取得
	int liGCnt = 0;
	for (i = 0; i < siCCnt; i++) {
		if (i == si1GNo[i]) {
			liGCnt++;
		}
	}

	return liGCnt;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOut(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



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

int main() {
  string s;
  cin >> s;
  int C = -1, F = -1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'C' && C == -1) C = i;
    if (s[i] == 'F') F = i;
  }
  if (C < F && C != -1 && F != -1) cout << "Yes" << endl; else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 384
# python3だとTLE,pypy3だとAC
def main():
    N, W = map(int, input().split())
    w = [None for _ in range(N)]
    v = [None for _ in range(N)]
    for i in range(N):
        w[i], v[i] = map(int, input().split())
    MAX_V = sum(v)
    dp = [[10**9 for _ in range(MAX_V+1)] for _ in range(N)]
    dp[0][0] = 0
    for i in range(N-1):
        if i == 0:
            for sum_v in range(1, v[i]+1):
                dp[i][sum_v] = w[i]
        for sum_v in range(MAX_V+1):
            if sum_v - v[i+1] >= 0:
                dp[i+1][sum_v] = min(w[i+1] + dp[i]
                                     [sum_v-v[i+1]], dp[i][sum_v])
            else:
                dp[i+1][sum_v] = min(w[i+1], dp[i][sum_v])
    print(len(list(filter(lambda sum_v: sum_v <= W, dp[-1])))-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 173448
#include <bits/stdc++.h>
using namespace std;
int main(){

  for(;;){

  int n;
  cin>>n;
  if(!n) break;

  pair <string,string> train[n];

  for(int i=0;i<n;i++){

    string s1,s2;
    cin>>s1>>s2;

    train[i]=make_pair(s1,s2);

  }

  sort(train,train+n);

  priority_queue <string, vector <string>,greater <string>> train_q;
  int r=0;

  for(int i=0;i<n;i++){

    if(train_q.empty() || train_q.top()>train[i].first) r++;
    else train_q.pop();

    train_q.push(train[i].second);

  }

  cout<<r<<endl;

  }

  return 0;

}



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

int main()
{
  long N, K, Q;
  cin >> N >> K >> Q;
  vector<long> A(Q);
  rep(i, Q)
  {
    cin >> A[i];
  }
  vector<long> point(N, 0);
  rep(i, Q)
  {
    point[A[i] - 1]++;
  }

  rep(i, N)
  {
    string ans = "No";
    if (point[i] > Q - K)
    {
      ans = "Yes";
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2176
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
G = [0]*3
ans = 1
for i in range(N):
    x = 0
    cnt = 0
    for j, g in enumerate(G):
        if g == A[i]:
            x = j if cnt == 0 else x
            cnt += 1
    
    G[x] += 1
    ans *= cnt
    ans = ans % mod

print(ans)

Measured memory_bytes: 20864
#include <stdio.h>
int main(void){
    int n;
    scanf("%d", &n);
    n = n % 10;
    if (n  == 3)
    printf("bon");
    else if (n  == 0 || n == 1 || n == 6 || n == 8)
    printf("pon");
    else
    printf("hon");
    return (0);
}


Measured memory_bytes: 1728
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload '(:cl-debug-print :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((s (read-line))
         (prevs (make-array 26 :element-type 'int32 :initial-element #x-80000000)))
    (dotimes (i (length s))
      (let ((c (- (char-code (aref s i)) 97)))
        (if (>= (- i (aref prevs c)) 3)
            (setf (aref prevs c) i)
            (progn
              (format t "~D ~D~%" (+ 1 (aref prevs c)) (+ 1 i))
              (return-from main)))))
    (write-line "-1 -1")))

#-swank (main)


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

using namespace std;

int main(){
    int N;
    long sum=0;
    


    //入力
    cin >> N;
    vector<int> d(N);
    for(int i; i<N;i++){
        cin >> d[i];
    }

    for(int i=1; i<N; i++) {
        for(int j=0; j<i; j++) {
            sum += d[i]*d[j];
            //cout << i << " " << j << endl; 
        }
    }

    cout << sum << endl;

    return 0;
}

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s, t;
  while (cin >> s >> t, s != ".") {
    if (s == t) {
      cout << "IDENTICAL" << endl;
      continue;
    }
    int p = 0, q = 0;
    int sz = s.size(), tz = t.size();
    int flag = 0;
    int miss = 0;
    while (p < sz && q < tz) {
      if (s[p] == '"' && t[q] == '"') {
        int np = p + 1, nq = q + 1;
        while (s[np] != '"') np++;
        while (t[nq] != '"') nq++;
        miss += s.substr(p, np - p) != t.substr(q, nq - q);
        p = np, q = nq;
      } else if (s[p] != t[q]) {
        flag = 1;
        break;
      }
      p++, q++;
      if ((p == sz) ^ (q == tz)) {
        flag = 1;
        break;
      }
    }
    if (miss > 1 || flag) cout << "DIFFERENT" << endl;
    else cout << "CLOSE" << endl;
  }  

  return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int  n,x,p;
    long long s=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                x=__gcd(i,j);
                p=__gcd(x,k);
                s+=p;
            }
        }
    }

cout<<s;
}


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

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<int>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

const int mn = -1000, mx = 1000;
lli my_pow(int n, int m = 5){
    lli res = 1;
    for(int i = 1; i <= m; ++i) res*=n;
    return res;
}
int main(){
    ios::sync_with_stdio(false);
    int n = input();
    lli sum = 0;
    for(int i = mn; i <= mx; ++i){
        for(int j = mn; j <= mx; ++j){
            if(my_pow(i) - my_pow(j) == n){
                cout << i << " " << j;
                return 0;
            } 
        }
    }
}

Measured memory_bytes: 3616
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] ymd = s.split("/");
		if (Integer.parseInt(ymd[0]) < 2019) {
			System.out.println("Heisei");
		} else if (Integer.parseInt(ymd[0]) > 2019) {
			System.out.println("TBD");
		} else {
			if (Integer.parseInt(ymd[1]) <= 4) {
				System.out.println("Heisei");
			} else {
				System.out.println("TBD");
			}
		}
    }
  
}


Measured memory_bytes: 23380
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
template <class... T> void printArr(T&&...){ }
#endif

struct Node{
    vector<int> dests;
    vector<int> cs;
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<Node> nodes(n), rnodes(n);
    for(int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--; c = -c;
        nodes[a].dests.push_back(b);
        nodes[a].cs.push_back(c);
        rnodes[b].dests.push_back(a);
        rnodes[b].cs.push_back(1);
    }
    vector<ll> rdists(n, MLL);
    rdists[n - 1] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(uint k = 0; k < rnodes[j].dests.size(); k++){
                if(rdists[j] != MLL && rdists[j] + rnodes[j].cs[k] < rdists[rnodes[j].dests[k]]){
                    rdists[rnodes[j].dests[k]] = rdists[j] + rnodes[j].cs[k];
                }
            }
        }
    }

    vector<ll> dists(n, MLL);
    dists[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(uint k = 0; k < nodes[j].dests.size(); k++){
                if(dists[j] != MLL && dists[j] + nodes[j].cs[k] < dists[nodes[j].dests[k]] && rdists[nodes[j].dests[k]] != MLL){
                    if(i == n - 1){
                        cout << "inf" << '\n';
                        return 0;
                    }
                    dists[nodes[j].dests[k]] = dists[j] + nodes[j].cs[k];
                }
            }
        }
    }
    cout << - dists[n - 1] << '\n';
    return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

long long int arr[(int)1e5 + 1];
long long int dp[(int)1e5 + 1];

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

	for(int i = 0; i < n; i++){
		scanf("%lld",&arr[i]);
	}
	
	dp[0] = 0;

	if(n >= 2)dp[1] = abs(arr[1]-arr[0]);

	for(int i = 2; i < n; i++){
		dp[i] = min( abs(arr[i]-arr[i-1]) + dp[i-1], abs(arr[i]-arr[i-2]) + dp[i-2]);
	}

	cout << dp[n-1] << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int t,n,a[202],p[65];
char s[202];
inline void insert(re int x){
	for(re int i=62;~i;--i){
		if(x&(1ll<<i)){
			if(!p[i]){
				p[i]=x;
				return;
			}
			else x^=p[i];
		}
	}
}
inline int ask(re int x){
	for(re int i=62;~i;--i){
		if(x&(1ll<<i))x^=p[i];
	}
	return x;
}
signed main(){
	t=read();
	while(t--){
		n=read();
		memset(p,0,sizeof(p));
		re int ans=0;
		for(re int i=1;i<=n;++i)a[i]=read();
		scanf("%s",s+1);
		for(re int i=n;i;--i){
			if(s[i]=='0')insert(a[i]);
			else{
				if(ask(a[i])){
					ans=1;break;
				}
			}
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 3720
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N, X = map(int, input().split(" "))
	
	m = []
	mini = 1001
	to = 0
	for i in range(N):
		tmp = int(input())
		to += tmp
		if mini > tmp:
			mini = tmp
			
	tmp = (X-to) // mini
	print(N+tmp)
	
			
	
if __name__ == "__main__":
	main()


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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl
#define HYPP(x) hypot(x.first,x.second)

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;



int main() {
	array<array<int, 3>, 3> arr;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> arr[i][j];
		}
	}
	array<int, 3> B;
	for (B[0] = 0; B[0] <= 100; B[0]++) {
		for (B[1] = 0; B[1] <= 100; B[1]++) {
			for (B[2] = 0; B[2] <= 100; B[2]++) {
				if (arr[0][0] - B[0] == arr[0][1] - B[1] && arr[0][0] - B[0] == arr[0][2] - B[2] && //A[0]
					arr[1][0] - B[0] == arr[1][1] - B[1] && arr[1][0] - B[0] == arr[1][2] - B[2] && //A[0]
					arr[2][0] - B[0] == arr[2][1] - B[1] && arr[2][0] - B[0] == arr[2][2] - B[2]) { //A[0]
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int a, b, c, d;

int gcd(int a, int b) {
    if (a<b) gcd(b,a);
    int r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

int num_factors(int x, int d) {
    return x/d;
}
signed main() {
    cin >> a >> b >> c >> d;

    int ans = b - a + 1;
    int cn = num_factors(b,c) - num_factors(a-1,c);
    int dn = num_factors(b,d) - num_factors(a-1,d);
    int cd = c*d / gcd(c,d);
    int cdn = num_factors(b,cd) - num_factors(a-1,cd);

    ans -= cn + dn;
    ans += cdn;
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    REP(p_bit, (int)pow(2, n - 1)) {
        ll num = 0;
        REP(i, n) {
            num = num * 10 + s[i] - '0';
            if((p_bit >> i & 1) == 1 or i == n - 1) {
                ans += num;
                num = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = [None]*m
c = [0]*m
for i in range(m):
    a[i], b = map(int, input().split())
    ls = list(map(int,input().split()))
    for j in ls:
        c[i] |= 1<<(j-1)

dp = [[1e9]*(1<<n) for i in range(m+1)]
dp[0][0] = 0
for i in range(m):
    for S in range(1<<n):
        dp[i+1][S] = min(dp[i+1][S], dp[i][S])
        dp[i+1][S|c[i]] = min(dp[i+1][S|c[i]], dp[i][S]+a[i])
if dp[m][(1<<n)-1] < 1e9:
    print(dp[m][(1<<n)-1])
else:
    print(-1)

Measured memory_bytes: 138468
#include <iostream>

using namespace std;

int main()
{	
	int n;
	cin >> n;
	int x = n % 10;
	if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9) {
		cout << "hon" << endl;
	}
	if (x == 0 || x == 1 || x == 6 || x == 8) {
		cout << "pon" << endl;
	}
	if (x == 3) {
		cout << "bon" << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
n = int(input())
a = list(map(int, input().split()))
colorSet = set()
minAns = 0
maxAns = 0
cnt = 0

for i in range(n):
    color = a[i] // 400
    if color < 8:
        colorSet.add(color)
    else:
        colorSet.add(8)

    if color >= 8:
        cnt += 1

#print(colorSet)

if len(colorSet) > 1 and any(item >= 8 for item in colorSet):
    minAns = len(colorSet) - 1
else:
    minAns = len(colorSet)

if cnt > 0:
    # maxAns = min(len(colorSet) - 1 + cnt, 8)
    maxAns = len(colorSet) - 1 + cnt
else:
    maxAns = len(colorSet)

print(minAns, maxAns)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
const int limit = 50;

 int n, m;
 int a[limit], b[limit];

 bool graph[limit][limit];
 bool visited[limit];
 void dfs(int v) {
 visited[v] = true;
 for (int v2 = 0; v2 < n; ++v2) {
 if (graph[v][v2] == false) continue;
 if (visited[v2] == true) continue;
 dfs(v2);
 }
}

 int main(void) {

 cin >> n >> m;

 for (int i = 0; i < m; ++i) {
 cin >> a[i] >> b[i];
 a[i]--, b[i]--;
 graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
 }

 int ans = 0;

 for (int i = 0; i < m; ++i) {
 graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

 for (int j = 0; j < n; ++j) visited[j] = false;
 dfs(0);

 bool bridge = false;
 for (int j = 0; j < n; ++j) if (visited[j] == false) bridge = true;
 if (bridge) ans += 1;

 graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
 }

 cout << ans << endl;

 return 0;
 }

Measured memory_bytes: 256
solver::Int->Int->Int->Int
solver a b c =     if a<=b && b<=c then a+b
              else if a<=c && c<=b then a+c
              else if b<=a && a<=c then b+a
              else if b<=c && c<=a then b+c
              else if c<=a && a<=b then c+a
              else c+b

main::IO()
main=do
  d<-getLine
  let a:b:c:[]= map read (words d)
  print (solver a b c)               


Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
typedef long long ll;

int main(){
  ll N, tmp;
  cin >> N;
  vector<ll> A;
  ll sum = 0;
  for (int i=0; i<N; i++){
    cin >> tmp;
    A.push_back(tmp);
    sum += tmp;
  }
  ll mid_r = 0;
  ll i = 0;
  do {
    mid_r += A[i];
    i++;
  } while (mid_r < sum / 2);
  ll mid_l = mid_r - A[i-1];
  
  cout << min((ll)(abs(sum / 2.0 - mid_l)*2), (ll)(abs(sum / 2.0 - mid_r)*2)) << endl;
  
  return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, x, n) for(int i = x; i > n; i--)
long long MOD = 1e9 + 7;
long long INF = 1e15;
typedef pair<long long, long long> P;

int main(){
    int N, M;
    cin >> N >> M;
    int u, v;
    vector<int> edge[3*N+1];
    rep(i, M){
        cin >> u >> v;
        edge[u].push_back(v+N);
        edge[u+N].push_back(v+2*N);
        edge[u+2*N].push_back(v);
    }
    int S, T;
    cin >> S >> T;
    long long d[3*N+1];
    rep2(i, 1, 3*N+1){
        d[i] = INF;
    }
    d[S] = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, S));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int i = p.second;
        if(d[i] < p.first) continue;
        rep(j, edge[i].size()){
            int k = edge[i][j];
            if(d[k] > d[i]+1){
                d[k] = d[i]+1;
                que.push(P(d[k], k));
            }
        }
    }
    if(d[T] == INF) cout << -1 << endl;
    else cout << d[T]/3 << endl;
}

Measured memory_bytes: 18944
N = int(input())
h = [int(x) for x in input().split(" ")]
ans = [0 for _ in range(N)]
for i in range(N):
    if i == 0:
        ans[i] = h[i]
    elif h[i] <= h[i-1]:
        ans[i] = ans[i-1]
    else:
        ans[i] = ans[i-1] + (h[i] -h[i-1])
print(ans[N-1]) 

Measured memory_bytes: 3064
from collections import defaultdict


def main():
    N, M = map(int, input().split())
    students = []
    for _ in range(N):
        a, b = map(int, input().split())
        students.append((a, b))

    checkpoints = []
    for _ in range(M):
        c, d = map(int, input().split())
        checkpoints.append((c, d))

    for s in students:
        ans = ""
        best = float("inf")
        for i, c in enumerate(checkpoints, start=1):
            if abs(s[0] - c[0]) + abs(s[1] - c[1]) < best:
                best = abs(s[0] - c[0]) + abs(s[1] - c[1])
                ans = i
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include<stdio.h>

#define MAX 1000
#define MAXWEIGHTIJ 20000

struct MCS {
	int cost;
	int order;
};

void exchange( struct MCS *pa, struct MCS *pb )
{
   	struct MCS t;
     
	t=*pa;
	*pa=*pb;
	*pb=t;
	 
	 return;
}
 
int Partition( struct MCS A[], int p, int r )
{
    struct MCS x;
    int i,j;
 
    x=A[r];
    i=p-1;
    for( j=p; j<r; j++ ) {
        if( A[j].cost < x.cost ) {
            i++;
            exchange( &A[i], &A[j] );
         }
    }
    exchange( &A[i+1], &A[r] );

    return i+1;
}
void QuickSort( struct MCS A[], int p, int r )
{
    int q;
     
    if( p < r ) {
        q=Partition( A, p, r );
        QuickSort( A, p, q-1 );
        QuickSort( A, q+1, r );
    }
    return;
}

int tryChange( int n, struct MCS W[] )
{
	int cnt;
	int fixedcost,profit;
	int from, to, togoal;
	
	int cost,lowestCost;
	int i,j;
	int lowW,lowestW;
	int low,high,lowest;

	lowestW=lowW=lowestCost=cost=MAXWEIGHTIJ;
	lowest=high=low=-1;	
	for( i=0; i<n; i++ ) {
		if( i != W[i].order && W[i].cost < lowW ) {
			lowW=W[i].cost;
			low=i;
			for( j=0; j<n; j++ ) {
				if( low == W[j].order ) {
					high=j;
					break;
				}
			}
		}
		if( W[i].cost < lowestW ) {
			lowestW=W[i].cost;
			lowest=i;	
		}		
	}

	if( W[high].order == low && W[low].order == high ) { 
		lowestCost = W[low].cost + W[high].cost;
	} else if( low != lowest ) {	
		fixedcost = W[low].cost + W[lowest].cost;
		profit = W[low].cost - W[lowest].cost;
		from=high;
		to=low;
		togoal = W[low].order;
		cnt=0;
		while( 1 ) {
			if( W[from].order == to ) {
				if( togoal == to ) { break; }
				to=from;
				cnt++;
			} else {
				break;
			}
			for( i=0; i<n; i++ ) {
				if( i != W[i].order ) {
					if( to == W[i].order ) {
						from=i;
						break;
					}
				}
			}
		}
		profit = ( profit * cnt ) - ( 2 * fixedcost );
		if( 0 < profit ) {
			high=low;
			low=lowest;
			lowestCost = fixedcost;
		}
	}
	if( W[high].order == low ) { 
		lowestCost = W[low].cost + W[high].cost;
	}

    if( MAXWEIGHTIJ != lowestCost ) {
		exchange( &W[low], &W[high] );
	} else {
    	lowestCost=0;
    }
	return lowestCost;
}

int main( void ) 
{   
    int n,i;
    struct MCS W[MAX+1];
    int cost;
        
    scanf( "%d", &n );
    for( i=0; i<n; i++ ) {
        scanf( "%d", &W[i].cost );
        W[i].order=i;
    }

	QuickSort( W, 0, n-1 ); 
	cost=i=0;
	while( (i = tryChange( n, W ) ) ) {
		cost+=i;
	}
	printf( "%d\n", cost );

    return 0;
}

Measured memory_bytes: 644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

static class CodeJam
{
    static long? Solve(long P, long Q)
    {
        if (P + Q < 0) { return 0; }
        if (P + Q == 0) { return null; }
        long S = -P / (P + Q);
        long T = -P % (P + Q);
        return (T == 0) ? S * 2 : S * 2 + 1;
    }

    static long? Solve(int T1, int T2, long A1, long A2, long B1, long B2)
    {
        long P = T1 * (A1 - B1);
        long Q = T2 * (A2 - B2);
        return (P > 0) ? Solve(-P, -Q) : Solve(P, Q);
    }

    static void Main(string[] args)
    {
        int[] T = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        long[] A = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        long[] B = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        var ans = Solve(T[0], T[1], A[0], A[1], B[0], B[1]);
        Console.WriteLine(ans.HasValue ? ans.ToString() : "infinity");
    }
}


Measured memory_bytes: 13268
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))


n = inp()
a = inpl()
c = Counter(a)
a.sort()
s = set()
res = 0
for x in a:
    if x in s:
        continue
    if c[x] == 1:
        res += 1
    b = 1
    while b*x <= 10**6:
        s.add(b*x)
        b += 1
print(res)

Measured memory_bytes: 221516
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,K = inpl()
a = [inpl() for _ in range(n)]
res = INF
a.sort(key=lambda x:x[0])
for j in range(n-1):
    for k in range(j+1,n):
        l = a[j][0]
        r = a[k][0]
        b = [a[j],a[k]]
        cnt = 2
        for _ in range(n):
            if _ == j or _ == k:
                continue
            if l < a[_][0] < r:
                cnt += 1
                b += [a[_]]
        if cnt < K: continue
        b.sort(key=lambda x:x[1])
        for _ in range(cnt-K+1):
            u = max(x[1] for x in b[_:_+K])
            d = min(x[1] for x in b[_:_+K])
            res = min(res, (r-l)*(u-d))
            # print(res)
print(res)


Measured memory_bytes: 71896
import java.util.Scanner;

public class Main {

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

		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();

		run(a);

		scan.close();
		System.exit(0);
	}

	private static void run(int[] a) {
		for (int i = 1; i < a.length; i++) {
			printA(a);
			int temp = a[i];
			for (int j = i; j > 0; j--)
				if (a[j - 1] > a[j]) {
					a[j] = a[j - 1];
					a[j - 1] = temp;
				} else
					break;
		}
		printA(a);

	}

	private static void printA(int[] a) {
		for (int i = 0; i < a.length; i++) {
			if (i > 0)
				System.out.print(" ");
			System.out.print(a[i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 34152
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
ll cnt[10][10];

int main() {
    ll N;
    cin >> N;
    string i_str;
    ll head, tail;
    for (int i = 1; i <= N; i++) {
        i_str = to_string(i);
        head = i_str[0] - '0';
        tail = i_str[i_str.length() - 1] - '0';
        cnt[head][tail]++;
    }
    ll ans = 0;
    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        if (A == B && B == C && C == A){
            System.out.println("No");
        } else if (A != B && B != C && C != A){
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }

    }
}


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

using namespace std;
const int maxn=5e5+1212;

int n,m1,m2;
int edgenum;
bool vis[maxn];
int head[maxn],Next[maxn],b[maxn],V[maxn];
int num[maxn];
vector <int> human[maxn],vv;
bool book[maxn];
void add(int u,int v)
{
    V[++edgenum]=v;
    Next[edgenum]=head[u];
    head[u]=edgenum;
}

void DFS(int u)
{
    vis[u]=true;
    int pos=b[u];
    if(book[pos]==false) vv.push_back(pos);
    human[pos].push_back(u);
    for(int i=head[u];i!=-1;i=Next[i])
    {
        int v=V[i];
        if(vis[v]==false) DFS(v);
    }
}

int f(int x)
{
    if(b[x]==x) return x;
    else return b[x]=f(b[x]);
}
int main()
{
    int u,v;
    while(scanf("%d %d %d",&n,&m1,&m2)!=EOF)
    {
        for(int i=1;i<=n;i++) b[i]=i;
        for(int i=1;i<=m1;i++)
        {
            scanf("%d %d",&u,&v);
            int t1=f(u),t2=f(v);
            b[t2]=t1;
        }
        for(int i=1;i<=n;i++) b[i]=f(i);
        memset(vis,false,sizeof(vis));
        memset(head,-1,sizeof(head));
        memset(book,false,sizeof(book));
        memset(num,0,sizeof(num));
        edgenum=0;
        for(int i=1;i<=m2;i++)
        {
            scanf("%d %d",&u,&v);
            add(u,v);
            add(v,u);
        }
        for(int i=1;i<=n;i++)
        {
            if(vis[i]==false)
            {
                DFS(i);
                for(int j=0;j<(int)vv.size();j++)
                {
                    int pos=vv[j];
                    for(int s=0;s<(int)human[pos].size();s++)
                    {
                        int q=human[pos][s];
                        num[q]+=human[pos].size();
                    }
                    human[pos].clear();
                }
                vv.clear();
            }
        }
        for(int i=1;i<=n;i++)
        {
            if(i==n) printf("%d\n",num[i]);
            else printf("%d ",num[i]);
        }
    }
    return 0;
}


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

public class Main{
	static void main() throws Exception{
		String x=sc.nextLine();
		pw.print(x);
		if(x.charAt(x.length()-1)=='s') {
			pw.println("es");
		}
		else {
			pw.println("s");
		}
	}
	public static void main(String[] args) throws Exception {
		sc = new MScanner(System.in);
		pw = new PrintWriter(System.out);
//		int tc = 1;
//		tc=sc.nextInt();
//		while (tc-- > 0)
			main();
		pw.flush();
	}

	static PrintWriter pw;
	static MScanner sc;

	static class MScanner {
		StringTokenizer st;
		BufferedReader br;

		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int[] intArr(int n) throws IOException {
			int[] in = new int[n];
			for (int i = 0; i < n; i++)
				in[i] = nextInt();
			return in;
		}

		public long[] longArr(int n) throws IOException {
			long[] in = new long[n];
			for (int i = 0; i < n; i++)
				in[i] = nextLong();
			return in;
		}

		public int[] intSortedArr(int n) throws IOException {
			int[] in = new int[n];
			for (int i = 0; i < n; i++)
				in[i] = nextInt();
			shuffle(in);
			Arrays.sort(in);
			return in;
		}

		public long[] longSortedArr(int n) throws IOException {
			long[] in = new long[n];
			for (int i = 0; i < n; i++)
				in[i] = nextLong();
			shuffle(in);
			Arrays.sort(in);
			return in;
		}

		public Integer[] IntegerArr(int n) throws IOException {
			Integer[] in = new Integer[n];
			for (int i = 0; i < n; i++)
				in[i] = nextInt();
			return in;
		}

		public Long[] LongArr(int n) throws IOException {
			Long[] in = new Long[n];
			for (int i = 0; i < n; i++)
				in[i] = nextLong();
			return in;
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}

	static void shuffle(int[] in) {
		for (int i = 0; i < in.length; i++) {
			int idx = (int) (Math.random() * (i + 1));
			int tmp = in[i];
			in[i] = in[idx];
			in[idx] = tmp;
		}
	}

	static void shuffle(long[] in) {
		for (int i = 0; i < in.length; i++) {
			int idx = (int) (Math.random() * (i + 1));
			long tmp = in[i];
			in[i] = in[idx];
			in[idx] = tmp;
		}
	}
}

Measured memory_bytes: 25432
#include<bits/stdc++.h>
using namespace std;
long long n,a,x,dp[55][2505],cnt=0;
int main()
{
	scanf("%lld%lld",&n,&a);
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		for(int j=i-1;j>=0;j--)
		{
			for(int k=2500;k>=0;k--)
			{	
				if(k+x<=2500)
				{
					dp[j+1][k+x]+=dp[j][k];
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		cnt+=dp[i][a*i];
	}
	printf("%lld\n",cnt);
}

Measured memory_bytes: 4808
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (A, B, H, M) = Scanner.Scan<int, int, int, int>();
            var h = (H + M / 60.0) * 30.0;
            var m = M * 6.0;
            var angle = Math.Abs(h - m) * Math.PI / 180.0;
            var answer = Math.Sqrt((A * A) + (B * B) - (2.0 * A * B * Math.Cos(angle)));
            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 28676
from copy import deepcopy

def count(A):
    cnt = 0
    for a in A:
        cnt += (a*(a-1))//2
    return cnt


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    max_A = max(A)

    count_A = [0]*(max_A+1)

    for a in A:
        count_A[a]+= 1

    combi_A = 0

    for c in count_A:
        combi_A += (c*(c-1))//2
    for a in A:
        print(combi_A-(count_A[a]*(count_A[a]-1)-(count_A[a]-1)*(count_A[a]-2))//2)

Measured memory_bytes: 33168
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

template <typename T> bool next_combination(const T first, const T last, int k) {
    const T subset = first + k;
    // empty container | k = 0 | k == n 
    if (first == last || first == subset || last == subset) {
        return false;
    }
    T src = subset;
    while (first != src) {
        src--;
        if (*src < *(last - 1)) {
            T dest = subset;
            while (*src >= *dest) {
                dest++;
            }
            iter_swap(src, dest);
            rotate(src + 1, dest + 1, last);
            rotate(subset, subset + (last - dest) - 1, last);
            return true;
        }
    }
    // restore
    rotate(first, subset, last);
    return false;
}


using Graph = vector<vector<int>>;

Graph G;
vector<bool> seen;
vector<P> p;

void dfs(const Graph &G, int v,int i){
  seen[v] = true;
  for(auto next_v : G[v]){
    if(p[i].first == v && p[i].second == next_v) continue;
    if(p[i].second == v && p[i].first == next_v) continue;
    if(seen[next_v]) continue;
    dfs(G,next_v,i);
  }
}

int main(){
  int N,M;
  cin >> N >> M;
  Graph G(N);
  p.resize(M);
  rep(i,M){
    int a,b;
    cin >> a >> b;
    a--,b--;
    p[i] = make_pair(a,b); 
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int ans = 0;

  rep(i,M){
    seen.assign(N,false);
    bool ok = false;
    dfs(G, 0, i);
    rep(j,N){
      if(seen[j] == false) ok = true;
    }
    if(ok){
      ans++;
 
    }
    
  }
  cout << ans << endl;

  
  
  
}


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

using namespace std;

struct PAGE{
  int before;
  int after;
};

int main(){
  int i, n, m, x, y;
  vector<int> page;
  vector<int>::iterator iter;
  PAGE one;
  vector<PAGE> Page;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; ++i){
      cin >> m;
      page.push_back(m);
    }

    iter = page.begin() + 1;
    one.before = *(page.begin());
    while(1){
      if(iter == page.end()){
	one.after = *(iter - 1);
	Page.push_back(one);
	break;
      }else if(*iter != *(iter-1) + 1){
	one.after = *(iter-1);
	Page.push_back(one);
	one.before = *iter;
      }
      ++iter;
    }

    for(i=0; i<Page.size(); ++i){
      cout << Page[i].before;
      if(Page[i].after != Page[i].before)
	cout << "-" << Page[i].after;
      if(i < Page.size() - 1)
	cout << " ";
    }
    cout << endl;
    page.clear();
    Page.clear();
  }

  return 0;
}

Measured memory_bytes: 0
N = int(input())
A = [int(a) for a in input().split()]

print((" ").join((str(a) for a in A)))
for i in range(1, N):
    v = A[i]
    j = i - 1
    while(j >=0 and A[j] > v):
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print((" ").join((str(a) for a in A)))

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

const long long int MOD = 1e9+7;
#define pb push_back
typedef long long ll;
const long long int N = 1e5;

int main(){
    ll n,w;
    cin>>n>>w;
    ll wt[n+5],val[n+5];
    ll mx=0;
    for(int i=1;i<=n;i++){
        cin>>wt[i]>>val[i];
        mx+=val[i];
    }
    vector<vector<ll>> dp(n+5,vector<ll>(mx+5, 1e17 ));
    for(int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=mx;j++){
            if(val[i]<=j){
                dp[i][j]= min(dp[i-1][j-val[i]]+wt[i] , dp[i-1][j]);
            }
            else{
                dp[i][j]= dp[i-1][j];
            }
        }
    }
    int ans=0;
    for(int i=1;i<=mx;i++){
        if(dp[n][i]<=w) ans=i;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 86164
from itertools import product
from copy import deepcopy

n = int(input())
mod = 10 ** 9 + 7

comp = {"A": 0, "C": 1, "G": 2, "T": 3}
keys = comp.keys()

dp = [[0] * (4 ** 3) for _ in range(n + 1)]

bad = [0b001001, 0b000110, 0b100001]
for i in range(4 ** 3):
    if not i in bad:
        dp[3][i] = 1


def is_ok(li):
    for i in range(4):
        tmp = deepcopy(li)
        if i >= 1:
            tmp[i-1], tmp[i] = tmp[i], tmp[i-1]

        if "".join(tmp).count("AGC") >= 1:
            return False

    return True


def comp2int(li):
    ret = 0
    for i, e in enumerate(li):
        ret += comp[e] << 2 * (2 - i)

    return ret


for i in range(3, n):
    for last4 in product(keys, repeat=4):
        last4 = list(last4)
        if is_ok(last4):
            j_prev = comp2int(last4[:-1])
            j_nxt = comp2int(last4[1:])
            dp[i+1][j_nxt] += dp[i][j_prev]
            dp[i+1][j_nxt] %= mod

ans = 0
for i in range(4 ** 3):
    ans += dp[n][i]
    ans %= mod

print(ans)


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string S,T;
  cin>>S>>T;
  bool ans=false;
  rep(i,S.size()){
      bool h=true;
      rep(j,S.size()){
          if(S[(i+j)%S.size()]!=T[j]){
              h=false;
          }
      }

      if(h==true){
          ans=true;
          break;
      }
  }
  if(ans==false){
      cout<<"No"<<endl;
  }
  else{
      cout<<"Yes"<<endl;
  }
}


Measured memory_bytes: 3620
(set! *unchecked-math* true)

(def ^:const D-Y-X
  [[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1]])
(def ^:const one (unchecked-int \0))

(defn get_H_W []
  (->> (clojure.string/split (read-line) #"\s")
    (map #(Integer/parseInt %))))

(defn set_Array [[H W ^"[[C" Array]]
  (dotimes [h H]
    (->> (read-line)
      (char-array W)
      (aset ^"[[C" Array h))))


(defn Minesweeper [[H W ^"[[C" Array]]
  (let [X (range W)
        Y (range H)]
    (doseq [x X
            y Y
            :let [v (aget ^"[C" (aget ^"[[C" Array y) x)]
            :when (not= \# v)]
      (->> (for [d-y-x D-Y-X
                 :let [[dy dx] (map + (list y x) d-y-x)]
                 :when (and
                         (<= 0 dx)
                         (< dx W)
                         (<= 0 dy)
                         (< dy H)
                         (= \# (aget ^"[C" (aget ^"[[C" Array dy) dx)))]
             true)
        count
        (unchecked-add-int one)
        unchecked-char
        (aset ^"[C" (aget ^"[[C" Array y) x)))))

(defn output [[H W ^"[[C" Array]]
  (dotimes [h H]
    (->> (aget ^"[[C" Array h)
      (apply str)
      println)))

(let [[H W] (get_H_W)]
  (doto [H W (make-array Character/TYPE H W)]
    (set_Array)
    (Minesweeper)
    (output)))

Measured memory_bytes: 70988