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

long long GCD(long long a,long long b){//最大公約数
    while(b!=0){
        long long r=a%b;
        a=b;
        b=r;
    }
    return(a);
}

long long LCM(long long a,long long b){//最小公倍数
    return(a/GCD(a,b)*b);
}

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

    int n;
    cin>>n;

    long long ans=1;
    for(int i=1;i<=n;i++){
        long long t;
        cin>>t;
        ans=LCM(ans,t);
    }

    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e3 + 6;

typedef tuple<int,int,int> tp;
int ara[N][N] , dist[N][N];
int dx[] = {0 , 0 , 1 , -1};
int dy[] = {1 , -1 , 0 , 0};

int n , m;

// int ddx[] = {-2 , -2, -2, -2, -2 , 2 ,2 ,2 ,2 , 2 , -1, -1, 0 , 0 , 1 ,1 ,   -1, -1, -1 , 0 , 0 , 1 , 1 ,1  };
// int ddy[] = {-2, -1 , 0 , 1 , 2 , -2 , -1 , 0 , 1 , 2 , 2 ,2 ,2 ,2 ,2 , 2 ,   -1 , 0 , 1 , 1 , -1 , -1 , 0 , 1 };

int ok(int x, int y) {
    return (x>=0 && x< n && y >=0 && y < m && ara[x][y] !=-1);
}

int main()  {
    fastio;
    
    int x1 , y1;
    int x2 , y2;
    cin>>n>>m>>x1>>y1>>x2>>y2;
    x1--,y1--,x2--,y2--;

    for(int i = 0 ; i < n ; i++ ) {
        string s;
        cin>>s;
        for(int j =0 ; j < m ; j++ ) {
            if(s[j] == '#') ara[i][j] = -1;
            dist[i][j] = INF;
        }
    }

    dist[x1][y1] = 0;
    priority_queue<tp, vector<tp> , greater<tp> >pq;

    pq.push({0 , x1 , y1});

    while(!pq.empty()) {
        int d , x , y;
        tie(d , x , y) = pq.top();
        pq.pop();

        if(d != dist[x][y]) continue;

        for(int i =0 ; i < 4 ; i++ ) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if(ok(xx, yy) && dist[xx][yy] > d ) {
                dist[xx][yy] = d;
                pq.push({d , xx , yy});
            }
        }
        for(int ddx = -2 ; ddx <= 2 ; ddx ++) {
            for(int ddy = -2 ; ddy <=2 ; ddy ++) {
                int xx = x + ddx;
                int yy = y + ddy;
                if(ok(xx, yy) && dist[xx][yy] > d + 1) {
                    dist[xx][yy] = d+1;
                    pq.push({d+1 , xx , yy});
                }
            }
        }
\
    }
    if(dist[x2][y2] == INF) cout<<-1<<'\n';
    else cout<<dist[x2][y2]<<'\n';

    
    return 0;
    
}

Measured memory_bytes: 11576
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, a, b;
  cin >> n >> a >> b;
  int orig_n = n;
  bool flg = (a>b);
  if (flg) swap(a, b);
  vector< int > ans;
  int bottom = 1, top = n;
  while (n > 0) {
    if (a<=0 || b<=0) {
      /*
      cerr << "zero" << endl;
      for (int i=0; i<ans.size(); ++i) cerr << ans[i] << " ";
      cerr << endl;
      */
      cout << -1 << endl;
      return 0;
    }
    if (a+b > n+1) {
      if (ans.size() == 0) {
        //cerr << "larger" << endl;
        cout << -1 << endl;
        return 0;
      }
      for (int i=max(bottom, top-a+1); i<=top; ++i) ans.push_back(i);
      for (int i=top-a; i>=bottom; --i) ans.push_back(i);
      break;
    }
    /*
    if (a+b == n+1) {
      for (int i=0; i<a; ++i) {
        ans.push_back(top-a+i+1);
      }
      for (int i=1; i<b; ++i) {
        ans.push_back(b-i+bottom-1);
      }
      break;
    }
    */
    for (int i=top-a+1; i<=top; ++i) ans.push_back(i);
    for (int i=bottom+b-2; i>=bottom; --i) ans.push_back(i);
    n-=(a+b-1);
    top-=a; bottom+=b-1;
    a--; b--;
  }
  for (int i=0; i<ans.size(); ++i) cout << (flg ? orig_n+1-ans[i] : ans[i]) << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 3568
#include <stdio.h>
#include <math.h>

int main()
{
    int a, b, c;
    double s, l, h, d, rad;
    const double PI = 4 * atan(1);
    scanf("%d%d%d", &a, &b, &c);
    rad = PI * c / 180;
    s = a * b * sin(rad) / 2; 
    d = sqrt(a*a + b*b - 2*a*b*cos(rad));
    l = a + b + d;
    h = b*sin(rad);

    printf("%.6lf\n", s);
    printf("%.6lf\n", l);
    printf("%.6lf\n", h);
    return 0;
}


