akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

/** whole range */
#define whole(xs) (xs).begin(), (xs).end()

namespace {
    template<typename T> istream& operator>>(istream& is, vector<T>& xs) { for (auto& x : xs) is >> x; return is; }

    /** output whole vector. ex) vector<int>{1, 2, 3} -> '1 2 3'. */
    template<typename T>
    ostream& operator<<(ostream& os, const vector<T>& xs) {
       if (xs.empty()) return os;
       os << xs[0];
       for (auto i = 1; i < xs.size(); i++) os << ' ' << xs[i];
       return os;
    }

    using ll = long long;
    int N;
    ll L;
    vector<string> S;
    void input() {
        cin >> N >> L;
        S.resize(N); cin >> S;
    }

    template<int N, int base>
    struct Trie {
        struct Node {
            int count; shared_ptr<Node> children[N]; 
            Node() { count = 0; }
        };
        using NodeRef = shared_ptr<Node>;
        static NodeRef makeNode() { return make_shared<Node>(); }
        NodeRef root;
        Trie() { root = makeNode(); }
        void insert(const string& s) {
            NodeRef cur = root;
            for (int c : s) {
                c -= base;
                if (cur->children[c] == nullptr) cur->children[c] = makeNode();
                cur = cur->children[c];
            }
            cur->count++;
        }
        bool count(const string& s) {
            NodeRef cur = root;
            for (int c : s) {
                c -= base;
                if (cur->children[c] == nullptr) return 0;
            }
            return cur->count;
        }
    };

    void solve() {
        Trie<2, '0'> t;
        using NodeRef = Trie<2, '0'>::NodeRef;
        for (auto s : S) {
            t.insert(s);
        }
        vector<ll> xs;
        function<void(NodeRef, int)> traverse = [&](NodeRef n, int level) {
            if (n == nullptr) {
                xs.push_back(L + 1 - level);
            } else if (n->count > 0 || L <= level) {
                return;
            } else {
                for (int c = 0; c <= 1; c++) {
                    traverse(n->children[c], level + 1);
                }
            }
        };
        traverse(t.root, 0);

        vector<ll> ys;
        transform(whole(xs), back_inserter(ys), [](ll x) {
            ll c = 1;
            while (x % 2 == 0) {
                c *= 2;
                x /= 2;
            }
            return c;
        });

        ll grundy = accumulate(whole(ys), 0LL, [&](ll a, ll b) { return a ^ b; });
        cout << (grundy > 0 ? "Alice" : "Bob") << endl;
    }
}

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



Measured memory_bytes: 19832
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llinf (1ll<<62)
#define BG(x) ((x).begin())
#define ED(x) ((x).end())
#define rBG(x) ((x).rbegin())
#define rED(x) ((x).rend())
#define mp(a, b) make_pair((a), (b))

ll t;
ll n, m, x;
ll c[20], a[20][20];
ll ans = llinf;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
//	cin >> t;
	t = 1;
	
	for(int _ = 1; _ <= t; _++) {
	//	cout << "Case #" << _ << ": ";
		
		cin >> n >> m >> x;
		for(int i = 0; i < n; i++) {
			cin >> c[i];
			for(int j = 0; j < m; j++) {
				cin >> a[i][j];
			}
		}
		
		for(int i = 0; i < (1<<n); i++) {
			vector<ll> val(m, 0);
			ll total = 0;
			for(int j = 0; j < n; j++) {
				if((1<<j) & i) {
					for(int k = 0; k < m; k++) {
						val[k] += a[j][k];
					}
					total += c[j];
				}
			}
			bool ok = 1;
		//	cout << i << ": ";
			for(auto j : val) {
		//		cout << j << ' ';
				if(j < x)
					ok = 0;
			}
		//	cout << '\n';
			if(ok)
				ans = min(ans, total);
		}
		cout << (ans == llinf ? -1 : ans) << '\n';
	}
	
	return 0;
}

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

set<int> a;
int n, ans = 0;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		if (a.find(b) == a.end()) {
			a.insert(b);
			//cout << "in" << endl;
		}
		else {
			a.erase(b);
			//cout << "out" << endl;
		}
	}

	cout << a.size() << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<(b); i++)

