akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var totalnum = cin.ReadInt;
            int min= cin.ReadInt;
            int cnt = 1;

            for (int i=1;i<totalnum;i++)
            {

                int next = cin.ReadInt;

                if (next < min)
                {
                    cnt++;
                    min=next;
                }


                
            }
            WriteLine(cnt.ToString());




        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 34884
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    for(int i=0; i<R; i++) {
        cin >> r[i];
        --r[i];
    }
    vector< vector<int> > wf(N, vector<int>(N, 1000000000));
    while(M--) {
        int A, B, C;
        cin >> A >> B >> C;
        --A;
        --B;
        wf[A][B] = C;
        wf[B][A] = C;
    }

    for(int k=0; k<N; k++) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
            }
        }
    }

    vector<int> p(R);
    for(int i=0; i<R; i++) {
        p[i] = i;
    }

    int ans = INT32_MAX;
    do {
        int tmp = 0;
        for(int i=1; i<R; i++) {
            tmp += wf[r[p[i-1]]][r[p[i]]];
        }
        ans = min(ans, tmp);
    } while(next_permutation(p.begin(), p.end()));

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


Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;

		n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String snake = sc.next();
			String answer = "NA";
			int index = 0;
			if (6 <= snake.length()) {
				if (snake.charAt(0) == '>' && snake.charAt(snake.length() - 1) == '~') {
					snake = snake.substring(1, snake.length() - 1);
					if (snake.charAt(0) == '\'') {
						snake = snake.substring(1);
						if (snake.length() % 2 == 1) {
							answer = "A";
							for (int j = 0; j < snake.length(); j++) {
								if (j == snake.length() / 2 && snake.charAt(j) != '#') {
									answer = "NA";
								} else if (j != snake.length() / 2 && snake.charAt(j) != '=') {
									answer = "NA";
								}
							}
						}
					} else if (snake.charAt(0) == '^' && snake.charAt(snake.length() - 1) == '~') {
						snake = snake.substring(1, snake.length() - 1);
						if (snake.length() % 2 == 0) {
							answer = "B";
							for (int j = 0; j < snake.length(); j++) {
								if (j % 2 == 0 && snake.charAt(j) != 'Q') {
									answer = "NA";
								} else if (j % 2 == 1 && snake.charAt(j) != '=') {
									answer = "NA";
								}
							}
						}
					}
				}
			}
			System.out.println(answer);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int h1,h2,m1,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << (h2-h1)*60+m2-m1-k << "\n";
  return 0;
}



Measured memory_bytes: 3636
import java.util.*;
public class Main{
public static void main(String []args){
Scanner s=new Scanner(System.in);
  int n=s.nextInt();
  int m=s.nextInt();
  int ans=10000;
  for(int i=0;i<n;i++){
  	int k=s.nextInt();
    int b=s.nextInt();
    if(b<=m&&k<ans){
    	ans=k;
    }
  }
  if(ans==10000){System.out.println("TLE");}
  
  else System.out.println(ans);
}
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	for(int i=0; i<N; i++) cin >> A[i];

	sort(A.begin(), A.end());

	bool ans = true;
	for(int i=0; i<N-1; i++) {
		if(A[i]==A[i+1]) ans = false;
	}
	cout << (ans?"YES":"NO") << endl;

	return 0;
}


Measured memory_bytes: 1792
def resolve():
    n, m = map(int, input().split())
    if n % 2 == 0:
        x = (m + 1) // 2
        for i in range(x):
            print(x - i, x + i + 1)
        x = m // 2
        for i in range(x):
            print(n - (x - i - 1), n - (x + i + 1))
    else:
        for i in range(m):
            print(i + 1, n - i)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9204
#include<stdio.h>
int main(){
    int c=0,N, x=0, max=0;
    char S[256];
scanf("%d", &N);
scanf("%s",S);
for(c=0;c<N;c++){
    if(S[c]=='I')x++;
    else if(S[c]=='D')x--;
    if(max<x)max=x;
}
    printf("%d\n", max);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

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

// int A, B, F, H, I, J, K, L, M, N, S, T, U;
ll A, B, F, H, I, J, K, L, M, N, S, T, U;
// string S, T, U;
// int A, B;
ll ans;

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

	cin >> N >> A >> B;

	ans = A * (N / (A + B));
	ans += min(A, N % (A + B));

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

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        int x,y,temp;
        Scanner sc=new Scanner(System.in);
        while(true){
            x=sc.nextInt();
            y=sc.nextInt();
            if (x==0 && y==0) break;
            else if (x > y){
                temp=x;
                x=y;
                y=temp;
               System.out.printf("%d %d\n",x,y);
            }
            else System.out.printf("%d %d\n",x,y);
            
        }
    }
}


