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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

double dp[40010][210];

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

  int N;
  cin >> N;

  VI ts(N), vs(N);
  REP(i,N) cin >> ts[i];
  REP(i,N) cin >> vs[i];

  fill((double*)dp, (double*)dp+40010*210, -1e15);
  dp[0][0] = 0.;
  int t = 0;
  REP(i,N){
	REP(dt,ts[i]*2){
	  REP(v,vs[i]*2+1){
		maxi(dp[t+1][v], dp[t][v] + v/2. / 2.);
		if(v+1 <= vs[i]*2)
		  maxi(dp[t+1][v+1], dp[t][v] + (v/2. + (v+1)/2.) / 4.);
		if(v-1 >= 0)
		  maxi(dp[t+1][v-1], dp[t][v] + (v/2. + (v-1)/2.) / 4.);
	  }
	  ++t;
	}
  }
  cout << fixed << setprecision(11) << dp[t][0] << endl;

  return 0;
}


Measured memory_bytes: 65920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int inf = numeric_limits<int>::max();

int main(void){
  int n;
  int grid[550][550] = {};
  int whitec[550] = {};
  int nblackc = 0;
  cin >> n;
  for(int i = 0;i < n;++i){
    string s;
    cin >> s;
    for(int j = 0;j < n;++j){
      if(s[j] == '.'){
        grid[i][j] = 0;
      }else{
        grid[i][j] = 1;
      }
    }
  }
  for(int c = 0;c < n;++c){
    bool white = true;
    bool black = true;
    for(int r = 0;r < n;++r){
      if(grid[r][c] == 0)
        black = false;
      else
        white = false;
    }
    if(white)whitec[c] = 1;
    if(black)++nblackc;
  }
  bool muri = true;
  for(int c = 0;c < n;++c){
    if(!whitec[c]){
      muri = false;
      break;
    }
  }
  if(muri){
    cout << "-1" << endl;
    return 0;
  }
  int res = inf;
  for(int r = 0;r < n;++r){
    int cres = 0;
    if(whitec[r])++cres;
    for(int c = 0;c < n;++c){
      if(grid[r][c] == 0)
        ++cres;
    }
    cres += n - nblackc;
    res = min(res,cres);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1408
function primeFactorization(n) {

	// 平方根を保存
	var s = Math.floor(Math.sqrt(n));

	var r = 0;

	var result = Array();

	// 2から平方根までの素因数を求める
	for (var i = 2;i <= s;i++) {

		if ((n % i) == 0) {

			r = 0; // 指数カウンタクリア

			do {

				r++; // 指数カウンタプラス

				n = n / i;

			} while ((n % i) == 0);

			// 素因数iを指数とともに保存
			result.push({num:i, r:r});

		}

	}

	// 残った素数を追加
	if (n > s) {
		result.push({num:n, r:1});
	}

	return result;
}
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const line0vars = line0.split(" ");

	const n = parseInt(line0vars[0], 10);
	const p = parseInt(line0vars[1], 10);

	const a = primeFactorization(p);
	var result = 1;
	a.forEach(b => {
		if (n <= b.r) {
			const k = Math.floor(b.r / n);
			result = result * Math.pow(b.num, k);
		}
	});
	
	// console.log({
	// 	n: n,
	// 	p: p,
	// 	a: a
	// });

	console.log(result);

	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

	//出力
	// console.log('%d %s',a+b+c,s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)


Measured memory_bytes: 33292
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    int ans = 0;
    for(int i=1;i<=N-2;++i){
        int tmpans = 0;
        map<char,int> mp;
        rep(k,i) mp[S[k]] = 1; 
        for(int k=i;k<N;++k) if(mp[S[k]] == 1) mp[S[k]] =2;
        for(auto e:mp) if(e.second == 2) ++tmpans;
        ans = max(ans,tmpans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int H,W;
char field[100][100];
void dfs(int,int);
int main(){
	while(true){
		int count = 0;
		cin>>H>>W;
		if(!(H+W))break;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin>>field[i][j];
			}
		}
		int a,b;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if(field[i][j] != '.'){
					dfs(i,j);
					count++;
				}
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

void dfs(int x,int y) {
	char current = field[x][y];
	field[x][y] = '.';
	for (int dx = -1; dx <= 1; dx++) {
		for (int dy = -1; dy <= 1; dy++) {
			if(dx && dy)continue;
			int nx = x+dx,ny = y+dy;
			if(nx >= 0 && nx < H && ny >= 0 && ny < W && field[nx][ny] == current)dfs(nx,ny);
		}
	}
	return;
}

Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define int long long
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<vi>
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=(1ll<<62)-1;
signed main(){
  ll A,B; cin>>A>>B;
  string ans="Positive";
  if(A<=0&&0<=B) ans="Zero";
  else if(0>B&&(B-A)%2==0) ans="Negative";
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define sz(a)           (int)(a).size()
#define all(x)          (x).begin(), (x).end()
#define fore(i,a,b)     for(int i=a; i<b; i+=1)
#define forr(i,a)       for(int i=a; i>=0; i--)
#define F first
#define S second

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef vector<string> vs;
const int MAX=1e5+10;

ll sum(ll n){
    return (n*(n+1))/2;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n,m; cin>>n>>m;
    int res=sum(n-1)+sum(m-1);
    cout<<res<<endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
typedef long long lld;
const int LOGA = 60;
const int MAXN = 1e5+5;
int cnt[LOGA];
lld A[MAXN];
lld B[LOGA];
int N;

void augment_basis(lld vec) {
  for (int j = LOGA-1; j >= 0; --j) {
    if ((vec >> j) & 1) {
      if (B[j]) {
        vec ^= B[j]; // Subtract basis vector.
      } else {
        B[j] = vec;
        return;
      }
    }
  }
}

void init() {
  for (int j = 0; j < LOGA; ++j) {
    B[j] = cnt[j] = 0;
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < LOGA; ++j) {
      if ((A[i] >> j) & 1) ++cnt[j];
    }
  }
}

// Greedily augment MSBs of basis vectors

lld max_xor() {
  lld sum = 0LL;
  for (int j = LOGA-1; j >= 0; --j) {
    if (!B[j]) continue;
    if ((sum >> j) & 1) continue;
    sum ^= B[j];
  }
  return sum;
}

// Bits of odd multiplicity contribute exactly once to the sum.

lld odd_bits() {
  lld sum = 0LL;
  for (int j = 0; j < LOGA; ++j) {
    if (cnt[j] & 1) {
      lld two = (1LL << j);
      for (int i = 0; i < N; ++i) {
        A[i] &= ~two;
      }
      sum |= two;
    }
  }
  return sum;
}

lld solve() {
  lld ret = odd_bits();
  for (int i = 0; i < N; ++i) {
    augment_basis(A[i]);
  }
  ret += max_xor() << 1;
  return ret;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &A[i]);
  }
  init();
  printf("%lld\n", solve());
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int absi(int x1,int x2){
  if(x1>x2)swap(x1,x2);
  return x2-x1;
}

int main(){
  int N,K;
  cin>>N>>K;
  int h[N];
  REP(i,N)cin>>h[i];
  int dp[N];
  REP(i,N)dp[i]=0;
  FOR(i,1,N){
    int temp=1e9;
    FOR(j,1,K+1){
      if(j>i)break;
      temp=min(temp,dp[i-j]+absi(h[i],h[i-j]));
    }
    dp[i]=temp;
  }
  // REP(i,N)cerr<<dp[i]<<" ";
  // cerr<<endl;
  cout<<dp[N-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
N,M=map(int,input().split(' '))
H=list(map(int,input().split(' ')))
AB=[[] for i in range(N)]

for i in range(M):
    A,B=map(int,input().split(' '))
    AB[A-1].append(B)
    AB[B-1].append(A)

res=0
for i in range(N):
    if len(AB[i])==0:
        res+=1
        continue
    
    f=True
    for k in AB[i]:
        if H[i] <= H[k-1]:
            f=False
            break
    
    if f:
        res+=1

print(res)

    

Measured memory_bytes: 29480
#include <bits/stdc++.h>
#include <cctype>
using namespace std;
typedef long long int ll;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	cout.tie(NULL);
	char x; cin >> x;
	if(isupper(x))
		cout << "A" << '\n';
	else
		cout << "a" << '\n';
	return 0;
}

Measured memory_bytes: 3608
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define mp make_pair
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=20000+10;
const int inf=0x3f3f3f3f;

int n,x[2][N];
pair<int,int> a[N];

struct edge { int v,nxt; } e[N*40];
int head[N*5],ecnt;
void addEdge(int u,int v) {
	e[++ecnt]=(edge){v,head[u]},head[u]=ecnt;
}

#define ls (o<<1)
#define rs (o<<1|1)
int cnt,id[N<<2];
void build(int o,int l,int r) {
	if (l==r) { id[o]=a[l].second; return; }
	id[o]=++cnt; int mid=(l+r)>>1;
	build(ls,l,mid),build(rs,mid+1,r);
	addEdge(id[o],id[ls]),addEdge(id[o],id[rs]);
}
void link(int o,int l,int r,int ql,int qr,int u) {
	if (ql>qr) return;
	if (ql<=l&&r<=qr) { addEdge(u,id[o]); return; }
	int mid=(l+r)>>1;
	if (ql<=mid) link(ls,l,mid,ql,qr,u);
	if (qr>mid) link(rs,mid+1,r,ql,qr,u);
}
#undef ls
#undef rs

int dfn[N*5],low[N*5],tim=0,sta[N*5],in[N*5],top=0,bl[N*5],tot=0;
void tarjan(int u) {
	dfn[u]=low[u]=++tim,sta[++top]=u,in[u]=1;
	for (int i=head[u];i;i=e[i].nxt) {
		int v=e[i].v;
		if (!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
		else if (in[v]) low[u]=min(low[u],dfn[v]);
	}
	if (dfn[u]==low[u]) {
		++tot;
		while (1) {
			int t=sta[top--];
			bl[t]=tot,in[t]=0;
			if (t==u) break;
		}
	}
}

bool check(int mid) {
	memset(head,0,sizeof(head)),ecnt=0;
	cnt=n<<1,build(1,1,n<<1);
	for (int i=1;i<=n;++i)
		for (int j=0;j<2;++j) {
			int l=upper_bound(a+1,a+n+n+1,mp(x[j][i]-mid,inf))-a;
			int r=lower_bound(a+1,a+n+n+1,mp(x[j][i]+mid,0))-a-1;
			int p=lower_bound(a+1,a+n+n+1,mp(x[j][i],i+(!j)*n))-a;
			link(1,1,n<<1,l,p-1,i+j*n),link(1,1,n<<1,p+1,r,i+j*n);
		}
	memset(dfn,0,sizeof(dfn)),memset(low,0,sizeof(low)),tim=0;
	memset(in,0,sizeof(in)),memset(bl,0,sizeof(bl)),top=tot=0;
	for (int i=1;i<=cnt;++i) if (!dfn[i]) tarjan(i);
	for (int i=1;i<=n;++i) if (bl[i]==bl[i+n]) return 0;
	return 1;
}

int main() {
	n=read();
	for (int i=1;i<=n;++i) {
		x[0][i]=read(),a[i]=mp(x[0][i],i+n);
		x[1][i]=read(),a[i+n]=mp(x[1][i],i);
	}
	sort(a+1,a+n+n+1);
	int L=0,R=1e9;
	while (L<R) {
		int mid=(L+R+1)>>1;
		if (check(mid)) L=mid;
		else R=mid-1;
	}
	printf("%d\n",L);
	return 0;
}

Measured memory_bytes: 14056
using System;

namespace agc040a
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            long ans = 0;
            int[] A = new int[S.Length+1];
            int[] B = new int[S.Length+1];
            int countL = 0;
            int countR = 0;
            for(int i = 0; i < S.Length;i++){
                if(S.Substring(i,1) == "<"){
                    countL++;
                }else{
                    countL = 0;
                }
                A[i+1] = countL;
            }
            for(int i = S.Length-1; i >= 0;i--){
                if(S.Substring(i,1) == ">"){
                    countR++;
                }else{
                    countR = 0;
                }
                B[i] = countR;
            }
            for(int i = 0; i < A.Length; i++){
                ans += Math.Max(A[i],B[i]);
            }
            Console.WriteLine(ans);
            
        }
    }
}

Measured memory_bytes: 20940
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] cards = new string[3];
        for (int i = 0; i < 3; i++) cards[i] = Console.ReadLine();
        int turn = 0;
        
        while (true)
        {
            if (cards[turn].Length == 0) break;
            char next = cards[turn][0];
            cards[turn] = cards[turn].Remove(0, 1);
            turn = next - 'a';
        }
        if (turn == 0) Console.WriteLine("A");
        else if (turn == 1) Console.WriteLine("B");
        else if (turn == 2) Console.WriteLine("C");
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
char s[maxx];

int main() {
	scanf("%s", s + 1);
	int l = strlen(s + 1);
	int cnt1 = 0, cnt2 = 0;
	for(int i = 1; i <= l; i++) {
		if(s[i] == '0') cnt1++;
		else cnt2++;
	}
	int ans = min(cnt1, cnt2) * 2;
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define pii pair<int, int>
#define fir first
#define sec second
using namespace std;
const int MAXN = 2e5 + 7;
const int INF = 1e9;
int head[MAXN];
struct node{int v, next, val;}e[MAXN << 1];
int tot = 1, col[MAXN];
void add(int u, int v)
{
    e[++tot] = {v, head[u], INF};
    head[u] = tot;
}
pii a[MAXN];
int d[MAXN];
int main()
{
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) 
    {
        scanf("%d", &d[i]);
        a[i].fir = d[i], a[i].sec = i;
        col[i] = -1;
    }
    sort(a + 1, a + 1 + n);
    for (int i = 1, u, v; i <= m; i++)
    {
        scanf("%d%d", &u, &v);
        add(u, v); add(v, u);
    }
    for (int o = 1; o <= n; o++)
    {
        int u = a[o].sec;
        if (col[u] != -1) continue;
        int eid = 0;
        for (int i = head[u]; i; i = e[i].next)
        {
            int v = e[i].v;
            if (d[v] == d[u] && col[v] == -1) {eid = i; break;} 
            if (d[v] <= d[u] && col[v] != -1) eid = i;
        }
        if (!eid) 
        {
            puts("-1");
            return 0;
        }
        int v = e[eid].v;
        e[eid].val = e[eid ^ 1].val = d[u];
        if (col[v] == -1) {col[v] = 0; col[u] = 1;}
        else col[u] = col[v] ^ 1;
    }
    for (int i = 1; i <= n; i++) putchar(col[i] ? 'B' : 'W');
    putchar('\n');
    for (int i = 2; i <= tot; i += 2) printf("%d\n", e[i].val);
    return 0;
}

Measured memory_bytes: 9728
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <unordered_map>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#define int long long 
#define lli unsigned long long int
#define pb push_back
#define ins emplace
#define mod 1e9+7
#define fi(i,n) for(int i=1; i<=n;i++)
#define INF 10000000000
#define unm  unordered_map<int , int>
#define vvi  vector<vector<int>>
#define sortall(v) sort(v.begin(),v.end())
#define deb(x)     cout << #x << "=" << x << endl
#define deb2(x,y)  cout << #x << "=" << x << "," << #y << "=" << y << endl
#define mp make_pair
#define F  first
#define S second
#define itr(it,a) for(auto it = a.begin(); it!=a.end();it++)
#define vi  vector<int>
#define pii pair<int ,int>
#define vii vector<vi>
#define in1(x) int x; cin >> x
#define in2(x,y) int x,y; cin >> x >> y;
#define in3(x,y,z) int x,y,z; cin >> x >> y >> z

using namespace std;

int32_t main(){
	string s ;
	cin >> s;
	int sum= 0;
	int i= 0;
	for(auto c : s){
		sum+=(c-'0');
	}
	if(sum%9 == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3488
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long H, W;
    scan(H, W);
    long cnt;
    foreach (i; 0 .. H)
    {
        auto A = sread();
        foreach (c; A)
        {
            cnt += c == '#';
        }
    }
    writeln((cnt == H + W - 1) ? "Possible" : "Impossible");
}


Measured memory_bytes: 256
#include <stdio.h>

int head[1000];
int tail[1000];
int cnt;
int nxt[501010];
int val[501010];

int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++)head[i]=tail[i]=i,nxt[i]=-1;
	cnt=n;
	while(q--){
		int t;
		scanf("%d",&t);
		if(t==0){
			int k,x;
			scanf("%d%d",&k,&x);
			val[tail[k]]=x;
			nxt[tail[k]]=cnt;
			tail[k]=cnt;
			cnt++;
		}else if(t==1){
			int k;
			scanf("%d",&k);
			if(head[k]!=tail[k])printf("%d\n",val[head[k]]);
		}else{
			int k;
			scanf("%d",&k);
			if(head[k]!=tail[k])head[k]=nxt[head[k]];
		}
	}
}


Measured memory_bytes: 3280
import sys

INPUT = lambda: sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)


