akhauriyash/Code-Regression huggingface dataset:
using System;

class Program{
    public static void Main(){
        var n=int.Parse(Console.ReadLine());
        var nodes=new int[n, n];
        for (var i=0; i<n; i++) {
            var s=Console.ReadLine().Split(' ');
            var id=int.Parse(s[0]);
            var k=int.Parse(s[1]);
            for (var j=0; j<k; j++) {
                nodes[id-1, int.Parse(s[j+2])-1]=1;
            }
        }

        for (var i=0; i<n; i++) {
            for (var j=0; j<n; j++) {
                Console.Write(nodes[i, j]);
                if (j>=n-1) {
                    Console.WriteLine();
                } else{
                    Console.Write(" ");
                }
            }
        }
    }
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = (1 << 18) + 5;
int n, m, k, maxn, ans[MAXN + 5];

int main() {
	read(m), read(k);
	maxn = (1 << m) - 1, n = 1 << (m + 1);
	if (m == 1) {
		if (k == 0) puts("0 0 1 1");
		else puts("-1");
		return 0;
	}
	if (k > maxn) {
		puts("-1");
		return 0;
	}
	ans[n / 2] = k;
	for (int p = 0, i = 1; i <= maxn; ++i, ++p) {
		if (p == k) ++p;
		ans[i] = ans[n - i] = p;
	}
	ans[n] = k;
	for (int i = 1; i <= n; ++i) {
		write(ans[i]);
		putchar(' ');
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 2816
<?php
// B
fscanf(STDIN, '%d', $s);
$n = 1000000;
$ap = $s;
$c = array_fill(0, $n, false);
$c[$s] = true;
for ($i = 2; $i <= $n; $i++) {
    $a = f($ap);
    if ($c[$a]) break;
    $c[$a] = true;
    $ap = $a;
}
echo $i;

function f($n)
{
    return ($n & 1) ? 3 * $n + 1 : $n / 2;
}

Measured memory_bytes: 37368
#include <iostream>&#65279;
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

struct state{
	int val, move;
	vector<int> prev;
	state(){}
	state(int v, int m):val(v), move(m){}
	bool operator<(const state &r) const{
		if(val != r.val) return val < r.val;
		if(move != r.move) return move < r.move;
		rep(i, prev.size()){
			if(prev[i] != r.prev[i]) return prev[i] < r.prev[i];
		}
		return 1;
	}
};

int v[51][51];
state dp[51][51]; //pos, day
int prv[51][51];

void rec(int pos, int day){
	if(!day) return;
	rec(prv[pos][day], day-1);
	cout << pos+1 << endl;
}

int main(){
	int N, D;
	cin >> N >> D;
	rep(i, N) rep(j, D){
		cin >> v[i][j];
	}

	rep(i, 51) rep(j, 51){
		dp[i][j] = state(1<<29, 1<<29);
	}

	rep(i, 51) dp[i][0] = state(0, 0);

	MEMSET(prv, -1);
	rep(i, D) rep(j, N) rep(k, N){
		state s = dp[k][i];
		if(j != k) s.move++;
		s.val += v[j][i];
		s.prev.push_back(k);
		if(s < dp[j][i+1]){
			dp[j][i+1] = s;
		}
	}

	state ans = state(1<<29, 1<<29);
	int last = -1;
	rep(i, N){
		if(dp[i][D] < ans){
			ans = dp[i][D];
			ans.prev.push_back(i);
		}
	}


	cout << ans.val << ' ' << ans.move << endl;
	FOR(i, 1, ans.prev.size()){
		cout << ans.prev[i]+1 << endl;
	}

	return 0;
}

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

string a = "aiueo";

int main() {
    char b;
    cin >> b;
    bool flag = false;
    for(int i=0; i<5; i++){
      if(b == a[i]) flag = true;
    }
    
    if(flag) cout << "vowel" <<endl;
    else cout << "consonant" <<endl;
}

Measured memory_bytes: 256
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}
use input::*;
use std::cmp;

fn main() {
    let n: usize;
    let mut sum = 0;
    let mut ans1 = 0;
    let mut ans2 = 0;
    let mut flag = true;
    input!(n);
    let s = input_vector::<isize>();
    for z in s.iter() {
        sum += *z;
        if flag {
            if sum <= 0 {
                ans1 += -1 * sum + 1;
                sum = 1;
            }
            flag = false;
        } else {
            if sum >= 0 {
                ans1 += sum + 1;
                sum = -1;
            }
            flag = true;
        }
    }

    flag = false;
    sum = 0;
    for z in s {
        sum += z;
        if flag {
            if sum <= 0 {
                ans2 += -1 * sum + 1;
                sum = 1;
            }
            flag = false;
        } else {
            if sum >= 0 {
                ans2 += sum + 1;
                sum = -1;
            }
            flag = true;
        }
    }
    p(cmp::min(ans1, ans2));
}

Measured memory_bytes: 8444
n, h = gets.chomp.split.map(&:to_i)

a = Array.new(n)
b = Array.new(n)
n.times do |i|
  aa, bb = gets.chomp.split.map(&:to_i)
  a[i] = aa
  b[i] = bb
end

amax = a.max

b.sort!
b.reverse!

ans = 0
b.each do |e|
  break if e <= amax
  ans += 1
  h -= e
  if h <= 0
    h=0
    break
  end
end

puts ans + (1.0*h/amax).ceil

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

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

	int n, c; 
	cin >> n >> c;
	c /= 1000;
	for (int xx = 0; xx <= n; ++xx) {
		for (int yy = 0; yy <= n - xx; ++yy) {
			if (c == xx * 10 + yy * 5 + (n - xx - yy)) {
				cout << xx << " " << yy << " " << (n - xx - yy) << "\n";
				return 0;

			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << "\n";
	return 0;
}


Measured memory_bytes: 384
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
    int k,ans = 1;
    cin >> k;
    int mod;
    mod = 7 % k;
    if (mod == 0) {
        cout << ans << endl;
        return 0;
    }
    while (mod != 0) {
        mod = (10 * mod + 7) % k;
        ans++;
        if (ans > k) {
            ans = -1;
            break;
        }
    }

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

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

using namespace std;

int main() {
  int N;

  scanf("%d", &N);

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int x;
    scanf("%d", &x);
    if (x % 2 == 1) cnt++;
  }

  cout << (cnt % 2 == 0 ? "YES" : "NO") << endl;

  return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

template<typename T>
T power(T x, T y) {
    T res = 1;
    for(;0 < y;) {
        if(y%2 == 0) {
            x *= x;
            y /= 2;
        }else{
            res *= x;
            y--;
        }
    }
    return res;
}

LL root5(LL x) {
    bool plus = 0 <= x;
    if(!plus) {
        x *= -1;
    }

    LL left = 0;
    LL right = 2000;
    for(;1 < right - left;) {
        LL mid = (left + right)/2;
        if(power<LL>(mid, 5) <= x) {
            left = mid;
        }else{
            right = mid;
        }
    }
    if(!plus) {
        left *= -1;
    }
    return left;
}

int main() {
    LL X;
    cin >> X;
    LL B = 114514;
    FOR(i, -2000, 2001) {
        LL x = X + power<LL>(i, 5);
        LL rt = root5(x);
        if(power<LL>(rt, 5) == x) {
            B = i;
            break;
        }
    }
    LL A = root5(X + power<LL>(B, 5));
    cout << A << " " << B << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main()
{
  int a = 0;
  int tmp = 0;
  int alice = 0;
  int bob = 0;
  int total = 0;
  int A[100];
//カードの枚数
//  printf("total cards:");
  scanf("%d", &a);
//配列の取得
  for(int i = 0; i < a; i++)
    scanf("%d", &A[i]);

// 取得している配列の確認のための表示
  for(int j = 0; j < a; j++)
//    printf("\n%d\n", A[j]);


//配列の並び替え(大→小)
  for (int i2=0; i2<a; ++i2) {
    for (int j2=i2+1; j2<a; ++j2) {
      if (A[i2] < A[j2]) {
        tmp =  A[i2];
        A[i2] = A[j2];
        A[j2] = tmp;
      }
    }
  }
  // 取得している配列の確認のための表示
   // for(int j = 0; j < a; j++)
     //printf("\n%d\n", A[j]);

//aliceの点数
  for(int l = 0; l < a; l++)
  {
    total += A[l];
    //printf("current_total: %d\n", bob);
  }
  //printf("total: %d\n", total);


//bobの点数
  for(int k = 0; k < (a-a%2)/2 ; k++)
  {
    bob += A[k*2+1];
    //printf("alice: %d\n", alice);
  }
  //printf("alice: %d\n", total-bob);
  //printf("bob: %d\n", bob);

  printf("%d\n", total-bob*2-alice);




}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        String ans = "No";
        for(int a=0;a<=x;a++){
            int b = x-a;
            if(a*2+b*4==y){
                ans="Yes";
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35828
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

int n;
int a[105];

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

    bool f = true;
    for (int i = 0; i < n; i++) {
        if ((a[i] % 2 == 0) && (a[i] % 3 != 0 && a[i] % 5 != 0)) f = false;
    }

    if (f) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;

    return 0;
}


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

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

    vector<double> a(n);
    double total = 0;
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
        a.at(i) = 1 / a.at(i);
        total += a.at(i);
    }

    cout << 1 / total << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  string s;
  int ss = 0;
  cin >> s;
  rep(i , 4){
    if(s[i] == '+') ss++;
    else ss--;
  }
  cout << ss << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));

    LL ans = 0;
    rep(a, n)REP(b, a+1, n){
        // a < b
        // b-a < c < a+b
        int c = b+1;
        int low = upper_bound(all(l), l[b]-l[a]) - l.begin();
        chmax(c, low);
        int hi = lower_bound(all(l), l[a]+l[b]) - l.begin();
        ans += hi - c;
        // cout << l[a] << " " << l[b] << ":" << c << " " << hi << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from itertools import product

N = int(input())
xyh = [[int(_) for _ in input().split()] for _ in range(N)]

if N == 1:
    print(xyh[0][0], xyh[0][1], xyh[0][2])
else:
    for x, y in product(range(101), range(101)):
        for i in xyh:
            if i[2] > 0:
                H = i[2] + abs(x-i[0]) + abs(y-i[1])
                break
        for i in xyh:
            if i[2] != max(0, H-abs(x-i[0])-abs(y-i[1])):
                break
        else:
            print(x, y, H)
            break

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

int main(){
  string s;
  cin >> s;

  int counter = 0;

  if (s[0] == 'o') ++counter;
  if (s[1] == 'o') ++counter;
  if (s[2] == 'o') ++counter;

  cout << 700 + 100 * counter <<endl;

 }

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
#if DEBUG
            Solve(Console.In, Console.Out);
            Console.ReadLine();
#else
            Solve(Console.In, Console.Out);
#endif
        }

        class City { public int Index, P, Y, X; }

        public static void Solve(TextReader ci, TextWriter co)
        {
            int n, m;
            ReadInts(ci, out n, out m);
            var prefTable = new Dictionary<int, List<City>>();
            var allCities = new List<City>();
            for (int i = 0; i < m; ++i) {
                int p, y;
                ReadInts(ci, out p, out y);
                List<City> cityList;
                if (!prefTable.TryGetValue(p, out cityList)) {
                    cityList = new List<City>();
                    prefTable.Add(p, cityList);
                }
                var city = new City() { Index = i, P = p, Y = y };
                cityList.Add(city);
                allCities.Add(city);
            }
            foreach (var prefNo in prefTable.Keys) {
                var cities = prefTable[prefNo];
                cities.Sort((a, b) => a.Y - b.Y);
                for (int i = 0; i < cities.Count; ++i) {
                    cities[i].X = i + 1;
                }
            }
            foreach (var city in allCities.OrderBy(p => p.Index)) {
                co.WriteLine(city.P.ToString("000000") + city.X.ToString("000000"));
            }
            co.Flush();
        }

        public static int ReadInt(TextReader ci) => int.Parse(ci.ReadLine());

        public static void ReadInts(TextReader ci, out int a, out int b)
        {
            var array = IntArrayFrom(ci.ReadLine());
            a = array[0];
            b = array[1];
        }

        public static void ReadInts(TextReader ci, out int a, out int b, out int c)
        {
            var array = IntArrayFrom(ci.ReadLine());
            a = array[0];
            b = array[1];
            c = array[2];
        }

        public static int[] IntArrayFrom(string s)
            => s.Split(' ').Select(p => int.Parse(p)).ToArray();
    }
}


Measured memory_bytes: 41320
while True:
    Y = int(input())
    if Y == 0:
        break
    X = 1000 - Y
    a = X // 500
    X = X - a * 500
    b = X // 100
    X = X - b * 100
    c = X // 50
    X = X - c * 50
    d = X // 10
    X = X - d * 10
    e = X // 5
    X = X - e * 5
    f = X // 1
    
