akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i < 46300; i++) {
		if ((int)(i * 1.08) == n) {
			printf("%d\n", i);
			return 0;
		}
	}
	printf(":(\n");
	return 0;
}

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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

void solve(std::vector<long long> H, std::vector<long long> M, long long K){
    ll minutes = 0;
    if(H.at(0) == H.at(1)){
        minutes = M.at(1) - M.at(0);
    }else{
        minutes += 60 - M.at(0);
        H.at(0)++;
        minutes += (H.at(1) - H.at(0))*60;
        minutes += M.at(1);
    }

    cout << minutes - K << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::vector<long long> H(2);
    std::vector<long long> M(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&H[i]);
        scanf("%lld",&M[i]);
    }
    long long K;
    scanf("%lld",&K);
    solve(std::move(H), std::move(M), K);
    return 0;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    REP(i, n){
        cin >> x[i] >> y[i] >> h[i];
    }

    REP(i, 101){
        REP(j, 101){
            int num;
            REP(k, n){
                if(h[k] != 0){
                    num = h[k] + abs(i - x[k]) + abs(j - y[k]);
                    break;
                }
            }
            bool flag = true;
            REP(k, n){
                if(h[k] == 0 && abs(i - x[k]) + abs(j - y[k]) >= num) continue;
                if(num != h[k] + abs(i - x[k]) + abs(j - y[k])){
                    flag = false;
                }
            }
            if(flag){
                cout << i << " " << j << " " << num << endl;
                return 0;
            }
        }
    }
}


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

