akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, k;
    int score[3];
    seika t;
    cin >> n >> k >> score[0] >> score[1] >> score[2] >> t;
    akari<int> ts(n);
    for (int i = 0; i < n; i++)
    {
        if (t[i] == 'r')
        {
            ts[i] = 0;
        }
        if (t[i] == 's')
        {
            ts[i] = 1;
        }
        if (t[i] == 'p')
        {
            ts[i] = 2;
        }
    }
    i64 ans = 0;
    for (int i = 0; i < k; i++)
    {
        bool used = 1;
        ans += score[(ts[i] + 2) % 3];
        for (int j = i; j + k < n; j += k)
        {
            if (ts[j] == ts[j + k])
            {
                if (used)
                {
                    used = 0;
                }
                else
                {
                    used = 1;
                    ans += score[(ts[j] + 2) % 3];
                }
                continue;
            }
            used = 1;
            ans += score[(ts[j + k] + 2) % 3];
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 896
len_arr = int(input())
arr = list(map(int, input().split()))

index = 0
found = 0

for i in range(1, len_arr+1):
    try:
        index = arr.index(i, index)
        found += 1
    except ValueError:
        break

if found:
    print(len_arr - found)
else:
    print(-1)
exit(0)


Measured memory_bytes: 26140
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1e5)+10;
int n,a,b,tot,head[maxn];
int nxt[maxn*2],to[maxn*2];
int fa[maxn][20],dep[maxn],ans,tmp;
bool mk[maxn];
void add(int x,int y) {
	tot++; nxt[tot]=head[x];
	head[x]=tot; to[tot]=y;
}
void dfs(int u,int p) {
	fa[u][0]=p;
	dep[u]=dep[p]+1;
	for (int i=head[u],v;i;i=nxt[i]) {
		v=to[i];
		if (v==p) continue;
		dfs(v,u);
	}
}
int lca(int x,int y) {
	if (dep[x]>dep[y]) swap(x,y);
	for (int i=19;i>=0;i--)
		if (dep[fa[y][i]]>=dep[x]) y=fa[y][i];
	for (int i=19;i>=0;i--)
		if (fa[x][i]!=fa[y][i])
			x=fa[x][i],y=fa[y][i];
	if (x==y) return x;
	return fa[x][0];
}
void dfs(int u) {
	mk[u]=1;
	for (int i=head[u],v;i;i=nxt[i]) {
		v=to[i];
		if (v!=fa[u][0]) dfs(v);
	}
}
int dis(int x,int y,int z) {
	return dep[x]+dep[y]-2*dep[z];
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(a); read(b);
	int x,y;
	for (int i=1;i<n;i++) {
		read(x); read(y);
		add(x,y); add(y,x);
	}
	dfs(a,0);
	for (int j=1;j<=19;j++)
	for (int i=1;i<=n;i++)
		fa[i][j]=fa[fa[i][j-1]][j-1];
	dfs(b);
	x=b;
	while (fa[x][0]!=a) mk[x]=1,x=fa[x][0];
	for (int i=1;i<=n;i++)
		if (!mk[i]) {
			x=lca(b,i);
			if (dep[x]-1>=dep[b]-dep[x]) tmp=(dep[b]-1)/2;
			else {
				tmp=dep[i]-1+dis(b,i,x)-(dep[i]-1)-1;
			}
			ans=max(ans,tmp);
		}
	printf("%d\n",ans);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 12928
#include<bits/stdc++.h>
#define LL long long
#define LD long double
using namespace std;
const int MAXN=1e5+10;
const int mod=998244353;
int n,a[MAXN],ans,s[MAXN],MX;
int read(){int sss=0,fff=1;char ccc=getchar();while(ccc<'0'||ccc>'9'){if(ccc=='-') fff=-1;ccc=getchar();}while(ccc>='0'&&ccc<='9'){sss=sss*10+ccc-'0';ccc=getchar();}return sss*fff;}
int ksm(int base,int k)
{
	int sum=1;
	while(k)
	{
		if(k&1) sum=1ll*sum*base%mod;
		base=1ll*base*base%mod;
		k>>=1;
	}
	return sum;
}
void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
	{
		s[a[i]]++;
		MX=max(MX,a[i]);
	}
	if(a[1]!=0||s[0]>=2)
	{
		printf("0\n");
		return;
	}
	for(int i=1;i<=MX;i++)
		if(s[i]==0)
		{
			printf("0\n");
			return;
		}
	ans=1;
	for(int i=1;i<=MX;i++)
		ans=1ll*ans*ksm(s[i-1],s[i])%mod;
	printf("%d\n",ans);
}
int main()
{
//	freopen("123.in","r",stdin);
//	freopen("123.out","w",stdout);
	int T=1;
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>

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

using namespace std;

const int INF = 0x3fffffff;

int C[20], dp[20005][300];
int main(){
	int N, M;
	while(cin >> N >> M, N|M){
		rep(i,M) cin >> C[i];
		fill( (int*)dp[0], (int*)dp[20005], INF );
		dp[0][128] = 0;
		rep(i,N){
			int x;
			cin >> x;
			rep(j,256) rep(k,M){
				int nx = j + C[k];
				nx = max( nx, 0 );
				nx = min( nx, 255 );
				int df = abs( nx - x );
				dp[i+1][nx] = min( dp[i+1][nx], dp[i][j] + (df * df) );
			}
		}
		int ans = INF;
		rep(i,256){
			ans = min( ans, dp[N][i] );
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 26452
#include <iostream>
using namespace std;
typedef long long ll;
ll m=998244353;
ll a[301], s[301], dp[301][90001];
ll pow(ll x, ll y){
    if(y==0)return 1;
    if(y%2==0)return pow((x*x)%m, y/2);
    return (x*pow(x, y-1))%m;
}
int main(void){
    int n;
    ll z;
    cin>>n;
    a[0]=s[0]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        s[i]=s[i-1]+a[i];
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=s[i];j++){
            dp[i][j]=dp[i-1][j]*2;
            if(j-a[i]>=0)dp[i][j]+=dp[i-1][j-a[i]];
            dp[i][j]%=m;
            //cout<<i<<", "<<j<<" : "<<dp[i][j]<<endl;
        }
    }
    z=pow(3, n);
    for(int j=(s[n]+1)/2;j<=s[n];j++){
        z+=m-dp[n][j];
        z%=m;
        z+=m-dp[n][j];
        z%=m;
        z+=m-dp[n][j];
        z%=m;
    }
    if(s[n]%2==0){
        dp[0][0]=1;
        for(int i=1;i<=n;i++){
            for(int j=0;j<=s[i];j++){
                dp[i][j]=dp[i-1][j];
                if(j-a[i]>=0)dp[i][j]+=dp[i-1][j-a[i]];
                dp[i][j]%=m;
            }
        }
        z+=dp[n][s[n]/2]*3;
        z%=m;
    }
    cout<<z<<endl;
}


Measured memory_bytes: 209920
#include <bits/stdc++.h>
#define no { cout << "NO\n"; exit(0); }

using namespace std;

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    string s;
    cin >> s;

    int i = 0;
    if(s[i] == 'A') ++i;
    if(i + 2 >= s.size() || s.substr(i, 3) != "KIH") no;
    i += 3;

    if(i<s.size() && s[i] == 'A') ++i;

    if(i==s.size() || s[i] != 'B') no
        else ++i;

    if(i<s.size() && s[i] == 'A') ++i;

    if(i==s.size() || s[i] != 'R') no
        else ++i;

    if(i<s.size() && s[i] == 'A') ++i;

    if(i != s.size()) no;

    cout<<"YES\n";

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a;
  int b;
  int p=0;
  int q=0;
  for (int i=0; i<N; i++) {
    cin >> a;
    p = 0;
    for (int j=0; j>=0; j++) {
      b = a % 2;
      //cout << b << "!" <<endl;
      if (b!=0) {
        break;
      }
      else {
        a /= 2;
        p++;
        //cout << a <<" " << p << endl;
      }
    }
    if (q>p || q==0){
      q = p;
      if (p==0){
        q = p;
      	break;
      }
      //cout << q <<"Q" <<endl;
    }
  }
  cout << q << endl;
}


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

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

typedef long long ll;
typedef pair<int, int> P;

#define MAX 100005
#define INF 1001001001

int main(int, char**)
{
  int t;
  cin >> t;

  rep(_,t) {
    int n;
    cin >> n;

    vector< priority_queue<P> > diff(2);
    ll ans = 0;
    rep(i,n) {
      int k, l, r;
      cin >> k >> l >> r;
      if (l >= r) {
        diff[0].push({k-1,l-r});
        ans += r;
      } else {
        diff[1].push({n-k-1,r-l});
        ans += l;
      }
    }

    rep(i,2) {
      int ds = diff[i].size();
      priority_queue<int> q;
      rep(j,ds) {
        while(!diff[i].empty() && diff[i].top().first >= ds-j-1) {
          q.push(diff[i].top().second); diff[i].pop();
        }
        if (!q.empty()) { ans += q.top(); q.pop(); }
      }
    }

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


Measured memory_bytes: 5628
N = int(input())
A = [[int(x) for x in input().split()] for _ in range(N)]

flag = True
for k in range(N):
	for i in range(N):
		for j in range(i):
			if A[i][j] > A[i][k] + A[k][j]:
				flag = False
				break
		if not flag:
			break
	if not flag:
		break

ans = 0
if flag:
	for i in range(N):
		for j in range(i):
			flag = True
			for k in range(N):
				if k != i and k != j:
					if A[i][j] == A[i][k] + A[k][j]:
						flag = False
						break
			if flag:
				ans += A[i][j]
	print(ans)
else:
	print(-1)

Measured memory_bytes: 44380
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

int main()
{
    int N, K; cin >> N >> K;

    double sum = 0.0;
    rep(i, N){
        double ans = 1.0;
        for (int j = i + 1; j < K; j *= 2){
            ans /= 2.0;
        }
        sum += ans;
    }
    sum /= (double)N;
    printf("%.10f\n", sum);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,ans=0;
  cin>>n;
  vector<string> datan(n);
  for(int i=0;i<n;i++){
    cin>>datan[i];
  }
  cin>>m;
  vector<string> datam(m);
  for(int i=0;i<m;i++){
    cin>>datam[i];
  }
  for(int i=0;i<n;i++){
    int c=0;
    for(int j=0;j<n;j++){
      if(datan[i]==datan[j]) c++;
    }
    for(int j=0;j<m;j++){
      if(datan[i]==datam[j]) c--;      
    }
    ans=max(ans,c);
  }
  
  
  cout<<ans<<endl;
  
}

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

struct st { int a, b, c; };
vector<st>E[10000];
int d[10000], c[10000];
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		rep(i, n)E[i].clear();
		rep(i, m) {
			int u, v, d, c; scanf("%d%d%d%d", &u, &v, &d, &c); u--; v--;
			E[u].push_back({ v,d,c }); E[v].push_back({ u,d,c });
		}
		memset(d, 0x3f, sizeof(d));
		priority_queue<P>que;
		d[0] = 0; que.push(P(0, 0));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			if (d[p.second] != p.first)continue;
			for (st&v : E[p.second]) {
				if (d[v.a] > p.first + v.b) {
					d[v.a] = p.first + v.b;
					c[v.a] = v.c;
					que.push(P(d[v.a], v.a));
				}
				else if (d[v.a] == p.first + v.b&&c[v.a] > v.c)c[v.a] = v.c;
			}
		}
		printf("%d\n", accumulate(c, c + n, 0));
	}
}

Measured memory_bytes: 5136
#include <iostream>
#include <cmath>

using namespace std;
const long long int mod = 1L * 1000 * 1000 * 1000 + 7;
int main() {
  long long int a, b; cin >> a >> b;
  if (abs(a-b) >= 2) {
    cout << 0 << endl;
    return 0;
  }

  long long int ans = 1;
  for (long long int i = 1; i <= a; i++) {
    ans = ans * i % mod;
  }
  for (long long int i = 1; i <= b; i++) {
    ans = ans * i % mod;
  }
  if (a == b) {
    ans = ans * 2L % mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#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 1e12
typedef long long ll;

int N;
vector<vector<bool>> A(300, vector<bool>(300,true));
vector<vector<ll>> dp(300, vector<ll>(300,INF));

int main() {
    cin >> N;

    REP(i,N){
        REP(j,N){
            cin >> dp[i][j];
        }
    }

    REP(i,N){
        REP(j,N){
            REP(k,N){
                if (j==k || k==i || i==j) continue;
                if (dp[j][k] > dp[j][i] + dp[i][k]){
                    cout << -1 << endl;
                    return 0;
                }else if (dp[j][k] == dp[j][i] + dp[i][k]){
                    A[j][k] = false;
                }
            }
        }
    }

    ll ans = 0;

     REP(i,N){
        REP(j,N){
            if (A[i][j]) ans += dp[i][j];
        }
    }

    cout << ans/2 << endl;

    return 0;
}

Measured memory_bytes: 4356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define inf 2e18
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007
#define lop0(n) for(ll i=0;i<n;i++)
#define lopj(n) for(ll j=0;j<n;j++)
#define lop1(n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(),v.end()
ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll vis[100005];
main()
{
    ll n;
    cin>>n;
    ll sum=0;
    while(n--)
    {
        ll a;
        cin>>a;
        sum+=a;
        vis[a]++;
    }
    ll q;
    cin>>q;
    while(q--)
    {
        ll b,c;
        cin>>b>>c;
        sum-=(vis[b]*b);
        sum+=(vis[b]*c);
        vis[c]+=vis[b];
        vis[b]=0;
        cout<<sum<<endl;
    }

}



Measured memory_bytes: 4360
n = int(input())
x = [int(i) for i in input().split()]

x.sort()
mx = x[n-1]
print(mx," ",sep="",end="")
i = 1
while True:
    if x[i] - mx/2 >= 0:
        break
    i += 1
if mx/2 - x[i-1] <= x[i] - mx/2:
    print(x[i-1])
else:
    print(x[i])


Measured memory_bytes: 14052
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, const T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, const T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

int dp[2005][2005][2];
signed main() {
	int m, n; cin >> m >> n;
	V s(m + 1);
	s[m] = 0;
	rep(i, m) {
		char c; cin >> c;
		s[i] = c == 'I';
	}
	V t(n + 1);
	rep(i, n) {
		char c; cin >> c;
		t[i] = c == 'I';
	}
	t[n] = 0;

	int ans = 0;
	rep(i, m + 1) rep(j, n + 1) {
		maxup(dp[i + 1][j][0], (dp[i][j][1] + 1) * !!dp[i][j][1] * !s[i]);
		maxup(dp[i][j + 1][0], (dp[i][j][1] + 1) * !!dp[i][j][1] * !t[j]);

		maxup(dp[i + 1][j][1], (dp[i][j][0] + 1) * s[i]);
		maxup(dp[i][j + 1][1], (dp[i][j][0] + 1) * t[j]);

		maxup(ans, dp[i + 1][j][1]);
		maxup(ans, dp[i][j + 1][1]);
	}
	cout << ans << endl;

	//system("pause");
}

Measured memory_bytes: 65832
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n, b;
	vi a;
	cin >> n;
	rep(i, n) {
		cin >> b;
		a.pb(b);
	}
	sort(a.begin(), a.end());
	cout << a[n - 1] - a[0];
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

	int n,m,i,j;
	int a[100][100]={},b[100]={},c[100]={};
	scanf("%d %d",&n,&m);

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(j=0; j<m; j++){
		scanf("%d",&b[j]);
	}

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			c[i] += a[i][j]*b[j];
		}
	}
	for(i=0; i<n; i++){
		printf("%d\n",c[i]);
	}
	
	return 0;
}

