akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main(void){
    long long w, h;
    cin >> w >> h;
    vector<long long> p(w);
    for(long long i=0; i<w; i++){
        cin >> p[i];
    }
    vector<long long> q(h);
    for(long long i=0; i<h; i++){
        cin >> q[i];
    }
    long long ans = 0;
    long long count = 0;
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    int pi=0, qi=0;
    int nxt = 0;
    int val = 0;
    long long a = w+1;
    long long b = h+1;
    while(count<h*w+h+w){
        nxt = 0;
        if(pi==w){
            nxt = 2;
        }
        if(qi==h){
            nxt = 1;
        }
        if(nxt==0){
            if(p[pi]<q[qi]){
                nxt = 1;
            }else{
                nxt = 2;
            }
        }
        if(nxt==1){
            val = min(h*w+h+w-count, b);
            count += val;
            ans += val*p[pi];
            pi += 1;
            a -= 1;
        }else{
            val = min(h*w+h+w-count, a);
            count += val;
            ans += val*q[qi];
            qi += 1;
            b -= 1;
        }
        //cout << nxt << " val=" << val << " count=" << count << " ans=" << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
using namespace std;
long long n,maxn,ans,x;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        ans+=max(maxn-x,0ll);
        maxn=max(maxn,x);
    }
    cout<<ans;
    return 0;
}

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll X,K,Q;
vector<ll> R,T,A;
const int INF = 1e9;

ll f(ll a,ll b,ll mx,ll mn)
{
	return max(min(a + b,mx),mn);
}