    print(a+b+c+d+e+f)


Measured memory_bytes: 5588
#include<stdio.h>

int main(void)
{
    int tem=0,i,j;
    int a[5];
    for(i=0;i<5;i++) {
        scanf("%d",&a[i]);
    }
    for(j=0;j<4;j++){
        for(i=0;i<4;i++) {
            if(a[i]<a[i+1]){
                tem=a[i];
                a[i]=a[i+1];
                a[i+1]=tem;
            }
        }
    }
    for(i=0;i<4;i++){
        printf("%d ",a[i]);
    }
    printf("%d\n",a[i]);
    return 0;
}

Measured memory_bytes: 596
def main():
    N = int(input())
    V = [int(s) for s in input().split()]
    V.sort()

    sol = (V[0] + V[1]) / 2

    for i in range(2, N):
        sol = (sol + V[i]) / 2

    print(sol)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int n; string s; cin>> n>>s;
  for(int h=0;h<s.size();h++){
    for(int i=0;i<n;i++){
     if(s[h]=='A'){s[h]='B';} 
     else if(s[h]=='B'){s[h]='C';} 
     else if(s[h]=='C'){s[h]='D';} 
     else if(s[h]=='D'){s[h]='E';} 
     else if(s[h]=='E'){s[h]='F';} 
     else if(s[h]=='F'){s[h]='G';} 
     else if(s[h]=='G'){s[h]='H';} 
     else if(s[h]=='H'){s[h]='I';} 
     else if(s[h]=='I'){s[h]='J';} 
     else if(s[h]=='J'){s[h]='K';} 
     else if(s[h]=='K'){s[h]='L';} 
     else if(s[h]=='L'){s[h]='M';} 
     else if(s[h]=='M'){s[h]='N';} 
     else if(s[h]=='N'){s[h]='O';} 
     else if(s[h]=='O'){s[h]='P';} 
     else if(s[h]=='P'){s[h]='Q';} 
     else if(s[h]=='Q'){s[h]='R';} 
     else if(s[h]=='R'){s[h]='S';} 
     else if(s[h]=='S'){s[h]='T';} 
     else if(s[h]=='T'){s[h]='U';} 
     else if(s[h]=='U'){s[h]='V';} 
    else if(s[h]=='V'){s[h]='W';} 
    else  if(s[h]=='W'){s[h]='X';} 
   else   if(s[h]=='X'){s[h]='Y';} 
     else if(s[h]=='Y'){s[h]='Z';} 
    else  if(s[h]=='Z'){s[h]='A';} 
    }
    cout<<s[h];
  }
  cout<<endl;
}

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