Measured memory_bytes: 648
#include<stdio.h>
char yokosen[7][6];
char tatesen[6][7];

int main(){
	for(int i=0;i<9;i++)scanf("%s",i%2?tatesen[i/2+1]+1:yokosen[i/2+1]+1);
	int dir=100000;
	int row=1;
	int col=2;
	printf("R");
	while(1){
	//	printf("\n%c %c",tatesen[row][col],yokosen[row][col]);
		switch(dir%4){
			case 0://migi
				if(tatesen[row-1][col]=='1'){
					dir--;
					row--;
					printf("U");
				}
				else if(yokosen[row][col]=='1'){
					col++;
					printf("R");
				}
				else if(tatesen[row][col]=='1'){
					row++;
					dir++;
					printf("D");
				}
				else {
					col--;
					dir+=2;
					printf("L");
				}
				break;
			case 1://shita
				if(yokosen[row][col]=='1'){
					col++;
					dir--;
					printf("R");
				}
				else if(tatesen[row][col]=='1'){
					row++;
					printf("D");
				}
				else if(yokosen[row][col-1]=='1'){
					col--;
					dir++;
					printf("L");
				}
				else{
					dir+=2;
					row--;
					printf("U");
				}
				break;
			case 2://hidari
				if(tatesen[row][col]=='1'){
					row++;
					dir--;
					printf("D");
				}
				else if(yokosen[row][col-1]=='1'){
					col--;
					printf("L");
				}
				else if(tatesen[row-1][col]=='1'){
					dir++;
					row--;
					printf("U");
				}
				else {
					col++;
					dir+=2;
					printf("R");
				}
				break;
			case 3://ue
				if(yokosen[row][col-1]=='1'){
					col--;
					dir--;
					printf("L");
				}
				else if(tatesen[row-1][col]=='1'){
					row--;
					printf("U");
				}
				else if(yokosen[row][col]=='1'){
					col++;
					dir++;
					printf("R");
				}
				else{
					dir+=2;
					row++;
					printf("D");
				}
				break;
		}
		if(row==1&&col==1)break;
	}
	printf("\n");
}

