akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

struct Info{
	Info(){
		num = 0;
		right = up = true;
	}

	ll num;
	bool right,up;
};

void func(){

	Info table[16][16];

	int goal_col,goal_row,P;
	scanf("%d %d",&goal_col,&goal_row);

	scanf("%d",&P);

	int left_col,left_row,right_col,right_row;

	for(int i = 0; i < P; i++){
		scanf("%d %d %d %d",&left_col,&left_row,&right_col,&right_row);
		if(left_col == right_col){
			if(left_row > right_row){
				table[right_row][right_col].up = false;
			}else{
				table[left_row][left_col].up = false;
			}
		}else{
			if(left_col > right_col){
				table[right_row][right_col].right = false;
			}else{
				table[left_row][left_col].right = false;
			}
		}
	}

	table[0][0].num = 1;

	for(int i = 0; i <= goal_row;i++){
		for(int k = 0; k <= goal_col;k++){

			if(i < goal_row && table[i][k].up == true){
				table[i+1][k].num += table[i][k].num;
			}

			if(k < goal_col && table[i][k].right == true){
				table[i][k+1].num += table[i][k].num;
			}
		}
	}

	if(table[goal_row][goal_col].num == 0){
		printf("Miserable Hokusai!\n");
	}else{
		printf("%lld\n",table[goal_row][goal_col].num);
	}
}

int main(){

	int K;
	scanf("%d",&K);

	for(int i = 0; i < K; i++){
		func();
	}

    return 0;
}

Measured memory_bytes: 2688
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()

typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int32_t, int32_t> pii;
typedef vector<int32_t> vi;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;

  int32_t n;
  cin >> n;
  int32_t a[n];
  int64_t dp[n][n][2];
  rep(i, n) { cin >> a[i]; }

  loop(w, 1, n + 1) {
    rep(si, n - w + 1) {
      if (w == 1) {
        dp[si][si][0] = a[si];
        dp[si][si][1] = -1 * a[si];
      } else {
				dp[si][si + w - 1][0] = max(a[si] + dp[si + 1][si + w - 1][1], a[si + w - 1] + dp[si][si + w - 2][1]);
				dp[si][si + w - 1][1] = min(dp[si + 1][si + w - 1][0] - a[si], dp[si][si + w - 2][0] - a[si + w - 1]);
      }
			//cerr << dp[si][si][0] << ':' << dp[si][si][1] << ' ';
    }
		//cerr << endl;
  }
	cout << dp[0][n-1][0];
}

Measured memory_bytes: 140672
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    rep(i, N) cin >> P[i];
    sort(All(P));
    ll res = 0;
    rep(i, K) { res += P[i]; }
    cout << res << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	int N; cin >> N;
	double sum = 0.0;
	REP(i,N){
		int A; cin >> A;
		sum += 1.0 / A;
	}

	double ans = 1.0 / sum;
	printf("%f\n", ans);

	return 0;

}


Measured memory_bytes: 256
n = int(input())

while n != 0:
    test = [int(x) for x in input().split()]
    
    ave_test = sum(test)/n
    
    total_test = 0
    for i in range(n):
        sum_test = (test[i] - ave_test)**2
        #print(sum_test)
        total_test += sum_test
    sd_test = (total_test/n)**0.5
    print(sd_test)
    n = int(input())


Measured memory_bytes: 5672
#include<stdio.h>
 
int main()
{
    double x1,y1,x2,y2,xq,yq,xr,yr,m,n;
    for(;~scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&xq,&yq);)
    {
        if(x2==x1)
            printf("%f %f\n",2*x1-xq,yq);
        else if(y2==y1)
            printf("%f %f\n",xq,2*y1-yq);
        else
        {
            x2-=x1;y2-=y1;xq-=x1;yq-=y1;
            m=y2/x2;
            n=1/(1+m*m);
            xr=n*(1-m*m)*xq+2*m*n*yq+x1;
            yr=n*2*m*xq+n*(m*m-1)*yq+y1;
            printf("%f %f\n",xr,yr);
        }
    }
    return 0;
}

Measured memory_bytes: 652
x1,y1,x2,y2=$<.read.split.map(&:to_i)

dx=x2-x1
dy=y2-y1

x3=x2-dy
y3=y2+dx
x4=x3-dx
y4=y3-dy

puts [x3,y3,x4,y4].join(' ')


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
#define P 15
#define INF 1e9
#define Gmin(x,y) (x>(y)&&(x=(y)))
const int maxn = 100035;
const int maxs = 1<<17;

int n,cnt,a[maxn],f[maxs],sta,ans;