Measured memory_bytes: 2060
h,w = map(int,input().split())
map1 = []
map1.append([("n") for _ in range(w+1)])
for _ in range(h):
	map1.extend([list("n"+input())])

check_board = [[0]*(w+1) for _ in range(h+1)]

def cal_ans(a,b,x,y):
	return ((map1[a][b]^map1[x][y])&map1[x][y])+check_board[a][b]

for x in range(h+1):
	for y in range(w+1):
		if map1[x][y] == "#":
			map1[x][y] = 1
		else:
			if map1[x][y] == "n":
				check_board[x][y] = 3000
			map1[x][y] = 0
for x in range(1,h+1):
	for y in range(1,w+1):
		if x == 1 and y == 1:
			if map1[x][y] == 1:
				check_board[x][y] = 1
			continue
		check_board[x][y] = min(cal_ans(x-1,y,x,y),cal_ans(x,y-1,x,y))
print(check_board[h][w])


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;
typedef long long LL;
char s[maxn];
int cnt[256], n;
LL ans;
bool check(int i, int j) {
        ans = 0;
        for (; i>=0, j<n; ) {
            if (s[i]==s[j]) {--i, ++j; continue; }
            if (s[i]!='x'&&s[j]!='x') return 0;
            if (s[i]=='x') ++ans, --i;
            else if (s[j]=='x') ++ans, ++j;
        }
        if (i==-1) {
            ans += n-j;
            for (; j < n; ++j) if (s[j]!='x') {return 0; }
        }
        if (j==n) {
            ans += i+1;
            for (; i >= 0; --i) if (s[i]!='x') { return 0; }
        }
        return 1;
}
//struct node {
//    char ch;
//    int cnt;
//}a[maxn], b[maxn];
//bool check(int i, int j) {
//    int cnt1 = 0, cnt2 = 0, tot1 = 0, tot2 = 0;
//    for (; i >= 0; --i) {
//        if (s[i] == 'x') ++cnt1;
//        else a[tot1++] = {s[i],cnt1}, cnt1 = 0;
//    }
//    for (; j < n; ++j) {
//        if (s[j] == 'x') ++cnt2;
//        else b[tot2++] = {s[j],cnt2}, cnt2 = 0;
//    }
//    if (tot1 != tot2) return false;
//    ans = 0;
//    for (int i = 0; i < tot1; ++i) {
//        if (a[i].ch != b[i].ch) return false;
//        ans += abs(a[i].cnt-b[i].cnt);
//    }
//    ans += abs(cnt1-cnt2);
//    return true;
//}
int main() {
    scanf("%s", s);
    n = strlen(s);
    for (int i = 0; i < n; ++i) ++cnt[s[i]];
    char ch;
    int tot = 0, odd = 0;
    for (int i = 'a'; i <= 'z'; ++i) {
        if (i == 'x') continue;
        if (cnt[i] & 1) ++odd;
        tot += cnt[i];
    }
    if (odd > 1) { puts("-1"); return 0;}
    if (tot == 0) { puts("0"); return 0; }
    (tot /= 2) += 1;
    int cur=0, i = 0, l=0, r=0;
    for (; i < n; ++i) {
        if (s[i] != 'x') ++cur;
        if (cur == tot-1 && !r) r = i+1;
        if (cur == tot) { l = i; break; }
    }
    if (odd) r = i, l = i+1;
    if (check(r-1, l)) printf("%d\n", ans);
    else printf("-1\n");
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include <bits/stdc++.h>
using namespace std;


int main(){
    long double a;
    long double  b;

    cin >> a >> b;

    cout << (long long int)(a*b) << setprecision(18);
    cout << endl;
    
    
    return 0;

}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int niz[205];

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    ll x,k,d;
    cin >> x >> k >> d;
    ll sta = x/d;
    sta += k;
    sta /= 2;
    ll res = abs(x + d*k);
    res = min(res, abs(x - d*k));
    if(sta <= 0)sta = 0;
    for(ll i = sta-100; i <= sta + 100; i++){
        if(i < 0 || i > k)continue;
        ll a = i;
        ll tmp = abs(x + d*(k - 2*a));
        if(res < 0)res = tmp;
        else res = min(res, tmp);
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 6e18;
const int mod = 1e9 + 7;

signed main() {
    int N;
    cin >> N;
    vector<int> P(N);
    cin >> P;
    int ans = 0;
    int temp = inf;
    for (int i = 0; i < N; i++) {
        if (P[i] <= temp) ++ans;
        temp = min(temp, P[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include<sstream>
using namespace std;
int main(){
    int a,b,i;
    cin>>a>>b;
    stringstream ss;
    ss<<a;
    string s1;
    ss>>s1;
    stringstream ss2;
    ss2<<b;
    string s2,s3,s4;
    ss2>>s2;
    s3=s1;
    s4=s2;
    for (i=1;i<b;i++){
        s3.append(s1);
    }
    for(i=1;i<a;i++){
        s2.append(s4);
    }
    if (s2.size()>=s3.size())
        cout<<s2<<endl;
    if (s3.size()>s2.size())
        cout<<s3<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

long long ans=1;
int K;

bool dfs(int now, int from, vector<vector<int> > &edge, vector<bool> &used, vector<int> &cnt){
    if(used[now]==true)return false;
    used[now]=true;

    ans=ans*(K-cnt[from])%MOD;
    cnt[from]++;
    cnt[now]++;

    for(int i=0; i<(int) edge[now].size(); i++){
        dfs(edge[now][i], now, edge, used, cnt);
    }
    return true;
}

int main(){
    int N;
    cin >> N >> K;
    vector<vector<int> > edge(N,vector<int>(0));

    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        a--;b--;

        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    vector<bool> used(N,false);
    vector<int> cnt(N+1,1);
    cnt[N]=0;
    cnt[0]=0;
    dfs(0, N, edge, used, cnt);

    cout << ans << endl;
}

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

int getmd(int a,int b,int c,int d){
    return abs(a-c)+abs(b-d);
}

int main(){
    int a,p;
    cin >> a >> p;
    p += a*3;

    cout << (p/2) << endl;

    return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
  input! {
    n: usize,
    k: usize,
    mut vals: [usize;n]
  }
  vals.sort();
  
  let mut min = usize::max_value();
  let mut left = 0;
  for i in (k-1)..n {
    min = std::cmp::min(min, vals[i] - vals[left]);
    left += 1;
  }
  println!("{}", min);
}

Measured memory_bytes: 4184
#include<cstdio>
using namespace std;
int main(){
    int n,l,x,d=0,ans=1;
    scanf("%d %d",&n,&x);
    for(int i=0;i<n;i++){
        scanf("%d",&l);
        if(d+l<=x){
            ans++;
        }
        d+=l;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
int solve(vector<int> &v, int l, int r){
    int ret = 0, mx = 0;
    map<int, int> ms;
    for (int i=l; i <= r; i++){
        int dst = i-l;
        int st = v[i] - dst;
        if (st > mx){
            cout << -1;
            exit(0);
        }
        mx = min(mx, st);
        ms[st] = dst;
    }
    for (map<int, int>::iterator it = ms.begin(); it != ms.end(); it++){
        pair<int, int> p = *it;
        int val = p.first;
        int sk = p.second;
        int fin = val + sk;
        ret += fin;
    }
    return ret;

}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i=0; i < n; i++) cin >> v[i];
    int ans = 0;
    vector<int> start;
    for (int i=0; i < n; i++) if (!v[i]) start.push_back(i);
    start.push_back(n);
    if (v[0] != 0){
        cout << -1;
        return 0;
    }
    for (int i=0; i < start.size() - 1; i++){
        ans += solve(v, start[i], start[i+1] - 1);
    }
    cout << ans;

}


Measured memory_bytes: 13440
weather = [input().split() for l in range(2)]
weather_af = weather[0]
weather_bf = weather[1]
count=0

if weather_af[0][0] == weather_bf[0][0]:
    count=count+1
if weather_af[0][1] == weather_bf[0][1]:
    count=count+1
if weather_af[0][2] == weather_bf[0][2]:
    count=count+1

print(count)


Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
    int A1,A2,A3;

    scanf("%d%d%d",&A1,&A2,&A3);

    int a =A1+A2+A3;
    if(a>=22)
    {
        printf("bust\n");
    }
    else
    {
        printf("win\n");
    }

    return 0;
}


Measured memory_bytes: 128
# AOJ 0054 Sum of Nth decimal places
# Python3 2018.6.16 bal4u

while True:
	try:
		a, b, n = list(map(int, input().split()))
	except EOFError:
		break
        
	sum = 0
	a %= b
	for i in range(n):
		if a == 0: break
		a *= 10
		sum += a // b
		a %= b
	print(sum)


Measured memory_bytes: 5596
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;

ll a[100005];
int main(){
          int n, i;
          scanf("%d", &n);
          for( i=1; i<=n; i++)
             scanf("%lld", &a[i]);    
            bool check =true;
           for( i=1; i<=n; i++)
                check &=(a[i]%2ll==0);
             if(check)   printf("second");
             else printf("first");
               return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        Tree t = new Tree(n);
        List<Edge> el = new List<Edge>();
        for (int i = 0; i < n; i++)
        {
            int[] e = Console.ReadLine().Substring(1).Split(' ').Select(s => int.Parse(s)).ToArray();
            for (int j = 0; j < n; j++)
                if (e[j] != -1)
                    el.Add(new Edge(i + 1, j + 1, e[j]));
        }
        IC ic = new IC();
        el.Sort(ic);
        int ans = 0;
        foreach (var ed in el)
        {
            if (!t.IsSameSet(ed.s, ed.g))
            {
                ans += ed.length;
                t.unite(ed.s, ed.g);
            }
        }
        Console.WriteLine(ans);
    }
}
class Tree
{
    private int[] p; //頂点iの親がp[i-1]
    public Tree(int n) //コンストラクタ
    {
        p = new int[n];
        for (int i = 0; i < n; i++) p[i] = i + 1;
    }
    public int GetParent(int a) //aの親を返す
    {
        return p[a - 1];
    }
    public void SetParent(int a, int b) //aの親をbに設定
    {
        p[a - 1] = b;
    }
    public int root(int a) //aのrootを求め、aの親にする
    {
        if (p[a - 1] == a) return a;
        return (p[a - 1] = root(p[a - 1]));
    }
    public bool IsSameSet(int a, int b) //aとbが同一グループに属するか
    {
        return root(a) == root(b);
    }
    public void unite(int a, int b) //aとbを同一グループにまとめる
    {
        p[root(a) - 1] = root(b);
    }
}
class IC : IComparer<Edge>
{
    public int Compare(Edge e1, Edge e2)
    {
        return e1.length - e2.length;
    }
}
class Edge
{
    public int s;
    public int g;
    public int length;
    public Edge(int s, int g, int length)
    {
        this.s = s;
        this.g = g;
        this.length = length;
    }
}


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

long long A[100001], B[100001];
map<pair<long long, long long>, int> black;

int main(){
  int H,W,N;
  cin >> H >> W >> N;
  int dx[] = {-1,-1,-1,0,0,0,1,1,1};
  int dy[] = {-1,0,1,-1,0,1,-1,0,1};
  for(int i=0; i<N; i++){
    cin >> A[i] >> B[i];
    A[i] = A[i]-1;
    B[i] = B[i]-1;
    for(int d=0; d<9; d++){
      long long x = A[i]+dx[d];
      long long y = B[i]+dy[d];
      if(0<x&&x<H-1&&0<y&&y<W-1){
        black[make_pair(x,y)]++;
      }
    }
  }

  long long res[10];
  res[0] = (H-2)*(W-2);
  for(int i=1; i<10; i++) res[i] = 0;
  for(auto i=black.begin(); i!=black.end(); i++){
    if(i->first.first==0||i->first.first==H-1||
       i->first.second==0||i->first.second==W-1) continue;
    int n=i->second;
    if(n > 9) cout << "Too many!" << endl;
    if(n < 1) cout << "Too small!" << endl;
    res[n]++;
  }

  for(int i=1; i<10; i++){
    res[0] -= res[i];
  }
  for(int i=0; i<10; i++){
    cout << res[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 58112
N, X, Y = map(int, input().split())
d = {}


for i in range(1, N):
    for j in range(i+1, N+1):
        m = min(j-i, abs(X-i) + 1 + abs(Y-j))
        if d.get(m) is None:
            d[m] = 1
        else:
            d[m] += 1

for i in range(1, N):
    if d.get(i) is None:
        print(0)
    else:
        print(d[i])

Measured memory_bytes: 3572
#include<stdio.h>
#include<string.h>
int main(void){

    char N[2];
//文字列の読込
    scanf("%s",N);

    char str1[] = "9";
    //一致しない場合はNULL
    if(strstr(N,str1)!=NULL)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (auto&& e : b) cin >> e;
  int ans = b[0] + b[n - 2];
  for (int i = 0; i < n - 2; i++) {
    ans += min(b[i], b[i + 1]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    List<int>[] es;

    void calc()
    {
        cin = new Scanner();
        long N = cin.nextLong();
        int num = 1;
        while ((1L << (num + 1)) - 1 <= N)
        {
            num++;
        }

        N -= (1L << num) - 1;
        
        int next = num + 1;
        List<int>[] pos = new List<int>[num + 1];
        for (int i = 0; i < num + 1; i++)
        {
            pos[i] = new List<int>();
        }

        for (int i = num; i >= 0; i--)
        {
            long plus = 1 + (1L << i) - 1;
            while (plus <= N)
            {
                pos[i].Add(next++);
                N -= plus;
            }
        }

        List<int> ans = new List<int>();
        for (int i = 0; i < next - 1; i++)
        {
            ans.Add(i + 1);
        }

        for (int i = 0; i < num; i++)
        {
            for (int j = pos[i].Count - 1; j >= 0; j--)
            {
                ans.Add(pos[i][j]);
            }
            ans.Add(i + 1);
        }

        Console.WriteLine(ans.Count);
        Console.WriteLine(string.Join(" ", ans));


    }
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;


ve<vi> A;


struct edge { int to, cost; };
struct dijkstra {
    vector<vector<edge>> g;
    vector<int> d;
    vector<int> from_v;
    int V;
    
    dijkstra(int v){
        V = v;
        d.resize(V);
        g.resize(V);
        from_v.assign(V,-1);
    }
    
    void solve_d(int s){
        from_v[s] = s;
        pq1<pii> que;
        rep(i,V) d[i] = infi;
        d[s] = 0;
        que.push({0,s});
        
        while (!que.empty()) {
            pii p = que.top();
            que.pop();
            int v = p.se;
            if(d[v] < p.fi) continue;
            rep(i,int(g[v].size())){
                edge e = g[v][i];
                if(d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    from_v[e.to] = v;
                    que.push({d[e.to],e.to});
                }
            }
        }
    }
    
    int dis(int a){
        return d[a];
    }
};

int main()
{
    int N,M;
    cin >> N >> M;
    dijkstra G(N);
    A.assign(N,vi(N,0));
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        G.g[a].pb({b,c});
        G.g[b].pb({a,c});
        A[a][b] = 1;
        A[b][a] = 1;
    }
    rep(i,N){
        G.solve_d(i);
        //outve(G.from_v);
        rep(i,N) A[i][G.from_v[i]] = -1, A[G.from_v[i]][i] = -1;
    }
    int ans = 0;
    rep(i,N) reps(j,i+1,N) if(A[i][j] == 1) ans++;
    

    cout << ans << endl;
    
    
    //outmat(A);
    
    

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define piii pair<int,pair<int,int> >
#define pii pair<int,int>
#define ll long long
int a[3];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<a[2]-a[0<<'\n'];
    return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  char c;
  cin>>c;
  
  if(c=='A') cout<<'T'<<endl;
  else if(c=='T') cout<<'A'<<endl;
  else if(c=='C') cout<<'G'<<endl;
  else if(c=='G') cout<<'C'<<endl;
    
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  
  if (((s[0] == s[1]) && (s[1] == s[2]))
      || ((s[1] == s[2]) && (s[2] == s[3]))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	ll a[10005]={};
	ll i,j,k;
	for(i=1;i<=105;i++){
		for(j=1;j<=105;j++){
			for(k=1;k<=105;k++){
				ll x = i*i+j*j+k*k+i*j+j*k+k*i;
				if(x<10005){
					a[x]++;
				}
			}
		}
	}
	ll n;
	cin>>n;
	for(i=1;i<=n;i++){
		cout<<a[i]<<endl;
	}
}

Measured memory_bytes: 3752
from heapq import heappop, heappush, heapify

X, Y, Z, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

heap = list()
used = set()
res = list()

heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))
used.add((0, 0, 0))

for _ in range(K):
    v, i, j, k = heappop(heap)
    res.append(-v)
    if i + 1 < X and (i + 1, j, k) not in used:
        used.add((i + 1, j, k))
        heappush(heap, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
    if j + 1 < Y and (i, j + 1, k) not in used:
        used.add((i, j + 1, k))
        heappush(heap, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
    if k + 1 < Z and (i, j, k + 1) not in used:
        used.add((i, j, k + 1))
        heappush(heap, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        
print('\n'.join(map(str, res)))

Measured memory_bytes: 52188
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
N,M,X = map(int,input().split())
arrA = list(map(int,input().split()))

lis = [0]*N
for i in arrA:
    lis[i]=1

ans = min(sum(lis[:X]),sum(lis[X:]))

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, M;
    cin >> N >> M;
    dsu graph(N);
    rep(i, M) {
        ll A, B;
        cin >> A >> B;
        A--; B--;
        graph.merge(A, B);
    }
    cout << graph.groups().size() - 1 << endl;
    return 0;
}


Measured memory_bytes: 8888
#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__) << "] "

const int maxn=1e6+5;
vector<int> dv[maxn];
int cnt[maxn];

void calc(){
    for(int i=2;i<maxn;i++){
        if(dv[i].size()){
            continue;
        }
        for(int j=i;j<maxn;j+=i){
            dv[j].push_back(i);
        }
    }
}

void solve(){
    int n;
    cin>>n;
    int a[n];
    bool flag=false;
    int gcd=-1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(gcd==-1){
            gcd=a[i];
        }
        else{
            gcd=__gcd(gcd,a[i]);
        }
        if(flag){
            continue;
        }
        for(int j:dv[a[i]]){
            if(cnt[j]){
                flag=true;
            }
            cnt[j]++;
        }
    }
    if(!flag){
        cout<<"pairwise coprime\n";
    }
    else if(gcd==1){
        cout<<"setwise coprime\n";
    }
    else{
        cout<<"not coprime\n";
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    calc();
    while(t--){
        solve();
    }
    return 0;
}

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

int main()
{
    int A, B, C;
    int X, Y;
    scanf("%d%d%d%d%d", &A, &B, &C, &X, &Y);

    int cAB = min(A+B, C*2);
    int cA = min(A, C*2);
    int cB = min(B, C*2);


    int res = 0;
    if(X == Y) {
        res = cAB * X;
    }
    else if(X < Y) {
        res = cAB * X + cB * (Y-X);
    }
    else {
        res = cAB * Y + cA * (X-Y);
    }

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


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int abs(int a){return max(a,-a);}
signed main()
{
    int n;
    cin>>n;
    bool ok=1;
    int prex=0,prey=0,pret=0;
    rep(i,n)
    {
        int t,a,b;
        cin>>t>>a>>b;
        int d=abs(a-prex)+abs(b-prey);
        int dif=t-pret;
        if(d>dif||dif%2!=d%2){puts("No");return 0;}
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = S.size();
  string str = "keyence";
  int M = str.size();
  bool res = false;
  for (int i = 0; i <= M; i++){
    if (S.substr(0, i) == str.substr(0, i)){
      if (S.substr(N - M + i, M - i) == str.substr(i, M - i)){
        res = true;
      }
    }
  }
  cout << (res ? "YES" : "NO");
}

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

using namespace std;

#define int long long

const int mod=1e9+7;

void f(vector<int>coins,int amount)
{
   vector<int>table(amount+1);
   table[0]=1;
   for(int j=1;j<=amount;j++){
       for(int i=0;i<(int)coins.size();i++){
           if(j>=coins[i]){
                table[j] =(table[j-coins[i]]%mod+table[j]%mod)%mod;
                table[j]%=mod;
           }
           else break;
       }
   }
    cout<<table[amount]%mod<<endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int s;
    cin>>s;
    vector<int>coins;
    for(int i=3;i<=s;i++){
        coins.push_back(i);
    }
    f(coins,s);
}


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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const ld PI = acos(-1.0);

const int N = 3000;
int n;
ld a[N] , dp[N][N];
ld solve(int id , int tot)
{
	if(id == 0)
	{
		if(tot == 1)
			return a[0];
		if(tot == 0)
			return (1 - a[0]);
		return 0;
	}

	ld res = dp[id][tot];
	if(res != -1)   return res;
	
	res = 0;
	res += a[id]*solve(id - 1, tot - 1);
	res += (1.00 - a[id])*(solve(id - 1, tot));
	
	return dp[id][tot] = res;
}
int32_t main(){
	fast;

	int n;
	cin >> n;
	
	f(i,0,n)    cin >> a[i];
	
	f(i,0,N)    f(j,0,N)    dp[i][j] = -1;
	
	ld ans = 0;
	
	for(int i=n/2 + 1 ; i<=n ; i++)
	{
		ans += solve(n-1,i);
	}
	cout << fixed << setprecision(10) << ans;
}



Measured memory_bytes: 141184
//using namespace std;
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
   //std::set<int> nanka;
   //nanka.insert(irerukazu);
   //std::vecter<int> v(size)
   //v[0] = a;
    //std::sort(v.begin()v.end());
int main(){

    int a,b,c;
    std::cin >> a >> b >> c;
    std::vector<int> v(3);
    v[0] = a;
    v[1] = b;
    v[2] = c;
    std::sort(v.begin(),v.end());
    if(v[0] + v[1] == v[2]){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }





    return 0;
}


Measured memory_bytes: 256
start = Time.now
D = gets.to_i
@c = gets.split.map(&:to_i)
@s = Array.new D
D.times do |i|
  @s[i] = gets.split.map(&:to_i)
end

t = Array.new D
score = 0
last = Array.new 26, 0
D.times do |i|
  best = -99999999999
  res = nil
  base_c = 0
  26.times do |t|
    base_c += (i - last[t] + 1) * @c[t]
  end
  
  26.times do |t|
    diff = @s[i][t]
    diff -= base_c
    diff += @c[t] * (i - last[t] + 1)

    if diff > best
      best = diff
      res = t
    end
  end
  score +=  best
  last[res] = i + 1
  t[i] = res
end

@q = Array.new
def calc_pena t
  kei = Array.new(26, (1+D)*D/2)
  last = Array.new(26, 0)
  t.each_with_index do |_t, i|
    kei[_t] -= (i+1 - last[_t]) * (D - i)
    last[_t] = i + 1
  end
  res = 0
  26.times do |i|
    res += kei[i] * @c[i]
  end
  res
end
pena = calc_pena(t)
base_score = score + pena

while(Time.now - start < 1.9) do
  100.times do
    new_t = t.dup
    new_base_score = base_score
    (rand(D)+1).times do
      d = rand(D)
      old = new_t[d]
      rep = rand(26)
      new_t[d] = rep
      new_base_score = new_base_score - @s[d][old] + @s[d][rep]
    end

    new_pena = calc_pena(new_t)
    if new_base_score - new_pena > base_score - pena
      t = new_t
      base_score = new_base_score
      pena = new_pena
    end
  end
end
t.each do |_t|
  puts _t + 1
end

Measured memory_bytes: 18076
#include<bits/stdc++.h>
using namespace std;
vector<int>dy({0,-1,0,1}),dx({1,0,-1,0});

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,k; cin>>n>>k;
	vector<int>h(n); for(auto&&i:h)cin>>i;
	vector<int>dp(n,1e9); dp.front()=0;
	for(int i=0;i<n;++i){
		for(int j=i+1,lim=min(i+k+1,n);j<lim;++j){
			dp.at(j)=min(dp.at(j),dp.at(i)+abs(h.at(i)-h.at(j)));
		}
	}
	cout<<dp.back()<<"\n"s;
}


Measured memory_bytes: 3952
// Code for C - Average Length
#include <bits/stdc++.h>
#include "boost/tuple/tuple.hpp"

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,x,y) for(ll i=x;i<(ll)(y);i++)

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

  vector<int> x(N);
  vector<int> y(N);

  vector<int> v(N);
  REP(i, N) {
    v.at(i) = i;
  }

  REP(i, N) {
    cin >> x.at(i);
    cin >> y.at(i);
  }

  vector<vector<long double> > m(N, vector<long double>(N));

  REP(i, N - 1) {
    FOR(j, i + 1, N) {
      long double length = sqrtl((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
      m[i][j] = length;
      m[j][i] = length;
    }
  }

  long double total = 0;
  int count = 0;
  do {
    long double path = 0;
    REP(i, N-1) {
      path += m[v[i]][v[i + 1]];
    }
    total += path;
    count++;
  } while(next_permutation(v.begin(), v.end()));

  cout << fixed << setprecision(15) << total / count << endl;

	return 0;
}


Measured memory_bytes: 256
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifdef HOME
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef complex < double > com;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void test() {
    string s;
    int n;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < n - 2; ++i) {
        if (s.substr(i, 3) == "ABC") {
            ++ans;
        }
    }
    cout << ans << "\n";
}

int main() {
    fast_io();
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cout << fixed << setprecision(15);
    test();
    #ifdef HOME
        cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
    #endif
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
//#include<string>
//#include<sstream>
using namespace std;
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n",a+b/2);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,M;
vector<ll> A;

int main(){
  cin>>N>>M;
  A.resize(N);
  rep(i,N) cin>>A[i];

  priority_queue<ll> PQ;
  for(int i=0;i<N;i++) PQ.push(A[i]);

  for(int i=0;i<M;i++){
    ll f=PQ.top();
    PQ.pop();

    ll nex=f/2;
    PQ.push(nex);
  }

  ll ans=0;
  while(!PQ.empty()){
    ans+=PQ.top();
    PQ.pop();
  }
  cout<<ans<<endl;

  return 0;
}


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

int main(){
  int n, b, f, r, v, rooms[5][4][11];

  for(int i = 1; i < 5; i++){
    for(int j = 1; j < 4; j++){
      for(int k = 1; k < 11; k++){
        rooms[i][j][k] = 0;
      }
    }
  }

  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> b >> f >> r >> v;
    rooms[b][f][r] += v;
  }

  for(int i = 1; i < 5; i++){
    if(i != 1){
      for(int l = 0; l < 20; l++){
        cout << '#';
      }
      cout << endl;
    }
    for(int j = 1; j < 4; j++){
      for(int k = 1; k < 11; k++){
        cout << ' ' << rooms[i][j][k];
      }
      cout << endl;
    }
  }
  return 0;
}

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

#define MOD 1000000007
#define lli long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = n - 1; ~i; i--)
#define pb push_back
#define mkp make_pair
#define endl "\n"

using namespace std;

bool enable_test_case = false;
bool enable_google = false;

void solve()
{
    lli n, k;
    cin >> n >> k;
    lli h[n];
    lli dp[n];
    rep(i, n)
    {
        cin >> h[i];
        dp[i] = INT64_MAX;
    }
    dp[0] = 0;

    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            if ((i - j) >= 0)
                dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]));
        }
    }
    cout << dp[n - 1] << endl;
}

void google_contests(int t)
{
    cout << "Case #" << t + 1 << ": ";
}

void test_case()
{
    if (enable_test_case)
    {
        lli t;
        cin >> t;
        rep(i, t)
        {
            if (enable_google)
                google_contests(i);
            solve();
        }
    }
    else
    {
        solve();
    }
}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    test_case();

    return 0;
}


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

#define pb push_back
#define rep(i,s,t) for(int i = s; i <= t; ++ i)
const int MaxN = 100050;

int n, m;
vector<int> L[MaxN];
int K, LI, fa[MaxN];

int f(int x){return fa[x] == x?x:fa[x]=f(fa[x]);}

int main()
{
    scanf("%d%d",&n,&m);
    rep(i,1,n) 
    {
        scanf("%d",&K);
        rep(j,1,K)
        {
            scanf("%d",&LI);
            L[LI].pb(i);
        }
    }
    rep(i,1,n) fa[i] = i;
    rep(i,1,m) if(L[i].size()>1) rep(j,1,L[i].size()-1) fa[f(L[i][j])]=f(L[i][j-1]);
    rep(i,1,n) if(f(i) != f(1)) {puts("NO"); return 0;}
    puts("YES");
    return 0;
}

Measured memory_bytes: 4608
#include <map>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long int LL;
const int Max_N(18);
typedef pair<int, int> pil;
#define fi first
#define se second
#define mp make_pair

int N, A[Max_N + 5], tot;
pil All[1 << Max_N];
int le[1 << Max_N], re[1 << Max_N];
LL F[Max_N + 2][Max_N + 2][1 << Max_N];

void dfs(int cnt, int fl, int fr)
{
	All[++tot] = mp(fl, fr);
	if (cnt == N)
		return;
	dfs(cnt + 1, fl + fr, fr), dfs(cnt + 1, fl, fl + fr);
}

LL dp(int l, int r, int status)
{
	if (l + 1 == r)
		return A[l] * 1LL * All[status].fi + A[r] * 1LL * All[status].se;
	LL &Ret(F[l][r][status]);
	if (Ret != -1LL)
		return Ret;
	Ret = 0X3F3F3F3F3F3F3F3FLL;
	for (int m = l + 1;m <= r - 1;++m)
		Ret = min(Ret, dp(l, m, re[status]) + dp(m, r, le[status]) - A[m] * 1LL * (All[status].fi + All[status].se));
	return Ret;
}

int main()
{
	scanf("%d", &N);
	for (int i = 1;i <= N;++i)
		scanf("%d", A + i);
	dfs(2, 1, 1);
	sort(All + 1, All + 1 + tot), tot = unique(All + 1, All + 1 + tot) - (All + 1);
	for (int i = 1, x, y;i <= tot;++i)
	{
		x = All[i].fi + All[i].se, y = All[i].se;
		le[i] = lower_bound(All + 1, All + 1 + tot, mp(x, y)) - All;
		x = All[i].fi, y = All[i].fi + All[i].se;
		re[i] = lower_bound(All + 1, All + 1 + tot, mp(x, y)) - All;
	}
	memset(F, -1, sizeof(F));
	printf("%lld", dp(1, N, 1));
	return 0;
}

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

int main() {
  string S;
  long K;
  cin >> S;
  cin >>K;
  if(S.at(0)=='1'){
  bool a=true;
  for(int i=0;i<K;i++){
    if(S.at(i)!='1'){
      a=false;
      cout<<S.at(i)<<endl;
      break;
    }
  }
  if(a){
    cout<<1<<endl;
  }
  }
  else{
    cout<<S.at(0)<<endl;
  }  
}

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

using namespace std;
#define vsort(v) sort(v.begin(), v.end())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	string ans = "";
	ans += s[0] + ts(s.size() - 2) + s[s.size() - 1];
	cout << ans << endl;
}


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

using namespace std;

using int64 = long long;

int main() {
  int K, A, B;
  cin >> K >> A >> B;

  int64 ret = 1;
  for(int i = 1; i <= K; i++) {
    if(ret >= A && i + 1 <= K) {
      ret -= A;
      ret += max(A + 2, B);
      ++i;
    } else {
      ++ret;
    }
  }

  cout << ret << endl;
}



Measured memory_bytes: 384
a, b, c, k = gets.chomp.split(' ').map(&:to_i)
s = 0

def calc(k, i, d, s)
  if k >= i
    k -= i
    s += d * i
  else
    s += d * k
    k = 0
  end
  return k, s
end

[[a, 1], [b, 0], [c, -1]].each do |arr|
  k, s = calc(k, arr[0], arr[1], s)
  break if k <= 0
end

puts s


Measured memory_bytes: 14280
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        int N = scanner.nextInt();
        List<Integer> numbers = new ArrayList();

        for (int i = 0; i < N; i++) {
            numbers.add(Integer.parseInt(scanner.next()));
        }

        int count = 0;

        do {
            numbers = numbers.stream()
                    .filter(i -> (i % 2) == 0)
                    .map(i -> i / 2)
                    .collect(Collectors.toList());
            if (numbers.size() == N) count++;
        } while(numbers.size() == N);

        System.out.println(count);
    }
}

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

int main() {
	int n;
	cin >> n;
	unordered_map<string,int> mp;
	rep(i,n)
	{
		string s;
		cin >> s;
		sort(s.begin(),s.end());
		mp[s]++;
	}
	ll ans = 0;
	for(auto& p: mp)
	{
		int s = p.second;
		ans += (ll)s*(s-1)/2;
	}
	cout << ans << endl;
	return 0;
}


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

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

    for(int j=0; j<4; ++j) {
        int x=j/2, y=j%2;
        int a[n]={};
        a[0]=x;
        a[1]=y;
#define F(i) (s[i]%2^a[i]^a[(n+i-1)%n])
        for(int k=1; k+1<n; ++k) a[k+1]=F(k);
        if (a[0]==F(n-1) and a[1]==F(0)) {
            for(int e: a) cout<<"WS"[e];
            cout<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

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


/////////////////////////////////////////////////////////////////////////////////////////
int a[100005];
int main(){
    int n;
    cin >> n;
    ll ans = 0;
    vector<ll> a(n);
    for (int i = 0;i < n;i++){
        cin >> a[i];
        a[i] -= (i + 1);
    }
    sort(a.begin(),a.end());
    ll b = a[n / 2];
    for (int i = 0;i < n;i++){
        ans += abs(a[i] - b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792