akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <bitset>
#include <time.h>

using namespace std;
typedef long long  ll;
static const int M = 100000;
#define rep(i,s,n)for(int i = s;i<n;i++)

#include <fstream>

vector<ll> A;
vector<ll> B;
vector<ll> C;

int main()
{
	int N; cin >> N;
	rep(i, 0, N) {
		ll a; cin >> a;
		A.push_back(a);
	}
	rep(i, 0, N) {
		ll b; cin >> b;
		B.push_back(b);
	}
	rep(i, 0, N) {
		ll c; cin >> c;
		C.push_back(c);
	}

	sort(A.begin(), A.end());
	sort(C.begin(), C.end());

	ll count = 0;
	rep(i, 0, N) {
		ll xx = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
		ll yy = C.end() - upper_bound(C.begin(), C.end(), B[i]);
		count += xx * yy;
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3316
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
S = list(input())
white = [0] * (n+1)
black = [0] * (n+1)
for i in range(n):
    white[i+1] = white[i]  + (1 if S[i] == '.' else 0)
    black[i+1] = black[i] + (1 if S[i] == '#' else 0)
res = float('inf')
# 累積和で最小値を求める
for left in range(n+1):
    tmp = 0
    # leftを全部白に、
    tmp += black[left] - black[0]
    tmp += white[n] - white[left]
    res = min(res,tmp)
print(res)


Measured memory_bytes: 27616
import math
N = int(input())
X = [int(x) for x in input().split()]
s = sum(X)
p = s/N
floor = s//N
if p-floor >= 0.5:
  m = math.ceil(s/N)
else:
  m = math.floor(s/N)
square = [x**2 for x in X]
result = N*m**2 - 2*s*m + sum(square)
print(result)

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"math"
)

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

	p := make([]float64, n+1)
	q := make([]float64, n+1)
	psum := make([]float64, n+2) // i番目はi-1までの和とする
	qsum := make([]float64, n+2) // i番目はi-1までの和とする
	for i := 1; i <= n; i++ {
		fmt.Scan(&p[i])
		psum[i+1] = psum[i] + p[i]
	}
	for i := 0; i <= n; i++ {
		fmt.Scan(&q[i])
		qsum[i+1] = qsum[i] + q[i]
	}

	dp := make([][]float64, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]float64, n+1)
	}

	// calc
	for d := 0; d <= n; d++ {
		for l := 0; l+d <= n; l++ {
			r := l+d
			if l == r {
				dp[l][r] = q[l]
				continue
			}

			dp[l][r] = 1 << 30
			// iは中心となるnode
			for i := l+1; i <= r; i++ {
				left := dp[l][i-1] + psum[i] - psum[l+1] + qsum[i] - qsum[l]
				right := dp[i][r] + psum[r+1] - psum[i+1] + qsum[r+1] - qsum[i]
				dp[l][r] = math.Min(dp[l][r], p[i] + left + right)
			}
		}
	}

	fmt.Printf("%.8f\n", dp[0][n])
}



Measured memory_bytes: 3376
import java.util.Scanner;

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

		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] array = new int[w];
		int swap1, swap2;
		byte garbage;

		for(int i = 0;i < w;i++) array[i] = i + 1;

		for(int i = 0;i < n;i++){
//			String swap = sc.next();
			String[] swaps = sc.next().split(",", 0);

			swap1 = Integer.parseInt(swaps[0]) - 1;
			swap2 = Integer.parseInt(swaps[1]) - 1;

			int temp = array[swap1];
			array[swap1] = array[swap2];
			array[swap2] = temp;
		}

		for(int i = 0;i < w;i++){
			System.out.println(array[i]);
		}

	}
}


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

orders = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]
ans = []

for order in orders:
    cost = abs(A[order[0]] - A[order[1]]) + abs(A[order[1]] - A[order[2]])
    ans.append(cost)
    
print(min(ans))

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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define bits(n) __builtin_popcount(n)


void solve()
{
    int n,d;
    int c=0;
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        long double dist=sqrt((ll)x*x+(ll)y*y);

        if(dist<=d)
        c++;
    }
    cout<<c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define mod 1000000007
 
using namespace std;
 
int main(){
  int i,N,M;
  cin >> N >> M;
  vector<int> A(N);
  int sum=0;
  for(i=0; i<N; i++){
    cin >> A[i];
    sum += A[i];
  }
  int min = sum/(4*M);
  sort(A.begin(),A.end());
  if(A[N-M]*4*M >= sum) cout << "Yes";
  else cout << "No";
 
  return 0;
}

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

