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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y)      REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z)   REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
#define ncinp(n, p)         REP(i, 0, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }
#define ncin1_1(n, x)       REPE(i, 1, n) { cin1(x[i]); }
#define ncin2_1(n, x, y)    REPE(i, 1, n) { cin2(x[i], y[i]); }
#define ncin3_1(n, x, y, z) REPE(i, 1, n) { cin3(x[i], y[i], z[i]); }
#define ncinp_1(n, p)       REPE(i, 1, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

int main() {
    lli n;
    cin1(n);
    string s;
    cin1(s);

    lli ans = 0;
    lli x_start = 0;
    REPE(x_end,1,n-2) {
        lli y_start = x_end+1;
        lli y_end = n-1;

        map<char, bool> x_exist;
        map<char, bool> y_exist;
        lli cur_ans = 0;
        REPE(i,x_start,x_end) {
            x_exist[s[i]] = true;
        }
        REPE(i, y_start, y_end) {
            y_exist[s[i]] = true;
        }
        REPIT(it, x_exist) {
            if (y_exist.find((*it).first) != y_exist.end())
                cur_ans++;
        }
        ans = max(ans, cur_ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  var data = chunk.replace( '\n', '' ).split( ' ' ).map( Number );
  var d = data[0]/data[1];
  var r = data[0]%data[1];
  console.log( '%d %d', Math.floor( d ), r, d.toFixed( 6 ) );

});

Measured memory_bytes: 7904
x = input()
y = x.split(" ")
y = [int(z) for z in y]
w = y[0]
h = y[1]
x = y[2]
r = y[4]
y = y[3]
if (x <= w-r and x >= r) and (y <= h-r and y >= r):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 7736
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

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

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

	ll ans = 0;
	ans += n / (a + b)*a;
	
	ll c = n % (a + b);
	if (c <= a) {
		ans += c;
	}
	else {
		ans += a;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>

int main() {
    long N;
    long pair = 0;
    scanf("%ld", &N);
    long* a = malloc(sizeof(long)*N);
    bool* likedPair = malloc(sizeof(bool)*N);
    for (long i=0;i<N;i++) {
        scanf("%ld", &a[i]);
        likedPair[i] = false;
    }
    for (long i=0;i<N;i++) {
        if (likedPair[i]) {
            continue;
        }
        long target = a[i];
        if (a[target-1] == i+1) {
            likedPair[i] = true;
            likedPair[target-1] = true;
            pair++;
        }
    }
    printf("%ld\n", pair);
    
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	char* color = "RYBMGC";
	int n;
	while (scanf("%d", &n), n)
	{
		int ans = 0;

		set<int> used;
		while (n--)
		{
			int c[6];
			char buf[16];
			int fixed;
			for (int i = 0; i < 6; ++i)
			{
				scanf(" %s", buf);
				int j;
				for (j = 0; color[j] != *buf; ++j)
					;
				c[i] = j;
				if (j == 0)
					fixed = i;
			}
			int r[][4] = { 
				{ 1, 2, 4, 3 },
				{ 5, 2, 0, 3 },
				{ 0, 1, 5, 4 },
				{ 0, 4, 5, 1 },
				{ 0, 2, 5, 3 },
				{ 2, 1, 3, 4 }
			};
			int rota[4];
			for (int i = 0; i < 4; ++i)
				rota[i] = c[r[fixed][i]];

			bool u = false;
			for (int i = 0; i < 3; ++i)
			{
				int s = 0;
				for (int j = 0; j < 4; ++j)
					s = s*10 + rota[(i+j) % 4];
				if (used.count(s))
				{
					++ans;
					break;
				}
				else
					used.insert(s);
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}

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

namespace ConsoleApp62 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int x1 = st[0];
            int y1 = st[1];
            int x2 = st[2];
            int y2 = st[3];

            int plusVecX = x2 - x1;
            int plusVecy = y2 - y1;

            int plusVecRotX;
            int plusVecRotY;

            plusVecRotX = 0 * plusVecX - plusVecy;
            plusVecRotY = 1 * plusVecX + 0 * plusVecy;

            int x3 = x2 + plusVecRotX;
            int y3 = y2 + plusVecRotY;

            plusVecX = x3 - x2;
            plusVecy = y3 - y2;

            plusVecRotX = 0 * plusVecX - plusVecy;
            plusVecRotY = 1 * plusVecX + 0 * plusVecy;

            int x4 = x3 + plusVecRotX;
            int y4 = y3 + plusVecRotY;

            Console.WriteLine(x3 + " " + y3 + " " + x4 + " " + y4);


        }
    }
}


Measured memory_bytes: 13396
import copy
N = int(input())

lst = list(map(int, input().split()))

sorted_lst = sorted(lst)
idx = (N-1) // 2
low = sorted_lst[idx]
high = sorted_lst[idx+1]
for i in range(N):
  if lst[i] <= low:
    print(high)
  else:
    print(low)


Measured memory_bytes: 25660
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;

class UnionFind{
public:
	vector<ll> par;
	vector<ll> d;
	//0-indexed
	void init(ll n = 1) {
		par.resize(n);
		d.resize(n,0);
		for (ll i = 0; i < n; ++i) par[i] = i;
	}
	ll len1(ll x){
		if(par[x]==x)return 0;
		ll ans = d[x];
		ans += len1(par[x]);
		return ans;
	}
	ll root(ll x = 1){
		if(par[x]==x)return x;
		else{
			d[x] = len1(par[x]) + d[x];
			return par[x] = root(par[x]);
		}
	}
	ll length(ll x,ll y){
		return len1(y) - len1(x);
	}

	void unite(ll x,ll y,ll dd){
		while(par[x]!=x){dd+=d[x];x=par[x];}
		while(par[y]!=y){dd-=d[y];y=par[y];}
		if(par[x]==par[y])return;
		if(dd>=0){
			d[y] = dd;
			par[y] = x;
		}else{
			d[x] = -dd;
			par[x] = y;			
		}
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	//ifstream in("input.txt");
	//cin.rdbuf(in.rdbuf());
	ll n,m;
	cin >> n >> m;
	UnionFind uf;
	uf.init(n+1);
	ll l,r,d;
	FOR(i,0,m){
		cin >> l >> r >> d;
		uf.len1(l);uf.len1(r);
		if(uf.root(l)==uf.root(r)){
			if(uf.length(l,r)!=d){
				cout << "No" << endl;
				return 0;
			}
		}else{
			uf.unite(l,r,d);
			//cout << uf.length(l,r) << endl;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 1792
N = int(input())

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

count = 0
i = 0
j = 0

while i == 0:
    for a in A:
        if a % 2 == 1:
            i = 1
            break
        else:
            a = a / 2
            A[j] = a
            j += 1
    j = 0
    if i == 0:
        count += 1

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int main() {
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll all=0;
	if(k<a){
		all+=k;
	}else{
		all+=a;
		k-=a;
	}
	if(k>0){
		k-=b;
	} 
	if(k>0){
		all-=k;
	}
	cout<<all;
} 

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

int main() {int A,B; 
cin>>A>>B;
int sum=0;

  for (int i = A; i <=B; i++){
    
if(i/10000==i%10&&i/1000%10==i%100/10){sum++;
}
     else{sum+=0;
}
}

cout <<sum << endl;

}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct P
{
	int l, m, r;
	P() :l(0), m(0), r(0) {}
};

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

	int H, W, K;
	cin >> H >> W >> K;
	int dp[110][8] = { 0 };
	dp[0][0] = 1;

	rep(i, 0, H)
	{
		rep(j, 0, W)
		{
			rep(bit, 0, 1 << (W - 1))
			{
				bool ok = true;
				rep(k, 0, W - 2)
				{
					if ((bit&(1 << k)) && bit&(1 << (k + 1)))
					{
						ok = false;
						break;
					}
				}
				if (!ok)continue;

				if (j == W - 1)
				{
					if ((bit&(1 << (W - 2))))
					{
						dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - 1]) % MOD;
					}
					else
					{
						dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
					}
				}
				else
				{
					if ((bit&(1 << j)))
					{
						dp[i + 1][j] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;
					}
					else if (0 < j && (bit&(1 << (j - 1))))
					{
						dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - 1]) % MOD;
					}
					else
					{
						dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
					}
				}
			}
		}
	}

	cout << dp[H][K - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N, Y = LI()
y = 1000 * N
for i in range(N+1):
    for j in range(N-i+1):
        if i * 10000 + 5000 * j + 1000 * (N-i-j) == Y:
            print(i, j, N-i-j)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 40684
require 'set'

N = gets.to_i
V = Hash.new{|h, k| h[k] = []}
E = Hash.new
(N - 1).times{|i|
  a, b = gets.chomp.split(" ").map(&:to_i)
  E[i] = [a, b, 0]
  V[a] << E[i]
  V[b] << E[i]
}

def color(vi)
  v_e = V[vi].select{|v| v[2] == 0}
  return if v_e.size == 0
  col = @col_ar.dup
  v_out = V[vi].select{|v| v[2] != 0}.map{|v| v[2]}
  ret = true
  begin
    col_s = col.sample(v_e.size)
    ret = (col_s & v_out).empty?
    if ret then
      idx = -1
      ret = v_e.all?{|a, b, c|
        op = (b == vi ? a : b)
        idx += 1
        !V[op].select{|v| v[2] != 0}.map{|v| v[2]}.include?(col_s[idx])
      }
    end
  end until ret

  if ret then
    v_e.each_with_index{|e, idx|
      e[2] = col_s[idx]
    }
  end
end

col_max = 0
V.each{|k, v| col_max = v.size if col_max < v.size}
@col_ar = (1..col_max).to_a

done = Set.new
q = [V.max_by{|k, v| v.size}[0]]
done.add(q[0])
while(q.size > 0) do
  v = q.shift
  color(v)
  V[v].each{|e|
    if v == e[1] then
      (q << e[0]; done.add(e[0])) if !done.include?(e[0])
    else
      (q << e[1]; done.add(e[1])) if !done.include?(e[1])
    end
  }
end

puts col_max
E.map{|k, v| puts v[2]}


Measured memory_bytes: 37432
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

pair<bool,int> isT(string eq,int i) {
  if(eq[i] == 'T' || eq[i] == 'F')
    return make_pair(eq[i] == 'T', i);
  else if(eq[i] == '-')  {
    auto res = isT(eq,i+1);
    return make_pair(!res.first, res.second);
  } else if(eq[i] == '(') {
    auto res1 = isT(eq,i+1);
    pair<bool,int> res2;
    switch(eq[res1.second+1]) {
      case '-':
        res2 = isT(eq,res1.second+3);
        return make_pair(!res1.first || res2.first, res2.second+1);
        break;
      case '*':
        res2 = isT(eq,res1.second+2);
        return make_pair(res1.first && res2.first, res2.second+1);
        break;
      case '+':
        res2 = isT(eq,res1.second+2);
        return make_pair(res1.first || res2.first, res2.second+1);
        break;
      case '=':
        res2 = isT(eq,res1.second+2);
        return make_pair(res1.first == res2.first, res2.second+1);
        break;
    }
  }
}

bool search(string eq) {
  vector<bool> isExist(11);
  for(char c : eq)
    if(c >= 'a' && c <= 'k')
      isExist[c-'a'] = true;
  int mx = -1;
  REP(i,11)
    if(isExist[i])
      mx = i;
  if(mx != -1) {
    char c = mx+'a';
    string cpT = eq;
    string cpF = eq;
    for(char& d : cpT)
      if(c == d)
        d = 'T';
    for(char& d : cpF)
      if(c == d)
        d = 'F';
    return search(cpT) && search(cpF);
  } else {
    return isT('('+eq+')',0).first;
  }
}

int main(void) {
  while(1) {
    string eq;
    cin>>eq;
    if(eq == "#")break;
    bool res = search(eq);
    if(res)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
  return 0;
}

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

#define ll long long
#define ld long double
#define ii pair<int ,int >
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);



int main(){
    SPEED
        int n;
        cin>>n;
        cout<<n*(n+1)/2;

}


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

using namespace std;

// n円引き出すには何回操作が必要か
int solve(int n) {
  static vector<int> memo(n + 1, -1);
  if (memo[n] < 0) {
    if (n == 0) {
      memo[n] = 0;
      return 0;
    }

    vector<int> nums {1};
    vector<int> bases{6, 9};
    for (auto base : bases) {
      int exp = base;
      while(n >= exp) {
        nums.push_back(exp);
        exp *= base;
      }
    }

    int min_op = -1;
    for (auto num : nums) {
      if (n < num) {
        continue;
      }

      int op = solve(n - num) + 1;
      if (min_op < 0 || min_op > op) {
        min_op = op;
      }
    }

    memo[n] = min_op;
  }

  return memo[n];
}

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;
  cout << solve(n) << "\n";
  // 1
  // 6^n
  // 9^n
  return 0;
}

Measured memory_bytes: 22272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

const int MAXN = 2e5 + 5;
int N;
int A[MAXN], B[MAXN];

int main() {
    FAST_IO();
    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    priority_queue<pii, vector<pii>, less<pii>> PQ;
    rep(i, N) {
        if(B[i] > A[i]) PQ.push({B[i] - A[i], i});
    }
    ll cnt = 0;
    while(!PQ.empty()) {
        int i = PQ.top().second; PQ.pop();
        if(B[i] - A[i] >= B[(i - 1 + N) % N] + B[(i + 1) % N]) {
            cnt += (B[i] - A[i]) / (B[(i - 1 + N) % N] + B[(i + 1) % N]);
            B[i] = (B[i] - A[i]) % (B[(i - 1 + N) % N] + B[(i + 1) % N]) + A[i];
            if(B[i] > A[i]) PQ.push({B[i] - A[i], i});
        } else {
            cout << "-1\n";
            return 0;
        }
    }
    cout << cnt << "\n";
}

Measured memory_bytes: 3956
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cstring>
using namespace std;
int w,a,num;
char b[15];
int main()
{
	scanf("%d %s",&a,b);
	num=a;
	for(int i=0;i<=strlen(b)-1;i++)num=b[i]-'0'+num*10;
	if(int(double(sqrt(num))*1000000)%1000000==0)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <tuple>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;


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

    vector<vector <int> > x(n,vector<int> (d));
    
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            cin >> x.at(i).at(j);
        }
    }

    int ans=0;
    for (int i = 0; i < n-1; i++)
    {   
        
        for (int j = i+1; j < n; j++)
        {   
            int in=0;
            for (int k = 0; k < d; k++)
            {
                in += (x.at(i).at(k) - x.at(j).at(k)) * (x.at(i).at(k) - x.at(j).at(k));
            }
            for (int k = 1; k <= sqrt(in); k++)
            {
                if (k*k==in)
                {
                    ans++;
                }
                
            }
            
            
        }
        
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string a,b;
  cin>>a>>b;
  int sum=0;
  for(int i=0;i<a.length();i++)
  {
if(a[i]!=b[i])
  sum++;
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3852
N = int(input())
S = [list(map(int, list(input()))) for _ in range(N)]
for i in range(N):
  for j in range(N):
    if i == j:
      continue
    if S[i][j] == 0:
      S[i][j] = float("inf")
for k in range(N):
  for i in range(N):
    for j in range(N):
      S[i][j] = min(S[i][j], S[i][k] + S[k][j])
#print(S)
"""
g = [[0] * N for _ in range(2 * N)]
ig = [0] * N
order = [i for i in range(N)]
order.sort(key = lambda x: -max(S[x]))
g[N][order[0]] = 1
ig[order[0]] = N
"""
color = [0] * N
def dfs(v, c):
  global color
  color[v] = c
  for i in range(N):
    if S[v][i] == 1:
      if color[i] == c:
        return False
      if color[i] == 0 and not (dfs(i, -c)):
        return False
  return True

if dfs(1, 1):
  res = 0
  for r in S:
    res = max(max(r), res)
  print(res + 1)
else:
  print(-1)

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

namespace ALDS1_9_C
{
    class Program
    {
        static void Main(string[] args)
        {
            PriorityQue priorityQue = new PriorityQue();

            while (true)
            {
                string[] tmpLine = Console.ReadLine()
                                          .Split(' ');

                if (tmpLine[0] == "insert")
                {
                    priorityQue.Insert(int.Parse(tmpLine[1]));
                }
                else if (tmpLine[0] == "extract")
                {
                    Console.WriteLine(priorityQue.Pop());
                }
                else
                {
                    break;
                }
            }
            //Console.ReadLine();
        }
    }

    class PriorityQue
    {
        private int[] heapNodes;
        private int maxIndex;

        public PriorityQue()
        {
            this.heapNodes = new int[2000000];
            this.maxIndex = -1;
        }

        public void Insert(int targetKey)
        {
            //配列サイズ + 1
            this.maxIndex++;
            this.heapNodes[this.maxIndex] = targetKey;
            this.UpHeapfy(this.maxIndex);
        }

        private void UpHeapfy(int targetIndex)
        {
            if (targetIndex == 0)
            {
                return;
            }

            int parentIndex = (int)((targetIndex + 1) / 2) - 1;

            if (this.heapNodes[targetIndex] > this.heapNodes[parentIndex])
            {
                int tmp = this.heapNodes[targetIndex];
                this.heapNodes[targetIndex] = this.heapNodes[parentIndex];
                this.heapNodes[parentIndex] = tmp;
                this.UpHeapfy(parentIndex);
            }
        }

        public int Pop()
        {
            int returnKey = this.heapNodes[0];
            this.heapNodes[0] = this.heapNodes[this.maxIndex];
            this.maxIndex--;
            this.DownHeapfy(0);
            return returnKey;
        }

        private void DownHeapfy(int targetIndex)
        {
            int maxKeyIndex = targetIndex;
            int leftIndex = (targetIndex + 1) * 2 - 1;
            if (leftIndex <= this.maxIndex && this.heapNodes[leftIndex] > this.heapNodes[maxKeyIndex])
            {
                maxKeyIndex = leftIndex;
            }
            int rightIndex = (targetIndex + 1) * 2;
            if (rightIndex <= this.maxIndex && this.heapNodes[rightIndex] > this.heapNodes[maxKeyIndex])
            {
                maxKeyIndex = rightIndex;
            }
            if (maxKeyIndex != targetIndex)
            {
                int tmpKey = this.heapNodes[targetIndex];
                this.heapNodes[targetIndex] = this.heapNodes[maxKeyIndex];
                this.heapNodes[maxKeyIndex] = tmpKey;
                this.DownHeapfy(maxKeyIndex);
            }
        }

    }
}




Measured memory_bytes: 22844
N=int(input())
ans=[]
if N%2==0:
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i+j==N+1:
                continue
            ans.append([i,j])
else:
    for i in range(1,N):
        for j in range(i+1,N):
            if i+j==N:
                continue
            ans.append([i,j])
    for i in range(1,N):
        ans.append([i,N])
print(len(ans))
for u in ans:
    print(*u)

Measured memory_bytes: 4124
macro_rules! input {
    ($x:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        $x = buf.trim().parse().unwrap();
    };

    ($x:expr, $($y:expr), +) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        input_iter!(buf.split_whitespace(), $x, $($y), +);
    };

    ($v:expr; $size:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        for v in buf.split_whitespace() {
            $v.push(v.parse().unwrap());
        }
    };

    ($v:expr; $h_size:expr, $w_size:expr) => {
        for _ in 0..$h_size {
            let mut part_vec = Vec::new();
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).ok();
            for v in buf.split_whitespace() {
                part_vec.push(v.parse().unwrap());
            }
            $v.push(part_vec);
        }
    };
}

#[allow(unused_macros)]
macro_rules! input_iter {
    ($iter:expr, $x:expr) => {
        $x = $iter.next().unwrap().parse().unwrap();
    };

    ($iter:expr, $x:expr, $($y:expr), +) => {
        let mut iter = $iter;
        $x = iter.next().unwrap().parse().unwrap();
        input_iter!(iter, $($y), *);
    };
}

fn main() {
    let n: usize;
    let a: usize;
    let b: usize;
    let c: usize;
    let d: usize;
    let e: usize;
    input!(n);
    input!(a);
    input!(b);
    input!(c);
    input!(d);
    input!(e);
    let v = vec![a, b, c, d, e];
    let mut min = a;
    for i in 1..5 {
        min = std::cmp::min(min, v[i]);
    }
    println!("{}", (n + min - 1)/min + 4);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <tuple>
using namespace std;
typedef pair<int,int> P;
int V[100][100];//[v][i] leads to
int isDark[100];//-1???????????????.0~M-1??§??????
const int INF = 100000;
int D[16];
int N,M,K;

int dist[1<<16];
int move_to[1<<16][100];
bool isvisit[1<<16];

int main(){
    cin>>N>>M>>K;
    fill(isDark,isDark+100,-1);
    fill(dist,dist+(1<<16),INF);
    fill(isvisit,isvisit+(1<<16),false);
    for(int i=0;i<M;i++){
        cin>>D[i];
        D[i]--;
        isDark[D[i]]=i;
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<K;j++){
            cin>>V[i][j];
            V[i][j]--;
        }
    }
    for(int b=0;b<(1<<M);b++){
        for(int k=0;k<K;k++){
            move_to[b][k]=0;
            for(int m=0;m<M;m++){
                if(b&(1<<m)){
                    int to = V[D[m]][k];
                    if(isDark[to]!=-1){
                        move_to[b][k]|=1<<isDark[to];
                    }
                }
            }
        }
    }
    deque<P> que;
    dist[(1<<M)-1]=0;
    que.emplace_back(0,(1<<M)-1);
    while(!que.empty()){
        int d,v;
        tie(d,v)= que.front(); que.pop_front();
        if(!v){
            cout<<d<<endl;
            return 0;
        }
        if(isvisit[v]) continue;
        isvisit[v]=true;
        for(int k=0;k<K;k++){
            int to = move_to[v][k];
            if(dist[to]>d+1){
                que.emplace_back(d+1,to);
                dist[to]=d+1;
            }
        }
    }

    return 0;
}

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

const std::vector<int> ms{500, 100, 50, 10, 5, 1};

bool solve() {
    int n;
    std::cin >> n;
    if (n == 0) return false;

    n = 1000 - n;
    int ans = 0;
    for (auto m : ms) {
        ans += n / m;
        n %= m;
    }

    std::cout << ans << "\n";

    return true;
}

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

    while (solve()) {}

    return 0;
}



