akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<complex>
#include<vector>
#include<stdlib.h>
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
typedef P point;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
vector<point> convex_hull(vector<point> ps) {
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<point> ch(2*n);
  for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}
enum { OUT, ON, IN };
int contains(const vector<point>& P, const point& p) {
  bool in = false;
  for (int i = 0; i < P.size(); ++i) {
    point a = curr(P,i) - p, b = next(P,i) - p;
    if (imag(a) > imag(b)) swap(a, b);
    if (imag(a) <= 0 && 0 < imag(b))
      if (cross(a, b) < 0) in = !in;
    if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
  }
  return in ? IN : OUT;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
int x[200];
int y[200];
P wolf[200];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a+b){
		for(int i=0;i<a;i++)scanf("%d%d",x+i,y+i);
		for(int i=0;i<b;i++)scanf("%d%d",x+a+i,y+a+i);
		bool ok=true;
		int n=a+b;
		for(int i=0;i<n;i++)wolf[i]=P(x[i],y[i]);
		vector<point>A;
		vector<point>B;
		for(int i=0;i<a;i++)A.push_back(wolf[i]);
		for(int i=0;i<b;i++)B.push_back(wolf[a+i]);
		A=convex_hull(A);
		B=convex_hull(B);
		if(contains(A,B[0]))ok=false;
		if(contains(B,A[0]))ok=false;
		for(int i=0;i<A.size();i++)
			for(int j=0;j<B.size();j++)
				if(intersectSS(L(curr(A,i),next(A,i)),L(curr(B,j),next(B,j))))ok=false;
		if(ok)printf("YES\n");
		else printf("NO\n");
	}
}

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


int main(){
  long long n, m, d;
  cin >> n >> m >> d;
  if(d != 0){
    printf("%.9lf\n", 2.0*(m-1)*(n-d)/n/n);
  }else{
    printf("%.9lf\n", 1.0*(m-1)*(n-d)/n/n);
  }
}


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

using namespace std;

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

    int t;
    cin >> t;
    vector<int> heights;
    while (t--)
    {
        int a;
        cin >> a;
        heights.push_back(a);
    }
    int n = heights.size();
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(heights[1] - heights[0]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(heights[i - 1] - heights[i]), dp[i - 2] + abs(heights[i - 2] - heights[i]));
    }
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
map<P,int> ma;
vector<int> g[1000100];
bool used[1001000];
int h[1001000];
int dp[1001000];
int main(){
  int n;cin>>n;
  int ko=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ma[P(i,j)]=ko;
      ko++;
    }
  }
  for(int i=0;i<n;i++){
    int x[10100];
    for(int j=0;j<n-1;j++){
      cin>>x[j];x[j]--;
      if(j>=1){
        int a=i,b=x[j-1],c=i,d=x[j];
        if(a>b)swap(a,b);
        if(c>d)swap(c,d);
        g[ma[P(a,b)]].push_back(ma[P(c,d)]);
        h[ma[P(c,d)]]++;
      }
    }
  }
      
  stack<int> st;
  for(int i=0;i<n*(n-1)/2;i++){
    if(h[i]==0)st.push(i);
  }
  vector<int> res;
  while(st.size()){
    int i=st.top();st.pop();
    res.push_back(i);
    for(int j:g[i]){
      h[j]--;
      if(h[j]==0)st.push(j);
    }
  }
  
  if(res.size()!=n*(n-1)/2){
    cout<<-1<<endl;
    return 0;
  }
  
  //for(int i:res)cout<<i<<endl;
  int ans=0;
  for(int i=0;i<n*(n-1)/2;i++){
    int v=res[i];
    
    for(int w:g[v]){
      dp[w]=max(dp[w],dp[v]+1);
    }
    ans=max(ans,dp[v]);
  }
  cout<<ans+1<<endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  int x = N;
  while (x>0) {
    sum += x%10;
    x /= 10;
  }
  if(N%sum==0) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  cout << endl;
}


Measured memory_bytes: 256
N = int(input())
profit = [list(map(int, input().split())) for i in range(N)]
#dp[i][p] をi日目にｐをしたときのi日目までの最大値
#dpを初期化
dp = [[0 for j in range(3)] for i in range(N+1)]
# for p in range(3):
    # dp[0][p] = profit[0][p]

#dpの更新
for i in range(N):
    for p in range(3):
        dp[i][p] = max(dp[i-1][p-1],dp[i-1][p-2]) + profit[i][p]
print(max(dp[-2]))

Measured memory_bytes: 47380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string A;
  cin >> A;
  int N = A.size();
  int MI = 10000;
  rep(i, N - 2) {
    MI = min(abs((A.at(i) - '7') * 100 + (A.at(i+1) - '5') * 10 + A.at(i+2) - '3'), MI);
  }
  cout << MI << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
#define ll long long
#define repX(i,j,n)for (ll i = j; i < n; i++)
#define rep(i, n) repX(i,0,n)


