akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  string S;
  cin >> S;

  const ll half = S.length() / 2;
  string head;
  for (ll i = 0; i < half; i++) {
    head += S[i];
  }
  string tail;
  for (ll i = S.length() - 1; i >= half; i--) {
    tail += S[i];
  }
  ll count = 0;
  for (ll i = 0; i < half; i++) {
    if (head[i] != tail[i]) count++;
  }
  cout << count << endl;
  return 0;
}


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

using namespace std;

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

  int N, K;
  cin >> N >> K;
  vector<int> v(N);
  for (int i = 0; i < N; ++i) cin >> v[i];
  partial_sort(v.begin(), v.begin() + K, v.end(), greater<int>());

  const auto sum = accumulate(v.begin(), v.begin() + K, 0);
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
A,B=gets.split.map &:to_i
X,Y=[A-1,B].map{|x|
    l=[]
    i=0
    while 2**i<=x
        t=(x-2**i)/(2*2**i)*(2**i)
        l << (t+[x+1-2**i-2*t,2**i].min)%2
        i+=1
    end
    l.reverse.join("").to_i(2)
}
p X^Y

Measured memory_bytes: 1788
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

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

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  i64 n;
  i64 d;
  std::cin>>n>>d;

  i64 cnt=0;

  rep(i,0,n){
    i64 x,y;
    std::cin>>x>>y;

    if(x*x+y*y<=d*d)cnt++;
  }

  std::cout<<cnt<<"\n";
  
  return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
string s;
int ans=2e9;
int main()
{
	cin >> s;
	int sum = 0;
	for(int i = 0; i < s.size(); i+=2){
		if(s[i]!='0') sum++;
		if(i+1 < s.size() && s[i+1]!='1') sum++;
	}
	ans = min(sum,ans);
	sum = 0;
	for(int i = 0; i < s.size(); i+=2){
		if(s[i]!='1') sum++;
		if(i+1 < s.size() && s[i+1]!='0') sum++;
	}
	ans = min(sum,ans);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   int N, M;
   cin >> N >> M;
   bool ks[M][N];
   int p[M];
   memset(ks, false, sizeof(ks));
   for (int i = 0; i < M; i++) {
      int k, tmp;
      cin >> k;
      for (int j = 0; j < k; j++) {
         cin >> tmp;
         ks[i][tmp - 1] = true;
      }
   }
   for (int i = 0; i < M; i++) cin >> p[i];
   int ans = 0;
   int D = N;
   // cout << (1 << D) << endl; // 1をDだけ左にシフト = D番目のフラグが立っている
   for (int mask = 0; mask < (1 << D); ++mask) {
      bool allok = false;
      for (int m = 0; m < M; m++) {
         int sum = 0;
         for (int i = 0; i < D; ++i) {
            // cout << mask << "の" << i << "桁目: " << ((mask >> i) & 1) << endl;
            bool on = ((mask >> i) & 1);
            if (on && ks[m][i]) sum++;
         }
         if (sum % 2 == p[m]) allok = true;
         else {
            allok = false; 
            break;
         }
      }
      if (allok) ans++;
   }
   cout << ans << endl;
   return 0;
}


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

int main(){
  int n; cin >> n;
  bool ok = false;
  int t = 0;
  for(int i = 0; i <= n ; i++){
    t = t * 10 + 7;
    t %= n;
    if(t == 0){
      ok = true;
      cout << i + 1 << endl;
      break;
    }
  }
  if(!ok) cout << -1 << endl;  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
vector< int > adj[100005];
bool vis[100005];
int cc=0;
void dfs(int v)
{
  vis[v]=1;
  for(auto u:adj[v])
  {
    if(!vis[u])
      dfs(u);
  }
}
int main()
{
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
    int x,y;
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for(int i=1;i<=n;i++)
  {
    if(!vis[i])
    {
      cc++;
      dfs(i);
    }
  }
  cout<<cc-1;
  return 0;
}


Measured memory_bytes: 9584
N, K, S = map(int,input().split())


if S<1000000000:
    L1=[S for i in range(K)]
    L2=[(S+1) for i in range(N-K)]
    L=L1+L2
    print(' '.join(map(str, L)))

else:
    L1=[S for i in range(K)]
    L2=[1 for i in range(N-K)]
    L=L1+L2
    print(' '.join(map(str, L)))

Measured memory_bytes: 67088
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int c[] = new int[4];
        for(int i = 0;i < 3 * 2;++i)++c[sc.nextInt() - 1];
        int tc = 0;
        for (int i = 0;i < 4;++i){
            if(c[i] == 1 || c[i] == 3)++tc;
        }
        if(tc == 0 || tc == 2) System.out.println("YES");
        else System.out.println("NO");
    }

}




