akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------



int main() {
   ll m,n,keta=0,wa=0;
   cin>>m;
   vll c(m),d(m);
   rep(i,m)cin>>c.at(i)>>d.at(i);
   rep(i,m){
       keta+=d.at(i);
       wa+=c.at(i)*d.at(i);
   }
   
   cout<<(keta-1)+(wa-1)/9<<endl;
   
   
}



Measured memory_bytes: 6408
s=(input())
a=s[:2]
b=s[2:]
A=0
B=0
if(1<=int(a)<=12):
  A=1
if(1<=int(b)<=12):
  B=1
if(A*B==1):
  print("AMBIGUOUS")
elif(A==1):
  print("MMYY")
elif(B==1):
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3064
#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 pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int mod=1000000007;
int n,m;
int ca,cb;
ll a[1001],b[1001];
set<ll> sa,sb;
int main(){
    cin>>n>>m;
    bool flag=false;
    rep(i,n){
        cin>>a[i];
        if(sa.count(a[i])==0) sa.insert(a[i]);
        else flag=true;
    }
    rep(i,m){
        cin>>b[i];
        if(sb.count(b[i])==0) sb.insert(b[i]);
        else flag=true;
    }
    if(flag){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    for(int i=n*m;i>=1;--i){
        int ac=sa.count(i),bc=sb.count(i);
        if(ac==0&&bc==0){
            ans*=(1ll*ca*cb-n*m+i);
        }
        else if(ac==0){
            ++cb;
            ans*=1ll*ca;
        }
        else if(bc==0){
            ++ca;
            ans*=1ll*cb;
        }
        else ++ca,++cb;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


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


int main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#define N (1<<18)
#define INF (1e9)
using namespace std;
vector<int> tree[N];
int n,d;

void Update(){
  for(int i=0;i<n;i++){
    int pos=i+N/2-1;
    while(pos){
      pos=(pos-1)/2;
      tree[pos].push_back(tree[i+N/2-1][1]);
    }
  }
  for(int i=0;i<N;i++) sort(tree[i].begin(),tree[i].end());
}


int Bynary_Search(int pos){
  int l=0,r=tree[pos].size(),m;
  while(l<r){
    m=(l+r)/2;
    if(d<=tree[pos][m]) r=m;
    else l=m+1;
  }
  int res=abs(d-tree[pos][l]);
  if(l!=0) res=min(res,abs(d-tree[pos][l-1]));
  return res;
}

int Find(int a,int b,int k,int l,int r){
  if(r<=a||b<=l) return INF;
  if(a<=l&&r<=b) return Bynary_Search(k);
  int vl=Find(a,b,k*2+1,l,(l+r)/2);
  int vr=Find(a,b,k*2+2,(l+r)/2,r);
  return min(vl,vr);
}

int main(){
  int a,q,l,r;
  cin>>n;
  for(int i=0;i<N;i++) tree[i].push_back(INF);
  for(int i=0;i<n;i++) scanf("%d",&a),tree[i+N/2-1].push_back(a);
  Update();
  cin>>q;
  while(q--){
    scanf("%d%d%d",&l,&r,&d);
    printf("%d\n",Find(l,++r,0,0,N/2));
  }
  return 0;
}


Measured memory_bytes: 26776
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  string S;
  cin >> S;
  fin(S[2]==S[3] && S[4]==S[5] ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
// #include <set>
// #include <cmath>
// #include <map>
// #include <iomanip>

#define MOD 1000000007

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;

// void p() {
//     cout << "\n";
// }
// template<class Head, class... Body>
// void p(Head head, Body... body) {
//     cout << head << ",";
//     p(body...);
// }


int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    for (int j = 0; j < m; ++j) {
        cin >> y[j];
    }

    ll s1 = 0;
    for (int i = 0; i < n-1; ++i) {
        s1 = (s1 + (x[i+1] - x[i]) * (i+1)*(n-i-1)) % MOD;
    }
    ll s2 = 0;
    for (int j = 0; j < m-1; ++j) {
        s2 = (s2 + (y[j+1] - y[j]) * (j+1)*(m-j-1)) % MOD;
    }

    ll ans = (s1 * s2) % MOD;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,x,l[10000],i,d=0;
    memset(l,0,sizeof(l));
    cin >> n >> x;
    for(i=0;i<n;i++)
    {
        cin >> l[i];
    }
    for(i=0;i<n;i++)
    {
        d+=l[i];
        if(d == x)
        {
            cout << i+2;
            break;
        }
        else if(d > x)
        {
            cout << i+1;
            break;
        }
    }
    if(d<x)
    {
        cout << n+1;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

string s;

int main() {
	cin >> s;
	int n = SI(s);
	
	int ans = 0;
	incII(i, 0, n) {
	incII(j, i, n) {
		bool f = true;
		incID(k, i, j) { f &= (s[k] == 'A' || s[k] == 'T' || s[k] == 'G' || s[k] == 'C'); }
		if(f) { setmax(ans, j - i); }
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N, T; cin >> N >> T;
	vector<ll> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	vector<ll> b(N);
	ll mx = 0, m = 0;
	for (int i = N - 1; i >= 0; i--) {
		mx = max(mx, a[i]);
		b[i] = mx - a[i];
		m = max(m, b[i]);
	}
	
	int cnt = 0;
	for (int i = 0; i <N; i++) {
		if (b[i] == m) cnt++;
	}
	cout << cnt << endl;
}

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

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

    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, 0, n) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    rep(i, 0, n - 1) {
        v[i + 1] = (v[i] + v[i + 1]) / 2;
    }
    cout << v[n - 1] << endl;
    return 0;
}


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

int main(){
    int a, b;
    char op;
    while(true){
        cin >> a >> op >> b;
        if(op == '?') break;
        int ans = 0;
        if(op == '+'){
            ans = a + b;
        }
        else if(op == '-'){
            ans = a - b;
        }
        else if(op == '*'){
            ans = a * b;
        }
        else{
            ans = a / b;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

void solve(int N) {
  int a = 0;
  int n = N;
  while (n > 0) {
    a += 1;
    n /= 10;
  }
  long long ans = 0;
  for (int i = 0; i < a; i++) {
    if ((i + 1) % 2 != 0) {
      int x = 1;
      for (int j = 0; j < i; j++) {
        x *= 10;
      }
      if (i + 1 == a) {
        ans += (N - x + 1);
      } else {
        ans += (x * 10 - x);
      }
    }
  }
  printf("%lld\n", ans);
}

int main() {
  int N;
  cin >> N;
  solve(N);
  return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.size = [1] * (n+1)
        self.rank = [0] * (n+1)
    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x] 
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def getSize(self, x):
        return self.size[self.find(x)]
        
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

N, M = map(int, input().split())
adj = [tuple(map(int,input().split())) for i in range(M)]
maxF = N*(N-1)//2 
uf = UnionFind(N)
F = []
F.append(maxF)
for i in range(1, M):
    x, y = adj[-i]
    x-=1
    y-=1
    if(not uf.same_check(x,y)):
        X, Y  = (uf.getSize(x), uf.getSize(y))
        maxF += X*(X+1)//2 + Y*(Y+1)//2
        uf.union(x, y)
        X = uf.getSize(x)
        maxF -=X*(X+1)//2
    F.append(maxF)

for f in F[::-1]:
    print(f)

Measured memory_bytes: 26236
#include <stdio.h>
#include <string.h>
int main(void){
  int N;
  char S[101];
  scanf("%d",&N);
  scanf("%s",S);
  int a=0;
  int i;
  for(i=0;i<N/2;i++){
    if(S[i]!=S[i+N/2]){
      a++;
    }
  }
  if(N%2==1||a!=0){
    printf("No\n");
  }
  else{
    printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define MAXN 10005
#define MAXM 20005
struct Edge
{
	int id,len,cos;
	int nxt;
	Edge(){}
	Edge(int i,int l,int c){id=i;len=l;cos=c;}
}E[MAXM*2];
int V[MAXN],cur;
void add_edge(int u,int v,int length,int cost)
{
	E[cur]=Edge(v,length,cost);
	E[cur].nxt=V[u];
	V[u]=cur;
	cur++;
	E[cur]=Edge(u,length,cost);
	E[cur].nxt=V[v];
	V[v]=cur;
	cur++;
}
int N,M;
int dis[MAXN],cost[MAXN];
bool inque[MAXN];
queue<int>Q;
int SPFA()
{
	memset(inque,0,sizeof inque);
	for(int i=1;i<=N;i++)
		dis[i]=cost[i]=0x3FFFFFFF;
	while(!Q.empty())
		Q.pop();
	Q.push(1);
	dis[1]=0;
	inque[1]=1;
	cost[1]=0;
	while(!Q.empty())
	{
		int t=Q.front();
		Q.pop();
		inque[t]=0;
		for(int p=V[t];p!=-1;p=E[p].nxt)
		{
			int to=E[p].id;
			int len=E[p].len;
			if(dis[to]>dis[t]+len||(dis[to]==dis[t]+len&&cost[to]>E[p].cos))
			{
				dis[to]=dis[t]+len;
				cost[to]=E[p].cos;
				if(!inque[to])
				{
					Q.push(to);
					inque[to]=1;
				}
			}
		}
	}
	int ret=0;
	for(int i=1;i<=N;i++)
		ret+=cost[i];
	return ret;
}
int main()
{
	int u,v,d,c;
	while(~scanf("%d%d",&N,&M))
	{
		if(!N&&!M)break;
		memset(V,-1,sizeof V);
		cur=0;
		for(int i=1;i<=M;i++)
		{
			scanf("%d%d%d%d",&u,&v,&d,&c);
			add_edge(u,v,d,c);
		}
		printf("%d\n",SPFA());
	}
	return 0;
}

Measured memory_bytes: 3384
#include<bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int count=0;
    for(int i=0;i<6;i++){
        if(s[i]=='1'){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(); int b = sc.nextInt();
    if (b % a == 0) {
      System.out.println(b + a);
    } else {
      System.out.println(b - a);
    }
  }
}

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

using namespace std;

int main() {
	int n, m, l;
	cin >> n >> m >> l;
	vector<vector<pair<int, int>>> links(n + 1, vector<pair<int, int>>());
	for (int i = 0; i < m; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		if (z <= l) {
			links[x].push_back(make_pair(y, z));
			links[y].push_back(make_pair(x, z));
		}
	}
	vector<vector<pair<int, int>>> dist(n + 1, vector<pair<int, int>>(n + 1, pair<int, int>(-1, -1)));
	for (int sta = 1; sta <= n; sta++) {
		// cout << "sta---" << sta << endl;
		dist[sta][sta] = make_pair(0, l);
		vector<int> vis(n + 1, 0);
		for (int rnd = 0, now = sta; now != -1 && rnd < n; rnd++) {
			// cout << now << endl;
			vis[now] = 1;
			for (auto p: links[now]) {
				int nex = p.first;
				int d = p.second;
				if (!vis[nex]) {
					pair<int, int> np = dist[sta][now];
					if (d <= np.second) {
						np.second -= d;
					} else {
						np.first += 1;
						np.second = l - d;
					}
					if (dist[sta][nex].first == -1) {
						dist[sta][nex] = np;
					} else {
						if (np.first < dist[sta][nex].first) {
							dist[sta][nex] = np;
						} else
						if (np.first == dist[sta][nex].first && np.second > dist[sta][nex].second) {
							dist[sta][nex] = np;
						}
					}
				}
			}
			int idx = -1;
			for (int nex = 1; nex <= n; nex++) {
				if (!vis[nex] && dist[sta][nex].first != -1) {
					if (idx == -1) {
						idx = nex;
					} else {
						if (dist[sta][nex].first < dist[sta][idx].first) {
							idx = nex;
						} else
						if (dist[sta][nex].first == dist[sta][idx].first && dist[sta][nex].second > dist[sta][idx].second) {
							idx = nex;
						}
					}
				}
			}
			now = idx;
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int s, t;
		cin >> s >> t;
		cout << dist[s][t].first << endl;
	}
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;


int main()
{
    ll a,b,c,d,ans=-1e18;
    cin>>a>>b>>c>>d;
    ans=max(ans,a*c);
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3564
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.TreeSet;

public class Main {
	enum marks {
		S, H, C, D;
	}

	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			int n = Integer.parseInt(br.readLine());
			TreeSet<String> cardSet = new TreeSet<String>(
					new Comparator<String>() {
						@Override
						public int compare(String o1, String o2) {
							int flg;
							flg = marks.valueOf(o1.split("\\s")[0]).compareTo(
									marks.valueOf(o2.split("\\s")[0]));
							if (flg == 0) {
								return Integer.parseInt(o1.split("\\s")[1])
										- Integer.parseInt(o2.split("\\s")[1]);
							} else {
								return flg;
							}
						}
					});
			String[] marks = new String[] { "S", "H", "C", "D" };

			for (String mark : marks) {
				for (int i = 1; i <= 13; i++) {
					cardSet.add(mark + " " + i);
				}
			}

			for (int i = 0; i < n; i++) {
				cardSet.remove(br.readLine());
			}
			for (String str : cardSet) {
				System.out.println(str);
			}
			
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
}

Measured memory_bytes: 22664
n = int(input().rstrip())
s = [input().rstrip() for _ in range(n)]

bstart, aend = 0, 0
doubleend = 0
ab = 0
for item in s:
    if item[0] == "B" and item[-1] == "A":
        doubleend += 1
    else:
        if item[-1] == "A":
            aend += 1
        if item[0] == "B":
            bstart += 1
    ab += item.count("AB")

ab += max(doubleend - 1, 0)
n -= (doubleend - 1)
if bstart > 0 and doubleend > 0:
    ab += 1
    bstart -= 1
    n -= 1
if aend > 0 and doubleend > 0:
    ab += 1
    aend -= 1
    n -= 1
ab += min(aend, bstart, n-1) 
print(ab)

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

ll digit(ll b, ll n){
    ll num = n;
    ll ans = 0;
    while(num>0){
        ans += num%b;
        num /= b;
    }
    return ans;
}

int main() {
    ll n,s; cin >> n >> s;

    if(s==n){
        cout << n+1 << endl;
        return 0;
    }

    if(n<s){
        cout << -1 << endl;
        return 0;
    }

    FOR(b,2,sqrt(n)+1){
        if(digit(b,n)==s){
            cout << b << endl;
            return 0;
        }
    }

    for(ll p = sqrt(n)+1; p>=1; p--){
        if((n-s)%p == 0){
            ll b = (n-s)/p + 1;

            if(digit(b,n)==s){
                cout << b << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#include <bitset>
#define ll long long
using namespace std;

int answer(int x){
  if(x==0){
    return 0;
  }
  int p=0;
  for(int i=0;i<20;i++){
    if(x&(1<<i)){
      p++;
    }
  }
  return 1+answer(x%p);
}

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int pop=0;
  for(int i=0;i<n;i++){
    if(s[i]=='1'){
      pop++;
    }
  }
  ll vec[n]={};
  ll vecb[n]={};
  vec[0]=1;
  vecb[0]=1;
  ll sum=0,sumb=0;
  for(int i=1;i<n;i++){
    vec[i]=2*vec[i-1];
    vec[i]%=pop+1;
  }
  for(int i=1;i<n;i++){
    vecb[i]=2*vecb[i-1];
    if(pop!=1){
      vecb[i]%=pop-1;
    }
  }
  reverse(vec,vec+n);
  reverse(vecb,vecb+n);
  for(int i=0;i<n;i++){
    if(s[i]=='1'){
      sum+=vec[i];
      sumb+=vecb[i];
    }
  }
  sum%=pop+1;
  if(pop!=1){
    sumb%=pop-1;
  }
  
  for(int i=0;i<n;i++){
    if(s[i]=='0'){
      ll z=sum+vec[i];
      z%=pop+1;
      cout<<answer(z)+1<<endl;
    }
    if(s[i]=='1'){
      if(pop==1){
        cout<<0<<endl;
      }
      else{
        ll z=sumb-vecb[i];
        z+=pop-1;
        z%=pop-1;
        cout<<answer(z)+1<<endl;
      }
    }
  }
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 21;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 62;

ll n,m;
ll a[e5],b[e5];
ll c[e5];
ll f = -1;
graph g;

ll vis[e5];

void error(ll x){
  cerr << x << endl;
  cout << "No" << endl;
  exit(0);
}

void yes(){
  cout << "Yes" << endl;
  exit(0);
}
ll dfs(ll x){
  if(g[x].size() == 4) return x;

  vis[x] = 1;
  for(auto y : g[x]){
    if(vis[y.first]) continue;
    ll hoge = dfs(y.first);
    return hoge;
  }
  return 0;
}

int main(){
  cin >> n >> m;
  for(ll i = 0;i < m;i++) cin >> a[i] >> b[i];
  for(ll i = 0;i < m;i++) c[a[i]]++,c[b[i]]++;
  for(ll i = 1;i <= n;i++){
    if(c[i]%2 == 1) error(1);
    if(c[i] == 0) error(2);
    if(c[i] == 4) f++;
    if(c[i] >= 6) f += 5;
  }
  if(f > 1) yes();
  else if(f == 1){
    for(ll i = 0;i < m;i++){
      g[a[i]][b[i]] = 1;
      g[b[i]][a[i]] = 1;
    }
    ll i;
    ll s;
    for(i = 1;i <= n;i++){
      if(c[i] == 4){
        s = i;
        // cerr << i << endl;
        vis[i] = 1;
        for(auto y : g[i]){
          // cerr << y.first << endl;
          ll hoge = dfs(y.first);
          // cerr << hoge << endl;
          if(hoge == 0) yes();
        }
        break;
      }
    }

  }
  error(3);

}


Measured memory_bytes: 27684
#include <stdio.h>
int main(){
  int a,b,c,d,e;
  scanf("%d%d",&a,&b);
  if(a<b){ c=a,d=b;
  } else c=b,d=a;
  
  while(1){
    if(c==0)break;
    e=c;
    c=d%e;
    d=e;
  }  
  printf("%d\n",d);
  return 0;
}

Measured memory_bytes: 592
from bisect import bisect_left

S = input()
T = input()

if not set(list(T)) <= set(list(S)):
    print(-1)
    exit()

sToI = {s: [] for s in set(list(S))}
for i, s in enumerate(S):
    sToI[s].append(i)

now = 0
R = 0
for t in T:
    I = sToI[t]
    nx = bisect_left(I, now)

    if nx == len(I):
        nx = 0
        R += 1

    now = I[nx] + 1

print(now + R * len(S))


Measured memory_bytes: 7780
n = int(input())
s = input()
if len(s) == 1:
    print(1)
    exit()
tmp_s = s[0]
ans_s = s[0]
for i in range(1, len(s)):
    if tmp_s != s[i]:
        ans_s = ans_s + s[i]
    tmp_s = s[i]
print(len(ans_s))

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

const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,r,n) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

#define cout cout << setprecision(12)

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void dbg(T a) { cout << a << ' ' << endl; }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main() {
    cin >> s;
 // dbg(s.length());
	REP(i,s.length()/2) {
    	if (s[i] != s[s.length()-1-i])
          ans++;
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN

#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)

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


////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

int rec(int level, int n, int a)
{
	if(level==n)
	{
		return a;
	}

	rec(level+1, n, a);
	for(int i = a+1; i<=n; i++)
	{
		rec(level+1, n, a+1);
	}
	// ans.pb()
	// rec(level+1, n, a+1);
}

int best = imn;
int q, m, n;
void rec_fn(int i, int pivot, vector<int>& arr, vector<vector<int> >& mat)
{
	// cout<<i<<endl;

	// for(auto i: arr) cout<<i<<" ";
		// cout<<endl;
	if(i==n+1)
	{
		int sum = 0;
		for(int k = 0; k < q; k++)
		{
			if(arr[mat[k][1]-1]-arr[mat[k][0]-1]==mat[k][2])
				sum+=mat[k][3];
		}
		// cout<<sum<<endl;
		best = max(best, sum);
		return;
		// return best;
	}

	for(int j = pivot; j<=m; j++)
	{
		arr[i]=j;
		rec_fn(i+1, j, arr, mat);
		// best = max(rec_fn(i+1, j, arr, mat), best);
		// cout<<" best "<<best<<" j "<<j<<endl;
		// return best;
	}

}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// ll x;
	// cin>>x;
	// ll start =100;
	// int i = 0;
	// while(start < x)
	// {
	// 	start= (start+(start*1)/100);
	// 	i++;
	// }
	// cout<<i<<endl;
	// int a, b, c, d;
	ll sum = 0, maxim = 0;
	cin>>n>>m>>q;
	// for(int vector<)
	vector<vector<int> > mat(q+1, vector<int> (4));
	vector<int> ans(n+1, imx);
	for(int i = 0; i < q; i++)
		for(int j = 0; j < 4; j++)
			cin>>mat[i][j];

	// for(int i = 0; i < n; i++)
	// {
	// 	for(int j = 0; j < 4; j++)
	// 	{
	// 		cout<<mat[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	rec_fn(0, 1, ans, mat);
	p(best);
		// rec_fn(0, 1, ans, mat);
		// p(best);
	// rec(0, n, 1);
	// while(q--)
	// {
		// cin>>a>>b>>c>>d;

	// }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int n = 1000000;
int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i){cin >> a[i];}
  	bool ok = false;
  	for(int i=0; i<n; ++i){if(a[i]==1){ok = true; break;}}
  	if(!ok){cout << -1 << endl; return 0;}
    int now = 1;
    int res = 0;
    for(int i=0; i<n; ++i){
        if(a[i]!=now){res++;}
      	else{now++;}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4024
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, a[202020];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	int cnt = 1, ans = 0;
	for(int i = 0; i < n; i++){
		if(a[i] == cnt){
			cnt++;
		}
		else{
			ans++;
		}
	}
	if(ans == n) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
s = input()

def is_palindrome(a):
    n = len(a)
    i = 0
    while 2 * i < n:
        if s[i] != s[n - i - 1]:
            return False
        i += 1
    return True

if is_palindrome(s):
    n = len(s)
    fr = s[: (n - 1)//2]
    sc = s[(n + 1) // 2:]
    if is_palindrome(fr) and is_palindrome(sc):
        print('Yes')
    else:
        print('No')
else:
    print('No')


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

int n;
int h[25];

int main()
{
  int p=0;
  int ans=0;
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> h[i];
    if (p<=h[i]) {
      ans++;
      p=h[i];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint k, n;
llint a[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> k >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	llint mn = 0;
	for(int i = 0; i < n-1; i++) mn = max(mn, a[i+1]-a[i]);
	mn = max(mn, a[0]+k-a[n-1]);
	
	cout << k - mn << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#https://atcoder.jp/contests/abc125/tasks/abc125_b

N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
vc = []
for i in range(N):
    vc.append(V[i]-C[i])

vc.sort(reverse=True)
t=0
for i in range(len(vc)):
    if vc[i] > 0:
        t += vc[i]
print(t)

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

int main(){
    string w;
    cin >> w;
    string ans="";
    for(int i=0;i<w.size();i++){
        if(w.at(i)=='0'){
            ans+="0";
        }
        else if(w.at(i)=='1'){
            ans+="1";
        }
        else if(w.at(i)=='B'){
            if(ans.empty()==0){
                ans.erase(ans.size()-1);
            }
        }
    }
    cout << ans << endl;
}

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

class chara{
public:
  string name;
  int vote;
  bool operator<(const chara &x)const{
    return (vote==x.vote)?(name<x.name):(vote>x.vote);
  }
};

int main(){
  int n,m,k,l;
  chara c[100000];

  while(scanf("%d %d %d %d",&n,&m,&k,&l) &&(n||m||k||l)){
    char tmp[12];
    int x;
    for(int i=0;i<n;i++){
      scanf("%s %d",tmp,&x);
      c[i].name = tmp;
      c[i].vote = x;
    }

    sort(c,c+n);

    map<string,bool> fav;
    for(int i=0;i<m;i++){
      scanf("%s",tmp);
      string s = tmp;
      fav[s] = true;
    }

    int ans = 0;
    int pos = k-1;
    int now = k;
    for(;;){
      while(0<=pos && fav[c[pos].name])pos--;
      if(pos<0)break;

      while(now<n && !fav[c[now].name])now++;
      if(now==n)break;

      swap(c[now],c[k]);
      for(int i=pos;i<k;i++){
	l -= c[i].vote-c[i+1].vote;
	c[i+1].vote = c[i].vote;
	if(c[i].name<c[i+1].name){
	  l--;c[i+1].vote++;
	}
	if(l<0)break;
	swap(c[i],c[i+1]);
      }
      if(l<0)break;
    }

    for(int i=0;i<k;i++)if(fav[c[i].name])ans++;
     
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 9644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

ll n;
ll a[100100];

ll sq(ll num){
	return num*num;
}

ll mod_pow(ll num, ll k){
	if (k == 0)return 1;
	if (k == 1)return num;
	ll res = sq(mod_pow(num, k / 2));
	res %= INF;
	if (k % 2 == 1){
		res *= num;
		res %= INF;
	}
	return res;
}

int main(){
	cin >> n;
	REP(i, n)cin >> a[i];
	sort(a, a + n);
	bool f = 1;
	int cnt;
	if (n % 2 == 0)cnt = 1;
	else cnt = 0;
	REP(i, n){
		if (cnt != a[i])f = 0;
		if (n % 2 == 0){
			if (i % 2 == 1)cnt += 2;
		}
		else{
			if (i % 2 == 0)cnt += 2;
		}
	}
	ll ans = mod_pow(2, n / 2);
	if (f)cout << ans << endl;
	else cout << 0 << endl;
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

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

  if (b - a >= k) {
    cout << "OK" << endl;
    return 0;
  }

  if (a / k != b / k) {
    cout << "OK" << endl;
    return 0;
  }

  if (a % k == 0 || b % k == 0) {
    cout << "OK" << endl;
    return 0;
  }

  cout << "NG" << endl;
}


Measured memory_bytes: 3580
#include<cstdio>
#include<queue>
using namespace std;
#define N 200050
int fa[N],sz[N],head[N],cnt,mx[N],f[N],ti=1,as[N],n,a,b,fr[N],vl[N];
struct edge{int t,next;}ed[N*2];
priority_queue<pair<int,int> > st;
int finds(int x){return fa[x]==x?x:fa[x]=finds(fa[x]);}
void adde(int f,int t){ed[++cnt]=(edge){t,head[f]};head[f]=cnt;ed[++cnt]=(edge){f,head[t]};head[t]=cnt;}
void dfs1(int u,int fa){f[u]=fa;mx[u]=mx[f[u]],fr[u]=fr[f[u]];if(mx[u]<fa)mx[u]=fa,fr[u]=u;for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)dfs1(ed[i].t,u);}
int que(int x){if(x<ti)return sz[finds(x)]-1;int as=0;for(int i=head[x];i;i=ed[i].next)if(ed[i].t<ti)as+=sz[finds(ed[i].t)];return as;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)scanf("%d%d",&a,&b),adde(a,b);
	for(int i=1;i<=n;i++)fa[i]=i,sz[i]=1;
	dfs1(1,0);
	for(int i=head[1];i;i=ed[i].next)st.push(make_pair(-1,ed[i].t));
	while(!st.empty())
	{
		int las=ti;
		ti=-st.top().first;int s=st.top().second;st.pop();
		for(int i=las;i<ti;i++)
		for(int j=head[i];j;j=ed[j].next)if(ed[j].t<i){int a=finds(i),b=finds(ed[j].t);fa[a]=b,sz[b]+=sz[a];}
		as[s]+=as[mx[s]]+que(s)+1-vl[fr[s]];
		for(int i=head[s];i;i=ed[i].next)if(ed[i].t!=f[s])st.push(make_pair(-mx[ed[i].t],ed[i].t)),vl[ed[i].t]=ed[i].t<ti?sz[finds(ed[i].t)]:0;
	}
	for(int i=2;i<=n;i++)printf("%d ",as[i]);
}//

Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m ;
    cin>>m;
    return m ;
}
int main()
{
  int n=D();
 string s;
 cin>>s;
 int x=0,mx=0;
 for(int i=0;i<s.length();++i){
    if(s[i]=='I')
        x++;
    mx=max(x,mx);
    if (s[i]=='D')
        x--;
 }
 cout<<mx<<endl;
}



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

int main(){
    int N,M;
    std::cin >> N >> M;
    std::vector<std::vector<int>>edge(N);
    for(int i = 0; i < M; ++i){
        int s,t; std::cin >> s >> t;
        edge[s - 1].push_back(t - 1);
        edge[t - 1].push_back(s - 1);
    }
    constexpr long long inf = 1e18;
    std::vector<long long>d(N,inf),prev(N,0);
    d[0] = 0;
    std::priority_queue<std::pair<long long, long long>,std::vector<std::pair<long long, long long>>,std::greater<>>que;
    que.emplace(d[0],0);
    while(not que.empty()){
        auto tp = que.top(); que.pop();
        int cv,cd; std::tie(cd,cv) =  tp;
        if(cd > d[cv]) continue;
        for(const auto nv : edge[cv]){
            if(d[nv] > cd + 1){
                d[nv] = cd + 1;
                prev[nv] = cv;
                que.emplace(d[nv],nv);
            }
        }
    }
    if (std::count_if(d.begin(),d.end(),[&](auto e){return e == inf;})){
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
        prev.erase(prev.begin());
        for(const auto pv : prev){
            std::cout << pv + 1 << std::endl;
        }
    }
}


Measured memory_bytes: 13036
#include<stdio.h>
/*
void swap (char *x, char *y) {
    char temp;    // 値を一時保存する変数
    temp = *x;
    *x = *y;
    *y = temp;
}
*/

int main() {
    int n, ans = 0;
    int i, j, k;
    char c[200020] = {0};
    //int b[200020] = {0};//1なら消えている
    scanf("%d", &n);
    scanf("%s", c);
    i = -1;
    j = n ;

    do {
        do { i++; } while (c[i] == 'R');
        do { j--; } while (c[j] == 'W');
        if (i < j) {
          c[i]='R';
          c[j]='W';
            //swap(&c[i],&c[j]);
            //printf("%s\n",c);
            ans++;
        }
    } while(i<j);

    printf("%d",ans);
}


Measured memory_bytes: 1900
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;

int main() {
  vector<int> directionX = {-1, 1, 0, 0};
  vector<int> directionY = {0, 0, -1, 1};
  
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i, h) {
    cin >> s[i];
  }
  int ans = 0;
  
  REP(si, h) REP(sj, w) {
    if (s[si][sj] == '#') continue;
    queue<P> que;
    Graph dist(h, vector<int>(w, -1));
    auto update = [&](int i, int j, int x) {
      if(dist[i][j] != -1) return;
      dist[i][j] = x;
      que.push(P(i, j));
    };
    update(si, sj, 0);
    while(!que.empty()) {
      int i = que.front().first;
      int j = que.front().second;
      que.pop();
      REP(dir, 4) {
        int newi = i + directionX[dir];
        int newj = j + directionY[dir];
        if(newi < 0 || newi >= h || newj < 0 || newj >= w) continue;
        if(s[newi][newj] == '#') continue;
        update(newi, newj, dist[i][j] + 1);
      }
    }
    
    REP(i, h) REP(j, w) {
      if(dist[i][j] == -1) continue;
      ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
   int c,d;
   c=4,d=7;
   int n;
   cin>>n;
   int tmp,ch=0;
   for(int i=0;i<=n/4;i++){
       tmp=0;
       tmp+=c*i;
       if(tmp==n){
               ch++; 
               goto out;
           }
           else if(tmp>n) break;
       for(int j=0;j<=n/7;j++){
           tmp+=d;
           if(tmp==n){
               ch++; 
               goto out;
           }
           else if(tmp>n) break;
       }
   }
   out:
   if(ch){
   cout<<"Yes"<<endl;
   }else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 4352
//------------------------------------------
// C++ templete
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "; cout << endl;
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

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

    string S; cin >> S;

    reverse(ALL(S));

    vector<string> ss={ "dream", "dreamer", "erase", "eraser"};

    REP(i, ss.size())
    {
        reverse(ALL(ss.at(i)));
    }

    bool flag=false; //devideできたらtrue
    REP(i, S.size())
    {
        flag=false;
        for (auto s : ss)
        {
            if (S.substr(i, s.size())==s)
            {
                i += s.size()-1;
                flag = true;
                break;
            }
        }
        if (!flag) break;
    }

    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int N    = scanner.nextInt();
		int K    = scanner.nextInt();
		String S = scanner.next();
		String answer = "";
			
		answer =  S.substring(0,K-1) + S.substring(K-1,K).toLowerCase() + S.substring(K);
		
		
		System.out.println(answer);
	}
}

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
        b[i] = a[i] + i;
    }
    sort(b.begin(), b.end());

    int ans = 0;
    for(int i=0; i<n; i++){
        auto itr_l = lower_bound(b.begin(), b.end(), i-a[i]);
        int ind_l = distance(b.begin(), itr_l);
        auto itr_u = upper_bound(b.begin(), b.end(), i-a[i]);
        int ind_u = distance(b.begin(), itr_u);
        ans += ind_u - ind_l;
    }

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

Measured memory_bytes: 6412
function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const H=input[0]-0;
  var digits=1+Math.floor(Math.log2(H));
  console.log(2**digits-1)
  

}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  



  


Measured memory_bytes: 29788
N=int(input())
tzero=0
xzero=0
yzero=0
feasibility=1

for i in range(N):
    t,x,y=map(int,input().split())
    dist=abs(x-xzero)+abs(y-yzero)
    dt=t-tzero
    if dist>dt:
        feasibility=0
        break
    if dist%2 != dt%2:
        feasibility=0
        break
if feasibility==0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

int32_t main()
{
	//IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int n;
		cin >> n;
		int c1 = 0 , c2 = 0, c3 = 0 ,c4 = 0;
		//AC ,WA , TLE ,RE
		rep(i,1,n)
		{
			string s;
			cin >> s;
			if(s=="AC")
				c1++;
			else if(s=="WA")
				c2++;
			else if(s=="TLE")
				c3++;
			else
				c4++;
		}
		cout << "AC x " << c1 << endl;
		cout << "WA x " << c2 << endl;
		cout << "TLE x " << c3 << endl;
		cout << "RE x " << c4 << endl;
	}
}



Measured memory_bytes: 3556
def solve():
    music_score = input()
    for note in music_score[0::2]:  # 奇数文字目
        if note == 'L':
            print('No')
            return
    for note in music_score[1::2]:   # 偶数文字目
        if note == 'R':
            print('No')
            return
    print('Yes')

solve()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
//#define P pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;
int main()
{
  int N, A, B, C; cin >> N >> A >> B >> C;
  vector<int> bam(N);
  rep(i, 0, N) cin >> bam[i];
  //vector<int> cost(3, 10000);
  int cost = 100000;

  for(int bit = 0; bit < (1 << N); ++bit){
    for(int bit2 = 0; bit2 < (1 << N); ++bit2){
      if(bit & bit2) continue;
      for(int bit3 = 0; bit3 < (1 << N); ++bit3){
        if(bit3 & bit) continue;
        if(bit3 & bit2) continue;
        vector<int> mp(3);
        if(__builtin_popcount(bit) > 0) mp[0] += 10 * (__builtin_popcount(bit) - 1);
        if(__builtin_popcount(bit2) > 0) mp[1] += 10 * (__builtin_popcount(bit2) - 1);
        if(__builtin_popcount(bit3) > 0) mp[2] += 10 * (__builtin_popcount(bit3) - 1);
        int lena, lenb, lenc; lena = lenb = lenc = 0;
        rep(i, 0, N){
          if(bit & (1 << i)) lena += bam[i];
          if(bit2 & (1 << i)) lenb += bam[i];
          if(bit3 & (1 << i)) lenc += bam[i];
        }
        mp[0] += abs(A - lena);
        mp[1] += abs(B - lenb);
        mp[2] += abs(C - lenc);
        int tmp = 0;
        rep(i, 0, 3) tmp += mp[i];
        if(tmp < cost && lena > 0 && lenb > 0 && lenc >0) cost = tmp;
      }
    }
  }

  cout << cost << endl;
}


Measured memory_bytes: 3512