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

template<class CommutativeMonoid> struct UnionFind {
    using M = CommutativeMonoid;
    using T = typename M::value_type;
    vector<int> data; vector<T> val; int sz;
    UnionFind(int sz) : data(sz, -1), val(sz, M::id()), sz(sz) { }
    template<class InputIterator>
    UnionFind(int sz, InputIterator first, InputIterator last)
        : data(sz, -1), val(first, last), sz(sz) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[y] < data[x]) swap(x, y);
        data[x] += data[y]; data[y] = x; sz--;
        val[x] = M::op(val[x], val[y]);
        return true;
    }
    T& operator[](int x) { return val[root(x)]; }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};

template <typename T>
struct MinMonoid {
    using value_type = T;
    static constexpr T id() { return numeric_limits<T>::max(); }
    static T op(const T &a, const T &b) { return min(a, b); }
};

int main() {
    int n; cin >> n;
    map<string, int> name2id;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        string s; cin >> s >> x[i];
        name2id[s] = i;
    }
    UnionFind<MinMonoid<int>> uf(n, x.begin(), x.end());
    int m; cin >> m;
    while (m--) {
        string s, t; cin >> s >> t;
        uf.unionSet(name2id[s], name2id[t]);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) ans += uf[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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 repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}
//cout << fixed << setprecision(15);
int N, M, K, H, W, L, R, X;
string S, T;

signed main(){
  int A, B;
  cin >> A >> B;
  int ans;
  if(A<6) ans = 0;
  else if(A>=6 && A<=12) ans = B/2;
  else ans = B;
  COUT(ans);
  return 0;

}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b,x;cin>>a>>b>>x;

  if(a<=x&&a+b>=x)
    printf("YES\n");
    else printf("NO\n");

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

N, M = map(int, input().split())
A = list(map(int, input().split()))
cnt = defaultdict(int)
cnt[0] = 1
acc = 0
ans = 0

for Ai in A:
    acc += Ai
    ans += cnt[acc%M]
    cnt[acc%M] += 1

print(ans)

Measured memory_bytes: 58608
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

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

  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

template <class Tp>
Tp gcd(Tp m, Tp n) {
  while (n) std::swap(m%=n, n);
  return m;
}

int solve_testcase() {
  intmax_t A, B, C, D;
  scanf("%jd %jd %jd %jd", &A, &B, &C, &D);

  if (A < B) return puts("No"), 0;
  if (D < B) return puts("No"), 0;
  if (C >= B) return puts("Yes"), 0;

  intmax_t g = gcd(B, D);
  if ((A%g) + B-g > C) return puts("No"), 0;
  puts("Yes");
  return 0;
}

int main() {
  int T;
  scanf("%d", &T);

  for (int i=0; i<T; ++i)
    solve_testcase();
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int rem = n%10;
  if(rem == 3) {
  	cout<<"bon";
  } else if(rem == 0 || rem ==1 || rem == 6|| rem ==8) {
  	cout<<"pon";
  } else {
  	cout<<"hon";
  }
}

Measured memory_bytes: 3612
def main():
    from bisect import bisect_left as bl
    from bisect import bisect_right as br
    s=input()
    alpha="abcdefghijklmnopqrstuvwxyz"
    l=len(s)
    alpha2={j:i for i,j in enumerate(alpha)}
    memo=[[] for _ in [0]*26]
    mod=10**9+7
    for i in range(l):
        memo[alpha2[s[i]]].append(i)
    dp=[[0]*(l+1) for _ in range(l+1)]
    dp[0][l]=1
    ans=0
    for i in range(l):
        for j in range(i+1,l+1):
            p=dp[i][j]
            if p==0:
                continue
            for k in range(26):
                x=bl(memo[k],i)
                y=br(memo[k],j-1)-1
                if x>y:
                    continue
                ans+=p
                if x<y:
                    mx,my=memo[k][x],memo[k][y]
                    dp[mx+1][my]=(dp[mx+1][my]+p)%mod
            ans=ans%mod
    ans=(ans+sum([sum([i for i in j])%mod for j in dp])+mod-1)%mod
    print(ans)
    
if __name__=='__main__':
    main()


Measured memory_bytes: 44956
#include <iostream>

#define MAX 100005
#define NIL -1

using namespace std;

struct Node
{
    int parent;
    int depth;
    int height;
    int left;
    int right;
};

struct Node T[MAX];
int n;

void setDepth(int u, int d){
    if(u==NIL) return;
    T[u].depth = d;
    if(T[u].right != NIL) setDepth(T[u].right, d+1);
    if(T[u].left != NIL) setDepth(T[u].left, d+1);
}

int setHeight(int u){
    int h1=0, h2=0;
    if(T[u].right != NIL) h1 = setHeight(T[u].right)+1;
    if(T[u].left != NIL) h2 = setHeight(T[u].left)+1;
    return T[u].height = (h1>h2 ? h1:h2);
}

