akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N(111111);
bool vst[N];
vector<int> adj[N];
int dep[N];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i(1); i <= m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	long long cnt[2] = {0, 0};
	long long siz1(0);
	fill(vst + 1, vst + 1 + n, false);
	for(int i(1); i <= n; i++) {
		if(!vst[i]) {
			vector<int> q;
			q.push_back(i);
			vst[i] = true;
			dep[i] = 0;
			bool isBip(true);
			for(int op(0); op < (int)q.size(); op++) {
				int v(q[op]);
				for(int y : adj[v]) {
					if(!vst[y]) {
						vst[y] = true;
						q.push_back(y);
						dep[y] = dep[v] + 1;
					}else {
						if((dep[v] - dep[y]) % 2 == 0) {
							isBip = false;
						}
					}
				}
			}
			if(q.size() == 1) {
				siz1 += q.size();
			}else {
				cnt[isBip]++;
			}
		}
	}
	long long ans(0);
	ans += siz1 * siz1 + 2 * siz1 * (n - siz1);
	ans += (cnt[0] + cnt[1]) * (cnt[0] + cnt[1]);
	ans += cnt[1] * cnt[1];
	cout << ans << endl;
}


Measured memory_bytes: 8188
n=gets.to_i
s=(0...n).map{|i|i.chr"".encoding}.*""
$<.map{|l|c,x,y=l.split.map &:to_i
c<1?s[x]!=s[y]&&s.tr!(s[x],s[y]):p(s[x]==s[y]?1:0)}

Measured memory_bytes: 9028
n,m=map(int,input().split())
l={int(input()) for i in range(m)}
dp=[0 for i in range(n+1)]
dp[0]=1
for i in range(1,1+n):
    if i not in l:dp[i]+=dp[i-1]+dp[i-2];dp[i]%=10**9+7
print(dp[n])

Measured memory_bytes: 11884
#include <iostream>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<vector<int> > v(n, vector<int>(n, 0));
  for(int i = 0; i < n; i++){
    int u, k; cin >> u >> k;
    for(int j = 0; j < k; j++){
      int x; cin >> x;
      v[u - 1][x - 1] = 1;
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n - 1; j++){
      cout << v[i][j] << " ";
    }
    cout << v[i][n - 1] << endl;
  }
  return;
}

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



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

