akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>                                                                                       
                                                                                                         
int main() {                                                                                             
    int n;                                                                                               
    scanf("%d",&n);                                                                                      
    double o = 0;                                                                                        
    for (int i = 0; i < n; i++) {                                                                        
        if (i%2 == 0) o++;                                                                               
    }                                                                                                    
    double ans = o/n;                                                                                    
    printf("%lf\n", ans);                                                                                
}          

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

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> deg(N, 0);
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    G[x].emplace_back(y);
    deg[y]++;
  }

  queue<int> que;
  for (int i = 0; i < N; i++) {
    if (deg[i] == 0) que.push(i);
  }

  vector<int> dp(N, 0);
  while (!que.empty()) {
    int u = que.front();
    que.pop();

    for (int v : G[u]) {
      if (--deg[v] != 0) continue;
      dp[v] = dp[u] + 1;
      que.push(v);
    }
  }

  cout << *max_element(dp.begin(), dp.end()) << "\n";
  return 0;
}


Measured memory_bytes: 6528
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define VAR(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}
// }}} End Header

int dist(char c) {
    int cnt = 0;
    while (c != 'a') {
        c = (c == 'z' ? 'a' : c + 1);
        ++cnt;
    }
    return cnt;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    string s;
    i64 K;

    dump(dist('z'));
    dump(dist('y'));
    dump(dist('a'));

    read(s, K);
    const int N = s.length();
    rep(i, 0, N-1) {
        const int d = dist(s[i]);
        if (d <= K) {
            K -= d;
            s[i] = 'a';
        }
    }

    K %= 26;
    rep(i, 0, K) {
        s.back() = (s.back() == 'z' ? 'a' : s.back() + 1);
    }
    print(s);
    return 0;
}


Measured memory_bytes: 592
#include <stdio.h>

int main(){
	int a,b;
	
	scanf("%d", &a);
	scanf("%d", &b);
	
	if(a > b)
		printf("a > b\n");
	else if(a < b)
		printf("a < b\n");
	else if(a == b)
		printf("a == b\n");
	
	return 0;
}

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

int main() {
  double A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  double con = 0, wat = 0, sug = 0;
  for (int i = 0; i * 100 * A <= F; i++) {
    for (int j = 0; i * 100 * A + j * 100 * B <= F; j++) {
      for (int k = 0; i * 100 * A + j * 100 * B + k * C <= F; k++) {
        for (int l = 0;  i * 100 * A + j * 100 * B + k * C + l * D <= F; l++) {
          if (!(k * C + l * D + i * 100 * A + j * 100 * B)) continue;
          double tmp = (k * C + l * D) / (k * C + l * D + i * 100 * A + j * 100 * B);
          if (tmp > E / (E + 100)) continue;
          if (tmp >= con) con = tmp, wat = i * 100 * A + j * 100 * B, sug = k * C + l * D;
        }
      }
    }
  }

  cout << wat + sug << " " << sug << "\n";
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a = sorted(map(int, input().split()))
if sum(a) < x:
    ans = -1
elif sum(a) == x:
    ans = N
else:
    ans = 0


if x < min(a):
    print(0)
elif x == min(a):
    print(1)
else:
    if ans == N:
        print(N)
    else:
        for i in range(N):
            if x-a[i] >= 0:
                x -= a[i]
                ans += 1
            else:
                break
        print(ans)

Measured memory_bytes: 3064
x=[]
for i,j in enumerate(map(int,input().split())):
    c=[]
    for l in range(j):
        t=int(input())
        x.append((i,l,t))
        c.append([t])
x.sort(key=lambda x:x[2])
l=[-10**20]*2
for y in x:
    if y[0] != 2: 
        l[y[0]]=y[2]
    else:
        c[y[1]]+=l[:]
l=[10**20]*2
for y in x[::-1]:
    if y[0] != 2: 
        l[y[0]]=y[2]
    else:
        c[y[1]]+=l[:]
print("\n".join(str(min(d[0]-min(d[1],d[2]),max(d[3],d[4])-d[0],
        d[4]-d[1]+min(d[0]-d[1],d[4]-d[0]),
        d[3]-d[2]+min(d[0]-d[2],d[3]-d[0])
        )) for d in c)
        )


Measured memory_bytes: 68312
N = int(input())
num_list = list(map(int, input().split()))
mod = 10**9 + 7

sum_num = 0
sum_list = []
for num in num_list:
  sum_num += num
  sum_num = sum_num % mod
  sum_list.append(sum_num)

answer = 0
for i in range(N):
  sum_num -= num_list[i]
  sum_num = sum_num if sum_num >= 0 else sum_num + mod
  answer += num_list [i] * sum_num
  answer = answer % mod

print(answer)

Measured memory_bytes: 106660
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;
string s;

int main() {
    cin >> n;

    Vi dp(n+1);
    dp[0] = 1;
    dp[1] = 1;
    REP2(i, 2, n+1) {
        dp[i] = dp[i-1] + dp[i-2];
    }
    std::cout << dp[n] << '\n';

    return 0;
}



Measured memory_bytes: 3148
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
using namespace std;

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

    vector<int> b(n);
    rep (i, n-1) cin >> b[i];

    int A = 0;
    rep (i, n) {
        if (i == 0)
            A += b[0];
        else if (i == n - 1) 
            A += b[n - 2];
        else 
            A += min(b[i - 1], b[i]);
    }

    cout << A << endl;

    return 0;
}

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