def main():
    S = INPUT()

    b = 0
    for i in range(2):
        if 0 < int(S[2*i:2*i+2]) <= 12: b += i + 1

    if b == 0: print("NA")
    elif b == 1: print("MMYY")
    elif b == 2: print("YYMM")
    else: print("AMBIGUOUS")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int power(ll x, ll y) 
{ 
    int res = 1;  

    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x); 
        y = y>>1; 
        x = (x*x);  
    } 
    return res; 
} 

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,k;
    cin >> n >> k;
    ld answer = 0.0;
    for (int z=1;z<=n;z++){
    	ll count = z;
    	ll times = 0;
		while (count < k){
			count *= 2;
			times++;
		}
    	answer += ld(1.0)/power(2,times)/ld(n);
    }
    cout << setprecision(60) << answer << endl;
    cin >> n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define foru(i, a, b) for(int i = int(a); i <= int(b); i++)
using namespace std;

const int N = 1005;
const int K = 100005;

int n, m, k, ans1[K], ans2[K], ans3[K];
int x[K], y[K], a[K], b[K], t[N][N];
char s[N][N];

int rec(int x, int y, int a, int b) {
    return t[a][b] - t[a][y-1] - t[x-1][b] + t[x-1][y-1];
}

void sol(char cc, int ans[]) {
    foru(i, 1, n) foru(j, 1, m) t[i][j] = 0;
    foru(i, 1, n) foru(j, 1, m)
        t[i][j] = t[i-1][j] + t[i][j-1] - t[i-1][j-1]
                + (s[i-1][j-1] == cc);
    foru(i, 1, k)
        ans[i] = rec(x[i], y[i], a[i], b[i]);
}