class Class_FIO
{
	private:
		#define FS 100000
		#define tc() (A==B&&(B=(A=FI)+fread(FI,1,FS,stdin),A==B)?EOF:*A++)
		#define pc(c) (putchar(c))
		#define tn(x) (x<<3)+(x<<1)
		#define D isdigit(c=tc())
		int T;char c,*A,*B,FI[FS],S[FS];
	public:
		I Class_FIO() {A=B=FI;}
		Tp I void read(Ty& x) {x=0;W(!D);W(x=tn(x)+(c&15),D);}
		Tp I void write(Ty x) {W(S[++T]=x%10+48,x/=10);W(T) pc(S[T--]);}
		Ts I void read(Ty& x,Ar&... y) {read(x),read(y...);}
}F;
int dp(int x)
{
	if (!x) return 0;
	if (f[x]!=-1) return f[x];
	int ret = 1e9;
	for (int i=1; i<16; i++)
		if (x&(1<<i)) for (int j=1; j<16; j++)
			if ((x&(1<<j))&&i!=j)
				ret = std::min(ret, dp(x^(1<<i)^(1<<j)^(1<<(i^j)))+1+((x&(1<<(i^j)))?1:0));
	f[x] = ret;
	return ret;
}
int main()
{
	F.read(n);
	memset(f, -1, sizeof f);
	for (int i=1; i<n; i++)
	{
		int x,y,z;
		F.read(x), ++x, F.read(y), ++y, F.read(z);
		a[x] ^= z, a[y] ^= z;
	}
	for (int i=1; i<=n; i++)
		if (a[i]&&((sta>>a[i])&1)) sta ^= 1<<a[i], ++ans;
		else if (a[i]) sta ^= 1<<a[i];
	printf("%d\n",ans+dp(sta));
	return 0;
}

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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n >> k;
	ll ans = k;
	rep(i, n-1){
		ans *= (k-1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;cin>>h>>w;
  vector<vector<char>>m(h+2,vector<char>(w+2));
  for(int i=0;i<w+2;i++){
    m.at(0).at(i)='.';
    m.at(h+1).at(i)='.';
  }
  for(int i=0;i<h+2;i++){
    m.at(i).at(0)='.';
    m.at(i).at(w+1)='.';
  }
  for(int i=1;i<h+1;i++){
    string s;cin>>s;
    for(int j=1;j<w+1;j++)m.at(i).at(j)=s.at(j-1);
  }
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      if(m.at(i).at(j)=='.'){
        int a=0;
        if(m.at(i-1).at(j-1)=='#')a++;
        if(m.at(i-1).at(j)=='#')a++;
        if(m.at(i-1).at(j+1)=='#')a++;
        if(m.at(i).at(j-1)=='#')a++;
        if(m.at(i).at(j+1)=='#')a++;
        if(m.at(i+1).at(j-1)=='#')a++;
        if(m.at(i+1).at(j)=='#')a++;
        if(m.at(i+1).at(j+1)=='#')a++;
        m.at(i).at(j)='0'+a;
      }
    }
  }
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      cout<<m.at(i).at(j);
    }
    cout<<endl;
  }
}
  


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int hand[5];
	
	while (scanf("%d", hand) * hand[0] != 0){
		int i, j;
		int flag[3] = {0};
		
		flag[hand[0] - 1] = 1;
		for (i = 1; i < 5; i++){
			scanf("%d", hand + i);
			flag[hand[i] - 1] = 1;
		}
		if (flag[0] == flag[1] && flag[1] == flag[2]){
			for (i = 0; i < 5; i++){
				puts("3");
			}
			continue;
		}
		for (i = 0; i < 3; i++){
			if (flag[i] == 1 && (flag[(i + 1) % 3] | flag[(i + 2) % 3]) == 0){
				for (j = 0; j < 5; j++){
					puts("3");
				}
			}
		}
		for (i = 0; i < 3; i++){
			if (flag[i] == 1 && flag[(i + 1) % 3] == 1){
				for (j = 0; j < 5; j++){
					puts(hand[j] - 1 == i ? "1" : "2");
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 584
// by Balloons
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;
#define int LL

const int inf = 1 << 30;
const int maxn=3e5+5; 

int n;
LL k;
int a[maxn],nxt[maxn];
int to[maxn][65];
__int128 st[maxn][65];

signed main(){
	scanf("%lld%lld",&n,&k);
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	for(int i=n-1;i>=0;i--)nxt[a[i]]=n+i;
	for(int i=n-1;i>=0;i--){
		to[i][0]=nxt[a[i]]+1;
		st[i][0]=to[i][0]-i;
		to[i][0]=(to[i][0])%n;
		nxt[a[i]]=i;
	}
	
	for(int j=1;j<60;j++)
		for(int i=0;i<n;i++)
			to[i][j]=to[to[i][j-1]][j-1],
			st[i][j]=st[to[i][j-1]][j-1]+st[i][j-1];

	int p=0;LL pos=0;
	for(int j=59;j>=0;j--)
		if(pos+st[p][j]<=n*k)
			pos+=st[p][j], 
			p=to[p][j];
	
	vector<int>ans;
	while(pos<n*k){
		int cur=a[(pos)%n];
		if(pos+st[(pos)%n][0]>n*k){
			ans.push_back(cur);
			++ pos;
		} else pos+=st[(pos)%n][0];
	}
	for(int i=0;i<ans.size();i++)printf("%lld ",ans[i]);
	puts("");

	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  int max = 0;
  int x = 0;
  int i;
  for(i = 0; i < n; i++)
  {
    if(s.at(i)=='I')
    {
      x++;
      if(x > max)
      {
        max = x;
      }
    }
    else
    {
      x--;
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
h = list(map(int,input().split()))
h = sorted(h,reverse=True)
cnt = 0
if k>n:
    print(0)
else:
    for i in range(k):
        h[i] = 0
    for i in range(len(h)):
        cnt+=h[i]
    print(cnt)

Measured memory_bytes: 26180
from heapq import heapify, heappop, heappush
from math import floor

N, M = map(int, input().split())
A = list(map(int, input().split()))

A = list(map(lambda x: x*(-1), A))
heapify(A)

for _ in range(M):
    _max = heappop(A)*(-1)
    x = _max / 2
    heappush(A, floor(_max/2)*(-1))

ans_list = list(map(lambda x: x*(-1), A))
print(sum(ans_list))


Measured memory_bytes: 14532
from math import ceil
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())

L=[A,B,C,D,E]
X=[]
for l in L:
    res=ceil(l*0.1)*10
    #print(res)
    X.append([res,l,res-l])
X=sorted(X, key=lambda x: x[2], reverse=True)
ans=0
for i,x in enumerate(X):
    res,l=x[0],x[1]
    if i==0:
        ans+=l
    else:
        ans+=res

print(ans)

Measured memory_bytes: 3064
s = input()
nc = s.count('N')
sc = s.count('S')
ec = s.count('E')
wc = s.count('W')
if nc >= 1 and sc >= 1 and ec >= 1 and wc >= 1:
    print('Yes')
elif nc == 0 and sc == 0 and ec >= 1 and wc >= 1:
    print('Yes')
elif ec == 0 and wc == 0 and nc >= 1 and sc >= 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)));
#define Mx(a , b) ((a) > (b) ? (a) : (b))
#define Mn(a , b) ((a) < (b) ? (a) : (b))

const double EPS = 1e-10;
const int INF = 2147483647;

char s[13];
LL ans;

int main(){
	scanf("%s" , s);
	int x = 0;
	while(s[x] != 0) ++x;
	--x;
	for(int i = 0 ; i < (1 << x) ; ++i){
		int y = i;
		LL z = s[0] - '0';
		for(int j = 1 ; j <= x ; ++j){
			if(y % 2 == 0){
				z = z * 10 + s[j] - '0';
			} else {
				ans += z;
				z = s[j] - '0';
			}
			y /= 2;
		}
		ans += (LL)z;
	}
	printf("%lld\n" , ans);
	return 0;
}


Measured memory_bytes: 128
n, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

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

for i in range(n):
    for w in range(W+1):
        if w >= wv[i][0]:
            dp[i+1][w] = max(
                dp[i][w - wv[i][0]] + wv[i][1],
                dp[i][w]
            )
        else:
            dp[i+1][w] = dp[i][w]

print(dp[n][W])

Measured memory_bytes: 120044
import sys
sys.setrecursionlimit(100010)
n=int(input())
childs_list=[[] for _ in range(n)]
for i in range(n):
    tmp=list(map(int, input().split()))
    childs_num=tmp[1]
    node_id=tmp[0]
    childs_list[node_id].extend(tmp[2:])

class Tree:
    def __init__(self,childs_list):
        self.n=len(childs_list)
        self.parent=[-1]*self.n
        self.first_child=[-1]*self.n
        self.next_child=[-1]*self.n
        for i in range(self.n):
            childs_num=len(childs_list[i])
            if childs_num == 0:
                continue
            self.first_child[i]=childs_list[i][0]
            for j in range(childs_num):
                self.parent[childs_list[i][j]]=i
                if j < childs_num-1:
                    self.next_child[childs_list[i][j]]=childs_list[i][j+1]
        self.node_type=[0]*n
        for i in range(self.n):
            if self.parent[i]==-1:
                self.node_type[i]="root"
                self.root=i
            elif self.first_child[i]==-1:
                self.node_type[i]="leaf"
            else:
                self.node_type[i]="internal node"
        self.d=[-1]*self.n

    def parent_of(self,id):
        return self.parent[id]
    
    def childs_of(self,id):
        childs=[]
        if self.first_child[id]==-1:
            return childs
        else:
            now_child=self.first_child[id]
            while 1:
                childs.append(now_child)
                if self.next_child[now_child] == -1:
                    break
                else:
                    now_child=self.next_child[now_child]
        return childs
    
    def set_depth(self,id,d):
        if id != -1:
            self.d[id]=d
            self.set_depth(self.next_child[id],d)
            self.set_depth(self.first_child[id],d+1)


tree=Tree(childs_list)
tree.set_depth(tree.root,0)

for i in range(n):
    print("node {}: ".format(i),end="")
    print("parent = {}, ".format(tree.parent_of(i)),end="")
    print("depth = {}, ".format(tree.d[i]),end="")
    print("{}, ".format(tree.node_type[i]),end="")
    print(tree.childs_of(i))



Measured memory_bytes: 118812
#include<stdio.h>
#define max 5

int main(void)
{
  int a[max], b[max], c[max], d[max], t;
  int i, sum = 0, j, u;
  
  for(i = 0 ; i <= 4 ; i++)
  {
    scanf("%d", &a[i]);
    b[i] = a[i];
    while(b[i] >= 10)
    {
      t = b[i];
      b[i] = t - 10;
    }
  }
  for(i = 0 ; i <= 3 ; i++)
  {
    for(j = i ; j <= 4 ; j++)
    {
      if(b[j] < b[i] && b[j] != 0)
      {
        u = b[j];
        b[j] = b[i];
        b[i] = u;
        u = a[j];
        a[j] = a[i];
        a[i] = u;
      }
    }
  }
  
  for(i = 1 ; i <= 4 ; i++)
  {
    if(b[i] != 0)
    {
      c[i] = 10 - b[i];
      d[i] = a[i] + c[i];
    }
    else
      d[i] = a[i];
    sum += d[i];
  }
  sum += a[0];
  
  printf("%d", sum);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	ll cnt = 1;
	vector<ll>vec(N);
	bool ok = false;
	rep(i, 0, N) {
		cin >> vec[i];
		if (vec[i] == 0)ok = true;
	}
	if (ok) {
		cout << 0 << "\n";
		return 0;
	}
	rep(i, 0, N) {
		ll a = vec[i];
		if (cnt != 0 && a != 0 && cnt > (ll)1e18 / a) {
			cout << -1 << "\n";
			return 0;
		}
		cnt *= a;
	}
	cout << cnt << "\n";

	return 0;
}

Measured memory_bytes: 3992
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

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 main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    int l[100010];
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    sort(l, l+n);

    ll res = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i+2; j < n; j++)
        {
            int aplusb = l[i] + l[j];
            int abdiff = abs(l[i] - l[j]);

            auto iter_lower = lower_bound(l+i+1, l+j, aplusb);
            auto iter_upper = upper_bound(l+i+1, l+j, abdiff);
            
            auto tmp = iter_lower - iter_upper;

            res += tmp;
        }
        
    }
    cout << res << "\n";
    
    
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){

    ll n,m;
    cin >> n >> m;

    ll ans = 0;
    if(n>1){
        ans += (n)*(n-1)/2;
    }
    if(m>1){
        ans += (m)*(m-1)/2;
    }

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

Measured memory_bytes: 256
from collections import deque,Counter
import sys
input = sys.stdin.readline

n,m,k = map(int,input().split())
ans = [0]*n
frd = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    frd[a].append(b)
    frd[b].append(a)
    ans[a] -= 1
    ans[b] -= 1

ucnt = 0
uni = [-1]*n
stk = deque()
for i in range(n):
    if uni[i] != -1: continue
    stk.append((i,-1))
    while stk:
        cur,prev = stk.pop()
        uni[cur] = ucnt
        for nxt in frd[cur]:
            if nxt == prev: continue
            if uni[nxt] != -1: continue
            stk.append((nxt,cur))
    ucnt += 1
cnt = Counter(uni)

for _ in range(k):
    c,d = map(int,input().split())
    c -= 1
    d -= 1
    if uni[c] == uni[d]:
        ans[c] -= 1
        ans[d] -= 1

for i in range(n): 
    ans[i] += cnt[uni[i]] - 1
    print(ans[i],end=" ")

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

int main(){
	int a,p;
	cin >> a >> p;
	
	cout << (3*a+p)/2 << endl;
	
    return 0;
}



Measured memory_bytes: 256
input_str = input()[:4]
head = int(input_str[:2])
foot = int(input_str[2:4])

if head > 12 or head == 0:
    if foot <= 12 and foot > 0:
        print('YYMM')
    else:
        print('NA')
elif head > 0:
    if foot > 12 or foot == 0:
        print('MMYY')
    elif foot <= 12:
        print('AMBIGUOUS')
    else:
        print('NA')
else:
    print('NA')


Measured memory_bytes: 3060
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			long[] a = new long[n];
			long[] b = new long[n];
			
			for(int i=0;i<n;i++) {
				a[i] = sc.nextLong();
				b[i] = sc.nextLong();
			}
			
			long ret = 0;
			
			for(int i=n-1;i>=0;i--) {
				a[i]+=ret;
				
				if(a[i]%b[i]!=0) {
					ret += (a[i]/b[i]+1)*b[i]-a[i];
				}
			}
			
			System.out.println(ret);
		}
		
	}


