akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val s = readLine()!!.split(" ")[0]
    val n = s.length
    var flag = 0
    for (i in 0 until n){
        if (i % 2 == 0 && s.get(i) == 'L'){
            flag = 1
            break
        } else if (i % 2 != 0 && s.get(i) == 'R'){
            flag = 1
            break
        }
    }
    if (flag == 0){
        println("Yes")
    } else {
        println("No")
    }
}

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

int main()
{
    int N;
    cin >> N;
    int A[N+2], B[N+2], C[N+2];
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 0; i < N; ++i) cin >> B[i];
    for(int i = 0; i < N; ++i) cin >> C[i];

    sort(A, A + N);
    sort(B, B + N);
    sort(C, C + N);
    ll NB[N], NC[N];
    for(int i = 0; i < N; ++i) {
        int b = B[i], c = C[i];
        NB[i] = (lower_bound(A, A + N, b) - A);
        NC[i] = (lower_bound(B, B + N, c) - B);
    }
    
    /*
    for(int i = 0; i < N; ++i) cout << A[i] << " ";
    cout << endl;
    for(int i = 0; i < N; ++i) cout << B[i] << " ";
    cout << endl;
    for(int i = 0; i < N; ++i) cout << C[i] << " ";
    cout << endl;
    
    
    for(int i = 0; i < N; ++i) cout << NB[i] << " ";
    cout << endl;
    for(int i = 0; i < N; ++i) cout << NC[i] << " ";
    cout << endl;
    */

    for(int i = 1; i < N; ++i) {
        //累積和とって計算量削減
        NB[i] += NB[i-1];
    }

    ll res = 0;
    for(int i = 0; i < N; ++i) {
        ll c = NC[i]-1;
        if(c >= 0) res += NB[c];
    }
    cout << res << endl;
    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
        a[i]--;
    }
    
    int ans = 0;
    
    for(int i = 0; i < n; i++){
        if(i == a[a[i]]) ans++;
    }
    
    cout << ans / 2<< endl;
    
}


