akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <random>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef RUS_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef RUS_HOME
    freopen("input", "r", stdin);
    //freopen("output.txt", "w", stdout);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

const int MOD=1e9+7,N=2e5+100;

void smain() {


    int n;
    cin>>n;
    vpi a(n);
    for(int i=0;i<n;i++){
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(ALL(a));
    int ans=0;
    for(int i=0;i<n;i++){
        if(abs(i-a[i].second)&1)
            ans++;
    }
    cout<<ans/2;
}


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

typedef long long ll;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define debug(x) cout << '>' << #x << ':' << x << "\n";
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair



int main() {
    string s,t;
    int count=0;
    cin >> s;
    cin >> t;
    for(int i=0;i<s.length();i++){
        if(s[i]==t[i]){
            count++;
        }
    }
    cout << count;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a[5];
    int k;
    for(int i=0;i<5;i++){
    cin>>a[i];
    }
    cin>>k;
    
    for(int i=0;i<5;i++){
        for(int j=0;j<5-i;j++){
     if(abs(a[i]-a[j])>k){
         cout<<":("<<endl;
         return 0;
     }
     }
    }
    
    cout<<"Yay!"<<endl;
    
}

Measured memory_bytes: 256
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
  int N, count = 0;
  cin >> N;
  int a[N];
  REP(i,N){
    cin >> a[i];
  }
  for (int i = 0; i <= N; i = i+2){
    if (a[i]%2 != 0){
      count += 1;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3612
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        a: String, s: String, b: String,
    }

    println!("A{}C", &s[0..1]);
}


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

alphabet = set(s)
if any(c not in alphabet for c in t):
    print(-1)
    exit()

N = len(s)

# leftmost[c] = the position of the leftmost c
leftmost = {}
for i, c in enumerate(s):
    if c not in leftmost:
        leftmost[c] = i


# next[i][c] = the position of the next appearance of c
next = [None for i in range(N)]
next[N - 1] = {c: N + leftmost[c] for c in alphabet}
for i in range(N - 2, -1, -1):
    next[i] = {c: i + 1 if s[i + 1] == c else next[i + 1][c]
                  for c in alphabet}

pos = leftmost[t[0]]
for c in t[1:]:
    pos = pos - (pos % N) + next[pos % N][c]

print(pos + 1)


Measured memory_bytes: 168372
class dise:
    def __init__(self, label):
        self.label1 = label[0]
        self.label2 = label[1]
        self.label3 = label[2]
        self.label4 = label[3]
        self.label5 = label[4]
        self.label6 = label[5]
    
    def N_rotation(self):
        reg = self.label1
        self.label1 = self.label2
        self.label2 = self.label6
        self.label6 = self.label5
        self.label5 = reg
        
    def E_rotation(self):
        reg = self.label1
        self.label1 = self.label4
        self.label4 = self.label6
        self.label6 = self.label3
        self.label3 = reg
        
    def S_rotation(self):
        reg = self.label1
        self.label1 = self.label5
        self.label5 = self.label6
        self.label6 = self.label2
        self.label2 = reg
        
    def W_rotation(self):
        reg = self.label1
        self.label1 = self.label3
        self.label3 = self.label6
        self.label6 = self.label4
        self.label4 = reg

dise1 = dise(input().split())
order = list(input())

for i in order:
    if i == 'N':
        dise1.N_rotation()
    elif i == 'E':
        dise1.E_rotation()
    elif i == 'S':
        dise1.S_rotation()
    elif i == 'W':
        dise1.W_rotation()

print(dise1.label1)

Measured memory_bytes: 7592
sx, sy, tx, ty = map(int, input().split())
x = tx - sx
y = ty - sy
ans = ""
ans += "R" * x + "U" * y + "L" * x + "D" * y
ans += "D" + "R" * (x + 1) + "U" * (y + 1) + "L"
ans += "U" + "L" * (x + 1) + "D" * (y + 1) + "R"
print(ans)




Measured memory_bytes: 3064
// C++ program to count number of triangles that can be 
// formed from given array 
#include <bits/stdc++.h> 
using namespace std; 

/* Following function is needed for library function 
qsort(). Refer 
http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/ */
int comp(const void* a, const void* b) 
{ return *(int*)a > *(int*)b ; } 

// Function to count all possible triangles with arr[] 
// elements 
int findNumberOfTriangles(int arr[], int n) 
{ 
	// Sort the array elements in non-decreasing order 
	qsort(arr, n, sizeof( arr[0] ), comp); 

	// Initialize count of triangles 
	int count = 0; 

	// Fix the first element. We need to run till n-3 
	// as the other two elements are selected from 
	// arr[i+1...n-1] 
	for (int i = 0; i < n - 2; ++i) 
	{ 
		// Initialize index of the rightmost third 
		// element 
		int k = i + 2; 

		// Fix the second element 
		for (int j = i + 1; j < n; ++j) 
		{ 
			// Find the rightmost element which is 
			// smaller than the sum of two fixed elements 
			// The important thing to note here is, we 
			// use the previous value of k. If value of 
			// arr[i] + arr[j-1] was greater than arr[k], 
			// then arr[i] + arr[j] must be greater than k, 
			// because the array is sorted. 
			while (k < n && arr[i] + arr[j] > arr[k]) 
			++k; 

			// Total number of possible triangles that can 
			// be formed with the two fixed elements is 
			// k - j - 1. The two fixed elements are arr[i] 
			// and arr[j]. All elements between arr[j+1]/ to 
			// arr[k-1] can form a triangle with arr[i] and arr[j]. 
			// One is subtracted from k because k is incremented 
			// one extra in above while loop. 
			// k will always be greater than j. If j becomes equal 
			// to k, then above loop will increment k, because arr[k] 
			// + arr[i] is always greater than arr[k] 
			if(k > j) 
			count += k - j - 1; 
		} 
	} 

	return count; 
} 

// Driver code 
int main() 
{ 
  int n;
  cin>>n;
  int arr[n];
  long long int ans;
  for(int i=0;i<n;i++)
    cin>>arr[i];
  ans=findNumberOfTriangles( arr, n );
	cout<<ans; 

	return 0; 
} 


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

long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

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

int main() {

  long long n;
  cin >> n;

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

  long long answer = a[0];
  
  for (int i = 1; i < n; i++) {
    answer = lcm(answer, a[i]);
  }

  cout << answer << endl;

  return 0;

}


Measured memory_bytes: 3104
def colorchange(i,l,r,col):
    k=i-1
    while(k>=0):
        if not '#' in G[k]:
            for j in range(l+1,r+1):
                A[k][j]=col
        else:
            break
        k-=1
    k=i+1
    while(k<H):
        if not '#' in G[k]:
            for j in range(l+1,r+1):
                A[k][j]=col
        else:
            break
        k+=1
        

H,W,K=map(int,input().split())
G=[list(input()) for i in range(H)]
s=set()
A=[[-1]*W for i in range(H)]
now=1
for i in range(H):
    if not '#' in G[i]:
        continue
    last=-1
    first=True
    for j in range(W):
        if G[i][j]=='#' and j==0:
            first=False
        A[i][j]=now
        if j==W-1:
            colorchange(i,last,j,now)
            now+=1
        elif G[i][j+1]=='#':
            if first:
                first=False
            else:
                colorchange(i,last,j,now)
                last=j
                now+=1
for i in range(H):
    print(*A[i])

Measured memory_bytes: 8208
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;
#define ll long long
 
inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();}
	while(c<='9'&&c>='0'){x=x*10+c-48;c=getchar();}
	return x*f;
}
 
