akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, k, s;
    cin >> n >> k >> s;

    int a[n] = {};

    if(s != 1000000000){
        rep(i,n){
            if(i < k){
                a[i] = s;
            }else{
                a[i] = 1000000000;
            }
        }
    }else{
        rep(i,n){
            if(i < k){
                a[i] = 1000000000;
            }else{
                a[i] = 999999999;
            }
        }
    }

    rep(i,n){
        cout << a[i] << ' ';
    }
    cout << endl;
    return 0;
}
 
 


Measured memory_bytes: 1664
#include<stdio.h>
int main()
{
	int n;
	int sum=0;
	scanf("%d",&n);
	while(n>0)
	{
		sum+=n%10;
		n/=10; 
	 } 
	 if(sum==1)
	 {
	 	printf("10");
	 	return 0;
	 }
	 else 
	 {
	 	printf("%d",sum);
	 }
 } 

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	int i, j, a[10];
	for(i=0;i<10;i++){
		scanf("%d", &a[i]);
	}
	sort(a,a+10);
	for(j=0;j<3;j++){
		printf("%d\n", a[9-j]);
	}
}

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

int main(){
  int n;
  cin >> n;
  int ans=0;
  
  int a=n;
  
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  
  if(n%ans==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
from collections import deque

K = int(input())

q = deque([i for i in range(1, 10)])

for i in range(K):
  x = q.popleft()
  y = 10 * x + x % 10
  if x % 10:
    q.append(y - 1)
  q.append(y)
  if x % 10 != 9:
    q.append(y + 1)

print(x)


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

using namespace std;

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

int main() {
  long long h, w;
  string s[52];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  
  bool ans = true;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
          continue;
      }
      bool ok = false;
      for (int d = 0; d < 4; d++) {
        int nx = j + dx[d];
        int ny = i + dy[d];
        if (0 <= nx && nx < w && 0 <= ny && ny < h && s[ny][nx] == '#') {
            ok = true;
        }
      }
      if (!ok) {
        ans = false;
        break;
      }
    }
    if (!ans) {
        break;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

ans = 10 ** 10
while min(A) != ans:
    ans = min(A)
    for i, a_i in enumerate(A):
        if a_i > ans:
            A[i] = a_i % ans
            if A[i] == 0:
                del A[i]

print(ans)

Measured memory_bytes: 15020
// 2020-09-28 00:40:58
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
using T = tuple<ll, int, int>;  // c l r
const ll inf = 1e18;
void answer() {
  int n, m;
  cin >> n >> m;
  vector<set<T> > mp(n + 1);
  rep(i, m) {
    int l, r, c;
    cin >> l >> r >> c;
    mp[l].emplace(c, l, r);
  }
  vector<ll> dist(n + 1, inf);
  int cur = 0;
  dist[cur] = 0;
  priority_queue<T, vector<T>, greater<T> > que;
  que.emplace(0, 0, 1);
  while (!que.empty()) {
    auto [c, l, r] = que.top();
    que.pop();
    REPC(i, cur + 1, r) {
      chmin(dist[i], c);
      for (auto [c2, l2, r2] : mp[i]) {
        que.emplace(dist[l2] + c2, l2, r2);
      }
    }
    chmax(cur, r);
  }
  ll ans = dist[n];
  if (ans == inf) ans = -1;
  cout << ans << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 16192
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main(){
	ll n;
	double p, dp[3005][3005]={0}, ans = 0;
	cin >> n;
	rep(i,1,n){
		cin >> p;
		if(i == 1){
			dp[1][1] = p;
			dp[1][0] = 1.0 - p;
		} else {
			rep(j,0,i){
				dp[i][j] = dp[i-1][j-1] * p + dp[i-1][j] * (1.0 - p);
			}
		}
	}
	rep(i,(n+1)/2,n) ans += dp[n][i];
	cout << setprecision(13) << ans << endl;
    return 0;
}

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

#define pb push_back
#define scd second
#define fst first

using namespace std;

typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int x, a, b;
	cin>>x>>a>>b;
	if(abs(x-a)<abs(x-b)) cout<<"A\n";
	else cout<<"B\n"<<endl;	
}

Measured memory_bytes: 256
n=gets.to_i
a=gets.split.map(&:to_i)
a.unshift 0
a.push 0
sum=a.each_cons(2).map{|x,y|(x-y).abs}.inject(:+)
a.each_cons(3){|x,y,z|puts sum+(x-z).abs-(x-y).abs-(y-z).abs}

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

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

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

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

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

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

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

    let patterns = ["a", "i", "u", "e", "o"];
    let ret = patterns.iter().any(|p| p == &&*s);
    println!("{}", if ret {"vowel"} else {"consonant"});

}



Measured memory_bytes: 4352
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	private static Node[] V;
	static int Vn;
	
	public static void main(String[] args) {
		Vn = sc.nextInt();
		int En = sc.nextInt();
		
		V = new Node[Vn];
		for(int i=0; i<Vn; i++) {
			V[i] = new Node();
			V[i].id = i;
		}
		
		for(int i=0; i<En; i++) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			int c = sc.nextInt();
			V[u].nbr.add(new Edge(v, c));
			V[v].nbr.add(new Edge(u, 0));
		}
		
		int flow = 0;
		while(true) {
			for(int i=0; i<Vn; i++) {
				V[i].used = false;
			}
			int f = V[0].dfs(Integer.MAX_VALUE);
			if (f == 0) {
				System.out.println(flow);
				return;
			}
			flow += f;
		}
	}
	
	static class Node {
		int id;
		boolean used;
		HashSet<Edge> nbr = new HashSet<>();
		
		int dfs (int f) {
			if(id == Vn - 1) {
				return f;
			}
			used = true;
			for(Edge e : nbr) {
				if(!V[e.t].used && e.c > 0) {
					int d = V[e.t].dfs(Math.min(f, e.c));
					if(d > 0) {
						e.c -= d;
						for(Edge e2 : V[e.t].nbr) {
							if(e2.t == id) {
								e2.c += d;
								break;
							}
						}
						
						return d;
					}
				}
			}
			
			return 0;
		}
	}
	
	static class Edge {
		int t;
		int c;
		Edge(int t, int c) {
			this.t = t;
			this.c = c;
		}
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 47096
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;

signed main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    int ans = 0;
    rep(i, h) cin >> s[i];
    rep(is, 1<<h)rep(js, 1<<w){
        int cnt = 0;
        rep(i, h)rep(j, w){
            if(is>>i & 1) continue;
            if(js>>j & 1) continue;
            if(s[i][j] == '#') cnt++;
        }
        if(cnt == k) ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3640
/*TC:
1101001
> 4
*/
#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); \
				cin.tie(0); \
				cout.tie(0)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(_v)             _v.begin(), _v.end()
#define sz(_v)              (int) _v.size()
#define first(_obj)         (*_obj.begin())
#define last(_obj)          (*prev(_obj.end()))
#define FIND(_obj, _val)    (_obj.find(_val) != _obj.end())
#define RESET(_a, _v)       fill_n(_a,sizeof(_a)/sizeof(_a[0]),_v)
#define REP(_i, _n)         for (int _i = 0; _i < (int) _n; _i++)
#define FOR(_i, _a, _b)     for (int _i = (int) _a; _i <= (int) _b; _i++)
#define FORD(_i, _a, _b)    for (int _i = (int) _a; _i >= (int) _b; _i--)
#define FORIT(_it, _obj)    for (auto _it = _obj.begin(); _it != _obj.end(); _it++)

// DEBUG UTIL
#define DEBUG(args...) { cerr << "> "; \
						 string _s = #args; \
						 replace(_s.begin(), _s.end(), ',', ' '); \
						 stringstream _ss(_s); istream_iterator<string> _it(_ss); \
						 err(_it, args); }

void err(istream_iterator<string> it) { cerr << endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << ": " << a << " ";
	err(++it, args...);
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<double,double>;
using vi = vector<int>;
using vii = vector<pii>;
using vs = vector<string>;

const int DR[] = {-1, 0, 1, 0};
const int DC[] = {0, -1, 0, 1};
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = 1073741823;
const ll INFLL = 4e18;
const int MAX = 1e5;

int N;
char s[MAX+5];
int BIT[MAX+5];

void update(int x, int val) {
	x++;
	for (; x > 0; x -= x & -x) 
		BIT[x] = (BIT[x] + val + 2) % 2;
}

int get(int x) {
	x++;
	int ret = 0;
	for (; x <= N; x += x & -x)
		ret += BIT[x];
	return ret;
}

void read() {
	cin >> s;
	N = strlen(s);
}

bool check(int k) {
	memset(BIT, 0, sizeof BIT);
	REP(i,k) {
		// DEBUG(s[i], get(i));
		if ((s[i] == '1' && get(i)%2 == 0) || (s[i] == '0' && get(i)%2 == 1)) {
			if (i + k > N) return false;
			update(N-1, 1);
			update(i-1, -1);
		}
	}
	return true;
}

void solve() {
	int lo = 1, hi = N+1;
	REP(loop,18) {
		int mid = (lo + hi) / 2;
		if (check(mid)) lo = mid;
		else hi = mid;

		// if (loop < 5) DEBUG(lo, hi, mid);
	}

	cout << lo << "\n";
}

int main() {
	FAST_IO;
	int TC = 1;
	while (TC--) {
		read();
		solve();
	}
}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main(void){
    int h,w;
    while(cin>>h>>w,h!=0||w!=0){
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++)cout<<"#";
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

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

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

    bool p = s[0] == 'R';
    bool q = s[1] == 'R';
    bool r = s[2] == 'R';

    if (p && q && r)
    {
        cout << 3 << '\n';
    }
    else if (p && q || q && r)
    {
        cout << 2 << '\n';
    }
    else if (p || q || r)
    {
        cout << 1 << '\n';
    }
    else
    {
        cout << 0 << '\n';
    }

    return 0;
}


Measured memory_bytes: 3556
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int D;
    
    scanf("%d",&D);
    if (D<22 || D>25) {
        printf("22<=D<=25 の範囲で入力して下さい\n");
    } else {
        switch (D) {
            case 22:
                printf("Christmas Eve Eve Eve\n");
                break;
            case 23:
                printf("Christmas Eve Eve\n");
                break;
            case 24:
                printf("Christmas Eve\n");
                break;
            case 25:
                printf("Christmas\n");
                break;
                
            default:
                break;
        }

    }
    
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
using namespace std;
 
int main(){
  int a,b;
  
  cin >> a >> b;
  int d,r;
  double f;
  d = a / b;
  r = a % b;
  f = 1.00000 * a / b;
  cout << d << " " << r << " ";
  printf("%.5f\n",f);
  
      

  return 0;		 
}
		   


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

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

  int p[n];
  rep(i, n) cin >> p[i];
  sort(p, p + n);
  vector<int> v;
  for (int i = -200; i <= 0; i++) {
    v.push_back(i);
  }
  int j = 0;
  rep2(i, 1, 201) {
    if (i == p[j])
      j++;
    else
      v.push_back(i);
  }
  int ans = 1001001;
  rep(i, v.size()) {
    if (abs(x - ans) > abs(x - v[i])) ans = v[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
import unittest


class TestC(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(3, [[1, 7], [3, 2], [1, 7]]), 702)

    def test_2(self):
        self.assertEqual(think(3, [[2, 1], [2, 3]]), -1)

    def test_3(self):
        self.assertEqual(think(3, [[1, 0]]), -1)

    def test_4(self):
        self.assertEqual(think(1, [[1, 0]]), 0)

    def test_5(self):
        self.assertEqual(think(1, []), 0)


def solve():
    n, list_of_s_and_c = read()
    result = think(n, list_of_s_and_c)
    write(result)


def read():
    n, m = read_int(2)
    list_of_s_and_c = []
    for _ in range(m):
        list_of_s_and_c.append(read_int(2))
    return n, list_of_s_and_c


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, list_of_s_and_c):
    not_occupied = -1
    buf = [not_occupied] * n
    for s, c in list_of_s_and_c:
        index = s - 1
        if buf[index] == not_occupied:
            buf[index] = c
        else:
            if buf[index] == c:
                continue
            else:
                return -1
    for i in range(n):
        if buf[i] == not_occupied:
            if i == 0:
                if n == 1:
                    buf[i] = 0
                else:
                    buf[i] = 1
            else:
                buf[i] = 0

    if buf[0] == 0:
        if n == 1:
            return 0
        else:
            return -1
    return int(''.join(map(str, buf)))


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 49776
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long sum=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
          sum+=gcd(gcd(i,j),k);
      }
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3636
using System;

namespace id_0588cs
{
    class Program
    {
        static void Main(string[] args)
        {
            int internalVal = int.Parse(Console.ReadLine());
            while (true)
            {
                string calculation = Console.ReadLine();
                if (calculation == "=") break;
                if (calculation == "+")
                {
                    internalVal += int.Parse(Console.ReadLine());
                }
                if (calculation == "-")
                {
                    internalVal -= int.Parse(Console.ReadLine());
                }
                if (calculation == "*")
                {
                    internalVal *= int.Parse(Console.ReadLine());
                }
                if (calculation == "/")
                {
                    internalVal /= int.Parse(Console.ReadLine());
                }
            }
            Console.WriteLine(internalVal);
        }
    }
}



Measured memory_bytes: 17944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
   ll N,K;cin>>N>>K;
   string S;cin>>S;
   if(S[K-1]=='A'){S[K-1]='a';}
   else if (S[K-1]=='B'){S[K-1]='b';}
   else if (S[K-1]=='C'){S[K-1]='c';}
   cout<<S<<endl;
   

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int>B(N+1);
  B.at(0)=999999;
  for(int i=0;i<N;i++){
  cin>>B.at(i+1);
  }
  B.at(N)=999999;
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=min(B.at(i),B.at(i+1));
  }
  cout<<sum<<endl;
}
  
  

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