#define int long long int
#define ull unsigned long long int
#define for0(i, n) for (int i = 0; i < (int)(n); i++) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); i++) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); i++) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; i--) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; i--) // reverse 1 based


#define pb push_back
#define fi first
#define se second

#define I_max (int)1e9+7
#define size6 (int)1e6


#define all(x) (x).begin(), (x).end() 
#define rall(x) (x).rbegin, (x).rend() 
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())


using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef double ld;

//-----------------------------------------------------------------------------------END-------------------------------------------------------------------------------------//

int a[size6];


bool inc(vi vec){
	for1(i,vec.size()-1){
		if(vec[i]<vec[i-1])return 0;
	}
	return 1;
}


void solve(){
	int n;cin>>n;
	int change=1000;
	while(change<n)change+=1000;

	cout<<change-n;  
}



int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout.precision(10);
	//cout << fixed;
	//int tt;cin>>tt;
	//while(tt--){
		solve();
	//}
	return 0;
}




Measured memory_bytes: 3696
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,x;
    int count = 0;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    for(int i=0;i<=a;i++){
      for(int j=0;j<=b;j++){
        for(int k=0;k<=c;k++){
          if ((500*i + 100*j + 50*k) == x){
            count += 1; 
          }
        }   
      }    
    }
    cout << count << endl;
    
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	cin >> n;
	vector<pair<int, int>> lr(n);
	rep(i, n)cin >> lr[i].first >> lr[i].second, lr[i].second *= -1;


	sort(all(lr));
	map<int, int> mlr, mrl;
	int oma = 0;

	int ans = 0;
	for (auto p: lr) {
		auto q = p;
		q.second *= -1;
		for (auto it = mrl.lower_bound(q.second); it != mrl.end(); ) {
			oma = max(oma, it->first - it->second + 1);
			mlr.erase(it->second);
			it = mrl.erase(it);
		}
		mlr[q.first] = q.second;
		mrl[q.second] = q.first;
		ans = max(ans, q.second - q.first + 1);
	}

	
	set<int> gr1, gr2;
	set<int, greater<int>> gl1, gl2;
	for (auto p : mlr) {
		gl2.insert(p.first);
		gr2.insert(p.second);
	}
	ans = max(ans, max(0, *gr2.begin() - *gl2.begin() + 1) + oma);

	int m = mlr.size();
	for (auto it = mlr.begin(); --m; ++it) {
		auto p = *it;
		gl1.insert(p.first);
		gr1.insert(p.second);
		gl2.erase(gl2.find(p.first));
		gr2.erase(gr2.find(p.second));

		ans = max(ans, max(0, *gr1.begin() - *gl1.begin() + 1) + max(0, *gr2.begin() - *gl2.begin() + 1));
	}



	cout << ans << endl;



	return 0;
}

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

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

  if(K < 10){
    cout << K << endl;
  }
  else{
    set<int64_t> S;
    for(int64_t i=1; i<10; i++){ S.insert(i); }

    int64_t N= 10;
    int64_t head= 1;
    int64_t tail= 0;
    while(S.size() < K){
      S.insert(head*10+ tail);
      
      if(tail < 9 && abs(head%10-(tail+1)) <= 1){
        tail+= 1;
      }
      else{
        auto itr= S.upper_bound(head);
        head= *itr;
        tail= (head%10 != 0) ? head%10- 1
                             : 0;
      }
    }
    cout << *rbegin(S) << endl;
  }
}