Measured memory_bytes: 23124
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N , K ;
    string s ;
    
    cin >> N >> K;
    cin >> s;
    
    ll ans = 0;
    
    rep(i, s.size()){
        if(i == 0) continue;
        if(s[i] == s[i-1]) ans ++;
    }
    
    ans += 2 * K;
    if(ans > N-1) ans = N - 1;
    cout << ans << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import math
N,D= map(int, input().split())

c = 0

grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
    
for j in range(N-1):
  for l in range(j,N-1):
      d=0
      for k in range(D):
          d += (grid[j][k] - grid[l+1][k]) ** 2
      d = math.sqrt(d)
      if d.is_integer() == True:
  	    c += 1

print(c)

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

# 期待値
E = [(p+1)/2 for p in P]
#print(E)

# 累積和
S = [0] * (N+1)
for i in range(N):
    S[i+1] = S[i] + E[i]
#print(S)

# 隣接K個を取り出して足す
max_E = 0
for i in range(N-K+1):
    tmp_E = S[i+K] - S[i]
    #print(tmp_E)
    if tmp_E > max_E:
        max_E = tmp_E

print(max_E)

Measured memory_bytes: 25060
// https://atcoder.jp/contests/abc175/tasks/abc175_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#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)

// 現在の位置、残りの移動回数
// const int SZ = 5001;
// int score[SZ][SZ];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> P(N), C(N);
    REP(i, N) {
        cin >> P[i];
        P[i]--;
    }
    REP(i, N) { cin >> C[i]; }
    int maxv = -1e12;
    REP(i, N) {
        int now = i, sum = 0, cnt = 0;
        bool flag = false;
        REP(j, K) {
            int next = P[now];
            sum += C[next];
            // score[i][j] = sum;
            now = next;
            maxv = max(maxv, sum);
            cnt++;
            if (now == i) {
                flag = true;
                break;
            }
        }
        // 終端に対して1周戻った場所に最大値がある
        if (flag) {
            // (K / cnt) - 2周する
            int nloop = K / cnt - 2;
            nloop = max(0LL, nloop);
            sum += sum * nloop;
            cnt += cnt * nloop;
            maxv = max(maxv, sum);
            while (cnt < K) {
                int next = P[now];
                sum += C[next];
                // score[i][j] = sum;
                now = next;
                maxv = max(maxv, sum);
                cnt++;
            }
        }
    }
    cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 3680
MOD = 10 ** 9 + 7
fac = [1] * (10 ** 5 + 10)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD


def comb(n, k):
    return fac[n] * pow(fac[n - k], MOD - 2, MOD) * pow(fac[k], MOD - 2, MOD) % MOD


n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(k - 1, n):
    ans += comb(i, k - 1) * a[i]
for i in range(n - k + 1):
    ans -= comb(n - i - 1, k - 1) * a[i]
print(ans % MOD)


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

int main() {
    char x[1001];
    int i, sum=0;
    while(scanf("%s\n", x)) {
        sum = 0;
        if (x[0] == '0') break;
        for(i=0; x[i] != 0; i++)
            sum += x[i] - '0';
        cout << sum << endl;
    }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int j=0;
    bool b=true;
    string s,ans="AKIHABARA";
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(ans[j]==s[i])j++;
        else if((j==0||j==4||j==6)&&ans[j+1]==s[i])j+=2;
        else b=false;
    }
    if(b&&(j==8||j==9))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <complex>
#include <iomanip>
#include <queue>
#include <bitset>
//定数
#define MOD 1000000007
//マクロ
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

#define vsort(v) sort((v).begin(), (v).end());

typedef unsigned long long int ull;
typedef long long lint;

using namespace std;




int main(){
    int N, K;

    //入力
    cin >> N >> K;
    int count;
    if(N%2 == 0) {
        count = N/2;
    } else {
        count = N/2+1;
    }

    if(count >= K) cout << "YES" << endl;
    else          cout << "NO"  << endl;

    return 0;
}

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