Measured memory_bytes: 3080
# Author: cr4zjh0bp
# Created: Sat Mar  7 12:01:50 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
 
from math import ceil
 
N, A, B = na()
C = N % (A + B)
if C == N:
    print(min(A, N))
else:
    print(A * (N // (A + B)) + (C if C <= A else A))

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

double amax,amin,pp=0,p,t,k;

void ppsum(vector<bool> v){
    double tmp=1;
    for(int i=0;i<v.size();i++){
        if(v[i])tmp*=(1-p);
        else tmp*=p;
    }
    pp+=tmp;
}

void night(double r,double l,vector<bool> v){
    double h=(l+r)/2;
    if(v.size()==k||v.size()>23){
        if(h>=amin&&h<=amax){
            ppsum(v);
        }
        return;
    }
    if(l<amin||r>amax)return;
    else{
        v.push_back(true);
        (h>=t)?night(r,h,v):night(h,l,v);
        v[v.size()-1]=false;
        (h>=t)?night(h,l,v):night(r,h,v);
    }
}

void solve(int _k,int r,int l,double _p,double e,double _t){
    p=_p;
    k=_k;
    t=_t;
    amin=t-e;
    amax=t+e;
    vector<bool> v;
    night((double)r,(double)l,v);
    printf("%.13lf",pp);

    
}

int main (){
    int a,b,c;
    double d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    solve(a,b,c,d,e,f);
}

Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define CHAL_BC_APNE_BAAP_KO_MAT_SIKHA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fr first
#define se second
signed main()
{
	CHAL_BC_APNE_BAAP_KO_MAT_SIKHA;		

	int n,d;
	cin>>n>>d;
	vector<vector<int> > v;
	for(int i=1;i<=n;i++){
		vector<int> vec;
		for(int j=1;j<=d;j++){
			int tmp;
			cin>>tmp;
			vec.pb(tmp);
		}
		v.pb(vec);
	}
	int cnt=0;
	for(int i=0;i<v.size();i++){
		for(int j=i+1;j<v.size();j++){
			int sum=0;
			for(int k=0;k<d;k++){
				sum+=pow(abs(v[i][k]-v[j][k]),2);
			}
			int u=sqrt(sum);
			int y=ceil(1.0*sqrt(sum));
			if(u==y){
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    H, N = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    A.reverse()
    for a in A:
        H -= a

    if H>0:
        print("No")
    else:
        print("Yes")

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll h, w, a, b;
ll ans;
ll kai[200001];

ll mod_pow (ll x, ll y) {
    ll ret = 1;
    while (y) {
        if (y&1) ret = ret*x%MOD;
        x = x*x%MOD;
        y /= 2;
    }
    return ret;
}

ll conb (ll x, ll y) {
    ll z = x-y;
    ll ret = kai[x]*mod_pow(kai[y],MOD-2)%MOD;
    ret = ret*mod_pow(kai[z],MOD-2)%MOD;
    return ret;
}

int main(){
    kai[0] = 1;
    for (ll i = 1; i <= 200000; i++) kai[i] = kai[i-1]*i%MOD;
    cin >> h >> w >> a >> b;
    ll ai = h-a-1, bi = b;
    while (true) {
        if (ai < 0 || bi >= w) break;
        ans = (ans + conb(ai+bi, ai)*conb(h+w-2-ai-bi, h-1-ai))%MOD;
        ai--; bi++;
    }
    cout << ans << endl;
}
































Measured memory_bytes: 1792
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: u64,
        mut p: u64,
    }
    let mut f = std::collections::BTreeMap::new();
    for i in 2.. {
        if i * i > p {
            if p != 1 {
                f.insert(p, 1);
            }
            break;
        }
        let mut c = 0;
        while p % i == 0 {
            p /= i;
            c += 1;
        }
        if c != 0 {
            f.insert(i, c);
        }
    }
    // println!("{:?}", f);
    let mut res = 1;
    for (p, c) in f {
        res *= p.pow((c / n) as u32);
    }
    println!("{}", res);
}


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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (i == n - 1) {
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 210
ll d[MAX_V][MAX_V];
int V;
void warshall_floyd() {
	rep(k, 0, V) rep(i, 0, V) rep(j, 0, V) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

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

	int M, R;
	cin >> V >> M >> R;

	vector<int> r(R);
	rep(i, 0, R) {
		cin >> r[i];
		r[i]--;
	}

	vsort(r);

	rep(i, 0, V) rep(j, 0, V) d[i][j] = INF;

	rep(i, 0, M) {
		int a, b, c;
		cin >> a >> b >> c;
		d[--a][--b] = c;
		d[b][a] = c;
	}

	warshall_floyd();

	ll rsl = 1e18;
	do {
		ll tmp = 0;
		rep(i, 0, R - 1) {
			if(d[r[i]][r[i + 1]] != INF) {
				tmp += d[r[i]][r[i + 1]];
			}
		}
		rsl = min(tmp, rsl);

	} while(next_permutation(r.begin(), r.end()));
	
	cout << rsl << endl;


}


Measured memory_bytes: 640
num = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}

while True:
    try:
        S = input()
    except EOFError:
        break
    ans = 0
    for i in range(0,len(S) - 1):
        if num [S [i]] < num [S [i + 1]]:
            ans -= num [S [i]]
        else:
            ans += num [S [i]]
    ans += num [S [-1]]
    print(ans)

Measured memory_bytes: 7436
S = input()

if S[0] == "A":
    A = True
else:
    A = False

countC = 0
for i in range(2,len(S)-1):
    if S[i] == "C":
        countC += 1
        place = i
        
if countC == 1:
    C = True
else:
    C = False
    


'''
if C:
    for i in range(1,place):
        lower = S[i].islower()
        if lower == False:
            B = False
    for i in range(place+1,len(S)):
        lower = S[i].islower()
        if (lower):
            B = False
'''

B = False

new = ""
if C:
    for i in range(1,place):
        new = new + S[i]
    for i in range(place+1,len(S)):
        new = new + S[i]

    if new.islower():
        B = True
    else:
        B = False

            
if (A and B and C):
    print("AC")
else:
    print("WA")


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

int main(){
    int n,m; cin >>n>>m;

    vector<int> x(m);
    for(int i=0;i<m;i++) cin >> x.at(i);

    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    sort(x.begin(),x.end());
    vector<int> dis(m-1);
    for(int i=0;i<m-1;i++) dis.at(i)=x.at(i+1)-x.at(i);

    sort(dis.begin(),dis.end());
    int res=accumulate(dis.begin(),dis.end()-n+1,0);

    cout << res << endl;
}

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

int main(void) {
    int n;
    cin >> n;
    vector<pair<pair<string, int>, int>> v;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        int p;
        cin >> p;
        p = -p;
        v.push_back(make_pair(make_pair(s, p), i));
    }
    sort(v.begin(), v.end());
    for (auto &&i : v) {
        cout << i.second << endl;
    }

    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

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

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

bool cmp(pii a,pii b){
	return a.S<b.S;
}

int find(vector<int> &dp,int t){
	int hi=sz(dp)-1,lo=-1;
	while(hi-lo>1){
		int m=(hi+lo)/2;
		if(dp[m]<=t) lo=m;
		else hi=m;
	}
	return hi;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s; cin>>s;
	int cnt=0;
	for(auto &i:s) if(i=='2') cnt++;
	cout<<cnt<<"\n";
}



























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  string s,t;
  cin >> s >> t;
  string u = t.substr(0,s.size());
  if (s == u) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
using namespace std;
namespace MCF {
	// required <string.h> <vector> <queue> <algorithm>
	#define MAXN 10000
	#define MAXM 110000
	#define wint int
	#define cint int
	const wint wEPS = 0;
	const wint wINF = 1001001001;
	const cint cEPS = 0;
	const cint cINF = 1001001001;
	int n, m, ptr[MAXN], next[MAXM], zu[MAXM];
	wint capa[MAXM], tof;
	cint cost[MAXM], toc, d[MAXN], pot[MAXN];
	int vis[MAXN], pree[MAXN];
	void init(int _n) {
		n = _n; m = 0; memset(ptr, ~0, n * 4);
	}
	void ae(int u, int v, wint w, cint c) {
		next[m] = ptr[u]; ptr[u] = m; zu[m] = v; capa[m] = w; cost[m] = +c; ++m;
		next[m] = ptr[v]; ptr[v] = m; zu[m] = u; capa[m] = 0; cost[m] = -c; ++m;
	}
	bool solve(int src, int ink, wint flo = wINF) {
		int i, u, v;
		wint f;
		cint c, cc;
		memset(pot, 0, n * sizeof(cint));
		//*
		for (bool cont = 1; cont; ) {
			cont = 0;
			for (u = 0; u < n; ++u) for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
				if (pot[zu[i]] > pot[u] + cost[i] + cEPS) {
					pot[zu[i]] = pot[u] + cost[i]; cont = 1;
				}
			}
		}
		//*/
		for (toc = 0, tof = 0; tof + wEPS < flo; ) {
			typedef pair<cint,int> node;
			priority_queue< node,vector<node>,greater<node> > q;
			for (u = 0; u < n; ++u) { d[u] = cINF; vis[u] = 0; }
			for (q.push(make_pair(d[src] = 0, src)); !q.empty(); ) {
				c = q.top().first; u = q.top().second; q.pop();
				if (vis[u]++) continue;
				for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
					cc = c + cost[i] + pot[u] - pot[v = zu[i]];
					if (d[v] > cc) { q.push(make_pair(d[v] = cc, v)); pree[v] = i; }
				}
			}
			if (!vis[ink]) return 0;
			f = flo - tof;
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; f=min(f,capa[i]); }
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; capa[i] -= f; capa[i ^ 1] += f; }
			tof += f;
			toc += f * (d[ink] - pot[src] + pot[ink]);
			for (u = 0; u < n; ++u) pot[u] += d[u];
		}
		return 1;
	}
}
pair<pair<int,int>,int>p[110];
int y[110];
int z[110];
int ls[110];
int main(){
	int a;
	while(scanf("%d",&a),a){
		MCF::init(5000);
		int sz=0;
		int s=4998;
		int t=4999;
		int ln=0;
		MCF::ae(s,0,10,0);
		for(int i=0;i<a-1;i++){
			int b;scanf("%d",&b);
			
			for(int j=0;j<b;j++){
				int c,d,e;scanf("%d%d%d",&c,&d,&e);
				p[j]=make_pair(make_pair(c,d),e);
				y[j]=c;
				z[j]=d;
			}
			for(int j=0;j<b-1;j++){
				MCF::ae((i*2)*20+j,(i*2)*20+j+1,10,0);
			}
			std::sort(y,y+b);
			std::sort(z,z+b);
			if(i){
				for(int j=0;j<ln;j++){
					int at=lower_bound(y,y+b,ls[j])-y;
					if(at<b)MCF::ae((i*2-1)*20+j,(i*2)*20+at,1,0);
				}
			}
			for(int j=0;j<b;j++)ls[j]=z[j];
			ln=b;
			for(int j=0;j<b;j++){
				int L=lower_bound(y,y+b,p[j].first.first)-y;
				int R=lower_bound(z,z+b,p[j].first.second)-z;
				MCF::ae((i*2)*20+L,(i*2+1)*20+R,1,p[j].second);
			}
		}
		for(int i=0;i<ln;i++){
			MCF::ae((2*a-3)*20+i,t,1,0);
		}
		int g;scanf("%d",&g);
		MCF::solve(s,t,g);
		printf("%d %d\n",MCF::tof,MCF::toc);
	}
}

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

