akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int, input().split())) + [-1]
m = 1000
s = 0
for i in range(N):
    if A[i+1]>A[i]:
        n = m//A[i]
        s += n
        m %= A[i]

    if A[i+1]<A[i]:
        m += s*A[i]
        s = 0

print(m)

Measured memory_bytes: 9180
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 //   freopen("input.txt","r",stdin);
 //   freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    string a;
    cin>>a;
    int k;
    cin>>k;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]!=a[k-1])
            a[i]='*';
    }
    cout<<a;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<deque>
#include<queue>
#include<set>
#include <functional>
#include <cmath>


//マクロ
/*動かない・・・
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}


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

	int r;
	cin >> r;
	cout << r*r << endl;
}

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

int main(void) {
	int h, w;
	string a[100];

	cin >> h >> w;
	for (int i = 0; i < h; i++) cin >> a[i];

	//列削除
	int wcnt = 0;
	for (int j = 0; a[0][j] != '\0'; j++) {
		if (a[0][j] == '.') {
			bool flg = true;
			for (int i = 1; i < h; i++) {
				if (a[i][j] == '#') flg = false;
			}
			if (flg == true) {
				for (int i = 0; i < h; i++) a[i].erase(a[i].begin() + j);
				wcnt++;
				j--;
			}
		}
	}

	//行削除
	int hcnt = 0;
	string white(w - wcnt, '.');
	for (int i = 0; i < h; i++) {
		if (a[i] == white) {
			a[i].clear();
			hcnt++;
		}
	}

	for (int i = 0; i < h; i++) {
		if (a[i][0] != '\0') {
			cout << a[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

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

// type
#include <cstdint>
#include <functional>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* ---------- Functions */
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 (a > b) { a = b; return true; } return false; }

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int A, B, C, K;
    cin >> A >> B >> C >> K;

    if (K <= A) {
        cout << K << endl;
    } else if (K <= A + B) {
        cout << A << endl;
    } else {
        K -= A + B;
        int score = A;
        score -= K;
        cout << score << endl;
    }

    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main()
{
    int n,i,j,k,l,cnt;
    while (scanf("%d",&n)!=EOF){
    cnt=0;
    for (i=0;i<=9;i++){
        for (j=0;j<=9;j++){
            for (k=0;k<=9;k++){
                for (l=0;l<=9;l++){
                    if (i+j+k+l==n)
                        cnt=cnt+1;
                }
            }
        }
    }
    printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<set>
using namespace std;
int main(){
	multiset<int> a;
	int N;
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		int temp;
		scanf("%d", &temp);
		a.insert(temp);
	}
	int M;
	scanf("%d", &M);
	multiset<int>::iterator ii;
	for(int i=0; i<M; i++){
		int temp;
		scanf("%d", &temp);
		ii=a.find(temp);
		if(ii==a.end()){
			printf("NO");
			return 0;
		}
		a.erase(ii);
	}
	printf("YES");
	return 0;
}

Measured memory_bytes: 11648
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
class Combination{
private:
    vi fact;
public:
    Combination(int size){
        size++;
        fact.resize(size);
        fact[0]=1;
        FOR(i,1,size){
            fact[i]=(fact[i-1]*i)%MOD;
        }
    }
    int Fact(int n){
        return fact[n];
    }
    int MPow(int x,int y){
        if(y==0)return 1;
        if(y%2){
            return (MPow(x,y-1)*x)%MOD;
        }
        int p=MPow(x,y/2);
        return (p*p)%MOD;
    }
    int Comb(int n,int r){
        int res=Fact(n);
        (res*=MPow(Fact(r),MOD-2))%=MOD;
        (res*=MPow(Fact(n-r),MOD-2))%=MOD;
        cerr<<n<<" "<<r<<":"<<res<<endl;
        return res;
    }
};
signed main(){
    int H,W,A,B;
    cin>>H>>W>>A>>B;
    Combination C(H+W);
    int ans=0;
    REP(i,H-A){
        (ans+=(C.Comb(B+i-1,B-1)*C.Comb(W-B+H-i-2,W-B-1))%MOD)%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize('O2')
#include <iostream>
#include <algorithm>
using namespace std;
using int64 = int64_t;

const int64 INF = 1e18;

inline void fastin(int64 &num){
  int64 c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}

inline void fastout(int64 n){
  int64 N = n, rev, count = 0;
  rev = N;
  if (N == 0) {putchar_unlocked('0'); putchar_unlocked('\n'); return;}
  while ((rev % 10) == 0) {++count; rev /= 10;}
  rev = 0;
  while (N != 0) {rev = (rev << 3) + (rev << 1) + N % 10; N /= 10;}
  while (rev != 0) {putchar_unlocked(rev % 10 + '0'); rev /= 10;}
  while (count--) putchar_unlocked('0');
}

int main(){
  int64 a, b, q; fastin(a), fastin(b), fastin(q);
  int64 s[a + 2], t[b + 2];

  s[0] = -1 * INF; t[0] = -1 * INF; s[a + 1] = INF; t[b + 1] = INF;

  for (int i = 1; i <= a; ++i) fastin(s[i]);
  for (int i = 1; i <= b; ++i) fastin(t[i]);

  for (int i = 0; i < q; ++i){
    int64 x; fastin(x);
    auto pos1 = lower_bound(s, s + a + 2, x);
    auto pos2 = lower_bound(t, t + b + 2, x);

    int64 ans = min({max(*pos1 - x, *pos2 - x), 
		     max(x - *(pos1 - 1), x - *(pos2 - 1)),
		     2 * (*pos1 - x) + x - *(pos2 - 1),
		     *pos1 - x + 2 * (x - *(pos2 - 1)),
		     2 * (*pos2 - x) + x - *(pos1 - 1),
		     *pos2 - x + 2 * (x - *(pos1 - 1))}); 
    fastout(ans); putchar_unlocked('\n');
  }
  
  return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define eb emplace_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define cinarr(A,len) for(int i=0;i<len;i++){cin>>A[i];}
#define coutarr(A,len) for(int i=0;i<len;i++){cout<<A[i]<<' ';}cout<<endl
#define coutin(V) for(auto& i : V){cout << i << ' ';}cout<<endl // for vect and set
#define coutmap(U) for(auto& i : U){cout << i.first << "->" << i.second << ", ";}cout<<endl // for map
#define deb(x) cout << #x << '\t' << x << endl
const int imax = numeric_limits<int>::max(), imin = numeric_limits<int>::min();
const long long	lmax = numeric_limits<long long>::max(), lmin = numeric_limits<long long>::min();
/*========================================================================*/
/* strategi/note:



/================================*/




bool Svd=0;
void solve(){Svd=1;
    bool x;
    cin >> x;
    cout << !x << endl;
}


/*========================================================================*/

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
//cout<<fixed<<setprecision( ); // iomanip **

 solve();
 //int t;cin>>t;while(t--){solve();}

if(!Svd)cout<<"solve() function blm dipanggil!"<<endl;
//cout.flush(); cin.get();
return 0;
}

Measured memory_bytes: 3648
x = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(x[K-1])

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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

void solve()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=0;
    if(d>a) {
        d-=a;
        ans+=a;
    }
    else {
        ans+=d;
        cout<<ans;
        return;
    }
    if(d>b) {
        d-=b;
    }
    else {
        cout<<ans;
        return;
    }
    if(d>c) {
        d-=c;
        ans-=c;
    }
    else {
        ans-=d;
        cout<<ans;
        return;
    }
    

}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>  
using namespace std;
int dp[2][100005];
int f(int x,int k,int val[],int n)
{
    if(dp[x][k]!=-1)return dp[x][k];
    int flag=!x;
    for(int i=0;i<n;i++)
    {
        if(k<val[i])flag=!x;
        else if(k==val[i])flag=x;
        else 
        {
            flag=f(!x,k-val[i],val,n);
        }
        if(flag==x)break;
    }
    if(flag==x)dp[x][k]=x;
    else dp[x][k]=!x;
    return dp[x][k];
}
int main()
{
    memset(dp,-1,sizeof(dp));
    int n,k;
    cin>>n>>k;
    int val[n];
    for(int i=0;i<n;i++)
        cin>>val[i];
    if(n==1)
    {
        if((k/val[0])%2==0)cout<<"Second";
        else cout<<"First";
        return 0;
    }
    int flag=1;
    for(int i=0;i<n;i++)
    {
        dp[0][k]=f(1,k-val[i],val,n);
        if(dp[0][k]==0)
        {
            flag=0;
            break;
        }
    }
    if(flag==0)cout<<"First";
    else cout<<"Second";
}

Measured memory_bytes: 8832
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] nums = new int[3];
        for (int i = 0; i < 3; i++) {
            nums[i] = scanner.nextInt();
        }
        scanner.close();

        int temp = nums[0];

        nums[0] = nums[1];
        nums[1] = temp;

        temp = nums[0];

        nums[0] = nums[2];
        nums[2] = temp;

        System.out.println(nums[0] + " " + nums[1] + " " + nums[2]);

    }
}


