akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
using namespace std;

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) {
    cin >> a[i];
  }
  map<int, int> m;
  REP(i, N) {
    if(m.find(a[i]) == m.end()) {
      m[a[i]] = 1;
    } else {
      m[a[i]]++;
    }
  }
  map<int, int>::const_iterator it;
  long long ans = 0;
  for(it = m.begin(); it != m.end(); it++) {
    if(it->second < it->first) {
      ans += it->second;
    } else {
      ans += it->second - it->first;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    int c_before[1001], c_after[1001];
    int num, day;
    char p;

    for( int i = 1; i <= 1000; i++ )
        c_before[i] = 0;
    
    string str;
    while( getline( cin, str ) )
    {
        if( str == "" )
            break;
        if( str[1] == ',' )
            c_before[str[0]-'0']++;
        else if( str[2] == ',' )
            c_before[(str[0]-'0')*10+str[1]-'0']++;
        else if( str[3] == ',' )
            c_before[(str[0]-'0')*100+(str[1]-'0')*10+str[2]-'0']++;
        else if( str[4] == ',' )
            c_before[(str[0]-'0')*1000+(str[1]-'0')*100+(str[2]-'0')*10+str[3]-'0']++;
        else;
    }

    for( int i = 1; i <= 1000; i++ )
        c_after[i] = c_before[i];

    while( cin >> num >> p >> day )
        c_after[num]++;

    for( int i = 1; i <= 1000; i++ )
    {
        if( c_before[i] != 0 && c_before[i] != c_after[i] )
            cout << i << " " << c_after[i] << endl;
    }
    return 0;
}


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

int main() {
    long long n;
    cin >> n;
    vector<long long>a(n);
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    long long d=1e9+7;
    long long ans=0;
    for(int i=0; i<60; ++i){
        long long c=0; 
        for(int j=0; j<n; ++j){
            if((a[j]>>i)&1){
                c++;
            }
        }
        ans += (c*(n-c)%d)*((1ll<<i)%d);
    }
    cout << ans%d << endl;
}


Measured memory_bytes: 2560
/*input
2
ip cc
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	string s;
	cin>>s;
	int i=0,j=SZ(s)-1;
	int ans=0;
	while(i<j){
		if(s[i]!=s[j]) ans++;
		i++,j--;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
bool cmp(pair <int,int> a,pair <int,int> b){
    return a.second>b.second;
}
int main(){
    int n,m;
    cin>>n>>m;
    int a[n];
    pair <int,int> p[m];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<m;i++){
        cin>>p[i].first>>p[i].second;
    }
    sort(p,p+m,cmp);
    int curr=0,f=0;
    long long int ans=0;
    for(int i=0;i<m;i++){
        int cnt=1;
        while(curr<n&&cnt++<=p[i].first){
            if(a[curr]>p[i].second){
                f=1;
                break;
            }
            else{
                a[curr]=p[i].second;
            }
            curr++;
        }
        if(f) break;
    }
    for(int i=0;i<n;i++) ans+=a[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
    int N,M;
  cin>>N>>M;
  int S[10],C[10];
  for(int i=0;i<M;i++){
    cin>>S[i]>>C[i];
  }
 
  for(int i=0;i<=999;i++) {
    bool flag=true;
    string num=to_string(i);
 
    if(N!=num.size()){
      flag=false;
    }
 
    for(int i=0;i<M;i++) {
      if(num[S[i]-1]-'0'!=C[i]){
        flag=false;
      }
    }
 
    if(flag) {
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

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

int hw[12][1020];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w, k; cin >> h >> w >> k;
    for (int i = 0; i < h; i++) {
        string s; cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j] == '1') hw[i+1][j+1]++;
        }
    }
    for (int i = 0; i <= h; i++) {
        for (int j = 0; j <= w; j++) {
            hw[i+1][j] += hw[i][j];
        }
    }
    for (int i = 0; i <= h; i++) {
        for (int j = 0; j <= w; j++) {
            hw[i][j+1] += hw[i][j];
        }
    }
    auto rect = [&](int p, int q, int r, int s) {
        return hw[p][q] + hw[r+1][s+1] - hw[r+1][q] - hw[p][s+1];
    };
    int ans = 1e9;
    for (int bit = 0; bit < (1 << (h-1)); bit++) {
        vector<pair<int, int>> pv;
        int prev = 0, curr = 0;
        for (int i = 0; i < h-1; i++) {
            if (bit & (1 << i)) {
                pv.emplace_back(prev, i);
                prev = i+1;
                curr++;
            }
        }
        pv.emplace_back(prev, h-1);

        int wpr = 0; bool ok = true;
        for (int wi = 0; wi < w && ok; wi++) {
            bool cok = true;
            for (auto &iter: pv) {
                cok &= (rect(iter.first, wpr, iter.second, wi) <= k);
            }
            if (!cok) {
                if (wi == wpr) ok = false;
                curr++;
                wpr = wi; wi--;
            }
        }
        if (ok) ans = min(ans, curr);
    }
    cout << ans << "\n";
    return 0;
}

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

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

	vector<int> c(n, 0);
	for (int i = 1; i < n; ++i) {
		for (int j = i; j < n; j += i) {
			++c[j];
		}
	}

	int s = 0;
	for (int ci : c) {
		s += ci;
	}

	cout << s;
	
	return 0;
}


Measured memory_bytes: 7188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    int N;
    cin >> N;
    int x=N*100/108;
    if (x*108/100/1==N) cout << x << endl;
    else if ((x+1)*108/100==N) cout << x+1 << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
//
#include <bits/stdc++.h>
using namespace std;
#define ote(x) cout<<(x)<<endl

int main(){
	char c; cin>>c;
	if(c=='a') ote("vowel");
	else if(c=='i') ote("vowel");
	else if(c=='u') ote("vowel");
	else if(c=='e') ote("vowel");
	else if(c=='o') ote("vowel");
	else ote("consonant");
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
const int MAX = 510000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }
    
    int size(int x){
        return sizeuf[root(x)];
    }
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/*-----Library-----*/

signed main(){
    int n;
    cin>>n;
    int m;
    cin>>m;
    if(1<=n&&n<=9&&1<=m&&m<=9){
        cout<<n*m<<endl;
        
    }else cout<<-1<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
     
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    
    vector<vector<int>> even_edge(n, vector<int>()), odd_edge(n, vector<int>());
    for (int i = 0; i < n - 1; i++) {
        int u, v, w; cin >> u >> v >> w; u--; v--;
        if (w % 2 == 0) {
            even_edge.at(u).push_back(v);
            even_edge.at(v).push_back(u);
        } else {
            odd_edge.at(u).push_back(v);
            odd_edge.at(v).push_back(u);
        }
    }
    
    vector<int> ans(n, -1);
    ans.at(0) = 0;
    
    stack<int> st;
    st.push(0);
    
    while (!st.empty()) {
        int i = st.top();
        int c = ans.at(i);
        st.pop();
        for (int j : even_edge.at(i)) {
            if (ans.at(j) != -1) continue;
            ans.at(j) = c;
            st.push(j);
        }
        for (int j : odd_edge.at(i)) {
            if (ans.at(j) != -1) continue;
            ans.at(j) = 1 - c;
            st.push(j);
        }
    }
    
    for (int i = 0; i < n; i++) {
        cout << ans.at(i) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 9856
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	string a, b;
	cin>>a>>b;
	stringstream ss(a+b);
	int c;
	ss>>c;
	int d = sqrt(c);
	cout<<(d*d==c?"Yes":"No")<<endl;
	return 0;
}


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

using namespace std;

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<pair<long long, int>> shops(N);
    for_each(begin(shops), end(shops), [](auto &shop) {
        cin >> shop.first >> shop.second;
    });
    sort(begin(shops), end(shops));

    long long ans = 0;
    int i = 0;
    while (M > 0) {
        if (shops[i].second < M) {
            ans += shops[i].first * shops[i].second;
            M -= shops[i].second;
        } else {
            ans += shops[i].first * M;
            M = 0;
        }
        i++;
    }
    cout << ans << endl;
}


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

int main()
{
  int n, k, q, max;
  max = 0;
  cin >> n >> k >> q;
  int t[n];
  for (int i = 0; i < n; i++) {
    t[i] = 0;
  }
  for (int i = 0; i < q; i++) {
    int m;
    cin >> m;
    t[m - 1] += 1;
  }
  for (int i = 0; i < n; i++) {
    if (k + t[i] - q> 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    double n , k;
    cin >> n >> k;
    double ans = 0;
    for(int i = 1 ;i <= n ; i++){
        int times = 0;
        int t = i;
        while(t < k){
            t *= 2;
            times++;
        }
        
        double a = 1/n;
        double b = 1/pow(2 , times);
        
        ans += a*b;
    }
    printf("%0.12lf\n" , ans);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	int x, n;
	cin >> x >> n;

	map<int, int> mp;
	for (int i = -151; i <= 151; i++) mp[i] = 0;

	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		mp[p]++;
	}
	
	int minv = INT_MAX;
	int ans = 0;
	for (int i = -151; i <= 151; i++) {
		if (!mp[i]) {
			int tmp = abs(x - i);
			if (tmp < minv) {
				minv = tmp;
				ans = i;
			}
		}
	}
	cout << ans << endl;
}


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

bool f(const long kind, const size_t n, const vector<long>& a){
    map<long,long> c;
    long len = a[0];
    for(size_t i=1; i<n; i++){
        const long n_len = a[i];
        if(len>=n_len){
            c.erase(c.lower_bound(n_len), c.end());
            long j=n_len-1;
            c[j]++;
            for(;;){
                if(c[j]<kind){
                    c.erase(c.upper_bound(j), c.end());
                    break;
                }else if(j<=0){
                    return false;
                }else{
                    //c[j]=0;
                    c[j-1]++;
                    j--;
                }
            }
        }
        len = n_len;
    }
    return true;
}

bool strict_increasing(const vector<long>& a){
    size_t n = a.size();
    for(size_t i=1; i<n; i++){
        if(a[i-1]>=a[i]){
            return false;
        }
    }
    return true;
}

int main(void){
    long n;
    cin >> n;
    vector<long> a(n);
    for(long i=0; i<n; i++){
        cin >> a[i];
    }
    if(strict_increasing(a)){
        cout << 1 << endl;
        return 0;
    }
    long left=1, right=n;
    for(;;){
        const long mid = (left+right)/2;
        if(right-left<=1){
            if(f(right, n, a)){
                cout << right << endl;
            }else{
                cout << left << endl;
            }
            return 0;
        }
        const bool b = f(mid, n, a);
        //printf("[%ld, %ld] %ld %s\n", left, right, mid, b ? "true" : "false");
        if(b){
            right=mid;
        }else{
            left=mid;
        }
    }
}


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

using namespace std;

map<int, int> m;

void dfs(vector<vector<int>> &g, vector<int> &arr, int node, int value) {
    arr[node] = value + m[node];

    for (auto &next: g[node]) {
        if (arr[next] == -1) {
            dfs(g, arr, next, value + m[node]);
        }
    }
}

int main(int argc, char *argv[]) {
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> g(N, vector<int>());
    for (int i = 0; i < N - 1; i++) {
        int from, to;
        cin >> from >> to;
        from--;
        to--;
        g[from].push_back(to);
        g[to].push_back(from);
    }

    for (int j = 0; j < Q; j++) {
        int p, x;
        cin >> p >> x;
        p--;
        m[p] += x;
    }
    
    vector<int> arr(N, -1);
    dfs(g, arr, 0, 0);

    for (auto v: arr) {
        cout << v << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 42240
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int H,W,N;

int main(){
    int N; cin>>N;
    int cnt=0,a;
    vector<bool> f(100005,true);
    for (int i = 0; i < N; ++i) {
        cin>>a;
        if(f[a]){
           f[a]=false;
           cnt++;
        }
    }
    cout<<(cnt&1?cnt:cnt-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(x,a)for(auto &x: a)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll>pii;
typedef vector<ll>vi;
typedef map<ll,ll>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
}
int main()
{
	//fopen();
	fastio;
	int n,k;
	cin>>n>>k;
	if(n+k==3)
		{cout<<3;}
	else if(n+k==4)
		{cout<<2;}
	else{cout<<1;}
	//cout<<m<<" "<<e;
	
	
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    sort(all(a));

    int ans = 0;
    rep(i, n-1){
        if(a[i] != a[i+1]){
            ans++;
        }
    }
    if(ans % 2 == 0){
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
N_shima, M_fune = map(int, input().split())

shima_1 = []
shima_N = []

for i in range(M_fune):
    a, b = map(int, input().split())

    if (a == 1):
        shima_1.append(b)
    elif (a == N_shima):
        shima_N.append(b)
    if (b == 1):
        shima_1.append(a)
    elif (b == N_shima):
        shima_N.append(a)
    
judge = set(shima_1) & set(shima_N)

if (len(judge) >= 1):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


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

int main() {
  
  ll N, M;
  cin>>N>>M;
  vector<pair<ll, ll>> AB(N);
  for(ll i = 0; i < N; i++){
    cin>>AB[i].first>>AB[i].second;
  }
  sort(AB.begin(), AB.end());
  /* 同じ意味
  sort(AB.begin(), AB.end(),[](pair<ll, ll> l, pair<ll, ll> r){
    if(l.first != r.first) return l.first < r.first;
    else return l.second < r.second;
  });
  */
  ll sum = 0;
  for(ll i = 0; i < N; i++){
    if(M > AB[i].second){
      M -= AB[i].second;
      sum += AB[i].first * AB[i].second;
    }else{
      sum += AB[i].first * M;
      break;
    }
  }
  cout<<sum<<endl;
  
}


Measured memory_bytes: 1792
/*修正*/
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
  ll n,m,q;
  cin>>n>>m>>q;
  ll a[510][510],b[510][510];
  for(ll i=0;i<m;i++){
    ll l,r;
    cin>>l>>r;
    a[r][l]++;
  }
  for(ll i=0;i<=500;i++){
    for(ll j=0;j<=500;j++){
      b[i][j+1]=a[i][j]+b[i][j];
    }
  }
  for(ll i=0;i<q;i++){
    ll c,d;
    cin>>c>>d;
    ll ans=0;
    for(ll j=c;j<=d;j++){
      ans+=b[j][d+1]-b[j][c];
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 7572
n,m = map(int, input().split(' '))
gates = []
for _ in range(m):
  gates.append(list(map(int, input().split(' '))))

L, R = gates[0]
for l,r in gates[1:]:
  if r < L or R < l:
    L, R = 0, 0
    break
  if L < l <= R:
    L = l
  if L <= r < R:
    R = r

if R == 0 and L == 0:
  print(0)
elif R - L + 1 > n:
  print(n)
else:
  print(R - L + 1)

Measured memory_bytes: 28116
import java.util.Scanner;

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

        int N = sc.nextInt();

        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int dummy;
        int count = 0;
        int minj;

        for (int i = 0; i < N; i++) {
            minj = i;

            for (int j = i; j < N; j++) {
                if(A[j] < A[minj]){
                    minj = j;
                }
            }

            
            if(i != minj){
                dummy = A[minj];
                A[minj] = A[i];
                A[i] = dummy;
    
                count++;
            }
        }        

        


        for (int i = 0; i < N; i++) {
            System.out.print(A[i]);
            if(i != N-1){
                System.out.print(" ");
            }
        }
        System.out.println("");
        System.out.println(count);

        sc.close();
    }
}



Measured memory_bytes: 26356
def factorization(n):
    arr = []
    for i in range(2, int(-(-n**0.5//1))+1):
        if n%i == 0:
            cnt=0
            while n%i == 0:
                cnt += 1
                n //= i
            arr.append([i, cnt])

    if n != 1:
        arr.append([n, 1])

    return arr
N = int(input())
ans = 0
if N != 1:
    fact_list = factorization(N)
    for _, i in fact_list:
        j = 1
        while i >= j:
            ans += 1
            i = i - j
            j += 1
            
print(ans)

Measured memory_bytes: 9412
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int p[200001]={0};
    int a,n;
    cin >>n;
    rep(i,n-1){
        cin >> a;
        p[a-1]++;
    }
    rep(i,n){
        cout << p[i]<<endl;
    }
}

Measured memory_bytes: 3940
using System;
using System.Collections.Generic;
 
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        LinkedList<int> list = new LinkedList<int>();
 
        for(int i=0; i<n; i++)
        {
            string[] input = Console.ReadLine().Split(' ');
            switch(input[0])
            {
                case "insert":
                    list.AddFirst(int.Parse(input[1]));
                    break;
 
                case "delete":
                    list.Remove(int.Parse(input[1]));
                    break;
 
                case "deleteFirst":
                    list.RemoveFirst();
                    break;
 
                case "deleteLast":
                    list.RemoveLast();
                    break;
            }
        }
 
		bool is_space = false;
        foreach (int no in list)
        {
            Console.Write((is_space ? " " : "") + no);
				is_space = true;
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 82376
import copy
h, w = map(int,input().split())

maze = [[9]*(w+2)]
for i in range(h):
  s = input()
  tmp = [9]
  for j in s:
    if j == "#":
      tmp.append(9)
    else:
      tmp.append(0)
  tmp.append(9)
  maze.append(tmp)
maze.append([9]*(w+2))
#print(maze)

def bfs(start):
  maze2 = copy.deepcopy(maze)
  #print(maze2)
  pos = [start]
  max_depth = 0
  maze2[start[0]][start[1]] = 2
  while len(pos):
    x, y, depth = pos.pop(0)
    max_depth = max(depth, max_depth)
    
    if maze2[x-1][y] < 2:
      pos.append([x-1,y,depth + 1])
      maze2[x-1][y] = 2
    if maze2[x+1][y] < 2:
      pos.append([x+1,y,depth + 1])
      maze2[x+1][y] = 2
    if maze2[x][y-1] < 2:
      pos.append([x,y-1,depth +1])
      maze2[x][y-1] = 2
    if maze2[x][y+1] < 2:
      pos.append([x,y+1,depth +1])
      maze2[x][y+1] = 2
  return max_depth

ans = 0
for i in range(h):
  for j in range(w):
      start = [i+1,j+1,0]
      maze2 = maze
      if maze[i+1][j+1] != 9:
        #print(bfs(start))
        ans = max(ans,bfs(start))
print(ans)

Measured memory_bytes: 75668
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  int a,b,c,x,y;
  scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
  int ans = 1000000000;
  rep(i,0,2 * max(x,y)+1) {
    int tmp = i / 2;
    ans = min(ans, i * c + max((x - tmp), 0) * a + max((y - tmp), 0) * b);
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 256
N = int(input())
h = [int(i) for i in input().split()] 

dp = [0] * N
dp[0] = 0

for i in range(1, N):
  if i > 1:
  	dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
  else:
    dp[i] = dp[i-1] + abs(h[i] - h[i-1])

print(dp[N-1])

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

using namespace std;

using ll = long long;

deque<int> l, r;

int nxt = 1;

void go(ll x) {
    if (x == 1) {
        return;
    } else if (x % 2 == 1) {
        go(x - 1);
        l.push_back(nxt);
        r.push_front(nxt);
        nxt++;
    } else {
        go(x / 2);
        l.push_back(nxt);
        r.push_back(nxt);
        nxt++;
    }
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ll n;
    cin >> n;

    go(n);
    l.push_back(nxt);
    r.push_front(nxt);
    nxt++;

    cout << l.size() + r.size() << "\n";
    for (int x : l) {
        cout << x << " ";
    }
    for (int x : r) {
        cout << x << " ";
    }
    cout << "\n";

}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 2937.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int h, w, a, b;
  scanf("%d%d%d%d", &h, &w, &a, &b);

  printf("%d\n", h * w - (h / a) * a * (w / b) * b);
  return 0;
}



Measured memory_bytes: 3228
# https://atcoder.jp/contests/abc142/tasks/abc142_d
# 公約数とは、最大公約数の約数

import sys
import math
from functools import reduce

input = sys.stdin.readline

A, B = [int(x) for x in input().split()]


def gcd(*numbers):
    return reduce(math.gcd, numbers)

# 素因数分解
# 考え方：1~√nまで実際に割れるか試せば良いが、割れた場合は割れる限りその数で割り続ける
# 計算量：O(√n)
def prime_factorize(n):
    i = 2
    primes = []
    while i * i <= n:
        if n % i != 0:
            i += 1
            continue
        exp = 0
        while n % i == 0:
            exp += 1
            n = n // i
        primes.append([i, exp])
        i += 1
    # 最後に残った数は1か素数にしかならない
    if n != 1:
        primes.append([n, 1])
    return primes

g = gcd(A, B)
divisors = prime_factorize(g)
print(len(divisors)+1)



Measured memory_bytes: 68216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=20;
const ll INF=1LL<<60;
int N;
ll A[MAX];

ll solve(int l,int r,ll lx,ll rx){
    if(l+2==r){
        ll res=0;
        if(l==0) res+=A[l]*lx;
        if(r==N) res+=A[r-1]*rx;
        return res;
    }
    
    ll ans=INF;
    for(int i=l+1;i<r-1;i++){
        chmin(ans,solve(l,i+1,lx,lx+rx)+solve(i,r,lx+rx,rx)+A[i]*(lx+rx));
    }
    
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    for(int i=0;i<N;i++) cin>>A[i];
    
    cout<<solve(0,N,1,1)<<endl;
}


Measured memory_bytes: 256
def main():
    import sys

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

    n = int(input())
    a = tuple(map(int, input().split()))

    ret = 0
    for j in range(60):
        cnt1 = sum((x >> j) & 1 for x in a)
        cnt0 = n - cnt1
        ret = (ret + cnt0 * cnt1 * (1 << j)) % mod

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 123132
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;

public class Main {

	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] str = br.readLine().split(" ");
		Arrays.sort(str);
		sb.append("557".equals(str[0]+str[1]+str[2]) ? "YES" : "NO");
		System.out.println(sb);
	}
}

Measured memory_bytes: 7892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector< vector<int> > Graph;
int n[2],m[2];
map<string,int> mp;
vector<int> vp;
int cnt=1;

vector<Graph> Forest_to_Trees(Graph &G){
	vector<int> num(n[0],-1);
	vector<Graph> tree;
	for(int i=0;i<n[0];i++){
		if(num[i]==-1){
			Graph gra(1);
			queue<int> q;
			q.push(i);
			int cur=0;
			num[i]=0;
			while(q.size()){
				int v=q.front();
				q.pop();
				for(int j=0;j<G[v].size();j++){
					int nv=G[v][j];
					if(num[nv]==-1){
						num[nv]=++cur;
						gra.push_back(vector<int>());
						gra[num[v]].push_back(num[nv]);
						gra[num[nv]].push_back(num[v]);
						q.push(nv);
					}
				}
			}
			tree.push_back(gra);
		}
	}
	return tree;
}


int calc2(Graph &G2,int v,int parent){
	if(G2[v].size()==0)return 1;
	if(G2[v].size()==1 && parent!=-1)return 1;
	vector<string> s;
	for(int i=0;i<(int)G2[v].size();i++){
		int nv=G2[v][i];
		if(parent==nv)continue;
		int val=calc2(G2,nv,v);
		s.push_back(to_string(val));
	}
	sort(s.begin(),s.end());
	string str="";
	for(int i=0;i<s.size();i++){
		str+=s[i];
	}
	if(!mp.count(str))mp.insert(map<string,int>::value_type(str,++cnt));
	return mp[str];
}

void dfs2(Graph &G2,int v,vector<int> &dist){
	if(dist[v]==-1)dist[v]=0;
	for(int i=0;i<G2[v].size();i++){
		if(dist[G2[v][i]]==-1){
			dist[G2[v][i]]=dist[v]+1;
			dfs2(G2,G2[v][i],dist);
		}
	}
}

vector<int> getCenter(Graph &G){
	int nn=G.size();
	vector<int> dist(nn,-1);
	vector<int> dist2(nn,-1);
	vector<int> dist3(nn,-1);
	dfs2(G,0,dist);
	int maxi=-1;
	int tgt=0;
	for(int i=0;i<nn;i++){
		if(dist[i]>maxi){
			maxi=dist[i];
			tgt=i;
		}
	}
	dfs2(G,tgt,dist2);
	maxi=-1;
	for(int i=0;i<nn;i++){
		if(dist2[i]>maxi){
			maxi=dist2[i];
			tgt=i;
		}
	}
	dfs2(G,tgt,dist3);
	vector<int> res;
	for(int i=0;i<nn;i++){
		if(maxi%2==0){
			if(dist2[i]==maxi/2 && dist3[i]==maxi/2)res.push_back(i);
		}else{
			if(dist2[i]==(maxi+1)/2 && dist3[i]==maxi/2)res.push_back(i);
			if(dist2[i]==maxi/2 && dist3[i]==(maxi+1)/2)res.push_back(i);
		}
	}
	return res;
}

int main(void){
	Graph g2;
	scanf("%d%d",&n[0],&m[0]);
	Graph G(n[0]);
	for(int i=0;i<m[0];i++){
		int f,t;
		scanf("%d%d",&f,&t);
		f--;
		t--;
		G[f].push_back(t);
		G[t].push_back(f);
	}
	vector<Graph> tree=Forest_to_Trees(G);
	scanf("%d",&n[1]);
	m[1]=n[1]-1;
	for(int i=0;i<n[1];i++){
		g2.push_back(vector<int>());
	}
	for(int i=0;i<m[1];i++){
		int f,t;
		scanf("%d%d",&f,&t);
		f--;
		t--;
		g2[f].push_back(t);
		g2[t].push_back(f);
	}
	vector<int> root[2];
	root[1]=getCenter(g2);
	mp["0"]=1;
	for(int i=0;i<root[1].size();i++){
		vp.push_back(calc2(g2,root[1][i],-1));
	}
	int res=0;
	for(int i=0;i<tree.size();i++){
		if(tree[i].size()!=n[1])continue;
		root[0].clear();
		root[0]=getCenter(tree[i]);
		bool flag=false;
		for(int j=0;j<root[0].size();j++){
			if(flag)break;
			int s1=calc2(tree[i],root[0][j],-1);
			for(int k=0;k<vp.size();k++){
				if(s1==vp[k])flag=true;
			}
		}
		if(flag)res++;
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 55668
#include <functional>
#include <cstring>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    struct edge { int src, dst, C; } edges[n-1];
    for (int i = 0; i < n-1; i++) {
        int u, v; cin >> u >> v;
        edges[i] = {u-1, v-1, 0};
    }
    int m; cin >> m;
    int C[n];
    memset(C, 0, sizeof C);
    function <bool(int, int, int, int)> dfs = [&](int i, int j, int c, int p) {
        for (edge &e : edges) {
            int k = e.src == i ? e.dst : e.dst == i ? e.src : -1;
            if (k == -1 || k == p) continue;
            if (k == j || dfs(k, j, c, i)) {
                e.C |= (1<<c);
                return true;
            }
        }
        return false;
    };
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        dfs(u-1, v-1, i, -1);
    }
    long long dp[1<<m];
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    function <void(int, int)> dfs2 = [&] (int i, int p) {
        for (edge &e : edges) {
            int k = e.src == i ? e.dst : e.dst == i ? e.src : -1;
            if (k == -1 || k == p) continue;
            for (int s = (1<<m)-1; s >= 0; s--) dp[s|e.C] += dp[s];
            dfs2(k, i);
        }
    };
    dfs2(0, -1);
    cout << dp[(1<<m)-1] << endl;
}


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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}

// end of Template

int n,m;
ll ans;
pll job[200000];
priority_queue <ll> q;
int main(){

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        int a,b;cin>>a>>b;
        job[i] = mp(a,b);
    }
    sort(job+1,job+1+n);

    int idx = 1;
    for(int i=1;i<=m;i++){
        while(idx<=n && job[idx].fi<=i){q.push(job[idx].se);idx++;}
        if(!q.empty()){
            ans+=q.top();q.pop();
        }
    }
    cout<<ans<<newl;

}


Measured memory_bytes: 2936
/*
 Sarthak Jain
*/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
	return (a<b)?a:b;
}
int max(int a,int b){
	return (a>b)?a:b;
}
int fp(int a,int b){
	if(b==0) return 1;
	int x=fp(a,b/2);
	x=(x*x)%mod;
	if(b&1) x=(x*a)%mod;
	return x;
}
int add(int &a,int b)
{
	a=(a+b+mod)%mod;
}




signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 int x,y,z;
 cin>>x>>y>>z;
 cout<<z<<" "<<x<<" "<<y;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N;
  vector<int> A;

  cin >> N ;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    A.push_back(a);
  }
  //A.sort();
  sort(A.begin(), A.end());
  for(int j=0;j<A.size()-1;j++){
    if(A[j]==A[j+1]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 1400
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
//constexpr ll MOD = 1e9+7;
constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

Vec2<ll> graph;

set<ll> st;

bool dfs(ll node, ll prev, Vec &a){
	if(node == a[0]){
		if (!st.empty()) return st.find(a[1]) == st.end();
	}

	bool res = false;
	for (ll i : graph[node]){
		if (i == prev) continue;
		if (st.find(i) != st.end()) continue;
		st.insert(i);
		res |= dfs(i, node, a);
		st.erase(i);
	}
	return res;
}

int main(void){
	ll n, m;
	cin >> n >> m;
	graph.resize(n);
	rep(i, m){
		ll a, b;
		cin >> a >> b;
		--a, --b;
		graph[a].pb(b);
		graph[b].pb(a);
	}

	bool flg = true;
	rep(i, n) flg &= !(graph[i].size() & 1);
	if(flg){
		if (m - n > 2) puts("Yes");
		else if(m - n < 2) puts("No");
		else{
			Vec a;
			rep(i, n) if (graph[i].size() > 2) a.pb(i);
			if (a.size() == 1) puts("Yes");
			else{
				if(dfs(a[0], -1, a)) puts("Yes");
				else
					puts("No");
			}
		}
	}else puts("No");

	return 0;
}


Measured memory_bytes: 11904
#include <stdio.h>

int main() {
	int ans;
	int n;
	scanf("%d", &n);
	int p[n+2];
	for (int i = 1; i <= n; i++) {
		scanf("%d", p+i);
		if (p[i] == i) p[i] = 1;
		else p[i] = 0;
	}
	p[0] = p[n+1] = 0;

	ans = 0;
	for (int i = 1; i <= n; i++) {
		if (p[i]) {
			if (p[i+1]) {
				p[i] = 0;
				p[i+1] = 0;
			} else {
				p[i] = 0;
			}
			ans++;
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
import numpy as np
import functools
import math
import scipy
import fractions
import itertools
 
def solve():
    x = input()
    a, b = 0, 0
    for i in x:
        if i == "S":
            a += 1
        else:
            if a == 0:
                b += 1
            else:
                a -= 1
    print(a + b)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 20220
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();
		long ans = a;

		if (0<a && 0<b){
			System.out.println("Positive");
		} else if(a == 0 || b == 0){
			System.out.println("Zero");
		} else if(a>0 && b<0){
			System.out.println("Zero");
		}else if(a<0 && b>0){
			System.out.println("Zero");
		}else if (a<0 && b<0){
			if ((b - a)%2 !=0) System.out.println("Positive");
			else 			System.out.println("Negative");
		} 			

		sc.close();

	}
}



Measured memory_bytes: 9940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_N = 8;
vector<int> G[MAX_N];
bool used[MAX_N];
int N, M;
int res;
void dfs(int u, int depth){
	if (depth == N - 1){
		++res;
		return;
	} // end if

	used[u] |= true;
	rep (i, (int)G[u].size()){
		int v = G[u][i];
		if (!used[v]){
			dfs(v, depth + 1);
		} // end if
	} // end rep
	used[u] = false;
}

int main()
{
	memset(used, false, sizeof(used));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	rep (i, MAX_N) G[i].clear();

	cin >> N >> M;
	rep (i, M){
		int a, b; cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	} // end rep
	res = 0;
	dfs(0, 0);
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long n,k,x,y,rem,res;
	cin>>n>>k;
	x=n/k;
	rem=n-x*k;
	y=abs(k-rem);
	res=min(rem,y);
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan=new Scanner(System.in);
	int a[][]=new int[4][2];
	a[0][0]=scan.nextInt()*8;
	a[1][0]=scan.nextInt()*4;
	a[2][0]=scan.nextInt()*2;
	a[3][0]=scan.nextInt();
	a[0][1]=1;
	a[1][1]=2;
	a[2][1]=3;
	a[3][1]=4;
	Arrays.sort(a, (c, b) -> Integer.compare(c[0], b[0]));
	double n=scan.nextInt();
	long ans=0;
	//case1→0.25ℓ 2→0.5ℓ 3→1ℓ 4→2ℓ
	switch(a[0][1]) {
	case 1:
		ans+=(long)(long)a[0][0]/8*(int)(n/0.25);
		System.out.println(ans);
		return;
	case 2:
		if(n>=0.5) {
			ans+=(long)(long)a[0][0]/4*(int)(n/0.5);
			n-=((int)n/0.5)*0.5;
		}
		break;
	case 3:
		if(n>=1) {
			ans+=(long)(long)a[0][0]/2*(int)(n/1);
			n-=((int)n/1)*1;
		}
		break;
	case 4:
		if(n>=2) {
			ans+=(long)(long)a[0][0]*(int)(n/2);
			n-=((int)n/2)*2;
		}break;
	}
	switch(a[1][1]) {
	case 1:
		ans+=(long)(long)a[1][0]/8*(int)(n/0.25);
		System.out.println(ans);
		return;
	case 2:
		if(n>=0.5) {
			ans+=(long)(long)a[1][0]/4*(int)(n/0.5);
			n-=((int)n/0.5)*0.5;
		}
		break;
	case 3:
		if(n>=1) {
			ans+=(long)a[1][0]/2*(int)(n/1);
			n-=((int)n/1)*1;
		}
		break;
	case 4:
		if(n>=2) {
			ans+=(long)a[1][0]*(int)(n/2);
			n-=((int)n/2)*2;
		}break;
	}
	switch(a[2][1]) {
	case 1:
		ans+=(long)a[2][0]/8*(int)(n/0.25);
		System.out.println(ans);
		return;
	case 2:
		if(n>=0.5) {
			ans+=(long)a[2][0]/4*(int)(n/0.5);
			n-=((int)n/0.5)*0.5;
		}
		break;
	case 3:
		if(n>=1) {
			ans+=(long)a[2][0]/2*(int)(n/1);
			n-=((int)n/1)*1;
		}
		break;
	case 4:
		if(n>=2) {
			ans+=(long)a[2][0]*(int)(n/2);
			n-=((int)n/2)*2;
		}break;
	}
	switch(a[3][1]) {
	case 1:
		ans+=(long)a[3][0]/8*(int)(n/0.25);
		System.out.println(ans);
		return;
	case 2:
		if(n>=0.5) {
			ans+=(long)a[3][0]/4*(int)(n/0.5);
			n-=((int)n/0.5)*0.5;
		}
		break;
	case 3:
		if(n>=1) {
			ans+=(long)a[3][0]/2*(int)(n/1);
			n-=((int)n/1)*1;
		}
		break;
	case 4:
		if(n>=2) {
			ans+=(long)a[3][0]*(int)(n/2);
			n-=((int)n/2)*2;
		}break;
	}
	System.out.println(n);
}
}

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

int func(int x){
  if(x%100 != 0) return 0;
  return func(x/100) + 1;
}

int main(){
  int D, N;
  cin >> D >> N;
  int cnt = 0;
  for(int i=1;;i++){
    if(func(i) == D){
      cnt++;
      if(cnt == N){
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main ()
{
	int a,b;
	scanf ("%d%d",&a,&b);
	if ((a+b)>=24)
	{
		printf ("%d\n",(a+b)-24);
	}
	else if ((a+b)<24&&(a+b>=0))
	{
		printf ("%d\n",a+b);
	}
	else;
}

Measured memory_bytes: 256