akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}
int n;
vector< vector<int> > v;
vector<int> c;
vector<int> f;
vector<int> dd;

int func() {
  vector<bool> visit(n, false);
  queue< pair<int, int> > q;
  q.push({0, 0});
  while(!q.empty()){
    int p = q.front().first;
    c[p] = q.front().second;
    q.pop();
    visit[p] = true;
    for(int i=0; i<v[p].size(); i++){
      if(visit[v[p][i]]) continue;

      q.push({v[p][i], c[p]+1});
    }
  }
  return 0;
}

int sfunc(int p) {
  dd.push_back(p);
  if(p == 0) return 0;
  for(int i=0; i<v[p].size(); i++){
    if(c[v[p][i]]+1 == c[p]){
      sfunc(v[p][i]);
    }
  }
  return 0;
}

int func2(){
  vector<bool> visit(n, false);
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int p = q.front();
    q.pop();
    if(f[p] == -1) continue;

    f[p] = 1;
    visit[p] = true;
    for(int i=0; i<v[p].size(); i++){
      if(visit[v[p][i]]) continue;

      q.push(v[p][i]);
    }
  }

  return 0;
}

int main() {
  cin >> n;
  c.resize(n);
  v.resize(n, vector<int>());
  for(int i=0; i<n-1; i++){
    int a, b; cin >> a >> b; a--; b--;
    v[a].push_back(b); v[b].push_back(a);
  }
  func();

  sfunc(n-1);
  f.resize(n, 0);
  for(int i=0; i<dd.size()/2; i++){
    f[dd[i]] = -1;
  }
  for(int i=dd.size()/2; i<dd.size(); i++){
    f[dd[i]] = 1;
  }
  func2();
  int fen = 0;
  for(int i=0; i<n; i++){
    if(f[i] == 1) fen++;
  }
  int snk = n - fen;
  cerr << fen << " " << snk << endl;

  if(fen > snk) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;

  return 0;
}
//


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

int main() {
	string s;
	cin >> s;
	int a = stoi(s.substr(0, 2));
	int b = stoi(s.substr(2, 2));
	
	bool yymm, mmyy;
	if (0 < a && a < 13) mmyy = true;
	else mmyy = false;

	if (0 < b && b < 13) yymm = true;
	else yymm = false;

	if (yymm && (!mmyy)) cout << "YYMM" << endl;
	else if (mmyy && (!yymm)) cout << "MMYY" << endl;
	else if (yymm && mmyy) cout << "AMBIGUOUS" << endl;
	else cout << "NA" << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, D, X, ans;
std::vector<int>A;

int main()
{
	in >> N >> D >> X;
	A.resize(N);
	rep(i, N) in >> A[i];
	ans = X;
	rep(i, N) ans += (D - 1) / A[i] + 1;
	out << ans << std::endl;
	return 0;
}


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

const int MAXN = 1e5+5;
const int MAXNN = 1e2+5;
const int INF = 1e9+7;
#define ll long long
#define pb push_back
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

ll modd;

ll MOD(ll a){
    return ((a%modd)+modd)%modd;
}

ll inv(ll a){
    return poww(a,INF-2,INF);
}

ll dp[MAXN][2],n;
vector<int> adjList[MAXN];

void dfs(int start,int par){
    dp[start][0] = 1;
    for(auto u : adjList[start]){
        if(u != par){
            dfs(u,start);
            dp[start][0] *= (dp[u][0] + 1);
            dp[start][0] = MOD(dp[start][0]);
        }
    }
}

void dfs1(int start,int par){
    vector<ll> parr(adjList[start].size()+4),suff(adjList[start].size()+4);
    parr[0] = 1;
    for(int i=1;i<=adjList[start].size();++i){
        if(adjList[start][i-1] == par){
            parr[i] = parr[i-1];
            continue;
        }
        parr[i] = MOD(parr[i-1] * (dp[adjList[start][i-1]][0]+1)) ;
    }
    suff[adjList[start].size()+1] = 1;
    for(int i=adjList[start].size();i>=1;--i){
        if(adjList[start][i-1] == par){
            suff[i] = suff[i+1];
            continue;
        }
        suff[i] = MOD(suff[i+1] * (dp[adjList[start][i-1]][0]+1));
    }
    for(int i=1;i<=adjList[start].size();++i){
        if(adjList[start][i-1] != par){
            dp[adjList[start][i-1]][1] = MOD(1 + (MOD(MOD(parr[i-1] * suff[i+1])) * dp[start][1]));
            dfs1(adjList[start][i-1],start);
        }
    }
}

int main()
{
    fast_io;
    //cout << fixed << setprecision(15);

    cin >> n >> modd;
    for(int i=0;i<n-1;++i){
        int c,d;cin >> c >> d;
        adjList[c].pb(d);
        adjList[d].pb(c);
    }
    dfs(1,-1);
    dp[1][1] = 1;
    dfs1(1,-1);
    for(int i=1;i<=n;++i){
        ll res = MOD(dp[i][0] * dp[i][1]) ;
        cout << res << endl;
    }
}


Measured memory_bytes: 24064
N = int(input())
S = list(map(int,input().split()))
H = list(map(int,input().split()))
T = S[0]
A = S[1]
sub = abs(A - (T - H[0]*0.006))
for x in range(0,N):
    H_sub = abs(A -(T - H[x]*0.006))
    if H_sub <= sub:
        sub = H_sub
        X = x
print(X+1)

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

int N;
vector<int> a;

bool check(int x) {
  map<int, int> ma;
  for (int i = 1; i < N; i++) {
    if (a[i - 1] < a[i]) {
      continue;
    }
    if (x == 1) return false;
    int idx = a[i];
    auto it = ma.upper_bound(idx);
    while (it != ma.end()) {
      ma.erase(it++);
    }
    while (true) {
      ma[idx]++;
      if (ma[idx] < x) {
        break;
      }
      if (idx == 1) return false;
      ma.erase(idx);
      idx--;
    }
  }
  return true;
}

void solve() {
  cin >> N;
  a.resize(N); cin >> a;
  int ok = 200000, ng = 0;
  while (ok - ng > 1) {
    int md = (ok + ng) / 2;
    check(md) ? (ok = md) : (ng = md);
  }
  cout << ok << '\n';
}


Measured memory_bytes: 1024
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)