int main() {
    int n;
    while (cin>>n, n) {
        map<long long, int> m;
        int c=0, res=0, a;
        for (int i=0; i<n; ++i) {
            cin >> a;
            int &ma = m[a];
            ++ma;
            if (c < ma) {
                c = ma; res = a;
            }
        }
        if (n < c*2) {
            cout << res << endl;
        } else {
            cout << "NO COLOR" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3244
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x) {
	x=0; char c=getchar(); int f=1;
	while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
	while (c>='0'&&c<='9') {x=10*x+c-'0'; c=getchar();} x*=f;
}
const int N = 600000;
int n,a,b;
int ans[N],len;

int main() {
	read(n); read(a); read(b);
	if (1LL*a*b>=n&&a+b<=n+1) {
	//	int mx=n;
	//	per(i,a,1) ans[++len]=n-i+1; mx=n-a;
		ans[++len]=a; int tot=n-a;
		rep(i,2,b) {ans[i]++; tot--;}
		rep(i,2,b) {
			while (ans[i]+1<=a&&tot) {ans[i]++; tot--;}
		}
		int mx=n;
		rep(i,1,b) {
			per(j,ans[i],1) printf("%d ",mx-j+1); mx-=ans[i];
		}
	}
	else puts("-1");
	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
const int maxn = 255;
int col[maxn];
int rem[maxn];
int dis[maxn];
int n;
char mp[maxn][maxn];
bool nott[maxn];
queue<int> q;

bool bfs(int x){
    memset(dis, 0, sizeof(dis));
    memset(col, 0, sizeof(col));
    q.push(x);
    col[x] = 1;
    dis[x] = 1;
    int minv = x;
    int max_dis = 1;
    while(!q.empty()){
        int u = q.front(); q.pop();
        for(int i = 1; i <= n; i ++){
            if(mp[u][i] == '0') continue;
            if(col[i] == col[u]){
                return false;
            }
            else if(col[i]) continue;
            dis[i] = dis[u] + 1;
            col[i] = -1 * col[u];
            q.push(i);
            minv = min(minv, i);
            max_dis = max(max_dis, dis[i]);
        }
    }
    nott[minv] = true;
    rem[minv] = max(rem[minv], max_dis);
    return true;
}

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++){
        scanf("%s", mp[i] + 1);
    }

    for(int i = 1; i <= n; i ++){
        if(!bfs(i)){
            printf("-1");
            return 0;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i ++){
        if(nott[i]) 
            ans += rem[i];
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
ll modpow(long long a, long long n, long long mod2) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod2;
        a = a * a % mod2;
        n >>= 1;
    }
    return res;
}

int main() {
    int n;
    double ans = 0.0;
    cin >> n;
    vector<pair<double,double>> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(),p.end());
    do{
        for (int i = 1; i < n; ++i) {
            ans += sqrt(pow(p[i].first-p[i-1].first,2)+pow(p[i].second-p[i-1].second,2));
        }
    }while(next_permutation(p.begin(),p.end()));
    double waru = 1;
    for (int i = 1; i <= n; ++i) {
        waru *= i;
    }
    cout << fixed << setprecision(10) << ans/waru << endl;
    return 0;
}


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

int main()
{
  int A,B;
  cin >> A >> B;
  if (A==B)
  {
    cout << (A+B) << endl;
    return 0;
  }
  
  if (A>B)
  {
    cout << (A+A-1) << endl;
    return 0;
  }
  cout << (B+B-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;

int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

bool equal(string s) {
  for(int i = 0,j = s.size()/2;j < s.size();i++,j++) {
    if(s[i] != s[j]) return false;
  }
  return true;
}

int main() {
  int n,m;
  cin>>n>>m;
  int a[n+1]; 
  memset(a,0,sizeof a);
  frn(i,m) {
    int x,y;
    cin>>x>>y;
    a[x]++, a[y]++;
  }
  fr(i,1,n+1) {cout<<a[i];nl;}
}

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n;cin>>n;
    set<ll> a;
    rep(i,n){
        ll num;
        cin>>num;
        
        if(a.find(num)==a.end()) a.insert(num);
        else a.erase(num);
    }

    cout<<a.size()<<endl;
    return 0;
}

Measured memory_bytes: 8272
def read_input():
    s = input()
    return s

def submit():
    s = read_input()

    p_card = 0
    hands = []
    for c in s:
        if p_card == 0:
            hands.append('g')
            p_card += 1
            continue

        if c == 'p':
            if p_card > 0:
                hands.append('p')
                p_card -= 1
                continue
            else:
                hands.append('g')
                p_card += 1
                continue
        else:
            if p_card > 0:
                hands.append('p')
                p_card -= 1
                continue
            else:
                hands.append('g')
                p_card += 1
                continue

    win = 0
    loose = 0
    for a,t in zip(hands, s):
        if a == t:
            continue

        if a == 'g':
            loose += 1
        else:
            win += 1

    print(win - loose)



if __name__ == '__main__':
    submit()


Measured memory_bytes: 3964
line = input().split(" ")
n = int(line[0])
a = int(line[1])
b = int(line[2])
sum = 0

def keisan(x):
    ressum = 0
    for j in list(x):
        ressum += int(j)
    return ressum

for i in range(1, n+1, 1):
    num = keisan(str(i))
    if(num >= a and num <= b):
        sum += i
print(sum)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int k;
    cin >> k;

    cout << (k / 2) * ((k % 2) + k / 2) << endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;

using ci = const int;
using ld = long double;
using llint = long long;
using ullint = unsigned long long;
using pii = pair <int,int>;
using pcc = pair <char,char>;
using pll = pair <llint,llint>;
using pss = pair <string,string>;
using vi = vector <int>;
using vb = vector <bool>;
using vll = vector <llint>;
using vii = vi::iterator;

#define INF (1<<30)
#define MOD 1000000007
#define mt make_tuple
#define all(c) c.begin(), c.end()
#define ms(name,val) memset(name, val, sizeof name)
#define np nullptr
// inline functions



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

    int n;
    cin >> n;
    vi v(n), dp(n+1, INF);

    for (int t1 = 0; t1 < n; ++t1)
        cin >> v[t1];

    dp[0] = 0;
    dp[1] = abs(v[0]-v[1]);

    for (int t1 = 2; t1 < n; ++t1)
        dp[t1] = min(dp[t1-2] + abs(v[t1]-v[t1-2]),
                     dp[t1-1] + abs(v[t1]-v[t1-1]));

    cout << dp[n-1] << '\n';






























    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

int main() {
  int n;
  std::cin >> n;
  int room[5][4][11] = {};
  
  for (int i = 0; i < n; i++) {
    int b, f, r, v;
    std::cin >> b >> f >> r >> v;
    room[b][f][r] += v;
  }
  
  for (int b = 1; b < 5; b++) {
    for (int f = 1; f < 4; f++) {
      for (int r = 1; r < 11; r++) {
        std::cout << " " << room[b][f][r];
      }
      std::cout << "\n";
    }
    if (b < 4) std::cout << "####################" << "\n";
  }
  
  return 0;
}

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

string LCS(string s, string t){
    ll ns = s.size();
    ll nt = t.size();
    vector< vector<ll> > dp(ns+1, vector<ll> (nt+1, 0));
    // initilaize
    rep(i, 0, ns){
        if(s[i] == t[0]) dp[i][0] = 1;
    }
    rep(i, 0, nt){
        if(s[0] == t[i]) dp[0][i] = 1;
    }
    // build DP table
    rep(i, 1, ns){
        rep(j, 1, nt){
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i] == t[j]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
        }
    }
    // make LCS
    string ret;
    ll i = ns-1, j = nt-1;
    while(i >= 0 && j >= 0){
        if(s[i] == t[j]){
            ret.push_back(s[i]);
            i--; j--;
        }else{
            if(j == 0) i--;
            else if(i == 0) j--;
            else if(dp[i-1][j] > dp[i][j-1]) i--;
            else j--;
        }
    }
    return ret;
}

int main(){
    ll Q;
    cin >> Q;
    rep(q, 0, Q){
        string x, y;
        cin >> x >> y;
        cout << LCS(x, y).size() << endl;
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;

int dp[114514][3];

int main(){
	int n;
	cin>>n;
	vector<int>a(n),b(n),c(n);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<3;j++){
			if(j%3==0)dp[i][j]=max(dp[i-1][j+1]+b[i-1],dp[i-1][j+2]+c[i-1]);
			else if(j==1)dp[i][j]=max(dp[i-1][j-1]+a[i-1],dp[i-1][j+1]+c[i-1]);
			else dp[i][j]=max(dp[i-1][j-2]+a[i-1],dp[i-1][j-1]+b[i-1]);
		}
	}
	int ans=0;
	for(int i=0;i<3;i++){
		if(dp[n][i]>ans)ans=dp[n][i];
	}
	cout<<ans<<endl;
	return 0;	
}


Measured memory_bytes: 2560
#include<stdio.h>
#define N 100
int main(){
  int i,j,key,n,A[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n;i++){
    key=A[i];
    j=i-1;
    while(j>=0&&key<A[j]){
      A[j+1]=A[j];
      j--;
      A[j+1]=key;
    }
    for(j=0;j<n;j++){
      if(j>=0 && j<n-1){
 printf("%d ",A[j]);
      }
      if(j==n-1){
 printf("%d",A[j]);
      }
    }
    printf("\n");
  }
    return 0;
  }

Measured memory_bytes: 604
"""Boot-camp-for-Beginners_Easy011_B_Collatz-Problem_29-August-2020.py"""
import numpy as np

#N = 100
N=int(input())
Division_2 = []
number=[]
for i in range(1, N+1):
    j = i
    count = 0
    while True:
        if j/2 != int(j/2):
            break
        j = j/2
        count += 1
    Division_2.append(count)
    number.append(i)
Division_2=np.array(Division_2)
print(number[np.argmax(Division_2)])
#print(Division_2)


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

int main() {
  int N;
  cin >> N;
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    if ((i+1)%15 == 0) {
      ans += 0;
    }
    else if ((i+1)%3 == 0) {
      ans += 0;
    }
    else if ((i+1)%5 == 0) {
      ans += 0;
    }
    else {
      ans += i+1;
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // write your code here
        //dream dreamer erase eraser
        int A;
        int B;
        int C;
        int D;
        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            D = sc.nextInt();

        }
        if (B < C || D < A) {
            System.out.println("0");
        } else {
            int start = Math.max(A, C);
            int end = Math.min(B, D);
            System.out.println(end - start);
        }

    }

}


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

