akhauriyash/Code-Regression huggingface dataset:
import qualified Data.Vector.Unboxed as V
import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition)
import Data.Char (isSpace)
import Control.Monad.ST (ST)
import Control.Monad.Trans.State (StateT(..))
import qualified Data.ByteString.Char8 as B

import Debug.Trace (trace)

-- utility functions

--tr x = trace (show x) x
tr = id

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

readCharV :: Int -> B.ByteString -> V.Vector Char
readCharV n = V.unfoldrN n f where
  f bs = Just (B.head bs, B.tail bs)

readIntsA :: Int -> B.ByteString -> UArray Int Int
readIntsA n bs = runSTUArray $ do
  arr <- newArray_ (0,n-1)
  go arr 0 bs
  return arr
  where
    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
    go arr i bs
      | i==n = return ()
      | otherwise = do
        let Just (x,bs') = readInt bs
        writeArray arr i x
        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

lowerBound size sat = go (-1) size where
  go l r
    | l==r-1 = r
    | sat m = go l m
    | otherwise = go m r
    where m = (l+r)`div`2

upperBound size sat = go (-1) size where
  go l r
    | l==r-1 = l
    | sat m = go m r
    | otherwise = go l m
    where m = (l+r)`div`2

(!*) = V.unsafeIndex

enumACPos xs = go xs 0 where
  go xs i
    | B.null xs = V.empty
    | B.head xs == 'A' = go' (B.tail xs) (i+1)
    | otherwise = go (B.tail xs) (i+1)
  go' xs i
    | B.null xs = V.empty
    | B.head xs == 'A' = go' (B.tail xs) (i+1)
    | B.head xs == 'C' = V.cons i  $ go (B.tail xs) (i+1)
    | otherwise = go (B.tail xs) (i+1)

solv :: B.ByteString -> V.Vector (Int,Int) -> IO ()
solv s qs = V.forM_ qs $ print . solv1
  where
    acpos = enumACPos s
    solv1 (l,r) = right - left + 1 where
      left = lowerBound (V.length acpos) (\i -> l <= acpos!*i )
      right = upperBound (V.length acpos) (\i -> (acpos!*i)+1 <= r)
      

main = do
  [n,q] <- map read . words <$> getLine :: IO [Int]
  s <- B.getLine
  qs <- readTsV q <$> B.getContents
  solv s qs


Measured memory_bytes: 7036
n = int(input())
a = []
b = []
for _ in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
a.sort()
b.sort()
if n%2:
    print(b[n//2] - a[n//2] + 1)
else:
    print(b[n//2]+b[n//2-1] - a[n//2]-a[n//2-1] + 1)

Measured memory_bytes: 25552
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		std::vector<int> num;
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (; x; x /= 10) {
			num.push_back(x % 10);
		}
		while (!num.empty()) {
			putchar(num.back() ^ '0');
			num.pop_back();
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

int n;
int a[100005];
long long b[100005];

void solve() {
	read(n);
	for (int i = 0; i <= n; ++i) {
		read(a[i]);
	}
	b[n] = a[n];
	for (int i = n - 1; ~i; --i) {
		b[i] = b[i + 1] + a[i];
	}
	b[0] = 1;
	for (int i = 0; i < n; ++i) {
		b[i + 1] = std::min(b[i + 1], 2ll * (b[i] - a[i]));
	}
	long long ans = 0;
	for (int i = 0; i <= n; ++i) {
		if (b[i] < a[i]) {
			print(-1);
			return;
		}
		ans += b[i];
	}
	print(ans);
}

int main() {
	int T = 1;
	// read(T);
	while (T--) {
		solve();
	}
}


Measured memory_bytes: 5040
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

if sum(map(int, raw_input().split())) <= 21:
    print "win"
else:
    print "bust"

Measured memory_bytes: 4268
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
ll a[1000009];
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    cin>>n;
    for(i=1;i<=n;i++)
        if(i%3!=0 && i%5!=0)
        x+= i;
    cout<<x<<endl;
    return 0;
}



Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program {
    static void Main() {
        var n = NextInt();
        var k = NextInt();
        var g = 0;
        var m = 0;

        foreach (var i in Enumerable.Range(0, n)) {
            var a = NextInt();
            if (i == 0) {
                g = a;
                m = a;
            }
            g = gcd(g, a);
            m = Math.Max(m, a);
        }
        if (k % g == 0 && k <= m) {
            WriteLine("POSSIBLE");
        } else {
            WriteLine("IMPOSSIBLE");
        }
    }

    static int gcd(int x, int y) {
        while (y != 0) {
            x %= y;
            var tmp = x;
            x = y;
            y = tmp;
        }
        if (x < 0) {
            x *= -1;
        }
        return x;
    }

    static int NextInt() {
        return int.Parse(NextString());
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 17328
import sys


if __name__ == "__main__":
    n = int(input())
    s = input()
    sum_w = s.count("W")
    sum_e = s.count("E")
    ans = 10**9
    w,e = 0,0
    for i in range(n):
        if s[i] == "W":
            sum_w-=1
        else:
            sum_e-=1
        chenge = w + sum_e
        if s[i] == "W":
            w += 1
        else:
            e += 1
        ans = min(ans,chenge)
    print(ans) 

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9+7;

int main(void){
  int n;
  vector<int> v;
  map< int,int > a1;
  map< int,int > a2;
  cin >> n;
  for(int i = 0;i < n;++i){
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
    if(i % 2 == 0){
      ++a1[tmp];
    }else{
      ++a2[tmp];
    }
  }
  
  vector< P > v1;
  vector< P > v2;
  for(auto iter : a1){
    v1.push_back(P(iter.second, iter.first));
  }
  v1.push_back(P(0,-1));
  sort(v1.begin(),v1.end(), greater<P>());
  for(auto iter : a2){
    v2.push_back(P(iter.second, iter.first));
  }
  v2.push_back(P(0,-1));
  sort(v2.begin(),v2.end(), greater<P>());
  if(v1[0].second == v2[0].second){
    cout << n - max(v1[0].first + v2[1].first,
                    v2[0].first + v1[1].first) << endl;
  }else{
    cout << n - (v1[0].first + v2[0].first) << endl;
  }
  return 0;
}



Measured memory_bytes: 6648
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using ld = long double;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

string s;
int main(){
    cin >> s;
    int cou = 0;
    rep(i,1,s.size() - 1){
        cou += (s[i - 1] != s[i])? 1 : 0;
    }

    cout << cou << endl;
}


Measured memory_bytes: 512
s=input()
t=input()

keep=[0]*26
moji=["0"]*26
res=1

for i in range(0,len(s)):
  moji_s=s[i]
  moji_t=t[i]
  s_num=ord(moji_s)-97
  t_num=ord(moji_t)-97
  if keep[s_num]==0:
    keep[s_num]=1
    moji[s_num]=moji_t
  else:
    if moji[s_num]!=moji_t:
      res=0
      break
  kepkep=moji[s_num]
  moji[s_num]="0"
  if moji_t in moji:
    res=0
    break
  moji[s_num]=kepkep

if res==1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//nCrを返す関数.
long long int comb(long long int n, long long int r){
	if(n < r || n < 0)
		return 0;
	long long int x = 1, y = 1;
	if (n-r < r) r = n - r;
	for (long long int i = 0; i < r; i++)
	{
		x = x * (n - i);
		y = y * (i + 1);
	}
	return x / y;
}


int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	a[0]--;
	rep(i, n - 1)
	{
		if(a[i] < a[i+1])
			a[i+1]--;
	}
	rep(i,n-1){
		if(a[i] > a[i+1]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
class Main{
    int H,W,i,r;
    boolean x = true;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt();
        W = sc.nextInt();
        if(H == 0 && W == 0){
            x = false;
        }
        while(x == true){
            for(i = 0; i < H; i++){
                for(r = 0; r < W; r++){
                    if(i == 0 || i == H-1 || r == 0 || r == W-1){
                        System.out.print("#");
                    }else{
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
            H = sc.nextInt();
            W = sc.nextInt();
            if(H == 0 && W == 0){
                x = false;
            }
        }
    }
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 22900
import sys
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
a = na()
b = range(n)


for i in sorted(b, key = lambda x:a[x]):
    print(i+1, end= " ")

Measured memory_bytes: 13876
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var N = ReadInt();
            List<int> points = new List<int>();
            List<int> minus = new List<int>();
            for (int i = 0; i < N; i++)
            {
                int tmp = ReadInt();
                points.Add(tmp);
                if (tmp % 10 != 0)
                {
                    minus.Add(tmp);
                }
            }

            minus = minus.OrderBy(x => x).ToList();
            var pointSum = points.Sum();

            if (pointSum % 10 != 0)
            {
                Console.WriteLine(pointSum);
                return;
            }
            if (minus.Any())
            {
                Console.WriteLine(pointSum - minus[0]);
                return;
            }

            Console.WriteLine(0);
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

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

using namespace std;
const int MAX = 100000;
typedef pair<int,int> P;
int ans[MAX];

int ToS(int h, int m, int s){
  return h*60*60+m*60+s;
}

void init(){
  fill(ans,ans+MAX,0);
}

int main(){
  int n;
  while(cin >> n && n){
    init();
    for(int i = 0; i < n; i++){
      int hh,ss,mm;
      int hh2,ss2,mm2;
      scanf("%d:%d:%d",&hh,&mm,&ss);
      scanf("%d:%d:%d",&hh2,&mm2,&ss2);
      int from = ToS(hh,mm,ss);
      int to = ToS(hh2,mm2,ss2);
      for(int i = from; i < to; i++)
	ans[i]++;
    }
    
    int out = 0;
    for(int i = 0; i < MAX; i++)
      out = max(out,ans[i]);

    cout << out << endl;

  }
  return 0;
}

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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    vector<char> f(26, 'a' - 1), g(26, 'a' - 1);
    for (int i = 0; i < s.size(); ++i) {
        if (f.at(s.at(i) - 'a') < 'a') f.at(s.at(i) - 'a') = t.at(i);
        else if (f.at(s.at(i) - 'a') != t.at(i)) {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = 0; i < t.size(); ++i) {
        if (g.at(t.at(i) - 'a') < 'a') g.at(t.at(i) - 'a') = s.at(i);
        else if (g.at(t.at(i) - 'a') != s.at(i)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 900
#include <cstdio>
#include <string>
#include <iostream>

using int64 = long long;
int main(void) {
  std::string s;
  while (std::cin >> s) {
    int64 prev = 0;
    int64 res = 0;
    for (auto c : s) {
      if (c == 'B') {
        prev++;
      } else {
        res += prev;
      }
    }
    std::cout << res << "\n";
  }

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	string s ; cin >> s ;
	string sub = "CF" ;
	int pos = 0 ;
	for(int i=0;i<s.size();i++){
		if(s.at(i)==sub.at(pos)) pos++ ;
		if(pos==2){
			cout << "Yes" << endl ;
			return 0 ;
		}
	}
	cout << "No" << endl ;
}


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

char ym_check(int x) {
	if (x >= 1 && x <= 12)
		return 'm';
	if (x >= 0 && x <= 99)
		return 'y';
	return 'n';
}

string check_ans(char c1, char c2) {
	if (c1 == 'n' || c2 == 'n')
		return "NA";
	if (c1 == 'm' && c2 == 'm')
		return "AMBIGUOUS";
	if (c1 == 'y' && c2 == 'm')
		return "YYMM";
	if (c1 == 'm' && c2 == 'y')
		return "MMYY";
	return "NA";
}

int main(void) {
	string S;
	cin >> S;

	int d1 = 10 * (int)(S[0] - '0') + (int)(S[1] - '0');
	int d2 = 10 * (int)(S[2] - '0') + (int)(S[3] - '0');
	char c1 = ym_check(d1);
	char c2 = ym_check(d2);
	string ans = check_ans(c1, c2);

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
/*
No matter how long a night, dawn will always break.

Simular saying ... The darkest hour is just before the dawn.
 ***************************************   ************************8   **********************************
*/
#include <bits/stdc++.h>
using namespace std;

 
#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define sz(x)	    (int)(x).size()
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define hell        998244353
#define output(x) cout << (x ? "YES" : "NO")<<endl;
 
 
 
 
 
int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }  
bool mod(double a,double b) {return a/b - floor(a/b);}
 

 
 
 
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int i,j,x,a,b,c,n,sum=0;
   string s,t;
cin>>a>>b>>c>>n;
x=min(a,n);
sum+=x;
n-=x;
x=min(b,n);
n-=x;
x=min(c,n);
sum-=x;
cout<<sum<<endl;

   
   
   
   
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long k;
	cin>>k;
	queue<long long> q;
	for(int i=1;i<=9;i++)
		q.push(i);
	while(!q.empty()){
		long long x=q.front();
		q.pop();
		k--;
		if(k==0){
			cout<<x<<endl;
			break;
		}
		for(int i=x%10-1;i<=x%10+1;i++){
			if(i>9||i<0)
				continue;
			q.push(x*10+i);
		}
	} 
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]

for cx in range(101):
    for cy in range(101):
        needH = -1

        for x, y, h in xyh:
            if h > 0:
                # この頂点から見て、頂上がcx, cyのときどのくらいの高さがあってほしいか
                tmp = h + abs(cx - x) + abs(cy - y)
                if needH == -1:
                    needH = tmp
                else:
                    if needH != tmp:
                        needH = -2
                        break

        if needH == -2:
            continue

        for x, y, h, in xyh:
            if h == 0:
                dist = abs(cx - x) + abs(cy - y)
                if needH > dist:
                    needH = -2
                    break
        if needH == -2:
            continue

        print(cx, cy, needH)
        exit()


Measured memory_bytes: 3064
inputNums = input().split()
A = int(inputNums[0])
B = int(inputNums[1])
K = int(inputNums[2])
if K > A:
    K = K - A
    A = 0
else:
    A = A - K
    K = 0
if K > B:
    K = K - B
    B = 0
else:
    B = B - K
    K = 0
print(str(A) + " " + str(B))

Measured memory_bytes: 3064
import sys
import math

N, M = map(int, input().split())
factors = [1]

if M % N == 0:
    print(M // N)
    sys.exit()

for m in range(2, int(math.sqrt(M)) + 1):
    tmp = M
    while tmp % m == 0:
        factors.append(m)
        factors.append(tmp // m)
        tmp = tmp // m
factors.append(M)

factors.sort()

for i in range(len(factors)):
    if factors[i] * N > M:
        ans = factors[i - 1]
        break
print(factors[i - 1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const ll INF = 1e18;

int n, m;
int a[2001], b[2001];
ll c[2001];
ll d[1001];
ll ans = INF;
bool neg[1001] = {};

int main(){
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    c[i] = -c[i];
  }
  for (int i = 0; i <= n; i++) {
    d[i] = INF;
  }
  d[1] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (d[a[j]] == INF) continue;
      if (d[b[j]] > d[a[j]] + c[j]) {
        d[b[j]] = d[a[j]] + c[j];
      }
    }
  }
  ans = -d[n];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (d[a[j]] == INF) continue;
      if (d[b[j]] > d[a[j]] + c[j]) {
        d[b[j]] = d[a[j]] + c[j];
        neg[b[j]] = true;
      }
      if (neg[a[j]]) neg[b[j]] = true;
    }
  }
  if (neg[n]) cout << "inf" << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

n,m = list(map(int,input().split()))
N = [[] for _ in range(n)]
V = [0] * n

for _ in range(m):
  a,b = list(map(int,input().split()))
  a -= 1
  b -= 1
  N[a].append(b)
  N[b].append(a)
  
for i in range(n):
  N[i] = list(set(N[i]))
ans = 0

for i in range(n):
  if V[i] == 0:
    cnt = 1
    Q = [i]
    V[i] = 1
    
    while Q:
      node = Q.pop()
      for child in N[node]:
        if V[child]==0:
          Q.append(child)
          V[child] = 1
          cnt += 1
    ans = max(ans, cnt)
          
print(ans)

Measured memory_bytes: 120172
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	cout << max(0, A - B * 2) << endl;

	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007
#define MEM_SIZE = 1e5+5;

template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}




//-----CODE------//


void solve(void)
{
  string str;
  cin>>str;
  int G = 0, P = 0;
  for (int i = 0; i < str.size(); i++)
  {
    if(str[i]== 'g')G++;
    else P++;
  }
  cout<<((G-P)>>1)<<endl;  
  
  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

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

int sum(int n) {
  return n * (n+1) / 2;
}

int main() {
  int N;
  while(scanf("%d", &N) != EOF && N) {
    int ans = 0;
    for (int i=2; i<=N; i++) {
      for (int j=0; j<=i-2; j++) {
	if (sum(i) - sum (j) == N) {
	  ans++;
	}
      }
    }
    printf("%d\n", ans);
  } 
}

Measured memory_bytes: 1172
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<stdlib.h>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
using namespace std;

int main() {
	int n, k;
	char s[51];
	cin >> n >> k >> s;
	s[k-1] = tolower(s[k - 1]);
	cout << s << endl;
	return 0;
}

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

const ll N = 2e5 + 5;
ll n,a[N],sum[N],f[N];

int main(){
   cin >> n;
   cin >> a[1] >> a[2];
   sum[1] = a[1];
   sum[2] = a[2];
   
   for(int i=3;i<=n;i++){
      cin >> a[i];
      sum[i] = sum[i-2] + a[i]; 
   }

   for(int i=2;i<=N;i++){
      if(i&1){
         f[i] = max(f[i-2] + a[i], f[i-1]);
      }else{
         f[i] = max(f[i-2] + a[i], sum[i-1]);
      } 
   }

   cout << f[n] << endl;
   return 0;  
}

Measured memory_bytes: 8308
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main() {
    string[] input = new string[](2);
    bool[] cup = new bool[](3);

    cup.fill(false);
    cup[0] = true;
    while ((input = readln.chomp.split(",")).length != 0) {
        swap(cup[(input[0][0] - 'A').to!int], cup[(input[1][0] - 'A').to!int]);
    }

    foreach (i; 0..cup.length) {
        if (cup[i]) {
           writeln((i + 'A').to!char);
           break;
        }
    }
}

Measured memory_bytes: 1060
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=4999999996000000001;
ll frac[1001001];

void output(ll a){
    string res;
    for(int i=0;i<12;i++){
        res+=(char)('0'+a%10);
        a/=10;
    }
    reverse(res.begin(),res.end());
    cout<<res<<endl;
}

int main(){
    ll n,m;
    cin>>n>>m;
    map<ll,vector<P> > mp;
    for(ll i=0;i<m;i++){
        ll p;
        ll y;
        cin>>p>>y;
        mp[p].push_back(P(y,i));
    }
    vector<ll> ans(m);
    for(auto vp:mp){
        ll pre=vp.first;
        ll count=1;
        sort(vp.second.begin(),vp.second.end());
        for(auto p:vp.second){
            ll y=p.first;
            ll i=p.second;
            ans[i]=count;
            ans[i]+=pre*1000000;
            count++;
        }
    }

    for(int i=0;i<m;i++){
        output(ans[i]);
    }

}

Measured memory_bytes: 14652
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

int tate[300000];
int yoko[300000];
int tatewa[300000];
int yokowa[300000];

int q1[300000];
int q2[300000];

signed main(){
    int n,q;
    cin >> n >> q;
    REP(i,q){
        int a1,a2;
        cin >>a1 >> a2;
        q1[i] = a1;
        q2[i] = a2;
        if(a1==1){
            tate[a2] = 1;
        }
        else{
            yoko[a2] = 1;
        }
    }
    for(int i=n-1;i>=0;i--){
        tatewa[i] = tatewa[i+1] + tate[i];
        yokowa[i] = yokowa[i+1] + yoko[i];
    }
    int ans = 0;
    int nokotate = n-1;
    int nokoyoko = n-1;
    REP(i,q){
        //cout << "i=" << i << " ans=" << ans << endl;
        //cout << "nokotate=" << nokotate << " nokoyoko" << nokoyoko << endl; 
        if(q1[i]==1 && q2[i]<=nokotate){
            ans += (nokotate-q2[i]) * (nokoyoko-1) -  (nokoyoko-1) * (tatewa[q2[i]+1] - tatewa[nokotate+1]);
            nokotate = q2[i]-1;
        }
        if(q1[i]==2 && q2[i]<=nokoyoko){
            ans += (nokoyoko-q2[i]) * (nokotate-1) -  (nokotate-1) * (yokowa[q2[i]+1] - yokowa[nokoyoko+1]);
            nokoyoko = q2[i]-1;
        }
    }
    ans += (nokotate-1) * (nokoyoko-1);
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 13016
while True:
    h,w = map(int, input().split())
    if (h == 0 and w == 0):
        break
    for i in range(h):
        if (i % 2 == 0):
            print("#."*(w//2) + "#"*(w%2))
        elif (i % 2 == 1):
            print(".#"*(w//2) + "."*(w%2))
    print()


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


int main(void){
  int n;
  cin >> n;
  vector<string> title(n);
  vector<int> length(n);
  for(int i = 0; i < n; i++){
    cin >> title[i];
    cin >> length[i];    
  }
  
  string stop_title;
  cin >> stop_title;
  int flag = 0, sum = 0;
  for(int i = 0; i < n; i++){
    if(flag == 1){
      sum += length.at(i);
    }
    if(title.at(i) == stop_title){
      flag = 1;
    }
    
  }
  cout << sum << endl;
 return 0; 
}

Measured memory_bytes: 256
/*
   Author : tarang
*/
#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with(false); cin.tie(0);cout.tie(0);
#define PI = acos(-1)
using namespace std ;
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
int main(){
	 ll m = 1000000007;
     ll n ; cin >> n ;
     vector<ll> v(n);
     for(ll i = 0 ; i < n ; i++){
     	cin >> v[i];
	 }
	 ll f[68] = {0};
//	 for(auto x:f) cout << x << " ";
//	 cout << endl;
	 for(ll i = 0 ; i < n ; i++){
	 	  for(ll j = 0 ; j < 63  ; j++){
	 	  	    if((v[i] & (1LL << j)))
	 	  	       f[j]++;
		   }
	 }
	// for(auto x :f) cout << x << " ";
	// cout << endl;
	 ll res = 0 ;
	 for(ll i = 0 ; i < 63 ; i++){
	 	  ll x = f[i];
	 	  ll z = (n-x);
	 	  ll ans = power(2 , i , m);
	 	  //cout << x << " " << z << " " << ans << endl;
	 	  res = (res%m +(((x%m * z%m)%m)*ans)%m)%m;
	 }
	 cout << (res)%m << endl;
}


Measured memory_bytes: 5640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;


//120
int main() {
	static char S[100010];

	scanf("%s", S);

	ll len = strlen(S);

	ll countOne = 0;
	for (ll i = 0; i < len; i++) {
		if (S[i] == '1') {
			countOne++;
		}
	}

	printf("%lld", std::min(countOne, len - countOne) * 2);

	return 0;
}


Measured memory_bytes: 384
N = int(input())
H = [int(s) for s in input().split(' ')]
count_max = 0
count = 0
prev = H[0]
for h in H[1:]:
    if h <= prev:
        count += 1
    else:
        count_max = max(count, count_max)
        count = 0
    prev = h
count_max = max(count, count_max)
print(count_max)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}



int main() {
	int n;
	stack <int> st;
	string str;
	cin >> n;
	rep(i, n) {
		cin >> str;
		if (str == "A") {
			st.push(1);
		}
		else {
			if(st.empty()){
				cout<<"NO"<<endl;
				return 0;
			}else{
				st.pop();
			}
		}
	}
	if(st.empty()){
		cout<<"YES"<<endl;
		return 0;
	}else{
		cout<<"NO"<<endl;
		return 0;
	}
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
#include<utility>
#include<map>
typedef long long ll;
typedef unsigned long long ull;
typedef std::vector<long long > vi ;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
using  namespace std;
ll pow1(ll n,ll p)
{
	if(p==0)	return 1;
	ll x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}
ll binarySearch(ll arr[], ll l, ll r,ll x) 
{ 
    if (r >= l) 
    { 
        ll mid = l + (r - l) / 2;  
        if (arr[mid] == x) 
        return mid; 
        if (arr[mid] > x) 
        return binarySearch(arr, l, mid - 1, x); 
        return binarySearch(arr, mid + 1, r, x); 
    }
    return -1; 
} 
ll gcd(ll a, ll b, ll &x, ll &y) {
    if (a == 0) {
        x = 0; y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

bool find_any_solution(ll a, ll b,ll c, ll &x0, ll &y0, ll &g) {
    g = gcd(llabs(a), llabs(b), x0, y0);
    if (c % g) {
        return false;
    }

    x0 *= c / g;
    y0 *= c / g;
    if (a < 0) x0 = -x0;
    if (b < 0) y0 = -y0;
    return true;
}
void shift_solution(ll & x,ll & y, ll a, ll b, ll cnt) {
    x += cnt * b;
    y -= cnt * a;
}

ll find_all_solutions(ll a, ll b, ll c, ll minx, ll maxx, ll miny, ll maxy)
{
    ll x, y, g;
    if (!find_any_solution(a, b, c, x, y, g))
    return 0;
    a /= g;
    b /= g;

    ll sign_a = a > 0 ? +1 : -1;
    ll sign_b = b > 0 ? +1 : -1;

    shift_solution(x, y, a, b, (minx - x) / b);
    if (x < minx)
    shift_solution(x, y, a, b, sign_b);
    if (x > maxx)
    return 0;
    ll lx1 = x;
    shift_solution(x, y, a, b, (maxx - x) / b);
    if (x > maxx)
    shift_solution(x, y, a, b, -sign_b);
    ll rx1 = x;
    shift_solution(x, y, a, b, -(miny - y) / a);
    if (y < miny)
    shift_solution(x, y, a, b, -sign_a);
    if (y > maxy)
    return 0;
    ll lx2 = x;

    shift_solution(x, y, a, b, -(maxy - y) / a);
    if (y > maxy)
    shift_solution(x, y, a, b, sign_a);
    ll rx2 = x;
    if (lx2 > rx2)
    swap(lx2, rx2);
    ll lx = max(lx1, lx2);
    ll rx = min(rx1, rx2);
    if (lx > rx)
    return 0;
    return (rx - lx) / llabs(b) + 1;
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
  
bool compare(const pair<ll, ll>&p1, const pair<ll,ll>&p2)
{
    if(p1.F < p2.F) return true;
        if(p1.F == p2.F) return p1.S < p2.S;
        return false;
}
int main()
{
    fast;
   ll n,w,k;
   std::cin >> n>>w;
   k=w;
   ll a[n],v[n];
   ll i,sum=0;
   for(i=0;i<n;i++)
   std::cin >> a[i]>>v[i];
   for(i=0;i<n;i++)
   {
       sum+=v[i];
   }
   ll dp[sum+1];
   for(i=1;i<=sum;i++)
   {
       dp[i]=1e18L + 5;
   }
   dp[0]=0;
   ll j;
   for(i=0;i<n;i++)
   {
       for(j=sum-v[i];j>=0;j--)
       {
           dp[j+v[i]]=min(dp[j+v[i]],dp[j]+a[i]);
       }
   }
   for(j=sum;j>=0;j--)
   {
       if(dp[j]<=w)
       {
           cout<<j<<"\n";
           break;
       }
   }
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    string S;
    cin >> S;
    string ans;

    int year = stoi(S.substr(0,4));
    int month = stoi(S.substr(5,2));
    int day = stoi(S.substr(8,2));

    if(year >= 2019 && month > 4 && day >= 1 ){
        ans = "TBD";
    }else{
        ans = "Heisei";
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int X,K,D;
signed main(){
    scanf("%lld %lld %lld",&X,&K,&D);
    X=abs(X);
    int kaisu=X/D;
    if(kaisu>K){printf("%lld\n",X-D*K);return 0;}
    int d=X-kaisu*D;
    int ans=0;
    if((K-kaisu)%2==1)ans=D-d;
    else ans=d;
    printf("%lld\n",ans);return 0;
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

struct Unionfind {
	vector< int > par;
	Unionfind(int N) : par(N,-1){
	}
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if(x == y) return 0;
		if(par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return 1;
	}
	int root(int k) {
		if(par[k] < 0) return (k);
		return (par[k] = root(par[k]));
	}
	bool same(int x, int y){
		x = root(x);
		y = root(y);
		return x==y;
	}
	int size(int k) {
		return (-par[root(k)]);
	}
};

int main(){
  
  int n,m; cin>>n>>m;
  Unionfind uf(n);
  while(m--){
    int a,b; cin>>a>>b;
    --a; --b;
    uf.unite(a,b);
  }
  set<int> s;
  for(int i=0; i<n; i++){
    s.insert(uf.root(i));
  }
  cout<<s.size()-1<<endl;
  
}



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

int main() {
    int n; cin >> n;
    vector<long long> a(n);
    int exist_odd = 0;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        if(a[i] % 2 == 1) ++exist_odd;
    }
    
    if(exist_odd % 2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define int long long

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N; cin >> N;
    ll s[100100];
    rep(i, N) cin >> s[i];
    ll dp[100100];
    ll ans = s[N - 1];
    rep1(C, N - 2) {
        int n_max = (N - 1) / C - 1;
        if(n_max < 1) break;
        if((N - 1) % C == 0) {
            dp[0] = s[N - 1];
            rep1(n, n_max) {
                if(n * C >= N - 1 - n * C) break;
                if(n * C < N - 1 && N - 1 - n * C > 0) {
                    dp[n] = dp[n - 1] + s[n * C] + s[N - 1 - n * C];
                    ans = max(ans, dp[n]);
                }
            }
        } else {
            dp[0] = s[N - 1];
            rep1(n, n_max) {
                if(n * C < N - 1 && N - 1 - n * C > 0) {
                    dp[n] = dp[n - 1] + s[n * C] + s[N - 1 - n * C];
                    ans = max(ans, dp[n]);
                }
            }
        }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,t;
    ll ans = 0;
    cin >> n >> t;
    vector<ll> a(n);
    cins(all(a));
    rep(i,n-1){
        ans += min(a[i+1]-a[i],t);
    }
    ans += t;
    PRINT(ans);
}

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

int main() {
  int n, ans=0;
  vector<int> h(20);
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> h.at(i);
  }
  int max_height = h.at(0);
  for(int i=0;i<n;i++){
    if(max_height<=h.at(i)){
      ans++;
      max_height=h.at(i);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"
#define P           pair<int, int>
#define dint        long double

const int mod = 998244353;
 
inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }
 
int modpow(int a, int b) {
    if(a == 0 || a == 1 || b == 1) return a;
    int ans = 1;
    while(b) {
        if(b%2) ans = mul(ans, a);    
        b /= 2; a = mul(a, a);
    }   return ans;
}

void solve() {
    int k, a, b; cin >> k >> a >> b;
    int up = (a + k - 1) / k;
    if(up * k <= b) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;
    for(int i=1; i<=T; i++) {
        solve();
    }
    return 0;

}



Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a*b/gcd(a,b);
}

long long com(long long n,long long k){
	
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin>>s;
	string t="";
	for(int i=0;i<4;i++){
		t+=s[i];
	}
	t+=" ";
	for(int i=5;i<13;i++){
		t+=s[i-1];
	}
	cout<<t<<endl;
}

	


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B,C,x;
    scanf("%d%d%d",&A,&B,&C);
    x=A-C;
    if(x==0)
    {
        printf("%d\n",B);
    }
    else if(x>0)
    {
        if(x<B)
        printf("%d\n",B-x);
        else
            printf("0\n");

    }
    else if(x<0)
    {
        printf("%d\n",B-x);
    }

    return 0;
}


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

int main(){
  int N, a1, a2;
  cin >> N;
  a1 = N / 10;
  a2 = N - (N/1000 * 1000);
  if(a1 % 111 == 0 || a2 % 111 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 3588