Measured memory_bytes: 40732
# -*- coding: utf-8 -*-

h, w = map(int, input().split())

a = [['#']+list(input())+['#'] for i in range(h)]

a.insert(0, ['#']*(w+2))
a.insert(len(a), ['#']*(w+2))

for i in range(len(a)):
    print(''.join(a[i]))


Measured memory_bytes: 3060
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#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>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
using namespace std;
int a,b,c;
ll k;
int main(){
    cin>>a>>b>>c>>k;
    if(k&1)printf("%d\n",b-a);
    else printf("%d\n",a-b);
	//system("pause");
	return 0;
}


Measured memory_bytes: 764
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
  int n, c, k, bus = 0;
  cin >> n >> c >> k;
  int t[100001] = {0};
  for (int i = 0; i < n; i++) cin >> t[i];
  sort(t, t + n);
  for (int i = 0; i < n; i++) {
    int j;
    for (j = 0; j < c; j++) {
      if (i + j + 1 >= n) break;
      if (t[i] + k < t[i + j + 1]) break;
    }
    if (j == c) j--;
    i += j;
    bus++;
  }
  cout << bus << endl;
  return 0;
}

Measured memory_bytes: 640
open Str

let rec splitSixty list a =
  match (a / 60, a mod 60) with
  | (syou, amari) ->
    if syou < 60 then syou :: amari :: list
    else splitSixty (amari :: list) syou

let rec fill list = if List.length list >= 3 then list
  else fill (0 :: list)

let rec format list = 
  match list with
  | hour :: minute :: second :: [] -> hour ^ ":" ^ minute ^ ":" ^ second
  | _ -> failwith "Error";;

read_line()
|> int_of_string
|> splitSixty []
|> fill 
|> List.map string_of_int
|> format
|> print_endline



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


signed main() {
  int N;
  cin >> N;
  
  vector<int> dp(100010);
  dp.at(0) = 0;
  for( int i = 1; i <= 100000; i++ ){
    dp.at(i) = 1000000;
    int roku = 1;
    while( roku <= i ){
      dp.at(i) = min( dp.at(i), dp.at(i-roku)+1 );
      roku *= 6;
    }
    int kyuu = 1;
    while( kyuu <= i ){
      dp.at(i) = min( dp.at(i), dp.at(i-kyuu)+1 );
      kyuu *= 9;
    }
  }
  
  cout << dp.at(N) << endl;
    
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;
template<class T> void add(T &a, T b) { (a += (b % MOD + MOD) % MOD) %= MOD; }

int main() {
    string s; cin >> s;
    int n = s.length();
    vector<vector<int>> dp(n + 1, vector<int>(4));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4; j++) {
            if (s[i] == 'A' || s[i] == '?') add(dp[i + 1][j], dp[i][j]);
            if (s[i] == 'B' || s[i] == '?') add(dp[i + 1][j], dp[i][j]);
            if (s[i] == 'C' || s[i] == '?') add(dp[i + 1][j], dp[i][j]);
        }
        {
            if (s[i] == 'A' || s[i] == '?') add(dp[i + 1][1], dp[i][0]);
            if (s[i] == 'B' || s[i] == '?') add(dp[i + 1][2], dp[i][1]);
            if (s[i] == 'C' || s[i] == '?') add(dp[i + 1][3], dp[i][2]);
        }
    }
    cout << dp[n][3] << endl;
    return 0;
}


Measured memory_bytes: 5760
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n, k = sp()
arr = l()
answer = [1]
s = {1}
index = 1
while True:
    temp = arr[answer[-1]-1]
    if temp in s:
        index = temp
        break
    s.add(temp)
    answer.append(temp)
if k <= len(answer)-1:
    out(answer[k])
    exit()
k -= (len(answer)-1)
temp = answer.index(index)
answer = answer[temp:]
k %= len(answer)
if k == 0:
    k = len(answer)
out(answer[k-1])


Measured memory_bytes: 135440
from sys import stdin
from collections import defaultdict