inline ll llread()
{
	ll x=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();}
	while(c<='9'&&c>='0'){x=x*10+c-48;c=getchar();}
	return x*f;
}

int k,n;
int c[505][505];

int main()
{	
	int i,j,x,y,step,a,b;
	k=read();
	if(k<=5)
	{
		printf("%d\n",k);
		for(i=1;i<=k;i++)
		{
			for(j=1;j<k;j++)
				printf("%d ",i);
			printf("%d\n",i);
		}
	}
	else if(k%4==0)
	{
		n=k>>1;
		printf("%d\n",n);
		for(i=1;i<=n;i++)
		{
			for(j=1;j<n;j++)
				printf("%d ",j+(i&1)*n);
			printf("%d\n",n+(i&1)*n); 
		}
	}
	else
	{ 
		n=(k/4+1)*2;
		printf("%d\n",n);
		for(i=1;i<=n;i++)
		{
			x=1;y=i; step=1;
			a=b=i;
			if(i+n<=k)
				b=i+n;
			for(j=1;j<=n;j++)
			{
				if(step)
					c[x][y]=a;	
				else
					c[x][y]=b;
				step^=1;
				x++;y++;
				if(x==n+1) x=1;
				if(y==n+1) y=1;
			}	
		}
		for(i=1;i<=n;i++)
		{
			for(j=1;j<n;j++)
				printf("%d ",c[i][j]);
			printf("%d\n",c[i][n]); 
		}
	}
	
	return 0;
} 

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

