akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

#define to 'A'-'a'
#define small(x) (x) >= 'a' && (x) <= 'z'
#define big(x) (x) >= 'A' && (x) <= 'Z'

int main(){
    string line;
    char s;
    while(1){
        cin >> line >> s;
        if(s == 'X') break;
        if(s == 'U' || s == 'L'){
            for(int i=0;i<line.size();i++){
                if(i == 0 && s == 'U' && small(line[i])) line[i] += to;
                else if(i == 0 && s == 'L' && big(line[i])) line[i] -= to;
                if(line[i] == '_') line[i+1] += to;
            }
            while(line.find("_") != string::npos) line.erase(line.find("_"),1);
        }
        else {
            for(int i=0;i<line.size();i++){
                if(i == 0 && big(line[i])) line[i] -= to;
                else if(big(line[i])) {
                    line[i] -= to;
                    line.insert(i,"_");
                }
            }
        }
        cout << line << endl;
    }
}

Measured memory_bytes: 1204
from collections import deque

S = deque(input())
Q = int(input())

rev = False

for _ in range(Q):
    T, F, C, *D = input().split() + [None, None]
    T = int(T)

    if T == 1:
        rev = not rev
    else:
        F = int(F)
        if rev:
            if F == 1:
                F = 2
            else:
                F = 1

    if F == 1:
        S.appendleft(C)
    else:
        S.append(C)

if rev:
    S.reverse()

print(*[x for x in list(S) if x], sep='')


Measured memory_bytes: 12232
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;

using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	ll N, M;cin >> N >> M;
	ll E = 1e+7;
	ll ans = 1;
	if (abs(N - M) > 1) cout << 0 << endl;
	else {
		if (N == M) {
			cout << (2 * frac(N) * frac(M)) % MOD << endl;
		}
		else cout << (frac(N) * frac(M)) % MOD << endl;
	}
}