if __name__ == '__main__':
    n, q = map(int, stdin.readline().rstrip().split())
    ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n - 1)]
    px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(q)]

    g = defaultdict(list)
    for a, b in ab:
        a -= 1
        b -= 1
        g[a].append(b)
        g[b].append(a)

    adder = defaultdict(int)
    for p, x in px:
        p -= 1
        adder[p] += x

    ans = [float('inf')] * n
    ans[0] = adder[0]
    qu = [0]

    while qu:
        cur = qu.pop()

        for target in g[cur]:
            if ans[target] == float('inf'):
                ans[target] = ans[cur] + adder[target]
                qu.append(target)

    for _ans in ans:
        print(_ans)


Measured memory_bytes: 154396
#include<stdio.h>
#define MAX 100000
#define S 2000000000

struct C {
  char a;
  int b;
};

struct C L[MAX/2+2],R[MAX/2+2];

void merge(struct C A[],int n, int left,int mid,int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int i,j=0,k;
  // L[0...n1], R[0...n2] を生成                                                
  for(i = 0 ;i<n1;i++)L[i] = A[left + i];
  for (i = 0;i<n2;i++)R[i] = A[mid + i];

  L[n1].b = S;
  R[n2].b = S;
  i=0;
  for(k = left;k<right;k++){
      if(L[i].b <= R[j].b){
      A[k] = L[i++];

    }
    else {
      A[k] = R[j++];

    }
  }
}

void mergeSort(struct C A[],int n,int left,int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);

  }
}
int partition(struct C A[],int n,int p,int r){
  int i,j;
  struct C x,tmp;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].b<=x.b){
      i++;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;

  return i+1;
}
void quicksort(struct C A[],int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quicksort(A,n,p,q-1);
    quicksort(A,n,q+1,r);
  }
}
int main(){
  int n,i,suu,sta=1;
  struct C A[MAX],B[MAX];
  char C[10];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",C,&suu);
    A[i].a=B[i].a=C[0];
    A[i].b=B[i].b=suu;
  }

  mergeSort(A,n,0,n);
  quicksort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].a!=B[i].a)sta=0;
  }
  if(sta==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].a, B[i].b);
  }


  return 0;
}



Measured memory_bytes: 4068
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
//const int mod=1e9+7;
                     // I'm in Love with Experience. 
void solve()
{
    int N;cin>>N;
    if(N%1000==0){cout<<"0";return;}
    int m=N%1000;
    cout<< 1000-m;
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);solve();
    //int T;cin>>T;while(T--){solve();}exit(0);
}/*Solved By:- Ritik Agarwal*/

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

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    ll n;
    cin >> n;
    cout << (n * (n - 1LL) / 2) << endl;
    return 0;
}

Measured memory_bytes: 888
def calc(a,n):
    array = [[a[j]>i  for j in range(n)] for i in range(max(a))]
    mat = [[a for a,b in zip(row,row[1:]+[False]) if a and a!=b]for row in array]
    return sum([len(row)for row in mat])
n = int(input())
a = [int(e) for e in input().split()]

print(calc(a,n))

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

int main(){
  long long int a,b,k;
  cin >> a >> b >> k;
  if(k<=a)
    cout << a-k << " " << b << endl;
  else if(k<=a+b)
    cout << 0 << " " << b+a-k << endl;
  else
    cout << 0 << " " << 0 << endl;
}

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

using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//
//using namespace __gnu_pbds;
//template<typename dtype> using ordered_set = tree<dtype, null_type, less<dtype>, rb_tree_tag, tree_order_statistics_node_update>;

class Timer {
    clock_t start;
    string name;
public:
    Timer() {name = "";start = clock();}
    Timer(string s){name = s;start = clock();}
    ~Timer() {fprintf(stderr, "%s: %.3gs\n", name.c_str(), 1.0*(clock() - start) / CLOCKS_PER_SEC);}
};

//#define isValid(a, b) (a >= 0 && a < b)
//int dr[]  =  {0, -1, -1, -1,  0,  1, 1, 1};
//int dc[]  =  {1,  1,  0, -1, -1, -1, 0, 1};

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define what_is(x) cerr << fixed << setprecision(2) << boolalpha << #x << " = " << x << endl

const double EPS = 1e-9;
const double PI = acos(-1.0L);