Measured memory_bytes: 640
#include<iostream>
#include <stdio.h>
#include<string>
#include<math.h>
#include <algorithm>
using namespace std;
int a[3],b;
char c;
int main() {
	cin >> b;
	if (b == 2) { cin >> a[0] >> a[1]; }
	else cin >> a[0] >> a[1] >> a[2];
	if (b == 2) {
		for (size_t i = 1; i <= min(a[0], a[1]); i++)
		{
			if (a[0] % i == 0 && a[1] % i == 0)cout << i << endl;
		}
	}
	else {
		for (size_t i = 1; i <= min(a[0], min(a[1],a[2])); i++)
		{
			if (a[0] % i == 0 && a[1] % i == 0&&a[2]%i==0)cout << i << endl;
		}
	}

	
	return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl;
#define all(x) x.begin(), x.end()
ll MOD = 1e9 + 7;
const int INF = 2e9 + 10;
const int mx = 2e6+60;
vll fact(mx);
vll modinv(mx);

void mulmod(ll &a,ll &b)
{
    if(a<0)
        a += MOD;
    if(b<0)
        b+= MOD;
    a = (a*b)%MOD;
    if(a<0)
        a += MOD;
}

ll bpow(ll base,ll pow)
{
    if(pow == 0) return 1ll;
    ll ans = bpow(base,pow/2);
    mulmod(ans,ans);
    if(pow%2)
        mulmod(ans,base);
    return ans;
}

ll minv(ll i)
{
    return bpow(i,MOD-2);
}

void pre()
{
    fact[0]=1;
    for(int i=1;i<mx;i++)
    {
        fact[i] = (fact[i-1]*i)%MOD;
    }
    modinv[mx-1] = minv(fact[mx-1]);
    for(int i=mx-2;i>=0;i--)
    {
        modinv[i] = (modinv[i+1]*(i+1))%MOD;
    }
}

ll choose(ll n,ll r)
{
    if(r==0) return 1;
    if(r<0 || r>n) return 0;
    ll num = fact[n];
    mulmod(num,modinv[r]);
    mulmod(num,modinv[n-r]);
    return num;
}

void solve()
{
    pre();
    ll r1,c1,c2,r2;
    cin>>r1>>c1>>r2>>c2;
    ll ans = 0,temp;
    //cout<<fact[1e5]<<endl;
    for(int i =c1;i<=c2;i++)
    {
        temp = (choose(i+r2+1,i+1) - choose(i+r1,i+1) + MOD)%MOD;
        ans = (ans + temp)%MOD;
    }   
    cout<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 34592
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int sz = 1e6 + 1;

int n;
int a[sz];
int s[sz];
int prime[sz];

void sieve() {
	for (int i = 2; i < sz; i++) {
		if (s[i] == 0) {
			for (int j = i; j < sz; j += i)
				s[j] = i;
		}
	}
}

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

void solve() {
	sieve();
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int g = a[0];
	for (int i = 0; i < n; i++) {
		g = gcd(g, a[i]);
		set<int> fact;
		int t = a[i];
		while (t != 1) {
			fact.insert(s[t]);
			t /= s[t];
		}
		for (int p : fact)
			prime[p]++;
	}

	bool ok = 1;
	for (int i = 0; i < sz; i++)
		if (prime[i] > 1)
			ok = 0;
	if (ok)
		cout << "pairwise coprime";
	else if (g == 1)
		cout << "setwise coprime";
	else
		cout << "not coprime";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}


Measured memory_bytes: 15160
def calc_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def div_or_sub(n, k):
    while k <= n:
        if n % k == 0:
            n //= k
        else:
            n %= k
    return n

n = int(input())
cnt = len(calc_divisors(n - 1)) - 1
n_divisors = calc_divisors(n)
for divisor in n_divisors[1:]:
    if div_or_sub(n, divisor) == 1:
        cnt += 1
print(cnt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n + 1), b(n+1,0);
    for (ll i = 1; i < n + 1; i++) cin >> a[i];
    for (ll i = n; i > 0;i--){
        ll tmp = 0;
        for (ll j = 2*i; j < n + 1; j += i) tmp += b[j];
        if (tmp % 2 == a[i])
            b[i] = 0;
        else
            b[i] = 1;
    }
    cout << count(b.begin(), b.end(), 1) << endl;
    vector<ll> ans;
    for (ll i = 1; i < n + 1;i++)
        if (b[i]) ans.push_back(i);
    for (ll i = 0; i < ans.size(); i++) cout << ans[i] << " \n"[i == ans.size() - 1];
}

Measured memory_bytes: 7204
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct{
  char suit,value;
}Card;

void Bubble(Card A[],int n)
{
  int i,j;
  Card f;
  for(i=0;i<=n-1;i++)
    {
      for(j = n-1;j>=i+1;j--)
	{
	  if(A[j].value<A[j-1].value)
	    {
	      f = A[j];
	      A[j]=A[j-1];
	      A[j-1]=f;
	    }
	}
    }
}

void Selection(Card A[], int n)
{
  int i,j,minj,a,b;
  Card t;
  for(i=0;i<=n-1;i++)
    {
      minj=i;
      for(j = i;j<=n-1;j++)
	{
	  if(A[j].value<A[minj].value)
	    {
	      minj=j;
	    }
	}
	  t =A[i];A[i] = A[minj];A[minj]=t;    
	
    }
}

int isStable(Card C1[],Card C2[],int n)
{
  int i;
  for(i=0;i<n;i++)
    {
      if(C1[i].suit != C2[i].suit)return 0;
    }
  return 1;
} 

int main()
{
  int i,j,n;
  Card C1[100],C2[100];
  char as,s[3]; 
  scanf("%d",&n);
  for(i = 0;i<n;i++)
    {
    scanf("%s",s);
  C1[i].suit=s[0];
  C1[i].value=s[1];
    }

  for(i=0;i<n;i++)C2[i]=C1[i];

  Bubble(C1,n);
  Selection(C2,n);

  for(i=0;i<n-1;i++)
    {
      s[0] = C1[i].suit;
      s[1]=C1[i].value;

      printf("%s ",s);
    }
  s[0] = C1[i].suit;
  s[1]=C1[i].value;
  printf("%s\n",s);
  printf("Stable\n");

  for(i=0;i<n-1;i++)
    {
      s[0] = C2[i].suit;
      s[1]=C2[i].value;

      printf("%s ",s);
    }
  s[0] = C2[i].suit;
  s[1]=C2[i].value;
  printf("%s\n",s);

  if(isStable(C1,C2,n))
    {
      printf("Stable\n");
    }
  else{
    printf("Not stable\n");
  }


  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
int main(void){
    std::deque<char> deq;
    string s;
    cin>>s;
    for (int i=0;i<4;i++) {
        char c=s.at(i);
        deq.emplace_back(c);
    }
    sort(deq.begin(),deq.end());
    if (deq[0]==deq[1]&&deq[2]==deq[3]&&deq[0]!=deq[3]) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
def lscan; gets.split.map &:to_i; end

n, d = lscan
a = n.times.map{lscan}
ans = 0
a.combination(2) do |i,j|
	r2 = i.zip(j).map{|y,z| (y - z) ** 2}.inject(:+)
	ans += 1 if Math.sqrt(r2).to_i ** 2 == r2
end
puts ans


Measured memory_bytes: 1788
a, b, c = map(int, input().split())
dic = []
count = 0

while all([a%2 == 0, b%2 == 0, c%2 == 0]):
    a, b, c = int((b+c)/2), int((a+c)/2), int((c+a)/2)
    if (a, b, c) in dic:
        count = -1
        break
    else:
        dic.append((a, b, c))
        count += 1

print(count)

Measured memory_bytes: 9000
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
s=[0]*n
for i in range(n):
  s[i]=s[i-1]+a[i]
s=[0]+s
c=[[0]*w for _ in range(h)]
cnt=0
k=1
for i in range(h):
  for j in range(w):
    cnt+=1
    if cnt>s[k]:
      k+=1
    if i%2==0:
      c[i][j]=k
    else:
      c[i][w-1-j]=k
for c_y in c:
  print(*c_y)

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

int main(void) {
    string n;
    cin >> n;
    if((n[0]==n[1] && n[1]==n[2]) || (n[1]==n[2] && n[2]==n[3]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int W,H,x,y,r;

  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  if(y + r > H || x + r > W) printf("No\n");
  else  if(x - r < 0 || y - r < 0) printf("No\n"); 
  else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a.begin(), a.end());

    vector<ll> s(n+1);
    for(i=0; i<n; i++) {
        s[i+1]=(s[i]+a[i])%MOD;
    }
    ll ans=0;
    for(i=0; i<n; i++) {
        ll tmp0=a[i]*mpow(2,n)%MOD;
        ll tmp1=s[i]*mpow(2,n-1)%MOD;
        ans=(ans+tmp0+tmp1)%MOD;
    }
    ans=ans*mpow(2,n-1)%MOD;
    printf("%lld\n", ans);

    return 0;
}



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

using ll = long long;

int main(){
  int N, K;
  cin >> N >> K;
  vector<ll> h(N);

  vector<ll> dp(100000, 1000000000);
  for (int i = 0; i < N; i++) cin >> h[i];

  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  for (int i = 2; i < N; i++) {
    for (int j = 1; j <= K; j++) {
      if(i>=j) dp[i]=min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
    }
  }
  cout << dp[N-1] << endl;
}


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

using namespace std;


#define pb push_back
#define fo(i, n) for(int i = 1; i <= n; ++i)

const int mod = 1e9 + 7;
const int N = 700012;
const int inf = 2e9;
typedef long long ll;
int n;
map<int, int> cnt1, cnt2;
int a[N];
inline bool cmp(pair<int,int> a, pair<int,int> b) {
    if(a.second!=b.second) return a.second>b.second;
    return a.first<b.first;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    fo(i, n) cin >> a[i];
    for(int i = 1; i <= n; i += 2)
        cnt1[a[i]]++;
    for(int i = 2; i <= n; i += 2)
        cnt2[a[i]]++;
    cnt1[0] = 0;
    cnt2[0] = 0;
    int c = 0;
    int ans = 0;
    vector<pair<int,int>> r1;
    vector<pair<int,int>> r2;
    for(auto x: cnt1)
        r1.pb(x);
    for(auto y : cnt2)
        r2.pb(y);
    sort(r1.begin(),r1.end(), cmp);
    sort(r2.begin(),r2.end(), cmp);
    for(auto x : r1) {
        ++c;
        if(c > 4) break;
        for(auto y : r2) {
            if(x.first != y.first) ans = max(ans, x.second + y.second);
        }
    }
    cout << n - ans;
    return 0;
}

Measured memory_bytes: 6524
#include<bits/stdc++.h>
#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
#define N 200123
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define pb emplace_back
#define fs first
#define sc second
#define sz(x) ((int)((x).size()))
#define oo 1000000123
#define mod 1000000007LL
#define eps 1e-9

using namespace std;

double th, tM, h, m, pi = acos(-1);

int main(){
    ios_base::sync_with_stdio(0);
    cin >> th >> tM >> h >> m;
    cout << fixed << setprecision(15);
    double uh = 360.0 / 12.0, um = 360.0/60.0;
    double ah = uh * h, am = um * m, a;

    if(m != 0.0) ah = ah+ uh*(m/60.0);
    //cout << ah << ' '  << am << '\n';

    if(ah < am) swap(ah, am);

    
    a = min((ah - am), 360.0 - (ah - am));

    /*
    if(abs(a - 180.0) < eps) {
        cout << th + tM << '\n';
        return 0;
    }
    */

    double ar = (a * pi) / 180.0;

    //cout << a << ' ' << ar << '\n';
    double cs = cos(ar);
    //cout << cos(ar) << '\n';
    double ans = sqrt(th*th + tM*tM - 2.0 * th * tM * cos(ar));
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4216
#include<bits/stdc++.h>
using lint = int_fast64_t;

int main(){
        lint n, c;
        scanf("%ld %ld", &n, &c);

        std::vector<std::vector<lint>> scd(c, std::vector<lint>(2e5+9, 0));
        for(lint i=0; i<n; i++){
                lint s, t, cc;
                scanf("%ld %ld %ld", &s, &t, &cc);
                scd[cc-1][s*2-1] = 1;
                scd[cc-1][t*2] = -1;
        }
        for(lint i=0; i<c; i++){
                for(lint j=1; j<2e5+9; j++){
                        scd[i][j] += scd[i][j-1];
                }
        }

        lint ans = 1;
        for(lint i=0; i<2e5+9; i++){
                lint tmp = 0;
                for(lint j=0; j<c; j++) tmp += (scd[j][i]>0);
                ans = std::max(ans, tmp);
        }
        printf("%ld\n", ans);
        return 0;
}

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

long long int gcd(long long int a, long long int b)  
{ 
        if (b == 0) return a;  
        return gcd(b, a%b);
}

long long int lcm(long long int a, long long int b)
{
        return (a*b)/gcd(a,b);
}

int main()
{
        long long int a,b,c,d,rB,rA,ans;
        cin >> a >> b >> c >> d;
        rB = b/c + b/d - b/lcm(c,d);
        rA = (a-1)/c + (a-1)/d - (a-1)/lcm(c,d);
        a--;
        cout << (b - a) - (rB - rA)<< endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define LONGMAX 1e18
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define endl "\n"
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define INF 1e9
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
void ceilsearch(ll ar[],ll low,ll high,ll x,ll &y){ll mid=(low+high)/2;if(low>high)return;if(ar[mid]>=x){y=mid;ceilsearch(ar,low,mid-1,x,y);}else{ceilsearch(ar,mid+1,high,x,y);}}
int main()
{
	fastio();
	//#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("outpu.txt","w",stdout);
    //#endif
	string s,t;
	cin>>s>>t;
	ll a,b;
	cin>>a>>b;
	string u;
	cin>>u;
	if(u==s)
	    a--;
	 else
	    b--;
	    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
 
int main(){
	int n;
	cin >> n;
	cin.ignore(numeric_limits<streamsize>::max(), '\n');
	string s, t;
    
	cin >> s >> t;
    
    for(int i=0;i<n;i++){
    	cout << s[i];
    	cout << t[i];
	}
     
    return 0;
}
	

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();

    int x0,y0;
    cin>>x0>>y0;
    if((x0+y0)%3!=0){
        cout<<0<<endl;
        return 0;
    }
    long long int x,y;
    x=x0-(x0+y0)/3;
    y=y0-(x0+y0)/3;

    cout << COM(x+y,x) << endl;
    return 0;
}

Measured memory_bytes: 23680
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, T, A = sc.nextInt()
  val Hs = List.fill(N)(sc.nextInt())
  val ((_, index), _) =
    Hs.zipWithIndex.map { case (h, i) =>
      (h -> i) -> math.abs(A - T + h * 0.006)
    }.minBy { case (_, diff) => diff }
  println(index + 1)
}


Measured memory_bytes: 56064
#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ll long long
#define pb push_back
#define fo(i,a,b) for(int i=a;i<b;i++)
#define foe(i,a,b) for (int i=a;i<=b;i++)
void solve()
{
    int n,k;
    cin>> n>> k;
    int a[n];
    bool dp[k+1];
  //dp[i] represents whether first win or not if i is the number of stone left and turn is of first
    fo(i,0,n) cin>>a[i];
    foe(i,0,k) dp[i]=false;
    foe(i,0,k){
        for (int j=0;a[j]<=i && j<n;j++){
            if (dp[i-a[j]]==false)
               dp[i]=true;
        }
    }
    if (dp[k]== true)
    cout<<"First";
    else
    {
        cout<<"Second";
    }
    
}
signed main()
{
   faster;
        solve();
}


Measured memory_bytes: 384
#include <climits>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef pair<int, int> i_i;
typedef double D;
typedef complex<D> P;
typedef long long ll;
D pi = acos(-1.0);

void FFT(vector<P>& a, int N, double t) {
	for (int m = N; m >= 2; m /= 2) {
		int mh = m / 2;
		for (int i = 0; i < mh; i++) {
			P w = polar(1.0, t * i);
			for (int j = i; j < N; j += m) {
				int k = j + mh;
				P x = a[j] - a[k];
				a[j] += a[k];
				a[k] = w * x;
			}
		}
		t *= 2;
	}
	int i = 0;
	for (int j = 1; j <= N - 2; j++) {
		for (int k = N / 2; k > (i^=k); k /= 2);
		if (j < i) swap(a[i], a[j]);
	}
}

vector<P> conv(vector<P> a, vector<P> b) {
	int n = a.size() + b.size();
	int N = 1;
	while (N < n) N *= 2;
	a.resize(N);
	b.resize(N);
	FFT(a, N, 2 * pi / N);
	FFT(b, N, 2 * pi / N);
	for (int i = 0; i < N; i++)
		a[i] *= b[i];
	FFT(a, N, -2 * pi / N);
	for (int i = 0; i < N; i++)
		a[i] /= N;
	return a;
}

vector<int> f(int N, vector<int>& a) {
	vector<int> sum(N + 1);
	for (int i = 0; i < N; i++)
		sum[i + 1] = sum[i] + a[i];
	vector<P> p(200001), q = p;
	for (int i = 0; i <= N; i++) {
		p[sum[i]] += 1;
		q[200000 - sum[i]] += 1;
	}
	vector<P> r = conv(p, q);
	vector<int> ans(200001);
	for (int x = 1; x <= 200000; x++)
		ans[x] += (int)(r[200000 + x].real() + 0.5);
	return ans;
}

int main() {
	int N, M, Q; cin >> N >> M >> Q;
	vector<int> a(N), b(M);
	for (int i = 0; i < N; i++)
		scanf("%d", &a[i]);
	for (int j = 0; j < M; j++)
		scanf("%d", &b[j]);
	vector<int> A = f(N, a), B = f(M, b);
	vector<P> p(200001), q(200001);
	for (int x = 0; x <= 200000; x++)
		p[x] += A[x];
	for (int x = 0; x <= 200000; x++)
		q[200000 - x] += B[x];
	vector<P> r = conv(p, q);
	vector<ll> ans(200001);
	for (int x = 0; x <= 200000; x++)
		ans[x] += (ll)(r[200000 + x].real() + 0.5) + (ll)(r[200000 - x].real() + 0.5);
	ans[0] /= 2;
	while (Q--) {
		int c; scanf("%d", &c);
		printf("%lld\n", ans[c]);
	}
}

Measured memory_bytes: 34276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	int H[100000];
	rep(i, N) cin >> H[i];

	int dp[100100];
	rep1(i, N) dp[i] = 1e9;
	dp[0] = 0;
	rep(i, N) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]));
	}
	co(dp[N - 1]);

	Would you please return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<tuple<string,int,int>>a(n);
  for(int i=0;i<n;i++){
    string s;
    int k;
    cin>>s>>k;
    a.at(i)=make_tuple(s,100-k,i+1);
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
    cout<<get<2>(a.at(i))<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //System.out.print("入力してください > ");
        //int    x = Integer.parseInt(scanner.nextLine());
        //int n = Integer.parseInt(scanner.nextLine());
        //String d = scanner.nextLine();
       
        int n    =  Integer.parseInt(scanner.nextLine());
        String s =  scanner.nextLine();
        
        char[] ss = s.toCharArray();
        
        for(int i = 0 ; i < ss.length ; i++){
            ss[i] = inc(ss[i],n);
        }
        
        System.out.println(new String(ss));
        // Scannerクラスのインスタンスをクローズ
        scanner.close();
    }
    
    private static char inc(char c, int n){
        
        char ret = c;
        for(int i = 0 ; i < n ; i ++){
            if(ret == 'z'){
                ret = 'a';
            }
            else if(ret == 'Z'){
                ret = 'A';
            }
            else{
                ret++;
            }
        }
        return ret;
        
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
const int N = 105;
const int K = 1e5+5;
int dp[N][K];
int a[N];
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)   scanf("%d",&a[i]);
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        int sum = 0;
        for(int j=0;j<a[i];j++){
            sum += dp[i][j];
            sum %= MOD;
            dp[i+1][j] = sum;
        }
        for(int j=a[i];j<=k;j++){
            sum += dp[i][j];
            sum %= MOD;
            dp[i+1][j] = sum;
            sum -= dp[i][j-a[i]];
            sum = (sum+MOD)%MOD;
        }
    }
    printf("%d\n",dp[n][k]);
    return 0;
}