int main() {
    //freopen("a.txt", "r", stdin);

    scanf("%d%d%d", &n, &m, &k);
    foru(i, 0, n-1) scanf("%s", &s[i]);
    foru(i, 1, k) scanf("%d%d%d%d", &x[i], &y[i], &a[i], &b[i]);

    sol('J', ans1);  sol('O', ans2);  sol('I', ans3);

    foru(i, 1, k) printf("%d %d %d\n", ans1[i], ans2[i], ans3[i]);
}

Measured memory_bytes: 8844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

ll solve(ll h,ll w){
    ll res=LINF;
    ll men = h*w;
    for(ll i=0;i<=h;i++){
        ll S1 = w*i;
        ll S2 = (h-i)/2LL * w;
        ll S3 = men - S1 - S2;
        if(min({S1,S2,S3})<0) continue;
        ll tmp = max({S1,S2,S3}) - min({S1,S2,S3});
        res = min(res,tmp);
    }
    for(ll i=0;i<=h;i++){
        ll S1 = w*i;
        ll S2 = (h-i) * (w/2);
        ll S3 = men - S1 - S2;
        if(min({S1,S2,S3})<0) continue;
        ll tmp = max({S1,S2,S3}) - min({S1,S2,S3});
        res = min(res,tmp);
    }
    return res;
}

