akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  ll n, k;
  scan(n, k);
  n %= k;
  ll ans = min(n, k - n);
  print(ans);

  return 0;
}


Measured memory_bytes: 888
import scala.io.StdIn

object Main extends App {

  val rn = StdIn.readLine().trim.toInt
  val ra = StdIn.readLine().trim.split(' ').map(_.toInt)

  def selectionSort(a: Array[Int], n: Int): (Array[Int], Int) = {
    var changeCount = 0
    (0 until n).foreach{ i =>
      var minj = i
      (i until n).foreach{ j =>
        minj = if(a(j) < a(minj)) j else minj
      }
      val temp = a(minj)
      a(minj) = a(i)
      a(i) = temp
      changeCount = if(i != minj) changeCount + 1 else changeCount
    }
    (a, changeCount)
  }

  val (r, c) = selectionSort(ra, rn)
  println(r.toList.mkString(" "))
  println(c)
  
}



Measured memory_bytes: 44064
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	int N;
	std::cin >> N;
	std::vector<int> vec(N);
	for (auto& v : vec)
	{
		std::cin >> v;
	}
	std::vector<int> sum(N);
	sum[0] = vec[0];
	for (auto i : boost::irange(1, N))
	{
		sum[i] = sum[i - 1] + vec[i];
	}
	int min = sum[N - 1];
	for (auto i : boost::irange(0, N))
	{
		min = std::min(min, std::abs(sum[i] - (sum[N - 1] - sum[i])));
	}
	std::cout << min << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cstdlib>
#include <queue>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;

struct res
{
    string city;
    int score;
    int id;
};
int main()
{
    int n;
    cin >> n;
    vector<res> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i].city >> A[i].score;
        A[i].id = i + 1;
    }
    sort(A.begin(), A.end(), [](const res &a, const res &b){
        if(a.city == b.city)
        {
            return a.score > b.score;
        }
        else return a.city < b.city;
    });
    for(auto x : A)
        cout << x.id << endl;
    return 0;
}

Measured memory_bytes: 256
import queue
def main():
    h, w = map(int, input().split())
    s = [input().rstrip() for _ in range(h)]
    g = [[0 for j in range(w)] for i in range(h)]
    num = 1
    q = queue.Queue()
    for i in range(h):
        for j in range(w):
            if g[i][j] != 0:
                continue
            q.put([i, j])
            g[i][j] = num
            while not q.empty():
                y, x = q.get()
                if 0 < y and g[y-1][x] == 0 and s[y][x] != s[y-1][x]:
                    g[y-1][x] = num
                    q.put([y-1, x])
                if y < h-1 and g[y+1][x] == 0 and s[y][x] != s[y+1][x]:
                    g[y+1][x] = num
                    q.put([y+1, x])
                if 0 < x and g[y][x-1] == 0 and s[y][x] != s[y][x-1]:
                    g[y][x-1] = num
                    q.put([y, x-1])
                if x < w-1 and g[y][x+1] == 0 and s[y][x] != s[y][x+1]:
                    g[y][x+1] = num
                    q.put([y, x+1])
            num += 1
    blk, wht = [0]*(num+1), [0]*(num+1)
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                blk[g[i][j]] += 1
            else:
                wht[g[i][j]] += 1
    ans = 0
    for i in range(num+1):
        ans += blk[i] * wht[i]
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 11880
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int N, K;
    string S;
    cin >> N;
    cin >> S;
    cin >> K;
    
    char s = S[K-1];
    for(int i = 0; i < N; i++)
    {
        if(S[i] != s)
        {
            S[i] = '*';
        }
    }
    cout << S << endl;

    return 0;

}


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

using namespace std;

typedef long double ld;
typedef long long ll;

const int M = 3030;
const int mod = 1e9 + 7;

int add(int x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
  return x;
}

int udd(int &x, int y) {
  return x = add(x, y);
}

int n, m;
int l[M], r[M];
int up[M], down[M];
int d[M][M];
string s;

void read() {
  cin >> n >> m >> s;
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    --l;
    ::l[i] = l;
    ::r[i] = r;
  }
}

void calc(string s, function<bool(char, char)> cmp, int *to) {
  for (int i = 0; i < m; ++i)
    sort(s.begin() + l[i], s.begin() + r[i], cmp);
  for (int i = 0; i < n; ++i)
    to[i + 1] = to[i] + (s[i] - '0');
}