int getSibling(int u){
    if(T[u].parent == NIL) return NIL;
    if(T[T[u].parent].left!=u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
    if(T[T[u].parent].right!=u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
    return NIL;
}

void printNode(int u){
    int i,c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "sibling = " << getSibling(u) << ", ";
    int deg = 0;
    if(T[u].left != NIL) deg++;
    if(T[u].right != NIL) deg++;
    cout << "degree = " << deg << ", ";
    cout << "depth = " << T[u].depth << ", ";
    cout << "height = " << T[u].height << ", ";

    if(T[u].parent == NIL) cout << "root" << endl;
    else  if(T[u].left == NIL && T[u].right == NIL) cout << "leaf" << endl;
    else cout << "internal node" << endl;



}

int main(){
    int v,l,r,root=0;
    cin >> n;
    for(int i=0; i<n; ++i) T[i].parent = NIL;

    for(int i=0; i<n; ++i){
        cin >> v >> l >> r;
        T[v].left = l;
        T[v].right = r;
        if( l != NIL) T[l].parent = v;
        if( r != NIL) T[r].parent = v;
    }

    for(int i = 0; i<n;++i){
        if(T[i].parent == NIL) root = i;
    }

    setDepth(root, 0);
    setHeight(root);

    for(int i=0; i<n; ++i) printNode(i);

    return 0;

}


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

typedef long long ll;

typedef pair<int, int> p;

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

    int n;
    cin >> n;

    deque<int> d;

    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if(i % 2) d.push_back(a);
        else d.push_front(a);
    }

    if(n % 2) {
        for(int i = 0; i < n; i++) {
            cout << d.front() << " ";
            d.pop_front();
        }
    } else {
        for(int i = 0; i < n; i++) {
            cout << d.back() << " ";
            d.pop_back();
        }
    }

    cout << endl;
}

Measured memory_bytes: 3072
#include<stdio.h>
#include<string.h>
int main(){
  char str[1201];
  int i,j,sstr;
  gets(str);
  sstr=strlen(str);
  for(i=0;i<sstr;i++){
    if(64<str[i] && str[i]<91)str[i]+=32;
    else if(96<str[i] && str[i]<123)str[i]-=32;
  }
  puts(str);
  return(0);
}

Measured memory_bytes: 524
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return(false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return(true);
  }

  int find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = find(data[k]));
  }

  int size(int k)
  {
    return(-data[find(k)]);
  }

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

int main()
{
    int N;
    cin >> N;
    vector<int> h(N);
    REP(i, N) cin >> h[i];
    int ans = 0;
    while (true)
    {
      int begin, end;
      begin = end = N;

      for (int i = 0; i < N; ++i)
      {
        if (h[i] > 0)
        {
          begin = i;
          break;
        }
      }

      for (int i = begin + 1; i < N; ++i)
      {
        if (h[i] == 0)
        {
          end = i;
          break;
        }
      }

      if (begin == N && end == N)
      {
        break;
      }

      for (int i = begin; i < end; ++i)
      {
        --h[i];
      }
      ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	int a,b,c;
	cin >>a >>b >>c;
	
	int ans = max({a,b,c}) * 9 + a+b+c;
	cout << ans << "\n";
}


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

int main() {
    int n, k=1, x, y;
    double ans=0;
    cin >> n;
    vector<int> a(n);
    vector<pair<int, int>> p(n);
    for(int i=0; i<n; i++) {
        cin >> x >> y;
        p[i]=make_pair(x,y);
    }
    for(int i=0; i<n; i++) {
        a[i]=i;
    }
    do {
        for(int i=0; i<n-1; i++) {
            ans+=sqrt((p[a[i]].first-p[a[i+1]].first)*(p[a[i]].first-p[a[i+1]].first)+(p[a[i]].second-p[a[i+1]].second)*(p[a[i]].second-p[a[i+1]].second));
        }
    } while(next_permutation(a.begin(), a.end()));

   

    for(int i=1; i<=n; i++) {
        k*=i;
    }
    ans/=k;
    cout << fixed << setprecision(10);
    cout << ans;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
l=[0]*n
l[0]=a[0]
for i in range(1,n):
  l[i]=l[i-1]+a[i]
import bisect as bi
x=bi.bisect_left(l,s/2)
if l[x]==s/2:
  print(0)
else:
  print(min(s-l[x-1]*2,l[x]*2-s))

Measured memory_bytes: 26024
from sys import stdin
input = stdin.readline

def bfs(s):
    q = [s]
    vst[s] = True
    ret = 1
    for u in q:
        for v in adj[u]:
            if not vst[v]:
                vst[v] = True
                q.append(v)
                ret += 1
    return ret


if __name__ == "__main__":
    N, M = map(int, input().split())
    adj = [set() for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        adj[a - 1].add(b - 1)
        adj[b - 1].add(a - 1)
    vst = [False] * N
    ans = 0
    for i in range(N):
        if not vst[i]:
            ans = max(ans, bfs(i))
    print(ans)

Measured memory_bytes: 146984
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N+1];

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

		for (int i=1; i < N + 1; i++) {
			System.out.print(A[i] + " ");
		}
	}
}