int main() {
  long long N;
  cin >> N;
  int ans = 100; //初期値は十分大きくしておく
  
  for (long long i=1; i*i<=N; i++) {
    if (N % i != 0) continue;
    long long A,B;
    A = i;
    B = N/i;
    int ketaA = 1; int ketaB = 1;
    while (A/10 > 0) {
      ketaA++;
      A /= 10;
    }
    while (B/10 > 0) {
      ketaB++;
      B /= 10;
    }
    ans = min(ans, max(ketaA, ketaB));
  }
    
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]){
    cout<<"Bad"<<endl;
  }
  else{
    cout<<"Good"<<endl;
  }
  return(0);
}


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

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

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

    for(int i = 0 ; i < n + 2 ; ++i){
        for(int j = 1 ; j < n + 2 ; ++j){
            imos[i][j] += imos[i][j - 1];
        }
    }

    for(int j = 0 ; j < n + 2 ; ++j){
        for(int i = 1 ; i < n + 2 ; ++i){
            imos[i][j] += imos[i - 1][j];
        }
    }

    for(int i = n - 2 ; i > 0 ; --i){
        int y = i + 1, x = 1;
        while(y < n + 2 && x < n + 2){
            imos[y][x] += imos[y - 1][x - 1];
            ++y;
            ++x;
        }
    }

    for(int j = 0 ; j < n + 2 ; ++j){
        int y = 1, x = j + 1;
        while(y < n + 2 && x < n + 2){
            imos[y][x] += imos[y - 1][x - 1];
            ++y;
            ++x;
        }
    }

    int ans = 0;
    for(int i = 0 ; i < n ; ++i){
        for(int j = 0 ; j < n ; ++j){
            if(imos[i][j] > 0){
                ++ans;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 100828
#!/usr/bin/env python3
import sys
from itertools import combinations

def solve(N: int, D: int, X: "List[List[int]]"):
    pairs = combinations(range(N), 2)
    counter = 0
    for p in pairs:
        x1 = X[p[0]]
        x2 = X[p[1]]
        d2 = 0
        for (xx1, xx2) in zip(x1, x2):
            d2 += (xx1 - xx2) ** 2
        if float.is_integer(d2 ** 0.5):
            counter += 1
        
    print(counter)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [ [ int(next(tokens)) for _ in range(D) ] for _ in range(N) ]  # type: "List[List[int]]"
    solve(N, D, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstdio>
#define inf -99999999
using namespace std;
int cnt(int x,int y);
int cross[17][17];
int main(void){
    int a,b,n,i,j,k,x,y;
    for(j=0;j<6;j++){
        scanf("%d%d",&a,&b);
        if(a==0) return 0;
        scanf("%d",&n);
        for(i=1;i<17;i++) for(k=1;k<17;k++) cross[i][k]=inf;
        for(i=0;i<n;i++){
            scanf("%d%d",&x,&y);
            cross[x][y]=0;
        }
        printf("%d\n",cnt(a,b));
    }
}
int cnt(int x,int y){
    if(x+y==2){
        return 1;
    }else if(cross[x][y]-inf){
        return cross[x][y];
    }else if(x==1){
        return cnt(x,y-1);
    }else if(y==1){
        return cnt(x-1,y);
    }else return cnt(x,y-1)+cnt(x-1,y);
}

Measured memory_bytes: 2612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}


struct UnionFind{
	vector<int> par;
	vector<int> rank;
	
	UnionFind(int n){
		par.resize(n);
		rank.resize(n);
		rep(i,n) par.at(i) = i;
	}
	
	int find(int x){
		if(par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	
	bool unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return false;
		else{
			par.at(y) = x;
			if(rank.at(x) == rank.at(y)) rank.at(x)++;
		}
		return true;
	}
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,t,l;cin >> n >> t >> l;
	UnionFind uf1 = UnionFind(n), uf2 = UnionFind(n);
	rep(i,t){
		int p,q;cin >> p >> q;
		p--;q--;
		uf1.unite(p,q);
	}
	rep(i,l){
		int r,s;cin >> r >> s;
		r--;s--;
		uf2.unite(r,s);
	}
	map<pii,int> m;
	vector<int> ans(n);
	rep(i,n) m[mp(uf1.find(i), uf2.find(i))]++;
	rep(i,n) ans.at(i) = m[mp(uf1.find(i), uf2.find(i))];
	rep(i,n){
		if(i == n - 1) cout << ans.at(i) << endl;
		else cout << ans.at(i) << " ";
	}
}


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

using namespace std;

int main () {

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

	string S;
	cin >> S;

	int n = S.length();

	int hugs = 0;

	for (int i = 0; i < n / 2; ++i) {
		if (S[i] != S[n-1 - i]) {
			hugs = hugs + 1;
		}
	}

	cout << hugs << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define M 1000000007
#define inf 1000000000000000001
#define pb push_back
#define mp make_pair
#define forz(i,s,n) for(lli i=s;i<n;i++)
#define fore(i,n,s) for(lli i=n;i>=s;i--)

#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

typedef long long int lli;
//typedef pair<long long int, long long int> pll;
typedef unsigned long long int ull;
using namespace std;

lli recpow(lli x, lli n)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0) //n is even
        return recpow((x * x) % M, n / 2);
    else //n is odd
        return (x * recpow((x * x) % M, (n - 1) / 2)) % M;
}

bool sortbysec(const pair<pair<lli, lli>, lli> &a,
               const pair<pair<lli, lli>, lli> &b)
{
    if(a.second==b.second)
    return (a.first.second<b.first.second);
    else
    return (a.second > b.second);
}

bool comp(pair<lli, lli> a, pair<lli, lli> b)
{
    if(a.first==b.first)
        return a.second<b.second;
    else
        return a.first<b.first;
}

string rev(string s)
{
    string t;
    fore(i,s.length()-1,0)
    {
        t.pb(s[i]);
    }
    return t;
}

lli numfac(lli n)
{
    lli ans=0;
    while(n%2==0)
    {
        ans++;
        n/=2;
    }
    lli lim=sqrt(n)+1;
    forz(i,3,lim)
    {
        while(n%i==0)
        {
            ans++;
            n/=i;
        }
    }
    if(n>2)
    ans++;
    return ans;
}

int lo(lli n)
{
    if(n%2==0 and n%4!=0)
    return 1;
    else if(n%4==0)
    return 2;
    else  
    return 3;
}

//code begins here
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b<<"\n";
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}

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


Measured memory_bytes: 3104
#include <stdio.h>

void swap(int *x, int *y){ int t = *x; *x = *y; *y = t;}

int main(){
  int n, a[101], min, i, j, c = 0;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) scanf("%d", a + i);

  for(i = 0; i < n; ++i){
    min = i;
    for(j = i + 1; j < n; ++j)
      if(a[j] < a[min]) min = j;
    if(min != i){
      swap(&a[i], &a[min]);
      c++;
    }
  }

  for(i = 0; i < n; ++i) printf(i != 0 ? " %d" : "%d", a[i]);
  printf("\n%d\n", c);
  return 0;
}


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

int main(int argc, char const *argv[]) {
  int N, M;
  cin >> N >> M;

  map<int, int> likes;

  int K;
  cin >> K;

  for (size_t i = 0; i < K; i++) {
    int tmp;
    cin >> tmp;
    likes[tmp] = 1;
  }

  for (size_t i = 0; i < N-1; i++) {
    cin >> K;
    
    for (size_t j = 0; j < K; j++) {
      int tmp;
      cin >> tmp;
    
      auto it = likes.find(tmp);
      it->second += 1;
    }
  }

  int count = 0;
  for(auto i = likes.begin(); i != likes.end(); i++) {
    if (i->second == N) count++;
  }

  std::cout << count << '\n';
}


Measured memory_bytes: 256
import sys
import re


def judge(a, b, c):
    if a ** 2 + b ** 2 == c ** 2:
        return "YES"
    else:
        return "NO"


#file = sys.argv[1]
#lis = open(file, "r").readlines()
lis = sys.stdin.readlines()
lis.pop(0)

for line in lis:
    edges = map((lambda x: int(x)), re.split(" +", line))
    edges.sort()
    r = judge(edges[0], edges[1], edges[2])
    print r

Measured memory_bytes: 4248
import bisect
import collections
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N,C = map(int,(input().split()))
D = [[] for _ in range(C)]
c = [[] for _ in range(N)]
for i in range(C):
    D[i] = list(map(int,(input().split())))
for i in range(N):
    c[i] = list(map(int,(input().split())))

r0 = []
r1 = []
r2 = []
for i in range(N):
    for j in range(N):
        if (i+j)%3 == 0:
            r0.append(c[i][j])
        elif (i+j)%3 == 1:
            r1.append(c[i][j])
        else:
            r2.append(c[i][j])

d0 = [[]]*C
d1 = [[]]*C
d2 = [[]]*C
for color in range(C):
    s = 0
    for i in range(len(r0)):
        s += D[r0[i]-1][color]
    d0[color] = (s,color)
for color in range(C):
    s = 0
    for i in range(len(r1)):
        s += D[r1[i]-1][color]
    d1[color] = (s,color)
for color in range(C):
    s = 0
    for i in range(len(r2)):
        s += D[r2[i]-1][color]
    d2[color] = (s,color)

d0.sort()
d1.sort()
d2.sort()

ans = float("inf")
for i in range(3):
    for j in range(3):
        for k in range(3):
            if d0[i][1] != d1[j][1] and d0[i][1] != d2[k][1] and d1[j][1] != d2[k][1]:
                ans = min(ans,d0[i][0]+d1[j][0]+d2[k][0])
print(ans)

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

#define FOR(a, b, c) for(int a=b;a<c;a++)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

template<typename T>
void remove(vector<T>& vector, unsigned int index) {
	vector.erase(vector.begin() + index);
}

int main() {
	char x[200005];
	cin >> x;
	int lx = strlen(x);
	vector<char> a;
	FOR(i,0,lx) {
		a.push_back(x[i]);
	}
	int la = lx;
	FOR(i,1,la) {
		if (a[i-1] == 'S' && a[i] == 'T') {
			remove(a,i-1);
			remove(a,i-1);
			i-=2; la -= 2;
		}
	}
	
	cout << a.size() << endl;
}

Measured memory_bytes: 896
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

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

    int odd = 0;
    for (int i = 1; i <= N; i++) {
        if (i & 0x1) {
            odd++;
        }
    }

    printf("%.10f\n", static_cast<double>(odd) / static_cast<double>(N));

    return 0;
}


