akhauriyash/Code-Regression huggingface dataset:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


A, B, Q = list(map(int, sys.stdin.buffer.readline().split()))
S = [int(sys.stdin.buffer.readline()) for _ in range(A)]
T = [int(sys.stdin.buffer.readline()) for _ in range(B)]
X = [int(sys.stdin.buffer.readline()) for _ in range(Q)]

st_i = np.searchsorted(T, S).tolist()
ts_i = np.searchsorted(S, T).tolist()
st = []
ts = []

for s, i in zip(S, st_i):
    d = INF
    if 0 < i:
        d = min(d, abs(T[i - 1] - s))
    if i < len(T):
        d = min(d, abs(T[i] - s))
    st.append(d)
for t, i in zip(T, ts_i):
    d = INF
    if 0 < i:
        d = min(d, abs(S[i - 1] - t))
    if i < len(S):
        d = min(d, abs(S[i] - t))
    ts.append(d)

ans = []
for x in X:
    d = INF
    si = bisect.bisect_left(S, x)
    if 0 < si:
        d = min(d, abs(S[si - 1] - x) + st[si - 1])
    if si < len(S):
        d = min(d, abs(S[si] - x) + st[si])
    ti = bisect.bisect_left(T, x)
    if 0 < ti:
        d = min(d, abs(T[ti - 1] - x) + ts[ti - 1])
    if ti < len(T):
        d = min(d, abs(T[ti] - x) + ts[ti])
    ans .append(d)

print(*ans, sep='\n')


Measured memory_bytes: 47504
#include <functional>
#include <iostream>
#include <utility>
#include <vector>

template <class F> class rec_lambda {
  F f;

public:
  rec_lambda(F &&f) : f(std::move(f)) {}
  template <class... Args> auto operator()(Args &&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};
template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); }

int main() {
  using i64 = long long;

  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  std::cin >> n;
  std::vector<int> c(n);
  for (int &e : c) {
    std::cin >> e;
    e -= 1;
  }
  std::vector<std::vector<int>> g(n);
  for (int i = 0; i != n - 1; i += 1) {
    int a, b;
    std::cin >> a >> b;
    a -= 1;
    b -= 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  std::vector<i64> size(n, 1);

  make_rec([&](const auto &dfs, const int v, const int p) -> void {
    for (const int e : g[v]) {
      if (e == p)
        continue;
      dfs(e, v);
      size[v] += size[e];
    }
  })(0, n);

  std::vector<i64> count(n, n), ans(n, i64(n) * (n + 1) / 2);

  make_rec([&](const auto &dfs, const int v, const int p) -> void {
    const i64 prev = count[c[v]];
    for (const int e : g[v]) {
      if (e == p)
        continue;
      count[c[v]] = size[e];
      dfs(e, v);
      ans[c[v]] -= count[c[v]] * (count[c[v]] + 1) / 2;
    }
    count[c[v]] = prev - size[v];
  })(0, n);

  for (int i = 0; i != n; i += 1) {
    ans[i] -= count[i] * (count[i] + 1) / 2;
    std::cout << ans[i] << "\n";
  }
}


Measured memory_bytes: 38204
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    string s,t; cin >> s >> t;
    int si = SIZE(s) + SIZE(t);
    rep(i,si){
        if(i % 2 == 0){
            cout << s[i/2];
        } else cout << t[i/2];
    }
    cout << endl;
    return 0;
}


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

using namespace std;

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.14159265358979323846;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int a, b, c, d, e, k;

signed main() {
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a <= k)cout << "Yay!" << endl;
    else cout << ":(" << endl;
}


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

int main() {
    ll n,k;
    cin>>n>>k;
    vector<bool> m(n,false);
    rep(i,k){
        ll d;
        cin>>d;
        rep(j,d){
            ll a;
            cin>>a;
            m[a-1]=true;
        }
    }
    ll ans=0;
    rep(i,n)if(!m[i])ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	if(n==25)
		printf("Christmas");
	else if(n==24)
		printf("Christmas Eve");
	else if(n==23)
		printf("Christmas Eve Eve");
	else if(n==22)
		printf("Christmas Eve Eve Eve");
	return 0;
}

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