Measured memory_bytes: 62620
#pragma GCC optimize("O3")
#include<stdio.h>
int main(void)
{
    long long ans = 0;
    char c=getchar();
    while(c<='9'&&c>='0') {ans=(ans<<1)+(ans<<3)+c-'0'; c=getchar();}
    long long n = ans + 1;
    for (long long i = 2; i < n; ++i)
    {
        long long u = 0, v = 0;
        c=getchar();
        while(c<='9'&&c>='0') {u=(u<<1)+(u<<3)+c-'0'; c=getchar();}
        c=getchar();
        while(c<='9'&&c>='0') {v=(v<<1)+(v<<3)+c-'0'; c=getchar();}
        switch(u > v)
        {
            case true: ans += i * (n - i) - v * (n - u); break;
            default: ans += i * (n - i) - u * (n - v);
        }
    }
    printf("%ld", ans);
    return 0;
}


Measured memory_bytes: 1604
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll n,k;
vector<ll> a;
vector<bitset<5010>> b, c;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    a.resize(n); b.resize(n), c.resize(n);
    rep(i,0,n) cin>>a[i];
    if(n==1){
        cout <<0<<"\n";
        return 0;
    }
    b[0][0]=1;
    if(a[0]<=k) b[0][a[0]]=1;
    rep(i,1,n){
        if(a[i]<=k) b[i]=b[i-1]|(b[i-1]<<a[i]);
        else b[i]=b[i-1];
    }
    c[n-1][0]=1;
    if(a[n-1]<=k) c[n-1][a[n-1]]=1;
    rer(i,n-1,0){
        if(a[i]<=k) c[i]=c[i+1]|(c[i+1]<<a[i]);
        else c[i]=c[i+1];
    }
    int ans=0;
    rep(i,max(0LL,k-a[n-1]),k){
        if(b[n-2][i]==1) break;
        if(i==k-1) ans++;
    }
    rep(i,max(0LL,k-a[0]),k){
        if(c[1][i]==1) break;
        if(i==k-1) ans++;
    }
    rep(i,1,n-1){
        vector<ll> x,y;
        rep(j,0,k+1){
            if(b[i-1][j]) x.pb(j);
            if(c[i+1][j]) y.pb(j);
        }
        rep(j,0,sz(x)){
            if(lb(y,k-a[i]-x[j])!=y.end()&&x[j]+*lb(y,k-a[i]-x[j])<k){
                break;
            }
            if(j==sz(x)-1) ans++;
        }
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 6712
N = int(input())
L = list(input())
ANS = []
ans = L.count("E")
for i in range(len(L)) :
    if L[i] == "E" :
        ans -= 1
    if L[i-1] == "W" and i != 0 :
        ans += 1
    ANS.append(ans)
print(min(ANS))


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

int main() {

  long long N;
  cin >> N;
  map<char, long long> S;
  vector<char> key = {'M', 'A', 'R', 'C', 'H'};
  S['M'] = 0;
  S['A'] = 0;
  S['R'] = 0;
  S['C'] = 0;
  S['H'] = 0;
  for (int i = 0; i < N; i++) {
  	string name;
    cin >> name;
    char f = name.at(0);
    if (f == 'M' || f == 'A' || f == 'R' || f == 'C' || f == 'H') {
      S[f] += 1;
    }
  }
  long long sum = 0;
  for (long long i = 0; i < key.size(); i++) {
    for (long long j = i + 1; j < key.size(); j++) {
        for (long long k = j + 1; k < key.size(); k++) {
          sum += S[key[i]] * S[key[j]] * S[key[k]];
        }
     }
  }

  cout << sum << endl;
}


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

long N, M, ans;
vector<long> H;
vector<set<long>> G;

int main(void) {

    cin >> N >> M;
    H.resize(N+1);
    G.resize(N+1);

    for (long i = 1; i <= N; i++) {
        cin >> H[i];
    }

    for (long i = 0; i < M; i++) {
        long a, b; cin >> a >> b;
        G[a].emplace(b);
        G[b].emplace(a);
    }

    for (long i = 1; i <= N; i++) {
        bool flag = true;
        for (auto e: G[i]) {
            if (H[i] <= H[e]) {
                flag = false;
                break;
            }
        }

        if (flag) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 17880
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>
#include <atcoder/all>

using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

const int L=100*1000+9;
const long long M = 998244353;

template<int S>
struct Comb
{
	LL r[S+1];
	LL f[S+1];
	LL inv[S+1];
	LL mod;
	Comb(int m)
	{
		mod=m;
		inv[1]=1;
		for(int i=2;i<=S;i++){
			inv[i]=(m-m/i)*inv[m%i]%m;
		}
		f[0]=1;
		r[0]=1;
		for(LL i=1;i<=S;i++){
			f[i]=i*f[i-1]%m;
			r[i]=inv[i]*r[i-1]%m;
		}
	}
	LL c(int n,int i){
		if(i<0||n<i)
		{
			//assert(0);
			return 0;
		}
		return f[n]*r[i]%mod*r[n-i]%mod;
	}
};
Comb<L> comb(M);
LL C(int n,int i){
	return comb.c(n,i);
}

LL df[L];
void solve(long long N, std::vector<long long> h){
	df[0]=1;
	for(int i=1;i<L;i++){
		df[i]=df[i-1]*(2*i-1)%M;
	}
	map<int,int> cnt;
	for(auto v:h){
		cnt[v]++;
	}
	vector<vector<LL>> cur,nex;
	for(auto p:cnt){
		int s=p.second;
		vector<LL> b;
		for(int i=0;2*i<=s;i++){
			b.push_back(C(s,2*i)*df[i]%M);
		}
		cur.push_back(b);
	}
	while(cur.size()>1){
		nex.clear();
		for(auto i=0;i<cur.size();i+=2){
			if (i+1<cur.size()){
				nex.push_back(atcoder::convolution(cur[i],cur[i+1]));
			}
			else{
				nex.push_back(cur[i]);
			}
		}
		nex.swap(cur);
	}
	LL ret=0;
	auto& cs=cur[0];
	LL sg=1;
	for(int i=0;i<cs.size();i++){
		ret+=(M+sg)*cs[i]%M*df[N-i]%M;
		ret%=M;
		sg=-sg;
	}
	cout << ret << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> h(2*N);
    for(int i = 0 ; i < 2*N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, std::move(h));
    return 0;
}


Measured memory_bytes: 20256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine());
		int[] H = Arrays.stream(sc.nextLine().split(" ")).mapToInt(s -> Integer.parseInt(s)).toArray();

		int pre = -1;
		for (int i = 0; i < N; i++) {
			if (pre <= H[i] - 1) {
				pre = H[i] - 1;
			} else if (pre <= H[i]) {
				pre = H[i];
			} else {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 54692
def sizeAGCTString(str)
  temp = str.count("A") + str.count("G") + str.count("C") + str.count("T")
  return str.size == temp ? str.size : 0
end
n=gets.chomp
agct = [0]
n.size.times do |startIndex|
  str = n[startIndex]
  agct << sizeAGCTString(str)
  next if agct[-1] == 0
  ((startIndex+1)...n.size).each do |endIndex|
    str = n[startIndex..endIndex]
    agct << sizeAGCTString(str)
    break if agct[-1] == 0
  end
end
puts agct.max

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

int main(){
    string s;
    cin >> s;
    vector<int> ans(s.length(), 0);
    vector<vector<int>> memo(32, vector<int>(s.length(), 0));
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'R') memo[0][i] = i+1;
        else memo[0][i] = i-1;
    }

    for(int i = 1; i < 32; i++){
        for(int j = 0; j < s.length(); j++){
            memo[i][j] = memo[i-1][memo[i-1][j]];
        }
    }

    for(int i = 0; i < s.length(); i++){
        int mask = 100000;
        int coans = i;
        for(int j = 0; (1 << j) <= 100000; j++){
            if(mask & (1 << j)){
                coans = memo[j][coans];
            }
        }
        ans[coans]++;
    }

    for(int i = 0; i < s.length(); i++){
        cout << ans[i];
        if(i == s.length()-1) cout << endl;
        else cout << " ";
    }
    return 0;
}

Measured memory_bytes: 13824
import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List as L

dateList = [1212, 1111, 1010, 909, 808, 707, 606, 505, 404, 303, 202, 101]

main :: IO()
main = do
  [a, b] <- map read . words <$> getLine
  printf "%d" $ length $ dropWhile (> a * 100 + b) dateList



Measured memory_bytes: 508
import java.util.Scanner;

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

    int K = scanner.nextInt();
    int N = scanner.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) A[i] = scanner.nextInt();

    int max = A[0] + K - A[N - 1];
    for (int i = 1; i < N; i++) {
      max = Math.max(max, A[i] - A[i - 1]);
    }
    System.out.println(K - max);
  }
}