Measured memory_bytes: 500
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    T1,T2 = mis()
    A1,A2 = mis()
    B1,B2 = mis()
    d1 = T1*A1 - T1*B1
    d2 = T2*A2 - T2*B2
    if d1 + d2 == 0:
        print('infinity')
    elif d1 < 0 > d2 or d1 > 0 < d2:
        print(0)
    else:
        if d1 < 0:
            d1 *= -1
            d2 *= -1
        if d1 + d2 > 0:
            print(0)
        elif d1 % (d1+d2) == 0:
            print(d1 // abs(d1+d2) * 2)
        else:
            print(d1 // abs(d1+d2) * 2 + 1)




main()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    string s;
    ll k;
    cin >> s >> k;
   
   for(ll i=0;i < k;i++)
   {
       if(s.at(i)=='1'){
           continue;
       }else{
           cout << (int)(s.at(i)-'0') << endl;
           return 0;
       }
   }
   cout << 1 << endl;  
}
    


Measured memory_bytes: 256
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    Cins(S);
    Cins(T);
    rep(i,N){
        cout << S[i] << T[i];
    }
    cout << nn;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 998244353 
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main()
{
	int n, k, q;
	cin >> n >> k >> q;
	vector <int> v(n + 1);
	while(q--)
	{
		int x;
		cin >> x;
		v[x]++;
	}
	ll sum = 0;
	for (int i = 1; i <= n; i++)
	{
		sum += v[i];
	}
	for (int i = 1; i <= n; i++)
	{
		if(sum - v[i] < k)
		{
			cout << "Yes\n";
		}
		else
		{
			cout << "No\n";
		}
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, M; cin >> N >> M;
	vector<int> a(M, 0);
	rep (i, M) cin >> a[i];

	int res = N - 1 - M;
	cout << res << endl;

	return 0;
}

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

int main()
{
  int n, k;
  cin >> n >> k;
  int ans = 1;
  for (int i = 0; i < n; i++)
  {
    if(ans < k) ans *= 2;
    else ans += k;
  }
  cout << ans << endl;
  return 0;
}


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

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

    if (N < A) {
        cout << "Yes" << endl;
    }
    else if (A == 0) {
        if (N%500 == 0) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else if (N%500 < A) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin>>n;
  ll dp[n];
  ll h[n];
  for(ll i=0;i<n;i++)
    cin>>h[i];
  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
     for(ll i=2;i<n;i++)
     {
       dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	 }
  cout<<dp[n-1];
 return 0;
}

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

#define MOD 10000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

ll dp[3005][6005];
int n;
pair<int, int> v[3005];

ll solve(int obj, int time){
    if(dp[obj][time]!=-1){
        return dp[obj][time];
    }
    if(obj>n){
        return dp[obj][time]=0;
    }
    ll nao, pega;
    nao=solve(obj+1, time);
    if(time>3000){
        pega=solve(obj+1, time-v[obj].f)+v[obj].s;
        return dp[obj][time]=max(pega, nao);
    }
    return dp[obj][time]=nao;
}

int main(){
    fastio;
    int t;
    memset(dp, -1, sizeof(dp));
    cin >> n >> t;
    for(int i=1; i<=n; i++){
        cin >> v[i].f >> v[i].s;
    }
    sort(v+1, v+n+1);
    cout << solve(1, 3000+t) << endl;
    return 0;
}

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

int main() {
	int N, K;

	cin >> N >> K;
	vector<int> D( N );
	for( int i = 0; i < N; i++ ) {
		cin >> D[i];
	}

	int R = min( N, K );
	int ans = 0;
	for( int A = 0; A <= R; A++ ) {
		for( int B = 0; B <= R; B++ ) {
			if( A + B > R ) {
				continue;
			}
			int res = 0;
			vector<int> a;
			for( int i = 0; i < A; i++ ) {
				res += D[i];
				a.push_back( D[i] );
			}
			for( int i = N - 1; i > N - B - 1; i-- ) {
				res += D[i];
				a.push_back( D[i] );
			}
			for( int C = 0; C < K - A - B; C++ ) {
				if( a.empty() ) {
					break;
				}
				auto it = min_element( a.begin(), a.end() );
				if( *it >= 0 ) {
					break;
				}
				res -= *it;
				a.erase( it );
			}
			ans = max( ans, res );
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
using namespace std;

int N;
int b[100], b_c[100];
int ans[100];
int ok;

int main(void) {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &b[i]);
		b_c[i] = b[i];
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - i; j++) {
			if (b[j]-1 >= j) {
				ans[N-1-i] = j;
			}

		}
		for (int j = ans[N-1-i]; j < N - i - 1; j++) {
			b[j] = b[j + 1];
		}
		for (int j = 0; j < N - i - 1; j++) {
		}
	}

	for (int i = 0; i < N; i++) {
		/*i番目の値ans[i] + 1をans[i]番目に挿入する操作
		b[i-1] = b[i];
		b[ans[i]+1] = b[ans[i]]
		b[ans[i]] = ans[i]+1*/
		for (int j = i - 1; j >= ans[i] + 1;j--) {
			b[j] = b[j-1];
		}
		b[ans[i]] = ans[i] + 1;
	}

	ok = 1;
	for (int i = 0; i < N; i++) {
		if (b[i] != b_c[i]) {
			ok = 0;
		}
	}


	if (ok == 0) {
		printf("-1\n");
	}
	else {
		for (int i = 0; i < N; i++) {
			printf("%d\n", ans[i] + 1);
		}
	}
}

Measured memory_bytes: 760
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(double v;cin>>v;){
		int n=ceil(v*v/98+1)+1e-10;
		cout<<n<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

void swap(int a, int b) {
	int tmp = a;
	a = b;
	b = tmp;
}

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

	queue<string>Q;

	Q.push("a");
	int count = 1;

	for (int i = 1; i < n;i++) {
		int c = count;
		while (c!=0) {
			string S = Q.front();
			Q.pop();
			c--;
			count--;
			int k = 0;
			for (int j = 0; j < i; j++) {
				k=max(k,S[j]-'a');
			}
			count += k+2;

			for (int j = 0; j <= k+1; j++) {
				char g='a'+j;
				string d = S + g;
				Q.push(d);
			}


		}
	}


	
	while (!Q.empty()) {
		cout << Q.front() << endl;
		Q.pop();
	}

	return 0;
}

Measured memory_bytes: 7328
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

#define MAX_N 1000010
long long extgcd(long long a, long long b, long long& x, long long& y) {
	long long d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else {
		x = 1; y = 0;
	}
	return d;
}
long long mod_inverse(long long a, long long m) {
	long long x, y;
	if(extgcd(a, m, x, y) == 1) return (m + x % m) % m;
	else return -1;
}
vector<long long> fact(MAX_N+1, INF);
long long mod_fact(long long n, long long& e) {
	if(fact[0] == INF) {
		fact[0]=1;
		if(MAX_N != 0) fact[1]=1;
		for(ll i = 2; i <= MAX_N; ++i) {
			fact[i] = (fact[i-1] * i) % MOD;
		}
	}
	e = 0;
	if(n == 0) return 1;
	long long res = mod_fact(n / MOD, e);
	e += n / MOD;
	if((n / MOD) % 2 != 0) return (res * (MOD - fact[n % MOD])) % MOD;
	return (res * fact[n % MOD]) % MOD;
}
// return nCk
long long mod_comb(long long n, long long k) {
	if(n < 0 || k < 0 || n < k) return 0;
	long long e1, e2, e3;
	long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2), a3 = mod_fact(n - k, e3);
	if(e1 > e2 + e3) return 0;
	return (a1 * mod_inverse((a2 * a3) % MOD, MOD)) % MOD;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	ll buf=1;
	REP(i,n-1) {
		buf*=(i+1);
		buf%=MOD;
	}
	buf*=(n-1);
	buf%=MOD;
	ll ans=buf;
	buf=1;
	vector<ll> fact(n+10,1);
	FOR(i,1,n+10) {
		buf*=i;
		buf%=MOD;
		fact[i]=buf;
	}
	for(ll i=n-1; i>=0; i--) {
		ll c1=i,c2=(n-1)-i;
		if(c2>=c1) continue;
		ans-=((mod_comb(c1-1,c2)*fact[i])%MOD)*fact[n-1-i];
		ans%=MOD;
	}
	cout<<((ans+fact[n-1])%MOD+MOD)%MOD<<endl;
}


Measured memory_bytes: 15872
fun main(array: Array<String>) {
    val (x1, y1, x2, y2) = readLine()!!.split(" ").map { it.toInt() }
    val vx1 = x2 - x1
    val vy1 = y2 - y1
    val x4 = -vy1 + x1
    val y4 = vx1 + y1
    val vx2 = x1 -x4
    val vy2 = y1 - y4
    val x3 = -vy2 + x4
    val y3 = vx2 + y4
    print(x3.toString() + " " + y3.toShort() + " " + x4.toString() + " " + y4.toString())
}

Measured memory_bytes: 37932
import sys
input = sys.stdin.readline

# D - Triangles
def binary_search(i, j):
	global N

	left = j
	right = N
	
	while right - left > 1:
		mid = (left + right) // 2
		
		if is_match(mid, i, j):
			left = mid
		else:
			right = mid
	
	return left
		

def is_match(mid, i, j):
	global L
	
	a = L[i]
	b = L[j]
	c = L[mid]
	
	if b < c + a and c < a + b:
		return True
	else:
		return False


N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0

for i in range(N - 2):
	for j in range(i + 1, N - 1):
		k = binary_search(i, j)
		
		if k > j and k < N:
			ans += k - j
			
print(ans)

Measured memory_bytes: 74328
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    string S;
    cin >> S;
    int sum = 0;
    rep0(i,S.length()){
        sum+=S[i]-'0';
    }
    if(atoi(S.c_str())%sum==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;        
    }
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int a[10005];
int b[10005];
int main()
{
int h, w;
cin >> h >> w;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> b[i];
int temp = 1;
int j = 1;
for (int i = 1; i <= n; i++)
{
while (b[i] > 0)
{
a[j] = temp;
j++;
b[i]--;
}
temp++;
}
for (int i = 1; i <= h; i++)
{
if (i % 2 == 1)
{
for (int p = w*(i - 1) + 1; p <= i*w; p++)
{
cout << a[p] << " ";
}
if (i != h)
cout << endl;
}
else if (i % 2 == 0)
{
for (int p = w*i; p >= w*(i - 1) + 1; p--)
{
cout << a[p] << " ";
}
if (i != h)
cout << endl;
}
}
return 0;
}

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

int main(){
int n; cin >> n; int f=0;
string s; cin >> s;
if(n%2==0){
rep(i,n/2){
    if(s[i] != s[i+(n/2)]){
        f++;
        break;
    }
}
if(!f) cout << "Yes" << endl;
else cout << "No" << endl;
}
else cout << "No" << endl;
return 0;
}


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

	std::vector<pair<int,int>> a(n);
	std::vector<pair<int,int>> c(m);
	
	for(int i = 0; i < n; ++i)cin>>a[i].first>>a[i].second;
	for(int i = 0; i < m; ++i)cin>>c[i].first>>c[i].second;
	
	for(int i=0;i<n;i++){

		int x = a[i].first;
		int y = a[i].second;
		int dis = INT_MAX;
		int ans;
		for(int j=0;j<m;j++){
			int d = abs(x-c[j].first) + abs(y-c[j].second);
			// cout<<" For student "<<x<<" "<<y<<" "<<" cp: "<<j+1<<" Distance: "<<d<<endl;
			if( d<dis ){
				dis = d;
				ans = j+1;
			}
		}
		cout<<ans<<" "<<endl;
	}

	return 0;

}

