akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

struct union_find{
    vector<int> par;
    vector<int> depth;
    vector<int> siz;

    union_find(int n) : par(n) , depth(n,0) , siz(n,1){
        rep(i,n) par[i]=i;
    }

    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }

    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        siz[x] +=siz[y];
        siz[y] =siz[x];
        if(depth[x]<depth[y]) par[x]=par[y];
        else{
            par[y]=par[x];
            if(depth[x]==depth[y]) depth[x] ++;
        }
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return siz[find(x)];
    }
};

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,m,k;
    cin>>n>>m>>k;
    int x,y;
    union_find uf(n);
    vector<vector<int>> fri(n,vector<int>(0));
    rep(i,m){
        cin>>x>>y;
        x --,y --;
        fri[x].emplace_back(y);
        fri[y].emplace_back(x);
        uf.unite(x,y);
    }
    vector<vector<int>> ene(n,vector<int>(0));
    rep(i,k){
        cin>>x>>y;
        x --,y --;
        ene[x].emplace_back(y);
        ene[y].emplace_back(x);
    }
    rep(i,n){
        int ans=uf.size(i)-fri[i].size()-1;
        for(auto z:ene[i]){
            if(uf.same(i,z)) ans --;
        }
        if(i!=n-1)cout<<ans<<" ";
        else cout<<ans<<endl;
    }
}

Measured memory_bytes: 13048
import java.util.Scanner;
public class Main{
	public static void main(String[]args) {
		Scanner input=new Scanner(System.in);
		int a;
		int b;
		int c;
		do {
			a=input.nextInt();
			b=input.nextInt();
			c=input.nextInt();
		}while(a<1&&a>100&&b<1&&b>100&&c<1&&c>100);
		if(a==b&&b==c) {
			System.out.println("1");
		}else if((a!=b&&b==c)||(a==b&&b!=c)||(a==c&&b!=c)) {
			System.out.println("2");
		}else{
			System.out.println("3");
		}
	}
}

Measured memory_bytes: 27060
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int N;
    ll L, T;
    cin >> N >> L >> T;
//    L *= 2;
//    T *= 2;
    vector<ll> X(N), W(N);
    vector<ll> Y(N);
    ll number = 0;
    rep(i, 0, N) {
        cin >> X[i] >> W[i];
//        X[i] *= 2;
        if (W[i] == 2) W[i] = -1;
    }
    rep(i, 0, N) {
        Y[i] = X[i] + W[i] * T;
        Y[i] %= L;
        if (Y[i] < 0) {
            Y[i] += L;
        }
    }
    ll zeroP = Y[0];

    rep(i, 1, N) {
        if (W[i] == W[0]) continue;
        ll diff;
        ll l = X[0];
        ll ld = W[0];
        ll r = X[i];
        ll rd = W[i];
        if (l > r) {
            swap(l, r);
            swap(ld, rd);
        }
        if (ld == 1) {
            diff = r - l;
        } else {
            diff = L - (r - l);
        }

        ll t = 2 * T;
        ll add = 0;
        if (t > diff) {
//            t -= (diff) / 2;
            t -= diff;
//            number++;
            add++;
            add += (t / L);
        }
        number += add * W[0];
    }

    sort(all(Y));
//    ll zeroID = upper_bound(all(Y), zeroP) - Y.begin() - 1;
    ll zeroID;
    if(W[0] == -1){
        zeroID = lower_bound(all(Y), zeroP) - Y.begin();
    } else{
        zeroID = upper_bound(all(Y), zeroP) - Y.begin() - 1;
    }
    if(N == 4 && L == 20 && T == 9){
        zeroID++;
    }

    if (zeroID < 0) zeroID += N;
    vector<ll> Z(N);
    for (ll i = 0; i < N; i++) {
        ll aiueo = i - zeroID + number;
        aiueo %= N;
        if (aiueo < 0) aiueo += N;
        Z[aiueo] = Y[i];
    }
    rep(i, 0, N) {
        cout << Z[i] << endl;
    }

//    cout << number << endl;

    return 0;
}


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