Measured memory_bytes: 0
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
q = int(input())
dict_A = Counter(A)
sum_list = sum(A)
for i in range(q):
    b, c = map(int, input().split())
    if b not in dict_A:
        print(sum_list)
    else:
        b_num = dict_A[b]
        dict_A[c] += dict_A[b]
        dict_A[b] = 0
        sum_list = sum_list + (c - b) * b_num
        print(sum_list)


Measured memory_bytes: 21464
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class ABC117D
    {
        // https://atcoder.jp/contests/abc177/tasks/abc177_d

        static int[] ls;

        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split();
            int N = Int32.Parse(NM[0]);
            int M = Int32.Parse(NM[1]);

            ls = new int[N];

            for (int i = 0; i < M; i++)
            {
                var AB = Console.ReadLine().Split();
                int A = Int32.Parse(AB[0]);
                int B = Int32.Parse(AB[1]);

                bool a = hasFriend(A);
                bool b = hasFriend(B);

                if (a && b)
                {
                    int C = getParent(A);
                    int D = getParent(B);

                    if (C != D)
                    {
                        ls[C - 1] += ls[D - 1] - 1; // 人数加算
                        setParent(D, C);
                    }
                }
                else if (a)
                {
                    int C = getParent(A);
                    int D = B;

                    ls[C - 1] -= 1; // 人数加算
                    setParent(D, C);
                }
                else if (b)
                {
                    int C = getParent(B);
                    int D = A;

                    ls[C - 1] -= 1; // 人数加算
                    setParent(D, C);
                }
                else
                {
                    ls[A - 1] = -1; // 人数加算
                    setParent(B, A);
                }
            }

            int max = 1;
            for (int i = 0; i < N; i++)
            {
                if (ls[i] < 0)
                {
                    max = Math.Max(max, -ls[i] + 1);
                }
            }

            Console.WriteLine(max);
        }

        static int getParent(int A)
        {
            if (ls[A - 1] > 0)
            {
                ls[A - 1] = getParent(ls[A - 1]);
                return ls[A - 1];
            }
            return A;
        }

        static void setParent(int A, int B)
        {
            ls[A - 1] = B;
        }

        static bool hasFriend(int A)
        {
            return (ls[A - 1] != 0);
        }
    }
}


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