int main() {
  char b;
  cin >> b;
  char res;
  if (b == 'A') res = 'T';
  else if (b == 'T') res = 'A';
  else if (b == 'C') res = 'G';
  else res = 'C';
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
a = abs(abs(x)-abs(y))
if y == 0:
  if x >= 0:
    ans = a + 1
  else:
    ans = a
elif abs(x) <= abs(y):
  if x >= 0 and y >= 0:
    ans = a
  elif x < 0 and y < 0:
    ans = a + 2
  else:
    ans = a + 1
else:
  if x < 0 and y < 0:
    ans = a
  elif x >= 0 and y >= 0:
    ans = a + 2
  else:
    ans = a + 1
print(ans)

Measured memory_bytes: 38256
open System
open System.Numerics

// prelude
let readStr () = stdin.ReadLine()

let read f () = readStr() |> f
let reads f () = readStr().Split() |> Array.map f

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let readPair f g () =
  let (a,b) = readStr().Split() |> pair
  (f a, g b)

let readTriple f g h () =
  let (a,b,c) = readStr().Split() |> triple
  (f a, g b, h c)

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let N = read int ()
let A = reads int64 ()
let MAX = BigInteger(1e18)
A
|> Array.fold (
  fun (v,o) x ->
    let y = v * BigInteger(x)
    (
      (if y>MAX then 1I else y),
      (if y>MAX then true else o)
    )
) (1I, false)
|> fun (v,o) -> if o && v<>0I then -1I else v
|> int64
|> printfn "%d"

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

int main(){
  int N,L;
  cin >> N >> L;
  vector<int> p(N);
  int goukei=0;
  for (int i=0;i<N;i++){
    p[i]=L+i;
    goukei +=p[i];
  }
  
  int ans = 1e9;
  
  for (int i=0;i<N;i++){
    int t = goukei-p[i];
    if(abs(t-goukei)<abs(ans-goukei))ans=t;
  }
  cout<< ans <<endl;
}
  


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

template<class Monoid> struct SegTree {
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid UNITY;
    int SIZE_R;
    vector<Monoid> dat;
    
    SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
    void init(int n) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, UNITY);
    }
    
    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
    void build() {
        for (int k = SIZE_R - 1; k > 0; --k)
            dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* update a, a is 0-indexed */
    void update(int a, const Monoid &v) {
        int k = a + SIZE_R;
        dat[k] = v;
        while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* get [a, b), a and b are 0-indexed */
    Monoid get(int a, int b) {
        Monoid vleft = UNITY, vright = UNITY;
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if (left & 1) vleft = F(vleft, dat[left++]);
            if (right & 1) vright = F(dat[--right], vright);
        }                                                                                                              
        return F(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }
    
    /* debug */
    void print() {
        for (int i = 0; i < SIZE_R; ++i) {
            cout << (*this)[i];
            if (i != SIZE_R-1) cout << ",";
        }
        cout << endl;
    }
};


const int MAX = 110000;
const long long INF = 1LL<<60;

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

    using pll = pair<long long, long long>;
    auto f = [](pll a, pll b){return max(a, b);};
    SegTree<pll> rmq(MAX, f, pll(-INF, -INF));
    rmq.update(0, pll(0, 0));
    for (int i = 0; i < N; ++i) {
        auto p = rmq.get(0, A[i]);
        rmq.update(A[i], pll(p.first + 1, p.second + A[i]));
    }
    pll res(0, -INF);
    for (int v = 0; v < MAX; ++v) {
        auto pi = rmq.get(v, v+1);
        if (pi.second < 0) continue;
        res = max(res, pi);
    }
    cout << res.second << endl;
}                                        