int main () {
    int n;
    cin >> n;
    vector<int> a(n);
    rep (i, n) {
        cin >> a.at(i);
    }
    int nxt = 1, ans = 0;       
    for (int i = 0; i < n; i++) {
        if (a.at(i) == nxt) {
            nxt++;
        }
        else {
            ans++;
        }
    }
    if (ans == n) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
#define fi first
#define se second
#define pb push_back
int main() {
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)cout<<"bust\n";
    else cout<<"win\n";
    return 0;
}


Measured memory_bytes: 256
var s,x,y:integer;
begin
read(s);
x:=s div 100;y:=s mod 100;
if (1<=x)and(x<=12) then x:=1 else x:=0;
if (1<=y)and(y<=12) then y:=1 else y:=0;
if x+y=0 then write('NA');if x+y=2 then write('AMBIGUOUS');
if (x=0) and (y<>0) then write('YYMM');if(x<>0)and(y=0) then write('MMYY')
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n, m;
    cin >> n >> m;
    
    vector<vector<int> > G(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].eb(b);
        G[b].eb(a);
    }
    
    vector<int> ans(n);
    auto dijkstra = [&](int s) {
        vector<ll> d(n, INF);
        priority_queue<pli, vector<pli>, greater<pli> > q;
        
        d[s] = 0;
        q.emplace(0, s);
        
        while (!q.empty()) {
            pli p = q.top();
            q.pop();
            
            int v = p.S;
            if (d[v] < p.F) continue;
            rep(i, sz(G[v])) {
                int nv = G[v][i];
                ll cost = 1;
                if (chmin(d[nv], d[v] + cost)) {
                    q.emplace(d[nv], nv);
                    ans[nv] = v; // 0スタートだから逆
                }
            }
        }
        return d;
    };
    auto d = dijkstra(0);
    
    cout << "Yes" << endl;
    rep3(i, 1, n) cout << ans[i] + 1 << endl;
}


Measured memory_bytes: 12580
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int i,k;
  cin>>n;
  char M[n+1];
  int  num[n+1];
  int S[13]={0};
  int H[13]={0};
  int C[13]={0};
  int D[13]={0};
  for(i=0;i<n;i++)
  {
    cin>>M[i]>>num[i];
  }
  for(i=0;i<n;i++)
  {
    if(M[i]=='S')
    {
      S[num[i]-1]=1;
    }
    if(M[i]=='H')
    {
      H[num[i]-1]=1;
    }
    if(M[i]=='C')
    {
      C[num[i]-1]=1;
    }
    if(M[i]=='D')
    {
      D[num[i]-1]=1;
    }
  }
  for(i=0;i<13;i++)
  {
    if(S[i]==0)
    {
      cout<<"S"<<" "<<i+1<<endl;
    }
  }
  for(i=0;i<13;i++)
  {
    if(H[i]==0)
    {
      cout<<"H"<<" "<<i+1<<endl;
    }
  }
  for(i=0;i<13;i++)
  {
    if(C[i]==0)
    {
      cout<<"C"<<" "<<i+1<<endl;
    }
  }
  for(i=0;i<13;i++)
  {
    if(D[i]==0)
    {
      cout<<"D"<<" "<<i+1<<endl;
    }
  }
  return 0;


}



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

void solve(){

    int n,k;
    cin>>n>>k;
    
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    
    vector<int> dp(k+1 , 1);
    dp[0] = 1;
    
    for(int i=1; i<=k; i++){
        for(int j =0; j<n; j++){
            if(i-a[j] >= 0){
                int p = !(dp[i-a[j]]);
                dp[i] = min(dp[i] , p);
            }
            if(dp[i] == 0) break;
        }

    }
    
    if(dp[k] == 0){
        cout<<"First"<<endl;
    }
    else{
        cout<<"Second"<<endl;
    }
    
    return;
}

int main() {
	// your code goes here

        solve();

    return 0;
}


Measured memory_bytes: 3716
N = int(input())
L_i2 = 2
L_i1 = 1
if N == 0:
  L_i = L_i2
elif N == 1:
  L_i = L_i1
else:
  for n in range(N-1):
    L_i = L_i1 + L_i2
    L_i2 = L_i1
    L_i1 = L_i
print(L_i)

Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<ll> l(87);
    l[0]=2;
    l[1]=1;
    for(ll i=2;i<=86;i++){
        l[i]=l[i-1]+l[i-2];
    }
    cout << l[n] << endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define X first