Measured memory_bytes: 40832
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long cnt = 0, n;
	cin >> n;
	for(int i=1; i<=n; i++)
		if(i % 3 != 0 && i % 5 != 0)
			cnt += i;
	cout << cnt << endl;
	return 0; 
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<math.h>
using namespace std;

int main() 
{
	int a = 0;
	string s;

	cin >> s;
    for(int i=0;i<7;i++)if(s[i]=='1')a++;
	
	cout << a;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define mod (int)(1e9 + 7)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

map<pair<int,string>,int> mp;
int N;
string AGCT="AGCT";

int dfs(int n, string s){
  if(s=="AGC") return 0;
  if(mp.find(make_pair(n,s))!=mp.end()) return mp[make_pair(n,s)];
  if(n==N) return 1;

  int ret=0;
  for(int i=0;i<4;i++){
    if(i==2 && s[0]=='A' && s[2]=='G') continue;
    if(i==2 && s[0]=='A' && s[1]=='G') continue;
    if(s.substr(1)+AGCT[i]=="GAC" || s.substr(1)+AGCT[i]=="ACG") continue;
    int tmp=dfs(n+1,s.substr(1)+AGCT[i]);
    ret=(ret+tmp)%mod;
    //cout<<s+AGCT[i]<<endl;
  }
  mp[make_pair(n,s)]=ret;
  return ret;
}

int main(){
  cin>>N;
  cout<<dfs(0,"TTT")<<endl;
  
  return 0;
}



Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;

const int oo = 1e8+7;
const int mod = 1e9+7;

int n;
vector<vi> AdjList;
vector<vector<ll>> dp;

int solve(int a, int prev, int col) {

    if(dp[a][col] != -1) return dp[a][col];
    ll ans = 1;
    
    for(int b : AdjList[a]) {

        if(b == prev) continue;
        
        ll nextBlack = solve(b, a, 1);
        ll nextWhite = solve(b, a, 0);
        
        if(col == 0) {
            ans *= (nextBlack + nextWhite) % mod;
        } else {
            ans *= nextWhite % mod;
        }
        
        ans %= mod;
    }
    
    dp[a][col] = ans;
    return ans;
}

int main() {
 
    scanf("%d",&n);
    
    AdjList.resize(n+1);
    dp.resize(n+1);
    
    for(int i = 1; i <= n; ++i) {
        dp[i].assign(2, -1);
    }
    
    for(int i = 0; i < n-1; ++i) {
        int a, b;
        scanf("%d%d",&a,&b);
        AdjList[a].push_back(b);
        AdjList[b].push_back(a);
    }
    
    ll ans = solve(1, -1, 0);
    ans += solve(1, -1, 1);
    
    cout << ans%mod << endl;
 
    return 0;   
}



Measured memory_bytes: 19584
#include <stdio.h>

int main() {

  char alphabeth;
  scanf("%c", &alphabeth);

if(alphabeth >= 'a' && alphabeth <= 'z') {
    puts("a");
    }else if(alphabeth >= 'A' && alphabeth <= 'Z') {
    puts("A");
    }

  return 0;
}

Measured memory_bytes: 1572
n=int(input())
h=list(map(int,input().split()))
count=0
i=0
while(i<n):
  if(h[i]==0):
    i=i+1
    continue
  j=i
  while(j<n):
    if(h[j]==0):
      break
    if(h[j]>0):
      h[j]=h[j]-1
      j=j+1
      continue
  count=count+1
  #print(h)
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int a, b;
  cin >> a >> b;

  cout << (a + b + 1) / 2 << endl;

  return 0;
}


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