Measured memory_bytes: 21840
#include<iostream>
#include<math.h>
using namespace std;

int main(){
    int N;
    float T, A, answer;
    cin >> N;
    float a[N];
    cin >> T >> A;
    float min = 10000000;
    for (int i = 0; i < N; i++){
        cin >> a[i];
        a[i] = abs(A - (T - a[i] * 0.006));
        if (min > a[i]){
            min = a[i];
            answer = i + 1;
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 888
# ABC088D

import sys
from collections import deque
input=sys.stdin.readline

def main():
    H,W=map(int,input().split())
    mas=[input() for i in range(H)]
    dist=[[-1]*W for i in range(H)]
    sharps=0
    for row in mas:
        sharps+=row.count("#")
    qu=deque([(0,0)])
    dist[0][0]=1
    d=((-1,0),(1,0),(0,-1),(0,1))
    qup=qu.popleft
    qua=qu.append
    while(len(qu)>0):
        v=qup()
        for di in d:
            nv=(v[0]+di[0],v[1]+di[1])
            if not(0<=nv[0]<H) or not(0<=nv[1]<W) or mas[nv[0]][nv[1]]=="#" or dist[nv[0]][nv[1]]!=-1:
                continue
            else:
                dist[nv[0]][nv[1]]=dist[v[0]][v[1]]+1
                qua(nv)
    ms=dist[H-1][W-1]
    if ms==-1:
        print(ms)
    else:
        print(H*W-sharps-ms)
    
    
    
    
if __name__=="__main__":
    main()

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

#define MOD 1000000007

bool isPrime(int n) {
    if (n == 1) return false;
    if (n == 2) return true;
    for (int i = 2; i <= (sqrt(n) + 1); i++){
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    int N; cin >> N;
    vector<ll> f(N+1);
    for (int i = 0; i <= N; i++){
        f[i] = 1;
    }
    for (int i = 2; i <= N; i++){
        int tmp = i;
        int j = 2;
        while (tmp > 1 && j <= tmp) {
            if (isPrime(j)){
                while (tmp % j == 0) {
                    f[j] = f[j] + 1;
                    tmp /= j;
                }
            }
            j++;
        }
        
    }
    ll ans = 1;
    for (int i = 0; i <= N; i++){
        ans *= f[i];
        ans %= MOD;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

long long euclidean_gcd(long long a, long long b)
{
	if (a < b)
		return euclidean_gcd(b, a);
	long long r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

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

	long long r = 0;

	if (n % 2 == 1)
	{
		printf("0");
		return 0;
	}

	long long tmp = n;
	int k = 0;
	while (tmp >= 5)
		tmp /= 5, k++;

	for(int i = k; i >= 1; i--)
	{
		tmp = pow(5, i);
		r += (n / 2) / tmp;
	}

	printf("%lld", r);

	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)

using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int  l[m],r[m];
  int maxl=1;
  int minr=n;
  int i=0;
  rep(i,m){
    cin>>l[i]>>r[i];  
  }
  rep(i,m){//rep?
    maxl=max(maxl,l[i]);
    minr=min(minr,r[i]);
  }
  int ans=minr-maxl+1;//区間の長さは+1;
  ans=max(ans,0);//もし答えが負だったら答えが0になるように
  cout<<ans<<endl;
}
//2019/05/27 RE


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

int main() {
    int h, w; cin >> h >> w;
    vector<string> a(h);

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

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (a[i][j] == '#') {
                row[i] = true;
                column[j] = true;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        if (row[i]) {
            for (int j = 0; j < w; j++) {
                if (column[j]) {
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
A = list(map(int, input().split()))

fmax = 0
for i in range(40, 0, -1):
  x = 2 ** (i - 1)
  f1 = 0
  f0 = 0
  for a in A:
    a_ = a & x
    f1 += x ^ a_
    f0 += a_
  #print(i, f0, f1)
  if f0 >= f1:
    fmax += f0
  else:
    if k >= x:
      fmax += f1
      k -= x
    else:
      fmax += f0
print(fmax)

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

using ll = long long;

int main() {
    vector<ll> ten(12, 1);
    for(int i = 1; i < 12; ++i) {
        ten[i] = ten[i - 1] * 10LL;
    }

    int digit = 0;
    while(digit < 11) {
        cout << "? " << ten[digit] << endl;
        char res;
        cin >> res;
        if(res == 'Y') {
            digit++;
        } else {
            break;
        }
    }
    if(digit == 11) { // 1 or 10 or ... 10^n
        ll tmp = 9;
        digit = 0;
        while(digit < 11) {
            cout << "? " << tmp << endl;
            char res; cin >> res;
            if(res == 'Y') {
                break;
            }
            tmp *= 10;
            tmp += 9;
            digit++;
        }
        cout << "! " << ten[digit] << endl;
    } else {
        ll lb = ten[digit], ub = ten[digit + 1];
        while(ub - lb > 1) {
            ll m = (lb + ub) / 2;
            cout << "? " << m << endl;
            char r;
            cin >> r;
            if(r == 'Y') {
                ub = m;
            } else {
                lb = m;
            }
        }
        cout << "! " << ub / 10 << endl;
    }
}


Measured memory_bytes: 688
#include <iostream>
#include <cmath>
using namespace std;
int x = 0;
int ans = -1000000;
int main(){
int n; string s;
cin >> n >> s;
for(int i = 0; i < n; i++){
ans = max(ans, x);
x += (s[i] == 'I' ? 1 : -1);
ans = max(ans, x);
}
cout << ans;
}

Measured memory_bytes: 504
#include <iostream>

using namespace std;

int main(void){
  string a;
  cin>>a;
  int ar[3] = {0,0,0};
  for(int i = 0 ; i < a.size()  ; i ++){
    ar[a[i]-'a'] ++;
  }

  bool f = true;
  for(int i = 0 ; i < 3 ; i ++){
    f = f && ar[i] == 1;
  }
  cout<<(f?"Yes":"No")<<endl;
}




Measured memory_bytes: 256
import numpy as np

N = int(input())
L = list(map(int, input().split()))
L2 = np.square(L)

A = N
B = sum(L) * 2
C = sum(L2)

lim = round(B / A / 2)

l = list(map(lambda x: x - lim, L))
l2 = list(map(lambda x: x ** 2, l))

print(sum(l2))

Measured memory_bytes: 13304
# frozen_string_literal: true

n, d = gets.split.map(&:to_i)
x = []
n.times { x << gets.split.map(&:to_i) }

puts [*0...n].combination(2).count { |i|
  tmp = Math.sqrt(Array.new(d) { |j| (x[i[0]][j] - x[i[1]][j])**2 }.inject(:+))
  tmp.to_i == tmp
}

Measured memory_bytes: 1916
#include <stdio.h>
long long k, q, s;
long long n, x, m, t, f, g;
long long d[5000];
long long e[5000];
int main() {
	scanf("%lld%lld", &k, &q);
	for (long long i = 0; i < k; i++) {
		scanf("%lld", d + i);
	}
	for (long long i = 0; i < q; i++) {
		scanf("%lld%lld%lld", &n, &x, &m);
		s = 0;
		f = 0; g = 0;
		for (long long j = 0; j < k; j++) {
			e[j] = d[j] % m;
			s += e[j];
			if (e[j] == 0)g++;
		}
		n -= 2;
		t = x;
		t += (n / k) * s;
		f += (n / k) * g;
		for (long long j = 0; j <= n % k; j++) {
			t += e[j];
			if (e[j] == 0)f++;
		}
		printf("%lld\n", (n + 1) - t / m + x / m - f);
	}
}

Measured memory_bytes: 256
import java.util.*;

// ABC 70-D
// https://beta.atcoder.jp/contests/abc070/tasks/abc070_d

public class Main {

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

		int N = in.nextInt();
		
		ArrayList<ArrayList<KPoint>> map = new ArrayList<ArrayList<KPoint>>();
		for (int i = 0; i < N; i++) {
			map.add(new ArrayList<KPoint>());
		}
		
		for (int i = 0; i < N - 1; i++) {
			int a = in.nextInt() - 1;
			int b = in.nextInt() - 1;
			int c = in.nextInt();

			map.get(a).add(new KPoint(b, c));
			map.get(b).add(new KPoint(a, c));
		}
		int Q = in.nextInt();
		int K = in.nextInt() - 1;

		long[] dist = new long[N];
		int[] visited = new int[N];
		dfs(K, dist, visited, 0, map);
		
		for (int i = 0; i < Q; i++) {
			int start = in.nextInt() - 1;
			int end = in.nextInt() - 1;
			System.out.println(dist[start] + dist[end]);
		}
	}
	
	public static void dfs(int curr, long[] dist, int[] visited, long d, ArrayList<ArrayList<KPoint>> map) {
		visited[curr] = 1;
		dist[curr] = d;
		for (int i = 0; i < map.get(curr).size(); i++) {
			KPoint kp = map.get(curr).get(i);
			if (visited[kp.p] == 0) {
				dfs(kp.p, dist, visited, d + kp.dist, map);
			}
		}
	}
}

class KPoint {
	int p;
	int dist;
	
	public KPoint(int p, int dist) {
		this.p = p;
		this.dist = dist;
	}
}

Measured memory_bytes: 192200
//ITP1_8_C

#include <stdio.h>
#include <stdlib.h>

#define num 20

int main(){

	int i;
	int alp[26];
	int p,q;
	char r;

	for(i=0;i<26;i++){alp[i]=0;}
	
	while(scanf(" %c",&r)!=EOF){
	
		p=r;
		
		if(('A'<=p)&&(p<='z')){
			
			if(p-'A'<26){alp[p-'A']++;}
			if(p-'A'>26){alp[p-'a']++;}
		}
	}
		
	for(i=0;i<26;i++){
		printf("%c : %d\n",'a'+i,alp[i]);
	}
	
	return 0;
}

Measured memory_bytes: 540
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // long long64_t, long long*_t
#include <cstdio> // prlong longf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;
int main(){
  int n,sum;
  cin >> n;
  vector<int> a(n);
  vector<int> co(9,0);
  for(int i=0; i<n; i++){
    cin >> a[i];
    int x;
    x=a[i]/400;
    co[min(x,8)]++;
  }
  for(int i=0; i<8; i++){
    if(co[i]!=0) sum++;
  }
  if(sum!=0){
    cout << sum << " " << sum+co[8] << endl;
  }
  else{
    cout << 1 << " " << sum+co[8] << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

const int MOD = 1000000007;

// vector<vector<int>> data(3, vector<int>(4));

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

  int n;
  cin >> n;

  if(n==0)cout<<1;
  if (n == 1) cout << 0;

  return 0;
}

Measured memory_bytes: 3648
// メイン
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (i * j == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n, m;
string s, t;
int main(){
	cin >> n >> m >> s >> t;
	if(n > m){
		swap(n, m);
		swap(s, t);
	}
	LL len = lcm(n, m);
	for(int i = 0;i < n;i++){
		if((i*(len/n)) % (len/m) == 0){
			if(s[i] != t[(i*(len/n)) / (len/m)]){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	cout << len << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 505;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    LL n, m, q;
    cin >> n >> m >> q;
    LL sum[SIZE][SIZE] = {};

    for( int i = 0; i < m; ++i ) {
        LL l, r;
        cin >> l >> r;
        ++sum[l][r];

    }

    //二次元累積和
    for( int i = 1; i <= n; ++i ) {
        for( int j = 1; j <= n; ++j ) sum[i][j] += sum[i][j - 1];

    }

    for( int i = 1; i <= n; ++i ) {
        for( int j = 1; j <= n; ++j ) sum[i][j] += sum[i - 1][j];

    }

    for( int i = 0; i < q; ++i ) {
        LL a, b;
        cin >> a >> b;
        cout << sum[b][b] + sum[a - 1][a - 1] - sum[a - 1][b] - sum[b][a - 1] << endl;

    }

    return 0;
}



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

class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		for(int i=0;i<s.length();i++){
			if(i==3){
				System.out.print(8);
			}
			else{
				System.out.print(s.charAt(i));
			}
		}
		System.out.println();
	}
}



Measured memory_bytes: 21588
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main () {
	string s;
	cin >> s;
	bool flag = true;
	int q;
	cin >> q;
	char ans[500000];
	int start = 200005;
	int end = 200006;
	for(int i = 0; i < s.length(); i++) {
		ans[end] = s[i];
		end += 1;
	}
	for(int i = 0; i < q; i++) {
		int cur;
		cin >> cur;
		if(cur == 1) {
			flag = (flag == true) ? false : true;
		}else {
			int op;
			char c;
			cin >> op >> c;
			if(op == 1) {
				if(flag == true) {
					ans[start] = c;
					start -= 1;
				}else {
					ans[end] = c;
					end += 1;
				}
			}else {
				if(flag == true) {
					ans[end] = c;
					end += 1;
				}else {
					ans[start] = c;
					start -= 1;
				}
			}
		}
	}
	if(flag == true) {
		for(int i = start + 1; i < end; i++) {
			cout << ans[i];
		}
		cout << "\n";
	}else {
		for(int i = end - 1; i > start; i--) {
			cout << ans[i];
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 1088
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

int main(){
    int n , k ; 
    cin >> n >> k ; 
    vector<int> v(n) ; 
    for(int i = 0; i < n; i++){
        cin >> v[i] ; 
    }
    int res = 0 ;
    for(int i = 0; i <= min(n, k); i++){
        for(int j = 0; j + i <= min(n, k); j++){
            vector<int> ans ; 
            for(int c = 0; c < i; c++){
                ans.push_back(v[c]);
            }
            for(int c = 0; c < j; c++){
                ans.push_back(v[n - c - 1]);
            }
            sort(ans.begin(), ans.end());
            int remain = k - (i + j) ; 
            int sum = 0 ; 
            for(int c = 0; c < (int) ans.size(); c++){
                if ( ans[c] < 0 ){
                    if ( remain ){
                        remain-- ; 
                    }
                    else sum += ans[c] ; 
                }
                else sum += ans[c] ; 
            }
            res = max(res,sum) ;
        }
    }
    cout << res << endl;
    return 0 ;
}


Measured memory_bytes: 256
S = gets.split("")
s = S
s.each.with_index do |st, i|
  if st == "A" then
    $start = i
    break
  end
end

s.reverse!
  
  s.each.with_index do |en, i|
  if en == "Z" then
  $ending = i
    break
  end
end

end_index = S.length - $ending
p end_index - $start 

Measured memory_bytes: 16636
#include<stdio.h>
#include<stdlib.h>
//小さい順にソート
int c[200002];
void merge(int i,int j,int *s){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d]=s[b];
        b++;
      }
      else if(j<b){
        c[d]=s[a];
        a++;
      }
      else if(s[a]<s[b]){
        c[d]=s[a];
        a++;
      }
      else{
        c[d]=s[b];
        b++;
      }
    }
    for(d=i;d<=j;d++)
      s[d]=c[d];
  }
}

int main(){
  int n,i,j;
  long long sum=0;
  scanf("%d",&n);
  int a[n+1];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    a[i]-=i+1;
  }
  merge(0,n-1,a);
  for(i=1;i<n;i++)
    a[i]-=a[0];
  a[0]=0;
  for(j=0;j<n;j++)
    sum+=abs(a[n/2]-a[j]);
  printf("%lld\n",sum);
  return 0;
}


Measured memory_bytes: 1664
using System;
using System.Linq;

namespace Structured_Program_II
{
    class How_many_ways
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var array = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                var n = array[0];
                var x = array[1];
                if (n == 0 && x == 0) break;

                int c = 0;
                for (int i = 1; i <= n; i++)
                    for (int j = i + 1; j <= n; j++)
                        for (int k = j + 1; k <= n; k++)
                            if (i + j + k == x) c++;
                Console.WriteLine(c);
            }
           
        }
    }
}

Measured memory_bytes: 9540
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k; cin >> k; cout << a[k-1] << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
using namespace std;
int main(){
    double b,c;
    int K,a;
    cin >> K;
    if(K%2==0){
        cout << (K/2)*(K/2) <<endl;
    }else{
        b = K;
        c = (b/2)*(b/2);
        a = c;
        cout << a;   
    }
}

Measured memory_bytes: 256
#include <cstdio>

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

    int sums_of_2_exponents = 0;
    while(no_of_elements--)
    {
        int element;
        scanf("%d", &element);

        while(element%2 == 0)
        {
            sums_of_2_exponents++;
            element /= 2;
        }
    }

    printf("%d\n", sums_of_2_exponents);
    return 0;
}


Measured memory_bytes: 128
n = int(input())
A = list(map(int, input().split())) 
q = int(input())

from collections import Counter
arr = Counter(A)
ans = sum([i*arr[i] for i in arr])
 
for i in range(q):
    b,c = list(map(int,input().split()))
    ans += (c-b)*arr[b]
    arr[c],arr[b] = arr[c]+arr[b],0
    print(ans)

Measured memory_bytes: 24104
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,d=I()
for i in range(n):
    x,y=I()
    if (x**2+y**2)**(0.5)<=d:
        cnt+=1

print(cnt)


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define RFOR(i,a,b) for(int i=(a);i>(b);i--)
#define RFORE(i,a,b) for(int i=(a);i>=(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ll n,m;
    cin >> n >> m;
    vector<pair<ll,ll> > pr_li;
    FOR(i,0,n){
        int a,b;
        cin>>a>>b;
        pr_li.push_back(make_pair(a,b));
    }
    sort(pr_li.begin(),pr_li.end());
    ll ans=0;
    FOR(i,0,n){
        int mn=min(m,pr_li[i].second);
        m-=mn;
        ans=ans+pr_li[i].first*mn;
        if(m==0)break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2420
N = int(input())
A = list(map(int, input().split()))

import fractions
import copy
from functools import reduce

#最大公約数を求める関数
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

l = []
sorted_A = sorted(A)
ind = 0
for i in range(1, len(A)):
    if gcd_list([sorted_A[0], sorted_A[i]]) == 1:
        ind = i
        break
if ind == 0:
    ind = 1
for i in [0,ind]:
    sorted_A = sorted(A)
    del sorted_A[i]
    l.append(gcd_list(sorted_A))

print(max(l))

Measured memory_bytes: 14076
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    int a = scan!int, b = scan!int, c = scan!int, d = scan!int;
    auto sf = new Finite[][](c + 1, d + 1);

    foreach(i; a .. c + 1) foreach(j; b .. d + 1){
        if(i == a && j == b) sf[i][j] = 1;
        else sf[i][j] = sf[i][j - 1] * i + sf[i - 1][j] * j
          - sf[i - 1][j - 1] * (i - 1) * (j - 1);
    }
    sf[c][d].print;
}

const long mod = 998244353;
struct Finite{
	long value; 
	this(long v){ value = val(v); }
	static long val(long v){ return (v + mod  - (v / mod) * mod) % mod; }
	bool opCast(T: bool)(){ return value != 0; }
	bool opEquals(Finite b){ return(value == b.value); }
	string toString(){ return value.to!string; }
 
	Finite opUnary(string s){ long v;
		if(s == "+") v = value;
		else if(s == "-") v = mod - value;
		else if(s == "++") v = value + 1;
		else if(s == "--") v = value + mod - 1;
		else assert(0, "Operator unary " ~ s ~ " not implemented");
		return Finite(v);
	}
 
	Finite opBinary(string s)(Finite b){ return opBinary!s(b.value); }
	Finite opBinary(string s)(long u){ long v;
		if(s == "+") v = value + u;
		else if(s == "-") v = value + mod - u;
		else if(s == "*") v = value * u;
		else if(s == "/") v = value * inv(u);
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opBinaryRight(string s)(long u){ long v;
		if(s == "+") v = u + value;
		else if(s == "-") v = u + mod - value;
		else if(s == "*") v = u * value;
		else if(s == "/") v = u * invvalue;
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opAssign(long v){ value = v; return this; }
 
	Finite opOpAssign(string s)(Finite b){ return opOpAssign!s(b.value); }
	Finite opOpAssign(string s)(long v){
		if(s == "+") value = (value + v) % mod;
		else if(s == "-") value = (value + mod - v) % mod;
		else if(s == "*") value = (value * v) % mod;
		else if(s == "/") value = (value * inv(v)) % mod;
		else assert(0, "Operator " ~ s ~ "= not implemented");
		return this;
	}
	
	private static long[] _inv = [0, 1];
	long invvalue(){ return inv(value); }
	long inv(long v){ int i = val(v).to!int;
		while(i >= _inv.length){
			_inv ~= _inv[(mod % $).to!int] * (mod - mod / _inv.length) % mod;
		}
		return _inv[i];
	}
	
}

Measured memory_bytes: 75392
N,K = map(int,input().split())
DP = [0]*(N+1)
DPsum=[0]*(N+1)
DP[1]=1
DPsum[1]=1
lr = []
m=998244353
for _ in range(K):
    l,r = map(int,input().split())
    lr.append([l,r])

for i in range(2,N+1):
    for l,r in lr:
        lx = i - r - 1
        rx = i - l
        lx = max(0,lx)
        rx = max(0,rx)
        DP[i]+= DPsum[rx]-DPsum[lx]
    DPsum[i]=(DPsum[i-1]+DP[i])%m
print(DP[N]%m)


Measured memory_bytes: 76928
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    double w, h;
    cin >> w >> h;
    ll x, y;
    cin >> x >> y;
    double ans_area = w * h / 2;
    printf("%.10lf ", ans_area);
    if(w / 2 == x && h / 2 == y) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#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(){
   ll n,m;
   cin >> n >> m;
   vector<vector<ll>> map(n); 
   rep(i,n){
      ll s;
      cin >> s;
      map.at(i).push_back(i);
      map.at(i).push_back(s);
   }
   rep(i,m){
      ll x,y;
      cin >> x >> y;
      x--;
      y--;
      if(map[x][1] > map[y][1]){
         map[y][0] = -1;
      }else if(map[x][1] < map[y][1]){
         map[x][0] = -1;
      }else{
         map[x][0] = -1;
         map[y][0] = -1;
      }
   }
   set<ll> ans;
   rep(i,n){
      ans.insert(map[i][0]);
   }
   ans.erase(-1);
   cout << ans.size() << endl;
   return 0;  
}

Measured memory_bytes: 12496
# coding: utf-8
# Your code here!
N = int(input())
W = list(map(int,input().split()))
S = sum(W)
ans = float('inf')
for i in range(N):
    l = sum(W[:i+1])
    r = S - l
    ans = min(ans, abs(l-r))

print(ans)

Measured memory_bytes: 9176
from collections import defaultdict

n = int(input())
s = input()
s1 = s[:n]
s2 = s[n:][::-1]
def makeDic(s):
    dic = defaultdict(int)
    for i in range(2 ** n):
        mask = 1
        c1 = ""
        c2 = ""
        for j in range(n):
            if i & mask:
                c1 += s[j]
            else:
                c2 += s[j]
            mask <<= 1
        dic[(c1, c2)] += 1
    return dic


dic1 = makeDic(s1)
dic2 = makeDic(s2)
ans = 0
for key in dic1:
    if key in dic2:
        ans += dic1[key] * dic2[key]
print(ans)

Measured memory_bytes: 125912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    if (c < a) {
        if (d <= b) cout << max((ll)0, d-a) << endl;
        else cout << b-a << endl;
    } else if (c <= b) {
        if (d <= b) cout << d-c << endl;
        else cout << b-c << endl;
    } else cout << 0 << endl;
}

Measured memory_bytes: 3636
import java.util.*;

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

        int N = scanner.nextInt();

        HashSet<Character> hashSet = new HashSet<>();


        for(int i=0; i<N; i++){
            String S = scanner.next();
            hashSet.add(S.charAt(0));
        }

        if(hashSet.size() == 3) {
            System.out.println("Three");
        }else{
            System.out.println("Four");
        }
    }
}


Measured memory_bytes: 23124
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;
const int MOD = 1e9 + 7;

int main() {
    string sa, sb, sc;
    cin >> sa >> sb >> sc;

    size_t ia, ib, ic;
    ia = ib = ic = 0;
    int turn = 'a';
    while(1){
        switch(turn){
            case 'a':
                if(ia >= sa.length()){
                    cout << 'A' << endl;
                    return 0;
                }
                turn = sa[ia++];
                break;
            case 'b':
                if(ib >= sb.length()){
                    cout << 'B' << endl;
                    return 0;
                }
                turn = sb[ib++];
                break;
            case 'c':
                if(ic >= sc.length()){
                    cout << 'C' << endl;
                    return 0;
                }
                turn = sc[ic++];
                break;
        }
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> p;
	for(int i = 0; i < N; i++) {
		int A;
		cin >> A;
		A = INT_MAX - A;
		auto it = upper_bound(p.begin(), p.end(), A);
		if(it == p.end()) {
			p.push_back(A);
		} else {
			*it = A;
		}
	}

	cout << p.size() << endl;
}


Measured memory_bytes: 1524
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    L = len(S)
    ans = S[0] + str(L-2) + S[-1]
    print(ans)

if __name__ == '__main__':
    main()


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

class UnionFind {
public:
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i)
            par[i] = i;
    }

    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

int X[100010], Y[100010];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(M), B(M), C(K), D(K);
    UnionFind uni(N);
    rep(i, M) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        X[A[i]]++; X[B[i]]++;
        uni.unite(A[i], B[i]);
    }
    rep(i, K) {
        cin >> C[i] >> D[i];
        C[i]--; D[i]--;
        if (!uni.issame(C[i], D[i])) continue;
        Y[C[i]]++; Y[D[i]]++;
    }
    rep(i, N) {
        int num = uni.size(i) - X[i] - Y[i] - 1;
        cout << num << ' ';
    }
    cout << endl;
    return 0;
}

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

using namespace std;

#define INF 1000000007
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define maxn 15

int gcd(int x, int y)
{
    if (x < y)
        swap(x, y);
    if (y == 0)
        return x;
    return gcd(x % y, y);
}
signed main()
{
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int l[Q], r[Q];
    rep(i, Q)
    {
        cin >> l[i] >> r[i];
    }
    vector<int> ans;
    int count = 0;
    rep(i, S.length())
    {
        if (i > 0 && S[i] == 'C' && S[i - 1] == 'A')
        {
            count++;
        }
        ans.push_back(count);
    }
    rep(i, Q)
    {
        cout << ans[r[i] - 1] - ans[l[i] - 1] << endl;
    }
}


Measured memory_bytes: 3444