akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>

int dist[200010];

using namespace std;

int main() {
    int n, m;   cin >> n >> m;
    vector<vector<int> > G(n);
    for (int i = 0; i < m; i++) {
        int a, b;   cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    for (int i = 0; i < n; i++)
        dist[i] = -1;

    queue<int> que;
    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int s = que.front();

        for (int i = 0; i < G[s].size(); i++) {
            int g = G[s][i];

            if (dist[g] >= 0 && dist[g] < dist[s] + 1)
                continue;

            dist[g] = dist[s] + 1;

            que.push(g);
        }

        que.pop();
    }

    if (dist[n-1] == 2)
        cout << "POSSIBLE" << endl;
    else 
        cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 13168
#include<stdio.h>

int main(void)
{
	int count = 0;	/* ?????????????????????????????? */
	char word[40][10];	/* ????????°, ??????????????? */
	int n;	/* ??\?????????????????° */
	int i, j, k;
	int start = 0;
	int case_count = 0;

	while (1) {
		/* ??\??? */
		scanf("%d", &n);
		if (n == 0)
			break;
		else {
			for (i = 0; i < n; i++)
				scanf("%s", word[i]);
		}
		
		/* ?????? */
		for (i = 0; i < n; i++) {	/* 57577?????????????????£?????´??????????§????????????????????????? */
			j = i;
			/* 1?????????????????????????¨???¬??????????????????????????????????????°(5 or 7)??¨??????????°????????????°???????????????????????§???????????°start++?????????continue; */
			while (1) {
				/* ????????°???????????? */
				for (k = 0; word[j][k] != '\0'; k++) {
					count++;
				}
				/*
				printf("%d\n", count);
				getchar();
				*/
				/* 5?????? */
				if (case_count == 0) {
					if (count == 5) {
						case_count++;
						count = 0;
						//printf("equal\n");
					}
					else if (count > 5) {
						count = 0;
						//printf("cont\n");
						break;
					}
					else {
						//printf("do\n");
					}
				}

				/* 7?????? */
				else if (case_count == 1) {
					if (count == 7) {
						case_count++;
						count = 0;
						//printf("equal\n");
					}
					else if (count > 7) {
						count = 0;
						case_count = 0;
						//printf("cont\n");
						break;
					}
					else {
						//printf("do\n");
					}
				}

				/* 5?????? */
				else if (case_count == 2) {
					if (count == 5) {
						case_count++;
						count = 0;
						//printf("equal\n");
					}
					else if (count > 5) {
						count = 0;
						case_count = 0;
						//printf("cont\n");
						break;
					}
					else {
						//printf("do\n");
					}
				}

				/* 7?????? */
				else if (case_count == 3) {
					if (count == 7) {
						case_count++;
						count = 0;
						//printf("equal\n");
					}
					else if (count > 7) {
						count = 0;
						case_count = 0;
						//printf("cont\n");
						break;
					}
					else {
						//printf("do\n");
					}
				}

				/* 7?????? */
				else if (case_count == 4) {
					if (count == 7) {
						case_count++;
						count = 0;
						break;
						//printf("equal\n");
					}
					else if (count > 7) {
						count = 0;
						case_count = 0;
						//printf("cont\n");
						break;
					}
					else {
						//printf("do\n");
					}
				}

				j++;	/* ??????????????????????????? */
			}

			if (case_count == 5)
				break;
		}

		/* ?????? */
		printf("%d\n", i + 1);

		/* ????????? */
		start = 0;
		case_count = 0;
	}

	return 0;
}

Measured memory_bytes: 604
#include<cstdio>

int main(){
	int n = 0, sum = 0, v = 0;
	int a, b;
	while(1 + scanf("%d,%d", &a, &b)){
		sum += a * b;
		v += b;
		if(a == 0){
			break;
		}
		n++;
	}
	int t = v % n;
	if(2 * t / n){
		printf("%d\n%d\n", sum, v / n + 1 );
	}else{
		printf("%d\n%d\n", sum, v / n);
	}
}

Measured memory_bytes: 1020
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll,ll,ll> tl3;
// https://atcoder.jp/contests/abc174/tasks/abc174_c
ll gcd(ll a, ll b){
    if(a < b) swap(a,b);
    if(b == 0)
        return a;
    else return gcd(b, a%b);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll k;
    cin >> k;
    if(k%7 == 0){
        k /= 7;
    }
    if(gcd(10,k) != 1){
        cout << -1;
    }
    else{
        ll temp = 1 % k;
        ll ans = 1;
        while(temp != 0){
            temp = (10 * temp + 1) % k;
            ans++;
        }
        cout << ans;
    }

    return 0; 
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i =(b)-1;i>=(a);--i)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
typedef vector<int> vi;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 10;
int n,m,q;
int v[11];
int a[51],b[51],c[51],d[51];
int mx = 0;
void count(){
	int r = 0;
	rep(i,0,q){
		r += (v[b[i]] - v[a[i]] == c[i] ? d[i] : 0);
	}
	mx = max(r,mx);
}
void dfs(int x,int t){
	if(t > n)count();
	else{
		rep(i,x,m+1){
			v[t] = i;
			dfs(i,t+1);
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> q;
	rep(i,0,q)cin >> a[i] >> b[i] >> c[i] >> d[i];
	dfs(1,1);
	cout << mx;
	return 0;
}


Measured memory_bytes: 3600
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair

using namespace std;

int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
 //    #endif
	
    int temp;
    int t=3;
    int f=0;
    int s=0;
    while(t--){
    	cin>>temp;
    	if(temp==5){
    		f++;
    	}else if(temp==7){
    		s++;
    	}
    }
    if(f==2 && s==1){
    	cout<<"YES"<<endl;
    }else{
    	cout<<"NO"<<endl;
    }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  string S;
  cin >> n >> S;

  int ans = 0;
  char pre_char = S[0];
  for (int i = 0; i < S.size(); ++i) {
    if (S[i] != pre_char) {
      ++ans;
      pre_char = S[i];
    }
  }

  cout << ans+1 << endl;

  return 0;
}

Measured memory_bytes: 512
import sys

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


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    cnt_4 = 0
    cnt_2 = 0
    for a in A:
        if a % 4 == 0:
            cnt_4 += 1
        elif a % 2 == 0:
            cnt_2 += 1

    print("Yes" if n - max(0, cnt_2 - 1) <= cnt_4 * 2 + 1 else "No")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 14340
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from bisect import bisect_right
n,m=map(int,input().split())

def make_divisors(n):
    divisors=[]
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

D=make_divisors(m)
print(D[bisect_right(D,m/n)-1])

Measured memory_bytes: 3064
def main():
    
    n = int(input())
    a = input().split()
    
    A = []
    for i in range(n):
        A.append(int(a[i]))
        
    display(A)
    insertSort(A)
        
def insertSort(A):
    
    for i in range(1,len(A)):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        display(A)
            
def display(A):
    for i in range(len(A)):
        if i != len(A) - 1:
            endStr = ' '
        else:
            endStr = '\n'
        print(str(A[i]), end=endStr)
                
if __name__ == "__main__":
    main()



Measured memory_bytes: 5988
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n;
vector<int> con[111];
int lv[111],mx[111];
void dfs(int x,int pre=-1)
{
	int d=0;
	for(int i=0;i<con[x].size();i++)
	{
		int u=con[x][i];
		if(u==pre)continue;
		lv[u]=lv[x]+1;
		dfs(u,x);
		d++;
	}
	mx[lv[x]]=max(mx[lv[x]],d);
}
pair<int,ll> solve(int rx,int ry)
{
	memset(mx,0,sizeof(mx));
	lv[rx]=1;
	dfs(rx,ry);
	lv[ry]=1;
	dfs(ry,rx);
	int ret=0;
	for(int i=1;i<=n;i++)ret=max(ret,lv[i]);
	ll cnt=1;
	for(int i=1;i<ret;i++)cnt=cnt*mx[i];
	if(rx!=ry)cnt=cnt*2;
	return MP(ret,cnt);
}
int main()
{
	geti(n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		getii(x,y);
		con[x].PB(y);
		con[y].PB(x);
	}
	pair<int,ll> ans=MP(n+1,1);
	for(int i=1;i<=n;i++)
	{
		ans=min(ans,solve(i,i));
		for(int j=0;j<con[i].size();j++)
		{
			ans=min(ans,solve(i,con[i][j]));
		}
	}
	cout<<ans.FF<<" "<<ans.SS<<endl;
	return 0;
}


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

using namespace std;

int main(void)
{
    int64_t h, n, x;
    cin >> h >> n;
    vector<int64_t> a;
    for (size_t i = 0; i < n; i++)
    {
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end(), greater<int64_t>());
    int64_t damage = 0;
    for (size_t i = 0; i < n; i++)
    {
        damage += a.at(i);
    }
    if (damage >= h)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1400
char s[4005],t[4005];u[4005],m,i,j,c;main(n){for(;~scanf("%s%s",s,t+1);i=m=!printf("%d\n",m)){for(n=strlen(s);!i|t[i];i++)for(j=n;j--;m<c?m=c:0)u[j+1]=c=s[j]-t[i]?0:u[j]+1;}}

Measured memory_bytes: 428
s = list(map(str, input()))
n = len(s) - 1
for i in range(2**n):
    ans = s[0]
    for j in range(n):
        if ( i >> j ) & 1 :
            ans += "+" + s[j+1]
        else:
             ans += "-" + s[j+1]   
        if j == n-1:
            if eval(ans) == 7:
                print(ans+"=7")
                exit()

Measured memory_bytes: 3060
#include <stdio.h>

int main(){
 int S;
 int h,m,s;
 scanf("%d",&S);

 s=S%60;
 S/=60;
 m=S%60;
 S/=60;
 h=S%60;

 printf("%d:%d:%d\n",h,m,s);

 return 0;
}


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

const int INF = 1e9 + 7;

int main()
{
	ios_base::sync_with_stdio(false);

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

	return 0;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  int a[N], b[N], c[N];
  rep(i, N) cin >> a[i] >> b[i] >> c[i];
  int dp[401][401];
  fill(dp[0], dp[401], inf);
  dp[0][0] = 0;
  rep(i, N) {
    for(int j = 400; j >= a[i]; j--) {
      for(int k = 400; k >= b[i]; k--) {
	dp[j][k] = min(dp[j][k], dp[j-a[i]][k-b[i]] + c[i]);
      }
    }
  }

  int ans = inf;
  reps(i, 1, 401) reps(j, 1, 401) {
    if(i*Mb == j*Ma) ans = min(ans, dp[i][j]);
  }

  cout << (ans == inf ? -1 : ans) << endl;

  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int n,t=0;
void dfs(int k,int end,string s)
{
    if(k>end)
        if(++t==n)
        {
            cout<<s;
            exit(0);
        }
        else return ;
    for(char ch=s[s.size()-1]-1;ch<=s[s.size()-1]+1;ch++)
        if(ch>='0'&&ch<='9')
            dfs(k+1,end,s+ch);
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;;i++)
		for(char c='1';c<='9';c++)
		{
			string s="";
			dfs(2,i,s+c);
		}
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
 
int main()
{
    int n=0;
    cin>>n;
    int*NumArray=new int [n];
    for (int i=0;i<n;i++)
    {
        cin>>NumArray[n-1-i];
    }
    for (int i=0;i<n-1;i++)
    {
        cout<<NumArray[i]<<' ';
    }
    //????????????????????\??????????????´??????????????????????????????\????????????????????????
    cout<<NumArray[n-1]<<endl;
    delete[] NumArray;
    return 0;
}

Measured memory_bytes: 3056
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        for (int i = 1; i <= 9; i++)
        {
            if (n % i == 0)
            {
                int j = n / i;
                if (1 <= j && j <= 9)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
        }

        Console.WriteLine("No");
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

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

int main() {
    int n, m;
    cin >> n;
    vector<int> t(n);
    rep(i,n) cin >> t[i];
    cin >> m;
    vector<P> drink(m);
    rep(i,m) cin >> drink[i].first >> drink[i].second;
    rep(i,m) {
        int ans = 0;
        rep(j,n){
            if((drink[i].first)==(j+1)) {ans+=drink[i].second; continue;}
            ans+=t[j];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define inf         1e9+8
#define mp          make_pair
#define rep(i,n)    for(int i=0;i<n;i++)
#define repo(i,m,n) for(int i=m;i<=n;i++)
#define ll          long long
#define pii         pair<int,int >
#define sc(n)       scanf("%d",&n)
#define sc2(m,n)    scanf("%d%d",&m,&n);
#define MOD         4294967296
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define mem(x,i)    memset(x,i,sizeof x)
#define PI          acos(-1.0)
#define ff          first
#define ss          second
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/
using namespace __gnu_pbds;
using namespace std;
template <typename T>  using orderedSet =
    tree<T, null_type, less<T>,
    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key


int main()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    if(str.size()%2)
    {
        puts("No");
        return 0;
    }
    for(int i=0,j=n/2;i<n/2;i++,j++)
    {
        if(str[i]!=str[j])
        {
            cout<<"No\n";
            return 0;
        }
    }
    puts("Yes");
}



Measured memory_bytes: 256
x,n=gets.split.map(&:to_i)
if n==0
  puts x
  exit
end
p=gets.split.map(&:to_i)
m=100
0.upto(101) do |i|
  if (i-x).abs<m&&!p.include?(i)
    m=(i-x).abs
    n=i
  end
end
puts n


Measured memory_bytes: 14356
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
const int MAX_bit = 45;
ll A[MAX_N],dp0[MAX_bit],dp1[MAX_bit];
int cnt0[MAX_bit],cnt1[MAX_bit];

int main()
{
	int N;
	ll K;
	cin >> N >> K;
	rep(i,N)
	{
		cin >> A[i];
		rep(j,MAX_bit)
		{
			if (A[i] & (1ull << j)) cnt1[j]++;
			else cnt0[j]++;
		}
	}

	for (int i = MAX_bit-2; i >= 0; --i)
	{
		if (K & (1ull << i)) dp0[i] = dp0[i+1] + (1ull << i) * cnt0[i];
		else dp0[i] = dp0[i+1] + (1ull << i) * cnt1[i];
	}
	bool b = false;
	for (int i = MAX_bit-2; i >= 0; --i)
	{
		if ((K & (1ull << i)) && !b)
		{
			b = true;
			dp1[i] = dp0[i+1] + (1ull << i) * cnt1[i];
		}
		else if ((K & (1ull << i)) && b)
		{
			dp1[i] = max(dp0[i+1] + (1ull << i) * cnt1[i], dp1[i+1] + (1ull << i) * max(cnt0[i],cnt1[i]));
		}
		else if (b)
		{
			dp1[i] = dp1[i+1] + (1ull << i) * max(cnt0[i],cnt1[i]);
		}
	}
	/*
	rep(i,MAX_bit)
	{
		if (K & (1 << i)) cout << "1 ";
		else cout << "0 ";
	}
	cout << endl << b << endl;
	cout << dp0[0] << " " << dp1[0] << endl;
	*/
	cout << max(dp0[0],dp1[0]) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
map<int,int> mp;
map<int,int>::iterator it;
int main(){
	int n,a;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&a);
		mp[a]++;
	}
	int ans=0;
	for(it=mp.begin();it!=mp.end();++it){
		if(it->second%2==1){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int H=in(),W=in(),K=in();
	vector<vector<int>> L(H,vector<int>(W,0)),M(H);
	REP(i,H){
		string S=in<string>();
		REP(j,W){
			if(S[j]=='#'){
				M[i].push_back(j);
			}
		}
	}
	int SN=1;
	REP(i,H){
		if(!M[i].empty()){
			int old=0;
			for(int j=0,ej=M[i].size()-1;j<ej;j++){
				for(int k=old;k<=M[i][j];k++){
					L[i][k]=SN;
				}
				old = M[i][j]+1;
				SN++;
			}
			for(int k=old;k<W;k++){
				L[i][k]=SN;
			}
			SN++;
		}
	}
	REP(j,W){
		int old=0,cur=0,last=0;
		while(cur<=H-1){
			if(L[cur][j]>0){
				for(int i=old;i<=cur;i++){
					L[i][j] = L[cur][j];
				}
				last = L[cur][j];
				old = cur+1;
				cur = old;
			}
			else cur++;
		}
		for(int i=old;i<H;i++){
			L[i][j] = last;
		}
	}

	REP(i,H){
		REP(j,W-1){
			cout << L[i][j] << ' ';
		}
		out(L[i][W-1]);
	}
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string p1[20],p2[20];
bool used[20];
int n,m,indent1[20],indent2[20],a1[20][3],a2[20][3];
int ans[20];
void init_indent(){
  int r=0,c=0,s=0;
  r(i,n){
    int ind=0;
    r(j,p1[i].size()){
      if(p1[i][j]=='.')ind++;
      else break;
    }
    r(j,p1[i].size()){
      if(p1[i][j]=='(')r++;
      if(p1[i][j]==')')r--;
      if(p1[i][j]=='{')c++;
      if(p1[i][j]=='}')c--;
      if(p1[i][j]=='[')s++;
      if(p1[i][j]==']')s--;
    }
    indent1[i]=ind;
    a1[i][0]=r;
    a1[i][1]=c;
    a1[i][2]=s;
  }
  r(i,m){
    r(j,p2[i].size()){
      if(p2[i][j]=='(')r++;
      if(p2[i][j]==')')r--;
      if(p2[i][j]=='{')c++;
      if(p2[i][j]=='}')c--;
      if(p2[i][j]=='[')s++;
      if(p2[i][j]==']')s--;
    }
    a2[i][0]=r;
    a2[i][1]=c;
    a2[i][2]=s;
  }
}
int main(){
  while(cin>>n>>m,n){
    r(i,n)cin>>p1[i];
    r(i,m)cin>>p2[i];
    memset(ans,-1,sizeof(ans));
    memset(used,0,sizeof(used));
    init_indent();
    r(R,21)r(C,21)r(S,21){
      if(!R||!C||!S)continue;
      int flag=0;
      r(i,n-1)if(a1[i][0]*R+a1[i][1]*C+a1[i][2]*S!=indent1[i+1])flag++;
      if(flag)continue;
      r(i,m-1){
        if(!used[i]){
          used[i]=1;
          ans[i]=R*a2[i][0]+C*a2[i][1]+S*a2[i][2];
        }
        else if(used[i]&&ans[i]!=-1){
          if(R*a2[i][0]+C*a2[i][1]+S*a2[i][2]!=ans[i]){
            ans[i]=-1;
          }
        }
      }
    }
    cout<<0;
    r(i,m-1)cout<<' '<<ans[i];
    cout<<endl;
  }
}

Measured memory_bytes: 3056
N,X=map(int,input().split())
L=[0]*(N+1)
t=1
L[0]=t
for i in range(1,N+1):
    t=2*t+3
    L[i]=t
M=[0]*(N+1)
s=1
for i in range(1,N+1):
    s=2*s+1
    M[i]=s
a=X
ans=0
for i in range(N-1,0,-1):
    t=L[i]
    s=M[i]
    if a==1:
        a-=1
        break
    elif 2<=a<=t+1:
        a-=1
    elif a==t+2:
        a-=t+2
        ans+=s+1
        break
    elif t+3<=a<=2*t+2:
        ans+=s+1
        a=a-(t+2)
    elif a==2*t+3:
        a-=2*t+3
        ans+=2*s+1
        break
#print('g',i,ans,a,X)
if 0<=a<=4:
    ans+=max(a-1,0)
else:
    ans+=3
print(ans)

Measured memory_bytes: 38384
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
int main() {
	int a, b, k; cin >> a >> b >> k;
	int tot = 0;
	for (int i = min(a, b); i >= 1; --i) {
		if (a % i == 0 && b % i == 0) ++tot;
		if (tot == k) return printf("%d\n", i), 0;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), x = in.nextInt();
        int sum = 0, min = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++) {
            int m = in.nextInt();
            sum += m;
            min = Math.min(min, m);
        }
        System.out.println(n + (x - sum) / min);
    }
}

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

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

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

int main(){
    long int H,W;
    cin >> H >> W;
    while(H!=0 && W!=0){
        for(long int i=0; i<H; i++){
            for(long int j=0; j<W; j++){
                cout << '#' ;
            }
            cout << '\n';
        }
        cin >> H >> W;
        cout << '\n';
    }


    
return 0;
}


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

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

	int sum = 0;
	for (int i = 0; i < N; i++) {
		if (i < K) sum += X;
		else sum += Y;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	int n, m; cin >> n >> m;
	bool r[n];
	rep(i, n) r[i] = false;
	r[0] = true;
	int c[n];
	rep(i, n) c[i] = 1;
	
	rep(i, m){
		int x, y; cin >> x >> y; x--; y--;
		c[x]--; c[y]++;
		if(r[x]){
			if(c[x] == 0) r[x] = false;
			r[y] = true;
		}
	}
	
	int ans = 0;
	rep(i, n) if(r[i]) ans++;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int a[201];
int main()
{
     int n,sum=0,maxs=0;
     cin>>n;
     for(int i=0;i<n;i++)
        {
            cin>>a[i];
          sum+=a[i];
         maxs=max(maxs,a[i]);
        }
       sum=sum-maxs;
       if(sum<=maxs)
        printf("No\n");
       else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
# import sys 
# input = sys.stdin.readline
 
 
n = int(input())
 
a= list(map(int,input().split())) 
 
def main(a):
    if 0 in a:
        print(0)
        return
     
    ans = 1
    for i in a:
        ans *= i 
        
        if ans > 1000000000000000000:
            print(-1)
            return
    
    print(ans)
    
main(a)


Measured memory_bytes: 21776
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut y: f64 = 0f64;
    for _ in 0..n {
        let x: f64 = read(&mut stdin_lock, &mut buf, b' ');
        let u: String = read(&mut stdin_lock, &mut buf, b'\n');
        y += x * if u == "JPY" {
            1f64
        } else if u == "BTC" {
            380000f64
        } else {
            unreachable!()
        };
    }
    println!("{}", y);
}


Measured memory_bytes: 4352
#include <iostream>
#include <math.h>

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

Measured memory_bytes: 256
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP
import qualified Data.Set as ST
import qualified Data.Sequence as SQ
import Data.Array
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.IO
import Data.Maybe
import Data.Ratio
import Data.Char
import Data.Bits
import Data.List
import Data.Tuple
import Data.Functor
import Data.IORef
import Data.STRef
import Control.Applicative
import Control.Monad
import Control.Monad.ST

step :: [(Int, Int)] -> Double -> [Int] -> Double
step xys acc as = acc + res
  where
    res = loop as
    loop [_] = 0.0
    loop (a:b:as) = s + loop (b:as)
      where
        (ax,ay) = xys !! (a-1)
        (bx,by) = xys !! (b-1)
        s = sqrt $ fromIntegral ((ax-bx)^2 + (ay-by)^2)

main = do
  n <- readLn :: IO Int
  xys <- replicateM n $ do
    [x,y] <- map read . words <$> getLine :: IO [Int]
    return (x, y)
  
  let 
      ps = permutations [1..n] 
      a = foldl' (step xys) 0.0 ps
      b = (fromIntegral $ length ps)

  print $ a / b

Measured memory_bytes: 12668
#include <stdio.h>
int main(void)
{
   int i,j;
   char c[3][4];

   for(i=0;i<3;i++)
      for(j=0;j<4;j++)
         scanf("%c",&c[i][j]);

   for(i=0;i<3;i++)
      for(j=0;j<4;j++)
         if(i==j) printf("%c",c[i][j]);
   printf("\n");

   return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>


int main() {
	int n; std::cin >> n;
	std::vector<long long int> taco_ball(n); for (auto& t : taco_ball) std::cin >> t;
	long long int sum = std::accumulate(taco_ball.begin(), taco_ball.end(), 0LL);
	long long int result = 0;
	for (const auto t : taco_ball) {
		result += (sum - t) * t;
	}
	std::cout << result / 2 << std::endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L[i];
  sort(L.begin(), L.end());

  int sum = 0;
  for (int i = 0; i < N - 1; i++) {
    sum += L[i];
  }

  if (L[N - 1] < sum) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int N= 105;
int Selection_Sort(int a[],int n)	//选择排序 
{
	int minj,count=0;
	for(int i=0;i<n;i++)
	{
		minj=i ;
	for(int j=i+1;j<n;j++)
	{
		if(a[j]<a[minj])
		{
			minj = j;
		}
	}
	if(i!=minj) 
	{
		swap(a[i],a[minj]);
		count++;
	}
	}
	return count; 
}
int main()
{
	int n,count;
	int a[N];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	count=Selection_Sort(a,n);
	for(int i=0;i<n;i++)
	{
		if(i<n-1)
		cout<<a[i]<<' ';
		else 
		cout<<a[i]<<endl;
	}
	cout<<count<<endl;
}


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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    string s;
    cin >> s;

    for(int i = 0 ; s[i] ; i ++)printf("x");
}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

ll mod=1000000007;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main() {
  string s;cin>>s;
  cout<<s.substr(0,3)<<endl;
}

Measured memory_bytes: 3628
extern crate proconio;
use proconio::fastout;
use proconio::marker::Chars;

#[fastout]
fn main() {
    proconio::input! {
        mut s: Chars,
    }
    {
        let g = &mut s[1];
        *g = match *g {
            'B' => 'R',
            'R' => 'B',
            _ => unreachable!(),
        };
    }
    for c in s {
        print!("{}", c);
    }
    println!("");
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll H, W;
  cin >> H >> W;

  if (H == 1 || W == 1)
    FINALANS(1);

  cout << (H * W + 1) / 2 << endl;
}

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

##
## A - Frog1
## https://atcoder.jp/contests/dp/tasks/dp_a
##

import sys

def solve(N, nums):
    assert N > 0
    if N == 1:
        return 0
    cost_2 = 0
    cost_1 = abs(nums[1] - nums[0])
    for i in range(2, N):
        c1 = cost_1 + abs(nums[i] - nums[i-1])
        c2 = cost_2 + abs(nums[i] - nums[i-2])
        cost_i = min(c1, c2)
        cost_2 = cost_1
        cost_1 = cost_i
    return cost_1

def load(input):
    line = input.readline()
    N = int(line.strip())
    buf = []; add = buf.append
    size = 8192
    s = input.read(size)
    while s:
        add(s)
        s = input.read(size)
    return N, "".join(buf)

def main():
    N, string = load(sys.stdin)
    nums = [ int(x) for x in string.split() ]
    result = solve(N, nums)
    print(result)

main()


Measured memory_bytes: 13856
#include <cstdio>

const int maxn=50;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

char s[maxn+2][maxn+2];
int n,m;

int main()
{
  scanf("%d%d",&n,&m);
  for(int i=1; i<=n; ++i)
    {
      scanf("%s",s[i]+1);
    }
  for(int i=1; i<=n; ++i)
    {
      for(int j=1; j<=n; ++j)
        {
          if(s[i][j]=='#')
            {
              int flag=0;
              for(int k=0; k<4; ++k)
                {
                  int nx=i+dx[k],ny=j+dy[k];
                  if((nx>0)&&(nx<=n)&&(ny>0)&&(ny<=m)&&(s[nx][ny]=='#'))
                    {
                      flag=1;
                      break;
                    }
                }
              if(flag==0)
                {
                  puts("No");
                  return 0;
                }
            }
        }
    }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;
long ggd(ll a, ll b) {
	if(a<b)swap(a,b);
	if (b == 0) {
		return a;			
	}
	return ggd(b, a % b);
}
long lcm(ll number1,ll number2){
	return number1 / ggd(number1,number2)* number2;	
}

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  std::cout << min(min(min(max(0,b-c),max(0,d-a)),b-a),d-c) << std::endl;
}

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

using namespace std;

const int mod = 1e9 + 7;

int add(int a, int b) {
  return a + b - mod * (a + b >= mod);
}

int mul(int a, int b) {
  return int(1ll * a * b % mod);
}

int pwr(int a, int x) {
  if (x == 0) {
    return 1;
  }
  return mul(pwr(mul(a, a), x >> 1), (x & 1 ? a : 1));
}

int dvd(int a, int b) {
  return mul(a, pwr(b, mod - 2));
}

int sub(int a, int b) {
  return a - b + mod * (a < b);
}

void inc(int& a, int b) {
  a = add(a, b);
}

void dec(int& a, int b) {
  a = sub(a, b);
}

class matrix {
  int n, m;
  vector<vector<int>> data;
  matrix base(int n) {
    matrix b(n, n);
    for (int i = 0; i < n; ++i) {
      b[i][i] = 1;
    }
    return b;
  }
public:
  matrix(int _n, int _m) : n(_n), m(_m) {
    data.resize(n, vector<int>(m));
  }
  vector<int>& operator[](int i) {
    return data[i];
  }
  matrix operator*(matrix b) {
    matrix a = (*this), c(a.n, b.m);
    if (a.m != b.n) {
      throw 1;
    }
    for (int i = 0; i < a.n; ++i) {
      for (int j = 0; j < b.m; ++j) {
        for (int k = 0; k < a.m; ++k) {
          inc(c[i][j], mul(a[i][k], b[k][j]));
        }
      }
    }
    return c;
  }
  template<typename T> matrix operator^(T x) {
    if (x == 0) {
      return base(n);
    }
    matrix a = *this;
    return ((a * a) ^ (x >> 1)) * (x & 1 ? a : base(n));
  }
};

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

  int n;
  long long k;
  cin >> n >> k;
  matrix d(n, n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> d[i][j];
    }
  }
  d = d ^ k;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      inc(ans, d[i][j]);
    }
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 3072
from math import gcd

def setwise_coprime_check_fun(A_list, N):
    gcd_all = A_list[0]
    for i in range(N - 1):
        gcd_all = gcd(gcd_all, A_list[i + 1])
        if gcd_all == 1:
            break
    return gcd_all

def preprocess_fun(A_max):
    p_flg = [True] * (A_max + 1)
    D = [0] * (A_max + 1)
    p_flg[0] = False
    p_flg[1] = False
    for i in range(2, A_max + 1, 1):
        if p_flg[i]:
            for j in range(i, A_max + 1, i):
                p_flg[j] = False
                D[j] = i
    return D

def pairwise_coprime_check(A_list, D):
    p_count = [0] * (max(A_list) + 1)
    for A in A_list:
        temp = A
        d = 0
        while temp != 1:
            if p_count[D[temp]] == 1 and d != D[temp]:
                return 0
            p_count[D[temp]] = 1
            d = D[temp]
            temp = temp // D[temp]
    return 1

## 標準入力
N = int(input())
A_list = list(map(int, input().split(" ")))

# 整数の最大値を取得
A_max = max(A_list)

# 本体
if(setwise_coprime_check_fun(A_list, N) != 1):
    print("not coprime")
else:
    D = preprocess_fun(A_max)
    if pairwise_coprime_check(A_list, D) == 1:
        print("pairwise coprime")
    else:
        print("setwise coprime")

Measured memory_bytes: 134496
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class AABCSwap {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        cout << Z << " " <<  X << " " << Y;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    AABCSwap solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <sstream>
#include <bitset>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <time.h>
#include <limits>
#include <math.h>
#include <climits>
#include <numeric>
#include <utility>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <functional>
#include<unordered_map>

using namespace std;
const double pi=acos(-1.0);
//memset ( a , 0 , n * sizeof(ll) ) ;

#define 	boost  		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // don't use if small inpts
#define 	endl 		'\n'
#define 	sl(n) 		scanf("%lld",&n)
#define		mp 			make_pair
#define 	pb 			push_back
#define 	ppb 		pop_back
#define 	fi 			first
#define 	se 			seconchutd
#define 	ll 			long long
#define 	ull 		unsigned long long
#define 	pii 		pair<int, int>
#define 	f(i,a,b) 	for(ll i = (ll)(a); i < (ll)(b); i++)
#define 	rf(i,a,b) 	for(ll i = (ll)(a); i > (ll)(b); i--)
#define 	ms(a,b) 	memset((a),(b),sizeof(a))
#define 	max(a,b) 	((a>b)?(a):(b))
#define 	min(a,b) 	((a<b)?(a):(b))
#define 	vec(g1) 	int temp;cin>>temp;g1,push_back(temp);
#define 	abs(x) 		((x<0)?(-(x)):(x))
#define 	MAX 		1000005
#define 	inf 		LLONG_MAX
#define 	MIN 		INT_MIN

//typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;


int mod = 1e9 + 7 ;
ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll powmod(ll a,ll b) {ll res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}// ll fac[200005];
// ll inverse(ll n){return powmod(n, mod-2);}
// ll nCr(ll n, ll r){return (fac[n] * inverse(fac[r]) % mod * inverse(fac[n-r]) % mod) % mod;}

/**.................................................................................................................................*/

int main() {

  boost;
  string s,t;
  cin>>s>>t;
  int n=s.size();
  int m=t.size();
  int dp[n+1][m+1];
  for(int i=0;i<=n;i++){
  	for(int j=0;j<=m;j++){
  		if(i==0 || j==0)dp[i][j]=0;
  		else if(s[i-1]==t[j-1]){ 
  		
  			dp[i][j]=dp[i-1][j-1]+1;
  		}
  		else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
  	}
  }
  int idx=dp[n][m];
    char ans[idx+1];
    int i=n;
    int j=m;
    while(i>0 && j>0){
    	 if(s[i-1] == t[j-1]){
    	 	 ans[idx-1]=s[i-1];
    	 	  i--;j--;idx--;
    	 }
    	 else {
    	 	 if(dp[i-1][j]>dp[i][j-1])i--;
    	 	 else j--;
    	 }
    }
    
   for(int i=0;i<dp[n][m];i++)cout<<ans[i];
    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()

ll n, ans;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	if(n == 2) cout << 1, exit(0);
    for(ll i = 1; i * i <= n; ++i) {
        if(n % i == 1) {
            if(i > 1)
            ans++;
            if(n / i != i) ans++;
        }
    }
    for(ll i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            if(i > 1) {
                ll tmp = n;
                while(tmp % i == 0) tmp /= i;
                if(tmp % i == 1) ans++;
            }
            if(n / i != i) {
                ll newi = n / i;
                ll tmp = n;
                while(tmp % newi == 0) tmp /= newi;
                if(tmp % newi == 1) ans++;
            }
        }
    }
    cout << ans + 1;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func main() {
	var n int
	var slimeStr string
	fmt.Scan(&n)
	fmt.Scan(&slimeStr)

	if n <= 0 {
		fmt.Println(0)
	}

	slimes := strings.Split(slimeStr, "")

	length := 1
	for index, slime := range slimes {
		if (index + 1 >= n) {
			break
		}

		next := slimes[index + 1]

		if slime != next {
			length++
		}
	}

	fmt.Println(length)
}

Measured memory_bytes: 2944
#include <iostream>

using namespace std;
static const int N = 100;

int main(void)
{
	int M[N][N];
	int n, u, k, v;

	std::cin >> n;
	
	for(int i = 0; i < n; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			M[i][j] = 0;
		}
	}

	for(int i = 0; i < n; ++i)
	{
		std::cin >> u >> k;
		u--;

		for(int j = 0; j < k; ++j)
		{
			std::cin >> v;
		    v--;
			M[u][v] = 1;	
		}
	}

	for(int i = 0; i < n; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			if( j != 0 ) std::cout << " "; 
			std::cout << M[i][j];
		}
		
		std::cout << std::endl;
	}

	return 0;
}



Measured memory_bytes: 3136