Measured memory_bytes: 4992
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-06-07 21:32:19
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF 1000000000

int main()
{
    string s;
    cin >> s;

    string ans;
    char c = s[s.length()-1] - '0';
    if (c == 3) {
        ans = "bon";
    } else if (c == 0 || c == 1 || c == 6 || c == 8) {
        ans = "pon";
    } else {
        ans = "hon";
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 100000;

int main(){
    long long N,M;
    pair<long long,long long> v[MAX];

    cin >> N >> M;
    for(int i = 0;i < N;i++){
        cin >> v[i].first >> v[i].second;
    }

    sort(v,v+N);

    long long ans = 0;

    for(int i = 0;i < N;i++){
        long long n = min(M,v[i].second);
        ans += n * v[i].first;
        M -= n;
        if(M == 0)break;
    }

    cout << ans << endl;

    return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

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

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    LL c = 0;
    for(int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        while(a % 2 == 0) {
            c++;
            a >>= 1;

        }
    }
    cout << c << endl;
    return 0;
}


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

//答えが合わない場合はlong long型を疑うこと！

int main(){
    int n,d,x,a,ans=0,temp=0;
    cin >> n >> d >> x;
    rep(i,n){
        cin >> a;
        temp=(d-1)/a+1;
        ans+=temp;
    }
    cout << ans+x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
int main()
{
	sync;
	ll n;
	cin>>n;
	ll arr[n],dp[n];
	input(arr,n);
	dp[n-1]=1;
	for(ll i=n-2;i>=0;i--)
	{
		dp[i]=1;
		if(arr[i]>=arr[i+1])
		dp[i]=dp[i+1]+1;
	}
	cout<<*max_element(dp,dp+n)-1;
}

Measured memory_bytes: 1792
import sys
from collections import deque
def query(s1,s2):
	print "{0}\n{1}".format("".join(s1),"".join(s2))
	sys.stdout.flush()
	return raw_input()
def solve():
	dss = [(".","."),(".","#"),("#","."),("#","#")]
	tmp_dss = []
	N = map(int,raw_input().split())
	for ds in dss:
		res = query([ds[0]],[ds[1]])
		if res == "T": tmp_dss.append(ds)
	dss = tmp_dss
	s1 = deque(dss[0][0]); s2 = deque(dss[0][1]) 
	for _ in xrange(420):
		#right
		for ds1,ds2 in dss:
			s1.append(ds1); s2.append(ds2)
			res = query(s1,s2)
			if res == "end": return
			if res == "T": break
			s1.pop();s2.pop()
		else:
			break
	for _ in xrange(420):
		#left
		for ds1,ds2 in dss:
			s1.appendleft(ds1); s2.appendleft(ds2)
			res = query(s1,s2)
			if res == "end": return
			if res == "T": break
			s1.popleft();s2.popleft()
solve()

Measured memory_bytes: 10180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,Q;
int x[100100];
int nxt[18][100100];
int L;
int solve(int a,int b){
	if(a>b)swap(a,b);
	int res = 0;
	for(int i=17;i>=0;i--){
		if(nxt[i][a]<b){
			res |= (1<<i);
			a = nxt[i][a];
		}
		if(a==b)break;
	}
	return res+1;
}
int main(){
	cin >> N;
	for(int i=0;i<N;i++)cin >> x[i];
	cin >> L;
	for(int i=0;i<N;i++){
		nxt[0][i]=upper_bound(x,x+N,x[i]+L)-x-1;
	}
	for(int i=0;i<17;i++){
		for(int j=0;j<N;j++){
			nxt[i+1][j]=nxt[i][nxt[i][j]];
		}
		//for(int j=0;j<N;j++)printf("%d ",nxt[i][j]);
		//printf("\n");
	}
	cin >> Q;
	for(int i=0;i<Q;i++){
		int a,b;
		cin >> a >> b;
		a--;b--;
		cout << solve(a,b) << endl;
	}
	return 0;
}


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

int N;
vector<long long> A;
vector<long long> sum;

int main() {
    cin >> N; 
    A.resize(N); sum.resize(N+1); sum[0] = 0;
    for (int i = 0; i < N; ++i) cin >> A[i], sum[i+1] = sum[i] + A[i];

    long long res = 1LL<<60;
    for (int i = 0; i <= N; ++i) {
        // P < Q となる最大の切れ目を求める: 二分探索を終えた時の left_low
        int low = 0, high = i;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] >= sum[i] - sum[mid]) high = mid;
            else low = mid;
        }
        long long P = sum[low], Q = sum[i] - sum[low]; // 候補1
        long long P2 = sum[high], Q2 = sum[i] - sum[high]; // 候補2
        long long left_min = min(P, Q), left_max = max(P, Q);
        if (abs(P2-Q2) < abs(P-Q)) left_min = min(P2, Q2), left_max = max(P2, Q2);

        // R < S となる最大の切れ目を求める
        low = i, high = N;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] - sum[i] >= sum[N] - sum[mid]) high = mid;
            else low = mid;
        }
        long long R = sum[low] - sum[i], S = sum[N] - sum[low]; // 候補1
        long long R2 = sum[high] - sum[i], S2 = sum[N] - sum[high]; // 候補2
        long long right_min = min(R, S), right_max = max(R, S);
        if (abs(R2-S2) < abs(R-S)) right_min = min(R2, S2), right_max = max(R2, S2);

        // 真ん中の切れ目が i であるときの暫定解
        long long tmp = max(left_max, right_max) - min(left_min, right_min);
        res = min(res, tmp);
    }
    cout << res << endl;
}


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

