akhauriyash/Code-Regression huggingface dataset:
N,M = map(int, input().split())

NL=[]
ML=[]
for i in range(1, int(N**0.5)+1):
    if N%i==0:
        NL.append(i)
        if i != N//i:
            NL.append(N//i)
for i in range(1, int(M**0.5)+1):
    if M%i==0:
        ML.append(i)
        if i != M//i:
            ML.append(M//i)
NL.remove(1)
NL.sort()
L=[]
for i in NL:
    if i in ML:
        for j in L:
            if i%j==0:
                break
        else:
            L.append(i)
print(len(L)+1)


Measured memory_bytes: 40796
#include <cstdio>
#include <cctype>
#include <utility>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, int &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

int read () {
	int y {in()},yy {y - 1}, m{in() - 1}, mm {}, d{in()};
	for (int i = 1; i <= m; i++) {
		if (i == 2)
			mm += 28 + (y % 4 ? 0 : y % 400 ? !!(y % 100) : 1);
		else if (i == 4 || i == 6 || i == 9 || i == 11)
			mm += 30;
		else
			mm += 31;
	}
	return yy * 365 + yy / 4 - yy / 100 + yy / 400 + mm + d;
}

int main() {
	for (;;) {
		int a {read()}, b {read()};
		if (a < 0)
			return 0;
		outl(b - a);
	}
}


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

int main() {
	int n,k=0;
	cin>>n;
	char p;
	for(int i=0;i<n;i++){
		cin>>p;
		if(p=='Y')k++;
		}
		if(k==0)cout<<"Three"<<endl;
		else cout<<"Four"<<endl;
  return 0;
  }

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

#define INF 999999999

using namespace std;

// input
string S;

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

    cin >> S;

    int len = S.length() - 1;

    ll total = stoll(S);


    for(int i = 1;i < (1 << len);i++){
        vector<int> vec;

        for(int j = 0;j < len;j++){
            int target_bit = (i>>j) & 1;
            if(target_bit == 1){
                vec.push_back(j);
            }
        }

        int before = 0;
        for(auto sp:vec){
            total += stoll(S.substr(before,sp+1-before));
            before = sp + 1;
        }
        total += stoll(S.substr(before,len));
    }

    cout << total << "\n";
    
}

Measured memory_bytes: 256
module MakeBinaryHeap (M : sig type t val compare : t -> t -> int end) = struct

  type t = { node : M.t array; mutable size : int }

  let make n (init : M.t) = { node = Array.make n init; size = 0 }

  let empty_p t = if t.size = 0 then true else false

  let pop t =
    let rec max_heapify i =
      let l = 2*i in
      let r = 2*i + 1 in
      let m = if l <= t.size && M.compare t.node.(l) t.node.(i) > 0 then l else i in
      let m = if r <= t.size && M.compare t.node.(r) t.node.(m) > 0 then r else m in
      if m = i then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(m);
        t.node.(m) <- tmp;
        max_heapify m
      end in
    let ret = t.node.(1) in
    t.node.(1) <- t.node.(t.size);
    t.size <- t.size - 1;
    max_heapify 1;
    ret

  let push x t =
    let parent i = int_of_float (floor (float_of_int i) /. 2.) in
    let rec doit i =
      let p = parent i in
      if i <= 1 || M.compare t.node.(p) t.node.(i) >= 0 then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(p);
        t.node.(p) <- tmp;
        doit p
      end in
    t.size <- t.size + 1;
    t.node.(t.size) <- x;
    doit t.size

end

module H = MakeBinaryHeap(struct type t = (int * int) let compare (_, x) (_, y) = y - x end)

let dijkstra g n =
  let reached_p = Array.make n false in
  let d = Array.make n max_int in
  d.(0) <- 0;
  let h = H.make 50000 (0, 0) in
  H.push (0, 0) h;
  while not (H.empty_p h) do
    let (u, x) = H.pop h in
    reached_p.(u) <- true;
    if x > d.(u) then ()
    else
      List.iter (fun (v, c) ->
        let x = d.(u) + c in
        if not reached_p.(v) && x < d.(v) then begin
          d.(v) <- x;
          H.push (v, x) h;
        end) g.(u)
  done;
  d

let rec make_pair acc = function
  | [] -> acc
  | v :: c :: tl -> make_pair ((v, c) :: acc) tl
  | _ -> assert false

let make_pair lst = make_pair [] lst

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let g = Array.make n [] in
  for _ = 0 to n - 1 do
    match read_line () |> split_on_char ' ' |> List.map int_of_string with
    | u :: _ :: l -> g.(u) <- make_pair l
    | _ -> assert false
  done;
  dijkstra g n |> Array.iteri (fun i e -> Printf.printf "%d %d\n" i e)

Measured memory_bytes: 30168
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc162
{
    class Program
    {
        static void Main(string[] args)
        {
            
            var k = int.Parse(Console.ReadLine());

            var a = Enumerable.Range(1,k).ToArray();
            var b = Enumerable.Range(1, k).ToArray();
            var c = Enumerable.Range(1, k).ToArray();
            long ans = 0;
            foreach (var itema in a)
            {
                foreach (var itemb in b)
                {
                    var x = Gcd(itema, itemb);
                    foreach (var itemc in c)
                    {
                        ans += Gcd(x, itemc);
                    }
                }
            }
            Console.WriteLine(ans);
        }
        static int Gcd(int a, int b)
        {
                    if (b==0) return a;
                    return Gcd(b, a % b);
        }
    }
}


Measured memory_bytes: 28260
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let rec inchworm i j m (((k, d) :: klrs') as klrs) c =
  if i < k
  then c klrs j m
  else inchworm i (j + 1) (IntMap.update d (fun o -> Some (1 + Option.value ~default:0 o)) m) klrs' c

let rec sieve i k j m =
  if j <= i + 1
  then k j m
  else
    sieve i k (j - 1) @@
    match IntMap.min_binding m with
    | (d, 1) -> IntMap.remove d m
    | (d, n) -> IntMap.add d (n - 1) m

let rec solve n i klrs j m =
  if n <= i
  then IntMap.fold (fun d n -> ( + ) @@ d * n) m 0
  else
    inchworm i j m klrs @@ fun klrs ->
      sieve i @@ solve n (i + 1) klrs

let () = Scanf.scanf "%d\n" @@ fun t ->
  for i = 1 to t do
    Scanf.scanf "%d\n" @@ fun n ->
      let klrs = List.init n @@ fun _ ->
        Scanf.scanf "%d %d %d\n" @@ fun k l r -> (k - 1, l, r) in
      let left, right = List.partition (fun (_, l, r) -> r <= l) klrs in
      Printf.printf "%d\n" @@
      List.fold_left (fun sum (_, l, r) -> sum + min l r) 0 klrs
      + solve n 0
          (List.sort (fun (k, _) (k', _) -> compare k k')
            ((n, 0) :: List.map (fun (k, l, r) -> (k, l - r)) left)) 0 IntMap.empty
      + solve n 0
          (List.sort (fun (k, _) (k', _) -> compare k k')
            ((n, 0) :: List.filter_map (fun (k, l, r) -> if n - k - 2 < 0 then None else Some (n - k - 2, r - l)) right)) 0 IntMap.empty
  done

Measured memory_bytes: 53228
#include<iostream>
#include<string>
using namespace std;
int a[1000];
int main(){
      int n;
      cin>>n;
      for(int i=1;i<n+1;i++){
		  cin>>a[i];
	  }
	  for(int j=0;j<n;j++){
		  cout<<a[n-j];
		  if(j<n-1){
			  cout<<" ";
	  }
  }
  cout<<endl;
}



Measured memory_bytes: 3080
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int k;
    cin >> k;

    cout << k / 2 * (k - k / 2) << endl;
}


Measured memory_bytes: 3628
program main
      implicit none
      integer :: n, i, cnt, maxs
      character(10), allocatable :: s(:)

      read *, n
      allocate( s(n) )
      do i = 1, n
        read *, s(i)
      end do

      call quicksort1( s, 1, n )

      cnt = 1
      maxs = 1
      do i = 1, n
        if ( s(i) == s(i+1) ) then
          cnt = cnt + 1
        else
          if ( maxs <= cnt ) then
            maxs = cnt
          end if 
          cnt = 1
        end if
      end do

      cnt = 1
      do i = 1, n
        if ( maxs == 1 ) then
          print *, s(i)
        else
          if ( s(i) == s(i+1) ) then
            cnt = cnt + 1
          else
            if ( maxs == cnt ) then
              print *, s(i)
            end if 
            cnt = 1
          end if
        end if
      end do

end program main
recursive subroutine quicksort1( namec, first, last )

  implicit none
  character(10), intent(inout) :: namec(*)
  integer,intent(in)::first,last
  !
  ! Original
  ! https://gist.github.com/t-nissie/479f0f16966925fa29ea
  !
  character(100)::x,t
  integer::i,j

  x = namec((first+last)/2)
  i = first
  j = last
  do
     do while ( LGT( x, namec(i) ) )
        i=i+1
     end do
     do while ( LGT( namec(j), x ) )
        j=j-1
     end do
     if (i >= j) exit
     t = namec(i)
     namec(i) = namec(j)
     namec(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i-1) call quicksort1( namec, first, i-1  )
  if (j+1 < last)  call quicksort1( namec, j+1  , last )

  return

end subroutine quicksort1


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

signed main() {
  int n, m; cin >> n >> m;
  VVI G(n);
  REP (i, m) {
    int x, y; cin >> x >> y;
    x--; y--;
    G[x].push_back(y);
  }
  VI len(n, -1);
  function<void(int)> dfs = [&](int v) {
    if (len[v] >= 0) return;
    int ma = 0;
    for (int s: G[v]) {
      dfs(s);
      ma = max(ma, len[s] + 1);
    }
    len[v] = ma;
  };
  REP (i, n) {
    dfs(i);
  }
  cout << *max_element(ALL(len)) << endl;
}


Measured memory_bytes: 9984
package main

import "fmt"

func main() {
	var n int
	var h []int

	fmt.Scan(&n)
	h = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}

	var res int
FOR_LABEL:
	for i := 0; i < n; i++ {
		if i == 0 {
			res++
			continue
		}
		for j := 0; j < i; j++ {
			if h[j] > h[i] {
				continue FOR_LABEL
			}
		}
		res++
	}

	fmt.Println(res)
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	
	if (a == b && b == c && a % 2 == 0) {
		cout << -1 << endl;

		return 0;
	}

	int ans = 0;
	int ta, tb, tc;
	while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
		ta = a / 2;
		tb = b / 2;
		tc = c / 2;

		a = tb + tc;
		b = ta + tc;
		c = tb + ta;

		ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define INF 1e9
#define MOD 1000000007;//1e9+7

void solve() {
    int N;
    cin >> N;
    vector<tuple<string, int, int>>V(N);
    for (int i = 0; i < N; i++) {
        string S;
        int P;
        cin >> S >> P;
        V[i] = make_tuple(S, -P, i + 1);
    }

    sort(V.begin(), V.end());
    for (int i = 0; i < N; i++)cout<<get<2>(V[i]) << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
//Moh_K_Imar .......
//28/08/2020  ... 11,35.
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a,b;
    cin>>a>>b;
    ll x=a*3; ll y=x+b;
    cout<<y/2<<endl;

    return 0;
}



Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

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

  int n;
  int64 x;
  std::cin >> n >> x;

  std::vector<int64> a(n);

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

  constexpr int64 kInf = (1LL << 50);
  int64 ans = kInf;
  std::vector<int64> b(a.begin(), a.end());

  for (int i = 0; i < n; i++) {
    ans = std::min(ans, std::accumulate(b.begin(), b.end(), 0LL) + i * x);

    for (int j = 0; j < n; j++) {
      b[j] = std::min(b[j], a[(j - (i + 1) + n) % n]);
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int x,y,a,b,c;
vector<int> v1,v2,v3;
vector<int> v;

int32_t main()
{
    IOS
    cin>>x>>y>>a>>b>>c;
    for (int i=1;i<=a;i++)
    {
        int z;
        cin>>z;
        v1.pb(z);
    }
    for (int i=1;i<=b;i++)
    {
        int z;
        cin>>z;
        v2.pb(z);
    }
    for (int i=1;i<=c;i++)
    {
        int z;
        cin>>z;
        v3.pb(z);
    }
    sort(all(v1));
    sort(all(v2));
    sort(all(v3));
    reverse(all(v1));
    reverse(all(v2));
    reverse(all(v3));

    int ans=-1,sum=0;
    for (int i=0;i<x;i++)
    {
        sum+=v1[i];
        v.pb(v1[i]);
    }
    for (int i=0;i<y;i++)
    {
        sum+=v2[i];
        v.pb(v2[i]);
    }

    sort(all(v));
    reverse(all(v));

    ans=max(ans,sum);
    for (int i=0;i<min(c,x+y);i++)
    {
        sum-=v.back();
        v.pop_back();
        sum+=v3[i];
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4852
import java.util.Scanner;

class Main{

	public static void main(String[] args) {




		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		int[] data = new int[N];

		for(int i = 0;i < N; i++){
			data[i] = scan.nextInt();
		}

		long[] ansdata = new long[N];

		for(int i = 0;i <= N-K; i++){
			ansdata[i] = Math.min(Math.abs(data[i]) + Math.abs(data[i]-data[i+K-1]),Math.abs(data[i+K-1]) + Math.abs(data[i]-data[i+K-1]))  ;


		}
		long min = Integer.MAX_VALUE;
		for(int i= 0;i <= N-K;i++){
			min = Math.min(min, ansdata[i]);
		}
		
		
			System.out.println(min);
		



	}


}


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

using namespace std;

int c[26];

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	for(char x : s) c[x - 'a']++;
	long long ans = 1LL * n * (n + 1) / 2;
	for(int i = 0; i < 26; i++) ans -= 1LL * c[i] * (c[i] + 1) / 2;
	cout << ans + 1;
}

Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] S = new char[H][W];
		for(int i=0; i<H; i++) {
			String temp = sc.next();
			for(int j=0; j<W; j++) {
				S[i][j] = temp.charAt(j);
			}
		}
		char[][] ans = new char[H][W];
		for(int i=0; i<H; i++) {
			for(int j=0; j<W; j++) {
				if(S[i][j] == '#') {
					ans[i][j] = '#';
				} else {
					boolean li = i-1>=0;
					boolean ui = i+1<H;
					boolean lj = j-1>=0;
					boolean uj = j+1<W;
					int count = 0;
					if(li&&lj&&S[i-1][j-1]=='#') count++;
					if(li&&S[i-1][j] == '#') count++;
					if(li&&uj&&S[i-1][j+1] == '#') count++;
					if(lj&&S[i][j-1]=='#') count++;
					if(uj&&S[i][j+1]=='#') count++;
					if(ui&&lj&&S[i+1][j-1]=='#') count++;
					if(ui&&S[i+1][j] == '#') count++;
					if(ui&&uj&&S[i+1][j+1]=='#') count++;
					ans[i][j] = (char)(count+'0');
				}
			}
		}
		for(int i=0; i<H; i++) {
			for(int j=0; j<W; j++) {
				System.out.print(ans[i][j]);
			}
			System.out.println();
		}
	}
	
	// print
	static void print(String s) {
		System.out.println(s);
	}
	
	// union find lib
	// usage:
	// 最初にinitを呼ぶ
	// root: 直接は呼ばないで
	// unite: まとめる
	// same: グループ判定
	static void init(int par[], int N) {
		for(int i=0; i<N; i++) {
			par[i] = i;
		}
	}
	
	static int root(int x, int [] par) {
		if(par[x] == x) {
			return x;
		} else {
			return (par[x] = root(par[x], par));
		}
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}
	
	// end union find lib
	
	// number lib
	
	static int max(int...ls) {
		int ans = Integer.MIN_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.max(ans, ls[i]);
		}
		return ans;
	}
	
	static int min(int...ls) {
		int ans = Integer.MAX_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.min(ans, ls[i]);
		}
		return ans;
	}
	
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
	
	// end number lib
}

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

using namespace std;

vector<int> factorize(int x) {
  vector<int> factors;
  for (int a = 1; a * a <= x; a++) {
    if (x % a == 0) {
      factors.push_back(a);
      if (a * a != x) {
        factors.push_back(x / a);
      }
    }
  }
  sort(factors.begin(), factors.end());
  return factors;
}

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

  unordered_map<int64_t, int> counts;
  for (int i = 0; i < N; i++) {
    counts[A[i]]++;
  }

  int answer = 0;
  for (int i = 0; i < N; i++) {
    counts[A[i]]--;
    {
      vector<int> F = factorize(A[i]);
      F.push_back(1);
      F.push_back(A[i]);
      bool ok = true;
      for (int f : F) {
        if (counts[f] > 0) {
          ok = false;
          break;
        }
      }
      if (ok) answer++;
    }
    counts[A[i]]++;
  }

  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 33172
lst = [int(input()) for _ in range(5)]

sum = 0
edge = 10

for ele in lst:
    if ele % 10 == 0:
        # do something
        sum += ele
    else:
        sum += ((ele - 1) // 10 + 1) * 10
        edge = min(edge, ele % 10)

print(sum + edge - 10)


Measured memory_bytes: 2940
using System;

namespace Hello
{
class A
	{
  static void Main(string[] args)
    {
    var N = int.Parse(Console.ReadLine());
    var A = N / 1000;
    var B = A * 1000 + 1000 - N;
    if (N % 1000 == 0){
      B = 0;
    }
    Console.WriteLine(B);
  }
}
}

Measured memory_bytes: 27524
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize ("Ofast,unroll-loops,-ffloat-store,no-stack-protector")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

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

string to_string(const string& s) { return '"' + s + '"'; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
    #define debug(...) cout << "#" << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 3
#endif
 
#define cin_exception cin.exceptions(cin.failbit);
#define cout_precision cout.setf(ios::fixed); cout.precision(15);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using ld = long double;  using ui = uint_fast32_t;
using ll = int_fast64_t; using ul = uint_fast64_t;

// -----------------------------------------------------------------------------

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
int n, k;
int cn[N];

inline void madd(int &a, int b) { a += b; if (a >= MOD) a -= MOD; }
inline void msub(int &a, int b) { a -= b; if (a < 0) a += MOD; }
inline int mmul(int a, int b) { return (ll)a * b % MOD; }
int mpow(int a, ll b) { int r = 1; for (b %= (MOD - 1); b > 0; b >>= 1) { if (b & 1) r = mmul(r, a); a = mmul(a, a); } return r; }

void solve() {
    cin >> n >> k;
    int re = 0;
    for (int g = k; g >= 1; --g) {
        cn[g] = mpow(k / g, n);
        for (int gx = 2 * g; gx <= k; gx += g) {
            msub(cn[g], cn[gx]);
        }
        madd(re, mmul(g, cn[g]));
    }
    cout << re << '\n';
}

// -----------------------------------------------------------------------------

int main() {
    fast_io;
#ifdef LOCAL
    cin_exception;
#endif
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 3972
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int64 s;
    cin >> s;
    int64 x = 1000000000;
    int64 y = 1;
    int64 xx = (x-s%x)%x;
    int64 yy = (s+xx)/x;

    cout << 0 << " " << 0 << " ";
    cout << x << " " << y << " ";
    cout << xx << " " << yy << endl;
}


Measured memory_bytes: 384
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h> 
#include <stddef.h> 
#include <stdint.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h>

int main()
{
    int n;
    scanf("%d",&n);
    int ones;

    while(n%10!=0)
    {
        ones++;
        n-=1;
    }

    if(ones ==2||ones ==4||ones ==5||ones==7||ones==9)
        printf("hon");
    else if(ones ==0||ones ==1||ones ==6||ones==8)
        printf("pon");
    else
    {
        printf("bon");
    }
    
    return 0;
}


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

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

  a = N / 1000;
  b = (N - a * 1000) / 100;
  c = (N - (a * 1000) - (b * 100)) / 10;
  d = N - (a * 1000) - (b * 100) - (c * 10);
  
  if (a == b && b == c) {
	cout << "Yes" << endl;
  }
  
  else if (b == c && c == d) {
  	cout << "Yes" << endl;
  }
  
  else if (a == b == c == d) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}

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

all = s.count('R') * s.count('G') * s.count('B')
max_diff = (n - 3) // 2
for i in range(max_diff + 1):
    for j in range(n - i - i - 2):
        if s[j] != s[j + 1 + i] and s[j] != s[j + 1 + i + 1 + i] and s[j + 1 + i] != s[j + 1 + i + 1 + i]:
            all -= 1
print(all)


Measured memory_bytes: 9196
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
int main(){
	int n=0;
	scanf("%d\n",&n);
	double money=0;
	char type[5];
	double ans=0;
	for(int i=0;i<n;i++){
		scanf("%lf %s\n",&money,type);
		if(type[0]=='J'){
			ans=ans+money;
		}else{
			ans=ans+money*380000.0;
		}
	}
	printf("%lf\n",ans);
}


Measured memory_bytes: 128
import math
n=int(input())
A=[0]*n
cnt=0
for i in range(0,n):
    A[i]=int(input())
for i in range(0,n):
    if A[i]<2: pass
    elif A[i]==2 or A[i]==3 or A[i]==5 or A[i]==7:
        cnt+=1
    else:
        x=int(math.sqrt(A[i])+1)
        for j in range(2,x):
            if A[i]%j==0:
                break
            else: pass
            if j==x-1:
                cnt+=1
            else: pass
print(cnt)


Measured memory_bytes: 6048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

//a,b,c,d,eのうち一番小さい人数に全ての交通手段を合わせても変わらない
int main(){
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    //{}で配列にすると2つ以上もminで扱える
    ll minmove = min({a,b,c,d,e});
    ll ans = ((n+minmove-1)/minmove) +4;
    cout << ans << endl;


}

Measured memory_bytes: 3604
N,M,Q = map(int,input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int,input().split())
import itertools
ans = 0
for seq in itertools.combinations_with_replacement(range(1,M+1),N):
    score = 0
    for i in range(Q):
        if seq[b[i]-1] - seq[a[i]-1] == c[i]:
            score += d[i]
    ans = max(ans,score)
print(ans)


Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std; 
  
typedef long long ll; 
typedef pair<ll, ll> pll;
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
 
#define MOD 1000000007  
#define ffor(a, b, c) for (ll(a) = (b); (a) < (c); ++(a))  
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL)); 
#define rep(i, n) ffor(i, 0, n) 
#define ff first 
#define ss second  
#define pb push_back 
#define all(v) v.begin(), v.end()  
#define TC(t) while (t--) 
#define N 200005
#define inf 1e18
#define modd 998244353
#define pp(var) cout<<var<<"\n";
#define pm(var1, var2) cout<<var1<<" "<<var2<<"\n"; 

ll binpow(ll x,ll y){
    ll res = 1;
    while(y){
        if(y&1) res = (res*x)%MOD;
        y= y>>1;
        x = (x*x)%MOD;
    }
    return res%MOD;
}

int main(){
    fast;
    ll l,r,i,j,m,k,a,b,c,q,t,x,y,d,n;
    cin>>n>>k;
    ll ans = 0;
    i=0;j=n;
    l=0;r=0;
    for(x=0;x<k;++x){
        l=(l+i)%MOD; r=(r+j)%MOD;
        i++; --j;
    }
    for(x=k;x<=n;x++){
        ans = ( ans + r-l+1)%MOD;
        l=(l+i)%MOD; r=(r+j)%MOD;
        ++i; --j;
    }
    if(ans<0) ans += MOD;
    pp(ans+1);
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string N;
    cin >> N;
    if(N[0] == N[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int binaryS(vector<int> v,int a){
    int right=v.size()-1;
    int left=0;
    int mid,ans;
    while(1){
        if(right-left==1){
            if((v[right]-a)<(a-v[left]))
                ans=v[right];
            else
                ans=v[left];
            break;
        }
        mid=(left+right)/2;
        if(v[mid]>a)
            right=mid;
        else if(v[mid]<a)
            left=mid;
        else{
            ans=a;
            break;
        }
    }

    return ans; 
}

int main(){
    int n;
    cin>>n;
    vector<int> v;
    for(int i = 0; i < n; ++i){
        int tmp;
        cin>>tmp;
        v.push_back(tmp);
    }

    sort(v.begin(), v.end());
    if(n==2)
    {
        cout<<v[1]<< " "<<v[0];
        cout<<endl;
        return 0;
    }


    int mx=v[n-1];
    int mm=(mx+1)/2;
    v.pop_back();

    cout<<mx<< " "<<binaryS(v,mm);
    cout<<endl;


    return 0;
    
}

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

int main() {
  int m, n;
  char s[51];
  scanf("%d %d", &n, &m);
  vector<vector<int>> a(n, vector<int>(n)), b(m, vector<int>(m));
  for(int i = 0; i < n; i++) {
    scanf("%s", s);
    for(int j = 0; j < n; j++) a[i][j] = s[j];
  }
  for(int i = 0; i < m; i++) {
    scanf("%s", s);
    for(int j = 0; j < m; j++) b[i][j] = s[j];
  }
  for(int i = 0; i <= n - m; i++) {
    for(int j = 0; j <= n - m; j++) {
      int f = 1;
      for(int k = 0; k < m; k++)
        for(int l = 0; l < m; l++)
          if(a[i + k][j + l] != b[k][l]) f = 0;
      if(f) {
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int h, w; cin >> h >> w;
	vector<string> v(h);
	rep(i, h) cin >> v[i];
	
	rep(it, 1 << (h + w - 2)){
		vector<string> u(h, string(w, '.'));
		int y = 0, x = 0;
		bool ok = 1;
		rep(i, h + w - 2){
			u[y][x] = '#';
			if(it >> i & 1) y++; else x++;
			if(y >= h || x >= w){
				ok = 0; break;
			}
		}
		
		if(!ok) continue;
		u[y][x] = '#';
		
		if(y == h - 1 && x == w - 1 && u == v){
			cout << "Possible" << endl;
			return 0;
		}
	}
	cout << "Impossible" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#define ll long long

using namespace std;


void solve(){
    int n;
    cin >> n;
    if(n >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define inf 1000000000
#define maxs(x,y) (x = max(x , y))
#define mins(x,y) (x = min(x , y))
using namespace std;
typedef long long int ll;

int main(){

  int H,W,i,j;
  cin >> H >> W ;
  char a[H][W];
  bool x[H]={false};
  bool y[W]={false};

  for(i=0 ; i<H ; i++){
    for(j=0 ; j<W ; j++){
      cin >> a[i][j];
      if(a[i][j] == '#'){
        x[i] = true;
        y[j] = true;
      }
    }
  }

  for(i=0 ; i<H ; i++){
    if(!x[i]){
      continue;
    }
    for(j=0 ; j<W ; j++){
      if(!y[j]){
        continue;
      }
      cout << a[i][j];
    } 
    cout << "\n"; 
  }
}


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

int main()
{
    int r, g, b;
    cin >> r >> g >> b;

    int n = r * 100 + g * 10 + b;
    if( n % 4 == 0 ) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf std::numeric_limits<double>::infinity()
#define DECI(n) fixed<<showpoint<<setprecision(n)
#define MOD 1000000007LL
#define FOR(i,start,end) for (int i=start;i<end;i++)
#define FORR(i,end,start) for(int i=end-1;i>start;i--)
#define INPUT(arr,n) FOR(i,0,n) cin>>arr[i];
#define INPUT2d(arr,n,k) FOR(i,0,n) FOR(j,0,k) cin>>arr[i][j];
#define SIZE 100005
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))

int main(){
string s;
  getline (cin,s);
 
if(s[2]==s[3] && s[4]==s[5])
{
cout<<"Yes"<<endl;
}
    else {
      cout<<"No"<<endl;
    }
  
return 0;
}








Measured memory_bytes: 256
# 点数計算
def scoring(last_, c, s, t, d, score):
    # score += s[d][t[d]-1]
    score = s[d][t]
    k = 8
    
    for i in range(len(c)):
        # score -= c[i] * (d+1 - last_[d][i])
        # score -= c[i] * (d + 1 - last_[i])
        score -= k * c[i] * (d - last_[i]) + c[i] * (k * (k+1)) / 2
    return score


# input
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    s.append([int(i) for i in input().split()])
# t = []
# for i in range(D):
#     t.append(int(input()))
last = [[0 for i in range(len(c))] for j in range(D+1)] # last[d][i]

ans = []
for d in range(D):
    # last[d][t[d]-1] = d+1
    last_dummy = last[d][:]
    score = -float("inf")
    t_d = 0
    for t in range(len(c)):
        last_dummy2 = last_dummy[:]
        last_dummy2[t] = d+1
        if score < scoring(last_dummy2, c, s, t, d, score):
            score = scoring(last_dummy2, c, s, t, d, score)

            t_d = t

    ans.append(t_d)
    last[d][t_d] = d+1


    # last更新
    for i in range(len(c)):
        last[d+1][i] = last[d][i]


[print(ans[i]+1) for i in range(D)]





Measured memory_bytes: 9648
n, q = gets.split.map(&:to_i)
s = gets.chomp
hist = Array.new(n, 0)
count = 0
for i in 0...(n - 1) do
  if s[i] == "A" && s[i + 1] == "C"
    count += 1
  end
  hist[i + 1] = count
end
q.times do
  l, r = gets.split.map(&:to_i)
  puts hist[r - 1] - hist[l - 1]
end


Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
const int N=100010;

int main()
{
    IOS;
    string s;cin>>s;
    int n=s.length();
    int l=0,r=n-1;
    int ans=0;
    while(l<=r)
    {
        if(s[l]==s[r])l++,r--;
        else if(s[l]=='x')l++,ans++;
        else if(s[r]=='x')r--,ans++;
        else{
            ans=-1;
            break;
        }
    }
    cout<<ans<<endl;
}








Measured memory_bytes: 3728
#include<cstring>
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
double a,b,c,d;
double deg,ans,pi=acos(-1.0);
int main() {
    scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
    double d1=d*6.0,d2=c*30.0+d*0.5;
    deg=max(d1,d2)-min(d1,d2);
    ans=sqrt(a*a+b*b-2.0*a*b*cos(deg/180.0*pi));
    printf("%.20lf\n",ans);
    return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);

    ll total = 0;
    ll dis = 0;
    REP(i, N){
        cin >> A[i];
        total += A[i];
        total = total % MOD;
        dis += (A[i]*A[i]) % MOD;
        dis = dis % MOD;
    }

    // cout << total << endl;
    // cout << dis << endl;
    total = (total*total) % MOD;

    cout << ((total-dis + MOD) % MOD) * modinv(2, MOD) % MOD << endl;

    return 0;
}

Measured memory_bytes: 4772
#include<bits/stdc++.h>
#define PB push_back
using namespace std;
typedef vector<int> VI;
int n, m, a, b;

VI d1, d2;
int use = 0;
signed main()
{
  cin >> n >> m >> a >> b;
  for(int i = 0; i < n; i++){
    int d;
    cin >> d;
    d1.PB(d);
  }

  for(int i = 0; i < d1.size(); i++){
    if(d1[i] < a){
      break;
    }
    else{
      d2.PB(d1[i]);
    }
  }

  if(n - d2.size() < m){
    while(d2.size()){
      if(*(d2.end() - 1) <= b){
	d2.erase(d2.end() - 1);
      }
      else{
	break;
      }
    }
  }
  
  cout << d2.size() << endl;
  return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
typedef long long ll;

ll k, now = 0;
char ans[100];

void dfs(ll a, ll b) {
  ll i;
  if(a) {
    for(i = (0 > ans[a - 1] - '0' - 1 ? 0 : ans[a - 1] - '0' - 1); i <= (9 < ans[a - 1] - '0' + 1 ? 9 : ans[a - 1] - '0' + 1); ++i) {
      ans[a] = i + '0';
      if(a != b) dfs(a + 1, b);
      else now++;
      if(now == k) return;
    }
  } else {
    for(i = 1; i < 10; ++i) {
      ans[0] = i + '0';
      if(b) dfs(1, b);
      else now++;
      if(now == k) return;
    }
    dfs(0, b + 1);
  }
}

int main(void) {
  ll i;
  scanf("%lld", &k);
  for(i = 0; i < 100; ++i) ans[i] = 0;
  dfs(0, 0);
  printf("%s", ans);
  return 0;
}

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

int main(){
    ll x, y;
    cin >> x >> y;

    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, x);
    set<ll> viewed;
    while(que.size()){
        auto p = que.top(); que.pop();
        if(viewed.count(p.second) != 0) continue;
        if(p.second == y){
            cout << p.first << endl;
            break;
        }
        viewed.insert(p.second);
        que.emplace(p.first+1, -p.second);
        ll abs_diff = abs(abs(p.second) - abs(y));
        ll nx = p.second + abs_diff;
        if(abs(abs(nx) - abs(y)) < abs_diff){
            que.emplace(p.first + abs_diff, nx);
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  string s,t,v;
  int cnt=0;
  cin>>s;
  t=s;
  reverse(all(s));
  v=s;
  rep(i,s.size()){
    if(t[i]!=v[i])
      cnt++;
  }
  cout<<cnt/2<<endl;
}

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

using namespace std;

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


Measured memory_bytes: 256
n=int(input())
w={}
d=[]
for i in range(n):
    x,y=map(int, input().split())
    d.append((x,y))

chk=0
for i in range(n):
    a=d[i][0]
    b=d[i][1]
    for j in range(n):
        if i==j: continue
        p=d[j][0]
        q=d[j][1]
        if (a-p,b-q) in w:
            w[(a-p,b-q)]+=1
        else:
            w[(a-p,b-q)]=1
        chk=max(chk,w[(a-p,b-q)])
print(n-chk)

Measured memory_bytes: 39664
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;
  int links = n - 1 - m;
  if (links == 0) {
    cout << 0;
  } else if (links * 2 > n) {
    cout << "Impossible";
  } else {
    vector<int> a(n);
    cin >> a;
    vector<int> vec;
    vector<vector<int>> g(n);
    for (int rep = 0; rep < m; ++rep) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    vector<bool> vis(n);
    vector<int> tmp;
    function<void(int)> dfs = [&](int u) {
      vis[u] = true;
      tmp.push_back(a[u]);
      for (int v : g[u])
        if (!vis[v])
          dfs(v);
    };
    ll ans = 0;
    for (int i = 0; i < n; ++i)
      if (!vis[i]) {
        dfs(i);
        auto it = min_element(tmp.begin(), tmp.end());
        ans += *it;
        vec.insert(vec.end(), tmp.begin(), it);
        vec.insert(vec.end(), it + 1, tmp.end());
        tmp.clear();
      }
    nth_element(vec.begin(), vec.begin() + (links - 1), vec.end());
    ans += accumulate(vec.begin(), vec.begin() + (links - 1), 0LL);
    cout << ans;
  }


#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 7416
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<pll,ll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define piii pair<pii, int>
#define pb push_back
const ll llinf = 2e18 + 7;
const int inf = 2e9 + 7;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 1;
const ll M = 1e3 + 5;
const ld pi = 3.14159265358979; 
vector<ll> preA,preB;
bool check(int mid,int k,int n,int m) {
    // cout<<mid<<" ";
    for(int i=0;i<=mid;i++) {
        ll rem = mid - i;
        if(i==0) {
            if(mid <= m) {
                if(preB[mid-1] <= k) {
                    return 1;
                }
            }
            continue;   
        }
        if(rem <= m && i <= n) {
            ll sum = preA[i-1];
            if(rem-1>=0) sum += preB[rem - 1];
            if(sum <= k) return 1;
        } 
    }
    // cout<<endl;
    return 0;
} 
void solve() {
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n),b(m);
    ll sum = 0;
    preA = vector<ll>(n);
    preB = vector<ll>(m);
    for(int i=0;i<n;i++) {
        cin>>a[i];
        sum += a[i];
        preA[i] = sum;
    }
    sum = 0;
    for(int i=0;i<m;i++) {
        cin>>b[i];
        sum += b[i];
        preB[i] = sum;
        // cout<<preB[i]<<" ";
    }
    ll ans = 0;
    ll lb = 1,ub = n+m;
    while(lb<=ub) {
        int mid = (lb + ub)/2;
        if(check(mid,k,n,m)) {
            ans = mid;
            lb = mid + 1;
        }   
        else {
            ub = mid - 1;
        }
    }
    cout<<ans;
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    
    // cin>>t;
    while(t--) {
        solve();
        cout<<"\n";
    }
    return 0; 

}


Measured memory_bytes: 9532