long long calc(string s){
  int N = s.length();
  long long ret = stoll(s);
  
  //recursive step
  for(int i=1;i<N;i++){
    string sl = s.substr(0,i);
    string sr = s.substr(i,N-i);
    ret += stoll(sl)*pow(2,sr.length()-1);
    ret += calc(sr);
  }
  
  return ret;
}

int main(){
  string s;
  cin >> s;
  cout << calc(s) << endl;
  
  return 0;
}


Measured memory_bytes: 4000
import sys
input = sys.stdin.readline

n = int(input())
l = list(map(int,input().split()))

l.sort()
ans = 0

for i in range(n):
    count = i
    for j in range(i+1,n-1):
        ad = l[i] + l[j]
        if count < n:
            while l[count] < ad and count < n:
                count += 1
                if count == n:
                    break
        ans += count - j - 1

print(ans)


Measured memory_bytes: 42588
//package com.beginner.b051;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();

        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();

        sb2.append("L");

        for(int i=0;i<ty-sy;i++){
            sb1.append("U");
            sb2.append("U");
        }
        sb2.append("UR");
        for(int i=0;i<tx-sx;i++){
            sb1.append("R");
            sb2.append("R");
        }
        sb2.append("DR");
        for(int i=0;i<ty-sy;i++){
            sb1.append("D");
            sb2.append("D");
        }
        sb2.append("DL");

        for(int i=0;i<tx-sx;i++){
            sb1.append("L");
            sb2.append("L");
        }
        sb2.append("U");
        System.out.print(sb1.toString());
        System.out.println(sb2.toString());

        sc.close();
    }

}