template<typename dtype> inline dtype sq(dtype a){return a*a;}
template<typename dtype1, typename dtype2> inline pair<dtype1, dtype2> mp(dtype1 a, dtype2 b){return make_pair(a, b);}
template<typename dtype1, typename dtype2> inline dtype1 safeMod(dtype1 a, dtype2 m){return (a%m + m)%m;}/*handling negative sign of remainder*/
template<typename dtype1, typename dtype2> inline bool isEq(dtype1 a, dtype2 b){return abs(a - b) < EPS;}
template<typename dtype1, typename dtype2, typename dtype3> inline bool isEq(dtype1 a, dtype2 b, dtype3 eps){return abs(a - b) < eps;}
template<typename dtype> inline bool isKthBitOn(dtype n, int k){assert(n <= numeric_limits<dtype>::max());assert(k<=numeric_limits<dtype>::digits);dtype ONE = 1;return bool((n & (ONE<<k)));}
template<typename dtype> inline void setKthBit(dtype& n, int k){assert(n <= numeric_limits<dtype>::max());assert(k<=numeric_limits<dtype>::digits);dtype ONE = 1;n = (n|(ONE<<k));}

#define toRad(deg) ((deg)*PI/180.0)
#define toDeg(rad) ((rad)*180.0/PI)

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

const int oo = 0x3f3f3f3f;
const int MAX = 200010;
const int MOD = 1000000007;
const int precision = 10;

int main(int argc, char* argv[])
{
    //assert(freopen("in.txt", "r", stdin));
    //assert(freopen("out.txt", "w", stdout));
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    //cout << fixed << setprecision(precision);
    int n;
    cin >> n;
    vector<int>v(n);
    int sum = 0;
    for(int &x:v){
        cin >> x;
        sum += x;
    }
    int ss = 0;
    int diff = oo;
    for(int i = 0; i < n; i++){
        ss += v[i];
        sum -= v[i];
        diff = min(diff, abs(sum - ss));
    }
    cout << diff;
    return 0;
}


Measured memory_bytes: 256
s=(input())
pap,rk=0,0
sm=0
for el in s:
    if(el=='g'):#rock
        if(pap+1<=rk):
            sm+=1
            pap+=1
        else:
            sm+=0
            rk+=1
    else:
        if(pap+1<=rk):
            sm+=0
            pap+=1
        else:
            sm-=1
            rk+=1
print(sm)


Measured memory_bytes: 9172
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
 int main(void){
     int N;
     cin >> N;
     int count[N+10]={},ma=0,si=0;
     for(int i=1; i<=N; i++){
         int a=i;
         while(a%2==0){
             count[i]+=1;
             a/=2;
         }
         if(ma <= count[i]){
             ma=count[i];
             si=i;
         }
     }
    cout << si << endl;
 }


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

using namespace std;

typedef unsigned long long u64;

int gcd(int a, int b)
{
	while (b != 0)
	{
		int r = a % b;
		a = b;
		b = r;
	}

	return a;
}