int main() {
	string o, e; cin >> o >> e;
	string ans;
	for (int i = 0; i < o.length(); i++) {
		ans += o[i];
		if(i < e.length())ans += e[i];
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  int A,B;
  int a=0;
  
  cin >> A >> B;
    
  for(int i=A;i<=B;i++){
    if((i%10==i/10000)&&((i/10)%10==(i/1000)%10)){
      a++;
    }
    else {}
  }
  
  cout << a <<endl;
}

Measured memory_bytes: 3612
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

ll c[2001][2001] = {0};
int main(){
  ll n,k;
  cin >> n >> k;
  rep(i,2001){
    c[i][0] = 1;
    c[i][i] = 1;
  }

  rep(i,2001){
    for(int j = 1; j < i; j++){
      c[i][j] = (c[i-1][j] + c[i-1][j-1])%mod;
    }
  }

  ll ans;
  for(int i = 1; i <= k; i++){
    ans = (c[n-k+1][i]*c[k-1][i-1])%mod;
    printf("%lld\n", ans);
  }

  return 0;
}


Measured memory_bytes: 30080
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  vector<int> dp(100005,INF);
  dp[0] = 0;
  for(int i=0; i<100000; ++i){
    dp[i+1] = min(dp[i+1], dp[i]+1);
    for(int j=6; i+j<=100000; j*=6){
      dp[i+j] = min(dp[i+j], dp[i] +1);
    }
    for(int j=9; i+j<=100000; j*=9){
      dp[i+j] = min(dp[i+j], dp[i] +1);
    }
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 640
# coding: utf-8

def mole():
    global p
    global s
    num=term()
    while len(s)>p:
        if s[p]=='+':
            p+=1
            num+=term()
        else:
            break
    return num

def term():
    global p
    global s
    num=factor()
    while len(s)>p:
        if s[p]=='*':
            p+=1
            num*=factor()
        else:
            break
    return num

def factor():
    global p
    global s
    num=0
    if len(s)>p and s[p]=='(':
        p+=1
        num=mole()
        p+=1
    else:
        return number()
    return num

def number():
    global p
    global s
    num=0
    if s[p].isdigit():
        while len(s)>p and s[p].isdigit():
            num*=10
            num+=int(s[p])
            p+=1
    elif s[p]!='(' and s[p]!=')':
        tmp=''
        while len(s)>p and s[p]!='(' and s[p]!=')' and s[p]!='+' and s[p]!='*':
            tmp+=s[p]
            p+=1
        if tmp in dic:
            num=int(dic[tmp])
        else:
            global f
            f=False
    return num

def pre():
    global s
    s=list(s)
    i=1
    while True:
        if i>=len(s):
            break
        if s[i].isdigit():
            s.insert(i,'*')
            i+=1
            while i+1<len(s) and s[i+1].isdigit():
                i+=1
        elif (s[i]=='(' or s[i].isupper()) and (s[i-1]!='('):
            s.insert(i,'+')
            i+=1
        i+=1
    s=''.join(s)

dic={}
while True:
    s=input()
    if s=='END_OF_FIRST_PART':
        break
    a,b=s.split()
    dic[a]=b
while True:
    s=input()
    if s=='0':
        break
    p=0
    f=True
    pre()
    ans=mole()
    print(ans if f else 'UNKNOWN')




Measured memory_bytes: 5620
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=1000000007;
const ll INF=10000000010101001;
int main(){
    ll x,n;cin>>x>>n;
    vector<ll> p(n);
    rep(i,n)cin>>p[i];
    ll tmp=INF;
    ll ans=0;
    for(int i=-1;i<=101;i++){
        if(find(all(p),i)==p.end()){
       if(tmp>abs(x-i))ans=i;
        tmp=min(tmp,abs(x-i));
    }
    }
    cout << ans << endl;
}

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

const int maxn=200007;
int n;
vector<pair<int,int> > e[maxn];
int ans[maxn],ret;

void dfs(int u,int p,int col){
    int j=1;
    for (auto c:e[u]){
        if (c.first==p) continue;
        if (j==col) j++;
        ans[c.second]=j;
        dfs(c.first,u,j);
        j++;
    }
}

int main(){
    scanf("%d",&n);
    for (int i=1;i<n;++i){
        int u,v;
        scanf("%d%d",&u,&v);
        e[u].push_back({v,i});
        e[v].push_back({u,i});
    }
    for (int i=1;i<=n;++i){
        ret=max(ret,(int)e[i].size());
    }
    dfs(1,-1,-1);
    printf("%d\n",ret);
    for (int i=1;i<n;++i){
        printf("%d\n",ans[i]);
    }
    return 0;
}

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

#define MAXN 1000001	
ll spf[MAXN]; 


int main(){
		

	ll n;
	cin>>n;
	ll ar[n];
	
	for(int i=0;i<n;i++){
	 	cin>>ar[i];
	}
	
	ll ans = 0;
	for(int i=0;i<n;i++){
		ans+=(ar[i]-1);
	}	
	
	cout<<ans;

	
	
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vll a(n);
    int tmp=inf;int m;ll ans=0;
    rep(i,n){
        cin>>a[i];
        if(abs(a[i])<tmp){
            tmp=abs(a[i]);
            m=i;
        }
        ans+=abs(a[i]);
    }
    rep(i,m){
        if(a[i]<0){
            a[i]*=-1;
            a[i+1]*=-1;
        }
    }
    for(int i=n-1;i>m;i--){
        if(a[i]<0){
            a[i]*=-1;
            a[i-1]*=-1;
        }
    }
    if(a[m]<0)ans+=2*a[m];
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define sz(a) int((a).size()) 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ld(a) while(a--)
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define tcf(v,i) for(auto i : v)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define repd(i,start,lim) for(long long (i)=(start);i>=(lim);i--)
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator
#define MOD 		1000000007
#define INF 		0x3f3f3f3f
#define LLINF       1000111000111000111LL
#define pi 			3.14159265358979323
#define endl '\n'
#ifdef WIN32
#define getchar_unlocked getchar
#endif
#define gc getchar
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define N 1000006
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long int ll;
typedef vector<long long int> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<ii,vii,greater<ii> > spq;
template<typename T> T sqr(T x){return x*x;}
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename T>void read(T &x) { register T c = gc(); x = 0; int t = 0; if (c == '-') t = 1, c = gc(); for (; (c < 48 || c>57); c = gc()); for (; c > 47 && c < 58; c = gc()) { x = (x << 1) + (x << 3) + c - 48; }if (t) x = -x; }
template<typename T> T pow(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y%2==1) ans=(ans*x)%m;y/=2;x=(x*x)%m;}return ans%m;} //using this instead of inbuilt pow due to precision issues in that
template<typename T> ll roundp(T x){ll ans=x;if(x-floor(x)<=0.001) ans=floor(x);else if(ceil(x)-x<=0.001) ans=ceil(x);return ans;}
int main(){
	ll n,a,b; cin>>n>>a>>b;
	vll v(n); rep(i,0,n) cin>>v[i];
	ll ans=0;
	rep(i,0,n-1){
		ans+=min((v[i+1]-v[i])*a,b);
	}
	cout<<ans<<endl;
}

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

using namespace std;

int main(){
    int N,a;
    int t;
    int count=1;
    int M =0;
    int ball_num=0;
    int A[200001],B[200001];
    vector<int> C;
    //vector<int> B;


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

    for (int i=N/2;i<N;i++){
        B[i]=A[i];
    }
    for (int i=(N/2);i>0;i--){
        while(1){
            ball_num += B[i*count-1];
            count++;
            if(i*count > N){
                break;
            }
            
        }
        if(ball_num%2!=A[i-1]){
            B[i-1]=1;
        }
        count=1;
        ball_num = 0;
    }
    for (int i=0;i<N;i++){
        if(B[i]==1){
            M++;
            C.push_back(i+1);
        }
    }
    cout << M << endl;
    if(C.size()!=0){
        for (int i=0;i<C.size();i++){
            cout << C[i] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3064
/*
I believe on myself and I will achieve
this->author = Fuad Ashraful Mehmet, CSE-UAP
Todo:
https://www.codechef.com/COOK119?itm_campaign=contest_listing
*/
#include<bits/stdc++.h>
#define forn(i,n) for(int i=0;i<(int)n;++i)
#define all(o) (o).begin(),(o).end()
#define dbg(o)  cerr<<"at "<<__LINE__<<" response = "<<o<<endl;
#define pb push_back
using namespace std;

const int N=3005;
typedef long long ll;
//int n,m,d,k,cs=1;

ll grid[N][N];
ll dp[4][N][N];
int r,c,k;
ll fun(int i,int j,int taken)
{
      if(i==r and j==c)
      {
            if(taken<3)return grid[i][j];
            return 0;
      }

      ll &ret=dp[taken][i][j];

      if(-1!=ret)
      {
         //   cout<<"memo"<<endl;
            return ret;
      }

      ll r1=0,r2=0,r3=0;
      if(j<c)
      {
            r1=fun(i,j+1,taken);
            if(taken<3 and grid[i][j]>0)
            r2=grid[i][j]+fun(i,j+1,taken+1);
      }

      if(i<r)
      {
            if(taken<3)
            r3=grid[i][j]+fun(i+1,j,0);
            else r3=fun(i+1,j,0);
      }

      return ret=max({r1,r2,r3});

}//end
void HalfDead()
{

       
      cin>>r>>c>>k;

      int x,y;
      ll val;
      forn(i,k)
      {
            cin>>x>>y>>val;
            grid[x][y]=val;
      }

     memset(dp,-1,sizeof dp);
     ll res=fun(1,1,0);
     cout<<res<<endl;
}
int main()
{
      ios_base::sync_with_stdio(0); cin.tie(nullptr);
      int tc=1;
     // cin>>tc;
      while(tc--)
      {
            HalfDead();
      }
      return 0;
}

Measured memory_bytes: 356876
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int main()
{
    fast;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);

    int ans = 0;

    for (ll i = 2; i*i <= g; i ++) {
        if (g % i == 0) {
            ans++;
            while (g % i == 0)
                g /= i;
        }
    }
   
    if(g>1)ans++;

    cout << ++ans;

    return 0;
}


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

#define MIN(X, Y) (X < Y ? X : Y)
#define INF (100000000)
using namespace std;


int dp[100005];

int main()
{
    int n;
    int ans = 0;

    cin >> n;

    int nine[10] = {9};
    int six[10] = {6};
    int coin[30];

    int i, j, k;

    k = 0;
    i = 0;
    while (nine[i] <= 100000) {
        nine[i + 1] = nine[i] * 9;
        coin[k] = nine[i];
        i++;
        k++;
    }

    j = 0;
    while (six[j] <= 100000) {
        six[j + 1] = six[j] * 6;
        coin[k] = six[j];
        j++;
        k++;
    }
    coin[k] = 1;
    k++;


    for (int i = 0; i <= n; i++) {
        dp[i] = INF;
    }
    dp[0] = 0;
    for (int ii = 0; ii < k; ii++) {
        for (int jj = 0; jj + coin[ii] <= n; jj++) {
            dp[jj + coin[ii]] = MIN(dp[jj + coin[ii]], dp[jj] + 1);
        }
    }
    
    
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)

//変数
ll N;
map<char,ll> name;

//解法
void solve() {

	ll ans =0;
	ans += name['M'] * name['A'] * name['R'];
	ans += name['M'] * name['A'] * name['C'];
	ans += name['M'] * name['A'] * name['H'];
	ans += name['M'] * name['R'] * name['C'];
	ans += name['M'] * name['R'] * name['H'];
	ans += name['M'] * name['C'] * name['H'];
	ans += name['A'] * name['R'] * name['C'];
	ans += name['A'] * name['R'] * name['H'];
	ans += name['A'] * name['C'] * name['H'];
	ans += name['R'] * name['C'] * name['H'];

	cout << ans;

	return;
}

int main() {
	//入力
	cin >> N;
	rep(i, N) {
		string input;
		cin >> input;
		name[input[0]]++;
	}
	solve();
	cout << endl;
	return 0;
}


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

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;
using namespace std;
typedef pair<int, int> ii;
typedef priority_queue<int, vector<int>, greater<int> > heapq;
// #define int long long int

class UnionFindWithSize {
    public:
        UnionFindWithSize(int N) : parent(N, -1) {}
        void unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return;
            if (parent[x] > parent[y]) swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
        }
        int find(int x) {
            if (parent[x] < 0) return x;
            return parent[x] = find(parent[x]);
        }
        int size(int x) {
            return -parent[find(x)];
        }
    private:
        vector<int> parent;
};

signed main() {
    int N, M; cin >> N >> M;

    UnionFindWithSize ufws(N);
    for (int i = 0; i < M; i++) {
        int X, Y, Z; cin >> X >> Y >> Z;
        ufws.unite(X - 1, Y - 1);
    }
    map<int, int> m;
    for (int i = 0; i < N; i++) {
        m[ufws.find(i)]++;
    }
    cout << m.size() << endl;
    return 0;
}


Measured memory_bytes: 5376
/**********
Author: WLBKR5
Problem: ABC176 C
Date: 2020/08/22
**********/
#include<bits/stdc++.h>
using namespace std;
inline int getint(){
    int ans=0,f=1;
    char c=getchar();
    while(c>'9'||c<'0'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        ans=ans*10+c-'0';
        c=getchar();
    }
    return ans*f;
}
#define ll long long
int main(){
    int n=getint();
    long long ans=0;
    ll lst=0;
    while(n--){
        ll t=getint();
        if(t<lst)ans+=lst-t;
        lst=max(t,lst);
    }
    cout<<ans;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
#define MOD 1000000007ll // prime
// How to devide :
// ModInt a(6ll);
// ModInt b(2ll);
// a *= b.exp(MOD-2ll);  -> a/=b;  result: a = 3
struct ModInt{
	ll val;
	ModInt():val(0ll){}
	ModInt(ll v):val(((v%MOD)+MOD)%MOD){}
	ModInt exp(ll y)const{
		if(!y)return ModInt(1ll);
		ModInt a = exp(y/2ll);
		a *= a;
		if(y&1)a*=(*this);
		return a;
	}
	bool operator==(const ModInt& x)const{return val==x.val;}
	inline bool operator!=(const ModInt& x)const{return !(*this==x);}
	bool operator<(const ModInt& x)const{return val<x.val;}
	bool operator>(const ModInt& x)const{return val>x.val;}
	inline bool operator>=(const ModInt& x)const{return !(*this<x);}
	inline bool operator<=(const ModInt& x)const{return !(*this>x);}
	ModInt& operator+=(const ModInt& x){if((val+=x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator-=(const ModInt& x){if((val+=MOD-x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator*=(const ModInt& x){(val*=x.val)%=MOD;return *this;}
	ModInt operator+(const ModInt& x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt& x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt& x)const{return ModInt(*this)*=x;}
};
istream& operator>>(istream&i,ModInt&x){i>>x.val;return i;}
ostream& operator<<(ostream&o,const ModInt&x){o<<x.val;return o;}
ModInt pow(ModInt a,ll x){
	ModInt res = ModInt(1ll);
	while(x){
		if(x&1)res *= a;
		x >>= 1;
		a = a*a;
	}
	return res;
}
const int SIZE = 100100;
ModInt inv[SIZE+10],fac[SIZE+10],facinv[SIZE+10];
// notice: 0C0 = 1 
ModInt nCr(int n,int r){
	assert(!(n<r));
	assert(!(n<0||r<0));
	return fac[n]*facinv[r]*facinv[n-r];
}
void init(){
	fac[0]=ModInt(1ll);
	for(int i=1;i<=SIZE;i++)fac[i]=fac[i-1]*ModInt(i);
	inv[1]=ModInt(1ll);
	for(int i=2;i<=SIZE;i++)inv[i]=ModInt(0ll)-ModInt(MOD/i)*inv[MOD%i];
	facinv[0]=ModInt(1ll);
	for(int i=1;i<=SIZE;i++)facinv[i]=facinv[i-1]*inv[i];
	return;
}
string s;
int N;
int cnt[30];
int main(){
	init();
	cin >> N;
	cin >> s;
	for(int i=0;i<s.size();i++){
		cnt[s[i]-'a']++;
	}
	ModInt ans = ModInt(1ll);
	for(int i=0;i<30;i++){
		ans *= ModInt(cnt[i]+1);
	}
	ans-=ModInt(1ll);
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2816
/* 
 * Project: AtCoder Beginners Contest 152 B - Comparing Strings
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/07/13
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <stdio.h>
#include <algorithm>
#include <numeric>
using namespace std;

int a;
int b;

void solve() {

    if (a < b) {
        for (int i=0;i<b;i++) {
            printf("%d", a);
        }
    } else {
        for (int i=0;i<a;i++) {
            printf("%d", b);
        }
    }
    printf("\n");
}

int main() {

    scanf("%d", &a);
    scanf("%d", &b);

    solve();

}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;

const int MX = 1e5 + 10;
vector<int> adj[MX];
int ans[MX];
lli mod;

struct node{
	node *left, *right;
	short int height;
	int size;
	int value, prod;

	node(int value = 1): left(NULL), right(NULL), value(value), prod(value), height(1), size(1){}

	inline short int balance(){
		return (right ? right->height : 0) - (left ? left->height : 0);
	}

	node *maxLeftChild(){
		node *ret = this;
		while(ret->left) ret = ret->left;
		return ret;
	}
};

struct Tree{
	node *root;

	Tree(): root(NULL){}

	inline int nodeSize(node *& pos){return pos ? pos->size: 0;}
	inline int nodeHeight(node *& pos){return pos ? pos->height: 0;}
	inline int nodeProd(node *& pos){return pos ? pos->prod : 1;}

	inline void update(node *& pos){
		if(!pos) return;
		pos->height = 1 + max(nodeHeight(pos->left), nodeHeight(pos->right));
		pos->size = 1 + nodeSize(pos->left) + nodeSize(pos->right);
		pos->prod = (lli)pos->value * nodeProd(pos->left) % mod * nodeProd(pos->right) % mod;
	}

	void leftRotate(node *& x){
		node *y = x->right, *t = y->left;
		y->left = x, x->right = t;
		update(x), update(y);
		x = y;
	}

	void rightRotate(node *& y){
		node *x = y->left, *t = x->right;
		x->right = y, y->left = t;
		update(y), update(x);
		y = x;
	}

	void updateBalance(node *& pos){
		if(!pos) return;
		short int bal = pos->balance();
		if(bal > 1){
			if(pos->right->balance() < 0) rightRotate(pos->right);
			leftRotate(pos);
		}else if(bal < -1){
			if(pos->left->balance() > 0) leftRotate(pos->left);
			rightRotate(pos);
		}
	}

	void insert(node *&pos, int value){
		if(pos){
			value < pos->value ? insert(pos->left, value) : insert(pos->right, value);
			update(pos), updateBalance(pos);
		}else{
			pos = new node(value);
		}
	}

	void erase(node *&pos, int value){
		if(!pos) return;
		if(value < pos->value) erase(pos->left, value);
		else if(value > pos->value) erase(pos->right, value);
		else{
			if(!pos->left) pos = pos->right;
			else if(!pos->right) pos = pos->left;
			else{
				pos->value = pos->right->maxLeftChild()->value;
				erase(pos->right, pos->value);
			}
		}
		update(pos), updateBalance(pos);
	}

	void multiply(int value){insert(root, value);}
	void divide(int value){erase(root, value);}
	int get(){return nodeProd(root);}
};

Tree mem[MX];

inline int g(int x){
	return (1 + x) % mod;
}

Tree dfs(int u, int p){
	for(int v: adj[u]){
		if(v == p) continue;
		mem[u].multiply(g(dfs(v, u).get()));
	}
	return mem[u];
}

void dfs2(int u, int p){
	ans[u] = mem[u].get();
	for(int v : adj[u]){
		if(v == p) continue;
		int old_u = mem[u].get(), old_v = mem[v].get();
		int div_u = g(old_v);
		mem[u].divide(div_u);
		int mult_v = g(mem[u].get());
		mem[v].multiply(mult_v);
		dfs2(v, u);
		mem[v].divide(mult_v);
		mem[u].multiply(div_u);
	}
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n >> mod;
	for(int i = 1; i <= n-1; ++i){
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1, 0);
	dfs2(1, 0);
	for(int v = 1; v <= n; ++v){
		cout << ans[v] << "\n";
	}
	return 0;
}

Measured memory_bytes: 33024
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
    int n,m,ans = 0;
    string s,t;
    map<string,int> st;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s;
        st[s]++;
    }
    cin >> m;
    for(int i = 0; i < m; i++){
        cin >> t;
        st[t]--;
    }

    for(auto i = st.begin(); i != st.end(); i++) ans = max(ans,i->second); 

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// 未解決

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

//**********

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

  string s;
  cin >> s;
  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }

  return 0;
};


Measured memory_bytes: 3612
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

vector<int> V[110000];
int color[110000];

//二部グラフならtrueを返す
bool dfs(int x,int c){
  color[x]=c;
  for(int i=0;i<(int)V[x].size();i++){
    //隣接している頂点が同じ色ならfalse
    if(color[V[x][i]]==c) return false;
    //隣接している頂点がまだ塗られていないなら-cで塗る
    if(color[V[x][i]]==0 && !dfs(V[x][i],-c)) return false;
  }
  return true;
}

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

  for(int i=0;i<M;i++){
    cin>>a>>b;
    V[a].push_back(b);
    V[b].push_back(a);
  }

  if(dfs(1,1)){
    ll countA=0,countB=0;
    for(int i=1;i<=N;i++){
      if(color[i]==1) countA++;
      else countB++;
    }
    cout<<countA*countB-M<<endl;
  }else{
    cout<<N*(N-1)/2-M<<endl;
  }
}


Measured memory_bytes: 6912
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD 1000000007
#define INF 2000000000
#define PI 3.14159265359
#define ull unsigned long long

int main(){
    double a = 0.0,b = 0.0,h = 0.0,m = 0.0,ans=0.0,tmp=0.0,pi=0.0;
    scanf("%lf%lf%lf%lf",&a,&b,&h,&m);
    pi=(((11*m-60*h))/360)*PI;
    if (pi<0) pi*=-1;
    ans=sqrt(a*a+b*b-2*a*b*cos(pi));
    printf("%.10lf",ans);
    return 0;
}



Measured memory_bytes: 2480
import sys
from collections import deque
input = sys.stdin.readline
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n-1+m)]
tree_go = [[] for i in range(n+1)]
tree_come = [[] for i in range(n+1)]
excess = [0 for i in range(n+1)]
for a,b in ab:
  tree_go[a].append(b)
  tree_come[b].append(a)
for i in range(1,n+1):
  if tree_come[i] == []:
    root = i
  if len(tree_come[i]) >= 2:
    excess[i] = len(tree_come[i])-1
que = deque([(root,0)])
parent = [0 for i in range(n+1)]
visited = [0 for i in range(n+1)]
while que:
  x,px = que.popleft()
  parent[x] = px
  if excess[x] >= 1:
    excess[x] -= 1
    continue
  for y in tree_go[x]:
    que.append((y,x))
print(*parent[1:],sep="\n")


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    for(auto x : a){
        if(x % 2 == 0){
            if(x % 3 != 0 && x % 5 != 0){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
inline int read()
{
    int s=0,f=1; char ch=getchar();
    while(!isdigit(ch) && ch!='-')ch=getchar();
    if(ch=='-')ch=getchar(),f=-1;
    while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
    return ~f?s:-s;
}

const int maxn=1e6+20;

struct node {
    int ch[26];
    int s[26];
};
node t[maxn];
int ttot;
int rt=1;

int n;

char str[maxn];
int lastf[maxn],TO[maxn];

inline void init()
{
    n=read();
    ttot=1;
    REP(i,1,n)
    {
	scanf("%s",str+1);
	int u=1;
	int len=strlen(str+1);
	reverse(str+1,str+len+1);
	static int pt[maxn],P[26]; pt[0]=1;
	REP(j,1,len)
	{
	    int to=str[j]-'a';
	    if(!t[u].ch[to])t[u].ch[to]=++ttot;
	    u=t[u].ch[to]; pt[j]=u;
	}
	memset(P,0,sizeof(int)*26);
	lastf[i]=pt[len-1];
	DREP(j,len,0)
	{
	    REP(sz,0,25)t[pt[j]].s[sz]+=P[sz];
	    if(j)P[str[j]-'a']=1;
	}
	TO[i]=str[len]-'a';
    }
    ll ans=0;
    REP(i,1,n)ans+=t[lastf[i]].s[TO[i]]-1;
    printf("%lld\n",ans);
}

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


Measured memory_bytes: 209060
dp=[[""] * 100 for i in range(100)]

while(1):
    try:
        h,w = (int(x) for x in input().split())
        if w == 0:
            break
        s = ""
        x = y = 0
        ans = "LOOP"
        for i in range(0,h):
            s += input()
        for i in range(0,h):
            for j in range(0,w):
                dp[i][j] = s[i * w + j]

        while(1):
            c = dp[y][x]
            dp[y][x] = 'd'
            if(c == '>'):
                x += 1
            if(c == 'v'):
                y += 1
            if(c == '^'):
                y -= 1
            if(c == '<'):
                x -= 1
            if(c == 'd'):
                break;
            if(c == '.'):
                ans = str(x)+ ' ' + str(y)
                break
        print(ans)
    except EOFError:
        break


Measured memory_bytes: 5704
#include<bits/stdc++.h>
/******************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >;
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/******************************************/
using namespace std;
int n,a,b;
vector<int> v[100000];
int step[2][100000];
void dfs(int fx,int d,int c){
	step[c][d]=step[c][fx]+1;
	for(int i=0;i<v[d].size();i++)
	if(v[d][i]!=fx)
	dfs(d,v[d][i],c);
}
int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>a>>b;
		a--,b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	step[0][0]=-1;
	step[1][n-1]=-1;
	dfs(0,0,0);
	dfs(n-1,n-1,1);
	int black=0,white=0;
	for(int i=0;i<n;i++){
		if(step[0][i]<=step[1][i])
		black++;
		else
		white++;
	}
	if(black>white)
	cout<<"Fennec";
	else
	cout<<"Snuke";
	re 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 666
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
char a[N][N],b[N][N],c[N][N];
int main()
{	int n,m; cin>>n>>m;
	for(rint i=1;i<=n;i++) scanf("%s",a[i]+1);
	memcpy(b,a,sizeof(b)); memcpy(c,a,sizeof(c));
	for(rint i=2;i<n;i++)
	for(rint j=1;j<=m;j++) if(j&1) b[i][j]='#';
	for(rint i=1;i<=m;i++) b[1][i]='#';
	for(rint i=2;i<n;i++)
	for(rint j=1;j<=m;j++) if(!(j&1)) c[i][j]='#';
	for(rint i=1;i<=m;i++) c[n][i]='#';
	for(rint i=1;i<=n;i++) printf("%s\n",b[i]+1); cout<<endl;
	for(rint i=1;i<=n;i++) printf("%s\n",c[i]+1);
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <cstdlib>
#include <cstdio>

#define STACK_SIZE 101

using namespace std;

class stack
{
private:
  int data[STACK_SIZE];
  int top=0;
  
public:
  void push(int value);
  int pop();
  bool isFull();
  bool isEmpty();
  void init();
  void print();
};

void stack::push(int value){
  if(isFull()){
    cout << "Full" << endl;
  }
  else{
    top++;
    data[top] = value;
  }
}

int stack::pop(){
  if(isEmpty()){
    cout << "Empty" << endl;
    return 0;
  }
  else{
    top--;
    return data[top+1];
  }
}

bool stack::isFull(){
  return (top >= STACK_SIZE-1);
}

bool stack::isEmpty(){
  return (top == 0);
}

void stack::init(){
  for(int i = 0; i < STACK_SIZE; i++){
    data[i] = 0;
  }
  top = 0;
}

void stack::print(){
  for(int i = 0; i <= top; i++){
    cout << data[i] << " ";
  }
  cout << endl;
}

int main(){
  stack s;
  char str[100];

  while(scanf("%s", str) != EOF){
    if(str[0] == '+'){
      s.push(s.pop() + s.pop());
    }
    else if(str[0] == '-'){
      int a = s.pop();
      int b = s.pop();
      s.push(-a + b);
    }
    else if(str[0] == '*'){
      s.push(s.pop() * s.pop());
    }
    else{
      s.push(atoi(str));
    }
  }

  cout << s.pop() << endl;
  
  return 0;
}



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

void fnInput(vector<int>& rvnHeight)
{
  int nHeightSiz;
  cin >> nHeightSiz;
  rvnHeight.resize(nHeightSiz);

  for (int& rnHeight : rvnHeight)
    cin >> rnHeight;
}

int fnMinWorkCnt(vector<int>& rvnHeight)
{
  int nWorkCnt = 0;
  int nPrevWorkCnt = -1;

  while (nPrevWorkCnt != nWorkCnt)
  {
    nPrevWorkCnt = nWorkCnt;
    int nBgn = 0;
  
    while (nBgn < rvnHeight.size() )
    {
      int nFoward = nBgn;

      while (nFoward < rvnHeight.size() &&
             rvnHeight[nFoward]            )
      {
        rvnHeight[nFoward]--;
        nFoward++;
      }

      if (nBgn != nFoward) nWorkCnt++;
      nBgn = nFoward + 1;
    }
  }
  return nWorkCnt;
}
 
int main()
{
  vector<int> vnHeight;

  fnInput(vnHeight);
  cout << fnMinWorkCnt(vnHeight) << endl;

  return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int n;

int main() {
  cin >> n;
  switch (n) {
    case 0:
      cout << 1 << endl;
      return 0;
    case 1:
      cout << 2 << endl;
      return 0;
    case 2:
      cout << 1 << endl;
      return 0;
    default:
      cout << 0 << endl;
      return 0;
  }
}



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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = 0; i < k; i++) {
        if (i % 2 == 0) {
            a /= 2;
            b += a;
        } else {
            b /= 2;
            a += b;
        }
    }
    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<utility>
#include<bitset>
#include<complex>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=a; i<=b; ++i)
#define FOR(i,a,b) for(int i=a; i<b; ++i)
#define MP make_pair
#define PB push_back
#define fi first
#define se second
typedef long long LL;
typedef pair<int,int> pii;

int main() {
    int n, x = 0, y = 0, t = 0;
    scanf("%d", &n);
    for(int i = 1, xx, yy, tt; i <= n; ++i) {
        scanf("%d%d%d", &tt, &xx, &yy);
        int d = abs(x-xx) + abs(y-yy);
        if(d > tt - t) { puts("No"); exit(0); }
        if((tt-t - d) % 2) { puts("No"); exit(0); }
        x = xx, y = yy, t = tt;
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
N,K=list(map(int, input().split()))

ans = N
if N%K==0 :
  print(0)
else:
  N = N%K
  while True:
      N = abs(N-K)
      if N < ans:
          ans=N
      elif N == ans or ans== 0:
          break
  print(ans)

Measured memory_bytes: 3060
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
#b = [int(i) for i in readline().split()]

wt = [0]*(n+2)
for i in a:
    wt[i] += 1

MOD = 998244353

ans = 1
cnt = 1

#print(wt)

for i,c in enumerate(wt):
    if i == 0:
        if c != 1:
            ans = 0
            break
        else: pass
    else:
        cnt += c
#        print(cnt,c)
        if cnt != n:
            if c == 0:
                ans = 0
                break
            else:
                ans *= pow(wt[i-1],c,MOD)
        else:
            ans *= pow(wt[i-1],c,MOD)
            break
    ans %= MOD    
#    print(i,c,ans,cnt)    


if a[0] != 0: ans = 0


print(ans%MOD)

        






Measured memory_bytes: 53532
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
  int n; cin >> n;
  
  int cnt = 0, p1, p2, p3; cin >> p1; cin >> p2;
  for (int i = 2; i < n; i++) {
    cin >> p3;
    if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
      cnt++;
    }
    p1 = p2; p2 = p3;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> a(N);
  rep(i, N) { cin >> a[i]; }

  int result = numeric_limits<int>::max();
  rep(i, N) {
    int cost = K - (K + a[(i + 1) % N] - a[i]) % K;
    result = min(result, cost);
  }
  cout << result << endl;

  return 0;
}

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

int main() {
	int n;
	cin>>n;
	int arr[n],dp[n];
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	    dp[i]=0;
	}
	dp[1] = abs(arr[0]-arr[1]);
	for(int i=2;i<n;i++){
	    dp[i] = min(dp[i-2] + abs(arr[i-2]-arr[i]) , dp[i-1] + abs(arr[i-1]-arr[i]));
	}
	
	cout<<dp[n-1]<<endl;
  return 0;
	
	
	
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        sc.close();
        long gcd = gcd(A, B);
        int count = 1;
        for (int i = 2; i <= Math.sqrt(gcd); i++) {
            if (gcd % i == 0) {
                count++;
            }
            while (gcd % i == 0) {
                gcd /= i;
            }
        }
        if(gcd >1) count++;
        System.out.println(count);
    }
  
  	private static long gcd(long i, long j) {
        if (j == 0)
            return i;
        else
            return gcd(j, i % j);
    }
}

Measured memory_bytes: 21844
#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()
using ll = long long;

int main(){
    int n;cin>>n;
    vector<int>v(n),V(n);
    int sum=0;
    rep(i,n){
        cin>>v[i];
        sum+=v[i];
        V[i]=sum;
    }
    vector<int>t(n-1);
    rep(i,n-1){
        t[i]=abs(sum-2*V[i]);
    }
    sort(all(t));
    cout<<t[0]<<endl;
}

Measured memory_bytes: 256
n,q = map(int,input().split())
NO = (n-1).bit_length()
INF = pow(2,31)-1
A = [INF]*(2<<(NO))

def update(i,x):
    v = pow(2,NO)+i
    A[v] = x
    while v>0:
        v//=2
        A[v] = min(A[v<<1],A[(v<<1)+1])

def find(i,j):
    s = INF
    l = i+pow(2,NO)
    r = j+pow(2,NO)
    while l<r:
        if l & 1:
            s = min(s,A[l])
            l+=1
        if r & 1:
            r-=1
            s = min(s,A[r])
        l//=2
        r//=2
    return s

for i in range(q):
    com,x,y = map(int,input().split())
    if com==0:
        update(x,y)
    else:
        print(find(x,y+1))


Measured memory_bytes: 8692
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,k,s;
  cin >> n >> k >> s;
  if(k==0){
    for(int i=0;i<n;i++){
      if(i!=0) cout << " ";

      if(s<1000000000) cout << s+1;
      else cout << s-1;
    }
    cout << endl;
  }
  else{
    for(int i=1;i<=n;i++){
      if(i!=1) cout << " ";

      if(i<=k) cout << s;
      else{
        if(s<1000000000) cout << s+1;
        else cout << s-1;
      }
    }
    cout << endl;
  }
  return 0;
}

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

#define INF 2e9
#define LINF 1e18
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << "=" << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")

int main(){

    int n;
    cin >> n;
    int mi = INF;
    int maval = -INF;

    rep(i, n){
        int r;
        cin >> r;
        maval = max(r-mi, maval);
        mi = min(r, mi);
    }

    cout << maval << endl;

}


Measured memory_bytes: 3092
#include <iostream>
using namespace std;
typedef unsigned long long LL;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	int i;
	LL A;
	LL F=0;
	for (i=0;i<N;i++){
		cin>>A;
		A--;
		F+=A;
	}
	cout<<F<<endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()

	if strings.Index(s, "RRR") != -1 {
		fmt.Println(3)
		return
	}
	if strings.Index(s, "RR") != -1 {
		fmt.Println(2)
		return
	}
	if strings.Index(s, "R") != -1 {
		fmt.Println(1)
		return
	}
	fmt.Println(0)
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
#define ll long long int 
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pair<pll,pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min(ll a,ll b,ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}
                                                 /*Code Begins*/


int main(){
    _cin;
    cout << setprecision(15);
    ll mn = MAX, mx = MIN;
    ll n, t, m, k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, diff, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
    cin >> n;
    vector<double> p(n+1);
    fo(i,n) cin >> p[i+1];
    double dp[n+1][n+1];
    fo(i,n+1) fo(j,n+1) dp[i][j]=0;
    double prod=1;
    fo(i,n+1) {
        dp[0][i]=0;
        dp[i][0]=prod;
        prod*=(1-p[i+1]);
    }
    // fo(i,n+1){
    //     fo(j,n+1) cout << dp[i][j] << ' ';
    //     cout << endl;
    // }
    repa(i,1,n+1){
        repa(j,1,i+1){
            dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
        }
    }
    // fo(i,n+1){
    //     fo(j,n+1) cout << dp[i][j] << ' ';
    //     cout << endl;
    // }
    prod=0;
    repa(i,(n+1)/2,n+1) prod += dp[n][i];
    
    cout << prod;
}
 return 0;      
}

Measured memory_bytes: 70656
package main

import (
	"fmt"
)

func main() {
  result := "YES"
  m := make(map[int]int)
  for i := 0; i < 3; i++ {
    var a, b int
    fmt.Scan(&a, &b)
    m[a]++
    m[b]++
    if m[a] > 2 || m[b] > 2{
      result = "NO"
      break
    }
  }
  fmt.Println(result)
}

Measured memory_bytes: 512