akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 998244353;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lint A, B, C, D;
    cin >> A >> B >> C >> D;
    vector<vector<lint>> dp(C-A+1, vector<lint>(D-B+1));
    dp[0][0] = 1;
    REP(i, C-A+1) {
        REP(j, D-B+1) {
            if(i == 0 && j == 0) continue;
            else if(j == 0) dp[i][j] = dp[i-1][j] * (B) % MOD;
            else if(i == 0) dp[i][j] = dp[i][j-1] * (A) % MOD;
            else {
                dp[i][j] = (dp[i-1][j] * (B+j) % MOD + dp[i][j-1] * (A+i) % MOD - dp[i-1][j-1] * (A+i-1) % MOD * (B+j-1) % MOD + MOD) % MOD;
            }
        }
    }
    cout << dp[C-A][D-B] << endl;
}

Measured memory_bytes: 73588
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, C;
  ll K;
  while (cin >> N >> C >> K) {
    vector<ll> T(N);
    for (int i = 0; i < N; i++) {
      cin >> T[i];
    }
    sort(T.begin(), T.end());
    int res = 1, cnt = 1;
    ll s = T[0] + K;
    for (int i = 1; i < N; i++) {
      if (T[i] > s || cnt + 1 > C) {
        ++res;
        s = T[i] + K;
        cnt = 1;
      } else {
        ++cnt;
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;

int main() {
    string st; cin >> st;
    for (int i : irange(0, (int)st.size(), 2)) {
        cout << st[i];
    }
    cout << endl;
}


Measured memory_bytes: 3740
import sys
from collections import deque

input = sys.stdin.readline


def dfs(G, v, p, counter):
    stack = deque([(v, p)])
    while stack:
        v, p = stack.pop()
        for c in G[v]:
            if c == p:
                continue
            counter[c] += counter[v]
            stack.append((c, v))


def main():
    N, Q = map(int, input().split())

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

    counter = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        p -= 1
        counter[p] += x

    dfs(G, 0, -1, counter)

    print(" ".join(map(str, counter)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 65664
/* When Talent doesn't work, Hard work beats Talent*/

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(20);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define double long double
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI=3.141592653589793;
const int L=1e18;

void solve()
{
	int n;
	cin>>n;
	int cur=7,ans=1;
	cur%=n;
	for (int i=1;i<=n;i++)
	{
		if(cur==0)
		{
			cout<< i << nl;
			return ;
		}
		cur*=10;
		cur+=7;
		cur%=n;
	}
	cout<< -1 <<nl;
	return ;
}

int32_t main()
{
	FastIO;
	Fast_D;
	solve();
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)

int main(){
  ll i,j,N,ans=0,len,cnt;
  cin>>N;
  string s;cin>>s;
  rep(i,N){
    len=cnt=0;
    rep(j,N-i){
      if(s[j]==s[i+j]){
        cnt++;
      }else{
        cnt=0;
      }
      len=max(len,cnt);
    }
    ans=max(ans,min(len,i));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
vector<int> F[100001];
int bel=0;
vector<int> belong[100001];
map<int,int> p;
bool visited[100001];
void dfs(int now,int c){
    int cn=0;
    if(!visited[now]){
        visited[now]=true;
        belong[c].push_back(now);
        p[now]=c;
        //keyは人、値は所属番号
        for(int j=0;j<F[now].size();j++){
            int child = F[now][j];
            if(!visited[child]){
                dfs(child,c);
                cn++;
            }
        }
        if(cn==0){
            bel++;
            //もう回り切った＝＞所属しているグループを変える
        }
    }
    
}
int main(){
    int n,m,k;
    cin>>n>>m;
    rep(i,m){
        int a,b,z;
        cin>>a>>b>>z;
        a--,b--;
        F[a].push_back(b);
        F[b].push_back(a);
    }
    rep(i,n){
        visited[i]=false;
    }
    rep(i,n){
        dfs(i,bel);
    }
    //cout<<bel<<endl;
    int ans=0;
    rep(i,bel){
        if(belong[i].size()!=0){
            ans++;
        }
    }
    cout<<ans<<endl;
    /*
    rep(i,bel){
        cout<<i<<"個目のグループ所属 ";
        rep(j,belong[i].size()){
            cout<<belong[i][j]<<" ";
        }
        cout<<endl;
    }
    */
    /*
    for(int i=1;i<=n;i++){
        int block=0;
        if(B[i].size()>=1){
            rep(j,B[i].size()){
                if(p[i]==p[B[i][j]]){
    
                    block++;
                }
            }
        }
        int bsize=belong[p[i]].size();
        int fsize=F[i].size();
        //cout<<bsize<<"-"<<fsize<<"-1-"<<block<<"=";
        cout<<bsize-fsize-1-block<<" ";
    }
    */
}


Measured memory_bytes: 17912
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeginnerABC
{
    class Program
    {
        static void Main(string[] args)
        {
            var str1 = Console.ReadLine().Split(' ');
            Console.Write(str1[0].Substring(0,1));
            Console.Write(str1[1].Substring(0, 1));
            Console.Write(str1[2].Substring(0, 1));


        }
    }
}


Measured memory_bytes: 2648
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll k;
ll a[200005];
ll ma[200005];

ll labs(ll v){
	if(v<0LL){
		return -v;
	}
	return v;
}

ll C(ll v){
	ll cnt=0;
	for(int i=0;i<n;i++){
		if(a[i]==0){
			if(v>=0){
				cnt+=n-i-1;
			}
		}else{
			if(v>=0){
				if(a[i]>=0){
					ll bo=v/a[i];
					int co=upper_bound(a+i+1,a+n,bo)-a;
					cnt+=co-(i+1);
				}else{
					ll bo=v/labs(a[i]);
					int co=upper_bound(ma,ma+n-i-1,bo)-ma;
					cnt+=co;
					//printf("bo %lld\n",bo);
				}
			}else{
				if(a[i]>=0){
					ll bo=labs(v)/labs(a[i]);
					int co=upper_bound(ma,ma+n-i-1,bo)-ma;
					cnt+=(n-i-1)-co;
				}else{
					ll bo=(labs(v)+labs(a[i])-1)/labs(a[i]);
					int co=lower_bound(a+i+1,a+n,bo)-a;
					cnt+=n-co;
				}
			}
		}
		//printf("%lld\n",cnt);
	}
	ll cg=(ll)n*(n-1)/2LL;
	//printf("%lld %lld %lld\n",v,cnt,cg-cnt);
	return cnt;	
}

int main(void){
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		ma[i]=-a[i];
	}
	sort(a,a+n);
	sort(ma,ma+n);
	ll mx=max(labs(a[0]),labs(a[n-1]));
	ll l=-mx*mx-1LL,r=mx*mx;
	while(l+1<r){
		ll mid=(l+r)/2;
		if(C(mid)<k){
			l=mid;
		}else{
			r=mid;
		}
	}
	printf("%lld\n",r);
	return 0;
}


Measured memory_bytes: 3328
import sys
N, M = map(int,input().split())
if N >= M:
    print(0)
    sys.exit()
X = list(map(int,input().split()))
X.sort()
D = []
D = [X[i+1] - X[i] for i in range(M-1)]
D.sort(reverse = True)
ans = 0
for i in range(N-1):
    ans -= D[i]
ans += X[-1] - X[0]
print(ans)

Measured memory_bytes: 13968
#include <bits/stdc++.h>
#include "atcoder/all"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n,q;
    cin >> n >> q;
    atcoder::fenwick_tree<ll> bit(n);
    rp(i,n){
        ll a;
        cin >> a;
        bit.add(i,a);
    }
    while(q--){
        int t;
        cin >> t;
        if(t==0){
            ll p,x;
            cin >> p >> x;
            bit.add(p,x);
        }else{
            ll l,r;
            cin >> l >> r;
            print(bit.sum(l,r));
        }
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

#define repl(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) repl(i, 0, n)
#define pb(i) push_back(i)

typedef long long ll;

int f(double x, double y) {
    int idx = 0;
    double r3 = sqrt(3);
    repl(i, -30, 30) {
        if (-r3 * (x - i + 1) < y && y < -r3 * (x - i)) idx += ((i + 30) % 2 == 0);
        if (r3 * (x - i + 1) > y && y > r3 * (x - i)) idx += ((i + 29) % 2 == 0) * 2;
        if (r3 * (i - 1) / 2 < y && y < r3 * i / 2) idx += ((i + 30) % 2 == 0) * 4;
    }
    return idx;
}

int main() {
    string s;
    int a, b;
    double d, l;
    double x, y;
    cin >> s >> d >> l;
    if (s == "CD") d = 120 - d;
    else if (s == "BC") d = 180 - d;
    else d = 60 - d;
    d = d * acos(-1) / 180;
    x = l * cos(d), y = l * sin(d);
    a = f(x, y);

    cin >> s >> d >> l;
    if (s == "CD") d = 120 - d;
    else if (s == "BC") d = 180 - d;
    else d = 60 - d;
    d = d * acos(-1) / 180;
    x = l * cos(d), y = l * sin(d);
    b = f(x, y);
    if(a + b == 7 || a == b) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3508
#include <stdio.h>
#include <string.h>

int main(){

	int i, q, a, b, k, len;
	char str[1001], st[1001], inst[33];
	char p[1001];
	char * tp;



	scanf( "%s", str );
	scanf( "%d", &q );


	for( i=0; i<q; i++ ){
		scanf( "%s %d %d", inst, &a, &b);
		len = b - a + 1;


		memset( st, '\0', sizeof(st) );
	
		if( strcmp( inst, "print") == 0 ){
			strncpy( st, &str[a], len );
			printf( "%s\n", st );
		}
		if( strcmp( inst, "reverse") == 0 ){
			strncpy( st, &str[a], len );
			for( k=0; k<len; k++ ) str[a+k] = st[len-k-1];
		} 
		if( strcmp( inst, "replace") == 0 ){
			scanf( "%s", p );
			strncpy( &str[a], p, len );
		}
	}


	return 0;

}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
const int INF = 1001001001;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define re0 return 0
#include<string.h>
int npr(int n , int r){//nPr
    r = n - r;
    int sum = 1;
    int i;
    for (i=n;i>=r+1;i--)sum*=i;
    return sum;
}
int gcd(int a, int b) {//最大公約数
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {//最小公倍数
    return a * b / gcd(a, b);
}
int digsum(int n) {//桁和
    int res = 0;
    while(n > 0) {
        //res += n%10;
        //　↑をres++;にすれば桁数
         res++;
        n /= 10;
    }
    return res;
}
bool isPrime(int x){//素数判定
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
/*bit全探索
for (int bit = 0; bit < (1<<N); ++bit) {
}
if (bit & (1 << i)) {
}
*/


int main(void){
    int x; 
    cin >> x;
    if(x>=30)cout << "Yes" <<endl;
    else cout << "No" <<endl;
    return 0;
}




Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel"
         << "\n";
  } else {
    cout << "consonant"
         << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#define F first
#define S second
using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> P2;
typedef pair<P2,string> info;

int main(){
  int n,m,H,W,num,x1,x2,y1,y2;
  string s,s2,now;
  while(cin >> n && n){
    multimap<string,info> web;
    cin >> W >> H;
    for(int j=0;j<n;j++){
      cin >> s >> num;
      if(j == 0)now = s;
      for(int i=0;i<num;i++){
	cin >> x1 >> y1 >> x2 >> y2 >> s2;
	web.insert(multimap<string,info>::value_type(s,info(P2(P(x1,y1),P(x2,y2)),s2)));
      }
    }
    cin >> m;
    string op,Back,Forward;
    string *history = new string[10005];
  
    int nx,ny,Index=0,len=0;
    int pointer = 0;
    //history[Index++] = now;
    history[pointer]=now;

    //cout << "now is " << now << endl;
    Back.clear();
    Forward.clear();
    for(int i=0;i<m;i++){
      cin >> op;
      if(op == "click"){
	cin >> nx >> ny;
	for(int i=pointer+1;i<=len;i++){
	  history[i].clear();
	}

	bool found = false;
	multimap<string,info>::iterator it = web.begin();	
	while(it != web.end() ){
	  if((*it).first == now){

	    if((*it).S.F.F.F <=nx && nx <=(*it).S.F.S.F && (*it).S.F.F.S <=ny && ny <= (*it).S.F.S.S){
	      now = (*it).S.S;
	      //history[Index++] = now; 
	      history[++pointer] = now;
	      len++;
	      break;
	    }

	  }
	  it++;
	}
	//cout << now << endl;
	//cout << "--------------" << endl;
 
      }
      else if(op == "show")cout << now << endl;
      else if(op == "back"){
	//if(Index-1 >=0 ){
	  //Index--;
	  //now = history[Index-1];
	  // cout << "back to "<< now << endl;
	if(pointer-1 >=0){
	  now = history[--pointer];
	}
      }
      else if(op == "forward"){
	//if(Index+1 <= len){
	//now = history[Index];
	//Index++;
	if(!history[pointer+1].empty()){
	//if(pointer+1 < len){
	  now = history[++pointer];
	}
      }


    }
    /*
    cout << "---------"<< endl;
    for(int i=0;i<=len;i++){
      cout << history[i] << endl;
    }
    */
    delete [] history;
  }
  return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    string s,t;
    cin >> s >> t;

    int n=s.length(), m=t.length();
    
    int ans=1e8,cnt=0;
    for(int i=0;i<=n-m;i++){
        cnt=0;
        for(int j=0;j<m;j++){
            if(s[i+j]!=t[j])cnt++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3612
if __name__ == '__main__':
    
    A, B = [int(x) for x in input().split(' ')]
    S = input()

    S = S.split('-')
    if len(S) != 2:
        print('No')
        exit()

    a = S[0]
    b = S[1]

    if len(a) == A:
        if len(b) == B:
            print('Yes')
            exit()

    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
int l[N], r[N];
int main() {
	ios::sync_with_stdio(0);
	string s;
	cin >> s;
	int n = s.size();
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (s[i - 1] == '<') l[i] = l[i - 1] + 1;
		//else l[i] = l[i - 1] - 1;
	}
	for (int i = n; i >= 1; i--) {
		if (s[i - 1] == '>') r[i - 1] = r[i] + 1;
		//else r[i - 1] = r[i] - 1;
	}
	for (int i = 0; i <= n; i++) {
//		cerr << i << " -- " << l[i] << " -- " << r[i] << endl;  
	}
	for (int i = 0; i <= n; i++) ans += max(l[i], r[i]);
	cout << ans << endl;
}

Measured memory_bytes: 4764
def main():
    INF = float('inf')
    V, E = map(int, input().split())
    
    G = [[INF for i in range(V)] for j in range(V)]
    
    for i in range(V): G[i][i] = 0
    
    for i in range(E):
        s, t = map(int, input().split())
        G[s][t] = -1
        
    for k in range(V):
        for i in range(V):
            for j in range(V):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])
            
    for i in range(V): 
        if G[i][i]: 
            print(1)
            break
    else: print(0)
 
if __name__ == '__main__':
    main()



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

int main() {
	char scores[50];
	int count;
	for(int i=0; i<50; i++){
		int m,f,r;
		cin >> m >> f >>r;
		if(m==-1 && f==-1 && r==-1){
			count=i;
			break;
		}
		if(m==-1 || f==-1) scores[i]='F';
		else if(m+f>=80) scores[i]='A';
		else if(m+f>=65) scores[i]='B';
		else if(m+f>=50 || (m+f>=30 && r>=50)) scores[i]='C';
		else if(m+f>=30) scores[i]='D';
		else scores[i]='F';
	}
	for(int i=0; i<count; i++){
		cout << scores[i] << endl;
	}
	return 0;
}


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


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 0

    for i in range(n):
        if b[i] - a[i] >= 0:
            ans += a[i]
            b[i] -= a[i]
            a[i] = 0

            if b[i] - a[i + 1] >= 0:
                ans += a[i + 1]
                b[i] -= a[i + 1]
                a[i + 1] = 0
            else:
                ans += b[i]
                a[i + 1] -= b[i]
                b[i] = 0
        else:
            ans += b[i]
            a[i] -= b[i]
            b[i] = 0

    print(ans)


if __name__ == '__main__':
    main()


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


int main(){
	int weight[11];
	weight[0] = 1;
	for(int i = 1;i<=10;i++)weight[i]=2*weight[i-1];
	while(true)
	{
	int object;
	cin >> object;
	if (cin.eof())break;
	int j = 0;
	for(int i = 0;i <=9;i++){
		if((object % 2)==1)
			{
			cout << weight[i];
			if(object == 1) break;
			else cout << " ";
			}
		object = object /2;
		}
	cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;


int main(){
    //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
    
    int n;
    string s;
    cin>>n>>s;
    
    int r = 0, g = 0, b = 0;
    ll ans = 0;
    for(int j=0;j<n;++j){
        for(int k=j+1;k<n;++k) if(s[j]!=s[k]){
            int c = 'R'^'G'^'B'^s[j]^s[k];
            if(c=='R') ans+=r; else
            if(c=='G') ans+=g; else
            if(c=='B') ans+=b; 
            int i = j - (k-j);
            if(i>=0){
                if(s[i]==c) --ans;
            }
        }
        
        if(s[j]=='R') ++r; else
        if(s[j]=='G') ++g; else
        if(s[j]=='B') ++b; 
    }
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3660
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <string>
#define SIZE 100005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

vector <int> vec[SIZE];
vector <int> tree[SIZE];
bool use[SIZE];
int go[SIZE];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--,b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	int L=0,R=0;
	use[0]=true;
	while(1)
	{
		bool up=false;
		for(int i=0;i<vec[L].size();i++)
		{
			int to=vec[L][i];
			if(!use[to])
			{
				tree[L].push_back(to);
				tree[to].push_back(L);
				L=to;
				use[L]=true;
				up=true;
				break;
			}
		}
		if(up) continue;
		for(int i=0;i<vec[R].size();i++)
		{
			int to=vec[R][i];
			if(!use[to])
			{
				tree[R].push_back(to);
				tree[to].push_back(R);
				R=L;
				L=to;
				use[L]=true;
				up=true;
				break;
			}
		}
		if(up) continue;
		break;
	}
	vector <int> cyc;
	cyc.push_back(L);
	while(L!=R)
	{
		use[L]=false;
		for(int i=0;i<tree[L].size();i++)
		{
			int to=tree[L][i];
			if(use[to])
			{
				L=to;
				cyc.push_back(to);
				break;
			}
		}
	}
	printf("%d\n",cyc.size());
	for(int i=0;i<cyc.size();i++)
	{
		if(i!=0) printf(" ");
		printf("%d",cyc[i]+1);
	}puts("");
	return 0;
}


Measured memory_bytes: 12412
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int h, w;
    cin >> h >> w;
    vector<string> v(h);
    int b = 0;
    REP(i,h) {
        cin >> v[i];
        REP(j, v[i].size()) if (v[i][j] == '#') b++;
    }
    set<pii> p;
    auto ppush = [&] (int x,int y) {p.insert(make_pair(x,y)); return;};
    ppush(0,0);
    int l = 0;
    bool goal = false;
    auto isroad = [&](int x,int y) {return v[x][y] != '#';};
    while(!p.empty()) {
        set<pii> ptmp;
        swap(p,ptmp);
        l++;
        for(auto q:ptmp) {
            //cerr << q.first << " " << q.second << endl;
            if (q.first == h-1 && q.second == w-1) {
                goal = true;
                break;
            }
            v[q.first][q.second] = '#';
            // up
            if (q.first != 0 && isroad(q.first-1,q.second)) ppush(q.first-1,q.second);
            if (q.first != h-1 && isroad(q.first+1,q.second)) ppush(q.first+1,q.second);
            if (q.second != 0 && isroad(q.first,q.second-1)) ppush(q.first,q.second-1);
            if (q.second != w-1 && isroad(q.first,q.second+1)) ppush(q.first,q.second+1);
        }
        if (goal) break;
    }
    //cerr << l << endl;
    int ans = 0;
    if (goal) ans = h*w - b - l;
    else ans = -1;

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func min3500(x int) int {
  if x < 3500 {
    return x
  } else {
    return 3500
  }
}

func main() {
  var N int
  fmt.Scan(&N)
  if N % 2 == 0 {
    fmt.Println(N / 2, N, N)
  } else if N % 3 == 0 {
    fmt.Println(N / 3, 2 * N, 2 * N)
  } else {
    w := 0
    for h := N / 4; h <= min3500(3 * N / 4); h++ {
      for n := (N * h) / (4 * h - N); n <= min3500((2 * N * h) / (4 * h - N)); n++ {
        if 4 * h * n - N * (h + n) <= 0 {
          continue
        }
        if N * h * n % (4 * h * n - N * (h + n)) != 0 {
          continue
        }
        w = N * h * n / (4 * h * n - N * (h + n))
        fmt.Println(h, n, w)
        break
      }
      if w != 0 {
        break
      }
    }
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<string> W(N);
  rep(i,N) cin >> W[i];

  bool rule1 = true;
  bool rule2 = true;

  rep(i,N) {
    auto result = count(W.begin(), W.end(), W[i]);
    if (result > 1) rule1 = false;
  }
  for (int i = 1; i < N; i++) {
    if (W[i-1].back() != W[i].front()) rule2 = false;
  }

  if (rule1 && rule2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <list>

using namespace std;

int main(){
    list<int> lst;
    int q, x, n;
    auto itr = lst.end();
    scanf("%d", &n);
    for(int i = 0; i<n; i++){
        scanf("%d", &q);
        if(q == 0){
            scanf("%d", &x);
            itr = lst.insert(itr, x);
        }else if(q == 1){
            scanf("%d", &x);
            if(x < 0){
                for(int i = 0; x < i; i--){
                    itr--;
                }
            }else{
                for(int i = 0; i < x; i++){
                    itr++;
                }
            }
        }else{
            itr = lst.erase(itr);
        }
    }
    for(auto i = lst.begin(); i != lst.end(); i++){
        printf("%d\n", *i);
    }
    return 0;
}



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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

int n, ans;

int main() {
	read(n);
	for (int i = 1; i <= n; ++i)
		if (i & 1) ++ans;
	printf("%.10lf\n", ans * 1.0 / n);
	return 0;
}

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

long long int func(long long int h)
{
    double x=(double)(h);
    double l=floor(x/2);
    long long int p=(long long int)(l);
    if(h==1)
        return 1;

    return 2*func(p)+1;
}
int main()
{
    long long int h;
    cin>>h;
    cout<<func(h)<<endl;
}


Measured memory_bytes: 256
// date: 14/06/20 17:35:26 // 
#include <bits/stdc++.h>
using namespace std;

#define iterall(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <double> vd;
typedef vector <ll> vll;
typedef vector <vector <int>> vvi;
typedef vector <vector <long long>> vvll;
typedef vector <vd> vvd;
typedef vector <long long> vll;
typedef pair <int, int> pii;
typedef pair<ll , ll> pll;
typedef vector <pair <int, int>> vpii;
typedef vector <pll> vpll;

const int INF = 1e9+5;
const double EPS = 1e-9;

int main()
{
    vi a(5);
    for(int i= 0; i < 5; i++)
    {
        cin >> a[i];
        if(a[i] == 0)
            cout << i+1 << endl;
    }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  
  for(int i=0; i<N; i++){
    cin >> d.at(i);
  }
  
  sort(d.begin(),d.end());
  int ans=1;
  for(int i=0;i<N-1;i++){
    if(d.at(i)!=d.at(i+1)){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, M, X = list(map(int, input().split()))
ca_list = [list(map(int, input().split())) for _ in range(N)]
c = [ca_list[i][0] for i in range(N)]
a = [ca_list[i][1:] for i in range(N)]
ans = sum(c)
check = False

for i in range(2**N):
    total = 0
    skills = [0] * M
    for j in range(N):
        if (i >> j) & 1:
            total += c[j]
            skills = [k + l for k, l in zip(a[j], skills)]
    if all([z >= X for z in skills]):
        ans = min(total, ans)
        check = True

if check:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9140
#include<bits/stdc++.h>
#define sag (root+root+1)
#define sol (root+root)
#define ort  ((bas+son)/2)
#define mod 1000000007

using namespace std;
typedef long long ll;




int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    int arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    sort(arr,arr+n);
    ll mn = 10000000005;
    for(int i=arr[0]; i<=arr[n-1]; i++){
        ll ans=0;
        for(int j=0; j<n; j++){
            ans+=(arr[j]-i)*(arr[j]-i);
        }
        mn = min(mn, ans);
    }
    cout << mn;
    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    S += "*";

    vec zero, one;
    ll p = 0, c;
    if(S[0] == '0') one.pb(0);
    while(p < N) {
        c = 1;
        while(S[p] == S[p+1]) {
            ++c;
            ++p;
        }
        if(S[p] == '0') zero.pb(c);
        else one.pb(c);
        ++p;
    }
    if(S[N-1] == '0') one.pb(0);

    if(SZ(zero) < K) PR(N);
    else {
        ll sum = one[0], m;
        REP(i,0,K) sum += zero[i] + one[i+1];
        m = sum;
        REP(i,0,SZ(zero)-K) {
            sum = sum - (zero[i] + one[i]) + (zero[i+K] + one[i+1+K]);
            m = MAX(m,sum);
        }
        PR(m);
    }

    return 0;
}

/*



*/

Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << (1LL * a * b) / __gcd (a, b) << '\n';
  return 0; 
}


Measured memory_bytes: 256
#include<stdio.h>
 
void mergeSort(int*, int, int);
void merge(int*, int, int, int);
int count;
 
int main(){
  int n, S[500005], i;
 
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &S[i]);
 
  mergeSort(S, 0, n);
   
  for(i = 0; i < n - 1; i++)
    printf("%d ", S[i]);
  printf("%d\n", S[n -1]);
 
  printf("%d\n", count);
 
  return 0;
}
 
void  merge(int *A, int left, int mid, int right){
  int n1= mid - left, n2 = right - mid, L[250005], R[250005], i, j = 0, k;
 
  for(i = 0; i < n1; i++)
    L[i] = A[left + i];
 
  for(i = 0; i < n2; i++)
    R[i] = A[mid + i];
   
  L[n1] = 2000000000;
  R[n2] = 2000000000;
   
  i = 0;
     
  for(k = left; k < right; k++){
    count++;
    if(L[i] <= R[j]){
      A[k] =  L[i];
      i = i + 1;
    }else{
      A[k] = R[j];
      j = j + 1;
    }
  }
}
void mergeSort(int *A, int left, int right){
  int mid;
 
  if(left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}



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

int main() {
  size_t N, K;
  std::cin >> N >> K;

  std::vector<size_t> H(N);

  for (size_t i=0; i<N; i++) {
    std::cin >> H[i];
  }

  std::sort(H.begin(), H.end());
  size_t ans = H.back() - H.front();

  for (auto i=std::next(H.begin(), K-1);
       i != H.end();
       i++) {
    ans = std::min(ans, *i - *(std::prev(i, K-1)));
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1024
import itertools

n = int(input())
ans = 0
x = [[0 for i in range(15)] for j in range(n)]
y = [[0 for i in range(15)] for j in range(n)]
a = [0 for i in range(n)]
for i in range(n):
    a[i] = int(input())
    for j in range(a[i]):
        tmpx, tmpy = map(int, input().split())
        x[i][j] = tmpx - 1
        y[i][j] = tmpy

person = [i for i in range(n)]
## i:正直と仮定する人の人数
for i in range(1,n + 1):
    ## j:i人正直と仮定したときの全ての組み合わせ
    for j in itertools.combinations(person,i):
        truth = [0 for i in range(n)]
        flag = True
        ##正直な人の処理 k:正直と仮定した人の番号
        for k in j:
            ##正直と仮定した人が他の正直者によって：嘘つきと言われていたら矛盾
            if truth[k] == -1:
                flag = False
                break
            ##k番目の人は正直とする
            truth[k] = 1
            ##正直な人の証言を信用 l:番号kのl番目の情報
            for l in range(a[k]):
                ##嘘つきの情報があれば
                if y[k][l] == 0:
                    ##すでに正直者と決まっていたら矛盾
                    if truth[x[k][l]] == 1 or x[k][l] in j:
                        flag = False
                        break
                    else:
                        truth[x[k][l]] = -1
                ##正直者の情報があれば
                else:
                    if truth[x[k][l]] == -1 or not (x[k][l] in j): 
                        flag = False
                        break
                    else:
                        truth[x[k][l]] = 1
            ##矛盾が生じたら
            if not flag: break
        """
        ##l:嘘つきと仮定した人の番号
        for k in list(set(person) - set(j)):
            ##嘘つきと仮定した人が正直と言われていたら矛盾
            if truth[k] == 1:
                flag = False
                break
            ##k番目の人は嘘つきとする
            truth[k] = -1
            ##嘘つきの証言は嘘 l:番号kのl番目の情報
            for l in range(a[k]):
                ##嘘つきの情報があれば
                if y[k][l] == 0:
                    ##すでに嘘つきと決まっていたら矛盾
                    if truth[x[k][l]] == -1 or x[k][l] in list(set(person) - set(j)):
                        flag = False
                        break
                    else:
                        truth[x[k][l]] = 1
                ##正直者の情報があれば
                else:
                    if truth[x[k][l]] == 1 or not (x[k][l] in list(set(person) - set(j))):
                        flag = False
                        break
                    else:
                        truth[x[k][l]] = -1
            ##矛盾が生じたら
            if not flag: break
        """
        if not flag:continue
        ##矛盾が一切無ければ
        ans = i
        break

print(ans)


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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = int64_t;
using ld = long double;
const ld EPS = 1e-9;
//const ll MOD = 924844033;
const ld PI = 3.141592653589793;
const int maxn = 300001;
const ll MOD = 1e9 + 7;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif


    function<void(int)> solve = [](int _) {
        string t;
        cin >> t;
        int n = t.size();

        ll ans = 0;
        for (int i = 0; i < n; ++i) {
            if (t[i] == '1' && i % 2 == 0) {
                ++ans;
            }
        }

        const int cnt_zeros = count(t.begin(), t.end(), '0');
        if (cnt_zeros == n) {
            cout << 0;
            return;
        }
        auto process_ones = [&](int start_pos, int cnt, int suff_zeros) {
            const int pref_zeros = cnt_zeros - suff_zeros;
            ans += cnt_zeros * 1ll * (cnt / 2);
            if (cnt & 1) {
                if (start_pos % 2 == 0) {
                    ans += pref_zeros / 2;
                } else {
                    ans += (pref_zeros + 1) / 2;
                }
                ans += suff_zeros;
            }

        };
        int suff_zeros = 0;
        reverse(t.begin(), t.end());
        auto it = t.begin();
        while (it != t.end()) {
            auto one_pos = find(it, t.end(), '1');
            auto zero_pos = find(one_pos, t.end(), '0');
            int cnt = zero_pos - one_pos;
            suff_zeros += one_pos - it;
            process_ones(t.size() - 1 - (one_pos - t.begin()), cnt, suff_zeros);
            it = zero_pos;
        }
        t.erase(remove(t.begin(), t.end(), '0'), t.end());
        while (!t.empty()) {
            t.pop_back();
            ans += (t.size() + 1) / 2;
        }
        cout << ans;
    };


    fast_io();
    cout.precision(9);
    cout << fixed;
    auto start = chrono::steady_clock::now();
//    int t;
//    cin >> t;
    for (int i = 1; i <= 1; ++i)solve(i);
    auto end = chrono::steady_clock::now();

    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);

}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main() {
  int N; cin >> N;
  ll L[100];
  L[0] = 2;
  L[1] = 1;
  for(int i = 2; i <= N; i++){
    L[i] = L[i-1] + L[i-2];
  } 
  cout << L[N] << endl;
	return 0;
}



Measured memory_bytes: 3608
#include<stdio.h>

//線形探索
int search(int A[], int n, int key) {
    int i = 0;
    A[n] = key;
    while ( A[i] != key ) i++;
    return i != n; //1 or 0
}

int main() {
    int i, n, A[10000+1], q, key, sum = 0;
    
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
    
    scanf("%d", &q);
    for ( i = 0; i < q; i++ ) {
        scanf("%d", &key);
        if ( search(A, n, key) ) sum++;
    }
    printf("%d\n", sum);
    
    return 0;
}



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

double calcMin(int n, int *r)
{
	static double dp[1 << 12][12] = {0};
	static double dist[12][12];
	const double MAX = 1000000;
	
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			double dx = r[i] + r[j], dy = abs(r[i] - r[j]);
			dist[i][j] = sqrt(dx * dx - dy * dy);
		}
	}
	
	for(int i = 0; i < (1 << n); ++i)
		for(int j = 0; j < n; ++j)
			dp[i][j] = MAX;
	for(int i = 0; i < n; ++i)
		dp[1 << i][i] = r[i];
	
	for(int i = 0; i < (1 << n); ++i) {
		for(int j = 0; j < n; ++j) {
			
			if(!(i & (1 << j)))
				continue;
				
			int prev = i & (~(1 << j));
			
			for(int k = 0; k < n; ++k) {
				
				if(!(prev & (1 << k)))
					continue;
				
				dp[i][j] = min(dp[i][j], dp[prev][k] + dist[k][j]);
			}
		}
	}
	
	double ans = MAX;
	
	for(int i = 0; i < n; ++i)
		ans = min(ans, dp[(1 << n) - 1][i] + r[i]);
		
	return ans;
}

int main()
{
	while(true) {
		
		int s, n = 0;
		int r[12];
		char c = 0;
		
		if(scanf("%d ", &s) == EOF)
			break;
			
		while(c != '\n')
			scanf("%d%c", &r[n++], &c);
		
		/*printf("[Debug] %d :", s);
		for(int i = 0; i < n; ++i)
			printf(" %d", r[i]);
		printf(" : %d\n", n);*/
			
		printf("%s\n", calcMin(n, r) <= s ? "OK" : "NA");
	}
	return 0;
}

Measured memory_bytes: 1112
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  multiset<int> st;
  for(int i=0;i<n;++i){
    int curr;cin>>curr;
    st.insert(-1 * curr);
  }
  while(m>0){
    m--;
    auto bg = st.begin();
    int tmp = *bg;
    st.erase(bg);
    st.insert(tmp/2);
  }
  long long result = 0;
  for(auto i:st){
    result += i;
  }
  cout<<(-1) * result<<endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int N=1000002,M=998244353;
#define For(i,x,y) for(register int i=(int)(x);i<=(int)(y);i++)
#define Rep(i,x,y) for(register int i=(int)(x);i>=(int)(y);i--)
int pw(int x,int y){int z=1;for(;y;y>>=1,x=1ll*x*x%M)if(y&1)z=1ll*z*x%M;return z;}
int n,i,a[N],num[N],ans;
signed main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]),num[a[i]]++;
	if (a[1]!=0 || num[0]>1) return puts("0"),0;
	ans=1;
	for (i=1;num[i];i++) ans=1ll*ans*pw(num[i-1],num[i])%M;
	for (;i<=n;i++)
		if (num[i]) return puts("0"),0;
	printf("%d",ans);
}

Measured memory_bytes: 4736
// https://atcoder.jp/contests/abc176/tasks/abc176_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int H, W, M;
    cin >> H >> W >> M;
    set<pair<int, int>> st;
    vector<pair<int, int>> sumh(H), sumw(W);
    REP(i, H) sumh[i].second = i;
    REP(i, W) sumw[i].second = i;

    REP(i, M) {
        int h, w;
        cin >> h >> w;
        h--, w--;
        sumh[h].first++;
        sumw[w].first++;
        st.insert({h, w});
    }
    // 降順ソート
    sort(ALLR(sumh));
    sort(ALLR(sumw));

    // X軸、Y軸方向の最大値に対して、爆弾が存在しなければ答え
    for (auto &h : sumh) {
        if (h.first < sumh[0].first) {
            break;
        }
        for (auto &w : sumw) {
            if (w.first < sumw[0].first) {
                break;
            }
            if (st.count({h.second, w.second}) == 0) {
                cout << sumh[0].first + sumw[0].first << endl;
                return;
            }
        }
    }
    // 最大値すべてに対して爆弾が存在したので、X軸の合計＋Y軸の合計-(X,Y)にある爆弾
    cout << sumh[0].first + sumw[0].first - 1 << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


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

const int nMatch[10] = {0,2,5,5,4,5,6,3,7,6};

string append(string s, string t){
    int n = s.length();
    for(int i=0; i<n; i++){
        if(s[i] <= t[0]){
            s.insert(i,t);
            break;
        }
    }

    return s;
}

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

    vector<string> dp(N+1,"");
    for(int i=0; i<M; i++){
        int ii = nMatch[A[i]];
        if(ii > N) continue;
        if(dp[ii] == "" || dp[ii] < to_string(A[i])) 
            dp[ii] = to_string(A[i]);
    }

    for(int i=1; i<=N; i++){
        if(dp[i]=="") continue;
        for(int j=0; j<M; j++){
            int nxt = i + nMatch[A[j]];
            if(nxt > N) continue;
            if(dp[nxt].length() < dp[i].length() + 1){
                dp[nxt] = append(dp[i], to_string(A[j]));
            }else if(dp[nxt].length() == dp[i].length() + 1){
                string tmp = append(dp[i], to_string(A[j]));
                if(dp[nxt] < tmp) dp[nxt] = tmp;
            }
        }
    }
    cout << dp[N] << endl;
}


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

const int N = 505;
int n;
int c[N];
int s[N];
int f[N];

int main() {
	cin >> n;
	for(int i = 0; i < n-1; i++) cin >> c[i] >> s[i] >> f[i];
	for(int i = 0; i < n; i++) {
		int curr = 0;
		for(int j = i; j < n-1; j++) {
			curr = max(((curr-1)/f[j] + 1)*f[j], s[j]) + c[j];
		}
		cout << curr << endl;
	}
	return 0;
}

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

#define ll long long
int val[150],weight[150],n,w;
ll dp[105][100010];

ll call(int i,ll cw)
{

    if(i==n)
        return 0;

    if(dp[i][cw]!=-1)
        return dp[i][cw];

    long long ans1=0,ans2=0;

    if(cw+weight[i]<=w)
        ans1+=val[i]+call(i+1,cw+weight[i]);
    else
        ans1=0;

    ans2=call(i+1,cw);

    dp[i][cw]=max(ans2,ans1);

    return dp[i][cw];
}

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

    cin>>n>>w;

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

    memset(dp,-1,sizeof dp);

    ll ans=call(0,0);

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 82304
#include<iostream>
#include<string>
#include<array>

int main() {
	int A, B; 
	std::cin >> A >> B;
	if (A * B % 2 == 1) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int n, k, h, c = 0;
  cin >> n >> k;
  REP(i, n) {
    cin >> h;
    if (h >= k) c++;
  }
  cout << c << endl;
  return 0;
}

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

int main() {
    long long int n, MARCH[5] = {0};
    cin >> n;
    string s;
    for(int i = 0; i < n; ++i) {
        cin >> s;
        if(s[0] == 'M') MARCH[0]++;
        else if(s[0] == 'A') MARCH[1]++;
        else if(s[0] == 'R') MARCH[2]++;
        else if(s[0] == 'C') MARCH[3]++;
        else if(s[0] == 'H') MARCH[4]++;
    }

    long long int ans = 0;
    for(int i = 0; i < 5; ++i) {
        for(int j = i+1; j < 5; ++j) {
            for(int k = j+1; k < 5; ++k) {
                ans += MARCH[i]*MARCH[j]*MARCH[k];
            }
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

//Square Carpets
public class Main{

	int w, h, res, L;
	int[][] a, t;
	boolean[][][] ok;
	Map<Integer, Integer> ref;

	void copy(int[][] a, int[][] b){
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)b[i][j]=a[i][j];
	}

	int get(int[][] t){
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)sb.append(t[i][j]);
		return sb.toString().hashCode();
	}


	void dfs(int i, int j, int step){
		if(res<=step)return;
		if(i==h){
			res = step; return;
		}
		if(a[i][j]==0){
			if(j==w-1)dfs(i+1, 0, step);
			else dfs(i, j+1, step);
		}
		int[][] p = new int[h][w];
		copy(t, p);
		if(t[i][j]==0){
			for(int len=L;len>0;len--){
				if(!ok[i][j][len])continue;
				for(int y=i;y<i+len;y++)for(int x=j;x<j+len;x++)t[y][x] = 1;
				int hash = get(t);
				if(ref.containsKey(hash)&&ref.get(hash)<=step){
					copy(p, t); return;
				}
				ref.put(hash, step);
				if(j==w-1)dfs(i+1, 0, step+1);
				else dfs(i, j+1, step+1);
				copy(p, t);
				break;
			}
		}
		else{
			if(j==w-1)dfs(i+1, 0, step);
			else dfs(i, j+1, step);
			for(int len=L;len>0;len--){
				if(!ok[i][j][len])continue;
				for(int y=i;y<i+len;y++)for(int x=j;x<j+len;x++)t[y][x] = 1;
				int hash = get(t);
				if(ref.containsKey(hash)&&ref.get(hash)<=step){
					copy(p, t); return;
				}
				ref.put(hash, step);
				if(j==w-1)dfs(i+1, 0, step+1);
				else dfs(i, j+1, step+1);
				copy(p, t);
				break;
			}
		}
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			w = sc.nextInt(); h = sc.nextInt();
			if((w|h)==0)break;
			L = Math.min(h, w);
			a = new int[h][w];
			ok = new boolean[h][w][L+1];
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)a[i][j]=sc.nextInt();
			for(int d=1;d<=L;d++)for(int i=0;i+d<=h;i++)for(int j=0;j+d<=w;j++){
				boolean f = true;
				for(int y=i;y<i+d;y++)for(int x=j;x<j+d;x++)if(a[y][x]==0)f = false;
				if(f)ok[i][j][d] = true;
			}
			res = w*h;
			ref = new HashMap<Integer, Integer>();
			t = new int[h][w];
			dfs(0, 0, 0);
			System.out.println(res);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main() {
  int b[50],n,i,count=0;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++) {scanf("%d",&a[i]);b[i]=a[i];}
  qsort(a, sizeof(a) / sizeof(int), sizeof(int), asc);
  
  for(i=0;i<n;i++){
    //printf("a%d b%d\n",a[i],b[i]);
  	if(a[i]==b[i])/*NOP*/;
    else count++;
  }
  if(count>2)printf("NO\n");
  else printf("YES\n");
  return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    if((S[2] == S[3]) && (S[4] == S[5])){
        cout << "Yes" << "\n";
    }
    else
    {
        cout << "No" << "\n";
    }
    return 0;
}

Measured memory_bytes: 256