for i in range(Q):
    l, r = LR[i][0], LR[i][1]
    cnt = t[r - 1] - t[l -1]
    print(cnt)

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

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    
    int cnt = 0;
    for(int i = A; i <= B; i++){
        int temp = i;
        vector<int> t;
        while(temp > 0){
            t.push_back(temp % 10);
            temp /= 10;
        }
        
        if(t[0] == t[4] && t[1] == t[3])    cnt++;
    }
    
    cout << cnt << endl;
}

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


int N, C, A[32], B[32];
int memo[1 << 16][32];


int rec(int panel, int now)
{
	if(now == N) return 0;
	if(memo[panel][now] != -1) return memo[panel][now];

	int next = panel | A[now];

	int best = 0;
	
	for(int i = 0; i < C; i++) {
		best = max(best, rec(next & ~B[i], now+1) + __builtin_popcount(next & B[i]));
	}

	return memo[panel][now] = best;
}


int main()
{
	for(; cin >> N >> C && (N || C); ) {
		memset(A, 0, sizeof A);
		memset(B, 0, sizeof B);
		memset(memo, -1, sizeof memo);

		for(int i = 0; i < N; i++) {
			for(int j = 0; j < 16; j++) {
				int b;
				cin >> b;

				A[i] |= (b << j);
			}
		}
		
		for(int i = 0; i < C; i++) {
			for(int j = 0; j < 16; j++) {
				int b;
				cin >> b;

				B[i] |= (b << j);
			}
		}

		cout << rec(0, 0) << endl;
	}
}

Measured memory_bytes: 9364
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define sz(v) (int)v.size()
#define pb push_back

using namespace std;
int n,m;
vector<long> x(1005),y(1005),z(1005);
long dp[1005][1005];
int dx[2] = {1,-1};

int main(){
    cin >> n >> m;
    rep(i,n) cin >> x[i] >> y[i] >> z[i];
    
    long pr = 0;
    
    rep(i,2) rep(j,2) rep(k,2){
        long sum[1005] = {};
        long ans = 0;
        rep(l,n){
            sum[l] = x[l]*dx[i] + y[l]*dx[j] + z[l]*dx[k];
        }
        sort(sum,sum+n);
        rep(l,m) ans += sum[n-1-l];
        pr = max(pr,ans);
    }
    
    cout << pr << endl;
}


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

using namespace std;