using namespace std;

int main (){
	int n;
  	double sum=0;
  
  cin>>n;
  
  vector<int> a(n);
   
  for(int i=0;i<n;i++){
  	
    cin>>a.at(i);
    sum+=1/(double)a.at(i);
  }

	cout<<1/sum<<endl;
  

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
     int n;
     long a,b;
     cin>>n;
     cin>>a>>b;
     long res=0;
     if(a>b){
       cout<<res;
       return 0;
     }
     if(n==1&&a<b){
     cout<<res;
     return 0;
     }
     res = b*(n-1)+a-a*(n-1)-b+1;
     cout<<res;
     return 0;
}
      

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

int main()
{
    double a, b, c;
    double d, e, f;
    double x, y;
    double D;  // 判別式
    
    while (std::cin >> a >> b >> c >> d >> e >> f){
        D = a * e - b * d;
        
        x = ( e * c - b * f) / D;
        y = (-d * c + a * f) / D;
        
        if (x == 0){
            x = 0;
        }
        else if (y == 0){
            y = 0;
        }
        
        std::printf("%.3lf %.3lf\n", x, y);
    }
    
    return 0;
}

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

using namespace std;

int n[1600]={};
char c[1600][150] = {};



int main(){
    int s = 0;
    while(1){
        scanf("%d",&n[s]);
        if(n[s] == 0) break;
        for(int i=0;i<n[s];i++) cin >> c[s][i] ;
        s++;
    }
    int times = s;
    int alpha[26]={};
    
    for(int i=0;i<times;i++){
        int first = 0,second = 0;
        int first_alpha = 0;
        for(int j=0;j<26;j++) alpha[j] = 0;
        for(int j=0;j<n[i];j++){
            int al = c[i][j] - 'A';
            alpha[al]++;
            if(alpha[al] > first) {
                first = alpha[al];
                first_alpha = 'A' + al;
            }
            else{
                if(alpha[al] > second){
                    second = alpha[al];
                }
            }
           if(first - second > n[i] - (j+1) ){
                printf("%c %d\n",first_alpha,j+1);
                break;
            }else if(first == second && j == n[i]-1){
                cout << "TIE" << endl;
            }
        }
    }
}


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