int main(){
    int n,m;
    cin >> n;
    int t[n] = {};
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> t[i];
        sum += t[i];
    }  
    cin >> m;
    int p[m] = {}, x[m] = {};
    for(int i = 0; i < m; i++){
        cin >> p[i] >> x[i];
    }
    for(int i = 0; i < m; i++){
        int a = p[i] - 1;
        cout << sum - t[a] + x[i] << endl;
        //cout << t[a] << " " << x[i] << endl;
    }
    return 0;
}



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

int main() {
	// your code goes here
	string s;
	cin>>s;
	int n = s.length();
	int f=1;
	for(int i=0;i<n;i++){
		if(i%2==0 and s[i]=='L'){
			f=0;
			break;
		}
		else if(i%2==1 and s[i]=='R'){
			f=0;
			break;
		}
	}
	if(f) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
string s,t;
int cdt,cds;
long long kq = 0;
int near[500000][200];
int main()
{
		cin >> s;
		int cds = s.size();
		cin >> t;
		int cdt = t.size();
		s = '0' + s + '0';
		t = '0' + t + '0';
		for (int i = cds ; i >= 0 ; i--)
		{
				for (int e = 'a' ; e <= 'z' ; e++)
				{
						char c = e;
						near[i][e] = near[i+1][e];
						if (s[i] == e)
						{
								near[i][e] = i;
						}
						//cout <<"near["<<i<<"]["<<c<<"] : "<<near[i][e]<<endl;
				}
		}
		int cur = 0;
		for (int i = 1 ; i <= cdt ; i++)
		{
				if (cur > cds) cur = 0;
				if (near[cur][t[i]] == 0)
				{
						kq += cds - cur + 1;
						cur = 0;
				}
				if (near[cur][t[i]] == 0)
				{
						cout <<-1;
						exit(0);
				}
				if (cur != 0)
				{
						kq += near[cur][t[i]] - cur + 1;
				}
				else
				{
						kq += near[cur][t[i]];
				}
				cur = near[cur][t[i]] + 1;
				//cout <<"after "<<i<<" cur : "<<cur<<" kq : "<<kq<<'\n';
		}
		cout << kq;
}


Measured memory_bytes: 80380
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

int main() {
    int n;
    cin >> n;
    vector<int> v(3*n, 0);
    vector<ll> S(n+1, 0);
    for (auto &&i : v) scanf("%d", &i);
    ll s = 0;
    GPQ<int> Q;
    for (int i = 0; i < n; ++i) {
        Q.push(v[i]);
        s += v[i];
    }
    S[0] = s;
    for (int i = n; i < 2*n; ++i) {
        Q.push(v[i]);
        s = s + (v[i]-Q.top());
        Q.pop();
        S[i-n+1] = s;
    }
    s = 0;
    PQ<int> Q2;
    for (int i = 0; i < n; ++i) {
        Q2.push(v[n*2+i]);
        s += v[n*2+i];
    }
    S[n] -= s;
    for (int i = 2*n-1; i >= n; --i) {
        Q2.push(v[i]);
        s = s + (v[i]-Q2.top());
        Q2.pop();
        S[i-n] -= s;
    }
    cout << (*max_element(S.begin(), S.end())) << "\n";
    return 0;
}


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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define tcase int _; cin>> _; for( ; _; --_)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

void solve(){
    cin >> n;
    vi a(n);

    for(int &i: a) cin>> i;

    sort(all(a), greater<int>());
    
    int ans = a[0];
    
    if(n & 1){
        for(int i = 1; i<n/2; ++i)  ans += 2*a[i];
        ans += a[n/2];
        cout<< ans<< endl;
    }
    else{
        for(int i = 1; i < n/2; ++i) ans += 2*a[i];
        cout<< ans<< endl;
    }
}

int32_t main(){
	fastio;
	solve();
	return 0;
}



Measured memory_bytes: 4764
#pragma region header
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    string s;cin >> s;
    int count=0;
    rep(i, s.size()) {
        count+=s[i]-'0';
    }
    if(count%9==0)cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 3756
use std::cmp::max;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n = read::<i64>();
    let ans  = (1..)
        .take_while(|&x| x * x <= n)
        .filter(|&x| n % x == 0)
        .map(|x| max(get_x(x), get_x(n/x)) )
        .min()
        .unwrap();

    print!("{}",ans);

}