int main(){
    ll h,w;
    cin >> h >> w;
    cout << min(solve(h,w),solve(w,h)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
using ll = long long;

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

int main() {
  int N;
  IN(N);
  vector<int> X(N);
  REP(i, N) IN(X[i]);
  double Z = 0.0;
  REP(i, N) Z += 1.0/X[i];
  OUT(1.0/Z);
}	

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const ll LINF = INF * (ll) INF;
ll dp[100001];
int N , E , T;
int a[100001];
ll dpRMQ[100001];
int opt = 0;
ll cost(int i , int opt)
{
	ll prev = 0;

	prev = dp[opt - 1];

	ll cur = max((a[i] - a[opt]) * 2 , T);

	return prev + cur;
}
int findOpt(int idx)
{
	return lower_bound(a , a + N , a[idx] - T / 2) - a;
}
ll findDp(int idx)
{
	int opt = findOpt(idx);

	ll dp1 = T;

	if(opt - 1 >= 0)
		dp1 += dp[opt - 1];

	ll dp2 = a[idx] * 2;

	if(opt - 1 >= 0)
		dp2 += min(dpRMQ[opt - 1] , 0LL);
	else
		return dp1;
	return(min(dp1 , dp2));

}
int main()
{
	scanf("%d %d %d" , &N , &E , &T);
	for(int i = 0; i < N; i++)
	{
		scanf("%d" , &a[i]);
	}
	dp[0] = T;
	dpRMQ[0] = - a[0] * 2;
	for(int i = 1; i < N; i++)
	{
		dpRMQ[i] = min(dpRMQ[i - 1] , dp[i - 1] - a[i] * 2);
		dp[i] = findDp(i);
	}
	cout << dp[N - 1] + E;
}




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

using namespace std;

int a[200], b[200], c[200], d, n, t[200], dp[200][200];//dp[i][j] i??\?????????j???????????¨???????????§

int main()
{
	cin >> d >> n;

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

	for (int i = 0; i < d;i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (a[j] <= t[i] && b[j] >= t[i])
			{
				if (i == 0)
				{
					dp[i][j] = 0;
				}
				else
				{
					for (int k = 0; k < n; k++)
					{
						if (dp[i - 1][k] != -1)
						{
							dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(c[j] - c[k]));
						}
					}
				}
			}
			else
			{
				dp[i][j] = -1;
			}
		}
	}

	sort(dp[d-1], dp[d-1] + n);

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

	return 0;
}

