akhauriyash/Code-Regression huggingface dataset:
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===

def disLR(a, idx):
    small = a[max(0, idx - 1)]
    large = a[min(len(a) - 1, idx)]
    return [small, large]


def main():
    a, b, q = ns()
    s = [ni() for _ in range(a)]
    t = [ni() for _ in range(b)]

    for _ in range(q):
        ans = INF

        x = ni()

        idxs = bisect.bisect_left(s, x)
        a1 = disLR(s, idxs)

        idxt = bisect.bisect_left(t, x)
        a2 = disLR(t, idxt)

        for ta1 in a1:
            for ta2 in a2:
                tmp1 = abs(x - ta1) + abs(ta2 - ta1)
                tmp2 = abs(x - ta2) + abs(ta1 - ta2)
                ans = min(ans, tmp1, tmp2)

        print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
	int n;
	cin >> n;
	int *a = new int[n];

	for (int x = 0; x < n; x++) cin >> a[x];

	for (int i = 0; i < n; i++) {
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j]>v) {
			a[j + 1] = a[j];
			j--;
			a[j + 1] = v;
		}
		for (int y = 0; y < n; y++) {
			cout << a[y];
			if (y != n - 1) cout << " ";
		}
		cout << "\n";
	}
	delete[] a;
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(all(a));
  cout<< a[(n/2)] - a[(n/2)-1]  <<endl;
}



Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
	int i,n;
	double m,sum;
	int s[1000];
	while(1) {
		memset(s,0,sizeof(s));
		scanf("%d",&n);
		if (n==0)break;
		sum=0;
		for (i=0;i<n;i++) scanf("%d",&s[i]),sum+=s[i];
		m=sum/n;
		sum=0;
		for (i=0;i<n;i++) sum+=pow((s[i]-m),2);
		printf("%lf\n",sqrt(sum/n));
	}
	return 0;
}

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

int main(){
    int h,n,sum=0;
    //int i=0;
    bool flag=0;
    cin >>h >>n;
     int a[n]={};
    for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<n; i++) sum+=a[i];
    //all=all*2;//2度の攻撃まで可能なため
   // cout <<2*sum;

    if(h>sum)flag=1; //全ての攻撃で倒せない

/*while(true){
  if((cnt*2)==all)break;
  for(; i<n*2; i++){
  h-=a[i];
  cnt++;
}
*/
if(flag==1)cout <<"No" <<endl;
else cout <<"Yes" <<endl;
//cout <<cnt <<endl;
return 0;
}

Measured memory_bytes: 640
// 2016-12-12
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int q, n;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> n;
		int c = 0;
		while (n >= 10) {
			int m = 0;
			for (int j = 10; j <= n; j *= 10) {
				m = max(m, (n / j) * (n % j));
			}
			n = m;
			c++;
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
s = input()
k = int(input())

def ones(s):
    ss = s[0]
    idx = 0
    while ss=="1" and idx+1 < len(s):
        idx += 1
        ss = s[idx]
    return idx

if s[0]!="1":
    print(s[0])
else:
    idx = ones(s)
    if idx>=k:
        print("1")
    else:
        print(s[idx])


Measured memory_bytes: 3060
import numpy as np

import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i - 1)
T = 2*max(t)
# for i in range(N):
#     table[2*s[i]-1: 2*t[i]] += 1
table = np.zeros(T)
for i in range(C):
    table_i = np.zeros(T)
    for j in range(N):
        if c[j] == i:
            table_i[2*s[j]-1: 2*t[j]] = 1
    table += table_i
print(int(np.max(table)))


Measured memory_bytes: 25656
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<math.h>
#include<map>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

double ans=0;
int N,W;

int main(){
    cin>>N>>W;
    double v[N],w[N],dp[W][N];
    vector<pair<double,double> > co(N);
    rep(i,N){
        cin>>v[i]>>w[i];
        co[i]=make_pair(v[i]/w[i],w[i]);
    }
    sort(co.begin(),co.end());
        for(int i=N-1;i>=0;i--){
            if(W>=co[i].second){
                ans+=co[i].first*co[i].second;
                W-=co[i].second;
            }
            else{
                ans+=co[i].first*W;
                W=0;
                break;
            }
            // out(W);
            // out(ans);
        }
    printf("%.10f\n",ans);
    
}



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

int main() {
	int x, y, z, K;
	cin >> x >> y >> z >> K;
	vector<ll> a(x), b(y), c(z);
	rep(i, x) cin >> a[i]; sort(a.begin(), a.end(), greater<ll>());
	rep(i, y) cin >> b[i]; sort(b.begin(), b.end(), greater<ll>());
	rep(i, z) cin >> c[i]; sort(c.begin(), c.end(), greater<ll>());
	vector<ll> abc;
	rep(i, x)rep(j, y)rep(k, z) {
		if ((i+1)*(j+1)*(k+1) <= K) abc.push_back(a[i]+b[j]+c[k]);
		else break;
	}
	sort(abc.begin(), abc.end(), greater<ll>());
	rep(i, K) cout << abc[i] << endl;
	return 0;
}