Measured memory_bytes: 7572
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def mapline(t = int):
    return map(t, sysread().split())
def mapread(t = int):
    return map(t, read().split())

def run():
    N, *A = mapread()
    ans = 1
    current = [0,0,0]
    for a in A:
        transition = 0
        cache = 0
        for i, c in enumerate(current):
            if c == a:
                transition += 1
                cache = i
        ans *= transition
        ans %= mod
        current[cache] += 1
        #print(current)
    print(ans)

if __name__ == "__main__":
    run()


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

int main()
{
	int n, max, min;
	
	cin >> n;
	
	int a[n];
	
	cin >> a[0];
	min = a[0];
	max = a[0];

	for (int i = 1; i < n; i++)
	{
		cin >> a[i];
		if (max < a[i]){max = a[i];}
		if (min > a[i]){min = a[i];}
	}
	
	cout << max - min << endl;
	
}


Measured memory_bytes: 256
program main
  implicit none
  integer(8) :: w, h, x, y, fuku
  real(8) :: half_area
  read (*, *) w, h, x, y
  half_area = w * h * 0.5d0
  if (x * 2 == w .and. y * 2 == h) then
    fuku = 1
  else
    fuku = 0
  end if
  write (*, "(f0.1, ' ', i0)") half_area, fuku
end program main


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    a,b,k=map(int,input().split())
    for i in range(k):
        if i%2==0:
            val=a//2
            a=val
            b+=val
        else:
            val=b//2
            b=val
            a+=val
    print(a,b)


    
resolve()

Measured memory_bytes: 38256
N = int(input())
ans=0
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

for i in range(N):
  ans+=B[A[i]-1]
  if(i<N-1 and A[i]+1==A[i+1]):
    ans += C[A[i]-1]
    
print(ans)

Measured memory_bytes: 3064
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 2e5 + 7;
int n, a[N];
ll ans;

int main() {
	rd(n), rda(a, n);
	for (int i = 1; i <= n; i++)
		if (a[i] >= i || a[i] - a[i-1] > 1) return print(-1), 0;
	for (int i = 1; i <= n; i++)
		if (i == n || a[i] != a[i+1] - 1) ans += a[i];
	print(ans);
	return 0;
}