Measured memory_bytes: 75928
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return (a.second < b.second);}
ll gcd(ll a, ll b){if(a==0)return b;return gcd(b % a, a);}
int main()
{
	chutiyaap;
    string s;
    cin>>s;
    int a=0,b=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='A')a++;
        else b++;
    }
    if(a!=0&&b!=0)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<i64>();
    let mut x = vec![0; n];
    for i in 1..n {
        x[0] ^= a[i];
    }
    for i in 1..n {
        x[i] = x[i - 1] ^ a[i - 1] ^ a[i];
    }
    for ans in x {
        print!("{} ", ans);
    }
    println!("");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  string s1,s2;
  for(int i=0;i<a;i++)
    s1.push_back(b+'0');
  for(int i=0;i<b;i++)
    s2.push_back(a+'0');
  if(s1<s2)
    cout<<s1<<endl;
  else
    cout<<s2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n, i, c = 0;
    cin >> n;
    long long A[n+1];
    for (i = 1; i <= n; i++)
        cin >> A[i];
    for (i = 1; i <= n; i += 2)
    {
        if (A[i] % 2 == 1)
            c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <iostream>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int nr = 0;
    for(int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        if(x >= k)
            nr++;
    }
    cout << nr << "\n";
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn
import Math.{abs,pow,sqrt,cbrt}
/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {
    StdIn.readInt()

    def read(): Array[Double] ={StdIn.readLine().split(" ").map(_.toDouble)}
    val xArray = read()
    val yArray = read()

    val list = (xArray zip yArray).map(x => abs(x._1 - x._2))
    val p1 = list.sum
    val p2 = sqrt(list.map(pow(_,2)).sum)
    val p3 = cbrt(list.map(pow(_,3)).sum)
    val pInfinity = list.max

    val format = "%.6f"
    println(format.format(p1))
    println(format.format(p2))
    println(format.format(p3))
    println(format.format(pInfinity))
  }
}