Measured memory_bytes: 61556
#54b
n,m = map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        t = [k[j:j+m] for k in a[i:i+m]]
        if t==b:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3060
#include <stdio.h>
long long lcm(long long a,long long b){
    if(a<b){
        long long tmp;
    tmp = a;
    a = b;
    b = tmp;
  }
  long long inia=a,r;
  long long inib=b;
    r = a % b;
      while(r!=0){
        a = b;
        b = r;
        r = a % b;
      }
      inia/=b;
      return (inia*inib);

}
int main(){
  long long n,i,t[101];
  scanf("%lld",&n);
  for(i=0;i<n;i++){
      scanf("%lld",&t[i]);
  }
  long long ans=t[0];
  for(i=0;i<n;i++){
      ans=lcm(ans,t[i]);
  }
  printf("%lld",ans);
  return 0;
}

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

int main() {
  string S;
  string dic = "abcdefghijklmnopqrstuvwxyz";
  cin >> S;
  //sort(S.begin(),S.end());
  for(int i=0;i<dic.size();i++){
    for(int j=0;j<S.size();j++){
     if(S[j]==dic[i]) break;
     if(j==S.size()-1) {
       cout << dic[i] << endl;
       return 0;
     }
   }
  }
  cout << "None" << endl;
}


Measured memory_bytes: 512
N,X=map(int,input().split())
import math
a=list(map(int,input().split()))
a.append(X)
a.sort()
S=[]
for i in range(N):
    S.append(a[i+1]-a[i])

    