int main() //https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d
{
    ll n,sum =0;
    cin >> n;
    
    for(ll m = 1; m*m<= n ;m++)
    {
        if(n%m==0 && n/m - m >1)
            sum +=n/m - 1;
    }
  
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect
n, a, b, q = map(int, input().split())

W = [input().split() for i in range(a)]
X = [int(x) for x, c in W]
C = [c for x, c in W]

P = [list(map(int, input().split())) for i in range(b)]
Y = [y for y, h in P] + [n+1]
D = [0]*b

for i in range(b):
    y0, h = P[i]; y1 = Y[i+1]
    l = y1 - y0
    D[i] = min(y0 - h, l)

idx = 0
S = {}
for i in range(a):
    x = X[i]; c = C[i]
    S[x] = c
    if x < Y[0]:
        continue
    while Y[idx+1] <= x: idx += 1
    i = idx; j = i
    while Y[0] <= x:
        while x < Y[i]: i -= 1
        y0, h = P[i]; y1 = Y[i+1]
        if h == 0: break
        x = h + ((x - y0) % D[i])
        assert x < y0
        S[x] = c
def check(z):
    if z in S:
        return S[z]
    i = bisect(Y, z)-1
    while Y[0] <= z:
        while z < Y[i]: i -= 1
        y0, h = P[i]; y1 = Y[i+1]
        if h == 0: break
        z = h + ((z - y0) % D[i])
        assert z < y0
        if z in S:
            return S[z]
    return '?'

Z = [int(input()) for i in range(q)]
print(*map(check, Z), sep='')

Measured memory_bytes: 89780
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n,k;
  cin>>n>>k;
  vector< vector<Int> > v(k);
  for(Int i=0;i<k;i++){
    v[i].resize(n/2);
    for(Int j=0;j<n/2;j++) cin>>v[i][j],v[i][j]--;
  }

  auto check=[&](string s){
    for(Int i=0;i<k;i++){
      Int tmp=0;
      for(Int j=0;j<n/2;j++)
	tmp+=(s[v[i][j]]=='1');
      //cout<<i<<":"<<tmp<<endl;
      if(tmp<n/8||tmp>3*n/8) return 0;
    }
    return 1;
  };
  
  srand((unsigned)time(NULL));
  while(1){
    string s;
    for(Int i=0;i<n;i++)
      s.push_back(char('0'+(rand()%2)));
    if(check(s)){
      cout<<s<<endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 4564
#include <iostream>
#include<cstring>
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200005];
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    int b[200005],e=0;
    memset(b,0,sizeof(b));
    b[0]=1;
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
            b[e]++;
        else
        {
            e++;
            b[e]++;
        }
    }
    sort(b,b+e+1);
    int cnt=0,num=e+1,w=0;
    while(num>k)
    {
        cnt+=b[w++];
        num--;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 1792
from subprocess import*
call(('pypy3','-c',"""
s=input()
t=input()
n,m=len(s),len(t)
dp=[[0]*(m+1) for i in range(n+1)]
dp[0][0]=1
for i in range(n+1):
    for j in range(m+1):
        dp[i][j]=max(dp[i][j-1],dp[i-1][j])
        if i*j!=0 and s[i-1]==t[j-1]:
            dp[i][j]=max(dp[i-1][j-1]+1,dp[i][j])
ans=""
i,j=n,m
while 0<i and 0<j:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        ans+=s[i-1]
        i-=1
        j-=1

print(ans[::-1])
"""))

Measured memory_bytes: 117036
//#include "pch.h"
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <map>
#define OO INT_MAX
#define mp(x,y) make_pair(x,y)
#define x first
#define y second
#define ll unsigned long long int
#define pp pair<int,int>
#define heap priority_queue<pp, vector<pp>, greater<pp>>
using namespace std;
map<int, int> marked;
vector<vector<int>> Sheet;

int main()
{
	//freopen("test.txt", "r", stdin);
	/*	int n, m;
	string num;
	cin >> n >> m;
	num.resize(n, '0');
	int in1, in2;
	map<int, int> isIn;
	for (int i = 0; i < m; i++) {
		cin >> in1 >> in2;
		if (isIn[in1] && num[in1-1]!= to_string(in2)[0]) {
			cout << -1;
			return 0;
		}
		num[in1 - 1] = to_string(in2)[0];
		isIn[in1] = true;
	}
	if (num.size() != 1) {
		for (int i = 0; i < num.size(); i++) {
			if (num[i] == '0') {
				cout << -1;
				return 0;
			}
			else {
				break;
			}
		}
	}
	cout << num;*/


	vector<int> v(3);
	Sheet.resize(3, v);
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> Sheet[i][j];
		}
	}
	int n;
	cin >> n;
	int in;
	for (int i = 0; i < n; i++) {
		cin >> in;
		marked[in] = true;
	}
	bool isNot = false;
	for (int i = 0; i < 3; i++) {
		isNot = false;
		for (int j = 0; j < 3; j++) {
			if (!marked[Sheet[i][j]]) {
				isNot = true;
				break;
			}
		}
		if (!isNot) {
			cout << "Yes";
			return 0;
		}
	}


	isNot = false;
	for (int i = 0; i < 3; i++) {
		isNot = false;
		for (int j = 0; j < 3; j++) {
			if (!marked[Sheet[j][i]]) {
				isNot = true;
				break;
			}
		}
		if (!isNot) {
			cout << "Yes";
			return 0;
		}
	}

	if ((marked[Sheet[0][0]] && marked[Sheet[1][1]] && marked[Sheet[2][2]]) ||
		(marked[Sheet[2][0]] && marked[Sheet[1][1]] && marked[Sheet[0][2]])) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}





