akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifndef STOPIT
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;
#else
#define debug 0;
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector< lint > a(n + 1, 0);
  loop(n) {
    int x; std::cin >> x;
    a.at(x)++;
  }
  std::sort(all(a));
  auto b = a;
  std::partial_sum(all(b), b.begin());
  b.insert(b.begin(), 0);

  auto ck = [&] (auto k, auto x) {
    lint l = std::upper_bound(all(a), x) - a.begin();
    lint sum = b.at(l) + lint(n - l + 1) * x;
    return lint(k) * x <= sum;
  };

  rep(k, 1, n + 1) {
    lint ok = 0, ng = n + 1, md;
    while (std::abs(ok - ng) > 1) {
      md = (ok + ng) >> 1;
      if (ck(k, md)) ok = md;
      else ng = md;
    }
    std::cout << ok << std::endl;
  }
  return 0;
}


Measured memory_bytes: 8704
#include<stdio.h>
#define ll long long

ll n,d;
ll x[212345],y[212345];

int main(){
  scanf("%lld%lld",&n,&d);
  ll ans=0;
  for(int i=0;i<n;i++){
    scanf("%lld%lld",&x[i],&y[i]);
    if(x[i]*x[i]+y[i]*y[i]<=d*d) ans++;}

  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 4856
$aryCheck = [[0],#dummny 
	[2,4], [1,3,5], [2,6], [1,5,7], [2,4,6,8], [3,5,9], [4,8], [5,7,9], [6,8]
]
def movecheck( p1, p2 )
	$aryCheck[ p1 ].include?( p2 )		
end

def checkpass( password ) 
	flag = true
	ary = password.split(//).map{|a| a.ord - "A".ord + 1}
	(ary.size - 1 ).times{ |i|
		unless movecheck( ary[ i ], ary[ i + 1 ])
			flag = false
			break	
		end
	}
	return flag
end

ans = Array.new
1000.times{
	line = $stdin.gets
	ans << line	if checkpass( line.chomp! )
}
ans.each{ |a| puts a }


Measured memory_bytes: 6096
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n, m = map(int, input().split())
    edges = []
    for i in range(m):
        a, b = map(int, input().split())
        edges.append([a, b])
    from_one = set()
    from_n = set()
    for i in range(m):
        if edges[i][0] == 1:
            from_one.add(edges[i][1])
        if edges[i][1] == n:
            from_n.add(edges[i][0])
    common = from_one & from_n
    print("POSSIBLE" if len(common) > 0 else "IMPOSSIBLE")

main()


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

int main() {
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

int main() {
    llong r, b, w, g;

    cin >> r >> b >> w >> g;
    cout << r + b + w + g << endl;

    return 0;
}



Measured memory_bytes: 3076
using System;

class D
{
	static void Main()
	{
		var n = long.Parse(Console.ReadLine());
		Func<int[]> read = () => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		var a = read();
		var b = read();
		Console.WriteLine(Exchange(Exchange(n, a, b), b, a));
	}

	static long Exchange(long n, int[] a, int[] b)
	{
		var dp = new long[n + 1];
		for (int i = 1; i <= n; i++)
		{
			dp[i] = i;
			for (int j = 0; j < 3; j++) if (a[j] <= i) dp[i] = Math.Max(dp[i], dp[i - a[j]] + b[j]);
		}
		return dp[n];
	}
}


Measured memory_bytes: 208352
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
struct UnionFind {
	int *par;
	int *rank;
	int *cnt;
	int size;
	UnionFind(int n) :size(n) {
		par = new int[size];
		rank = new int[size];
		cnt = new int[size];
		for (int i = 0; i < size; i++) {
			par[i] = i;
			rank[i] = 0;
			cnt[i] = 1;
		}
	}
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank[x] < rank[y]) {
			par[x] = y;
			cnt[y] += cnt[x];
		}
		else {
			par[y] = x;
			cnt[x] += cnt[y];
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
};
int a[50], b[50];
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}
	int ans = 0;
	for (int i = 0; i < M; i++) {
		UnionFind U(N);
		for (int j = 0; j < M; j++) {
			if (i == j) continue;
			U.unite(a[j], b[j]);
		}
		if (U.cnt[U.find(0)] != N) ans++;
	}
	cout << ans << endl;
}

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

int main() {
    int A, B, C, D;
    std::cin >> A >> B >> C >> D;

    if ((A + B) > (C + D)) {
        std::cout << "Left\n";
    } else if ((A + B) < (C + D)) {
        std::cout << "Right\n";
    } else {
        std::cout << "Balanced\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define int long long
    signed main() {
		    	int a,b,c;
		    	cin>>a>>b>>c;
		    	int k;
		    	cin>>k;
		    	vector<int>v={a,b,c};
		    	if(b>a&&c>b){
		    		cout<<"Yes"<<endl;
		    	}
		    	else {
		    		int cnt=0;
		    		while(b<=a){
		    			b*=2;
		    			cnt++;
		    		}
		    		while(c<=b){
		    			c*=2;
		    			cnt++;
		    		}
		    		if(cnt<=k){
		    			cout<<"Yes"<<endl;

		    		}
		    		else cout<<"No"<<endl;
		    	}

    	return 0;
    }


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n;
string s;

bool check(int len)
{
	map<string, int> h;
	for (int i = 0; i <= s.size() - len; i ++ )
	{
		string t = s.substr(i, len);
		if (h.count(t))
		{
			if (h[t] + len - 1 < i) return true;
		}
		else h[t] = i;
	}
	return false;
}

int main()
{
	cin >> n >> s;
	
	int l = 0, r = s.size();
	while (l < r)
	{
		int mid = l + r + 1 >> 1;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 6672
#include <cstdio>

int main(){
  int n;

  while(scanf("%d" ,&n) ,n){
    int p,d1,d2;
    int ans = 0,num;

    while(n--){
      scanf("%d %d %d" ,&p ,&d1 ,&d2);
      if(ans < d1+d2){
	ans = d1+d2;
	num = p;
      }
    }
    printf("%d %d\n" ,num ,ans);
  }

  return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<cstdio>
#include<cmath>
#include<math.h>
using namespace std;

int main() {
    int n,i;
    int x[1000],y[1000];
    double X1=0,X2=0,X3=0,X00=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>x[i];
    }
    for(i=0;i<n;i++){
        cin>>y[i];
    }
    for(i=0;i<n;i++){
        X1+=fabs(x[i]-y[i]);
    }
    for(i=0;i<n;i++){
        X2+=fabs(x[i]-y[i])*fabs(x[i]-y[i]);
    }
    X2=sqrt(X2);
    for(i=0;i<n;i++){
        X3+=pow(fabs(x[i]-y[i]),3.0);
    }
    X3=pow(X3,1.0 / 3.0);
    for(i=0;i<n;i++){
        if(X00<fabs(x[i]-y[i])){
            X00=fabs(x[i]-y[i]);
        }
    }
    printf("%.9f\n%.9f\n%.9f\n%.9f\n",X1,X2,X3,X00);
    return 0;
    
} 




Measured memory_bytes: 3344
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var S = cin.Read;
            var T = cin.Read;

            var ans = 0;
            if (S[0] == T[0])
                ans++;
            if (S[1] == T[1])
                ans++;
            if (S[2] == T[2])
                ans++;

            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[2*n];
  int sum=0;
  for(int i=0;i<2*n;i++)
  {
    cin>>a[i];
  }
  sort(a,a+(2*n));
  for(int i=0;i<2*n;)
  {
    sum+=a[i];
    i+=2;
  }
  cout<<sum<<'\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>


using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }


constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

class UnionFind {
public:
	vector<int> Parent;
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	int root(int A) {
		if (Parent[A] < 0) {
			return A;
		}
		return Parent[A] = root(Parent[A]);
	}

	long long size(int A) {
		return -(long long)Parent[root(A)];
	}

	bool connect(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B) {
			return false;
		}
		if (size(A) < size(B)) {
			swap(A, B);
		}

		Parent[A] += Parent[B];
		Parent[B] = A;

		return true;
	}

};
int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, m; cin >> n >> m;
	UnionFind uni(n);
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		uni.connect(u, v);
	}
	int res = 0; for (int i = 0; i < n; i++) chmax(res, (int)uni.size(i));
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3988
import sys
#from collections import deque
#from functools import *
#from fractions import Fraction as f
from copy import *
from bisect import *	
#from heapq import *
from math import gcd,ceil,sqrt
from itertools import permutations as prm,product
 
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
 
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:	
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def inc(d,c,x=1):
	d[c]=d[c]+x if c in d else x
def bo(i):
	return ord(i)-ord('A')	
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]	
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0		
def gi():	
	return [xx for xx in input().split()]
def fi():
	return int(input())
def pro(a): 
	return reduce(lambda a,b:a*b,a)		
def swap(a,i,j): 
	a[i],a[j]=a[j],a[i]	
def si():
	return list(input().rstrip())	
def mi():
	return 	map(int,input().split())			
def gh():
	sys.stdout.flush()
def isvalid(i,j):
	return 0<=i<n and 0<=j<m and a[i][j]!="."
def bo(i):
	return ord(i)-ord('a')	
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)