Measured memory_bytes: 1792
function Main(input){
	input=input.split(" ");
	let W = parseInt(input[0],10);
	let H = parseInt(input[1],10);
	let x = parseInt(input[2],10);
	let y = parseInt(input[3],10);
	let r = parseInt(input[4],10);
	if ((x - r >= 0) &&
		(x + r <= W) &&
		(y - r >= 0) &&
		(y + r <= H)) {
			console.log("Yes");
		} else {
			console.log("No");
		}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

const int INF = 1e9 + 7;
int N;

vector<int> to[200010];
int A[200010];
int ans[200010];
int dp[200010];
bool visited[200010];

void dfs(int now) {
  visited[now] = true;
  auto tmpIdx = lower_bound(dp, dp + N, A[now]);
  int tmpV = *tmpIdx;
  *tmpIdx = A[now];
  ans[now] = lower_bound(dp, dp + N, INF) - dp;

  for (int v : to[now]) {
    if (!visited[v]) {
      dfs(v);
    }
  }

  *tmpIdx = tmpV;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];

  for (int i = 0; i < N - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    to[u].push_back(v);
    to[v].push_back(u);
  }

  for (int i = 0; i < 200010; i++) dp[i] = INF;

  dfs(0);
  for (int i = 0; i < N; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 25616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll x, y;
  cin >> x >> y;
  cout << x + y/2 << endl;


  return 0;
}


Measured memory_bytes: 256
n = int(input())
d,x = map(int,input().split())
lst = []
lst1 = []
for i in range(n):
    a = int(input())
    lst.append(a)
for j in range(n):
    b = ((d-1)//lst[j])+1
    lst1.append(b)
print(sum(lst1)+x)

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

int main () {
   string S;
   cin>>S;
   int A[4];
   for(int i=0;i<4;i++)
       A[i]=S[i] - '0';
   string T;
   for(int i=0;i<(1<<3);i++){
       int x=A[0];
       T=S[0];
       for(int j=0;j<3;j++){
           if (i&(1<<j)){
               x+=A[j+1];
               T+='+';}
           else{
               x-=A[j+1];
               T+='-';
           }
           T+=S[j+1];
           }
       if(x==7) break;
           }
   T+= "=7";
   cout<<T<<endl;
    return 0;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define pii pair<ll,ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(ll i=a;i<=(ll)b;++i)
#define per(i,a,b) for(ll i=a;i>=(ll)b;--i)
#define ll long long
#define lowbit(x) ((x)&(-x))

int main()
{
    string s;cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

typedef long long ll;
const int mod=1e9+7;
const int maxn=1010;
int n,m; ll k;
char s[maxn];

struct Matrix{
	ll a[5][5];
	Matrix(int v=0){
		memset(a,0,sizeof(a));
		if(v==1) for(int i=0;i<4;i++) a[i][i]=1;
	}
	Matrix operator *(const Matrix& A)const{
		Matrix ret;
		for(int k=0;k<4;k++)
			for(int i=0;i<4;i++) for(int j=0;j<4;j++) ret.a[i][j]=(ret.a[i][j] + a[i][k]*A.a[k][j]%mod )%mod;
		return ret;
	}
	Matrix operator ^(ll y){
		Matrix ret(1), x=*this;
		while(y){
			if(y&1) ret=ret*x;
			x=x*x;
			y>>=1;
		}
		return ret;
	}
	void print(){
		for(int i=0;i<4;i++,puts("")) for(int j=0;j<4;j++) printf("%lld ",a[i][j]);
		puts("");
	}
}t, ans;

int a[maxn][maxn];
ll Pow(ll x,ll y){
	ll ret=1;
	while(y){
		if(y&1ll) ret=ret*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ret;
}
bool check(){
	if(!k){ puts("1"); return 1; }
	int flag1=0, flag2=0;
	for(int i=1;i<=n;i++) if(a[i][1] && a[i][m]){ flag1=1; }
	for(int i=1;i<=m;i++) if(a[1][i] && a[n][i]){ flag2=1; }
	if(flag1 && flag2){ puts("1"); return 1; }
	if(!flag1 && !flag2){
		ll cnt=0;
		for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cnt+=a[i][j];
		printf("%lld\n",Pow(cnt, k-1));
		return 1;
	}
	if(flag2){
		for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
			if(i>m || j>n) a[j][i]=a[i][j];
			else if(i<j) swap(a[i][j], a[j][i]);
		}
		swap(n, m);
	}
	return 0;
}

int main(){
	scanf("%d%d%lld",&n,&m,&k);
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=m;j++){ a[i][j]=(s[j]=='#'); }
	}
	if(check()) return 0;
	//for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=m;j++) printf("%d ",a[i][j]); puts("");
	for(int i=1;i<=n;i++){
		if(a[i][1])
			if(a[i][m])
				if(a[i][2]) t.a[0][1]++, t.a[1][1]++, t.a[2][3]++, t.a[3][3]++;
				else t.a[0][0]++, t.a[1][0]++, t.a[2][2]++, t.a[3][2]++;
			else
				if(a[i][2]) t.a[0][1]++, t.a[1][1]++, t.a[2][1]++, t.a[3][1]++;
				else t.a[0][0]++, t.a[1][0]++, t.a[2][0]++, t.a[3][0]++;
		for(int j=2;j<m;j++)
			if(a[i][j])
				if(a[i][j-1])
					if(a[i][j+1]) t.a[0][3]++, t.a[1][3]++, t.a[2][3]++, t.a[3][3]++;
					else t.a[0][2]++, t.a[1][2]++, t.a[2][2]++, t.a[3][2]++;
				else
					if(a[i][j+1]) t.a[0][1]++, t.a[1][1]++, t.a[2][1]++, t.a[3][1]++;
					else t.a[0][0]++, t.a[1][0]++, t.a[2][0]++, t.a[3][0]++;
		if(m>1 && a[i][m])
			if(a[i][m])
				if(a[i][m-1])
					if(a[i][1]) t.a[0][2]++, t.a[1][3]++, t.a[2][2]++, t.a[3][3]++;
					else t.a[0][2]++, t.a[1][2]++, t.a[2][2]++, t.a[3][2]++;
				else
					if(a[i][1]) t.a[0][0]++, t.a[1][1]++, t.a[2][0]++, t.a[3][1]++;
					else t.a[0][0]++, t.a[1][0]++, t.a[2][0]++, t.a[3][0]++;
	}
	ans.a[0][0] = 1;
	ans = ans*(t ^ (k-1));
	printf("%lld", (ans.a[0][0] + ans.a[0][1]) %mod );
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9

#define rep2(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) rep2(i,0,n)
#define ll long long
#define pb push_back

int n,k,d[101][101];

int main(){
	while(cin>>n>>k&&n){
		rep(i,n){
			fill(d[i],d[i]+n,INF);
			d[i][i]=0;
		}
		rep(i,k){
			int x;
			cin>>x;
			if(!x){
				int a,b;
				cin>>a>>b;
				a--;b--;
				cout<<(d[a][b]==INF?-1:d[a][b])<<endl;
			}
			else{
				int c,D,e;
				cin>>c>>D>>e;
				c--;D--;
				d[c][D]=d[D][c]=min(d[c][D],e);
				rep(j,n){
					d[j][c]=d[c][j]=min(d[j][c],d[j][D]+d[D][c]);
					d[j][D]=d[D][j]=min(d[j][D],d[j][c]+d[c][D]);
				}
				rep(j,n)rep(K,n){
					d[j][K]=d[K][j]=min(d[j][K],min(d[j][c]+d[c][K],d[j][D]+d[D][K]));
				}
			}
		}
	}
}

Measured memory_bytes: 904
#include <bits/stdc++.h>
#define ll long long
#define fr(i,n) for(ll i=0;i<n;i++)
using namespace std;
const ll mod=1e6+7;


int main() {
ll n,m,g,ans=1;
cin>>n>>m;
vector<bool> prime(mod, true);

prime[0]=false;prime[1]=false;
g=__gcd(n,m);
for(ll i=2;i<mod;i++){
    if(prime[i]==false)continue;
    for(ll j=i*2;j<mod;j+=i)
    prime[j]=false;
    if(g%i)continue;
    while(g%i==0)g/=i;
    ans++;

    }
    if(g!=1)ans++;
cout<<ans;
}


Measured memory_bytes: 3752
#include <iostream>

using namespace std;

int main()
{
	int n;

	while (1)
	{
		int a[5001] = {0}, s[5001] = {0}, max;

		cin >> n;
		if(n == 0)	break;

		for (int i=1; i<=n; i++)	//入力
			cin >> a[i];

		for (int i=1; i<=n; i++) {
			for (int j=1; j<=i; j++) {
				s[i] += a[j];		//s[i] = a[1]+a[2]+...+a[i]
			}
		}

		max = s[1];

		//int cont = 0;	//Debug
		for (int i=1; i<=n; i++) {
			for (int j=1; j<=i; j++) {
				//if (max < s[i] - s[j-1]) cout << j << '-' << i << ", max = " << s[i] - s[j-1] << endl;	//Debug
				max = (max < s[i] - s[j-1]) ? s[i] - s[j-1] : max;	//区間i,jの和を求めて比較
				//cont++;	//Debug
			}
		}

		cout << max << endl;
		//cout << cont << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
	int m,n,x,i,t,l=0,r=0;
	cin>>n>>m>>x;
	for(i=1;i<=m;i++)
	{
	cin>>t;
	a[t]=1;
	}
	for(i=x+1;i<=n;i++) r+=a[i];
	for(i=x-1;i>=0;i--) l+=a[i];
	cout<<min(l,r);
	return 0;
 } 

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  LL N,A,B,C,D;
  cin >> N >> A >> B >> C >> D;
  string s;
  cin>>s;
  s += "###";
  A--;
  B--;
  C--;
  D--;
  bool cd = C < D; //cdだと嬉しいな
  bool can = true;
  bool jump = false;
  while (true)
  {
    if(s[B-1]=='.'&&s[B+1]=='.'){
      jump = true;
    }
    if(B==D){
      break;
    }
    if(s[B+1]=='#'){
      if(s[B+2]=='#'){
        can = false;
        break;
      }else{
        B += 2;
      }
    }else{
      B += 1;
    }
  }

  while(true){
    if(A==C){
      break;
    }
    if(s[A+1]=='#'){
      if(s[A+2]=='#'){
        can = false;
        break;
      }else{
        A += 2;
      }
    }else{
      A += 1;
    }
  }
  if(!cd&&!jump){
    can = false;
  }
  if(can){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

int main()
{
  int n;
  cin >> n;
  string ans = "No";

  for (int i = 1; i <= 9; i++) {
    if (n % i == 0 && n / i <= 9) {
      ans = "Yes";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>
#include <thread>
#include <fstream>

using namespace std;

//const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
const int mod = int(1e9) + 7;
//const int inf = 1e7;
//const long long infLL = 1e16;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 100500; //       e6

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int n;
    cin >> n;
    int a, b, c;
    a = b = c = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(x % 4 == 0) a++; else
        if(x % 2 == 0) b++; else
            c++;
    }
    if(a >= c) {cout << "Yes" << endl;} else
    if(a + 1 >= c && b == 0){cout << "Yes" << endl;} else
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  string s; cin >> s;
  if (s.back() == '0' || s.back() == '1' || s.back() == '6' || s.back() == '8')
    cout << "pon\n";
  else if (s.back() == '3')
    cout << "bon\n";
  else
    cout << "hon\n";
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

int main(){
  int H,W,K; cin >> H >> W >> K; K--;
  vector<vector<ll>> dp ( H + 1  , vector<ll> ( W, 0));
  
  dp[0][0] = 1;
  
  for(int i = 0 ; i < H; i++){
    for(int j = 0; j < W; j++){
      //　横　→　縦、　の順
      for(int bit = 0; bit <  1 << (W - 1); bit++){
        bool flag = true;
        for(int k = 0; k < ( W - 2 ); k++){
          if( bit & (1 << k)  && bit &   1 <<( k + 1)){//続けて1が出ていたらcontinue
            flag = false;;}}
       //それ以外は、横棒が連続して並ぶことはない
        if( !flag){ continue;}
        
         if( bit & 1 << j && j < W - 1){ dp[i+1][j+1] += dp[i][j] ; dp[i+1][j+1] %= MOD;}
         else if( bit & 1 << (j - 1) && j > 0){
             dp[i+1][j-1] += dp[i][j]; dp[i+1][j-1] %= MOD;}
           else {
             dp[i+1][j] +=dp[i][j] ; dp[i+1][j] %= MOD;}
                   }
                   }
  }
    cout << dp[H][K] << endl;
    
    return 0;}
      
                   
                  
              

Measured memory_bytes: 256
#include<algorithm>//everybody dies in their nightmares
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<string>
#include<vector>
#include<sstream>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
#define eb(a) emplace_back(a)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const ll mod = 1e18 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 4e5 + 5;
int t;
int a[N];
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	int sum = 0;
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &a[i]);
		sum += a[i];
	}

	sort(a + 1, a + n + 1);

	int t = n - m + 1;
	if (a[t] * 4 * m < sum)
		puts("No");
	else
		puts("Yes");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long


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

    int a[100000];
    for (int i=0; i < n; i++) {
        cin >> a[i];
    }

    int min = 1000000000;
    while (true) {
        min = 1000000000;
        for (int i=0;i < n; i++) {
            if (a[i] < min) {
                min = a[i];
            }
        }

        int num = 0;
        for (int i=0; i < n; i++) {
            if (a[i] % min == 0) {
                a[i] = min;
                num++;
            } else {
                a[i] = a[i] % min;
            }
        }

        if (num == n) break;
    }

    cout << min << endl;

    return 0;
}


Measured memory_bytes: 640
#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);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000LL;
constexpr auto MOD = 1000000007;

int main() {

	ll n, m;
	cin >> n >> m;
	V<ll> a(n);
	rep(i, n)cin >> a[i];
	sort(all(a));
	V<ll> sum(n + 1);
	rep(i, n)sum[n - 1 - i] = sum[n - i] + a[n - 1 - i];

	ll l = 0, r = LINF;
	while (r - l > 1) {
		ll c = (l + r) / 2;
		ll cnt = 0;
		rep(i, n) {
			cnt += a.end() - lower_bound(all(a), c - a[i]);
		}
		if (cnt >= m)l = c;
		else r = c;
	}

	ll ans = 0;
	ll cnt = 0;
	rep(i, n) {
		int it;
		it = lower_bound(all(a), l - a[i]) - a.begin();
		cnt += n - it;
		ans += a[i] * (n - it) + sum[it];
	}
	
	ans -= (cnt - m) * l;
	cout << ans << endl;

}

Measured memory_bytes: 1792
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N, M;
    cin >> N >> M;
    V<ll> A(N), B(M);
    for(auto &&e : A) cin >> e;
    for(auto &&e : B) cin >> e;
    V<ll> cnt_sum_b(2e5 + 10), sum_b(2e5 + 10);
    for(auto &&e : B) cnt_sum_b[e]++;
    for(ll i = 1; i < sum_b.size(); i++) {
        sum_b[i] = i * cnt_sum_b[i] + sum_b[i - 1];
        cnt_sum_b[i] += cnt_sum_b[i - 1];
    }

    ll ans = 0;
    ll div_upper = sqrt(2e5 + 10);
    for(auto &&ele : A) {
        ans += ele * (cnt_sum_b.back() - cnt_sum_b[ele]);
        ll lower_idx = 0;
        for(ll d_val = 1; d_val < div_upper; d_val++) {
            ll lower = ele / (d_val + 1);
            ll upper = ele / d_val;
            lower_idx = lower;
            ans += ele * (cnt_sum_b[upper] - cnt_sum_b[lower]);
            ans -= d_val * (sum_b[upper] - sum_b[lower]);
        }
        for(ll i = 1; i <= lower_idx; i++) ans += (cnt_sum_b[i] - cnt_sum_b[i - 1]) * (ele % i);
    }

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



Measured memory_bytes: 9052
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct UnionFind {
private:
    vector< ll > data;
public:
    UnionFind(ll sz) {
        data.assign(sz, -1);
    }
    bool unite(ll x, ll y) {
        x = find(x), y = find(y);
        if(x == y) return(false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return(true);
    }
    ll find(ll k) {
        if(data[k] < 0) return(k);
        return(data[k] = find(data[k]));
    }
    ll size(ll k){
        return(-data[find(k)]);
    }
};

int main () {

    ll n; cin >>n;
    ll m; cin >>m;
    vector<ll> a(m);
    vector<ll> b(m);
    for (ll i = 0; i < m; i++) {
        cin >> a[m-1-i] >> b[m-1-i];
        a[m-1-i] -= 1;
        b[m-1-i] -= 1;
    }

    UnionFind tree(n);
    vector<ll> ans;
    ll res = n *(n-1)/2;
    ans.push_back(res);
    for (ll i = 0; i < m-1; i++) {
        ll n1 = tree.size(a[i]);
        ll n2 = tree.size(b[i]);
        if(tree.unite(a[i], b[i])) {
            res -= n1*n2;
            ans.push_back(res);
        } else {
            ans.push_back(res);
        }
    }

    for (ll i = 0; i < m; i++) {
        cout << ans[m-1-i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
class Calc{
	#define N 10000
	#define MOD 100000000
    public:
    ll carry, borrow,w,remainder;
	ll z[N];
	void ladd(ll a[], ll b[]){
		carry=0;
		for(int i=N-1;i>=0;i--){
			z[i]=a[i]+b[i]+carry;
			if(z[i]<MOD)carry=0;
			else{
				z[i]-=MOD;
				carry=1;
			}
		}
	}
	void lsub(ll a[], ll b[]){
		borrow=0;
		for(int i=N-1;i>=0;i--){
			z[i]=a[i]-b[i]-borrow;
			if(z[i]>=0)borrow=0;
			else{
				z[i]+=MOD;
				borrow=1;
			}
		}
	}
	void lmul(ll c[], ll d){
		carry=0;
		for(int i=N-1;i>=0;i--){
			w=c[i];
			z[i]=(w*d+carry)%MOD;
			carry=(w*d+carry)/MOD;
		}
	}
	void ldiv(ll c[],ll d){
		remainder=0;
		for(int i=0;i<N;i++){
			w=c[i];
			z[i]=(w+remainder)/d;
			remainder=((w+remainder)%d)*MOD;
		}
	}
	void displayL(ll s[]){
		int t=0;
		for(;t<N;t++)if(s[t]){
			printf("%d",s[t]);
			break;
		}
		for(t++;t<N;t++)printf("%08d",s[t]);
		printf("\n");
	}
	void displayS(ll s){
		for(int i=0;i<N-1;i++)printf("%8s"," ");
		printf("%08d\n",s);
	}
};
int main(){
	Calc calc;
	ll a,b,c;
	cin>>a>>b>>c;
	c-=a*b;
	if(c<0){
		cout<<0<<endl;
	}else{
		rep(i,N){
			calc.z[i]=0;
		}
		calc.z[N-1]=1;
		loop(i,1,c+a)calc.lmul(calc.z,i);
		loop(i,1,c+1)calc.ldiv(calc.z,i);
		loop(i,1,a)calc.ldiv(calc.z,i);
		calc.displayL(calc.z);
	}
}

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

#define rep(i, n) for(int i=0; i<n; i++) 

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

    string s1, s2;
    rep(i, s.size()){
        s1 += i % 2 == 0 ? '1' : '0';
        s2 += i % 2 == 0 ? '0' : '1';
    }

    int cnt1 = 0;
    int cnt2 = 0;

    rep(i, s.size()){
        if(s[i]!=s1[i])
            cnt1++;
        if(s[i]!=s2[i])
            cnt2++;
    }

    cout << min(cnt1, cnt2) << endl;
}

Measured memory_bytes: 768
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <memory.h>
#include <algorithm>
#include <cassert>
#include <numeric>
#include <functional>
#include <queue>

using namespace std;

#define prev prev_______________________
#define next next_______________________
#define hash hash_______________________
#define y1 y1___________________________

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(c) (c).begin(), (c).end()
#define sz(c) int((c).size())
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define fst first
#define snd second

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using pii = pair<int, int>;

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr);
#else
#define eprintf(args...) ;
#define cerr if (0) cerr
#endif

int n;
vi a;

bool read() {
    if  (!(cin >> n)) {
        return 0;
    }
    a.resize(n);
    forn(i, n) {
        cin >> a[i];
    }
    return 1;
}

void solve() {
    vi vals;
    forn(i, n) {
        vals.pb(a[i] - (i + 1));
    }
    sort(all(vals));

    int b = vals[n / 2];
    ll ans = 0;
    forn(i, n) {
        ans += abs(a[i] - (i + 1) - 1ll * b);
    }
    cout << ans << endl;
}

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

#ifdef LOCAL
    #define FNAME "a"
    freopen(FNAME ".in", "r", stdin);
    freopen(FNAME ".out", "w", stdout);
#endif

    while (read()) {
        solve();
    }

    return 0;
}



Measured memory_bytes: 2168
N = int(input())
Alist = [int(i) for i in list(input().split())]
Blist = [int(i) for i in list(input().split())]
ans = 0
for i in range(N):
    tmp = Alist[i]-Blist[i]
    if tmp < 0:
        ans += Alist[i]
        Blist[i] = -1 * (tmp)
    else:
        ans += Blist[i]
        continue
    tmp = Alist[i+1] - Blist[i]
    if tmp < 0:
        ans += Alist[i+1]
        Alist[i + 1] = 0
    else:
        ans += Blist[i]
        Alist[i+1] = tmp

print(ans)

Measured memory_bytes: 18468
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<vector<int>>c(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++) cin>>c[i][j];
  }
  string ans="No";
    int a1=0;
    int b1=c[0][0]-a1;
    int b2=c[0][1]-a1;
    int b3=c[0][2]-a1;
    int a21=c[1][0]-b1;
    int a22=c[1][1]-b2;
    int a23=c[1][2]-b3;
    int a31=c[2][0]-b1;
    int a32=c[2][1]-b2;
    int a33=c[2][2]-b3;
    if((a21==a22 && a22==a23) && (a31==a32 && a32==a33)) ans="Yes";
  cout<<ans<<endl;
      
}

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

typedef pair<int, int> P;

int main() {
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++)
        cin >> X[i] >> Y[i];

    map<P, int> ma;
    int max_cnt = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) continue;
            
            int dx = X[i] - X[j];
            int dy = Y[i] - Y[j];
            ma[P(dx, dy)]++;
            max_cnt = max(max_cnt, ma[P(dx, dy)]);
        }
    }

    cout << N - max_cnt << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int a, b, c, mod[101] = {};
    cin >> a >> b >> c;
    int val = a;
    bool ok = false;
    while (true) {
        int m = val%b;
        if (mod[m]) break;
        mod[m] = true;
        if (m == c) {
            ok = true;
            break;
        }
        val += a;
    }
    if (ok) cout << "YES\n";
    else cout << "NO\n";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    int x;
    cin >> x;
    int ans;
    if (x < 600) {
        ans = 8;
    } else if (x < 800) {
        ans = 7;;
    } else if (x < 1000) {
        ans = 6;
    } else if (x < 1200) {
        ans = 5;
    } else if (x < 1400) {
        ans = 4;
    } else if (x < 1600) {
        ans = 3;
    } else if (x < 1800) {
        ans = 2;
    } else if (x < 2000) {
        ans = 1;
    }
    cout << ans << endl;

    return 0;
}

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