int main()
{
	scanf("%lld%lld",&X,&K);
	R.assign(K,0ll);
	FOR(i,0,K){
		scanf("%lld",&R [i]);
	}
	R.insert(R.begin(),0ll);
	R.insert(R.end(),INF);
	K = R.size();
	scanf("%lld",&Q);
	T.assign(Q,0ll);
	A.assign(Q,0ll);
	FOR(i,0,Q){
		scanf("%lld%lld",&T [i],&A [i]);
	}

	ll mx = X,mn = 0,sum = 0,idx = 1;
	FOR(i,0,Q){
		while(idx < K && R [idx] <= T [i]){
			if(idx % 2){
				mx = min(mx - (R [idx] - R [idx - 1]),X);
				chmax(mx,0ll);
				mn = max(mn - (R [idx] - R [idx - 1]),0ll);
				chmin(mn,X);
				sum -= R [idx] - R [idx - 1];
			}
			else{
				mx = min(mx + (R [idx] - R [idx - 1]),X);
				chmax(mx,0ll);
				mn = max(mn + (R [idx] - R [idx - 1]),0ll);
				chmin(mn,X);
				sum += R [idx] - R [idx - 1];
			}
			idx++;
		}
		ll ans;
		if(idx % 2){
			ll t = T [i] - R [idx - 1];
			ll p = max(min(mx - t,X),0ll),q = min(max(mn - t,0ll),X);
			ans = f(A [i],-t + sum,p,q);
		}
		else{
			ll t = T [i] - R [idx - 1];
			ll p = max(min(mx + t,X),0ll),q = min(max(mn + t,0ll),X);
			ans = f(A [i],t + sum,p,q);
		}
		printf("%lld\n",ans);
	}

	return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back







int main(){
  
  string t;
  cin>>t;
  int n=int(t.size());
  
  rep(i,n){
    if (t.at(i)=='?'){
      t.at(i)='D';
    }
    
  }
  

  cout<<t<<endl;
  
  

}























Measured memory_bytes: 3712
N = int(input())
a = list(map(int, input().split()))
bai4 = 0
bai2 = 0
kisuu = 0
for i in a:
    if i%4 == 0:
        bai4 += 1
    elif i%2 == 0:
        bai2 += 1
    else:
        kisuu += 1
if N%2 == 0:
    if kisuu <= bai4:
        print("Yes")
    else:
        print("No")
else:
    if min(kisuu,N//2) <= bai4:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 15020
#include <iostream>
#include <map>

int main() {
    std::map<std::string, int> mp;
    int n; std::cin >> n;
    for(int i=0; i<n; ++i) {
        std::string s; std::cin >> s;
        if (mp.find(s) != mp.end())
            ++mp[s];
        else
            mp[s] = 1;
    }
    std::string judge[] = {"AC", "WA", "TLE", "RE"};
    for(auto j : judge)
        std::cout << j << " x " << mp[j] << std::endl;

    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    int l,r,d;cin>>l>>r>>d;
    int ans=0;
    for(int i=1;i<1000;i++){
        int c = i*d;
        if(c>=l && c<=r){
            ans++;
        }
    }    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x)(x)*(x)
#define fz1(i,n) for (i=1;i<=n;i++)
#define fd1(i,n) for (i=n;i>=1;i--)
#define fz0g(i,n) for (i=0;i<=n;i++)
#define fd0g(i,n) for (i=n;i>=0;i--)
#define fz0k(i,n) for (i=0;i<n;i++)
#define fd0k(i,n) for (i=(long long)(n-1);i>=0;i--)
#define fz(i,x,y) for (i=x;i<=y;i++)
#define fd(i,y,x) for (i=y;i>=x;i--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
int n,m,i,j,a[25],x=0;
vector<int> s1,s2,s3;
int main()
{
	cin>>n;
	fz1(i,19) a[i]=(1<<(19-i));
	if (n<=4)
	{
		cout<<2<<' '<<n<<endl;
		fz0k(i,n) cout<<"1 2 "<<i<<endl;
		return 0;
	}
	fz(i,2,19)
	{
		s1.push_back(i);
		s2.push_back(i+1);
		s3.push_back((1<<(19-i)));
		s1.push_back(i);
		s2.push_back(i+1);
		s3.push_back(0);
	}
	fz1(i,19)
	{
		while (n>=((1<<(19-i))))
		{
			n-=((1<<(19-i)));
			s1.push_back(1);
			s2.push_back(i+1);
			s3.push_back(x);
			x+=(1<<(19-i));
		}
	}
	cout<<20<<' '<<s1.size()<<endl;
	fz0k(i,s1.size()) cout<<s1[i]<<' '<<s2[i]<<' '<<s3[i]<<endl;
	return 0;
}

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

#define pi acos(-1)
using namespace std;
int main(){
   double a,b,h,m,temp,ans=0.0;                                
   cin >> a >> b >> h >> m;
   temp = m*6;
   double angle = ((60*h)+m)*360/(60*12);
   double ang = (angle-temp);
   double p = ang*(pi/180);
   ans = (a*a)+(b*b)-(2*a*b*cos(p));
   cout << fixed << setprecision(20) << sqrt(ans) << endl;
   return 0;
}

Measured memory_bytes: 4152
import bisect

a,b,q=[int(it) for it in input().split()]
dummy=10**20
s=[-dummy] + [int(input()) for it in range(a)] + [dummy]
t=[-dummy] + [int(input()) for it in range(b)] + [dummy]
x=[int(input()) for it in range(q)]

for xi in x:
    s_w = s[bisect.bisect_left(s, xi)-1]
    s_e = s[bisect.bisect_left(s, xi)]
    t_w = t[bisect.bisect_left(t, xi)-1]
    t_e = t[bisect.bisect_left(t, xi)]

    d = min(
        abs(xi - s_w) + abs(s_w - t_w),
        abs(xi - s_e) + abs(s_e - t_w),
        abs(xi - s_w) + abs(s_w - t_e),
        abs(xi - s_e) + abs(s_e - t_e),
        abs(xi - t_w) + abs(t_w - s_w),
        abs(xi - t_e) + abs(t_e - s_w),
        abs(xi - t_w) + abs(t_w - s_e),
        abs(xi - t_e) + abs(t_e - s_e)
    )
    print(d)


Measured memory_bytes: 16144
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define l first
#define r second

using namespace std;

const int maxn = 3e5 + 1;

int a[maxn];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    q *= 8; h *= 4; s *= 2;
    int ans = min(min(q, h), min(s, d)) * (n / 2);
    ans += min(q, min(h, s)) * (n % 2) / 2;
    cout << ans;
    return 0;
}


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

ru_xor = [0] * (n + 1)
ru_sum = [0] * (n + 1)

for i in range(n):
    ru_xor[i + 1] = ru_xor[i] ^ a[i]
    ru_sum[i + 1] = ru_sum[i] + a[i]

r = 0
ans = 0
for l in range(n):
    while not(r == n + 1) and ru_xor[r] ^ ru_xor[l] == ru_sum[r] - ru_sum[l]:
        r += 1
    ans += (r - 1) - l
print(ans)

Measured memory_bytes: 78028
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 105
using namespace std;
string W[MAX];
int main() {
  int n;
  cin >> n;
  bool flag=true;
  for(int i=0;i<n;i++) {
    cin >> W[i];
  }
  for(int i=0;i<n-1;i++) {
    for(int k=i+1;k<n;k++) {
      if(W[i] == W[k]) {
        flag = false;
        break;
      }
    }
  }
  if(flag) {
    for(int i=0;i<n-1;i++) {
      if(W[i][W[i].size()-1] != W[i+1][0]) {
        flag = false;
        break;
      }
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>

using namespace std;
#define li long long int
#define FOR(i, a, b) for (int i = a ; i < b ; ++i)
#define REP(i, n) for (int i = 0 ; i < n ; ++i)

li gcd(li a,li b) {
    return a % b == 0 ? b : gcd(b, a % b);
}

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

    string base = "AKIHABARA";
    li position = 0;

    if (s.length() > base.length()) {
        cout << "NO" << endl;
        return 0;
    }

    FOR(i, 0, base.length()) {
        if (position == s.length()) {
            if (i < 8) {
                cout << "NO" << endl;
                return 0;
            }
            break;
        }

        if (base[i] != s[position]) {
            // AKIHABARAとは別の文字が紛れている
            if (base[i] == 'A') {
                // A は追加可能なためセーフ
                continue;
            } else {
                cout << "NO" << endl;
                return 0;
            }
        } else {
            position += 1;
            continue;
        }
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main () {
  int n;
  cin >> n;
  int answer = 0;
  for (int i = 1; i <=n; i++) {
    if (i % 2 == 1) {
      int sub = 0;
      for (int j = 1; j <= i; j++) {
        if (i % j == 0) {
          sub++;  
        }    
      }  
      if (sub == 8) {
        answer++;
      }
    }  
  }  
  cout << answer << endl;
}

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

int main() {
    int a, b, c, maxnum, minnum, middle;
    cin >> a >> b >> c;

    maxnum = a > b ? ((a > c) ? a : c) : ((b > c) ? b : c);
    minnum = a < b ? ((a < c) ? a : c) : ((b < c) ? b : c);
    middle = (a != maxnum && a != minnum) ? a : (b != maxnum && b != minnum ? b : c);

    cout << minnum << " " << middle << " " << maxnum << endl;

    return 0;
}

Measured memory_bytes: 3056
# -*- coding: utf-8 -*-

"""
二分探索の応用
"""

N, K = map(int, input().split())
aN = [int(input()) for i in range(N)]

# 同じ荷物を2回積むことはないので、2重ループでも計算量はO(N)
def check(P):
    # 積んだ荷物の個数
    load = 0
    # トラックの台数ループ
    for j in range(K):
        truck = 0
        # あるトラックに荷物を積み込むループ
        while truck + aN[load] <= P:
            truck += aN[load]
            load += 1
            # 全部積めた
            if load == N:
                return N
    # i個詰めた
    return load

# 2分探索で最初にN個全部積める場所を見つける
hi = 10 ** 9
low = 0
# low+1 == hi -> lowとhiが隣り合った状態なので、境界が確定する
while low+1 < hi:
    mid = (hi+low) // 2
    if check(mid) == N:
        hi = mid
    else:
        low = mid
# hiの位置が最初にN個全部積める積載量S
print(hi)



Measured memory_bytes: 9572
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();

		int[] t = new int[n+1];
		int[] x = new int[n+1];
		int[] y = new int[n+1];

		t[0]=x[0]=y[0]=0;


		for(int i=0;i<n;i++) {
			t[i+1]=sc.nextInt();
			x[i+1]=sc.nextInt();
			y[i+1]=sc.nextInt();
		}

		boolean canReach=true;
		for(int i=0;i<n;i++) {

			//次の場所にいくのにかかる時間。
			int dt=t[i+1]-t[i];

			//次の場所への最短距離
			int distance=Math.abs(x[i+1]-x[i])+Math.abs(y[i+1]-y[i]);

			//そもそもたどりつけない
			if(dt<distance) {canReach=false;};

			//ふらついてもぴったり止まれない
			if(distance%2 != dt % 2) {canReach=false;};

		}

		if(canReach) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

		sc.close();


	}


}


Measured memory_bytes: 92000
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b && b < c)
    {
        Yes(1);
    }
    else
    {
        Yes(0);
    }
}


Measured memory_bytes: 3116
#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 gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main() {
    int k;
    cin >> k;
    int sum=0;
    for(int a=1;a<k+1;++a){
        for(int b=1;b<k+1;++b){
            for(int c=1;c<k+1;++c){
                sum += gcd(gcd(a,b),c);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3636
N,M,K=map(int,input().split())
mod=998244353
P=[1 for i in range(10**6+1)]
for i in range(10**6):
  P[i+1]=P[i]*(i+1)%mod

def comb(a,b):
    if a>=b:
        return P[a]*pow(P[a-b],mod-2,mod)*pow(P[b],mod-2,mod)%mod
    else:
        return 0
ans=0
for i in range(K+1):
  ans+=M*comb(N-1,i)*pow(M-1,N-1-i,mod)
  ans%=mod
print(ans)

Measured memory_bytes: 142100
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return x == 0 ? 0 : 1 + (x - 1) / y; }

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

    ll N;
    cin >> N;
    vector<ll> p(N);
    rep(i, N) cin >> p[i];
    ll ans = 0;
    ll ct = 0;
    rep(i, N){
        if(p[i] == i + 1) ct++;
        else{
            ans += devc(ct, 2);
            ct = 0;
        }
    }
    print(ans+devc(ct,2));

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

/*
   cin.tie(0);
   ios::sync_with_stdio(false);
*/

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int a,b;
  cin>>a>>b;
  if(a<=8&&b<=8)cout<<"Yay!"<<endl;
  else cout<<":("<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> dp(n + 1, 0);

  rep(i, 1, n + 1) {
    if (i < 6) {
      dp[i] = i;
      continue;
    } else if (i < 9) {
      dp[i] = dp[i - 6] + 1;
      continue;
    }
    for (int six = 6, nine = 9; six <= n || nine <= n; six *= 6, nine *= 9) {
      if (i < six)
        break;
      if (i < nine) {
        if (dp[i])
          dp[i] = min(dp[i], dp[i - six] + 1);
        else
          dp[i] = dp[i - six] + 1;
      } else {
        if (dp[i])
          dp[i] = min(dp[i], (min(dp[i - six], dp[i - nine]) + 1));
        else
          dp[i] = min(dp[i - six], dp[i - nine]) + 1;
      }
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 640
n = gets.chomp.to_i
a_list = gets.chomp.split.map(&:to_i)
result = {}
(1..n).each{|x| result[x] = 0}
a_list.group_by{|x| x}.each do |x|
  result[x[0]] = x[1].size
end
result.each do |k, v|
  puts v
end

Measured memory_bytes: 60232
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        BufferedReader bu = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String [] inp = bu.readLine().split(" " );
        int a = Integer.parseInt(inp[0]), b = Integer.parseInt(inp[1]), c = Integer.parseInt(inp[2]);
        int totSteps = Integer.parseInt(bu.readLine());
        int steps = 0;
        boolean check = true;
        while (b <= a)
        {
            b*=2;
            steps++;
            if (steps > totSteps)
            {
                check = false;
                break;
            }
        }
        if(!check){
            sb.append("No");
        }
        else {
            while(c <= b){
                c*=2;
                steps++;
                if (steps>totSteps){
                    check = false;
                    break;
                }
            }
            if (!check)
                sb.append("No");
            else
                sb.append("Yes");
        }


        System.out.print(sb);
    }
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    int ans = 0;
    string s, t;
    cin >> s >> t;
    rep(i, 3) {
        if (s[i] == t[i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++) {
        if(s[i]=='1') {
            cout << 9;
        }
        else {
            cout << '1';
        }
    }
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
xs = gets.split.map(&:to_i)
ys = gets.split.map(&:to_i)

p1 = 0
p2 = 0
p3 = 0
p_inf = 0

n.times do |i|
  diff = (xs[i] - ys[i]).abs

  p1 += diff
  p2 += diff**2
  p3 += diff**3
  p_inf = [p_inf, diff].max
end

p2 = Math.sqrt(p2)
p3 = Math.cbrt(p3)

p p1, p2, p3, p_inf



Measured memory_bytes: 6916
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x:x[0])
s = 0
c = 0
for i in range(N):
    for j in range(AB[i][1]):
        s += AB[i][0]
        c += 1
        if c >= M:
            print(s)
            exit()

Measured memory_bytes: 64984
#include <bits/stdc++.h>
#include "atcoder/dsu"
typedef long long int ll;
using namespace std;
using namespace atcoder;
int main() {
    int n, q;
    cin >> n >> q;
    vector<int> ans;
    dsu d(n);
    for (int i = 1; i <= q; i++) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            d.merge(u, v);
        }
        else {
            if (d.same(u, v)) {
                ans.push_back(1);
            }
            else {
                ans.push_back(0);
            }
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4404
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

#define INF 0x3f3f3f3f

using namespace std;

typedef long long LL;
typedef pair<int,int>PII;

int n;

void DFS(string s,char mx) {
	if(s.size() == n) {
		cout << s << endl;
	} else {
		for(char i = 'a'; i <= mx; i ++) {
			DFS(s + i,i == mx ? mx + 1 : mx);
		}
	}
	return ;
}

int main(void) {
	scanf("%d",&n);
	DFS("",'a');
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

vector<int> G[100001];
LL n,k; 
vector<LL> dp(100001);

void dfs(int u,int v,LL p,LL q){
    LL ret=0;
    LL a=p,b=q;
    dp[u]=(k-(p+q));
    for (int i = 0; i < G[u].size(); i++) {
        if(G[u][i]==v) continue;
        dfs(G[u][i],u,1,a);
        a++;
    }
    return ;
}



int main(){
    cin >> n >> k;
    for (int i = 0; i < n-1; i++) {
        int a,b;cin >> a >> b;
        a--,b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    LL ans=1;
    dfs(0,-1,0,0);
    for (int i = 0; i < n; i++) {
        if(dp[i]<0){
            puts("0");
            return 0;
        }
        ans=ans*dp[i]%mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

int N,M,Q;
map<int,vector<array<int,4>>> events;

int main(){
	cin>>N>>M>>Q;
	rep(i,M){
		int d,a,b;
		cin>>d>>a>>b;
		a--,b--;
		events[d].pb({1,a,b,0});
	}
	rep(i,Q){
		int e,s,t;
		cin>>e>>s>>t;
		s--,t--;
		events[e].pb({0,s,t,i});
	}
	set<int> yet;	//yet.count(i) <=> i x i+1
	rep(i,N) yet.insert(i);
	vector<bool> ans(Q);
	for(auto it:events){
		auto es = it.sc;
		sort(all(es));
		for(auto e:es){
			int type = e[0], l = e[1], r = e[2], qid = e[3];
			if(type==0){	//query
				int x = *yet.lower_bound(l);
				ans[qid] = x>r-1;
			}else{
				while(true){
					int x = *yet.lower_bound(l);
					if(x>r-1) break;
					yet.erase(x);
				}
			}
		}
	}
	rep(i,Q){
		if(ans[i]) puts("Yes");
		else puts("No");
	}
}



Measured memory_bytes: 29740
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#define LL long long
#define N 110000
using namespace std;
LL x[N],f[N],s[N],inf=1ll<<50,ans,ed,t;
int p[N],head,tail,n;
int main()
{
	scanf("%d%lld%lld",&n,&ed,&t);
	for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
	s[0]=t;
	int j=0;
	head=tail=1;p[1]=0;
	s[0]=-2*x[1];
	for(int i=1;i<=n;i++)
	{
		f[i]=inf;
		while(2*(x[i]-x[j+1])>t) j++;
		if(j>0) f[i]=3*x[i]+s[j-1];
		while(head<=tail && p[head]<j) head++;
		if(head<=tail) f[i]=min(f[i],f[p[head]]+x[i]-x[p[head]]+t);
		while(head<=tail && f[p[tail]]-x[p[tail]]>=f[i]-x[i]) tail--;
		p[++tail]=i;
		s[i]=min(s[i-1],f[i]-x[i]-2*x[i+1]);
	}
	ans=f[n]+ed-x[n];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2944
N, M = map(int, input().split())
Edge = [tuple(map(int, input().split())) for _ in range(M)]

Graph = [[] for _ in range(N)]
for a,b in Edge:
    Graph[a-1].append(b-1)
    Graph[b-1].append(a-1)

seen = set()
def dfs(v):
    seen.add(v)
    if len(seen) == N:
        seen.remove(v)
        return 1
    Res = [dfs(nv) for nv in Graph[v] if not nv in seen]
    seen.remove(v)
    return sum(Res)

print(dfs(0))

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int n,m;
  cin >> n >> m;

  vector<vector<P>> c(n+1);
  vector<int> ans1(m+1), ans2(m+1);

  REP(i,m){
    int p,y;
    cin >> p >> y;
    c[p].emplace_back(make_pair(y, i+1));
    ans1[i+1] = p;
  }


  FOR(i,1,n+1){
    sort(ALL(c[i]));
    REP(j, c[i].size()){
      ans2[c[i][j].second] = j+1;
    }
  }
  FOR(i,1,m+1){
    printf("%06d%06d\n",ans1[i], ans2[i]);
  }

}



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

#define int long long

vector<int> v;

void dfs(int node)
{
 	if(node > 1e10)
 		return;
 	v.push_back(node);
// 	s.insert(node);
 	dfs(node*10 + (node%10));
 	if(node%10 != 9)
 		dfs(node*10 + (node%10) + 1);
 	if(node%10 != 0)
 		dfs(node*10 + (node%10) - 1);
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	for(int i = 1; i <= 9; i++)
		dfs(i);
	sort(v.begin(), v.end());
	int k; cin >> k;
	cout << v[k-1] << endl;	
	return 0;
}


Measured memory_bytes: 2420
#include<iostream>
using namespace std;
int main(void){
    int t,n;
    for(int i=0; i<4; i++){
        cin >> t >> n;
        if(t==1)        cout << 6000 * n << endl;
        else if(t==2)   cout << 4000 * n << endl;
        else if(t==3)   cout << 3000 * n << endl;
        else if(t==4)   cout << 2000 * n << endl;
    }
}


Measured memory_bytes: 3104
# coding: utf-8
def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N = II()
    p = ILI()
    return N, p


def solve(N, p):
    ans = 0
    now_ind = 0
    while now_ind <= N - 1:
        if now_ind + 1 == p[now_ind]:
            ans += 1
            now_ind += 2
        else:
            now_ind += 1
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


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

int main(){
  
  int N, Q, Num_=0, i;
  string S;
  cin>>N>>Q>>S;
  vector<int> Num(N);
  for(i=0; i<N-1; i++){
    if(S[i]=='A' && S[i+1]=='C'){
      Num_++;
    }
    Num[i+1]=Num_;
  }

  int l, r;
  for(i=0; i<Q; i++){
    cin>>l>>r;
    cout<<Num[r-1]-Num[l-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3836
#この方法だとTLEになるためNG

from pprint import pprint
from copy import deepcopy

#N <= 10**5なので、全探索はNG
#Greedyでいける？


n,m = map(int,input().split())

requests = [list(map(int,input().split())) for _ in range(m)]

#区間スケジュール問題と考え、終端が小さい順で並べる。その後Greedyで計算。
requests = sorted(requests, key=lambda x:x[1])

counter = 0
before_point = -float('inf')

#pprint(requests)

for i in range(m):
    if requests[i][0] >= before_point:
        counter += 1
        before_point = requests[i][1]
        #print("requests[{}]={} YES".format(i,requests[i]))
    else:
        #print("requests[{}]={} NO".format(i,requests[i]))
        pass

print(counter)


Measured memory_bytes: 30532
#include <iostream>
#include <string>
#include <queue>

using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  queue<string> qname;
  queue<int> qtime;
  for(int i = 0; i < n; i++) {
    string name;
    int time;
    cin >> name >> time;

    qname.push(name);
    qtime.push(time);
  }

  int total_time = 0;
  while(!qname.empty()) {
    string pname = qname.front();
    qname.pop();
    int ptime = qtime.front();
    qtime.pop();

    total_time += ptime > q ? q : ptime;
    ptime -= ptime > q ? q : ptime;

    if(!ptime) {
      cout << pname << " " << total_time << endl;
    } else {
      qname.push(pname);
      qtime.push(ptime);
    }
  }

  return 0;
}


Measured memory_bytes: 5716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N;
  int i=0;
  
  for(; i<N; i++){
    cin >> S;
    if(S=="Y")
      break;
  }
  
  if(i==N)
    cout << "Three" << endl;
  else
    cout << "Four" << endl;
}

Measured memory_bytes: 256
nums = []
nums.append(int(input()))

for i in range(1,100000):
    if nums[i - 1] % 2 == 0:
        nums.append(nums[i - 1] // 2)
    else:
        nums.append(nums[i - 1] * 3 + 1)

for i in range(100000):
    for j in range(i + 1,100000):
        if nums[i] == nums[j]:
            print(j + 1)
            break
    else:
        continue
    break

Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
int d,n,c,An,a=1,b;
int main(){
    cin>>d>>n;
    for(int i=0;i<d;i++)a*=100;
    b=(a*100);
    int v=1;
    while(c<n){
        if(((v*a)%b)!=0){
            An=(v*a);
            v++;
            c++;
        }
        else{
            v++;
        }
    }
    cout<<An<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def dfs(s :str, n: int):
    if(int(s) > n):
        return 0
    ret = 1 if all(s.count(c) for c in '753') else 0
    for c in '753':
        ret += dfs(s+c, n)
    return ret


def solve(N: int):
    print(dfs('0',N))


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
a=input()
a=int(a)
b=[int(i) for i in input().split()]
x=0
c=0
of=0
for i in b:
    if x<i:
        b[of]-=1
        of+=1
        x=i-1
        continue
    of+=1
    x=i
x=0
for i in b:
    if x>i:
        c=1
        print("No")
        break
    x=i
if c==0:
    print("Yes")


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N;
    cin >> N;

    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        vec.push_back(t);
    }

    ll mn = INF;
    for(ll i = 1; i <= 100; i++){
        ll sum = 0;
        for(ll j = 0; j < N; j++){
            
            sum += (vec[j] - i)  *  (vec[j] - i) ;
        }
        mn = min(mn , sum);
    }

    cout << mn << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <cstdio>

int main(){
  std::string sb, item;
  std::getline( std::cin, sb );
  std::stringstream ss(sb);
  std::vector<std::string> res;
  while( std::getline( ss, item, ' ' ) ) {
    if ( !item.empty() ){ res.push_back(item); }
  }
  std::stack<int> stack;
  for( std::string v : res ){
    if ( v == "+" ){
      int num1, num2;
      num1 = stack.top(); stack.pop();
      num2 = stack.top(); stack.pop();
      stack.push( num1 + num2 );
      continue;
    }
    if ( v == "-" ){
      int num1, num2;
      num1 = stack.top(); stack.pop();
      num2 = stack.top(); stack.pop();
      stack.push( num2 - num1 );
      continue;
    }
    if ( v == "*" ){
      int num1, num2;
      num1 = stack.top(); stack.pop();
      num2 = stack.top(); stack.pop();
      stack.push( num1 * num2 );
      continue;
    }
    int num;
    sscanf( v.c_str(), "%d", &num );
    stack.push( num );
  }
  std::cout << stack.top() << std::endl;
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<=(int)(n); i++)
#define reprange(i, a) for(int i : vector<int>a)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;
typedef vector<ll> vl;
const ll INF=1LL << 60;
const ll MOD=1e9+7;

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

  int n;
  cin >> n;
  tuple<string, int, int> t[n];
  rep(i, n){
    string s;
    int m;
    cin >> s >> m;
    t[i]=make_tuple(s, 100-m, i+1);
  }

  sort(t, t+n);
  rep(i, n)cout << get<2>(t[i]) << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <fstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>

using std::cin;
using std::cerr;
using std::cout;
using std::endl;
using std::unordered_set;
using std::pair;
using std::stack;
using std::string;
using std::vector;

std::ofstream debug("/dev/null");

int main(int argc, char* argv[]) {
  int ab, bc, ca;
  cin >> ab >> bc >> ca;

  cerr << "Hello, world (^_^)/" << endl;
  cout << ab * bc / 2;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

string solve(){
    vector<int> a(10,0);
    rep(i,10){
        cin>>a[i];
    }
    for(int bit = 0; bit < (1<<11);++bit){
        vector<int> bv,cv;
        int b=0,c=0;
        bool is = true;
        rep(i,10){
            if(bit & (1<<i)){
                if(b<a[i]) b = a[i];
                else is = false;
            }else{
               if(c<a[i])c = a[i];
               else is = false;
            }
        }
        if(is) return "YES";
    }
    return "NO";

}

int main(){
    int n;
    cin >> n;
    rep(i,n){
        cout<<solve()<<endl;
    }

    return 0;
}


Measured memory_bytes: 2984
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int n,i,x1,y1,z1,w1,x2,y2,z2,w2,xyzw[10][4];
	while(1){
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++){
			cin>>x1>>y1>>z1>>w1>>x2>>y2>>z2>>w2;
			xyzw[i][0]=(x1*x2)+(y1*y2*-1)+(z1*z2*-1)+(w1*w2*-1);
			xyzw[i][1]=(x1*y2)+(x2*y1)+(z1*w2)+(w1*z2*-1);
			xyzw[i][2]=(z1*x2)+(x1*z2)+(y1*w2*-1)+(w1*y2);
			xyzw[i][3]=(x1*w2)+(y1*z2)+(z1*y2*-1)+(w1*x2);
		}
		for(i=0;i<n;i++){
			cout<<xyzw[i][0]<<' '<<xyzw[i][1]<<' '<<xyzw[i][2]<<' '<<xyzw[i][3]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3060
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
fun solve(N: Long, A: Long, B: Long){
    pw.println(Math.min(A*N, B))
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    solve(N, A, B)
}




Measured memory_bytes: 29724
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,col[N];

int cnt=1,head[N],nxt[N<<1],to[N<<1],len[N<<1];
void add_edge(int x,int y,int z) {
	nxt[++cnt]=head[x]; to[cnt]=y; len[cnt]=z; head[x]=cnt;
}

void dfs(int x) {
	for (int i=head[x];i;i=nxt[i]) {
		int y=to[i];
		if (!col[y]) {
			if (len[i]%2==0) col[y]=col[x]; else col[y]=3-col[x];
			dfs(y);
		}
	}
}

int main()
{
	cin>>n;
	for (int i=1;i<n;i++) {
		int x,y,z; scanf("%d%d%d",&x,&y,&z);
		add_edge(x,y,z); 
		add_edge(y,x,z);
	}
	col[1]=1;
	dfs(1);
	for (int i=1;i<=n;i++) printf("%d\n",col[i]-1);
	return 0;
}

Measured memory_bytes: 4864
import java.util.Arrays;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        final int H = sc.nextInt();
        final int W = sc.nextInt();
        final int A = sc.nextInt();
        final int B = sc.nextInt();
        sc.close();
        combinationInit();
        long ans = 0;
        // long ans = combination(H - 1 + W - 1, Math.min(H - 1, W - 1));
        for (int i = 0; i < H - A; i++) {
            long tmp = combination(B - 1 + i, Math.min(B - 1, i));
            tmp *= combination((W - B - 1) + (H - i - 1), Math.min((W - B - 1), (H - i - 1)));
            tmp %= MOD;
            ans += tmp;
            ans %= MOD;
        }
        System.out.println(ans);
    }

    static int MAX = 510000;
    static long[] fac = new long[MAX], finv = new long[MAX], inv = new long[MAX];

    static void combinationInit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[(int) MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    static long combination(int n, int k) {
        // System.out.println(n + " " + k);
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;

        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
}

Measured memory_bytes: 35284
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef long long ll;
const ll INF = 1e18L + 1;

int main()
{
  string s;
  cin >> s;
  if (s[0] == s[2] && s[1] == s[0])
    puts("No");
  else
    puts("Yes");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

//繰り返し二乗法
ll EX(ll x,ll n,ll bit){
    if(n == 0) return 1;
    else if(n%2 == 1) return EX(x,n-1,bit)*x%bit;
    else return EX(x*x%bit,n/2,bit)%bit;
}

ll solve(ll now,ll bit,ll ans = 0){
    now %= bit;
    bit = __builtin_popcount(now);
    if(now == 0) return ans+1;
    else {
        ans++;
        return solve(now,bit,ans);
    }
}

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int bit = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '1') bit++;
    }
    ll m = 0,p = 0;
    for(int i = 0; i < n; i++){
        if(bit == 1) break;
        if(s[i] == '1') m += EX(2,n-i-1,bit-1);
        m %= bit-1;
    }
    for(int i = 0; i < n; i++){
        if(s[i] == '1') p += EX(2,n-i-1,bit+1);
        p %= bit+1;
    }
    vector<ll> ans(n);
    for(int i = 0; i < n; i++){
        string t = s;
        bool mai = true;
        if(t[i] == '1'){
            t[i] = '0';
        } else {
            t[i] = '1';
            mai = false;
        }
        if(mai){
            if(bit == 1){
                ans[i] = 0;
            } else ans[i] = solve((m-EX(2,n-i-1,bit-1))%(bit-1)+bit-1,bit-1);
        } else {
            ans[i] = solve((p+EX(2,n-i-1,bit+1))%(bit+1)+bit+1,bit+1);
        }
    }
    for(int i = 0; i < n; i++) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 5276
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
import time
start=time.time()
x=(a1-b1)*t1
y=(a2-b2)*t2
if x<0:
    if x+y<0:
        print(0)
        exit()
    if x+y==0:
        print("infinity")
        exit()
    if -1*x%(x+y):
        print(-1*x//(x+y)*2+1)
    else:
        print(-1*x//(x+y)*2)
else:
    x*=-1
    y*=-1
    if x+y<0:
        print(0)
        exit()
    if x+y==0:
        print("infinity")
        exit()
    if -1*x%(x+y):
        print(-1*x//(x+y)*2+1)
    else:
        print(-1*x//(x+y)*2)


Measured memory_bytes: 38256
import sys
def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def s(): return(input())

def main():
  S = s()
  cur = [[1,S[0],""],[0,"",S[0]]]
  nxt = []
  N = len(S)
  
  for i in range(1,N):
    for c,p,n in cur:
      if len(n)==1 and p!=n+S[i]:
        nxt.append([c+1,n+S[i],""])
      elif len(n)==0:
        nxt.append([c,p,n+S[i]])
        if p!=n+S[i]:
          nxt.append([c+1,n+S[i],""])
    nxt.sort(key = lambda x: x[0], reverse = True)
    nxt.sort(key = lambda x:(x[1],x[2]))
    cur = [nxt[0]]
    for j in range(1,len(nxt)):
      if cur[-1][1:] != nxt[j][1:]:
        cur.append(nxt[j])
    nxt = []
  r = -1
  for c,p,n in cur:
    if n == "":
      r = max(r,c)
  return r

if __name__ == "__main__":
  print(main())

      


Measured memory_bytes: 45788
# include <bits/stdc++.h>
# define ll long long int
# define pb push_back
# define pf push_front
# define mpi make_pair
# define pi pair<ll,ll>
# define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
# define mod 1000000007
# define endl "\n"
using namespace std;
int main()
{
	fast
	ll n,ct=0;
	cin>>n;
	vector <ll> v;
	for(ll i=0;i<n;i++)
	{
		ll x;
		cin>>x;
		v.pb(x);
	}
	for(ll i=0;i<n;i++)
	{
		if(v[i]!=i+1)
		{
			ct++;
		}
	}
	if(ct<=2)
	{
		cout<<"YES";
	}
	else
	{
		cout<<"NO";
	}
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
N,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(N)]
dp=defaultdict(int)
dp[0]=0
for w,v in items:
  for tw,tv in list(dp.items()):
    if tw+w<=W:
      dp[tw+w]=max(tv+v,dp[tw+w])
print(max(dp.values()))

Measured memory_bytes: 3944
while True:
    a = input()
    b = a.split()
    x = int(b[0])
    y = int(b[1])
    if x == 0 and y == 0 :
        break
    else:
        for i in range(x):
            if i%2 == 0:
                for k in range(y):
                    if k%2 == 0 :
                        print("#",end="")
                    else:
                        print(".",end="")
            else:
                for j in range(y):
                    if j%2 == 0:
                        print(".",end="")
                    else:
                        print("#",end="")
            print()    
    print()


Measured memory_bytes: 7000
#include <iostream>
using namespace std;
int a[200];
int b[200];
int pollock[1000001];
int oddpollock[1000001];
int n,count;

void f(){
	count=1;
	b[0]=1;
	a[0]=1;
	for(int i=1;i<200;i++){
		a[i]=a[i-1]*(i+3)/i;
		if(a[i]%2==1){
			b[count]=a[i];
			count++;
		}
	}
}

int main(){
	f();
	pollock[0]=oddpollock[0]=0;
	pollock[1]=oddpollock[1]=1;
	for(int i=2;i<1000000;i++){
		pollock[i]=pollock[i-1]+1;
		for(int j=1;i>=a[j];j++){
			if(pollock[i]>pollock[i-a[j]]+1)pollock[i]=pollock[i-a[j]]+1;
		}
	}
	for(int i=2;i<1000000;i++){
		oddpollock[i]=oddpollock[i-1]+1;
		for(int j=1;i>=b[j];j++){
			if(oddpollock[i]>oddpollock[i-b[j]]+1)oddpollock[i]=oddpollock[i-b[j]]+1;
		}
	}
	while(1){
		cin >>n;
		if(n==0)break;
		cout <<pollock[n] <<" " <<oddpollock[n] <<endl;
	}
}

Measured memory_bytes: 10888
main = do
    text <- getLine 
    num <- getLine 
    let num_i = read num :: Int
    let (firstNum, firstCheck) = check text False
    --     then putStrLn $ text ++ " " ++ (show num_i) ++ (show $ check text False)
--     putStrLn $ text ++ " " ++ (show num_i) ++ (show firstNum) ++ (show firstCheck) 
    if num_i == 1
         then putStrLn $ show firstNum
         else putStrLn $ show $ mainSecond text firstCheck firstNum num_i
    -- putStrLn (num1 + num2 + num3) ++ text


mainSecond :: [Char] -> Bool -> Int -> Int -> Int
-- 2回目が最後に変更した場合は、次は一つ目を変更しないパターンに戻る
mainSecond text firstCheck firstNum num = if secondCheck == True
            then firstNum * (num - halfNum) + secondNum * halfNum
            else firstNum + secondNum * (num - 1)
    where
        -- 最後の文字と最初が同じかどうか
        lastCheck = (text !! 0 == text !! (length text  -1))
        -- 最後の1文字を置換してなくて、最初と最後の文字が同じ場合は、最初の1文字目を置換する）
        (secondNum, secondCheck) = if firstCheck == False && lastCheck 
            then check text True
            else check text False
        halfNum = div num 2


-- check :: [Char] -> Maybe Int -> Int
-- 畳み込みたいけど、一回前の状態が必要だから厳しいな・・
-- 先頭の1文字を置換する、まず件数を1増やして、チェックは2文字目から行う
-- 最後の文字を置換したかどうかが知りたいために複雑になった。。
check :: [Char] -> Bool -> (Int, Bool)
check word skip 
    | skip == True = if wordlen == 1
        then (1, True)
        else checkLoop word wordlen 1 False 1
    | otherwise = if wordlen == 1
        then (0, False)
        else checkLoop word wordlen 0 False 0
    where wordlen = length word
--            let (checkNum, checkBool) =  ()
--            in (checkNum + 1, checkBool)

-- 一回前がTrueだったらFalseを返す
checkLoop :: [Char] -> Int -> Int -> Bool -> Int-> (Int, Bool)
checkLoop word wordlen index last lastNum
    -- 2文字のチェックだから +2 した数の一つ前までチェックする
    | (index + 2) >= wordlen = (thisNum, thisCheck)
    | otherwise =  checkLoop word wordlen (index + 1) thisCheck thisNum
    -- last がTrueだったら今回はチェックしない
    where thisCheck = if last == True 
                then False 
                else checkIndex word index
          thisNum = if thisCheck == True 
                    then 1 + lastNum
                    else lastNum

-- 指定文字と次の文字を比較する
checkIndex :: [Char] -> Int -> Bool
checkIndex word index = if word1 == word2
                        then True
                        else False
    where 
        word1 = word !! index 
        word2 = word !! (index + 1)



Measured memory_bytes: 508