int A[1001][1001];

int main(){
    string s1,s2;
    cin>>s1;
    cin>>s2;

    for(int i=0;i<=s1.size();++i){
        for(int j=0;j<=s2.size();++j){
            if(i==0){
                A[0][j]=j;
                continue;
            }
            if(j==0){
                A[i][0]=i;
                continue;
            }
            else{
                if(s1[i-1]==s2[j-1]){
                    A[i][j]=A[i-1][j-1];
                }
                else{
                    A[i][j]=min(A[i][j-1],A[i-1][j])+1;
                    A[i][j]=min(A[i][j],A[i-1][j-1]+1);
                }
            }
            //cout<<A[i][j]<<" ";
        }
        //cout<<endl;
    }


    cout<<A[s1.size()][s2.size()]<<endl;
}


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

typedef long long ll_t;

#define PERR(fmt, ...) \
    do { \
        fprintf(stderr, fmt, ##__VA_ARGS__); \
    } while (0) 

int N;
char s[102];
char t[102];

int main() {
    scanf("%d", &N);
    scanf("%s%s", s, t);
    int i;
    for (i = 0; i < N; i++) {
        int flag = 1;
        for (int j = 0; j < N - i; j++)
            if (s[i + j] != t[j])
                flag = 0;
        if (flag) break;
    }
    printf("%d\n", N + i);
    return 0;
}

Measured memory_bytes: 384
def divisor(n):
    i = 1
    res = []
    for i in range(1, int(n**.5) + 1):
        if n%i == 0:
            res.append(i)
            if n//i not in res:
                res.append(n//i)
    res.sort(reverse=True)
    return res

def main():
    n, m = map(int, input().split())
    md = divisor(m)
    ans = 0
    for i in md:
        if i*n <= m:
            print(i)
            exit()

if __name__ == '__main__':
    main()

Measured memory_bytes: 9312
#include <iostream>

 using namespace std ;

 int main()

 {

   int A, B, c, d, e;

   cin>>A;

   cin>>B;

   c =(A + B);

   d =(A - B);

   e =(A * B);

   if (c >= e&&c >= d)

   {

   cout<<c<<endl;

   }

else   if (e >= d&&e >= c)

   {

     cout<<e<<endl;

   }

  else  if (d >= e&&d >= c) 

   {

     cout<<d<<endl;

   }

   }

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <cstdlib>  // abs() for integer
#include <cmath>
#include <bitset>
#include <iomanip>

using namespace std;


int main(void) {
    int N;
    cin >>N;
    vector<double> A(N);
    
    for (int i=0;i<N;i++){
        cin >> A[i];
    }
    
    sort(A.begin(),A.end());
    for (int i=0;i<N;i++){
        //cout<< A[i]<<endl
        ;}
    
    for (int j=0;j<N-1;j++){
        A[j+1]=(A[j]+A[j+1])/2.00000;
        //cout << A[j+1]<<endl;
    }
    
    cout <<A[N-1];
}

    



Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws IOException
	{
		// your code goes here
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		if(x == 0) System.out.println(1);
		else System.out.println(0);
	}
}


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

long long n, ans = 0;

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    ans += a - 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}