ans=S[0]
for j in range(1,N):
    ans=math.gcd(ans,S[j])
    
print(ans)


Measured memory_bytes: 20352
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> d(N); for(auto& in:d) cin >> in;
    sort(d.begin(),d.end());
    res = d[N/2] - d[N/2-1] ;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int h, w;
  cin >> h >> w;
  string s[h];
  for (int i = 0; i < h; i++) cin >> s[i];
  for (int i = 0; i < w + 2; i++) cout << '#';
  cout << endl;
  for (int i = 0; i < h; i++) {
    cout << '#' << s[i] << '#' << endl;
  }
  for (int i = 0; i < w + 2; i++) cout << '#';
  cout << endl;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  t=S()

  # a〜z
  l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

  l1=['']*26
  l2=['']*26

  for i in range(len(s)):
    if l1[l.index(s[i])]!='':
      if l1[l.index(s[i])]!=t[i]:
        return 'No'
    else:
      l1[l.index(s[i])]=t[i]

  for i in range(len(s)):
    if l2[l.index(t[i])]!='':
      if l2[l.index(t[i])]!=s[i]:
        return 'No'
    else:
      l2[l.index(t[i])]=s[i]

  return 'Yes'

print(main())


Measured memory_bytes: 5928
#include<bits/stdc++.h>
using namespace std;
struct node{
	int f,dis;
};
node f[100001];
int findx(int x){
	if(f[x].f==x&&f[x].dis==0)return x;
	int k=findx(f[x].f);
	f[x].dis=f[f[x].f].dis+f[x].dis;
	f[x].f=k;
	return k;
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		f[i].f=i;
		f[i].dis=0;
	}
	for(int i=1;i<=m;i++){
		int a,b,d;
		cin>>a>>b>>d;
		int k1=findx(a),k2=findx(b);
		if(k1!=k2){
			/*if(a>b){
				swap(a,b);
				d=-d;
			}*/
			if(k1>k2){
				f[k1].f=k2;
				f[k1].dis=-(f[a].dis-f[b].dis+d);
			}
			else{
				f[k2].f=k1;
				f[k2].dis=f[a].dis-f[b].dis+d;
			}
		}
		else{
			if(f[b].dis-f[a].dis!=d){
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
int main() {
    int N;
    cin >> N;
    map<i64, int> m;
    for(int i = 0; i < N; i++) {
        i64 x;
        cin >> x;
        if(!m.count(x)) m[x] = 0;
        m[x]++;
    }
    int ans = 0;
    for(auto x : m) {
        if(x.first <= x.second) ans += x.second - x.first;
        else ans += x.second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<Int> A(N);
	for (int i = 0; i < N; ++i) { cin >> A[i]; }

	vector<Int> a;
	a.push_back(A[0]);
	for (int i = 1; i < N; ++i) {
		if (a.back() != A[i]) { a.push_back(A[i]); }
	}

	int n = a.size();
	if (n == 1) {
		cout << "1000\n";
		return 0;
	}

	Int x = 1000;
	Int l = -1, h = -1;
	for (int i = 0; i < n; ++i) {
		if (i == 0) {
			if (a[i] < a[i + 1]) { l = a[i]; }
			continue;
		}
		if (i == n - 1) {
			if (a[i - 1] < a[i]) { h = a[i]; }
		}
		if (l < 0) {
			if (a[i - 1] > a[i] && a[i] < a[i + 1]) {
				l = a[i];
			}
		}
		if (h < 0) {
			if (a[i - 1] < a[i] && a[i] > a[i + 1]) {
				h = a[i];
			}
		}
		if (l > 0 && h > 0) {
			Int y = x / l;
			x = (x - y*l) + y*h;
			l = -1;
			h = -1;
		}
	}
	cout << x << endl;

	return 0;
}


Measured memory_bytes: 3624
#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() {
  int n, a;
  scanf("%d", &n);
  int m[n + 1] = { };
  rep(i,n-1)
  {
    scanf("%d", &a);
    m[a]++;
  }
  for (int i = 1; i <= (int) (n); ++i) {
    printf("%d\n", m[i]);
  }
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int L[N];
    REP(i, N){
        cin >> L[i];
    }

    int ans = 1, D = 0;
    FOR(i, 1, N){
        D = D + L[i-1];

        if (D <= X) ans++;
        else break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <cstdio>
int v[25],c[25];
int main()
{
 int n,ans=0;
 scanf("%d",&n);
 for(int i=1;i<=n;i++)
  scanf("%d",&v[i]);
 for(int i=1;i<=n;i++)
  scanf("%d",&c[i]);
 for(int i=1;i<=n;i++)
  if(v[i]>c[i])ans+=v[i]-c[i];
 printf("%d\n",ans);
 return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

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 RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

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

int main(void) {
    int N;
    cin >> N;
    VI v(N);
    REP(i, N) cin >> v[i];

    SORT(v);
    double ans = v[0];
    REP(i, N - 1) ans = (ans + v[i + 1]) / 2;
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    string s,t,b={"b"};
    cin>>s>>t;
    vector<vector<string>> dp(s.size()+1,vector<string>(t.size()+1));
    rep(i,s.size())rep(j,t.size()){
        string a=dp[i+1][j];
        if(a.size()<dp[i][j+1].size()) a=dp[i][j+1];
        if(s[i]==t[j]&&a.size()<dp[i][j].size()+1) a=dp[i][j]+s[i];
        dp[i+1][j+1]=a;
        if(i>1&&j>2) dp[i-2][j-2]=b;
    }
    cout<<dp[s.size()][t.size()];
}

Measured memory_bytes: 85740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k;
ll a[101];
ll dp[101][100100];
ll dp2[101][101000];
ll p=1000000007;
ll rec(ll pos,ll left)
{
    if(pos==n+1)
    {
        if(left==0)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    if(left<0)
    {
        return 0;
    }
    if(dp[n-pos+1][left]>=0)
    {
        return dp[n-pos+1][left];
    }
    ll answer=0;
    for(ll i=0;i<=a[pos];i++)
    {
        answer=(answer+rec(pos+1,left-i))%p;
    }
    dp[n-pos+1][left]=answer;
    return answer;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1,greater<ll>());
    ll dp1[n+1];
    dp1[1]=a[1];
    for(ll i=2;i<=n;i++)
    {
        dp1[i]=(dp1[i-1]+a[i])%p;
    }
    dp[1][0]=1;
    dp2[1][0]=1;
    for(ll i=1;i<=min(a[1],k);i++)
    {
        dp[1][i]=1;
        dp2[1][i]=(dp2[1][i-1]+1)%p;
    }
    for(ll i=2;i<=n;i++)
    {
        dp[i][0]=1;
        dp2[i][0]=1;
        for(ll j=1;j<=min(dp1[i],k);j++)
        {
            if(j<=a[i])
            {
                dp[i][j]=dp2[i-1][j];
            }
            else if(j<=min(dp1[i-1],k))
            {
                dp[i][j]=(dp2[i-1][j]-dp2[i-1][j-a[i]-1]+p)%p;
            }
            else
            {
                dp[i][j]=(dp2[i-1][min(dp1[i-1],k)]-dp2[i-1][min(dp1[i-1],k)-(a[i]-(j-min(dp1[i-1],k))+1)]+p)%p;
            }
            dp2[i][j]=(dp2[i][j-1]+dp[i][j])%p;
        }
    }
    cout<<dp[n][k];
    //memset(dp,-1,sizeof(dp));
    //cout<<rec(2);
    //cout<<dp[n][k];
	return 0;
}

Measured memory_bytes: 158208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)cin>>arr[i];
    sort(arr,arr+n);
    cout<<arr[n/2]-arr[n/2-1];
    return 0;
}

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

using namespace std;

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	const double phi = 3.14;
	int r;
	cin >> r;
	cout << (phi * r * r) / (phi * 1 * 1) << "\n";


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pa pair<int,int>
#define CLR(a,x) memset(a,x,sizeof(a))
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
const int maxn=1;

inline char gc(){
	return getchar();
	static const int maxs=1<<16;static char buf[maxs],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxs,stdin),p1==p2)?EOF:*p1++;
}
inline ll rd(){
    ll x=0;char c=gc();bool neg=0;
    while(c<'0'||c>'9'){if(c=='-') neg=1;c=gc();}
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();
    return neg?(~x+1):x;
}



int main(){
    //freopen("","r",stdin);
    int a=rd(),b=rd();
    if(a>=b) printf("1");
    printf("0\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#define int double
using namespace std;

signed main() {
	signed a, b;
	while (cin >> a >> b, a | b) {
		vector<int>c(b);
		for (int d = 0; d < a; d++) {
			for (int e = 0; e < b; e++) {
				int f;
				cin >> f;
				if (f)c[e]++;
			}
		}
		map<int, int>s;
		for (double g = 0; g < b; g++) {
			s[-(c[g] - g*0.01)];
			s[-(c[g] - g*0.01)] = g+1;
		}
		int n = 0;
		for (auto x = s.begin(); x != s.end(); x++,n++) {
			if (b - 1 == n)cout << x->second << endl;
			else cout << x->second << " ";
		}
	}
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807


int main()
{
int ans[100010]={};
queue<ll> q;
ll n;
cin >> n;
vector<pair<ll,ll> > G[n];

ans[0]=1;
rep(i, n-1)
{
    ll a,b,c;
    cin >> a>>b>>c;
    G[a-1].push_back(pair<ll,ll>(b-1, c));
    G[b-1].push_back(pair<ll,ll>(a-1, c));
}
q.push(0);
while(!q.empty()){
    ll aa=q.front();
    //cout << "aa"<<aa+1 << endl;
    q.pop();
    rep(i,G[aa].size()){
        if(ans[G[aa][i].first]>0)continue;
        q.push(G[aa][i].first);
        if(G[aa][i].second%2==0)ans[G[aa][i].first]=ans[aa];
        else ans[G[aa][i].first]=((ans[aa])%2)+1;
    }
}
rep(i,n){
    cout << ans[i] -1<< endl;
}

return 0;
}

Measured memory_bytes: 8320
#include<iostream>
using namespace std;
int main(){
  int n,r,p,c,a[51],b[51];
  while(cin>>n>>r){
    if(n==0 && r==0)break;
    for(int i=0;i<n;i++)
      a[i]=n-i;
    for(int i=0;i<r;i++){
      cin>>p>>c;
      for(int i=0;i<n;i++)
	b[i]=a[i];
      for(int i=0;i<c;i++)
	a[i]=b[p-1+i];
      for(int i=0;i<p-1;i++)
	a[c+i]=b[i];
    }
    cout<<a[0]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int x;
main() {
  file("threesum");
  ios;
  cin >> x;
  int y = x % 500;
  cout << x / 500 * 1000 + (y / 5) * 5;
  return 0;
}
/**

*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}


  
int main() {
  vi sq;
  srep(i,1,1000) {
    sq.push_back(i*i);
  }
  int N,D;
  cin >> N >> D;
  vvi X(N,vi(D));
  rep(i,N) {
    rep(j,D) {
      cin >> X[i][j];
    }
  }
  int ans = 0;
  rep(i,N) {
    rep(j,N) {
      if(i == j) continue;
      if(i > j) continue;
      // i < j
      int dis2 = 0;
      rep(k,D) {
        dis2 += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      }
      if(find(rng(sq),dis2) != sq.end()) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<algorithm> // sort,reverse,min,lower_bound
#include<vector>
#include<set>    // multiset
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;


int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >>n;
  vector<pair<li,li>> vec(n);
  rep(i,n){
    li x,r; cin >>x >>r;
    vec.at(i).first=x+r;
    vec.at(i).second=x-r;
  }
  sort(vec.begin(),vec.end());
  if(df){
    for(pair<li,li> x:vec)printf("(%d,%d)",x.first,x.second);
    printf("\n");
  }
  vector<int> dp(n,0);
  rep(i,n){
    auto temp=vec.at(i);
    auto itr=lower_bound(vec.begin(),vec.end()
			 ,make_pair(temp.second,temp.second));
    int x=itr-vec.begin();
    if(0==x){
      dp.at(i)=1;
    }else{
      dp.at(i)=dp.at(x-1)+1;
    }
    if(i>0 and dp.at(i-1)>dp.at(i))dp.at(i)=dp.at(i-1);
  }
  if(df){
    for(auto x:dp)printf("%ld ",x);
    printf("\n");
  }
  cout << dp.at(n-1);
}

/// confirm df==0 ///


Measured memory_bytes: 2176
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

#define dump1(v) for(auto i:v) std::cout << i << ' '; std::cout << "\n";
#define dump2(v) for(auto i:v) { for(auto j:i) std::cout << j << ' '; std::cout << "\n"; }


struct BIT
{
	int size;
	std::vector<int> data;
	BIT(int n) : data(n+1,0), size(n) {}
	void add(int i,int v) {
		i+=1;
		while(i<=size) {
			data[i]+=v;
			i += i&-i;
		}
	}
	int query(int l, int r) {
		// [l, r)
		int rv = 0;
		while(r>0) {
			rv+=data[r];
			r -= r&-r;
		}
		int lv = 0;
		while(l>0) {
			lv+=data[l];
			l -= l&-l;
		}
		return rv-lv;
	}
};


int inversion_number(const std::vector<int>& a) {
	int n = a.size();
	std::vector<int> b = a;
	std::sort(all(b));
	std::vector<int> c(n);
	for(int i=0;i<n-1;i++) {
		c[i+1] = c[i];
		if(b[i+1]!=b[i]) c[i+1]++;
	}

	// reconstruct
	std::vector<int> d(n);
	for(int i=0;i<n;i++) {
		d[i] = c[std::lower_bound(all(b),a[i]) - b.begin()];
	}

	BIT bit(n);
	int count = 0;
	for(int i=0;i<n;i++) {
		count += bit.query(0,d[i]+1);
		bit.add(d[i],1);
	}

	return count;
}

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	rep(i,n) {
		int x;
		std::cin >> x;
		a[i] = x-k;
	}
	std::vector<int> ac(n,0);
	ac[0] = a[0];
	for(int i=1;i<n;i++) {
		ac[i] = ac[i-1] + a[i];
	}

	int count = 0;
	for(int i:ac) {
		if(i>=0) count++;
	}

	print(inversion_number(ac)+count);

	return 0;
}


Measured memory_bytes: 9600
a=b=1
gets.to_i.times do
  na,nb = gets.rstrip.split.map(&:to_i)
  t = [a.to_r/na, b.to_r/nb].max.ceil
  # p [a, b, na,nb, t]
  a = na*t
  b = nb*t
end
p a+b

Measured memory_bytes: 2044
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

int main(){
    int d;
    while(cin >> d){
        int total = 0;
        for(int i = 0; i < 600/d - 1; i++){
            total = total + d*d*d*(i+1)*(i+1);
        }
        cout << total << endl;
    }
}

Measured memory_bytes: 3004
<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function arrayIn(){
		$buf = explode(" ", fgets(STDIN));
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->arrayIn();
		$ans1 = $s[0] + $s[1];
		$ans2 = $s[0] * $s[1];
		if($ans1 == 15){
			echo "+";
		}elseif($ans2 == 15){
			echo "*";
		}else{
			echo "x";
		}
	}
}
?>


Measured memory_bytes: 4728
#include <stdio.h>
void insertion(int *a,int n);

int main(int argc, const char * argv[]) {
    int a[1000],n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n-1;i++)
        printf("%d ",a[i]);
    printf("%d\n",a[i]);
    insertion(a,n);
}

void insertion(int *a,int n){
    int i,j,k,v;
    for(i=1;i<n;i++){
        v=a[i];
        j=i-1;
        while(j>=0 && a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        
        for(k=0;k<n-1;k++)
            printf("%d ",a[k]);
        printf("%d\n",a[k]);
    }
}



Measured memory_bytes: 2052
def getinputdata():

    array_result = []
    
    data = input()
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

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

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

#maxvalue
k = int(arr_data[0][0])

#sumvalue
s = int(arr_data[0][1])

cnt = 0

for x in range(0, k + 1):
    
    for y in range(0, k + 1):
        
        z = s-x-y
        
        if z >= 0 and z <= k:
            
            cnt += 1
            
print(cnt)
 
    

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-


if __name__ == '__main__':

    N = 8
    FREE = -1
    NOT_FREE = 1
    row = [FREE] * N
    col = [FREE] * N
    dpos = [FREE] * (2 * N - 1)
    dneg = [FREE] * (2 * N - 1)
    X = [["." for _ in range(N)] for _ in range(N)]

    k = int(input())
    for _ in range(k):
        i, j = map(int, input().split())
        X[i][j] = "Q"
        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE

    def printBoard(X):
        for i in range(N):
            print("".join(X[i]))

    def recursive(i):
        if i == N:
            printBoard(X)
            return
        if "Q" in X[i]:
            recursive(i + 1)

        for j in range(N):
            if NOT_FREE in [row[i], col[j], dpos[i + j], dneg[i - j + N - 1]]:
                continue
            else:
                X[i][j] = "Q"
                row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE
            recursive(i + 1)
            X[i][j] = "."
            row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE

    recursive(0)



Measured memory_bytes: 5624
def dfs():
    ans = []
    vNow = 0
    while True:
        useds[vNow] = True
        ans.append(vNow + 1)
        for v2 in adjL[vNow]:
            if not useds[v2]:
                vNow = v2
                break
        else:
            break

    return ans


N, M = map(int, input().split())
adjL = [[] for v in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    adjL[a - 1].append(b - 1)
    adjL[b - 1].append(a - 1)

useds = [False] * N
ans1 = dfs()
ans2 = dfs()
print(len(ans1) + len(ans2) - 1)
print(' '.join(map(str, ans1[::-1] + ans2[1:])))


Measured memory_bytes: 32928
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
 
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
 
int main() {
    int h,w,k;
    char fld[300][300];
    cin>>h>>w>>k;
    int ans[300][300];
    vector<int> v[h];
    REP(i,h){
        REP(j,w){
            cin>>fld[j][i];
            if(fld[j][i]=='#'){
                v[i].PB(j);
            }
        }
    }
    int s=-1;
    int cnt=1;
    REP(i,h){
        if(v[i].size()==0){
            if(s==-1)continue;
            else{
                REP(j,w)ans[i][j]=ans[i-1][j];
            }
        }else{
            if(s==-1)s=i;
            int p=0;
            REP(j,v[i].size()){
                for(;p<=v[i][j];p++){
                    ans[i][p]=cnt;
                }
                if(j==v[i].size()-1){
                    for(;p<w;p++)ans[i][p]=cnt;
                }
                cnt++;
            }
        }
    }
    REP(i,s){
        REP(j,w)ans[i][j]=ans[s][j];
    }
    REP(i,h){
        REP(j,w)cout<<ans[i][j]<<" ";cout<<endl;
    }
}


Measured memory_bytes: 1792