akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct StronglyConnectedComponents {
    private:
    vector<int> vs;
    vector<int> used;
    public:
    vector<vector<int>> gg, rg, cg; // original, reversed, scc
    vector<int> comp; // index of scc
    StronglyConnectedComponents() {}
    void build(vector<vector<int>>& g) {
        int n = g.size();
        gg.assign(n,vector<int>());
        rg.assign(n,vector<int>());
        comp.assign(n,-1);
        for ( int v = 0; v < n; v++ ) {
            for ( int u : g[v] ) {
                gg[v].push_back(u);
                rg[u].push_back(v);
            }
        }
        vs.clear();
        used.assign(n,false);
        for ( int v = 0; v < n; v++ ) {
            if ( used[v] ) continue;
            dfs(v);
        }
        int k = 0;
        used.assign(n,false);
        for ( int i = n-1; i >= 0; i-- ) {
            int v = vs[i];
            if ( used[v] ) continue;
            rdfs(v, k);
            k++;
        }
        cg.assign(n,vector<int>());
        for ( int v = 0; v < n; v++ ) {
            for ( int u : g[v] ) {
                if ( comp[v] == comp[u] ) continue;
                cg[comp[v]].push_back(comp[u]);
            }
        }
    }
    void dfs(int v) {
        used[v] = true;
        for ( int u : gg[v] ) {
            if ( used[u] ) continue;
            dfs(u);
        }
        vs.push_back(v);
    }
    void rdfs(int v, int k) {
        used[v] = true;
        comp[v] = k;
        for ( int u : rg[v] ) {
            if ( used[u] ) continue;
            rdfs(u, k);
        }

    }
};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_C&lang=jp
ll solve() {
    ll V, E, Q;
    int s, t, u, v;
    cin >> V >> E;
    vector<vector<int>> G(V);
    for ( int i = 0; i < E; i++ ) {
        cin >> s >> t;
        G[s].push_back(t);
    }
    StronglyConnectedComponents scc;
    scc.build(G);
    cin >> Q;
    vector<bool> ans;
    for ( int i = 0; i < Q; i++ ) {
        cin >> u >> v;
        ans.push_back(scc.comp[u] == scc.comp[v]);
    }
    for ( auto a : ans ) {
        cout << (a ? 1 : 0) << "\n";
    }
    return 0;
}

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


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

vector<string> a(810);
vector<vector<int>> dist(810, vector<int>(910, INF));
int main(){

    int h, w, k;
    int sx, sy;
    cin >> h >> w >> k;
    queue<pint> q;
    rep(i, h){
        cin >> a[i];
        rep(j, w){
            if(a[i][j] == 'S') a[i][j] = '.', sx = j, sy = i;
        }
    }

    q.push(make_pair(sx, sy));
    dist[sy][sx] = 0;
    int mn = INF;
    while(!q.empty()){
        int x, y;
        tie(x, y) = q.front(); q.pop();
        chmin(mn, (x+k-1)/k);
        chmin(mn, (w-x+k-2)/k);
        chmin(mn, (y+k-1)/k);
        chmin(mn, (h-y+k-2)/k);
        if(dist[y][x] == k) continue;
        rep(i, 4){
            int xx = x+dx[i];
            int yy = y+dy[i];
            if(xx < 0 or w <= xx or yy < 0 or h <= yy) continue;
            if(a[yy][xx] == '#') continue;
            if(dist[yy][xx] > dist[y][x]+1) q.push(make_pair(xx, yy)), dist[yy][xx] = dist[y][x]+1;
        }

    }

    ppp(mn+1);


    return 0;
}


Measured memory_bytes: 3840
#include <stdio.h>
int main(void){
    int a,b;
    int n;
    unsigned long long  int ans;
    
    scanf("%d %d %d", &n, &a, &b);
    
    if( a <= b) ans = (unsigned long long int)(b-a)*(n-2)+1;
    if( n == 1 && a == b) ans =  1;
    else if( n == 1) ans = 0;
    printf("%llu\n", ans);
    return 0;
}


Measured memory_bytes: 128
M, D = map(int, input().split(" "))
cnt = 0
for m in range(1, M + 1):
    for d in range(10, D + 1):
        ds = str(d)
        d1, d10 = int(ds[1]), int(ds[0])
        if d1 * d10 == m and d1 >= 2 and d10 >= 2:
            cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

vector<int> v(200001, 0);

int main(){
  int n,k;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    v[a-1]++;
  }
  sort(v.rbegin(), v.rend());
  int ind;
  bool flag=false;
  for(int i=0;i<n;i++){
    k--;
    if(k<0){
      ind=i;
      flag=true;
      break;
    }
    if(v[i]==0){
      break;
    }
  }
  int ans=0;
  if(flag){
    for(int i=ind;i<n;i++){
      if(v[i]!=0) ans+=v[i];
      else break;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c==17) cout<<"YES"<<'\n';
  else cout<<"NO"<<'\n';
  return 0;
}


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