void solve(std::string S){
    if(S=="ABC"){
        cout << "ARC" << endl;
        return;
    }
    cout << "ABC" << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define MAX (ll)(1e5 + 5)
ll n, k, r, s, p;
ll dp[MAX][4];
string str;

ll solve(ll i, ll t)
{
    if (i >= n)
        return 0;
    
    if (dp[i][t] == -1)
    {
        ll ans;
        if (i - k >= 0)
        {
            if (t == 3)
                return 0;
            if (str[i] == 'r')
            {
                ans = max(solve(i + k, 0), solve(i + k, 2));
                if (t != 1)
                    ans = max(ans, solve(i + k, 1) + p);
            }
            else if (str[i] == 'p')
            {
                ans = max(solve(i + k, 0), solve(i + k, 1));
                if (t != 2)
                    ans = max(ans, solve(i + k, 2) + s);
            }
            else
            {
                 ans = max(solve(i + k, 1), solve(i + k, 2));
                if (t != 0)
                    ans = max(ans, solve(i + k, 0) + r);
            }
        }
        else
        {
            if (str[i] == 'r')
                ans = max(solve(i + k, 0) + solve(i + 1, 3), max(solve(i + k, 1) + p + solve(i + 1, 3), solve(i + k, 2) + solve(i + 1, 3)));
            else if (str[i] == 'p')
               ans = max(solve(i + k, 0) + solve(i + 1, 3), max(solve(i + k, 1) + solve(i + 1, 3), solve(i + k, 2) + solve(i + 1, 3) + s));
            else
                ans = max(solve(i + k, 0) + solve(i + 1, 3) + r, max(solve(i + k, 1) + solve(i + 1, 3), solve(i + k, 2) + solve(i + 1, 3)));
        }

        dp[i][t] = ans;
    }
    return dp[i][t];
}

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

    cin >> n >> k >> r >> s >> p;
    cin >> str;
    memset(dp, -1, sizeof(dp));

    cout << solve(0, 3) << "\n";
}


Measured memory_bytes: 8272
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    vecl A(N); 
    int cnt_1 = 0;
    int cnt_2 = 0;
    int cnt_4 = 0;
    REP(i,N) {
        cin >> A[i];
        if(A[i]%4 == 0) cnt_4++;
        else if(A[i]%4 == 2) cnt_2++;
        else cnt_1++;
    }
    if(cnt_2 == 0) {
        if(cnt_1 <= cnt_4 || cnt_1 == cnt_4+1) cout << "Yes" <<endl;
        else cout << "No" << endl;
    } else {
        if(cnt_1 == 0 && cnt_4 == 0) {
            if(cnt_2 > 1) cout << "Yes" << endl;
            else cout << "No" << endl;
        } else if(cnt_1 <= cnt_4) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 3996