Measured memory_bytes: 6252
#include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(LL 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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL int
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
 
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
int main(){
	LL n;
	cin >> n;
 
	vector<LL> b;
 
	REP(i, n){
		LL x;
		cin >> x;
	
		if((i % 2 == 0 && n % 2 == 0) ||
			(i % 2 == 1 && n % 2 == 1)){
			b.pb(x);
		}else{
			b.insert(b.begin(), x);
		}
	}
 
	REP(i, n){
		cout << b[i];
		if(i != n - 1){
			cout << " ";
		}
	}
	cout << endl;
 
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll N; cin >> N;

    ll ans = 1;

    ll A[100005];

    for (int i = 0;i < N;i++){
        cin >> A[i];
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }

    double ansd = 1.0;

    for (int i = 0;i < N;i++){
        //ll A; cin >> A;
        ans *= A[i];
        ansd *= A[i];
        if(ansd > 1000000000000000000 || ans >  1000000000000000000  ){
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 4392
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")

# k: number of transfer
_,k = LI()
a = LI()
# 街の番号を0始まりに変更
a = list(map(lambda x:x-1,a))
# print(a)

s = set([0])

# 再帰関数
def rec(visited,next):
    if next in s:
        # print(visited)
        return visited,visited.index(next)
    else:
        s.add(next)
        visited.append(next)
        return rec(visited,a[next])

visited = [0]
# 訪れた街、初めて2度訪れた街のインデックスを取得
visited,loopStart = rec(visited,a[0])

# print(visited,loopStart)

if k < len(visited):
    townIndex = visited[k]
else:
    visitedLoop = visited[loopStart:]
    # print(visitedLoop)
    # 残り回数を循環配列の長さで割った余り
    index = (k-(loopStart))%len(visitedLoop)
    # print(index)
    townIndex = visitedLoop[index]

print(townIndex+1)

Measured memory_bytes: 202428
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors = sorted(divisors)
    return divisors

n,k = map(int,input().split())
a = list(map(int,input().split()))

sum_a = sum(a)
div = make_divisors(sum_a)
ans = []
for i in div:
    mod_list = sorted([j%i for j in a],reverse=True)
    x = int(sum(mod_list)/i)
    mod_list = mod_list[:x]
    change = sum([i-j for j in mod_list])
    if change <= k:
        ans.append(i)
print(max(ans))

Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

int n,m,k;

int joseph(int n,int k){
	if(n==1)return 1;
	else return (k-1+joseph(n-1,k))%n+1;
}

main(){
	while(cin>>n>>k>>m){
		if(n==0 && m==0 && k==0){
			break;
		}else{
			cout<<(joseph(n-1,k)+m-1)%n+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1096
from typing import List


class UnionFind:
    """Union Find (Disjoint Set): O(α(N))
    References:
        https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp
        https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html
    """

    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        """Find the group (root) of vertex x in O(α(n)) amortized."""
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def __len__(self) -> int:
        """Count the number of groups (roots)."""
        return len(self.groups)

    @property
    def groups(self) -> List[int]:
        """Return the set of groups (roots) in O(n)."""
        return [i for i, r in enumerate(self._roots) if r < 0]

    def is_connected(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are connected in O(α(n)) amortized."""
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y in O(α(n)) amortized."""
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x

    def get_size(self, x: int) -> int:
        """Return the size of the group where vertex x belongs in O(α(n)) amortized."""
        return -self._roots[self[x]]


def unionfind():
    # https://judge.yosupo.jp/problem/unionfind
    # https://atcoder.jp/contests/practice2/tasks/practice2_a
    import sys

    read = sys.stdin.buffer.read

    N, Q, *TUV = map(int, read().split())
    tree = UnionFind(N)
    res = []
    for t, u, v in zip(*[iter(TUV)] * 3):
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


def arc032_b():
    # https://atcoder.jp/contests/arc032/tasks/arc032_2
    N, M, *AB = map(int, open(0).read().split())
    tree = UnionFind(N + 1)
    for a, b in zip(*[iter(AB)] * 2):
        tree.unite(a, b)
    print(len(tree) - 2)


if __name__ == "__main__":
    unionfind()
    # arc032_b()


Measured memory_bytes: 53624
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion


// 123 C-Five Transportations
int main(void) {
	int n, w, h;
	int x, y, a;
	int x0 = 0, y0 = 0;

	scanf("%d %d %d", &w, &h, &n);

	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", &x, &y, &a);
		switch (a) {
		case 1:x0 =_max(x0,x); break;
		case 2:w = _min(w, x); break;
		case 3:y0 =_max(y0,y); break;
		case 4:h  =_min(h,y);  break;
		}
		//printf("\n%d %d %d %d\n", w, h, x0, y0);

	}

	w = (w < x0) ? 0 : w - x0;
	h = (h < y0) ? 0 : h - y0;
	printf("%d\n", w * h);

	return 0;
}

Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
typedef pair<double,double> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int l,n;
vector<string> vec;
int main(){
	cin >> n >> l;
	vec.resize(n);
	for(int i=0;i<n;i++)cin >> vec[i];
	sort(all(vec));
	for(int i=0;i<n;i++)cout << vec[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
k=int(input())
cand=[[1,2,3,4,5,6,7,8,9]]
for _ in range(9): #上記の操作を9回繰り返せば10^5個以上のルンルン数を列挙できる
 tmp=[]
 for val in cand[-1]:
   if val%10!=0: #末尾が0のときは(末尾-1)を付け加えた数はルンルン数にならない
     tmp.append(val*10+(val%10-1))
   tmp.append(val*10+(val%10))
   if val%10!=9: #末尾が9のときは(末尾+1)を付け加えた数はルンルン数にならない
     tmp.append(val*10+(val%10+1))
 cand.append(tmp)
ans=[]
for i in range(len(cand)):
 for val in cand[i]:
   ans.append(val)
ans=sorted(ans)
print(ans[k-1])

Measured memory_bytes: 15144
ls = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
K = int(input())
print(ls[K-1])

Measured memory_bytes: 9376
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (i*500 + j*100 + k*50) == X:
                ans += 1
print(ans)

Measured memory_bytes: 3060
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    long N = sc.nextLong();
    long M = sc.nextLong();

    sc.close();

    if (N * 2 < M) {
      System.out.println(N + (M - N * 2) / 4);
    } else {
      System.out.println(M / 2);
    }
    
  }

}

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

int n, k;
int a[101];
int b[100010];

bool func(int p){
	if(b[p] != 0) return b[p] == 1 ? true : false;
	bool f = false;
	for(int i=0; i<n; ++i)
		if(p - a[i] >= 0 && !func(p - a[i]))
			f = true;
	b[p] = f ? 1 : 2;
	return f;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(int i=0; i<n; ++i) cin >> a[i];
	b[0] = 2;
	if(func(k)) cout << "First\n";
	else cout << "Second\n";
}

Measured memory_bytes: 5376
#include <stdio.h>    
int main()
{
	int a;
	int i;
	int x, y, z;
	int max, M, N;
	
	scanf("%d",&a);
	for(i = 0; i < a; i++){
		scanf("%d %d %d",&x ,&y ,&z);
		if(x > y && x > z){
			max = x;
			M = y;
			N = z;
		}
		else if(y > x && y > z){
			max = y;
			M = x;
			N = z;
		}
		else{
			max = z;
			M = x;
			N = y;
		}
		if(max*max == M*M + N*N)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

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

#define nax 1009
#define FOR(i,n,m) for(int i =(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef vector<int> vi;

int main(){
	char tab[nax][nax];
	ll dp[nax][nax];
	int h, w; cin>>h>>w;

	ll mod = 1000000007LL;

	REP(i,h){
		REP(j,w){
			cin>>tab[i][j];
		}
	}

	memset(dp,0LL,sizeof dp);
	dp[0][0]=1;
	REP(i,h){
		REP(j,w){
			if(i==0&& j==0) continue;
			if(tab[i][j]=='#') continue;
			if(i==0){
				dp[i][j] = dp[i][j-1];
			}else if(j==0){
				dp[i][j] = dp[i-1][j];
			}else{
				dp[i][j] = (dp[i][j-1]+dp[i-1][j])%mod;
			}
		}
	}

	cout<<dp[h-1][w-1]%mod;
	
	return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n) {
      REP(i, n) par[i] = i;
    }

    int root(int x) {
      return par[x] == x ? x : par[x] = root(par[x]);
    }

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

    void unite(int x, int y) {
      x = root(x);
      y = root(y);

      if (x == y) return;

      par[x] = y;
    }
};


void solve(istream& cin, ostream& cout) {
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  REP(i, n) {
    cin >> p[i];
    p[i]--;
  }

  UnionFind uf(n);

  REP(i, m) {
    int x, y;
    cin >> x >> y;
    uf.unite(x - 1, y - 1);
  }
  int ans = 0;
  REP(i, n) {
    if (uf.same(i, p[i])) ans++;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3932
N = int(input())
 
def search(i,j,k,val) :
    ret = 0 
    if val > N :
        return 0
    elif i > 0 and j > 0 and k > 0 and val<=N:
        ret = 1 
    else :
        ret = 0 
    ret += search(i+1,j,k,val*10+3)
    ret += search(i,j+1,k,val*10+5)
    ret += search(i,j,k+1,val*10+7)
    return ret
print(search(0,0,0,0))

Measured memory_bytes: 3064
import sys

input = sys.stdin.readline
import fractions



def main():
    N = int(input())
    A = tuple([int(x) for x in input().split()])
    MOD = 10 ** 9 + 7

    x = 1
    for a in A:
        x = (a * x) // fractions.gcd(a, x)

    ans = 0
    for a in A:
        ans += x // a

    print(ans % MOD)



    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 6112
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    vector<int> as(N), bs(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> as[i] >> bs[i];
    }
    sort(as.begin(), as.end());
    sort(bs.begin(), bs.end());
    if (N % 2 == 1)
    {
        cout << bs[(N + 1) / 2 - 1] - as[(N + 1) / 2 - 1] + 1 << endl;
    }
    else
    {
        double min = static_cast<double>(as[N / 2 - 1] + as[N / 2]) / 2.0;
        double max = static_cast<double>(bs[N / 2 - 1] + bs[N / 2]) / 2.0;
        cout << static_cast<int>((max - min) / 0.5) + 1 << endl;
    }
}

Measured memory_bytes: 4840
use proconio::input;

fn gcd(a: usize, b: usize) -> usize {
  if b == 0 {
    return a
  }
  gcd(b, a % b)
}

fn lcm(a: usize, b: usize) -> usize {
  a * b / gcd(a, b)
}

fn main() {
  input! {
    a: usize,
    b: usize
  }
  
  println!("{}", lcm(a, b));
}

Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
void Fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
}
inline int D()
{
    int t;
    scanf("%d",&t);
    return t;
}
inline ll llD()
{
    ll t;
    scanf("%lld",&t);
    return t;
}
const int Max=1e5+8;
const int OO=-1e6;
int xt[4]= {1,0,0,-1};
int yt[4]= {0,1,-1,0};
ll n,m,f,l;
bool valid(int x,int y)
{
    return x>-1 && y>-1 && x<n && y<m;
}

int mem[209][209][209],k;
        string st,st2;

void init()
{
    memset(mem,-1,sizeof mem);
}
/////////////////////////////////////////////////////////////////////
int solve (int i=0,int t=0,int j=n )
{

}
ll arr[200009];
int main()
{

    int T=1;
///T=D();
    while(T-->0)
    {

       cin>>n;
    ll ans =0;
       for(int i =0;i<n;i++)
        {
            cin>>arr[i];
            if(i)
            {
            if(arr[i-1]>arr[i])
            {
                ans+=( arr[i-1]-arr[i]);
                arr[i]=arr[i-1];
            }
            }
        }
       cout<<ans;



    }

}


Measured memory_bytes: 5168
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

A, B, C = map(int, input().split())
K = int(input())
ans = "No"

while True:
  if(A<B and B<C):
    ans = "Yes"
  if(K==0):
    break
  if(A<B):
    C = C*2
    K-=1
  else:
    B = B*2
    K -= 1


print(ans)



Measured memory_bytes: 68696
s=[int(input()) for _ in range(5)]
k=[s[i]%10 for i in range(5)]
l=[]
for i in range(5):
    if k[i] !=0:
        l.append(10-k[i])
    else:
        l.append(0)
p=max(l)
m=sum(s)
n=sum(l)
print(int(m+n-p))

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


int main() {
    ll x;
    cin >> x;
    ll ans = 0;
    ans += (x/500)*1000;
    x %=  500;
    ans += (x/5)*5;
    cout << ans << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long
main(){
  int n,r=0;
  cin>>n;
  vector<int> a(n);
  map<int,int> m;
  for(int i=0;i<n;i++){cin>>a[i];if(i!=0)a[i]+=a[i-1];}
  for(int i=0;i<n;i++)m[a[i]]++;
  for(auto p:m)r+=p.second*(p.second-1)/2;
  cout<<r+m[0];
}

Measured memory_bytes: 14336
n,m=[int(i) for i in input().split()]

mise={}
for i in range(n):
    a,b=[int(j) for j in input().split()]
    if a in mise:
        mise[a]+=b
    else:
        mise[a]=b
nedan=list(mise.keys())
nedan.sort()
i=0
ans=0
while m:
    honnsuu=mise[nedan[i]]
    kauno=min(honnsuu,m)
    ans+=kauno*nedan[i]
    i+=1
    m=m-kauno

print(ans)

Measured memory_bytes: 17884
h,w = map(int, input().split())
n = int(input())
al = list(map(int, input().split()))

res=[]

for i in range(n):
    for j in range(al[i]):
        res.append((i+1))

for k in range(h):
    temp = res[k*w:(k+1)*w]        
    if k % 2==1:
        temp = list(reversed(temp))
    else:
        pass
    print(str(temp).replace("[","").replace("]","").replace(","," "))

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
int main()
{
    ll a,b,c,d,r,e,f;
    scanf("%d %d",&a,&b);
    c=a+b,d=a*b,e=a-b;
    f=max(c,max(d,e));
    printf("%d\n",f);
}


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

    int N,M,p;
    cin>>N>>M>>p;

    int d[10020];
    for(int i = 0;i < M;i++){
        cin>>d[i],d[i]-=p;
        if(d[i]<0)d[i]+=N;
    }
    sort(d,d+M);
    int ans = 1e+9;
    for(int i = 1;i < M;i++){
        ans = min(ans,d[i-1]*2+N-d[i]);
        ans = min(ans,(N-d[i])*2+d[i-1]);
    }
    ans = min(ans,N-d[0]);
    ans = min(ans,d[M-1]);
    cout<<ans*100<<endl;


    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <cmath>
#include<vector>
#include <algorithm>
#include <utility>
#include<stack>
#include<queue>
#include<map>
#include <fstream>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long

int n,d;
        long long x[30][30];

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

        cin>>n>>d;
        for( int i=0;i<n;i++ ){
            for( int j=0;j<d;j++ )
                cin>>x[i][j];
        }
        int cnt=0;
        for( int i=0;i<n;i++ ){

            for( int j=i+1;j<n;j++ ){
                    long long sum = 0;
                for( int k=0;k<d;k++ ){
                    sum += ( x[i][k] - x[j][k] )*( x[i][k] - x[j][k] );
                }
                long long root = sqrt( sum );
                if( root*root == sum ) cnt++;
            }
        }

        cout<<cnt<<endl;
      return 0;
    }



























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N;
    cin >> N;
    vector<double> x(N), y(N);
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> x.at(i) >> y.at(i);
        A.at(i) = i;
    }

    double sum = 0.0;
    int cnt = 0;
    do {
        cnt++;
        for (int i = 1; i < N; ++i) {
            int now = A.at(i), prev = A.at(i - 1);
            double dx = x.at(now) - x.at(prev);
            double dy = y.at(now) - y.at(prev);
            sum += sqrt(dx * dx + dy * dy);
        }
    } while (next_permutation(A.begin(), A.end()));

    cout << sum / cnt << endl;

    return 0;
}

Measured memory_bytes: 256