Measured memory_bytes: 10188
#include <iostream>
#include <stdio.h>
#define N 251
using namespace std;

int main(){
	int n,heap[N];
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>heap[i];
	}
	for(int i=1;i<=n;i++){
		printf("node %d: key = %d, ",i,heap[i]);
		if((i/2)) printf("parent key = %d, ",heap[i/2]);
		if((2*i)<=n) printf("left key = %d, ",heap[2*i]);
		if((2*i+1)<=n) printf("right key = %d, ",heap[2*i+1]);
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1176
virgin = true

loop do
  n = gets.to_i
  break if n.zero?
  puts "" unless virgin

  teams = {}
  
  n.times do
    team_and_score = gets.chomp.split
    team = team_and_score.first
    wld = team_and_score[1..-1].map(&:to_i)
    score = 3*wld[0] + wld[2]
    if teams[score].nil?
      teams[score] = [team]
    else
      teams[score] << team
    end
  end

  teams.sort.reverse.each do |score_teams|
    s = score_teams.first
    score_teams.last.each{ |t| puts "#{t},#{s}"}
  end

  virgin = false if virgin
end

Measured memory_bytes: 6124
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vint t(n), x(n), y(n);
    rep(i, n) cin >> t[i] >> x[i] >> y[i];
    int nt = 0, nx = 0, ny = 0;
    rep(i, n) {
        int d = abs(nx-x[i]) + abs(ny-y[i]);
        int dt = t[i] - nt;
        if (dt < d || dt%2 != d%2) {
            puts("No");
            return 0;
        }
        nt = t[i];
        nx = x[i];
        ny = y[i];
    }
    puts("Yes");
    return 0;
}

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