/*
	
	}*/

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    rep(i, N) rep(j, i + 1, N) rep(k, j + 1, N) {
        if(A[i] == A[j] || A[j] == A[k] || A[k] == A[i]) continue;
        if((A[i] + A[j] > A[k]) && (A[i] + A[k] > A[j]) && (A[k] + A[j] > A[i])) ans++;
    }
    output(ans);
    
    return 0;
}


Measured memory_bytes: 3552
from collections import deque

n = int(input())
nodes = [[] for _ in range(n)]
node_list = []
for _ in range(n - 1):
	a, b = map(int, input().split())
	nodes[a - 1].append(b - 1)
	node_list.append(b - 1)
 
que = deque([0])
ans = [0] * n
while len(que) > 0:
	ni = que.pop()
	color = 1
	for node in nodes[ni]:
		if color == ans[ni]:
			color += 1
		ans[node] = color
		color += 1
		que.append(node)
 
print(max(ans))
for node in node_list:
	print(ans[node])

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

using namespace std;

int n,a[25],b[25],c[25],i,j,ans,last;

int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
		scanf("%d",&b[i]);
	for(i=2;i<=n;i++)
		scanf("%d",&c[i]);
	for(i=1;i<=n;i++)
	{
		ans+=b[a[i]];
		if(a[i]==last+1)
			ans+=c[a[i]];
		last=a[i];
	}
	printf("%d",ans);
	return 0;
}

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

1000*1000*25
*/
struct Z{
  ll y;
  ll x;
  ll depth;
};

ll H,W,y,x,depth,oo=1e12,xs,ys,xg,yg,ans=oo;
vector<ll> y_vec={1,0,-1,0};
vector<ll> x_vec={0,1,0,-1};
vector<vector<ll>> A;
queue<Z> Q,Q2;

void bfs(){
  while(!Q.empty()){
    Z now=Q.front(); Q.pop();
    y=now.y, x=now.x, depth=now.depth;
    if (depth >= ans)
      continue;
    if(y==yg && x==xg){
      ans = min(ans, A[yg][xg]);
      continue;
    }
    for(ll i=0; i<4; i++){
      Z next={y+y_vec[i], x+x_vec[i], depth};
      if(A[next.y][next.x]==-1) continue;
      if(A[next.y][next.x]<=next.depth) continue;
      A[next.y][next.x]=next.depth;
      Q.push(next);
    }
    for(ll i=-2; i<=2; i++){
      for(ll j=-2; j<=2; j++){
        Z next={y+i, x+j, depth+1};
//cout<<"ny:"<<next.y<<" nx:"<<next.x<<endl;        
        if(A[next.y][next.x]==-1) continue;
        if(A[next.y][next.x]<=next.depth) continue;
        A[next.y][next.x]=next.depth;
        Q2.push(next);
//cout<<" d:"<<next.depth<<endl;          
      }
    }
  }
  if (!Q2.empty())
  {
    Q = Q2;
    queue<Z> tmp;
    Q2 = tmp;
    bfs();
  }
}

//A[y][x], A(x,y)として管理
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  cin>>H>>W;
  cin>>ys>>xs>>yg>>xg;
  ys++;
  xs++;
  yg++;
  xg++;
  A.assign(H+4, vector<ll>(W+4,-1));
  for(int i=2; i<H+2; i++){
    for(int j=2; j<W+2; j++){
      char a; cin>>a;
      if(a=='#') continue;
      A[i][j]=oo;
    }
  }
  A[ys][xs]=0;
  Z start={ys,xs,0};
  Q.emplace(start);
  bfs();
  if(ans==oo) ans=-1;
  cout<<ans<<endl;
  
/*for(int i=2; i<H+2; i++){
  for(int j=2; j<W+2; j++)
    cout<<A[i][j];
  cout<<endl;
  }*/
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ;
  string ans = "No" ;
  
  rep(i,26){
    rep(j,16){
      if( n == 4*i + 7*j)
        ans ="Yes" ;
    }
  }
  
  cout <<ans ;
  
}


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