void kill() {
  calc(s, less<char>(), down);
  calc(s, greater<char>(), up);
  d[0][0] = 1;
  int A = down[n];
  int B = n - A;
  for (int i = 0; i <= A; ++i)
    for (int j = 0; j <= B; ++j) {
      int k = i + j;
      if (down[k] <= i && i <= up[k]) {
        int cur = d[i][j];
        udd(d[i + 1][j], cur);
        udd(d[i][j + 1], cur);
      }
    }

  cout << d[A][B] << endl;
}

int main() {
#ifdef LOCAL
  assert(freopen("f.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();
}



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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c; cin>>a>>b>>c;
	cout << b+min(a+b+1,c) << endl;
	return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define EPS 1e-9
constexpr double PI = acos(-1);
int main() {
	struct Point {
		double x;
		double y;
	};
	int n = ri(), k = ri();
	Point pts[n];
	int c[n];
	for (int i = 0; i < n; i++) pts[i].x = ri(), pts[i].y = ri(), c[i] = ri();
	if (k == 1) {
		puts("0");
		return 0;
	}
	double l = 0, r = 300000;
	for (int i = 0; i < 100; i++) {
		double m = (l + r) / 2;
		double radius[n];
		for (int j = 0; j < n; j++) radius[j] = m / c[j];
		auto dist = [] (Point p0, Point p1) { return std::hypot(p0.x - p1.x, p0.y - p1.y); };
		Point res0, res1;
		int max = 0;
		auto kosa = [&] (Point p0, double r0, Point p1, double r1) {
			if (dist(p0, p1) > r0 + r1) return false;
			double base_atan2 = std::atan2(p1.y - p0.y, p1.x - p0.x);
			if (base_atan2 < 0) base_atan2 += 2 * PI;
			auto pos = [&] (double kakudo) {
				return Point{p0.x + std::cos(kakudo) * r0, p0.y + std::sin(kakudo) * r0};
			};
			auto opp = pos(base_atan2 + PI);
			if (dist(opp, p1) <= r1) return false;
			
			double upper, lower;
			{
				double l = base_atan2;
				double r = base_atan2 + PI;
				for (int i = 0; i < 60; i++) {
					double m = (l + r) / 2;
					if (dist(pos(m), p1) <= r1) l = m;
					else r = m;
				}
				upper = l;
			}{
				double l = base_atan2 - PI;
				double r = base_atan2;
				for (int i = 0; i < 60; i++) {
					double m = (l + r) / 2;
					if (dist(pos(m), p1) <= r1) l = m;
					else r = m;
				}
				lower = l;
			}
			res0 = pos(upper);
			res1 = pos(lower);
			return true;
		};
		auto try_pt = [&] (Point pt) {
			int cnt = 0;
			for (int i = 0; i < n; i++) if (dist(pts[i], pt) <= radius[i] + EPS) cnt++;
			max = std::max(max, cnt);
		};
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < j; k++) {
				if (kosa(pts[j], radius[j], pts[k], radius[k])) try_pt(res0), try_pt(res1);
			}
		}
		for (int j = 0; j < n; j++) try_pt(pts[j]);
		if (max >= k) r = m;
		else l = m;
	}
	printf("%.11f\n", l);
	return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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


lli d[200100];
lli b[200100];

int main(){

    lli n,k;
    cin>>n>>k;
    
    REP(i,0,n){
        d[i]=-INF;
        b[i]=-INF;
    }

    vector<lli> a(n);
    REP(i,0,n){
        lli tmp;
        cin>>tmp;
        tmp--;
        a[i]=tmp;
    }

    lli cnt = 0;
    lli now = 0;
    if(a[0]==0){
        cout<<1<<endl;
        return 0;
    }
    lli breakIndex,breakCnt;
    while(1){
        LOG2(now,cnt);
        if(b[now]!=-INF){
            breakCnt = cnt;
            breakIndex = now;
            break;
        }
        d[cnt] = now;
        b[now] = cnt;
        now = a[now];
        cnt++;
    }

    LOG(breakCnt);
    lli loopCnt = breakCnt-b[breakIndex];
    LOG(loopCnt);

    if(k<=b[breakIndex]){
        cout<<d[k]+1<<endl;
    }
    else{
        cout<<d[(k-b[breakIndex])%loopCnt + b[breakIndex]]+1<<endl;
    }

    return 0;
}


Measured memory_bytes: 8012
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<map>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
int n;
map<ll,int> a;
queue<pii> q;
set<int> l[100010];
int f[100010];
int find(int x)
{
	return f[x]==x?x:f[x]=find(f[x]);
}
ll getid(int x,int y)
{
	if(x>y)
		swap(x,y);
	return ll(x)*n+y;
}
void link(int x,int y)
{
	l[x].insert(y);
	l[y].insert(x);
	ll v=getid(x,y);
	a[v]++;
	if(a[v]==3)
	{
		printf("NO\n");
		exit(0);
	}
	if(a[v]==2)
		q.push(pii(x,y));
}
int main()
{
	scanf("%d",&n);
	int i,x,y;
	for(i=1;i<=2*n-2;i++)
	{
		scanf("%d%d",&x,&y);
		link(x,y);
	}
	for(i=1;i<=n;i++)
		f[i]=i;
	for(i=1;i<n;i++)
	{
		while(1)
		{
			if(q.empty())
			{
				printf("NO\n");
				return 0;
			}
			x=q.front().first;
			y=q.front().second;
			x=find(x);
			y=find(y);
			q.pop();
			if(x!=y)
				break;
		}
		if(l[x].size()>l[y].size())
			swap(x,y);
		f[x]=y;
		a.erase(getid(x,y));
		l[y].erase(x);
		l[x].erase(y);
		for(auto v:l[x])
		{
			v=find(v);
			if(v==y)
				continue;
			link(v,y);
			a.erase(getid(x,v));
			l[v].erase(x);
			l[x].erase(v);
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 36736
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>

using ll = long long;

int main() {
    int N;
    std::cin >> N;
    std::string ans = "";
    while (N != 0) {
        if (N % 2 != 0) {
            N--;
            ans = "1" + ans;
        }
        else {
            ans = "0" + ans;
        }
        N /= -2;
    }

    if (ans == "") ans = "0";

    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int N;
const int MAX_V = 2e5;
vector<int> es[MAX_V], res[MAX_V], vs;
bool used[MAX_V];
int topo[MAX_V];

void add_edge(int from, int to){
    es[from].pb(to), res[to].pb(from);
}

void dfs(int now){
    used[now] = true;
    for(auto &e: es[now]) if(!used[e]) dfs(e);
    vs.pb(now);
}

void rdfs(int now, int dpt){
    used[now] = true;
    topo[now] = dpt;
    for(auto &e: res[now]) if(!used[e]) rdfs(e, dpt);
}

//強連結分解し、残った頂点の数を出力
void scc(){
    fill(used, used+N, false);
    rep(i, N) if(!used[i]) dfs(i);
    fill(used, used+N, false);
    int k = 0;
    rep3(i, vs.size()-1, 0){
        int e = vs[i];
        if(!used[e]) rdfs(e, k++);
    }
}


//vに含まれない最小の非負整数
int calc(vector<int> v){
    int n = v.size();
    bool Used[n];
    fill(Used, Used+n, false);
    for(auto &e: v) if(e < n) Used[e] = true;
    rep(i, n) if(!Used[i]) return i;
    return n;
}

//有向木におけるgrundy数を求める
int grundy(int now){
    vector<int> v;
    for(auto &e: es[now]) if(topo[e]) v.pb(grundy(e));
    return calc(v);
}

int main(){
    cin >> N;
    rep(i, N){
        int p;
        cin >> p;
        p--;
        add_edge(p, i);
    }
    scc();
    int cnt = 0;
    set<int> gs;
    rep(i, N){
        //cout << topo[i] << ' ';
        if(topo[i]) continue;
        cnt++;
        gs.insert(grundy(i));
        //cout << grundy(i) << ' ';
    }
    //cout << endl;
    if(cnt%2 == 0 || gs.size() >= 2) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 30708
#include <iostream>
using namespace std;
struct card
{
    char suit;
    int num;
};

void bubble(struct card A[],int n)
{
    for (int i = 0; i < n; i++) {
        for (int j = n-1; j > i; j--) {
            if (A[j].num<A[j-1].num)
            {
                card t=A[j];A[j]=A[j-1];A[j-1]=t;
            }
        }
    }
}

void selection(struct card A[],int n)
{
    for (int i = 0; i < n; i++) {
        int mini=i;
        for (int j = i; j < n; j++) {
            if (A[j].num<A[mini].num)
                mini=j;
        }
        card t=A[i];A[i]=A[mini];A[mini]=t;
    }
}

void print(struct card A[],int n)
{
    for (int i = 0; i < n; i++) {
        cout << A[i].suit<<A[i].num;
        if (i != n - 1) cout << ' ';
    }
    cout<<endl;
}

bool is_stable(struct card A[], struct card B[],int n)
{
    for (int i = 0; i < n; i++) {
        if (A[i].suit!=B[i].suit) return false;
    }
    return true;
}

int main()
{
    int n;
    cin>>n;
    struct card cards1[36],cards2[36];

    for (int i = 0; i < n; i++) {
        cin>>cards1[i].suit>>cards1[i].num;
        cards2[i]=cards1[i];
    }

    bubble(cards1,n);
    selection(cards2,n);

    print(cards1,n);
    cout<<"Stable"<<endl;
    print(cards2,n);
    if (is_stable(cards1,cards2,n)) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;

    return 0;
}


Measured memory_bytes: 3104
// 日本語
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let vs: Vec<u64> = s.trim().split_whitespace().map(|token| token.parse().ok().unwrap()).collect();
    let n = vs[0];
    let m = vs[1] as usize;

    let mut x: Vec<bool> = vec![true; m + 1];

    for _ in 0..n {
        s = String::new();
        stdin().read_line(&mut s).ok();
        let mut vs: Vec<u64> = s.trim().split_whitespace().map(|token| token.parse().ok().unwrap()).collect();
        let vs: Vec<u64> = vs.drain(1..).collect();
        x = x.iter().enumerate().map(|(i, xi)| { *xi && vs.contains(&(i as u64)) }).collect();
    }
    let result = x.iter().enumerate().map(|(i, xi)| { if *xi { i as u64 } else { 0 } }).filter(|i| { *i > 0 }).count();
    println!("{}", result);
}


Measured memory_bytes: 4352
//Warmdust Code
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define db double
#define ll long long
#define ft float
#define PI acos(-1)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fro(i,a,b) for(int i=a;i>=b;i--)
#define inf 0x3f3f3f3f
#define Warmdust int main(){ TvT;
#define RETURN return 0;}
#define TvT ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=105;
int n;
int sz[maxn];
int a[maxn];
int sum=0;
Warmdust
	cin >> n;
	For(i,1,n-1) cin >> sz[i];
	For(i,1,n-2) a[i]=min(sz[i],sz[i+1]);
	
	For(i,1,n-2) sum+=a[i];
	sum+=max(a[1],sz[1]);
	sum+=sz[n-1];
	cout << sum << endl;
RETURN

Measured memory_bytes: 256
N = gets.to_i
  s = Array.new(N)
  t = Array.new(N)
  N.times do |i|
    s[i],t[i]=gets.chomp.split
  end

  X = gets.chomp

  sw="off"
  ans=0
  N.times do |i|
    if sw=="on"
      ans = ans+t[i].to_i
    elsif s[i]==X
      sw="on"
    end
  end

  puts ans

Measured memory_bytes: 1788
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    map<char,set<ll>> F;
    READV(N);
    string S;
    cin>>S;
    FORI(i,0,N)
    {
        F[(ll)S[i]-(ll)'0'].insert(i);
    }
    ll ans=0;
    FORI(i,0,10)
    {
        FORI(j,0,10)
        {
            FORI(k,0,10)
            {
                if(F[i].upper_bound((ll)(-1))!=F[i].end() && F[j].upper_bound(*F[i].upper_bound((ll)(-1)))!=F[j].end() && F[k].upper_bound(*F[j].upper_bound(*F[i].upper_bound((ll)(-1))))!=F[k].end())
                {
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n; cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  int d = 0;
  for (int i = n - 1; i >= 0; i--) {
    a[i] += d;
    if (a[i] == 0) continue;
    int t;
    if (a[i] <= b[i]) t = b[i];
    else t = ((a[i] - 1) / b[i] + 1) * b[i];
    d += t - a[i];
  }
  cout << d << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 4720
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

LL H,W,N;
LL num[10];
set<pair<int,int> > used;
int dx[9]={-1,0,1,-1,0,1,-1,0,1};
int dy[9]={-1,-1,-1,0,0,0,1,1,1};

int blacknum(int y,int x){
    int res =0;
    REP(i,9){
        if(y+dy[i]<=0||y+dy[i]>H||x+dx[i]<=0||x+dx[i]>W)return -1;
        if(used.find(make_pair(y+dy[i],x+dx[i]))!=used.end())res++;
    }
    return res;
}



int main(){

    cin>>H>>W>>N;
    fill_n(num,10,0);
    num[0]=(H-2)*(W-2);



    REP(i,N){
        int x,y;cin>>y>>x;
        REP(j,9){
            int res=blacknum(y+dy[j],x+dx[j]);
            if(res<0)continue;
            num[res]--;
            num[res+1]++;
        }
        used.insert(make_pair(y,x));
    }

    REP(i,10)cout<<num[i]<<endl;


    return 0;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

int N, A, B, C, D;
string S;

bool two_consecutive_hash(int i, int j) {
  for(int k = i;k < j;k++) {
    if(S[k] == '#' and S[k+1] == '#') return true;
  }
  return false;
}

bool three_consecutive_dot(int i, int j) {
  for(int k = i;k <= j;k++) {
    if(S[k-1] == '.' and S[k] == '.' and S[k+1] == '.') {
      return true;
    }
  }

  return false;
}

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> N >> A >> B >> C >> D;
  A--;B--;C--;D--;
  cin >> S;

  string ans = "No";
  if(A < C and B < D) {
    bool ac = two_consecutive_hash(A, C);
    bool bd = two_consecutive_hash(B, D);

    if((!ac) and (!bd)) {
      if((B > A) and (C > D)) {
        if(three_consecutive_dot(B, D)) ans = "Yes";
      } else if((B < A) and (C < D)) {
        if(three_consecutive_dot(A, C)) ans = "Yes";
      } else {
        ans = "Yes";
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
    /*変数定義，入力*/
    int N, M;
    int count = 0;
    cin >> N >> M;
    vector<int> a(N);  rep(i, N) cin >> a[i];
    int sum = std::accumulate(a.begin(), a.end(), 0);
    std::sort(a.begin(), a.end(), std::greater<int>());
    rep(i, N){
        if(a[i] >= sum * 1.0 / 4.0 / M){
            count ++;
        }else{
            break;
        }
    }
    if(count >= M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    //ll A, B;cin >> A >> B;
    //vector<ll> a(N);  rep(i, N) cin >> a[i];
    
    /*演算*/
    


    /*出力*/

    //cout << "result" << endl;

    /*終了*/
    return 0;
}

Measured memory_bytes: 256
#入力
N = int(input())
H = list(map(int, input().split()))

ans = 0
#処理 i番目のHがそれ以前以上の高さか調べる
for i in  range(N):
    l = H[:i+1]
    if max(l) == H[i]:
        ans += 1

#出力
print(ans)

Measured memory_bytes: 2940
import sys

def dfs(i, j):
    todo.append([i, j])
    while(todo != []):
        v = todo.pop(len(todo)-1)
        seen[v[0]][v[1]] = 1
        for i in range(8):
            if m[v[0]+dx[i]][v[1]+dy[i]] == 1 and seen[v[0]+dx[i]][v[1]+dy[i]] == 0:
                todo.append([v[0]+dx[i], v[1]+dy[i]])

while(1):
    w, h = map(int, input().split())
    if not w+h:
        break
    m = [[0] * (w+2) for i in range(h+2)]
    for j in range(h):
        m[j+1][1:w+1] = [int(i) for i in input().split()]

    dx = [0, 0, -1, 1, 1, 1, -1, -1]
    dy = [-1, 1, 0, 0, 1, -1, 1, -1]

    seen = [[0] * (w+2) for i in range(h+2)]
    todo = []
    ans = 0

    for i in range(h+2):
        for j in range(w+2):
            if m[i][j] == 1 and seen[i][j] == 0:
                ans += 1
                dfs(i, j)

    print(ans)


Measured memory_bytes: 5996
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node{
	int pre, to;
}edge[400010];
int head[200010], tot;
int n, a[200010];
int low[200010], cnt;
int ans[200010];
void add(int u, int v) {
	edge[++tot] = node{head[u], v};
	head[u] = tot;
}
void dfs(int x, int fa) {
	ans[x] = cnt;
	for (int i = head[x]; i; i = edge[i].pre) {
		int y = edge[i].to;
		if (y != fa) {
			if (low[cnt] < a[y]) {
				int b = cnt;
				low[++cnt] = a[y];
				dfs(y, x);
				cnt = b;
			} else {
				int p = lower_bound(low + 1, low + cnt + 1, a[y]) - low;
				int v = low[p];
				low[p] = a[y];
				dfs(y, x);
				low[p] = v;
			}
		}
	}
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		add(u, v);
		add(v, u);
	}
	low[++cnt] = a[1];
	ans[1] = cnt;
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 23396
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
//'A' = 65, 'a' = 97

int main()
{
    int n;
    cin >> n;
    double a[n];
    double sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }

    double ave = sum / n;

    double dif = 0;
    double ansnum = 1e9;
    int ans = 0;

    for (int i = 0; i < n; i ++)
    {
        dif = fabs(ave - a[i]);
        if (dif < ansnum) {
            ansnum = dif;
            ans = i;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
n, k = map(int, input().split())

ans = 0
nanjo = 0
a = True
tmp = n
while(a):
    if(tmp>=k):
        a = False
    else:
        tmp *= 2
        nanjo += 1

for i in range(n):
    tmp = n - i
    if (tmp >= k):
        ans += 1
    else:
        if(tmp * pow(2, nanjo) >= k):
            ans += pow(1 / 2, nanjo)
        else:
            nanjo += 1
            ans += pow(1 / 2, nanjo)

ans = ans / n
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
#define endl             "\n"
// -----------------<Container manipulation / traversal macros>------------------
#define mp                 make_pair
#define pb                 push_back
#define ff                 first
#define ss                 second
#define sz(x)             ((int)((x).size()))
#define all(x)             (x).begin(),(x).end()
#define rep(i,n)         for(ll (i)=0;(i)<(n);(i)++)
#define forn(i,a,b)     for(ll (i)=(a);(i)<=(b);(i)++)
#define fill(l,a)        memset((l) , (a) , sizeof(l))
// -----------------<Some common useful functions>------------------
#define maX(a,b)        ( (a) > (b) ? (a) : (b))
#define miN(a,b)        ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)   ( (n >> b) & 1)
#define INDEX(arr,i)      ( lower_bound(all(arr),i)-arr.begin())
#define in(b,a)         ( (b).find(a) != (b).end())
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector< std::vector<ll> > matrix;
typedef map<ll,ll> mii;
typedef vector<pii> vpii;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}
ll lcm(ll a,ll b)
{
    return(a/gcd(a,b)*b);
}
/*ll power(ll a,ll b,ll p)
{
    ll res=1;
    a%=p;
    while(b>0)
    {
        if(b&1)
        res=res*a%p;
        a=a*a%p;
        b>>=1;
    }
    return(res);
}
ll modInverse(ll a, ll m)
{
    ll g = gcd(a, m);
    return(power(a,m-2,m));
}*/
/*ll b_search(ll arr[],ll n,ll s)
{
    ll l=0,r=n-1;
    while(l<=r)
    {
        ll mid=l+(r-l)/2;
        if(arr[mid]==s)
        return(mid);
        if(arr[mid]<s)
        l=mid+1;
        else
        r=mid-1;
    }
    return(-1);
}*/
bool isprime(ll x)
{
    if(x==1)
        return(false);
    for(ll i=2;i*i<=x;i++)
    {
        if(x%i==0)
            return(false);
    }
    return(true);
}
//vector<ll> v[100005];
void solve()
{
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    map<ll,ll> mp;
    vector<ll> v(n,0);
    for(ll i=n-1;i>=0;i--)
    {
        v[i]=mp[i+arr[i]];
        mp[i-arr[i]]++;
    }
    ll ans=0;
    for(ll i=0;i<n;i++)
        ans+=v[i];
    cout<<ans<<endl;
}

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


Measured memory_bytes: 28952
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long 
using namespace std;
int n;
ll ans=0,a[1000010];
char s[1000010];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int now=1;
	a[0]=0;
	while(s[now]=='<'){
		a[now]=a[now-1]+1;
		now++;
	}
	while(now<n){
		if(s[now]=='>'&&s[now+1]=='<'){
			a[now]=0;
			int p=now-1;
			while(p>=0&&!a[p]){
				a[p]=a[p+1]+1;
				p--;
			}
			if(p>=0&&a[p]<a[p+1]+1)a[p]=a[p+1]+1;
			now++;
			while(s[now]=='<'){
				a[now]=a[now-1]+1;
				now++;
			}
		}
		else now++;
	}
	if(s[n]=='>'){
		a[n]=0;
		for(now=n-1;now>=0&&!a[now];now--)a[now]=a[now+1]+1;
		if(now>=0&&a[now]<a[now+1]+1)a[now]=a[now+1]+1;
	}
	/*cout<<a[0];
	for(register int i=1;i<=n;i++)cout<<s[i]<<a[i];
	cout<<endl;*/
	for(register int i=0;i<=n;i++)ans+=a[i];
	printf("%lld",ans);
	return 0;
} 

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

int main(){
    int n,tmp,a,b;
    bool judge;
    cin >> n;
    while(n--){
        stack <int> st1;
        stack <int> st2;
        judge = true;
        for(int i=0;i<10;i++){
            cin >> tmp;
            if(i == 0){
                st1.push(tmp);
                continue;
            }
            if(st2.empty()){
                if(tmp < st1.top()) st2.push(tmp);
                else st1.push(tmp);
                continue;
            }
            if(tmp - st1.top() > 0 && tmp - st2.top() > 0){
                a = tmp - st1.top();
                b = tmp - st2.top();
                if(a < b) st1.push(tmp);
                else st2.push(tmp);
            }
            else if(tmp - st1.top() > 0) st1.push(tmp);
            else if(tmp - st2.top() > 0) st2.push(tmp);
            else judge = false;
        }
        if(judge) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

Measured memory_bytes: 1192
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<String, Long> map = new HashMap<>();
		long cnt = 0;
		for ( int i = 0; i < n; i++ ) {
			char[] s = in.next().toCharArray();
			Arrays.sort(s);
			String key = new String(s);

			if ( map.containsKey(key) ) {
				Long prev = map.get(key);
				Long d = (long) Math.sqrt(prev * 2.0) + 1;
				map.put(key, prev + d);
			} else {
				map.put(key, (long) 0);
			}
		}

		for ( Entry<String, Long> en : map.entrySet() ) {
			// System.out.println(en);
			cnt += en.getValue();
		}

		System.out.println(cnt);
		in.close();
	}
}

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

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [i32; n],
    }
    let mut ans: usize = 0;
    for i in 0..n {
        if i % 2 == 0 && a[i] % 2 == 1 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		solve();

	}

	public static void solve() {
		Scanner sc = new Scanner(System.in);

		while (true) {
			int num = sc.nextInt();
			int min = sc.nextInt();
			int max = sc.nextInt();
			if (num == 0 && min == 0 && max == 0) {
				break;
			}

			int[] Tensu = new int[num];
			for (int i = 0; i < num; i++) {
				Tensu[i] = sc.nextInt();
			}

			int[] Gap = new int[max - min + 1];
			int tempMax = 0;
			int answer = 0;

			for (int j = min; j < max + 1; j++) {
				Gap[j - min] = Tensu[j - 1] - Tensu[j];
			}

			for (int k = 0; k < Gap.length; k++) {
				if (tempMax <= Gap[k]) {
					tempMax = Gap[k];
					answer = k + min;
				}
			}
			System.out.println(answer);
		}

	}
}

Measured memory_bytes: 57476
n = int(input())
temp = [int(_) for _ in input().split(' ')]
a = [0 for _ in range(100001)]
for k in temp:
    a[k] += 1
s = sum([i * a[i] for i in range(100001)])

q = int(input())

for _ in range(q):
    b, c = [int(_) for _ in input().split(' ')]
    s = s + (c - b) * a[b]
    print(s)
    a[c] += a[b]
    a[b] = 0


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

int main(){
  int n,i,m,k;
  cin >> n;
  vector<int> a(n);
  m=0,k=0;
  for(i=0;i<n;i++){
    cin >> a.at(i);
    if(a.at(i)>m){
      m=a.at(i);
      k=i;
    }
  }
  
  int m2=0;
  for(i=0;i<n;i++){
    if(i!=k){
      m2=max(m2,a.at(i));
    }
  }
  
  for(i=0;i<n;i++){
    if(i!=k){
      cout << m << endl;
    }else{
      cout << m2 << endl;
    }
  }
}

Measured memory_bytes: 3940
#include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

int note[100000000];

signed main(void) {
	int x;
	cin >> x;
	bool end = false;

	int a = 1;
	while (true) {
		int b = a;
		while ((pow(a, 5) - pow(b, 5))<=x) {
			if ((pow(a, 5) - pow(b, 5)) == x) {
				end = true;
				break;
			}
			b--;
		}
		if (end) {
			cout << a << " " << b << endl;
			break;
		}
		a++;
	}
}

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

int main(){
  int N;
  cin >> N;
  double A[N];
  for(int i = 0; i < N; i++)
    cin >> A[i];
  double sum = 0;
  for(int i = 0; i < N; i++)
    sum += 1 / A[i];
  cout << fixed << setprecision(10);
  cout << 1 / sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define int long long
long long ans;

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x*y/gcd(x,y);
}
 
signed main(){
	string s,t;
	cin>>s>>t;
	for(int i=s.size()-t.size();i>=0;i--){
		bool bou=true;
		for(int j=i;j<i+t.size();j++){
			if(s[j]!='?'&&s[j]!=t[j-i]){
				bou=false;
				break;
			}
		}
		if(bou){
			for(int j=0;j<i;j++){
				if(s[j]=='?')cout<<'a';
				else cout<<s[j];
			}
			for(int j=0;j<t.size();j++)cout<<t[j];
			for(int j=i+t.size();j<s.size();j++){
				if(s[j]=='?')cout<<'a';
				else cout<<s[j];
			}
			return 0;
		}
	}
	cout<<"UNRESTORABLE"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
int X, Y, A, B, C, curP = 0, curQ = 0, curR = 0;
vi P, Q, R, S;

void solve(){
    sort(P.begin(), P.end());
    sort(Q.begin(), Q.end());

    reverse(P.begin(), P.end());
    reverse(Q.begin(), Q.end());

    rep(i, X) S.push_back(P[i]);
    rep(i, Y) S.push_back(Q[i]);
    rep(i, C) S.push_back(R[i]);

    sort(S.begin(), S.end());
    reverse(S.begin(), S.end());

    rep(i, X+Y) ans += S[i];

    cout << ans << endl;
}

int main(){
    cin >> X >> Y >> A >> B >> C;
    P.resize(A);
    Q.resize(B);
    R.resize(C);

    rep(i, A) cin >> P[i];
    rep(i, B) cin >> Q[i];
    rep(i, C) cin >> R[i];

    solve();
}


Measured memory_bytes: 3572
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int D;
  cin >> D;
  vi c(26);
  cin >> c;
  vvi s(D, vi(26));
  cin >> s;

  rep(i, D) {
    out(i % 26 + 1);
  }
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);
int sub(int,int);
template<typename A> ostream& operator<<(ostream&,vector<A>&);

const int N=500001;
	
void solve(){
	int n;
	cin>>n;
	vi a(n);
	cin>>a;
	vi ans(n);
	int vl=0;
	for(int i=0;i<n-1;i++){
		if(i%2==0){
			vl+=a[i];
		}
		else{
			vl-=a[i];
		}		
	}
	vl=-vl;
	int ls=vl+a[n-1];
	ans[n-1]=ls;
	for(int i=n-2;i>=0;i--){
		ans[i]=2*a[i]-ans[i+1];
	}
	cout<<ans;
	
}
	
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}

int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
	    output<<i<<' ';
	return output;	
}


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

int main()
{
	int N;
	scanf("%d", &N);
	using Point = std::complex<long double>;
	std::vector<Point> points(N);
	for (auto& e: points)
	{
		long double x, y;
		scanf("%Lf%Lf", &x, &y);
		e.real(x);
		e.imag(y);
	}
	std::sort(points.begin(), points.end(),
		[](auto& a, auto& b) { return std::arg(a) < std::arg(b); }
	);
	long double max{};
	for (int i{}; i < N; i++)
		for (int j{}; j < N; j++)
		{
			Point sum{points[i]};
			for (int k{(i + 1) % N}; k != j; k = (k + 1) % N)
				sum += points[k];
			max = std::max(max, std::abs(sum));
		}
	printf("%.15Lf", max);

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
  const int MAX=20;
  const int INF=(1<<21);
int main(){
  int n,m;
  int a,b,c,d;
  int x1,x2,y1,y2;
  int road[MAX][MAX];
  cin>> n>> m;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      road[i][j]=INF;
    }
  }
  for(int i=0;i<m;i++){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    road[a-1][b-1]=c;
    road[b-1][a-1]=d;
  }
   for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	road[j][k]=min(road[j][k],road[j][i]+road[i][k]);
      }
    }
  }
  scanf("%d,%d,%d,%d",&x1,&x2,&y1,&y2);
  cout<< y1-(y2+road[x1-1][x2-1]+road[x2-1][x1-1])<< endl;
}

Measured memory_bytes: 1240
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
using namespace std;
int a[200010];
ll sum;
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    if(n>1)
    {
        sum+=a[n-1];
    }
    int k=n-2;
    n=n-2;
    while(n>=2)
    {
        sum=sum+2*a[k--];
        n=n-2;

    }
    if(n==1)
    {
        sum+=a[k];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4380
import java.sql.Date;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		String cnt = "20";
		String day = "01";

		Scanner sc1 = new Scanner(System.in);

		String s = sc1.next();

		String str1 = s.substring(0, 2);
		String str2 = s.substring(2, 4);

		//YYMM
		String date1 = cnt + str1 + "-" + str2 + "-" + day;
		//MMYY
		String date2 = cnt + str2 + "-" + str1 + "-" + day;

		//System.out.println(date1);
		//System.out.println(date2);

		boolean flg1 = true;
		boolean flg2 = true;

		try {
			Date.valueOf(date1);
		}
		catch(IllegalArgumentException e) {
			flg1 = false;
		}

		try {
			Date.valueOf(date2);
		}
		catch(IllegalArgumentException e) {
			flg2 = false;
		}

		if (flg1 && flg2) {
			System.out.println("AMBIGUOUS");
		}
		else if (flg1) {
			System.out.println("YYMM");
		}
		else if (flg2) {
			System.out.println("MMYY");
		}
		else {
			System.out.println("NA");
		}

		sc1.close();

	}

}

Measured memory_bytes: 24144