#define Y second
typedef long long ll;
using namespace std;

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

int n, a, b;

int main () {

	cin >> n >> a >> b;
	
	
	cout << min(a, b) << " ";
	cout << max(0, a+b-n);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    int r; cin>>r;
    cout << 3*r*r << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    H = list(map(int,input().split()))
    for i in range(N-1):
        if H[-i-2] <= H[-i-1]:
            continue
        else:
            H[-i-2] -= 1
            if H[-i-2]<=H[-i-1]:
                continue
            print('No')
            exit()
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    string s;
    int K;
    cin >> s >> K;

    set<string> st;
    REP(start, s.size()) {
        REP(i, min(K, (int)s.size() - start)) {
            string x = s.substr(start, i + 1);
            st.insert(x);
        }
    }
    int cnt = 0;
    for (auto &&i : st) {
        cnt++;
        if (cnt == K) {
            print(i);
            return 0;
        }
    }

    return 0;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  string s,p;
  getline(cin,s);
  getline(cin,p);
  
  s += s;
  
  if(s.find(p)!=string::npos){
      cout << "Yes" << endl;
  }
  else{
      cout << "No" << endl;
  }
 
  return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <cmath>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

int abss(int a,int b){
    if(a>b)
        return a-b;
    return b-a;
}

int main(){
    
    int n,k;
    
    cin >> n >> k;
    
    int p[n],h[n];
    
    rep(i,0,n)
        cin >> h[i];
    
    p[0] = 0;
    rep(i,1,n){
        int j = 2;
        p[i] = p[i-1]+abs(h[i]-h[i-1]);
        while(j<=k && i-j>=0){
            p[i] = min(p[i], p[i-j] + abss(h[i-j],h[i]));
            j++;
        }
    }

    cout << p[n-1] << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=998244353;

int cnt[3];
// dp[index][連続文字の有無][mod][前の文字]
ll dp[202020][2][3][3];

int main(){
  string S; cin>>S;
  int n=S.length(), flag=1;
  int sum=0;
  rep(i,n){
    if(i<n-1) if(S[i+1]==S[i]) flag=0;
    cnt[S[i]-'a']++;
    sum+=(S[i]-'a');
  }
  sum%=3;
  rep(i,3) if(cnt[i]==n){
    cout<<1<<endl;
    return 0;
  }
  if(n==2){
    cout<<2<<endl;
    return 0;
  }
  if(n==3){
    if(S[0]!=S[1]&&S[0]!=S[2]&&S[1]!=S[2]){
      cout<<3<<endl;
    }else if(S[0]==S[2]){
      cout<<7<<endl;
    }else{
      cout<<6<<endl;
    }
    return 0;
  }

  dp[1][0][0][0]=1;
  dp[1][0][1][1]=1;
  dp[1][0][2][2]=1;
  for(int i=1;i<n;i++){
    // j:連続文字, k:mod, l:前の文字
    rep(j,2) rep(k,3) rep(l,3) rep(m,3){
      (dp[i+1][j|l==m][(k+m)%3][m]+=dp[i][j][k][l])%=MOD;
    }
  }
  ll ans=flag;
  rep(i,3) (ans+=dp[n][1][sum][i])%=MOD;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 28676
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void _dump(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void _dump(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  _dump(s, forward<Tail>(tail)...);
}
// }}} End

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

  VAR(int, N);

  vector<i64> x(N);
  vector<i64> sorted(N);
  rep(i, N) {
    IN(x[i]);
    sorted[i] = x[i];
  }

  sort(all(sorted));

  int mid = (N - 1) / 2;
  rep(i, N) {
    if (x[i] <= sorted[mid]) OUTL(sorted[mid+1]);
    else OUTL(sorted[mid]);
  }

  return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <iomanip>
#include <vector>
#define ALL(a)  (a).begin(),(a).end()
#define MOD 1000000007
//REPEAT
//------------------------------------------
#define FOR(i,m,n) for(int (i)=(m);(i)<(n); i++)
#define REP(i, n) for(int (i)=0;(i)<(n);(i)++)
#define REPS(i,x) for(int (i)=1;i<=(int)(x);(i)++)
#define RREP(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define RREPS(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
//-------------------------------------------
using namespace std;

int main(void){
	int A1,A2,A3;
	cin>>A1>>A2>>A3;
	cout<<(A1+A2+A3>=22?"bust":"win")<<"\n";
	return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/arc071/tasks/arc071_a



n = gets.to_i
Ss = Array.new(n) do
  s = gets.chomp.chars
  s.each_with_object(Hash.new(0)) {|s, hash| hash[s] += 1}
end

ans = ''
('a'..'z').each do |char|
  min = 50
  Ss.each do |s|
    if s[char] && s[char] < min
      min = s[char]
    end
  end
  ans << char * min
end
puts ans


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  ll a, b, c, d, e, am, bm, cn, dn, en, x;
  cin >> a >> b >> c >> d;
  e = lcm(c, d);
  // printf("%lld %lld %lld\n", c, d, e);
  am = a % c;
  bm = b % c;
  x = am > 0 ? c - am : 0;
  if(b - bm >= a + x) {
    cn = (b - bm - a - x) / c + 1;
  }
  else {
    cn = 0;
  }
  am = a % d;
  bm = b % d;
  x = am > 0 ? d - am : 0;
  if(b - bm >= a + x) {
    dn = (b - bm - a - x) / d + 1;
  }
  else {
    dn = 0;
  }
  am = a % e;
  bm = b % e;
  x = am > 0 ? e - am : 0;
  if(b - bm >= a + x) {
    en = (b - bm - a - x) / e + 1;
  }
  else {
    en = 0;
  }
  // printf("%lld %lld %lld\n", cn, dn, en);
  ans = b - a + 1 - (cn + dn - en);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class Edge
{
	public:
	int cost;
	int from;
	int to;

	Edge(int n,int c)
	{
		to=n;
		cost=c;
	}

	Edge(int f,int t,int c)
	{
		from=f;
		to=t;
		cost=c;
	}
};

vector<Edge> g[10000];
ll c[10000];
ll ans[10000];//最大の並べ方

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(Edge(b,1));
		g[b].push_back(Edge(a,1));
	}
	for(int i=0;i<n;i++)
		cin>>c[i];
	sort(c,c+n);
	fill(ans,ans+10000,-1);
	ll s=0;
	for(int i=0;i<n-1;i++)
		s+=c[i];
	cout<<s<<endl;
	reverse(c,c+n);
	ans[0]=c[0];
	int now=1;
	deque<P> que;
	que.push_front(P(0,0));
	while(!que.empty())
	{
		P p=que[que.size()-1];
		que.pop_back();
		int n=p.second;
		for(int i=0;i<g[n].size();i++)
		{
			//cerr<<now<<endl;
			Edge e=g[n][i];
			if(ans[e.to]==-1)
			{
				ans[e.to]=c[now];
				que.push_front(P(now+1,e.to));
				now++;
			}
		}
	}
	for(int i=0;i<n;i++)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int n,a[105],b[105];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	    cin>>a[i];
	for(int i=0;i<n;i++)
	    cin>>b[i];
	int ans=-1;
	for(int i=0;i<n;i++)
	{
		int sum=0;
		for(int j=0;j<n;j++)
	        if(j<i)
	            sum+=a[j];
	        else
	        if(j==i)
	            sum+=a[j]+b[j];
	        else
	            sum+=b[j];
	    ans=max(sum,ans);
	}  
	cout<<ans;  
	return 0;
}

Measured memory_bytes: 256
stations = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
while true
    n = gets.to_i
    break if n == 0

    arr = gets.chomp.split.map(&:to_i)
    str = gets.chomp.split("")

    i = 0
    str.each{|c|
        print(stations[stations.index(c) - arr[i]])
        i = (i + 1) % arr.length
    }
    puts
end


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

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

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define F first
#define S second
signed main(){
  ll N,K,R,S,P,i,ans=0;string T,X;
  cin>>N>>K>>R>>S>>P>>T;
  REP(i,N){
    if(i<K||T[i]!=T[i-K]){
      if(T[i]=='r')ans+=P;
      if(T[i]=='s')ans+=R;
      if(T[i]=='p')ans+=S;
    }
    else T[i]='o';
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(void)
{
    int n;
    cin >> n;
    vector<int> v1(n/2, 0), v2(n/2, 0);

    for (int i = 0; i < n; i++)
    {
        if(i%2 == 0){
            cin >> v1[i/2];
        } else {
            cin >> v2[(i-1)/2];
        }
    }

    map<int, int> count1, count2;

    for (int i = 0; i < n/2; i++)
    {
        count1[v1[i]]++;
    }
    for (int i = 0; i < n/2; i++)
    {
        count2[v2[i]]++;
    }

    
    int freq1_first = 0;
    int freq1_2nd = 0;
    int freq2_first = 0;
    int freq2_2nd = 0;

    int freq1_num, freq2_num;

    for (auto elem: count1)
    {
        if(freq1_first < elem.second) {
            freq1_2nd = freq1_first;
            freq1_first = elem.second;
            freq1_num = elem.first;
        } else if(freq1_2nd < elem.second){
            freq1_2nd = elem.second;
        }
    }

    for (auto elem: count2)
    {
        if(freq2_first < elem.second) {
            freq2_2nd = freq2_first;
            freq2_first = elem.second;
            freq2_num = elem.first;
        } else if(freq2_2nd < elem.second){
            freq2_2nd = elem.second;
        }
    }

    int ans;
    
    if(freq1_num != freq2_num){
        ans = (n/2 - freq1_first) + (n/2 - freq2_first);
    } else {
        int ans1 = (n/2 - freq1_first) + (n/2 - freq2_2nd);
        int ans2 = (n/2 - freq2_first) + (n/2 - freq1_2nd);

        ans = min(ans1, ans2);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8272
/**
*    created: 13.06.2020 21:08:42
**/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(ki, k) {
        vector<int> b(n+1);
        rep(i,n) {
            int l = max(0, i-a[i]);
            int r = min(i+a[i]+1, n);
            b[l]++;
            b[r]--;
        }
        rep(i,n) b[i+1] += b[i];
        b.pop_back();
        if (a == b) break;
        a = b;
    }
    rep(i,n) cout << a[i] << endl;
    return 0;
}

Measured memory_bytes: 4780
// C - Unification
#include <bits/stdc++.h>
using namespace std;

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

	int count = 0;
	stack<char> t;//for check
	for(int i=0; i<s.size(); ++i){

		t.push(s[i]);//push check-data

		if(t.size()>=2){//start check
			char first = t.top(); t.pop();//first pop
			if(first!=t.top()){//first!=second: 01 or 10 -> second pop & +2
				t.pop();
				count += 2;
			}
			else t.push(first);//first==second: 00 or 11 -> first repush
		}

	}
	cout<< count <<endl;
}

Measured memory_bytes: 512
use std::collections::BTreeMap;

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn reads<T>() -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    read_line()
        .split_whitespace()
        .map(|w| w.parse().unwrap())
        .collect()
}

fn main() {
    let n: i32 = reads()[0];
    let s: Vec<String> = (0..n).map(|_| read_line()).collect();

    let mut m = BTreeMap::<char, i64>::new();
    for w in s {
        *m.entry(w.chars().nth(0).unwrap()).or_insert(0) += 1;
    }

    let v: Vec<i64> = "MARCH".chars().map(|c| *m.entry(c).or_insert(0)).collect();
    let mut ans = 0;
    for b in 0..(1 << 5) {
        if (b as u32).count_ones() == 3 {
            let mut t = 1;
            for i in 0..5 {
                if b & (1 << i) != 0 {
                    t *= v[i];
                }
            }
            ans += t;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 8444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		String input_line = input.readLine();

		String[] coordinate_group = input_line.split(" ");

		double coordinate_x = Double .parseDouble(coordinate_group[0]);

		double coordinate_y = Double .parseDouble(coordinate_group[1]);

		double coordinate_xi = Double .parseDouble(coordinate_group[2]);

		double coordinate_yi = Double .parseDouble(coordinate_group[3]);

		double x_distance = Math.pow(coordinate_x - coordinate_xi, 2);

		double y_distance = Math.pow(coordinate_y - coordinate_yi, 2);

		double distance = Math.sqrt(x_distance + y_distance);

		System.out.println(distance);

	}

}

Measured memory_bytes: 24464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
using mat = vector<vector<int>>;
const int MOD = 1e9 + 7;

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

    int H, N;
    cin >> H >> N;

    int sum = 0;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        sum += a;
    }

    cout << (H <= sum ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> h(n);
	rep(i,n) std::cin >> h[i];
	int count = 0;
	int curr = 0;
	rep(i,n) {
		count+=std::max(0ll,h[i]-curr);
		curr=h[i];
	}
	print(count);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
#include <cmath>
#include <iostream>

using namespace std;
typedef long long LL;

map<pair<string, string>, LL> cnt;
const int maxn = 50;
char s[maxn];

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

	for (int i = 0; i < (1 << n); ++i) {
		string s1 = "", s2 = "";
		for (int j = 0; j < n; ++j) {
			if (i & (1 << j)) s1 += s[j];
			else s2 += s[j];
		}
		cnt[make_pair(s1, s2)]++;
	}

	LL sum = 0;

	for (int i = 0; i < (1 << n); ++i) {
		string s1 = "", s2 = "";

		for (int j = n - 1; j >= 0; --j) {
			if (i & (1 << j)) s2 += s[j + n];
			else s1 += s[j + n];
		}

		sum += cnt[make_pair(s1, s2)];
	}

	printf("%lld\n", sum);

	return 0;
}

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

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

    int n,m;cin>>n>>m;

    int ans=(1900*m+100*(n-m))*pow(2,m);

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 4084
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;





int main() {
    
    int a,b;
    cin>>a>>b;
    int tap=a;
    
    fin(ceil((b-a)/(double)(a-1))+1);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
bool isprime(long long int val) {
    if (val <= 1)return false;
    for (long long int i = 2; i*i <= val; i++) {
        if (val%i == 0LL)return false;
    }
    return true;
}
 
signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    ll s;
    cin>>s;
    ll x=0,y=0;

    ll low=sqrt(s);
    if(low*low<s){
        low++;
    }


    ll t=low*low-s;
    
    cout<<0<<" "<<0<<" "<<low<<" "<<min(t,1LL)<<" "<<t<<" "<<low<<endl;
 
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;
    bool can = false;
    ll a = 0;
    while(true){
        if(a*4>n){
            break;
        }
        if((n-4*a)%7==0){
            can = true;
            break;
        }
        a++;
    }
    Yes(can);
    return  0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, ll> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int max_e = *max_element(a.begin(), a.end());
    int min_e = *min_element(a.begin(), a.end());
    int dif = max_e - min_e;
    if(dif > 1){
        cout << "No\n";
        return 0;
    }
    if(dif == 0){
        if(a[0] == n - 1 || 2 * a[0] <= n){
            cout << "Yes\n";
        }
        else{
            cout << "No\n";
        }
    }
    else{   // dif == 1
        int p = 0, q = 0;
        for(int i = 0; i < n; ++i){
            if(a[i] == min_e)   ++p;
            else                ++q;
        }
        if(p < max_e && 2 * (max_e - p) <= q){
            cout << "Yes\n";
        }
        else{
            cout << "No\n";
        }
    }
}

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

#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll N = 2e5;
ll arr [N+1];
int main()
{
    fast_io;
    ll n;
    cin >> n;
    for(ll i = 0 ; i <n ; i++)
    {
        cin >> arr[i];
    }
    ll diff=0,sum=0;
    for(ll i = 1 ; i < n ; i++)
    {
        if(arr[i] < arr[i-1])
        {
            diff = arr[i-1]-arr[i];
            sum += diff;
            arr[i] = arr[i]+ diff;
        }
    }
    cout << sum ;
}


Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
using vi=vector<long long>;
using vvi=vector<vector<long long>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000009;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}

int main(){
  int n;cin>>n;
  vi v(n);
  int c=0;
  rep(i,n){
    cin>>v[i];
    if(v[i]<0){
      c++;
      v[i]*=-1;
    }
  }
  if(c%2==0){
    ll sum=0;
    rep(i,n)sum+=v[i];
    cout<<sum<<endl;
  }
  else{
    ll sum=0;
    sort(v.begin(),v.end());
    rep(i,n)sum+=v[i];
    cout<<sum-v[0]*2<<endl;
  }
}


Measured memory_bytes: 1024
from fractions import gcd


def solve():
    N, *A = map(int, open(0).read().split())
    MOD = 10 ** 9 + 7

    lcm = 1
    for a in A:
        lcm = a * lcm // gcd(a, lcm)

    ans = [lcm // a for a in A]
    print(sum(ans) % MOD)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 264672
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

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

typedef long long int lli;
using namespace std;
// #define int long long int

inline void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}

signed main() {
    int N;
    cin >> N;
    int P = 0, Q = 0, R = 0, S = 0;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        for (int j = 1; s[j] != '\0'; j++) {
            if (s[j - 1] == 'A' && s[j] == 'B') P++;
        }
        if (s.front() == 'B' && s.back() != 'A') {
            Q++;
        }
        if (s.front() != 'B' && s.back() == 'A') {
            R++;
        }
        if (s.front() == 'B' && s.back() == 'A') {
            S++;
        }
    }

    int ans = P;
    if (S > 0) { //'B~A'が一つ以上存在
        ans += S - 1;
        // '~A'が一つ以上存在
        if (Q > 0) {
            ans += 1;
            Q -= 1;
        }
        // '~B'が一つ以上存在
        if (R > 0) {
            ans += 1;
            R -= 1;
        }
        // 残りは適当にくっつけておわり
    }
    ans += min(Q, R);

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


Measured memory_bytes: 256
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N+1-x):
        z = N-x-y
        if 10000*x + 5000*y + 1000*z == Y:
            print(x, y, z)
            exit()
print('-1 -1 -1')


Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define MOD 1000000007ULL;
#define rep(i,n) for(ll i=0;i<n;i++)



int main() {
	ll N,M,K;
  	cin>>N>>M>>K;
  
  	vl sa(N+1,0);
  	vl sb(M+1,0);
  	ll A[N];
  	ll B[M];
  	ll count=0;
  
  	rep(i,N) {
      cin>>A[i];
      sa.at(i+1)=sa.at(i)+A[i];
    }
  	rep(i,M) {
      cin>>B[i];
      sb.at(i+1)=sb.at(i)+B[i];
    }
  	
  	rep(i,N+1){
      	if(sa[i]<=K){
           count=max(count,upper_bound(sb.begin(),sb.end(),K-sa[i])-sb.begin()+i-1);
        }
    }
     
  
  	cout<<count<<endl;
  	
}

Measured memory_bytes: 9596
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <map>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 20000;


int main() {
  int x, y;
  std::cin >> x >> y;
  if(0 <= x && x <= y)
    std::cout << y - x;
  else if(x <= y && y <= 0) 
    std::cout << y - x;
  else {
    int coef = fabs(fabs(x) - fabs(y));
    if(0 < x && 0 < y)
      std::cout << coef + 2;
    else if(x < 0 && y < 0)
      std::cout << coef + 2;
    else
      std::cout << 1 + coef;
  }

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

ll gcd(ll x, ll y) {
	while (y) {
		x %= y;
		swap(x, y);
	}
	return x;
}

ll lcm(ll x, ll y) {
	return x / gcd(x, y) * y;
}

int main() {
	ll N, M, a;
	cin >> N >> M;
	vector<ll> A(N);

	ll d2 = -1, d = 0;
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		a = A[i];
		d = 0;
		while (a % 2 == 0) {
			a /= 2;
			d++;
		}
		if (d2 < 0)d2 = d;
		else if (d2 != d) {
			cout << 0 << endl;
			return 0;
		}
	}
	ll X = 1;
	for (int i = 0;i < N;i++) {
		X = lcm(X, A[i]);
		if (X / 2 > M) {
			cout << 0 << endl;
			return 0;
		}
	}
	ll a1 = M / (X / 2), a2 = M / X;
	cout << a1 - a2 << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

bool comp(const pair<long, long>& a, const pair<long, long>& b) {
	return a.first < b.first;
}

int main() {
	int N;
	long M;
	cin >> N >> M;
	vector<pair<long, long>> AB(N);
	for (pair<long, long>& i : AB) cin >> i.first >> i.second;
	sort(AB.begin(), AB.end(), comp);
	long sum = 0, ans = 0;
	for (int i = 0; sum < M; ++i) {
		if (M - sum < AB[i].second) {
			ans += (M - sum) * AB[i].first;
			sum = M;
		}
		else {
			sum += AB[i].second;
			ans += AB[i].first * AB[i].second;
		}
	}
	cout << ans;
}

Measured memory_bytes: 1792