public class Main {

    public static void main(String args[]) throws IOException {
        FastReader in = new FastReader();
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        Task.solve(in, out);
        out.close();
    }

    static class Task {

        public static void solve(FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            int cost =0;
            for(int i=0;i<n;i++){
                a[i] = in.nextInt();
                if(i!=0){
                    cost += Math.abs(a[i]-a[i-1]);
                }
            }
            cost += Math.abs(a[0]);
            cost += Math.abs(a[n-1]);
            out.println(cost - Math.abs(a[0]) - Math.abs(a[0]-a[1]) + Math.abs(a[1]));
            for(int i=1;i<n-1;i++){
                out.println(cost - Math.abs(a[i]-a[i-1]) - Math.abs(a[i]-a[i+1]) + Math.abs(a[i-1] - a[i+1]));
            }
            out.println(cost - Math.abs(a[n-1]-a[n-2]) - Math.abs(a[n-1]) + Math.abs(a[n-2]));

        }
    }

    static 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: 43940
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

const int inf=2147483647;

int n1,n2,n4;

int n;

int main()
{
	cin>>n;
	
	int x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		
		if(x%2!=0) n1++;
		else if(x%4!=0) n2++;
		else n4++;
	}
	
	if(n1>n4+1)
	{
		puts("No");
		return 0;
	}
	
