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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;
map<int,int> m;
string s;
int n;
int culc(int num){
    if(num == 0)return 0;
    if(num == 1)return 1;
    if(m.count(num)== 1)return m[num];
    int c = __builtin_popcount(num);
    return m[num] = culc(num%c)+1;
}
int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    cin>>n;
    int count = 0;
    cin>>s;
    vector<vector<int>> cu(2,vector<int>(n+2));
    for(int i=0;i<n;++i){
        if(s[i] == '1')count++;
    }
    cu[0][0] = 1;
    cu[1][0] = 1;
    for(int i=0;i<n;++i){
        cu[0][i+1] = cu[0][i]*2%(count+1);
        if(count > 1)cu[1][i+1] = cu[1][i]*2%(count-1);
    }
    vector<int> sum(2);
    for(int i=0;i<n;++i){
        if(s[i] == '1'){
            (sum[0]+= cu[0][n-i-1])%=(count+1);
            if(count > 1)(sum[1]+= cu[1][n-i-1])%=(count-1);
        }
    }
    vector<int> ret(n);
    for(int i=0;i<n;++i){
        int tmp = 0;
        if(s[i] == '0')tmp = (sum[0] +cu[0][n-i-1])%(count+1);
        else {
            if(count == 1)continue;
            tmp = ((sum[1] - cu[1][n-i-1])%(count-1)+count-1)%(count-1);
        }
        ret[i] = culc(tmp)+1;
    }
    for(int i=0;i<n;++i)cout << ret[i] << endl;
    return 0;
    
}

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
		}
		inv[n-1]=ppow(fact[n-1],MOD-2);
		for(int i=n-2;i>=0;i--){
			inv[i]=(inv[i+1]*(i+1))%MOD;
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll get_inv(int n){
		return inv[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};
vector<int>E[300000];
int sz[300000];
ll dp1[300000],dp2[300000];

int n;

Fact fac(200000);

void dfs(int v,int p){
	sz[v]=1;
	dp1[v]=1;
	for(int u:E[v]){
		if(u==p)continue;
		dfs(u,v);
		sz[v]+=sz[u];
	}
	if(sz[v]==1)return;
	dp1[v]=fac.get(sz[v]-1);
	for(int u:E[v]){
		if(u==p)continue;
		(dp1[v]*=fac.get_inv(sz[u])*dp1[u]%MOD)%=MOD;
	}
}

void dfs2(int v,int p){
	if(p==-1){
		dp2[v]=dp1[v];
	}
	else{
		dp2[v]=fac.get(n-1);
		for(int u:E[v]){
			if(u==p){
				ll d=dp2[p]*fac.get(n-sz[v]-1)%MOD*fac.get_inv(n-1)%MOD*fac.get(sz[v])%MOD*ppow(dp1[v],MOD-2)%MOD;
				ll S=(n-sz[v]);
				(dp2[v]*=fac.get_inv(S)*d%MOD)%=MOD;
			}
			else{
				(dp2[v]*=fac.get_inv(sz[u])*dp1[u]%MOD)%=MOD;
			}
		}
	}
	for(int u:E[v]){
		if(u==p)continue;
		dfs2(u,v);
	}
}

int main(){
	cin>>n;
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	dfs(0,-1);
	dfs2(0,-1);
	rep(i,n){
		printf("%lld\n",dp2[i]);
	}
}


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

int solve(const int n, const vector<int> digs) {
  int base = (n < 10) ? 1 : (n < 100) ? 10 : (n < 1000) ? 100 : 1000;
  int over = digs[0] ? digs[0] : digs[1];
  int even = 0;  // even or less
  for (; base; base /= 10) {
    int d = n / base % 10;
    over = 10 * over + digs[0];
    if (even >= 0)
      even = 10 * even + *lower_bound(digs.begin(), digs.end(), d);
    if (even > n / base) {
      over = even;
      even = -1;
    }
  }
  if (even == n)
    over = even;
  return over;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> D(k);
  for (int& d : D)
    cin >> d;
  vector<int> digs;
  for (int i = 0; i < 10; ++i) {
    if (i != D[0]) {
      digs.push_back(i);
    } else {
      D.erase(D.begin());
    }
  }
  cout << solve(n, digs) << "\n";

  return 0;
}


Measured memory_bytes: 504
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;


inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

const int mod = 1e9+7;
const int maxn=2e5+10;
ll num[maxn];

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int n;
	while(cin>>n)
	{
		for(int i=0;i<n;i++)
			cin>>num[i];
		
		ll sum=0,pre=0;
		
		for(int i=0;i<n;i++)
		{
			sum+=(pre%mod*num[i]%mod);
			sum%=mod;
			pre+=num[i];
		}
		
		cout<<sum<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 5172
#include<stdio.h>

struct tranp{
  char gara;
  int atai;
};

void bbsort(struct tranp C[], int);
void selsort(struct tranp C[], int);
void pr(struct tranp C[], int);


int main(){
  int i=0,j=0;
  struct tranp C[100];
  struct tranp CC[100];
  int N=0;
  int count=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf(" %c%d",&C[i].gara,&C[i].atai);
  }
  for(i=0;i<N;i++){
    CC[i]=C[i];
  }
  bbsort(C,N);
  selsort(CC,N);
  pr(C,N);
  printf("Stable\n");
  pr(CC,N);
  for(i=0;i<N;i++){
    if(C[i].gara!=CC[i].gara){
      printf("Not stable\n");
      break;
    }
  }
  if(i==N)printf("Stable\n");
  return 0;
}
void bbsort(struct tranp A[],int N){
  int i=0,j=0;
  struct tranp temp;
  for(i=0;i<N-1;i++){
    for(j=N-1;j>i;j--){
      if(A[j].atai<A[j-1].atai){
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;
      }
    }
  }
}
void selsort(struct tranp A[], int N){
  int i=0,j=0;
  struct tranp temp;
  int min=0;
  for(i=0;i<=N-1;i++){
    min=i;
    for(j=i;j<=N-1;j++){
      if(A[j].atai<A[min].atai){
	min=j;
      }
    }
    temp=A[i];
    A[i]=A[min];
    A[min]=temp;
  }
}
void pr(struct tranp A[],int N){
  int i=0;
  if(N>1){
    for(i=0;i<N;i++){
      if(i<N-1){
	printf("%c%d ",A[i].gara,A[i].atai);
      }
      if(i==N-1){
	printf("%c%d",A[i].gara,A[i].atai);
      }
    }
    printf("\n");
  }
  else {
    for(i=0;i<N;i++){
      printf("%c%d",A[i].gara,A[i].atai);
    }
    printf("\n");
  }
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

template<typename T> // order_of_key(), *find_by_order()
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 998244353;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll) ((ld) a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }

    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }

    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}
