akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){
    ll n, k; cin >> n >> k;
    vector<ll> P(n), C(n);
    rep(i, n){cin >> P[i]; P[i]--;}
    rep(i, n)cin >> C[i];

    ll res = -LINF;
    rep(i, n){
        //サイクルスコアとサイクル長を調べる
        ll cycle_score = 0; int cycle_len = 0, v = i;
        while(1){
            cycle_len++;
            v = P[v];
            cycle_score += C[v];
            if(v == i)break;
        }
        //非サイクル部を全探索してスコアを比較する。スコア＝非サイクル部のスコア+サイクルスコア
        ll score = 0; int cnt = 0;
        while(1){
            cnt++;
            v = P[v];
            score += C[v];
            if(cnt > k)break;

            ll sum = score + max(0LL, cycle_score) * ((k - cnt) / cycle_len);
            chmax(res, sum);
            if(v == i)break;
        }
    }
    cout << res << ln;
}
    


Measured memory_bytes: 3716
fun main(args: Array<String>) {
    val ignore = readLine()
    val numArray = readLine()?.split(" ")?.map { Integer.parseInt(it) }!!
    if (numArray.asSequence().any { it % 2 != 0 }) {
        println(0)
        return
    }
    var resultArray = numArray.map { it / 2 }
    var count = 1
    while (!resultArray.asSequence().any { it % 2 != 0 }) {
        resultArray = resultArray.map { it / 2 }
        count++
    }
    println(count)
}

Measured memory_bytes: 37892
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    int n, lim;
    cin >> n >> lim;
    vector<vector<ll>> a(4, vector<ll>(1, 0));
    ll minw;
    rep(i, n){
        ll w, v;
        cin >> w >> v;
        if(i == 0) minw = w;
        a[w - minw].push_back(v);
    }

    rep(i, 4){
        if(a[i].size() != 0) sort(rall(a[i]));
    }

    ll ans = 0;
    rep(i, a[0].size()){
        rep(j, a[1].size()){
            rep(k, a[2].size()){
                rep(l, a[3].size()){
                    ll w = (minw)*i + (minw+1)*j + (minw+2)*k + (minw+3)*l;
                    ll v = 0;
                    if(w <= lim){
                        rep(idx, i) v += a[0][idx];
                        rep(idx, j) v += a[1][idx];
                        rep(idx, k) v += a[2][idx];
                        rep(idx, l) v += a[3][idx];
                    }
                    ans = max(ans, v);
                }
            }
        }
    }

    cout << ans << endl;
}


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

ll solve() {
    ll N, K, Q;
    cin >> N >> K >> Q;
    vector<ll> num(N);
    int a;
    for ( int i = 0; i < Q; i++ ) {
        cin >> a;
        a--;
        num[a]++;
    }
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        bool win = K - Q + num[i] > 0;
        string ans = win ? "Yes" : "No";
        cout << ans << "\n";
    }
    return ans;
}

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

Measured memory_bytes: 1408
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 10;

int s[MAXN], ans[MAXN];
bool use[MAXN];