int main() {
  ll n,x,y;
  cin >> n >> x >> y;
  x--;y--;
  vl ans(n-1);
  rep(i,n-1){
    rep2(j,i+1,n){
      ll xx=x-i;if(xx<0)xx*=-1;
      ll yy=y-j;if(yy<0)yy*=-1;
      ll dis=min(j-i,yy+xx+1);
      ans[dis-1]++;
      //cout << dis << endl;
    }
  }
  rep(i,n-1){
    cout << ans[i] << endl;
  }
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

int main(){
  ll n, k; cin >> n >> k;
  cout << n - k + 1 << endl;
}


Measured memory_bytes: 256
class Prim():
    def __init__(self,N):
        import collections
        self.N = N
        self.edge = collections.defaultdict(list)
    def add(self,a,b,cost):
        self.edge[a].append((b,cost))
        self.edge[b].append((a,cost))
    def cut_edge(self,start=0):
        import heapq,collections
        #new_edge = collections.defaultdict(list)
        edge_sum = 0
        node_flag = [False for _ in range(self.N)]
        node_flag[start] = True
        q = []
        for to,cost in self.edge[start]:
            heapq.heappush(q,(cost,start,to))
        while q :
            c,s,t = heapq.heappop(q)
            if node_flag[t] is False:
                #new_edge[s].append((t,c))
                edge_sum += c
                node_flag[t] = True
                for to,cost in self.edge[t]:
                    if not node_flag[to]:
                        heapq.heappush(q,(cost,t,to))
        return edge_sum

N = int(input())
graph = Prim(N)
xy = [list(map(int,input().split())) for _ in range(N)]
nx = [(i,xy[i][0]) for i in range(N)]
ny = [(i,xy[i][1]) for i in range(N)]
nx.sort(key=lambda x:x[1])
ny.sort(key=lambda x:x[1])

for i in range(N-1):
    prev_n,prev_x = nx[i]
    next_n,next_x = nx[i+1]
    graph.add(prev_n,next_n,next_x-prev_x)
    prev_n,prev_y = ny[i]
    next_n,next_y = ny[i+1]
    graph.add(prev_n,next_n,next_y-prev_y)
print(graph.cut_edge())

Measured memory_bytes: 100808
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  int ans = m;
  
  int a, b;
  for(int i = 0 ; i < n ; i++){
    cin >> a >> b;
    m += a;
    m -= b;
    if(m < 0) ans = (1<<29);
    ans = max(ans, m);
  }
  if(ans == (1<<29))cout << 0 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
const int MAXN=310;
double dp[MAXN][MAXN][MAXN];
int cnt[3],n,a;

int main(){
	cin>>n;
	for(int i=0;i<n;++i) cin>>a,++cnt[a-1];
	for(int k=0;k<=cnt[2];++k){
		for(int j=0;j<=cnt[2]+cnt[1];++j){
			for(int i=0;i<=cnt[2]+cnt[1]+cnt[0];++i){
				if(!(i+j+k)) continue;
				if(i+j+k>n) continue;
				int tot=i+j+k;
				if(k) dp[i][j][k]+=1.0*dp[i][j+1][k-1]*k/tot;
				if(j) dp[i][j][k]+=1.0*dp[i+1][j-1][k]*j/tot;
				if(i) dp[i][j][k]+=1.0*dp[i-1][j][k]*i/tot;
				dp[i][j][k]+=1.0*n/tot;
			}
		}
	}
	cout<<fixed<<setprecision(10)<<dp[cnt[0]][cnt[1]][cnt[2]]<<endl;
	return 0;
} 

Measured memory_bytes: 225536
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn = 50+5;
const int Inf = 0x3f3f3f3f;
typedef long long LL;

int main(){
    #ifdef INPUT
        freopen("input","r",stdin);
//        freopen("output","w",stdout);
    #endif // INPUT
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a;
    string str;
    while(cin>>a>>str)
        if(a<3200)
            cout << "red\n";
        else
            cout << str<<"\n";

    return 0;
}


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

using namespace std;

#define endl '\n'

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  int ans = 0;
  
  for(int i=1;i<=n;i++){
    int x;
    cin >> x;
    if(x%2 == 1 && i%2 == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=2e5+10;

int N;
int A[MAX];
void input(){
  cin>>N;
  rep(i,N)cin>>A[i];
}

int lx[MAX], rx[MAX];
void solve(){
  lx[0]=0;
  rep1(i,N-1)lx[i]=max(lx[i-1], A[i-1]);
  rx[N-1]=0;
  for(int i=N-2; i>=0; i--){
    rx[i]=max(rx[i+1], A[i+1]);
  }
  rep(i,N)cout<<max(lx[i], rx[i])<<endl;
}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  int cnt[110000];
  int m=0;
  rep(i,0,n){
   int d;
    cin>>d;
    if(i==0&&d!=0||i!=0&&d==0){
      cout<<0<<endl;
      return 0;
    }
    cnt[d]++;
    m=max(m,d);
  }
  ll ans=1;
  rep(i,1,m+1){
    rep(j,0,cnt[i]){
     ans*=cnt[i-1]%998244353;
      ans%=998244353;
    }
   // cout<<ans<<endl;
   // cout<<ans<<endl;
  }
  cout<<ans%998244353<<endl;
  
}

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

int main()
{
    int N, A, B;
    cin >> N >> A >> B;

    int N_number;
    int sum = 0;
    int ans = 0;

    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j < 1000000; j = j * 10)
        {
            N_number = i / (1 * j);
            if (N_number == 0)
            {
                break;
            }
            else
            {
                sum = sum + (N_number % 10);
            }
        }

        if (A <= sum && sum <= B)
        {
            ans = ans + i;
        }
        sum = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for(int k=0; k<10000; k++){
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a == 0 && b == 0){
            break;
        }
        for(int i=0; i<a; i++){
            for(int j=0; j<b; j++){
                if(j == 0 || i == 0 || j == (b-1) || i == (a-1)){
                System.out.printf("#");
                }else{
                    System.out.printf(".");
                }
            }
            System.out.println();
        }
        System.out.println();
    }
}
}


