akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  int n,m;
  cin>>n>>m;

  vector<vector<int>> fr(n);
  vector<int> to(n);

  rep(i,n+m-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    fr[a].pb(b);
    to[b]++;
  }

  vector<int> ans(n);

  deque<int> que;
  rep(i,n){
    if(to[i]==0) {
      que.pb(i);
      ans[i]=0;
      break;
    }
  }
  while(!que.empty()){
    int z=que.front();
    que.pop_front();
    for(int x:fr[z]){
      to[x]--;
      if(to[x]==0){
        ans[x]=z+1;
        que.pb(x);
      }
    }
  }

  rep(i,n){
    cout << ans[i] << endl;
  }

}

Measured memory_bytes: 9408
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, a;
	cin >> n;
	vector<int> b(n, 0);
	for (int i = 0; i < n - 1; i++) {
		cin >> a;
		b.at(a - 1)++;
	}
	for (int i = 0; i < n; i++) {
		cout << b.at(i) << endl;
	}
}

Measured memory_bytes: 4052
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int X=scan.nextInt(),A=scan.nextInt();
        if(X < A){
            System.out.println(0);
        }else{
            System.out.println(10);
        }
    }
}

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

#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)

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

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (auto& ai : A)
		cin >> ai;
	int mi = 1, mx = 1000'000'001;
	while (mi < mx)
	{
		int mid = (mi + mx) / 2;
		int64_t cut = 0;
		forn(i, A.size())
		{
			cut += (A[i] - 1) / mid;
		}
		if (cut <= K)
		{
			mx = mid;
		}
		else
		{
			mi = mid + 1;
		}
	}
	cout << mx << endl;
	return 0;
}


Measured memory_bytes: 3984
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)


//??????????????°?????????(????????´??°or?????? , ????°????or?????§???or???) verified AOJ DSL_2,DSL_3
template<class T>
class segtree{
private:
    vector<T> dat;
    int _size;  //the number of leaves
    T _init;
    
public:
    segtree(int __size=0 , T init=numeric_limits<T>::max() ):_size(__size) , _init(init) , dat(4*__size,init){
        if(__size==0)return ;
        int x=1;
        while(x<_size)x*=2;
        _size = x;
    }
    
    void update(int m,T x){
        int i = m+_size;
        dat[i] += x;    //addition
//        dat[i] = x;     //initialize
        while(i!=1){
//            dat[i/2] = min(dat[i],dat[i^1]);    //minimum
//            dat[i/2] = max(dat[i],dat[i^1]);    //maximum
            dat[i/2] = dat[i]+dat[i^1];         //sum
            i/=2;
        }
    }
    
    // call find(s,t)
    T find(int s,int t,int num=1,int a=0,int b=-1){
        if(b==-1)b=_size-1; //I couldn't "int b=_size".
        if(b<s||t<a)return _init;
        if(s<=a&&b<=t)return dat[num];
//        return min( find(s,t,num*2,a,(a+b)/2) , find(s,t,num*2+1,(a+b)/2+1,b) );    //minimum
//        return max( find(s,t,num*2,a,(a+b)/2) , find(s,t,num*2+1,(a+b)/2+1,b) );    //maximum
        return find(s,t,num*2,a,(a+b)/2) + find(s,t,num*2+1,(a+b)/2+1,b);           //sum
    }
    int size(){return _size;}
};

/*
 segtree<int> x(100);                                                //100 datas
 segtree<pair<int,int>> x( 100,make_pair( 1<<31-1 , 1<<31-1 ) );     //100 datas
 */



int main(){
    int n,q;
    cin>>n>>q;
    segtree<int> st(n,0);
    rep(i,q){
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0)st.update(x-1,y);
        else cout<<st.find(x-1,y-1)<<endl;
    }
}

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