int main( void ) {
  int answer = 0;
  int N, M;
  cin >> N >> M;
  for ( int i = 0; i < N; i++ ) {
    int score = 0;
    for ( int j = 0; j < M; j++ ) {
      int a;
      cin >> a;
      if ( a ) score++;
    }
    answer = max( answer, score );
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}

int main() {
	ll x, y;
	cin >> x >> y;

	for (int i = 0; i <= x; i++) {
		for (int j = 0; j+i <= x; j++) {
			int t = i*2;
			int k = j*4;
			if (t + k == y && i+j==x) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>

using namespace std;
int main(){
   int N, K;
   int A[100000];
   
	cin >> N >> K;
	for(int i = 0; i<N; i++){
		scanf("%d",&A[i]);
	}

	int a;

	if(N!=K){
		if((N-1)%(K-1) == 0){
			a = (N-1)/(K-1);
		}
		else{
			a = (N-1)/(K-1) + 1;
		}
	}
	else{
		a = 1;
	}
	
	cout << a;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}

void solve() {
    ll n, q;
    std::cin >> n >> q;

    vvll ki(n);
    for (ll i = 0; i < n - 1; i++) {
        ll a, b; std::cin >> a >> b;
        a--, b--;
        ki[a].push_back(b), ki[b].push_back(a);
    }

    vll ans(n, 0);
    for (ll i = 0; i < q; i++) {
        ll p, x; std::cin >> p >> x;
        ans[--p] += x;
    }

    auto dfs = [&](auto &dfs, ll v, ll par) -> void {
        for (ll u : ki[v]) if (u != par) {
            ans[u] += ans[v];
            dfs(dfs, u, v);
        }
    };

    dfs(dfs, 0, -1);

    for (ll i = 0; i < n; i++)
        std::cout << ans[i] << (i < n - 1 ? ' ' : '\n');
}


Measured memory_bytes: 31392
N = int(input())
data = [int(i) for i in input().split()]
z_frug = 1
counter = 0
point = 0
i = 0
a = 0
while sum(data)!= 0:
  a +=1
  #print(data,counter,i,point)
  try:
    y = data[i]
  except:
    pass
  if y == 0:
    z_frug = (z_frug+1)%2
  if z_frug == 0 or i==N:
    if counter != 0:
      x = min(data[i-counter:i])
      point += x
      for j in range(i-counter,i):
        #print(a)
        data[j] -= x
      i = 0
      counter = 0
    else:
      i += 1
    z_frug = 1
    #break
  else:
    counter += 1
    i += 1
    
print(point)

Measured memory_bytes: 3064
from sys import stdin

rInt       = lambda : int(stdin.readline().strip("\n"))
rIntArray  = lambda : [int(x) for x in stdin.readline().split()]

rString    = lambda : stdin.readline().strip("\n")
rStrArray  = lambda : [x for x in stdin.readline().split()]

# for _ in range(rInt()):

maxn = 10**6

n = rInt()
arr = rIntArray()

pairwise = True

present = [0]*(maxn + 1)
for i in arr: present[i] += 1

for i in range(2, maxn + 1):
	cnt = 0
	for j in range(i, maxn + 1, i):
		cnt += present[j]
	if cnt > 1:
		pairwise = False

from math import gcd
g = 0
for i in arr: g = gcd(g, i)

if pairwise:
	print("pairwise coprime")
elif g == 1:
	print("setwise coprime")
else:
	print("not coprime")


Measured memory_bytes: 192824
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n;

ll f(ll a1, ll d) {
//    a1+x*d <= n;
//    x <= (n-a1)/d;

    ll x = (n-a1)/d;
    ll m = x+1;

    ll sn = m*a1 + m*(m-1)/2*d;

    return sn;

}
int main(void) {
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += f(i, i);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3524
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	string s;
	
	cin>>s;
	
	if(s[0] == 'S') cout<<"Cloudy"<<endl;
	if(s[0] == 'C') cout<<"Rainy"<<endl;
	if(s[0] == 'R') cout<<"Sunny"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

LL n, k;
V<LL> a;

template<typename T> bool judge(T x) {
	bool ans;

	LL cnt = 0;
	RBF(i, a) {
		LL tmp = ceil(static_cast<double>(i) / x) - 1;
		cnt += tmp;
	}
	if (cnt > k) {
		ans = false;
	}
	else {
		ans = true;
	}

	return ans;
}
// 範囲[a, b]の連続する整数のなかで，judge(x)=trueとなる最小のxを二分探索で求める
template<typename T> T bin_search_min(T a, T b) {
	if (a > b) {
		return bin_search_min(b, a);
	}

	T x = (b - a) / 2;
	T d = max(static_cast<T>(1), (b - a) / 4);
	T cnt = 0;
	T lim = log2(b - a) + 10;

	while (cnt < lim) {
		if (judge(x)) {
			x -= d;
		}
		else {
			x += d;
		}
		d = max(static_cast<T>(1), d / 2);
		cnt++;
	}

	if (x < a) {
		x = a;
	}
	while(!judge(x)) {
		x += 1;
	}

	// x > bならjudge(x)=trueとなるxが存在しなかったことを意味する
	return x;
}

signed main() {
	cin >> n >> k;
	a = V<LL>(n);
	LL b = 0;
	REP(i, n) {
		LL tmp;
		cin >> tmp;
		a[i] = tmp;
		b = max(b, tmp);
	}

	LL ans = bin_search_min(1ll, b);
	col(ans);
	return 0;
}

Measured memory_bytes: 4772
#include<stdio.h>
#include<string.h>
#include<math.h>

main()
{
    int t;
    double a,b,c,res;

    scanf("%d",&t);

    while(t--)
    {
        scanf("%lf%lf%lf",&a,&b,&c);

        if((a*a+b*b)==c*c)
        {
            printf("YES\n");
        }
        else if((b*b+c*c)==a*a)
        {
            printf("YES\n");
        }
        else if((c*c+a*a)==b*b)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1044
N,M=map(int, input().split())
L=[]
for i in range(M):
    a,b=map(int, input().split())
    L.append((b,a))

L=sorted(L)
preb=0
ans=0
for l in L:
    b,a=l
    if preb<=a:
        ans+=1
        preb=b
print(ans)

Measured memory_bytes: 17796
import sys
import math
import bisect

def main():
    n = int(input())
    max_val = 0
    val = 0
    for c in input():
        if c == 'I':
            val += 1
        elif c == 'D':
            val -= 1
        max_val = max(max_val, val)
    print(max_val)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

import java.util.LinkedHashMap;

public class Main {

    public static void main(String args[]) {
        FastScanner sc=new FastScanner();
        PrintWriter pw=new PrintWriter(System.out);

        Integer n = sc.nextInt();
        Integer k = sc.nextInt();
        Integer q = sc.nextInt();

        LinkedHashMap<Integer, Integer> score = new LinkedHashMap<>();
        for (int i = 1; i <= n; i++) {
            score.put(i, k);
        }

        int i = 0;
        for (; i < q; i++) {
            Integer winner = sc.nextInt();
            score.put(winner,score.get(winner)+1);
            //System.out.println(score);
        }

        for(int now : score.values()){
            pw.println(now<=i?"No":"Yes");
        }

        pw.flush();
    }

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 35532
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};

int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        if((n/i)<=9 && n%i==0){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
	exit(0);
}


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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int N = input();
  vector< int > a(N);
  cin >> a;

  int64 ans = 0;
  for (auto i : a) ans += i - 1;
  
  cout << ans << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}

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

bool ma[21][21];
int nowx, nowy;

void walk(char wc, int wl) {
	if (wc == 'N') {
		for (int i = 0; i < wl; i++) {
			nowy++;
			ma[nowx][nowy] = false;
		}
	}
	else if (wc == 'S') {
		for (int i = 0; i < wl; i++) {
			nowy--;
			ma[nowx][nowy] = false;
		}
	}
	else if (wc == 'E') {
		for (int i = 0; i < wl; i++) {
			nowx++;
			ma[nowx][nowy] = false;
		}
	}
	else {
		for (int i = 0; i < wl; i++) {
			nowx--;
			ma[nowx][nowy] = false;
		}
	}
}

int main() {
	int n;
	while (cin >> n, n) {
		for (int i = 0; i < 21; i++) {
			for (int j = 0; j < 21; j++) {
				ma[i][j] = false;
			}
		}
		for (int i = 0; i < n; i++) {
			int x, y;
			cin >> x >> y;
			ma[x][y] = true;
		}
		int m;
		cin >> m;
		nowx = 10,nowy = 10;
		for (int i = 0; i < m; i++) {
			char c;
			int l;
			cin >> c >> l;
			walk(c, l);
		}
		bool flag = false;
		for (int i = 0; i < 21; i++) {
			for (int j = 0; j < 21; j++) {
				if (ma[i][j] == true)flag = true;
			}
		}
		if (flag == true)cout << "No" << endl;
		else cout << "Yes" << endl;
	}
}

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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.group = [set() for _ in range(n)]

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

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

        if x == y:
            return

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

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

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

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

    def members(self, x):
        root = self.find(x)
        if not self.group[root]:
            for i in range(self.n):
                if self.find(i) == root:
                    self.group[root].add(i)
        return self.group[root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

def main():
    N, M, K = map(int, input().split())
    uni = UnionFind(N)
    not_cand = [0] * N
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        not_cand[A] += 1
        not_cand[B] += 1
        uni.union(A,B)
 
    for _ in range(K):
        C, D = map(int, input().split())
        C -= 1
        D -= 1
        if uni.same(C,D):
            not_cand[C] += 1
            not_cand[D] += 1
            
    
    ans = [0] * N
    for i in range(N):
        ans[i] = uni.size(i) - not_cand[i] - 1
    
    print(*ans)
 
 
if __name__ == "__main__":
    main()


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

using namespace std;

int ar[100010];

int main()
{
    long long ans = 0;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> ar[i];
    }

    ans += ar[0] / 2;
    ar[0] %= 2;

    for(int i = 1; i < n; i++) {
        if(ar[i - 1] <= ar[i])
        ans += ar[i - 1];
        if(ar[i] != 0)
        ar[i] -= ar[i - 1];
        ans += ar[i] / 2;
        ar[i] %= 2;
    }
    cout << ans;

	return 0;
}


Measured memory_bytes: 640
import sys
A,B,C=map(int,input().split())
cnt=0
A_old=B_old=C_old=0
for i in range(100000000):
    if A%2==1 or B%2==1 or C%2==1:
        print(cnt)
        sys.exit()
    elif  A==A_old and B==B_old and C==C_old:
        print(-1)
        sys.exit()

    A_old=A
    B_old=B
    C_old=C
    A=C_old/2+B_old/2
    B=A_old/2+C_old/2
    C=A_old/2+B_old/2
    cnt+=1


Measured memory_bytes: 62032
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=16,M=1<<13,T=1.6e6,mod=1e9+7;
int e[N],f[M],g[M],pc[M],pw[N*N],st[M],A[T],B[T];
int n,m,K,ALL,x,y,cnt,ans;

int mul(int x,int y){
	return (ll)x*y%mod;
}
void add(int &x,int y){
	x=(x+y>=mod?x+y-mod:x+y);
}

void init(){
	K=n-2,ALL=(1<<K)-1,pw[0]=1;
	rep(i,1,m) pw[i]=pw[i-1]*2%mod;
	REP(i,1<<K) pc[i]=pc[i>>1]+(i&1);
	REP(s,1<<K){
		int r=(~s)&ALL; st[s]=++cnt;
		for(int t=r;;t=(t-1)&r,cnt++){
			int u=ALL^s^t;
			A[cnt]=B[cnt]=1;
			rep(i,1,n){
				if(i<=2||(u>>(i-3)&1))
					A[cnt]=mul(A[cnt],pw[pc[e[i]&t]]-1);
				if(t>>(i-3)&1)
					A[cnt]=mul(A[cnt],pw[pc[e[i]&u]]);
				if(u>>(i-3)&1){
					B[cnt]=mul(B[cnt],pw[pc[e[i]&t]]-1);
					B[cnt]=mul(B[cnt],pw[pc[e[i]&u]]);
				}
				if(i<=2||(t>>(i-3)&1))
					B[cnt]=mul(B[cnt],pw[pc[e[i]&u]]);
			}
			if(!t) break;
		}
	}
}

int main(){
	read(n),read(m);
	rep(i,1,m){
		read(x),read(y);
		if(y>=3) e[x]|=1<<(y-3);
	}
	init(),f[0]=1;
	rep(i,0,K){
		memset(g,0,sizeof g);
		REP(s,1<<K){
			if(!f[s]) continue;
			int r=(~s)&ALL,cur=st[s];
			for(int t=r;;t=(t-1)&r,cur++){
				add(g[s|t],mul(f[s],A[cur]));
				add(ans,mul(f[s],B[cur]));
				if(!t) break;
			}
		}
		memcpy(f,g,sizeof g);
	}
	ans=(pw[m]+mod-ans)%mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12800
import sys

input = sys.stdin.readline

def main():
    N = int(input())
    P = []
    for i in range(N):
        P.append((int(input()), i))
    P.sort(key=lambda x: x[0])
    Q = list(zip(*P))[1]
    cnt = 1; ans = 1
    for i in range(N-1):
        if Q[i] < Q[i+1]:
            cnt += 1
        else:
            cnt = 1
        ans = max(ans, cnt)
    print(N-ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 47320
/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES

#include <iostream> // ?¨??????\??????
#include <fstream>  // ??????????????\??????
#include <string>   // ???????????¢???
#include <vector>   // ???????????????
#include <cmath>    // ??°??????
#include <iomanip>  // stream???????????¢???
#include <algorithm>// max??¢??°??????

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;        // ????´???°????????????????????????
using std::fixed;         // ???????????????????¨???????????????????????????????
using std::setprecision;  // ?????°????°???°?????\???????????°????????????????????¨????????\???

void out1(vector<int> a) {
	for (size_t i = 0; i < a.size(); i++)
	{
		cout << a[i] << " ";
	}
	cout << endl;
}

int main() {
	int w, n;
	cin >> w;	// ???????????°
	cin >> n;	// ?¨?????????°
	vector<int> begin(n);
	vector<int> end(n);
	vector<int> location(w);
	int num1 = 0;
	int num2 = 0;

	// ??\???
	for (size_t i = 0; i < n; i++)
	{
		scanf("%d,%d", &begin[i], &end[i]);
	}

	// location????????????
	for (size_t i = 0; i < w; i++)
	{
		location[i] = i + 1;
		
	}
	
	// ????????\??¬????????§????????????
	for (size_t i = 0; i < w; i++)
	{
		vector<int> tmp(w,0);
		//out1(tmp);
		tmp[i] = location[i];
		//cout << "----i = " << i << "?????¨???----" << endl;
		for (size_t j = 0; j < n; j++)
		{
			if (begin[j] == location[i])
			{
				
				//cout << begin[j] << "???" << end[j] << "?????\???????????????" << endl;
				location[i] = end[j];
			}
			else if (end[j] == location[i])
			{
				//cout << end[j] << "???" << begin[j] << "?????\???????????????" << endl;
				location[i] = begin[j];
			}
			//out1(location);
		}
	}
	// ???????????????
	vector<int> output(w,0);
	for (size_t i = 0; i < w; i++)
	{
		output[location[i]-1] = i;
	}

	// ???????????¨???????????????????????°??????1????¶????
	for (size_t i = 0; i < w; i++)
	{
		cout << output[i]+1 << endl;
	}


	return 0;
}

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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

bool is_prime(const unsigned n) {
  if (n % 2 == 0 || n % 3 == 0) {
    if (n == 2 || n == 3) {
      return true;
    }
    return false;
  }
  if (n == 1) {
    return false;
  }

  for (unsigned i = 5; i * i <= n; i += 6) {
    if (n % i == 0 || n % (i + 2) == 0) {
      return false;
    }
  }

  return true;
}

// prime factorization (素因数分解)
// key: value of prime factor
// value: number of prime factor
std::map<ll, ll> prime_factorization(ll n) {
  std::map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

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

// 約数リスト
vector<ll> get_divisors(const ll n) {
  vector<ll> divs;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      divs.push_back(i);
      if (i != n / i) {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

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

  ll n;
  cin >> n;
  vll a(n);
  rep(i, n) {
    cin >> a[i];
  }

  sort(all(a));

  vb exist(1000010);
  rep(i, n) {
    exist[a[i]] = true;
  }

  ll ans = 0;

  rep(i, n) {
    auto divs = get_divisors(a[i]);
    bool ok = true;

    if (i > 0 && a[i - 1] == a[i]) {
      continue;
    }

    if (i < n - 1 && a[i + 1] == a[i]) {
      continue;
    }

    for (auto d : divs) {
      if (d == a[i]) {
        continue;
      }
      if (exist[d]) {
        ok = false;
        break;
      }
    }

    if (ok) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5032
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

h,w=MI()
mines=[[0 for i in range(w+2)]for i in range(h+2)]

for i in range(w+2):
    mines[0][i]="."
    mines[h+1][i]="."
for i in range(h+2):
    mines[i][0]="."
    mines[i][w+1]="."
for i in range(h):
    s=list(input().rstrip())
    for j in range(w):
        mines[i+1][j+1]=s[j]
#print(mines)
minum=[[0 for i in range(w+2)]for i in range(h+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if mines[i][j]=="#":
            minum[i-1][j]+=1
            minum[i+1][j]+=1
            minum[i][j+1]+=1
            minum[i][j-1]+=1
            minum[i+1][j+1]+=1
            minum[i+1][j-1]+=1
            minum[i-1][j+1]+=1
            minum[i-1][j-1]+=1
#print(minum)
for i in range(1,h+1):
    for j in range(1,w+1):
        if mines[i][j]=="#":
            print("#",end="")
        else:
            print(minum[i][j],end="")
    print()

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

int main() {
 int A,B,C;
 cin>>A>>B>>C;
 for(int i=1;i<=1000;i++){
     int sum=A*i;
     if(sum%B==C){cout<<"YES"<<endl;return 0;}    
 }
 cout<<"NO"<<endl;
 return 0;}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#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>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

constexpr long long INF = 1e12;

int main() {

    int N;
    cin >> N;

    int K;
    cin >> K;

    vector<long long> h(N);
    for (int i = 0; i < N; i++)cin >> h[i];

    vector<long long> dp(N, INF);
    dp[0] = 0;

    for (int i = 1; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            int index = max(0, i - j);
            dp[i] = min(dp[i], dp[index] + abs(h[i] - h[index]));
        }
    }

    cout << dp[N - 1] << endl;

    return 0;
}
















































Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#ifdef Rahul
# define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
# define error(...) 42;
#endif
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
int const MOD = 1e9 + 7;
i64 const INF = 1e18 + 42;
/***********************************************************************/
inline int add(int a, int b, int mod = MOD) {
  a += b; return a >= mod ? a - mod : a;
}
inline int sub(int a, int b, int mod = MOD) {
  a -= b; return a < 0 ? a + mod : a;
}
inline int mul(int a, int b, int mod = MOD) {
  return int((long long) a * b % mod);
}
inline int mpow(int base, long long ex, int mod = MOD) {
  int res = 1;
  for (; ex > 0; ex >>= 1) {
    if (ex & 1) res = mul(res, base, mod);
    base = mul(base, base, mod);
  }
  return res;
}
inline int inv(int a, int mod = MOD) {
  return mpow(a, mod - 2, mod);
}
inline int mdiv(int a, int b, int mod = MOD) {
  return mul(a, mpow(b, mod - 2,  mod));
}
inline void adds(int &a, int b, int mod = MOD) {
  a += b; if (a >= mod) a -= mod;
}
inline void subs(int &a, int b, int mod = MOD) {
  a -= b; if (a < 0) a += mod;
}
inline void muls(int &a, int b, int mod = MOD) {
  a = int((long long) a * b % mod);
}
inline void mdivs(int &a, int b, int mod = MOD) {
  a = mdiv(a, b, mod);
}
int32_t main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int n, k; cin >> n >> k;
  vector<int> a(k + 1);
  int ans = 0;
  for (int i = k; i > 0; --i) {
    a[i] = mpow(k / i, n);
    for (int j = i + i; j <= k; j += i) {
      subs(a[i], a[j]);
    }
    adds(ans, mul(a[i], i));
  }
  kek(ans);
}


Measured memory_bytes: 4044
#include<stdio.h>
int main(void)
{   int a,b,c,d,t,m,p;
	while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
	{
	if(a>c)t=a;
	else t=c;
	if(b<d)m=b;
	else m=d;
	p=m-t;
	if(p>0)printf("%d\n",p);
	else printf("%d\n",0);}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
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 long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
class union_find{
  int N;vector<int> par;
  public:
    union_find(int n){
      N = n;
      par.resize(N);
      rep(i,N)par[i] = -1;
    }
    int find(int x){
      if(par[x] < 0)return x;
      else{
        return par[x] = find(par[x]);
      }
    }
    void unite(int x, int y){
      x = find(x);
      y = find(y);
      if(x == y)return;
      par[y] += par[x];
      par[x] = y;
    }
    bool same(int x, int y){
      return find(x) == find(y);
    }
    int size(int x){
      return -par[find(x)];
    }
};

////////////////////////////////////////////////////////////////////

int n,m;P es[60];vector<int> g[60];
signed main(){
  cin>>n>>m;
  rep(i,m){
    cin>>es[i].first>>es[i].second;
    es[i].first--;es[i].second--;
  }
  int ans = 0;
  rep(i,m){
    auto t = union_find(n);
    rep(j,m){
      if(i == j)continue;
      t.unite(es[j].first, es[j].second);
    }
    if(t.size(0) < n)ans++;
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

vector<ll> Zalgo(const string& S) {
  ll N = SZ(S);
  vector<ll> res(N);
  res[0] = N;
  ll i = 1, j = 0;
  while (i < N) {
    while (i + j < N && S[j] == S[i + j]) ++j;
    res[i] = j;
    if (j == 0) {
      ++i;
      continue;
    }
    ll k = 1;
    while (i + k < N && k + res[k] < j) res[i + k] = res[k], ++k;
    i += k, j -= k;
  }
  return res;
}

int main() {
  string s, t;
  cin >> s >> t;
  ll m = SZ(s), n = SZ(t);
  string u = s;
  while (SZ(u) <= m + n - 1) {
    u = u + u;
  }
  u = t + u;
  auto lcp = Zalgo(u);
  vector<vector<ll>> to(m);
  vector<ll> deg(m, 0);
  REP(i, m) {
    if (lcp[i + n] >= n) {
      ll j = (i + n) % m;
      to[i].push_back(j);
      deg[j]++;
    }
  }
  stack<ll> st;
  REP(i, m) if (deg[i] == 0) st.push(i);
  // dp[i] = 頂点iを始点とするパス長の最大値
  vector<ll> topo, dp(m, 0);
  while (!st.empty()) {
    ll cv = st.top();
    st.pop();
    topo.push_back(cv);
    FOREACH(nv, to[cv]) {
      deg[nv]--;
      dp[nv] = max(dp[nv], dp[cv] + 1);
      if (deg[nv] == 0) st.push(nv);
    }
  }

  //トポロジカルソート列に全頂点が格納されていない場合，閉路がある
  if (SZ(topo) != m) {
    cout << -1 << endl;
    return 0;
  }
  cout << *max_element(ALL(dp)) << endl;
  return 0;
}

Measured memory_bytes: 58384
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
const int mod = 1000000007;

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}



 
int main() {
    int k;
    cin >> k;
    int d = 0;
    for(int i = 1; i<=k; i++) {
        for(int j = 1; j<=k; j++) {
            for(int u = 1; u<=k; u++) {
                int tmp = gcd(i,j);
                d += gcd(tmp,u);
            }
        }
    }
    cout << d << endl;
}


Measured memory_bytes: 3644
#include <iostream>
using namespace std;
 
int main() {
	long long a,b,c,m,n,ans=0;
	cin>>a>>b>>c;
	if(a==0){	
		ans=1;
		a = 1;
	}
	n=b/c;
	m=(a-1)/c;
	ans+=n-m;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
mod = 10**9+7
if (x+y)%3!=0:
  print(0)
  exit()
if 2*min(x,y)<max(x,y):
  print(0)
  exit()
n = (2*x-y)//3
m = (2*y-x)//3
#n+mCm
if n==0 or m==0:
  print(1)
  exit()
def ka(x):
  a = 1
  while x!=1:
    a *= x
    x -= 1
    a%= mod
  return a

ans = (ka(n+m)*pow(ka(m),mod-2,mod)%mod)*(pow(ka(n),mod-2,mod))%mod
print(ans)

Measured memory_bytes: 9160
#include<bits/stdc++.h>
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define ret return
#define all(vl) vl.begin(),vl.end()
#define sor sort 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
int main()
{
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll cnt = 0;
	for(int i=0;i<n-2;i++)
	{
		if(s[i] == 'A'&&s[i+1] == 'B'&&s[i+2] == 'C')
			cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    const int rate = 8;
    int low = 0;
    int high = 9999999;
    while(1){
        if(low == high-1){
            break;
        }
        int mid = (low + high) / 2;
        int ans = ((mid * rate) / 100) + mid;
        if(ans == n){
            cout<<mid<<endl;
            return 0;
        }
        else if(ans > n){
            high = mid;
        }
        else
            low  = mid;
    }
    cout<<":("<<endl;
    return 0;
}

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

ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int n;
    cin >> n;
    vector<int> a(n);
    ll all;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if(i == 0) all = a[i];
        else all = gcd(all, a[i]);
    }
    
    unordered_set<int> seen;
    bool pc = true;
    for (int i = 0; i < n; ++i) {
        int tmp = a[i];
        for (int j = 2; j * j <= tmp; ++j) {
            if(tmp > 1 && tmp % j == 0 && seen.count(j)) {
                pc = false;
                break;
            }
            while(tmp > 1 && tmp % j == 0) {
                seen.insert(j);
                tmp /= j;
            }
        }
        if(tmp > 1 && seen.count(tmp)) pc = false;
        else if(tmp > 1) seen.insert(tmp);
        if(!pc) break;
    }

    if(pc) puts("pairwise coprime");
    else if(all == 1ll) puts("setwise coprime");
    else puts("not coprime");
}


Measured memory_bytes: 7196
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

void f(vvl &G, ll &ans, ll now, ll par, ll state, ll N) {

  if (state & (1 << now))
    return;
  state |= (1 << now);
  if (state == (1 << N) - 1) {
    ans++;
    return;
  }
  AUTO(g, G[now]) {
    if (g != par)
      f(G, ans, g, now, state, N);
  }
  return;
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M;
  cin >> N >> M;
  vl A(M), B(M);
  vvl G(N);
  REP(i, M) {
    cin >> A[i] >> B[i];
    G[A[i] - 1].push_back(B[i] - 1);
    G[B[i] - 1].push_back(A[i] - 1);
  }
  ll ans = 0;
  f(G, ans, 0, -1, 0, N);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3672