int main(){
	int n,k;
	cin >> n >> k;
	int ans=1;
	if(n%k == 0) ans = 0;
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<=a;i++)for(int j=0;j<=b;j++){
		if(i*b+j*a-i*j*2==c){printf("Yes\n");return 0;}
	}
	printf("No\n");
}

Measured memory_bytes: 128
def main():
  import numpy as np
  N = int(input())
  A = list(map(int,input().split()))

  def ternary (n):
      if n == 0:
          return '0'
      nums = []
      while n:
          n, r = divmod(n, 3)
          nums.append(str(r))
      return ''.join(reversed(nums))

  ans = 0
  AA = np.array(A)
  for i in range(3**N):
    I = ternary(i).zfill(N)
    tmp = 1
    for a in range(N):
      if I[a] == "0":
        tmp *= AA[a] - 1
      elif I[a] == "1":
        tmp *= AA[a]
      else:
        tmp *= AA[a] + 1
    if tmp % 2 == 0:
      ans += 1
  print(ans)
main()  

Measured memory_bytes: 14392
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    int a,b,c;
    cin >> a >>b;
    c =b*2-a;

    cout << c << endl; 

    return 0;
    


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
ll n;
const ll N = 100000 + 5;
ll a[N];
//ld c[N+1]; 
ll ans[N];

int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	for(int i=1;i<=n;i++){
		ans[1] += a[i]*(i%2==1? 1:-1);
	}
	for(int i=2;i<=n;i++){
		ans[i] = 2*a[i-1] - ans[i-1];
	}
	FOR(i,1,n){
		cout << ans[i] << ' ';
	}

	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

int main(){
    int n;
	cin>>n;
	vector<int> a(n);
	geti(a);
	range(i,1,n){
	    puti(a);
	    for(int j=i-1;j>=0;j--){
	        if(a[j+1]<a[j])swap(a[j+1],a[j]);
	    }
	}
	puti(a);
	return 0;
}



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

const int mod = 1e9+7;
typedef long long int ll;
class Mint{
    public:
        ll x;
        Mint(const ll a){
            x = a;
        }
        ll operator = (ll const &b){
            x = b;
            return b;
        }
        Mint operator = (Mint const &b){
            x = b.x;
            return b;
        }
        void operator += (Mint const &b){
            x = (x + b.x)%mod;
        }
        Mint operator+(const Mint &a){
            return (x + a.x)%mod;
        }
        Mint operator-(const Mint &a){
            return (x - a.x + mod)%mod;
        }
        Mint operator*(const Mint &a){
            return (x * a.x)%mod;
        }
        Mint operator/(const Mint &a){
            return (x * modInverse(a.x))%mod;
        }
        bool operator >=(const int &a){
            return x>=a;
        }
        ll gcdExtended(ll a, ll b, ll *x, ll *y) { 
            if (a == 0) { 
                *x = 0, *y = 1; 
                return b; 
            } 
            ll x1, y1;  
            ll gcd = gcdExtended(b%a, a, &x1, &y1); 
            *x = y1 - (b/a) * x1; 
            *y = x1; 
            return gcd; 
        }
        ll modInverse(ll a) { 
            ll x, y; 
            gcdExtended(a, mod, &x, &y); 
            ll res = (x%mod + mod) % mod; 
            return res; 
        } 
        Mint operator ^(ll b){
          Mint res = 1;
          long long int a = x;
          while(b>0){
            if(b&1)
              res.x = res.x * a % mod;
            a = a * a % mod;
            b = b/2;
          }
          return res;
        }
};
ostream& operator <<(ostream& os, const Mint a){
    return os << a.x;
}
int main(){
  int s;
  cin >> s;
  vector<Mint> dp(s+1,1);
  dp[0] = dp[1] = dp[2] = 0LL;
  for(int i=4; i<=s; i++){
    for(int j=3; j<i; j++){
      if(i-j>=0)
        dp[i] = dp[i] + dp[i-j];
    }
  }
  cout << dp[s];
  return 0;
}
  

