akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fr first
#define se second

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;



signed main(){
  int N;
  cin>>N;
  set<string> S;
  string s;
  REP(i,0,N){
    cin>>s;
    S.insert(s);
  }
  print(S.size())

}


Measured memory_bytes: 19244
#include <stdio.h>

int main(void)
{
    long long int a, b;
    long long int r, x, tmp;
    

    while (scanf("%lld %lld", &a, &b) != EOF){
        x = a * b;
        if (a < b){
            tmp = a;
            a = b;
            b = tmp;
        }

        r = a % b;
        while (r != 0){
            a = b;
            b = r;
            r = a % b;
        }
        printf("%lld %lld\n", b, x / b);

    }
    return (0);
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();

		long ans = 11;
		long end = (long) Math.sqrt(n);
		for (int i = 1; i <= end; i++) {
			if (n % i == 0) {
				ans = Math.min(ans, String.valueOf(n / i).length());
			}
		}
		System.out.println(ans);
	}
}


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

int main(){
    int a,b,m;
    cin >> a >> b >> m;
    vector<int> A(a);
    vector<int> B(b);
    vector<int> x(m);
    vector<int> y(m);
    vector<int> c(m);

    rep(i,a){
        cin >> A[i];
    }
    rep(i,b){
        cin >> B[i];
    }
    rep(i,m){
      cin >> x[i] >> y[i] >> c[i];
    }
    
    int ans=1000000;
    
    rep(i,m){
        ans=min(ans,A[x[i]-1]+B[y[i]-1]-c[i]);
    
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

 ans=min(ans,A[0]+B[0]);

    cout << ans << endl;

    return 0;

}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	int x, a, b;
	cin >> x >> a >> b;

	if(b <= a){
		puts("delicious");
	}else if(b <= a + x){
		puts("safe");
	}else{
		puts("dangerous");
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;
int main(){
	ll N;
	ll cnt = 2;
	scanf("%lld",&N);
	if(N==2){
		printf("1");
		return 0;
	}
	for(ll i = 2;i*i<=N;i++){
		if(N%i==0){
			ll M = N;
			ll K = i;
			while(M%K==0) M/=K;
			cnt += M%K==1;
			if(i*i==N) continue;
			
			M = N;
			K = N/i;
			while(M%K==0) M/=K;
			cnt += M%K==1;
		}
	}
	ll M = N-1;
	for(ll i=2;i*i<=M;i++){
		cnt +=(M%i==0)*2;
		if(i*i==M) cnt--;
	}
	printf("%lld\n",cnt);
	return 0;
	ll ccnt=0;
	for(ll i=2;i<=N;i++){
		ll t = N;
		while(t%i==0) t/=i;
		ccnt += t%i==1;
	}
	printf("%lld",ccnt);
}

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

int main(){

  int n,m;
  cin >> n >> m;

  vector<string> a(n);
  vector<string> b(m);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }

  for (int k = 0; k < n - m + 1; k++) {

    for (int j = 0; j < n - m + 1; j++) {
      bool c = true;
      for (int i = 0; i < m; i++) {
        if (a.at(k+i).substr(j,m) != b.at(i)) {
          c = false;
          break;
        }
      }
      if (c) {
        std::cout << "Yes" << '\n';
        return 0;
      }

    }
  }

  std::cout << "No" << '\n';
  return 0;

}


Measured memory_bytes: 256
n, mw = map(int, input().split())
w = []
v = []

for i in range(n):
    ww, vv = map(int, input().split())
    w.append(ww)
    v.append(vv)

dp = [0] * (mw + 1)
for i in range(n):
    for j in range(mw, w[i] - 1, -1):
        dp[j] = max(dp[j], dp[j - w[i]] + v[i])

print(dp[mw])

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

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(3000000);

mint f(int r, int c) {
    return comb(r+c, r);
}

mint g(int r, int c) {
    mint res = 0;
    for (int i = 0; i <= c; i++) {
        res += f(r, i + 1);
    }
    //     y = i
    // }

    return res;
}

int main() {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    mint ans = g(r2, c2) - g(r2, c1-1) - g(r1-1, c2) + g(r1-1, c1-1);
    cout << ans.x << endl;
}

Measured memory_bytes: 49992
#include <bits/stdc++.h>
//#define abs(x) (x>0?x:-x)
int main( ) {
int n, a[101], sum=0, ans=0;
std::cin >> n;
for (int i=0; i<n; ++i) std::cin >> a[i], sum += a[i];
for (int i=1; i<n; ++i) if ( abs(a[ans]*n-sum) > abs(a[i]*n-sum) ) ans = i;
std::cout << ans;
}

Measured memory_bytes: 256
def dfs(num, string, place):
    if len(string) == 0:
        return dfs(num, num[0], place+1)
    
    if len(string) == 7:
        if eval(string) == 7:
            print(string + "=7")
            exit()
        return 
    else:
        return dfs(num, string + "+" + num[place], place + 1), dfs(num, string + "-" + num[place], place + 1)

ABCD = input()
dfs(ABCD, "", 0)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define rep(i, s, n) for(int i = s;i<n;i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<int> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

template<typename T1, typename T2>
bool pairCompare(const pair<T1, T2> &firstElof, const pair<T1, T2> &secondElof) {
    return firstElof.second > secondElof.second;
}

int mapMaxValue(std::map<ll, int> m) {
    int max = 0;
    for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {
        if (max < it->second) max = it->second;
    }
    return max;
}

int main(void) {
    int x, a;
    cin >> x >> a;
    
    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
    char S[1000],T[1000];
    long int s,t,i,j,count = 0,kekka = 100000000;
    scanf("%s %s",S,T);
    s = strlen(S);
    t = strlen(T);
    for(i = 0 ; i <= s - t ; i++)
    {
        count = 0;
        for(j = i ; j <= i + t - 1 ; j++)
        {
            
            if(S[j] != T[j - i])
            {
                count++;
            }
        }
        if(count <= kekka)
            {
                kekka = count;
            }
    }
    printf("%ld\n",kekka);
    return 0;
}

Measured memory_bytes: 1704
n = int(input())
l = []
for i in range(n):
    a,b = map(int,input().split())
    l.append([b,a])
l.sort()
time = 0
for b,a in l:
    if time+a > b:
        print("No")
        exit()
    else:
        time += a
print("Yes")

Measured memory_bytes: 35616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
int n, k, m[64], b[64][64], r;
bool f[64];

int find_group(int a){
  rep(i, k)
    rep(j, m[i])
    if(a == b[i][j]) return i;
}

int main(){
  scanf("%d%d", &n, &k);
  rep(i, k){
    scanf("%d", m+i);
    rep(j, m[i]) scanf("%d", &b[i][j]);
  }
  scanf("%d", &r);
  int a, b;
  rep(i, r){
    scanf("%d%d", &a, &b);
    if(find_group(a) == find_group(b)) f[a] = f[b] = true;
  }
  int res;
  REP(i, 1, n+1) if(f[i]) res++;
  printf("%d\n", res);
  return 0;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int len = s.length();
  string ch[len];

  if(len == 1){
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i < len; i++){
    ch[i] = s.substr(i,1);
  }

  sort(ch,ch+len);
  bool isEven = false;
  bool isOK = true;

  for (int i = 1; i < len; i++){

    if(ch[i] != ch[i-1] && isEven){
      isEven = false;
    }else if(ch[i] != ch[i-1] && !isEven){
      isOK = false;
      break;
    }else{
      isEven = !isEven;
    }
  }

  if(isOK){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

	bool isOK = true;
	for (int i = 0; i < n; ++i) {
		int a;
		std::cin >> a;

		if (a % 2 == 0)
			isOK = isOK && (a % 3 == 0 || a % 5 == 0);
	}

	std::cout << (isOK ? "APPROVED" : "DENIED") << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    rep(i, 0, n) {
        int a;
        cin >> a;
        if (a % 2 == 0) {
            if (a % 3 != 0 && a % 5 != 0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

S = deque(list(input()))
Q = int(input())
rvs = False

for q in range(Q):
    query = list(input().split())
    if len(query) > 1:
        if query[1] == "1":
            if rvs:
                S.append(query[2])
            else:
                S.appendleft(query[2])
        elif query[1] == "2":
            if rvs:
                S.appendleft(query[2])
            else:
                S.append(query[2])
    else:
        rvs = not (rvs)

if rvs:
    S.reverse()

print("".join(S))


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

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int N;
map<long long, int> sisuu;

long long rec(int p, long long mul) {
    if (p > N) {
        if (mul == 1) return 1;
        else return 0;
    }
    long long res = 0;
    for (int i = 0; i < sisuu[p]+1; ++i) {
        if (mul % (i+1) != 0) continue;
        res += rec(p+1, mul / (i+1));
    }
    return res;
}

int main() {
    cin >> N;
    for (int i = 2; i <= N; ++i) {
        auto ps = prime_factorize(i);
        for (auto it : ps) sisuu[it.first] += it.second;
    }
    cout << rec(2, 75) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <math.h>
#include <stdio.h>
#define INF 1000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long int ll;
using namespace std;

int main() {

	int n; cin >> n;
	int MAX = 0,maxnum;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
        cin >> a[i];
		if (max(MAX, a[i]) == a[i]) {
			MAX = a[i];
			maxnum = i;
		}
	}
	for (int i = 0; i < n; i++) {
		if (i != maxnum) { cout << MAX << endl; }
		else {
			int smax = 0;
			for (int j = 0; j < n; j++) {
				if (j == maxnum) { continue; }
				smax = max(smax, a[j]);
			}
			cout << smax << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2432
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int i,j,m,n,x,a[100][100],b[100],c=0;
    
    scanf("%d %d",&i,&j);
    
    for(m=0;m<i;m++){
        for(n=0;n<j;n++){
            scanf("%d ",&x);
            a[m][n]=x;
        }
    }
    
    for(m=0;m<j;m++){
        scanf("%d",&x);
        b[m]=x;
    }
    
    for(m=0;m<i;m++){
        for(n=0;n<j;n++){
            c += a[m][n] * b[n];
        }
        printf("%d\n",c);
        c=0;
    }
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = 2e18;

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    cin >> A;
    sort(A.rbegin(), A.rend());
    map<int, int> check;
    for (auto temp : A) check[temp]++;
    int ans = 0;
    for (auto now : A) {
        if (check[now] == 0) continue;
        for (int i = 32; i >= 1; i--) {
            int minus = (1LL<<i) - now;
            if (minus < 0) break;
            if (check[minus] > 0) {
                if (now == minus && check[now] <= 1) continue;
                ans++;
                check[now]--;
                check[minus]--;
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 65152
package main

import (
	"fmt"
)

func main() {
	var A, B, K int
	fmt.Scan(&A, &B, &K)
	cnt := 0
	for i := A; i <= B; i++ {
		b := false
		if cnt < K {
			fmt.Println(i)
			b = true
		}
		if B-(A+cnt) < K && !b {
			fmt.Println(i)
		}
		cnt++
	}
}

Measured memory_bytes: 512
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        s: chars
    }
    let d = 1000000007;
    let mut tab: Vec<Vec<usize>> = vec![vec![0; n]; n];
    for i in 0..n {
        tab[0][i] = 1;
    }
    for i in 1..n {
        if s[i - 1] == '<' {
            let mut t: usize = 0;
            for j in 0..n - i {
                t = (t + tab[i - 1][j]) % d;
                tab[i][j] = t;
            }
        } else {
            let mut t: usize = 0;
            for j in 0..n - i {
                t = (t + tab[i - 1][n - i - j]) % d;
                tab[i][n - i - j - 1] = t;
            }
        }
    }
    println!("{}", tab[n - 1].iter().fold(0, |ac, x| (ac + x) % d));
}


Measured memory_bytes: 90364
N,K,C = map(int,input().split())

S = input()

l = [0]

last = float("-inf")
for i in range(N):

    if i > last+C and S[i] == "o":
        l.append(l[-1]+1)
        last = i
    else:
        l.append(l[-1])

l.append(l[-1])

r = [0]
last = float("-inf")
for i in range(N):

    if i > last+C and S[N-1-i] == "o":
        r.append(r[-1]+1)
        last = i
    else:
        r.append(r[-1])

r.append(r[-1])
r.reverse()

for i in range(1,N+1):

    if S[i-1] == "o" and l[i-1] + r[i+1] < K:
        print (i)


Measured memory_bytes: 58992
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;


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

	ll ans = 0;
	for (int i = 1; i < n; i++) {
		ll cnt = n / i;
		if (n % i == 0) {
			cnt--;
		}
		ans += cnt;
	}

	cout << ans << endl;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

unordered_map<ll, ll> Factorize (ll n);
ll EuclideanAlgorithm (ll a, ll b);
  
ll EuclideanAlgorithm (ll a, ll b) {
    if (b == 0) {
        return a;
    } else {
        return EuclideanAlgorithm(b, a%b);
    }
}

unordered_map<ll, ll> Factorize (ll n) {
  	unordered_map<ll, ll> result;
  	result[1]++;
  	for (ll i = 2; i*i <= n; i++)
    {
        if (n%i == 0) {
            while(n%i == 0) {
                n /= i;
                result[i]++;
            }
        }
    }
    result[n]++;
    return result;
}

int main() {
    ll a, b, gcd;
    unordered_map<ll, ll> mp;

    cin >> a >> b;
  	
	gcd = EuclideanAlgorithm(a, b);
  
  	mp = Factorize(gcd);
	cout << setprecision(20) << mp.size() << endl;
  	
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int x,y;
    int n=0;
    while(n<3000){
        
        cin>>x >>y;
        if(x==0&&y==0)break;
        if(x>=y){
            cout<<y<<" "<<x<<endl;
        }else{
            cout<<x<<" "<<y<<endl;
        }
        n+=1;
        
    }
    return 0;
}


Measured memory_bytes: 3096
inputs = input().strip().split(' ')
stack = list()
out = list()
for i in inputs:
    if(i == '+'):
        y = int(stack.pop())
        x = int(stack.pop())
        z = x + y
        stack.append(z)
    elif(i=='-'):
        y = int(stack.pop())
        x = int(stack.pop())
        z = x - y
        stack.append(z)
    elif(i=='*'):
        y = int(stack.pop())
        x = int(stack.pop())
        z = x * y
        stack.append(z)
    else:
        stack.append(i)
print(stack[-1])


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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');
    cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

const ll N=(ll)2000*1000;
vector<ll> primes;
int prm[N];

void seive(){
    for(ll i=2;i<N;i++)
        if(!prm[i]){
            for(ll j=i;j<N;j+=i)
                prm[j]=i;
            primes.pb(i);
        }
}

ll cntdivisor(ll n){
    ll ans=1;
    for(int i=0;i<_sz(primes)&&primes[i]*primes[i]<=n;i++){
        if(n%primes[i]==0){
            ll t=1;
            n/=primes[i];
            while(n%primes[i]==0)
                n/=primes[i],t++;
            ans*=(t+1);
        }
    }
    if(n>1)ans*=2;
    return ans;
}

int main(){
    nimble;
    seive();
    ll n;
    cin>>n;
    ll as=0;
    for(ll i=1;i<n;i++){
        ll x=n-i;
        as+=cntdivisor(x);
    }
    cout<<as;
    return 0;
}



Measured memory_bytes: 13068
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define entire(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
void solve()
{
  string s, t;
  cin >> s >> t;
  int diff = t.length();
  rep(i, s.length()) {
    int cnt = 0;
    if (i + t.length() <= s.length() )
    {
      rep(j, t.length()) {
        if (s[i + j] != t[j])
          cnt++;
      }
    } else {
      break;
    }
    diff = min(diff, cnt);
  }
  cout << diff << endl;
}


int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast
  int T = 1;
  // cin >> T;
  while (T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3660
class STNode:
    def __init__(self, k, l, r):
        self.key = k
        self.left = l
        self.right = r

def STinsert(h, z):
    p = None
    while True:
        if h.key == -1:
            break
        p = h
        if z.key < h.key:
            h = h.left
        else:
            h = h.right
    
    if z.key < p.key:
        p.left = z
    else:
        p.right = z
    
def preorder(head, h, A):
    if h.key == -1:
        return 
    A.append(h.key)
    preorder(head, h.left, A)
    preorder(head, h.right, A)
    if head == h:
        print('', *A)

def inorder(head, h, B):
    if h.key == -1:
        return 
    inorder(head, h.left, B)
    B.append(h.key)
    inorder(head, h.right, B)
    if head == h:
        print('', *B)

n = int(input())
NULLnode = STNode(-1, None, None)

first = list(input().split())
head = STNode(int(first[1]), NULLnode, NULLnode)
for i in range(n-1):
    temp = list(input().split())
    if temp[0] == 'insert':
        z = STNode(int(temp[1]), NULLnode, NULLnode)
        STinsert(head, z)
    else:
        A = []
        B = []
        inorder(head, head, B)
        preorder(head, head, A)


Measured memory_bytes: 120328
from collections import deque

n, x, y = [int(x) for x in input().split()]
x -= 1
y -= 1

# グラフを陽に持つ。
edges = [[] for _ in range(n)]
for i, e in enumerate(edges):
    if i == y:
        e.append(x)
    if i > 0:
        e.append(i - 1)
    if i < n - 1:
        e.append(i + 1)
    if i == x:
        e.append(y)

ans = [0] * n  # Patterns by distances

for v in range(n):
    que = deque()  # Queue
    que_append = que.append
    que_popleft = que.popleft
    dist = [-1] * n  # Distance

    dist[v] = 0
    que_append(v)

    while len(que):
        new_v = que_popleft()

        for adjacent in edges[new_v]:
            if dist[adjacent] != -1:
                continue
            que_append(adjacent)
            dist[adjacent] = dist[new_v] + 1

    for d in dist:
        ans[d] += 1

for a in ans[1:]:
    print(a // 2)


Measured memory_bytes: 48220
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

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

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

int main() {
	int n; cin >> n;
	ll ans = 1;
	for (int i = 0; i < n; i++) {
		ll t; cin >> t;
		ans = lcm(ans, t);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {

    fastio;
    int T=1;
    cin>>T;
    while(T--){
        int n;cin>>n;
        ll a[n];rep(i,n)cin>>a[i];
        vector<ll> basis;
        string s;cin>>s;
        int ans=0;
        for(int i=n-1;i>=0;i--){
        	for(auto j:basis){
        		a[i]=min(a[i],a[i]^j);
        	}
        	if(a[i]==0)continue;
        	if(s[i]=='1'){
        		ans=1;break;
        	}	
        	else{
        		basis.pb(a[i]);
        	}
        }
        cout<<ans<<endl;
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3652
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
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()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    in1(N);

    vi A(N);
    inN(A, N);

    vi B(N);
    inN(B, N);

    vll ca(N + 1);
    rep(i, N) ca[A[i]]++;

    vll cb(N + 1);
    rep(i, N) cb[B[i]]++;

    rep(i, N + 1)
    {
        if (ca[i] + cb[i] > N)
        {
            outl("No");
            return 0;
        }
    }

    vi C(N + 1);
    repse(i, 1, N) C[i] = C[i - 1] + ca[i];

    vi D(N + 1);
    repse(i, 1, N) D[i] = D[i - 1] + cb[i];

    int maxdiff = -2 * N;
    repse(i, 1, N)
    {
        chmax(maxdiff, C[i] - D[i - 1]);
    }

    outl("Yes");
    rep(i, N) cout << B[(i + N - maxdiff) % N] << " ";
    cout << endl;

    return 0;
}


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

using namespace std;

const int mod = 1e9 + 7;

void add_self(int &a, int b)
{
    a+=b;
    if(a>=mod) a-=mod;
}

int main()
{
    int h, w;
    cin>>h>>w;

    char grid[h][w];

    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            cin>>grid[i][j];
        }
    }

    vector<vector<int> > dp(h, vector<int> (w, 0));
    dp[0][0] = 1;

    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            if(i+1<h)
            {
                if(grid[i+1][j]=='.')
                {
                    add_self(dp[i+1][j], dp[i][j]);
                }
            }
            if(j+1<w)
            {
                if(grid[i][j+1]=='.')
                {
                    add_self(dp[i][j+1], dp[i][j]);
                }
            }
        }
    }

    cout<<dp[h-1][w-1]<<"\n";

    return 0;
}

Measured memory_bytes: 5120
N,M=list(map(int,input().split()))
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
l=[np.array([0]*N) for i in range(N)]
for i in range(M):
   tmp=(list(map(int,input().split())))
   l[tmp[0]-1][tmp[1]-1]=tmp[2]
   l[tmp[1]-1][tmp[0]-1]=tmp[2]
l2=csr_matrix(l)
l2=floyd_warshall(l2)
ans=0
for i in range(N):
   for j in range(i):
      if l[i][j] != l2[i][j] and l[i][j] != 0:
         ans+=1
print(ans)

Measured memory_bytes: 26236
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i)
  DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i)  
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end())
#define SSCLEAR(ss) ss.str("");ss.clear(stringstream::goodbit)
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
  TSTART();
  vll names(5); // M => 0, A => 1, R => 2, C => 3, H => 4
  REP(i,n){
    string name;
    cin >> name;
    if(name[0] == 'M')names[0]++;
    else if(name[0] == 'A')names[1]++;
    else if(name[0] == 'R')names[2]++;
    else if(name[0] == 'C')names[3]++;
    else if(name[0] == 'H')names[4]++;
  }
  DUMP(names);
  llu ans = 0;
  vi con[3];
  con[0] = {0,0,0,0,0,0,1,1,1,2};
  con[1] = {1,1,1,2,2,3,2,2,3,3};
  con[2] = {2,3,4,3,4,4,3,4,4,4};
  REP(i,10){
    ans += names[con[0][i]] * names[con[1][i]] * names[con[2][i]];
  }
  
  cout << ans << endl;
  TSTOP();
  }
  return 0;
}


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

using namespace std;

typedef long long int ll;

int main()
{
  	ll h,w;
  	cin >> h >> w;
  	ll ans = h*w;
  	if(h==1 || w==1)
    {
      	cout << 1 << endl;
      	return 0;
    }
  	
  	cout << (ans + 1)/2;
  	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <deque>
#include <math.h>

using namespace std;

int main()
{
    int N,D;
    cin >> N>>D;
    int X[10][10];
    for (int i=0;i<N;++i) {
        for(int j=0;j<D;++j) {
            cin >> X[i][j];
        }
    }

    int cnt=0;
    for (int i=0;i<N-1;++i) {
        for (int j=i+1;j<N;++j) {
            int s=0;
            for (int k=0;k<D;++k) {
                s+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
            }
            if ((int)sqrt(s)*(int)sqrt(s) == s) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,D;
  cin >>N >> D;
  int X[N][D];
  rep(i,N){
    rep(j,D){
      cin >> X[i][j];
    }
  }
  int ans=0;
  rep(i,N){
    for(int k=i+1; k<N; k++){
      int sq=0;
      rep(j,D){
	sq += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
      }
      int self = ((int)sqrt(((double)sq)))* ((int)sqrt(((double)sq)));
      if(sq==self){
	ans++;
      }					   
    }
  }
  cout << ans << endl;
  return 0;
    

}


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

int main(){
    string s;
    cin>>s;
    int yoy=123467;
    for(int i=0;i<=s.length()-3;i++){
        string game;
        game+=s[i];
        game+=s[i+1];
        game+=s[i+2];
        int diff;
        diff=stoi(game);
        if(abs(753-diff)<yoy)yoy=abs(753-diff);
    }
    cout<<yoy;
}


Measured memory_bytes: 256
n=int(input())
t=list(map(int,input().split()))
m=int(input())
d = [list(map(int,input().split())) for i in range(m)]

a=sum(t)
for i in range(m):
    j=d[i][0]
    ans=a-t[j-1]+d[i][1]

    print(ans)


Measured memory_bytes: 3060
import itertools
import math

k = int(input())
x = 0
for v in itertools.combinations_with_replacement(list(range(1, k+1)), 3):
    a, b, c = v
    x = x + math.gcd(math.gcd(a,b), c)

y = 0
for v in itertools.combinations(list(range(1, k+1)), 3):
    a, b, c = v
    y = y + math.gcd(math.gcd(a,b), c)

z = k * (1 + k) / 2
print( int(3 * x  + y * 3  -  2 * z))

Measured memory_bytes: 9148
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [h, w, m] <- getIntList
  dh <- VM.new h
  VM.set dh (0::Int)
  dw <- VM.new w
  VM.set dw (0::Int)

  let readInputs :: Int -> Set.Set (Int, Int) -> Int -> Int -> IO (Set.Set (Int, Int), Int, Int)
      readInputs i s my mx
        | i >= m = return (s, my, mx)
        | otherwise = do
            [h', w'] <- getIntList
            let h = h' - 1
                w = w' - 1
                s' = (h, w) `Set.insert` s
            ty <- VM.read dh h
            VM.write dh h (ty + 1)
            tx <- VM.read dw w
            VM.write dw w (tx + 1)
            let my' = max (ty + 1) my
                mx' = max (tx + 1) mx
            readInputs (i+1) s' my' mx'

  (s, my, mx) <- readInputs 0 (Set.empty) 0 0

  let getIs i j d mx is | i >= j = return is
                        | otherwise = do
                            t <- VM.read d i
                            let is' | t == mx = (i:is)
                                    | otherwise = is
                            getIs (i+1) j d mx is'

  ys <- getIs 0 h dh my []
  xs <- getIs 0 w dw mx []

  let found = or [not $ (y, x) `Set.member` s | y <- ys, x <- xs]
      d | found = 0
        | otherwise = 1

  print $ my + mx - d




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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int N;
  cin >> N;
  VI a(N);
  REP(i, N){
    cin >> a[i];
  }
  int ans = -1;
  REP(i, N)FOR(j, i + 1, N){
    ans = max(ans,abs(a[i]-a[j]));
  }
  cout << ans << endl;

}


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

typedef long long ll;
const ll mod = 1000*1000*1000+7;
int N, K;

vector<vector<ll> > dp[2];
vector<ll> po;

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

    dp[0] = dp[1] = vector<vector<ll> >(K + 1, vector<ll>(N + 1, 0));
    po.resize(2002);
    po[0] = 1;
    for(int i = 1; i < 2002; i++) {
        po[i] = po[i - 1] * 2 % mod;
    }

    for(int i = 1; i <= K; i++) {
        for(int j = 1; j <= N; j++) {
            int rem = (N - j) - (K - i);
            if(rem < 0) continue;

            if(i == 1) {
                dp[0][i][j] = rem + j - 2 < 0? 1 : po[rem + j - 2];
                dp[1][i][j] = dp[0][i][j];
                if(j) {
                    dp[1][i][j] += dp[1][i][j - 1];
                    dp[1][i][j] %= mod;
                }
                continue;
            }

            dp[0][i][j] = dp[1][i - 1][j - 1];
            if(rem) dp[0][i][j] += dp[0][i - 1][j];

            dp[1][i][j] = dp[0][i][j];
            if(j) {
                dp[1][i][j] += dp[1][i][j - 1];
                dp[1][i][j] %= mod;
            }
        }
    }

    printf("%lld", dp[0][K][N]);
}


Measured memory_bytes: 62976
n=int(input())

m=[[0 for i in range(10)] for j in range(10)]

for i in range(n+1):
    s=int(str(i)[0])
    e=int(str(i)[-1])

    m[s][e]+=1

ans=0

for i in range(10):
    for j in range(10):
        ans+=m[i][j]*m[j][i]

print(ans-1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int inf = 1e9 + 1;
const int N = 1e5 + 5;

vector<int> g[N];
bool vis[N];

void dfs(int x) {
    vis[x] = 1;
    // cout << x << " ";
    for(auto it : g[x]) {
        if(!vis[it]) dfs(it);
    }
}

typedef long long ll;

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

    int n, m, ans = 0;
    cin >> n >> m;

    for(int i=0; i<m; ++i) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for(int i=1; i<=n; ++i) {
        if(!vis[i]) {
            ans++;
            dfs(i);
        }
    }

    cout << ans - 1 << "\n";

    return 0;
}

Measured memory_bytes: 9668
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = 1000000007;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};


void solve(){
	
	ll n, m;
	cin >> n >> m;
	ll h[n+5];
	f1(n) cin >> h[i];
	ll x,y;
	ll ans= 0;
	vector < ll > v[n+5];
	f0(m) cin >> x >> y , v[x].pb(y) , v[y].pb(x);
	f1(n){
		ll ok = 1;
		for(auto u : v[i]){
			if(h[u] >= h[i]) ok = 0;
		}
		ans += ok;
	}
	cout << ans;
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


Measured memory_bytes: 10220
#include<bits/stdc++.h>
using namespace std;
const int nmax=100005;
int par[nmax*2];
void init(int x){
  for(int i=0;i<x;i++){
    par[i]=i;
  }
}
int root(int x){
  if(par[x]==x){
    return x;
  }
  else{
    return par[x]=root(par[x]);
  }
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y){
    return;
  }
  else{
    par[x]=y;
  }
}
int main(){
  int n,m;
  cin >> n >> m;
  init(n+m);
  for(int i=0;i<n;i++){
    int k;
    cin >> k;
    for(int j=0;j<k;j++){
      int l;
      cin >> l;
      unite(i,l-1+n);
    }
  }
  bool f=true;
  for(int i=0;i<n-1;i++){
    if(root(i)!=root(i+1)){
      f=false;
    }
  }
  if(f){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 1408