Measured memory_bytes: 1320
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int a = sc.nextInt();
        int[] arrA = new int[a];
        int b = sc.nextInt();
        int[] arrB = new int[b];
        int c = sc.nextInt();
        int[] arrC = new int[c];
        for(int i = 0; i < a; i++)
            arrA[i] = sc.nextInt();
        for(int i = 0; i < b; i++)
            arrB[i] = sc.nextInt();
        for(int i = 0; i < c; i++)
            arrC[i] = sc.nextInt();
        Arrays.sort(arrA);
        Arrays.sort(arrB);
        Arrays.sort(arrC);
        int[] selected = new int[x + y];
        int idx = 0;
        for(int i = a - 1; i >= a - x; i--)
            selected[idx++] = arrA[i];
        for(int i = b - 1; i >= b - y; i--)
            selected[idx++] = arrB[i];
        Arrays.sort(selected);
        for(int i = 0, j = c - 1; i < a + b && j >= 0; i++, j--)
            if(selected[i] >= arrC[j]) break;
            else selected[i] = arrC[j];
        long sum = 0;
        for(long num : selected)
            sum += num;
        System.out.println(sum);
    }
}

Measured memory_bytes: 95804
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << endl;
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define wh while
#define ve vector
#define mp make_pair
#define tp tuple
#define mt make_tuple
#define pb push_back
#define pof pop_front
#define pob pop_back
#define pf push_front
#define fr front
#define ft first
#define sc second
#define tos to_string
#define len length
#define rt return
#define br break
#define con continue
#define lcm(n, m) (n * m / __gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m) - 1;i>=(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) n.begin(), n.end()
#define allr(n) n.rbegin(), n.rend()
#define sp(n) cout << fixed << setprecision(n)
#define pi 3.14159265358979323846
#define inf 1000000007
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

ve<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};

int main() {
  int a, b;
  ci(a, b);
  co(a * b);
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <complex>
#include <cstdio>

using namespace std;

using P = complex<double>;
using Circle = pair<P,double>;

const double EPS = 1e-12;

bool overlap(const Circle& c1, const Circle& c2){
	auto d = abs(c1.first - c2.first);
	return c2.second - (d + c1.second) > -EPS;
}

bool inCircle(const Circle& c, const P& p){
	return c.second - abs(c.first-p) > -EPS;
}

bool crossCircle(const Circle& c1, const Circle& c2){
	auto r1 = c1.second;
	auto r2 = c2.second;
	auto d = abs(c1.first-c2.first);
	if(d < r1 || d < r2) return d - abs(r1 - r2) > EPS;
	return r1 + r2 - d > -EPS;
}

vector<P> crossPoint(const Circle& c1, const Circle& c2){
    if(!crossCircle(c1, c2)) return vector<P>();
	auto r1 = c1.second;
	auto r2 = c2.second;
	auto r3 = abs(c1.first - c2.first);
	auto rc = (r3*r3 + r1*r1 - r2*r2) / (2*r3);
	auto rs = sqrt(r1*r1 - rc*rc);
	P dif = (c2.first-c1.first)/r3;
    vector<P> res;
    res.emplace_back(c1.first + dif * P(rc,rs));
    res.emplace_back(c1.first + dif * P(rc,-rs));
	return res;
}

int main(){
    int N, K;
    while(cin >> N >> K){
        vector<P> vp;
        vector<int> c(N);
        for(int i=0;i<N;i++){
            int x, y;
            cin >> x >> y >> c[i];
            vp.emplace_back(x, y);
        }
        double L = 0.0, R = 1000000.0;
        for(int _=0;_<200;_++){
            double mid = 0.5*(L+R);
            vector<Circle> vc;
            for(int i=0;i<N;i++) vc.emplace_back(vp[i], mid/c[i]);
            int mcnt = 0;
            for(int i=0;i<N;i++){
                vector<P> check;
                check.push_back(vp[i]);
                for(int j=i+1;j<N;j++){
                    auto cp = crossPoint(vc[i], vc[j]);
                    copy(cp.begin(), cp.end(), back_inserter(check));
                }
                for(auto& cr : check){
                    int cnt = 0;
                    for(int k=0;k<N;k++){
                        if(inCircle(vc[k], cr)) ++cnt;
                    }
                    mcnt = max(mcnt, cnt);
                }
            }
            if(mcnt >= K) R = mid;
            else L = mid;
        }
        printf("%.8lf\n", 0.5*(L+R));
    }
}

Measured memory_bytes: 256
//Robs Code
/***********HEADER***************/
#include<bits/stdc++.h>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1000000007
#define mxval 1e9 + 7
#define grt [](auto x,auto y){return x>y;}
#define pii pair<int,int>
/*********VARIABLE****************/
using namespace std;
int i,j,n,m,k,l,q,t,a,b,sum[3],tot[3],cnt[3];
/*********FUNCTIONS**************/
int powom(int a,int b) {
    int result = 1;
    while (b > 0) {
        if (b & 1)
            result = result * a;
        a = a * a;
        b >>= 1;
    }
    return result;
}
int powwm(int a, int b) {
    a %= mxsz;
    int result = 1;
    while (b > 0) {
        if (b & 1)
            result = result * a % mxsz;
        a = a * a % mxsz;
        b >>= 1;
    }
    return result;
}
int mod(int a){
    return a%mxsz;
}
int sub(int a,int b){
    return ((a%mxsz)-(b%mxsz)+mxsz)%mxsz;
}
int mul(int a,int b){
    return ((a%mxsz)*(b%mxsz))%mxsz;
}
int add(int a,int b){
    return ((a%mxsz)+(b%mxsz))%mxsz;
}
int div(int a,int b){
    return ((a%mxsz)*(powwm(b,mxsz-b)%mxsz))%mxsz;
}
/***********MAIN**************/
void solve(){
    int h,w;
    cin>>h>>w;
    string s[h];
    for(i=0;i<h;i++){
        cin>>s[i];
    }
    vector<int> v1[h],v2[w];
    int up[h][w],down[h][w],left[h][w],right[h][w];
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(i==0){
                up[i][j] = (s[i][j]=='.');
            }else{
                up[i][j] = (up[i-1][j]+1)*(s[i][j]=='.');
            }
            if(j==0){
                left[i][j] = (s[i][j]=='.');
            }else{
                left[i][j] = (left[i][j-1]+1) * (s[i][j]=='.');
            }
        }
    }
    for(i=h-1;i>=0;i--){
        for(j=w-1;j>=0;j--){
            if(i==h-1){
                down[i][j] = (s[i][j]=='.');
            }else{
                down[i][j] = (down[i+1][j]+1)*(s[i][j]=='.');
            }
            if(j==w-1){
                right[i][j] = (s[i][j]=='.');
            }else{
                right[i][j] = (right[i][j+1]+1) * (s[i][j]=='.');
            }
        }
    }
    int ans = -1;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(s[i][j]=='.'){
                ans = max(ans,up[i][j]+left[i][j]+right[i][j]+down[i][j]-3);
            }
        }
    }
    cout<<ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int t = 1;
    // cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