int main()
{
    ll t,c=0;
    //cin>>t;
    //while(t--){
        ll n,x=0;ll s=101;
        cin>>n;
        ll l1[n+1];
        for(int i=1;i<=n;i++){
            cin>>l1[i];x+=l1[i];
            if(l1[i]%10!=0)s=min(s,l1[i]);
        }
        
        if(x%10!=0){
            cout<<x;return 0;
        }
        else if(s==101)cout<<0;
        else cout<<x-s;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

lint p=1000*1000*1000+7;

int main(){
  lint n,m;
  cin>>n>>m;
  lint x[n],y[m];
  REP(i,n)cin>>x[i];
  REP(i,m)cin>>y[i];
  sort(x,x+n);
  sort(y,y+m);
  lint dx[n-1],dy[m-1];
  REP(i,n-1)dx[i]=x[i+1]-x[i];
  REP(i,m-1)dy[i]=y[i+1]-y[i];
  lint X=0;
  lint Y=0;
  REP(i,n-1){
    X+=dx[i]*(i+1)*(n-i-1);
    X%=p;
  }
  REP(i,m-1){
    Y+=dy[i]*(i+1)*(m-i-1);
    Y%=p;
  }
  cout<<X*Y%p<<endl;
  return 0;
}


Measured memory_bytes: 3328
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K, L, R = LI()
    a = LI()

    N_half_A = N // 2
    A_sum = [[] for _ in range(N_half_A + 1)]
    for i in range(2 ** N_half_A):
        sum = 0
        num = 0
        for j in range(N_half_A):
            if (i >> j) & 1:
                sum += a[j]
                num += 1
        A_sum[num].append(sum)

    N_half_B = N - N_half_A
    B_sum = [[] for _ in range(N_half_B + 1)]
    for i in range(2 ** N_half_B):
        sum = 0
        num = 0
        for j in range(N_half_B):
            if (i >> j) & 1:
                sum += a[N_half_A + j]
                num += 1
        B_sum[num].append(sum)
    for i in B_sum:
        i.sort()

    ans = 0
    for i in range(N_half_A + 1):
        if 0 <= K - i <= N_half_B:
            for j in A_sum[i]:
                idx_l = bisect.bisect_left(B_sum[K-i], L - j)
                idx_r = bisect.bisect_right(B_sum[K-i], R - j)
                ans += idx_r - idx_l

    print(ans)


if __name__ == '__main__':
    resolve()



Measured memory_bytes: 107188
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<std::string> S(N);
  map<string, int> mp;
  for (int i = 0; i < N; i++)
  {
    std::cin >> S[i];
    mp[S[i]]++;
  }
  priority_queue<pair<ll, string>, vector<pair<ll, string>>, greater<pair<ll, string>>> q;
  for (auto &e : mp)
  {
    q.push({-e.second, e.first});
  }
  ll nmax = q.top().first;
  cout << q.top().second << endl;
  q.pop();
  while (nmax == q.top().first && !q.empty())
  {
    cout << q.top().second << endl;
    q.pop();
  }

  return 0;
}


Measured memory_bytes: 31216
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    int s,w;
    cin>>s>>w;
    if(w>=s)cout<<"unsafe";
    else cout<<"safe";  
  }  
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

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

		int ans = 0;
		for (int i = 0; i < N; i++) {
				int a;
				cin >> a;
				while (a % 2 == 0) {
						a /= 2;
						ans++;
				}
		}

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


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
i = 1
b = a.map.with_index(1){|x,i|
  x - i
  }
x = b.sort[n/2]
sum = 0
b.each do |s|
  sum += (s-x).abs
end
puts sum