Measured memory_bytes: 44304
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
    
using namespace std;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long int n,a[2];
  cin>>n>>a[0]>>a[1];
  sort(a, a+2);
  if((a[1]-a[0])%2==0)
  {
    cout<<((a[1]-a[0])/2)<<endl;
  }
  else
  {
    cout<<(min((a[0]+(a[1]-a[0]-1)/2),(n-a[1]+1+(a[1]-a[0]-1)/2)))<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import bisect
n = int(input())
l = [int(x) for x in input().split()]

l.sort()

ans = 0
for a in range(n):
    for b in range(a + 1, n):
        c = bisect.bisect_left(l, l[a] + l[b])
        if b < c:
            ans += c - (b + 1)

print(ans)

Measured memory_bytes: 42972
/*
|| Suyash Yadav | B.Tech (3rd Year CSE) | Tier-3 (NCR,India)
|| suyashky@gmail.com | "suyashky" @linkedIn
||
||		   /\_/\
||		  ( o.o )
|| 	 	   > ^ <
|| From infinity to beyond!
*/

# include <bits/stdc++.h>
using namespace std;
# define INF (long long int)1e28
# define MOD 1000000007
# define all(con) con.begin() , con.end()
# define MAX numeric_limits<int64>::max()
# define MIN numeric_limits<int64>::min()
# define watch1(x) cout<<#x<<": "<<x<<endl
# define watch2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
# define watch3(x,y,z) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
# define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int int64;
typedef unsigned long long int uint64;

struct node {
	int64 w, v;
};

int64 dp[102][100002];

int main()
{
/*
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
*/

	memset(dp, 0, sizeof(dp));
	int64 n, maxw;
	cin >> n >> maxw;

	vector<node> list;
	list.push_back({0, 0});
	int64 a, b;
	for (int64 i = 0 ; i < n ; i++)
	{
		cin >> a >> b;
		list.push_back({a, b});
	}

	// recursive/top-down/memoization
	/*int64 ans1 = knapsack(list, maxw, n - 1);
	cout << ans1 << endl;*/

	// iterative/bottom-up/dynamic programming

	for (int64 i = 1 ; i <= n ; i++)
	{
		for (int64 j = 1 ; j <= maxw ; j++)
		{
			if (list[i].w > j)
			{

				dp[i][j] = dp[i - 1][j];
			}
			else
			{
				dp[i][j] = max(dp[i - 1][j] , (dp[i - 1][j - list[i].w] + list[i].v));
			}
		}
	}

	cout << dp[n][maxw];
}

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


int main(){
  int N, K; cin >> N >> K;
  int A[N];
  long long tmp=1;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    if(i < K) tmp*=A[i];
  }
  for(int i = 0; i < N-K; i++){

      if(A[i+K]>A[i]) cout << "Yes" << endl;
      else cout << "No" << endl;
      // test[i] = A[i] * A[i+K];
      // if(test[i] > test[i-1]) cout << "Yes" << endl;
      // else cout << "No" << endl;
    

  }
  return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<bool> p(1000010,false);
    sort(all(a));
    int sum=0;
    rep(i,n){
        if(i!=n-1){
            if(a[i]==a[i+1]){
                p[a[i]]=true;
                continue;
            }
        }
        bool ans=true;
        for(ll j=1; j*j<=a[i]; j++){
            if(a[i]%j==0){
                if(p[j]) ans=false;
                if(p[a[i]/j]) ans=false;
            }
        }
        if(ans){
            sum++;
            // cout << a[i] << ' ';
        }
        p[a[i]]=true;
    }
    // cout << endl;

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 4252
use std::io::{stdout, Write, BufWriter};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        n: isize,
        xyh: [(isize, isize, isize); n],
    }

    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    let (x1, y1, h1) = *xyh.iter().find(|&&xyh_i| xyh_i.2 > 0).unwrap();

    let mut h = 0;
    for px in 0..101 {
        for py in 0..101 {
            h = h1 + (px - x1).abs() + (py - y1).abs();
            if xyh.iter().all(|&xyh_i| xyh_i.2 == std::cmp::max(h - (px - xyh_i.0).abs() - (py - xyh_i.1).abs(), 0)) {
                writeln!(out, "{} {} {}", px, py, h).unwrap();
            }
        }
    }
}

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