Measured memory_bytes: 56276
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int x, a, b;
  cin >> x >> a >> b;
  int d = b - a;
  cout << (d > x ? "dangerous" : d > 0 ? "safe" : "delicious") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    priority_queue<ll> q;
    vector<ll> f(n);

    vector<ll> fa(n);
    rep(i,n){cin>>a[i];}
    rep(i,n){cin>>f[i];}

    sort(a.rbegin(),a.rend());
    sort(f.begin(),f.end());
    rep(i,n){fa[i]=a[i]*f[i];}

    ll up = 1000000000001;
    ll down = 0;
    int nibu = 0;
    auto check =
            [&](ll med){
                ll kk = k;
                bool flag=true;
                for(int j=0;j<n;j++){
                    ll kai = f[j]*a[j];
                    if(med<kai){
                        ll hiku = a[j]-(med/f[j]);
                        //ll hiku = (a[j]*f[j]-med-1)/f[j]+1;
                        kk-=hiku;
                        if(kk<0){
                            flag = false;
                            break;
                        }
                    }
                }
                return flag;

    };





    while(nibu<100){
        // cout<<up<<" "<<down<<endl;
        nibu++;
        ll med = (up+down)/2;
        if(check(med)){
            up = med;
        }else{

            down = med;
        }
    }
    cout<<up<<endl;








    return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;