int main()
{
	int a, b; cin >> a >> b;

	int ans = 0;

	if (a < b) {
		ans += b;
		b--;
	}
	else {
		ans += a;
		a--;
	}

	if (a < b) {
		ans += b;
		b--;
	}
	else {
		ans += a;
		a--;
	}

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1e6;
constexpr int NIL = -1;
int n;
vi G[MAX];
vi color(MAX, NIL);
inline void dfs(int r, int c) {
	deque<int> S;
	S.eb(r);
	color[r] = c;
	int u, v;
	while(!S.empty()) {
		u = S.back(); S.pop_back();
		rep(i, 0, len(G[u])) {
			v = G[u][i];
			if(color[v] == NIL) {
				color[v] = c;
				S.eb(v);
			}
		}
	}
}
inline void assignColor() {
	int id = 0;
	rep(u, 0, n) {
		if(color[u] == NIL) dfs(u, ++id);
	}
}
int main() {
	int m;
	cin >> n >> m;
	int s, t;
	rep(i, 0, m) {
		cin >> s >> t;
		G[s].eb(t);
		G[t].eb(s);
	}
	assignColor();
	int q; cin >> q;
	rep(i, 0, q) {
		cin >> s >> t;
		P(color[s] == color[t] ? "yes" : "no");
	}
	return 0;
}

Measured memory_bytes: 33044
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




//UnionFind Template
struct UnionFind{ //構造体の定義
    vector<int> d; //メンバ変数
    UnionFind(int n=0): d(n,-1) {} //コンストラクタ（構造体が呼ばれたときにすぐに実行される処理）
    int find(int x){
        if(d[x]<0) return x;
        return d[x]=find(d[x]);
    }
    bool unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return false;
        if(d[x]<d[y]) swap(x,y);//d[x] is smaller. Then, connect d[x] to d[y].
        d[y]+=d[x];
        d[x]=y;
        return true;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return -(d[find(x)]);   
    }
    int rootsize(){
        int cnt=0;
        for(auto& v: d){
            if(v<0) cnt++;
        }
        return cnt;
    }
};
//How to use
//UnionFind uf(n); などと書けば使えるようになる.ufというobjectが生成される
//uf.unite(a,b);などで中の関数を使える



int main(){
    int n,m; cin>>n>>m;
    vector<int> p(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    vector<int> x(m), y(m);
    rep(i,m) cin>>x[i]>>y[i];
    UnionFind uf(n);
    rep(i,m){
        x[i]--; y[i]--;
        uf.unite(x[i],y[i]);
    }
    int ans=0;
    rep(i,n){
        if(p[i]==i || uf.same(p[i],i)) ans++;
    }
    cout<<ans<<endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> number(N);
  for (int i = 0; i < N;i++) cin >> number.at(i);
  
  vector<int> even(N);
  for (int i = 0; i < N;i++) {
    if (number.at(i)%2 == 0) even.at(i) = number.at(i);
    else even.at(i) = 0;
  }
  
  bool answer = true;
  for (int i = 0; i < N;i++) {
    if ((even.at(i)%3 != 0)&&(even.at(i)%5 != 0)) answer = false;
  }
  
  if (answer) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}

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

#define mod 1000000007
using ll=long long;

ll modpow(ll n,ll m=mod-2){
  ll r=1;
  while(m){
    r=r*((m%2)?n:1)%mod,n=n*n%mod,m>>=1;
  }
  return r;
}

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

	ll ans = modpow(10,n)+modpow(8,n)-modpow(9,n)-modpow(9,n);
	ans%=mod;
	if(ans<0) ans=(ans+mod)%mod;
	cout << ans << endl;
}



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

using namespace std;

typedef long long  ll;

pair<int, int> Solve(string s) {
    const int n = s.size();

    if (n == 1)
        return make_pair<int, int>(-1, -1);

    for (char c = 'a'; c <= 'z'; ++c) {
        int bf = -1;
        for (int i = 0; i < n; ++i) {
            if (s[i] == c) {
                if (bf != -1 && i - bf <= 2)
                    return make_pair<int, int>(bf + 1, i + 1);
                bf = i;
            }
        }
    }

    return make_pair<int, int>(-1, -1);
}

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

    string s;

    cin >> s;
    pair<int, int> ans = Solve(s);
    cout << ans.first << ' ' << ans.second << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		int answer = -1;

		for (int i = 0; i <= 1000; i++) {
			int aExp = i * 8 / 100;
			int bExp = i * 10 / 100;

			if (a == aExp && b == bExp) {
				answer = i;
				break;
			}
		}

		print(answer);
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

}