t=1
mod=998244353



while t>0:
	t-=1
	n,k=mi()
	d=[0]*(2*n+5)
	a=[]
	for i in range(k):
		a.append(li())
	d[1]=1	
	d[2]=-1
	for i in range(1,n+1):
		d[i]+=d[i-1]
		d[i]%=mod
		for j in range(k):
			d[i+a[j][0]]+=d[i]
			d[i+a[j][1]+1]-=d[i]
	
		
		
	print(d[n])		



Measured memory_bytes: 77964
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  ll left, right;
  ll cnt = 0;
  rep(i, N){
    cin >> left >> right;
    cnt += right - left + 1;
  }

  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	rep(i, 3) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl; return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	double t, x;
	cin >> t >> x;
	cout << setprecision(10) << t/x << endl;
 	return 0;
 }

Measured memory_bytes: 256
N, M = map(int,input().split())

broken = [N+1]*(M+1)
ans = [0]*(N+1)
broken_pointer = 0
for i in range(M):
    a = int(input())
    broken[i] = a

ans[0] = 1
if(broken[0] == 1):
    ans[1] = 0
    broken_pointer += 1
else:
    ans[1] = 1

for i in range(2,N+1):
    if (broken[broken_pointer] == i):
        ans[i] = 0
        broken_pointer += 1
    else:
        ans[i] = ans[i-1] + ans[i-2]
    