Measured memory_bytes: 3604
A,B = map(int,input().split())

def f(x):
	if x == 0:
		return 0
	elif x%2==0:
		return int(x/2)%2 ^ x
	else:
		return int((x-1)/2)%2 ^ x-1 ^ x

if A==B:
	print(B)
elif A == 0:
	print(0^f(B))
else:
	print(f(A-1)^f(B))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define P pair<ll, ll>
using namespace std;

const int INF = 1e9;

int main(){
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for(int i=0;i<N;i++)cin >> A[i] >> B[i];
    
    vector<vector<long long>> dp(N+1, vector<long long>(H+1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= H; ++j) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][min(j+A[i], H)] = min(dp[i+1][min(j+A[i], H)], dp[i+1][j] + B[i]);
        }
    }
    cout << dp[N][H] << endl;
}

Measured memory_bytes: 81668
#include <bits/stdc++.h>
using namespace std;
#define int long long
int N;
int M;
vector<vector<int> > to;
vector<int> col;
vector<int> t;
vector<int> mx;

struct Query {
	int v;
	int d;
	int c;
	
	bool operator<(const Query& right) const {
		return d < right.d;
	}
};
vector <Query> qu;
void update(int i) {
	queue<int> qq;
	int k;
	if (mx[qu[i].v] < qu[i].d) {
		mx[qu[i].v] = qu[i].d;
		if (col[qu[i].v]==0) {
			col[qu[i].v] = qu[i].c;
		}
		qq.push(qu[i].v);
	}
	//cerr << "A" << endl;
	while (!qq.empty()) {
		k = qq.front();
		qq.pop();
		for (int j = 0; j<to[k].size();j++) {
			if (mx[to[k][j]] < mx[k] - 1) {
				mx[to[k][j]] = mx[k] - 1;
				if (col[to[k][j]] == 0) {
					col[to[k][j]] = qu[i].c;
				}
				qq.push(to[k][j]);
			}
		}
	}
}
signed main() {
	

	cin >> N >> M;
	to.resize(N);
	col.resize(N, 0);
	t.resize(N, 0);
	mx.resize(N, -1);
	int a, b;
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
		
	}
	int Q;
	cin >> Q;
	qu.resize(Q);
	for (int i = 0; i < Q; i++) {
		cin >> qu[i].v >> qu[i].d >> qu[i].c;
		qu[i].v--;
	}
	//sort(qu.begin().qu.end());
	for (int i = Q - 1; i >= 0; i--) {
		update(i);
	}
	for(int i = 0; i < N; i++) {
		cout << col[i] << endl;
	}
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
ll mo=998244353;
map<string,ll> memo;