Measured memory_bytes: 20608
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        h: usize,
        w: usize,
        k: usize,
        v: [chars; h]
    }
    let mut ac = vec![vec![0; w + 1]; h + 1];
    for i in 0..h {
        for j in 0..w {
            ac[i + 1][j + 1] = ac[i + 1][j] + ac[i][j + 1] - ac[i][j] + (v[i][j] as u8 - '0' as u8) as usize;
        }
    }
    let mut ans = h * w;
    'next: for s in 0..1 << h - 1 {
        let mut t = 0;
        for i in 0..h - 1 {
            if s & 1 << i != 0 {
                t += 1;
            }
        }
        let mut yp = 0;
        for j in 0..w {
            let mut xp = 0;
            let mut f = false;
            for i in 0..h - 1 {
                if s & 1 << i == 0 {
                    continue;
                }
                f |= ac[i + 1][j + 1] + ac[xp][yp] - ac[xp][j + 1] - ac[i + 1][yp] > k;
                xp = i + 1;
            }
            f |= ac[h][j + 1] + ac[xp][yp] - ac[xp][j + 1] - ac[h][yp] > k;
            if f {
                if yp == j {
                    continue 'next;
                }
                t += 1;
                yp = j;
            }
        }
        ans = min(ans, t);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
N=int(input())
L= [int(i) for i in input().split()]

L.sort()
larger=[N]
prev=1
for i in range(N):
    larger= larger +[N-i]*(L[i]-prev)
    prev=L[i]

total=0    
for i in range(N-2):
    low=L[:i+1]
    high=L[i+1:]
    for j in range(len(high)-1):
        diff = high[j+1]-high[0]
        if diff >= len(larger):
            count = 0
        else:
            count = max(larger[diff] - (N-i-1),0)
        total += count
        
print(total)

Measured memory_bytes: 3316
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>
#define INF 2147483647

using namespace std;



int main()
{
	double x1, y1, x2, y2;

	cin >> x1 >> y1 >> x2 >> y2;

	cout << fixed << setprecision(8) << sqrt(pow(x2 - x1, 2.0) + pow(y2 - y1, 2.0))  <<  endl;

	return (0);
}

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

int main(){
  int n;
  cin >> n;
  map<string,int> mp;
  rep(i,n){
    string s;
    cin >> s;
    mp[s]++;
  }
  int mx = 0;
  for(auto p:mp) mx = max(mx,p.second);
  for(auto p:mp){
    if(p.second!=mx)continue;
    cout << p.first << endl;
  }
}


Measured memory_bytes: 25216
use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let mut editing = Vec::new();
    for c in stdin.lock().gets().chars() {
        match c {
            '0' | '1' => editing.push(c),
            'B' => { editing.pop(); },
            _ => panic!("Invalid input"),
        }
    }
    println!("{}", editing.into_iter().collect::<String>());
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define rep(i, n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) cout << setfill('0') << setw(len) << right << a << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

signed main() {
    string s, t;
    cin >> s >> t;
    auto ans = "No";

    string s2 = s + s;
    for (int i = 0; i < t.size(); ++i) {
        string sub = s2.substr(i, t.size());
        if (sub == t) ans = "Yes";
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2


ll power(int k) {
	int ret = 1;
	rep(i, 0, k)ret *= 2;
	return ret;
}
void err() {
	cout << "-1" << endl;
	exit(0);
}

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

	if (m == 0) {
		if (k != 0)err();
		else {
			cout << 0 << " " << 0 << endl;
			return 0;
		}
	}
	else if (m == 1) {
		if (k != 0)err();
		else {
			cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl;
			return 0;
		}
	}else if (k >= power(m)) {
		err();
	}
	else if (k == 0) {
		rep(i, 0, power(m+1)) {
			if (i)cout << " ";
			cout << i / 2;
		}
		cout << endl;
		return 0;
	}else {
		set<int>st;
		vector<pair<int, int>>match;
		rep(i, 0, power(m)) {
			if (!st.count(i) && !st.count(i^k)) {
				match.pb({ i,i^k });
				st.insert(i);
				st.insert(i^k);
			}
		}
		vector<int>ans;
		for (int i = 0; i < power(m)/2; i += 2) {
			auto p1 = match[i];
			auto p2 = match[i + 1];
			int a = p1.first;
			int b = p1.second;
			int c = p2.first;
			int d = p2.second;
			ans.pb(a);
			ans.pb(b);
			ans.pb(c);
			ans.pb(d);
			ans.pb(b);
			ans.pb(a);
			ans.pb(d);
			ans.pb(c);
		}
		rep(i, 0, ans.size()) {
			if (i)cout << " ";
			cout << ans[i];
		}
		cout << endl;
	}


	return 0;
}


Measured memory_bytes: 9588
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        String str = "" + N;
        int sum = 0;
        for (char tmp : str.toCharArray()) {
            sum += Integer.parseInt("" + tmp);
        }
        if(N % sum == 0) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23892
#include<stdio.h>

int main(void){
    int k, s, count = 0;;
    scanf("%d %d", &k, &s);
    int t = s / 3, u, z; 

    for(int x = 0; x <= t; x++){
        u = s - x;
        for(int y = x; 2 * y <= u; y++){
            z = u - y;
            if(z <= k){
                if(x != y && y != z){
                    count += 6;
                }else if(x == y && z == y){
                    count++;
                }else{
                    count += 3;
                }
            }
        }
    }
    printf("%d", count);

    return 0;
}


Measured memory_bytes: 1732
#include <cstdio>
#include <algorithm>

using namespace std;

int K, N, A[200010];
int ans;

int main() {
    scanf("%d%d", &K, &N);
    for (int i = 1; i <= N; ++i) {
        scanf("%d", &A[i]);
    }
    ans = A[1] + K - A[N];
    for (int i = 2; i <= N; ++i) {
        ans = max(ans, A[i] - A[i - 1]);
    }
    printf("%d\n", K - ans);
    return 0;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))