//.........

Measured memory_bytes: 129664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> get(char i) {
    vector<int> a(26, 0);
    a[i - 'a'] = 1;
    return a;
}

vector<int> add(vector<int> i, vector<int> j) {
    vector<int> k(26, 0);
    for (int l = 0; l < 26; l++) {
        k[l] = i[l] + j[l];
    }
    return k;
}
vector<int> sub(vector<int> i, vector<int> j) {
    vector<int> k(26, 0);
    for (int l = 0; l < 26; l++) {
        k[l] = i[l] - j[l];
    }
    return k;
}
int n;
vector<vector<int>> bit(5000001, vector<int>(26, 0));

void ko(int i, vector<int> j) {
    while (i <= n) {
        bit[i] = add(bit[i], j);
        i += i & (-i);
    }
}
vector<int> su(int i) {
    vector<int> s(26, 0);
    while (i > 0) {
        s = add(s, bit[i]);
        i -= i & (-i);
    }
    return s;
}

int main() {
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;

    vector<vector<int>> a(n, vector<int>(26, 0));
    for (int i = 0; i < n; i++) {
        ko(i + 1, get(s[i]));
        a[i] = get(s[i]);
    }

    for (int p = 0; p < q; p++) {
        int kind;
        cin >> kind;
        if (kind == 1) {
            int i;
            char j;
            cin >> i >> j;
            ko(i, sub(get(j), a[i - 1]));
            a[i - 1] = get(j);
        } else {
            int i, j;
            cin >> i >> j;
            auto b = sub(su(j), su(i - 1));
            int k = 0;
            for (int r = 0; r < 26; r++) {
                if (b[r] != 0) {
                    k += 1;
                }
            }
            cout << k << endl;
        }
    }
}

Measured memory_bytes: 731268
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
// const long long mod=1000000007;
// const long long inf=mod*mod;
// const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
long long mod;