print(ans[N]%1000000007)

Measured memory_bytes: 460020
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<queue>

using namespace std;

int main(void) {
	int n;
	cin >> n;
	double a, b = 0, c;
	for(int i = 0; i < n; i++) {
		cin >> a;
		b += 1/a;
	}
	printf("%lf\n", 1/b);
}

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

using namespace std;

int main() {

	string S;
	int tmp=0,cnt=0;	//cntで最大数、tmpは一時的なカウント

	cin >> S;

	for (int i = 0; i <S.length(); ++i) {
		if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')
			tmp++;
		else
			tmp = 0;

		if (tmp > cnt)
			cnt = tmp;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<set>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define mp make_pair
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
void outn(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(10);
}
const double eps = 1e-6;
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
//const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll quickpow(ll x, ll k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}
//ll C(int n, int m){return (fac[n] * quickpow((fac[m] * fac[n - m]) % mod, mod - 2)) % mod;}
const int maxn = 1e5 + 5;

int a[maxn], ans[maxn];
int main()
{
    ios::sync_with_stdio(false); cin.tie(false);

    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    int cur = a[1], ans = 0;
    for (int i = 2; i < n; ++i){
        cur = a[i] - cur;
    }
    ans = a[n] - cur;

    for (int i = 1; i <= n; ++i){
        cout << ans << ' ';
        ans = 2 * (a[i] - ans / 2);
    }

    return 0;
}


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

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {

            Solve();

            //Console.WriteLine(ans);
            Console.ReadKey();
        }

        static void Solve()
        {
            var ans = GetInt() / 3;


            Console.WriteLine(ans);
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        var A = cin.scanint;
        int cnt = 0;
        for (int i = 1; i < N; i++)
        {
            if (A[i] == A[i - 1])
            {
                A[i] = -1;
                cnt++;
            }
        }
        WriteLine(cnt);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13268
import sys

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

for i in range(N):
    if A[i] == 0:
        print(0)
        sys.exit(0)

output = 1
for i in range(N):
    output *= A[i]
    if output > 1000000000000000000:
        print(-1)
        sys.exit(0)
        
print(output)

Measured memory_bytes: 21648
A,B,C = map(int,input().split())
if A >= B and A >= C:
    A = str(A)
    B = str(B)
    D = A + B 
    D = int(D)
    print(D + C)
elif B >= A and B >= C:
    A = str(A)
    B = str(B)
    D = B + A
    D = int(D)
    print(D + C)
else:
    C = str(C)
    B = str(B)
    D = C + B 
    D = int(D)
    print(D + A)

Measured memory_bytes: 3064
# ABC136B

n = int(input())
if n <= 9:
    print(n)
elif n <= 99:
    print(9)
elif n <= 999:
    print(9 + n - 99)
elif n <= 9999:
    print(909)
elif n <= 99999:
    print(909 + n - 9999)
else:
    print(90909)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

vector<int> graph[250000];
bool besucht[250000];
ll query[250000];
ll res[250000];

void dfs( int p, ll sum ){
	if( besucht[p] ) return;
	besucht[p] = true;
	res[p] = sum;
	for( auto next : graph[p] ){
		dfs( next, sum+query[next] );
	}
}

int main(){
	int n, q; cin >> n >> q;
	for( int i = 0; i < n-1; ++i ){
		int a, b; cin >> a >> b; --a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	for( int i = 0; i < q; ++i ){
		int p; ll x; cin >> p >> x;
		query[p-1] += x;
	}
	dfs(0, query[0]);
	for( int i = 0; i < n; ++i ){
		cout << res[i] << ' ';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 24448
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defmacro aif (expr then else)
  `(let ((it ,expr))
     (if it ,then ,else)))

(defmacro awhen (expr &rest then)
  `(aif ,expr (progn ,@then) nil))

(defun comulative (function list &key base)
  (if base
      (comulative function (cons base list))
      (do ((lst (cdr list) (cdr lst))
           (acc (list (car list))))
          ((null lst) (reverse acc))
        (push (funcall function (car acc) (car lst)) acc))))

(defun binary-search (function left right
                      &optional
                        (eps 1)
                        (average-function (lambda (x y) (ash (+ x y) -1))))
  (if (<= (abs (- left right)) eps)
      right
      (let ((mid (funcall average-function left right)))
        (if (funcall function mid)
            (binary-search function left mid eps average-function)
            (binary-search function mid right eps average-function)))))

(defun arithmetic-mean (&rest body)
  (/ (apply #'+ body) (length body)))

(defvar +MOD+ (+ (expt 10 9) 7))

(defun mapa-b (fn a b &optional (step 1))
  (do ((i a (+ i step))
       (result nil))
      ((> i b) (nreverse result))
    (push (funcall fn i) result)))

(defun map0-n (fn n)
  (mapa-b fn 0 n))

(defun map1-n (fn n)
  (mapa-b fn 1 n))

(defun read-string (&optional (stream *standard-input*))
  (labels ((is-empty (x)
             (or (char= x #\space) (char= x #\newline))))
    (loop for char = (read-char stream)
          with result
          when (is-empty char)
            do (return (concatenate 'string (nreverse result)))
          do (push char result))))

(defun main (str1 str2)
  (loop repeat (length str1)
        with str = str1
        when (string= str str2)
          do (return t)
        do (setf str (concatenate 'string (subseq str 1) (string (aref str 0))))))

(princ (if (main (read-string) (read-string)) "Yes" "No"))


Measured memory_bytes: 23864
#![allow(non_snake_case)]

use std::cmp;
use std::io::Read;

const INF: i64 = 1e18 as i64;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    let mut h = vec![0; 1];
    for _ in 0..n {
        h.push(iter.next().unwrap().parse().unwrap());
    }
    let n = n + 1;

    let mut dp = vec![vec![vec![INF; k + 1]; n]; n];
    dp[0][0][k] = 0;
    for curr in 0..n - 1 {
        for height in 0..n {
            for rest in 0..k + 1 {
                let next = curr + 1;
                if rest > 0 {
                    dp[next][height][rest - 1] =
                        cmp::min(dp[next][height][rest - 1], dp[curr][height][rest]);
                }

                if h[height] > h[next] {
                    dp[next][next][rest] = cmp::min(dp[next][next][rest], dp[curr][height][rest]);
                } else {
                    dp[next][next][rest] = cmp::min(
                        dp[next][next][rest],
                        dp[curr][height][rest] + h[next] - h[height],
                    );
                }
            }
        }
    }
    let mut res = INF;
    for height in 0..n {
        for rest in 0..k + 1 {
            res = cmp::min(res, dp[n - 1][height][rest]);
        }
    }
    println!("{}", res);
}


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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  
  sort(A.begin(), A.end());
  int maxdiff = A.at(N - 1) - A.at(0);
  
  cout << maxdiff << endl;  
}

Measured memory_bytes: 3560
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    long long ans = K;
    for(int i = 0; i < N-1; i++)
        ans *= K-1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

void solve() {
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=1; i<n; ++i) {
		cin>>a[i];
		--a[i];
	}
	vector<int> b(n, 0);
	for(int i=1; i<n; ++i)
		++b[a[i]];
	for(int i=0; i<n; ++i)
		cout<<b[i]<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	solve();
    return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

const int WALL = -1;

int main() {
  while ( true ) {
	int n;
	cin >> n;
	if ( n == 0 ) break;
	char s, t, b;
	cin >> s >> t >> b;
	int is = s - 'A', it = t - 'A', ib = b - 'A';

	array<double, 9> table;
	fill( table.begin(), table.end(), 0.0 );
	table[ is ] = 1.0;

	array<int, 4> dx = { -1, 0, 1, 0 };
	array<int, 4> dy = { 0, -1, 0, 1 };
	array<double, 9> before;
	
	for ( int i = 0; i < n; i++ ) {
	  before = table;
	  fill( table.begin(), table.end(), 0 );
	  for ( int y = 0; y < 3; y++ ) {
		for ( int x = 0; x < 3; x++ ) {
		  for ( int j = 0; j < 4; j++ ) {
			int nx = x + dx[ j ];
			int ny = y + dy[ j ];
			
			if ( 0 <= nx and nx < 3 and
				 0 <= ny and ny < 3 and
				 ny * 3 + nx != ib ) {
			  
			  table[ ny * 3 + nx ] += before[ y * 3 + x ] / 4;
			} else {
			  table[ y * 3 + x ] += before[ y * 3 + x ] / 4;
			}
		  }
		}
	  }
	}
	cout << table[ it ] << endl;
  }
}

Measured memory_bytes: 1228
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
	int h,i,j,k,n,y,a[100000],b[100000],ans=0,amax=0;
	scanf("%d %d",&n,&h);
	for(i=0;i<n;i++){
    	scanf("%d %d",&a[i],&b[i]);
    	if(a[i]>amax) amax=a[i];
    }
    sort(b,b+n);
    i=n-1;
    while(b[i]>amax){
    	h-=b[i];
    	ans++;
    	if(h<=0){
    		printf("%d\n",ans);
			return 0;
		}
    	i--;
    }
    ans+=h/amax;
    if(h%amax!=0) ans++;
    printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <map>
#define PII pair<int,int>
using namespace std;
typedef long long ll;
ll h, w, n, a, b, s, c[15];
map<PII,ll> mp;
map<PII,ll>::iterator it;
int main() {
	ll i, j;
	scanf("%d%d%d", &h, &w, &n);
	while(n--) {
		scanf("%d%d", &a, &b);
		for(i=a; i<a+3; i++) for(j=b; j<b+3; j++) {
			if(i>=3 && j>=3 && i<=h && j<=w) mp[{i,j}]++;
		}
	}
	for(it=mp.begin(); it!=mp.end(); it++) c[it->second]++;
	for(i=1; i<=9; i++) s += c[i];
	printf("%lld\n", (h-2)*(w-2)-s);
	for(i=1; i<=9; i++) printf("%lld\n", c[i]);
	return 0;
}

Measured memory_bytes: 56448
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
const int INT_INF = 500000000;
const long long LONG_LONG_INF = (long long)pow(10, 18);
const int MOD = pow(10, 9) + 7;
/* contest template */
int N, cnt;
string s1, s2, r;

int main() {
  cin >> N;
  while (true) {
    cnt = 0;
    r = "F";
    while (r == "F" && cnt < 4) {
      cnt++;
      if (cnt == 1) {
        cout << s1 << "." << endl;
        cout << s2 << "." << endl;
      } else if (cnt == 2) {
        cout << s1 << "#" << endl;
        cout << s2 << "." << endl;
      } else if (cnt == 3) {
        cout << s1 << "." << endl;
        cout << s2 << "#" << endl;
      } else if (cnt == 4) {
        cout << s1 << "#" << endl;
        cout << s2 << "#" << endl;
      }
      cin >> r;
    }
    if (r == "end") {
      return 0;
    } else if (r == "T") {
      if (cnt == 1) {
        s1 = s1 + ".";
        s2 = s2 + ".";
      } else if (cnt == 2) {
        s1 = s1 + "#";
        s2 = s2 + ".";
      } else if (cnt == 3) {
        s1 = s1 + ".";
        s2 = s2 + "#";
      } else if (cnt == 4) {
        s1 = s1 + "#";
        s2 = s2 + "#";
      }
    } else if (r == "F") {
      break;
    }
  }
  while (true) {
    cnt = 0;
    r = "F";
    while (r == "F" && cnt < 4) {
      cnt++;
      if (cnt == 1) {
        cout << "." << s1 << endl;
        cout << "." << s2 << endl;
      } else if (cnt == 2) {
        cout << "#" << s1 << endl;
        cout << "." << s2 << endl;
      } else if (cnt == 3) {
        cout << "." << s1 << endl;
        cout << "#" << s2 << endl;
      } else if (cnt == 4) {
        cout << "#" << s1 << endl;
        cout << "#" << s2 << endl;
      }
      cin >> r;
    }
    if (r == "end") {
      return 0;
    } else if (r == "T") {
      if (cnt == 1) {
        s1 = "." + s1;
        s2 = "." + s2;
      } else if (cnt == 2) {
        s1 = "#" + s1;
        s2 = "." + s2;
      } else if (cnt == 3) {
        s1 = "." + s1;
        s2 = "#" + s2;
      } else if (cnt == 4) {
        s1 = "#" + s1;
        s2 = "#" + s2;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 724
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;
using static System.Math;

class Program
{

    static void Main(string[] args)
    {
        label:
        var nums = new long[5];
        int count = Parse(ReadLine());
        for (int i = 0; i < count; ++i)
        {
            switch (ReadLine()[0])
            {
                case 'M': ++nums[0]; break;
                case 'A': ++nums[1]; break;
                case 'R': ++nums[2]; break;
                case 'C': ++nums[3]; break;
                case 'H': ++nums[4]; break;
            }
        }
        long result = nums[0] * nums[1] * nums[2];
        result += nums[0] * nums[1] * nums[3];
        result += nums[0] * nums[1] * nums[4];
        result += nums[0] * nums[2] * nums[3];
        result += nums[0] * nums[2] * nums[4];
        result += nums[0] * nums[3] * nums[4];
        result += nums[1] * nums[2] * nums[3];
        result += nums[1] * nums[2] * nums[4];
        result += nums[1] * nums[3] * nums[4];
        result += nums[2] * nums[3] * nums[4];
        WriteLine(result);
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
#define N 100015
struct edge{int to,nxxt;}e[N*20];
int n,a[N][2],head[N<<1],cnt=1,js,ls[N],rs[N],rt,s[N],rv[N],tot,b[N];
int dfn[N<<1],low[N<<1],f[N<<1],cn,an;
bool inq[N<<1];
stack<int>st;
inline void ins(int u,int v){e[cnt].to=v;e[cnt].nxxt=head[u];head[u]=cnt++;}
inline int op(int x){return x<=n?x+n:x-n;}
void bt(int &o,int l,int r)
{
	o=++js;
	if(l==r)return;int mid=(l+r)>>1;
	bt(ls[o],l,mid);bt(rs[o],mid+1,r);
}
void dfs(int ind,int l,int r)
{
	if(l==r){ins(ind,op(b[l]));return;}int mid=(l+r)>>1;
	ins(ind,ls[ind]);ins(ind,rs[ind]);
	dfs(ls[ind],l,mid);dfs(rs[ind],mid+1,r);
}
void ade(int ind,int l,int r,int al,int ar,int x)
{
	if(al<=l&&r<=ar){ins(x,ind);return;}
	int mid=(l+r)>>1;
	if(al<=mid)ade(ls[ind],l,mid,al,ar,x);
	if(ar>mid)ade(rs[ind],mid+1,r,al,ar,x);
}
void tarjan(int x)
{
	dfn[x]=low[x]=++cn;inq[x]=1;st.push(x);
	for(int i=head[x];i;i=e[i].nxxt)
	{
		int j=e[i].to;
		if(!dfn[j]){tarjan(j);low[x]=min(low[x],low[j]);}
		else if(inq[j])low[x]=min(low[x],dfn[j]);
	}
	if(low[x]==dfn[x])
	{
		an++;
		while(!st.empty()&&st.top()!=x)
		{
			inq[st.top()]=0;f[st.top()]=an;st.pop();
		}inq[x]=0;f[x]=an;st.pop();
	}
}
inline bool che(int x)
{
	memset(head,0,sizeof(head));cnt=1;
	dfs(rt,1,2*n);
	for(int i=1;i<=2*n;i++)
	{
		int l=1,r=i-1,mid,tas=i;
		while(l<=r)
		{
			mid=(l+r)>>1;
			if(s[b[i]]-s[b[mid]]<x)tas=mid,r=mid-1;
			else l=mid+1;
		}
		if(tas<i)ade(rt,1,2*n,tas,i-1,b[i]);
		l=i+1,r=2*n,tas=i;
		while(l<=r)
		{
			mid=(l+r)>>1;
			if(s[b[mid]]-s[b[i]]<x)tas=mid,l=mid+1;
			else r=mid-1;
		}
		if(tas>i)ade(rt,1,2*n,i+1,tas,b[i]);
	}cn=an=0;
	for(register int i=1;i<=js;i++)dfn[i]=low[i]=inq[i]=f[i]=0;
	while(!st.empty())st.pop();
	for(int i=1;i<=js;i++)if(!dfn[i])tarjan(i);
	for(int i=1;i<=n;i++)if(f[i]==f[i+n])return false;
	return true;
}
inline bool cmp(int x,int y){return s[x]<s[y];}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i][0],&a[i][1]),s[i]=a[i][0],s[i+n]=a[i][1];
	for(int i=1;i<=2*n;i++)b[i]=i;
	sort(b+1,b+1+2*n,cmp);
	js=2*n;bt(rt,1,2*n);
	int l=0,r=1e9,mid,ans;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(che(mid))ans=mid,l=mid+1;
		else r=mid-1;
	}printf("%d\n",ans);
}


Measured memory_bytes: 15616
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");

while(true){
   var last=[];
   var nm=arr.shift().split(" ").map(Number);
   if(nm.join(" ")=="0 0")break;
   var n=nm[0];
   var m=nm[1];
   var yx=[];
   for(var i=0;i<n;i++){
      var ary=arr.shift().split(" ").map(Number);
      var d=ary.shift();
      var data=[];
      while(d--)data.push([ary.shift(),ary.shift()]);
      yx.push(data);
   }
   var dp=[];
   for(var i=0;i<=n;i++){
      dp[i]=[];
      for(var j=0;j<=1000;j++){
         dp[i][j]=[];
         for(var k=0;k<=m;k++){
            dp[i][j][k]=Infinity;
         }
      }
   }
   yx[0].forEach(function(v){
      var x=v[0];
      dp[0][x][0]=0;
   });
   yx[1].forEach(function(v){
      var x=v[0];
      dp[1][x][1]=0;
   });
   for(var i=1;i<n;i++){
      yx[i].forEach(function(v,index){
         var x=v[0];
         var value=v[1];
         yx[i-1].forEach(function(V,INDEX){
            var X=V[0];
            var VALUE=V[1];
            for(var j=0;j<=m;j++){
               dp[i][x][j]=Math.min(dp[i][x][j],dp[i-1][X][j]+(value+VALUE)*Math.abs(x-X));
            }
         });
      });
      if(i==n-1){
      yx[i].forEach(function(v,index){
         var x=v[0];
         var value=v[1];
         yx[i-1].forEach(function(V,INDEX){
            var X=V[0];
            var VALUE=V[1];
            for(var j=0;j<m;j++){
               dp[i][x][j]=Math.min(dp[i][x][j],dp[i-1][X][j]);
            }
         });
      });
      }
      if(i!=n-1){
      yx[i+1].forEach(function(v,index){
         var x=v[0];
         var value=v[1];
         yx[i-1].forEach(function(V,INDEX){
            var X=V[0];
            var VALUE=V[1];
            for(var j=0;j<m;j++){
               dp[i+1][x][j+1]=Math.min(dp[i+1][x][j+1],dp[i-1][X][j]+(value+VALUE)*Math.abs(x-X));
            }
         });
      });
      }
      
      if(i==n-1 && yx[i].length==0){
         var x=0;
         var value=0;
         yx[i-1].forEach(function(V,INDEX){
            var X=V[0];
            var VALUE=V[1];
            for(var j=0;j<m;j++){
               last.push(dp[i-1][X][j]);
            }
         });
      }
   }
   var min=Infinity;
   yx[n-1].forEach(function(v){
      var x=v[0];
      for(var j=0;j<=m;j++){
         min=Math.min(min,dp[n-1][x][j]);
      }
   });
   if(min==Infinity){
      last.forEach(function(v){
         min=Math.min(min,v);
      });
   }
   console.log(min);
}

Measured memory_bytes: 208392
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vi a(n);
  vl cnt(200001);
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }
  ll sum = 0;
  rep(i,n) cnt[a[i]]++;
  rep(i,200001){
    sum+=(cnt[i]*(cnt[i]-1))/2;
  }

  rep(i,n){
    ll b = cnt[a[i]];
    //show(b);
    ll x = (b*(b-1))/2;
    ll y = ((b-1)*(b-2))/2;
    maxs(y,0LL);
    // show(x);
    // show(y);
    // show(sum);
    cout<<sum-x+y<<endl;
  }

  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(){
  int x, y, flag;
  flag = 0;
  cin >> x;
  for(int i = 0; i < x; i++){
    cin >> y;
    if((i + 1)!= y){
      flag += 1;
    }
  }
  if(flag <= 2){
    cout << "YES";
  }else{
    cout << "NO";
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
flag = False
for i in range(n):
    for j in range(n):
        q = p.copy()
        q[i], q[j] = q[j], q[i]
        if q == sorted(q):
            flag = True
            break
if flag:
    print("YES")
else:
    print("NO")   

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

signed main(){
  int a, b, x; cin >> a >> b >> x;
  int res = a * a * b - x;
  double ans;
  if(2 * x >= a * a * b){
    double h = double(2 * res) / double(a * a);
    ans = atan(h / double(a)) * 180.0000 / 3.1415926535;
  }
  else{
    double h = double(2 * x) / double(a * b);
    ans = atan(double (b) / double(h)) * 180.00000 / 3.1415926535; 
  }
  cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }
typedef pair<int,int> P;

int main(){
  map<ll,ll> mp;
  int n;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];
  rep(i,n){
    mp[a[i]]++;
  }
  ll ans = 0;
  for(auto p:mp){
    ans += (p.second-1)*p.second/2;
  }
  rep(i,n){
    ll res;
    if(mp[a[i]]>=2){
      res = mp[a[i]]-1;
    }else {
      res = 0;
    }
    cout << ans - res << endl;
  }
}


Measured memory_bytes: 10240
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int n,k,a[200001],s;

int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++){int x;cin>>x;a[x]++;}
    sort(a,a+n);
    for(int i=n-1;i>=n-k;i--)s+=a[i];
    cout<<n-s<<endl;
}

Measured memory_bytes: 1152
import itertools
import math
import sys
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
s_cnt = Counter(s).most_common()
# print(s_cnt)
cnt = s_cnt[0][1]
# print(cnt)
ans = []
for i in s_cnt:
    if i[1] == cnt:
        ans.append(i[0])
ans.sort()
for i in ans:
    print(i)

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

#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REP(i,n) FOR(i,0,n)
typedef vector<int> vi;
typedef vector<vi> vii;
#define ALL(a) a.begin(),a.end()

int p[5000001]={1,1,0};
vi primes;
vi lp;
void prime(){
	FOR(i,2,5000001){
		if(!p[i]){
			primes.push_back(i);
			for(int j=1;i*j<5000001;j++){
				p[i*j]=1;
			}
		}
	}
}
void listp(int n,int p){
	lp.clear();
	int ii=0,jj=0;
	for(ii=0;primes[ii]<=n;ii++);
	for(jj=0;primes[jj]<=n;jj++);
	for(int i=ii;i<=ii+p;i++){
		for(int j=max(jj,i);j<=ii+p;j++){
			lp.push_back(primes[i]+primes[j]);
		}
	}
	sort(ALL(lp));
}

int main(){
	int n,p;
	prime();
	while(cin>>n>>p,n>-1&&p>-1){
		listp(n,p);
		cout<<lp[p-1]<<endl;
	}
}

Measured memory_bytes: 21000
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>
#define INF 1000000007
const int m=998244353;
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>PBDS;

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



int32_t main(){
	
	//FIO();
	
		int d,t,s;cin>>d>>t>>s;
		if((d+s-1)/s>t)
			cout<<"No\n";
		else
			cout<<"Yes\n";
	


	return 0;
		
}


			

Measured memory_bytes: 3612
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int main(){
    int n, m, cnt = 0;
    cin >> n >> m;
    while(n){
        cnt++;
        n /= m;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256