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

#define forn(i,m,n) for(int i=m;i<n;i++)
#define vv vector
#define vi vv<int>
#define ii pair<int,int>
#define vii vv<ii>
#define mp make_pair
#define pb push_back
#define PI 3.141592653589
#define ll long long
#define pll pair<ll,ll>
#define vl vv<ll>
#define ff first
#define ss second
#define MOD 1000000007

bool is_prime[1000001];
vi prime;
void sieve(int n)
{
    memset(is_prime,true,sizeof(is_prime));
    for(int i=2;i*i<=n;i++)
    {
        if(is_prime[i])
        {
            for(int j=i*i;j<=n;j+=i)
            {
                is_prime[j]=false;
            }
        }
    }
    forn(i,2,n+1)
    {
        if(is_prime[i])
            prime.pb(i);
    }
}


ll ex(ll a,ll b)
{
    ll res=1;
    a=a%MOD;
    while(b)
    {
        if(b%2){res=(res*a)%MOD;b--;}
        b/=2;
        a=(a*a)%MOD;
    }
    return res;
}

ll fermat_inv(ll a){ return ex(a,MOD-2); }



int main()
{
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif
    //sieve(1000000);
    int te=1;
    //cin>>te;
    while(te--)
    {

        
        int n;
        cin>>n;
        int a[n];
        forn(i,0,n)
        {
            cin>>a[i];
        }
        int dp[n];
        dp[0]=0;
        dp[1]=abs(a[0]-a[1]);
        forn(i,2,n)
        {
            dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
        }
        cout<<dp[n-1];
    }
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 998244353;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	int N;
	cin >> N;
	int a, b, c;
	int ans = 0;
	int maesum = 0, atosum = 0;
	priority_queue<int> mae;
	priority_queue<int, vector<int>, greater<int>> ato;
	rep(i,N){
		cin >> a;
		if(a == 1){
			cin >> b >> c;
			ans += c;
			if(mae.size() > ato.size()){
				int x = mae.top();
				if(x > b){
					mae.push(b);
					mae.pop();
					maesum += b-x;
					ato.push(x);
					atosum += x;
				}
				else{
					ato.push(b);
					atosum += b;
				}
			}
			else{
				if(mae.size() == 0){
					mae.push(b);
					maesum += b;
					continue;
				}
				int x = mae.top();
				if(x > b){
					mae.push(b);
					maesum += b;
				}
				else{
					ato.push(b);
					int y = ato.top();
					ato.pop();
					atosum += b-y;
					mae.push(y);
					maesum += y;
				}
			}
		}
		else{
			int x = mae.top();
			cout << x << " " << ans + x * (int)mae.size() - maesum + atosum - x * (int)ato.size() << endl;
		}
	}
 }

Measured memory_bytes: 3828
N = int(input())
A = list(map(int, input().split()))
B = [0]*(N+1)
for i in range(N, 0, -1):
    B[i] = sum(B[x] for x in range(i, N+1, i)) % 2 != A[i-1]
print(sum(B))
print(*[i for i, v in enumerate(B) if v])

Measured memory_bytes: 101680
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long ll;

