akhauriyash/Code-Regression huggingface dataset:
import numpy as np
import sys
# import copy


def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


def sp_xnxn(n=0):
    """
    args:
        int n: a number of lows to read
    example
        input   1
        retrun  [1]

        input   123
        return  [1,2,3]

        input   123
                4
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        return [int(k) for k in xsxs()]
    else:
        return [[int(k) for k in xsxs()] for _ in range(n)]


def xsxs(n=0):
    """
    args:
        int n: a number of lows to read
    example:
        input   AA
        retrun  AA

        input   A BBB CC
        return  ["A","BBB","CC"]

        input   A BB CCC
                D
        return  [["A","BBB","CC"],
                ["D"]]
    """
    if n == 0:
        temp = list(input().split())
        if len(temp) == 1:
            return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        return [list(input().split()) for _ in range(n)]


def sp_xsxs(n=0):
    """
    args:
        int n: a number of lows to read
        example:
            input   A
            retrun  ["A"]

            input   ABC
            return  ["A","B","C"]

            input   ABC
                    D
            return  [["A","B","C"],
                    ["D"]]
    """
    if n == 0:
        return [s for s in xsxs()]
    else:
        return [[s for s in xsxs()] for _ in range(n)]


a, b, h, m = xnxn()

ans = np.sqrt(a ** 2 + b ** 2 - 2 * a * b *
              np.cos(2 * np.pi * (1 / 60 * m - 1 / (12*60) * (60*h+m))))

print(ans)


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

#define cerr cout
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

struct item {
    int s, w, v;
    item(int s, int w, int v):s(s), w(w), v(v) {}
    bool operator<(const item& o) {
        return s+w < o.s+o.w;
    }
};

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

    int n; cin >> n;
    vector<item> a;
    FOR (i, 0, n - 1) {
        int w, s, v; cin >> w >> s >> v;
        a.emplace_back(s, w, v);
    }
    sort(all(a));
    vector<ll> dp(3e4);
    FOR (i, 0, n - 1) {
        NFOR (j, a[i].s, 0) {
            dp[j + a[i].w] = max(dp[j + a[i].w], dp[j] + a[i].v);
        } 
    }
    cout << *max_element(all(dp));

    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc142_c.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<P> c(N);
  rep(i, N) {
    int a;
    cin >> a;
    c[i] = make_pair(a, i);
  }

  sort(c.begin(), c.end());

  rep(i, N) {
    cout << c[i].second + 1 << endl;
  }
}

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

int main(){
    int a, b;
    cin >> a >> b;
    string S;
    cin >> S;
    for(int i=0; i<a; i++){
        if(S[i]=='-'){
            goto NO;
        }
    }
    if(S[a]!='-') goto NO;
    for(int i=a+1; i<S.length(); i++){
        if(S[i]=='-'){
            goto NO;
        }
    }
    cout << "Yes" << endl;
    goto END;
NO:
    cout << "No" << endl;

END:
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int h, w;
    cin >> h >> w;
    vector<string> pixels;
    vector<string> ans;
    for(int i=0;i<h;i++) {
        string s;
        cin >> s;
        pixels.push_back(s);
    }
    for(int i=0;i<2*h;i++)
    {
        string s="";
        for(int j=0;j<pixels[(i)/2].size();j++)
        {
            s += pixels[(i/2)][j];
        }
        ans.push_back(s);
    }
    for(int i=0;i<ans.size();i++)
        cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    cin>>s;
    ll count=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i+1]!=s[i])
            count++;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 512
class Node:
    def __init__(self, id):
        self.id = id
        self.left = None
        self.right = None
        self.parent = None

    def getId(self):
        return self.id

    def setRight(self, right):
        self.right = right

    def setLeft(self, left):
        self.left = left

    def getLeft(self):
        return self.left

    def setParent(self, parent):
        self.parent = parent

    def isRoot(self):
        return self.parent is None

    def preorder(self):
        print('', self.id, end='')
        if self.left is not None:
            self.left.preorder()
        if self.right is not None:
            self.right.preorder()

    def inorder(self):
        if self.left is not None:
            self.left.inorder()
        print('', self.id, end='')
        if self.right is not None:
            self.right.inorder()

    def postorder(self):
        if self.left is not None:
            self.left.postorder()
        if self.right is not None:
            self.right.postorder()
        print('', self.id, end='')

    def printInfo(self):
        if self.left is None:
            left = -1
        else:
            left = self.left.getId()
        if self.right is None:
            right = -1
        else:
            right = self.right.getId()
        print("{} {} {}".format(self.id, left, right))

n = int(input())

nodes = []

for i in range(n):
    nodes.append(Node(i))

for i in range(n):
    id, left, right = map(int, input().split())
    if left != -1:
        nodes[id].setLeft(nodes[left])
        nodes[left].setParent(nodes[id])
    if right != -1:
        nodes[id].setRight(nodes[right])
        nodes[right].setParent(nodes[id])

def getRootNode(nodes):
    for e in nodes:
        if e.isRoot():
            return e
    return None

def getLeftNode(nodes):
    node = getRootNode(nodes)
    while True:
        left = node.getLeft()
        if left is not None:
            node = left
        else:
            return node
    return None

def preorder(nodes):
    print('Preorder')
    root = getRootNode(nodes)
    root.preorder()
    print('')

def inorder(nodes):
    print('Inorder')
    root = getRootNode(nodes)
    root.inorder()
    print('')

def postorder(nodes):
    print('Postorder')
    root = getRootNode(nodes)
    root.postorder()
    print('')

preorder(nodes)
inorder(nodes)
postorder(nodes)



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

typedef long long LL;

LL Divide_ans(LL n){
  if (!n) return 0;
  else if (n==1) return 1;
    else return (Divide_ans(n>>1)<<1)+1;
}

int main(){
  LL n;
  scanf("%lld",&n);
  printf("%lld\n",Divide_ans(n));
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char[] array = s.toCharArray();
        Arrays.sort(array);
        if (array[0] == array[1] && array[1] != array[2] && array[2] == array[3]) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

int cnt[1000000];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;cin>>n>>k;
    set<int> b;
    memset(cnt,-1,sizeof cnt);
    f(n){
        int x;
        cin>>x;
        b.insert(x);
        if(cnt[x]==-1) cnt[x]=1;
        else ++cnt[x];
    }
    vi v;
    f(n){
        v.pb(cnt[i+1]);
    }
    sort(all(v));
    int ans=0;
    int tot=sz(b);
    for(auto x:v){
        if(x==-1) continue;
        if(tot<=k){
            break;
        }
        ans+=x;
        --tot;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 14712
#include <string>
#include <time.h>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <utility>
#include <iostream>
#include <cmath>
#include <deque>

#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair

typedef long long ll;
using namespace std;
#define MAXN 228228
#define MOD 1000000007
ll x, y, n, m, k;
ll a[505][505];
vector<ll> f, g;
int main() {
    cin >> n;
    if (1) {
        k = 0;
        for (int i = 20; i >= 0; i--) {
            ll x = (1 << i);
            if (x < n) {
                k++;
                f.clear();
                g.clear();
                for (int j = 0; j < n; j++) {
                    if (j % (2 * x) < x) {
                        f.push_back(j);
                    } else {
                        g.push_back(j);
                    }
                }
                if (f.empty() || g.empty()) {
                    cout << n << " " << "Hyu" << endl;
                }
                for (int l = 0; l < f.size(); l++) {
                    for (int j = 0; j < g.size(); j++) {
                        a[f[l]][g[j]] = a[g[j]][f[l]] = k;
                    }
                }
            }
        }
        for (int j = 0; j < n - 1; j++) {
            for (int k = j+1; k < n; k++) {
                cout << a[j][k];
                if (k != n-1) {
                    cout << " ";
                }
            }
            cout << endl;
        }
    }
    return 0;
}

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

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (ll i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

void Main();
void DebugMain() {
	while (true) {
		Main();
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

inline void Main() {
	vector<int> v(6);
	int count[4]{0,0,0,0};
	for (int i = 0; i < 6; ++i) {
		cin >> v[i];
		count[v[i] - 1]++;
	}
	for (int i = 0; i < 4; ++i) {
		if (count[i] >= 3) {
			cout << "NO\n";
			return;
		}
	}
	cout << "YES\n";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
  string s;
  cin >> s;
  size_t len = s.length();
  uint64_t count_b = 0;
  uint64_t ans = 0;
  for (auto i = 0; i < len; i++) {
    if (s[i] == 'B') {
      count_b++;
    } else {
      ans += count_b;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 832
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323
#define nu          pair<ll,pll>



void solve()
{
       ll l,r; cin>>l>>r;
       if(r-l+1>=2019) { cout<<0<<endl; return; }
       else
       {
              l %= 2019;
              r %= 2019;
              ll ans=10000;
              if(l<r)
              {
                     for(ll i=l; i<r; i++)
                     {
                            for(ll j=i+1; j<=r; j++)
                            {
                                   ans = min(ans, (i*j)%2019);
                            }
                     }
                     cout<<ans<<endl;
                     return;
              }
              else
              {
                     vector<ll>a;
                     for(ll i=r; i<2018; i++) a.push_back(i);
                     for(ll i=0; i<=l; i++) a.push_back(i);
                     for(ll x : a)
                     {
                            for(ll y : a)
                            {
                                   if(x==y) continue;
                                   ans = min(ans, (x*y)%2019);
                            }
                     }
                     cout<<ans<<endl;
                     return;
              }
       }
}



int main() {
	ll T = 1;
	//speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


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

using namespace std;

template <typename T=int>
struct Fenwick {
    int n;
    vector<T> v;
    
    Fenwick(int size = 100005) : n(size), v(n+1, 0) {}
    inline void add(int p, T val) {
        for (; p <= n; p += (p&-p)) { v[p] += val; }
    }
    inline T query(int p) {
        T tmp = 0;
        for (; p > 0; p -= (p&-p)) { tmp += v[p]; }
        return tmp;
    }
    inline T query(int l, int r) {
        return query(r) - query(l-1);
    }
};

const int N = 2019; 
int b_as_back[N][N];
int w_as_back[N][N];
int dp[N][N];

void solve() {
    int n; cin >> n;
    vector<int> pos_b(n+1), pos_w(n+1);
    for (int i = 1; i <= 2*n; i++) {
        char c;int x;
        cin >> c >> x;
        if (c == 'B') pos_b[x] = i;
        if (c == 'W') pos_w[x] = i;
    }
    auto calc_base = [&](auto& pos){
        Fenwick<int> f(2*n);
        int sum = 0;
        for (int i = n; i >= 1; i--) {
            int p = pos[i];
            sum += f.query(p);
            f.add(p, 1);
        }
        return sum;
    };
    int base = calc_base(pos_b) + calc_base(pos_w);
    auto calc_cross = [&](auto& B, auto& W, auto& b){
        Fenwick<int> f(2*n);
        for (int j = n; j >= 0; j--) {
            for (int i = 1; i <= n; i++) {
                b[i][j] = f.query(B[i]);
            }
            if (j) f.add(W[j], 1);
        }
    };
    calc_cross(pos_b,pos_w,b_as_back);
    calc_cross(pos_w,pos_b,w_as_back);
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (!i && !j) dp[i][j] = 0;
            if (!i) {dp[i][j] = dp[i][j-1]+w_as_back[j][i]; continue;}
            if (!j) {dp[i][j] = dp[i-1][j]+b_as_back[i][j]; continue;}
            dp[i][j] = min(dp[i-1][j]+b_as_back[i][j], dp[i][j-1]+w_as_back[j][i]);
        }
    }
    int res = dp[n][n] + base;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 47872
#include<stdio.h>
#include<string.h>
#include<stdbool.h>

int main(){
  char S[100001];
  scanf("%s", S);

  bool isOk = false;
  bool isEnd = false;
  int tag = 0;
  int count = 0;

  while(!isEnd){
    if(tag == 0){
      if(S[count] == 'd'){
        tag = 1;
        count ++;
      }else if(S[count] == 'e'){
        tag = 11;
        count ++;
      }else if(S[count] == '\0'){
        isOk = true;
        break;
      }else{
        break;
      }
    }
    if(tag == 1){
      if(S[count] == 'r'){
        tag = 2;
        count ++;
      }else{
        break;
      }
    }
    if(tag == 2){
      if(S[count] == 'e'){
        tag = 3;
        count ++;
      }else{
        break;
      }
    }
    if(tag == 3){
      if(S[count] == 'a'){
        tag = 4;
        count ++;
      }else{
        break;
      }
    }
    if(tag == 4){
      if(S[count] == 'm'){
        tag = 5;
        count ++;
      }else{
        break;
      }
    }
    if(tag == 5){
      if(S[count] == 'e'){
        tag = 6;
        count ++;
      }else if(S[count] == 'd'){
        tag = 1;
        count ++;
      }else if(S[count] == '\0'){
        isOk = true;
        break;
      }else{
        break;
      }
    }
    if(tag == 6){
      if(S[count] == 'r'){
        tag = 7;
        count ++;
      }else{
        break;
      }
    }
    if(tag == 7){
      if(S[count] == 'a'){
        tag = 13;
        count ++;
      }else if(S[count] == 'e'){
        tag = 11;
        count ++;
      }else if(S[count] == 'd'){
        tag = 1;
        count ++;
      }else if(S[count] == '\0'){
        isOk = true;
        break;
      }else{
        break;
      }
    }
    if(tag == 11){
      if(S[count] == 'r'){
        tag = 12;
        count ++;
      }else{
        break;
      }
    }
    if(tag == 12){
      if(S[count] == 'a'){
        tag = 13;
        count ++;
      }else{
        break;
      }
    }
    if(tag == 13){
      if(S[count] == 's'){
        tag = 14;
        count ++;
      }else{
        break;
      }
    }
    if(tag == 14){
      if(S[count] == 'e'){
        tag = 15;
        count ++;
      }else{
        break;
      }
    }
    if(tag == 15){
      if(S[count] == 'r'){
        tag = 16;
        count ++;
      }else if(S[count] == 'd'){
        tag = 1;
        count ++;
      }else if(S[count] == 'e'){
        tag = 11;
        count ++;
      }else if(S[count] == '\0'){
        isOk = true;
        break;
      }else{
        break;
      }
    }
    if(tag == 16){
      if(S[count] == 'a'){
        tag = 13;
        count ++;
      }else if(S[count] == 'd'){
        tag = 1;
        count ++;
      }else if(S[count] == 'e'){
        tag = 11;
        count ++;
      }else if(S[count] == '\0'){
        isOk = true;
        break;
      }else{
        break;
      }
    }
  }

  if(isOk){
    printf("%s\n", "YES");
  }else{
    printf("%s\n", "NO");
  }

  return 0;
}


Measured memory_bytes: 1744
from collections import Counter
import copy
from itertools import combinations


def A(x):
  return 1000 - x % 1000 if x % 1000 != 0 else 0


def B(n, ss):
  keys_values = Counter(ss)
  orders = ['AC', 'WA', 'TLE', 'RE']
  for order in orders:
    if order in keys_values:
      print("{} x {}".format(order, keys_values[order]))
    else:
      print("{} x {}".format(order, 0))


def _get_num_black(c_list, r_list, h, w, g):
  num_black = 0
  for i in range(h):
    if i in r_list:
      continue
    for j in range(w):
      if j in c_list:
        continue
      num_black += (1 if g[i][j] == '#' else 0)
  return num_black


def C(h, w, k, g):
  num_choice = 0
  for i in range(k + 1):
    for j in range(k - i + 1):
      for c_list in list(combinations(range(w), j)):
        for r_list in list(combinations(range(h), i)):
          if _get_num_black(c_list, r_list, h, w, g) == k:
            num_choice += 1
          # print(h, i, r_list, w, j, c_list, num_black, k)
  return num_choice


def C2(H, W, K, g):
  """All copied."""
  c = []
  for i in range(H):
    c.append([])
    for j in range(W):
      c[i].append(g[i][j])

  ans = 0
  for h in range(H + 1):
    for w in range(W + 1):
      for h2 in combinations(list(range(H)), h):
        for w2 in combinations(list(range(W)), w):
          paint = copy.deepcopy(c)
          for h3 in h2:
            for i in range(W):
              paint[h3][i] = "r"
          for i in range(H):
            for w3 in w2:
              paint[i][w3] = "r"
          count_black = 0
          for i in range(H):
            count_black += paint[i].count("#")
            #print(count_black,paint[i])
          if count_black == K:
            ans += 1

  return ans


def C3(h, w, k, g):
  """
  - Change the calculation of count_black.
  - Change the name of variables.
  """
  num_choice = 0
  for i in range(h + 1):
    for j in range(w + 1):
      for h2 in combinations(list(range(h)), i):
        for w2 in combinations(list(range(w)), j):
          if _get_num_black(w2, h2, h, w, g) == k:
            num_choice += 1
  return num_choice


def main():
  h, w, k = map(int, input().split())
  g = []
  for i in range(h):
    g.append(input())
  print(C3(h, w, k, g))


if __name__ == '__main__':
  main()


Measured memory_bytes: 9628
#include<stdio.h>
#include<stdlib.h>
typedef struct Graph
{
  int key;
  int numOfAdj;
  int *adj;
  int status;//0:not discovered, 1:discovered, 2:finished
} graph;
int n;//num of vertice
graph *p;//array of vertice
int *d;//array of degree
int *queue;
int head=0,tail=0;
void breadthFirstSearch(void);
void enqueue(int);
int dequeue(void);
int main(void)
{
  int i,j;//counter
  int key,numOfAdj,adj;
  scanf("%d",&n);
  p=(graph*)malloc(sizeof(graph)*n);
  d=(int*)malloc(sizeof(int)*n);
  queue=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&key);
      scanf("%d",&numOfAdj);
      p[key-1].numOfAdj=numOfAdj;
      p[key-1].adj=(int*)malloc(sizeof(int)*numOfAdj);
      for(j=0;j<numOfAdj;j++)
        {
          scanf("%d",&adj);
          p[key-1].adj[j]=adj-1;
        }
      p[key-1].status=0;
      d[i]=-1;
    }
  breadthFirstSearch();
  return 0;
}
void breadthFirstSearch(void)
{
  int i;//counter
  int u,v;
  d[0]=0;
  enqueue(0);
  while(head!=tail)
    {
      u=dequeue();
      for(i=0;i<p[u].numOfAdj;i++)
        {
          v=p[u].adj[i];
          if(p[v].status==0)
            {
              p[v].status=1;
              d[v]=d[u]+1;
              enqueue(v);
            }
        }
      p[u].status=2;
    }
  for(i=0;i<n;i++)
    {
      printf("%d %d\n",i+1,d[i]);
    }
}
void enqueue(int key)
{
  queue[tail]=key;
  tail++;
}
int dequeue(void)
{
  head++;
  return queue[head-1];
}


Measured memory_bytes: 2104
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)    

n,m,k = map(int,input().split())

uf = UnionFind(n)
A = {i:[] for i in range(n)}
for i in range(m):
  a,b = map(int,input().split())
  a,b = a-1,b-1
  A[a].append(b)
  A[b].append(a)
  uf.union(a,b)
  
C = {i:[] for i in range(n)}
for i in range(k):
  c,d = map(int,input().split())  
  c,d = c-1,d-1
  if uf.same(c,d):
    C[c].append(d)
    C[d].append(c)
  
ans = [0]*n
for i in range(n):    
  ans[i] = uf.size(i) - len(A[i]) - len(C[i]) - 1  
print(*ans)    

Measured memory_bytes: 63816
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------

    ll n,m;
    cin >> n >> m ;
    ll i,j;
    ll a[n];
    ll b[n];
    ll c[m];
    ll d[m];

    ll ans[n];
    ll ansk[n];

    rep (i,n){
        cin >> a[i] >> b[i] ;
    }
    rep (i,m){
        cin >> c[i] >> d[i] ;
    }
    
    rep(i,n){
        ansk[i] = INF;
        rep(j,m){
            // マンハッタン距離算出
            ll kyo  = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if ( ansk[i] > kyo){
                ansk[i] = kyo;
                ans[i] = j;
            }
        } 
    }
    rep (i,n) pri(ans[i]+1);

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a>>b>>c;
  int ans;
  int max1=max(max(a,b),max(b,c));
  if(max1==a)
    ans=10*a+b+c;
  else if(max1==b)
    ans=10*b+a+c;
  else
    ans=10*c+a+b;

  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string s; cin >> s;
    int cnt1 = 0;
    int cnt2 = 0;
 
    for(int i=0; i<s.size(); i++){
        if(i%2 == 0){
            if(s[i] == '0') cnt1++;
            else cnt2++;
        }else{
            if(s[i] == '1') cnt1++;
            else cnt2++;
        }
    }
 
    cout << min(cnt1,cnt2) << endl;
}

Measured memory_bytes: 512
#include<stdio.h>

int selection_sort(int A[], int N) {

	int i, j;
	int change = 0;
	int minj;
	int tmp;

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

		tmp = A[i];
		A[i] = A[minj];
		A[minj] = tmp;

		if (minj != i) {
			change++;
		}
	}

	return change;
}

int main() {

	int N, A[100], i, change;

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	change = selection_sort(A, N);

	for (i = 0; i < N; i++) {
		if (i > 0)printf(" ");
		printf("%d", A[i]);
	}

	printf("\n");
	printf("%d\n", change);

	return 0;

}

Measured memory_bytes: 1032
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>


using namespace std;
typedef long long ll;

int N = 0;
int W = 0;

int main(){
    //ナップサック問題　荷物の価値を最大化
    cin >> N;
    cin >> W;

    vector<pair<ll, ll> > T;

    ll value = 0;
    ll weight = 0;
    ll max_value = 0;
    
    //入力
    for(int i = 0; i < N; i++){
        cin >> weight >> value;
        max_value += value;
        T.push_back(make_pair(value, weight));
    }

    //価値が大きい順にソート 
    sort(T.rbegin(), T.rend());
    //前に余白
    T.insert(T.begin(), make_pair(0, 0));

    //dp　Value　価値を基準に表を作る
    vector<vector<ll> > dp;
    dp = vector<vector<ll> >(N + 1, vector<ll>(max_value + 1, 1145141919));
    dp[0][0] = 0;

    //答え
    ll ans = 0;

    //縦：個数　横：価値　価値を達成する最小の重さで更新していく

    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= max_value; j++){
            if(dp[i - 1][j] < 1145141919){
                //直下を更新
                if(dp[i][j] >= dp[i - 1][j]){
                    dp[i][j] = dp[i - 1][j];
                }
                //荷物を足し合わせたところを更新
                if(dp[i][j + T[i].first] >= dp[i - 1][j] + T[i].second && dp[i - 1][j] + T[i].second <= W){
                    dp[i][j +T[i].first] = dp[i - 1][j] + T[i].second;
                    //ans確認
                    if(ans < j + T[i].first) ans = j + T[i].first;
                }
            }          
        }

    }

    cout << ans << endl;

    //確認
    
    /*
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= max_value; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
}

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

#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;


struct Node {
  Node(int weight, int solid, int val)
  {
    this->weight = weight;
    this->solid = solid;
    this->val = val;
  }
  int weight;
  int solid;
  int val;
};

vector <Node> arr;
ll int dp[1005][10005];


bool cmp(Node n1, Node n2)
{
  if(n1.solid + n1.weight < n2.solid + n2.weight)
    return true;
  return false;
}


ll int kil(int idx, int weight)
{
  if(weight >=10005)
    return 0;

  if(idx == arr.size())
    return 0;

  if(dp[idx][weight] != -1)
    return dp[idx][weight];

  dp[idx][weight] = 0;
  dp[idx][weight] = max(dp[idx][weight], kil(idx+1, weight));
  if(arr[idx].solid >= weight)
    dp[idx][weight] = max(dp[idx][weight], kil(idx+1, weight + arr[idx].weight) + arr[idx].val);

  return dp[idx][weight];
}


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

  memset(dp, -1, sizeof dp);
  int n, x, y, z;
  cin>>n;

  for(int i=0;i<n;i++)
  {
    cin>>x>>y>>z;
    arr.push_back(Node(x, y, z));
  }
  sort(arr.begin(), arr.end(), cmp);
  cout<<kil(0, 0)<<endl;

  return 0;
}


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

int main() {
  vector<char> data(16);
  for (int i = 0; i < 16; i++) {
    cin >> data.at(i);
  }

  string str = "CODEFESTIVAL2016";
    
  int answer = 0 ;

  for (int i = 0; i < 16; i++) {

    if (data.at(i) != str.at(i) ) {
      answer++;
    }

  }

  cout << answer << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int A,B; cin >> A >> B;
    cout << lcm(A,B) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int d, c[30], l[30], s[400][30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d)for1(j, 26)cin >> s[i][j];
	for1(i, d) {
		int p = 0, k = -mod;
		for1(j, 26) {
			int kj = s[i][j] + c[j] * (i - l[j]) * 4.5 + c[j] * 8;
			if (kj > k) { p = j; k = kj; }
			else if (kj == k && c[j] > c[p])p = j;
		}
		puts(p); l[p] = i;
	}
}

Measured memory_bytes: 3696
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string N;
    cin >> N;
    int sub = 0;
    for (char c : N) {
        sub += c - '0';
    }

    if (sub == 1) {
        cout << 10 << "\n";
    } else {
        cout << sub << "\n";
    }
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void){
    int mbls;
    int len;
    int ary[25], i;
    
    while (scanf("%d", &len)){
        if (len==0) break;
        for (int n=0; n<len; n++){
            scanf("%d", &ary[n]);
        }
        mbls=32;
        i=0;
        while(mbls>0){
            mbls -= (mbls-1)%5;
            printf("%d\n", mbls);
            if (mbls<ary[i]) mbls = 0;
            else mbls -= ary[i];
            printf("%d\n", mbls);
            i = (i+1)%len;
        }
    }
    return 0;
}

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

using ll = long long int;

const ll MAX = (ll)(1e9 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

/////////////////////////////////////////////////////////////
class BinaryIndexedTree {
public:
  static const int MAX_N_LIB = (int)(2e5 + 100);

  ll bit_bit[MAX_N_LIB];
  int bit_n;

  BinaryIndexedTree(int n) {
    bit_n = n;
    init();
  }

  void init() {
    for (int i = 0; i < bit_n; ++i) bit_bit[i] = 0LL;
  }

  ll sum(int i) {
    ll s = 0LL;
    while (i > 0) {
      s += bit_bit[i];
      i -= i & -i;
    }
    return s;
  }

  void add(int i, ll x) {
    while (i <= bit_n) {
      bit_bit[i] += x;
      i += i & -i;
    }
  }
};
/////////////////////////////////////////////////////////////

int n;
ll a[MAX_N];
ll b[MAX_N];

int s[MAX_N];

BinaryIndexedTree bit(MAX_N * 2);

bool check(ll x) {
  ll num = 0;

  s[0] = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] >= x) {
      s[i] = 1;
      // num += 1;
    }
    else {
      s[i] = -1;
    }
  }

  for (int i = 1; i <= n; ++i) s[i] += s[i - 1];

  int min_elem = n + 5;
  for (int i = 1; i <= n; ++i) min_elem = min(min_elem, s[i]);

  bit.init();

  bit.add(MAX_N, 1);

  for (int i = 1; i <= n; ++i) {
    num += bit.sum(s[i] + MAX_N);
    bit.add(s[i] + MAX_N, 1);
  }

  // printf("%lld: %d\n", x, num);

  ll whole = (1LL * (n + 1) * n) / 2;
  ll target =  (whole - 1) / 2 + 1;

  return (num >= target);
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &(a[i]));
    b[i] = a[i];
  }

  sort(b + 1, b + n + 1);

  b[n + 1] = b[n] + 1; // guard

  int ok = 1;
  int ng = n + 1;

  while (abs(ok - ng) > 1) {
    int next = (ok + ng) / 2;

    if (check(b[next])) {
      ok = next;
    }
    else {
      ng = next;
    }
  }

  printf("%lld\n", b[ok]);

  return 0;
}


Measured memory_bytes: 3712
/* Author : bhavye9499 - Bhavye Anand Gupta */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define endl "\n"
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define showArr(A,a,n) {for(int i=a; i<a+n; i++) cout << A[i] << " "; cout << endl;}
#define showPair(A,a,n) {for(int i=a; i<a+n; i++) cout << A[i].fi << " " << A[i].se << endl;}

const ll MOD = 1e9 + 7;

ll h, w, dp[1050][1050], A[1050][1050];

ll fun(ll i, ll j);

int main() {
    ios::sync_with_stdio(false);
    memset(dp, -1, sizeof(dp));
    memset(A, -1, sizeof(A));

    cin >> h >> w;
    for(int i = 0; i < h; i++) {
    	for(int j = 0; j < w; j++) {
    		char ch;
    		cin >> ch;
    		A[i][j] = (ch == '.') ? 0 : 1;
    	}
    }

    ll ans = fun(0, 0);

    cout << ans << endl;
}

ll fun(ll i, ll j) {
	if(dp[i][j] != -1)
		return dp[i][j];
	if(i >= h || j >= w || A[i][j] == 1)
		return dp[i][j] = 0;
	if(i == h-1 && j == w-1)
		return dp[i][j] = 1;
	return dp[i][j] = ((fun(i + 1, j) % MOD) + (fun(i, j + 1) % MOD)) % MOD;
}

Measured memory_bytes: 17536
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N;
vector<int> A;

void solve(void) {
    vector<int> LDS;

    LDS.push_back(A[1]);
    for(int i = 2;i <= N;i++) {
        vector<int>::iterator it = upper_bound(LDS.begin(),LDS.end(),A[i]);
        if(it == LDS.end()) {
            LDS.push_back(A[i]);
        } else {
            *it = A[i];
        }
    }

    cout<<LDS.size()<<endl;

    return;
}

int main(void) {
    cin>>N;

    A.push_back(1);
    for(int i = 0;i < N;i++) {
        int a;
        cin>>a;
        a = -1*a;
        A.push_back(a);
    }

    solve();

    return 0;
}





Measured memory_bytes: 1400
S = input()

if S == 'SUN':
    print(7)
if S == 'MON':
    print(6)
if S == 'TUE':
    print(5)
if S == 'WED':
    print(4)
if S == 'THU':
    print(3)
if S == 'FRI':
    print(2)
if S == 'SAT':
    print(1)

Measured memory_bytes: 8824
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
int n,x,w[100010],le[100010],ho[100010];
ll ans;
int main(){
	read(n);
	for (int i=1;i<=n;i++){read(x);w[x]=i;}
	for (int i=1;i<=n;i++)le[i]=i-1,ho[i]=i+1;
	for (int i=1;i<=n;i++){
		int x=le[w[i]],y=le[x];
		int z=ho[w[i]],p=ho[z];
		if (x!=0)ans+=1ll*(x-y)*(z-w[i])*i;
		if (z!=n+1)ans+=1ll*(w[i]-x)*(p-z)*i;
		ho[x]=z;le[z]=x;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<list>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;

int fac(int n) {
    if (n == 0) {
	return 1;
    } else {
	return n * fac(n-1);
    }
}
int main(){
    ll n;
    cin >> n;
    ll ans=0;
    string s;
    map<string,ll> mp;
    std::vector<string> strList(n);
    for(ll i=0;i<n;i++){
        cin >> s;
        sort(s.begin(),s.end());
        strList[i]=s;
        mp[s]++;
    }
    /*for(int i = 0;i < n;i++){
        mp[strList[i]]++;
    }*/
    for(auto it = mp.begin(); it != mp.end(); it++){ //autoはC++11から
        //if((*it).second != 1)
        ans += ((*it).second*((*it).second-1))/2; 
    }

    /*REP(i,n){
        for(int j=i+1;j<n;j++){
            if(i!=j){
                if(strList[i]==strList[j])ans++;
            }
        }
    }*/


    cout << ans << endl;

    return 0;
}



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

using namespace std ;

const int Inf = 1e9 + 5 ;

bool p[ 15 ] ;
int val[ 15 ][ 15 ] , v[ 15 ] , c[ 15 ] , n , m , x , ans = Inf ; 

int hgs() {
	int res = 0 ;
	for( int i = 1 ; i <= m ; ++i )
		if( v[ i ] < x ) return Inf ;
	for( int i = 1 ; i <= n ; ++i ) 
		if( p[ i ] ) res += c[ i ] ;
	return res ;
}

void dfs( int s ) {
	if( s > n ) {
		memset( v , 0 , sizeof v ) ;
		for( int i = 1 ; i <= n ; ++i ) {
			if( !p[ i ] ) continue ;
			for( int j = 1 ; j <= m ; ++j )
				v[ j ] += val[ i ][ j ] ;
		}
		ans = min( ans , hgs() ) ;
		return ;
	}
	p[ s ] = 1 ;
	dfs( s + 1 ) ;
	p[ s ] = 0 ;
	dfs( s + 1 ) ;
}

signed main() {
	cin >> n >> m >> x ;
	for( int i = 1 ; i <= n ; ++i ) {
		cin >> c[ i ] ;
		for( int j = 1 ; j <= m ; ++j ) cin >> val[ i ][ j ] ;
	}
	dfs( 1 ) ;
	printf( "%d\n" , ans == Inf ? -1 : ans ) ;
	return 0 ;
}

Measured memory_bytes: 3764
X = int(input())

if X >= 400 and X <= 599:
  print(8)
elif X >= 600 and X <= 799:
  print(7)
elif X >= 800 and X <= 999:
  print(6)
elif X >= 1000 and X <= 1199:
  print(5)
elif X >= 1200 and X <= 1399:
  print(4)
elif X >= 1400 and X <= 1599:
  print(3)
elif X >= 1600 and X <= 1799:
  print(2)
elif X >= 1800 and X <= 1999:
  print(1)


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


int main()
{
	ll N,K;
	cin>>N>>K;
	map<ll,ll> dict;
	rep(i,N)
	{
		ll a,b;
		cin>>a>>b;
		dict[a]+=b;
	}
	ll ans=0;
	for(pair<ll,ll> p:dict)
	{
		K-=p.second;
		if(K<=0)
		{
			ans=p.first;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x,y) x = min(x,y)

const int INF = 1e9+10;

void dfs(ve<ve<int>> &to,ve<bool> &tok, int i){
    tok[i] = true;
    for(int j: to[i]){
        if(tok[j]) continue;
        dfs(to,tok,j);
    }
    return;
}
void rdfs(ve<ve<int>> &rto,ve<bool> &rok, int i){
    rok[i] = true;
    for(int j: rto[i]){
        if(rok[j]) continue;
        dfs(rto,rok,j);
    }
    return;
}

int main(){
    int n,m,p;
    cin >> n >> m >> p;
    ve<tuple<int,int,int>> e;
    ve<ve<int>> rto(n), to(n);
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        c -= p;
        c *= -1;
        e.emplace_back(a,b,c);
        to[a].push_back(b);
        rto[b].push_back(a);
    }
    ve<bool> rok(n,false), tok(n,false), ok(n,false);
    
    dfs(to,tok,0);
    rdfs(rto,rok,n-1);
    
    rep(i,n) if(tok[i] && rok[i]) ok[i] = true;
    
    ve<int> d(n,INF);
    d[0] = 0;
    bool upd = true;
    int stp = 0;
    while(upd){
        upd = false;
        rep(i,m){
            int a,b,c;
            tie(a,b,c) = e[i];
            if(!ok[a])continue;
            if(!ok[b])continue;
            int newD = d[a] + c;
            if(newD < d[b]){
                d[b] = newD;
                upd = true;
            }
        }
        stp++;
        if(stp>n){
            cout << -1 << endl;
            return 0;
        }
    }
    int ans = max(0,-d[n-1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4068
#include <iostream>
    #include <vector>
    using namespace std;
     
    int main() {
        int N, M; cin >> N >> M;
        vector<int> G(N+1, 0);
        for (int i = 0; i < M; ++i) {
            int l, r; cin >> l >> r; --l;
            G[l]++;
            G[r]--;
        }
        for (int i = 0; i < N; ++i) G[i+1] += G[i];
        int res = 0;
        for (int i = 0; i < N; ++i) if (G[i] == M) ++res;
        cout << res << endl;
    }

Measured memory_bytes: 640
#include<iostream>
#include  <stdio.h>
#include <cstdlib>
using namespace std;

void QSort(int x[ ], int left, int right);
void Swap(int x[ ], int i, int j);

void QSort(int x[ ], int left, int right)
{
    int i, j;
    int pivot;

    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */

    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

    while (1) {                    /* 無限ループ */

        while (x[i] < pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */

        while (pivot < x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */

        Swap(x, i, j);             /* x[i] と x[j]を交換 */
        i++;                       /* 次のデータ */
        j--;
    }
    //ShowData(x, 10);               /* 途中経過を表示 */

    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}

  /* 配列の要素を交換する */
void Swap(int x[ ], int i, int j)
{
    int temp;

    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}

  /* n 個のデータを表示する */
void ShowData(int x[ ], int n)
{
    int i;

    for (i = 0; i < n ; i++)
        printf("%d  ", x[i]);
    printf("\n");
}


int main(){

    int N;
    int M;

    cin >> N;
    cin >> M;

    int X[M];
    int L[M-1];
    int i_start;
    int i_end;

    for(int n = 0 ; n < M ; n++ ) cin >> X[n];
    i_start = 0;
    i_end   = M - 1;
    QSort(X, i_start, i_end);

    for(int n = 0 ; n < M - 1; n++ ){
        L[n] = X[n+1] - X[n];
    }
    i_start = 0;
    i_end   = M - 2;
    QSort(L, i_start, i_end);

    int ans;
    ans = 0;
    for(int n = 0 ; n < M - 1 - ( N - 1 ) ; n++ ) ans = ans + L[n];

    cout << ans;
    return 0;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)
#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(V.begin(),V.end(),c))

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N;
    cin >>N;

    int ans=N/2;
    if(N==1) ans=0;
    if(N%2==0) ans--;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
 
  cin>> S;

  if(S.at(0)=='7' ||S.at(1)=='7'||S.at(2)=='7'){
    cout<< "Yes" <<endl;
  }
else {
  cout<< "No"<<endl;
}
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

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

	int N;
	cin >> N;

	double sum = 0;

	FOR(i, 0, N){
		double in;
		cin >> in;
		sum += 1.0/in;
	}

	cout << setprecision(16) << 1/sum << '\n';

}


Measured memory_bytes: 256