Measured memory_bytes: 25812
package main

import "fmt"

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

	res := false
	for i := 1; i <= 9; i++ {
		if n%i == 0 && n/i <= 9 {
			res = true
			break
		}
	}
	if res {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main()
{
  int a, b;
  cin >> a >> b;

  int N;
  cin >> N;

  int s[100], f[100];
  for(int i=0; i<N; i++){
    cin >> s[i] >> f[i];
  }

  int dup = 0;
  for(int i=0; i<N; i++){
    if(b<=s[i] || a>=f[i]){
      dup++;
    }
  }
  
  if(dup==N){
    cout << 0 << endl;
  }
  else{
    cout << 1 << endl;
  }

  return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
ll a[200005];

int main(){
   ll n,k;
   cin>>n;
   for(ll i=1;i<=n;i++)cin>>a[i];
   vector<ll> tmp;
   for(ll i=1;i<=n;i++) if(a[i]!=a[i-1])tmp.pb(a[i]);
   ll j=1;
   for(ll i=1;i<=n;i++)a[i]=0;
   for(ll i=0;i<tmp.size();i++) a[j++]=tmp[i];
   
   ll s=0;
   ll ns=1000;
   ll ans=1000;
   a[0]=205;
   for(ll i=1;i<=n;i++){
   	   if(a[i]>a[i-1] && a[i]>a[i+1]){
   	   	   ll sell=s*a[i];
   	   	   ns=ns+sell;
   	   	   ans=max(ans,ns);
   	   	   s=0;
   	   	   
	   }
	   
	   if(a[i]<a[i-1] && a[i]<a[i+1]){
	   	  ll buy=ns/a[i];
	   	  ns=ns-buy*a[i];
	   	  s+=buy;
	  
	   }
   }
   cout<<ans;
}
	
 
    

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

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    int cnt = 0;
    while(n) {
        cnt++;
        n /= k;
    }
    printf("%d\n", cnt);
    return 0;
}


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

int main(){
  int n; cin>>n;
  vector<int> p(n);
  
  for (int i=0; i<n; i++) cin>>p[i];
  
  int cnt=0;
  for (int j=1; j<n-1; j++){
    if ((p[j-1]<=p[j] && p[j]<=p[j+1]) or (p[j+1]<=p[j] && p[j]<=p[j-1])){
      cnt+=1;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
using namespace std;
inline ll read(){
    ll x = 0; char zf = 1; char ch = getchar();
    while (ch != '-' && !isdigit(ch)) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int i,j,k,m,n,x,y,z,cnt;
char c[5];
int main(){
	scanf("%s",c+1);
	for(rt i=1;i<=3;i++)putchar('1'+'9'-c[i]);
	return 0;
}


Measured memory_bytes: 256
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.21 02:11:21
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n;cin >> n;
    vector<ll> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    n++;
    int l;cin >> l;
    x.push_back(x[x.size()-1] + l);
    vector<int> next(n);
    for (int i = 0; i < n; i++) {
        auto t = upper_bound(x.begin(), x.end(), x[i] + l);
        t--;
        next[i] = t - x.begin();
    }
    vector<vector<int>> doubling(32,vector<int>(n));
    for (int i = 0; i < n; i++) {
        doubling[0][i] = next[i];
    }
    for (int i = 1; i < 32; i++) {
        for (int j = 0; j < n; j++) {
            doubling[i][j] = doubling[i-1][doubling[i-1][j]];
        }
    }
    
    int q;cin >> q;
    while(q--) {
        int a,b;cin >> a >> b;
        a--;b--;
        if (b < a) swap(a,b);
        int ans = 0;
        for (int i = 31; i >= 0; i--) {
            if (doubling[i][a] <= b) {
                a = doubling[i][a];
                ans += (1 << i);
            } 
        }
        if (a != b) ans++; 
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 17352
import java.util.BitSet;
import java.util.Scanner;


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

        
        int n = Integer.parseInt(line);
        
        int a[] = new int[n+1];
        
        for (int i = 1; i <= n; i++) {
        	line = sc.nextLine();
			a[i] = Integer.parseInt(line);
		}
        
        BitSet bits = new BitSet();
        
        int current = 1;	// Button 1 on
        bits.set(1);	// button 1 on
        int count = 0;

        while (true) {
        	count++;
        	int next = a[current];
        	
        	if (next == 2) {
        		System.out.println(count);
        		return;
        	}
        	
        	if (bits.get(next)) {
        		System.out.println(-1);
        		return;
        	} else {
        		bits.set(next);
        	}
        	
        	current = next;
        }
        
        
        
	}
	

	

}


Measured memory_bytes: 96660
/*
...........__________                                                                           ___  __
.............|       |                                                                           |   /
.............|       |                                                                           |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
...........__|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
#define inf 1e18
const int mod=1e9+7;
const int N=2e5+9;
int a[N],b[N];

void raushan_kumar(){

    //variables
    int d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m,n,o=0,p=0,q=0,r=0,u=0,v=0,w=0,x=0,y=0,z=0,t=0;
    double f1=0.0,f2=0.0,f3=0.0,f4=0.0,f5=0.0,f6=0.0;
    int flag=0,ans=0,res=0,cnt=0;

    string s;cin>>s;
    fo0(i,s.length()){
        if(s[i]=='7'){
            flag=1;
        }
    }
    if(flag)
        cout<<"Yes";
    else{
        cout<<"No";
    }
    
}

int32_t main()
{
    fast;int t=1;
    //cin>>t;
    while(t--){
        raushan_kumar();
    }

}


Measured memory_bytes: 3612
import collections
s = input()
K = int(input())

abc = collections.defaultdict(list)

for i in range(len(s)):
  for j in range(1,K+1):
    if i+j <= len(s):
        abc[s[i:i+j]].append(i)


abc = list(abc.items())
abc.sort(key=lambda x: x[0])

print(abc[K-1][0])


Measured memory_bytes: 7844
#include<map>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
typedef long long int ll;
using namespace std;
#define MAXN 100001
#define X first
#define Y second
#define MOD 1000000007
#define fr(a,b,c) for(ll a=b;a<c;++a)
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll t,n,i,j;
int main()
{
    fastio;
    cin>>n;
    vector <ll > v(n+1);
    fr(i,1,n+1)
        cin>>v[i];
    ll dp[MAXN]={0};
    dp[1]=0;
    dp[2]=abs(v[2]-v[1]);
    dp[3]=min(abs(v[3]-v[1]),dp[2]+abs(v[3]-v[2]));
    fr(i,4,n+1){
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i-2]-v[i]));
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	string S;
	cin >> N;
	cin >> S;

	int ans = 0;
	int num = 0;
	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'I')
			num++;
		else
			num--;
		ans = max(ans, num);
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <sstream>
#include <array>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stack>

template <typename T, typename U>
inline std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <typename T, typename U>
inline std::istream& operator>>(std::istream& os, std::pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <typename T>
inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    if (v.empty()) {
        return os;
    }
    if (v.begin() != v.end()) {
        os << v.front();
    }
    for (auto it = ++v.begin(); it != v.end(); ++it) {
        os << ' ' << *it;
    }
    return os;
}
template <typename T>
inline std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (auto& i : v) {
        is >> i;
    }
    return is;
}

void Solve(std::istream& is, std::ostream& os) {
    std::string s;
    is >> s;

    for (int i = 0; i < s.size() - 1; ++i) {
        if (s[i] == s[i + 1]) {
            os << i + 1 << ' ' << i + 2;
            return;
        }
    }
    for (int i = 0; i < s.size() - 2; ++i) {
        if (s[i] == s[i + 2]) {
            os << i + 1 << ' ' << i + 3;
            return;
        }
    }
    os << "-1 -1";
}

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    Solve(std::cin, std::cout);
    return 0;
}


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

using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int inf = 2e18;
const ld eps = 1e-9;
const int NN = 1e5 + 2;


void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0; 
      cin >> k;
      ld x = 2 * acos(-1.000) * (ld)k;
      cout << fixed << setprecision(18);
      cout << x << el;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }

      return 0;
}

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

int main() {
  ll ans=0;
  string s;
  cin >> s;
  if(s=="SUN") ans=7;
  if(s=="MON") ans=6;
  if(s=="TUE") ans=5;
  if(s=="WED") ans=4;
  if(s=="THU") ans=3;
  if(s=="FRI") ans=2;
  if(s=="SAT") ans=1;
  cout << ans <<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <map>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,val) memset(A,val,sizeof(A))
#define ITER(it,a) for(__typeof(a.begin()) it=a.begin();it!=a.end();++it)

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double Pi = acos(-1.0);
const int INF = 1000000000;

const int MOD = 1000000007;

pair<int, int> A[200200];

int D[5000][5000];
int F[10000];

int bpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b % 2 == 1) {
			res = (res * (long long)a) % MOD;
		}

		a = (a * (long long)a) % MOD;
		b /= 2;
	}
	return res;
}

int main()
{
	//freopen("in.txt", "r", stdin);

	int n;
	scanf("%d", &n);
	//n = 200000;
	int minx, miny, maxx, maxy;
	minx = INF;
	miny = INF;
	maxx = -INF;
	maxy = -INF;
	FOR(i, 0, n) {
		scanf("%d%d", &A[i].first, &A[i].second);
		//A[i] = MP(rand() % 2000 + 1, rand() % 2000 + 1);
		D[2000 - A[i].first][2000 - A[i].second]++;
		//	D[2000 + A[i].first][2000 + A[i].second]++;

		minx = min(minx, 2000 - A[i].first);
		maxx = max(maxx, 2000 + A[i].first);
		miny = min(miny, 2000 - A[i].second);
		maxy = max(maxy, 2000 + A[i].second);
	}

	FOR(i, minx, maxx + 1) {
		FOR(j, miny, maxy + 1) {
			D[i + 1][j] += D[i][j];
			if (D[i + 1][j] >= MOD) D[i + 1][j] -= MOD;

			D[i][j + 1] += D[i][j];
			if (D[i][j + 1] >= MOD) D[i][j + 1] -= MOD;
		}
	}
	
	int res = 0;
	FOR(i, 0, n) {
		res += D[2000 + A[i].first][2000 + A[i].second];
		if (res >= MOD) res -= MOD;
	}

	F[0] = 1;
	FOR(i, 1, 8001) {
		F[i] = (F[i - 1] * (long long)i) % MOD;
	}

	FOR(i, 0, n) {
		long long N = (A[i].first + A[i].second) * 2;
		long long M = A[i].first * 2;
		long long K = A[i].second * 2;

		N = F[N];
		M = F[M];
		K = F[K];

		M = bpow(M, MOD - 2);
		K = bpow(K, MOD - 2);

		res -= (((N * M) % MOD)*K) % MOD;

		if (res < 0) res += MOD;
	}

	res = (res * (long long)bpow(2, MOD - 2)) % MOD;
	

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 80000
import sys


def popcount(n):
    c = 0
    while n:
        if n & 1:
            c += 1
        n >>= 1

    return c


def f(n, c=0):
    while pc := popcount(n):
        n %= pc
        c += 1

    return c


def _resolve(n, x_bytes):
    one_i = b'1'[0]
    pc_x = x_bytes.count(b'1')

    i2_mod_pc_x_p1 = [0] * n
    i2_mod_pc_x_m1 = [0] * n
    x_mod_pc_x_p1 = 0
    x_mod_pc_x_m1 = 0

    i2 = 1
    x = 0
    mod = pc_x + 1
    for a in range(n):
        i2_mod_pc_x_p1[- 1 - a] = i2
        i2 *= 2
        i2 %= mod

        x *= 2
        x %= mod
        if (x_bytes[a] == one_i):
            x += 1
    x_mod_pc_x_p1 = x % mod

    if pc_x > 1:
        i2 = 1
        x = 0
        mod = pc_x - 1
        for a in range(n):
            i2_mod_pc_x_m1[- 1 - a] = i2
            i2 *= 2
            i2 %= mod

            x *= 2
            x %= mod
            if (x_bytes[a] == one_i):
                x += 1
        x_mod_pc_x_m1 = x % mod

    # print(pc_x)
    # print(x_mod_pc_x_p1)
    # print(x_mod_pc_x_m1)

    # print(i2_mod_pc_x_p1)
    # print(i2_mod_pc_x_m1)

    for a in range(n):
        if x_bytes[a] == one_i:
            mod = pc_x - 1
            if mod == 0:
                yield 0
                continue
            b = x_mod_pc_x_m1 - i2_mod_pc_x_m1[a]
        else:
            mod = pc_x + 1
            b = x_mod_pc_x_p1 + i2_mod_pc_x_p1[a]
        b %= mod

        yield f(b, 1)

def resolve(in_, out):
    n = int(in_.readline())
    x_bytes = in_.readline()
    for ret in _resolve(n, x_bytes):
        print(ret, file=out)


def main():
    resolve(sys.stdin.buffer, sys.stdout)


if __name__ == '__main__':
    main()


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

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    
    # 奇数は終わる
    if N%2:
        print('0')
        quit()
    
    def calc(x,ans):
        fl = 2*(5**x)
        if N >= fl:
            ans += N//fl
            return calc(x+1,ans)
        else:
            return ans
    
    print(calc(1, 0))
        
    
    
if __name__ == '__main__':
    main()
    


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

int main(){
  int n;
  cin>>n;
  int a[n];
  for (int i=0;i<n;i++){
    int t;
    cin>>t;
    a[i]=t;   
  }

  for (int j=1;j<=n;j++){
    cout<<a[n-j];
    if (j !=n) cout<<" ";
  }
  cout<<endl;
}


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

int main(){
	int n,r;
	string in,ou;
	stringstream ss;
	char a,b;

	while(1){
		cin >> n;

		if(n != 0){
			cin >> ou;

			for(int i = 0; i < n; i++){
				r = 1;
				in = ou;
				ss.str("");
				a = in.at(0);

				for(int j = 1; j < in.length(); j++){
					b = in.at(j);
					if(a == b){
						r++;
					}else{
						ss << r << a;
						r = 1;
					}

					if(j == in.length()-1){
						ss << r << b;
						r = 1;
					}

					a = b;
				}

				ou = ss.str();
			}

			cout << ou << endl;
		}else{
			break;
		}
	}
 
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using itn = int;//typpo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
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; }
intl kai(intl k){//k!を求める関数
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

//--------------入力受け取る場所,分けてた方がデバッグしやすい気がする---------------------
string s;

void input_var(){
    cin >> s;
}
//-------------------------------------------------------------------------------


signed main(){
    cout << fixed << setprecision(10);
    input_var();
    reverse(all(s));
    string d,dr,e,er;
    d = "dream";reverse(all(d));
    dr = "dreamer";reverse(all(dr));
    e = "erase";reverse(all(e));
    er = "eraser";reverse(all(er));
    intl i = 0;
    intl len = s.length();
    bool f = true;
    while(i < len){
        if((s.substr(i,5) == d)||(s.substr(i,5) == e))i += 5;
        else if(s.substr(i,6) == er)i += 6;
        else if(s.substr(i,7) == dr)i += 7;
        else {
            f = false;
            break;
        }
    }
    fp(f,"YES","NO");
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
  string s;cin>>s;
  int a = 0;
  long long ret = 0;
  for(int i = 0; s.size()-1 > i; i++){
    if(s[i] == 'B' && s[i+1] == 'C'){
      ret =(long long)ret+a;
      i++;
      continue;
    }
    if(s[i] == 'A'){
      a++;
      continue;
    }
    else{
      a=0;
    }
  }
  cout << ret << endl;
}

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

#define int long long

using namespace std;

const int N = 100005;

vector <int> g[N];
int visited[N], dp[3];
bool type = false;

void dfs (int u, int cur) {
    if (visited[u]) {
        if (visited[u] != cur) {
            type = true; //can match all because we have an edge connected between two node have the same number.
        }
        return;
    }

    visited[u] = cur; dp[cur]++;
    for (int i = 0; i<g[u].size(); i++) {
        int v = g[u][i];
        dfs(v, cur ^ 3);
    }
}

signed main(){
    int n, m;
    scanf("%lld %lld", &n, &m);
    for (int i = 0; i<m; i++) {
        int u, v;
        scanf("%lld %lld", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }

    memset(visited, 0, sizeof(visited));
    dfs(1, 1);

    if (type) printf("%lld", n * (n - 1)/2 - m); //can match all
    else printf("%lld", dp[1] * dp[2] - m); //can only match edge between two node have number differ.
    return 0;
}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
  int n, m;
  cin >> n >> m;
  vi num(n + 1, 1);
  vector<bool> red(n + 1, false);
  red[1] = true;

  rep(i, 0, m) {
    int x, y;
    cin >> x >> y;
    if(red[x]) red[y] = true;
    num[x]--;
    num[y]++;
    if(!num[x]) red[x] = false;
  }
  int ans = count(all(red), true);
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)          
{
	
	int x, y, queue;
	

	while(1 > 0)
	{
		scanf("%d %d", &x, &y);
		if (x == 0 && y == 0) break;
		
		if (x > y)
		{
			queue = x;
			x = y;
			y = queue;
		}
		printf("%d %d\n", x, y);
	}


	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = LLONG_MAX;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    vi b = a;
    sort(all(a));
    int count = 0;
    rep(i, n) if(a[i]!=b[i]) count++;
    if(count==0||count==2) puts("YES");
    else puts("NO");
    // cout << count << endl;
    return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;

class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();

    if (A + B >= 10){
    System.out.println("error");
    }
    else {
      System.out.println(A + B);
    }
  }
}


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

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

  unordered_map<string, int> freq;
  for(int i=0; i<N; i++){
  	string str;
  	cin >> str;
  	sort(str.begin(), str.end());
    if(freq.count(str)){
      freq.at(str)++;
    }
    else{
      freq[str]= 1;
    }
  }

  int64_t ans= 0;
  for(auto p:freq){
    int64_t cnt= p.second;

    ans+= cnt*(cnt-1)/2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 10660
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

int dp[100005][2];
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   string s;
   cin >> s;
   dp[0][0] = 1;
   int n = s.size();
   rep(i, 0, n) {
      /* a_i + b_i = 0 */
      if (s[i] == '0') {
         dp[i + 1][0] = dp[i][0];
         dp[i + 1][1] = dp[i][1];
      } else {
         dp[i + 1][1] = (dp[i][0] + dp[i][1]) % MOD;
      }
      /* a_i + b_i = 1 */
      if (s[i] == '0') {
         (dp[i + 1][1] += 2 * dp[i][1] % MOD) %= MOD;
      } else {
         (dp[i + 1][0] += 2 * dp[i][0] % MOD) %= MOD;
         (dp[i + 1][1] += dp[i][1] * 2 % MOD) %= MOD;
      }
   }
   int ans = (dp[n][0] + dp[n][1]) % MOD;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 1232
import java.util.*;
class Main{
  public static void main(String[] args){
Scanner sc=new Scanner(System.in);
     long n=sc.nextLong();
    long a[]=new long[(int)n+1];
    Arrays.fill(a,1);
    for(int i=2;i<=n;i++){
for(int j=i;j<=n;j+=i){    //O(logN)
a[j]++;
}
    }
    long sum=0;
    for(int i=1;i<=n;i++){
sum+=(i*a[i]);
    }
    System.out.println(sum);
  }
}
    
  


Measured memory_bytes: 116152
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	h := getNextInt(scanner)

	nodes := make([]Node, h+1)
	for i := 1; i <= h; i++ {
		nodes[i].key = getNextInt(scanner)
	}
	for i := 1; i <= h; i++ {
		fmt.Fprintf(writer, "node %d: key = %d, ", i, nodes[i].key)
		if i>>1 >= 1 {
			fmt.Fprintf(writer, "parent key = %d, ", nodes[i>>1].key)
		}
		if i<<1 <= h {
			fmt.Fprintf(writer, "left key = %d, ", nodes[i<<1].key)
		}
		if i<<1+1 <= h {
			fmt.Fprintf(writer, "right key = %d, ", nodes[i<<1+1].key)
		}
		fmt.Fprintln(writer, "")
	}
	writer.Flush()
}

// Node ...
type Node struct {
	key int
}



Measured memory_bytes: 1200
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    String w,t,n;
    int co=0;
        n = "END_OF_TEXT";
           w = s.next();
           while(true){
               t = s.next();
               if(t.equalsIgnoreCase(w))co++;
               else if(t.equals(n))break;
           }
           System.out.println(co);
    }
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
 vector<char> w(3);
  
  cin >> w.at(0) >> w.at(1) >>w.at(2);
 sort(w.begin(),w.end());
  bool a=true;
  if(w.at(0)!='a')a=false;
   if(w.at(1)!='b')a=false;
   if(w.at(2)!='c')a=false;
  if(a)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256