int main()
{
   int n;
   long long a[100100];
   while(scanf("%d",&n)==1)
   {
       int i,r;long long s=0;
   for(i=0;i<n;i++)
    scanf("%lld",&a[i]);
   for(i=0;i<n;i++)
   {
       int t=a[i];
       r=t/2;
       while(r*2==t)
       {
           s++;t=r;r=t/2;
       }
   }
   printf("%lld\n",s);
   }

    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int h, w, k; cin>>h>>w>>k;
    vector<string> s(h);
    for(int i=0; i<h; i++) cin>>s[i];

    int ans = inf;
    for(int bit=0; bit<(1<<(h-1)); bit++){
        int row = __builtin_popcount(bit) + 1;
        int sum = row - 1;
        bool valid = true;
        vector<int> psum(row, 0);
        for(int j=0; j<w; j++){
            vector<int> ccost(row, 0);
            int idx = 0;
            for(int i=0; i<h; i++){
                if(s[i][j] == '1') ccost[idx]++;
                if(ccost[idx] > k) valid = false;
                if(bit & (1 << i)) idx++;
            }

            bool cut = false;
            for(int i=0; i<row; i++){
                if(psum[i] + ccost[i] > k) cut = true;
            }

            if(cut){
                sum++;
                for(int i=0; i<row; i++) psum[i] = ccost[i];
            }
            else{
                for(int i=0; i<row; i++) psum[i] += ccost[i];
            }
        }

        if(valid) chmin(ans, sum);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;

immutable int INF = 1 << 29;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto H = readln.split.map!(to!int).array;
    auto G = new int[][](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        auto u = s[0] - 1;
        auto v = s[1] - 1;
        G[u] ~= v;
        G[v] ~= u;
    }

    int ans = 0;
    foreach (i; 0..N) {
        if (G[i].map!(j => H[j] < H[i]).all) {
            ans += 1;
        }
    }

    ans.writeln;
}


Measured memory_bytes: 15204
#include <cmath>
#include <cstdio>
int a, b, c; double d, s, l, f, h, t;
int main() {
	scanf("%d%d%d", &a, &b, &c);
	d = 1.0 * c / 180.0 * 3.14159265358979;
	h = b * sin(d);
	f = sqrt(b * b - h * h);
	t = a + (c > 90 ? 1.0 : -1.0) * f;
	s = a * h / 2.0;
	l = a + b + sqrt(t * t + h * h);
	printf("%.9f\n", s);
	printf("%.9f\n", l);
	printf("%.9f\n", h);
	return 0;
}

Measured memory_bytes: 2800
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
  int a,b,n;
  int  sum,p,s;
  while( scanf("%d%d%d",&a,&b,&n) != EOF ){
  sum = 0;
  a%=b;
 
  for(int i = 0 ; i < n ; i++){
    a = a*10;
    sum += a/b;
    a = a%b;
  }
  cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
a.sort()

for i in range(len(a)):
    if i % 2 == 0:
        alice += a.pop()
    else:
        bob += a.pop()

print(alice - bob)


Measured memory_bytes: 9076
// Prime Numbers
#include <stdio.h>

int primeNumber(int);

int main(){
  int n, i, A[10000], count=0;
    
  scanf("%d", &n);
  for(i=0; i < n; i++){
    scanf("%d", &A[i]);
    if(primeNumber(A[i]) == 1)count++;
  }
  printf("%d\n", count);
  
  return 0;
}

int primeNumber(int x){
  int i;
  if(x == 2)return 1;
  if(x % 2 == 0)return 0;
  
  for(i=3; i*i <= x; i+=2){
    if(x % i == 0)return 0;
  }
  return 1;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
 
using namespace std;
 
#define EPS 1e-10
#define INF 1e9
#define equal(a,b) (fabs(a-b) < EPS)
 
struct Point{
    double x,y;
 
    Point(){}
    Point(double x,double y) : x(x),y(y) {}
 
    Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
    Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
    Point operator * (const double &k)const{ return Point(x*k,y*k); }
    Point operator / (const double &k)const{ return Point(x/k,y/k); }
    bool operator < (const Point &p)const{ return x != p.x ? x < p.x : y < p.y; }
};
 
double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double dist(const Point &a,const Point &b){
    return sqrt(pow(a.x-b.x,2) + pow(a.y-b.y,2));
}
 
istream &operator >> (istream &is,Point &p){
    return is >> p.x >> p.y;
}
 
typedef Point Vector;
 
struct Segment{
    Point s,t;
    Segment(){}
    Segment(Point s,Point t) : s(s),t(t) {}
};
 
bool isParallelSS(const Segment &s1,const Segment &s2){
    Vector a = s1.t-s1.s;
    Vector b = s2.t-s2.s;
    return equal(cross(a,b),0);
}
 
Point getPoint(vector<Point> &p,int N){
    for(int i = 0 ; i < N/2 ; i++){
	Segment a = Segment(p[i],p[i+1]);
	Segment b = Segment(p[N/2+i],p[(N/2+i+1)%N]);
	if(!isParallelSS(a,b)) return Point(INF,INF);
	if(!equal(dist(a.s,a.t),dist(b.s,b.t))){
	    return Point(INF,INF);
	}
    }
    return (p[0]+p[N/2])/2;
}
 
int main(){
    int N;
    cin >> N;
    vector<Point> p(N);
    for(int i = 0 ; i < N ; i++){
	cin >> p[i];
    }
    if(N&1){
	cout << "NA" << endl;
    }else{
	Point res = getPoint(p,N);
	if(res.x == INF && res.y == INF){
	    cout << "NA" << endl;
	}else{
	    printf("%.8f %.8f\n",res.x,res.y);
	}
    }
    return 0;
}

Measured memory_bytes: 3264
var input = ""
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
 
process.stdin.on('end', function() {
  input = input.split("\n");
  arr = input[1].split(" ");
  
  min = Math.min.apply(null, arr)
  max = Math.max.apply(null, arr)
  sum = 0
  for (var i = 0; i < arr.length; ++i) {
    sum += Number(arr[i]);
  }

  console.log(min + " " + max + " " + sum);
});

Measured memory_bytes: 9428
#include<cstdio>
using namespace std;
int j,n,i;
char s[105],t[105];
int main()
{
	scanf("%d%s%s",&n,s,t);
	for(i=n-1;i>=0;i--)
	{
		for(j=i;j>=0;j--)if(t[j]!=s[n-1+j-i])break;
		if(j==-1)
		{
			printf("%d\n",2*n-i-1);
			return 0;
		}
	}
	printf("%d\n",2*n);
	return 0;
}

Measured memory_bytes: 128
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (s, w) = scan "%d %d" Tuple2.make

let () =
  (if s <= w then "unsafe" else "safe")
  |>  Printf.printf "%s\n"


Measured memory_bytes: 5404
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (x, y) = listOfInt()
    println(x + y/2)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt()= listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 35952
def solve(asum, a, ans):
    for i in range(1, n):
        # print(asum)
        asumplus = asum + a[i]
        if asumplus == 0 and asum > 0:
            asumplus -= 1
            ans += 1
        elif asumplus == 0 and asum < 0:
            asumplus -= 1
            ans += 1
        elif asumplus > 0 and asum > 0:
            ans += asumplus + 1
            asumplus = -1
        elif asumplus < 0 and asum < 0:
            ans += -asumplus + 1
            asumplus = 1
        asum = asumplus
    return ans

n = int(input())
a = list(map(int,input().split()))
asum = a[0]
if asum > 0:
    ans = min(solve(asum,a,0),solve(-1,a,asum+1))
elif asum < 0:
    ans = min(solve(asum,a,0),solve(1,a,1-asum))
else:
    ans = min(solve(1,a,1),solve(-1,a,1))
print(ans)


Measured memory_bytes: 14468
#include<bits/stdc++.h>
#define PI 3.141592653589793238
using namespace std;

int main(){
    int a,b;cin>>a>>b;
    int h,m;cin>>h>>m;
     double angle_minute_hand=6*m;
     double angle_hour_hand=30*h + 0.5*m;
     double angle=max(angle_minute_hand,angle_hour_hand)-min(angle_minute_hand,angle_hour_hand);
    if(angle>180){
        angle=360-angle;
    }
    if(angle==180){
        printf("%.10f", (double)a+b);
        return 0;
    }
    if(angle==0){
        printf("%.10f", (double)abs(a-b));
        return 0;
    }
     double dist=sqrt((a*a)+(b*b)-2*a*b*cos(angle*PI/180));
    printf("%.10f",dist);
}


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

using namespace std;
#define ll long long 

int main(){
	
	ll n,W;
	cin>>n>>W;
	ll wt[n],value[n];
	for (ll i=0;i<n;i++){
		cin>>wt[i]>>value[i];
	}
	ll dp[n+1][W+1];
	for (ll i=0;i<=n;i++){
		for (ll w=0;w<=W;w++){
			if (i==0||w==0){
				dp[i][w]=0;
			}
			else if (wt[i-1]<=w){
				dp[i][w]=max(dp[i-1][w],dp[i-1][w-wt[i-1]]+value[i-1]);
			}
			else {
				dp[i][w]=dp[i-1][w];
			}
		}
	}
//	for (ll i=0;i<=n;i++){
//		for (ll w=0;w<=W;w++){
//			cout<<dp[i][w]<<" ";
//		}
//		cout<<endl;
//	}
	cout<<dp[n][W];
	
}

Measured memory_bytes: 82516
n,m,x = map(int,input().split())
a =list(map(int,input().split()))
c1 = 0
c2 = 0
for i in range(x):
  if i in a:
    c1 += 1
for i in range(x,n):
  if i in a:
    c2 += 1
print(min(c1,c2))
  


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
	int n,k=0;
	double w,h;
	while(scanf("%d,%lf,%lf",&n,&w,&h)!=EOF){
		if(25*h*h<=w){k=1;printf("%d\n",n);}
	}
	if(k==0)printf("該当なし\n");
	return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9+3;
const ll INF = 1e18;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct edge{int to; ll sum;};

const int MAX_V = 1e5;
vector<edge> es[MAX_V];
ll x = INF;
ll num[MAX_V], dig[MAX_V];
vector<bool> used(MAX_V, false);

void add_edge(int u, int v, ll sum){
    es[u].eb((edge){v, sum}), es[v].eb((edge){u, sum});
}

void dfs(int now, int pre){
    for(auto &e: es[now]){
        if(x != INF) break;
        if(e.to == pre) continue;
        if(!used[e.to]){
            num[e.to] = e.sum-num[now];
            dig[e.to] = -dig[now];
            used[e.to] = true;
            dfs(e.to, now);
        }
        else{
            if(dig[e.to] != dig[now]){
                if(num[e.to]+num[now] == e.sum) continue;
                else x = -1;
            }
            elif(dig[e.to] == 1){
                ll y = e.sum-(num[e.to]+num[now]);
                if(y > 0 && y%2 == 0) x = y/2;
                else x = -1;
            }
            else{
                ll y = num[e.to]+num[now]-e.sum;
                if(y > 0 && y%2 == 0) x = y/2;
                else x = -1;
            }
        }
    }
}

int flag = 1;

void dfs2(int now){
    used[now] = true;
    for(auto &e: es[now]){
        if(used[e.to]){
            if(num[now]+num[e.to] != e.sum) flag = 0;
        }
        else{
            num[e.to] = e.sum-num[now];
            if(num[e.to] <= 0) flag = 0;
            dfs2(e.to);
        }
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    rep(i, M){
        int u, v; ll s;
        cin >> u >> v >> s; u--, v--;
        add_edge(u, v, s);
    }
    num[0] = 0, dig[0] = 1, used[0] = true;
    dfs(0, -1);
    if(x <= 0) {cout << 0 << endl; return 0;}
    elif(x != INF){
        fill(all(used), false);
        num[0] = x;
        dfs2(0);
        cout << flag << endl;
        return 0;
    }
    ll l = INF, r = INF;
    rep(i, N){
        if(dig[i] == 1) chmin(l, num[i]);
        else chmin(r, num[i]);
    }
    l *= -1;
    cout << max(r-l-1, 0LL) << endl;
}

Measured memory_bytes: 15616
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define up(a,b) (((a)%(b)==0)?((a)/(b)):((a)/(b))+1)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;

ll mymod(ll a, ll b)
{
	return (a%b + b)%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}
struct vertex
{
	vll adj;
};
void dfs(ll i,vertex V[], bool vis[], ll dist[])
{
	vis[i]=true;
	//cout<<i<<" ke liye\n";
	for(auto x : V[i].adj)
	{
		if(!vis[x])
		{
			dfs(x,V,vis,dist);
		}
		dist[i]=max(dist[i],1+dist[x]);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll A[n+1];
    REP(i,0,n)
    {
        cin>>A[i];
    }
    ll dp[n+1][k+1]; //dp[i][j] = number of ways to distribute j candies among the first i people
    ll pre[k+1];
    dp[0][0]=1;
    pre[0]=1;
    REP(i,1,k+1)
    {
        dp[0][i]=0;
        pre[i]=dp[0][i]+pre[i-1];
    }
    REP(i,1,n+1)
    {
        REP(j,0,k+1)
        {
            if(j>A[i-1])
            {
                dp[i][j] = pre[j] - pre[j-A[i-1]-1];
            }
            else
            {
                dp[i][j] = pre[j];
            }
            dp[i][j] = mymod(dp[i][j],num);
        }
        pre[0]=dp[i][0];
        REP(j,1,k+1)
        {
            pre[j]=dp[i][j]+pre[j-1];
        }
    }
    cout<<dp[n][k]<<endl;
	return 0;
}




Measured memory_bytes: 80000
# frozen_string_literal: true

n = gets.to_i
m = gets.split.map(&:to_i)
m.sort!
 i = 1
cnt= 0
sum = 0
m.each do |k|
    if k == i
    cnt += 1 
else
i <= cnt ? sum += (cnt - i) : sum += cnt
cnt = 1
i = k
end
end
i <= cnt ? sum += (cnt - i) : sum += cnt
puts sum

Measured memory_bytes: 9336
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

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

int main()
{
    ll n;
    cin >> n;
    ll h;
    cin >> h;
    ll pre = h;
    ll down = 0;
    bool flag = true;
    for (int i = 1; i < n; i++)
    {
        cin >> h;
        down = seinomi(down + (pre - h));
        pre = h;
        if (down > 1)
        {
            cout << "No" << endl;
            flag = false;
            break;
        }
    }
    if (flag)
    {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)


Measured memory_bytes: 3060
#!/usr/bin/env php
<?php
if (basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {

	$n = 0;
	$m = 0;
	$line = fgets(STDIN);
  {
    $tokens = explode(' ', $line);
    $n = intval($tokens[0]);
    $m = intval($tokens[1]);
  }

    for ($i = 1; $i <= $n; $i++) {
    	$arr[$i] = 0;
    }


  while ($line = fgets(STDIN)) {
  	$tokens = explode(' ', $line);

  	$num1 = intval($tokens[0]);
    $num2 = intval($tokens[1]);

    	$arr[$num1] = $arr[$num1] + 1;
    	$arr[$num2] = $arr[$num2] + 1;

  }

  for ($i = 1; $i <= $n; $i++) {
  	if (isset($arr[$i])) {
        echo($arr[$i]);
  	} else {
  		echo ('0');
  	}
  	echo(PHP_EOL);
  }
}
?>

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

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

    for (int i = 0; 2 * i < s.size(); i++){
        cout << s.at(2 * i);
    }
    cout << "\n";
    return 0;
}

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

int main() {
	int a,b,c,k;
	scanf("%d %d %d %d",&a,&b,&c,&k);
	if (k <= a + b) {
		if (k >= a)
		{
			printf("%d",a);
		} else
		{
			printf("%d",k);
		}
	}else
	{
		printf("%d",a - (k - a - b));
	}	
}

Measured memory_bytes: 1728
#include<stdio.h>
#include<math.h>
int main()
{
	double x,h;
	double sei;
	double s,san,tai,hen;
do{
	scanf("%lf%lf",&x,&h);
	if(x==0 && h==0)break;
	sei=x*x;
	tai=(double)x/2;
	hen=tai*tai+h*h;
	hen=sqrt(hen);
	san=(double)hen*x/2;
	s=4*san+sei;
	printf("%0.6f\n",s);
}while(1);
return 0;
}

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

int main() {
   long long a,atleast,ans;
   cin >> a;
   atleast = a-1;
   for(long long i=2; i*i <=a; i++){
		if(a%i==0){
			ans = a/i;
			atleast = min(atleast,ans+i-2);
		}
	}
	cout << atleast << "\n";
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define N 105
using namespace std;

int n, x[N], y[N];
double mx, PI = acos(-1), a[N];
int main()
{
	int i, j, k;
	cin >> n;
	for (i = 0; i < n; i++) scanf("%d %d", &x[i], &y[i]);
	for (i = 0; i < n; i++) {
		for (j = k = 0; j < n; j++) {
			if (i == j) continue;
			a[k++] = atan2(y[j] - y[i], x[j] - x[i]);
		}
		sort(a, a + k);
		mx = 2 * PI - a[k - 1] + a[0];
		for (j = 1; j < k; j++) mx = max(mx, a[j] - a[j - 1]);
		printf("%.9f\n", max(0.0, (mx - PI)) / (2 * PI));
	}
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
long double EPS=1E-8;
////////////////////////////////////////
#define MAX_V 500000
#define MAX_LOGV 30
vector<int>G[MAX_V];
int root;//根ノード
int parent[MAX_LOGV][MAX_V];//親を2^k回辿って到達する頂点(根を通り過ぎる場合は-1)
int depth[MAX_V];
void dfs(int v,int p,int d){
    parent[0][v]=p;
    depth[v]=d;
    for(auto x:G[v]){
        if(x!=p)dfs(x,v,d+1);
    }
}
void init(int V){
    //parent[0]とdepthを初期化
    dfs(root,-1,0);
    //parentを初期化
    rep(k,0,MAX_LOGV-2){
        rep(v,0,V-1){
            if(parent[k][v]<0)parent[k+1][v]=-1;
            else parent[k+1][v]=parent[k][parent[k][v]];
        }
    }
}
//uとvのLCAを求める
int lca(int u,int v){
    //uとvの深さが同じになるまで親をたどる
    if(depth[u]>depth[v])swap(u,v);
    rep(k,0,MAX_LOGV-2){
        if((depth[v]-depth[u])>>k&1){
            v=parent[k][v];
        }
    }
    if(u==v)return u;
    for(int k=MAX_LOGV-1;k>=0;k--){
        if(parent[k][u]!=parent[k][v]){
            u=parent[k][u];
            v=parent[k][v];
        }
    }
    return parent[0][u];
}

////////////////////////////////////////
int main(){
    int n;cin>>n;
    rep(i,0,n-1){
        int s;cin>>s;
        rep(j,1,s){
            int c;cin>>c;G[i].pb(c);
            G[c].pb(i);
        }
    }
    
    init(n);
    int q;cin>>q;
    while(q--){
        ll a,b;cin>>a>>b;
        cout<<lca(a,b)<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 34828
module Main where

import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [a, b, c, d] <- fmap read . words <$> getLine :: IO [Int]
    let x = max a c
    let y = min b d
    if y - x >= 0
        then print (y - x)
        else print 0

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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}

void dfs(int i,int vis[],vi adj[],vector<int> &ans)
{
    if(vis[i])
        return;
    vis[i]=1;
    for(auto a:adj[i]){
        if(!vis[a]){
            dfs(a,vis,adj,ans);
        }
    }
    ans.pb(i);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int t=1;
	//cin>>t;
	//SieveOfEratosthenes(1000000);
    while(t--){
        int n,m;
        cin>>n>>m;
        vi adj[100001];
        int vis[100001]={0};
        vi adjinv[100001];
        for(int i=0;i<m;i++){
            int x,y;
            cin>>x>>y;
            adj[x].pb(y);
            adjinv[y].pb(x);
        }
        vector<int> topo;
        for(int i=1;i<=n;i++){
            if(!vis[i])
                dfs(i,vis,adj,topo);
        }
        
        int dp[n+1]={0};
        for(int i=0;i<n;i++){
            for(auto a:adjinv[topo[i]])
                dp[a]=max(dp[a],dp[topo[i]]+1);
        }
        int mx=0;
        for(int i=1;i<=n;i++){
            mx=max(mx,dp[i]);
        }
        cout<<mx<<'\n';
    }
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

map<i64, i64> memo;
i64 a, b, c, d;

i64 dp(i64 n) {
    if (n < 0) return 1e18;

    if (n == 0) return 0;
    if (memo.count(n)) return memo[n];
    i64 &res = memo[n];
    res = 1e18;
    if (abs(n) < 2e9) res = abs(n) * d;

    fore(delta, -4, 4) {
        i64 x = n + delta;
       
        if (x % 2 == 0) uin(res, dp(x / 2) + a + abs(delta) * d);
        if (x % 3 == 0) uin(res, dp(x / 3) + b + abs(delta) * d);
        if (x % 5 == 0) uin(res, dp(x / 5) + c + abs(delta) * d);
    }
    return memo[n] = res;
}

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

   // freopen("input.txt", "r", stdin);


    int T;
    cin >> T;
    while (T--) {
        i64 n;
        cin >> n >> a >> b >> c >> d;
        memo.clear();
        cout << dp(n) << '\n';
    }

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int64_t cnt=1;
  for(int i=1;i<=N;i++){
    cnt*=i;
    if(cnt>1000000007){
      cnt%=1000000007;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3536
#include <stdio.h>
int main(void)
{
  int buil[4][3][10] = {};
  int i, j, k, n, b, f, r,v;

  scanf("%d", &n);
  while (n--) {
    scanf("%d%d%d%d", &b, &f, &r, &v);
    buil[b-1][f-1][r-1] += v;
  }
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 3; j++) {
      for (k = 0; k < 10; k++) {
        printf(" %d", buil[i][j][k]);
      }
      putchar('\n');
    }
    if (i != 3) printf("####################\n");
  }
  return 0;
}

Measured memory_bytes: 612
gcd = lambda a, b: a if b == 0 else gcd(b, a % b)
N = int(input())
A = list(map(int, input().split()))
if A[0] < A[1]:
    tmp = A[0]
    A[0] = A[1]
    A[1] = tmp
c = gcd(A[0], A[1])
for i in range(2, N):
    if c < A[i]:
        tmp = c
        c = A[i]
        A[i] = tmp
    c = gcd(c, A[i])
print(c)

Measured memory_bytes: 14252
from collections import defaultdict
def solve():
    N = int(input())
    A = list(map(int, input().split()))

    counter = defaultdict(int)

    for i in range(N):
        counter[A[i]] += 1
    
    res = 0
    for i in range(N+1):
        res += counter[i] * (counter[i] - 1) / 2
    
    for i in range(N):
        val = counter[A[i]]
        before = val * (val-1)/2
        after = (val - 1) * (val - 2) / 2
        print(int(res + after - before))

if __name__ == '__main__':
    solve()

Measured memory_bytes: 100684
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;typedef vector<ll> vll;
ll mod = 1000000007, INF = 10000000000000000;
ll gcd(ll a, ll b){if(b==0){return a;}return gcd(b, a%b);}
// for (ll i = 0; i < n; i++) {
// sort(.begin(), .end());
int main(){
  ll n;
  cin >> n;
  vll b(34, -1);
  for (ll i = 1; i <= 34; i++) {
    ll k = pow(2,i);
    if (n % k != 0) {
      b[34-i] = 1;
      n -= pow(-2,i-1);
    }
    else {
      b[34-i] = 0;
    }
    if (n == 0) {
      break;
    }
  }
  for (ll i = 0; i < 34; i++) {
    if (b[i] != -1) {
      cout << b[i];
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(10**9)

dx = [1,1,0,-1,-1,-1,0,1]
dy = [0,-1,-1,-1,0,1,1,1]
  
def DFS(y,x):
  if table[y][x] == 0:
    return
  table[y][x] = 0
  for i in range(8):
    nx = x + dx[i]
    ny = y + dy[i]
    if 0<=ny<h and 0<=nx<w:
      DFS(ny, nx)
while True:  
  w, h = map(int, input().split())
  if w == 0 and h == 0:
    exit()
  table = []
  ans = 0
  for i in range(h):
    c = list(map(int, input().split()))
    table.append(c)
  for y in range(h):
    for x in range(w):
      if table[y][x] == 1:
        ans += 1
        DFS(y,x)
  print(ans)


Measured memory_bytes: 8308
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void prime_function(vector<int> &ans)
{
    int n=1e6+1;
    vector<int> prime(n+1,0);
    prime[2]=0;
    for(int i=4;i<n;i+=2)
        prime[i]=1;
    for(int i=3;i*i<n;i+=2)
    {
        if(prime[i]==0)
        {
            for(int j=i+i;j<n;j+=i)
                prime[j]=1;
        }
    }
    for(int i=2;i<n;i++)
        if(prime[i]==0)
            ans.push_back(i);
}
void solve()
{
    int n;
    cin>>n;
    vector<int> ans;
    prime_function(ans);
    cout<<*lower_bound(ans.begin(),ans.end(),n);
}
int32_t main()
{
    // clock_t tStart = clock();
    // #ifndef ONLINE_JUDGE
    // _READ
    // #endif
    
    int t;
    t=1;
    while(t--)
        solve();
    
    // #ifndef ONLINE_JUDGE
    // cout<<fixed<<setprecision(5)<<"\nTime taken: "<<(double)(clock() - tStart)/CLOCKS_PER_SEC;
    // #endif
    
    return 0;
}
/*
===FOR N-Dimensional Vector===
https://codeforces.com/blog/entry/76149
g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined a.cpp -o a -D_GLIBCXX_DEBUG
*/

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

using namespace std;

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

	string t;
	getline(cin, t);

	double money = 0;
	while (N--) {
		string x, v;
		getline(cin, x, ' ');
		getline(cin, v);

		if (v == "JPY") {
			money += stoi(x);
		} else if (v == "BTC") {
			money += stod(x) * 380000;
		} else {
			// ???
		}
	}
	cout << fixed << money;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string>
#include<cmath>
#include<vector>
//最小公倍数
int gcd(int m, int n){
 int M=m,N=n; 

    int temp;
    while(m%n!=0){
        temp=n;
        n=m%n;
        m=temp;
    }
    return (int)n;
 }


int main(void){
    int k;
    long long int ans=0;
    scanf("%d",&k);
    for(int m=1;m<=k;m++){
        for(int n=1;n<=m;n++){
            for(int s=1;s<=n;s++){
                int pre=gcd(gcd(m,n),s);
                if((m==n)||(n==s)){
                    if(m==s){
                        ans+=pre;
                    }else{
                        ans+=pre*3;
                    }
                }else{
                    ans+=pre*=6;
                }
            }
        }
    }
    printf("%lld",ans);
      
}

Measured memory_bytes: 1736
#include <iostream>
#include <string>

using namespace std;

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int count;

  for(int a=0;a<A+1;a++) {
    for (int b=0;b<B+1;b++) {
      for (int c=0;c<C+1;c++) {
        int x = 500 * a + 100 * b + 50 * c;
        if (x == X) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

//Ｏ(log(max(a,b))
//aとbの最大公約数
int gcd(lint a,lint b){
  if(b==0)return a;
  return gcd(b,a%b);
}

//aとbの最小公倍数
int lcm(lint a,lint b){
  int x=gcd(a,b);
  return (a/x)*b;
}


signed main(){
  int N;cin>>N;

  int ans;cin>>ans;
  for(int i=1;i<N;i++){
    int t;cin>>t;
    ans=lcm(ans,t);
  }

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


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	SINT64 N = 0;

	cin >> N;

	vector<SINT64> DATA(N+1);

	DATA[0] = 2;
	DATA[1] = 1;
	
	rep(i,2,N+1) {
		DATA[i] = DATA[i-1] + DATA[i-2];
	}

	cout << DATA[N] << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

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

fn main() {
    let x = read::<usize>();

    let mut ans = 0;

    ans += x / 500 * 1000;
    ans += (x % 500) / 5 * 5;

    println!("{}", ans);
}

Measured memory_bytes: 4352