int main()
{
	u64 n, m;
	string s, t;

	cin >> n >> m;
	cin >> s >> t;

	if (s[0] != t[0])
	{
		cout << -1 << endl;
		return 0;
	}

	int g = gcd(n, m);
	
	u64 l = n * m / g;
	u64 p = l / n;
	u64 q = l / m;
	u64 v = p * q;

	for (u64 i = 0; i < l; i += v )
	{
		if (s[i / p] == t[i / q])
		{
			continue;
		}

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

	cout << l << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string s, t;
    cin >> s >> t;

    string S = s + s;
    ll ns, nt;
    ns = s.size(); nt = t.size();
    vector<vector<ll>> order(26);
    Rep (i, ns * 2) {
        order[S[i] - 'a'].push_back(i);
    }

    // Rep (i, 26) {
    //     for (auto e : order[i]) {
    //         cout << 'a' + i << " " << e << endl;
    //     }
    // }

    ll now = -1;
    ll cnt = 0;
    Rep (i, nt) {
        ll target = t[i] - 'a';
        if (order[target].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        auto itr = upper_bound(order[target].begin(), order[target].end(), now % ns);
        ll idx = *itr;
        // cout << t[i] << " idx:" << idx << endl;
        now = now - now % ns + idx;
        // cout << t[i] << " " << now << endl;
    }
    cout << now + 1 << endl;
}

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

int N;
int a[210];

int main() {
	cin >> N;
	N += N;
	for (int i = 0; i < N; ++i)
		cin >> a[i];
	sort (a, a + N);
	int answer = 0;
	for (int i = 0; i < N; i += 2)
		answer += a[i];
	cout << answer << "\n";
	return 0;
}

Measured memory_bytes: 256
n=int(input())

if n==2:
    print(-1)
else:
    x=[]
    if n%3==0:
        for i in range(n//3):
            x.append("."*(3*i)+"a"+"."*(n-3*i-1))
            x.append("."*(3*i)+"a"+"."*(n-3*i-1))
            x.append("."*(3*i)+".aa"+"."*(n-3*i-3))
    elif n%6==1:
        for i in range(n//6-1):
            x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
            x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
            x.append("."*(6*i)+"ddg.ll"+"."*(n-6*i-6))
            x.append("."*(6*i)+"e.g.kk"+"."*(n-6*i-6))
            x.append("."*(6*i)+"e.hhj."+"."*(n-6*i-6))
            x.append("."*(6*i)+"ffiij."+"."*(n-6*i-6))
        x.append("."*(n-7)+".aab.c.")
        x.append("."*(n-7)+"d..b.c.")
        x.append("."*(n-7)+"d..eeff")
        x.append("."*(n-7)+"g..mm.l")
        x.append("."*(n-7)+"gnn...l")
        x.append("."*(n-7)+"h...kkj")
        x.append("."*(n-7)+"hii...j")
    elif n%6==2:
        for i in range(n//6-1):
            x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
            x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
            x.append("."*(6*i)+"ddg.ll"+"."*(n-6*i-6))
            x.append("."*(6*i)+"e.g.kk"+"."*(n-6*i-6))
            x.append("."*(6*i)+"e.hhj."+"."*(n-6*i-6))
            x.append("."*(6*i)+"ffiij."+"."*(n-6*i-6))
        x.append("."*(n-8)+".a.bb.cc")
        x.append("."*(n-8)+".a...m.j")
        x.append("."*(n-8)+"..pp.m.j")
        x.append("."*(n-8)+"hh..i.o.")
        x.append("."*(n-8)+"gg..i.o.")
        x.append("."*(n-8)+"..n.ll.k")
        x.append("."*(n-8)+"f.n....k")
        x.append("."*(n-8)+"f.dd.ee.")
    elif n%6==4:
        for i in range(n//6):
            x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
            x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
            x.append("."*(6*i)+"ddg.ll"+"."*(n-6*i-6))
            x.append("."*(6*i)+"e.g.kk"+"."*(n-6*i-6))
            x.append("."*(6*i)+"e.hhj."+"."*(n-6*i-6))
            x.append("."*(6*i)+"ffiij."+"."*(n-6*i-6))
        x.append("."*(n-4)+"aacb")
        x.append("."*(n-4)+"ffcb")
        x.append("."*(n-4)+"hgdd")
        x.append("."*(n-4)+"hgee")
    else:
        for i in range(n//6):
            x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
            x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
            x.append("."*(6*i)+"ddg.ll"+"."*(n-6*i-6))
            x.append("."*(6*i)+"e.g.kk"+"."*(n-6*i-6))
            x.append("."*(6*i)+"e.hhj."+"."*(n-6*i-6))
            x.append("."*(6*i)+"ffiij."+"."*(n-6*i-6))
        x.append("."*(n-5)+"aabbc")
        x.append("."*(n-5)+"g.h.c")
        x.append("."*(n-5)+"gjh..")
        x.append("."*(n-5)+"dj.ii")
        x.append("."*(n-5)+"deeff")
    for i in range(n):
        print("".join(x[i]))

#また出力が違うやつをやりましたが


Measured memory_bytes: 5364
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let n=t.n()
  let nr=t.n(n)
  let m=t.max(...nr)
  t.o(m<nr.reduce((t,d)=>{return t+d})-m?'Yes':'No')
}
main()

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
//const int PI = acos(-1);
int main(){
	int n;cin>>n;
	vl a(n);
	rep(i,n)cin>>a[i];
	sort(been(a));
	int ans =1;
	ll sum[n];
	sum[0]=a[0];
	rep(i,n){
		if(i==0)continue;
		sum[i]=sum[i-1]+a[i];
		if(sum[i-1]*2<a[i])ans=0;
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    print((n+1)//2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
//cout << std::fixed << std::setprecision(15);
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e9;
const long long MOD = 1e9+7;
signed main(){
    int n; cin >> n;
    set<int> set;
    vint a(n); rep(i,n) {cin >> a[i]; set.insert(a[i]);}
    if(set.size()==n) coutY;
    else coutN;
}

Measured memory_bytes: 11136
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	string s;
	cin >> s;
	REP(i, 19) {
		if (i == 5 || i == 13) {
			cout << " ";
		}
		else
			cout << s[i];
	}
	cout << endl;
	
	return 0;
}



Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

#define EPS 1e-8
#define EQ (abs((a) - (b)) < EPS)
#define re() real()
#define im() imag()

inline int signum(double x) { return abs(x) < EPS ? 0 : x > 0 ? 1 : -1; };

typedef complex<double> P;
typedef pair<P, P> L;
typedef vector<P> Poly;

//constないとError
namespace std {
    bool operator<(const P &a, const P &b) {
        return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
    }
}

double dot(P a, P b) {
    return a.real() * b.real() + a.imag() * b.imag();
}

double cross(P a, P b) {
    return a.real() * b.imag() - a.imag() * b.real();
}

int ccw(P a, P b, P c) {
    b -= a;
    c -= a;
    int sign = signum(cross(b, c));
    if (abs(sign) == 1) return sign;
    if (signum(dot(b, c)) < 0) return -2;
    if (abs(b) < abs(c)) return 2;
    return 0;
}

double poly_diameter(Poly poly) {
    int n = poly.size();
    if (n == 2) return abs(poly[0] - poly[1]);

    int i = 0, j = 0;
    for (int k = 0; k < n; k++) {
        if (!(poly[i] < poly[k])) i = k;
        if (poly[j] < poly[k]) j = k;
    }

    double res = 0;
    int si = i, sj = j;
    while (i != sj || j != si) {
        res = max(res, abs(poly[i] - poly[j]));
        if (cross(poly[(i + 1) % n] - poly[i], poly[(j + 1) % n] - poly[j]) < 0) i = (i + 1) % n;
        else j = (j + 1) % n;
    }

    return res;
}

int main() {

    int N;
    cin >> N;

    Poly poly(N);
    for (int i = 0; i < N; i++) {
        double x, y;
        cin >> x >> y;
        poly[i] = P(x, y);
    }

    cout << fixed << setprecision(10) << poly_diameter(poly) << endl;

}














































Measured memory_bytes: 5556
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const ll c=1e3,cn=1e7,con=1e4;
const ll mod=1e9+7;
int nm,m,cntr=1e9,pos=0,cntr2=0,sum=0,temp;
vector<pair<int,pair<int,int> > >v;
vector<int>ve;
bool lef[cn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k,a;
    cin>>n>>k;
    ll ans=0,j=0;
    for(int i=0;i<n;i++){
        cin>>a;
        ve.push_back(a);
    }
   // sort(ve.begin(),ve.end());
    while(j<n-1){
        ans+=k;
        j+=(k-1);
        //cout<<j<<" "<<ans<<endl;
    }
    cout<<ans/k;
    return 0;
}


Measured memory_bytes: 892
#include <iostream>

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;

	int count = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i]) {
			count++;
		}
	}
	cout << count << endl;

}





Measured memory_bytes: 3596
#include<stdio.h>

int main() {
	int n;
	float a, b, c, d, e, f, g, h;
	scanf("%d", &n);
	for (int i = 0; i < n;i++){ 
		int Bool = 0;
		scanf("%f %f %f %f %f %f %f %f", &a, &b, &c, &d, &e, &f, &g, &h);
		if (a == c || e == g) {
			if (a == c && e == g)Bool = 1;
		}
		else {
			if ((b - d) / (a - c) == (f - h) / (e - g))Bool = 1;
		}
		if (Bool == 1) {
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,sum=0;
    cin>>n;
    string s= to_string(n); 
    for(int i=0;i<s.length();i++)
    {
        sum+=s[i]-'0';
    }
    if(n%sum==0)
    {
        cout<<"Yes"<<"\n";
    }
    else
    {
        cout<<"No"<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3700
#include <iostream>
using namespace std;
int main()
{
    int h , n,sum =0;
    cin >> h >> n;
    int a[n];
    for (int i = 0 ; i < n ; i++ ){
       cin >> a[i];
       sum = sum +a[i]  ;
    }
    if (h - sum <= 0){cout << "Yes"<<endl;}
    else {cout <<"No"<<endl;}
    return 0;
}


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

int main()
{
ll n ;
cin >> n ;
string s ;
cin >> s ;
vector<ll> sum(3);
vector<vector<ll>> v(10, vector<ll>(3,0) );
rep(i,n){
  ll t=s[i]-'0';
  sum[2]+=sum[1]-v[t][2];
  v[t][2]=sum[1];
  sum[1]+=sum[0]-v[t][1];
  v[t][1]=sum[0];
  if(v[t][0]==0){
    v[t][0]=1;
    sum[0]++;
  }
}

cout << sum[2] << endl;
return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        String s = String.valueOf(N);

        if(s.charAt(0) == '7' || s.charAt(1) == '7' || s.charAt(2) == '7' )
            os.println("Yes");
        else
            os.println("No");
    }
}

Measured memory_bytes: 27076
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,m) = get!(usize, usize);
    let xyz = get!(usize, usize, usize; m);

    let mut nodes = vec![Vec::new(); n+1];
    for (x,y,_) in xyz {
        nodes[x].push(y);
        nodes[y].push(x);
    }

    let mut queue = VecDeque::new();
    let mut visited = BTreeSet::new();

    let mut count = 0;
    for i in 1..n+1 {
        if visited.contains(&i) {
            continue;
        }
        count += 1;
        queue.push_back(i);
        visited.insert(i);
        while let Some(node) = queue.pop_front() {
            for &next in &nodes[node] {
                if visited.contains(&next) {
                    continue;
                }
                visited.insert(next);
                queue.push_back(next);
            }
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 20732
///                ..:: In The Name Of God ::..
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define endl    '\n' 
#define INF 2e9
#define int ll
#define vi          vector<int>
#define de          deque<int>
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()//全範囲指定を簡略化

typedef long long ll;

using namespace std;

//配列の要素数は　sizeof(ar)/sizeof(ar[0]) で求める

signed main(){

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

    int X, A;
    cin >> X >> A;
    if (X < A)
    {
        cout << 0 << endl;
    }
    else if (X >= A)
    {
        cout << 10 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
s = gets.strip

s.length.times do |i|
  if(s[i] == "L" && i % 2 == 0)
    puts "No"
    break
  elsif(s[i] == "R" && i % 2 != 0)
    puts "No"
    break
  end
  
  if(i == s.length - 1)
    puts "Yes"
  end
end

Measured memory_bytes: 1788
///https://atcoder.jp/contests/abc065/tasks/arc076_b
#include<bits/stdc++.h>
#define fast_read ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define For(i,a,b) for(int i = a; i <= b;i++)
#define Forr(i,a,b) for(int i = a;i >= b;i--)
#define fi first
#define se second
#define maxn 200005
#define ll long long
#define INF 1e18
using namespace std;

int P[maxn],h[maxn];

struct edge
{
    int u,v;
    ll d;
} e[maxn];

int n;

struct point
{
    ll x,y;
    int id;
} p[maxn];

ll len(point u,point v)
{
    return min(abs(u.x - v.x),abs(u.y - v.y));
}

void make_set(int i)
{
    P[i] = i;
    h[i] = 0;
}

int Find(int i)
{
    while(i != P[i]) i = P[i];
    return i;
}

bool Union(int u,int v)
{
    int x = Find(u);
    int y = Find(v);
    if(x == y) return false;
    if(h[x] < h[y]) P[x] = y;
    else
    {
        P[y] = x;
        if(h[x] == h[y]) h[x]++;
    }
    return true;
}

bool cmp1(point u,point v)
{
    return u.x < v.x;
}

bool cmp2(point u,point v)
{
    return u.y < v.y;
}

bool cmp(edge x,edge y)
{
    return x.d < y.d;
}

int main()
{
    fast_read;
    cin >> n;
    For(i,1,n)
     {
         cin >> p[i].x >> p[i].y;
         p[i].id = i;
     }
    int cnt = 0;
    sort(p+1,p+1+n,cmp1);
    For(i,1,n-1)
    {
        int u = p[i].id;
        int v = p[i+1].id;
        e[++cnt] = {u,v,len(p[i],p[i+1])};
    }
    sort(p+1,p+1+n,cmp2);
    For(i,1,n-1)
    {
        int u = p[i].id;
        int v = p[i+1].id;
        e[++cnt] = {u,v,len(p[i],p[i+1])};
    }
    For(i,1,n) make_set(i);
    int t = 0;
    ll ans = 0;
    sort(e+1,e+1+cnt,cmp);
    For(i,1,cnt)
        if(Union(e[i].u,e[i].v))
        {
            t++;
            ans += e[i].d;
            if(t == n-1) break;
        }
    cout << ans << endl;
}

Measured memory_bytes: 8832
import java.lang.reflect.Array;
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

  static int N;
  static int K;
  static long Q;
  static int A;
  static long B;
  static long C;
  static double min = 9999999;
  static long ans = 0;




  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int[] map = new int[N];
    for (int i = 0; i < N; i++) {
      map[i] = scanner.nextInt();

    }

    Arrays.sort(map);
//    System.out.println(map[0]);
    int total = 0;
    for (int i = 0; i < N -1; i++) {
      total += map[i];
    }

    if(total > map[N - 1]){
        System.out.println("Yes");
      }else{
        System.out.println("No");
    }
  }



}


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

const float PI = acos(-1);

int main() {
    float a, b, x;
    cin >> a >> b >> x;
    float val;
    float unit_r = 180.0 / PI; // rad -> 度
    if (x >= (a*a*b) / 2) {
        val = 2.0*(a*a*b-x) / (a*a*a);
    } else {
        val = (a*b*b) / (2.0*x);
    }
    float ans = atan(val) * unit_r;
    printf("%.10f", ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
signed main(){
    fast();
    string a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i=0; i<a.length(); i++){
        if(a[i] != b[i]){
            ans++;
        }
    }
    cout << ans << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 3904
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
typedef long long ll;
typedef unsigned un;
typedef std::string str;
typedef std::pair<ll,ll> pll;
typedef std::pair<int,int> pii;
typedef std::pair<double,double> pd;
ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
void umax(int& a,int t){if(t>a)a=t;}
bool umin(ll& a,ll t){if(t<a)return a=t,1;return 0;}
#define MAXN 55
ll c[MAXN][MAXN];
int main()
{
    int n=read();
    for(int i=1;i<=n;++i)
    {
        double x;scanf("%lf",&x);
        ll y=ll(x*1e9+0.5);
        ll c2=0,c5=0;
        while(y%2==0&&c2<18)y/=2,++c2;
        while(y%5==0&&c5<18)y/=5,++c5;
        ++c[c2][c5];
    }
    ll ans=0;
    for(int x1=0;x1<=18;++x1)
        for(int y1=0;y1<=18;++y1)
            for(int x2=0;x2<=18;++x2)
                for(int y2=0;y2<=18;++y2)
                    if(x1+x2>=18&&y1+y2>=18)
                    {
                        ans+=c[x1][y1]*c[x2][y2];
                        if(x1==x2&&y1==y2)ans-=c[x1][y1];
                    }
    printf("%lld",ans>>1);
    return 0;
}

Measured memory_bytes: 3776
N = int(input().strip())

x = (int(input().strip()), 0)
y = (int(input().strip()), 1)
if x[0] > y[0]:
  x, y = y, x

for i in range(2, N):
  a = int(input().strip())
  if a > x[0]:
    if a > y[0]:
      x = y
      y = (a, i)
    else:
      x = (a, i)

for i in range(N):
  if i == y[1]:
    print(x[0])
  else:
    print(y[0])

Measured memory_bytes: 4540
def main():
    a,b,c,k = map(int, input().split())
    ans = 0
    if k > 0:
        ans += min(a,k)*1
        k -= min(a,k)
    if k > 0:
        k -= min(b,k)
    if k > 0:
        ans += min(c,k)*(-1)
        k -= min(c,k)
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 9132
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

int prim(){
  int u, minv;
  int d[MAX], p[MAX], color[MAX];

  for(int i=0; i<n; i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    for(int i=0; i<n; i++){
      if(minv > d[i] && color[i] != BLACK){
        u = i;
        minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    for(int v=0; v<n; v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
        if(d[v] > M[u][v]){
          d[v] = M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
  int sum = 0;
  for(int i=0; i<n; i++){
    if(p[i] != -1) sum += M[i][p[i]];
  }

  return sum;
}

int main(){
  cin >> n;

  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      int e; cin >> e;
      M[i][j] = (e == -1) ? INFTY : e;
    }
  }

  cout << prim() << endl;

  return 0;
}



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


int main() {
long long A,B,K;
  cin>>A>>B>>K;

long long X=0;
  
  if(A>=K){
    
  cout<<A-K<<" "<<B<<endl;
  }else if(A<K){
    X=K-A;
    if(B>=X){
    cout<<0<<" "<<B-X<<endl;
  }else{cout<<0<<" "<<0<<endl;
       }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
  int a,b;
  cin >> a >> b;
  if (a > b) {
    cout << a - 1 << endl;
  } else {
    cout << a << endl;
  }
}


Measured memory_bytes: 256