ll const maxn = 1e7 + 7;
ll fact[maxn];
ll pw[maxn];

ll C(ll n, ll k) {
    return mul(fact[n], inv(mul(fact[n - k], fact[k])));
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    fact[0] = 1;
    pw[0] = 1;
    for (int i = 1; i < maxn; i++) {
        fact[i] = fact[i - 1] * i;
        pw[i] = pw[i - 1] * 2;
        pw[i] %= mod;
        fact[i] %= mod;
    }
    ll n;
    cin >> n;
    ll ans = poww(3, n);
    ll kek = 0;
    for (ll i = n / 2 + 1; i <= n; i++) {
        (kek += mul(C(n, i), pw[n - i])) %= mod;
    }
    kek = mul(kek, 2);
    cout << ((ans - kek) % mod + mod) % mod << endl;
    return 0;
}
/*

*/

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

group1 = []
group2 = []
group3 = []

for p in P:
    if p <= A:
        group1.append(p)
    elif A < p and p <= B:
        group2.append(p)
    elif B < p:
        group3.append(p)

ans = min(len(group1), len(group2))
ans = min(ans, len(group3))
print(ans)


Measured memory_bytes: 3064
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
    ll n;
    std::cin >> n;
    vector<ll> b(n-1);
    ll res = 0;
    for (int i = 0; i < n-1; i++) {
        std::cin >> b[i];
        if(i==0){
            res += b[0];
        }else if(i<n-1){
            res += min(b[i-1],b[i]);
        }
    }
    res += b[n-2];
    std::cout << res << std::endl;
    
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    string s, t;
    cin >> s >> t;
    dump(s);
    dump(t);

    // 状態 (i,j) : s[0]~s[i-1], t[0]~[i-1]から選んだ状態
    // ma(i,j) : 状態(i,j) でのLCSの最大値
    vector<vector<int>> ma(s.size() + 1, vector<int>(t.size() + 1, -1));

    for (int i = 0; i < s.size() + 1; i++) {
        ma[i][0] = 0;
    }
    for (int i = 0; i < t.size() + 1; i++) {
        ma[0][i] = 0;
    }

    for (int i = 1; i < s.size() + 1; i++) {
        for (int j = 1; j < t.size() + 1; j++) {
            if (s[i - 1] == t[j - 1]) {
                ma[i][j] = max(ma[i][j], ma[i - 1][j - 1] + 1);
            } else {
                ma[i][j] = max(ma[i - 1][j], ma[i][j - 1]);
            }
        }
    }
    // cout << ma[s.size()][t.size()] << endl;

    // ddump(ma);

    int i = s.size(), j = t.size();
    string ans = "";
    while (0 < i and 0 < j) {
        if (ma[i - 1][j] == ma[i][j]) {
            i--;
        } else if (ma[i][j - 1] == ma[i][j]) {
            j--;
        } else {
            ans.push_back(s[i - 1]);
            i--, j--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 38608
def main():
    H, N = map(int, input().split())
    AB = [[]*2]*N
    for i in range(N):
        AB[i] = list(map(int, input().split()))

    dp = [[100000000]*(10000*2)]*(N+1)
    dp[0][0] = 0

    for i in range(0, N):
        for h in range(0, H+1):
            dp[i+1][h] = min(dp[i+1][h], dp[i][h])
            dp[i+1][min(h+AB[i][0], H)] = min(dp[i+1][min(h+AB[i][0], H)], dp[i+1][h]+AB[i][1])

    ans = {}
    for i in range(N):
        ans[i] = dp[i][H]
    print(min(ans.values()))

if __name__ == "__main__":
    main()

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

using namespace std;
int a[100005],dp[100005],i,j,k,n;
const int inf=1e9+5;
int main()
{
    //ios_base::sync_with_stdio(0);
    cin.tie();
    cin>>n>>k;
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
        dp[i]=inf;
    }
    dp[1]=0;
    for(i=1; i<=n; i++)
        for(j=i+1; j<=i+k; j++)
          dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
        cout<<dp[n];
            return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(ll,N);
  N %= 10;
  if(N == 3){
    OUT("bon");
  }else if(N == 0 || N == 1 || N == 6 || N == 8){
    OUT("pon");
  }else{
    OUT("hon");
  }
}

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

int a[101];

int main()
{
	int x,n;
	cin>>x>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
		
	sort(a+1,a+n+1);
	
	if(!binary_search(a+1,a+n+1,x))
	{
		cout<<x<<endl;
		return 0;
	}
	
	for(int i=1;i<=101;i++)
	{
		if(!binary_search(a+1,a+n+1,x-i))
		{
			cout<<x-i<<endl;
			return 0;
		}
		if(!binary_search(a+1,a+n+1,x+i))
		{
			cout<<x+i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <climits>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define in1(n) cin>>n;
#define in2(n, k) cin>>n>>k;
#define in3(n, k, s) cin>>n>>k>>s;
#define scn(t) scanf("%d", &t)
#define scnld(t) scanf("%ld", &t)
#define scnlld(t) scanf("%lld", &t)
#define scnc(t) scanf("%c", &t)
#define scns(t) scanf("%s", t)
#define scnf(t) scanf("%f", &t)
#define scnlf(t) scanf("%lf", &t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define nloop(i, j, k, in) for (int i = j; i < k; i += in)
#define rloop(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rep(i, j) nloop(i, 0, j, 1)
#define rrep(i, j) rloop(i, j, 0, 1)
#define inar(n, a) \
    rep(i, n)\
        cin>>a[i];
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define fast  \
    ios_base::sync_with_stdio(false);\
    cin.tie(NULL);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

int main()
{
    fast
    int n, m;
    cin>>n>>m;
    cout<<m*n;
    return 0;
}

Measured memory_bytes: 3640
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mp make_pair
#define pi pair<int,int>
#define pl pair<long long int,long long int>
#define pb push_back
#define fi first
#define se second
#define len(a) (int)(a).length()
#define sz(a) (int)(a).size()

using namespace std;

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n, a[100000], b[100000], c[100000], dp[100000][3];
	cin >> n;
	for (int i=0; i<n; ++i)
		cin >> a[i] >> b[i] >> c[i];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (int i=1; i<n; ++i) {
		dp[i][0] = max(dp[i-1][1]+a[i], dp[i-1][2]+a[i]);
		dp[i][1] = max(dp[i-1][0]+b[i], dp[i-1][2]+b[i]);
		dp[i][2] = max(dp[i-1][1]+c[i], dp[i-1][0]+c[i]);
	}
	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>

int main(void){
	int a[5], b[5];
	int sum=0, min=100, last=0, mark=100;

	for(int i=0;i<5;i++){
		scanf("%d",&a[i]);
		b[i] = a[i] % 10;
	}
	for(int i=0;i<5;i++){
		if(min > b[i] && b[i]>0){
			min = b[i];
			mark = i;
			last = a[i];
		}
	}
	for(int i=0;i<5;i++){
		if(i != mark){
			if(a[i]%10 == 0){
				sum += a[i];
			}else{
				sum += a[i] + (10 - b[i]);
			}
		}
	}

	sum += last;

	if(sum>643){
		sum = 643;
	}

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

}


Measured memory_bytes: 128
from collections import Counter
S=input()
K=int(input())
S_double = S*2
n = 0
if len(set(list(S)))==1:
    print(len(S)*K//2)
    exit()
while n< len(S_double)-1:
    if S_double[n] ==S_double[n+1]:
        S_double = S_double[:n+1]+' '+S_double[n+2:]
    n += 1
ans = Counter(S_double[:len(S)])[' '] + Counter(S_double[len(S):])[' ']*(K-1)
print(ans)


Measured memory_bytes: 3316
/*************************************************************************
	> File Name: A.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Created Time: 2020/4/19 19:57:23
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
using namespace std;
const double pi=acos(-1.0);
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	int r;
	scanf("%d",&r);
	printf("%.18lf\n",r*pi*2);
	return 0;
}


Measured memory_bytes: 3816
N,M = map(int,input().split())
dp = [-float("INF")]*(N+1)
dp[1] = 0
edges = [list(map(int,input().split())) for _ in range(M)]
cnt = 0
while cnt < N:
    cnt += 1
    for a,b,c in edges:
        dp[b] = max(dp[a]+c,dp[b])
tmp = dp[N]
cnt = 0
while cnt < N:
    cnt += 1
    for a,b,c in edges:
        dp[b] = max(dp[a]+c,dp[b])
if dp[N] > tmp:
    print("inf")
else:
    print(dp[N])

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  string s; cin >> s;
  int n = s.size();

  while(n > 3) {
    string tmp;
    for(int i=0;i<n;++i) {
      int sz = tmp.size();
      if(sz >= 2 && tmp[sz-2] == 'A' && tmp[sz-1] == 'B' && s[i] == 'C') {
        tmp.pop_back();
        tmp.pop_back();
      } else {
        tmp.push_back(s[i]);
      }
    }

    // cout << tmp << endl;

    bool a = true, b = true, c = true;
    int sz = tmp.size();
    for(int i=0;i<sz;++i) {
      if(tmp[i] == 'A') {
        a = false;
      } else if(tmp[i] == 'B') {
        b = false;
      } else {
        c = false;
      }
    }

    if(!((a && !b && !c) || (!a && b && !c) || (!a && !b && c))) {
      cout << "No" << endl;
      return 0;
    }

    tmp.clear();
    // cout << s << endl;

    int cnt = 0;
    for(int i=0;i<n;++i) {
      int sz = tmp.size();
      if(cnt <= 0 && sz >= 2 && tmp[sz-2] == 'A' && tmp[sz-1] == 'B' && s[i] == 'C') {
        tmp.pop_back();
        tmp.pop_back();
        if(a) {
          tmp.push_back('A');
        } else if(b) {
          tmp.push_back('B');
        } else {
          tmp.push_back('C');
        }
        cnt = 2;
      } else {
        tmp.push_back(s[i]);
        cnt--;
      }
      //cout << tmp << endl;
    }

    s = tmp;
    n = s.size();
    // cout << s << endl;;
  }

  if(s == "ABC") {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}



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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;
long long stint(string str) {
	long long ret;
	stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

void solve() {
	int n, a, b;
	cin >> n >> a >> b;
	int count = 0;
	REP(i, 1, n + 1) {
		string s = to_string(i);
		int sum = 0;
		rep(j, s.length()) {
			sum += (int)(s[j] - '0');
		}
		if (a <= sum and sum <= b) {
			count += stint(s);
		}
	}
	P(count);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#define INF 0x3f3f3f3f
#define lowbit(x) x & -x
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=5e3+5;
int p[N],c[N];
int vis[N];
ll sum[N],maxx;

ll check(int x,int k){
    memset(vis,0,sizeof vis);
    int cnt=0;
    while(!vis[x]){
        vis[x]=1;
        sum[++cnt]=c[p[x]];
        x=p[x];
    }
    ll maxxsum=sum[1],ans=0;
    for(int i=2;i<=cnt;i++){
        sum[i]+=sum[i-1];
        maxxsum=max(maxxsum,sum[i]);
    }
    if(k>cnt){
        if(sum[cnt]<=0){
            return maxxsum;
        }
        ll tmp=sum[cnt]*(k/cnt-1);
        int cntt=k%cnt+cnt;
        for(int i=1;i<=cntt;i++){
            if(i>cnt)
                ans=max(ans,sum[i-cnt]+sum[cnt]);
            else
                ans=max(ans,sum[i]);
        }
        return max(maxxsum,ans+tmp);
    }
    ans=-1e18;
    for(int i=1;i<=k;i++){
        ans=max(ans,sum[i]);
    }
    return ans;
    
}

int main(){
#ifdef Mizp
    freopen("in.txt","r",stdin);
#endif
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&p[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&c[i]);
    maxx=-1e18;
    for(int i=1;i<=n;i++){
        maxx=max(maxx,check(i,k));
    }
    printf("%lld\n",maxx);
    return 0;
}


Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);

double a,b,x;

int main()
{
    scanf("%lf%lf%lf",&a,&b,&x);
    double L=0,R=pi/2,cnt=0;
    while(cnt <= 2000){
        double mid = (L+R)/2,mxs;
        if(mid >= atan(b/a)) mxs = b/sin(mid)*a*b*cos(mid)/2;
        else{
            double aa = a/cos(mid),bb = b*cos(mid)-a*sin(mid),cc = a*sin(mid);
            mxs = aa*a*bb+aa*a*cc*0.5;
        }
        if(mxs>=x) L=mid+1e-9;
        else R=mid-1e-9;
        cnt++;
    }
    printf("%.10f",L/pi*180);

}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm> 
#include<cstring>
#define LL long long
using namespace std;
const int N=1e5+10;
int n,h,a[N],b[N],c[N];
LL ans,bb[N];
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)b[i]=read();
	for(int i=1;i<=n;i++)c[i]=read();
	sort(a+1,a+n+1);sort(b+1,b+n+1);sort(c+1,c+n+1);
	h=n;
	for(int i=n;i>=1;i--)
	{
		while(h>=1&&a[h]>=b[i])h--;
		bb[i]=h;
	}
	for(int i=1;i<=n;i++)bb[i]+=bb[i-1];
	h=n;
	for(int i=n;i>=1;i--)
	{
		while(h>=1&&b[h]>=c[i])h--;
		ans+=bb[h];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll a(3*N);
        rep(i, 0, 3*N) cin >> a[i];
        sort(rall(a));

        ll ans = 0;
        rep(i, 1, 2*N) {
                ans += a[i];
                ++i;
        }
        cout << ans << endl;
}

Measured memory_bytes: 5572
#include<iostream>
#include<algorithm>
using namespace std;
pair<int, int>x[1009]; int n, dp[1009][1009];
int main() {
	cin >> n; for (int i = 0; i < n; i++)cin >> x[i].second >> x[i].first;
	sort(x, x + n); for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++)dp[i][j] = 999999999; }dp[0][0] = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			if (dp[i][j] + x[i].second > x[i].first)continue;
			dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + x[i].second);
		}
	}
	int maxn = 0; for (int i = 0; i <= n; i++) { if (dp[n][i] != 999999999)maxn = i; }
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 3176
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

std::vector<int> topologicalSort(const Graph &G) {
    int n = (int)G.size();
    std::vector<int> cntIn(n);
    for (auto vec : G) {
        for (int x : vec) {
            cntIn.at(x)++;
        }
    }

    std::vector<int> res;
    std::stack<int> st;
    for (int i=0; i<n; i++) {
        if (cntIn.at(i) == 0) {
            st.push(i);
        }
    }
    while (!st.empty()) {
        int cur = st.top(); st.pop();
        res.push_back(cur);
        for (int x : G.at(cur)) {
            cntIn.at(x)--;
            if (cntIn.at(x) == 0) {
                st.push(x);
            }
        }
    }

    return res;
}

void solve() {
    int n, m;
    cin >> n >> m;
    Graph G(n);
    for (int i=0; i<n+m-1; i++) {
        int a, b;
        cin >> a >> b;
        G.at(a-1).push_back(b-1);
    }

    auto sorted = topologicalSort(G);
    vector<int> res(n, 0);
    for (int x : sorted) {
        for (int nx : G.at(x)) {
            res.at(nx) = x + 1;
        }
    }

    for (int x : res) {
        cout << x << '\n';
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 7152
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";


        int const N = 2e5+100;
        int parent[N],sz[N];
        void make_set(int v)
        {
            parent[v]=v;
            sz[v]=1;
        }
        int find_set(int v)
        {
            if(parent[v]==v)return v;
            else return parent[v]=find_set(parent[v]);
        }
        void set_unite(int x,int y)
        {
            int a=find_set(x);
            int b=find_set(y);
            if(a!=b)
            {
                if(sz[a]<sz[b])swap(a,b);
                parent[b]=a;
                sz[a]+=sz[b];
            }
        }

        int32_t main()
        {
            tani_nachi_ke  
            
            int n,m;
            cin >> n >> m;
            for(int i = 1; i <= n; i++)
                make_set(i);

            for(int i = 1; i <= m; i++)
            {
                int x,y;
                cin >> x >> y;
                if(find_set(x) != find_set(y))
                    set_unite(x,y);
            }

            vector<int> bin;
            for(int i = 1; i <= n; i++)
            {
                if(parent[i] == i)
                    bin.push_back(sz[i]);
            }
            sort(bin.begin(), bin.end());

            int ans = 0;
            int cur = 0;
            for(int i = 0; i < bin.size(); i++)
            {
                bin[i] -= cur;
                ans += bin[i];
                cur += bin[i];
            }
            cout << ans << '\n';





           return 0;
        }
          

Measured memory_bytes: 8396
//            ____             ____
//           /@@@@\           |@@@@|      ____
//          /@@@@@@\          |@@@@|     |@@@@|
//         /@@@@@@@@\         |@@@@|   __|@@@@|___    ____       ____      ___  _________     ____        ____    ____________      ___  _________     ____         ____
//        /@@@@/\@@@@\        |@@@@|   @@@@@@@@@@@   |@@@@|     |@@@@|    |@@@\/@@@@@@@@@\   (@@@@\      /@@@@)  /@@@@@@@@@@@@|    |@@@\/@@@@@@@@@\   (@@@@\       /@@@@)
//       /@@@@/  \@@@@\       |@@@@|     |@@@@|      |@@@@|     |@@@@|    |@@@@|    \@@@@@|   \@@@@\    /@@@@/  |@@/     |@@@@|    |@@@@|    \@@@@@|   \@@@@\     /@@@@/
//      /@@@@(____)@@@@\      |@@@@|     |@@@@|      |@@@@|     |@@@@|    |@@@@|     |@@@@|    \@@@@\  /@@@@/            |@@@@|    |@@@@|     |@@@@|    \@@@@\   /@@@@/
//     /@@@@@@@@@@@@@@@@\     |@@@@|     |@@@@|      |@@@@|     |@@@@|    |@@@@|     |@@@@|     \@@@@\/@@@@/    /@@@@@@@@@@@@@|    |@@@@|     |@@@@|     \@@@@\ /@@@@/
//    /@@@@@@@@@@@@@@@@@@\    |@@@@|     |@@@@|___   |@@@@|____/@@@@@|    |@@@@|     |@@@@|      \@@@@@@@@/    (@@@@(   )@@@@@|    |@@@@|     |@@@@|      \@@@@|@@@@/
//   /@@@@/          \@@@@\   |@@@@|     |@@@@@@@@    \@@@@@@@@@@@@@@|    |@@@@|     |@@@@|       \@@@@@@/      \@@@@\_/@@@@@@|    |@@@@|     |@@@@|       \@@@@@@@/
//  /@@@@/            \@@@@\  |@@@@|      \@@@@@@/      \@@@@@/  \@@@|    |@@@@|     |@@@@|        )@@@@/        \@@@@@@@/\@@@|    |@@@@|     |@@@@|        \@@@@@/
//                                                                                                (@@@@/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

//-----------------------------------------------
#define all(x)  x.begin(), x.end()
#define sz(x)   (int)x.size()
#define sq(x)   (x) * (x)
#define fr      first
#define sc      second
//-----------------------------------------------
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pli = pair<ll, int>;

const int N = 1000 * 1000 + 5;
const ll mod = 1000000007;
const ll INF = 1000000000 * 1ll * 1000000000 + 500000;
const ld pi = acosl(-1.0);

ll ans, n;

ll bpw(ll a, ll n) {
    return (n == 0 ? 1 : (n % 2 == 1 ? a * bpw(a, n - 1) % mod : bpw(a * a % mod, n >> 1)));
}

void input() {
    cin >> n;
}

void solve(int testId) {
    if (n == 1) {
        cout << 0 << endl;
    } else {
        cout << ((bpw(10, n) - 2 * bpw(9, n) + bpw(8, n)) % mod + mod) % mod << endl;
    }
}

int main() {
    // freopen("test", "r", stdin);
    int testcases = 1;
    // scanf("%d", &testcases);
    for(int testId = 1; testId <= testcases; testId++) {
        input();
        solve(testId);
    }
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    	ArrayList<Integer> number=new ArrayList<>();
		for(int i=0;i<4;i++){
      		number.add(sc.nextInt());
        }
      		
		Collections.sort(number);
      	if(number.get(0)!=1||number.get(3)!=9||number.get(2)!=7||number.get(1)!=4){
        	System.out.println("NO");
        }else{
        	System.out.println("YES");
        }
    }
}

Measured memory_bytes: 21972
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int main()
{
	ll a,b,c; cin>>a>>b>>c;
	if(a%2==0||b%2==0||c%2==0) puts("0");
	else cout<<min(a*b,min(b*c,a*c))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>

typedef long long LL;

using namespace std;
bool book[15];
int e[15][15];
int e1[15];
int dis[15];
int inf=0x3f3f3f3f;
int ss;
void Dijkstra(int n,int n1)
{
    int i,j,k,minn,u;
    for(i=n1; i<=n; i++)
    {
        minn=inf;
        for(j=n1; j<=n; j++)
            if(dis[j]<minn && book[j]==0)
                minn=dis[j],u=j;
        book[u]=1;
        for(k=n1; k<=n; k++)
        {
            if(e[u][k]<inf)
            {
                if(dis[k]>dis[u]+e[u][k])
                    dis[k]=dis[u]+e[u][k];
            }
        }
    }
}

int main()
{
    int n;
    while(scanf("%d",&n) && n!=0)
    {
        memset(e,0,sizeof(e));
        memset(e1,0,sizeof(e1));
        int i,j,maxx=0,min1=inf;
        for(i=0; i<=9; i++)
            for(j=0; j<=9; j++)
            {
                if(i==j)e[i][j]=0;
                else e[i][j]=inf;
            }
        for(i=0; i<n; i++)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            if(a>maxx)maxx=a;
            if(b>maxx)maxx=b;
            if(min1>a)min1=a;
            if(min1>b)min1=b;
            if(e[a][b]==inf)
                e[a][b]=e[b][a]=c;
        }
        int minn=inf,t;
        for(j=min1; j<=maxx; j++)
        {
            ss=0;
            for(i=min1; i<=maxx; i++)
            {
                dis[i]=e[j][i];
                book[i]=0;
            }
            book[j]=1;
            Dijkstra(maxx,min1);
            int sum=0;
            for(i=min1; i<=maxx; i++)
            {
                sum=sum+dis[i];
            }
            if(minn>sum)minn=sum,t=j;
        }

        printf("%d %d\n",t,minn);
    }
    return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll> 
#define pll pair<ll,ll>

ll M = (ll)(1e9+7);

void solve()
{
    ll n;
    cin>>n;
    int a[n][n];
    f(i,0,n)
    f(j,0,n)cin>>a[i][j];
    // cout<<"1\n";

    vector<int> dp(vector<int>(1<<n,0));
    // memset(dp, 0, sizeof dp);
    // dp[0][0]=1;
    dp[0]=1;
    // for(ll i=0;i<(1<<n);i++)
    // {
    //     // cout<<i<<" ";
    //     if(__builtin_popcount(i)==1 )
    //     {
    //         f(k,0,n)
    //         {
    //             // cout<<k<<" ";
    //             if(((i>>k) & 1 )==1 && a[0][k]==1)dp[1][i]++;
    //         }
    //     }
    //     // cout<<"\n";
    // }

    f(i,0,1<<n)
    {
        int j = __builtin_popcount(i);
        f(k,0,n)
        {
            if((i & (1<<k) )==0 && a[j][k]==1)
            {
                dp[i |(1<<k)] += dp[i];
                dp[i |(1<<k)]%=M;
            }
        }
    }
    cout<<dp[(1<<n)-1];
}

int main()
{
   ll t;
   t=1;
//    cin>>t;
   while (t--)
   {
       solve();
   }  
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
#define rep(i, r) for(int i = 0; i < (int)(r); i ++)

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
    int n, k; cin >> n >> k;
    vector <ll> A(n);
    rep(i, n){
        cin >> A.at(i);
    }

    sort(A.rbegin(), A.rend());
    if (A.at(0) < k){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    ll g = A.at(0);
    rep(i, n){
        g = gcd(g, A.at(i));
    }

    if (k % g == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;

}

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

int main()
{
    string s, t;
    cin >> s >> t;
  if (s.size()+1 == t.size())
    {
        if (s == t.substr(0, s.size()))
        {
            printf("Yes");
            return 0;
        }
    }
    
    printf("No");

    return 0;
}

Measured memory_bytes: 3720
#include <stdio.h>
#include <cassert>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <iomanip>
 
#ifdef LOCAL_CODE
	#define DEBUG(x) cerr << "[" << #x << '=' << x << "]" << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int i = (N)-1; i >= 0; i--)
#define REP(i, N) for(int i = 0; i < (int)(N); i++)
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.first >> p.second; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.first << ' ' << p.second; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

ll n,m,k;//A,B,C,D;
void solve(istream& cin, ostream& cout) {
	cin >> n;
	vector<ll> A(n+1);
	cin >> A;
	if(n == 0) {
		if(A[0] == 1) cout << 1 << endl;
		else cout << -1 << endl;
		return;
	}
	if(A[0] >= 1) {
		cout << -1 << endl;
		return;
	}
	ll prevNonLeafs = 1;
	ll ans = 1;
	ll sufSum = 0;
	REP(i, n) sufSum += A[i+1];
	REP(i, n) {
		DEBUG(prevNonLeafs);
		ll mini = prevNonLeafs, all = prevNonLeafs*2;
		ll C = A[i+1];
		if(i == n-1) {
			if(C < mini || C > all) ans = -1;
			else ans += C;
		} else {
			if(C >= all) {ans = -1;break;}
			else {
				sufSum -= C;
				prevNonLeafs = min(all-C, sufSum); 
				ans = ans+C+prevNonLeafs;
				DEBUG(all);
			}
		}
	}
	cout << ans << endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


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



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

  int hantei = g * 10 + b;
  if ((hantei % 4) == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

int n, x[500];
int a[1000000];
vector<pair<int, int>>col;//first:position,second:value

int main(void)
{
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> x[i];
	int siz = n * n;
	fill(a, a + siz, -1);
	for (int i = 0; i < n; ++i)
	{
		a[x[i] - 1] = i + 1;
		col.emplace_back(x[i] - 1, i + 1);
	}
	sort(col.begin(), col.end());
	int gauge = 0;
	for (auto itr = col.begin(); itr != col.end(); ++itr)
	{
		int umnum = itr->second - 1;
		for (int i = 0; i < umnum; ++i)
		{
			while (gauge < siz && a[gauge] >= 0)++gauge;
			if (gauge >= siz)
				return 0 * printf("No\n");
			a[gauge] = itr->second;
			if (gauge > itr->first)
			{
				return 0 * printf("No\n");
			}
		}
	}
	gauge = siz - 1;
	for (auto itr = col.rbegin(); itr != col.rend(); ++itr)
	{
		int umnum = n - itr->second;
		for (int i = 0; i < umnum; ++i)
		{
			while (gauge >= 0 && a[gauge] >= 0)--gauge;
			if(gauge < 0)
				return 0 * printf("No\n");
			a[gauge] = itr->second;
			if (gauge < itr->first)
			{
				return 0 * printf("No\n");
			}
		}
	}
	printf("Yes\n");
	for (int i = 0; i < siz; ++i)
	{
		cout << a[i];
		if (i != siz - 1)
		{
			cout << " ";
		}
		else
		{
			cout << "\n";
		}
	}
	return 0;
}


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

int main()
{
  int N ;
  string S ;
  cin>>N>>S ;
  
  int sum=0 ;
  for(int i=0;i<N-1;i++){
    if(S[i]==S[i+1]){
      int k=0 ;
      while(S[i]==S[i+k]&&i+k<N) k++ ;
      sum+=k-1 ;
      i=i+k-1 ;
    }
  }
  cout<<N-sum<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  char abcd[4];
  std::cin >> abcd;
  int a[4];
  for (int i = 0; i <4; i++) {
    /* code */
    a[i]=int(abcd[i]-48);
  }
  int b[3];
  for (int i = 0; i <2 ; i++) {
    /* code */
    for (int j = 0; j < 2; j++) {
      /* code */
      for (int k = 0; k < 2; k++) {
        /* code */
        if(a[0]+a[1]*pow(-1,i)+a[2]*pow(-1,j)+a[3]*pow(-1,k)==7){
          char c[3];
          if(i==1)c[0]='-';
          else c[0]='+';
          if(j==1)c[1]='-';
          else c[1]='+';
          if(k==1)c[2]='-';
          else c[2]='+';
          std::cout <<a[0] <<c[0] <<a[1] <<c[1] <<a[2] <<c[2] <<a[3] <<"=7" << std::endl;
          exit(0);
        }
      }
    }
  }
}


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

string increment(string s, int n) {
    rep(j,n) {
        rep(i,s.size()) {
            if (s[i] == 'Z') s[i] = 'A';
            else s[i] = s[i] + 1;
        }
    }
    return s;
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    cout << increment(s,n) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int dp[110][110];
int n,m;
int a[110][110];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			char c;
			cin>>c;
			if(c=='.')a[i][j]=0;
			else a[i][j]=1;
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			dp[i][j]=1000000000;
		}
	}
	dp[1][1]=a[1][1];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(i==1&&j==1)continue;
			if(dp[i-1][j]==dp[i][j-1]){
				if(a[i-1][j]==1){
					dp[i][j]=dp[i-1][j];
				}
				else if(a[i][j-1]==1){
					dp[i][j]=dp[i][j-1];
				}
				else{
					dp[i][j]=dp[i][j-1]+a[i][j];
				}
			}
			else if(dp[i-1][j]<dp[i][j-1]){
				if(a[i-1][j]==0){
					dp[i][j]=dp[i-1][j]+a[i][j];
				}
				else dp[i][j]=dp[i-1][j];
			}
			else{
				if(a[i][j-1]==0){
					dp[i][j]=dp[i][j-1]+a[i][j];
				}
				else dp[i][j]=dp[i][j-1];
			}
		}
	}
	cout<<dp[n][m]<<endl;
	return 0;
}

Measured memory_bytes: 384