akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),m=sc.nextInt();
        int[] deg = new int[n+1];
        int[] ans = new int[n+1];
        ArrayList<Integer>[] graph = new ArrayList[n+1];
        for(int i=0;i<=n;i++) graph[i]=new ArrayList<>();
        for(int i=0;i<n-1+m;i++){
            int u = sc.nextInt();
            int v = sc.nextInt();
            deg[v]++;
            graph[u].add(v);
        }
        int root = 0;
        for(int i=1;i<=n;i++){
            if(deg[i]==0) root = i;
        }
        LinkedList<Integer> que = new LinkedList<>();
        que.add(root);
        while(que.size()>0){
            int cur = que.poll();
            for(int w:graph[cur]){
                deg[w]--;
                if(deg[w]==0){
                    ans[w] = cur;
                    que.add(w);
                }
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=1;i<=n;i++){
            out.println(ans[i]);
        }
        out.flush();
    }

}


Measured memory_bytes: 102460
def solve(string):
    s = string.replace("?", "d").lower()
    n = len(s)
    dp = [[0] * (n + 1) for _ in range(4)]
    dp[0][0] = 1
    mod = 10**9 + 7
    for i, _s in enumerate(s):
        dp[0][i + 1] = dp[0][i] % mod
        dp[1][i + 1] = dp[1][i] % mod
        dp[2][i + 1] = dp[2][i] % mod
        dp[3][i + 1] = dp[3][i] % mod
        if _s == "a":
            dp[1][i + 1] += dp[0][i]
        if _s == "b":
            dp[2][i + 1] += dp[1][i]
        if _s == "c":
            dp[3][i + 1] += dp[2][i]
        if _s == "d":
            dp[0][i + 1] *= 3
            dp[1][i + 1] *= 3
            dp[1][i + 1] += dp[0][i]
            dp[2][i + 1] *= 3
            dp[2][i + 1] += dp[1][i]
            dp[3][i + 1] *= 3
            dp[3][i + 1] += dp[2][i]
    return str(int(dp[3][-1] % (10**9 + 7)))


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 21320
import kotlin.comparisons.*
import java.util.*

const val MOD = 1000000007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun ceil(x: Double) = Math.ceil(x)
fun log2(x: Double) = Math.log(x) / 0.6931471805599453

fun main(args: Array<String>) {
  val (n, k) = readIs()
  val kf = k.toDouble()
  var ans = 0.0
  for (m in 1..n) {
    if (k <= m) {
      ans += 1
      continue
    }
    val x = ceil(log2(kf / m))
    ans += Math.pow(0.5, x)
  }
  println("%.13f".format(ans / n))
}


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

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

	if(X >= 30)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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


using namespace std;

typedef long long ll;
#define SWAP(x,y,z) {if ( y > z ) swap(y,z); if ( x > y ) swap(x,y); if (y > z) swap(y,z);}

double const eps = 1e-10;
ll const modulo = 1e9+7;

int a[100100];


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

    char a,b;
    cin >> a >> b;
    if ( a == 'H' && b == 'H' ) cout << 'H';
    else if ( a == 'H' && b == 'D' ) cout << 'D';
    else if ( a == 'D' && b == 'H' ) cout << 'D';
    else cout << 'H';


    return 0;

    // 274751WM
}


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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

