akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(ll i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (ll i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<ll, ll>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const ll INF = 1E+18;

string rev (string s) {
    reverse(whole(s));
    return s;
};

struct Edge {
    ll to, co;
    Edge(ll to, ll co): to(to), co(co) {}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    vector<string> s(n);
    vector<ll> c(n);
    rep(i, n) {
        cin >> s[i] >> c[i];
    }
    rep(i, n) {
        s.push_back(rev(s[i]));
        c.push_back(c[i]);
    }

    vector<vector<ll>> id(2*n);
    ll num = 1;
    rep(i, 2*n) {
        ll l = s[i].size();
        id[i].resize(l);
        rep(j, l) id[i][j] = num++;
    }
    vector<vector<Edge>> g(num);
    rep(i, 2*n) {
        ll l = s[i].size();
        rep(j, l) {
            ll v = id[i][j];
            string s1 = s[i].substr(j);
            rep(k, 2*n) {
                if (i/n==k/n) continue;
                ll l2 = min(s[k].size(), s1.size());
                string s2 = s[k].substr(0, l2);
                if (s1.substr(0, l2)!=s2) continue;
                ll u = 0;
                if (s[k].size()<s1.size()) {
                    u = id[i][j+l2];
                }
                else if (s[k].size()>s1.size()) {
                    u = id[k][s1.size()];
                }
                else {
                    u = 0;
                }
                g[v].emplace_back(u, c[k]);
                //printf("%lld %lld %lld\n", v, u, c[k]);
            }
        }
    }

    vector<ll> dist(num, INF);
    priority_queue<P, vector<P>, greater<P>> q;
    rep(i, 2*n) {
        ll v = id[i][0];
        q.emplace(c[i], v);
        dist[v] = c[i];
    }
    while (!q.empty()) {
        P now = q.top();
        q.pop();
        ll co = now.first;
        ll v = now.second;
        if (dist[v]<co) continue;
        for (auto e: g[v]) {
            ll ico = co + e.co;
            ll u = e.to;
            if (dist[u]<=ico) continue;
            dist[u] = ico;
            q.emplace(ico, u);
        }
    }

    ll ans = INF;
    rep(i, 2*n) {
        ll l = s[i].size();
        rep(j, l) {
            string now = s[i].substr(j);
            if (now==rev(now)) {
                ll v = id[i][j];
                chmin(ans, dist[v]);
            }
        }
    }
    chmin(ans, dist[0]);
    if (ans==INF) ans = -1;

    pr(ans);
    return 0;
}

Measured memory_bytes: 3804
import itertools
n, m = map(int, input().split())
adj_matrix = [[0] * n for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    adj_matrix[a-1][b-1] = 1
    adj_matrix[b-1][a-1] = 1

cnt = 0
for each in itertools.permutations(range(n)):
    if each[0] != 0:
        break
    flag = 1
    for i in range(n-1):
        flag *= adj_matrix[each[i]][each[i+1]]
    cnt += flag
print(cnt)

Measured memory_bytes: 39408
#include <bits/stdc++.h>
using namespace std;
const int INF = 10000000;
vector<int> to[100005];
int main() {
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for(int u : to[v]){
      if(dist[u] != INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }
  cout << "Yes" << endl;
  for(int i = 1; i < n; i++){
    int ans = pre[i];
    ans++;
    cout << ans << endl;
  }
}

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

int n;
string a;

int solve();
map<string, int> calc(string &s);

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

int solve() {
  string now;
  for (int i = 0; i < n; ++i) now += '0' + i;
  map<string, int> st = calc(now), go = calc(a);
  int res = n - 1;
  for (auto p : st)
    if (go.find(p.first) != go.end()) res = min(res, p.second + go[p.first]);
  return res;
}

map<string, int> calc(string &s) {
  map<string, int> mp;
  mp[s] = 0;
  queue<string> qu;
  qu.push(s);
  while (qu.size()) {
    string now = qu.front();
    int cos = mp[now];
    if (cos >= (n - 1) / 2) break;
    qu.pop();
    for (int i = 0; i < n; ++i)
      for (int j = i + 1; j < n; ++j) {
        string to = now;
        reverse(to.begin() + i, to.begin() + j + 1);
        if (mp.find(to) == mp.end()) {
          mp[to] = cos + 1;
          qu.push(to);
        }
      }
  }
  return mp;
}


Measured memory_bytes: 71520
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int int64_t
#define double long double
#define pii pair<int, int>
#define pdd pair<double, double>
#define F first
#define S second
#define pb push_back
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orset;

const int N = 202000;

int32_t main(){
   ios_base :: sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   int x, y, z;
   cin >> x >> y >> z;
   swap(x, y);
   swap(x, z);
   cout << x << " " << y << " " << z;
}


Measured memory_bytes: 256
#include<iostream>
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (ll)1e9
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout<<"##"<<x<<"##"<<endl;
void solve()
{
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
        {
            cout<<"No";
            return;
        }
    }
    cout<<"Yes";

}
int main() 
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    solve();
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int h, w;
int cnt1[30];

bool solve(){
    if(w%2) swap(h,w);
    int cnt2[5]={}, x=h/2, y=w/2; bool a=h%2, b=w%2;
    for(int i=0; i<='z'-'a'; i++) cnt2[cnt1[i]%4]++;
    if(a && b){
        if(cnt2[1]+cnt2[3]>1) return false;
        if(cnt2[1]) cnt2[1]--, cnt2[0]++;
        if(cnt2[3]) cnt2[3]--, cnt2[2]++;
        return cnt2[2]<=(x+y);
    }
    if(cnt2[1] || cnt2[3]) return false;
    if(!a && !b) return cnt2[2]==0;
    return cnt2[2]<=w/2;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>h>>w;
    for(int i=1; i<=h; i++) for(int j=1; j<=w; j++){ char c; cin>>c; cnt1[c-'a']++; }
    cout<<(solve() ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

//上下左右は独立して考える
//必要十分条件を考える
//iターン目の先手が手を打った直後に[l,r]にロボットが存在するためには
//s[i]==Lなら[l+1,r]にロボットが存在する必要がある
//s[i]=Rなら[l,r-1]にロボットが存在している必要がある
//さらにiターン目の後手が手を打った直後に[l,r]にロボットが存在するようにするためには
//t[i]=Lなら[l,min(r+1,w-1)]にロボットが存在すること
//t[i]=Rなら[max(0,l-1),r]にロボットが存在すること
//とも言える
int main() {
	int H, W, N; cin >> H >> W >> N;
	int sr, sc; cin >> sr >> sc;
	sr -- ; sc--;
	string S, T; cin >> S >> T;
	int L = 0;
	int R = W - 1;
	int U = 0;
	int D = H - 1;
	for (int i = N-1; i >=0; --i) {
		if (T[i] == 'R') {
			L = max(0, L - 1);
		}
		else if (T[i] == 'L') {
			R = min(W - 1, R + 1);
		}
		else if (T[i] == 'D') {
			U = max(0, U - 1);
		}
		else {
			D = min(H - 1, D + 1);
		}
		
		if (S[i] == 'R') {
			R -= 1;
		}
		else if(S[i]=='L'){
			L += 1;
		}
		else if (S[i] == 'D') {
			D -= 1;
		}
		else {
			U += 1;
		}
		if (R < 0 || L >= W || U >= H || W < 0) {
			cout << "NO" << endl;
			return 0;
		}
	}
	if (L <= sc && sc <= R && U <= sr && sr <= D) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll a[4], b = 0, c = 0;
int main(){
	REP(i, 6) {
		int s;
		cin >> s;
		a[s - 1]++;
	}
	REP(i, 4) {
		if (a[i] == 1)b++;
		if (a[i] == 2)c++;
	}
	if (b == 2 and c == 2)cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=10000+5;
int d[maxn],num[10];
bool ok[10];
int n,k;
bool check(int x){
    int tmp=x;
    while(tmp>0){
        if(ok[tmp%10]) return false;
        tmp/=10;
    }
    return true;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++){
        scanf("%d",&d[i]);
        ok[d[i]]=true;
    }
    for(int i=n;;i++){
        if(check(i)){
            printf("%d\n",i);
            exit(0);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int N, L;
    cin>>N>>L;
    int minabs = 1000000;
    int eat = 0;
    int sum=0;
    int taste[200];
    for(int i=0;i<N;i++){
        taste[i]=L+i;
        if(minabs>abs(taste[i])){
            minabs=abs(taste[i]);
            eat = taste[i];
        }
        sum+=taste[i];
    }
    // cout<<eat<<endl;
    cout<<sum-eat<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+10;
int n,m,k;
char s[7][7];
int base[100][6];
char str[7][7];
void init()
{
    for(int i=0;i<(1<<6);i++){
        for(int j=0;j<6;j++){
            base[i][j]=((i>>j)&1);
        }
    }
}
bool judge(int r,int c)
{
    for(int i=0;i<n;i++){
        if((r>>i)&1){
            for(int j=0;j<m;j++){
                str[i][j]='*';
            }
        }
    }
    for(int j=0;j<m;j++){
        if((c>>j)&1){
            for(int i=0;i<n;i++){
                str[i][j]='*';
            }
        }
    }
    int ko=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(str[i][j]=='#'){
                ko++;
            }
        }
    }
    if(ko==k){
        return true;
    }
    return false;
}
int main()
{
    init();
   /* for(int i=0;i<10;i++){
        for(int j=0;j<6;j++){
            printf("%d ",base[i][j]);
        }
        printf("\n");
    }*/
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<n;i++){
        scanf("%s",s[i]);
    }
    int res=0;
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<(1<<m);j++){
            for(int K=0;K<n;K++){
                for(int l=0;l<m;l++){
                    str[K][l]=s[K][l];
                }
            }
            if(judge(i,j)){
                res++;
            }
        }
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
//char a[55][55];
int dx[] = {1,0,-1,0,1,1,-1,-1};
int dy[] = {0,1,0,-1,1,-1,-1,1};
ll a[100];
int main()
{
	dhoom;
	int n;
	cin >> n;
	int x = n;
	int sum = 0;
	while(x!=0){
		sum += (x%10);
		x /= 10;
	}
	if(n%sum == 0)
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
	return 0;
}


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

int main (){
  int N;
  cin >>N;
  vector<double> A(N);
  
  for(int i=0;i<N;i++){
    cin >>A.at(i);
  }
  
  double sum_h = 1;
  for(int i=0;i<N;i++){
    sum_h *= A.at(i);
  }
  vector<double> S(N);
  for(int i=0;i<N;i++){
    S.at(i) = sum_h/A.at(i);
  }
  double sum_of_S = 0;
  for(int i=0;i<N;i++){
    sum_of_S += S.at(i);
  }
  double ans = sum_h/sum_of_S;
  cout <<ans<<endl;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;
//エイシングプログラミング　コンテスト2019

//status unsolved
int h,w;
char maze[410][410];


int main(){
    
    cin>>h>>w;
    queue<int>Q;
    //queue<int>color;
    rep2(i,h){
        rep2(k,w){
            cin>>maze[i][k];
            if(maze[i][k]=='#'){
                Q.push(i);
                Q.push(k);
                //color.push(1); //黒の数
                //color.push(0); //白の数
            }
        }
    }
    bool checked[410][410]={};
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    long long ans=0;

    while(!Q.empty()){
    long long  nowb=1;
    long long  noww=0;
    int nowy=Q.front();Q.pop();
    int nowx=Q.front();Q.pop();
    if(checked[nowy][nowx])continue;

    queue<int>q;
    q.push(nowy);
    q.push(nowx);
    checked[nowy][nowx]=true;
        while(!q.empty()){
            nowy=q.front();q.pop();
            nowx=q.front();q.pop();
        //int nowb=color.front();color.pop();
        //int noww=color.front();color.pop();
            rep(i,4){
                int nx=nowx+dx[i];
                int ny=nowy+dy[i];
                if(nx<1 ||nx>w || ny<1 ||ny>h)continue;
                if(checked[ny][nx])continue;

                //白から黒
                if(maze[nowy][nowx]=='.' && maze[ny][nx]=='#'){
                nowb++;
                checked[ny][nx]=true;
                q.push(ny);q.push(nx);
                }
                //黒から白
                else if((maze[nowy][nowx]=='#' && maze[ny][nx]=='.')){
                noww++;
                checked[ny][nx]=true;
                q.push(ny);q.push(nx);
                }
            }
        }
    //cout<<ans<<" ";
    ans+=noww*nowb;
    }
    cout<<ans<<endl;

    return 0;

}
/*


*/


Measured memory_bytes: 1664
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <random>

using ll = long long;

//vector
template <class T>
using vec = std::vector<T>;

//namespace std
//{
//    template<>
//    class hash<Key>
//    {
//    public:
//        size_t operator() (const Key& key) const
//        {
//            size_t seed = 0;
//            auto i_hash = hash<int>()(key.i_th);
//            auto w_hash = hash<int>()(key.W);
//
//            seed ^= i_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
//            seed ^= w_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
//
//            return seed;
//        }
//    };
//}

void solve()
{
    using namespace std;

    int N;
    cin >> N;

    vec<int> v;
    v.push_back(1);

    for (int i = 6; i <= N; i *= 6)
    {
        v.push_back(i);
    }

    for (int i = 9; i <= N; i *= 9)
    {
        v.push_back(i);
    }

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

    vec<vec<int>> dp(v.size() + 1, vec<int>(N + 1, 10000000));

    for (int i = 0; i < dp.size(); ++i)
        dp[i][0] = 0;
    
    for (int j = 0; j <= N; ++j)
        dp[0][j] = j;

    for (int i = 1; i <= v.size(); ++i)
        for (int j = 0; j <= N; ++j)
        {
            dp[i][j] = min(dp[i - 1][j] ,dp[i][j]);
            

            for (int k = 0; k < i; ++k)
                if (j >= v[k])
                    dp[i][j] = min({dp[i][j], dp[i - 1][j - v[k]] + 1, dp[i][j - v[k]] + 1});
        }

    cout << dp[v.size()][N] << endl;
}

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

Measured memory_bytes: 5760
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define eps 1e-8
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

int n,m,total=0;
vector<vi> v;
vi cost,treasurbit;

int dp[1005][5000];

int f(int i,int selected){
    if(i==m){
        if(selected==total)return 0;
        return 1e18;
    }
    
    if(dp[i][selected]!=-1)return dp[i][selected];
    
    int a=f(i+1,selected);
    int b=f(i+1,selected|treasurbit[i])+cost[i];
    
    return dp[i][selected]=min(a,b);
    
}

signed main(){
    FASTER;
    cin>>n>>m;
    v.resize(m);
    cost.resize(m);
    treasurbit.resize(m,0);
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++){
        total|=(1<<i);
    }
    
    for(int i=0;i<m;i++){
        int a;
        cin>>cost[i]>>a;
        while(a--){
            int in;cin>>in;
            treasurbit[i]|=(1<<(in-1));
        }
    }
    
    int anss=f(0,0);
    
    if(anss!=1e18){
        cout<<anss;
    }else cout<<-1;
}

Measured memory_bytes: 39552
#include <stdio.h>
#define ll long long
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	printf("%lld\n",pom(m,n,MOD));
}


Measured memory_bytes: 2056
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

char ans[1000][1000];

vector<vector<char>> b3 = {
    {'.', 'a', 'a'},
    {'b', '.', '.'},
    {'b', '.', '.'}
};

vector<vector<char>> b4 = {
    {'a', 'a', 'c', 'd'},
    {'b', 'b', 'c', 'd'},
    {'c', 'd', 'b', 'b'},
    {'c', 'd', 'a', 'a'}
};

vector<vector<char>> b5 = {
    {'a', 'b', 'b', 'c', 'c'},
    {'a', 'c', 'c', '.', 'b'},
    {'b', '.', '.', 'c', 'b'},
    {'b', '.', '.', 'c', 'a'},
    {'a', 'a', 'b', 'b', 'a'},
};

vector<vector<char>> b7 = {
    {'a', '.', 'b', '.', '.', 'c', 'c'},
    {'a', '.', 'b', 'c', 'c', '.', '.'},
    {'.', 'b', 'a', 'a', '.', 'c', 'c'},
    {'.', 'b', '.', '.', 'a', 'b', '.'},
    {'a', 'a', '.', '.', 'a', 'b', '.'},
    {'.', '.', 'a', 'a', 'c', '.', 'c'},
    {'a', 'a', '.', '.', 'c', '.', 'c'}
};

vector<int> find(int n){
    vector<int> ans;
    if(n%3 == 0){
        for(int i = 0; i < n/3; i++) ans.push_back(3);
    }else if(n%4 == 0){
        for(int i = 0; i < n/4; i++) ans.push_back(4);
    }else{
        for(int i = 0; i < n/4; i++){
            int rem = n-i*4;
            if(rem%5 == 0){
                for(int j = 0; j < i; j++) ans.push_back(4);
                for(int j = 0; j < rem/5; j++) ans.push_back(5);
                break;
            }
            if(rem%7 == 0){
                for(int j = 0; j < i; j++) ans.push_back(4);
                for(int j = 0; j < rem/7; j++) ans.push_back(7);
                break;
            }
        }
        if(ans.size() == 0){
            for(int i = 0; i < n/5; i++){
                int rem = n-i*5;
                if(rem%7 == 0){
                    for(int j = 0; j < i; j++) ans.push_back(5);
                    for(int j = 0; j < rem/7; j++) ans.push_back(7);
                    break;
                }
            }
        }
    }
    return ans;
}

vector<vector<char>> buf[10];

void create(vector<int> v){
    int cur = 0;
    for(int i = 0; i < v.size(); i++){
        for(int j = 0; j < buf[v[i]].size(); j++){
            for(int k = 0; k < buf[v[i]].size(); k++){
                ans[cur+j][cur+k] = buf[v[i]][j][k];
            }
        }
        cur += buf[v[i]].size();
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    buf[3] = b3;
    buf[4] = b4;
    buf[5] = b5;
    buf[7] = b7;
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            ans[i][j] = '.';
        }
    }
    if(N == 2){
        cout << -1 << endl;
        return 0;
    }
    vector<int> v = find(N);
    create(v);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cout << ans[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 2176
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#define SIZE 200005

using namespace std;

vector <int> A[SIZE];
vector <int> B[SIZE];
int dep[SIZE],par[SIZE];
int dp[SIZE];

void solve(int v,int p,int d)
{
	par[v]=p;
	dep[v]=d;
	for(int i=0;i<B[v].size();i++)
	{
		int to=B[v][i];
		if(to!=p) solve(to,v,d+1);
	}
}
bool good(int s,int t)
{
	if(dep[s]>dep[t]) swap(s,t);//dep[s]<=dep[t]
	if(s==t||par[t]==s||par[s]==par[t]) return false;
	if(par[t]!=-1&&par[par[t]]==s) return false;
	return true;
}
int main()
{
	int n,X,Y;
	scanf("%d %d %d",&n,&X,&Y);X--,Y--;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--;b--;
		A[a].push_back(b);
		A[b].push_back(a);
	}
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--;b--;
		B[a].push_back(b);
		B[b].push_back(a);
	}
	memset(dp,-1,sizeof(dp));
	solve(Y,-1,0);
	dp[X]=0;
	queue <int> que;
	que.push(X);
	int ret=0;
	while(!que.empty())
	{
		int v=que.front();que.pop();
		ret=max(ret,dep[v]*2);
		for(int i=0;i<A[v].size();i++)
		{
			int to=A[v][i];
			if(dp[to]!=-1) continue;
			if(good(v,to))
			{
				puts("-1");
				return 0;
			}
			if(dp[v]+1<dep[to])
			{
				dp[to]=dp[v]+1;
				que.push(to);
			}
		}
	}
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 35836
n, m, l = map(int,input().split())
A = [list(map(int, input().split())) for i in range(n)]
B = [list(map(int, input().split())) for i in range(m)]
for i in range(n):
    C = []
    for j in range(l):
        c = 0
        for k in range(m):
            c += A[i][k] * B[k][j]
        C.append(c)
    print(*C)

Measured memory_bytes: 8564
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        
        String[] x = stdR.readLine().split(" ");
        long A = Long.parseLong(x[0]);
        long B = Long.parseLong(x[1]);
        
        long gcd = GCD(A, B);
        System.out.println(primeFactorization(gcd) + 1);

    }
    
    public static long GCD(long x, long y) {
        if ( y == 0) return x;
        return GCD(y, x % y);
    }
    
    public static long primeFactorization(long n){
        
        int s = (int)(Math.sqrt(n));
        
        int[] primes = new int[s];

        int j = 0;
        for(int i = 2; i <= s; i++){
            
            if(n % i == 0){
                while(n % i  == 0){
                    n /= i;
                }
                primes[j++] = i;                
            }
        }
        
        if(n != 1){
            j++;
        }
        
        return j;
    }
    
}


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

int main(){
  string s, t; cin >> s >> t;
  vector<char> S(s.size());
  vector<char> T(t.size());
  for (int i=0;i<s.size();i++){
    S.at(i)=s.at(i);
  }
  for (int i=0;i<t.size();i++){
    T.at(i)=t.at(i);
  }
  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  reverse(T.begin(), T.end());
  for (int i=0;i<s.size();i++){
    s.at(i)=S.at(i);
  }
  for (int i=0;i<t.size();i++){
    t.at(i)=T.at(i);
  }
  if (s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  
    

Measured memory_bytes: 764
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int[] t = new int[n];
		for(int i = 0; i < n; i++){
			t[i] = scan.nextInt();
		}
		int m = scan.nextInt();
		int[] p = new int[m];
		int[] x = new int[m];
		for(int i = 0; i < m; i++){
			p[i] = scan.nextInt();
			x[i] = scan.nextInt();
		}

		for(int i = 0; i < m; i++){
			int s = t[p[i]-1];
			t[p[i]-1] = x[i];
			int sum = 0;
			for(int j = 0; j < n; j++){
				sum += t[j];
			}
			System.out.println(sum);
			t[p[i]-1] = s;
		}
	}
}


Measured memory_bytes: 23252
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int A,B;
    cin >> A >> B;
    if(A<=8 && B<=8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans=0;
  bool f = (s[0] == '0');

  for (int i=1; i<n; i++) {
    if (f) {
      if (s[i] == '0') ans++;
    } else {
      if (s[i] == '1') ans++;
    }
    f = !f;
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
s=list(input())+['Z']
ACGT=['A','C','G','T']
t=[]
count=0
for i in s:
    if i in ACGT:
        count+=1
    else:
        t.append(count)
        count=0

if len(t)==0:
    print(len(s))
else:
    print(max(t))


Measured memory_bytes: 2940
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn=new Scanner(System.in);
	int n = stdIn.nextInt();
	int j;
	int[] result=new int[3];
	int i=2;
	while(n!=0){
	    j = n%10;
	    if(j==9){
		result[i]=1;
	    }else if(j==1){
		result[i]=9;
	    }else{
		result[i]=j;
	    }
	    n/=10;
	    i--;
	}
	System.out.print(result[0]);
	System.out.print(result[1]);
	System.out.println(result[2]);
    }
}
	


Measured memory_bytes: 21716
#include<iostream>
using namespace std;
int main(){
	int N,i,A[1000],M,B[1000],max;
	int a,temp,b;
	int sum[1000]={0};
	cin>>N>>M;
	for(i=0;i<N;i++){
		cin>>A[i];
	}
	for(i=0;i<M;i++){
		cin>>B[i];
	}
	for(i=0;i<M;i++){
		for(a=0;a<N;a++){
			if(B[i]>=A[a]){
				sum[a]++;
				break;
			}
		}
	}
	max=0;
	for(i=0;i<N;i++){
		if(sum[i]>max){
			max=sum[i];
			b=i;
		}
	}
	cout<<b+1<<endl;
	return 0;
}

Measured memory_bytes: 3056
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

x=I()
if x>=30:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 65424
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n, a;
    std::cin>>n>>a;

    std::cout<<((n % 500) <= a ? "Yes" : "No")
        <<std::endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int a[200010];
int vis[1000010],ok[1000010];

signed main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],vis[a[i]]++;
	sort(a+1,a+n+1);
	int ans=0;
	for(int i=1;i<=n;i++) if(vis[a[i]]&&!ok[a[i]]){
		if(vis[a[i]]==1) ans++;
		for(int j=a[i];j<=1000000;j+=a[i]) ok[j]=1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12084
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0319
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = RInt();
            int[] score = RArInt();
            Array.Sort(score);
            Array.Reverse(score);

            int res = 0;
            for (int i = 0; i < score.Length; i++)
            {
                if (i  < score[i]) res = i + 1;
            }
            Console.WriteLine(res);
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 17992
// Tazoe

#include <iostream>
using namespace std;

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

		if(n==0)
			break;

		int cnt = 0;

		while(n!=1){
			if(n%2==0){
				n = n/2;
			}
			else{
				n = n*3+1;
			}

			cnt++;
		}

		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 0
n=int(input())
a=[int(i) for i in input().split()]
k,m=0,abs(a[0])
for i in range(1,n):
    if abs(a[i])>m:
        m=abs(a[i])
        k=i
print(2*n-1)
for i in range(n):
    print(k+1,i+1)
if a[k]>=0:
    for i in range(1,n):
        print(i,i+1)
else:
    for i in range(1,n):
        print(n+1-i,n+1-i-1)



Measured memory_bytes: 38524
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/
int sigma(LL x){
  LL ans = (x-1)*x/2;
  ans%=MOD;
  return ans;
}
LL dp[4000][4000];
int main(){
  int n;
  cin >> n;
  LL ans=0;
  vector<pair<LL,LL>> a(n);
  REP(i, n){
    cin >> a[i].first;
    a[i].second=i;
  }
  sort(ALL(a),greater<pair<LL,LL>>());
  REP(i,n){
    REP(j, n-i){
      dp[i+1][j]=max(dp[i+1][j], dp[i][j]+abs(a[i+j].second-i)*a[i+j].first);
      dp[i][j+1]=max(dp[i][j+1], dp[i][j]+abs(a[i+j].second-(n-j-1))*a[i+j].first);
    }
  }
  REP(i,n){
    ans=max(ans,dp[i][n-i]);
  }
  cout << ans << endl;


}

Measured memory_bytes: 27248
#include <cstdio>

using namespace std;

int main()
{
	int a,b,c;
	scanf("%d %d", &a, &b);
	if(a+b>24) {
		printf("%d", (a+b)%24);
	}
	else if (a+b==24){
		printf("0");
	}
	else{
		printf("%d", a+b);
	}
	
	
	
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
   int n,x;
   cin>>n>>x;
  vector<int> L(n),y(n+1,0);
  for(int i=0;i<n;i++)cin>>L.at(i);
  for(int i=0;i<n;i++)y.at(i+1)=L.at(i)+y.at(i);
  int count=0;
  for(int i=0;i<=n;i++){
      if(x>=y.at(i))count++;
      else break;
  }
  cout<<count<<endl;
}

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

using P = pair<int, int>;

constexpr int INF = 1e9;

int main() {
    ll N, W;
    cin >> N >> W;
    vector<vector<vector<ll>>> dp(N+1, vector<vector<ll>>(N+1, vector<ll>(301)));
    vector<ll> w(N), v(N);
    for(int i=0; i<N; ++i) {
        cin >> w[i] >> v[i];
    }
    for(int i=0; i<N; ++i) {
        for(int j=0; j<N; ++j) {
            for(int k=0; k<301; ++k) {
                dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
                if(k + (w[i] - w[0]) <= 300) {
                    dp[i+1][j+1][k+(w[i]-w[0])] = max(dp[i+1][j+1][k+(w[i]-w[0])], dp[i][j][k] + v[i]);
                }
            }
        }
    }
    ll res = 0;
    for(int i=0; i<=N; ++i) {
        for(int j=0; j<301; ++j) {
            if(i*w[0] + j <= W) {
                res = max(res, dp[N][i][j]);
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 24832
#include <cstdio>
#define Maxn 100000
#define Mod 998244353
int dep[Maxn+5];
int num[Maxn+5];
int n;
int mx(int a,int b){
	return a>b?a:b;
}
int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1){
			ans=1ll*ans*a%Mod;
		}
		a=1ll*a*a%Mod;
		b>>=1;
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	int mx_dep=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&dep[i]);
		num[dep[i]]++;
		mx_dep=mx(mx_dep,dep[i]);
	}
	if(dep[1]!=0){
		puts("0");
		return 0;
	}
	if(num[0]>1){
		puts("0");
		return 0;
	}
	int ans=1;
	for(int i=1;i<=mx_dep;i++){
		ans=1ll*ans*ksm(num[i-1],num[i])%Mod;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<functional>
#include<map>
using namespace std;
int main()
{
	char a, b;
	cin >> a >> b;
	if (a == b)cout << "=" << endl;
	else if(a<b)cout << "<" << endl;
	else if (a>b)cout << ">" << endl;
	//system("pause");
	return 0;
}

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

int main(){
    int n;
    int a[100000],b[100000];
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> a[i] >> b[i];
    }
    int max = a[0];
    int j;
    for(int i=1;i<n;++i){
        if(max < a[i]){
            max = a[i];
            j = i;
        }
    }
    cout << max + b[j] << endl;
    return 0;
}

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

class DAG {
public:
    int n, m;
    vector<vector<int>> g;
    DAG(int nn, int mm) {
        n = nn;
        m = mm;
        g.resize(n+1);
    }
    void addEdge(int u, int v) {
        g[u].push_back(v);
    }
    int dfs(int src, vector<int>& dp) {
        if(dp[src] != -1) {
            return dp[src];
        }
        int ans = 1;
        for(auto edge : g[src]) {
            ans = max(ans, 1+dfs(edge, dp));
        }
        dp[src] = ans;
        return ans;
    }
    int longestPath() {
        vector<int> dp(n+1, -1);
        set<int> src;
        for(int i = 1; i <= n; i ++)src.emplace(i);
        for(auto i : g) {
            for(auto j : i) src.erase(j);
        }
        assert(src.size() > 0);
        int ans = 0;
        for(auto i:src) {
            if(dp[i] == -1) {
                ans = max(ans, dfs(i, dp));
            }
        }
        return ans;
    }
};


int32_t main() {
    int n, m; cin >> n >> m;
    DAG dag(n, m);
    for(int i = 0; i < m; i ++) {
        int u, v; cin >> u >> v;
        dag.addEdge(u, v);
    }
    int ans = dag.longestPath();
    cout << ans-1 << endl;
    
    return 0;
}

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

int main() {
  int N, M, i, j;
  cin >> N >> M;
  vector<int> a(M), b(M);
  for (i = 0; i < M; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  vector<int> graph(N - 1);
  for (i = 0; i < N - 1; i++) {
    graph.at(i) = i + 2;
  }
  int count = 0;
  bool flag = false;
  do {
    for (i = -1; i < N - 2; i++) {
      flag = false;
      if (i == -1) {
        for (j = 0; j < M; j++) {
          if (a.at(j) == 1) {
            if (b.at(j) == graph.at(i + 1)) {
              flag = true;
              break;
            }
          }
        }
      }
      else {
        if (graph.at(i) < graph.at(i + 1)) {
          for (j = 0; j < M; j++) {
            if (a.at(j) == graph.at(i)) {
              if (b.at(j) == graph.at(i + 1)) {
                flag = true;
                break;
              }
            }
          }
        }
        else {
          for (j = 0; j < M; j++) {
            if (b.at(j) == graph.at(i)) {
              if (a.at(j) == graph.at(i + 1)) {
                flag = true;
                break;
              }
            }
          }
        }
      }
      if (!flag) {
        break;
      }
    }
    if (flag) {
      count++;
    }
  } while (next_permutation(graph.begin(), graph.end()));
  cout << count << endl;
}

Measured memory_bytes: 3604
from fractions import gcd


def lcm(x, y):
    return x*y//gcd(x, y)


A, B, C, D = map(int, input().split())

LCM = lcm(C, D)

x = B//C
y = B // D
z = B // LCM
ans = B-x-y+z

x = (A-1) // C
y = (A-1) // D
z = (A-1) // LCM

ans -= (A-1) - x - y + z

print(ans)


Measured memory_bytes: 5180
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

x, y = MAP()
if y%2 ==1:
    print('No')
    sys.exit()
a = 2*x-(y//2)
b = -x + (y//2)
if a >=0 and b>=0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 77364
n = int(input())
lst = [list(map(int, input().split())) for i in range(n)]
lst.sort()

if n%2 == 1:
  lst.sort()
  m = lst[n//2][0]
  lst.sort(key=lambda x: x[1])
  M = lst[n//2][1]
  print(M-m+1)
  
else:
  lst.sort()
  p, q  = lst[n//2-1][0], lst[n//2][0]
  m = p+q
  lst.sort(key=lambda x: x[1])
  P, Q  = lst[n//2-1][1], lst[n//2][1]
  M = P+Q
  print(M-m+1)

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

#define ld long double
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define nl '\n'
#define pii pair <ll, ll>
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323846264
#define y1 abacaba
#define fn "abc"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define chill_wave ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pressF freopen("lepus.in", "r", stdin); freopen("lepus.out", "w", stdout);
#define __lcm(a, b) a * b / __gcd(a, b)
#define up_b upper_bound
#define low_b lower_bound
#define pcnt(i) __builtin_popcount(i)

using namespace std;

const long long MXN = 1e6 + 1;
const long long MAXN = 1e3 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

inline void JUDGE(bool ok = 0) { chill_wave if(ok) { pressF; } }

//int dx[]= {1,-1,0,0}; int dy[]= {0,0,1,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

ll n, k;

int main() {

    JUDGE();

    cin >> n >> k;
    if(n <= k) {
        while(k--) {
            cout << n;
        }
    } else {
        while(n--) {
            cout << k;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n, a[123];
	while (cin >> n, n) {
		n++;
		for (int i = 0; i < n; i++)cin >> a[i];
		if (a[3] - a[2] == a[2] - a[1] && a[3] - a[2] == a[1] - a[0]) {
			for (int i = 4; i < n; i++) {
				if (a[i] - a[i - 1] != a[3] - a[2]) {
					cout << a[i] << endl;
					goto heaven;
				}
			}
		}
		else if (a[4] - a[3] == a[3] - a[2] && a[3] - a[2] == a[2] - a[1]) cout << a[0] << endl;
		else if (a[4] - a[3] == a[3] - a[2] && a[3] - a[2] == a[2] - a[0]) cout << a[1] << endl;
		else if (a[4] - a[3] == a[3] - a[1] && a[3] - a[1] == a[1] - a[0]) cout << a[2] << endl;
		else cout << a[3] << endl;
	heaven:;
	}
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
const int N=110;
char s[N][N];
int n,m,x,y,ans,cnt[N][N],dp0[N][N][N],dp1[N][N][N];
void bemax(int &x,int v){
	if (x<v) x=v;
	if (ans<v) ans=v;
}
int count(int x1,int y1,int x2,int y2){
	return cnt[x2][y2]-cnt[x2][y1-1]-cnt[x1-1][y2]+cnt[x1-1][y1-1];
}
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<=m;j++){
		cnt[i][j]=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1]+(s[i][j]=='o');
		if (s[i][j]=='E') x=i,y=j;
	}
	for (int a=0;a<=x-1;a++){
		for (int b=0;b<=n-x;b++)
		for (int c=0;c<=y-1;c++)
		for (int d=0;d<=m-y;d++)
			dp1[b][c][d]=0;
		for (int b=0;b<=n-x;b++)
		for (int c=0;c<=y-1;c++)
		for (int d=0;d<=m-y;d++){
			int v=dp0[b][c][d];
			int lx=max(x-a,b+1),ly=max(y-c,d+1),rx=min(x+b,n-a),ry=min(y+d,m-c);
			if (x-a-1>b) bemax(dp1[b][c][d],v+count(x-a-1,ly,x-a-1,ry));
			if (x+b+1<n-a+1) bemax(dp0[b+1][c][d],v+count(x+b+1,ly,x+b+1,ry));
			if (y-c-1>d) bemax(dp0[b][c+1][d],v+count(lx,y-c-1,rx,y-c-1));
			if (y+d+1<m-c+1) bemax(dp0[b][c][d+1],v+count(lx,y+d+1,rx,y+d+1));
		}
		for (int b=0;b<=n-x;b++)
		for (int c=0;c<=y-1;c++)
		for (int d=0;d<=m-y;d++)
			dp0[b][c][d]=dp1[b][c][d];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10496
#include <stdio.h>

long long chmax(long long N,long long A,long long B){
	

		if(N-A>B-1)return (B-1+A)/2;
		else return (N-B+1+N-A)/2;
		
		
	
	return 0;
}
int main()
{
	long long N,A,B,ans;
	
	scanf("%lld%lld%lld",&N,&A,&B);
	
	if((B-A)%2==0){
		ans =(B-A)/2;
	}
	else {
		
		ans= chmax(N,A,B);
	}
	printf("%lld\n",ans);
	return 0;
}

//2 3 4,,, 2 3 4 "5" 6 7 8 9 "10" 11 12 
 //                  1 2 3 4   5   6

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll //unsigned long long
typedef pair<int, int> pii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
constexpr int INF = 1e9;
constexpr int MOD = 1e9+7;

int pnum[60];
int xnum[60];

void cal_num(int n) {
    FOR(i, 1, n+1) {
        pnum[i] = pnum[i-1] * 2 + 1;
        xnum[i] = xnum[i-1] * 2 + 3;
    }
    //REP(i, n+1) cout << pnum[i] << endl;
    //cout << pnum[1] << endl;
}

int cal_pnum(int n, int x) {
    if (n == 0) {
        if (x <= 0) return 0;
        else return 1;
    }
    int div = (xnum[n] + 2 -1) / 2;
    if (x == div) {
        return pnum[n-1] + 1;
    } else if (x < div) {
        return cal_pnum(n-1, x-1);
    } else {
        x -= div;
        return pnum[n-1] + 1 + cal_pnum(n-1, x);
    }
}

signed main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int N, X;
    cin >> N >> X;
    pnum[0] = 1;
    xnum[0] = 1;
    cal_num(N);
    int ans = cal_pnum(N, X);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

const int MAX_N = 2e5;
int N, K, L, parent[MAX_N], hight[MAX_N], road[MAX_N];

void init(int n){
    for(int i=1;i<=n;i++){
        parent[i] = i;
        hight[i] = 0;
    }
}

int find(int x){
    if(parent[x] == x) return x;
    else return parent[x] = find(parent[x]);
}

void unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return;
    if(hight[x]<hight[y]) parent[x] = y;
    else{
        parent[y] = x;
        if(hight[x] == hight[y]) hight[x]++;
    }
}

int main(){
    cin >> N >> K >> L;
    init(N);
    for(int i=0;i<K;i++){
        int p, q; cin >> p >> q;
        unite(p, q);
    }
    for(int i=1;i<=N;i++) road[i] = find(i);

    init(N);
    for(int i=0;i<L;i++){
        int p, q; cin >> p >> q;
        unite(p, q);
    }

    map<P, int> cnt;
    for(int i=1;i<=N;i++) cnt[P(road[i], find(i))]++;
    for(int i=1;i<=N;i++) cout << cnt[P(road[i], parent[i])] << ' ';
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 14336