akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  int cnt = 0;
  REP(i, s.size()){
    if(s[i] == 'C' && cnt == 0) cnt++;
    if(s[i] == 'F' && cnt == 1) cnt++;
  }

  if(cnt == 2) Yes;
  else No;

  return 0;
}

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

int A, B, C, D, E, F;
int total, suger;
bool dp[3001][3001];

P cmax(P p1, P p2) {
  return (p2.first * p1.second < p1.first * p2.second) ? p2 : p1;
}

void dfs(int t, int s) {
  if (dp[t][s]) return;

  P p{t, s};
  if (t + 100 * A <= F) {
    dfs(t + 100 * A, s);
    dp[t + 100 * A][s] = true;
    p = cmax(p, {t + 100 * A, s});
  }
  if (t + 100 * B <= F) {
    dfs(t + 100 * B, s);
    dp[t + 100 * B][s] = true;
    p = cmax(p, {t + 100 * B, s});
  }
  if (t + C <= F && cmax({100 + E, E}, {t + C, s + C}).second == E) {
    dfs(t + C, s + C);
    dp[t + C][s + C] = true;
    p = cmax(p, {t + C, s + C});
  }
  if (t + D <= F && cmax({100 + E, E}, {t + D, s + D}).second == E) {
    dfs(t + D, s + D);
    dp[t + D][s + D] = true;
    p = cmax(p, {t + D, s + D});
  }
  p = cmax(p, {total, suger});
  total = p.first;
  suger = p.second;
}

main() {
  cin >> A >> B >> C >> D >> E >> F;
  dfs(100 * A, 0);
  cout << total << ' ' << suger << endl;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;

int main(){
    int N,A,B,C,D; cin >> N >> A >> B >> C >> D;
    string S; cin >> S;

    bool isOK = true;
    for(int i = A-1; i < C-1; i++){
        if (S[i]=='#' && S[i+1]=='#'){
            isOK = false;
        }
    }
    for(int i = B-1; i < D-1; i++){
        if (S[i] == '#' && S[i+1] == '#'){
            isOK = false;
        }
    }
    if(D < C){
        bool isNG = true;
        for(int i = B-1; i < D; i++){
            if (S[i-1]=='.' && S[i] == '.' && S[i+1] == '.'){
                isNG = false;
            }
        }
        if(isNG) isOK = false;
    }
    if(isOK) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int a, b;
	cin >> a >> b;
	cout << a*b << endl;
	return 0;
}

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

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)