ll hoge(string S) {
	if(S.empty()) return 1;
	if(memo.count(S)) return memo[S];
	ll ret=0;
	
	ret = (1+S[0])*hoge(S.substr(1))%mo;
	for(int rep=1;rep<=S.size()/2;rep++) {
		string C(rep,1);
		for(int num=1;rep*num<=S.size();num++) {
			for(int x=(num-1)*rep;x<rep*num;x++) C[x%rep] &= S[x];
			if(num>1) (ret+=hoge(C)*hoge(S.substr(rep*num)))%=mo;
		}
		
	}
	
	return memo[S]=ret;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	N=S.size();
	FORR(c,S) c-='0';
	
	cout<<hoge(S)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	rep(i,b) {
		rep(j,w-a) cout << 0;
		rep(j,a) cout << 1;
		cout << endl;
	}
	rep(i,h-b) {
		rep(j,w-a) cout << 1;
		rep(j,a) cout << 0;
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3620
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main {
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int N = s.nextInt();
	int[] A = new int[N];
	
	for(int i = 0; i < N; i++){
		A[i] = s.nextInt();
	}

	int max = A[0];
	long count = 0;
	for(int i = 1; i < N; i++){
		if(max<A[i]){
			max = A[i];
		}else{
			count = count + (max - A[i]);
		}
	}
	
	
	System.out.println(count);
	

    
  }
}

Measured memory_bytes: 59780
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def gcd(a, b):
    """
    最大公約数を求める
    """
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    """
    最小公倍数を求める
    """
    return a*b//(gcd(a, b))


def calc_num(n, C, D):
    """
    0~Nまでで、C or Dで割り切れない数の個数
    """

    div_C = n//C
    div_D = n//D
    div_CD = n//(lcm(C, D))
    return n-div_C-div_D+div_CD


def solve():
    A, B, C, D = map(int, input().split())
    return calc_num(B, C, D)-calc_num(A-1, C, D)


print(solve())


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

int main(){
  int w,h,x,y,r;
  cin>>w>>h>>x>>y>>r;
  if(0 <= x-r && x+r <= w && 0 <= y-r && y+r <=h)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}

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

#define endl '\n'

using namespace std;

int main()
{
	string s;
	cin>>s;
	unsigned long long int sum=0; 
	for(int i=0;i<s.size();i++)
	{
		sum+=s[i]-'0';
	}
	if(sum%9==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 3756
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int a[1000];

int main()
{
  int i,j,n,ans,cnt,prev;
  scanf("%d",&n);
  for (i=0;i<n;i++)
    scanf("%d",&a[i]);
  cnt=0;
  prev=0;
  for (i=0;i<n;i++)
  {
    if (a[i]!=prev)
    {
      ans+=cnt/2;
      prev=a[i];
      cnt=1;
    }
    else cnt++;
  }
  ans+=cnt/2;
  printf("%d\n",ans);
}

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

int main() {
  int N, dekasa, f;
  cin >> N;
  f = N-N/10*10;
  if (f == 2 || f == 4 || f==5 || f==7 || f==9){
    cout << "hon" << endl;
  }
  else if (f==0 || f==1 || f==6 || f==8){
    cout << "pon" << endl;
  }
  else {
    cout << "bon" << endl;
  }
}

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

int main()
{
    cout<<fixed<<setprecision(20);
    fastio;ll n,m,x,y,a,u,v;
    cin>>n>>m;
    vector<vector<ll > > adj(n+1,vector<ll >());
    vector<ll > dp(n+1,0);
    vector<bool > used(n+1,false);
    vector<ll > in_degree(n+1,0);
    for(i=0;i<m;i++){
        cin>>x>>y;
        adj[x].pb(y);
        in_degree[y]++;
    }
    queue <ll > q;
    for(i=1;i<=n;i++)
        if(in_degree[i]==0 && used[i]!=true) q.push(i);
    //cout<<q.size()<<endl;
    while(q.size()>0){
        a=q.front();q.pop();
        //cout<<a<<endl;
        queue <ll > q1;
        q1.push(a);//used[a]=true;
        while(q1.size()>0){
            u=q1.front();q1.pop();
            used[u]=true;
            for(auto v:adj[u]){
                dp[v]=max(dp[v],dp[u]+1);
                in_degree[v]--;
                if(in_degree[v]==0) q.push(v);
            }
            //cout<<u<<endl;
        }
    }
    //for(i=1;i<=n;i++) cout<<dp[i]<<" ";
    //cout<<endl;
    cout<<*max_element(dp.begin(),dp.end());
}


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

int main(){
	const long double PI = (acos(-1));
	int a, b, h, m;
	cin >> a >> b >> h >> m;
	m = h*60+m;
	double zs = 2*PI/12/60 * m;
	double bs = 2*PI/60 * m;
	double zx, zy, bx, by;
	zx = cos(zs)*a;
	zy = sin(zs)*a;
	bx = cos(bs)*b;
	by = sin(bs)*b;
	double ans = sqrt((zx-bx)*(zx-bx) + (zy-by)*(zy-by));
	cout << fixed << setprecision(20) << ans << endl;	
	return 0;
}

Measured memory_bytes: 4068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DIVERTA2019C
{
    class Program
    {
        static int includeOf(string src, string target)
        {
            int count = 0;

            int index = src.IndexOf(target, 0);
            while (index >= 0)
            {
                count++;
                index = src.IndexOf(target, index + target.Length);
            }

            return count;
        }

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var input = Enumerable.Range(0, n)
                .Select(_ => Console.ReadLine()).ToList();

            var includeCount = 0;
            var endCount = 0;
            var startCount = 0;
            var bothCount = 0;
            foreach (var s in input)
            {
                // 文字列中のAB数
                includeCount += includeOf(s, "AB");

                // 末尾がA
                var lastChar = s.Last();
                if (lastChar == 'A')
                {
                    endCount++;
                }
                // 先頭がB
                var startChar = s.First();
                if (startChar == 'B')
                {
                    startCount++;
                }
                // 先頭がBで末尾がA
                if (startChar == 'B' && lastChar == 'A')
                {
                    bothCount++;
                }
            }

            var unionCount = Math.Min(startCount, endCount);
            var output = includeCount + unionCount;

            //Console.WriteLine($"{output}, {includeCount}, {unionCount}, {bothCount}");
            // 単純に数えるだけだと、「B***A」みたいな単語でおかしくなるので調整
            if (output > 0 && unionCount > 0 && (bothCount == Math.Max(startCount, endCount)))
            {
                output--;
            }

            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 13792
def fib(n)
	return 1 if n == 1 || n == 0
	$memo[n-2] ||= fib(n-2)
	$memo[n-1] ||= fib(n-1)
	return $memo[n-2] + $memo[n-1]
end
$memo = []
n = gets.chomp.to_i
puts fib(n)


Measured memory_bytes: 6852
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int a, b;
  cin >> a;
  cin >> b;
  int min_a = min(a, b);
  int max_b = max(a, b);
  if(min_a == 1 & max_b == 2){
    cout << 3 << endl;
  }else if(min_a == 2 & max_b == 3){
    cout << 1 << endl;
  }else if(min_a == 1 & max_b == 3){
    cout << 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include<iostream>
using namespace std;
int main(){
  int n,ans=0;
  cin>>n;
  int l[n],r[n];
  for(int i=0;i<n;i++)cin>>l[i]>>r[i];
  for(int i=0;i<n;i++)
    ans+=r[i]-l[i]+1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int N;
  cin >> N;
  vector<ll> num(N+1);
  rep(i, N) {
    int tmp;
    cin >> tmp;
    num[i+1] = num[i]+tmp;
  }
  ll ans = 1e18+1;
  for(int i=1; i<N; i++) {
    ll x = num[i], y = num[N]-num[i];
    chmin(ans, (ll)abs(x-y));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    Yes(x >= 30);
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n%1000==0)
        cout<<0;
    else
    {
        int div = ceil(n/1000.0);
        cout<<div*1000 - n;
    }
    cout<<endl;
}


Measured memory_bytes: 3712
/**
 *    author:  math2do
 *    created: 04.09.2020 15:52:43 IST
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, w, m = 2;
  cin >> n >> w;
  vector <vector <int> > mat(n, vector <int>(m));
  for (int i = 0; i < n; i++) {
    cin >> mat[i][0] >> mat[i][1];
  } 
  vector <long long> dp(w + 1, 0);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = w - mat[i][0]; j >= 0; j--) {
      dp[j + mat[i][0]] = max(dp[j + mat[i][0]], dp[j] + mat[i][1]);
    } 
  } 
  long long ans = 0;
  for (int i = 0; i <= w; i++) {
    ans = max(ans, dp[i]);
  } 
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3964
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int a[n];
  for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
  int count=0;
  for(int i=0;i<n-2;i++){
    if((a[i+1]-a[i])*(a[i+1]-a[i+2])<0)
      count++;
  }
  printf("%d",count);
}

Measured memory_bytes: 1700
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  string hi, bye;
  int a;
  cin >> hi >> bye;
  hi += hi;
  a = hi.find(bye, 0);
  if (a == -1) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 3192