int main ()
{
    int n, k;
    scanf ("%d%d", &n, &k);
    memset (use, true, sizeof (use));
    for (int i = 1; i <= k; i ++)
    {
        int x;
        scanf ("%d", &x);
        use[x] = false;
    }
    int all = 0;
    while (n)
    {
        all ++;
        s[all] = n % 10;
        n /= 10;
    }
    int now = 0;
    for (int i = all; i >= 1; i --)
    {
        if (use[s[i]])
        {
            ans[i] = s[i];
        }
        else
        {
            bool flag = false;
            now = i;
            while (now <= all)
            {
                for (int j = s[now] + 1; j <= 9; j ++)
                {
                    if (use[j])
                    {
                        ans[now] = j;
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    break;
                }
                now ++;
            }
            if (!flag)
            {
                all ++;
                for (int j = 1; j <= 9; j ++)
                {
                    if (use[j])
                    {
                        ans[all] = j;
                        break;
                    }
                }
            }
            break;
        }
    }
    if (now > 0)
    {
        for (int i = 0; i <= 9; i ++)
        {
            if (use[i])
            {
                for (int j = now - 1; j >= 0; j --)
                {
                    ans[j] = i;
                }
                break;
            }
        }
    }
    for (int i = all; i >= 1; i --)
    {
        printf ("%d", ans[i]);
    }
    printf ("\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String r = scanner.next();
        String g = scanner.next();
        String b = scanner.next();
        int out = Integer.parseInt(r+g+b);
        if (out % 4 == 0){
            System.out.println("YES");
        }else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21588
function main(input) {
  input = input.trim();
  const [a,b,c] = input.split(" ").map(Number);
  let A = b-a;
  let B = c-b;
  if(A==B){
    console.log("YES");
  }else{
    console.log("NO");
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29632
#include <bits/stdc++.h>
using namespace std;
#define lp(i, x, n) for (int i = x; i < (int)n; ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll long long
#define N 1000001
string s, s1;
int f[27], f1[27];
vector<int> v, v1;
int main() {
        cin >> s>> s1;
        lp (i, 0, sz(s)) f[s[i] - 'a']++;
        lp (i, 0, sz(s1)) f1[s1[i] - 'a']++;
        lp (i, 0, 26) if (f[i])
                v.push_back(f[i]);

        lp (i, 0, 26) if (f1[i])
                v1.push_back(f1[i]);

        sort(all(v1));
        sort(all(v));
        if (sz(v) != sz(v1)) {
                cout << "No";
        } else {
                lp (i, 0, sz(v)) {
                        if (v[i] != v1[i]) {
                                cout << "No";
                                return 0;
                        }
                }
                cout << "Yes";
        }
        return 0;
}


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

#define ll long long int
#define mp make_pair 
#define pb push_back
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define ff first
#define ss second
#define MOD  1000000007
#define ll_MAX 922337203685477999
#define endl "\n"
inline ll absdiff(ll a,ll b) {return (a>b)?a-b:b-a;}
ll fast_expo(ll x,ll p){if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll gcd(ll a,ll b){if(a==0||b==0) return a+b;  else return gcd(b%a,a); }

ll ans=0;

void recur(ll n,ll m){
    if(n==1) {
        ans+=m;
        return ;
    }
    recur(n/2,m*2);
    ans+=m;
    return ;
}

int main()
{
    // fast
    ll t_c;t_c = 1;
    // cin>>t_c;
    for (ll ti = 0; ti < t_c; ++ti)
    {   
        ll h;cin>>h;
        recur(h,1ll);
        cout<<ans;
    }
    return 0;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=1e6+5;
const ll inf=-1e17;

int ar[ms];
int dp[ms][2];



int main()
{
    idfc;

    int n,z,w;
    cin>>n>>z>>w;
    int i;int j;

    for(i=1;i<=n;i++)
    {
        cin>>ar[i];
    }
    ar[0]=w;
    for(i=n;i>=1;i--)
    {
        dp[i][0]=INT_MIN;
        dp[i][1]=INT_MAX;
        for(j=i;j<n;j++)
        {
            dp[i][0]=max(dp[i][0],dp[j+1][1]);
            dp[i][1]=min(dp[i][1],dp[j+1][0]);
        }
        dp[i][0]=max(dp[i][0],abs(ar[n]-ar[i-1]));
        dp[i][1]=min(dp[i][1],abs(ar[n]-ar[i-1]));
    }
    cout<<dp[1][0];

    return 0;
}

Measured memory_bytes: 3648
import string

s = input()
alps = string.ascii_lowercase
mx = {c:0 for c in alps}
tmp = {c:0 for c in alps}

for char in s:
    for alp in alps:
        if alp == char:
            mx[alp] = max(mx[alp], tmp[alp])
            tmp[alp] = 0
        else:
            tmp[alp] += 1

for alp in alps:
    mx[alp] = max(mx[alp], tmp[alp])

print(min(mx.values()))

Measured memory_bytes: 74724
import sys
from io import StringIO
import unittest

def resolve():
    n = input()

    target = n[-1]

    if target in ("2","4","5","7","9"):
        print("hon")
    elif target in ("0","1","6","8"):
        print("pon")
    else:
        print("bon")


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """16"""
        output = """pon"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2"""
        output = """hon"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """183"""
        output = """bon"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

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

#define int long long
const int MOD = 1e9 + 7;
const int INF = 1e18;

bool cmp(int a, int b){
  return a < b;
}

void solve(){
 int n;
 string a, b, c;
 cin >> n >> a >> b >> c;
 set <char> check;
 int moves = 0;
 for (int i = 0; i < n; i++){
   check.insert(a[i]);
   check.insert(b[i]);
   check.insert(c[i]);
   moves += (int)check.size() - 1;
   check.clear();
 }
 cout << moves << endl;
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i=(a); i<(n); ++i)
#define rrep(i,a,n) for(ll i=(a); i>(n); --i)
#define erep(i,a,n) for(ll i=(a); i<=(n); ++i)
#define rerep(i,a,n) for(ll i=(a); i>=(n); --i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int) x.size())
#define print(X) cout << (X) << endl
#define _ << " " <<
static const int INF = 1e+9+7;
ll n,m,l;
str s,t;
int A[100000];

int calc1(int n){
    int i = 0;
    while(true){
        if(i*i*i>n) break;
        ++i;
    }
    --i;
    return (i*i*i);
}

int calc2(int n){
    int i = 0;
    while(true){
        if(i*(i+1)*(i+2)/6>n) break;
        ++i;
    }
    --i;
    return (i*(i+1)*(i+2)/6);
}

int calc3(int n){
    int i = 0;
    int res = 0;
    while(true){
        if(i*i*i>=n) break;
        res = max(res, i*i*i+calc2(n-i*i*i));
        ++i;
    }
    --i;
    return res;
}


int main(){
    vi vc;
    rep(i,0,1024){
        int x;
        cin >> x;
        if (x == 0) break;
        vc.pb(x);
    }

    rep(i,0,sz(vc)){
        int large = max(calc1(vc[i]),calc2(vc[i]));
        large = max(large, calc3(vc[i]));
        print(large);
    }



  return 0;
}






Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD=1000000007LL;
LL dp[1000001]; //dp[i]::=i番目以降の決め方
int main() {
	LL n;
	cin>>n;
	dp[n]=n;
	LL sum=n-1,add=((n-1)*(n-1))%MOD;
	for(int i=n-1;i>=1;i--) {
		dp[i]=(dp[i+1]+add+sum)%MOD;
		sum=(sum+MOD-1)%MOD;
		if(i+2<=n) sum=(sum+dp[i+2])%MOD; else sum=(sum+1)%MOD;
	}
	cout<<dp[1]<<endl;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)
 
int main() {
  ll ans=0;
  ll a[5];
  ll n;
  cin >> n;
  fr(i,5){
    cin >> a[i];
  }
  sort(a, a + 5, greater<long>());
  
  ans = (n-1)/a[4]+5;
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))

cnt = 0
for i,b in enumerate(B):
    c = min(b,A[i]+A[i+1])
    cnt += c
    A[i+1] -= max(0, c-A[i])
print(cnt)

Measured memory_bytes: 19116
#include<stdio.h>

int n,x;

int main(){
	while(scanf("%d",&n)!=EOF){
		x=1;
		while(n!=0){
			if(n%2==1)printf("%d%c",x,(n/2==0)?'\n':' ');
			n=n/2;x=x*2;
		}
		//printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
vector<int> to[maxn];
int c[maxn], val[maxn], stk;
long long ans;
void dfs(int u, int p = 0){
	sort(to[u].begin(), to[u].end(), [&](int a, int b){
		return to[a].size() > to[b].size();
	});
	val[u] = c[stk++];
	if(p) ans += val[u];
	for(int v : to[u]){
		if(v == p) continue;
		dfs(v, u);
	}
}
int main(){
	int n; cin >> n;
	for(int i = 0; i < n - 1; i++){
		int x, y; cin >> x >> y;
		to[x].push_back(y);
		to[y].push_back(x);
	}
	for(int i = 0; i < n; i++) cin >> c[i];
	sort(c, c + n);
	reverse(c, c + n);
	int big = 0;
	for(int i = 0; i < n; i++) if(to[i].size() > big) big = i;
	dfs(big);
	cout << ans << endl;
	for(int i = 1; i <= n; i++) cout << val[i] << " \n"[i == n];
	return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <cstring>

using namespace std;

const int maxv = 100002;

int n, m, w, v, f[maxv];

int main() {

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

	memset(f, -1, sizeof(f));
	f[0] = 0;

	cin >> n >> m;
	int sumv = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> w >> v;
		sumv += v;

		for (int j = sumv; j >= v; --j)
			if (f[j-v] != -1 && f[j-v] + w <= m)
				if (f[j] == -1 || f[j] > f[j-v] + w)
					f[j] = f[j-v] + w;
	}
	
	int ans = 0;
	for (int i = sumv; i > 0; --i)
		if (f[i] != -1 && f[i] <= m) {
			ans = i;
			break;
		}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    while (k > 0 && a >= b)
    {
        k--;
        b *= 2;
    }
    while (k > 0 && b >= c)
    {
        k--;
        c *= 2;
    }

    if (a < b && b < c)
        cout << "Yes\n";
    else
        cout << "No\n";
}

Measured memory_bytes: 3688
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int n,i,a[100010],b[100010],f[100010]={};
  long long s=1,M=(1e9)+7;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  for(i=0;i<n;i++)scanf("%d",&b[i]);
  for(i=0;i<n;i++){
    if(i&&a[i-1]>a[i])s=0;
    if(i&&b[i-1]<b[i])s=0;
    if(i==0||a[i]-a[i-1]){
      f[i]=1;
      if(a[i]>b[i])s=0;
    }
    if(i==n-1||b[i]-b[i+1]){
      f[i]=1;
      if(b[i]>a[i])s=0;
    }    
  }
  if(a[n-1]-b[0])s=0;
  for(i=0;i<n;i++){
    if(f[i])continue;
    s=(s*MIN(a[i],b[i]))%M;
  }
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 500010;
const LL INF = 9999999;
int n, m;
char s[N];
int ans1[N], ans2[N];
int main(){
  memset(ans1, 0, sizeof(ans1));
  memset(ans2, 0, sizeof(ans2));
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i){
    if (s[i] == 'W') ans1[i] = ans1[i - 1] + 1;
    else ans1[i] = ans1[i - 1];
  }
  for (int i = n; i >= 1; --i){
    if (s[i] == 'E') ans2[i] = ans2[i + 1] + 1;
    else ans2[i] = ans2[i + 1];
  }
  int mini = INF;
  for (int i = 1; i <= n; ++i)
    mini = min(mini, ans1[i - 1] + ans2[i + 1]);
  printf("%d\n", mini);
  return 0;
}



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

int main(){
  int a,b;
  cin>>a>>b;
  if(a==b) cout<<"Draw"<<endl;
  else if(a==1) cout<<"Alice"<<endl;
  else if(b==1) cout<<"Bob"<<endl;
  else cout<<(a>b ? "Alice" : "Bob" )<<endl;
}

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

const int mx = 1e5 + 5;
vector<int> arr(mx,0);

int main(){
    
    int n, k, q;
    cin >> n >> k >> q;
    for(int i = 0; i < q; i++){
        int x;
        cin >> x;
        arr[x - 1]++; 
    }
    
    for(int i = 0; i < n; i++){
        arr[i] += k;
        arr[i] -= q;
        if(arr[i] > 0) cout << "Yes\n";
        else cout << "No\n";
    }
    
}


Measured memory_bytes: 1024
N, A, B = map(int, input().split())
S = input()
tol = 0
bcnt = 0
ans = []
for c in S:
    if c == 'a':
        if tol < (A+B):
            tol += 1
            ans.append('Yes')
        else:
            ans.append('No')
    elif c == 'b':
        bcnt += 1
        if tol < (A+B) and bcnt <= B:
            tol += 1
            ans.append('Yes')
        else:
            ans.append('No')
    else:
        ans.append('No')
        continue
for s in ans:
    print(s)

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

using namespace std;

const int N = 100010;

int a[N];
char s[110];

int check(char ch)
{
	if(ch == 'V')exit(0);
	if(ch == 'M')return 0;
	return 1;
}

void work(int l, int r)
{
	int mid = (l + r) >> 1;
	cout << mid << endl;
	fflush(stdout);
	scanf("%s", s);
	a[mid] = check(s[0]);
	int l1 = (mid - l + 1), l2 = (r - mid + 1);
	if((l1 % 2 == 0 && a[mid] == a[l]) || (l1 % 2 == 1 && a[mid] != a[l]))work(l, mid);
	else work(mid, r);
}

int main()
{
	int n;
	scanf("%d", &n);
	cout << 0 << endl;
	fflush(stdout);
	scanf("%s", s);
	a[0] = check(s[0]);
	cout << n - 1 << endl;
	fflush(stdout);
	scanf("%s", s);
	a[n - 1] = check(s[0]);
	work(0, n - 1);
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
const int maxn=1e5+10;
int a[maxn];
signed main(){
    int n,m;
    scanf("%lld%lld",&n,&m);
    int lcm=1;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        if(lcm>m){
            continue;
        }
        lcm=lcm*a[i]/2/__gcd(lcm,a[i]/2);
    }
    //printf("debug %lld\n",lcm);
    int flag=0;
    for(int i=1;i<=n;i++){
        int temp=lcm*2/a[i];
        if(temp%2==0){
            flag=1;
            break;
        }
    }
    if(flag){
        puts("0");
        return 0;
    }
    int cnt=m/lcm;
    if(cnt&1){
        cnt=cnt/2+1;
    }
    else{
        cnt=cnt/2;
    }
    printf("%lld\n",cnt);
    return 0;
}

Measured memory_bytes: 4528
#include <iostream>
#include<vector>
#include<bitset>
using namespace std;

int D;
long long G;
vector<long long> p,c;

int main(){
    cin >> D >> G;
    p.resize(D);c.resize(D);
    for(int i=0;i<D;++i) cin >> p[i] >>c[i];
    long long res=1<<29;
    //100000000000000000000000000000がresには入っている
    for(int bit=0;bit<(1<<D);bit++){
        long long sum=0;
        long long num=0;
        for(int i=0;i<D;i++){
            if(bit & (1<<i)){
                sum+=c[i]+p[i]*100*(i+1);
                num+=p[i];
            }
        }
        //1<<Dの意味は000…01をDビットだけ右シフト
        //bitのループを回す回数は状態数2**Dとなる！
        //bit&(1<<i)で右端からその状態が1か0か判別している
        //ループが一回終わるごとにbit++だが、これは普通にintでしていると考える
        if(sum>=G) res=min(res,num);
        else{
            for(int i=D-1;i>=0;i--){
                if(bit & (1<<i)) continue;
                for(int j=0;j<p[i];j++){
                    if(sum>=G) break;
                    sum +=100*(i+1);
                    ++num;
                }
                //この状態のみでGを満たしていないのなら、上から加算していく
            }
            res=min(res,num);
            //これまでのnumの最小値になるように確かめる
        }
    }
    cout << res;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N;
vector<int> s;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N){
    cin >> a[i];
    a[i]--;
  }
  int cnt =0, pre=0;
  bool flag = false;
  do{
    if(pre == 1){
      flag = true;
      break;
    }
    pre = a[pre];
    cnt++;
  }while(cnt < N + 10);

  if(flag){
    cout << cnt << endl;
  }
  else{
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
const ll MAX = 202020;
ll fac[MAX], finv[MAX], inv[MAX];
void cinit() { // O(nlogn)
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    reps(i, 2, MAX){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll c(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;
}

//--MAIN-----------------------------------
void Main() {
    cinit();
    ll N,K; cin>>N>>K;
    vector<ll> A(K);
    rep(i,K) cin>>A[i];
    ll dp[K+1][N+1]={}; //i日目まででj個の黒が取られている。
    dp[0][0]=1;
    rep(i,K){
        rep(j,N+1){
            rep(k,N+1-j){ //k個の黒をとる。
                ll ans=c(N-j,k)*c(N-k,A[i]-k);
                ans%=MOD;
                dp[i+1][j+k]+=dp[i][j]*ans;
                dp[i+1][j+k]%=MOD;
            }
        }
    }
    cout<< dp[K][N]<<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 5120
#include <stdio.h>
#include <stdlib.h>
struct card{
  char handle;
  int num;
};
void quicksort(struct card *,int,int);
int partition(struct card *,int,int);
void merge(struct card *,int,int,int);
void mergesort(struct card *,int,int);
int main(){
  int n,i;
  char dummy[10];
  struct card A[100000],c[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",dummy,&A[i].num);
    A[i].handle=dummy[0];
    c[i]=A[i];
  }
  mergesort(A,0,n);
  quicksort(c,0,n-1);
  int cnt=0;
  for(i=0;i<n;i++){
    if(A[i].handle!=c[i].handle){
      printf("Not stable\n");
      cnt++;
      break;
    }
  }
  if(cnt==0)printf("Stable\n");
  for(i=0;i<n;i++){
      printf("%c %d\n",c[i].handle,c[i].num);
  }
  return 0;
}
void quicksort(struct card *A,int p,int r){
  int q;
  if(p<r){
    q=partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }
}
int partition(struct card *A,int p,int r){
  int i,cnt=p-1,q;
  q=A[r].num;
  struct card j;
  for(i=p;i<r;i++){
    if(A[i].num<=q){
      cnt++;
      j=A[i];
      A[i]=A[cnt];
      A[cnt]=j;
    }
  }
  j=A[cnt+1];
  A[cnt+1]=A[r];
  A[r]=j;
  return cnt+1;
}
void mergesort(struct card *c,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(c,left,mid);
    mergesort(c,mid,right);
    merge(c,left,mid,right);
  }
}
void merge(struct card *c,int left,int mid,int right){
  int n1=mid-left,n2=right-mid;
  struct card *L,*R;
  L=malloc(sizeof(struct card)*(n1+2));
  R=malloc(sizeof(struct card)*(n2+2));
  int i;
  for(i=0;i<n1;i++)L[i]=c[i+left];
  for(i=0;i<n2;i++)R[i]=c[i+mid];
  L[n1].num=R[n2].num=2000000000;
  int j=0,k;
  i=0;
  for(k=left;k<right;k++){
    if(L[i].num<=R[j].num)c[k]=L[i++];
    else c[k]=R[j++];
  }
  free(L);
  free(R);
}





Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int a[105],n,k,d,b,i;
	cin>>n>>k;
	memset(a,0,sizeof(a));
	while(k--)
	{
		cin>>d;
		for(i=1;i<=d;i++)
		{
			cin>>b;
			a[b]++;
		}
	}
	int ans=0;
	for(i=1;i<=n;i++)
	if(a[i]==0)ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define swap(a,b) a^=b^=a^=b //二変数を入れ替え//
#define inf 1000000007

void sort(int x[], int left, int right);
int main(void);

//小さい順にソート//
void sort(int x[], int left, int right) {
	int temp[inf], smid, si, sj, sk;
	if (left >= right) return;
	if (left == right - 1) {
		if (x[left] > x[right]) {
			swap (x[left], x[right]);
		}
	return;
	}
	smid = (left + right) / 2;
	sort(x, left, smid);
	sort(x, smid+1, right);
	for (si = left; si <= smid; si++) temp[si] = x[si];
	for (si = smid+1 ; si <= right; si++) temp[si] = x[smid + right + 1 - si];
	si = left;
	sj = right;
	for (sk = left; sk <= right; sk++) {
		if (temp[si] <= temp[sj]) {
			x[sk] = temp[si];
			si=si+1;
		} else {
			x[sk] = temp[sj];
			sj=sj-1;
		}
	}
}

int main(void) {
	// your code goes here
  int x,a,b;
  scanf("%d",&x);
  scanf("%d",&a);
  scanf("%d",&b);
  x=x-a;
  x=x%b;
  printf("%d\n",x);
	return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PI;
using namespace std;
#define MAX  999999
int main(){
    int c,d;
    while(cin>>c >> d,c+d){
        double ans = INF;
        for(int i = 0; i<=c;i++)
            for(int j = 0; j<=c;j++){
                if(i+j == c){
                    double temp = abs(sqrt((int)(i*i+j*j))-d);
                    ans =min(ans,temp);
                }
            }
        printf("%lf\n",ans);
        
    }
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


signed main(){
int a,p;cin>>a>>p;
p += a*3;
int ans = p/2;  
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())

a = [0] * N

for i in range(1,N+1):
    if i%3 == 0 and i%5 == 0:
        pass
    elif i%3 == 0:
        pass
    elif i%5 == 0:
        pass
    else:
        a[i-1] = i

print(sum(a))

Measured memory_bytes: 33616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>

using namespace std;

void solve(string a, string b, string c) {
    if (a.back() == b.front()) {
        if (b.back() == c.front()) {
            std::cout << "YES" << std::endl;
        } else {
            std::cout << "NO" << std::endl;
        }
    } else {
        std::cout << "NO" << std::endl;
    }
}

int main() {
    struct timeval start,end;
    long long span;
    string a,b,c;
    gettimeofday(&start,NULL);
    std::cin >> a >> b >> c;
    solve(a, b, c);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  priority_queue<P, vector<P>, greater<P>> q;
  rep(i,0,n) {
    ll a; int b;
    cin >> a >> b;
    q.push(P(a,b));
  }
  ll ans = 0;
  while(m > 0) {
    P p = q.top(); q.pop();
    ans += p.first * min(m,p.second);
    m -= p.second;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5268
#include<cstdio>
#include<algorithm>
char s[200001];
int main(){
    int n,a,b,c,d;
    scanf("%d%d%d%d%d%s",&n,&a,&b,&c,&d,s);
    a--;
    b--;
    c--;
    d--;
    for(int i=a;i<c;i++){
        if(s[i]=='#'&&s[i+1]=='#'){
            printf("No\n");
            return 0;
        }
    }
    for(int i=b;i<d;i++){
        if(s[i]=='#'&&s[i+1]=='#'){
            printf("No\n");
            return 0;
        }
    }
    if(c<d){
        printf("Yes\n");
        return 0;
    }
    for(int i=b;i<=d&&i+1<n&&i-1>=0;i++){
        if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(solve(s) ? "Yes" : "No");
    }
    static bool solve(int[] s) {
        return Math.Abs(s[2]-s[0]) <= s[3] || (Math.Abs(s[1]-s[0]) <= s[3] && Math.Abs(s[2]-s[1]) <= s[3]);
    }
}

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

int a[200005];
int pref[200005];
long long qs[200005];
int opt[200005];

int main(){
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &a[i]), qs[i] = qs[i-1]+a[i];
    opt[1] = 1;
    for(int i=2; i<=n-2; i++){
        opt[i] = opt[i-1];
        while(abs(qs[i]-2*qs[opt[i]+1]) < abs(qs[i]-2*qs[opt[i]])) opt[i]++;
    }
    int last = n;
    long long res = 1e18;
    for(int i=n-1; i>=3; i--){
        while(abs(qs[n]-qs[last-2]-qs[last-2]+qs[i-1]) < abs(qs[n]-qs[last-1]-qs[last-1]+qs[i-1])) last--;
        long long C = qs[opt[i-1]];
        long long D = qs[i-1]-qs[opt[i-1]];
        long long E = qs[last-1]-qs[i-1];
        long long F = qs[n]-qs[last-1];
        res = min(res, max(max(C, D), max(E, F))-min(min(C, D), min(E, F)));
    }
    printf("%lld", res);
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
inline int read()
{
    int x=0,t=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-') t=-1,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return x*t;
}
int n;
int a[25],b[25],c[25];
int sum;
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();
	for(int i=1;i<=n;i++)
	{
		sum+=b[a[i]];
		if(a[i]-1==a[i-1]&&a[i-1]!=0)
			sum+=c[a[i-1]];
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> data(1010, vector<int>(1010,0));  //reset 0 
int N;
vector<queue<int>> q(2, queue<int>());  //reset 0 
vector<int> t(1010,0), p(1010,0);

int main(){
  cin >> N;
  for(int i=1; i<N+1; i++)for(int j=1; j<N; j++){ cin >> data.at(i).at(j); } //map road
  for(int i=1; i<N+1; i++){q.at(0).push(i);}
  int now=1, nex=0;
  
  for(int day=1,game=N*(N-1)/2; day<=N*(N-1)/2; day++){
    swap(now,nex);
    while(!q.at(now).empty()){			// loop until 0 
      int x = q.at(now).front();
      q.at(now).pop();
      t.at(x)++;						// tsugi ha t.at(x)++ siaime
      int y = data.at(x).at(t.at(x)); // vs  cout << x << ":" << t.at(x) << ":" << y << endl;
      if(p.at(y) == x){					// siai seiritsu
        game--;
        q.at(nex).push(x);
        q.at(nex).push(y);
        p.at(y) = p.at(x) = 0;
      } else {
        p.at(x) = y;
      }
    }
    if(!game){ cout << day << endl; return 0;}
  }
  cout<<-1<<endl;
  return 0;  
}
 

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

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    if (c % i == 0) {
      ans++;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define maxn 100005
#define maxm 205
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}

int n, m, a[55], A, sum;
ll f[55][55][2505], ans;
int main(){
	int i, j, k;
	n = read(), A = read();
	for(i = 1;i <= n;i++) a[i] = read(), sum += a[i];
	f[0][0][0] = 1;
	for(i = 1;i <= n;i++){
		for(j = 0;j <= i;j++){
			for(k = 0; k <= sum;k++){
				if(i > j) f[i][j][k] = f[i - 1][j][k];
				if(k >= a[i] && j) f[i][j][k] += f[i - 1][j - 1][k - a[i]];
			}
		}
	}
	for(i = 1;i <= n;i++) ans += f[n][i][i * A];
	cout<<ans; 
	return 0;
}


Measured memory_bytes: 29712
#include <iostream>
#include <cmath>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;
typedef long long ll;

struct Point { double x, y, z; };
struct Line { Point p, q; };

int N, Q;
ll R[50], L[50];
Point P[50];
Line C[50];

double distance(Line l, Point p) {
  double x0 = p.x, y0 = p.y, z0 = p.z;
  double x1 = l.p.x, y1 = l.p.y, z1 = l.p.z;
  double x2 = l.q.x, y2 = l.q.y, z2 = l.q.z;
  double a = x2 - x1;
  double b = y2 - y1;
  double c = z2 - z1;
  double a2 = a * a;
  double b2 = b * b;
  double c2 = c * c;
  double r2 = a2 + b2 + c2;
  double t2 = -(a * (x1 - x0) + b * (y1 - y0) + c * (z1 - z0));
  if(t2 < 0) return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) + (z1 - z0) * (z1 - z0));
  if(t2 > r2) return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0) + (z2 - z0) * (z2 - z0));
  double fx = b * (z1 - z0) - c * (y1 - y0);
  double fy = c * (x1 - x0) - a * (z1 - z0);
  double fz = a * (y1 - y0) - b * (x1 - x0);
  double f2 = fx * fx + fy * fy + fz * fz;
  return sqrt(f2 / r2);
}

int main(void) {
  cin >> N >> Q;
  REP(i, 0, N) cin >> P[i].x >> P[i].y >> P[i].z >> R[i] >> L[i];
  REP(i, 0, Q) cin >> C[i].p.x >> C[i].p.y >> C[i].p.z >> C[i].q.x >> C[i].q.y >> C[i].q.z;

  REP(i, 0, Q) {
    ll ans = 0;
    REP(j, 0, N) if(distance(C[i], P[j]) <= R[j]) ans += L[j];
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAXN 10005
#define MAXM 1000005
int n,m;
struct Edge
{
	int id;
	double val;
	Edge *nxt;
	Edge(){nxt=NULL;}
	Edge(int i,double v){id=i;val=v;nxt=NULL;}
}E[MAXM],*V[MAXN],*cur;
void add_edge(int x,int y,double val)
{
	*cur=Edge(y,val);
	cur->nxt=V[x];
	V[x]=cur++;
	*cur=Edge(x,val);
	cur->nxt=V[y];
	V[y]=cur++;
}
struct cmp
{
	bool operator () (Edge *a,Edge *b)
	{return a->val<b->val;}
};
bool used[MAXN];
double Prim(int s)
{
	double ans=0;
	priority_queue<Edge*,vector<Edge*>,cmp>Q;
	used[s]=1;
	for(Edge *p=V[s];p;p=p->nxt)
		if(!used[p->id])
			Q.push(p);
	while(!Q.empty())
	{
		Edge *t=Q.top();
		Q.pop();
		if(used[t->id])
			continue;
		ans+=t->val;
		used[t->id]=1;
		for(Edge *p=V[t->id];p;p=p->nxt)
			if(!used[p->id])
				Q.push(p);
	}
	return ans;
}
pair<int,int>pile[MAXN];
double dis(int a,int b)
{
	return sqrt((pile[a].first-pile[b].first)*(pile[a].first-pile[b].first)+
	(pile[a].second-pile[b].second)*(pile[a].second-pile[b].second));
}
int main()
{
	int N,M;
	scanf("%d%d",&N,&M);
	for(int i=1;i<=N;i++)
		scanf("%d%d",&pile[i].first,&pile[i].second);
	cur=E;
	double sum=0;
	for(int j=1,p,q;j<=M;j++)
	{
		scanf("%d%d",&p,&q);
		double tmp=dis(p,q);
		add_edge(p,q,tmp);
		sum+=tmp;
	}
	for(int i=1;i<=N;i++)
		if(!used[i])
			sum-=Prim(i);
	printf("%.3lf\n",sum);
	return 0;
}

Measured memory_bytes: 26476
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        double ans = 0;
        double x;
        String u;
        for(int i = 0; i < n; i++){
            x = Double.parseDouble(sc.next());
            u = sc.next();
            if(u.equals("JPY")){
                ans += x;
            }else{
                ans += x * 380000;
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''


n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
ans=0
from math import floor
for i in range(1,n):
    ans+=a[n-1-floor(i/2)]
    #print(ans)
print(ans)


Measured memory_bytes: 31448
class Map < Array
  Next = [[1, 0], [-1, 0], [0, 1], [0, -1]]
  def flood_fil(y, x, p)
    h = self.size
    w = self.first.size
    return unless y.between?(0, h - 1)
    return unless x.between?(0, w - 1)
    target = self[y][x]
    self[y][x] = p
    Next.each do |dy, dx|
      ny = y + dy
      nx = x + dx
      next unless ny.between?(0, h - 1)
      next unless nx.between?(0, w - 1)
      next unless self[ny][nx] == target
      p.copy(p.merge(Piece.new(nx + 0.5)))
      flood_fil(ny, nx, p)
    end
    self
  end
end

class Piece
  attr_reader :x, :weight, :lx, :rx, :upon
  def initialize(x, w = 1.0, l = nil, r = nil, u = Array.new)
    @x = x.to_f
    @weight = w.to_f
    @lx = l
    @rx = r
    @upon = u
  end
  def copy(p)
    @x, @weight, @lx, @rx, @upon = p.x, p.weight, p.lx, p.rx, p.upon
  end
  def ends(l, r)
    @lx = l unless @lx
    @rx = r unless @rx
    @lx = [@lx, l].min
    @rx = [@rx, r].max
  end
  def pile(p)
    @upon << p unless @upon.include?(p)
  end
  def merge(p)
    x = (@x * @weight + p.x * p.weight) / (@weight + p.weight)
    w = @weight + p.weight
    l = @lx
    r = @rx
    u = p.upon.dup
    Piece.new(x, w, l, r, u)
  end
  def above
    result = self.dup
    @upon.each do |u|
      result.copy(result.merge(u.above))
    end
    result
  end
  def stable?
    x = above.x
    @lx < x && x < @rx
  end
end

until (w, h = gets.split.map(&:to_i)).all?(&:zero?)
  map = Map.new
  h.times do
    map.push(Map.new.push(*gets.chomp.chars))
  end

  piece = Array.new
  h.times do |i|
    w.times do |j|
      next unless map[i][j] =~ /[0-9]/
      piece << Piece.new(j + 0.5)
      map.flood_fil(i, j, piece.last)
    end
  end
  map.push(Map.new(w, Piece.new(0, 0, 0, 0, [])))           # 番兵
  h.times do |i|
    w.times do |j|
      next unless map[i][j].kind_of?(Piece)
      next unless map[i + 1][j].kind_of?(Piece)
      next if map[i][j] == map[i + 1][j]
      map[i][j].ends(j, j + 1)
      map[i + 1][j].pile(map[i][j])
    end
  end

  puts piece.all?(&:stable?) ? "STABLE" : "UNSTABLE"
end

Measured memory_bytes: 6172
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM = 1000000007;

int main()
{
    // 整数の入力

    ll N;
    cin >>  N;
    set<string> sss;
    for(int i = 0;i < N;i++){
        string s;
        cin >> s;
        sss.insert(s);
    }
    cout << sss.size() << endl;
  return 0;
}

Measured memory_bytes: 19256
package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)
 
func run() {
	n := nextInt()

	h := make([]int, 0)
	d := make([]int, 0)

	for i := 0; i < n; i++ {
		d = append(d, 0)
	}
	
	h = readIntArray(n)

	for i, v := range h {
		d[v-1] = i+1
	}
	for _, v := range d {
		Print(strconv.Itoa(v) + " ")
	}

}

// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 
func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 

func readIntArray(n int) ([]int) {
	v := make([]int, 0)
	for i := 0; i < n; i++ {
		v = append(v, nextInt())
	}
	return v
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		log.Fatal(err)
	}
	return a
}
 
func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}

 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}


Measured memory_bytes: 16128
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

n, s = list(map(int, sys.stdin.readline().strip().split()))
a = [0 for x in range(n)]
a = list(map(int, sys.stdin.readline().strip().split()))

mod = 998244353

d = array2(n+1, s+1)
d[0][0] = 1

for i in range(n):
    #print(d)
    for j in range(s+1):
        d[i+1][j] += d[i][j] * 2
        d[i+1][j] %= mod
        if j + a[i] <= s:
            d[i+1][j+a[i]] += d[i][j]
            d[i+1][j+a[i]] %= mod

#print(d)
print(d[n][s])


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

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
    reverse(all(a));
    ll ans=a[0];
    int cnt=0,id=1;
    rep(i,n-2){
        if(cnt==0){
            cnt++;
            ans+=a[id];
        }
        else{
            ans+=a[id];
            cnt=0;
            id++;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4704
#include <iostream>
#include <vector>
#include <algorithm>

int main(int argc, char **argv)
{
    int N;
    std::cin >> N;

    std::vector<int> a(N);
    for(int i = 0; i < N; i++){
        std::cin >> a.at(i);
    }

    std::sort(a.begin(), a.end(), std::greater<int>());

    int alice = 0, bob = 0;
    int alice_turn = true;
    for(int i = 0; i < N; i++){
        if(alice_turn){
            alice += a.at(i);
        }else{
            bob += a.at(i);
        }
        alice_turn = !alice_turn;
    }

    std::cout << (alice - bob) << std::endl;
    
}


Measured memory_bytes: 256
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    S = [""] * N
    for i in range(N):
        S[i] = input().rstrip()

    c = Counter(S)
    ans = []
    max_v = max(c.values())
    for k, v in c.items():
        if v == max_v:
            ans.append(k)

    ans.sort()
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 35936
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    string s,t;
    cin>>s>>t;
    int c=0;
    for(int i=0;s[i];i++)
    {
        if(s[i]!=t[i])
            c++;
    }
    cout<<c<<endl;
}









































Measured memory_bytes: 3812
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    aa = [LI() for _ in range(n)]
    r = [0,0,0]
    for a in aa:
        r = [a[i] + max(r[i-1], r[i-2]) for i in range(3)]

    return max(r)


print(main())


Measured memory_bytes: 26696
<?php

fscanf(STDIN,"%d",$a);
fscanf(STDIN,"%d",$b);
fscanf(STDIN,"%d",$c);
fscanf(STDIN,"%d",$x);

$total = 0;
$count = 0;

for ($ai = 0; $ai <= $a; $ai++){
    for ($bi = 0; $bi <= $b; $bi++){
        for ($ci = 0; $ci <= $c; $ci++){
            $total = (500 * $ai) + (100 * $bi) + (50 * $ci);
            if ($x == $total){
                $count++;
            }
        }
    }
}

echo $count;

Measured memory_bytes: 4604
import heapq
n, M = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(M):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [[b, 1]]
  graph[b] += [[a, 1]]

def dijkstra(s):
  dist = [float('inf')]*n
  dist[s] = 0
  num = [0]*n
  num[s] = 1
  q = [[0, s]]
  pre = [0]*n
  heapq.heapify(q)
  while q:
    c, u = heapq.heappop(q)
    if dist[u] < c:
      continue
    for v, weight in graph[u]:
      if dist[v] > dist[u] + weight:
        dist[v] = dist[u] + weight
        num[v] = num[u]
        heapq.heappush(q, [dist[v], v])
        pre[v] = u
      elif dist[v] == dist[u] + weight:
        num[v] += num[u]
  return dist, num, pre

dist, num, pre = dijkstra(0)
print('Yes')
for i in pre[1:]:
  print(i+1)


Measured memory_bytes: 128836