using namespace std;

typedef pair<int, int> P_ii;
typedef pair<string, int> P_si;
typedef long long int ll;

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

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

const int MOD = 1000000007;

int main() {
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    N--;

    for (ll i = 0; i <= N; ++i) {
        ll from = A + C * i - D * (N - i);
        ll to = A + D * i - C * (N - i);
        if (from <= B && B <= to) {
            printf("%s\n", "YES");
            return 0;
        }
    }
    printf("%s\n", "NO");
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long sol = 0ll;
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    for(int i = 0;i*r<=n;i++)
    {
        for(int j = 0;j*g<= n;j++)
        {
            if(n - i*r - j*g >= 0 and (n - i*r - j*g )%b == 0)
            {
                sol++;
            }
        }
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())

check = [1]+[0]*n
numlis = [1]*(n+1)

for i in range(m):
    x, y = map(int, input().split())
    if numlis[x-1] > 1 and check[x-1] == 1:
        check[y-1] = 1
        numlis[x-1] -= 1
        numlis[y-1] += 1
    elif numlis[x-1] == 1 and check[x-1] == 1:
        check[y-1] = 1
        check[x-1] = 0
        numlis[x-1] -= 1
        numlis[y-1] += 1
    else:
        numlis[x-1] -= 1
        numlis[y-1] += 1
    

print(sum(check))

Measured memory_bytes: 10436
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
string c[1000010];
int main()
{
    int h, w, k;
    cin>>h>>w>>k;
    int xs, ys, xt, yt;
    cin>>xs>>ys>>xt>>yt;
    xs--; ys--; xt--; yt--;
    for(int i=0; i<h; i++){
        cin>>c[i];
    }
    const int INF=1e9+7;
    vector<vector<int>> d(h, vector<int>(w, INF));
    d[xs][ys]=0;
    queue<P> que;
    que.push({xs, ys});
    int dx[4]={1, -1, 0, 0}, dy[4]={0, 0, 1, -1};
    while(!que.empty()){
        P p=que.front(); que.pop();
        int x=p.first, y=p.second;
        for(int t=0; t<4; t++){
            for(int i=1; i<=k; i++){
                int x1=x+dx[t]*i, y1=y+dy[t]*i;
                if(x1<0 || x1>=h || y1<0 || y1>=w || c[x1][y1]=='@' || d[x1][y1]<=d[x][y]) break;
                if(d[x1][y1]>d[x][y]+1){
                    d[x1][y1]=d[x][y]+1;
                    que.push({x1, y1});
                }
            }
        }
    }
    if(d[xt][yt]==INF) cout<<-1<<endl;
    else cout<<d[xt][yt]<<endl;
    return 0;
}


Measured memory_bytes: 43340
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int>pl(n);
  for(int i=0;i<n;i++){
    int t;cin>>t;t--;
    pl[t]=i;
  }
  int l=0,cnt=0,p=-1;
  for(int i=0;i<n;i++){
    if(p<pl[i]){
      cnt ++;
    }
    else{
      l=max(l,cnt);
      cnt=1;
    }
    p=pl[i];
  }
  l=max(l,cnt);
  cout<<n-l<<endl;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

llong findSumOfDigits(llong n)
{
    llong sum = 0;
    while (n > 0) { // n が 0 になるまで
        sum += n % 10;
        n /= 10;
    }
    return sum;
}


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

    string divide[4] = {"dream", "dreamer", "erase", "eraser"};
    string S;
    cin>>S;
    reverse(S.begin(),S.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for (int i = 0; i < S.size();)
    {
        bool can2 = false; // 4 個の文字列たちどれかで divide できるか
        for (int j = 0; j < 4; ++j) 
        {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) { // d で divide できるか
                can2 = true;
                i += d.size(); // divide できたら i を進める
                }
     }
        if (!can2) { // divide できなかったら
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;



}

Measured memory_bytes: 512
method = {"+": lambda a, b: a + b,
		  "-": lambda a, b: a - b,
		  "*": lambda a, b: a * b,
		  "/": lambda a, b: a / b}
		
while True:
	args = raw_input().split(" ")
	if args[1] == "?":
		break
	else:
		a = int(args[0])
		op = args[1]
		b = int(args[2])
		print method[op](a,b)
			

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

struct UnionFind {
	vector<ll> data;

	UnionFind(ll sz) {
		data.assign(sz, -1);
	}

	bool unite(ll x, ll y) {
		x = find(x), y = find(y);
		if (x == y) return(false);
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return(true);
	}

	ll find(ll k) {
		if (data[k] < 0) return(k);
		return(data[k] = find(data[k]));
	}

	ll size(ll k) {
		return(-data[find(k)]);
	}
};


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

	int n, m;
	cin >> n >> m;
	vector<ll> a(m), b(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}


	UnionFind uf(n);
	vector<ll> ans;
	ll score = n * (n - 1LL) / 2LL;
	for (int i = m - 1; i >= 0 ; i--) {
		ans.push_back(score);

		ll aa = uf.find(a[i]), bb = uf.find(b[i]);
		if (aa == bb) {
			continue;
		}

		score -= uf.size(a[i]) * uf.size(b[i]);
		uf.unite(a[i], b[i]);
		continue;
	}

	reverse(begin(ans), end(ans));

	for (auto v : ans) {
		cout << v << endl;
	}
	return 0;
}


Measured memory_bytes: 4596
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N), rev(N);
    for(int i = 0; i < M; ++i){
        int a, b;
        cin >> a >> b;
        graph[a].emplace_back(b);
        rev[b].emplace_back(a);
    }
    
    vector<int> vs;
    vector<bool> used(N, false);
    auto dfs = [&](auto&& self, int from) -> void {
        used[from] = true;
        for(int to : graph[from]){
            if(!used[to])   self(self, to);
        }
        vs.emplace_back(from);
    };
    for(int v = 0; v < N; ++v){
        if(!used[v])    dfs(dfs, v);
    }
    reverse(vs.begin(), vs.end());
    
    vector<int> idx(N, -1);
    int K = 0;
    auto rdfs = [&](auto&& self, int from) -> void {
        idx[from] = K;
        for(int to : rev[from]){
            if(idx[to] == -1)   self(self, to);
        }
    };
    for(int v : vs){
        if(idx[v] == -1){
            rdfs(rdfs, v);
            ++K;
        }
    }
    
    vector<vector<int>> scc_set(K);
    for(int v = 0; v < N; ++v){
        scc_set[idx[v]].emplace_back(v);
    }
    
    cout << K << '\n';
    for(int i = 0; i < K; ++i){
        int num = scc_set[i].size();
        cout << num << ' ';
        for(int j = 0; j < num; ++j){
            cout << scc_set[i][j];
            cout << ((j == num - 1) ? '\n' : ' ');
        }
    }
}