const int mat_N=5;
const int mat_M=5;
// long long, including mod calculation
struct mat{
	long long a[mat_N][mat_M];
	mat(){for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)a[i][j]=0;}
	mat(int s){for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)a[i][j]=(i==j)*s;}
	mat operator+(const mat &m)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]+m.a[i][j];
		return ret;
	}
	mat operator-(const mat &m)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]+m.a[i][j];
		return ret;
	}
	mat operator-()const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=-a[i][j];
		return ret;
	}
	mat operator*(const long long &k)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]*k%mod;
		return ret;
	}
	// assuming mat_N = mat_M
	// by changing here, you can use for graph problems (ex. a[i][j]=min(a[i][k]+a[k][j]))
	mat operator*(const mat &m)const{
		mat ret;
		for(int k=0;k<mat_N;k++)for(int i=0;i<mat_N;i++)for(int j=0;j<mat_N;j++){
			ret.a[i][j]=(ret.a[i][j]+a[i][k]*m.a[k][j])%mod;
		}
		return ret;
	}
};
mat I=mat(1);
mat pw(mat a,long long t){
	mat ret=I;
	while(t){
		if(t&1){
			ret=ret*a;
		}
		t/=2;
		a=a*a;
	}
	return ret;
}
long long pw(long long a,long long b){
	long long ret=1;
	a%=mod;
	while(b){
		if(b%2)ret=ret*a%mod;
		b/=2;a=a*a%mod;
	}
	return ret;
}
long long p10[19];
long long calc(long long a,long long b){
	if(b<=0)return 0;
	mat m;
	m.a[0][0]=1;
	m.a[1][0]=1;
	m.a[1][1]=a%mod;
	m.a[2][2]=1;
	m.a[2][1]=1;
	m=pw(m,b);
	long long ret=(m.a[2][1]+m.a[2][0])%mod;
//	printf("%lld\n",ret);
	return ret;
}
int main(){
	long long c,a,b;
	scanf("%lld%lld%lld%lld",&c,&a,&b,&mod);
	long long ret=0;
	long long kt=1;
	p10[0]=1;
	for(int i=1;i<19;i++)p10[i]=p10[i-1]*10;
	for(int i=18;i>=1;i--){
		if(p10[i]<=a)continue;
		long long L=(p10[i-1]-1-a+b)/b;
		long long R=(p10[i]-1-a)/b;
		if(R>=c)R=c-1;
		if(L<0)L=0;
		if(R<L)continue;
	//	printf("%lld %lld\n",L,R);
		long long tmp=0;
		tmp=(tmp+calc(p10[i],R-L+1)*((a+L*b)%mod))%mod;
		tmp=(tmp+mod-calc(p10[i],R-L)*((mod+a+L*b-b)%mod)%mod)%mod;		
		ret=(ret+tmp*kt)%mod;
		for(int j=0;j<i;j++)kt=kt*pw(10,(R-L+1))%mod;
	}
	ret%=mod;
	printf("%lld\n",ret);
}

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

int val[10];

void rec(int now, int vmax, int to) {
  if(now == to) {
    for(int i = 0;i < now;++i){
      printf("%c", 'a' + val[i]);
    }
    printf("\n");
    return;
  }
  for(int i = 0;i <= vmax;++i){
    val[now] = i;
    rec(now+1, vmax, to);
  }
  val[now] = vmax + 1;
  rec(now+1, vmax+1, to);
}

int main(void){
  int n;
  scanf("%d", &n);
  val[0] = 0;
  rec(1,0,n);
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <math.h>
#include <set>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const double PI = 3.1415926535897932384626433;

///////////////////////////
////Prime Creator//////////
///////////////////////////
//bool Prime[100001] = {};
//void createPrime() {
//	ll n = 100001;
//	rep(i, 0, n) Prime[i] = true;
//	Prime[0] = false;
//	Prime[1] = false;
//	rep(i, 2, n) {
//		if (Prime[i]) {
//			rep(j, 2, n) {
//				if (j*i >= n)break;
//				Prime[j*i] = false;
//			}
//		}
//	}
//}
///////////////////////////
///////////////////////////

///////////////////////////
////Warshal Floyid/////////
///////////////////////////
////initialize`
////rep(i, 0, N)rep(j, 0, N) wf[i][j] = 1 << 29;
//static const ll WF_MAX = 300;
//ll wf[WF_MAX][WF_MAX];
//void WarshalFloyid(int size) {
//	rep(k, 0, size)rep(i, 0, size)rep(j, 0, size)wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
//}

ll x[100001] = {};
ll y[100001] = {};
int main() {
	ll n, m; cin >> n >> m;
	repe(i, 1, n)cin >> x[i];
	repe(i, 1, m)cin >> y[i];
	//sort(x + 1, x + n);
	//sort(y + 1, y + n);
	ll MOD = 1000000007;
	ll X = 0;
	repe(k, 1, n) {
		X = (X + (2 * k - n - 1)*x[k]) % MOD;
	}
	ll Y = 0;
	repe(k, 1, m) {
		Y = (Y + (2 * k - m - 1)*y[k]) % MOD;
	}

	cout << (X * Y) % MOD << endl;
	return 0;
}

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

int main() {
	long long n,i,j,k,y,cur,ans,res;
	
	string s;
	cin >> s;
	
	for(i=0; i<(1<<3); i++){
		cur=s[0]-'0'; res=0;
		for(j=0; j<3; j++){
			res=s[j+1]-'0';
			if((1<<j)&i){
				cur+=res;
			}else{
				cur-=res;
			}
			
		}
		if(cur==7){
			cout << s[0];
			if((1<<0)&i){
				cout << '+';
			}else{
				cout << '-';
			}
			cout << s[1];
			if((1<<1)&i){
				cout << '+';
			}else{
				cout << '-';
			}
			cout << s[2];
			if((1<<2)&i){
				cout << '+';
			}else{
				cout << '-';
			}
			cout << s[3] << "=7" << endl; return 0;
		}
	}


}

Measured memory_bytes: 256
//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        System.out.println(k / 2 * ((k + 1) / 2));
    }
}

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

long long int n;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	if (n%10==0) cout<<"pon";
	if (n%10==1) cout<<"pon";
	if (n%10==2) cout<<"hon";
	if (n%10==3) cout<<"bon";
	if (n%10==4) cout<<"hon";
	if (n%10==5) cout<<"hon";
	if (n%10==6) cout<<"pon";
	if (n%10==7) cout<<"hon";
	if (n%10==8) cout<<"pon";
	if (n%10==9) cout<<"hon";
}