	if(n1==n4+1)
	{
		if(n2==0)
		{
			puts("Yes");
			return 0;
		}
		else
		{
			puts("No");
			return 0;
		}
	}
	
	puts("Yes");
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 3e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n;
ll a[maxn];

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

	cin >> n;
	for (int i = 0; i < 3 * n; i++) {
		cin >> a[i];
	}
	sort(a, a + 3 * n);

	ll ans = 0;
	int l = 0, r = 3 * n;
	while (r > l) {
		ans += a[r - 2];
		r -= 2;
		l++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 5940
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

int n;
int ans;
int a[100005];
char done[100005];

void solve() {
	for (int i = 0; i < n; i++) {
		if (done[i]) continue;
		if (i == a[a[i]]) {
			ans++;
			done[i] = 1;
			done[a[i]] = 1;
		}
	}
	cout << ans << endl;
}

int main() {
	cin >> n; 
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	solve();
	return 0;
}




Measured memory_bytes: 768
#include <iostream>
#include <string>
using namespace std;
int main(){

	string s;
	cin >> s;
	bool b[4] = {false,false,false,false};
	for (int i = 0; i < s.size(); ++i)
	{
		switch(s[i]){
			case 'N':
			b[0]=true;
			break;
			case 'W':
			b[1] = true;
			break;
			case 'S':
			b[2] = true;
			break;
			case 'E':
			b[3] = true;
			break;
		}
	}
	if(b[0]==b[2]&&b[1]==b[3]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int r, g;
    scan(r, g);
    int ans = 2 * g - r;
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	int fare;
	while(scanf("%d%d%d%d",&a,&b,&c,&d)==4)
	{
		fare=0;
		if(a>=b)
		fare+=b;
		else
		fare+=a;
		if(c>=d)
		fare+=d;
		else
		fare+=c;
		cout<<fare<<'\n';
	}
	return 0;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <deque>
#include <numeric>
#include <set>
using namespace std;

int par[100005];
int depth[100005];

void init(int n){
    for(int i = 0; i < n; ++i){
        par[i] = i;
        depth[i] = 0;
    }
}

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(depth[x] < depth[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
        if(depth[x] == depth[y])    ++depth[x];  
    }
}

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

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

    int n, m;
    cin >> n >> m;
    init(n);
    for(int i = 0; i < m; ++i){
        int x, y, z;
        cin >> x >> y >> z;
        unite(x, y);
    }

    set<int> s;
    for(int i = 0; i < n; ++i){
        s.insert(find(i));
    }

    int res = (int)s.size();
    cout << res << endl;
}

Measured memory_bytes: 5760
#include<stdio.h>
int main(void)
{ char s[4]={0};
  int check[4]={0};
  scanf("%s\n",s);
  int i=0;int j;
  int count=0;
  for(i=0;i<4;i++)
  { if(s[i]=='a')j=0;
    if(s[i]=='b')j=1;
    if(s[i]=='c')j=2;
     if(check[j]==0)
     { count++;
       check[j]++;
     }
  }
  if(count==3){puts("Yes");}else{puts("No");}
 return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
// clang-format off
using i64 = int64_t;
using i32 = int32_t;
#define all(x) x.begin(), x.end()
#define int i64
template <class T, typename U> constexpr inline bool exist(const T &s, const U &e) { return s.find(e) != s.end(); }
template <class T> constexpr inline i32 SZ(const T &x) { return x.size(); }
template <class T> constexpr inline bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> constexpr inline bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
const char el = '\n'; const i32 MOD = 1e9 + 7, INF = 0x3f3f3f3f; const i64 INFLL = ((i64)INF << 32) | INF;

#ifdef LOCAL // debugging swiss knife
template <typename Ostream, typename Cont> enable_if_t<is_same<Ostream, ostream>::value, Ostream &> operator<<(Ostream &os, const Cont &v) { os << "{"; for (const auto &x : v) os << x << ", "; return os << "}"; }
template <typename Ostream, typename... Ts> Ostream &operator<<(Ostream &os, const pair<Ts...> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class... Args> void dbg_out(Args... args) { ((std::cerr << "\033[32m" << args << "\033[37m, "), ...); }
#define dbg(...) cerr << "\033[1;31m" << __LINE__ << ": [" << #__VA_ARGS__ << "]\033[37m  = ", dbg_out(__VA_ARGS__), cerr << "\033[0m" << endl;
#else
#define dbg(...) ;
#endif
// clang-format on
////////////////////////////////// TEMPLATE ENDS /////////////////////////////////
vector<vector<i32>> adj;
vector<i32> vis, color;

int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(13), cerr << fixed << setprecision(3);

    int n;
    cin >> n;
    using pii = pair<int, int>;
    vector<pii> v(n);
    int ans = n * (n + 1) / 2;
    for (i64 i = 1; i < n; ++i) {
        ans += i * (i + 1) / 2;
        int l, r;
        cin >> l >> r;
        if (l > r) swap(l, r);
        ans -= l * (n + 1 - r);
    }
    cout << ans << el;

    return 0;
}

Measured memory_bytes: 6312
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
        cout << "YES"
             << "\n";
    else
        cout << "NO"
             << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    string s;
    cin>>a>>b>>s;
    int l=s.size();
    if(s[a]!='-')
    {
        cout<<"No"<<endl;
        return 0;
    }
    else
    {
        s[a]='2';
        for(int i=0;i<l;i++)
        {
            //printf("%d\n",s[i]);
            if(s[i]<48||s[i]>57)
            {
                cout<<"No"<<endl;
                return 0;
            }
        }


    }
    cout<<"Yes"<<endl;
    return 0;


}


Measured memory_bytes: 256
/*
 * 2435.cc: Zero Division Checker
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<bitset>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_M = 100;
const int BN = 256;

/* typedef */

typedef bitset<BN> bb;
typedef map<string,int> msi;

/* global variables */

bb vrs[MAX_M];
msi vmap;

/* subroutines */

/* main */

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

  for (int i = 0; i < m; i++) {
    string name;
    int lb, ub;
    cin >> name >> lb >> ub;

    vrs[i].reset();
    for (int j = lb; j <=ub; j++) vrs[i].set(j);
    vmap[name] = i;
  }

  int n;
  cin >> n;

  stack<bb> st;
  bool ok = true;

  for (int i = 0; i < n; i++) {
    string e;
    cin >> e;

    msi::iterator mit = vmap.find(e);
    if (mit != vmap.end())
      st.push(vrs[mit->second]);
    else if (e[0] < '0' || e[0] > '9') {
      bb b = st.top(); st.pop();
      bb a = st.top(); st.pop();
      bb r(0);
      
      for (int bi = 0; bi < BN; bi++) {
	if (! b.test(bi)) continue;

	if (bi == 0 && e[0] == '/') {
	  ok = false;
	  break;
	}

	for (int ai = 0; ai < BN; ai++) {
	  if (! a.test(ai)) continue;

	  int ri;
	  if (e[0] == '+') ri = (ai + bi) % BN;
	  else if (e[0] == '-') ri = (ai + BN - bi) % BN;
	  else if (e[0] == '*') ri = (ai * bi) % BN;
	  else ri = (ai / bi) % BN;

	  r.set(ri);
	}
      }
      if (! ok) break;

      st.push(r);
    }
    else {
      int k = atoi(e.c_str());
      bb r(0);
      r.set(k);
      st.push(r);
    }
  }

  cout << (ok ? "correct" : "error") << endl;
  return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

int min(int a,int b){
    if(a<=b){
        return a;
    }
    return b;
}

int main() {
    int n;
    string s;
    cin>>n>>s;
    int c=0;
    for(int i=0;i<n;i++){
        if(s[i]=='.'){
            c++;
        }
    }
    int ans=c;
    int dp[n+1];
    dp[0]=c;
    for(int i=0;i<n;i++){
        if(s[i]=='.'){
            dp[i+1]=dp[i]-1;
            ans=min(ans,dp[i+1]);
        }else{
            dp[i+1]=dp[i]+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = k; i < (int)(n); i++)
const int maxN = int(1e5 + 10);
int e[maxN] = {}, o[maxN] = {};
int num[maxN] = {};

int main() {
    int n;
    int x[110], y[110], h[110];
    cin >> n;
    rep(i, n) {
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] == 100) {
            printf("%d %d %d\n", x[i], y[i], h[i]);
            return 0;
        }
    }
    rep(cx, 101) rep(cy, 101) {
        bool flag = true;
        int ch = 0;
        rep(i, n) {
            if(h[i] != 0) {
                ch = h[i] + abs(cx - x[i]) + abs(cy - y[i]);
                break;
            }
        }
        rep(i, n) {
            if(h[i] == 0) {
                if(ch > abs(cx - x[i]) + abs(cy - y[i])) {
                    flag = false;
                    break;
                }
            } else {
                int tch = h[i] + abs(cx - x[i]) + abs(cy - y[i]);
                if(tch != ch) {
                    flag = false;
                    break;
                }
            }
        }
        if(flag == true) {
            printf("%d %d %d\n", cx, cy, ch);
            return 0;
        }
    }
    return 0;
}


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

#define Pi acos(-1.)
#define pb push_back
#define all(x) (x).begin(), x.end()
#define mp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define FILE "474"
#define standart 1

using namespace std;

typedef long long ll;

const int INF = 1e9 + 322;
const ll LINF = 2e18 + 474;
const int MAXN  = 1e5 + 228;
const ll MOD = 1e9 + 7;
const double eps = 1e-14;

int n;
int t[MAXN], x[MAXN], y[MAXN];

void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }
    for(int i = 1; i <= n; i++) {
        int tt = t[i] - t[i-1];
        int xx = abs(x[i] - x[i-1]);
        int yy = abs(y[i] - y[i-1]);
        int dist = xx + yy;
        if(tt >= dist && (tt % 2) == (dist % 2))
            continue;
        else {
            cout << "No";
            return;
        }
    }
    cout << "Yes";

}



int main() {
    if(!standart) {
        freopen(FILE".in", "r", stdin);
        freopen(FILE".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int kyky = 1;
    while(kyky--)
        solve();

    return 0;
}


Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //c
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    cout << a[i].second;
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 1664