Measured memory_bytes: 79568
#include <stdio.h>

int n, cards[5][14];

int ctoi(char c) {
    switch (c) {
    case 'S': return 1;
    case 'H': return 2;
    case 'C': return 3;
    case 'D': return 4;
    }
}

char itoc(int i) {
    switch (i) {
    case 1: return 'S';
    case 2: return 'H';
    case 3: return 'C';
    case 4: return 'D';
    }
}

int main(void) {
    int i, j, rank;
    char suit[2];
    
    scanf("%d", &n);
    
    for (i = 0; i < n; ++i) {
        scanf("%s %d", suit, &rank);
        ++cards[ctoi(suit[0])][rank];
    }
    
    for (i = 1; i <= 4; ++i) {
        for (j = 1; j <= 13; ++j) {
            if (!cards[i][j]) {
                printf("%c %d\n", itoc(i), j);
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 596
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
list.sort(a, reverse=True)
ans = a[0]
for i in range((n-1)//2):
    ans += a[i+1]*2
if n % 2 == 1:
    ans -= a[i+1]
print(ans)


Measured memory_bytes: 31564
n=int(input())
a=[0]+list(map(int,input().split()))
sm=0
for i in range(n):
  sm+=abs(a[i+1]-a[i])
sm+=abs(a[n])

for i in range(n-1):
  print(sm-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i]))

print(sm-abs(a[n-1]-a[n])-abs(a[n])+abs(a[n-1]))


Measured memory_bytes: 20568
# frozen_string_literal: true

x, y = gets.split.map(&:to_i)

sum = 0
[x, y].each do |i|
  if i == 1
    sum += 300000
  elsif i == 2
    sum += 200000
  elsif i == 3
    sum += 100000
  end
end
sum += 400000 if x == 1 && y == 1

puts sum


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
#include<string>
#include<deque>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define pii(p)			pair<int,int> p
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
const double PI	 = 3.141592;
const int	 MOD = 1e9 + 7;
using namespace std;

void solve() {
	int q, t, f;
	bool re = false;
	char c;
	string str;	cin >> str;
	deque<char> s(str.size());
	for(int i = 0; i < str.size(); ++i) s[i] = str[i];
	cin >> q;
	for(int i = 0; i < q; ++i) {
		cin >> t;
		if(t == 1) { re = !re; continue;}
		cin >> f;
		cin >> c;
		if(f == 1) {
			if(re) s.push_back(c);
			else s.push_front(c);
		}
		else {
			if(re) s.push_front(c);
			else s.push_back(c);
		}
	}
	if(re)
		for(int i = s.size()-1; i >= 0; --i) cout << s[i];
	else
		for(int i = 0; i < s.size(); ++i) cout << s[i];
	cout << endl;
}

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

Measured memory_bytes: 3928
#include<stdio.h>
#include<math.h>

int toT(int a,int b,int t)
{
	double x,y;
	y=a*((100.0+t)/100)+0.000000001;
	x=b*((100.0+t)/100)+0.000000001;
	return floor(x)+floor(y);
}

int main()
{
	int x,y,s,i,j,r;
	for(;scanf("%d%d%d",&x,&y,&s),x+y+s;)
	{
		r=0;
		for(i=1;i<s;i++)
			for(j=1;j<s;j++)
			{
				if(toT(i,j,x)==s)
					r=r>toT(i,j,y)?r:toT(i,j,y);
			}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 600
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

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

N = In.str()

if N[-1] in ["2","4","5","7","9"]:
    Out.str("hon")
elif N[-1] in ["0","1","6","8"]:
    Out.str("pon")
else:
    Out.str("bon")

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

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Measured memory_bytes: 67972
N=int(input())
Flist=[]
for a in range(N):
    list=[]
    F=input().split()
    for b in F:
        list.append(int(b))
    Flist.append(list)
Plist=[]
for a in range(N):
    list=[]
    F=input().split()
    for b in F:
        list.append(int(b))
    Plist.append(list)
FFlist=[]
for a in range(N):
    list=[]
    item = Flist[a]
    n = len(item)
    for i in range(2 ** n):
        bag = []
        for j in range(n):
            if ((i >> j) & 1):
                bag.append(item[j])
        z=sum(bag)
        list.append(z)
    del list[0]
    FFlist.append(list)
goukei=[]
for a in range(2**10-1):
    c=0
    for b in range(N):
        c+=Plist[b][FFlist[b][a]]
    goukei.append(c)
print(max(goukei))


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define mx 100001
typedef long long L;
L ar[mx+5],sum=0,mn=99999999999999999;
void solve(L n){
	for(L i=0;i<n-1;i++){
		mn=min(mn,abs(ar[i]));
		sum+=(abs(ar[i]));
		if(ar[i]<0){
			ar[i+1]=(ar[i+1]*(-1));
		}
	}
	mn=min(mn,abs(ar[n-1]));
	sum+=abs(ar[n-1]);
	//cout<<mn<<" "<<sum<<" "<<ar[n-1]<<endl;
	if(ar[n-1]<0){
		sum-=(mn*2);
	}
}

int main()
{
	L n;
	scanf("%lld",&n);
	for(L i=0;i<n;i++)scanf("%lld",&ar[i]);
	solve(n);
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 1024
MOD = 10 ** 9 + 7


def main():
  L = input().strip()
  l = len(L)
  assert l > 0

  dp1 = [-1] * l
  dp2 = [-1] * l
  dp1[0] = 1
  dp2[0] = 2
  for k in range(1, l):
    dp1[k] = dp1[k - 1] * 3 % MOD

    if L[k] == '1':
      dp1[k] += dp2[k - 1]
      dp2[k] = dp2[k - 1] * 2 % MOD
    else:
      dp2[k] = dp2[k - 1]

  return (dp1[-1] + dp2[-1]) % MOD


if __name__ == '__main__':
  print(main())

Measured memory_bytes: 41072
#include<cstdio>
#include<algorithm>
using namespace std;
const int MOD = 998244353;
const int MAXN = 100000;
char S[3*MAXN + 5];
int func(char ch) {
	if( ch == 'R' ) return 0;
	else if( ch == 'G' ) return 1;
	else return 2;
}
int main() {
	int N; scanf("%d%s", &N, S + 1);
	int c[3] = {}, b[3] = {}, ans = 1;
	for(int i=1;i<=3*N;i++) {
		if( c[func(S[i])] ) {
			ans = 1LL*ans*c[func(S[i])]%MOD;
			c[func(S[i])]--;
		}
		else if( b[(func(S[i])+1)%3] ) {
			c[(func(S[i])+2)%3]++;
			ans = 1LL*ans*b[(func(S[i])+1)%3]%MOD;
			b[(func(S[i])+1)%3]--;
		}
		else if( b[(func(S[i])+2)%3] ) {
			c[(func(S[i])+1)%3]++;
			ans = 1LL*ans*b[(func(S[i])+2)%3]%MOD;
			b[(func(S[i])+2)%3]--;
		}
		else b[func(S[i])]++;
	}
	int fct = 1;
	for(int i=1;i<=N;i++)
		fct = 1LL*fct*i%MOD;
	printf("%lld\n", 1LL*ans*fct%MOD);
}

Measured memory_bytes: 512