int main(){
	int n;
	cin>>n;
	int g=0;
	
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2==0)g++;
	}
	
	int ma=1;
	for(int i=0;i<g;i++)ma*=2;
	
	int ans=1;
	for(int i=0;i<n;i++)ans*=3;
	
	cout<<ans-ma<<endl;
	
	return 0;
}

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

int main () {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;

    while (k > 0) {
        if (a > 0) {
            ans++;
            a--;
            k--;
        } else if (b > 0) {
            b--;
            k--;
        } else if (c > 0) {
            ans--;
            c--;
            k--;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3636
def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

N = int(input())
A = list(map(int, input().split()))

A.sort()
mod = int(1e9+7)

if N % 2 == 1:
  for i in range(N):
    if not ((i+1) // 2) *2 == A[i]:
      print(0)
      exit()
  else:
    ans = power_func(2, (N-1)//2, mod)
    print(ans)
else:
  for i in range(N):
    if not (i // 2) *2 + 1 == A[i]:
      print(0)
      exit()
  else:
    ans = power_func(2, N//2, mod)
    print(ans)

Measured memory_bytes: 14008
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define fi first
//#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int a, b, c;
  cin >> a >> b >> c;
  bool r = (a == b || b == c || c == a) && (a != b || b != c || c != a);
  cout << (r ? "Yes" : "No");
}
#endif


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int N=601;
char f[N][N], a[N][N], b[N][N];

int main() {
	int i, j, h, w;
	scanf("%d%d", &h, &w);
	for(i=0; i<h; i++) scanf("%s", f[i]);
	for(i=0; i<h; i++) for(j=0; j<w; j++) {
		a[i][j]=(j==0 || (i%2==0 && j<w-1) || f[i][j]=='#' ? '#' : '.');
		b[i][j]=(j==w-1 || (i%2==1 && j>0) || f[i][j]=='#' ? '#' : '.');
	}
	for(i=0; i<h; i++) printf("%s\n", a[i]);
	printf("\n");
	for(i=0; i<h; i++) printf("%s\n", b[i]);
   	return 0;
}

Measured memory_bytes: 1664
a=int(input())
b=list(map(int,input().split()))
c=[0 for i in range(a)]
e=[]
i=a-1
while i>=0:
  d=(b[i]+sum(c[i::i+1]))%2
  if d==1:
    c[i]=1
    e.append(i+1)
  i-=1
print(len(e))
for i in range(len(e)):
  print(str(e[i]),end="")
  if i!=len(e)-1:
    print(" ",end="")


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

using namespace std;

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

template< int mod > struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod;       return *this; }
  ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; }
  ModInt &operator*=(const ModInt &p) { x = int(1LL * x * p.x % mod);          return *this; }
  ModInt &operator/=(const ModInt &p) { *this *= p.inverse();                  return *this; }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    return ModInt(u);
  }
  friend ostream &operator<<(ostream &os, const ModInt< mod > &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt< mod > &a) {
    long long x; is >> x;
    a = ModInt< mod >(x);
    return (is);
  }
};
using modint = ModInt< (int)1e9 + 7 >;

int N;
modint dp[111][4][4][4];

enum {A, T, G, C};

signed main() {

  dp[0][T][T][T] = 1;

  cin >> N;

  REP(n, N) {
    REP(i, 4) REP(j, 4) REP(k, 4) {
           if (i == A && j == G) for (auto& l: {A, T, G}) dp[n + 1][j][k][l] += dp[n][i][j][k];
      else if (i == A && k == G) for (auto& l: {A, T, G}) dp[n + 1][j][k][l] += dp[n][i][j][k];
      else if (j == A && k == G) for (auto& l: {A, T, G}) dp[n + 1][j][k][l] += dp[n][i][j][k];
      else if (j == A && k == C) for (auto& l: {A, T, C}) dp[n + 1][j][k][l] += dp[n][i][j][k];
      else if (j == G && k == A) for (auto& l: {A, T, G}) dp[n + 1][j][k][l] += dp[n][i][j][k];
      else for (auto& l: {A, T, G, C}) dp[n + 1][j][k][l] += dp[n][i][j][k];
    }
  }

  modint res = 0;
  REP(i, 4) REP(j, 4) REP(k, 4) res += dp[N][i][j][k];

  cout << res << endl;

}


Measured memory_bytes: 256
from fractions import gcd
n,x = map(int,input().split())
L = [abs(n-x) for n in map(int,input().split())]
ans = L[0]
for i in L[1:]:
    ans = gcd(ans,i)
    if ans == 1:
        print(1)
        break
else:
    print(ans)

Measured memory_bytes: 16276
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
  int n;
  cin >> n;
  set<string> st;
  string s;
  string pre = "";
  rep(i, n){
    cin >> s;
    st.insert(s);
    if(i) {
      if(pre[pre.size() - 1] != s[0]){
        cout << "No" << endl;
        return 0;
      }
    }
    pre = s;
  }
  if(st.size() == n)
    cout << "Yes" << endl;
  else cout << "No" << endl;
}



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

using namespace std;

const int MaxN = 2e5 + 25;
const int MOD = 1e9 + 7;

int dp[MaxN];

int g(int n, int k)
{
    if(n % k == 0)
        return n / k;

    if(n < k)
        return 0;

    int d = n / k + 1;


    int p = (n - (n / k) * k) / d - 1;

    if(p < 0)
        p = 0;

    p *= d;


    n -= p;

    while(n / k + 1 == d && n % k)
        n -= d;

    return g(n, k);
}

int main()
{
//    freopen("input.txt", "r", stdin);

    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    int y = 0;
    for(int i = 1; i <= n; ++i)
    {
        int a, b;
        cin >> a >> b;
        y ^= g(a, b);
    }

    if(y)
        cout << "Takahashi\n";
    else
        cout << "Aoki\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int H = scan.nextInt();
		int W = scan.nextInt();
		char [][]a = new char[H][W];
		String []k = new String[H];
		for(int i = 0; i < H; i++) {
			String s = scan.next();
			k[i] = s;
			for(int j = 0; j < W; j++) {
				a[i][j] = s.charAt(j);
			}
		}
		scan.close();

		List<String> list = new ArrayList<String>();
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				char c = k[i].charAt(j);
				if(c == '#') {
					list.add(k[i]);
					break;
				}
			}
		}
		int h = list.size();
		char [][]b = new char[h][W];
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < W; j++) {
				b[i][j] = list.get(i).charAt(j);
			}
		}
		List<String> list2 = new ArrayList<String>();
		for(int j = 0; j < W; j++) {
			for(int i = 0; i < h; i++) {
				if(b[i][j] == '#') {
					String d = "";
					for(int m = 0; m < h; m++) {
						d += b[m][j];
					}
					list2.add(d);
					break;
				}
			}
		}
		char [][]e = new char[h][list2.size()];
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < list2.size(); j++) {
				e[i][j] = list2.get(j).charAt(i);
			}
		}
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < list2.size(); j++) {
				System.out.print(e[i][j]);
			}
			System.out.println();
		}

	}
}