int main (void) {
  int N;
  cin >> N;
  vector<vector<pair<int, int>>> graph(N, vector<pair<int, int>>());
  for (int i = 0; i < N - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    graph[u].emplace_back(v, w);
    graph[v].emplace_back(u, w);
  }
  // 任意に頂点をひとつとる
  // とりあえず頂点0
  // 葉をさがす
  int leaf = 0;
  stack<int> st;
  st.push(0);
  vector<bool> visited(N, false);
  while (!st.empty()) {
    const int u = st.top(); st.pop();
    leaf = u;
    for (const auto& edge : graph[u]) {
      const int v = edge.first;
      if (!visited[v]) {
        st.push(v);
        visited[v] = true;
      }
    }
  }
  // cout << "LEAF: " << leaf << endl;

  // 頂点の色
  vector<int> color(N, -1);

  // 葉から順に色を塗っていく
  // とりあえず0で始める
  st.push(leaf);
  color[leaf] = 0;

  // 訪問済みテーブルを初期化する
  visited.assign(N, false);

  while (!st.empty()) {
    const int u = st.top(); st.pop();
    const int u_color = color[u];
    for (const auto& edge : graph[u]) {
      const int v = edge.first, w = edge.second;
      if (!visited[v]) {
        const int next_color = w % 2 == 0 ? u_color : 1 - u_color;
        color[v] = next_color;
        st.push(v);
        visited[v] = true;
      }
    }
  }
  for (const auto& c : color) {
    assert(c != -1);
    cout << c << endl;
  }
  return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
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<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
 int v[60][30];
 map<char,int>mp;
int main(){
   string s;
   cin>>s;
 //  int min_s=100;
   
   vector<vector<int>>v(30);
   for (int i = 0; i <=25; i++)
   {
       v[i].push_back(-1);
   }
   
   for (int i = 0; i < s.size(); i++)
   {
       v[s[i]-'a'].push_back(i);
   }
   for (int i = 0; i < 26; i++)
   {
       v[i].push_back(s.size());
   }
   int tmp1,tmp2;
   int min_s=100;
   for (int i = 0; i < 26; i++)
   {    if(v[i].size()==2)continue;
         tmp2=0;
       for (size_t j = 0; j < v[i].size()-1; j++)
       {
           tmp1=v[i][j+1]-v[i][j]-1;
           tmp2=max(tmp1,tmp2);
          // cerr<<tmp1<<endl;
       }
       // cerr<<tmp1<<" "<<tmp2<<endl;
       if(tmp2<min_s){
           min_s=tmp2;
       }
   }
    cout<<min_s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
 
using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
 
 
int main(void) {
	int n; cin >> n;
	vector<int> v(n);
	rep(i, n)cin >> v[i];
	int sum = 0;
	rep(i, n-1) {
		for (int j = i + 1; j < n;j++) {
			sum += v[i] * v[j];
		}
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

const int N = int(1e5) + 2;
const int LG = 20;
const ll mod = 998244353;
const int INF = 2147483647;
const ll linf = 1e18;
const ld pi = acos(-1);
const ld EPS = 1e-10;

int n;
bool color[N];
vector < pii > g[N];

void dfs (int v, int p, bool flag){
    color[v] = flag;
    for (auto to : g[v]){
        if (to.fi == p) continue;
        dfs(to.fi, v, flag ^ to.se);
    }
}

int main (){
    scanf ("%d", &n);
    for (int i = 1; i <= n - 1; ++i){
        int u, v, w;
        scanf ("%d %d %d", &u, &v, &w);
        g[u].pb({v, w % 2});
        g[v].pb({u, w % 2});
    }
    dfs(1, 0, 0);
    for (int i = 1; i <= n; ++i) printf ("%d\n", color[i]);
}


Measured memory_bytes: 8064
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,K = II()
h = [I() for _ in range(N)]
h.sort()

ans = float('inf')

for i in range(N-K+1):
    temp = h[i+K-1]-h[i]
    if temp < ans:
        ans = temp

print(ans)

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

public class P
{
    public int color { get; set; }
    public int count { get; set; }
}


public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            getAns(n);
        }
    }
    static void getAns(int n)
    {
        var st = new Stack<P>();
        var w = int.Parse(Console.ReadLine().Trim());
        if (n == 1)
        {
            if (w == 1) Console.WriteLine(0);
            else Console.WriteLine(1);
            return;
        }
        st.Push(new P { color = w, count = 1 });
        for (int i = 0; i < n - 1; i++)
        {
            var c = int.Parse(Console.ReadLine().Trim());
            if (i % 2 == 0)
            {
                var p = st.Pop();
                if (c == p.color) { st.Push(new P { color = c, count = p.count + 1 }); }
                else
                {
                    var tcount = p.count + 1;
                    if (st.Count() > 0) { var p2 = st.Pop();  tcount += p2.count; }
                    st.Push(new P { color = c, count = tcount });
                }
            }
            else
            {
                var p = st.Peek();
                if (c == p.color) { st.Pop();   st.Push(new P { color = c, count = p.count + 1 }); }
                else { st.Push(new P { color = c, count =  1 }); }
            }
        }
        var ans = 0;
        while (st.Count() > 0)
        {
            var p = st.Pop();
            if (p.color == 0) ans += p.count;
        }
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 20524
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        s = s.Replace("/", "");
        var s2 = int.Parse(s);
        if (s2 <= 20190430) Console.WriteLine("Heisei");
        else Console.WriteLine("TBD");

    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <queue>
#include <utility>
#include <algorithm>

using namespace std;

#define S 0
#define E 1
#define pii pair<int, int>

int main()
{
    int N;
    cin >> N;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;

    for (int i = 0; i < N; i++)
    {
        int s, e;
        cin >> s >> e;
        q.push(pii(s, S));
        q.push(pii(e, E));
    }

    vector<int> vs(N);
    vector<int> ve(N);
    int l = 0;
    int r = 0;
    while (!q.empty())
    {
        auto p = q.top();
        q.pop();
        if (p.second == S)
        {
            vs[l] = p.first;
            l++;
        }
        else
        {
            ve[r] = p.first;
            r++;
        }
    }

    int ans;
    if (N % 2 == 1)
    {
        int i = (N + 1) / 2 - 1;
        ans = ve[i] - vs[i] + 1;
    }
    else
    {
        int i = N / 2 - 1;
        ans = ve[i] + ve[i + 1] - vs[i] - vs[i + 1] + 1;
    }

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

Measured memory_bytes: 7484
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n';

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	
	ll cnt = 0;
	vector<int> h(n);
	rep(i, n) {
		cin >> h[i];
		cnt += h[i];
	}
	if (k > n) {
		cout << 0; return 0;
	}
	sort(h.rbegin(), h.rend());
	int j = 0;
	while (k > 0) {
		cnt -= h[j];
		++j;
		--k;
	}
	cout << cnt;
}



Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
	int y,next;
}a[200010];
int first[100010],len;
int fa[100010],d[100010];
int mark[100010],f[100010];
int X,Y;
int A[100010],al;
int B[100010],bl;
long long ans;
int cmp(const void *xx,const void *yy)
{
	int x=*(int *)xx,y=*(int *)yy;
	return x-y;
}
void ins(int x,int y)
{
	a[++len].y=y;
	a[len].next=first[x];
	first[x]=len;
}
void dfs(int x,int F,int K)
{
	f[x]=-1;
	int k,y;
	for(k=first[x];k;k=a[k].next)
	{
	  y=a[k].y;
	  if(k==(K^1)||mark[y])continue;
	  dfs(y,x,k);
	}
	if(F)
	{
	  ans+=abs(f[x]);
	  f[F]-=f[x];
	}
}
void DFS(int x,int F,int K)
{
	fa[x]=F;
	d[x]=d[F]+1;
	int k,y;
	for(k=first[x];k;k=a[k].next)
	{
	  y=a[k].y;
	  if(k==(K^1))continue;
	  if(d[y])
	  {
		if(d[y]<d[x])X=x,Y=y;
		continue;
	  }
	  DFS(y,x,k);
	}
}
int main()
{
	int T,n,m,x,y,i,j;T=1;
	while(T--)
	{
	  scanf("%d%d",&n,&m);
	  for(i=1;i<=n;i++)first[i]=0,mark[i]=0,d[i]=0;
	  len=1;
	  for(i=1;i<=m;i++)
	  {
		scanf("%d%d",&x,&y);
		ins(x,y);ins(y,x);
	  }
	  if(m==n-1)
	  {
		ans=0;
		dfs(1,0,0);
		if(f[1])printf("-1\n");
		else printf("%I64d\n",ans);
	  }
	  else
	  {
		ans=0;
		DFS(1,0,0);
		for(x=X;x!=Y;x=fa[x])
		  mark[x]=1;
	    mark[Y]=1;
		al=0;
		for(x=X;x!=Y;x=fa[x])
		{
		  dfs(x,0,0);
	      A[++al]=f[x];
		}
		dfs(Y,0,0);
		A[++al]=f[Y];
		X=1;Y=0;
		for(i=1;i<=al;i++)
		{
		  X*=-1;Y=A[i]-Y;
		}
		if(X==1)
		{
		  if(Y)printf("-1\n");
		  else
		  {
			bl=al;
			X=1;Y=0;
			for(i=1;i<=al;i++)
			{
			  X*=-1;Y=A[i]-Y;
			  if(X==1)B[i]=Y;
			  else B[i]=-Y;
			}
			qsort(B+1,bl,sizeof(int),cmp);
			int mid=(1+bl)>>1;
			for(i=1;i<=bl;i++)
			  ans+=abs(B[i]-B[mid]);
		    printf("%I64d\n",ans);
		  }
		}
	    else
	    {
		  if(Y%2==0)
		  {
			Y/=2;
			for(i=1;i<=al;i++)
			{
			  Y=A[i]-Y;
			  ans+=abs(Y);
			}
			printf("%I64d\n",ans);
		  }
		  else printf("-1\n");
	    }
	  }
	}
	return 0;
}

Measured memory_bytes: 9468
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)

ll a[100001] = {};
ll s[100001] = {};
int main() {
	ll n, k; cin >> n >> k;
	ll maxV = 0;
	repe(i, 1, n) {
		cin >> a[i];
		if (a[i] == k) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
		maxV = max(maxV, a[i]);
	}
	if (maxV < k || n == 1) {
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	sort(a + 1, a + 1 + n);
	repe(i, 1, n) {
		s[i] = a[i] - a[i - 1];
		if (s[i] == 1) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
		else if (s[i] != 0 && k % s[i] == 0) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;

	return 0;
}

Measured memory_bytes: 1408
/*
package com.company.practice;
*/

import java.util.Scanner;
import java.lang.*;
import java.util.Scanner;

import static java.lang.Character.isUpperCase;

public class Main {
    public static void main(String[] args)
    {
        Scanner key = new Scanner(System.in);
        char s = key.next().charAt(0);
        if(isUpperCase(s))
            System.out.println("A");
        else
            System.out.println("a");
    }
}


Measured memory_bytes: 35680
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
applyTuple :: (a -> b, a -> c) -> a -> (b, c)
applyTuple (f,g) a = (f a, g a)
-- end of templete

cbrt q = head . dropWhile ((>=0.00001 * q) . abs . (subtract q) . (^3)) . iterate (\x -> x - (x^3 - q) / (3 * x^2)) $ q / 2

main = map cbrt .takeWhile (/=(-1)) . map read . lines <$> getContents >>= mapM_ print 

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

int main () {
  int N; cin >> N;
  vector<int> vec(N);
  int maxdiff = 0;
  for (int i = 0; i < N; i++) cin >> vec.at(i);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int tempmax;
      tempmax = abs(vec.at(i) - vec.at (j));
      if (tempmax > maxdiff) {
        maxdiff = tempmax;
      }
    }
  }
  cout << maxdiff << endl;
}

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

int N,C;

int calc(vector<vector<int>> &D,vector<int> &cnt,int x){
  int ans=0;
  for(int i=0;i<C;i++){
    ans+=D.at(i).at(x)*cnt.at(i);
  }
  return ans;
}

int main(){
  cin >> N >> C;
  vector<vector<int>> D(C,vector<int>(C));
  for(int i=0;i<C;i++){
    for(int j=0;j<C;j++){
      cin >> D.at(i).at(j);
    }
  }
  vector<vector<int>> c(N,vector<int>(N));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin >> c.at(i).at(j);
      c.at(i).at(j)--;
    }
  }

  vector<vector<int>> cnt(3,vector<int>(C,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cnt.at((i+j)%3).at(c.at(i).at(j))++;
    }
  }
  int ans=1e9;
  for(int i=0;i<C;i++){
    for(int j=0;j<C;j++){
      for(int k=0;k<C;k++){
        if(i==j || j==k || k==i)  continue;
        int tmp0=calc(D,cnt.at(0),i);
        int tmp1=calc(D,cnt.at(1),j);
        int tmp2=calc(D,cnt.at(2),k);
        ans=min(ans,tmp0+tmp1+tmp2);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1280
// -*- coding:utf-8-unix -*-

use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        n: u64,
    }

    let mut ans = 0;
    for a in 1..n {
        // println!("a = {}, {}", a, (n - 1) / a);
        ans += (n - 1) / a;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2164
while True:
	H,W=[int(i)for i in input().split()]

	if H==0 and W==0:
		break
	else:
		for i in range (H):
			if i == 0 or i == H-1:
				print("#"*W)
			else:
				print("#"+"."*(W-2)+"#")
		print("")

Measured memory_bytes: 7644
from collections import Counter
def main():
    S = input()
    C = Counter(S)
    if C["R"] == 3:
        print(3)
    elif C["R"] == 2:
        if S[1] == "S":
            print(1)
        else:
            print(2)
    elif C["R"] == 1:
        print(1)
    else:
        print(0)
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 9400
import sys;sys.setrecursionlimit(10**9)
class Union_Find():
  def __init__(self,n):self.n,self.r=[-1]*n,[0]*n
  def Find_Root(self,x):
    if self.n[x]<0:return x
    else:self.n[x]=self.Find_Root(self.n[x]);return self.n[x]
  def Unite(self,x,y):
    x,y=self.Find_Root(x),self.Find_Root(y)
    if x==y:return
    elif self.r[x]>self.r[y]:self.n[x]+=self.n[y];self.n[y]=x
    else:self.n[y]+=self.n[x];self.n[x]=y;self.r[y]+=self.r[x]==self.r[y]
  def isRootSame(self,x,y):return self.Find_Root(x)==self.Find_Root(y)
  def Count(self,x):return -self.n[self.Find_Root(x)]
n,m=map(int,input().split())
a=n*(n-1)//2
ans=[a]
u=Union_Find(n)
b=[tuple(map(int,input().split()))for _ in range(m)]
for ii,jj in b[::-1][:-1]:
  i,j=ii-1,jj-1
  if not(u.isRootSame(i,j)):
    a-=u.Count(i)*u.Count(j)
    u.Unite(i,j)
  ans+=[a]
for i in ans[::-1]:print(i)

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

long long const MOD = 1000000007;
long long p[200100];
void init() {
    p[0] = 1;
    for(int i=1; i<200100; ++i) p[i] = p[i - 1] * 2 % MOD;
}

int main() {
    int N; cin >> N;
    vector<long long> C(N);
    for(int i=0; i<N; ++i) cin >> C[i];
    sort(begin(C), end(C));
    
    init();
    long long res = 0;
    for(int i=0; i<N; ++i) {
        long long tmp = p[N - 1];
        if(N > 1) tmp = (tmp + (N - 1 - i) * p[N - 2] % MOD) % MOD;
        tmp = tmp * C[i] % MOD;
        res = (res + tmp) % MOD;
    }
    res = res * p[N] % MOD;
    cout << res << endl;
}

Measured memory_bytes: 3328
import functools

def gcd(x, y):
    if y==0:
        return x
    else:
        return gcd(y, x%y)

def lcm(x, y):
    return (x * y) // gcd(x, y)

n = int(input())
print(functools.reduce(lcm, [int(input()) for i in range(n)]))


Measured memory_bytes: 3700
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define sl(c) (('a')<=(c)&&(c)<=('z'))
#define ll(c) (('A')<=(c)&&(c)<=('Z'))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define PI 3.141592653589793
#define cout (cout<<fixed<<setprecision(15))
#define makeupper(t) (transform(all(t),t.begin(),::toupper))
#define makelower(t) (transform(all(t),t.begin(),::tolower))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define NEXT_LINE string junk; getline(cin, junk);
#define output(v) do{rep(i,v.size())cout<<(i?" ":"")<<v[i];cout<<"\n";}while(0)
#define output2(v) rep(i,v.size()){rep(j,v[i].size()){cout<<(j?" ":"")<<v[i][j];}cout<<"\n";}
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    lint n;
    cin>>n;
    set<string> a;
    rep(i,n){
        string t;
        string s;
        cin>>s>>t;
        if(s=="insert")a.insert(t);
        if(s=="find"){
            if(a.count(t))cout<<"yes"<<"\n";
            else cout<<"no\n";
        }
    }
}


Measured memory_bytes: 29044
import java.io.*;
import java.util.*;
class Main {

	public static void main(String[] args) {
        FastScanner in = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        char ch[] = in.next().toCharArray();
        if(ch[ch.length-1]=='s'){
        	out.println(new String(ch)+"es");
        }
        else {
        	out.println(new String(ch)+"s");
        }
        out.flush();
	}
	
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		
		String next() {
			while(!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				}catch(IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int a[] = new int[n];
			for(int i=0;i<n;i++) a[i] = nextInt();
			return a;
		}
		
		Integer[] readArray(long n) {
		    Integer a[] = new Integer[(int)n];
			for(int i=0;i<n;i++) a[i] = nextInt();
			return a;
		}
		
		long[] readArray(int n,long x) {
			long a[] = new long[n];
			for(int i=0;i<n;i++) a[i] = nextLong();
			return a;
		}
		
	}
	
	static class Pair implements Comparable<Pair> {
		int x, y;
		Pair(int a, int b){ x = a; y = b; }
		int getKey() { return x; }
		int getVal() { return y; }
		@Override
		public int compareTo(Pair o) {
			if(o.getVal() - this.getVal()>0)
				return -1;
			else if(o.getVal() - this.getVal()<0)
				return 1;
			else 
				return 0;
		}
		
	}
	
	static boolean arrayEquals(char a[], char b[]) {
		int n = a.length;
		boolean verdict = true;
		for(int i=0;i<n;i++) {
			if(a[i]!=b[i]) {
				verdict = false;break;
			}
		}
		return verdict;
	}
	
	static long lcm(long a, long b) {
		return (a*b)/gcd(a,b);
	}
	
	static long gcd(long a, long b) {
		if(b==0) return a;
		else return gcd(b,a%b);
	}
	
	static long hashInt(int x,int y) {
		return x*(1_000_000_000L)+y;
	}
}


Measured memory_bytes: 36744
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    ll d;
    cin >> L >> R >> d;

    D = d;
    for (int i = 1; D <= R; D=d*i)
    {
        if(D>=L)A++;
        i++;
    }
    cout << A;
    
    return 0;
}

Measured memory_bytes: 3552
#include <iostream>

using namespace std;

int main() {
    int a, b, c;

    cin >> a >> b >> c;

    if(a==5 && b==5 && c==7) {
        cout << "YES" << endl;
    } else if(a==5 && b==7 && c==5) {
        cout << "YES" << endl;
    } else if(a==7 && b==5 && c==5) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int i=0,j=0;
  if(a==5) {
    ++i;
  } else if(a==7) {
    ++j;
  }
  if(b==5) {
    ++i;
  } else if(b==7) {
    ++j;
  }
  if(c==5) {
    ++i;
  } else if(c==7) {
    ++j;
  }
  if(i==2 && j==1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

bool can_reach(int start, int goal, const string s) {
	int n = (int)s.size();
	for(int i = start; i < goal; ++i) {
		if( s[i] == '#' && s[i + 1] == '#' ) return false;
	}
	
	return true;
}

int main(void) {
	int n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d >> s;
	a--; b--;
	c--; d--;
	
	if( !can_reach(a, c, s) || !can_reach(b, d, s) ) {
		cout << "No" << endl;
		return 0;
	}
	
	if( c < d ) {
		cout << "Yes" << endl;
	} else if( c > d ) {
		bool threeDot = false;
		
		for(int i = b; i <= d; ++i) {
			if( s.substr(i - 1, 3) == "..." ) {
				threeDot = true;
			}
		}
	
		if( threeDot ) cout << "Yes" << endl;
		else cout << "No" << endl;
	}	
	
	return 0;
}


Measured memory_bytes: 3864
import math
import itertools
import collections
import bisect
import heapq

def IN(): return int(input())
def sIN(): return input()
def MAP(): return map(int,input().split())
def LMAP(): return list(map(int,input().split()))
def TATE(n): return [input() for i in range(n)]
MOD = 10**9 + 7


n = IN()
a = LMAP()
q = IN()
ans = sum(a)
dic = {}

for i in a:
  if i not in dic:
    dic[i] = 1
  else:
    dic[i] += 1

for i in range(q):
  b,c = MAP()
  if b not in dic:
    print(ans)
  else:
    ans -= (b-c) * dic[b]
    if c in dic:
      dic[c] += dic[b]
      dic.pop(b)
    else:
      dic[c] = dic.pop(b)
    print(ans)
    
    
    

Measured memory_bytes: 21352
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;

using namespace std;

ll conb(ll n, ll r) {
	if (n - r < r) { return conb(n, n - r); }
	ll tmp = 1;
	FOR(i, n - r + 1, n + 1) {
		tmp *= i;
	}
	FOR(i, 1, r + 1) {
		tmp /= i;
	}
	return tmp;
}

ll mod(ll n, ll r) {
	ll q = n % r;
	return (q < 0) ? q + r : q;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<ll> a(n);
	vector<ll> list(n + 1);
	map<ll, ll> mp;

	list[0] = 0;
	mp[0] = 1;
	REP(i, n) {
		cin >> a[i];
		list[i + 1] = list[i] + a[i];
		list[i + 1] = mod(move(list[i + 1]), m);
		if (mp.find(list[i + 1]) == mp.end()) {
			mp[list[i + 1]] = 1;
		} else {
			++mp[list[i + 1]];
		}
	}

	ll count = 0;
	REPC(x, mp) {
		//cout << x.first << " " << x.second << endl;
		if (x.second >= 2) {
			count += conb(x.second, 2);
		}
	}

	cout << count << endl;

}

Measured memory_bytes: 5760
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iterator>
#include <numeric>
#include <functional>
#include <climits>



using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, char> pic;

void bubble(vector<pic>& v){
  size_t n = v.size();
  for (size_t i = 0; i < n; i++) {
    for (size_t j = n-1; j > i; j--) {
      if(v[j-1].first > v[j].first){
        pic buf = v[j-1];
        v[j-1] = v[j];
        v[j] = buf;
      }
    }
  }
}

void selection(vector<pic>& v){
  size_t n = v.size();
  for (size_t i = 0; i < n; i++) {
    size_t minj = i;
    for (size_t j = i; j < n; j++) {
      if(v[j].first < v[minj].first){
        minj = j;
      }
    }
    pic buf = v[minj];
    v[minj] = v[i];
    v[i] = buf;
  }
}

void print(vector<pic> v){
  for (size_t i = 0; i < v.size()-1; i++) {
    cout << v[i].second << v[i].first << " ";
  }
  cout << v.back().second << v.back().first << endl;
}


bool stable(vector<pic> in, vector<pic> out){
  size_t n = in.size();
  for (size_t i = 0; i < n; i++) {
    for (size_t j = i+1; j < n; j++) {
      if(in[i].first == in[j].first){
        size_t x = 0, y = 0;
        for(; x < n; x++){
          if(in[i] == out[x]) break;
        }
        for(; y < n; y++){
          if(in[j] == out[y]) break;
        }
        if((i<j) != (x<y)) return false;
      }
    }
  }
  return true;
}

void print2(vector<pic> in, vector<pic> v){
  if(stable(in, v)){
    cout << "Stable" <<endl;
  } else{
    cout << "Not stable" <<endl;
  }
}


int main(int argc, char *argv[]){
  size_t n;
  cin >> n;
  vector<pic> v(n);
  for (size_t i = 0; i < n; i++) {
    string buf;
    cin >> buf;
    v[i].first = buf[1]-'0';
    v[i].second = buf[0];
  }

  vector<pic> b = v;
  vector<pic> s = v;

  bubble(b);
  print(b);
  print2(v, b);

  selection(s);
  print(s);
  print2(v, s);

  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
int gcd(int a, int b) {
	if (a < b)swap(a, b);
	return b == 0 ? a : gcd(b, a%b);
}
int n;
int vis[N], a[N], isp[N];
bool ck() {
	for (int i = 2; i < N; i++) {
		if (isp[i])continue;
		int cnt = 0;
		for (int j = i; j < N; j += i) {
			isp[i] = 1;
			cnt += vis[j];
		}
		if (cnt > 1)return false;
	}
	return true;
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%d", &a[i]), vis[a[i]]++;
	if (ck()) { puts("pairwise coprime"); return 0; }
	int g = a[1];
	for (int i = 2; i <= n; i++)g = gcd(g, a[i]);
	if (g == 1)puts("setwise coprime");
	else puts("not coprime");
	return 0;
}

Measured memory_bytes: 11816
N = int(input())

ans = 0
for i in range(1, N+1):
    if int(i * 1.08) < N:
        continue
    elif int(i * 1.08) == N:
        ans = i
        break
    else:
        break

if ans==0:
    print(":(")
else:
    print(ans)


Measured memory_bytes: 2940
#include<stdio.h>

int input_num[9999], case_num = 0;
int i = 0;

int main() {
	do {
		scanf("%d", &input_num[case_num]);
		case_num++;
	} while (input_num[case_num-1] != 0);
	
	do {
		printf("Case %d: %d\n", i+1, input_num[i]);
		i++;
	} while (i != case_num-1);

	return 0;
}


Measured memory_bytes: 2060
#include <iostream>
#include <algorithm>
#include <map>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef pair<int,int> P;

int n, m;
P arm[100000];
int st[200000];
int en[200000];

void init(){
    rep(i,n){
        st[i] = i;
        en[i] = i+1;
    }
}

void unite(int x, int y){
    int s = min(st[x],st[y]);
    int e = max(en[x],en[y]);
    st[x] = s; st[y] = s;
    en[x] = e; en[y] = e;
}

int main(){
    cin >> n >> m;
    init();
    rep(i,m){
        int x, y;
        cin >> x >> y;
        arm[i] = P(x,y);
    }
    sort(arm,arm+m);
    rep(i,m){
        unite(arm[i].second-1,arm[i].second);
    }
    rep(i,n){
        if(i != n-1) cout << en[i]-st[i] << " ";
        else cout << en[i]-st[i] << endl;
    }
}

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

using namespace std;
constexpr int NMAX = 100010;

char initString[NMAX];

int main() {
	scanf("%s", initString);
	deque<char> dq;
	for (int i = 0; initString[i]; ++i) dq.push_back(initString[i]);
	bool beginIsStart = true;
	int q; scanf("%d", &q);
	for (int qta = 0; qta < q; ++qta) {
		int t; scanf("%d", &t);
		if (t == 1) {
			beginIsStart = !beginIsStart;
		} else {
			int f; char c; scanf("%d %c", &f, &c);
			if (beginIsStart == (f == 1)) {
				dq.push_front(c);
			} else {
				dq.push_back(c);
			}
		}
	}
	vector<char> fans;
	if (beginIsStart) fans = vector<char>(dq.begin(), dq.end());
	else fans = vector<char>(dq.rbegin(), dq.rend());
	for (char c : fans) printf("%c", c);
	printf("\n");
	return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


string sim(string s) {
    string stk;
    for (char c: s) {
	if (stk.empty()) {
	    stk += c; continue;
	}
	if (stk.back() == '(' && c == ')') {
	    stk.pop_back(); continue;
	}
	stk += c;
    }
    return stk;
}

vector<string> mid;

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

    int n;
    cin>>n;

    while (n--) {
	string s; cin>>s;
	s = sim(s);
	if (s == "") continue;
	mid.push_back(s);
    }
    vector<string> left, right;
    for (auto s: mid) {
	int rnk = 0;
	for (char c: s) {
	    if (c=='(') rnk++; else rnk--;
	}
	if (rnk>=0) left.push_back(s); else right.push_back(s);
    }

    sort(left.begin(), left.end(), [&](string a, string b) {
	    int n = a.length();
	    int m = b.length();
	    int i=0;
	    while (i<n && a[i]==')') i++;
	    
	    int j=0;
	    while (j<m && b[j]==')') j++;

	    return i<j;
	});

    sort(right.begin(), right.end(), [&](string a, string b) {
	    int n = a.length();
	    int m = b.length();
	    
	    int o1 = 0;
	    while (o1<(int)a.size() && a[o1]==')') o1++;
	    
	    int o2 = 0;
	    while (o2<(int)b.size() && b[o2]==')') o2++;

	    return n-o1 > m-o2;
	});
    

    string s;

    for (auto p: left) {
	for (char c: p) s += c;
    }
    for (auto p: right) {
	for (char c: p) s += c;
    }

    
    s = sim(s);
    if (s.empty()) cout<<"Yes\n"; else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 88152
def resolve():
    l=list(map(int,input().split()))
    l.sort()
    c=l[2]-l[1]
    if (l[2]-(l[0]+c))%2==0:
        c+=(l[2]-(l[0]+c))//2
    else:
        c+=1+(l[2]+1-(l[0]+c))//2
    print(c)
resolve()

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

/*int main(){
  int a,b,x;
  scanf("%d %d %d",&a,&b,&x);

}*/
long double to_rad(long double a) {
    return a * atan(1.0) * 4.0 / 180.0;
}
long double to_deg(long double r) {
    return r * 180.0 / (atan(1.0) * 4.0);
}

int main(){
  int a,b,x;
  scanf("%d %d %d",&a,&b,&x);
  long double tmp1,tmp2,tmp3;
  tmp3=a*a*b/2.0;
  long double deg,rad;
  long double X=x;
  if(X>=tmp3){
  tmp1=2.0*(a*a*b-x);
  tmp2=a*a*a;
  deg=tmp1/tmp2;

  rad =atan(deg);

  deg=to_deg(rad);
  printf("%Lf\n", deg );
}else{
  tmp1=b*b*a;
  tmp2=2.0*x;
  deg=tmp1/tmp2;

  rad =atan(deg);

  deg=to_deg(rad);
  printf("%Lf\n", deg );
}

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>

int main(void){
    int i, N, V, j, k;
    int *In;
    
    scanf("%d",&N);
    In = (int*)malloc(sizeof(int)*N);
      for(k=0 ; k<N ; k++){
            scanf("%d",&In[k]);
        }
  printf("%d",In[0]);
             for(k=1 ; k<N ; k++){
            printf(" %d",In[k]);
        }
        printf("\n");
  
    
    for(i=1 ; i<N ; i++){
        V=In[i];
        j=i-1;
        while(j>=0 && In[j]>V){
            In[j+1] = In[j];
            j--;
            In[j+1]=V;
        }
        printf("%d",In[0]);
        for(k=1 ; k<N ; k++){
            printf(" %d",In[k]);
        }
        printf("\n");
    }
    
    return 0;
}


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

int main() {
	long long N; cin >> N;
	vector<long long> A(5);
	long long mi = 1LL << 60;
	for (int i = 0; i < 5; i++)
	{
		cin >> A[i];
		mi = min(mi, A[i]);
	}
	cout << (N + mi - 1) / mi + 4 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  
  int i;
  

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
 
  int n, i, j;
  int A[N+1];
  int key;
  
 scanf("%d", &n);
 
 for ( i = 1; i <= n; i++ )
   scanf("%d", &A[i]);
 
 for ( i = 1; i <= n; i++ ){
   key = A[i];
   j = i - 1;
   
   while(j > 0 && A[j] > key){
     A[j+1] = A[j];
     j--;
   }
   
   A[j+1] = key;
   trace(A, n);
 }
 
 return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#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 RREP(i,n) for (int i=(n)-1;i>=0;i--)
 
 
ll n,l,t;
ll x[100001],w[100001],afx[100001],change[100001];
 
int main(void){
    scanf("%lld%lld%lld",&n,&l,&t);
 
    REP(i,n){
        scanf("%lld%lld",&x[i],&w[i]);
    }
 
    REP(i,n){
        ll a;
        if(w[i] == 1)
            a = 1;
        else
            a = -1;
        afx[i] = (x[i] + t * a) % l;
        if(afx[i] < 0)
            afx[i] += l;
    }
    
    FOR(i,1,n){
        if(w[0] == w[i]){
            change[i] = 0;
        }else{
            ll d = t * 2;
            
            ll b,c;
            
            if(w[0] == 1){
                b = x[0];c = x[i];
            }else{
                b = x[i];c = x[0];
            }
            change[i] = 0;
            if(c >= b){
                 d -= c - b;
            }else{
                d -= l - b +c;
            }
            if(d >= 0)
            change[i]++;
            else
                d = 0;
            change[i] += d / l;
        }
    }
    
    ll sum = 0;
    
    FOR(i,1,n){
        sum += change[i];
    }
    sum %= n;
    if(w[0] == 2)
        sum = (n - sum) % n;
        
    ll rem = afx[0];
    
    sort(afx,afx + n);
    
    ll start;
    afx[n] = -1000;
    REP(i,n){
        if(afx[i] == rem && afx[(i + 1) % n] != rem){
            start = i;
            break;
        }
        else if(afx[i] == rem && afx[(i + 1) % n] == rem){
            if(w[0] == 1)
                start = i  + 1;
            else
                start = i;
            break;
        }
    }
    
    start = (n + start - sum) % n;
    
    REP(i,n){
        printf("%lld\n",afx[start++]);
        if(start == n)
            start = 0;
    }
    
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, 0);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v.at(a - 1)++;
    v.at(b - 1)++;
  }
  for (int i = 0; i < n; i++) {
    cout << v.at(i) << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int s = scan.nextInt();
		int w = scan.nextInt();
		
		if (w >= s) {
			System.out.println("unsafe");
		} else {
			System.out.println("safe");
		}
	}
}


Measured memory_bytes: 35728
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x,a,c;
    cin>>x>>a>>c;
    vector<int> v;
    v = {x,a,c};
    sort(v.begin(), v.end());
    cout<<v[0]+v[1]<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = 1;
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int[] x = new int[n];
			int[] y = new int[n];
			for(int i = 0; i < n; i++) {
				x[i] = sc.nextInt();
				y[i] = sc.nextInt();
			}
			double sum = 0;
			for(int i = 0; i < n; i++) {
				if(i == n-1) {
					sum += (x[i] - x[0])*(y[i] + y[0]);
				}
				else {
					sum += (x[i] - x[i+1])*(y[i] + y[i+1]);
				}
			}
			sum /= 2.0;
			sum = Math.abs(sum);
			
			System.out.println((count++) + " " + sum);
			
		}
	}
}

Measured memory_bytes: 21168
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;

const LL INF=1<<30;
const LL MOD=1000000007;





int main(){
    string n;
    cin>>n;
    if(n[0]=='9'||n[1]=='9')cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int n;
string s;
vector<char>be,en;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>s;
	int op=0;
	for(int i=0;i<n;i++){
		if(s[i]==')'&& op<=0)be.push_back('(');
		if(s[i]==')' && op>0)op--;
		if(s[i]=='(')op++;
	}
	for(int i=0;i<be.size();i++){
		cout<<be[i];
	}
	cout<<s;
	for(int i=op;i>0;i--){
		cout<<')';
	}
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<ll> a(n+1);
    rep1(i,n) cin>>a[i];
    ll sum[n+1],dp[n+1];
    rep(i,n+1){
        sum[i]=0;
        dp[i]=0;
    }
    
    sum[1]=a[1];
    for(int i=3;i<=n;i+=2) sum[i]=sum[i-2]+a[i];
    for(int i=2;i<=n;i++){
        if(i%2==1) dp[i]=max(dp[i-1],dp[i-2]+a[i]);
        else dp[i]=max(sum[i-1],dp[i-2]+a[i]);
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 8008
#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
	cin >> s;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'B') {
			if(t.size()) t.pop_back();
		}
		else {
			t += s[i];
		}
	}
	cout << t << endl;
}

Measured memory_bytes: 256
# input
num = int(input())

# calculate order
order = 0
for i in range(5):
    if 0 < num // 10**i <= 9:
        order = i

# loops
s = []
for j in range(1, num+1):
    if j % 3 == 0 or '3' in str(j):
        s.append(j)

print(' ', end='')
print(*s)


Measured memory_bytes: 6136
n = int(input())
r = list(map(int,input().split(" ")))
ar = {i: 0 for i in range(1,10 ** 5 + 1)}
s = sum(r)
for a in r:
    ar[a] += 1
q = int(input())
for i in range(q):
    x,y = map(int,input().split(" "))
    s += (y - x) * ar[x]
    ar[y] += ar[x]
    ar[x] = 0
    print(s)

Measured memory_bytes: 24280
s=input()
for i in range(int(input())):
    t=input().split()
    opr=t[0];a=int(t[1]);b=int(t[2])
    if t[0]=='print':
        print(s[a:b+1])
    elif t[0]=='reverse':
        s=s[:a]+''.join(list(reversed(s[a:b+1])))+s[b+1:]
    elif t[0]=='replace':
        p=t[3]
        s=s[:a]+p+s[b+1:]


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vc = vector<char>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

ll mod = 1000000007;

int main(){
    ll K; cin >> K;
    ll m = K % 50;
    ll n = K/50;
    ll p = 49 + n;
    p -= m;
    cout << 50 << endl;
    for(int i=0; i<50; i++){
        if(i < 50-m){
            cout << p << " ";
        }
        else{
            cout << p + 51 << " ";
        }
    }
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
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; }

    long a, b, x;

long int func(long n){
    if(n == -1) return 0;
    else{
        long tmp = n/x+1;
        return tmp;
    }
    
}

int main(){

    cin >> a >> b >> x;
    long num;
    num = func(b) - func(a-1);
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int next(int now,int num){
  switch(now){
  case 0:
    return num ? 4 : 3;
  case 1:
    return num ? 3 : 4;
  case 2:
    return num ? 4 : 1;
  case 3:
    return num ? 5 : -1;
  case 4:
    return num ? -1 : 3;
  case 5:
    return num ? 1 : 2;
  }
  return -1;
}

int main(){
  string str;

  while(cin >> str ,str != "#"){
    int now = 0; 
    for(int i = 0 ; i < (int)str.size() ; i++){
      now = next(now,str[i]-'0');
      if(now == -1) break;
    }

    if(now == 1){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1180
import java.util.*;

public class Main{

	public static void main(String args[]){

      Scanner in =new Scanner (System.in);
      int a,b,k;
      a=in.nextInt();
      b=in.nextInt();
      k=in.nextInt();

      for(int i=a;i<=Math.min(b,a+k-1);i++){
      	System.out.println(i);
      }


      for(int i=Math.max(b-k+1,a+k);i<=b;i++){
        System.out.println(i);}

	}
}

Measured memory_bytes: 23764