fn get_x(x:i64) -> usize {
        let mut cnt = 0;
        let mut n = x;
        while n > 0 {
            cnt += 1;
            n /= 10;
        }
        cnt
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline void chmax(S &a, T b){
  if(a<b){
    a=b;
  }
}
int N, W, gain[4][100], sum[4][101], sz[4], v[100], w[100];
int main(){
  int a, b, c, d, i, j, res=0, tmp;
  long long minw, r;
  rd(N);
  rd(W);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(w[Lj4PdHRW]);
      rd(v[Lj4PdHRW]);
    }
  }
  minw = w[0];
  for(i=0;i<N;i++){
    j = w[i] - minw;
    gain[j][sz[j]++] = v[i];
  }
  {
    int KL2GvlyY;
    for(KL2GvlyY= 0;KL2GvlyY< (3) + 1;KL2GvlyY++){
      sort(gain[KL2GvlyY], gain[KL2GvlyY]+sz[KL2GvlyY], greater<int>());
    }
  }
  {
    int Q5VJL1cS;
    for(Q5VJL1cS= 0;Q5VJL1cS< (3) + 1;Q5VJL1cS++){
      {
        int e98WHCEY;
        for(e98WHCEY= 1;e98WHCEY< (sz[Q5VJL1cS]) + 1;e98WHCEY++){
          sum[Q5VJL1cS][e98WHCEY] += sum[Q5VJL1cS][e98WHCEY - (1) + (0)] + gain[Q5VJL1cS][e98WHCEY - (1) + (0)];
        }
      }
    }
  }
  for(a=0;a<sz[0]+1;a++){
    for(b=0;b<sz[1]+1;b++){
      for(c=0;c<sz[2]+1;c++){
        r = W - (long long)minw*a - (long long)(minw+1)*b - (long long)(minw+2)*c;
        if(r < 0){
          break;
        }
        d = min(r / (minw+3), (long long)sz[3]);
        chmax(res, sum[0][a] + sum[1][b] + sum[2][c] + sum[3][d]);
      }
    }
  }
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20170429-1