int h;

int parent(int i){
  return i / 2;
}

int left(int i){
  return 2 * i;
}

int right(int i){
  return 2 * i + 1;
}

void maxHeapify(int *A, int i){
  int l, r, largest;
  
  l = left(i);
  r = right(i);
  
  if(l <= h && A[l] > A[i]) largest = l;
  else largest = i;
  
  if(r <= h && A[r] > A[largest]) largest = r;
  
  if(largest != i){
    swap(A[i], A[largest]);
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(int *A){
  for(int i = h / 2;i >= 1;i--) maxHeapify(A, i);
}

int main(){
  
  int a[500010];
  
  cin >> h;
  for(int i = 1;i <= h;i++) cin >> a[i];
  
  buildMaxHeap(a);
  
  for(int i = 1;i <= h;i++) cout << " " << a[i];
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 4948
import heapq

n,m = map(int,input().split())
dic = {}

for i in range(n):
  a,b = map(int,input().split())
  if a in dic:
    pass
  else:
    dic[a] = []
  
  dic[a].append(-b)
  
dic = dict(sorted(dic.items(),key=lambda x: -x[0]))

count = 0

lst = []
for i in range(1,m+1):
  if i in dic.keys():
    for num in dic[i]:
      heapq.heappush(lst, num)
  if len(lst) != 0:
    tmp = heapq.heappop(lst)
    count -= tmp
  

print(count)

Measured memory_bytes: 45404
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (let* ((s (read))
         (table (make-array 1000001 :element-type 'bit :initial-element 0))
         (f (make-array 1000001 :element-type 'int32 :initial-element -1)))
    (setf (aref table s) 1)
    (setf (aref f 1) s)
    (loop for i from 2 to 1000000
          do (let ((next (if (evenp (aref f (- i 1)))
                             (ash (aref f (- i 1)) -1)
                             (1+ (* 3 (aref f (- i 1)))))))
               (when (= 1 (aref table next))
                 (println i)
                 (return-from main))
               (setf (aref table next) 1)
               (setf (aref f i) next)))))

#-swank(main)



Measured memory_bytes: 24036
#include <bits/stdc++.h>
#define FOR(i,a,b) for(LL i=(a);i<(LL)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const LL INF=1LL<<60;
const LL MAX=1e10;
const int BITSIZE=1<<17;
const LL p=7+1e9;
const int SIZE=2*1e5;
LL nums[SIZE];
LL doubling[SIZE][20];
LL solve(int a,int b){
	if(a>=b) return 0;
	REP(i,20){
		int x=20-i-1;
		if(x && doubling[a][x]==doubling[a][x-1]) continue;
		if(doubling[a][x]<b || x==0){
			return (1LL<<x)+solve(doubling[a][x],b);
		}
	}
}
int main(){
	LL N,L,a,b;
	cin.tie(0);
	cin >> N;
	REP(i,N){
		cin >> nums[i];
	}
	cin >> L;
	nums[N]=INF;
	int s=0;
	LL now=0;
	REP(i,N+1){
		while(nums[i]-nums[s]>L){
			doubling[s++][0]=i-1;
		}
		
	}
	doubling[N][0]=N;

	FOR(j,1,20){
		REP(i,N+1){

			doubling[i][j]=doubling[doubling[i][j-1]][j-1];			
		}
	}
	LL Q;
	cin >> Q;
	REP(i,Q){
		cin >> a >> b;
		if(a>b) swap(a,b);
		printf("%lld\n",solve(a-1,b-1));
	}
	return 0;
}


Measured memory_bytes: 17280
#include <iostream>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if(a > b && a > c)
	{
		cout << b + c << endl;
	}
	else if(b > a && b > c)
	{
		cout << a + c << endl;
	}
	else
	{
		cout << a + b << endl;
	}
	return 0;
}

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

using namespace std;

int n,m,al[100010],in[100010],st[100010],top,res[100010],res1;
vector<int> a[100010];
deque<int> d;

void dfs(int u,int p)
{
	al[u]=1;
	for (int i=0;i<a[u].size();i++)
	{
		int v=a[u][i];
		if (al[v]) continue;
		if (p) d.push_front(v);
		else d.push_back(v);
		dfs(v,p);
		break;
	}
}

int main()
{
	//freopen("input.txt","r",stdin);
	cin >> n >> m;
	for (int i=1;i<=m;i++)
	{
		int u,v;
		cin >> u >> v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	for (int i=1;i<=n;i++)
	{
		if (!a[i].size()) continue;
		d.push_front(i);
		dfs(i,0);
		dfs(i,1);
		break;
	}
	cout << d.size() << "\n";
	while (d.size()) cout << d.front() << " ",d.pop_front();
}

Measured memory_bytes: 11392
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    ll N, M; cin >> N >> M;

    vector<ll> A(N), B(N);
    vector<pair<ll, ll> > AB(N);
    rep(i, N) {
        cin >> A[i] >> B[i];
        AB[i] = make_pair(A[i], B[i]);
    }
    sort(AB.begin(), AB.end());
    ll hon = 0, ned=0;
    rep(i, N) {
        hon += AB[i].second;
        if (hon < M) {
            ned += AB[i].first * AB[i].second;
        }
        else {
            ned += AB[i].first * AB[i].second;
            ned -= AB[i].first * (hon - M);
            break;
        }
    }
    cout << ned << endl;
}

Measured memory_bytes: 3456
#include<stdio.h> 
int main(void){
	

 int a,b,c;
	int count=0;
	int i;
	scanf("%d %d %d",&a,&b,&c); 
	for(i=a;i<=b;i++)
	{ 
		if(c%i==0) count++; 
	}   
	printf("%d\n",count); 
	return 0;
}

Measured memory_bytes: 596
def main():  
  import sys
  input = sys.stdin.readline
  n,p = [int(i) for i in input().split()]
  s = input()
  ans = 0
  import collections
 
  if p == 2 or p == 5:
      for i in range(n):
          if int(s[i]) % p == 0:
              ans += i + 1
      print(ans)
      exit()
 
  else:
    chk = []
    m = 0
    chk = collections.deque(chk)
    for i in range(n)[::-1]:
      m = (int(s[i])*pow(10,n-1-i,p)+m)%p
      chk.append(m)
    chk.append(0)
    chk = list(chk)
    c = collections.Counter(chk)
    for i in range(p):
      ans += c[i]*(c[i]-1)/2
    print(int(ans))
if __name__ == '__main__':
    main()

Measured memory_bytes: 12944
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<string>
#include<stack>
#include<algorithm>

using namespace std;

void slove(){
    long long n,d;
    int ans = 0;
    long long a,b;
    cin>>n>>d;
    for(int i = 0; i < n; ++i){
        cin>>a>>b;
        if((a*a + b*b) <= (d*d)) ans++;
    }
    cout<<ans<<endl;
}

int main(){
    slove();
}

Measured memory_bytes: 3628
import Data.Bits
import Data.List
main = do
  [n,k] <- map read . words <$> getLine
  as <- map read . words <$> getLine :: IO [Integer]
  let step xs i
        | length ys < k = xs
        | otherwise = ys
        where ys = filter (`testBit` i) xs
      bs = concatMap (scanl (+) 0) $ init $ tails as
  print $ foldl1 (.&.) $ foldl step bs [40,39..0]

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

int pos[20001], height[20001], hmax[20001], l[10000];

int main() {
    string data;
    int p, i, len, m, s, d, k, A;

    getline(cin, data);
    height[0] = 0;
    for (i = 0, len = data.size(); i < len; i++) {
        switch (data[i]) {
            case '\\': d = -1; break;
            case '/': d = 1; break;
            case '_': d = 0; break;
            default: break;
        }
        height[i+1] = height[i] + d;
    }
    hmax[len] = height[len];
    for (i = len; i > 0; i--) {
        hmax[i-1] =  height[i-1] < hmax[i] ? hmax[i]: height[i-1];
    }
    p = 0;
    for (i = 0, p = 0, s = 0, k = 0, A = 0;
         i < len; i++) {
        switch (data[i]) {
            case '\\':
            pos[p++] = i;
            break;
            case '/':
            if (p > 0) {
                s += i - pos[--p];
                if (p == 0 || hmax[i+1] == height[i+1]) {
                    l[k++] = s;
                    A += s;
                    s = 0;
                }
            }
            break;
            default: break;
        }
    }
    cout << A << endl << k;
    for (i = 0; i < k; i++) {
        cout << " " << l[i];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1460
player = {}

player['a'] = list(input())
player['b'] = list(input())
player['c'] = list(input())
flag = 1
next_player = player['a'][0]
player['a'].pop(0)
while flag:
    if player[next_player]:
        before_player = next_player
        next_player = player[next_player][0]
        player[before_player].pop(0)
    else:
        print(next_player.upper())
        break


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>

using namespace std;

const int TARO = 1, HANAKO = 2;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    int L[201];
    fill(L, L+2*n+1, HANAKO);
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      L[x] = TARO;
    }
    int b = 0, t = n, h = n;
    for (bool s = true; t && h; s = !s) {
      int *p = find(L+1+b, L+2*n+1, s ? TARO : HANAKO);
      if (p == L+2*n+1)
        b = 0;
      else {
        b = p-L-1;
        *p = 0;
        (s ? t : h)--;
      }
    }
    printf("%d\n%d\n", h, t);
  }
}

Measured memory_bytes: 0
S0 = input()
N = len(S0)
S1 = S0[:(N - 1) // 2]
S2 = S0[((N + 3) // 2) - 1:]

def isPal(a):
    if(len(a) % 2 == 0):
        l = len(a) // 2
    else:
        l = (len(a) - 1) // 2

    for i in range(l):
        if (a[i-1] != a[-i]):
            return False

    return True

if (isPal(S0) and isPal(S1) and isPal(S2)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------

A,B = map(int,input().split())
S = input().rstrip()

sa,sb = S[:A],S[A+1:]
cond = sa.count("-") == 0 and sb.count("-") == 0 and S[A] == "-"
print("Yes" if cond else "No")


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll A,B,K;cin >> A >> B >> K;
  if(A>K) A-=K;
  else{
    K -= A;
    A = 0;
    B = max(0ll, B-K);
  }
  cout << A SP B << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define in(e,l) (std::find(l.begin(), l.end(), e) != l.end())
#define asort(l) (std::sort(l.begin(), l.end()))
#define dsort(l) (std::sort(l.rbegin(), l.rend()))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;

int main() {
  string s,t;
  cin >> s >> t;
  ll lst = 0;
  ll column = 0;
  for(ll i = 0; i < t.size(); ++i) {
    lst = s.find(t[i],lst);
    if(lst != -1) {
      ++lst;
      ll tmp = lst % s.size();
      if (tmp != lst){
        ++column;
        lst = tmp;
      }
      continue;
    }
    ++column;
    lst = 0;
    lst = s.find(t[i], lst);
    if(lst == -1){
      cout << -1 << endl;
      return 0;
    }
    ++lst;
  }
  cout << column * s.size() + lst << endl;

  return 0;
}



Measured memory_bytes: 640
import java.util.*;

//Linear Search
public class Main {
    public static void main(String[] args) {
        int count = 0;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[10000 + 1];
        for(int i = 0; i<n; i++){
            A[i] = sc.nextInt();
        }

        int q = sc.nextInt();
        int[] Key = new int[10000 + 1];
        for(int i = 0; i<q; i++){
            Key[i] = sc.nextInt();
            if(search(A, n, q, Key[i]) == 1){
                count++;
            }
        }
        System.out.println(count);

    }

    public static int search(int[] A, int n, int q, int Key) {
        int i, j;
        int sum = 0;
        for(i = 0; i<n; i++){
                if(Key != A[i]){
                    sum++;
                }
        }
        if(sum == n){
            return 0;
        }
        return 1;
    }
}


Measured memory_bytes: 39700
#include <iostream>

using namespace std;

int main ()
{
  long int a; int b;
  cin >> a >> b;
  const int e = b;
  int c[e];
  for (int i = 0; i < b; i++) {
      cin >> c[i]; }
     long int d = 0;
     for (int i = 0; i < b; i++) {
         d += c[i]; }
    cout << (a < d ? -1 : a - d) << '\n';
    }
     
  
  


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ll a, b, c;
    cin>>a>>b>>c;
    ll k;
    cin>>k;
    ll ans = 0;
    while(b<=a){
        b*=2;
        ans++;
    }
    while(c<=b){
        c*=2;
        ans++;
    }
    if(ans>k){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}

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

S = S + 'end'
if S[0] == '0':
    stand = 1
else:
    stand = 0

r = 0
l = 0
ans = 0
while r < N:
    if stand <= K:
        if S[r] == '1' and S[r+1] == '0':
            stand += 1
        r += 1
        ans = max(ans, r - l)
    elif l == r:
        l += 1
        r += 1
    else:
        if S[l] == '0' and S[l+1] == '1':
            stand -= 1
        l += 1

print(ans)

Measured memory_bytes: 42352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main()
{
    string s;
    cin >> s;
    s.at(3) = '8';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    ll n, z, w;
    cin >> n >> z >> w;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    if (n == 1) {
        cout << abs(a[0] - w) << endl;
        return 0;
    }
    ll ret = 0;
    chmax(ret, abs(a[n - 2] - a[n - 1]));
    chmax(ret, abs(a[n - 1] - w));
    cout << ret << "\n";
    return 0;
}

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

long long extgcd(long long a)
{
	long long MOD = 1E9+7;
	long long b = MOD;
	long long u = 1, v = 0, q; 
	while ( b > 0 ) {
		q = a / b;
		a -= q * b;
		swap(a, b);
		u -= q * v;
		swap(u, v);
	}
	u %= MOD;
	while (u<0)
		u += MOD;
	return u;
}
long long comb(long long n,long long k)
{
	long long MOD = 1E9+7;
	long long t = 1;
	long long j = k;
	for(long long  i = n; i >= n-k+1; i--) {
		t *= i;
		t %= MOD;
		t *= extgcd(j);
		j--;
		t %= MOD;
	}  
  	while (t<0)
		t += MOD;
	return t;
}
int main(){
	long long n,a,b, k=1LL,MOD= 1E9+7LL;
	cin >>n >> a >> b;
  	long long tmp = n;
  	while(tmp > 16) {
     	k <<= 16;
      	k %= MOD;
   		tmp -= 16;
    }
  	k <<= tmp;
  	k--;
  	k %= MOD;
  	k =  (k - comb(n,a)) %MOD;
  	k =  (k - comb(n,b)) %MOD;
  	k%= MOD;
 	while (k<0)
		k+=MOD;
	cout << k << endl;
}


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

#define MAX_N 100

int main() {
	int N;
	int d[MAX_N] = {0};
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	sort(d, &d[N]);
	int min = 101;
	int sum = 0;
	for (int i = N-1; i >= 0; i--) {
		if (min > d[i]) {
			sum++;
			min = d[i];
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    ll cost=1e15;
    for(ll i=-100;i<=100;i++){
        ll x=0;
        for(ll j=0;j<n;j++){
            x+=pow(a[j]-i,2);
        }
        cost=min(cost,x);
    }
    cout << cost << endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>

int main(){
    int i=0,j=0,n=0;
    std::string taro_str,hanako_str;
    std::cin>>n;


    int taro_c,hanako_c;
    int taro_p=0,hanako_p=0;

    for(i=0;i<n;i++){
        std::cin>>taro_str>>hanako_str;
        taro_str=taro_str+"_";
        hanako_str=hanako_str+"_";
        j=0;
        while(1){
            taro_c=(int)taro_str[j];
            hanako_c=(int)hanako_str[j];//std::cout<<taro_c<<" "<<hanako_c<<std::endl;//ASCIIコードへの変換ok
            
            if(taro_c>hanako_c){
                taro_p+=3;
                break;
            }else if(taro_c<hanako_c){
                hanako_p+=3;
                break;
            }else if(taro_str==hanako_str){
                taro_p++;
                hanako_p++;
                break;
            }
        j++;
        }
    //std::cout<<taro_str<<" "<<hanako_str<<std::endl;
    //std::cout<<taro_p<<" "<<hanako_p<<std::endl;
    }
    

    std::cout<<taro_p<<" "<<hanako_p<<std::endl;
    return 0;
}



Measured memory_bytes: 3192
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

l = [a, b, c, d, e]
l_times_ten = []
amari_list = []
for i in range(len(l)):
    amari = l[i] % 10
    if amari == 0:
        l_times_ten.append(l[i])
    elif amari != 0:
        amari_list.append(amari)
        l_tmp =  l[i] +(10 - amari)
        l_times_ten.append(l_tmp)
# print(l_times_ten)
# print(amari_list)
max_total_time = sum(l_times_ten)
# print(min(amari_list))
if len(amari_list) != 0:
    adding = 10 - min(amari_list)
else:
    adding = 0
min_total_time = max_total_time - adding
print(min_total_time)

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

int main(){
  int s;
  cin >> s;
  int s_1 = s/1000;
  s = s%1000;
  int s_2 = s/100;
  s = s%100;
  int s_3 = s/10;
  int s_4 = s%10;
  if(s_1 == s_2){
    cout << "Bad" << endl;
    return 0;
  }
  if(s_2 == s_3){
    cout << "Bad" << endl;
    return 0;
  }
  if(s_3 == s_4){
    cout << "Bad" << endl;
    return 0;
  }
  cout << "Good" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int64_t n, k;
  cin >> n >> k;
  
  vector<int> A(n);
  
  for (int p = 0; p < n; p++) {
    cin >> A.at(p);
  }
  
    vector<int> B(n);
   B.at(0)=1; 
  
   set<int> S;
   S.insert(1);
  
  int q=0;
  int i=1;
  while(q==0){
    B.at(i)=A.at(B.at(i-1)-1);
    if (S.count(B.at(i))) {
      q++;
    }
    S.insert(B.at(i));
    i++;
    }

  
    
  int j=0;
  int m=0;
  while(m==0){
    if(B.at(j)==B.at(i-1)){
      m++;
    }
    j++;
  }
  
  
  if(k>=i){
  cout << B.at(j+((k-j)%(i-j))) << endl;
  }
  
  else{
    cout << B.at(k) << endl;
  }


}


Measured memory_bytes: 13992
//
//  main.cpp
//  four
//
//  Created by deepaz on 8/10/20.
//  Copyright © 2020 deepaz. All rights reserved.
//
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <iterator>
#include <cstring>
#include <algorithm>
#include <fstream>
#include <typeinfo>
#define ll long long
//deepaz
using namespace std;
//int num = stoi(a); -> str to int
//a = to_string(num); -> int to str
//total += c-48; -> char to int
//cout<<typeid(variable).name(); -> finding datatype of variable
 
//comparison func
bool comp(int x,int y){
    return x<y;
}
//char to int
int to_int(char c){
    return c;
}
//minimum in array
ll getMin(ll arr[], ll n){
    long long res = 1e6;
    for (int i = 0; i <= n; i++){
        res = min(res, arr[i]);
    }
    return res;
}
//get divisors of number
ll divisors(ll n){
    ll cnt = 0;
    for(int i=2;i*i<n;){
        if(n%i==0){
            cnt+=i+(n/i);
        }
        i++;
        if(i*i==n){
            cnt += i;
        }
    }
    if(cnt==0){
        return 0;
    }
    cnt++;
    return cnt;
}
//find if prime
bool isPrime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
//display prime in faster way
void dispPrime(ll n){
    ll num = 1e6;
    bool prime[num+num+num];
    memset(prime,true,sizeof(prime));
    for(int i=2;i*i<num+num+num;i++){
        if(prime[i]){
            for(int j=i*2;j<num+num+num;j+=i){
                //cout<<"i: "<<i<<"j: "<<j<<"\n";
                prime[j] = false;
            }
        }
    }
    ll k = 2;
    ll cnt = 0;
    ll upto = n; //for summing prime upto certain number
    //ll tot = 0;
    while(true){
        if(k<num+num+num){
            if(prime[k]){
                //tot += k;
                cnt++;
                if((k*k) == n){
                    cout<<"YES"<<"\n";
                    return;
                }
                //cout<<k<<" ";
            }
        }
        //if(cnt==n){break;}
        if(k>=upto){
            cout<<"NO"<<"\n";
            break;
        }
        k++;
    }
    //cout<<tot<<"\n";
}

int mltply(int n,int f[],int sz){
    int carry = 0;
    for(int i=0;i<sz;i++){
        int prod = f[i]*n + carry;
        f[i] = prod%10;
        carry = prod/10;
    }
    while(carry){
        f[sz] = carry%10;
        carry /= 10;
        sz++;
    }
    return sz;
}
//factorial of large numbers
void factorial(int n){
    int f[500];
    f[0] = 1;
    int sz = 1;
    for(int i=2;i<n+1;i++){
        sz = mltply(i, f, sz);
    }
    int ans = 0;
    for(int i=sz-1;i>=0;i--){
        //cout<<f[i];
        ans += f[i];
    }
    cout<<ans<<"\n";
}
//cout<<"Case #"<<cnt<<": "<<solve()<<"\n";
vector<int> arr(28123);
int calc(){
    int cnt = 0;
    for(int i=0;i<28124;i++){
        if(divisors(i)>i){
            arr[cnt] = i;
            cnt++;
            //cout<<arr[i]<<"\n";
        }
    }
    return cnt;
}

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({(a*c),(a*d),(b*c),(b*d)})<<"\n";
    return 0;
}


Measured memory_bytes: 3752
while True:
    H,W = map(int,input().split())
    if(H == W == 0):
        exit()
    for y in range(H):
        for x in range(W):
            if(y == 0 or x == 0 or y == H-1 or x == W-1):
                print("#",end="")
            else:
                print(".",end="")
        print("")
    print("")

Measured memory_bytes: 8940
import math
a,b=map(int,input().split())
start=0
end=1000000
ans=1000000
while start<=end:
    mid=(start+end)//2
    aa=math.floor(mid*0.08)
    bb=math.floor(mid*0.1)
    if aa==a and bb==b:
        ans=min(ans,mid)
        # exit()
        end=mid-1
    elif aa>a or bb>b:
        end=mid-1
    else:
        start=mid+1 
if ans==1000000:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<numeric>
#include<vector>
using namespace std;

typedef long long ll;
int n;
vector<ll> a;
ll sum = 0;

bool f(ll x){
    for(int i = 1; i <= n; i++){
        auto first = lower_bound(a.begin(), a.end(), a[i-1]+x);
        if(first == a.end())    continue;
        ll s = *first-a[i-1];
        auto second = lower_bound(a.begin(), a.end(), *first+x);
        if(second == a.end())   continue;
        ll t = *second-*first;
        if(sum-s-t >= x)    return true;
    }
    return false;
}

int main(){
    cin >> n;

    a.resize(n+1);
    a[0] = 0;
    for(int i = 0; i < n; i++)  cin >> a[i+1];

    sum = accumulate(a.begin(), a.end(), 0ll);
    ll l = 1, r = sum/3;

    for(int i = 0; i < n; i++)  a[i+1] += a[i];

    while(r-l > 1){
        ll mid = (l+r)/2;
        if(f(mid))  l = mid;
        else        r = mid;
    }

    cout << l << endl;

    return 0;
}


Measured memory_bytes: 3592
N,M = map(int, input().split())

shop = [tuple(map(int, input().split())) for _ in range(N)]

shop.sort()

count = 0
money = 0
for i in range(N):
    if count == M:
        break
    elif count + shop[i][1] <= M:
        count += shop[i][1]
        money += shop[i][0] * shop[i][1]
    elif count + shop[i][1] > M:
        money += shop[i][0] * (M - count)
        count += M - count

print(money)

Measured memory_bytes: 17000
#include<cstdio>
#include<cctype>
#define For(i,j,k) for(int i=j;i<=k;i++)
int read(){
	int x=0,l=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') l=-1; ch=getchar();}
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	return x*l;
}
using namespace std;
int ans,a[11],n;
void dfs(int x,bool fl){
	if (x==n+1){
		if (fl) ans++;
		return;
	}
	For(i,a[x]-1,a[x]+1){
		if (i%2==0) dfs(x+1,1);
		else dfs(x+1,fl);
	}
}
int main(){
	n=read();
	For(i,1,n) a[i]=read();
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(read())

for i in range(1, 10):
    if N % i == 0 and N / i <= 9:
        print('Yes')
        break
else:
    print('No')


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

int main()
{

    int x,t,z= 0;
    cin >> x >> t;
    
    if(x < t){
        z = 0;
    }
    else if(x >=t){
        z = x-t;
    }
    cout << z << endl;
    return 0;

    
}

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;

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




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



void printv(vint &v){
  for(auto e:v) cout<<e<<" ";
  cout<<endl;
}


// 繰り返し二乗法
ll power(ll a, ll b){
  if(a==1)return a;
  // if(a==0)re
  ll res=1;
  while(b>0){
    if(b&1) res=res*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return res;
}

const int MAX=2100000;
 
ll fact[MAX], fact_inv[MAX];
 
void init_fact(ll n){
  fact[0]=1;
  // 階乗の計算
  rep(i, n) fact[i+1]=fact[i]*(i+1)%MOD;
  fact_inv[n]=power(fact[n], MOD-2);
  // 逆元の計算
  for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}
 
ll comb(ll n, ll r){
  return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
 
ll perm(ll n, ll r){
  return (fact[n]*fact_inv[n-r])%MOD;
}






int main() {
  cout<<fixed<<setprecision(10);

  ll x; cin>>x;

  if(x==1){
    puts("Hello World");
  }else{
    ll a,b ; cin>>a>>b; cout<<a+b<<endl;
  }

}






Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long,long long>;

int main(){
    int N; cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N;i++)cin >> a[i];
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(i%2 == 0&& a[i]%2 == 1)ans++;
    }
    cout << ans << endl;
    
}




Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
//---------------------------------------------------------------------------//

int main(){
        string s,t;
        cin>>s;
        rep(i,s.length()){
                if(s[i]=='0') {
                        t+="0";
                }else if(s[i]=='1') {
                        t+="1";
                }else if(s[i]=='B') {
                        if(t.length()>0) {
                                t=t.substr(0,t.length()-1);
                        }else{
                                t="";
                        }
                }
        }
        cout<<t<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int &a:A) cin >> a;
    sort(A.begin(), A.end());
    
    int mx = A.back();
    int r = 1;
    int mi = mx+1;
    for(int i=0; i<N; i++){
        if(A[i] == mx) continue;
        if(abs(A[i] - (mx - A[i])) < mi){
            mi = abs(A[i] - (mx - A[i]));
            r = i;
        }
    }
    
    cout << mx << " " << A[r] << endl;
}


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

struct edge{
	int first;
	int last;
};

int pointNum,edgeNum;
bool flag = true;
vector<edge> v;
int color[101] = {};

void dfs(int u){
	color[u] = 1;

	for(int i = 0;i < v.size();i++){
		if(!flag){
			break;
		}
		if(v[i].first == u){
			if(color[v[i].last] == 1){
				flag = false;
			}
			else if(color[v[i].last] == 0){
				dfs(v[i].last);
			}
		}
	}
	color[u] = 2;
}

int main(){
	edge e;

	cin >> pointNum >> edgeNum;
	for(int i = 0;i < edgeNum;i++){
		cin >> e.first >> e.last;
		v.push_back(e);
	}

	for(int i = 0;i < pointNum;i++){
		if(!flag){
			break;
		}
		for(int i = 0;i < 101;i++){
			color[i] = 0;
		}
		dfs(i);	
	}

	if(flag){
		cout << "0" << endl;
	}
	else{
		cout << "1" << endl;
	}

	return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
 
using namespace std;
 
 
int main(){
	
long a,b,c,d;
cin>>a>>b>>c>>d;
 
if(((abs(a-b)<=d) && (abs(b-c)<=d )) || (abs(a-c)<=d)){
	cout<<"Yes"<<endl;
}	else{
	cout<<"No"<<endl;
}
	return 0;
}


Measured memory_bytes: 256
#define lp(i,n) for(int i=0;i<n;i++)
#define pau system("pause")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>> v(h,vector<char>(w));
    lp(i,h){
        lp(j,w){
            cin>>v[i][j];
        }
    }
    lp(i,h){
        lp(j,2){
            lp(k,w)
                cout<<v[i][k];
            cout<<endl;
        }
    }
}


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

int dat[2002];
vector<int> graph[2002];
bool visit[2005];
int n;

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

vector<int> merge(vector<vector<int>> vvt, int head)
{
	int total = 0;
	for (auto &&v : vvt) total += v.size();
	vector<int> ret(total + (head >= 0));
	int ptr = 0;
	if (head >= 0) ret[ptr++] = head;
	priority_queue<tuple<int, int, int>> pq;
	for (int i = 0; i < vvt.size(); i++)
	{
		pq.emplace(vvt[i][0], i, 0);
	}
	while (pq.empty() == false)
	{
		int val, idx, nxt;
		tie(val, idx, nxt) = pq.top();
		pq.pop();
		ret[ptr++] = val;

		if (nxt + 1 < vvt[idx].size())
			pq.emplace(vvt[idx][nxt + 1], idx, nxt + 1);
	}
	return ret;
}

vector<int> process(int t)
{
	vector<vector<int>> vvt;
	visit[t] = true;

	for (int nxt : graph[t])
	{
		if (visit[nxt]) continue;
		vvt.emplace_back(process(nxt));
	}

	return merge(move(vvt), t);
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &dat[i]);
	}

	sort(dat, dat + n);

	for (int i = 0; i < n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (gcd(dat[i], dat[j]) > 1)
			{
				graph[i].push_back(j);
				graph[j].push_back(i);
			}
		}
	}

	for (int i = 0; i < n; i++) sort(graph[i].begin(), graph[i].end());

	vector<vector<int>> vvt;

	for (int i = 0; i < n; i++)
	{
		if (visit[i]) continue;
		vvt.emplace_back(process(i));
	}

	auto ret = merge(move(vvt), -1);

	for (int t : ret) printf("%d ", dat[t]);
	printf("\n");
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

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

    string a,b,c;
    cin>>a>>b>>c;

    int ans=0;

    rep(i,n){
        set<char>x;
        x.insert(a[i]);
        x.insert(b[i]);
        x.insert(c[i]);

        if(x.size()==2)ans++;
        else if(x.size()==3)ans+=2;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
// PUJI TUHAN !!! YES
#include<iostream>
#include<queue>
#include<vector>
#define ii pair<int,int>
#define iii pair<int,ii> 
using namespace std;
int v,e,a,b;
vector<int> adjl[110000];
int vis[110000];
int memo[110000];
int start = 0;
int dp(int nodes){
//	cout<<nodes<<"\n";
	int sz = adjl[nodes].size();
	if(sz == 0) return 0;
	if(memo[nodes]!=-1) return memo[nodes];
	int ret = 0;
	for(int i = 0;i<sz;i++){
//		cout<<" visit "<<adjl[nodes][i]<<"\n";
		ret = max(ret, dp(adjl[nodes][i]) + 1);
	}
//	cout<<"\n";
	return memo[nodes] = ret;
}


int main(){
	cin>>v>>e;
	for(int i = 1;i<=v;i++) adjl[0].push_back(i);
	for(int i = 0;i<e;i++){
		cin>>a>>b;
		adjl[a].push_back(b);
	}
	int ans = 0;
	for(int i = 0;i<=v;i++) memo[i] = -1;
	ans = dp(0) -1 ;
	cout<<ans<<"\n";
//	for(int i = 0;i<=v;i++) cout<<memo[i]<<" ";cout<<"\n";
//	for(int i = 0;i<=v;i++) ans = max(ans,)
	return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

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

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

ll binpow(ll x, ll e) {
  ll ret = 1, p = x;
  while(e > 0) {
    if(e&1) {(ret *= p) %= MOD; e--;}
    else {(p *= p) %= MOD; e /= 2;} 
  }
  return ret;
}

PII dfs(vector<ll> a) {
    ll n = a.size();
    // 最小の要素の分引く
    ll mi = *min_element(ALL(a)), cnt = 0;
    REP(i, n) {
        a[i] -= mi;
        cnt += a[i]==0;
    }
    // 子が存在しない
    if(cnt == n) {
        ll ans = binpow(2, n);
        (ans += MOD-2) %= MOD;
        (ans += binpow(2, mi)) %= MOD;
        // cout << a << " " << mi << " " << PII{binpow(2, mi), ans} << endl;
        return {binpow(2, mi), ans};
    }
    // a[i]=0のところで分割して子を求める
    ll l = 0;
    vector<vector<ll>> child;
    while(l < n) {
        if(a[l] == 0) {l++; continue;}
        ll r = l;
        while(r+1<n && a[r+1] > 0) ++r;
        vector<ll> c;
        FOR(i, l, r+1) c.push_back(a[i]);
        child.push_back(c);
        l = r+1;
    }
    // 子の答えを求める
    vector<PII> ret;
    for(auto c: child) ret.push_back(dfs(c));
    ll ans1 = 1, ans2 = 1;
    for(auto p: ret) {
        (ans1 *= p.first) %= MOD;
        (ans2 *= (p.first + p.second)) %= MOD; 
    }
    PII ans;
    ans.first = binpow(2, mi) * ans1 % MOD;
    ans.second = binpow(2, cnt) * ans2 % MOD;
    (ans.second += (binpow(2, mi) + MOD - 2) % MOD * ans1 % MOD) %= MOD;
    // cout << a << " " << mi << " " << ans << endl;
    return ans;
}

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

    ll n;
    cin >> n;
    vector<ll> h(n);
    REP(i, n) cin >> h[i];

    cout << dfs(h).second << endl;

    return 0;
}


Measured memory_bytes: 384