int main(){
  string S;
  cin >> S;
  
  int k = S.size();
  int res = 1;
  string s1 = S.substr(0,1);
  //cout << "s1 = " << s1 << endl;
  for (int i = 1; i < k; i++){
    //cout << "i=" << i;
    for (int j = 1; i + j <= k; j++){
      string s2 = S.substr(i,j);
      if (s1 != s2) {
        //cout << ",s2=" << s2  << ",j=" << j << endl;
        res++;
        i = i + j - 1;
        s1 = s2;
        break;
      }
    }
  }
  cout << res;
  
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> pos(n);
    vector<int> v(n);
    iota(v.begin(), v.end(), 0);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        pos[i] = make_pair(x, y);
    }
    double ans = 0;
    long cnt = 0;
    do {
        for (int i = 0; i < v.size() - 1; i++) {
            pair<int, int>& p1 = pos[v[i]];
            pair<int, int>& p2 = pos[v[i + 1]];
            ans += sqrt(pow(p1.first - p2.first, 2) + pow(p1.second - p2.second, 2));
        }
        cnt++;
    } while (next_permutation(v.begin(), v.end()));
    cout << setprecision(10) << fixed << ans / cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,f[3][102];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&f[i][j]);
	for(int i=1;i<=n;i++)
		f[1][i]+=f[1][i-1]; 
	for(int i=1;i<=n;i++)
		f[2][i]+=max(f[2][i-1],f[1][i]);
	printf("%d",f[2][n]);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
    int n,i,a=0,b=0,k1,k2,n1=0,n2=0,ans1,ans2;
    cin>>n;
    int m1[n];
    int m2[n];
    for(i=0;i<n;i++)
    {
        cin>>m1[i];
        n1=n1*10+m1[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>m2[i];
        n2=n2*10+m2[i];
    }
    sort(m1,m1+n);
    sort(m2,m2+n);
    for(i=0;i<n;i++)
    {
        a=a*10+m1[i];
    }
    k1=a;
    for(i=1;i<n;i++)
    {
        b=b*10+m2[i];
    }

    long long fact=1;
    for(i=1;i<=n;i++)
    {
        fact=fact*i;
    }
    map<int,int>mp1;
    map<int,int>mp2;
    mp1.insert({k1,1});
    for(i=2;i<=fact;i++)
    {
        next_permutation(m1,m1+n);
        a=0;
        for(int j=0;j<n;j++)
        {
            a=a*10+m1[j];
        }
        mp1.insert({a,i});
    }
    for(auto i:mp1)
    {
        if(i.first==n1)
        {
             ans1=i.second;
        }
        if(i.first==n2)
        {
             ans2=i.second;
        }
    }
    cout<<abs(ans2-ans1)<<endl;
    return 0;

}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int f(int nn){
  int n=nn;
  int t=0;
  while(n){
    int pc = __builtin_popcount(n);
    n%=pc;
    t++;
  }
  return t;
}

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

  int pc=0;
  for(auto c:s)if(c=='1')pc++;
  
  int pc0=pc+1;
  int pc1=pc-1;

  vector<int>pow2_pc1(n);
  int s1=0;
  if(pc>=2){
    int t1=1;
    rep(i, n){
      int ci = n-1-i;
      pow2_pc1[ci]=t1%pc1;
      t1 = t1*2%pc1;
    }
    int t=1;
    rrep(i, n){
      if(s[i]=='1')s1 = (s1+t)%pc1;
      t = t*2%pc1;
    }
  }


  vector<int>pow2_pc0(n);
  int s0=0;
  int t0=1;
  int t=1;

  rep(i, n){
    int ci = n-1-i;
    pow2_pc0[ci]=t0%pc0;
    t0 = t0*2%pc0;
  }

  rrep(i, n){
    if(s[i]=='1')s0 = (s0+t)%pc0;
    t = t*2%pc0;
  }

  
  rep(i, n){
    int ci = n-1-i;
    if(s[i]=='1'){
//            cout<<'u';
      int tmp = s1-pow2_pc1[i];
      if(pc<=1)cout<<0<<endl;
      else cout<<f((tmp+pc1)%pc1)+1<<endl;
    }else{
      int tmp = (s0+pow2_pc0[i])%pc0;

//      cout<<'d';
//      cout<<tmp<<' '<<s0<<' '<<pow2_pc0[i]<<'('<<i<<')';

      cout<<f(tmp)+1<<endl;
    }
  }

  return 0;

  cout<<"---"<<endl;
  cout<<pc0<<' '<<pc1<<' '<<s1<<' '<<s0<<endl;
  rep(i, n)cout<<pow2_pc1[i]<<' ';cout<<endl;
  rep(i, n)cout<<pow2_pc0[i]<<' ';cout<<endl;
  
  rep(i, n)cout<<s[i];cout<<endl;

  return 0;
}

Measured memory_bytes: 5200
N = int(input())
p = list(map(int,input().split()))

ans = False
for i in range(N-1):
    for j in range(i,N):
        q = p.copy()
        q[i],q[j] = q[j],q[i]

        for n in range(1,N):
            if q[n-1]>=q[n]:
                break
        else:
            ans = True

print('YES' if ans else 'NO')


Measured memory_bytes: 3060
#include <cstdio>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <tuple>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long int ll;
using namespace std;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
 
int main()
{
	int ans = 0;
	int n;
	int love[100002] = {};
	cin >> n;
	
	REP(i,n)
	{
		cin >> love[i];
		love[i]--;
		if(i != 0 && love[love[i]] == i)
		ans ++;
	}
	
	cout << ans << endl;
	return 0 ;
}