int main(){
	int n,i;
	cin>>n>>i;

	ANS(n-i+1);

return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Xmax = 1000;
int X, Y, Z, K;
ll A[Xmax], B[Xmax], C[Xmax];

int main(){
	cin >> X >> Y >> Z >> K;
	for(int i=0; i<X; i++) cin >> A[i];
	for(int i=0; i<Y; i++) cin >> B[i];
	for(int i=0; i<Z; i++) cin >> C[i];

	vector<ll> ab;
	for(int i=0; i<X; i++){
		for(int j=0; j<Y; j++){
			ab.push_back(A[i]+B[j]);
		}
	}
	sort(ab.begin(), ab.end());
	reverse(ab.begin(), ab.end());
	ab.resize(K);
	vector<ll> abc;
	for(int i=0; i<ab.size(); i++){
		for(int j=0; j<Z; j++){
			abc.push_back(ab[i]+C[j]);
		}
	}
	sort(abc.begin(), abc.end());
	reverse(abc.begin(), abc.end());
	for(int i=0; i<K; i++){
		cout << abc[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 43364
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        if (4*a*b<(c-a-b)*(c-a-b)&&c-a-b>0)System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 35716
S=gets.chomp
Q=gets.to_i

left = []
right = []
rev = false
Q.times do
  a,b,c = gets.split
  if a == '1'
    rev = !rev
  elsif (b == '1' && !rev) || (b == '2' && rev)
    left << c
  else
    right << c
  end
end

s = left.reverse.join + S + right.join
s = s.reverse if rev
puts s


Measured memory_bytes: 18428
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int A, B, C;

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

  cin >> A >> B >> C;
  if (C <= A+B+1) cout << B+C << endl;
  else cout << A+B+1+B << endl;

  return 0;
}


Measured memory_bytes: 888
import std.algorithm;
import std.range;
import std.math;
import std.regex;
import std.array;
import std.container;
import std.stdio;
import std.string;
import std.conv;

string[] readStrs() { return readln.chomp.split(' '); }
T[] readInts(T)() { return readln.chomp.split(' ').map!(to!T).array(); }
T readInt(T)() { return readln.chomp.to!T; }

void main()
{
    auto N = readInt!int;
    auto Ts = readInts!int;
    auto M = readInt!int;
    foreach(i; 0 .. M){
        auto px = readInts!int;
        auto p = px[0] - 1,
             x = px[1];

        auto v = Ts[p];
        Ts[p] = x;
        writeln(Ts.sum);
        Ts[p] = v;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll,ll> P;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;

ll n;
vl a,b,c;

void input(void){
	cin>>n;
	inputv(a,n);
	inputv(b,n);
	inputv(c,n);
}

void solve(void){
	ll k=0;
    rep(i,n){
    	ll t=a[i]-1;
    	k+=b[t];
    	if(i<n-1&&a[i+1]==a[i]+1)k+=c[t];
    }
    
    cout<<k<<endl;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
}

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

using namespace std;

vector<string> rep;
string actions = "357";

void brute(string s, int k, int n) {
  if (k == n) {
    if (count(s.begin(), s.end(), '3') > 0 &&
        count(s.begin(), s.end(), '5') > 0 &&
        count(s.begin(), s.end(), '7') > 0) 
      rep.push_back(s);
    return;
  }
  for (auto &a : actions) {
    brute(s+a, k+1, n);
  }
}

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

  string t;
  cin >> t;
  int n = t.size();
  int res = 0;
  string s = "";
  for (int i = 3; i <= n; ++i) {
    brute(s, 0, i);
  }
  int target = stoi(t);
  for (auto &r : rep) {
    if (stoi(r) <= target) {
      res++;
    }
  }

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int n, m;
  cin >> n >> m;
  if (n == m) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(a==b)
	{
		cout<<c;
	}
	else if (a==c)
	{
		cout<<b;
	}
	else
	{
		cout<<a;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
 
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main()
{
    char s[200005]={};
    long int ans=0;
    scanf("%s\n",s);
    int j=strlen(s)-1;
    for(int i=strlen(s)-1;i>=0;i--)
    {
        if(s[i]=='B')
        {
            ans+=j-i;
            j--;
        }
    }
    printf("%ld\n",ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const ll oo = 1e15 + 7;
const int mod = 1e9 + 7, maxn = (2 * 1e3) + 10;
const long double PI = acos(-1);

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, sa = 0, sb = 0;
    cin >> n;

    vector<ll> v(3*n), memo(3*n);
    priority_queue<ll> a, b;

    for (int i=0; i<3*n; i++){
        cin >> v[i];
        if (i<2*n){
            sa+=v[i];
            a.push(-v[i]);
            if ((int)a.size() > n){
                sa += a.top();
                a.pop();
            }
            memo[i] = sa;
        }
    }

    ll ans = -oo;

    for (int i=3*n-1; i>=n; i--){
        sb += v[i];
        b.push(v[i]);
        if ((int)b.size() > n) {
            sb-=b.top();
            b.pop();
        }
        if (i<=2*n) ans = max(ans, memo[i-1] - sb);
    }

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

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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define scn(var)         cin >> var;
#define pYes()           prt("Yes")
#define pNo()            prt("No")
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arr(a,n);

  int max1=0, max2=0;
  rep(i,n){
    if(max1<a[i]){
      max2=max1;
      max1=a[i];
    } else if(max2<=a[i]){
      max2=a[i];
    }
  }

  rep(i,n){
    if(a[i]==max1){
      prt(max2);
    } else {
      prt(max1);
    }
  }
}


Measured memory_bytes: 2432
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

  ll ans = 0LL;
  for(int i=0;i<N-1;i++){
    ans += A[i] / 2;
    A[i] %= 2;
    if(A[i] == 1 && A[i+1] > 0){
      ans++;
      A[i]--;
      A[i+1]--;
    }
  }

  ans += A[N-1] / 2;

  cout << ans << endl;
  return 0;

}

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

using namespace std;
using ll = long long;
int n,m,ans;
double x,y;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>n>>m;
    for(int i=1; i<=n; i++){
        cin>>x>>y;
        ans += sqrt(pow(x,2)+pow(y,2)) <= m;
    }
    cout<<ans;
}


Measured memory_bytes: 3856
program march
  implicit none
  integer :: n, i, j, k
  integer(8) :: cnt(5) = 0_8, ans = 0_8
  character(10) :: s
  read(*,*) n
  do i = 1, n
    read(*,*) s
    select case (s(1:1))
    case ("M")
      cnt(1) = cnt(1)+1_8
    case ("A")
      cnt(2) = cnt(2)+1_8
    case ("R")
      cnt(3) = cnt(3)+1_8
    case ("C")
      cnt(4) = cnt(4)+1_8
    case ("H")
      cnt(5) = cnt(5)+1_8
    end select
  end do
  do concurrent (i = 1:5, j = 1:5, k = 1:5, i < j .and. j < k)
    ans = ans+cnt(i)*cnt(j)*cnt(k)
  end do
  write(*,'(i0)') ans
end program march

Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[200009];
int main() {
	cin >> n;
	for (int i = 0; i < 2 * n; i++) cin >> a[i];
	sort(a, a + 2 * n);
	long long ret = 0;
	for (int i = 0; i < 2 * n; i++) ret += 1LL * a[i] * i;
	cout << fixed << setprecision(15) << 1.0L * ret / (2 * n - 1) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<complex>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
    bool c[6][6];
    int h,w,k,ans=0,i,j,t,cnt=0,x=0,y=0,cx,cy;
    char s;
    cin >> h >> w >> k;
    for(i=0;i<h;i++)for(j=0;j<w;j++){
      cin >> s;
      if(s=='#'){
        c[i][j]=1;
        cnt++;
      }
      else c[i][j]=0;
    }
    k=cnt-k;
    for(t=0;t<pow(2,h+w);t++){
      cnt=0;
      cx=1;
      for(i=0;i<h;i++){
        cy=1;
        for(j=0;j<w;j++){
          if(c[i][j]*((x&cx)+(y&cy))>0)cnt++;
          cy*=2;
        }
        cx*=2;
      }
      if(cnt==k)ans++;
      x++;
      if(x>=pow(2,h)){
        x=0;
        y++;
      }
    }
    cout << ans;
    return 0;
}

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


int main() {
    int R,G,B,N;
    cin >> R >> G >> B >> N;
int res=0;
for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++){
int temp=N-R*i-G*j;
if(temp>=0 && temp%B==0){res++;}
}}



    cout << res << endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll int128_t
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
#if !defined(ONLINE_JUDGE)
#include "debugging.h"
#endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

int const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x){
    return power(x,mod-2,mod);
}

int const N = 1e5+5;
int const inf = 2e9;

void solve(){  
    int i,j;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int t = 0;
    while(a>0 && c >0){
        if(t == 0){
            c -= b;
        }
        else{
            a -= d;
        }
        t^=1;
    }
    if(t == 0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}           

int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


/*

*/

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
#define mod 1000000007
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2.
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

 ll n,a,b,ans=0;
 cin>>n;
 for(int i=0;i<n;i++)
 {
     cin>>a>>b;
     vp.push_back(make_pair(a+b,a-b));
 }
 sort(vp.begin(),vp.end());
 ans++;
 //cout<<vp[0].first<<" "<<vp[0].second<<endl;
 ll cur=vp[0].first;
 for(int i=1;i<vp.size();i++)
 {
     //cout<<vp[i].first<<" "<<vp[i].second<<endl;;
     if(vp[i].second>=cur)
     {
         cur=vp[i].first;
         ans++;
     }
 }
 cout<<ans<<endl;
return 0;
}



Measured memory_bytes: 2420
#include <iostream>
#include <vector>

using namespace std;
using int64 = long long;

int main() {
    int n;
    cin >> n;
    vector<int64> a(n);
    vector<int64> b(n);
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<n; i++) b[i] = a[i]-i-1;
    sort(b.begin(), b.end());

    int64 b1 = 0;
    int64 b2 = 0;
    for (int i=0; i<n; i++) b1 += abs(b[i] - b[n/2-1]);
    for (int i=0; i<n; i++) b2 += abs(b[i] - b[n/2]);

    int64 ans = min(b1, b2);
    cout << ans << endl;
}

Measured memory_bytes: 3328
n=int(input())
result = 0
for i in range(n):
  a = n-i
  while a % 2 == 0:
    a /= 2
    if a == 1:
      result = n-i
      break
  else:
    continue
  break
  
  
if n == 1:
  print(1)
else:
  print(result)

Measured memory_bytes: 2940
fn main() {
    let v = read_vec::<u32>();
    let sum = v[0] * 500;
    if sum >= v[1] {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  cout << n - k + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter

def main():
    A = input()
    N = len(A)
    ans = N * (N-1) // 2 + 1
    cnt = Counter(A)
    for c in cnt:
        ans -= cnt[c] * (cnt[c] - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 40048
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

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

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N, M = MII_split()
Heightis = LII_split()

searched = [False for _ in range(N)]
group_indicies = [-1 for _ in range(N)]

count = 0
groups = []
# while searched.count(False) > 0:
id_count = 0
neighbors = dict()
for _ in range(M):
    A, B = MII_split()
    searched[A - 1] = searched[B - 1] = True
    if A - 1 in neighbors:
        neighbors[A - 1].append(B - 1)
    else:
        neighbors[A - 1] = [B - 1]
    if B - 1 in neighbors:
        neighbors[B - 1].append(A - 1)
    else:
        neighbors[B - 1] = [A - 1]
for k, v in neighbors.items():
    n_heights = []
    for i in v:
        n_heights.append(Heightis[i])
    ma = max(n_heights)
    if ma < Heightis[k]:
        count += 1

# if not searched[A - 1] and not searched[B - 1]:
#     searched[A - 1] = True
#     searched[B - 1] = True
#     group_indicies[A - 1] = group_indicies[B - 1] = id_count
#     count += 1
#     id_count += 1
# elif searched[A - 1] and searched[B - 1]:
#     if group_indicies[A - 1] != group_indicies[B - 1]:
#         new_g_id = group_indicies[A - 1]
#         group_indicies = [new_g_id if i == group_indicies[B - 1] else i for i in group_indicies]
#         count -= 1
# elif not searched[A - 1]:
#     searched[A - 1] = True
#     group_indicies[A - 1] = group_indicies[B - 1]
# elif not searched[B - 1]:
#     searched[B - 1] = True
#     group_indicies[B - 1] = group_indicies[A - 1]

print(count + searched.count(False))

Measured memory_bytes: 36360
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long k = sc.nextLong();
      long[] a = new long [2];
      long div = 0;
      div = n / k;
      a[0] = k * div;
      a[1] = k * (div+1);

      long min = n;
      if( n - a[0] >= 0 && n - a[0] < min ){
        min = n - a[0];
      }
      if( a[1] - n >= 0 && a[1] - n < min ){
        min = a[1] - n;
      }
      System.out.println(min);
	}
}

Measured memory_bytes: 26712
package main

import (
    "fmt"
    "os"
    "bufio"
    "strconv"
)

func main() {
    var sc = bufio.NewScanner(os.Stdin)
    var H, W, N string
    if sc.Scan() {
        H = sc.Text()
    }
    if sc.Scan() {
        W = sc.Text()
    }
    if sc.Scan() {
        N = sc.Text()
    }
    var large int
    var ans int
    var h, _ = strconv.Atoi(H)
    var w, _ = strconv.Atoi(W)
    var n, _ = strconv.Atoi(N)
    if h > w {
        large = h
    } else {
        large = w
    }
    for n > 0{
        n -= large
        ans ++
    }
    fmt.Println(ans)
}


Measured memory_bytes: 640
let (tbl : (string, unit) Hashtbl.t) = Hashtbl.create ~random:true 1000000

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
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["find"; s] -> print_endline (if Hashtbl.mem tbl s then "yes" else "no")
    | [_; s] -> Hashtbl.add tbl s ()
    | _ -> assert false
  done

Measured memory_bytes: 43924
# coding: utf-8
# Here your code !

def func():
    data=[]
    while(True):
        try:
            line=[ int(item) for item in input().rstrip().split(" ") ]
            if(line == [0,0]):
                break
            data.append(line)
        except EOFError:
            break
        except:
            return inputError()
    
    left=1
    numbers=3
    [print(len(sumcombination(left,line[0],numbers,line[1]))) for line in data]

def sumcombination(left,right,numbers,total):
    '''
    left ~ right??????????????°??????(numbers)????????´??°???????¨????total?????????????????????????????????????????????
    '''
    result=[]
    if(numbers==1):
        if( (left <= total) and (right >= total) ):
            result=[total]
        return(result)
    
    for i in range(left,right+1):
        if( numbers == 2):
            if(i >= total-i):
                break
            elif( (i != total-i) and (left <= total-i) and (right >= total-i) ):
                result.append([i,total-i])
        elif( ( len( range(i,right+1) ) < numbers ) or ( sum( range(i+1,i+numbers) ) > total-i ) ):
            break
        elif( sum( range(right-numbers+2,right+1) ) < total-i ):
            continue
        else:
            sub = sumcombination(i+1,right,numbers-1,total-i)
            if(len(sub)>0):
                [items.insert(0,i) for items in sub]
                result.extend(sub)

    return(result)

def inputError():
    print("input error")
    return -1

func()

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

int func(int x) {
	int res;
	if (x == 3) {
		res = 100000;
	}
	else if (x == 2) {
		res = 200000;
	}
	else if (x == 1) {
		res = 300000;
	}
	else res = 0;
	return res;
}

int main() {
	
	int x, y; cin >> x >> y;
	if (x == 1 && y == 1) {
		cout << 1000000 << endl;
		return 0;
	}
	cout << func(x) + func(y) << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
long long n,a[3][102];
int main()
{
    cin>>n;
    for(int i=1;i<=2;i++)
      for(int j=1;j<=n;j++)
        cin>>a[i][j];
    for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
          a[i][j]+=max(a[i-1][j],a[i][j-1]);
    cout<<a[2][n];
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    ll N, W; cin >> N >> W;
    vector<ll> w, v;
    REP(i, N){
        ll w_i, v_i;
        cin >> w_i >> v_i;
        w.PB(w_i);
        v.PB(v_i);
    }
    vector<vector<ll>> dp(N, vector<ll>(W+1, -1));
    for(ll weight = 1; weight <= W; weight++){
        if (weight < w.at(0)){
            dp.at(0).at(weight) = 0;
        }
        else{
            dp.at(0).at(weight) = v.at(0);
        }
    }

    REP(i, N){
        if (i == 0){continue;}
        for(ll j = 1; j <= W; j++){
            if (j < w.at(i)){
                dp[i][j] = dp[i-1][j];
            }
            else{
                dp[i][j] = max(dp[i-1][j-w.at(i)] + v.at(i), dp[i-1][j]);
            }
        }
    }
    cout << dp[N-1][W] << endl;
}


Measured memory_bytes: 82436
/* ex9_1
    sak_Citrus  */

#include <stdio.h>
#include <stdlib.h>

//双方向リストの構造体
typedef struct node{
    char elem;
    struct node *prev;
    struct node *next;
} node;

//リストの後ろ側に追加
void push(node **first,node **last,char elem){
    node *new = (node*)malloc(sizeof(node));
    if(new == NULL)exit(1);
    new->elem = elem;
    new->next = NULL;
    new->prev = *last;
    if(*first == NULL) *first = new;
    else (*last)->next = new;
    *last = new;
}

//末端から取り出す
char pop(node **last){
    char elem;
    node *tmp = *last;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *last = tmp->prev;
    free(tmp);
    return elem;
}

//先頭から取り出す
char popleft(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL)exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    free(tmp);
    return elem;
}

int main(void){
    char elem;
    //キューの長さ
    int count = 0;

    node *first = NULL,*last;
    
    while(1){
        elem = fgetc(stdin);
        //手元環境用
        //if(elem == '\n')break;
        //提出用
        if(elem == EOF)break;
        //Bキーで1文字破棄、それ以外は末端に追加
        if(elem == 'B'){
            //キューが空の状態でpopしないように
            if(count>0){
                pop(&last);
                count--;
                //キューが空になったとき、firstに割り当てられていたノードのメモリも解放されてしまうため
                if(count==0)first = NULL;
            }
        }
        else{
            push(&first,&last,elem);
            count++;
        }
    }
    while(count-->0){
        //先頭から取り出す
        printf("%c",popleft(&first));
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1472
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


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


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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){
    if(a>b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

/*
 *
 * */

int main() {
    int N;
    cin >> N;
    int pre = 0;
    int sum = 0;
    rep(i,N) {
        int H;
        cin >> H;
        if (pre <= H) sum++;
        pre = max(pre, H);
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

int main(){
	string r, a;
	while(cin >> r >> a, r!="0"||a!="0"){
		map<char, int> n;
		rep(i, 4){
			n[r[i]] = 1;
		}
		int hit = 0, blow = 0;
		rep(i, 4){
			if(r[i] == a[i]) hit++;
			blow+=n[a[i]];
		}
		cout << hit << ' ' << blow-hit << endl;
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  ll x[n], y[n];
  rep(i,n) cin >> x[i] >> y[i];
  map<P,int> m;
  rep(i,n) {
    rep(j,n) {
      if(i != j) m[P(x[i]-x[j],y[i]-y[j])]++;
    }
  }
  int ans = 0;
  for(auto k : m) ans = max(k.second,ans);
  cout << n - ans << endl;
  return 0;
}

Measured memory_bytes: 384
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
c = []
for i in range(N):
    c += [str(i+1)]*a[i]
for i in range(H):
    ans,c = c[:W],c[W:]
    if i%2==1:
        ans = ans[::-1]
    ans = ' '.join(ans)
    print(ans)

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

typedef long long ll;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 998244353

ll powmod(ll x, ll y, ll mod)
{
    if (y == 0)
        return 1;

    if (y & 1) {
        return powmod(x*x % mod, y/2, mod) * x % mod;
    } else {
        return powmod(x*x % mod, y/2, mod);
    }
}

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

    ll N;
    cin >>N;
    
    vector<ll> cnt(N,0);
    vector<ll> D(N);
    ll dmax = -1;
    rep(i, N) {
        cin >> D[i];
        cnt[D[i]]++;
        chmax(dmax, D[i]);
    }
// D1(dmax);
// cout << "cnt: "; cout_h(cnt);    
// cout << "D: "; cout_h(D);    
    if (D[0] != 0 || cnt[0] != 1) {
// cout << "bad input(1)\n";
        cout << 0 << endl;
        return 0;
    }

    for (int i = 0; i <= dmax; i++) {
        if (cnt[i] == 0) {
// cout << "bad input(2)\n";
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = 1;

    for (int i = 2; i <= dmax; i++) {
        ans = ans * powmod(cnt[i-1], cnt[i], MOD) % MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	abc := []int{a, b, c}
	m := map[int]bool{}
	ans := 0

	for _, v := range abc {
		if !m[v] {
			m[v] = true
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
int n,m;
int e[51][51];
bool seen[51];

void dfs(int s,int pre = -1){
    seen[s]=true;
    for (int i=0;i < n;i++){
        if (e[s][i] == 1 && seen[i] == false){
            dfs(i,s);
        }
    }
}
int main(){
    cin >> n >> m;
    vector<pair<int,int>> edges(m);
    rep(i,m){
        int x,y;
        cin >> x >> y;
        x--;y--;
        edges[i] = {x,y};
        e[x][y]=1;
        e[y][x]=1;
    }
    int ans=0;
    rep(i,m){
        e[edges[i].first][edges[i].second] = 0;
        e[edges[i].second][edges[i].first] = 0;
        int cnt=0;
        rep(j,n) seen[j] = false;
        rep(k,n){
            if (seen[k]) continue;
            dfs(k);
            cnt++;
        }
        if (cnt > 1) {
            ans++;
            //printf("edge (%d,%d)\n",edges[i].first+1,edges[i].second+1);
        }
            
        e[edges[i].first][edges[i].second] = 1;
        e[edges[i].second][edges[i].first] = 1;
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  int N,M;
  cin >> N>>M;
  vector<vector<int>> s(N, vector<int>(2));
  vector<vector<int>> c(M, vector<int>(2));
  for(int i=0;i<N;i++){
    for(int j=0;j<2;j++){
    cin >> s[i][j];
    }
  }
  for(int i=0;i<M;i++){
    for(int j=0;j<2;j++){
    cin >> c[i][j];
    }
  }

  for(int i=0;i<N;i++){
    int minimum=999999999, d, idx;
    for(int j=0;j<M;j++){
      d = abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]);
      if(minimum>d){
        idx = j+1;
        minimum = d;
      }

    }
      cout << idx<<endl;
  }

}


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

using ll = long long;
#define BITS 40

int main()
{
    ll N, K; cin >> N >> K;
    vector<ll> A(N); for (auto& a : A) cin >> a;

    vector<int> bits(BITS);
    for (int i = 0; i < N; i++) {
        for (int b = 0; b < BITS; b++) {
            if (A[i] & (1LL << b)) bits[b]++;
        }
    }
    ll x = 0;
    for (int b = BITS-1; b >=0; b--) {
        if (bits[b] > N/2 == 0) {
            if ((x | (1LL << b)) <= K) {
                x |= (1LL << b);
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += x^A[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include<unordered_map>
using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}

vector<pii> primefactor(int n){
    vector<pii> ret;
    for(int i = 2; i*i <= n; i++)if(n % i == 0){
        int cnt = 0;
        while(n%i == 0)n /= i, cnt++;
        ret.push_back(pii(i,cnt));
    }
    if(n != 1)ret.push_back(pii(n,1));

    return ret;

}

long long beki(long long a,int n)
{
  long long s=1LL;
  while(n){
    if(n%2)s=(s*a)%MOD;
    a=(a*a)%MOD;
    n/=2;
  }
  return s;
}

signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    unordered_map<int,int> ma;
    rep(i,n){
        vp v = primefactor(a[i]);
        rep(j,v.size()){
            int num = v[j].first;
            int cnt = v[j].second;
            ma[num] = max(ma[num],cnt);
        }
    }
    int l = 1;
    for(auto x: ma){
        int num = x.first;
        int cnt = x.second;
        rep(_,cnt)l *= num, l %= MOD;
    }
    int ans = 0;
    rep(i,n){
        ans += l*beki(a[i],MOD-2)%MOD;
        ans %= MOD;
    }
    cout << ans << endl;

}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#define BIT(n) (1<<(n))
using namespace std;

int count(int x){
    for(int i=21;;--i){
        if(BIT(i)&x)return i;
    }
}

vector<int> make(int a, int b, int c){
    vector<int> res;
    res.push_back(a);
    res.push_back(b);
    res.push_back(c);
    return res;
}
int main(){
    int L;
    cin >> L;
    vector<vector<int> > ans;
    int r = count(L);
    int N = r + 1;
    int M = r * 2;
    for(int i=1;i<N;++i){
        ans.push_back(make(i, i+1, BIT(i-1)));
        ans.push_back(make(i, i+1, 0));
    }
    for(int i=N-1;i>0;--i){
        if(L-BIT(i-1)>=BIT(r)){
            ans.push_back(make(i, N, L-BIT(i-1)));
            L-=BIT(i-1);
            ++M;
        }
    }
    cout << N << " " << M << endl;
    for(int i=0;i<ans.size();++i){
        cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    int a[6];
    a[0] = 0;
    int ans = 0;
    for (int i = 1;i <= 5;i++){
        cin >> a[i];
        if (a[i] == 0){
            ans = i;
        }
    }
    cout << ans << endl;
}



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

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    c = input()

    return N, c


def main(N: int, c: str) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 石の個数（2 <= N <= 200000）
        c (str): 石の色
    """
    # 求解処理
    w = 0
    r = c.count("R")
    ans = max(w, r)
    for n in range(N):
        c_n = c[n]
        if c_n == "W":
            w += 1
        else:
            r -= 1
        ans = min(ans, max(w, r))

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, c = get_input()

    # メイン処理
    main(N, c)


Measured memory_bytes: 9476
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#include <array>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__)
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
template<typename T>
T gcd(T a, T b){
    while(b){
        a %= b;
        swap(a, b);
    }
    return a;
}
struct TwoStacks{
    using T = long long;
    struct Node{
        T val, sum;
        Node(const T &val, const T &sum):val(val), sum(sum){}
    };
    T merge(T l, T r){
        return gcd(l, r);
    }
    stack<Node> front, back;
    int size(){
        return front.size() + back.size();
    }
    T eval(){
        //        assert(front.size() + back.size() > 0);
        if(!back.empty()){
            if(!front.empty()){
                return merge(front.top().sum, back.top().sum);
            }else{
                return back.top().sum;
            }
        }else{
            return front.top().sum;
        }
    }
    void pop_front(){
        //        assert(front.size() + back.size() > 0);
        if(front.empty()){
            front.emplace(back.top().val, back.top().val);
            back.pop();
            while(!back.empty()){
                front.emplace(back.top().val, merge(back.top().val, front.top().sum));
                back.pop();
            }
        }
        front.pop();
    }
    void push_back(const T &val){
        if(!back.empty()){
            back.emplace(val, merge(back.top().sum, val));
        }else{
            back.emplace(val, val);
        }
    }
};
bool isprime(int x){
    for(int i = 2; i * i <= x; i++){
        if(x%i==0)return false;
    }
    return true;
}
int main(){
    int x;
    cin >> x;
    while(!isprime(x))x++;
    cout << x << endl;
}


Measured memory_bytes: 256
A, B, C, D = list(map(int, input().split()))
from fractions import gcd
e = C * D // gcd(C, D)
p1 = B-A+1
p2 = (B//C) + (B//D) - (B//e)
p3 = ((A-1)//C) + ((A-1)//D) - ((A-1)//e)
print(p1 + p3 - p2)

Measured memory_bytes: 5048