// --- original code ---
// int N, W, w[100], v[100];
// int gain[4][100], sum[4][101], sz[4];
// {
//   int res = 0, tmp;
//   int i, j, a, b, c, d;
//   ll r, minw;
//   rd(N, W, (w,v)(N));
//   minw = w[0];
//   rep(i,N){
//     j = w[i] - minw;
//     gain[j][sz[j]++] = v[i];
//   }
//   sort(gain[0..3], gain[0..]+sz[0..], greater<int>());
// 
//   sum[0...3][1..sz[0...]] += sum[0...][0..] + gain[0...][0..];
// 
//   rep(a,sz[0]+1) rep(b,sz[1]+1) rep(c,sz[2]+1){
//     r = W - (ll)minw*a - (ll)(minw+1)*b - (ll)(minw+2)*c;
//     if(r < 0) break;
//     d = min(r / (minw+3), (ll)sz[3]);
//     res >?= sum[0][a] + sum[1][b] + sum[2][c] + sum[3][d];
//   }
//   wt(res);
// }


Measured memory_bytes: 256
// C.

#include <iostream>
#include <sstream>
#include <cmath>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	LL n, p, ans = 1;
	cin >> n >> p;
	if (n == 1) {
		ans = p;
	} else if (n < 64) {
		LL sq = (LL)sqrt(p);
		for (LL a = sq; a > 1; --a) {
			LL x = 1;
			for (LL b = 0; b < n; ++b) {
				x *= a;
				if (x > p) {
					break;
				}
			}
			if (p >= x && (p % x) == 0) {
				ans = a;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
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<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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 int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
int digit(int a){
    int count = 0;
    for (int i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }     
    }
    return count;
}
//pow(x,n) == x^n

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

int a,b,count = 0;
string s;
cin >> a >> b >> s;
rep(i,s.size()){
    if (s[i] != '-')
    {
        count++;
    }
}
if (count == a+b && s[a] == '-')
{
    cout << "Yes" << endl;
}else
{
    cout << "No" << endl;
}



//////////////////////////////////////////////////////
return 0;}

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

using namespace std;

const int WHITE = 1;
const int BLACK = 2;
const int GRAY = 3;
int N;

bool connected(vector<int> list[]){
    int s = 0;
    vector<int> color(N,WHITE);
    queue<int> Q;
    color[s] = BLACK;
    Q.push(s);
    while(!Q.empty()){
        int u = Q.front(); Q.pop();
        color[u] = BLACK;
        for(int j=0;j<list[u].size(); j++){
            int v = list[u][j];
            if(color[v] != BLACK){
                color[v] = BLACK;
                Q.push(v);
            }
        }
    }
    for(int i=0;i<N;i++){
        if(color[i] == WHITE){
            return false;
        }
    }
    return true;
}

int main(){
    int M;
    cin >> N >> M;
    vector<pair<int,int> > P(M);
    for(int i=0;i<M;i++){
        int a,b; cin >> a >> b;
        a--; b--;
        P[i] = make_pair(a,b);
    }
    int ans = 0;
    for(int i=0;i<M;i++){
        vector<int> list[N];
        for(int j=0;j<M;j++){
            if(j==i) continue;
            int a = P[j].first, b = P[j].second;
            list[a].push_back(b);
            list[b].push_back(a);
        }
        if(!connected(list)) ans++;
    }
    cout << ans << endl;
    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;

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a % b);
}

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

    int t;
    cin >> t;
    for(int loop = 0; loop < t; ++loop){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        if(b > a || b > d){
            cout << "No\n";
            continue;
        }
        if(c >= b){
            cout << "Yes\n";
            continue;
        }
        
        ll g = gcd(d, b);
        ll tmp = b + a % g - g;     // mod b で取り得る最大の値
        if(tmp <= c)    cout << "Yes\n";
        else    cout << "No\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n, m; cin >> n >> m;
    vector<set<int>> G(n);
    rep(i, m){
        int a, b; cin >> a >> b; a--, b--;
        if(not G[a].insert(b).second) G[a].erase(b);
        if(not G[b].insert(a).second) G[b].erase(a);
    }

    bool ok = true;
    rep(v, n){
        if((int)G[v].size() % 2 == 1) ok = false;
    }

    cout << (ok ? "YES":"NO") << endl;

    return 0;
}


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