Measured memory_bytes: 640
fun main(arg: Array<String>) {
    val N = nextInt()
    val A = listOfLong()
    val T = A.sum()
    var X = 0L
    var ans = Long.MAX_VALUE
    for (n in 0 until N - 1) {
        X += A[n]
        ans = Math.min(ans, Math.abs(X - (T - X)))
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong() = listOfString().map(String::toLong)



Measured memory_bytes: 82440
n = int(input())
li = list(input())

R = li.count("R")
G = li.count("G")
B = li.count("B")

cnt = 0

for i in range(n-1):
    for j in range(i+1, n):
        if 2*j - i > n-1:
            continue
        if li[i] != li[j]:
            if li[2*j-i] != li[i] and li[2*j-i] != li[j]:
                cnt += 1
print(R*G*B - cnt)

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50
int n;
vi link(100001);
vi sz(100001);

int fd(int i)
{
    while(i != link[i])
    {
        i = link[i];
    }
    return i;
}

bool same(int a, int b)
{
    return fd(a) == fd(b);
}

void unite(int a, int b)
{
    a = fd(a);
    b = fd(b);
    if(sz[a] < sz[b])
    {
        swap(a, b);
    }
    sz[a] += sz[b];
    link[b] = a;
}

int main()
{
    cin >> n;
    vp xco(n), yco(n);
    for(int i = 0 ; i < n; i++)
    {
       int x, y;
       cin >> x >> y;
       xco[i] = make_pair(x, i+1);
       yco[i] = make_pair(y, i+1);
    }
    sort(xco.begin(), xco.end());
    sort(yco.begin(), yco.end());

    vector<tuple<int, int, int>> edgelist;

    for(int i = 1; i < n ; i++)
    {
        edgelist.pb(make_tuple(xco[i].first - xco[i-1].first, xco[i-1].second, xco[i].second));
        edgelist.pb(make_tuple(yco[i].first - yco[i-1].first, yco[i-1].second, yco[i].second));
    }

    sort(edgelist.begin(), edgelist.end());


    for(int i = 1; i <= n; i++)
    {
        link[i] = i;
    }

    for(int i = 1; i <= n; i++)
    {
        sz[i] = 1;
    }
    ll ans = 0;
    for(int i = 0; i < edgelist.size(); i++)
    {
        int x, a, b;
        tie(x, a, b) = edgelist[i];
        if(!same(a, b))
        {
            unite(a, b);
            ans += x;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 7284
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n;
	ll x[100005] = {};
	ll y[100005] = {};
	ll z[100005] = {};
	cin >> a;
	for (int i = 0; i < a; i++)
	{
		cin >> x[i];
	}
	sort(x, x + a);
	for (int i = 0; i < a; i++)
	{
		b = x[i];
		c = 0;
		while (b==x[i])
		{
			i++;
			c++;
		}
		if (c<b)
		{
			ans += c;
		}
		else
		{
			ans += c - b;
		}
		i--;
	}
	cout << ans << endl;


	return 0;


	//cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n;
    scanf("%d%d",&m,&n);
    if(m*10000<n)
	{
        printf("-1 -1 -1");
        return 0;
    }
    if(m*1000>n)
	{
        printf("-1 -1 -1");
        return 0;
    }
    if(n%1000!=0)
	{
        printf("-1 -1 -1");
        return 0;
    }
    for(int i=0;i<=m;i++)
     	for(int j=0;j<=m;j++)
     		for(int k=0;i+j+k<=m;k++)
	    	{
	            if(i+j+k==m && i*1000+j*5000+k*10000==n)
	            {
	                printf("%d %d %d",k,j,i);
	                return 0;   
	            }
	       }
    printf("-1 -1 -1");
    return 0;
}

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

int main(){
int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  int ans=1;
  
  for(int i=0;i<N-1;i++){
    if(A.at(i)!=A.at(i+1)){
      ans++;
    }
  }
  cout<<ans<<endl;
}
    

Measured memory_bytes: 3644
////#include<bits/stdc++.h>
//#include<algorithm>
//#include<stdio.h>
//#include<math.h>
//using namespace std;
//#define pi acos(-1.0)
//double r,R,h,v,hh;
//int panduan(double h1)
//{
//    double rr=((hh-h1)/hh)*R;
//    double V=pi*(rr*rr+R*R+rr*R)*h1/3.0;
//    if(V>=v)
//        return 0;
//    else
//        return 1;
//}
//int main()
//{
//    int t;
//    scanf("%d",&t);
//    while(t--)
//    {
//        scanf("%lf %lf %lf %lf",&r,&R,&h,&v);
//        if(r-R<1e-5)
//        {
////            printf("%.6lf\n",pi);
////            printf("%.6lf\n",r*r);
//            printf("%.6lf\n",v/(pi*r*r));
////            printf("1\n");
//            continue;
//        }
//        hh=h+(h*r)/(R-r);
//        double l=1,r=100,mid;
//        while(r-l>1e-9)
//        {
//            mid=(r+l)/2.0;
//            if(panduan(mid))
//            {
//                l=mid;
//            }
//            else
//                r=mid;
//        }
//        printf("%.6lf\n",l);
//    }
//}
#include<stdio.h>
#include<algorithm>
using namespace std;
int q[100010];
int main()
{
    int n,c,k;
    scanf("%d%d%d",&n,&c,&k);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&q[i]);
    }
    sort(q,q+n);
    int qidian=q[0];
    int zhongdian=qidian+k;
    int sum=1,ans=1;
    for(int i=1; i<n; i++)
    {
        if(q[i]>=qidian&&q[i]<=zhongdian&&sum<c)
        {
            sum++;

        }
        else
        {
            ans++;

            qidian=q[i];
//            printf("%d\n",qidian);
            zhongdian=qidian+k;

            sum=1;
        }
    }
    printf("%d\n",ans);
}


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

int main(void){
    int n;
    cin>>n;
    vector<int>h(n),dp(n,0);
    for(int i=0;i<n;i++)cin>>h[i];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
    }
    cout<<dp[n-1]<<endl;
    
    
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <math.h>

int id(char *);
void insert(char *);
void find(char *);

int dic[22369621]={0};

int main(void)
{
	int i, n;
	char op[7], str[13];
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%s %s",op,str);
		if( strcmp(op, "insert") == 0 ) {
			insert(str);
		} else if( strcmp(op, "find") == 0 ) {
			find(str);
		}
	}
	
	return 0;
}

int id(char *str)
{
	int i;
	int id=0;
	
	i = 0;
	while (1) {
		if(str[i] == '\0') break;
		switch (str[i]) {
		case 'A':
			id += (int)pow(4,i) * 1;
			break;
		case 'C':
			id += (int)pow(4,i) * 2;
			break;
		case 'G':
			id += (int)pow(4,i) * 3;
			break;
		case 'T':
			id += (int)pow(4,i) * 4;
			break;
		}
	i++;
	}
	return id;
}

void insert(char *str)
{
	dic[id(str)] = 1;
}

void find(char *str)
{
	if(dic[id(str)]) {
		printf("yes\n");
	} else {
		printf("no\n");
	}
}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

inline ll calc(ll val, ll mx, ll l, ll r, vector<ll> a) {
    if (a[l] * val >= mx) return 0;
    ll tmp = l;
    while (r - l > 1) {
        ll m = (r + l) / 2;
        if (a[m] * val < mx)
            l = m;
        else
            r = m;
    }
    return l + 1 - tmp;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> an, ap, ze;
    rep(i, 0, n) {
        ll a;
        cin >> a;
        if (a > 0)
            ap.emplace_back(a);
        else if (a < 0)
            an.emplace_back(-a);
        else
            ze.emplace_back(a);
    }
    sort(an.begin(), an.end());
    sort(ap.begin(), ap.end());
    ll neg = (ll)ap.size() * an.size();
    ll pos = (ll)ap.size() * (ap.size() - 1) / 2 + (ll)an.size() * (an.size() - 1) / 2;
    ll zero = (n - ze.size()) * ze.size() + (ll)ze.size() * (ze.size() - 1) / 2;
    debug(neg, zero, pos);
    debug(an.size(), ap.size(), ze.size());
    if (neg < k && k <= neg + zero) {
        cout << 0 << endl;
        return 0;
    }
    if (k <= neg) {
        k = neg + 1 - k;
        ll lx = 0, rx = (ll)1.1e18;
        while (rx - lx > 1) {
            ll mid = (rx + lx) / 2;
            ll cnt = 0;
            rep(i, 0, (int)an.size()) {
                // ll tx = calc(an[i], mid, 0, ap.size(), ap);
                ll t = lower_bound(ap.begin(), ap.end(), (mid + an[i] - 1) / an[i]) - ap.begin();
                // if (t != tx) debug(t, tx);
                if (t)
                    cnt += t;
                else
                    break;
            }
            debug(mid, cnt);
            if (cnt < k)
                lx = mid;
            else
                rx = mid;
        }
        cout << -lx << endl;
    } else {
        k -= neg + zero;
        debug(k);
        ll lx = 0, rx = (ll)1.1e18;
        while (rx - lx > 1) {
            ll mid = (lx + rx) / 2, cnt = 0;
            rep(i, 1, (int)ap.size()) {
                // ll tx = calc(ap[i], mid, 0, i, ap);
                ll t = lower_bound(ap.begin(), ap.end(), (mid + ap[i] - 1) / ap[i]) - ap.begin();
                t = min(t, (ll)i);
                if (t)
                    cnt += t;
                else
                    break;
            }
            rep(i, 1, (int)an.size()) {
                // ll tx = calc(an[i], mid, 0, i, an);
                ll t = lower_bound(an.begin(), an.end(), (mid + an[i] - 1) / an[i]) - an.begin();
                t = min(t, (ll)i);
                if (t)
                    cnt += t;
                else
                    break;
            }
            debug(mid, cnt);
            if (cnt < k)
                lx = mid;
            else
                rx = mid;
        }
        cout << lx << endl;
    }
    //debug
    //vector<ll> zz;
    //rep(i, 0, n) rep(j, i + 1, n) zz.emplace_back(aa[i] * aa[j]);
    //sort(zz.begin(), zz.end());
    //debug(zz);

    return 0;
}


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

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

  for (int i = 1; i <= 9; i++)
  {
    for (int j = 1; j <= 9; j++)
    {
      if (i * j == n)
      {
        cout << "Yes";
        return 0;
      }
    }
  }

  cout << "No";
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MOD = 1e9+7, MX = 1e6+5;
int x,y,z;
ll exp(ll b, ll n){
	ll res = 1;
	for(; n; n/=2,(b*=b)%=MOD) if(n%2) (res *= b) %= MOD;
	return res;
}
ll fact[MX] = {1}, invf[MX];
void setcomb(int n){
	for(int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % MOD;
	invf[n] =  exp(fact[n] ,MOD-2);
	for(int i = n; i > 0; i--) invf[i-1] = (invf[i] * i) % MOD;
}
inline ll comb(int a, int b){return fact[a] * invf[a-b] % MOD * invf[b] % MOD;}
int main(){
	scanf("%d%d", &x, &y);
	if((x+y)%3) return 0*puts("0");
	z = (x+y)/3;
	x -= z; y -= z;
	setcomb(z);
	printf("%lld\n", comb(z,x));
}

Measured memory_bytes: 12032
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <utility>
#include <functional>
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int a[400000];
int n;
ll K, L;

bool C(int t) {
	ll sum = 0;
	int g = 0;
	int cnt = 0;
	rep(i, n) {
		while (g < n&&cnt < K) {
			if (a[g] <= t)cnt++;
			g++;
		}
		if (cnt >= K) {
			sum += n - g + 1;
		}
		if (a[i] <= t)cnt--;
	}
	return sum >= L;
}
int main() {
	cin >> n >> K >> L;
	rep(i, n)scanf("%d", &a[i]);
	int ok = n, ng = 0;
	while (ok - ng > 1) {
		int t = (ok + ng) / 2;
		if (C(t))ok = t;
		else ng = t;
	}
	cout << ok << endl;
}


Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace   std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define double    long double
#define ull       unsigned long long
#define mod       1000000007
#define vi        vector<ll>
#define extreme   inline
#define ppi       pair<ll,pair<ll,ll>>
#define pb        push_back
#define mp        make_pair
#define pi        2*acos(0.0)
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define p(a)      cout<<a;
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define test      cout<<"THIS_AND_THIS"<<endl;
#define str       string
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll a,b;cin>>a>>b;
	ll c=(a+b);
	if(c%2==0){cout<<c/2;}
	else{cout<<"IMPOSSIBLE";}
}
int32_t main(){
	kehsihba();
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}






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

using namespace std;

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

    int t;
    cin >> t;
    
    bool flag = 0;

    deque<char> q;
    
    for (char x: s)
        q.push_back(x);

    while(t--) {
        int c;
        cin >> c;
        if(c == 1) flag = !flag;
        else {
            int x;
            char y;
            cin >> x >> y;
            if(x == 1) {
                if(!flag) q.push_front(y);
                else q.push_back(y);
            } else {
                if(flag) q.push_front(y);
                else q.push_back(y);
            }
        }
    }

    string ans = "";

    while(!q.empty()) {
        ans += q.front();
        q.pop_front();
    }

    if(flag) reverse(ans.begin(), ans.end());
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1412
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=200005;
long long sum,a[N],n,l=1,r=1,tmp=0;
int main() {
	scanf("%lld",&n);
	for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
	while(r<=n) {
		while( ( (a[r]^tmp) == (a[r]+tmp) )&& r<=n) tmp^=a[r],r++;
		if(r!=n+1) sum+=r-l;
		else sum+=(r-l)*(r-l+1)/2;
		tmp^=a[l++];
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N;
	vector<int> ans;
	cin >> N;

	vector<int> b(N);
	rep(i, N) cin >> b[i];

	rep(i, N) {
		int index = 0;

		rrep(j, (int)b.size()) {
			if (b[j] == j + 1) {
				index = j;
				break;
			}
			if (j == 0) {
				cout << -1 << endl;
				return 0;
			}
		}

		ans.push_back(b[index]);

		vector<int>::iterator it = b.begin();
		rep(loop, index) it++;
		b.erase(it);
	}

	rrep(i, N) cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N = INT()
print(N*(N+1)//2)

Measured memory_bytes: 5144
n=int(input())
a=[int(i) for i in input().split()]
ans,l,r=[0]*3
ss,xs=[0],[0]
for i in a:
    ss.append(ss[-1]+i)
for i in a:
    xs.append(xs[-1]^i)
    
while l<n:
    if r<n and ss[r+1]-ss[l]==(xs[r+1]^xs[l]):
        r+=1
    else:
        ans+=r-l
        l+=1

print(ans)


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

long long f(long long n, long long a, long long b) {
	if (a > b) return 0;
	if (a == b) return 1;
	if (n < 2) return 0;
	return (n - 2) * (b - a) + 1;
}

int main() {
	int n, a, b; cin >> n >> a >> b;
	cout << f(n, a, b) << endl;
	return 0;
}


Measured memory_bytes: 256
A,B=tuple(map(int,input().split()))
if A-1>=B:
    print(A*2-1)
elif B-1>=A:
    print(B*2-1)
elif A==B+1 or B==A+1:
    print(max(A,B)+min(A,B))
else:
    print(2*A)

Measured memory_bytes: 3060
from itertools import permutations

N = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))

P = []
for perm in permutations(range(1, N + 1), r=N):
    P.append(tuple(perm))

P.sort()
print(abs(P.index(A) - P.index(B)))

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

const int INF = 1e9;
const int MOD = 998244353;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

ll dp[3001][3001];

int main()
{
    int n, s;
    cin >> n >> s;
    vector<int> vi(n);
    REP(i, n)
    cin >> vi[i];
    dp[0][0]=1;
    FOR(i,1,n+1) {
        REP(j,s+1){
            dp[i][j]=dp[i-1][j];
            if(j-vi[i-1]>0)
            dp[i][j]+=dp[i-1][j-vi[i-1]];
            if(j-vi[i-1]==0)
            dp[i][j]+=dp[i-1][j-vi[i-1]]*(i);
            dp[i][j]%=MOD;
        }
    }
    ll ans=0;
    FOR(i,1,n+1){
        ans+=(dp[i][s]-dp[i-1][s])*(n-i+1)+(ll)MOD*3002LL;
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 73960
#include<bits/stdc++.h>
using namespace std;
int main(){
  int S;
  cin>>S;
  set<int>st;
  int x=S;
  while(st.count(x)==0){
    st.insert(x);
    if(x%2==0){
      x/=2;
    }
    else{
      x=x*3+1;
    }
  }
  cout<<(st.size()+1)<<endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
  int N;
  cin >> N;
  bool flag = 0;
  for (int i=1; i<10; i++){
    if(N%i==0 && N/i<10){
      flag = 1;
    }
  }
    if(flag){
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}


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

n, m = map(int,input().split())
s = [0] #累積和
a = list(map(int,input().split()))
for i in range(n):
    s.append(s[i]+a[i])

mod = {} 
for i in s:
    if i%m in mod:
        mod[i%m] += 1
    else:
        mod[i%m] = 1

ans = 0
for i in mod:
    j = mod[i]
    ans += j*(j-1)//2

print(ans)

Measured memory_bytes: 17284
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

vector<int> a;
vector<vector<int>> s;
vector<int> l;
vector<int> ans;

void search(int u, int par){
  //cout<<par<<u<<endl;
  for(int v:s[u]){
    if(v==par) continue;
    if(a[v]>l.back()){
      l.push_back(a[v]);
      ans[v]=l.size();
      search(v,u);
      l.pop_back();
    }else{
      auto pos=lower_bound(l.begin(), l.end(), a[v]);
      int pre=*pos;
      *pos=a[v];
      ans[v]=l.size();
      search(v,u);
      *pos=pre;
    }
  }
}

void app() {
  int n;
  cin>>n;

  a.reserve(n);
  rep(i,n){
    cin>>a[i];
  }

  s.reserve(n);
  rep(i,n-1){
    int u,v;
    cin>>u>>v;
    u--;v--;
    s[u].push_back(v);
    s[v].push_back(u);
  }

  l.reserve(n);
  ans.reserve(n);
  l.push_back(a[0]);
  ans[0]=1;
  search(0,-1);

  rep(i,n){
    cout<<ans[i]<<endl;
  }
}

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


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

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

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義 #define int long long
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; }
//lambda: [&](int x, int y){return x<y;}

string solve(string s,string t){
    for(int i=s.size()-t.size();i>=0;--i){
        bool p=true;
        rep(j,t.size()){
            p&=(s[i+j]==t[j]||s[i+j]=='?');
        }
        if(!p)continue;
        rep(j,s.size()){
            if(j<i||i+t.size()<=j)s[j]=max('a',s[j]);
            else s[j]=t[j-i];
        }
        return s;
    }
    return "UNRESTORABLE";
}

signed main(void){
    string s,t;cin>>s>>t;
    cout << solve(s,t) << endl;

}


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

int main(void) {
	char num[1000][1010];
	int jump;
	int outnum[100] = {};

	for (int i = 1; i <= 2000; i++) {
		cin >> num[i];
		if (num[i][0] == '0') {
			jump = i;
			break;
		}
	}
	for (int t = 1; t < jump; t++) {
		for (int u = 0; u <= 2000; u++) {
			if (num[t][u] == '\0') {
				cout << outnum[t] << "\n";
				break;
			}
			outnum[t] += num[t][u]-48;
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n, q;
    string s;
    cin >> n >> q >> s;

    int rui[n];
    rep(i, n) {
        rui[i] = 0;
    }

    for(int i = 1; i < n; i++) {
        rui[i] = rui[i-1];
        if(s[i-1] == 'A' && s[i] == 'C') {
            rui[i]++;
        }
    }

    int ans[q];
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        l--;  r--;
        ans[i] = rui[r] - rui[l];
    }

    rep(i, q) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 1920
#define dbg(...) ; 
#define db(...) ; 
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define tst cout<<'*';
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mod 1000000007
using namespace std;
 
int n,k,ar[105],dp[100005][2],mn;

int fun(int rem, int x)
{
    dbg(rem,x);
    int i;
    if(rem<mn)
        return (x+1)%2;
    if(dp[rem][x]!=-1)
        return dp[rem][x];

    dp[rem][x]=(x+1)%2;

    f(i,0,n)
    {
    	if(ar[i] <= rem){
        	dp[rem][1]=max(dp[rem][1],fun(rem-ar[i],0));
        	dp[rem][0]=min(dp[rem][0],fun(rem-ar[i],1));
    	}
    }

    return dp[rem][x];
}

int main()
{
    fast;
    int i;
    cin>>n>>k;
    f(i,0,n)
        cin>>ar[i];
    mn=*min_element(ar,ar+n);
    memset(dp,-1,sizeof(dp));
    (fun(k,1))?cout<<"First":cout<<"Second";
    db(dp,0,k,0,2);
}

Measured memory_bytes: 10640
#include<iostream>
#include<queue>
using namespace std;
#define max 100

int n;
int aa[max][max];
int ans[max];
int color[max];
int p[max];
queue<int> q;

void bfs(int u) {
	for (int i = 0; i < n; i++) {
		if (aa[u - 1][i] == 1 && color[i] != 1) {
			q.push(i + 1);
			color[i] = 1;
			p[i] = u;
		}
	}
	while (!q.empty()) {
		int x = q.front(); q.pop();
		ans[x - 1] = ans[p[x-1]-1] + 1;
		bfs(x);
	}
}

int main()
{
	for (int i = 0; i < max; i++) {
		ans[i] = 0;
		color[i] = 0;
		p[i] = -1;
	}
	cin >> n;
	for (int i = 0; i < max; i++) {
		for (int j = 0; j < max; j++) {
			aa[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++) {
		int id;
		cin >> id;
		int num;
		cin >> num;
		for (int j = 0; j < num; j++) {
			int num1;
			cin >> num1;
			aa[id - 1][num1 - 1] = 1;
		}
	}

	bfs(1);

	for (int i = 0; i < n; i++) {
		cout << i + 1 << " ";
		if (i == 0) cout << "0" << endl;
		else if (ans[i] == 0) cout << "-1" << endl;
		else cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MIN / 2 + 1;
    ll n, w;
    cin >> n >> w;
    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, inf));
    dp[0][0] = 0;
    ll ans = 0;
    rep(i, n) {
        ll tv, tw;
        cin >> tv >> tw;
        rep(j, w + 1) {
            if (j < tw) {
                dp[i + 1][j] = dp[i][j];
            }
            else {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
                if (dp[i][j - tw] != inf) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - tw] + tv);
                if (dp[i + 1][j - tw] != inf) dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j - tw] + tv);
                ans = max(ans, dp[i + 1][j]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<long> v(87);
  v.at(0) = 2;
  v.at(1) = 1;
  if (n > 1) {
    for (int i = 2; i <= n; i++) v.at(i) = v.at(i - 1) + v.at(i - 2);
  }
  cout << v.at(n) << endl;

}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    acc = list(accumulate([0] + A))
    S = []
    for i in range(N):
        for j in range(i+1, N+1):
            S.append(acc[j] - acc[i])
    S.sort(reverse=True)
    ans = 0
    for t in range(41, -1, -1):
        cur = 0
        for i in range(N*(N+1)//2):
            if ans + 2**t & S[i] == ans + 2**t:
                cur += 1
            if K == cur:
                break
        if K <= cur:
            ans += 2**t
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 72444
import math
X=int(input())
def isPrime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
  

if X==2:
    print(2);exit()
else:
  if X%2==0:
    X+=1
      
while True:  
  if isPrime(X):
    print(X);exit()
  
  X+=2
  
  

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int A,B;
  cin >> A >> B;
  cout << (A+B)%24 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a[3];
  int temp;
  for(int i = 0; i < 3; i++) scanf("%d", &a[i]);
  for(int i = 0; i < 3; i++){
    for(int j = i + 1; j < 3; j++){
      if(a[i] < a[j]){
	temp = a[i];
	a[i] = a[j];
	a[j] = temp;
      }
    }
  }
  printf("%d\n", 10 * a[0] + a[1] + a[2]);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,f,n) for(int i=(f); (i) < (n); i++)
#define repe(i,f,n) for(int i=(f); (i) <= (n); i++)
using namespace std;

typedef long long ll;
ll INF = 1LL << 60;
ll MAX = 100010;

vector<int> check;

int
digit(ll val)
{
  int count = 0;
  while(val >= 1){
    val /= 10;
    count++;
  }
  return count;
}

int
main() 
{

  int k; cin >> k;
  queue<ll> lun;

  if(k <= 9){
    cout << k << endl;
    return 0;
  }

  rep(i, 1, 10) lun.push(i);

  int count = k - 9;
  while(count > 0){
    ll next = lun.front();
    lun.pop();
    rep(j, -1, 2){
      ll add = next % 10 + j;
      if(0 <= add && add <= 9){
        lun.push(next * 10 + add);
        count--;
        if(count <= 0) break;
      }
    }
  }

  cout << lun.back() << endl;



}




Measured memory_bytes: 4164
#include<bits/stdc++.h>
using namespace std;
//ofstream fout("output.txt");
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define en "\n"
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(0);
#define pi 4*atan(1)
#define f(n) for(int i=0;i<n;++i)
#define fab(a,b) for(int i=a;i<=b;++i)
#define fba(b,a) for(int i=b;i>=a;--i)
#define reset(a,x) memset(a,x,sizeof(a))
typedef pair<int,int> ipair;
typedef vector<int> vi;
ll a[150001],b[150001];
vector<ll>v;

int main()
{
    IOS
    cin.tie(0);
    string s1,s2;
    cin>>s1>>s2;
    s2.erase(s2.length()-1);

    if(s2==s1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;






    return 0;
}


Measured memory_bytes: 3644
S = input()

f = 0
while(1):
    #print(S)
    if len(S) <= 4:
        break
    if S[:5] == "dream":
        if len(S) == 5:
            f = 1
            break
        elif len(S) == 6:
            break
        if S[:7] == "dreamer":
            if len(S) == 7:
                f = 1
                break
            if S[7] != "a":
                S = S[7:]
                continue
            else:
                S = S[5:]
        else:
            S = S[5:]
    elif S[:5] == "erase":
        if len(S) == 5:
            f = 1
            break
        if S[:6] == "eraser":
            if len(S) == 6:
                f = 1
                break
            if S[6] != "a":
                S = S[6:]
                continue
            else:
                S = S[:5]
        else:
            S = S[5:]
    else:
        break

if f == 0:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3188
#include <stdio.h>
int A[2000001],B[2000001];
int main(void){ 
  
  int i,k=0,j,n,C[10001];

  scanf("%d",&n);
  for(j = 1 ; j <= n ; j++){
    scanf("%d",&A[j]);
  }
  for(j = 1 ; j <= n ; j++){
    if(A[j] > k){   
      k = A[j];
    }
  }
  
  for(i = 0 ; i <= k ; i++){
    C[i] = 0;
  }
  for(j = 1 ; j <= n ; j++){
    C[A[j]] = C[A[j]] + 1;
  }
  
  for(i = 0 ; i <= k ; i++){
    C[i] = C[i] + C[i-1];
  }
  
  for(j = n ; j >= 1 ; j--){
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]] - 1;
  }
  for(j = 1 ; j <= n ; j++){
    printf("%d",B[j]);
    if(j <= n-1){
      printf(" ");
    }
  }
  printf("\n");
  
  return 0;
}

Measured memory_bytes: 15000
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<bool> ban(10, false);
    for(int i=0; i<K; ++i) {
        int b;
        cin >> b;
        ban[b] = true;
    }
    for(int i=N; ; ++i) {
        string s = to_string(i);
        bool ok = true;
        for(int j=0; j<s.size(); ++j) {
            if(ban[s[j] - '0']) {
                ok = false;
                break;
            }
        }
        if(ok) {
            cout << s << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
const int maxx  = 3*1e5 , limit = 9*1e18 , MOD=1e9+7;
#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n';
int dp[50000];
int find(int sum){
    if(dp[sum] >= 0)return dp[sum];
    
    if(sum == 0)return 1;
    else if(sum < 0) return 0;
    
    int ans=0;
    for(int i  =3  ; i<= 2000 ; i ++ ){
        if(sum-i < 0)break;
        int val = find(sum-i);
        if(val > 0)
            dp[sum-i] = val;
        ans = (ans + val)%MOD;
    }
    
    return ans;
    
}
int32_t main(){
    boost;
    
    int a,b;
    cin>>a>>b;
    int p,q;
    cin>>p>>q;
    int ans1 = a*p;
    int ans2 = a*q;
    int ans3 = b*p;
    int ans4 = b*q;
    int res = max({ans1,ans2,ans3,ans4});
    cout<<res<<endl;
    
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	string S;
	cin >> S;
	int minimum = 753;
	for (int i = 0; i < S.size() - 2; i++) {
		int n = std::atoi(S.substr(i, 3).c_str());
		chmin(minimum, abs(753 - n));
	}
	cout << minimum << endl;
	return 0;
}

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

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

    int ans = 0;
    rep(i, s.size() - 1) if (s[i] != s[i + 1]) ans++;

    cout << ans << endl;
    return 0;
}


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


signed main(){
	int n;cin>>n;
	vector<int> a(n+1,0);
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<n;i++)a[i+1]+=a[i];
	map<int,int>cnt;
	for(auto&& w:a)cnt[w]++;
	int sum=0;
	for(auto&& w:cnt)sum+=w.second*(w.second-1)/2;
	cout<<sum<<endl;
//  	for(auto&& w:cnt)cerr<<w.first<<" "<<w.second<<endl;
  //	cerr<<endl;
  	//for(auto&& w:a)cerr<<w<<" ";
  
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    set<ll> s;
    rep(i, 0, n) {
        ll a;
        cin >> a;
        if (s.find(a) == s.end()) s.insert(a);
        else s.erase(a);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int a, b; cin >> a >> b;
	if (a < b) {
		cout << "a < b" << endl;
	} else if (a > b) {
		cout << "a > b" << endl;
	} else {
		cout << "a == b" << endl;
	}
}

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



Measured memory_bytes: 3208
while True:
    n=int(input())
    if n==0:
        break
    elif n==1:
        print(1) 
    else:
        B=[0]*(n+1)
        B[0]=1
        B[1]=1
        B[2]=2
        for i in range(3, n+1):
            B[i]=B[i-1]+B[i-2]+B[i-3]
        if B[n]%3650==0:
            print(B[n]//3650)
        else:
            print(B[n]//3650+1)


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

int Sum(vector<int>& x) {
    int ret = 0;
    for (auto i : x) ret += i;
    return ret;
}

int main() {
    vector<int> a(4), b(4);
    for (auto& i : a) cin >> i;
    for (auto& i : b) cin >> i;
    cout << max(Sum(a), Sum(b)) << endl;

    return 0;
}

Measured memory_bytes: 3072
/*
  AtCoder Beginner Contest 106
  C - To Infinity

  方針
    まず5000兆日という以上に大きな数字であることに着目する。
    i番目の文字S[i]に対して、5000兆日後はS[i]^{5*10^16}文字の長さになるため、
    S[i]が2以上であれば、10^18の範囲を超える。

  実装
    (1) S[0] != '1'のとき
      ans = S[0]
    (2) S[0] == '1'のとき
      if K文字目まで'1'
        ans = '1'
      else
        ans = '1'でなくなった位置の文字
      

    10^18であるため型に注意して実装する。
*/

#include<iostream>
#include<string>
using namespace std;

string S;
long long K;

int main() {
  cin >> S >> K;

  if (S[0] == '1') {
    for (long long i = 1; i < K; ++i) {
      if (S[i] != '1') {
        printf("%c\n", S[i]);
        return 0;
      }
    }
    printf("1\n");
  }
  else printf("%c\n", S[0]);

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int s, w;
		Scanner scan = new Scanner(System.in);

		s = scan.nextInt();
		w = scan.nextInt();

		if(s > w) {
			System.out.println("safe");
		} else {
			System.out.println("unsafe");
		}
	}

}


Measured memory_bytes: 26992