Measured memory_bytes: 3620
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int n = nextInt();
		int a = nextInt();
		int b = nextInt();

		out.println(n * a > b ? b : n * a);
	}

	private void solveB() {
		int n = nextInt();
		int d = nextInt();
		int[][] wk = Stream.generate(() -> IntStream.range(0, d).map(i -> nextInt()).toArray()).limit(n)
				.toArray(int[][]::new);

		int res = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				long tmp = 0;
				for (int k = 0; k < d; k++) {
					tmp += Math.pow(wk[i][k] - wk[j][k], 2);
				}
				long tmpRes = (long) Math.sqrt(tmp);
				if (Math.pow(tmpRes, 2) == tmp) {
					res++;
				}
			}
		}

		out.println(res);
	}

	private void solveC() {
		int n = nextInt();

		out.println("");
	}

	private void solveD() {
		int n = nextInt();

		out.println("");
	}

	private void solveE() {
		int n = nextInt();

		out.println("");
	}

	private void solveF() {
		int n = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 27860
import java.util.Scanner;

public class Main {
	static long cnt = 0; // 反転数
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(); // 要素の個数
		int[] num = new int[n]; // 個数のリスト

		for (int i = 0; i < n; i++) {
			num[i] = scan.nextInt();
		}
		mergeSort(num,0,n);
		System.out.println(cnt);
	}


	
	/**
	 * 比較してソートする
	 * @param A	ソートするリスト
	 * @param left	ソート対象の一番左側のリスト番号
	 * @param mid	分割地点
	 * @param right	ソート対象の一番右側のリスト番号
	 */
	public static void merge(int[] A,int left,int mid,int right){
		int n1 = mid -left;
		int n2 = right -mid;
		int[] L =new int[n1+1];
		int[] R =new int[n2+1];
		L[n1] = Integer.MAX_VALUE;//∞
		R[n2] = Integer.MAX_VALUE;//∞
		for(int i = 0;i<n1;i++){

			L[i] = A[left+i];
		}
		for(int i = 0;i<n2;i++){	  
			R[i] = A[mid+i];
		}

		int i = 0;
		int j = 0;
		for(int k = left; k<right;k++ ){
			
			if(L[i] <= R[j]){
				A[k] = L[i];
				i = i+1;
			}else{
				if (i < n1) {
                    cnt += n1 - i;
                }

				A[k] = R[j];
				j = j+1;
			}

		}


	}
	/**
	 *  マージソート
	 * @param A	ソートするリスト
	 * @param left　ソート対象の一番左側のリスト番号
	 * @param right　ソート対象の一番右側のリスト番号
	 * @return
	 */
	private static  void  mergeSort(int[] A, int left, int right){
		if(left +1 < right){

			int mid = (left + right) /2;
			mergeSort(A,left,mid);
			mergeSort(A,mid , right);
			merge(A,left,mid,right);
		}
	}
}



Measured memory_bytes: 100284
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

pair<ll,ll> calc(const vi &a, const vector<ll> &s, int n, ll lb){
	ll sum = 0, cnt = 0;
	for(int i = n - 1, j = 0; i >= 0; i--){
		while(j < n && a[j] + a[i] < lb) j++;
		cnt += n - j;
		sum += s[n] - s[j] + (ll)(n - j) * a[i];
	}
	return pair<ll,ll>(cnt, sum);
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; ll m; cin >> n >> m;
	vi a(n); rep(i, n) cin >> a[i];
	sort(all(a));
	vector<ll> s(n + 1);
	rep(i, n) s[i + 1] = s[i] + a[i];
	
	ll lo = 0, hi = 2 * a[n - 1] + 1, mid;
	while(lo + 1 < hi){
		mid = (lo + hi) / 2;
		auto r = calc(a, s, n, mid);
		if(r.first >= m) lo = mid;
		else hi = mid;
	}
	auto r = calc(a, s, n, hi), r2 = calc(a, s, n, lo);
	ll d = (r2.second - r.second) / (r2.first - r.first);
	ll ans = r.second + (m - r.first) * d;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
import sys

s = list(raw_input())
if len(s) == 1:
	print str(int(''.join(s)))
	sys.exit()

sequence = [x for x in range(2**( len(s) -1 ))]

total = 0
def get_binary(seq):
	r = ''
	while seq > 0:
		r = r + str(seq % 2)
		seq = seq / 2
	if (len(list(r)) < (len(s) - 1)):
		for _ in range(len(s) - 1 - len(list(r))):
			r = r + '0'
	return list(r)

for seq in sequence:
	subtotal = 0
	index = 1
	num = s[0]
	b = get_binary(seq)
	for x in b:
		if x == '0':
			num = num + s[index]
		else:
			subtotal = subtotal + int(num)
			num = s[index]
		index = index + 1
	total = total + subtotal + int(num)

print str(total)


Measured memory_bytes: 2696
N, M = [int(x) for x in input().split()]

L = [None] * M

for i in range(M):
    a, b = [int(x) for x in input().split()]
    L[i] = (a, b)

set1 = set()
set2 = set()

for l in L:
    a, b = l[0], l[1]
    if a == 1:
        set1.add(b)
    if b == N:
        set2.add(a)

if set1.isdisjoint(set2):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")



Measured memory_bytes: 37008
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n - 2):
  if (p[i] < p[i + 1] and p[i + 1] < p[i + 2]) or (p[i] > p[i + 1] and p[i + 1] > p[i + 2]):
    ans += 1
print(ans)

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

int main() {
  int x,y;
  cin >> x >> y;
  if(x*2<=y&&x*4>=y&&y%2==0)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3572