Measured memory_bytes: 3588
#include<iostream>
#include<map>
using namespace std;
int main(){
	int n;
	cin >> n;
	map<int,int> m;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		m[a-1]++;
		m[a]++;
		m[a+1]++;
	}
	int ans=0;
	for(auto i=m.begin();i!=m.end();i++){
		ans=max(i->second,ans);
	}
	cout << ans << endl;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
ll l,r;
ll f[64][2][2][2][2];
int L[100],R[100];
ll dfs(int pos,int fl,int fr,int s,int ht)
{
    if(pos<0)return 1;
    ll &ans=f[pos][fl][fr][s][ht];
    if(ans)return ans;
    for(int i=0;i<2;i++)//y
    {
        for(int j=0;j<2;j++)//x
        {
            int tl=fl,tr=fr,ts=s,tt=ht;
            if(!tt&&i)if(i!=j)continue;
            if((i&j)!=j)continue;
            if(!tl&&j<L[pos])continue;
            if(!tr&&i>R[pos])continue;
            if(!ts&&j>i)continue;
            if(j>L[pos])tl=1;if(i<R[pos])tr=1;if(j<i)ts=1;if(j)tt=1;
            ans+=dfs(pos-1,tl,tr,ts,tt);
        }
    }
    ans%=mod;
    return ans;
}
int main()
{
    scanf("%lld%lld",&l,&r);
    for(int i=63;i>=0;i--)
    {
        L[i]=(int)((l>>i)&1),R[i]=(int)((r>>i)&1);
    }
    printf("%lld\n",dfs(63,0,0,0,0));
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define REP(i, n) for(int i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()

using namespace std;


class B754 {
public:
    string S;
    ll m = 10000;

    void solve(std::istream& in, std::ostream& out) {
        in >> S;
        REP(i, S.length()-2) {
            ll num = (S[i] - '0') * 100 + (S[i+1] - '0') * 10 + S[i+2] - '0';
            m = min(m, abs(753-num));
        }
        out << m << endl;
    }
};


int main() {
    B754 solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
  if s[i]=='R':
    R.append(i+1)
  elif s[i]=='G':
    G[i+1]=G.get(i+1,0)+1
  else:
    B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
  for j in B:
    if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
      res-=1
    if G.get(2*max(i,j)-min(i,j),0)==1:
      res-=1
    if G.get(2*min(i,j)-max(i,j),0)==1:
      res-=1
print(res)

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  string s; cin >> s;
  lint k; cin>> k;
  
  for(int i=0;i<k;i++) {
    if(s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
  }

  cout << '1' << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>

int count_divisor(int N) {
    int cnt = 0;
    for (int i=1; i<=N; ++i) {
        if (N % i == 0) cnt++;
    }
    return cnt;
}

int main() {
    int N;
    std::cin >> N;
    
    int ans = 0;
    if (N < 104) {
        std::cout << 0;
    } else {
        for (int i=105; i<=N; i+=2) {
            if (count_divisor(i) == 8) ans++;
        }
        std::cout << ans << std::endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

const int maxn = 1e5 + 5;
int n;
int a[maxn], in[maxn];

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (int j = 0; j < n; j++)
	{
		in[a[j]]=j+1;
	}
	for (int i = 1; i <= n; i++)
		cout << in[i] << " ";
	cout << endl;
    return 0; 
}

Measured memory_bytes: 1536
#include<stdio.h>

int min(int a, int b){return a>b?b:a;}

int N, A, B, n[3], F, ans, i;

int main(){
	scanf("%d%d%d", &N, &A, &B);
	for(i=0; i<N; i++){
		scanf("%d", &F);
		if(F>B){
			n[2]++;
		}else if(F>A){
			n[1]++;
		}else{
			n[0]++;
		}
	}
	ans = min(n[0], n[1]);
	ans = min(ans, n[2]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
h,w=map(int,input().split())
s=['.'+input()+'.' for _ in range(h)]
s=['.'*(w+2)]+s+['.'*(w+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
        cnt=0
        if s[i][j]=='#': print('#',end='')
        else:
            if s[i-1][j-1]=='#': cnt+=1
            if s[i-1][j]=='#': cnt+=1
            if s[i-1][j+1]=='#': cnt+=1
            if s[i][j-1]=='#': cnt+=1
            if s[i][j+1]=='#': cnt+=1
            if s[i+1][j-1]=='#': cnt+=1
            if s[i+1][j]=='#': cnt+=1
            if s[i+1][j+1]=='#': cnt+=1
            print(cnt,end='')
    print()

Measured memory_bytes: 3444
#include<cstdio>
#include<vector>
using namespace std;
const int MAXN = 1000;
vector<int>G[MAXN + 5];
bool tag[MAXN + 5], vis[MAXN + 5], flag;
int stk[MAXN + 5], tp, val;
void dfs(int x) {
	stk[++tp] = x, vis[x] = tag[x] = true;
	for(int i=0;i<G[x].size();i++) {
		int p = G[x][i];
		if( !vis[p] ) dfs(p);
		else if( tag[p] )
			val = p, flag = true;
		if( flag ) return ;
	}
	stk[tp--] = 0, vis[x] = false;
}
int nxt[MAXN + 5];
vector<int>ans;
int main() {
	int N, M; scanf("%d%d", &N, &M);
	for(int i=1;i<=M;i++) {
		int A, B; scanf("%d%d", &A, &B);
		G[A].push_back(B);
	}
	for(int i=1;i<=N;i++)
		if( !tag[i] ) {
			dfs(i);
			if( flag ) break;
		}
	if( !flag ) {
		puts("-1");
		return 0;
	}
	int pos;
	for(int i=1;i<=tp;i++)
		if( stk[i] == val ) pos = i;
	nxt[stk[tp]] = val;
	for(int i=pos;i<tp;i++)
		nxt[stk[i]] = stk[i+1];
	for(int i=1;i<=N;i++) {
		if( !nxt[i] ) continue;
		for(int j=0;j<G[i].size();j++) {
			int x = G[i][j];
			if( !nxt[x] ) continue;
			int p = i, q = nxt[i];
			while( q != x ) {
				int r = nxt[q];
				nxt[p] = r;
				nxt[q] = 0;
				q = r;
			}
		}
	}
	int x;
	for(int i=1;i<=N;i++)
		if( nxt[i] ) x = i;
	int p = x;
	do {
		ans.push_back(p);
		p = nxt[p];
	}while( p != x );
	printf("%d\n", ans.size());
	for(int i=0;i<ans.size();i++)
		printf("%d\n", ans[i]);
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long

void solve()
{
    string s;
    cin>>s;
    ll l=s.length();
    if(s[l-1]=='s') s+="es";
    else s+="s";
    cout<<s;
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++) solve();
    return 0;
}

Measured memory_bytes: 3648
"ARC 059 C - いっしょ / Be Together"

if __name__ == "__main__":
    N = int(input())
    a = list(map(int, input().split()))

    ans = 10**12

    for i in range(-100, 101):
        tmp = 0
        for j in range(N):
            tmp += (a[j] - i) **2
        if tmp < ans:
            ans = tmp
    
    print(ans)


Measured memory_bytes: 2940
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
using ll = long long int;

ll dp[80010][12];
int solve_testcase() {
    string s; cin >> s;
    if(s == "0") return 1;

    int N = s.size();
    fill(dp[0], dp[N + 1], 0);

    for(int i=0; i<N; i++) {
        for(int j=0; j<11; j++) {
            // proceed
            dp[i+1][(j*10+(s[i]-'0'))%11] += dp[i][j];
        }
        // new seq
        if(s[i] != '0') {
            dp[i+1][(s[i] - '0')]++;
        }
    }

    ll ans = 0;
    for(int i=1; i<=N; i++) ans += dp[i][0];
    cout << ans << endl;
    
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 10632
import java.util.*;
import java.io.*;

class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A = n/1000;
    int B = n/100 - A*10;
    int C = n/10 - A*100 - B*10;
    int D = n%10;
    String[] ops = new String[2];
    ops[0] = "+";
    ops[1] = "-";
    boolean cont = true;
    outerloop:
    for(int i = 0; i < 2; i++) {
      for(int j = 0; j < 2; j++) {
        for(int k = 0; k < 2; k++) {
          int sum = 0;
          if(ops[i].equals("+"))
            sum += A+B;
          else
            sum += A-B;
          if(ops[j].equals("+"))
            sum += C;
          else
            sum -= C;
          if(ops[k].equals("+"))
            sum += D;
          else
            sum -= D;

          if(sum == 7) {
            System.out.println(A+ops[i]+B+ops[j]+C+ops[k]+D+"=7");
            break outerloop;
          }
        }
      }
    }
  }
}


Measured memory_bytes: 21972
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; ++i)
        cin >> h[i];

    int ans = 0;
    for(;;){
        int i = 0;
        while(i < n){
            if(h[i] == 0){
                ++ i;
                continue;
            }

            int j = i;
            int x = INT_MAX;
            while(j < n && h[j] != 0){
                x = min(x, h[j]);
                ++ j;
            }
            while(i < j){
                h[i] -= x;
                ++ i;
            }
            ans += x;
        }
        if(h == vector<int>(n, 0))
            break;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if (A <= 9 && A > 0 && B <= 9 && A > 0) {
    cout << A * B << endl;
  } else {
  	cout << -1 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#define int long long
using namespace std;
int test[123][123];
signed main() {
	int n, q, a, b, c; cin >> n >> a;
	if (500 * n >= a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
/**


  ######                                                                     ######   #     #  #######
  #     #    ##    #####   #    #  #    #  #    #  #   ####   #    #  #####  #     #  #     #       #
  #     #   #  #   #    #  #   #   #   #   ##   #  #  #    #  #    #    #    #     #  #     #      #
  #     #  #    #  #    #  ####    ####    # #  #  #  #       ######    #    ######   #######     #
  #     #  ######  #####   #  #    #  #    #  # #  #  #  ###  #    #    #    #   #    #     #    #
  #     #  #    #  #   #   #   #   #   #   #   ##  #  #    #  #    #    #    #    #   #     #   #
  ######   #    #  #    #  #    #  #    #  #    #  #   ####   #    #    #    #     #  #     #  #######



**/
/*

    BismiLLAHIR RAHMANIR RAHIM
    It's not how you look or who you are underneath, it's what you do that defines you

                                ------********-------

    Status : ;
    TC: xxx/xxx;
    DOS: ;
    OJ: ;

*/

#include <bits/stdc++.h>

using namespace std;

#define test        cout<<"thiq ase boss"<<endl;
#define PB          push_back
#define PF          push_front
#define PII         pair <int,int>
#define MII         map <int,int>
#define MSI         map <string,int>
#define MIS         map <int,string>
#define MLI         map <long long int,int>
#define MIL         map <int,long long int>
typedef long long int           LL;
typedef vector <string>         VS;
typedef vector <int>            VI;
typedef vector <char>           VC;
typedef vector <LL>             VLL;

const int INF = 1e9;
const int MX = 1e9;
const double PI = acos(-1);

/* Functions */

int main() {
    #ifdef LU_SERIOUS
        freopen("get.txt","r",stdin);
    #endif // LU_SERIOUS
    int t,cs=0,n,l,r,i,j,x,y,ans;
    char c;
    while (cin >> c) {
        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cout << "vowel" <<endl;
        else cout << "consonant" << endl;
    }
    return 0;
}



Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>

#define ll long long

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N;

	cin >> N;

	string ans = "";

	while (N) {

		N -= 1;
		ans = char(('a') + N % 26) + ans;
		N /= 26;
	}

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

Measured memory_bytes: 3628
from sys import stdin


# 最大化問題
def chmax(a,b):
    if a < b: return b
    else: return a


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    s =     _in[0]   # type:str
    t =     _in[1]   # type:str
    S, T = len(s), len(t)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    dp = [[0] * (T+1) for _ in range(S+1)]  # 最大化問題
    # dp[i+1][j+1]:=sのi文字目までとtのj文字目までのLCSの長さ
    dp[0][0] = 0  # 初期条件

    # 配るDP
    for i,_s in enumerate(s):
        for j,_t in enumerate(t):
            if _s == _t:
                dp[i+1][j+1] = chmax(dp[i+1][j+1],dp[i][j]+1)
            dp[i+1][j+1] = chmax(dp[i+1][j+1],dp[i+1][j])
            dp[i+1][j+1] = chmax(dp[i+1][j+1],dp[i][j+1])

    ans = ''
    i, j = S, T
    while (i>0 and j>0):
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ans = s[i-1] + ans
            i -= 1
            j -= 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


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

int main(){
	while(true){
		int n, x;
		
		cin >> n >> x;
		
		if(n==0 && x==0) break;
		
		int ans = 0;
		for(int a=1; a<=n; a++){
			for(int b=a+1; b<=n; b++){
				if(x-a-b>b && x-a-b<=n) ans++;
			}
		}
		cout << ans << "\n";
	}
	cout << flush;
	return 0;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s.at(i);
  rep(i,w+2) cout << '#';
  cout << endl;
  rep(i,h){
    cout << '#' << s.at(i) << '#' << endl;
  }
  rep(i,w+2) cout << '#';
  cout << endl;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

const MAX: usize = 200_000;
const MOD: usize = 998244353;

struct ModComb {
    max: usize,
    modulus: usize,
    fact: Vec<usize>,
    finv: Vec<usize>,
    inv: Vec<usize>,
}

impl ModComb {
    fn new(max: usize, modulus: usize) -> Self {
        let mut mc = Self {
            max,
            modulus,
            fact: vec![1; max],
            finv: vec![1; max],
            inv: vec![0; max],
        };
        mc.init_table();
        mc
    }

    fn init_table(&mut self) {
        self.inv[1] = 1;
        for i in 2..self.max {
            self.fact[i] = self.fact[i-1] * i % self.modulus;
            self.inv[i] = self.modulus - self.inv[self.modulus%i] * (self.modulus / i) % self.modulus;
            self.finv[i] = self.finv[i-1] * self.inv[i] % self.modulus;
        }
    }

    fn comb(&self, n: usize, k: usize) -> usize {
        if n < k {
            0
         } else {
            self.fact[n] * (self.finv[k] * self.finv[n-k] % self.modulus) % self.modulus
        }
    }
}

fn mod_pow(a: usize, n: usize, m: usize) -> usize {
    if n == 0 {
        1
    } else if n % 2 == 0 {
        let x = mod_pow(a, n / 2, m);
        x * x % m
    } else {
        let x = mod_pow(a, n / 2, m);
        a * ((x * x) % m) % m
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        k: usize,
    }

    let mut ans = 0usize;
    let mc = ModComb::new(MAX, MOD);
    for i in 0..=k {
        let mut num = m;
        num = num * mc.comb(n-1, i) % MOD;
        num = num * mod_pow(m-1, n-1-i, MOD) % MOD;
        ans = (ans + num) % MOD;
    }

    println!("{}", ans);

}

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

const int MAX_N = 1e5 + 5, MAX_M = 40;
int n, x, ans, p;
int a[MAX_N];
int l[MAX_N];
int cnt[MAX_M];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
		
	for (int i = 0; i < n; i++)
		x ^= a[i];
		
	for (int i = 0; i < n; i++) {
		l[i] = __builtin_ctz(a[i]);
		cnt[l[i]]++;
	}
		
	
	for (int i = 31; ~i; i--)
		if (((x >> i) & 1) ^ p) {
			if (!cnt[i]) {
				cout << "-1\n";
				return 0;
			}
			
			p = !p;
			cnt[i]--;
			ans++;
		}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int n,m,l;
  cin>>n>>m>>l;
  vector<vector<int> > A(n,vector<int>(m));
  vector<vector<int> > B(m,vector<int>(l));
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++)cin>>A[i][j];
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<l;j++)cin>>B[i][j];
  }
  vector<vector<int> > ans(n,vector<int>(l,0));

  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      int tmp=0;
      for(int k=0;k<m;k++){
        tmp+=A[i][k]*B[k][j];
      }
      ans[i][j]=tmp;
    }
  }

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



Measured memory_bytes: 3268
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
using namespace std;
int main()
{
    string s;
    double ans = 0;
    cin >> s;
    for (int i = 0; i < 4; i++)
    {
        if (s[i] == '+')
        {
            ans++;
        }
        else
        {
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
temp=str(input())
templ=list(temp)
tempb=templ[len(templ)-1]
w=[0]*n
w[0]=temp
for i in range(0,n-1):
  temp=str(input())
  templ=list(temp)
  if temp in w or tempb!=templ[0]:
    print("No")
    break
  tempb=templ[len(templ)-1]
  w[i+1]=temp
else:
  print("Yes")
  

Measured memory_bytes: 3064
K = gets.to_i
７ = [
	[],
	[7,6,5,4,3,2,1,0,9,8],
	[],
	[9,2,5,8,1,4,7,0,3,6],
	[],
	[],
	[],
	[1,8,5,2,9,6,3,0,7,4],
	[],
	[3,4,5,6,7,8,9,0,1,2]
][K%10]
if ７.empty?
	p(-1)
	exit
end

n = 0
k = K*７[0]
z = 0
while 0<k
	k += K*７[z] if 7 != z = k%10
	n += 1
	k /= 10
end
p n


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

using namespace std;
using ll = long long;
const int def = 20000;

//arrの要素のいくつかを反転させたsumでxを作ることは可能か?
bool chack(vector<int> arr, int x, bool flag) {
    vector<int> dp(def * 2); //dp[i] := dp[i]を作ることは可能？
    int n = arr.size();
    dp[def] = true;
    for(int i = 0; i < n; i++) {
        vector<int> DP = dp;
        if(flag && i == 0) {
            dp[def + arr[i]] = 1;
            continue;
        }
        for(int j = 0; j < def * 2; j++) {
            if(dp[j]) {
                DP[j + arr[i]] += 1;
                DP[j - arr[i]] += 1;
            }
        }
        for(int j = 0; j < def * 2; j++) {
            if(dp[j] == DP[j])DP[j] = 0;
        }
        dp = DP;
    }
    return dp[x];
}


int main()
{
    string s; int x, y; cin >> s >> x >> y;
    x += def, y += def;
    vector<int> xa, ya;
    int n = s.size();
    bool rot = false;

    for(int i = 0; i < n; i++) {
        int j = i;
        while(s[j] == 'F' && j < n)j++;
        rot = !rot;
        if(j - i == 0 && i != 0)continue;
        if(rot)xa.push_back(j - i);
        else ya.push_back(j - i);
        i = j;
    }

    cout << (chack(xa, x, true) && chack(ya, y, false) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <sstream>
#include <fstream>
#include <float.h>
#include <cmath>
#include <cstring>

using namespace std;
#define int long long

signed main() {
	int N;
	cin >> N;
	int tmp = 1;
	for (int i = 1; i <= N; i++) {
		tmp *= i;
		tmp %= 1000000007;
	}
	cout << tmp << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n;cin>>n;
 	ll a[n];	
  	for(int i=0;i<n;i++){
      cin>>a[i];
    }
  	ll nsr[n];
  	stack<pair<ll, ll> > st;
  	for(int i=n-1;i>=0;i--){
      while(!st.empty()&&st.top().first>a[i]) st.pop();
      if(st.empty()) nsr[i]=n;
      else nsr[i]=st.top().second;
      st.push({a[i],i});
    }
//    for(int i=0;i<n;i++) cout<<nsr[i]<<" \n"[i==n-1];
  	ll dp[n+10]={0},sum=0;
  	for(int i=n-1;i>=0;i--){
      dp[i]=(nsr[i]-i)*a[i]+dp[nsr[i]];
      sum+=dp[i];
    }
	cout<<sum<<endl;
  	return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n;
    cin >> n;
    vector<int>t(n);
    vector<int>x(n);
    vector<int>y(n);
    rep(i,n) {
        cin >> t[i] >> x[i] >> y[i];
    }
    bool ans = true;
    rep(i,n) {
        if(t[i]< x[i]+y[i]) ans = false;
        if(t[i]%2 != (x[i]+y[i])%2) ans = false;
        if(i==n-1) continue;
        if(abs(t[i]-t[i+1]) < abs(x[i]-x[i+1])+abs(y[i]-y[i+1])) ans = false;        
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408
N = int(input())
A = list(map(int, input().split()))

ans = 0
S = 0
X = 0
end = -1

for i in range(N):
  while end < N-1:
    end += 1
    S += A[end]
    X ^= A[end]
    if S != X:
      S -= A[end]
      X ^= A[end]
      end -= 1
      break
  ans += end - i + 1
  S -= A[i]
  X ^= A[i]

print(ans)

Measured memory_bytes: 32200
# include<bits/stdc++.h>
using namespace std;
int main(){
	int d;
    cin >>d;
    if (d==25)
    	cout << "Christmas"<<'\n';
    else if (d==24)
		cout << "Christmas Eve"<<'\n';
    else if (d==23)
		cout << "Christmas Eve Eve"<<'\n';
    else cout << "Christmas Eve Eve Eve"<<'\n';
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn lcm(a: usize, b: usize) -> usize {
    a / gcd(a, b) * b
}

fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize,
        d: usize,
    }
    let mut v_a = 0;
    v_a += a - a / c;
    v_a += a - a / d;
    v_a -= a - a / lcm(c, d);
    let mut v_b = 0;
    v_b += b - b / c;
    v_b += b - b / d;
    v_b -= b - b / lcm(c, d);
    let ans = v_b - v_a + if a % c != 0 && a % d != 0 { 1 } else { 0 };
    println!("{}", ans);
}


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

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

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

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

struct Edge{
  int to, cost;

  Edge(int t, int c = 0): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
using Graph =  vector< vector<Edge> >;


// ????????°???????????¨???
void add_edge(Graph& graph, int u, int v, int cost = 0){
  graph[u].push_back(Edge(v,cost));
  graph[v].push_back(Edge(u,cost));
}

int prim(const Graph& G){
  const int V = G.size();
  int res = 0;
  vector<bool> visited(V, false);
  priority_queue<Edge, vector<Edge>, greater<Edge> > pq;

  pq.push(Edge(0,0));
  for(int i=0;i<V;++i){
	Edge edge = pq.top(); pq.pop();
	int v = edge.to;
	if(visited[v]){
	  --i;
	  continue;
	}
	visited[v] = true;
	res += edge.cost;

	for(const auto& e:G[v]){
	  pq.push(e);
	}
  }

  return res;
}

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

  int V, E; cin >> V >> E;
  Graph G(V);
  REP(i,E){
	int a, b, c; cin >> a >> b >> c;
	add_edge(G, a, b, c);
  }

  cout << prim(G) << endl;

  return 0;
}

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

const int MOD = 1e9 + 7;
int poww(long long a , long long b){
	int tms = 1;
	while(b){
		if(b & 1) tms = tms * a % MOD;
		a = a * a % MOD; b >>= 1;
	}
	return tms;
}
char Map[1003][1003]; int H , W; long long K;

int main(){
	cin >> H >> W >> K; if(K <= 1){cout << 1; return 0;}
		int num = 0;
	for(int i = 1 ; i <= H ; ++i)
		for(int j = 1 ; j <= W ; ++j){
			cin >> Map[i][j]; num += Map[i][j] == '#';
		}
	int Q1 = 0 , Q2 = 0; 
	for(int i = 1 ; i <= H ; ++i) Q1 += Map[i][1] == '#' && Map[i][W] == '#';
	for(int i = 1 ; i <= W ; ++i) Q2 += Map[1][i] == '#' && Map[H][i] == '#';
	if(Q1 && Q2) cout << 1;
	else if(!Q1 && !Q2) cout << poww(num , K - 1);
	else{
		int P = 0 , Q = Q1 + Q2;
		if(Q1) for(int i = 1 ; i <= H ; ++i) for(int j = 1 ; j <= W ; ++j) P += Map[i][j] == '#' && Map[i][j + 1] == '#';
		else for(int i = 1 ; i <= H ; ++i) for(int j = 1 ; j <= W ; ++j) P += Map[i][j] == '#' && Map[i + 1][j] == '#';
		int t = 1ll * Q * poww(num , MOD - 2) % MOD , sum = (poww(t , K - 1) - 1ll) * poww(t - 1 , MOD - 2) % MOD;
		cout << (poww(num , K - 1) - 1ll * poww(num , K - 2) * sum % MOD * P % MOD + MOD) % MOD;
	}
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>

using namespace std;

void selectionSort(int* A, int N){
    int count = 0;
    for(int i = 0; i < N; i++){
        int minj = i;
        for(int j = i; j < N; j++){
            if(A[j] <A[minj]){
                minj = j;
            }
        }
        int tmp = A[i];
        A[i] = A[minj];
        A[minj] = tmp;
        if(A[i] != A[minj]){
            count++;
        }
    }
    for(int i = 0; i < N; i++){
        cout << A[i];
        if(i < N - 1){
            cout << " ";
        }
    }
    cout << endl;
    cout << count << endl;
}

int main(){
    int N;
    int A[1000];
    cin >> N;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        A[i] = a;
    }
    selectionSort(A, N);
    return 0;
}


Measured memory_bytes: 3088
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int a,b,N,poj=1;
  cin >> a >> b;
  if((a <= 0 && b >= 0) || a==0 || b==0){
    cout << "Zero" << endl;
  }else if(a > 0){
    cout << "Positive" << endl;
  }else{
    if((b-a+1) % 2 == 1){
      cout << "Negative" << endl;
    }else{
      cout << "Positive" << endl;
    }
  }
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

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

bool same(int x, int y){
  return find(x) == find(y);
}



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

using namespace std ;

int main()
{

    long long a , b , x  , divfora , divforb ;

    cin >> a >> b >> x ;

    if(a!=0)cout << ((b / x)-((a-1) / x)) << endl ;
    else cout << (b / x) + 1 << endl ;

}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,q;
int fie[2001][2001];
int sum[2][4005][4005];

int main(void){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=0;i<n;i++){
		string str;
		cin >> str;
		for(int j=0;j<m;j++){
			if(str[j]=='1'){
				sum[0][i+1][j+1]++;
				fie[i][j]=1;
			}else{
				fie[i][j]=0;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(j<m-1 && fie[i][j]==1 && fie[i][j+1]==1){
				sum[1][(i+1)*2][(j+1)*2+1]++;
			}
			if(i<n-1 && fie[i][j]==1 && fie[i+1][j]==1){
				sum[1][(i+1)*2+1][(j+1)*2]++;
			}
		}
	}
	for(int k=0;k<2;k++){
		for(int i=0;i<=n*2;i++){
			for(int j=1;j<=m*2;j++){
				sum[k][i][j]+=sum[k][i][j-1];
			}
		}

		for(int i=0;i<=m*2;i++){
			for(int j=1;j<=n*2;j++){
				sum[k][j][i]+=sum[k][j-1][i];
			}
		}
	}
	for(int i=0;i<q;i++){
		int x1,x2,y1,y2;
		scanf("%d%d%d%d",&y1,&x1,&y2,&x2);
		ll v1=sum[0][y2][x2]-sum[0][y2][x1-1]-sum[0][y1-1][x2]+sum[0][y1-1][x1-1];
		ll v2=sum[1][y2*2][x2*2]-sum[1][y2*2][x1*2-1]-sum[1][y1*2-1][x2*2]+sum[1][y1*2-1][x1*2-1];
		printf("%d\n",v1-v2);
	}
	return 0;
}


Measured memory_bytes: 142720
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

int main() {
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;

  return 0;
}

Measured memory_bytes: 3636