long long dp[5010][5010];
long long tmp[5010];
bool pos[5010][5010];
bool ptmp[5010];
int sz[5010];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<vector<int>> e(n);
    for (int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        u--, v--;
        e[u].emplace_back(v);
        e[v].emplace_back(u);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = 1e16;
        }
    }
    auto f = [&](auto f, int curr, int prev) -> void {
        sz[curr] = 1; pos[curr][0] = (a[curr] > 0);
        dp[curr][0] = a[curr];
        for (auto &to: e[curr]) {
            if (to == prev) continue;
            f(f, to, curr);
            for (int i = 0; i < n; i++) tmp[i] = 1e16, ptmp[i] = 0;
            for (int i = 0; i < sz[curr]; i++) {
                for (int j = 0; j < sz[to]; j++) {
                    if (pos[to][j] || dp[to][j] < 0) {
                        tmp[i+j+1] = min(tmp[i+j+1], dp[curr][i]);
                        ptmp[i+j+1] |= pos[curr][i];
                    }
                    ptmp[i+j] |= pos[curr][i] & pos[to][j];
                    tmp[i+j] = min(tmp[i+j], dp[curr][i] + dp[to][j]);
                }
            }
            sz[curr] += sz[to];
            for (int i = 0; i < sz[curr]; i++) {
                dp[curr][i] = tmp[i];
                pos[curr][i] = ptmp[i];
            }
        }
    };
    f(f, 0, -1);
    for (int i = 0; i < n; i++) {
        if (dp[0][i] < 0 || pos[0][i]) {
            cout << i << "\n";
            return 0;
        }
    }
    assert(false);
    return 0;
}

Measured memory_bytes: 221184