Measured memory_bytes: 1404
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int c=0;
		for(int i=1;i<=n;i++) {
			String s=String.valueOf(i);
			if(s.length()%2==1) {
				c++;
			}
		}System.out.println(c);
		
	}

}

Measured memory_bytes: 27732
#include<stdio.h>
int main(void){
int H, N, A[100010], sum=0;
scanf("%d%d", &H , &N);
for(int i=0;i<N;i++){
    scanf("%d", &A[i]);
    sum+=A[i];
}
if(sum>=H){
printf("Yes\n");
}else{
printf("No\n");
}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n , m; cin>>n>>m;
    for(int i = 0 ; i <= 100; ++i){
        for(int j = 0 ; j <= 100; ++j){
            if(i * 4 + j * 2 == m && i + j == n){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll maxi=1e5+5;
const int mod=1e9+7;
ll fac[maxi],inv[maxi],finv[maxi];
void cominit(){
  fac[0]=fac[1]=finv[0]=inv[1]=finv[1]=1;
  for(int i=2;i<maxi;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;
  }
}
ll com(int n,int k){
  if(n<k||n<0||k<0)return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  ll l,r;
  map<int,int> mp;
  rep(i,n+1){
      int j;cin>>j;
      if(mp.find(j)!=mp.end()) l=mp[j],r=i+1;
      else mp[j]=i+1;
  }
  cominit();
  for(int i=1;i<=n+1;i++){
      int ans=(com(n+1,i)-com(n-r+l,i-1)+mod)%mod;
      cout<<ans<<endl;
  }
  return 0;
  }


Measured memory_bytes: 8320
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector <string> visited;
vector<int> num;

int main(){
  int N,M;
  string s;

  cin >> N;



  cin >> s;
  visited.push_back(s);
  num.push_back(1);
  for (int i = 0;i < N-1; i ++){
    int flag = 0;
    cin >> s;
    for (int j = 0; j < (int)visited.size(); j++){
      if (s == visited[j]){
        num[j]++;
        flag = 1;
      }
    }
      if(flag == 0){
        visited.push_back(s);
        num.push_back(1);
      }
    }

  cin >> M;
  for (int i = 0; i < M ; i++){
    cin >>s;
    for (int j = 0; j < (int)visited.size(); j++){
      if (s == visited[j]){
        num[j]--;
      }
    }
  }
  int ma = 0;
  for (int i = 0; i <(int)num.size();i++){
    ma = max(ma,num[i]);
  }
  cout << ma << endl;
  return 0;
}


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

int main()
{
    int n,m,ans=0;cin>>n>>m;
    rep(i,1,sqrt(m)+2){
        if(m%i) continue;
        if(m/i>=n) ans=max(ans,i);
        if(i>=n) ans=max(ans,m/i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int x, y, z;
  cin >> x >> y >> z;
  cout << (abs(x-y) < abs(x-z) ? "A" : "B") << endl;
  return 0;
}


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int a,b,c;

int32_t main()
{
    IOS
    cin>>a>>b>>c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if (sz(s)==2)  cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
using System;

class Program
{
   static void Main(string[] args)
   {
      string input = Console.ReadLine();
      int cnt = 0; 
      
      if (input[0] == '1') cnt++;
      if (input[1] == '1') cnt++;
      if (input[2] == '1') cnt++;

      Console.WriteLine(cnt);
   }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
    string s,t;
    cin>>s>>t;
    ll n=s.length(),c=0;
    for(int i=0;i<n;i++)
    {
      if(s[i]!=t[i])
        c++;
    }
    cout<<c<<endl;
}
return 0;
}

Measured memory_bytes: 3888
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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 const INF = 1001001001;


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

int N,K; cin >> N >> K;

int R = (N-1) * (N-2) / 2 - K;
if(R < 0) {
    cout << -1 << endl;
    return 0;
}

int M = N - 1 + R;
cout << M << endl;
for(int i = 2; i <= N; ++i) {
    cout << 1 << ' ' << i << endl;
}

for(int i = 2; i <= N; ++i) {
    for(int j = i+1; j <= N; ++j) {
        if(R == 0) return 0;
        cout << i << ' ' << j << endl;
        R--;
    }
}

return 0;
}

Measured memory_bytes: 256
s = input()
ss = ""
for i in range(len(s)):
    if s[i] not in ["A", "T", "G", "C"]:
        ss += " "
    else:
        ss += s[i]
l = ss.split()
# print(l)
m = 0
for ll in l:
    if (len(ll)) > m:
        m = len(ll)
print(m)


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

int N;
vector<int> G[100000];
vector<int> v(100000, 0);

void bfs() {
    queue<int> S;
    queue<int> F;
    F.push(0);
    S.push(N - 1);
    v[0] = 1;
    v[N - 1] = 2;
    bool check = true;
    while (check) {
        check = false;
        queue<int> S_next;
        queue<int> F_next;
        while (!F.empty()) {
            int k = F.front();
            F.pop();
            for (int i = 0; i < G[k].size(); i++) {
                if (v[G[k][i]] == 0) {
                    v[G[k][i]] = 1;
                    F_next.push(G[k][i]);
                    check = true;
                }
            }
        }
        F = F_next;
        while (!S.empty()) {
            int k = S.front();
            S.pop();
            for (int i = 0; i < G[k].size(); i++) {
                if (v[G[k][i]] == 0) {
                    v[G[k][i]] = 2;
                    S_next.push(G[k][i]);
                    check = true;
                }
            }
        }
        S = S_next;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    bfs();
    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < N; i++) {
        if (v[i] == 1) cnt1++;
        if (v[i] == 2) cnt2++;
    }
    cout << (cnt1 > cnt2 ? "Fennec" : "Snuke") << endl;
}

Measured memory_bytes: 6368
#include<iostream>
#include<cstring>
//#include<bits/stdc++.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#define  si(a)       scanf("%d",&a)
#define  sl(a)       scanf("%lld",&a)
#define  sii(a,b)    scanf("%d%d",&a,&b)
#define  sll(a,b)    scanf("%lld%lld",&a,&b)
#define  queues      priority_queue
#define mod  10000007
#define mem(a)  memset(a,0,sizeof(a));
#define def(a) ((a)&(-a))
#define fi  first
#define se  second
#define mp  make_pair
#define  pb push_back
#define mem(a,b) memset(a,b,sizeof(a));
typedef long long ll;
const ll maxn=5000006;
//priority_queue<ll,vector<ll >,greater<ll > >q;
const ll INF=0x3f3f3f3f;
//const double E=exp(1);
//const double PI=acos(-1);
using namespace std;
//__builtin_popcount
//priority_queue

int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
ll kc(ll a,ll b){ll c=1;while(b){if(b&1)c=(c*a)%mod;a=(a*a)%mod;b>>=1;}return c;}
bool cmp(double x,double y){return x>y;}
int read(){int x=0,f=1;char s=getchar();for(; s>'9'||s<'0'; s=getchar()) if(s=='-') f=-1;for(; s>='0'&&s<='9'; s=getchar()) x=x*10+s-'0';return x*f;}
int a[maxn],c[maxn];
int main()
{
     ios::sync_with_stdio(false);
   string s;
   cin>>s;
   int b=s.size();
   int R,L,Rid,Lid;Rid=Lid=0;R=L=0;
   for(int i=0;i<b;i++)
   {
       if(s[i]=='R'){if(Lid)c[Lid]=L,Lid=0,L=0;R++;}
       else {
        c[i]=R;
        R=0;
        L++;
        if(Lid==0)Lid=i+1;
       }
   }
    c[Lid]=L;

   for(int i=1;i<=b;i++)
     if(c[i])
   {
       if(c[i]>c[i+1])
       { int x=c[i+1];
           int z=c[i]-c[i+1];
           if(c[i+1]&1)
           {
               if(z&1)
               {
                   c[i+1]=x+(z+1)/2;
                   c[i]=x+z/2;
               }
               else
               {
                   c[i+1]=x+z/2;
                   c[i]=x+z/2;
               }
           }
           else {
            if(z&1)
            {
                c[i]=x+(z+1)/2;
                c[i+1]=x+z/2;
            }
            else
            {
                 c[i+1]=x+z/2;
                   c[i]=x+z/2;
            }

           }
       }
       else{
        int x=c[i];
         int z=c[i+1]-c[i];
           if(c[i]&1)
           {
               if(z&1)
               {
                   c[i]=x+(z+1)/2;
                   c[i+1]=x+z/2;
               }
               else
               {
                   c[i+1]=x+z/2;
                   c[i]=x+z/2;
               }
           }
           else {
            if(z&1)
            {
                c[i+1]=x+(z+1)/2;
                c[i]=x+z/2;
            }
            else
            {
                 c[i+1]=x+z/2;
                   c[i]=x+z/2;
            }

           }
       }
       i++;
   }
     for(int i=1;i<=b;i++)
    printf(i==b?"%d\n":"%d ",c[i]);
}


Measured memory_bytes: 1104
#include <bits/stdc++.h>
using namespace std;
string s, s1, s2;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> s >> s1;
	if (s + s1[s1.size()-1] == s1) {
		cout << "Yes";
	}
		else
	cout << "No";
}

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

#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define size_t long long
// sort(&a[0], &a[4], [](auto& x, auto& y){return x[0] < y[0];});
//accumulate(&arr2[n], &arr2[m-1], 0);
using namespace std;

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

  ll N,X; std::cin >> N >> X;
  ll cnt = 0;
  for (size_t i = 0; i < N; i++) {
    int temp;
    std::cin >> temp;
    cnt += temp;
    if(cnt > X){
      std::cout << i+1 << '\n';
      return 0;
    }
  }
  std::cout << N+1 << '\n';
  return 0;
}


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

    def prime_factorization_dict(n):
        """nを素因数分解したときの素数とその指数の辞書"""
        from collections import defaultdict
        if n == 1:
            return {2: 0}  # 1は素数の0乗の積とみなす
        i, table = 2, defaultdict(int)
        while i**2 <= n:
            while n % i == 0:
                table[i] += 1
                n //= i
            i += 1
        if n > 1:
            table[n] = 1
        return table

    d = prime_factorization_dict(N)
    ans = 0
    for v in d.values():
        tmp = 1
        total = 0
        count = 0
        while total <= v:
            total += tmp
            tmp += 1
            count += 1
        ans += count - 1
    return ans

print(d_div_game())

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

#define int long long

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

#define len(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    map<int, int> cnt;
    int k;
    cin >> cnt[1] >> cnt[0] >> cnt[-1] >> k;
    int ans = 0;
    vector<int> ord = {1, 0, -1};
    for (auto x : ord) {
        int y = min(cnt[x], k);
        k -= y;
        ans += y * x;
    }
    cout << ans;
    return 0;
}


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

const int MAXN = 210;
int a[MAXN];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; ++i)
        scanf("%d",&a[i]);
    bool flag = true;
    int res = 0;
    while(flag)
    {
        for(int i = 0; i < n; ++i)
        {
            if(a[i]%2 == 0) a[i] /= 2;
            else {flag = false;break;}
        }
        if(flag) ++res;
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
#include <math.h>
#include <bitset>

using namespace std;

#define taskname "A"
#define LL long long 
#define uLL unsigned long long 
#define FOR(i,l,r) for(int i = l; i <= r; ++i)
#define REP(i,l,r) for(int i = l; i < r; ++i)
#define FORD(i,r,l) for(int i = r; i >= l; --i)
#define REPD(i,r,l) for(int i = r; i > l; --i)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define _USE_MATH_DEFINES 
/* M_PI */

const int maxN = 2e5 + 11;
const LL oo = 1e17 + 11;

int tcases = 1;

int N,M,K,C[maxN];
LL A[maxN],res[maxN];

bool cmp(int i,int j){
    return A[i] == A[j] ? i < j : A[i] > A[j];
}
void testcase(){
    scanf("%d",&N);
    FOR(i,1,N){
        scanf("%lli",&A[i]);
        C[i] = i;
    }
    sort(C + 1,C + 1 + N,cmp);
    //
    int first = 1;
    int curpos = C[1];

    while(first <= N){
        int last = first;
        while(last < N && A[C[last + 1]] == A[C[last]]) ++last;
        if(last >= N){
            res[curpos] += A[C[first]] * last;
            break;
        }else res[curpos] += (A[C[first]] - A[C[last + 1]]) * last;
        //
        first = last + 1;
        curpos = min(curpos,C[first]);
    }
    FOR(i,1,N) printf("%lli\n",res[i]);
}

int main(){

    //cin >> tcases;

    FOR(i,1,tcases) testcase();

    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;

int main()
{
  int N,D,X;
  int a[110];
  cin >> N >>D>>X;
  rep(i,N) cin>>a[i];

  int res=X;
  rep(i,N) {
    int cnt=0;
    while((a[i]*cnt+1)<=D){
      res++;
      cnt++;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
void exgcd(int, int, int*, int*);
main()
{
        int x, y, a, b;
        scanf("%d %d", &x, &y);
        exgcd(x, y, &a, &b);
        printf("%d %d\n", a, b);
}
void exgcd(int x, int y, int *a, int *b)
{
        int q, r0 = x, r1 = y, r2 ,a0 = 1, a1 = 0, a2, b0 = 0, b1 = 1, b2;
        while(r1 > 0){
                q = r0 / r1;
                r2 = r0 % r1;
                a2 = a0 - q * a1;
                b2 = b0 - q * b1;
                r0 = r1;
                r1 = r2;
                a0 = a1;
                a1 = a2;
                b0 = b1;
                b1 = b2;
        }
        *a = a0;
        *b = b0;
}

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

int main( void )
{
	int a, b, c;
	while ( cin >> a >> b >> c && a > 0 && b > 0 && c > 0 )
	{
		int n;
		cin >> n;

		vector <int> parts( a+b+c+1, 2 );
		vector < vector <int> > PASSED;
		vector < vector <int> > FAILED;

		for ( int lpc = 0; lpc < n; lpc++ )
		{
			vector <int> L(3);
			int r;
			for ( int i = 0; i < 3; i++ )
				cin >> L[i];
			cin >> r;

			if ( r == 0 )
			{
				// Ìá©àµêñ
				FAILED.push_back( L );
			}
			else if ( r == 1 )
			{
				// âÎÀS
				PASSED.push_back( L );
			}
		}

		for ( vector < vector <int> >::iterator it = PASSED.begin(); it != PASSED.end(); it++ )
		{
			vector <int> &test = *it;
			for ( int i = 0; i < 3; i++ )
			{
				parts.at( test[i] ) = 1;
			}
		}

		for ( vector < vector <int> >::iterator it = FAILED.begin(); it != FAILED.end(); it++ )
		{
			vector <int> &test = *it;
			if ( parts.at( test[0] ) == 1 && parts.at( test[1] ) == 1 )
				parts.at( test[2] ) = 0;
			else if ( parts.at( test[1] ) == 1 && parts.at( test[2] ) == 1 )
				parts.at( test[0] ) = 0;
			else if ( parts.at( test[2] ) == 1 && parts.at( test[0] ) == 1 )
				parts.at( test[1] ) = 0;
		}

		for ( int lpc = 1; lpc < a+b+c+1; lpc++ )
		{
			cout << parts[lpc] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<queue>

using namespace std;

static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK =2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra(){
  priority_queue<pair<int, int> >PQ;
  int color[MAX];
  int d[MAX];
  for(int i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }
  d[0]=0;
  PQ.push(make_pair(0,0));
  color[0]=GRAY;
  while(!PQ.empty()){
    pair<int, int>f=PQ.top();PQ.pop();
    int u=f.second;
    color[u]=BLACK;
    if(d[u]<f.first*(-1))continue;
    for(int j=0;j<adj[u].size();j++){
      int v=adj[u][j].first;
      if(color[v]==BLACK)continue;
      if(d[v]>d[u]+adj[u][j].second){
        d[v]=d[u]+adj[u][j].second;
        PQ.push(make_pair(d[v]*(-1),v));
        color[v]=GRAY;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<(d[i]==INFTY ? -1:d[i])<<endl;
  }
}

int main(){
  int k,u,v,c;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      adj[u].push_back(make_pair(v,c));
    }
  }
  dijkstra();
  return 0;
}



Measured memory_bytes: 8044
function Main(input){
  var arr = input.split('\n');
  var c = [];
  c.push(arr[0].split(' ').map(a=>Number(a)));
  c.push(arr[1].split(' ').map(a=>Number(a)));
  c.push(arr[2].split(' ').map(a=>Number(a)));

  if((c[0][1]-c[0][0]==c[1][1]-c[1][0])&&
  (c[0][1]-c[0][0]==c[2][1]-c[2][0])&&
  (c[0][2]-c[0][0]==c[1][2]-c[1][0])&&
  (c[0][2]-c[0][0]==c[2][2]-c[2][0])){
    console.log('Yes');
  }else{
    console.log('No');
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if((a+b) >= c){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {
	
	char s[100001];
	scanf("%s", s);
	for (int i = 0; i < strlen(s); i += 2) {
		printf("%c", s[i]);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){   
   int n,max=0,sum=0;
   cin>>n;
   rep(i,n){
      int a;
      cin>>a;
      sum+=a;
      if(max<a) max=a;

   }
   sum-=max/2;
   cout<<sum;

   return 0;
}


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

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            int rest = s - i - j;
            if (rest <= k && rest >= 0)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define mod 1000000007

long long N, K, X, Y, ans = 0, tans;
int A[1<<20], B[1<<20];

int main() {
   // freopen("input.in","r",stdin);
//    freopen("output.out","w",stdout);
	cin >> N >> K;
	for(int i = 0;i < N;i++) {
		cin >> A[i] >> B[i];
	}

	int dont = 0;
	for(int i = 29;i >= 0;i--) {
		if((1LL<<i) & K) {
			dont |= (1LL << i);
			tans = 0;
			for(int j = 0;j < N;j++) {
				if((dont & A[j]) == 0) {
					tans += B[j];
				}
			}
			ans = max(ans, tans);
			dont ^= (1LL << i);
		} else {
			dont |= (1LL << i);
		}
	}

	tans = 0;
	for(int j = 0;j < N;j++) {
		if((dont & A[j]) == 0) {
			tans += B[j];
		}
	}
	ans = max(ans, tans);

	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  int N; cin >> N;
  int A[N]; rep(i,N) cin >> A[i];
  sort(A, A+N);
  reverse(A,A+N);

  ll ans = 0;
  int m = N/2;
  rep(i,N){
    if (i<m-1) ans += 2*A[i];
    else if (i==m-1) ans += A[i];
    else if (i==m && N%2) ans += A[i];
    else if (i==m && N%2==0) ans -= A[i];
    else ans -= 2*A[i]; 
  }
  ll ans2 = 0;
  rep(i,N){
    if (i<m) ans2 += 2*A[i];
    else if (i<=m+1) ans2 -= A[i];
    else ans2 -= 2*A[i];
  }
  if (N%2) chmax(ans, ans2);
  cout << ans << endl;


  
  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 4032
#include <iostream>
using namespace std;
 
int main(){
	unsigned int N;
  	cin >> N;
  	
  	unsigned int odd_counter=0;
  	for(int i=1; i<=N; i++){
      if (i % 2 == 1){
      	odd_counter += 1;
      } 
    }
  	float output=0;
  	output = (float)odd_counter / N;
      
    cout << output << endl;
    return 0;
}

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

vector<int> v(1000001,0);

ll next(int x)
{
  if(x%2==0){
    return x/2;
  } else {
    return 3*x+1;
  }
}

int main()
{
  ll s;
  cin >> s;
  ll cnt = 1;
  while(1){
    if(v[s]!=0){
      cout << cnt << endl;
      return 0; 
    }
    v[s] = 1;
    s = next(s);
    cnt++;
  }
  return 0;
}

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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#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 {
#ifndef ONLINE_JUDGE
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
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
	IOS;
	int n;
	cin>>n;
	vi a(n+1);
	int i;
	REP(i,1,n){
		cin>>a[i];
	}
	vector<ll> dp(n+1,0);
	dp[1] = 0;
	vector<ll> prefix(n+1);
	prefix[1] = a[1];
	for(int i=3;i<=n;i+=2){
		prefix[i] = prefix[i-2]+a[i];
	}
	for(int i=2;i<=n;i++){
		if(i&1){
			dp[i]=max(dp[i-1],dp[i-2]+a[i]);
		}else{
			dp[i] = a[i] + dp[i-2];
			dp[i] = max(dp[i],prefix[i-1]);
		}
	}
	cout<<dp[n];
	return 0;
}

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

#define int long long

using namespace std;

const int MAXN = 1e6 + 100;

int arr[MAXN];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    for(int i = 0 ; i < MAXN ; i++)arr[i] = -1;

    int N;
    cin >> N;

    int md = 7%N;

    int cont = 0;

    arr[md] = ++cont;

    int pw = 1;

    while(1)
    {
    	pw = pw*10%N;

    	md = (md + pw*7)%N;

    	if(arr[md] == -1)
    	{
    		arr[md] = ++cont;
    	}
    	else
    	{
    		break;
    	}
    }

    cout << arr[0] << '\n';

    return 0;
}

Measured memory_bytes: 11444
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Scanner
{
    private readonly char Separator = ' ';
    private int Index = 0;
    private string[] Line = new string[0];
    public string Next()
    {
        if (Index >= Line.Length)
        {
            Line = Console.ReadLine().Split(Separator);
            Index = 0;
        }
        var ret = Line[Index];
        Index++;
        return ret;
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public string[] StringArray()
    {
        Line = Console.ReadLine().Split(Separator);
        Index = Line.Length;
        return Line;
    }

    public int[] IntArray()
    {
        var l = StringArray();
        var res = new int[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = int.Parse(l[i]);
        }
        return res;
    }

    public long[] LongArray()
    {
        var l = StringArray();
        var res = new long[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = long.Parse(l[i]);
        }
        return res;
    }
}

class Program
{
    private int N, A, B;
    private void Scan()
    {
        var sc = new Scanner();
        N = sc.NextInt();
    }

    private int Sum(int n)
    {
        if (n < 10)
        {
            return n;
        }
        return n % 10 + Sum(n / 10);
    }

    public void Solve()
    {
        Scan();
        Console.WriteLine(N % Sum(N) == 0 ? "Yes" : "No");
    }



    static void Main(string[] args)
    {
        new Program().Solve();
    }
}

Measured memory_bytes: 13012
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <random>
#include <map>
#include <iomanip>
#include <sstream>

//AtCoderC++.cpp

using namespace std;


#define rep(i,from,to) for(int i=from;i<to;i++)
#define ints(name,n) vector<int> name;name.resize(n)

template<typename T> void Show(const vector<vector<T>>& v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			cout << v[i][j];
			if (j != v[i].size() - 1) {
				cout << delimiter;
			} else {
				cout << endl;
			}
		}
	}
}
template<typename T> void Show(const vector<T>& v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i != v.size() - 1) {
			cout << delimiter;
		} else {
			cout << endl;
		}
	}
}
template<typename T> vector<T> getUniform(T value, int n) {
	vector<vector<T>> ts;
	ts.resize(n);
	for (int i = 0; i < n; i++) {
		ts[i] = value;
	}
	return ts;
}
template<typename T> vector<vector<T>> getUniform(T value, int row, int col) {
	vector<vector<T>> ts;
	ts.resize(row);
	for (int i = 0; i < row; i++) {
		ts[i].resize(col);
		for (int j = 0; j < col; j++) {
			ts[i][j] = value;
		}
	}
	return ts;
}
bool All(vector<vector<bool>> ts) {
	int h = ts.size();
	int w = ts[0].size();
	rep(i, 0, h) {
		rep(j, 0, w) {
			if (!ts[i][j])return false;
		}
	}
	return true;
}

bool is_month(const string& mm) {
	if (mm[0] > '1') return false;
	if (mm[0] == '1') {
		return mm[1] <= '2';
	} else {
		return mm[1] != '0';
	}
}

int main() {
	int n, k;
	cin >> n >> k;
	long double prob = 0.0;
	for (size_t i = 1; i <= n; i++) {
		auto p = 0;
		auto point = i;
		while (point < k) {
			point *= 2;
			p++;
		}
		prob += powl(0.5, p) / n;
	}
	cout << setprecision(10) << prob << endl;
}

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

struct Pos{ int x, y, i; };

struct E{
	int s, e, x;
	bool operator<(const E &oth) const {
		return x < oth.x;
	}
};

int n, p[100010], ans;
Pos a[100010];
vector<E> el;

int fnd(int x){ return p[x] = (x == p[x] ? x : fnd(p[x])); }
void uni(int x, int y){ p[fnd(x)] = fnd(y); }

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d%d", &a[i].x, &a[i].y);
		a[i].i = i;
	}
	sort(a + 1, a + n + 1, [](Pos a, Pos b){ return a.x < b.x; });
	for(int i = 2; i <= n; i++){
		el.push_back({a[i - 1].i, a[i].i, a[i].x - a[i - 1].x});
	}
	sort(a + 1, a + n + 1, [](Pos a, Pos b){ return a.y < b.y; });
	for(int i = 2; i <= n; i++){
		el.push_back({a[i - 1].i, a[i].i, a[i].y - a[i - 1].y});
	}
	sort(el.begin(), el.end());
	for(int i = 1; i <= n; i++) p[i] = i;
	for(auto &i : el){
		if(fnd(i.s) == fnd(i.e)) continue;
		ans += i.x;
		uni(i.s, i.e);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 6132
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))


#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321

#define MAXN 100500
int N,M,K,Q,T;

const ll mod = 1e9+7;
char s[100][100];
ll dp[60][5][5];
ll solve(int n, int a, int b){
	if( n == N ) return 1;

	
	if( n == 0 ){
		ll tres = 0;
		if( s[0][n] == s[1][n] ){
			rep(i,3){
				tres = (tres + solve(n+1,i,i) )%mod; 
			}
		}
		else{
			rep(i,3)rep(j,3)if(i!=j) tres = (tres + solve(n+1,i,j) ) % mod;
		}
		return tres;
	}
	ll& res = dp[n][a][b];
	if( res != -1LL ) return res;
	res = 0;
	

	if( s[0][n] == s[1][n] ){
		rep(i,3)if(i!=a&&i!=b) res = (res + solve(n+1,i,i) ) % mod;
		return res;
	}

	if( s[0][n] == s[0][n-1] && s[1][n] == s[1][n-1] ){
		res = solve(n+1,a,b);
		return res;
	}

	if( s[0][n] == s[0][n-1] && s[1][n] != s[1][n-1] ){
		rep(i,3)if(i!=a&&i!=b) res = (res + solve(n+1,a,i) ) % mod;
		return res;
	}

	if( s[0][n] != s[0][n-1] && s[1][n] == s[1][n-1] ){
		rep(i,3)if(i!=a&&i!=b) res = (res + solve(n+1,i,b) ) % mod;
		return res;
	}

	if( s[0][n] != s[0][n-1] && s[1][n] != s[1][n-1] ){
		rep(i,3)rep(j,3)if(i!=j&&i!=a&&j!=b){
			res = (res + solve(n+1,i,j) ) % mod;
		}
		return res;
	}


	return res;
}

int main(void){
	memset(dp,-1,sizeof dp);
	scanf("%d%s%s",&N,s[0],s[1]);
	cout << solve(0,-1,-1);

}

Measured memory_bytes: 256
n,m = map(int, input().split())

l = []
for i in range(n): #Kを除く好きな食べ物を取得
    a = [int(_) for _ in input().split()]
    l.append(a[1:a[0]+1])

y = [] #全部好きな人を要素’1’として格納
for j in range(1,m+1):
    x = 0
    for k in range(n):
        if j in l[k]:
            x += 1
    if x == n: #これが全部好きの条件
        y.append(1)
        
print(len(y))


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

typedef pair<int,int> P;
typedef vector<P> vp;
typedef vector<vp> mp;

int N, M;

int solve(mp& m, int s, int t) {

    priority_queue<P, vector<P>, greater<P> > que;
    vector<int> dp(M, 1 << 28);
    dp[s] = 0;

    for (int i = 0; i < m[s].size(); i++) {
        que.push(m[s][i]);
        dp[m[s][i].second] = m[s][i].first;
    }

    while (que.size()) {
        P p  = que.top(); que.pop();
        int now = p.second;
        int cost = p.first;

        if (dp[now] < cost) continue;

        for (int i = 0; i < m[now].size(); i++) {
            int cost_ = cost + m[now][i].first;
            int next = m[now][i].second;

            if (dp[next] > cost_) {
                que.push(P(cost_, next));
                dp[next] = cost_;
            }
        }
    }

    return dp[t];
}

int main() {

    while (cin >> N >> M, N || M) {
        mp mc(M), mt(M);

        for (int i = 0; i < N; i++) {
            int a, b, c, t;
            cin >> a >> b >> c >> t;
            a--, b--;
            mc[a].push_back(P(c, b));
            mc[b].push_back(P(c, a));
            mt[a].push_back(P(t, b));
            mt[b].push_back(P(t, a));
        }

        int Q;
        cin >> Q;

        while (Q--) {
            int a, b, t;
            cin >> a >> b >> t;
            a--, b--;

            if (!t) {
                cout << solve(mc, a, b) << endl;
            } else {
                cout << solve(mt, a, b) << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3216
n, x = map(int, input().split())
a = list(map(int, input().split()))

count = 0
for i in range(0, n, 2):
    if i != 0:
        if a[i - 1] + a[i] > x:
            temp = min(a[i - 1] + a[i] - x, a[i])
            a[i] -= temp
            count += temp
            if a[i - 1] + a[i] > x:
                temp = a[i - 1] + a[i] - x
                a[i - 1] -= temp
                count += temp
    if i == n - 1:
        pass
    else:
        if a[i] + a[i + 1] > x:
            temp = min(a[i] + a[i + 1] - x, a[i + 1])
            a[i + 1] -= temp
            count += temp
            if a[i] + a[i + 1] > x:
                temp = a[i] + a[i + 1] - x
                a[i] -= temp
                count += temp
print(count)

Measured memory_bytes: 14324
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map> 
using namespace std;

#define LL long long
#define MOD (1000000007)


//E
struct LLPair {
	LL price = 0;
	LL open = 0;
};

int main() {
	LL N, M;
	scanf("%lld %lld", &N, &M);

	vector<LLPair> key;

	for (LL i = 0; i < M; i++) {
		LLPair p;

		LL price, num;
		scanf("%lld %lld", &price, &num);

		p.price = price;
		for (LL j = 0; j < num; j++) {
			LL val;
			scanf("%lld", &val);

			val -= 1; //�󔠔ԍ���0����n�܂�悤�ɂ���

			p.open |= (1 << val);
		}

		key.push_back(p);
	}

	static LL dp[1010][4096];

	for (LL i = 0; i <= M; i++) {
		for (LL j = 0; j < (1 << N); j++) {
			dp[i][j] = -1;
		}
	}
	dp[0][0] = 0;
	//memset(dp, 0, sizeof(dp));

	for (LL i = 0; i < M; i++) {
		for (LL j = 0; j < (1 << N); j++) {
			if (dp[i][j] < 0) {
				continue;
			}

			//��i���g��Ȃ��ꍇ
			LL nextJ = j;
			LL nextPrice = dp[i][j];
			
			if (dp[i + 1][nextJ] < 0 || nextPrice < dp[i + 1][nextJ]) {
				dp[i + 1][nextJ] = nextPrice;
			}

			//��i���g���ꍇ
			nextJ |= key[i].open;
			nextPrice += key[i].price;

			if (dp[i + 1][nextJ] < 0 || nextPrice < dp[i + 1][nextJ]) {
				dp[i + 1][nextJ] = nextPrice;
			}
		}
	}

	printf("%lld\n", dp[M][(1 << N) - 1]);
}

//D
/*
//�ő����
LL GCD(LL a, LL b) {
	if (a < b) {
		LL temp = a;
		a = b;
		b = temp;
	}

	LL r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

bool Prime(LL x) {
	if (x == 1 || x == 2) {
		return true;
	}

	if (x % 2 == 0) {
		return false;
	}

	for (LL i = 3; i <= (LL)std::sqrt(x); i += 2) {
		if (x % i == 0) {
			return false;
		}
	}

	return true;
}

int main() {
	LL A, B;
	scanf("%lld %lld", &A, &B);

	LL g = GCD(A, B);

	vector<LL> ans;

	LL result = 1;
	for (LL i = 2; i <= g; i++) {
		if (g % i == 0) {
			//i�͖�

			//bool ok = true;
			//for (auto item : ans) {
			//	if (i % item == 0) {
			//		ok = false;
			//		break;
			//	}
			//}
			//if (ok == false) {
			//	continue;
			//}

			//if (Prime(i) == true) {
			//	ans.push_back(i);
			//	result++;
			//}
		}
	}

	printf("%lld\n", result);
}
*/

//C
/*
struct LLPair
{
	LL a = 0;
	LL b = 0;
};

int main() {
	LL N;
	scanf("%lldd", &N);

	vector<LLPair> A;
	for (LL i = 1; i <= N; i++) {
		LL a;
		scanf("%lld", &a);

		LLPair p;
		p.a = i;
		p.b = a;

		A.push_back(p);
	}

	std::sort(A.begin(), A.end(), [](const LLPair &a, const LLPair &b) {
		return a.b < b.b;
	});

	for (auto item : A) {
		printf("%lld ", item.a);
	}

	printf("\n");

	return 0;
}
*/


//B
/*
int main() {
	LL N, K;
	scanf("%lld %lld", &N, &K);

	LL result = 0;

	for (LL i = 0; i < N; i++) {
		LL h;
		scanf("%lld", &h);

		if (h >= K) {
			result++;
		}
	}

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

	return 0;
}
*/

//A
/*
int main() {
	LL N;

	scanf("%lld", &N);

	double result = (double)((N + 1) / 2) / (double)N;

	printf("%0.9f\n", result);

	return 0;
}
*/

Measured memory_bytes: 32256
n=int(input())
deg=[0]*40
if n>=0:
    for i in range(32):
        if n>>i&1:
            if i%2==0:
                deg[i]+=1
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                deg[i]+=1
                deg[i+1]+=1
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
        else:
            if i%2==0:
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
else:
    n*=-1
    for i in range(32):
        if n>>i&1:
            if i%2==1:
                deg[i]+=1
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                deg[i]+=1
                deg[i+1]+=1
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
        else:
            if i%2==1:
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
deg.reverse()
l=39
for i in range(40):
    if deg[i]==1:
        l=i
        break
print(*deg[l:],sep="")

Measured memory_bytes: 3192