int main(void) {
  int ary[5], i;

  for (i = 0; i < 5; i++) {
    std::cin >> ary[i];
  }

  std::sort(ary, ary + 5, std::greater<int>());

  for (i = 0; i < 5; i++) {
    std::cout << ary[i];

    if (i == 4) {
      std::cout << std::endl;
    } else {
      std::cout <<  " ";
    }
  }

  return 0;
}

Measured memory_bytes: 1176
def isLeap(y):
    return y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)

flag2 = False
while True:
    a,b = map(int,input().split())
    if a == 0: break
    if flag2:print()
    flag2 = True

    flag = True
    for y in range(a,b + 1):
        if isLeap(y):
            print(y)
            flag = False
    if(flag):print("NA")

Measured memory_bytes: 7788
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define mod 1000000007
int main()
{
ll m,n;
string s;
cin>>s;ll k=0;ll p=1;
for(ll i=0;i<3;i++)
{
    if(s[i]=='R'&&p==1)
    {
        k++;
    }
    else if(k!=0)
    {
        p=0;
    }
}
cout<<k;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)

void FIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	FIO();
	int n; cin >> n;
	vector<double> a(n);

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

	vector<vector<double>>dp(n + 1, vector<double>(n + 1, 0.0));
	dp[0][0] = 1;

	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j <= i; ++j)
		{
			if (j == 0)
				dp[i][j] = dp[i - 1][j] * (1 - a[i - 1]);
			else
				dp[i][j] = dp[i - 1][j - 1] *  a[i - 1] + dp[i - 1][j] * (1 - a[i - 1]);
		}
	}

	double ans = 0.0;

	for (int i = n; i > n / 2; --i)
		ans = ans + dp[n][i];

	cout << ps(ans, 10) << '\n';

	return 0;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 N,K;
    cin >> N >> K;

    i64 ans=0;
    rep(b,K+1,N+1){
        i64 l=K,r=b-1,i=(N-l)/b+1;
        ans+=(r-l+1)*(i-1);
        ans+=min(r-l+1,N-l-b*(i-1)+1);
    }
    if(K==0) ans-=N;
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; i++) {
        cin >> a[i];
    }

    bitset<100> whiterow, whitecolomn;

    for (int i = 0; i < h; i++) {
        bool is_white_row = true;
        for (int j = 0; j < w; j++) {
            is_white_row &= a[i][j] == '.';
            if (!is_white_row) break;
        }
        whiterow[i] = is_white_row;
    }

    for (int i = 0; i < w; i++) {
        bool is_white_column = true;
        for (int j = 0; j < h; j++) {
            is_white_column &= a[j][i] == '.';
            if (!is_white_column) break;
        }
        whitecolomn[i] = is_white_column;
    }

    for (int i = 0; i < h; i++) {
        if (whiterow[i]) continue;

        for (int j = 0; j < w; j++) {
            if (whitecolomn[j]) continue;
            cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3644
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/08/20 03:55:25
// -----------------------------------

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using ll = long long;

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

  int n,m; cin>>n>>m;
  atcoder::scc_graph G(n);
  for (int i = 0; i < m; i++) {
    int a,b; cin>>a>>b;
    G.add_edge(a, b);
  }
  auto res = G.scc();
  cout << res.size() << endl;
  for (auto& S : res) {
    cout << S.size() << " ";
    for (auto s : S) 
      cout << s << " ";
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 40564
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;cin>>s;
  int a=0,b=0;
  for(int i=0;i<3;i++){
    if(s.at(i)=='R'){
      a++;
    }else{
      if(a!=0){
      b=a;
      a=0;
      }
    }
  }
  cout << max(a,b)<<endl;
}


Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()
{
    int n;
    cin>>n;
    vin l(n);
    rep(i,n)cin>>l[i];
    sort(l.begin(),l.end(),greater<int>());
    int sum=0;
    for(int i=1;i<n;i++)sum+=l[i];
    if(l[0]<sum)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

template<typename T> 
map<T, int> factorize(T x){
  map<T, int> res;
  for(int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;
  return res;
}

//INSERT ABOVE HERE
signed main(){
  int n;
  scanf("%d",&n);
  vector<int> a(n);
  for(int i=0;i<n;i++) scanf("%d",&a[i]);
  sort(a.begin(),a.end());

  vector<int> ans(n);

  int m=0;
  map<int, int> r;

  vector<vector<int> > G(n);
  for(int i=0;i<n;i++){
    auto x=factorize(a[i]);
    for(auto p:x){
      if(!r.count(p.first)) r[p.first]=m++,G.emplace_back();
      G[i].emplace_back(n+r[p.first]);
      G[n+r[p.first]].emplace_back(i);
    }
  }
  
  int color=0;
  vector<int> cs(n+m,-1),used(n+m,0),post(n,0);
  for(int t=0;t<n;t++){
    for(int i=0;i<n+m;i++){
      if(used[i]||~cs[i]) continue;
      queue<int> q;
      cs[i]=color;
      q.emplace(i);
      while(!q.empty()){
	int v=q.front();q.pop();
	for(int u:G[v]){
	  if(used[u]||~cs[u]) continue;
	  cs[u]=color;
	  q.emplace(u);
	}
      }
      color++;
    }
    
    int idx=-1;
    for(int i=0;i<n;i++){
      if(used[i]||post[i]) continue;
      idx=i;
      break;
    }
    
    used[idx]=1;
    ans[t]=idx;
    
    for(int i=0;i<n+m;i++){
      if(used[i]||cs[idx]!=cs[i]) continue;
      if(i<n) post[i]=__gcd(a[idx],a[i])<=1;
      cs[i]=-1;
    }
  }

  vector<int> b(n);
  for(int i=0;i<n;i++) b[i]=a[ans[i]];
  
  vector<vector<int> > H(n);
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      if(__gcd(b[i],b[j])>1) H[i].emplace_back(j);

  vector<int> indeg(n);
  for(int i=0;i<n;i++)
    for(int j:H[i]) indeg[j]++;
  
  using P = pair<int, int>;
  priority_queue<P> pq;
  for(int i=0;i<n;i++)
    if(!indeg[i]) pq.emplace(b[i],i);

  vector<int> c;
  while(!pq.empty()){
    P p=pq.top();pq.pop();
    c.emplace_back(p.first);
    for(int u:H[p.second]){
      indeg[u]--;
      if(!indeg[u]) pq.emplace(b[u],u);
    }
  }
  
  for(int i=0;i<n;i++){
    if(i) printf(" ");
    printf("%d",c[i]);
  }
  puts("");
  return 0;
}


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

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

typedef vector<int> vi;

bool good[20][20];
int dp[2][20];

int main(){
    int w,h;
    while(cin>>w>>h, w|h){
        memset(good,1,sizeof(good));
        memset(dp,0,sizeof(dp));
        int n; cin>>n;
        rep(i,n){
            int x,y; cin>>x>>y;
            x--,y--;
            good[x][y] = false;
        }

        int* prev = dp[0];
        int* cur = dp[1];
        prev[0]=1;
        rep(y,h){
            memset(cur,0,sizeof(dp)/2);
            rep(x,w){
                if(good[x][y]){
                    cur[x] += prev[x];
                    if(x!=0) cur[x] += cur[x-1];
                }
            }
            // rep(i,w) cout << cur[i] << " ";
            // cout<<endl;
            swap(prev, cur);
        }

        cout << prev[w-1] << endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
const int N = 3e5 + 5;

int n, m, ser[N], siz, cnt, h[N];
LL ans, a, b, c;
bool s;
struct Edge {
	int to, next;
} e[N<<1];

void add(int u, int v) {
	e[++cnt] = (Edge) {v, h[u]};
	h[u] = cnt;
}

void Dfs(int u, int pre) {
	ser[u] = 3 - pre;
	siz++;
	for(int i = h[u]; i; i = e[i].next) {
		int v = e[i].to;
		if(!ser[v]) Dfs(v, 3 - pre);
		else if(ser[v] == ser[u]) s = 1;
	}
}

int main() {
	cin>>n>>m;
	rep(i, 1, m) {
		int u, v;
		cin>>u>>v;
		add(u, v);
		add(v, u);
	}
	rep(i, 1, n) {
		if(ser[i]) continue;
		siz = s = 0;
		Dfs(i, 1);
		if(siz == 1) {
			a++; 
			continue;
		}
		if(s == 1) {
			c++;
			continue;
		}
		b++;
	}
	ans += 2*a*n - a*a;
	ans += 2*b*b + b*c;
	ans += c*b + c*c;
	cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;

void solve(int l) {
    vector<vector<pair<int,int>>> hen(20);
    for(int i = 0; i < 19; i++) {
        hen[i].push_back({i + 1, 1<<i});
        hen[i].push_back({i + 1, 0});
    }   
    int k = 1<<19;
    for(int i = 0; i < 19; i++) {
        if(l & (1<<i)) {
            hen[i].push_back({19, k});
            k += (1<<i);
        }
    }
    int m = 0;
    for(auto i : hen)m += i.size();
    cout << 20 << " " << m << endl;
    for(int i = 0; i < 20; i++) {
        for(auto j : hen[i])cout << i + 1 << " " << j.first + 1 << " " << j.second << endl;
    }
}

int main()
{
    int l; cin >> l;
    if(l >= (1<<19)){solve(l);return 0;}
    int k = 0;

    vector<vector<pair<int,int>>> hen(20);

    for(int i = 0; i < 19; i++) {
        if((1<<i) & l) {
            hen[i].push_back({19, k});
            k = k + (1<<i);
        }
    }
    for(int i = 0; i < 18; i++) {
        hen[i].push_back({i + 1, 0});
        hen[i].push_back({i + 1, (1<<i)});
    }

    int m = 0;
    for(auto i : hen)m += i.size();
    cout << 20 << " " << m << endl;
    for(int i = 0; i < 20; i++) {
        for(auto j : hen[i])cout << i + 1 << " " << j.first + 1 << " " << j.second << endl;
    }

}


Measured memory_bytes: 3576
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  let
    modulus = 1000000007 :: Int
    modInv :: Int -> Int -> Int -> Int
    modInv modulus maxArg = (invs VU.!) . (`mod` modulus)
      where
        invs :: VU.Vector Int
        invs = VU.constructN (succ maxArg `min` modulus) rec
          where
            rec v = case VU.length v of
              0 -> 0
              1 -> 1
              l -> let (q, r) = modulus `divMod` l in (modulus - (v VU.! r) * q) `mod` modulus
    modComb :: Int -> Int -> Int
    modComb n = go 1
      where
        go :: Int -> Int -> Int
        go c 0 = c
        go c k = go (c * (n - k') `mod` modulus * modInv' k `mod` modulus) k'
          where
            k' = k - 1 :: Int
        modInv' :: Int -> Int
        modInv' = modInv modulus 666666
    f :: Int -> Int -> Int
    f x y
        | (x + y) `mod` 3 /= 0 || 2 * x < y || 2 * y < x
          = 0
        | otherwise
          = modComb (u + v) u
      where
        u = (2 * y - x) `div` 3 :: Int
        v = (2 * x - y) `div` 3 :: Int
  [x, y] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  print $ f x y

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 9520
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#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()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 1;
    int cnt = 0;
    int sum = 0;
    rep(i,s.size()){
        s[i] = char(s[i] == 'B');
        //cout << i << " " << s[i] << " " << cnt << " " << sum << " " << ans << endl;
        if(sum == n || cnt == n){
            if(s[i] != cnt%2){
                cout << 0 << endl;
                return 0;
            }
            ans *= cnt;
            ans %= MOD;
            cnt--;
        }else if(cnt == 0){
            cnt++;
            sum++;
            if(s[i] != cnt%2){
                cout << 0 << endl;
                return 0;
            }
        }else{
            if(s[i] == cnt%2){//へる
                ans *= cnt;
                ans %= MOD;
                cnt--;
            }else{
                cnt++;
                sum++;
            }
        }
    }
    loop(i,1,n+1){
        ans *= i;
        ans %= MOD;
    }
    if(sum == n)cout << ans << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int S,resH,resM,resS=0;
  scanf("%d",&S);
  resH=S/3600;
  resM=(S%3600)/60;
  resS=(S%3600)%60;
    printf("%d:%d:%d\n",resH,resM,resS);
    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
int N;
double p[3333];
double dp[3333][3333]; // dp[i][j]: 表i枚、裏j枚が出る確率
 
signed main() {
  // 入力
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
 
  dp[0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
        if(i+j > N) continue;
      // おもて
      dp[i+1][j] += dp[i][j] * p[i+j];
      // うら
      dp[i][j+1] += dp[i][j] * (1 - p[i+j]);
    }
  }
 
  double ans = 0;
  for (int i = N/2+1; i <= N; i++) {
    int j = N - i;
    ans += dp[i][j];
  }
 
  printf("%.10f\n", ans);
 
  return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
#define pq priority_queue
using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2;
typedef pair<int, P2> P3; typedef long long ll; typedef long double ld;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<10> fact; constexpr Prime<10> prime;
constexpr int comb(int a, int b){long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b];return pos * pot % MOD * por % MOD;}
template<int n> struct Bernoulli{long long arr[n+1];constexpr Bernoulli():arr(){arr[0]=1;for(int i=1;i<=n;i++){long long sum=0;for(int j=0;j<i;j++){(sum+=comb(i+1,j)*arr[j]%MOD)%=MOD;}arr[i]=(MOD-mod_pow(i+1,MOD-2,MOD))%MOD*sum%MOD;}}};
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr int sqrtN = 512, logN = 32;
constexpr ld PI = abs(acos(-1));
constexpr ll LINF=1e18;

int main(){
	int a, b; cin >> a >> b;
	
	int c = 0;
	for(int i = a; i <= b; i++){
		string s = to_string(i);
		if(s[0] == s[4] and s[1] == s[3]) c++;
	}
	
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		boolean judge = false;

		for (int i = 0; i < b; i++){
			if ((a * i) % b == c){
				judge = true;
			}
		}
		if (judge){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


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

void trace(int A[], int N) { //配列の要素を順番に出力
    int i;
    for (i=0; i<N; i++) {
        if (i > 0) cout << " "; //隣接する要素の間に1つの空白を出力
        cout << A[i];
    }
    cout << endl;
}

//挿入ソート（0オリジン配列）
void insertionSort(int A[], int N) {
    int j, i, 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;
        trace(A, N);
    }
}
int main() {
    int N, i, j;
    int A[100];

    cin >> N;
    for (i=0; i<N; i++) cin >> A[i];

    trace(A, N);
    insertionSort(A, N);
    
    return 0;
}


Measured memory_bytes: 3088
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let n : usize = get_one();
    let v : Vec<i32> = get_vec();
    let ans = v.iter().max().unwrap() - v.iter().min().unwrap();
    println!("{}", ans );
}


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

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

    int N, M;
    map<string, int> s = {};
    string tmp;

    cin >> N;

    for (int i = 0; i < N; ++i)
    {
        cin >> tmp;
        if (s.find(tmp) == s.end())
        {
            s[tmp] = 0;
        }
        ++s[tmp];
    }

    cin >> M;

    for (int i = 0; i < M; ++i)
    {
        cin >> tmp;
        if (s.find(tmp) != s.end())
        {
            --s[tmp];
        }
    }

    int ans = 0;
    for (auto itr = s.begin(); itr != s.end(); ++itr)
    {
        if (ans < itr->second)
        {
            ans = itr->second;
        }
    }

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


Measured memory_bytes: 888
N = int(input())
LIST =[input() for _ in range(N)]
AC = LIST.count("AC")
WA = LIST.count("WA")
TLE = LIST.count("TLE")
RE = LIST.count("RE")
print(f"AC x {AC}\nWA x {WA}\nTLE x {TLE}\nRE x {RE}")

Measured memory_bytes: 16276
import bisect

def main():
    n = int(input())
    ll = list(map(int, input().split()))
    ll.sort()

    ans = 0
    for i in range(n-2):
        e1 = ll[i]
        for j in range(i+1, n-1):
            e2 = ll[j]
            # ans += bisect.bisect_left(ll[j+1:], e1+e2)
            comb = bisect.bisect_left(ll, e1+e2)
            comb -= (j+1)
            ans += max(comb,0)

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int a[100000][2], i, I, x, y, z;
	for(i = 0 ;  ; i++)
	{
		scanf("%d%d", &a[i][0], &a[i][1]);
		if(a[i][0] == 0 || a[i][1] == 0)
		{
			for(I = 0; I < i ; I++)
			{
				for(z = 0 ; z < a[I][1] ; z++)
				{
					printf("#");
				}
				printf("\n");
				for(x = 0 ; x < a[I][0]-2 ; x++)
				{
					printf("#");
					for(y = 0 ; y < a[I][1]-2 ; y++)
					{
						printf(".");
					}
					printf("#");
					printf("\n");
				}
				for(z = 0 ; z < a[I][1] ; z++)
				{
					printf("#");
				}
				printf("\n\n");
			}
			exit(0);
		}
	}
	return 0;
}


Measured memory_bytes: 2044
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	string s;
	cin >> s;
	if (s[0] != '1' || s[s.length() - 1] != '0') {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < s.length()-1; ++i) {
		if (s[i] != s[s.length() - i - 2]) {
			cout << -1 << endl;
			return 0;
		}
	}
	s[s.length() - 1] = '1';
	int hoge = s.length()-1;
	for (int i = s.length() - 2; i >= 0; --i) {
		cout << hoge+1 << " " << i+1 << endl;
		if (s[i] == '1') {
			hoge = i;
		}
	}
	return 0;
}

Measured memory_bytes: 1600
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main() {
	cin.sync_with_stdio(false); cin.tie(nullptr);
	int n; cin >> n;
	int x, y; cin >> x >> y; x--; y--;
	vector<int> cnt(n, 0);
	vector<vector<int>> mat(n, vector<int>(n));
	for(int i = 0; i<n; ++i)
		for (int j = i + 1; j < n; ++j) {
			int dis2 = j-i;
			if (i <= x && j >= y)
				dis2 -= y - x - 1;
			if (i >= x && j <= y)
				dis2 = min(dis2, i - x + 1 + y - j);
			if (i <= x && j <= y && j >= x)
				dis2 = min(dis2, x - i + 1 + y - j);
			if (i >= x && i <= y && j >= y)
				dis2 = min(dis2, i - x + 1 + j - y);
			cnt[dis2]++;
			mat[i][j] = dis2;
		}
	for (int i = 1; i < n; ++i)
		cout << cnt[i] << "\n";
	return 0;
}

Measured memory_bytes: 16000
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    L = kwargs["L"]
    res = 0
    for i in range(n):
        for j in range(i+1, n):
            for k in range(j+1, n):
                if L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
                    if abs(L[i] - L[j]) < L[k] < L[i] + L[j]:
                        res += 1

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"] = [int(i) for i in cin][0]

    cin = input().split()
    kwargs["L"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 31172
import java.lang.Math

val MOD: Int = 1000000000 + 7
val MODL: Long = MOD.toLong()

fun main(args: Array<String>)
{
    val (a, b)  = read().split(" ").map{it.toLong()}
    val g = gcd(a,b)

    println(a * b / g)
}

fun gcd(a: Long, b: Long): Long {
    if (b == 0L) return a

    return gcd(b, a % b)
}

fun read(): String = readLine()!!


Measured memory_bytes: 37840
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>
#include <fstream>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N;
	cin >> N;
	double A[N];
	for (ll i = 0; i < N; ++i) cin >> A[i];
 
	// 解法
    double ans = 0;
    REP(i,N) ans += 1/A[i];
    ans = 1/ans;

	//出力
	printf("%.10f\n", ans); // lld としないとオーバーフローする
	// if (ans) printf("Yes\n");
	// else printf("No\n");
}


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

int main(void){
    int N; cin >> N;
    vector<int> f(N); vector<int> d(N);
    for(int i = 0; i < N; i++){
        char c; int l;
        cin >> c >> l;
        d[i] = (c == 'y'? true : false);
        f[i] = l;
    }

    vector<int> order(f);
    vector<int> o(N, -1);
    for(int i = 0; i < N; i++){
        int minv = 1001, mini = -1;
        for(int j = 0; j < N; j++){
            if(minv > order[j]){
                minv = order[j];
                mini = j;
            }
        }
        o[i] = mini;
        order[mini] = 1001;
    }

    int ans = 0;
    vector<int> used(N, false);
    for(int i = 0; i < N; i++){
        int idx = o[i];
        if(used[idx] == true || d[idx] == false) continue;
        used[idx] = true;
        ans++;
        for(int i = idx-1; i >= 0; i--){
            if(d[i] == false && f[i] >= f[idx]) break;
            used[i] = true;
        }
        for(int i = idx+1; i < N; i++){
            if(d[i] == false && f[i] >= f[idx]) break;
            used[i] = true;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3172
function Main(input) {
    // inputにはすべての入力の文字列が与えられるので必要に応じて input.split("\n") などで分割する。
    var data = input.split("\n")
    var first_line = data[0].split(" ")
    
    var c = parseInt(first_line[0]) + parseInt(first_line[1])/2

    console.log(c);
}

// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <atcoder/dsu>
#include <bits/stdc++.h>
 
using namespace std;
using namespace atcoder;
 
int main() {
  int N, Q;
  cin >> N >> Q;
  dsu d(N);
  
  for (int i = 0; i < Q; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    
    if (t == 0) {
      d.merge(u, v);
    } else {
      cout << d.same(u, v) << endl;
    }
  }
}

Measured memory_bytes: 4004
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
int N, M, Q, a[50], b[50], c[50], d[50];

int ans = 0;
int A[10];
void dfs(int cnt, int v)
{
    if(cnt == N)
    {
        int tot = 0;
        for(int i = 0; i < Q; i++)
        {
            if(A[b[i]] - A[a[i]] == c[i])
                tot += d[i];
        }

        ans = max(ans, tot);
        return ;
    }

    for(int i = v; i < M + 1; i++)
    {
        A[cnt] = i;
        dfs(cnt + 1, i);
    }

}
int main()
{
    cin >> N >> M >> Q;

    for(int i = 0; i < Q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }

    dfs(0, 1);
    cout << ans << endl;
}

Measured memory_bytes: 3164
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class T2 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.ni();
            int count = 0;
            for (int i = 1; i <= n; i += 2) {
                int div = 0;
                for (int j = 1; j <= i; ++j) {
                    if (i % j == 0) div++;
                }
                if (div == 8) count++;
            }
            out.print(count);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21460
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
using namespace std;

int main(){
	int n;
	int k;
	scanf("%d%d", &n, &k);
	
	bool disl[10]; for(int i = 0; i < 10; ++i) disl[i] = 1;
	for(int i = 0; i < k; ++i){
		int a;
		cin >> a;
		disl[a] = 0;
	}

	for(int i = n; i < 100000; ++i){
		bool ans = 0;
		char s[7]; for(int j = 0; j < 7; ++j) s[j] = 'a';
		sprintf(s, "%d", i);
		for(int j = 0; j < 7; ++j){
			if((s[j] != 'a') && (s[j] != 0) && (!disl[s[j] - '0'])) break;
			else if(j == 6) ans = 1;
		}

		if(ans){
			cout << i << endl;
			break;
		}
	}

	return 0;
}

	

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

#define For(i,l,r) for(int i=l;i<=r;i++)
#define ForR(i,l,r) for(int i=l;i>=r;i--)
#define ll long long
int main(){
//	freopen(".inp","r",stdin);
// 	freopen(".out","w",stdout);
	ll a,b;
	cin>>a>>b;
	if(a<=b)For(i,1,b)cout<<a;
	else For(i,1,a)cout<<b;
	}

Measured memory_bytes: 256