bool evenString(string s) {
  string s1 = s;
  string s2 = s;
  int n = s.size();
  if (n % 2 != 0) {
    return 0;
  } else {
    s1.erase(n / 2);
    s2.erase(0, n / 2);
    debug2(s1, s2);
    if (s1 == s2) {
      return 1;
    } else {
      return 0;
    }
  }
}

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

  string s;
  cin >> s;

  int n = s.size();

  for (int i = n - 1; i > 0; i--) {
    s = s.erase(i);

    if (evenString(s)) {
      debug(s);
      cout << s.size() << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define MAX 201

int search_table1( char c );
char * search_table2( char * inmstr, int strsize );
void initary( char * p, int size );

char * table1[32][2] = {
	{"00000", "A"},
	{"00001", "B"},
	{"00010", "C"},
	{"00011", "D"},
	{"00100", "E"},
	{"00101", "F"},
	{"00110", "G"},
	{"00111", "H"},
	{"01000", "I"},
	{"01001", "J"},
	{"01010", "K"},
	{"01011", "L"},
	{"01100", "M"},
	{"01101", "N"},
	{"01110", "O"},
	{"01111", "P"},
	{"10000", "Q"},
	{"10001", "R"},
	{"10010", "S"},
	{"10011", "T"},
	{"10100", "U"},
	{"10101", "V"},
	{"10110", "W"},
	{"10111", "X"},
	{"11000", "Y"},
	{"11001", "Z"},
	{"11010", " "},
	{"11011", "."},
	{"11100", ","},
	{"11101", "-"},
	{"11110", "'"},
	{"11111", "?"}
};

char * table2[32][2] = {
	{"101"     ," "},
	{"000000"  ,"'"},
	{"000011"  ,","},
	{"10010001","-"},
	{"010001"  ,"."},
	{"000001"  ,"?"},
	{"100101"  ,"A"},
	{"10011010","B"},
	{"0101"    ,"C"},
	{"0001"    ,"D"},
	{"110"     ,"E"},
	{"01001"   ,"F"},
	{"10011011","G"},
	{"010000"  ,"H"},
	{"0111"    ,"I"},
	{"10011000","J"},
	{"0110"    ,"K"},
	{"00100"   ,"L"},
	{"10011001","M"},
	{"10011110","N"},
	{"00101"   ,"O"},
	{"111"     ,"P"},
	{"10011111","Q"},
	{"1000"    ,"R"},
	{"00110"   ,"S"},
	{"00111"   ,"T"},
	{"10011100","U"},
	{"10011101","V"},
	{"000010"  ,"W"},
	{"10010010","X"},
	{"10010011","Y"},
	{"10010000","Z"}
};

int search_table1( char c )
{
	for ( int i = 0 ; i < 32 ; i++ ) {
		if ( c == table1[i][1][0] ) {
			return i;
		}
	}
	return 32;
}

char * search_table2( char * inmstr, int strsize )
{
	int i = 0, j = 0, k = 0;
	char p[9] = { 0 };

	while ( 1 ) {
		for ( i = 0 ; i < 32 ; i++ ) {
			if ( strncmp( &inmstr[k], table2[i][0], strlen( table2[i][0] ) ) == 0 ) {
				printf( "%s", table2[i][1] );
				k += strlen( table2[i][0] );
				break;
			}
		}

		if ( i == 32 ) {
			break;
		}
	}
	return 0;
}

void initary( char * p, int size )
{
	int i = 0;
	for ( i = 0 ; i < size  ; i++ ) {
		*(p+i) = 0;
	}
}

int main()
{
	char str[MAX], *p;
	char inmstr[MAX*5+9] = { 0 };
	int i = 0, pos = 0;

	while ( fgets( str, MAX, stdin ) != NULL ) {
		initary( inmstr, MAX*5 );
		for ( i = 0 ; i < strlen( str )-1 ; i++ ) {
			pos = search_table1( str[i] );	
			strcat( inmstr, table1[pos][0] ); // 文字列を追加していく
		}
		search_table2( inmstr, strlen( inmstr ) );
		printf( "\n" );
	}
	return 0;
}



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

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

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

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

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

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

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

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

fn main() {
    let modd = 10usize.pow(9) + 7;
    let n = 13;
    let mut dp = vec![0; n];
    dp[0] = 1;

    input! {
        s: chars,
    }

    let mut mul = 1;
    for i in (0..s.len()).rev() {
        let mut next_dp = vec![0; n];
        let c = s[i];
        if c == '?' {
            for k in 0..10 {
                for j in 0..n {
                    next_dp[(k * mul + j) % n] += dp[j];
                    next_dp[(k * mul + j) % n] %= modd;
                }
            }
        } else {
            let k = s[i].to_digit(10).unwrap() as usize;
            for j in 0..n {
                next_dp[(k * mul + j) % n] += dp[j];
                next_dp[(k * mul + j) % n] %= modd;
            }
        }
        mul *= 10;
        mul %= n;
        dp = next_dp;
    }
    println!("{}", dp[5]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    pair<int, int> a[M];
    for(int i=0; i<M; i++){
        cin >> a[i].first >> a[i].second;
        a[i].first--; a[i].second--; 
    }
    sort(a, a + M);
    priority_queue<int, vector<int>, greater<int> > q;
    int ans = 0;
    int cnt = 0;
    for(int i=0; i<N; i++){
        if(!q.empty() && i == q.top()){
            ans ++;
            while(!q.empty()){
                q.pop();
            }
        }
        while(i == a[cnt].first && cnt < M) {
            q.push(a[cnt].second);
            cnt ++;
        }
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
using namespace std;

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    set<int> sqmod;
    for(int i = 1; i < N; ++i)
      sqmod.insert((i*i)%N);
    // sort(begin(sqmod), end(sqmod));
    // sqmod.erase(unique(begin(sqmod), end(sqmod)), end(sqmod));
    vector<int> cnt((N - 1) / 2 + 1, 0);
    for(int i : sqmod) {
      for(int j : sqmod) {
        if(i == j) continue;
        int diff = i - j;
        if(diff < 0) diff += N;
        if(diff > (N - 1)/2) diff = N - diff;
        cnt[diff]++;
      }
    }
    for(int i = 1; i < (int)cnt.size(); ++i) {
      cout << cnt[i] << endl;
    }
  }
}

Measured memory_bytes: 1452
// Atcoder beginner round 175 C - Walking Takahashi

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

void solve() {
    ll X, K ,D; 
    cin >> X >> K >> D;
    X = abs(X);
    if (X / D >= K)
        cout << X - K*D;
    else {
        K = K - X/D;
        X = X - (X /D) * D;
        if (K % 2 == 0) 
            cout << X;
        else 
            cout << abs(X - D);
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3156
#include <stdio.h>

int main(){
	int N,K;
	int need;
	double ans;
	int i,j;
	
	scanf("%d %d",&N,&K);
	
	double prob[N];
	
	for(i=1; i<=N; i++){
		need=0;
		j=i;
		while(j<K){
			j*=2;
			need++;
		}
		
		prob[i-1]=(double)N;
		for(j=0; j<need; j++){
			prob[i-1]*=2.0;
		}
		
		prob[i-1]=1.0/prob[i-1];
	}
	
	ans=0;
	for(i=0; i<N; i++){
		ans+=prob[i];
	}
	
	printf("%.12lf\n",ans);
	
	return 0;
}

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

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

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> sm(n, 0);
    const ll mod = 1000000007;
    sm[0] = a[0];
    rep1(i, n) sm[i] = (sm[i-1] + a[i]) % mod;

    ll res = 0;
    rep1(i, n){
        res = (res + a[i]*sm[i-1]) % mod;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 6328
type dice = { one : int; two : int; three : int;
              four : int; five : int; six : int}

let right_side {one=a;two=b;three=c;four=d;five=e;six=f} t_f =
  let find l = List.fold_left (fun acc p -> acc || p=t_f) false l in
  if find [b,c;c,e;d,b;e,d] then a
  else if find [a,d;c,a;d,f;f,c] then b
  else if find [a,b;b,f;e,a;f,e] then c
  else if find [a,e;b,a;e,f;f,b] then d
  else if find [a,c;c,f;d,a;f,d] then e
  else f

let () =
  let dice = Scanf.sscanf (read_line ()) "%d %d %d %d %d %d"
      (fun a b c d e f -> {one=a;two=b;three=c;four=d;five=e;six=f}) in
  let n = read_int () in
  let rec loop = function
      0 -> ()
    | i -> Scanf.sscanf (read_line ()) "%d %d" (fun a b -> a,b)
           |> right_side dice
           |> Printf.printf "%d\n";
      loop (i-1)
  in loop n

Measured memory_bytes: 2388
#
# abc049 b
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 2
*.
.*"""
        output = """*.
*.
.*
.*"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1 4
***."""
        output = """***.
***."""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """9 20
.....***....***.....
....*...*..*...*....
...*.....**.....*...
...*.....*......*...
....*.....*....*....
.....**..*...**.....
.......*..*.*.......
........**.*........
.........**........."""
        output = """.....***....***.....
.....***....***.....
....*...*..*...*....
....*...*..*...*....
...*.....**.....*...
...*.....**.....*...
...*.....*......*...
...*.....*......*...
....*.....*....*....
....*.....*....*....
.....**..*...**.....
.....**..*...**.....
.......*..*.*.......
.......*..*.*.......
........**.*........
........**.*........
.........**.........
.........**........."""
        self.assertIO(input, output)


def resolve():
    H, W = map(int, input().split())
    ans = []
    for i in range(H):
        S = input()
        ans.append(S)
        ans.append(S)

    for i in range(2*H):
        print(ans[i])


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16244
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
using i64 = int64_t;
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> ab;
    for(int i = 1; i <= M; i++) {
        int a, b;
        cin >> a >> b;
        ab.emplace_back(a, i);
        ab.emplace_back(b, -i);
    }
    sort(WHOLE(ab));
    set<int> s;
    int ans = 0;
    for(auto i : ab) {
        if(i.second < 0) {
            if(s.count(-i.second)) {
                s.clear();
                ans++;
            }
        } else {
            s.insert(i.second);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3312
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	static long  MOD = 1000000007;

	public static void main(String[] args)
	{
		FastReader scan=new FastReader();
		int n=scan.nextInt();

		long ar[]=new long[n];
		for(int i=0;i<n;i++)
			ar[i]=scan.nextLong();

		long dp[][]=new long[n][n];
		long cummSum[]=new long[n];
		long s=0;

		for(int i=0;i<n;i++)
		{
			s+=ar[i];
			cummSum[i]=s;
		}

		for(int l=0;l<n;l++)
		{
			for(int i=0;i<(n-l);i++)
			{
				int j=i+l;
				if(i==j)
				{
					continue;
				}
				long sum=cummSum[j]-((i==0)? 0: cummSum[i-1]);
				long min=Long.MAX_VALUE;
				for(int k=i;k<j;k++)
				{
					min=Math.min(min, dp[i][k]+dp[k+1][j]+sum);
				}
				dp[i][j]=min;
			}
		}

		System.out.println(dp[0][n-1]);
	}
}


 class FastReader
{
    BufferedReader br;
    StringTokenizer st;
 
    public FastReader()
    {
        br = new BufferedReader(new
                InputStreamReader(System.in));
    }
 
    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            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());
    }
 
    double nextDouble()
    {
        return Double.parseDouble(next());
    }
 
    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


Measured memory_bytes: 23876
#include <stdio.h>
#include <stdlib.h>
#define N 1000000
int count=0,n,m,C[N],*Q;

void insertionSort(int C[], int n, int e){
  int i,j,v;
  for(i=e;i<n;i++){
    v=C[i];
    j=i-e;
    while(j>=0&&C[j]>v){
      C[j+e]=C[j];
      j-=e;
      count++;
    }
    C[j+e]=v;
  }
}

void shellSort(int C[],int n){
  int i=0,k;

  Q=(int *)malloc(n * sizeof(int));
  for(k=1; ; ){
    if(k>n)
      break;
      Q[i]=k;
      i++;
      k=3*k+1;
    }
    m=i;
    for(i=m-1;i>=0;i--){
      insertionSort(C,n,Q[i]);
    }
  }

  int main(){
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d",&C[i]);
      count=0;
    }
    
    shellSort(C,n);

    printf("%d\n",m);

    for(i=m-1;i>=0;i--){
      printf("%d",Q[i]);
      if(i){
	printf(" ");
      }
    }
    printf("\n");
    printf("%d\n",count);
    for(i=0;i<n;i++){
      printf("%d\n",C[i]);
    }

      free(Q);
      return 0;
    }
      



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

int N;

void dfs(string s, char mx){
  if(s.length() == N){
    printf("%s\n", s.c_str());
  }
  else{
    for(char c='a';c<=mx;c++){
      dfs(s+c, ((c==mx) ? (char)(mx+1) : mx));
    }
  }
}

int main() {
  cin >> N;
  dfs("", 'a');
  return 0;
 
}

Measured memory_bytes: 1536
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#define inf 1000000002
using namespace std;
 
int main()
{
  int ma,mi,N;
  vector<string> S;
  string s;
  while(1){
    cin>>N;
    if(N==0)break;
    S.clear();
    S.push_back("1000000002");
    for(int i=0;i<N;i++){
      cin>>s;
      S.push_back(s);
    }
 
    ma=inf;mi=(-1)*inf;
    for(int i=1;i<N+1;i++){
      if(S[i]=="x"){
        if(S[i-1]=="x"){
      ma=(-1)*inf;mi=inf;
      break;
      }
    if(i%2==0){
      mi=max(mi,atoi(S[i-1].c_str())+1);
    }
    if(i%2==1){
      ma=min(ma,atoi(S[i-1].c_str())-1);
    }
      }
      else {
    if(S[i-1]=="x"){
      if(i%2==0){
        ma=min(ma,atoi(S[i].c_str())-1);
      }
      if(i%2==1){
        mi=max(mi,atoi(S[i].c_str())+1);
      }
    }
    else {
      if(i%2==0){
            if(atoi(S[i].c_str())<atoi(S[i-1].c_str())){
          ma=(-1)*inf;mi=inf;
          break;
        }
      }
      if(i%2==1){
        if(atoi(S[i].c_str())>atoi(S[i-1].c_str())){
          ma=(-1)*inf;mi=inf;
          break;
        }
      }
    }
      }
    }
    if(ma==mi)cout<<ma<<endl;
    else if(ma<mi)cout<<"none"<<endl;
    else cout<<"ambiguous"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3240
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    _ = input()
    A = [int(e) for e in input().split()]
    A.sort(reverse=True)
    sum_a = 0
    sum_b = 0
    for i, e in enumerate(A):
        if i % 2 == 0:
            sum_a += e
        else:
            sum_b += e
    print(sum_a - sum_b)

main()


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


Measured memory_bytes: 4800
import std.stdio;
import std.conv;
import std.string;
import std.math;
import std.algorithm;

void main() {
    uint n, k;

    readf(" %s %s\n", &n, &k);
    long[] x = readln.chomp.split.to!(long[]);

    ulong ans = ulong.max;
    foreach(l; 0..n - k + 1) {
        uint r = l + k - 1;
        auto d = x[r] - x[l];
        auto a = min(abs(x[r]) + d, abs(x[l]) + d);
        ans = min(ans, a);
    }

    ans.writeln;
}


Measured memory_bytes: 4372
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
    tmp = 0
    if a[i] == b[i]:
        tmp += 1
    if a[i] == c[i]:
        tmp += 1
    if b[i] == c[i]:
        tmp += 1
    if tmp == 1:
        ans += 1
    elif tmp == 0:
        ans += 2
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define INF 10000000000000009
#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl



signed main(){
    int N;
    cin >> N;
    int r[4]={0,3,5,7};
    int Ans=0;
    for(int j=0;j<(1<<(20));j++){
        bool b[4]={};
        int c=0;
        int F=0;
        REP(i,10){
            c=0;
            F*=10;
            if((j>>(2*i))%2==1){
                c+=1;
            }
            if((j>>(2*i+1))%2==1){
                c+=2;
            }
            b[c]=1;
            F+=r[c];
            if(F==0)b[0]=0;
        }
        if(F<=N&&b[0]==0&&b[1]==1&&b[2]==1&&b[3]==1){Ans++;}
    }
    cout << Ans << endl;
    return 0;
}   


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

using ll = long long;

template<class H, class T> H maximum(H head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

template<class H> void print(H head) {std::cout << head << std::endl;}

int main()
{
  ll A;
  std::string s;
  std::cin >> A >> s;

  if (A < 3200) s = "red";
  print(s);

  return 0;
}


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

sortedX = X[:]
sortedX.sort()
lenX = len(X)

for i in X:
    if i > sortedX[int(lenX/2) - 1]:
        print(sortedX[int(lenX/2)-1])
    else:
        print(sortedX[int(lenX/2)])


Measured memory_bytes: 25556
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var h = ReadLongs();

            var dp = new long[N];
            for (int i = 0; i < N; i++)
            {
                if (i == 0) continue;
                if (i == 1)
                {
                    dp[1] = dp[0] + Math.Abs(h[1] - h[0]);
                    continue;
                }

                dp[i] = Math.Min(
                    dp[i - 1] + Math.Abs(h[i] - h[i - 1]),
                    dp[i - 2] + Math.Abs(h[i] - h[i - 2]));
            }

            return dp[N - 1];
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 36236
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
//		
//		ArrayList<String> ans = new ArrayList<String>();
//		
//		int n = Integer.parseInt(br.readLine());
//		for (int i = 0; i < n; i++) {
//			BigInteger a = new BigInteger(br.readLine());
//			BigInteger b = new BigInteger(br.readLine());
//			if (a.toString().length() > 80 || b.toString().length() > 80 || a.add(b).toString().length() > 80) {
//				ans.add("overflow");
//				continue;
//			}
//			ans.add(a.add(b).toString());
//		}
//		
//		for (String a : ans)
//			System.out.println(a);
		int a = Integer.parseInt(br.readLine());
		long sum = 1;
		for (int i = 1; i <= a; i++) {
			sum *= i;
		}
		System.out.println(sum);
		
	}
	
}

Measured memory_bytes: 8912
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int coun[105][105][105];
vector<int>x,y,z;
int rx[52][2], ry[52][2], rz[52][2];
int n,m;

int compress1(int x1[52], int x2[52]){
	for(int i = 0;i < n;i++){
		x.push_back(x1[i]);
		x.push_back(x2[i]);
	}
	sort(x.begin(), x.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	for(int i = 0;i < n;i++){
		rx[i][0] = find(x.begin(),x.end(),x1[i])-x.begin();
		rx[i][1] = find(x.begin(),x.end(),x2[i])-x.begin();
	}
	return x.size();
}

int compress2(int x1[52], int x2[52]){
	for(int i = 0;i < n;i++){
		y.push_back(x1[i]);
		y.push_back(x2[i]);
	}
	sort(y.begin(), y.end());
	y.erase(unique(y.begin(), y.end()), y.end());
	for(int i = 0;i < n;i++){
		ry[i][0] = find(y.begin(),y.end(),x1[i])-y.begin();
		ry[i][1] = find(y.begin(),y.end(),x2[i])-y.begin();
	}
	return y.size();
}

int compress3(int x1[52], int x2[52]){
	for(int i = 0;i < n;i++){
		z.push_back(x1[i]);
		z.push_back(x2[i]);
	}
	sort(z.begin(), z.end());
	z.erase(unique(z.begin(), z.end()), z.end());
	for(int i = 0;i < n;i++){
		rz[i][0] = find(z.begin(),z.end(),x1[i])-z.begin();
		rz[i][1] = find(z.begin(),z.end(),x2[i])-z.begin();
	}
	return z.size();
}

void paint(){
	for(int i = 0;i < n;i++){
	for(int tx=rx[i][0];tx<rx[i][1];tx++)
    {
      for(int ty=ry[i][0];ty<ry[i][1];ty++)
        {
          for(int tz=rz[i][0];tz<rz[i][1];tz++)
        {
          coun[tx][ty][tz]++;
        }
        }
    }
	}
}

int main()
{
	int a[52],b[52],c[52],d[52],e[52],f[52];
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d %d %d %d %d %d",&a[i],&b[i],&c[i],&d[i],&e[i],&f[i]);
	}
	int w = compress1(a, d);
	int h = compress2(b, e);
	int p = compress3(c, f);
	paint();
	
  long long ans=0;
  for(int i=0;i<=w;i++)
    {
      for(int j=0;j<=h;j++)
    {
      for(int k=0;k<=p;k++)
        {
          if(coun[i][j][k]>=m)
        {
          long long s1=(x[i+1]-x[i]),s2=(y[j+1]-y[j]),s3=(z[k+1]-z[k]);
          ans+=s1*s2*s3;
        }
        }
    }
    }
	//long long ans = 0;
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int judge = 1;
  int N = S.length();
 
  string S1 = S.substr(0, (N-1)/2);
  string S2 = S.substr((N+3)/2-1, (N-3)/2+1);

  for(int i=0; i<S1.length()/2; i++) {
    if(S1[i]!=S1[S1.length()-i-1]) {
      judge = 0;
      break;
    }
  }
  
  if(judge==1) {
    for(int i=0; i<S2.length()/2; i++) {
      if(S2[i]!=S2[S2.length()-i-1]) {
        judge = 0;
        break;
      }
    }
  }
  
  if(judge==1) {
    for(int i=0; i<S.length()/2; i++) {
      if(S[i]!=S[S.length()-i-1]) {
        judge = 0;
        break;
      }
    }
  }
  
  cout << ((judge==1) ? "Yes" : "No") << endl;
  return 0;
}

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

using namespace std;

int main()
{
	int numa[4];
	int numb[4];
	int a, i, j;
	int hit, blow;
	

	while(cin >> numa[0] >> numa[1] >> numa[2] >> numa[3] >> numb[0] >> numb[1] >> numb[2] >> numb[3] )
	{	
		hit = 0;
		blow = 0;
		
		for(i = 0; i < 4; i++)
		{
			if(numa[i] == numb[i])
			{
				hit = hit + 1;
			}
				for(j = 0; j < 4; j++)
				{
					if(numa[i] == numb[j] && i != j)
					{
						blow = blow + 1;
					}		
				}
		}
		cout << hit << " " << blow << endl;
	}
		
	return 0;
		
}

Measured memory_bytes: 1156
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

int main() {
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    vector<ll> cnt(N, 0);
    rep(i, N) {
        while (a[i] % 2 == 0) {
            cnt[i]++;
            a[i] /= 2;
        }
    }

    ll cnt_zero = 0;
    ll cnt_one = 0;
    ll cnt_two = 0;
    rep(i, N) {
        if (cnt[i] == 0)
            cnt_zero++;
        else if (cnt[i] == 1)
            cnt_one++;
        else if (cnt[i] >= 2)
            cnt_two++;
    }

    if (cnt_one >= 1) {
        if (cnt_two >= cnt_zero)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    } else {
        if (cnt_two + 1 >= cnt_zero)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 4768
#include<bits/stdc++.h>
#include<string.h>
using namespace std;   
int main(){
    string s;
    cin >> s;
    int sum=0;
    for(int i=0;i<s.size();i++)
        sum+=s[i]-'0';
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k, s;
  cin >> n >> k >> s;
  
  for(int i = 0; i < k; i++){
    cout << s << " ";
  }
  for(int i = 0; i < n - k; i++){
    if(s == 1e9) cout << 1 << " ";
    else cout << 1000000000 << " ";
  }
  cout << '\n';
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	//input
	int N;
	cin >> N;
	vector<int> l(N), r(N);
	int total = 0;
	for (int i = 0; i < N; i++) {
		cin >> l[i] >> r[i];
		total += abs(l[i] - r[i]) + 1;
	}


	cout << total;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;


int main(void){

	while( true ) {
		
		int cnt[2] = {};
		string str;
		cin >> str;
		if( cin.eof() ) break;
		for( int i = 0; i < str.length() - 3; i++ ) {
			if( str[i] == 'J' && str[i+1] == 'O' && str[i+2] == 'I' )
				cnt[0] ++;
			if( str[i] == 'I' && str[i+1] == 'O' && str[i+2] == 'I' )
				cnt[1] ++;
		}
		for( int i = 0; i < 2; i++ )
			cout << cnt[i] << endl;
	}


    return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define E endl
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(9)

int main()
{
	ll n,k;
	cin>>n>>k;
	if(n*500>=k)
	cout<<"Yes";
	else
	cout<<"No";
}
	
	


Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main(void){
    // Your code here!
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    
    for (i = 1; i<=n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    
    head = 1; tail = n + 1;
    
    while ( head != tail ){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if ( u.t > 0) enqueue(u);
        else{
            printf("%s %d\n", u.name, elaps);
        }
    }
    return 0;
}



Measured memory_bytes: 11844
/**
*    created: 01.07.2020 23:43:19
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#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++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const int MOD = 1000000007;
// const int MOD = 998244353;
const long double pi = acos(-1.0);
const int INF = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int tn = 0;
    int xn = 0;
    int yn = 0;
    rep(i,n) {
        int t, x, y;
        cin >> t >> x >> y;
        int d = t - tn - abs(x-xn) - abs(y-yn);
        if (d >= 0 && d % 2 == 0) {
            tn = t;
            xn = x;
            yn = y;
            continue;
        }
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3636
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#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(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

//library

class UFTree {
//private:
public:
	vector<int> par;
	vector<int> rank;
	vector<int> num;

//public:
	UFTree(int n)
	{
		par = vector<int>(n);
		rank = vector<int>(n);
		num = vector<int>(n);
		for(int i = 0; i < n; i++){
			par[i] = i;
			rank[i] = 0;
			num[i] = 1;
		}
	}

	int find(int x)
	{
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			num[y] += num[x];
		}else{
			par[y] = x;
			num[x] += num[y];
			if(rank[x] == rank[y])	rank[x]++;
		}
	}

	int count(int x)
	{
		return num[find(x)];
	}

	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};
//library

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<P> xy(n);
		REP(i,n){
			cin >> xy[i].F >> xy[i].S;
		}
		UFTree uf(n);
		vector<P> xa(n), ya(n);
		REP(i,n){
			xa[i] = {xy[i].F,i};
			ya[i] = {xy[i].S,i};
		}
		sort(ALL(xa)); sort(ALL(ya));
		// xa.erase(unique(ALL(xa)), xa.end());
		// ya.erase(unique(ALL(ya)), ya.end());
		using PP = pair<LL,P>;
		vector<PP> v;
		REP(i,SZ(xa)-1){
			v.emplace_back(xa[i+1].F-xa[i].F,P({xa[i].S, xa[i+1].S}));
		}
		REP(i,SZ(ya)-1){
			v.emplace_back(ya[i+1].F-ya[i].F,P{ya[i].S, ya[i+1].S});
		}
		sort(ALL(v));
		LL ans = 0;
		REP(i,SZ(v)){
			P p;
			LL c;
			tie(c, p) = v[i];
			if(!uf.same(p.F, p.S)){
				uf.unite(p.F, p.S);
				ans += c;
			}
		}
		cout << ans << endl;
		// dpite(ALL(ya)); dpite(ALL(xa));
		// cout << min(abs(xa[0]-xa.back()), abs(ya[0]-ya.back())) << endl;
	}
	return 0;
}


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

int main() {
  int N, M; cin >> N >> M;
  int s[5], c[5]; for (int i = 0; i < M; i++) {cin >> s[i] >> c[i]; s[i]--;}

  for (int i = 0; i <= 999; i++) {
    string x = to_string(i);

    if (x.size() != N) {
      continue;
    }

    bool ok = true;
    for (int j = 0; j < M; j++) {
      if (x[s[j]] != (char)(c[j] + '0')) {
        ok = false;
        break;
      }
    }

    if (ok) {
      cout << x << endl;
      return 0;
    }
  }

  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
class Node
  attr_accessor :parent, :rank

  def initialize
    @parent = -1 # Positive value means its parent,and Negative value means its size.
    @rank = 0
  end
end

class UnionFindTree
  def initialize(n)
    @nodes = (0...n).to_a.map { |i| Node.new }
  end

  def find(x)
    return @nodes[x].parent < 0 ? x : @nodes[x].parent = find(@nodes[x].parent)
  end

  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b

    if @nodes[a].rank < @nodes[b].rank
      @nodes[b].parent += @nodes[a].parent
      @nodes[a].parent = b
    else
      @nodes[a].parent += @nodes[b].parent
      @nodes[b].parent = a
      @nodes[a].rank += 1 if @nodes[a].rank == @nodes[b].rank
    end
  end

  def same?(a, b)
    find(a) == find(b)
  end
  
  def size(a)
    -@nodes[find(a)].parent
  end

  # 確認用。アルゴリズムとは関係無い
  def parents
    @nodes.map(&:parent)
  end
end

N, M = gets.split.map(&:to_i)

class Bridge
  attr_accessor :first, :second

  def initialize
    @first = nil
    @second = nil
  end
  
  def nodes=(a)
    a[0], a[1] = a[1], a[0] if a[0] > a[1]
    @first = a[0]
    @second = a[1]
  end
  
end

bridges = (0...M).to_a.map { Bridge.new }

M.times do |i|
  bridge = gets.split.map(&:to_i)
  bridge.map! { |n| n - 1 }
  bridges[i].nodes = bridge
end
# p bridges

f = Array.new(N, N)
ans = Array.new(M, 0)

inco = N * ( N - 1 ) / 2 # inconvenience

n = N
q = M

uft = UnionFindTree.new(n)

q.times do |i|
  
  j = (M-1)-i
  ans[j] = inco
  
  x, y = bridges[j].first, bridges[j].second
  
  inco -= uft.size(x) * uft.size(y) if !uft.same?(x, y)
  break if inco == 0
  
  uft.unite(x, y)
end

puts ans


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

using namespace std;


int main()
{
  int r, d, x;
  cin >> r >> d >> x;
  int x1[10];

  x1[0] = r*x - d;

  cout << x1[0] << endl;
  for(int i = 1;
      i < 10;
      ++i)
    {
      x1[i] = x1[i - 1]* r - d;
      cout << x1[i] << endl;
    }


  return 0;
}


Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,m;
map<int,int> mp;
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)
	{
		int x;
		geti(x);
		mp[x]++;
	}
	geti(n);
	for(int i=1;i<=n;i++)
	{
		int x;
		geti(x);
		mp[x]--;
		if(mp[x]<0)
		{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	
	return 0;
}


Measured memory_bytes: 9728
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_6-C: Quick Sort

#include <algorithm>
#include <cstring>
#include <iostream>

using uint = unsigned int;

struct Card {
  char suit;
  uint rank;
  uint index; // for stable check
};

std::ostream& operator<<(std::ostream& os, const Card& card)
{
  return os << card.suit << " " << card.rank;
}

std::istream& operator>>(std::istream& is, Card& card)
{
  return is >> card.suit >> card.rank;
}

static void print_cards(const Card cards[], const uint n)
{
  for (auto i = 0u; i < n; ++i) {
    std::cout << cards[i] << std::endl;
  }
}

static bool is_stable(const Card cards[], const uint n)
{
  for (auto i = 0u; i< n-1; ++i) {
    if (cards[i].rank == cards[i+1].rank &&
        cards[i].index > cards[i+1].index) {
      return false;
    }
  }
  return true;
}

static uint partition(Card cards[], uint begin, uint end)
{
  auto last = end-1;
  auto gt = begin;
  for (auto i = begin; i < last; ++i) {
    if (cards[i].rank <= cards[last].rank) {
      std::swap(cards[gt++], cards[i]);
    }
  }
  std::swap(cards[gt], cards[last]);
  return gt;
}

static void quick_sort(Card cards[], uint begin, uint end)
{
  if (end - begin > 1) {
    auto middle = partition(cards, begin, end);
    quick_sort(cards, begin, middle);
    quick_sort(cards, middle+1, end);
  }
}

int main()
{
  uint n;
  std::cin >> n;
  Card cards[n];
  for (uint i = 0; i < n; ++i) {
    cards[i].index = i;
    std::cin >> cards[i];
  }

  quick_sort(cards, 0u, n);

  std::cout << (is_stable(cards, n) ? "Stable" : "Not stable") << std::endl;
  print_cards(cards, n);
}

// eof

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

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

//fill(score, score+202020, 0);
#define NN 202020
vector<pll> G[NN];
ll used[NN];
ll value[NN];

bool dfs(ll node, ll v){
  //cout << node << " " << v << " " << value[node] << endl;
  if (value[node] == INF) value[node] = v;
  else if (value[node] != v) return false;
  
  if (used[node]) return true;
  else used[node] = 1;
  
  for (int i=0;i<G[node].size();i++){
    ll nnode = G[node][i].first;
    ll nvalue = G[node][i].second;
    //cout << node << " " << nnode << endl;
    if (!dfs(nnode, value[node] + nvalue)) return false;
  }
  return true;
}

int main(){
  ll n, m;
  cin >> n >> m;
  ll L, R, D;
  for (int i=0;i<m;i++){
    cin >> L >> R >> D;
    G[R-1].push_back(pll(L-1, D));
    G[L-1].push_back(pll(R-1, -D));
  }

  fill(used, used+NN, 0);
  fill(value, value+NN, INF);
  for (int i=0;i<n;i++){
    if (used[i] == 0){
      value[i] = 0;
      bool ans = dfs(i, 0);
      if (!ans){
        cout << "No" << endl;
        exit(0);
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 21248
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int r; cin >> r;
    Out(3 * r * r);

    return 0;
}


Measured memory_bytes: 256