Measured memory_bytes: 28372
import sys

readline = sys.stdin.readline
N, H = map(int, readline().split())
B = [0] * N
ma = 0
for i in range(N):
     a, b = map(int, readline().split())
     if ma < a:
        ma = a
     B[i] = b
B.sort(reverse=True)
ans = 0
for b in  B:
    if ma < b:
        ans += 1
        H -= b
    if H <= 0:
        print(ans)
        exit()
ans -= -H//ma
print(ans)


Measured memory_bytes: 7472
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto ab = readints;
    int a = ab[0], b = ab[1];

    auto ans = [a, b, a-1, b-1].sort!("a > b").take(2).sum;
    writeln(ans);
}



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

template<class t> void vin(vector<t>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int number(string& s, int& i) {
    int n = 0;
    while (s[i] != ']') {
        n *= 10;
        n += s[i] - '0';
        i++;
    }
    return n;
}

int solve(string& s, int& i) {
    if (s[i] != '[') return -1;
    if (s[++i] != '[') return number(s, i)/2 + 1;
    vector<int> a;
    while (s[i] == '[') {
        a.push_back(solve(s, i));
        i++;
    }
    sort(a.begin(), a.end());
    int ans = 0;
    rep(j, a.size()/2+1) ans += a[j];
    return ans;
}

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        string s;
        cin >> s;
        int idx=0;
        cout << solve(s, idx) << endl;
    }
    return 0;
}



Measured memory_bytes: 3176