int main(){
    int A[4][4];
    int b[12];
    int N;
    int i;
    int cnt = 0;
    for(i = 1; i < 4; i++){
        for(int j = 1; j < 4; j++){
            cin >> A[i][j];
        }
    }
    cin >> N;
    for(i = 0; i < N; i++){
        cin >> b[i];
    }
    
    for(int k = 0; k < N; k++){
        for(i = 1; i < 4; i++){
            for(int j = 1; j < 4; j++){
                if(A[i][j] == b[k]){
                    A[i][j] = 0;
                }
            }
        }
    }

    for(i = 0; i < 4; i++){
        if(A[1][i] == 0 && A[2][i] == 0 && A[3][i] == 0) cnt = 1;
    }
    for(i = 0; i < 4; i++){
        if(A[i][1] == 0 && A[i][2] == 0 && A[i][3] == 0) cnt = 1;
    }
    if(A[1][1] == 0 && A[2][2] == 0 && A[3][3] == 0) cnt = 1;
    if(A[3][1] == 0 && A[2][2] == 0 && A[1][3] == 0) cnt = 1;
    
    if(cnt) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  string cmd;
  int cmd_n;
  list<int> ls;
  int i;
  for (i = 0; i < n; i++) {
    cin >> cmd;
    if (cmd.length() == 6) {
      cin >> cmd_n;
    }
    if (cmd == "insert") {
      ls.push_front(cmd_n);
    } else if (cmd == "delete") {
      for (auto it = ls.begin(); it != ls.end(); it++) {
        if (*it == cmd_n) {
          ls.erase(it);
          break;
        }
      }
    } else if (cmd == "deleteFirst") {
      ls.pop_front();
    } else if (cmd == "deleteLast") {
      ls.pop_back();
    }
  }
  
  int temp = ls.back();
  ls.pop_back();
  ls.push_back(-1);
  ls.push_back(temp);

  for (auto it = ls.begin(); it != ls.end(); it++) {
    if (*it != -1) {
      cout << *it << ' ';
    } else {
      it++;
      cout << *it;
    }
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 34432
h,w=map(int,input().split())
m=[list(input()) for _ in range(h)]
ans=[[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if m[i][j]=='#':
      ans[i][j]='#'
    else:
      for k in range(max(0,i-1),min(h,i+2)):
        ans[i][j]+=m[k][max(0,j-1):min(w,j+2)].count('#')
[print(*l,sep='') for l in ans]

Measured memory_bytes: 3572
def resolve():
    h, n = map(int, input().split())
    w = []
    v = []
    for i in range(n):
        a, b = map(int, input().split())
        w.append(a)
        v.append(b)
    dp = [[0 for i in range(h + 1)] for j in range(n + 1)]
    for i in range(1, h + 1):
        dp[0][i] = float("inf")
    for i in range(n):
        for j in range(h + 1):
            if j >= w[i]:
                dp[i + 1][j] = min(dp[i + 1][j - w[i]] + v[i], dp[i][j])
            else:
                dp[i + 1][j] = min(dp[i][j], v[i])
    # print(dp[n])
    print(dp[n][h])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 125788
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

int main(){
    long long k;
    cin >> k;
    int n = 50;
    cout << n << endl;
    vector<long long> ret(n);
    for(int i = 0; i < n; i++) ret[i] = i;
    long long s = k / n;
    int r = k % n;
    for(int i = 0; i < n; i++) ret[i] += s;
    for(int i = 0; i < r; i++){
        for(int j = 0; j < n; j++){
            if(i == j) ret[j] += n;
            else ret[j]--;
        }
    }
    for(int i = 0; i < n; i++) cout << ret[i] << " ";
    cout << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<cassert>
#include<ctime>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define all(n) n.begin(),n.end()
using namespace std;
int a,b;

int main(){
 
  while(true){
    cin >> a >> b;
    if(a+b == 0)break;
    int ans = (1<<27);
    assert(a>=0 && b>=0);
    for(int i=1;i<=a/2+1;i++){
      if(a%i != 0)continue;
      vector<int> vec;
      //cout << "a = " << i << "," << a/i << " ";
      vec.push_back(i);vec.push_back((int)(a/i));
      for(int j=1;j<=b/2+1;j++){
	if(b%j != 0)continue;
	//cout << "b = " << j << "," << b/j << endl;
	vec.push_back(j); vec.push_back(b/j);
	sort(all(vec));
	//for(int k=0;k<4;k++){
	//cout << vec[k] << endl;
	//}
	//cout << "---" << endl;
	int sum = 0;
	sum = (vec[1]-vec[0])*(vec[1]-vec[0]) + (vec[2]-vec[1])*(vec[2]-vec[1]) + (vec[3]-vec[2])*(vec[3]-vec[2]);
	//cout << "sum -  " << sum << endl;
	ans = min(ans,sum);
	vec.clear();
	vec.push_back(i); vec.push_back(a/i);
      }
    }

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

Measured memory_bytes: 1216
N,C = list(map(int,input().split()))

discomforts = [[0]*(N+1)]
for _ in range(C):
    row = [0]
    row.extend(list(map(int,input().split())))
    discomforts.append(row)
grid = [[0]*(N+1)]
for _ in range(N):
    row = [0]
    row.extend(list(map(int,input().split())))
    grid.append(row)

color_counts = [[0]*(C+1) for i in range(3)]

for i in range(1,N+1):
    for j in range(1,N+1):
        color_counts[(i+j)%3][grid[i][j]] += 1

ans = float('inf')
for c0 in range(1,C+1):
    for c1 in range(1,C+1):
        for c2 in range(1,C+1):
            if c0 != c1 and c1 != c2 and c2 != c0:
                total = 0
                for i in range(1,C+1):
                    total += discomforts[i][c0]*color_counts[0][i]
                    total += discomforts[i][c1]*color_counts[1][i]
                    total += discomforts[i][c2]*color_counts[2][i]
                ans = min(ans,total)
print(ans)

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string s;
    cin >> s;
    cout << (s[0] == s[1] && s[1] == s[2] ? "No" : "Yes") << endl;
    return 0;
}


Measured memory_bytes: 256
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
bool prime(int x){
	if(x==1||x==0) return false;
	if(x==2) return true;
	if(x%2==0) return false;
	for(int i=3;i*i<=x;i++) if(x%i==0) return false;
	return true;
}
void solve(int x){
	int i=2;
	if(prime(x)){printf(" %d\n",x);return;}
	while(i<=x){
		while(prime(i)&&x%i==0){
			printf(" %d",i);
			x/=i;
		}
		i++;
	}
	printf("\n");
}
int main(){
	int n;
	scanf("%d",&n);
	printf("%d:",n);
	solve(n);
}


Measured memory_bytes: 3228
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class BTwoContests {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<P> vec(n), vec2(n);
      rep(i, n) {
        cin >> vec[i].second >> vec[i].first;
        vec2[i].first = vec[i].second;
        vec2[i].second = vec[i].first;
      }
      sort(all(vec));
      sort(vec2.rbegin(), vec2.rend());

      vector<ll> v1(n);
      ll mi = 1;
      ll ma = 1e+9;
      rep(i, n) {
        chmax(mi, vec[i].second);
        chmin(ma, vec[i].first);
        v1[i] = max(ma-mi+1, 0LL);
      }
      vector<ll> v2(n);
      mi = 1;
      ma = 1e+9;
      for(int i=n-1; i>=0; i--) {
        chmax(mi, vec[i].second);
        chmin(ma, vec[i].first);
        v2[i] = max(ma-mi+1, 0LL);
      }
      ll ans = 0;
      rep(i, n-1) {
        chmax(ans, v1[i]+v2[i+1]);
      }

      mi = 1;
      ma = 1e+9;
      rep(i, n) {
        chmax(mi, vec2[i].second);
        chmin(ma, vec2[i].first);
        v1[i] = max(ma-mi+1, 0LL);
      }
      mi = 1;
      ma = 1e+9;
      for(int i=n-1; i>=0; i--) {
        chmax(mi, vec2[i].second);
        chmin(ma, vec2[i].first);
        v2[i] = max(ma-mi+1, 0LL);
      }
      rep(i, n-1) {
        chmax(ans, v1[i]+v2[i+1]);
      }

      multiset<int, greater<>> left;
      multiset<int> right;
      rep(i, n) {
        left.insert(vec2[i].first);
        right.insert(vec2[i].second);
      }

      rep(i, n) {
        auto it = left.find(vec2[i].first);
        left.erase(it);
        it = right.find(vec2[i].second);
        right.erase(it);

        debug(*right.begin(), *left.begin());

        ll tmp = max(0, (*right.begin())-(*left.begin())+1);
        ll tmp2 = max(0LL, vec2[i].second-vec2[i].first+1);
        chmax(ans, tmp + tmp2);

        left.insert(vec2[i].first);
        right.insert(vec2[i].second);
      }

      cout << ans << endl;

    }
};

signed main() {
  BTwoContests solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

int color[100001];
vector<int> g[100001];

int dp[100001][11];
int V[100001], D[100001], C[100001];

void dfs(int v, int d, int c) {
    if (dp[v][d] != 0) return;
    dp[v][d] = 1;
    if (color[v] == 0) {
        color[v] = c;
    }
    if (d == 0) return;
    for (int i=0; i<g[v].size(); ++i) {
        int n = g[v][i];
        dfs(n, d-1, c);
    }
}

int main() {
    int N, M, Q;
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cin >> Q;
    rep(i, Q) {
        cin >> V[i] >> D[i] >> C[i]; V[i]--;
    }
    for (int i=Q-1; i>=0; --i) {
        dfs(V[i], D[i], C[i]);
    }
    rep(i, N) {
        cout << color[i] << endl;
    }
}


Measured memory_bytes: 12408
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans=0
P=[]
for i in range(X):
    P.append(p[i])
    #ans+=p[i]
for i in range(Y):
    P.append(q[i])
    #ans+=q[i]
P.sort()
tmp=0
Q=[]
count=0
for i in range(C):
    if count>=(X+Y):
        break
    if r[i]>P[count]:
        Q.append(r[i])
        count+=1
    else:
        break
R=[]
ans=0
for i in range(len(Q)):
    ans+=Q[i]
for i in range(len(Q),X+Y):
    ans+=P[i]
#print(P)
#print(Q)
print(ans)

Measured memory_bytes: 109676
N = int(input())
S = input()
S = S[1:]+S[0]
animal = ['WW', 'WS', 'SW', 'SS']

for pair in animal:
    a,b = pair[0],pair[1]
    pre, nex = a, b
    answer = [a,b]
    for i in range(N):
        if (nex == 'S' and S[i] == 'o') or (nex=='W'and S[i] == 'x'):
            tmp = nex
            nex = pre
            pre = tmp
            answer.append(nex)
        else:
            tmp = nex
            nex = 'W'if pre == 'S' else 'S'
            pre = tmp
            answer.append(nex)
    if nex == b and pre == a:
        print(''.join(answer[:-2]))
        break
else:
    print(-1)

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	// your code goes here
	ll n,a,b;
	cin>>n>>a>>b;
	ll out=n/(a+b);
	out*=a;
	n=n%(a+b);
	out+=min(a,n);
	cout<<out;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _i in range(m)]

visit = [-1 for _ in range(n)]
visit[0] = 0
tree = [[] for _ in range(n)]
for a, b in ab:
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

from collections import deque
q = deque([0])
while q:
    p = q.popleft()
    for i in tree[p]:
        if visit[i] < 0:
            visit[i] = p
            q.append(i)
if all(i >= 0 for i in visit):
    print("Yes")
    for i in visit[1:]:
        print(i+1)
else:
    print("No")

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

namespace ITP1
{
    class ITP1_5_C
    {
        static void Main(string[] args)
        {
            int h, w;
            List<int> dataSet;

            while (true)
            {
                dataSet = Console.ReadLine().Split().Select(int.Parse).ToList();
                h = dataSet[0];
                w = dataSet[1];

                if (h == 0 && w == 0)
                {
                    break;
                }

                for (int i = 1; i <= h; i++)
                {
                    for (int j = 1; j <= w; j++)
                    {
                        if (i % 2 == 0)
                        {
                            if (j % 2 == 0)
                            {
                                Console.Write("#");
                            }
                            else
                            {
                                Console.Write(".");
                            }
                        }
                        else 
                        {
                            if (j % 2 == 0)
                            {
                                Console.Write(".");
                            }
                            else
                            {
                                Console.Write("#");
                            }
                        }
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 20464
S = str(input())
T = str(input())
lenS = len(S)
lenT = len(T)
max_match = 0
for idx in range(lenS - lenT + 1):
    cnt_match = 0
    for i in range(lenT):
        if S[idx + i] == T[i]:
            cnt_match += 1
    if cnt_match > max_match:
        max_match = cnt_match
print(lenT - max_match)



Measured memory_bytes: 8980
n = gets.chomp.to_i
pos_list = []
distance_list = []

n.times do
  pos_list << gets.chomp.split(' ').map(&:to_i)
end

def distance(x1,y1,x2,y2)
  return Math.sqrt((x1-x2)**2 + (y1-y2)**2)
end

for i in 0..n-1
  for j in 0..n-1
    next if (i == j)
    distance_list[i] = 0 if (distance_list[i].nil?) 
    distance_list[i] += distance(pos_list[i][0], pos_list[i][1], pos_list[j][0], pos_list[j][1])
  end
end

sum = 0
distance_list.each do |d|
  sum += d
end

puts sum / distance_list.size


Measured memory_bytes: 1788
#include<stdio.h>

int main()
{
	int min,max,n,i,number;
	long sum;
	sum=i=0;
	scanf("%d",&n);
	while(i<n){
//		printf("%d:",i);
		scanf("%d",&number);
		if(i==0) min = max = number;
		else if(number < min ) min = number;
		else if(number > max) max = number;
		
		i++;
		sum += number;
	}
	printf("%d %d %ld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace MyProgram
{
    public class Program
    {
        public static void Main(){
            int n = int.Parse(Console.ReadLine());
            　
            int[] dp = new int[n+1];
            for(int i = 0 ; i <= n ; i++) dp[i] = -1;
            dp[0] = 0;
            
            Queue<int> que = new Queue<int>();
            que.Enqueue(0);
            
            int a = 0;
            while(que.Count > 0)
            {
                a = que.Dequeue();
                
                for(int pow6 = 1 ; a + pow6 <= n ; pow6 *= 6)
                {
                    if(dp[a+pow6] == -1)
                    {
                        dp[a+pow6] = dp[a] + 1;
                        que.Enqueue(a+pow6);
                    }
                }
                for(int pow9 = 1 ; a + pow9 <= n ; pow9 *= 9)
                {
                    if(dp[a+pow9] == -1)
                    {
                        dp[a+pow9] = dp[a] + 1;
                        que.Enqueue(a + pow9);
                    }
                }
            }
            
            Console.WriteLine(dp[n]);
        }
    }
}

Measured memory_bytes: 11360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, x, t;
  cin >> n >> x >> t;
  if ( n % x == 0) {
    cout << n/x*t;
  } else {
    cout << (n/x+1)*t;
  }
}

Measured memory_bytes: 3560
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, K): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let (x, y): (Vec<i64>, Vec<i64>) = {
        let (mut x, mut y) = (vec![], vec![]);
        for _ in 0..N {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            x.push(iter.next().unwrap().parse().unwrap());
            y.push(iter.next().unwrap().parse().unwrap());
        }
        (x, y)
    };

    const INF: i64 = 4e18 as i64;

    let ans = (0..N).map(|i| {
        (0..N).map(|j| {
            (0..N).map(|k| {
                (0..N).map(|l| {
                    if (0..N).filter(|&m| x[i] <= x[m] && x[m] <= x[j] && y[k] <= y[m] && y[m] <= y[l]).count() >= K {
                        (x[i] - x[j]).abs() * (y[k] - y[l]).abs()
                    } else {
                        INF
                    }
                }).min().unwrap()
            }).min().unwrap()
        }).min().unwrap()
    }).min().unwrap();

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

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

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

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    int N;
    cin>>N;
    queue<string> q;
    q.push("a");
    while((int)q.front().size()!=N){
        string s = q.front();
        q.pop();
        int n = s.size();
        int t = 0;
        for(auto x:s){
            int m = x - 'a';
            chmax(t,m);
        }
        rep(i,t+2){
            char c = 'a'+i;
            string l = s + c;
            q.push(l);
        }
    }
    while(!q.empty()){
        cout<<q.front()<<endl;
        q.pop();
    }
}

Measured memory_bytes: 7284
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <functional>
#include <queue>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int d ;
    cin >> d ;
    vector<int> c (26,0) ;
    for (int i = 0; i < 26; i++)
    {
        cin >> c.at(i) ;
    }
    vector<vector<int> > s(d,vector<int>(26)) ;
    for (int i = 0; i < d; i++)
    {
        for (int j = 0; j < 26 ; j++)
        {
            cin >> s.at(i).at(j) ;
        }
        
    }
    vector<int64_t>ans(0) ;
    vector<int64_t> score(0) ;
    int64_t snow = 0 ;
    vector<int64_t> last(26,-1) ;
    vector<int64_t> judge(26,0) ;
    for (int i = 0; i < d; i++)
    {
        for (int j = 0; j < 26; j++)
        {
            judge.at(j) =c.at(j) *(i - last.at(j)) *(i - last.at(j)) + s.at(i).at(j) ;
        }
        
        int num = 1 ;
        int temp = judge.at(0) ;
        for (int j = 0; j < 26; j++)
        {
            if (temp < judge.at(j) )
            {
                temp =  judge.at(j) ;
                num = j+1 ;
            }
            
        }
        ans.push_back(num) ;
        snow += s.at(i).at(num-1) ;
        last.at(num-1) = i ;
        for (int j = 0; j < 26; j++)
        {
            snow -= c.at(j) * (i - last.at(j)) ;
        }
        //score.push_back(snow) ;
    }
    for (int i = 0; i < d; i++)
    {
        cout << ans.at(i) << endl ;
    }
    //cout << snow << endl ;

}

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

int main() {
    ll N, ans=0, tmp;
    cin >> N;
    vector<ll> a(N), add(2e7, 0), sub(2e7, 0);
    for(ll i=0; i<N; i++){
	cin >> a[i];	
    }

    for(ll i=0; i<N; i++){
	tmp = (i+1) + a[i];
	if(tmp<2e7)
	    add[tmp]++;
	
	tmp = (i+1) -a[i];
	if (tmp>=0 && tmp<2e7)
	    sub[tmp]++;
    }

    for(ll i=0; i<2e7; i++){
	ans += add[i] * sub[i];
    }
    cout << ans << endl;
} 




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

constexpr long long MOD = 1'000'000'007;

class binomial_coefficients {
	long long MAX_VAL;
	vector<long long> fac, mmi;

public:

	binomial_coefficients(){
	}
	
	binomial_coefficients(long long num){
		init(num);
	}
	
	~binomial_coefficients(){
		
	}
	
	void init(long long num){
		MAX_VAL = num+1; 
		fac.resize(MAX_VAL);
		mmi.resize(MAX_VAL);
		
		factorial_mod();
		modular_multiplicatibe_inverse();
	}
	
	void factorial_mod(){
		 fac[0] = 1;
		for(long long i = 1; i < MAX_VAL; fac[i] %= MOD, i++)
			fac[i] = fac[i - 1] * (i % MOD);
	}
	
	long long power(long long x, long long n){
		long long ans = 1;
		for(;n;n >>= 1, x *= x, ans %= MOD, x %= MOD)
			if(n&1)ans*=x;
		return ans % MOD;
	}
	
	void exgcd(long long a, long long b, long long &x, long long &y){
		if(b == 0){
			x = 1;
			y = 0;
			return ;
		}
		exgcd(b, a % b, y, x);
		y -= a / b * x;
	}
	
	void modular_multiplicatibe_inverse(){
		long long x, y;  
		exgcd(fac[MAX_VAL - 1], MOD, x, y);
		mmi[MAX_VAL-1] = (x % MOD + MOD) % MOD;
		// mmi[MAX_VAL-1] = power(fac[MAX_VAL-1], MOD-2);
		for(long long i = MAX_VAL - 2; i >= 0; mmi[i]%=MOD, i--)
			mmi[i] = mmi[i + 1] * ((i + 1) % MOD);
	}
	
	long long combination(long long n, long long r){
		return r < 0 ? 0 :n < r ? 0 :fac[n] * (mmi[r] * mmi[n-r] % MOD) % MOD;
	}
};


int main(){
	
	long long n, k;
	long long ans = 0;
	binomial_coefficients bc;
	vector<vector<long long>> dp;
	
	cin>>n>>k;
	
	bc.init(n+k);
	dp.resize(k+1, vector<long long>(n+2));
	
	
	dp[0][0] = 1;
	
	for(int i = 1; i <= k; i++){
		for(int j = 0; j <= n; j++){
			dp[i][j] = dp[i-1][j];
			if(j >= i) dp[i][j] += dp[i][j-i];
			dp[i][j] %= MOD;
		}
	}
	
	if(n >= k)ans = dp[k][n-k];
	
	cout<<ans<<endl;
}


Measured memory_bytes: 10772
/*input
5 1
100 200 300 400 500
*/
#include <bits/stdc++.h>
using namespace std;
 
#define all(a) (a).begin(), (a).end()
#define pb push_back
 
using ll = long long;
using pii = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);cin.tie(nullptr);
  int ans = 0;
  int n, k; cin >> n >> k;
  for (int i = 0; i < n; ++i) {
  	int h; cin >> h;
  	ans += (h >= k);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
n = int(input())
dp = [10 ** 9 for _ in range(n + 2)] # ちょっと大きめに
dp[0] = 0

h = [int(x) for x in input().split()]

for i in range(1, n):
  total_cost = dp[i-1] + abs(h[i] - h[i-1])
  dp[i] = min(dp[i], total_cost)
  if i > 1:
    total_cost = dp[i-2] + abs(h[i] - h[i - 2])
    dp[i] = min(dp[i], total_cost)
  
print(dp[n-1])

Measured memory_bytes: 15032
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvi = vector<vector<int> >;
using vvll =  vector<vector<ll> >;
const ll mod = 1e9 + 7;

const ll inf = 1LL << 60;

struct mint{
    ll x;
    mint(ll x = 0): x((x % mod + mod)%mod){}

    
    mint& operator+=(const mint a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += mod-a.x) >= mod)  x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    
    mint operator+(const mint a) const{ //クラスのメンバを変更しない
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const{ //クラスのメンバを変更しない
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const{ //クラスのメンバを変更しない
        mint res(*this);
        return res*=a;
    }

    mint pow(ll n)const{
        if(n == 0)return 1;
        mint a = pow(n>>1);
        a *= a;
        if(n & 1)a *= (*this);
        return a;
    }

    mint inv() const{
        return pow(mod-2);
    }
    mint& operator/=(const mint a){
        return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
        mint res(*this);
        return res/=a;
    }
    
};

ostream& operator<<(ostream &os, const mint &m){
    os << m.x;
    return os;
}

struct Combination{
    vector<mint> fact,ifact;
    Combination(int n): fact(n+1),ifact(n+1){
        fact[0] = 1;
        for(int i = 1; i<=n; i++)fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for(int i = n; i>= 1; i--){
            ifact[i-1] = ifact[i] * i;
        }
    }

    mint comb(int n, int k){
        if(k < 0 || n < k)return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N,K; cin >> N >> K;
    vector<ll> A(N);
    REP(i,N){
        cin >> A[i];
    }
    sort(ALL(A));
    vector<mint> small(N,0),big(N,0);
    Combination C(N);
    REP(i,N){
        if(N - i >= K){
            small[i] = C.comb(N-1-i, K-1);
        }
        if(i >= K - 1){
            big[i] = C.comb(i,K-1);
        }
    }
    mint ans = 0;
    REP(i,N){
        ans += big[i]*A[i] - small[i]*A[i];
    }
    cout << ans << endl;

}

Measured memory_bytes: 7120
<?php
fscanf(STDIN, "%d", $N);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
rsort($A);

$p = 0;
$l = [$A[0]];
for ($i = 1; $i <= $N / 2; $i++) {
    $p += $l[$i - 1];
    // echo $l[$i - 1], PHP_EOL;
    $l[] = $A[$i];
}
// echo "end\n";
if (count($l) <= 2) {
    $min = min($l);
    for ($j = $i; $j < $N; $j++) {
        $p += $min;
    }
} else {
    for ($j = $i; $j < $N; $j++) {
        // echo $l[$j - $i + 1] ?? $l[$j - $i], PHP_EOL;
        $p += $l[$j - $i + 1] ?? $l[$j - $i];
    }
}

echo $p, PHP_EOL;


Measured memory_bytes: 38112
<?php
fscanf(STDIN, "%s", $a);

$str = $a;

while(strlen($a) > 0) {
	$a = substr($a, 0, -1);
	
	if(strlen($a) % 2 === 0) {
		if(substr($a, 0, strlen($a)/2).substr($a, 0, strlen($a)/2) === $a) {
			print_r(strlen($a));
			break;
		}
	}	
}

Measured memory_bytes: 4728
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    int N, M, X, Y;
    int x[100];
    int y[100];
    cin >> N >> M >> X >> Y;
    rep (i, N) {
        cin >> x[i];
        X = max(X, x[i]);
    }
    rep (i, M) {
        cin >> y[i];
        Y = min(Y, y[i]);
    }
    if (X < Y) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
    return 0;
    
}


Measured memory_bytes: 256
S = input()
T = input()
a = []
for i in range(len(S)):
    ok = True
    for j in range(len(T)):
        if i+j >= len(S):
            ok = False
            break
        if S[i+j] == '?':
            continue
        if S[i+j] != T[j]:
            ok = False
            break
    if not ok:
        continue
    U = list(S)
    for j in range(len(T)):
        U[i+j] = T[j]
    for i in range(len(U)):
        if U[i] == '?':
            U[i] = 'a'
    a.append("".join(U))
if a:
    print(sorted(a)[0])
else:
    print("UNRESTORABLE")


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

int main() {
  int n, k;
  cin >> n >> k;
  set<int> s;
  while (k--) {
    int d;
    cin >> d;
    while (d--) {
      int a;
      cin >> a;
      s.insert(a);
    }
  }
  cout << n - s.size() << endl;
}


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

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


int main(void){

    int n, m;
    cin >> n >> m;

    vector<int> h(n);
    rep(i, n) cin >> h.at(i);

    //始点、高さの差
    vector<pair<int,int>>P[n];
    bool check[n];
    rep(i, n) check[i] = true;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        check[a - 1] = false;
        check[b - 1] = false;
        //始点-相手
        int dis = h.at(a - 1) - h.at(b - 1);
        int dis2 = h.at(b - 1) - h.at(a - 1);
        P[a-1].push_back(make_pair(b, dis));
        P[b-1].push_back(make_pair(a, dis2));
    }

    int cnt = 0;
    rep(i, n){
        if(check[i]){
            cnt++;
            continue;
        }
        bool OK = true;
        for (int j = 0; j < P[i].size(); j++){
            if(P[i].at(j).second <= 0)
                OK = false;
        }
        if(OK)
            cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 9588
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n, k := nextInt(), nextInt()

	if k%2 == 0 {
		a := n / k
		b := (n + (k / 2)) / k
		fmt.Println(a*a*a + b*b*b)
	} else {
		a := n / k
		fmt.Println(a * a * a)
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define  inf 2e18
#define  bg begin()
#define  en end()
#define  ll long long int
#define  pb push_back
#define  mp make_pair
#define  mod 1000000007
#define  vi vector<int>
#define  eb emplace_back
#define  lb(v,a) lower_bound(v.begin(),v.end(),a)
#define  ub(v,a) upper_bound(v.begin(),v.end(),a)
#define  bs binary_search
#define  vll vector<long long int>
#define  vpll vector<pair<long long int,long long int> >
#define  vpii vector<pair<int,int> >
#define  mpii map<int ,int>
#define  mpll map<long long int,long long int >
#define  max3(a,b,c) max(a,max(b,c))
#define  min3(a,b,c) min(a,min(b,c))
#define  w(t) ll t; cin>>t; while(t--)
#define  forn(i,n) for(int i=0;i<n;i++)
#define  forn1(i,n) for(int i=1;i<=n;i++)
#define  forv(it,v) for(auto it=v.begin();it!=v.end();it++)
#define  mem(a,val) memset(a,val,sizeof(a))
#define  Sort(vec) sort(vec.begin(),vec.end())
#define  RSort(vec) sort(vec.rbegin(),vec.rend())
#define  vin(v,n) for(int i=0;i<n;i++){cin>>x; v.pb(x);}
#define  deb1(x) cerr<<#x<<": "<<x<<" "<<endl
#define  deb2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define  deb3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define  deb4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define  FIFO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define  PI 3.141592653589793238462643383279502884L
mpii mpx;
vector<vector<int> > G;
void bfs(int o, int dp[], int n, int par[]) {
    queue<int> q;
    q.push(o);
    dp[o] = 0;
    par[o] = INT_MAX;
    bool visited[n + 1] = {0};
    visited[o] = true;
    while (q.empty() == false) {
        int a = q.front();
        q.pop();
        for (int u : G[a]) {
            if (visited[u] == false) {
                visited[u] = true;
                q.push(u);
                dp[u] = dp[a] + 1;
                par[u] = a;
            }
        }
    }
}



int main() {
    int n, m;
    cin >> n >> m;
    G.resize(n + 1);
    int a, b;
    forn1(i, m) {
        cin >> a >> b;
        G[a].pb(b);
        G[b].pb(a);
    }
    int dp[n + 1], par[n + 1];
    for (int i = 1; i <= n; i++) {
        dp[i] = INT_MAX;
        par[i] = INT_MAX;
    }
    bfs(1, dp, n, par);
    forn1(i, n)
    {
        if (dp[i] == INT_MAX) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int i = 2; i <= n; i++)
        cout << par[i] << endl;
    return 0;
}


Measured memory_bytes: 10708
import collections
N, M = map(int, input().split())
G = collections.defaultdict(list)
for _ in range(M):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
    
dist = [-1] * (N + 1)
que = collections.deque()

dist[1] = 0
que.append(1)

while len(que):
    v = que.popleft()
    for nv in G[v]:
        if dist[nv] != -1:
            continue
        dist[nv] = v
        que.append(nv)

print('Yes')
for value in dist[2:]:
    print(value)

Measured memory_bytes: 39116
#include<iostream>
#include<cmath>

using namespace std;

int main(){
	int n, a, b, f;
	cin >> n >> a >> b;
	f = (abs(a - b) - 1) % 2;
	if(f == 1){
		cout << "Alice" << endl;
	}else{
		cout << "Borys" << endl;
	}
	return 0;
}

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

int main(){
  int s,c;
  cin >> s >> c;
  vector<pair<int,int>>check(c,pair<int,int>(0,0));
  vector<pair<int,int>>stu(s,pair<int,int>(0,0));
  for(int i=0;i<s;i++)
    cin >> stu.at(i).first >> stu.at(i).second;
  for(int i=0;i<c;i++)
    cin >> check.at(i).first >> check.at(i).second;
  vector<int>ans(s);
  for(int i=0;i<s;i++){
    int64_t near=10e8;
    for(int j=0;j<c;j++){
      if(abs(check.at(j).first-stu.at(i).first)+abs(check.at(j).second-stu.at(i).second)<near){
        near=abs(check.at(j).first-stu.at(i).first)+abs(check.at(j).second-stu.at(i).second);
        ans.at(i)=j;
      }
    }
  }
  for(int i=0;i<s;i++)
    cout << ans.at(i)+1 << endl;
}

Measured memory_bytes: 3592
N = int(input())
ans = 0
a, b, ab = 0, 0, 0
for _ in range(N):
  s = input()
  ans += s.count('AB')
  if s[-1] == 'A' and s[0] == 'B':
    ab += 1
  elif s[-1] == 'A':
    a += 1
  elif s[0] == 'B':
    b += 1
if ab > 0:
  ans += ab-1
  if a > 0:
    ans += 1
    a -= 1
  if b > 0:
    ans += 1
    b -= 1
ans += min(a, b)
print(ans)

Measured memory_bytes: 9184
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

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

    // input
    ll N, M, K;
    cin >> N >> M;
    vector<ll> sum_vec(M+1, 0);
    REP(i, N) {
        cin >> K;
        vector<ll> vec(K);
        REP(j, K) {
            cin >> vec[j];
            sum_vec[vec[j]]++;
        }
    }
    
    // calculation
    ll res = 0;
    REPN(i, M+1) {
        if (sum_vec[i] == N) res++;
    }
    
    cout << res << "\n";
    
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;


public class Main {

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

		while (sc.hasNext()) {
			int n = sc.nextInt();
			StringBuilder sb = new StringBuilder();
			for (int i = 0 ; i < 10 ; i++) {
				if ((n & (int) Math.pow(2, i)) != 0) sb.append((int) Math.pow(2, i)).append(" ");

			}
			System.out.println(sb.deleteCharAt(sb.length()-1));
		}

	}
}

Measured memory_bytes: 17208
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
list<int> L;
stack<int> S;
queue<int> Q;
deque<int> dq;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=100000;
static const int NMAX=50;
static const int MMAX=50;
ll N,T,t1,t2,sum;

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    cin>>N>>T;
    
    for(int i=0;i<N;i++){
        cin>>t2;
        if(t1+T<=t2)sum+=T;
        else sum+=t2-t1;
        t1=t2;
    }
    cout<<sum+T<<"\n";
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define PB push_back
#define POP pop_back()
#define PII pair<int,int>
#define FI first
#define SE second
#define ULL unsigned long long
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
char mp[10][10];
bool tt[10][10];
int h,w,k,num;
int check(int x,int y){
	for(int i=0;i<10;i++)
	for(int j=0;j<10;j++){
		tt[i][j]=0;
	}
	int cnt=1;
	while(x){
		if(x&1){
			for(int i=1;i<=w;i++)if(mp[cnt][i]=='#')tt[cnt][i]=1;	
		}
		cnt++;
		x>>=1;
	}
	cnt=1;
	while(y){
		if(y&1){
			for(int i=1;i<=h;i++)if(mp[i][cnt]=='#')tt[i][cnt]=1;	
		}
		cnt++;
		y>>=1;
	}
	cnt=0;
	for(int i=1;i<=h;i++)
	for(int j=1;j<=w;j++){
		if(!tt[i][j]&&mp[i][j]=='#')cnt++;
	}
	return cnt;
}
int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	cin>>h>>w>>k;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>mp[i][j];
		}	
	}
	int ans=0;
	int tmp1=1<<h,tmp2=1<<w;
	for(int i=0;i<tmp1;i++){
		for(int j=0;j<tmp2;j++){
			//cout<<"i="<<i<<" j="<<j<<endl;
			if(check(i,j)==k)ans++;
		}
	}
	cout<<ans<<endl;
 	return 0;
}







Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using ld = long double;
using Point = complex<ld>;
using Set = vector<Point>;
const ld pi = acos(-1);
constexpr ld eps = 1e-10;
constexpr ld inf = 1e12;

istream& operator>>(istream& is, Point& p){
    ld x, y;
    is >> x >> y;
    p = Point(x, y);
    return is;
}
ostream& operator<<(ostream& os, const Point& p){
    return os << p.real() << ' ' << p.imag() << '\n';
}

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

    int n;
    cin >> n;
    Set ps(n);
    vector<pair<ld, int>> foo;
    for(int i = 0; i < n; ++i){
        cin >> ps[i];
        foo.emplace_back(arg(ps[i]), i);
    }
    sort(foo.begin(), foo.end());
    Set table(n);
    for(int i = 0; i < n; ++i){
        table[i] = ps[foo[i].second];
    }
    ld ans = 0.0;
    for(int k = 1; k <= n; ++k){
        for(int i = 0; i < n; ++i){
            Point cur = table[i];
            for(int j = 1; j < k; ++j){
                cur += table[(i + j) % n];
            }
            chmax(ans, abs(cur));
        }
    }
    cout << fixed << setprecision(15);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
#define rep(i,n) for (i = 0; i < n; ++i) 
#define REP(i,k,n) for (i = k; i <= n; ++i) 
#define REPR(i,k,n) for (i = k; i >= n; --i)
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n,r,l ,ans=0;
    cin>>l>>r>>n;
    ll tr = l/n;
    if(tr*n==l)
    {
        l = tr*n;
    }
    else
    l = (tr+1)*n;
    for(int i = l;i<=r;i=i+n)
    ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

main()
{
  int length, i, j, tmp, count = 0;
  int A[100];

  scanf("%d", &length);

  for(i = 0; i < length; i++)
    {
      scanf("%d", &A[i]);
    }

  for(i = 0; i < length - 1; i++)
    {
      for(j = length - 1; j >= i + 1; j--)
	{
	  if(A[j] < A[j - 1])
	    {
	      tmp = A[j];
	      A[j] = A[j - 1];
	      A[j - 1] = tmp;
	      count++;
	    }
	}
    }
  for(i = 0; i < length; i++)
    {
      if(i == length - 1)
	{
	  printf("%d\n", A[i]);
	}
      else
	{
	  printf("%d ", A[i]);
	}
    }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 600
package main

import (
	"fmt"
	"math"
)

func main() {
	var (
		n int
	)
	fmt.Scan(&n)

	x1 := int(math.Ceil(math.Sqrt(float64(n))))
	a := x1*x1 - n
	fmt.Printf("0 0 %v %v %v %v", x1, 1, a, x1)
}


Measured memory_bytes: 512