int main(){
    FAST
    int n; cin >> n;
    cout << n * n * 3;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 5000;
int N,K;
ll A[Nmax];

bool cond(int n){
	vector<bool> vec(K);
	vec[K-1] = true;
	for(int j=0; j<N; j++){
		if(j==n) continue;
		for(int k=0; k<K; k++){
			if(k+A[j]<K) vec[k] = vec[k] || vec[k+A[j]];
		}
	}

	bool ok = true;
	for(int k=0; k<min(A[n], (ll)K); k++){
		ok = ok && !vec[k];
	}
	return ok;
}

int main(){
	cin >> N >> K;
	for(int i=0; i<N; i++) cin >> A[i];

	sort(A, A+N);

	if(!cond(0)){
		cout << 0 << endl;
		return 0;
	}
	if(cond(N-1)){
		cout << N << endl;
		return 0;
	}

	int lb=0, ub=N-1;

	while(ub-lb>1){
		int med = (ub+lb)/2;
		if(cond(med)){
			lb = med;
		}
		else{
			ub = med;
		}
	}

	cout << ub << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int d = stdIn.nextInt();
		
		int ans = (int)Math.ceil(n/(2*d+1.0));
		
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int MAXN = 1000001;
vector<int> adj[MAXN];
int power(int x, int y, int p = mod){ 
    int res = 1; 
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0) {  
        if (y & 1) res = (res*x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
} 
int modFact(int n, int p = mod) 
{ 
    if (n >= p) 
        return 0; 
  
    int result = 1; 
    for (int i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result; 
} 
int32_t main(){
    SPEED;
    int n;
    cin >> n;
    string s[n];
    set<string> dif;
    for(int i = 0; i < n; ++i){
        cin >> s[i];
        dif.insert(s[i]);
    }
    if(len(dif) == n){
        for(int i = 0; i < n - 1; ++i){
            int x = len(s[i]);
            if(s[i][x - 1] != s[i + 1][0]){
                cout << "No";
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

}
// check indices of loop
// check for overflow


Measured memory_bytes: 27100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * One-Dimensional Cellular Automaton - Accepted
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			StringTokenizer st = new StringTokenizer(line);

			int N, M, A, B, C, T;
			N = parseInt(st.nextToken());
			M = parseInt(st.nextToken());
			A = parseInt(st.nextToken());
			B = parseInt(st.nextToken());
			C = parseInt(st.nextToken());
			T = parseInt(st.nextToken());
			if ((N | M | A | B | C | T) == 0) break;

			//
			int[][] mat = new int[N][N];

			for (int i = 0; i < N; i++) {
				if (i - 1 >= 0) mat[i][i - 1] = A;
				mat[i][i] = B;
				if (i + 1 < N) mat[i][i + 1] = C;
			}

			int[][] aa = pow(mat, T, M);

			//
			st = new StringTokenizer(br.readLine());

			int[][] S = new int[N][1];

			for (int i = 0; i < N; i++) {
				S[i][0] = parseInt(st.nextToken());
			}

			S = mul(aa, S, M);

			String[] SS = new String[N];

			for (int i = 0; i < N; i++) {
				SS[i] = String.valueOf(S[i][0]);
			}

			System.out.println(String.join(" ", SS));
		}
	}

	static int[][] mul(int[][] a, int[][] b, int mod) {

		int[][] t = new int[a.length][b[0].length];

		for (int i = 0; i < a.length; i++) {
			for (int k = 0; k < b.length; k++) {
				for (int j = 0; j < b[0].length; j++) {
					t[i][j] = (t[i][j] + a[i][k] * b[k][j]) % mod;
				}
			}
		}

		return t;
	}

	static int[][] pow(int[][] a, int e, int mod) {

		if (e == 0) {
			int[][] t = new int[a.length][a[0].length];
			for (int i = 0; i < a.length; i++) {
				t[i][i] = 1;
			}
			return t;
		}

		if (e == 1) return a;

		int[][] t = {};

		t = pow(mul(a, a, mod), e / 2, mod);
		if (e % 2 == 1) t = mul(t, a, mod);

		return t;
	}
}

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

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> cities(N), roads(2*M);
	
	for(int i = 0;i<2*M;i++){
		cin >> roads.at(i);
	}
	
	for(int j = 0;j<2*M;j++){
		int c;
		c = roads.at(j);
		c = c-1;
		cities.at(c)++;
	}
	
	for(int k = 0;k<N;k++){
		cout << cities.at(k) << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
X = []
U = []
for i in range(N):
    I = input().split()
    (x, u) = (float(I[0]), I[1])
    X.append(x)
    U.append(u)

otoshidama = 0.0

for i in range(N):
    if U[i] == "JPY":
        otoshidama += X[i]
    elif U[i] == "BTC":
        otoshidama += X[i] * 380000.0

print(otoshidama)

Measured memory_bytes: 3064
d=input().split()
for _ in range(int(input())):
 t,f=[d.index(s)for s in input().split()]
 n=[(1,2,4,3,1),(0,3,5,2,0),(0,1,5,4,0),(1,0,4,5,1),(0,2,5,3,0),(1,3,4,2,1)][t]
 print(d[n[n.index(f)+1]])


Measured memory_bytes: 5608
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cctype>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 2e6 + 5;
const ll maxm = 1e3 + 5;
template<class T>
inline T qread(T &IEE){
	register T x = 0, f = 1;
	register char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-'){
			f = -f;
		}
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return IEE = x * f;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
template<class T>
inline T ab(T a){
	return (a > 0) ? a : -a;
}
template<class T>
inline void swa(T &a, T &b){
	a ^= b ^= a ^= b;
	return ;
}
ll tp, x, y, cur, n;
ll tmp[maxn], len[maxn], head[maxn], nex[maxn], to[maxn];
ll a[maxn];
void add(ll u, ll v){
	nex[++cur] = head[u];
	to[cur] = v;
	head[u] = cur;
	return ;
}
void lis(ll now, ll fa){
	if(a[now] > tmp[tp]){
		tmp[++tp] = a[now];
		len[now] = tp;
//		cout << now << " ";
//	for(int i = 1;i <= tp;i++){
//		cout << tmp[i] << " ";
//	}
//	puts("");
		for(int i = head[now];i;i = nex[i]){
			ll t = to[i];
//			cout << t << " "; 
			if(t != fa){
				lis(t, now);
			}
		}
		tp--;
	} else {
		ll l = 1, r = tp, ind = 0;
		ind = lower_bound(tmp + 1, tmp + tp + 1, a[now]) - tmp;
		ll old = tmp[ind];
		if(ind) tmp[ind] = a[now];
		len[now] = tp;
//		cout << now << " " << ind << " ";
//		for(int i = 1;i <= tp;i++){
//		cout << tmp[i] << " ";
//	}
//	puts("");
		for(int i = head[now];i;i = nex[i]){
			ll t = to[i];
			if(t != fa){
				lis(t, now);
			}
		}
		tmp[ind] = old;
	
	}
	return ;
}
int main(){
	qread(n);
	for(int i = 1;i <= n;i++){
		qread(a[i]);
	}
	for(int i = 1;i <= n - 1;i++){
		qread(x);
		qread(y);
		add(x, y);
		add(y, x);
	}
	lis(1, -1);
	for(int i = 1;i <= n;i++){
		cout << len[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 28768