//ここから。
int main(){
    int N;
    cin >> N;
    vector<int> a(N+1,0);
    rep(i,N) cin >> a[i];
    ll ans = 0;
    rep(i,N){
        ans += a[i]/2;
        a[i] %= 2;
        if(a[i] & (a[i + 1]>0)){
            ans++;
            a[i+1]--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
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); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N;cin>>N;
  string S;cin>>S;
  vector<vector<int>> left(10,vector<int>(N,0)),right(10,vector<int>(N,0));
  vector<int> to_int(N,0);
  int a;
  a=(int)S.at(0)-'0';
  to_int[0]=a;
  left[a][0]=1;
  REP(i,1,N){
    a = (int) S.at(i)-'0';
    to_int[i]=a;
    REP(j,0,10){
        left[j][i]=left[j][i-1]+(a==j?1:0);
    }
  }
  a=(int)S.at(N-1)-'0';
  right[a][N-1]=1;
  RREP(i,N-2,-1){
    a=(int) S.at(i)-'0';
    REP(j,0,10){
        right[j][i]=right[j][i+1]+(a==j?1:0);
    }
  }
  // debug(right);
  // debug(left);
  vector<vector<vector<int>>> memo(10,vector<vector<int>>(10,vector<int>(10,0)));
  int ans=0;
  REP(i,1,N-1){
    REP(j,0,10){
      REP(k,0,10){
       if((left[j][i-1])&&(right[k][i+1])){
         memo[j][k][to_int[i]]=1;
       }
      }
    }
  }
  REP(i,0,10){
    REP(j,0,10){
      REP(k,0,10){
        ans+=memo[i][j][k];
      }
    }
  }
  print(ans);
}


Measured memory_bytes: 5268
class EnglishText
  def initialize
    @texts = []
  end

  def read (lineage)
    lineage.times{@texts << gets.chomp}
  end

  def change (before_string, after_string)
    @texts.each{|text| puts text.gsub(/#{before_string}/, after_string) }
  end
end

lineage = gets.chomp.to_i
text = EnglishText.new
text.read(lineage)
text.change('Hoshino', 'Hoshina')

Measured memory_bytes: 6152
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

int group(int x){
	switch(x){
		case 2:
			return 3;
		case 4:
		case 6:
		case 9:
		case 11:
			return 2;
		default:
			return 1;
	}
}

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

	int x, y;
	cin >> x >> y;
	if(group(x) == group(y)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    X, Y, A, B, C = map(int, input().split())
    P = sorted(list(map(int, input().split())), reverse=True)[:X]
    Q = sorted(list(map(int, input().split())), reverse=True)[:Y]
    R = sorted(list(map(int, input().split())), reverse=True)
    L = sorted(P + Q + R, reverse=True)
    res = sum(L[:X + Y])
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 28360
import math
import fractions
a,b,c,d=list(map(int,input().split()))
a-=1
calc_c=(b-b//c)-(a-a//c)
calc_d=(b-b//d)-(a-a//d)
count=calc_c+calc_d
def lcm(x, y):
    #return (x * y) // math.gcd(x, y)
    return math.floor((x * y) /fractions.gcd(x, y))


com=lcm(c, d)
tmp=(b-b//com)-(a-a//com)
print(count-tmp)

Measured memory_bytes: 5984
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n ;
  cin >> n ;
  int a[200005];
  for(int i = 1 ; i <= n ; i++)    cin>>a[i];
  int s=1;
  for(int i = 1 ; i <= n ; i++) if(a[i]==s)  s++;
  if(s==1) cout << -1 << endl ;
  else
    cout << n - s + 1 << endl ;
  return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
from collections import defaultdict, deque
import heapq


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    if M % 2 != 0:
        print(-1)
        return

    adj = defaultdict(set)
    for a, b in zip(A, B):
        adj[a].add(b)
        adj[b].add(a)
    parent = [None for _ in range(N)]
    children = [set() for _ in range(N)]

    res = set()
    count = [0 for _ in range(N)]

    Q = deque([0], N)
    visited = [False for _ in range(N)]
    visited[0] = True

    while len(Q) > 0:
        u = Q.popleft()
        for v in adj[u]:
            if parent[u] == v:
                continue
            if visited[v]:
                if (v, u) in res:
                    continue
                res.add((u, v))
                count[u] += 1
                continue
            parent[v] = u
            children[u].add(v)
            visited[v] = True
            Q.append(v)
    visited = [False for _ in range(N)]
    Q = deque([0], N)
    while len(Q) > 0:
        u = Q.popleft()
        if (len(children[u]) > 0
            and not all(visited[v] for v in children[u])
            ):
            Q.appendleft(u)
            Q.extendleft(children[u])
            continue
        
        if parent[u] is None:
            visited[u] = True
            continue
        
        v = parent[u]
        if count[u] % 2 == 0:
            res.add((v, u))
            count[v] += 1
        else:
            res.add((u, v))
            count[u] += 1
        visited[u] = True

    for c, d in res:
        print(c+1, d+1)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]" 
    B = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        A[i] = int(next(tokens)) - 1
        B[i] = int(next(tokens)) - 1
    solve(N, M, A, B)

if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;

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

int solve(const int N, const string S) {
    int acc = 0;

    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            for (int k = 0; k <= 9; k++) {
                vector<int> cand = {i, j, k};
                int pos = 0;
                bool ok = false;
                for (int s_ind = 0; s_ind < N; s_ind++) {
                    if (cand[pos] == (S[s_ind] - '0')) {
                        pos++;
                        if (pos == 3) {
                            ok = true;
                            break;
                        }
                    }
                }
                if (ok) {
                    acc++;
                }
            }
        }
    }

    return acc;
}

int main(void) {
    int N;
    string S;
    cin >> N >> S;

    cout << solve(N, S) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  char S[11],T[11];
  int i,n;
  scanf("%s",S);
  scanf("%s",T);
  for(i=0;i<11;i++){
    if(S[i]=='\0'){
      n=i;
      break;
    }
  }
  if(strncmp(S,T,n)==0) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 1768
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll inf=100000000000000000;
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll L[100];
ll f(ll n,ll x){
    if(n==0)return 1;
    else if(x==1)return 0;
    else if(x>=1&&x<=1+L[n-1])return f(n-1,x-1);
    else if(x==L[n-1]+2)return f(n-1,L[n-1])+1;
    else if(x>=(L[n-1]+3)&&x<=(2*(L[n-1]+1)))return f(n-1,L[n-1])+1+f(n-1,x-(L[n-1]+2));
    else if(x==(2*L[n-1]+3))return 2*f(n-1,L[n-1])+1;
    return 0;
}
int main(){
    ll n,x;cin>>n>>x;
    L[0]=1;
    for(int i=1;i<n+1;i++){
        L[i]=L[i-1]*2+3;
    }
    cout<<f(n,x)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#define nmax 101

using namespace std;
ifstream fin("p.in");
ofstream fout("p.out");

struct object
{
    long long val,g;
}obj[nmax];

int n,g_max;
long long sol;
long long val_curr[nmax][nmax*nmax*10];

int main()
{
    cin>>n>>g_max;
    for(int i=1; i<=n; i++)
        cin>>obj[i].g>>obj[i].val;

    for(int i=1; i<=n; i++)
        for(int j=0; j<=g_max; j++)
            {
                if(obj[i].g<=j)
                    val_curr[i][j]=max(obj[i].val+val_curr[i-1][j-obj[i].g],val_curr[i-1][j]);
                else
                    val_curr[i][j]=val_curr[i-1][j];
            }

    cout<<val_curr[n][g_max];
    return 0;
}


Measured memory_bytes: 79872
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int a,b;cin>>a>>b;
    if(a<=9&&b<=9){
        cout<<(a*b)<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
# 解説放送

def pow2(n, mod):
    """2のn乗まで"""
    t = 1
    yield t
    for _ in range(n):
        t = t * 2 % mod
        yield t


def main():
    MOD = 10 ** 9 + 7

    N = int(input())
    *c, = map(int, input().split())

    c.sort()

    *two, = pow2(N, MOD)

    ans = 0
    for l, x in enumerate(c):
        # x:=係数.この位置の操作にかかるコストの総和を求める.
        # r:=xの右側にある要素数
        # (1<<r)個の状態を行として並べて,列で不一致数を確認すると,どの列も状態の半分が不一致.これがr列ある.
        r = N - l - 1

        t = two[r]
        if r != 0:
            t += two[r - 1] * r  # 右側の個数
        t = t * two[l] % MOD
        t = t * x % MOD
        ans += t

    ans = ans * two[N] % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25768
// review
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
typedef long long ll;
int n;
ll a[300010];
ll former[100010], latter[100010];

void solve() {
  priority_queue<ll, vector<ll>, greater<ll> > pq;
  priority_queue<ll> pq2;
  ll sum = 0;
  for (int i=0;i<n;i++) {
    pq.push(a[i]);
    sum += a[i];
  }
  former[0] = sum;
  for (int i=n;i<2*n;i++) {
    pq.push(a[i]);
    sum -= pq.top();
    pq.pop();
    sum += a[i];
    former[i-n+1] = sum;
  }
  sum = 0;
  for (int i=2*n;i<3*n;i++) {
    pq2.push(a[i]);
    sum += a[i];
  }
  latter[n] = sum;
  for (int i=2*n-1;i>=n;i--) {
    pq2.push(a[i]);
    sum -= pq2.top();
    pq2.pop();
    sum += a[i];
    latter[i-n] = sum;
  }
  ll ans = -1e16-7;
  for (int i=0;i<=n;i++) {
    ans = max(ans, former[i] - latter[i]);
  }
  cout << ans << endl;
}

int main() {
  cin >> n;
  for (int i=0;i<n*3;i++) {
    cin >> a[i];
  }
  solve();
}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  int k; cin >> k, --k;
  for (auto&& c : s) if (c != s[k]) {
    c = '*';
  }
  cout << s << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int a[30];
bool rec(int d,int t){
  if(t==0) return true;
  if(d==n||t<0) return false;
  return rec(d+1,t)||rec(d+1,t-a[d]);
}
signed main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  int q;
  cin>>q;
  int m[q];
  for(int i=0;i<q;i++) cin>>m[i];
  for(int i=0;i<q;i++) cout<<(rec(0,m[i])?"yes":"no")<<endl;
  return 0;
}

Measured memory_bytes: 3064
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,cnt=0,ans=1e9;
string s;

int main()
{
	cin>>n>>s;
	rep(i,n) if(s[i]=='.') cnt++;
	ans=min(ans,cnt);
	rep(i,n)
	{
		if(s[i]=='.') cnt--;
		else cnt++;
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;

int main(){
        char a,b,c,d;
        scanf("%c%c%c%c",&a,&b,&c,&d);
        int A,B,C,D;
        A = a-'0';
        B = b-'0';
        C = c-'0';
        D = d-'0';
        int tmp,flag;
        flag=0;
        char op1,op2,op3;
        rep(i,2){
                rep(j,2){
                        rep(k,2){
                                if(flag==0) {
                                        if(i==0) tmp = A+B;
                                        else tmp = A-B;
                                        if(j==0) tmp= tmp+C;
                                        else tmp = tmp-C;
                                        if(k==0) tmp = tmp+D;
                                        else tmp = tmp-D;
                                        if(tmp==7) {
                                                if(i==0) op1='+';
                                                else op1='-';
                                                if(j==0) op2='+';
                                                else op2='-';
                                                if(k==0) op3='+';
                                                else op3='-';
                                                printf("%d%c%d%c%d%c%d=7",A,op1,B,op2,C,op3,D);
                                                flag=1;
                                        }
                                }
                        }
                }
        }
        return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	char[] S = sc.next().toCharArray();
    	String ans = "AC";
    	boolean check = true;
    	for (int i = 0; i < S.length; i++) {
    		if (i == 0) {
    			if (S[0] != 'A') ans = "WA";
    		} else if (1 < i && i < S.length-1 && check) {
    			if (S[i] == 'C') check = false;
    		} else {
    			if (S[i] < 97) ans = "WA";
    		}
    	}
    	System.out.println(check ? "WA" : ans);
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define rREP(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (ll i = a; i <= b; ++i)
#define rFOR(i, a, b) for (ll i = a; i >= b; --i)
#define aFOR(i, V) for (auto i : V)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
#define INF 1'000'000'007 // 10^9 + 7
#define MOD 1'000'000'007 // 10^9 + 7
#define lINF 1'000'000'000'000'000'007 // 10^18 + 7
// ------------------------------

int main() {
    string S;
    cin >> S;
    if (S[S.size() - 1] == 's') S += "es";
    else S += "s";
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 3628