ll solve() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll x, y;
    cin >> y;
    ll ans = 0;
    for ( int i = 1; i < N; i++ ) {
        cin >> x;
        ans += min(B, (x - y) * A);
        y = x;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, D, X;    cin >> N >> D >> X;
    int *A = new int[N];
    for (int i = 0; i < N; i++)
        cin >> A[i];

    int ans = X;
    for (int i = 0; i < N; i++) {
        ans += (D-1)/A[i]+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  ll n;
  cin>>n;

  if(n%2==1){
    cout << 0 << endl;
  }
  else {
    n/=2;
    ll ans=0;
    while(n>0){
      ans+=n/5;
      n/=5;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

template <typename T>
class SegmentTree {
  const T unit;
  const function<T(const T&, const T&)> op;
  vector<T> container;

 public:
  template <typename Op>
  SegmentTree(int size, const T& identity, const Op& operation)
      : unit(identity), op(operation), container(msb(size * 2 - 1)) {
    fill(container.begin(), container.end(), unit);
  }
  void update(size_t index, T value) {
    int n = container.size() / 2;
    container[index + n] = value;

    int node = (index + n) >> 1;
    while (node > 0) {
      container[node] = op(container[node << 1], container[(node << 1) + 1]);
      node >>= 1;
    }
  }
  T find(size_t s, size_t t) {
    if (s >= t) {
      return unit;
    }
    return find_inner(s, t, 0, container.size() / 2);
  }

 private:
  T find_inner(size_t s, size_t t, size_t lb, size_t ub) {
    if (s == lb && t == ub) {
      int n = container.size() / 2;
      return container[lca(n + s, n + t - 1)];
    }

    T result = unit;
    size_t mid = (lb + ub) / 2;
    if (mid > s) {
      result = op(result, find_inner(s, min(mid, t), lb, mid));
    }
    if (mid < t) {
      result = op(result, find_inner(max(s, mid), t, mid, ub));
    }

    return result;
  }
  int lca(int n0, int n1) {
    int a = n0 ^ n1;
    return n0 / msb(a);
  }
  int msb(int x) {
    x |= x >> 1;
    x |= x >> 2;
    x |= x >> 4;
    x |= x >> 8;
    x |= x >> 16;

    return x + 1;
  }
};

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

  int Q;
  cin >> Q;

  vector<SegmentTree<int8_t>> seg(vector<SegmentTree<int8_t>>(
      26, SegmentTree<int8_t>(N, 0, [](const int8_t& lh, const int8_t& rh) {
        return max(lh, rh);
      })));
  rep(i, N) { seg[s[i] - 'a'].update(i, 1); }

  rep(i, Q) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      char c;
      cin >> i >> c;

      rep(j, 26) { seg[j].update(i - 1, 0); }
      seg[c - 'a'].update(i - 1, 1);
    } else {
      int l, r;
      cin >> l >> r;
      int result = 0;
      rep(j, 26) { result += seg[j].find(l - 1, r); }
      cout << result << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 28676
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 str = cin.ReadLine;
            var strList = str.ToCharArray();
            
            var ans = strList
                      .Where((value, index) => (index+1) % 2 == 1)
                      .Aggregate("", (value, elem) => value + elem);
            
            WriteLine(ans);
            
            
        }
    }

    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: 34900
#include <deque>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 1000005
int n, A[N], num, ans;
char S[N], T[N];
vector<int>P[30];
deque<int>que;
int main()
{
	scanf("%d%s%s", &n, S + 1, T + 1);
	A[n + 1] = n + 1;
	int m = 0;
	for (int i = 1; i <= n; i++)
		m += (S[i]==T[i]);
	if (m == n)
	{
		puts("0");
		return 0;
	}
	if (n == 1)
	{
		puts("-1");
		return 0;
	}
	for (int i = 1; i <= n; i++)
		P[S[i] - 'a'].push_back(i);
	for (int i = n; i >= 1; i--)
	{
		if (T[i] == T[i + 1] && i >= A[i + 1])
		{
			A[i] = A[i + 1];
			continue;
		}
		else
		{
			while (!P[T[i] - 'a'].empty() && P[T[i] - 'a'].back() >= A[i + 1])
			{
				P[T[i] - 'a'].pop_back();
				if (P[T[i] - 'a'].empty())
				{
					puts("-1");
					return 0;
				}
			}
			A[i] = P[T[i] - 'a'].back();
			if (i >= A[i + 1])
			{
				num--;
				que.push_front(A[i + 1] - num - 1);
				while (que.back() + num >= i)
					que.pop_back();
				que.push_back(i - num);
			}
			else
			{
				while (!que.empty())
					que.pop_back();
				if (A[i] < i)
					que.push_back(i - num);
			}
			ans = max(ans, (int)que.size());
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 14600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
int main(){
    string s,t;cin >> s >> t;
    vector<vector<int>> dp(s.size()+1,vector<int>(t.size()+1,0));
    for(int i=0; i<s.size(); i++){
        for(int j=0; j<t.size(); j++){
            if(s[i]==t[j]) dp[i+1][j+1]=dp[i][j]+1;
            else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
        }
    }
    string ans="";
    int i=(int)s.size(),j=(int)t.size();
    while(i>0&&j>0){
        if(s[i-1]==t[j-1]){
            ans=s[i-1]+ans;
            i--;j--;
        }
        else if(dp[i][j]==dp[i-1][j]) i--;
        else j--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 35584
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
template<typename T>void read(T &x){
	x=0;int f(1);char c(getchar());
	for(;!isdigit(c);c=getchar())if(c=='-')f=-f;
	for(; isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c-'0');
	x*=f;
}
template<typename T>void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)write(x/10),x%=10;
	putchar(x+'0');
}
const int maxn=105;
int vis[maxn];
int main(){
	int n,k;
	read(n),read(k);
	while(k--){
		int d;read(d);
		while(d--){
			int pos;read(pos);
			vis[pos]|=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i)
		ans+=!vis[i];
	write(ans),putchar('\n');
	return 0;
}


Measured memory_bytes: 3640
/*input
ABC
*/

#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>;

int main() {
  string s;
  cin >> s;
  if (s == "ABC") cout << "ARC" << endl;
  else  cout << "ABC" << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

typedef vector<int> rep;

int N, M;
long long x[100100];
long long K;
int a[100100];
long long d[100100];
rep dr;

rep id(int size) {
  rep A;
  for (int i=0; i<size; i++) A.push_back(i);
  return A;
}

rep mul(rep &A, rep &B) {
  rep C;
  for (int i=0; i<A.size(); i++) {
    C.push_back(B[A[i]]);
  }
  return C;
}

rep pow(rep A, long long k) {
  rep B = id(A.size());
  while (k > 0) {
    if (k & 1) B = mul(B, A);
    A = mul(A, A);
    k >>= 1;
  }
  return B;
}

int main() {
  cin >> N;
  for (int i=0; i<N; i++) cin >> x[i];
  cin >> M;
  cin >> K;
  for (int i=0; i<M; i++) cin >> a[i];

  for (int i=0; i<N-1; i++) {
    d[i] = x[i+1] - x[i];
    dr.push_back(i);
  }
  for (int i=0; i<M; i++) {
    int k = dr[a[i]-1];
    dr[a[i]-1] = dr[a[i]-2];
    dr[a[i]-2] = k;
  }
  rep r = pow(dr, K);

  long long pos = x[0];
  cout << pos << ".0" << "\n";
  for (int i=0; i<r.size(); i++) {
    pos += d[r[i]];
    cout << pos << ".0" << "\n";
  }
  return 0;
}



Measured memory_bytes: 5464
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    n = int(input())
    s = [ input() for _ in range(n) ]
    m = int(input())
    t = [ input() for _ in range(m) ]
    factors = list(set(s+t))
    dic = { key: 0 for key in factors}
    ans = float("-inf")
    for word in s:
        dic[word] += 1
    for word in t:
        dic[word] -= 1
    for word in list(set(s+t)):
        ans = max(ans, dic[word])
    else:
        if ans < 0:
            print(0)
        else:
            print(ans)

Measured memory_bytes: 3064
A, B, C, D, E, F = gets.split.map(&:to_i)

max_a = F/(100*A)
max_b = F/(100*B)
max_c = E*(F/100)/C
max_d = E*(F/100)/D

water = []
0.upto(F/100) do |i|
  0.upto(F/100) do |j|
    w = (A*i + B*j) * 100
    water << w if F >= w
  end
end

sugar = []
0.upto(F/D) do |i|
  0.upto(F/D) do |j|
    s = C*i + D*j
    sugar << s if F >= s
  end
end

max_water = 0
max_sugar = 0
max_density = 0
water.each do |w|
  sugar.each do |s|
    next if F < w + s
    next if w == 0

    if (w/100)*E >= s
      density = (100.0*s)/(w + s)
      if max_density < density
        max_water = w
        max_sugar = s
        max_density = density
      end
    end
  end
end

if max_water == 0
  puts "#{100*A} 0"
else
  puts "#{max_water + max_sugar} #{max_sugar}"
end


Measured memory_bytes: 3324
from fractions import gcd
N,X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
b = [abs(X-x[i]) for i in range(N)]
ans = b[0]
for i in range(N-1):
  ans = gcd(ans,b[i+1])
print(ans)

Measured memory_bytes: 89236
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    rep(i,b+1){
        if(a*i%b==c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N; cin >> N;
  int X{}, Y{}, T{};
  int res = true;
  for (int _ = 0; _ < N; ++_) {
    int x, y, t;
    cin >> t >> x >> y;
    if (!res) {
      continue;
    }

    auto dX = std::abs(X-x);
    auto dY = std::abs(Y-y);
    auto dT = std::abs(T-t);
    if (dX + dY > dT) {
      res = false;
      continue;
    }
    auto amari = dT - (dX + dY);
    if (amari % 2 != 0) {
      res = false;
      continue;
    }

    T = t;
    X = x;
    Y = y;
  }
  auto ans = res ? "Yes" : "No";
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
	static int[] color;
    static ArrayList<Path>[] pair;
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		pair = new ArrayList[n + 1];
		for (int i = 0; i < n; i++) {
		    pair[i] = new ArrayList<Path>();
		}
		for (int i = 0; i < n - 1; i++) {
		    int a = saori.saori_hayami() - 1;
		    int b = saori.saori_hayami() - 1;
		    int length = saori.saori_hayami();
		    pair[a].add(new Path(b, length));
		    pair[b].add(new Path(a, length));
		}
		color = new int[n + 1];
		Arrays.fill(color, -1);
		dfs(0,0);
		for(int i = 0;i < n;i++){
			System.out.println(color[i]);
		}
	}
	
	static void dfs(int i,int next_color){
		if(color[i] != -1){
			return;
		}
		color[i] = next_color;
		
		for(Path p:pair[i]){
			int a;
			if(p.distance % 2 == 0){
				a = next_color;
			} else {
				a = (1 + next_color) % 2;
			}
			dfs(p.to,a);
		}

		
	}
}

class Path{
	int to;
	int distance;

	public Path(int to,int distance){
		this.to = to;
		this.distance = distance;
	}
}
class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 72044
/*input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1

*/ 
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 
    
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5+1;
    

 
int32_t main() {
    IOS;
	int n;cin>>n;
	int arr[n][3];	
	int dp[n][3];
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			dp[i][j] = 0;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>arr[i][j];
		}
	}
	for(int j=0;j<3;j++){
		dp[0][j] = arr[0][j];
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++)
				if(k!=j)
					dp[i][j] = max(dp[i][j],dp[i-1][k]+arr[i][j]);
		}
	}
	int ans = 0;
	// for(int i=0;i<n;i++){
	// 	for(int j=0;j<3;j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	for(int j=0;j<3;j++){
		ans = max(ans,dp[n-1][j]);
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 4992
/**
 *    author:  Taichicchi
 *    created: 26.09.2020 21:09:03
 **/

#include <bits/stdc++.h>

#include <algorithm>
#include <atcoder/all>
#include <iostream>
#include <vector>

using namespace std;
using namespace atcoder;

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

int main() {
    int N, M;

    cin >> N >> M;

    dsu d(N);

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        d.merge(a, b);
    }

    int ans;
    ans = d.groups().size() - 1;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll ans = b*d;
    chmax(ans, b*c);
    chmax(ans, a*d);
    chmax(ans, a*c);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<int>arr(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	vector<int>dp(n,0);
	for(int i=1;i<n;i++){
		int val=INT_MAX;
		for(int j=i-1;j>=max(0,i-k);j--){
			val=min(val,abs(arr[i]-arr[j])+dp[j]);
		}
		dp[i]=val;
		// cout<<dp[i]<<" ";
	}
	// cout<<endl;
	cout<<dp[n-1];
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli x;
	cin>>x;

	if(x==7 || x == 5 || x==3)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
using namespace std;
int x, y, z, k;
long long a[1010], b[1010], c[1010];
struct Q{
	int i, j, m;
	bool operator < (const Q& u) const {
		if( a[i]+b[j]+c[m] != a[u.i]+b[u.j]+c[u.m] )
			return a[i]+b[j]+c[m] < a[u.i]+b[u.j]+c[u.m];
		else
			if( i != u.i )
				return i > u.i;
			else
				if( j != u.j )
					return j > u.j;
				else
					if( m != u.m )
						return m > u.m;
					else
						return false;
	}
	bool operator == (const Q& u) const {
		if( i == u.i && j == u.j && m == u.m )
			return true;
		return false;
	}
	bool operator != (const Q& u) const {
		if( i == u.i && j == u.j && m == u.m )
			return false;
		return true;
	}
	long long get(){
		return a[i] + b[j] + c[m];
	}
};
set<Q> st;
priority_queue<Q> que;
bool cmp(long long a, long long b){
	return a>b;
}
void work(){
	for( int i = 1; i <= k; ++i ){
		Q u = que.top();
		que.pop();
		printf("%lld\n", u.get());
		int s = u.i, d = u.j, e = u.m;
		Q va = (Q){s+1,d,e}, vb = (Q){s,d+1,e}, vc = (Q){s,d,e+1};
		if( s < x )
			if( st.find(va) == st.end() ){
				que.push(va);
				st.insert(va);
			}
		if( d < y )
			if( st.find(vb) == st.end() ){
				que.push(vb);
				st.insert(vb);
			}
		if( e < z )
			if( st.find(vc) == st.end() ){
				que.push(vc);
				st.insert(vc);
			}
	}
}
int main(){
	scanf("%d%d%d%d", &x, &y, &z, &k);
	for( int i = 1; i <= x; ++i )
		scanf("%lld", &a[i]);
	for( int i = 1; i <= y; ++i )
		scanf("%lld", &b[i]);
	for( int i = 1; i <= z; ++i )
		scanf("%lld", &c[i]);
	sort(a+1, a+1+x, cmp);
	sort(b+1, b+1+y, cmp);
	sort(c+1, c+1+z, cmp);
	que.push((Q){1,1,1});
	work();
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin>>N;
    bool can=true;
    vector<string> W(N);
    for(int i=0;i<N;i++){
        cin>>W[i];
    }
    for(int i=1;i<N;i++){
        int size=W[i-1].size();
        if(W[i-1][size-1]!=W[i][0]){
            can=false;
            break;
        }
        for(int j=0;j<i;j++){
            if(W[i]==W[j]){
                can=false;
                break;
            }
        }
    }
    if(can){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n & 1) 
    puts("No");
  else {
    bool ok = true;
    for (int i = 0, j = n / 2; j < n && ok; i++, j++) {
      if (s[i] != s[j]) ok = false;
    }
    puts(ok ? "Yes" : "No");
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#define MOD 1000000007

typedef long long ll;
using namespace std;

int main(void) {
    int r,g,b,n;
    
    int i,j,k;
    int count = 0;
    cin >> r >> g >> b >> n;
    for(i=n;i>=0;i-=r){
        
        for(j=i;j>=0;j-=g){
            if(j%b==0){
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    a.sort(reverse=True)
    line = -1
    lines = []
    for an in a:
        if line == an:
            lines.append(an)
            if len(lines) == 2:
                break
            line = -1
        else:
            line = an
    print(lines[0] * lines[1] if len(lines) == 2 else 0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84968
#include <iostream>

using namespace std;
#define ll long long
#define int ll
#define max(A,B) (((A)>(B)) ? (A) : (B))
#define min(A,B) (((A)<(B)) ? (A) : (B))
#define abs(A) (((A)<0) ? (-(A)):(A))
#define celi(A,B) (((A)+(B)-1) / (B))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)

int arr[200200];
void solve(int tc) {
	int n, ans = 0;
	cin >> n;
	rep(i, n) cin >> arr[i];
	for (int i = 1; i < n; i++) {
		if (arr[i - 1] > arr[i]) {
			ans += arr[i - 1] - arr[i];
			arr[i] = arr[i - 1];
		}
	}
	cout << ans << endl;
}
signed main() {
	int T = 1, tc;
	//	cin >> T;
	for (tc = 1; tc <= T; tc++) solve(tc);
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
int main() {
  int ans;
  rep(i,5){
    int x;
    cin >> x;
    if(x == 0) ans = i;
  }
  cout << ans + 1 << endl;
  }


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int N, D;
	cin >> N >> D;
	int num = N / (2 * D + 1);
	if (N % (2 * D + 1) != 0) num++;
	cout << num << endl;
	
	return 0;
}

Measured memory_bytes: 3512
from sys import stdin
from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)

def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    t=[int(readline()) for _ in range(n)]

    ans=1
    for i in range(n):
        ans=lcm(ans,t[i])

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 5076