akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
int main()
{
    char str[102];
    gets(str);
    int i=1,j=0,l;
    l=strlen(str);
    for(i;i<=l;i=i+2){
        if(str[i]=='R'){
            printf("No\n");
            return 0;
        }
    }
    for(j;j<=l;j=j+2){
        if(str[j]=='L'){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 128
N=int(input())
L=list(map(int,input().split()))
B=1
for i in range(N):
    B=B|B<<L[i]
BI=list(str(bin(B)))
BI=BI[2:]
SB=BI[::-1]
#print(SB)
Q=int(input())
A=list(map(int,input().split()))
for i in range(Q):
    if A[i]>=len(SB):
        print("no")
    elif SB[A[i]]=="1":
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,m;
long long gt[1000001],igt[1000001];

long long moe(long long a,long long b)
{
    if (b==0) return 1;
    if (b%2==0) return moe((a*a)%MOD,b/2);
    return (a*moe((a*a)%MOD,b/2))%MOD;
}

void init()
{
    gt[0]=1;
    for (int i=1;i<=1000000;++i)
        gt[i]=(gt[i-1]*i)%MOD;
    igt[1000000]=moe(gt[1000000],MOD-2);
    for (int i=1000000-1;i>=0;--i)
        igt[i]=(igt[i+1]*(i+1))%MOD;
}

void process()
{
    int x=2*n-m;
    x/=3;
    int y=n-2*x;
    if (x<0 || y<0)
    {
        cout<<0;
        return ;
    }
    cout<<((gt[x+y]*igt[x])%MOD*igt[y])%MOD;
}

int main()
{
    init();
    scanf("%d %d",&n,&m);
    if ((m+n)%3!=0)
        cout<<0;
    else process();
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

void solve(long long N, std::vector<std::string> S) {
    map<string, int> cnt;
    for (auto s : S) {
        cnt[s]++;
    }
    for (auto s : {"AC", "WA", "TLE", "RE"}) {
        cout << s << " x " << cnt[s] << endl;
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<std::string> S(N);
    for (int i = 0; i < N; i++) {
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
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];
  }
};

int main(){
    int K;cin >> K;
    string S; cin >> S;
    int N; N = S.length();

    mint ans = 0;
    combination comb = combination(N+K+100);
    vector<mint> tf(N+K+100);
    vector<mint> ts(N+K+100);
    tf[0] = 1; ts[0] = 1;
    rep(i, N+K+10){
        tf[i+1] = tf[i] * 25;
        ts[i+1] = ts[i] * 26;
    }
    rep(i, K+1){
        ans += comb(N+K-i-1, N-1) * tf[K-i] * ts[i];
    }
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 66668
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

void rec(ll n,vector<int>& visited,vector<vector<ll>>& G){
    if(visited[n]) return;
    visited[n] = true;
    for(auto next:G[n]){
        rec(next,visited,G);
    }
}
template<class Type>
Type solve(Type res = Type()){
    ll N,M; cin >> N >> M;
    vector<vector<ll>> G(N);
    vector<ll> X(M),Y(M),Z(M);
    vector<int> visited(N);
    for(int i = 0; i < M;i++){
        cin >> X[i] >> Y[i] >> Z[i];
        X[i]--;Y[i]--;
        Z[i]%=2;
        G[X[i]].push_back(Y[i]);
        G[Y[i]].push_back(X[i]);
    }
    for(ll i = 0; i < N;i++){
        if(visited[i]) continue;
        res++;
        rec(i,visited,G);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

int even_num, odd_num;

int main(){

    cin >> even_num >> odd_num;

    int even_c=0, odd_c=0;

    if (even_num<2){
        even_c =0;
    }
    else
    {
        even_c = (even_num*(even_num-1))/2;
    }
    
    if (odd_num<2){
        odd_c =0;
    }
    else{
        odd_c = (odd_num*(odd_num-1))/2;
    }


    /*
    cout << kaijo_a << endl;
    cout << kaijo_c << endl;
    cout << even_c << endl;
    cout << odd_c << endl;
    */
    cout << even_c+odd_c << endl;
    return 0;
}

Measured memory_bytes: 256
def solve():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    ans = 0
    for i in range(101):
        if X-i not in P:
            ans = X-i
            break
        if X+i not in P:
            ans = X+i
            break
    return ans
print(solve())

Measured memory_bytes: 61864
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll res = 1, tmp = 1;
  rep(i, n) {
    ll a;
    cin >> a;
    res *= 3;
    if (a%2 == 0) tmp *= 2;
  }
  cout << res - tmp << endl;
}

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

using namespace std;

// DP テーブル
long long dpa[100010];
long long dpb[100010];
long long dpc[100010];

int main() {
    // DP テーブル全体を初期化
    for (int i = 0; i < 100010; ++i) {
        dpa[i] = 0; dpb[i] = 0; dpc[i] = 0;
    }

    int N;
    cin >> N;
    vector<int> a(N); vector<int> b(N); vector<int> c(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }
    dpa[0] = a[0]; dpb[0] = b[0]; dpc[0] = c[0];
    for (int i = 1; i < N; ++i) {
        dpa[i] = a[i]+max(dpb[i-1], dpc[i-1]);
        dpb[i] = b[i]+max(dpc[i-1], dpa[i-1]);
        dpc[i] = c[i]+max(dpa[i-1], dpb[i-1]);
    }
    cout << max(dpa[N-1], max(dpb[N-1], dpc[N-1])) << endl;
    return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

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

const int mod = 1e9 + 7;
const int N = 100005;

ll w[N], v[N], dp[N];

int main(){
	fastio;
    int n,p;
    cin >> n >> p;
    for(int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    for(int i = 0; i < n; i++){ // try insert on the knap the ith element
        for(int j = p-w[i]; j >= 0; j--){ // iterate over all possible available weights if i put the ith element
            dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
        }
    }
    cout << dp[p] << endl;
}


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

int main (){
    int x[110];
    int N,K;
    cin >> N >> K;
    for (int i = 0; i <N; i++){
        cin >> x[i];
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        ans +=2 *min(x[i],K - x[i]);
    }
    cout << ans <<endl;
    return 0;
}

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

	int h, w;
	int i, j;

	while (1)
	{
		scanf("%d %d", &h, &w);
		
		if (h == 0 && w == 0)
		{
			break;
		}

		for (i = 0; i<h; i++)
		{
			for (j = 0; j<w; j++) 
			{
				printf("#");
			}

			printf("\n");
		}

		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int kSize = 100001;

vector<int> adj[kSize];
bool isMarked[kSize];
int d[kSize];
int cc = 0;

void dfs(int v) {
    isMarked[v] = true;
    d[v] = cc;

    for (int i = 0; i < adj[v].size(); ++i) {
        int u = adj[v][i];
        if (!isMarked[u]) {
            dfs(u);
        }
    }
}

int main() {
    int n, m;
    fill(isMarked, isMarked + kSize, false);
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int from, to;
        cin >> from >> to;
        adj[from].push_back(to);
        adj[to].push_back(from);
    }

    for (int i = 0; i < n; ++i) {
        if (!isMarked[i]) {
            dfs(i);
            cc++;
        }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int from, to;
        cin >> from >> to;
        if (d[from] == d[to]) {
            cout << "yes";
        } else {
            cout << "no";
        }
        cout << endl;
    }
    return 0;
}


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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

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 a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int main(){
	ios::sync_with_stdio(false);
	int p,q,r;
	cin>>p>>q>>r;
	cout<<min({p+q,p+r,q+r})<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define num (10 * 10 * 10 * 10 * 10 + 1)

typedef struct
	{
		char before[3];
		char after[3];
	} change;

int main()
{
	int i,j,m,flag,n = 1;
	char str[num][3];
	change change[num];
	do
	{
		scanf("%d",&n);
		if(n != 0)
		{
			for(i=0;i<n;i++)
			{
				scanf("%s %s",&change[i].before,&change[i].after);
			}
			scanf("%d",&m);
			for(i=0;i<m;i++)
			{
				scanf("%s",&str[i]);
				flag = 0;
				for(j=0;j<n;j++)
				{
					if(str[i][0] == change[j].before[0] && flag == 0)
					{
						str[i][0] = change[j].after[0];
						flag = 1;
					}
				}
			}
			for(i=0;i<m;i++)
			{
				printf("%c",str[i][0]);
			}
			printf("\n");
		}
	} while(n != 0);
	return 0;
}

Measured memory_bytes: 872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353

int main(){
	ll k, q, n, x, y, m, cnt, ans, dvr, lef, divd, addit;
	cin >> k >> q;
	vector<ll> d(k);
	REP(i,k) cin >> d.at(i);

	REP(i,q){
		cin >> n >> x >> m;
		ans = 0;
		dvr = (n-1)/k;
		lef = ((n-1) % k);
		cnt = x % m;
		REP(i,k){
			addit = 0;
			if (i <= lef-1) addit = 1;
			divd = d.at(i) % m;
/*			cout << i << " " << addit << " " << dvr << endl;*/
			if (divd == 0){
				ans += (addit+dvr);
			}
			cnt += divd * (addit+dvr);
		}
		ans += cnt/m;
		cout << n-ans-1 << endl;
	}
}

Measured memory_bytes: 384
n, l = map(int, input().split())
L = []
for i in range(1,n+1):
    L.append(l+i-1)

aji = []
for a in L:
    aji.append(sum(L)-a)
aji2 = []
for i in range(len(L)):
    aji2.append(abs(aji[i]-sum(L)))

m = 10**7
ans = 1
for i in range(len(L)):
    if m > abs(aji[i]-sum(L)):
        m = min(abs(aji[i]- sum(L)), m)
        ans = aji[i]

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define YES cout << "YES" << endl
#define NO  cout << "NO"  << endl
#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 100001
using namespace std;
typedef long long ll;

int main(){
  int n;  cin >> n;
  if(n==3 or n==5 or n==7){
    YES;
  }else{
    NO;
  }
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	vs := make([]int, n)
	for i := range vs {
		fmt.Scan(&vs[i])
	}
	min := k
	if n < min {
		min = n
	}

	ans := 0
	for a := 0; a <= min; a++ {
		for b := 0; b <= min-a; b++ {
			xs := make([]int, 0, a+b)
			xs = append(xs, vs[0:a]...)
			xs = append(xs, vs[len(vs)-b:len(vs)]...)
			sort.Ints(xs)

			sum := 0
			d := k - (a + b)
			for _, v := range xs {
				if v < 0 && d > 0 {
					d--
					continue
				}
				sum += v
			}
			if sum > ans {
				ans = sum
			}
		}
	}
	fmt.Println(ans)
}


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

using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 4e18;
const ll MOD = 1e9+7;

int dp[100010];
int h[100010];
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  
  for (int i = 1; i <= n; i++) {
    dp[i] = inf;
    cin >> h[i];
  }
  
  dp[1] = 0;
  for (int i = 1; i < n; i++) {
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
    dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
  }

  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1024
let () =
  let w = read_line () in
  let tbl = Hashtbl.create (String.length w) in
  String.iter (fun c ->
               let x = try
                   Hashtbl.find tbl c
                 with
                   Not_found -> 0 in
               Hashtbl.replace tbl c (x+1)
              ) w;
  (if (Hashtbl.fold (fun _ v b -> (v mod 2 = 0) && b) tbl true) then "Yes" else "No") |> print_endline


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0;

int main (){
    ll n ;  cin >> n;
  string s; cin >> s;

  for(int i=0;i<n-2;i++){
      if(s.at(i) == 'A' && s.at(i+1) == 'B' && s.at(i+2) == 'C'){
          cnt++;
      }
  }
  cout << cnt << endl;



}

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

int main()
{
    string a,b;
    cin >> a >> b;

    if(a.length() > b.length()) cout << "GREATER";
    else if(a.length() < b.length()) cout << "LESS";
    else if(a == b) cout << "EQUAL";
    else cout << (a > b ? "GREATER" : "LESS");
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits>
#include <climits>
#include <functional>
#include <numeric>

using namespace std;

#define alloc(type,n) (type*)calloc(sizeof(type),(n));
typedef long long lli;

#define N 100000
#define MOD 1000000007

lli n;
vector<lli> x;
stack<lli> s;
lli ans;

lli factrial(lli x){
	static lli dp[N];
	if(dp[x]) return dp[x];
	if(x == 0) 	return dp[x] = 1;
				return dp[x] = (factrial(x-1) * x) % MOD;
}

int main(){
	cin >> n;
	x = vector<lli>(n);
	for(int i = 0;i < n;i++) cin >> x[i];
	ans = 1;
	for(int i = 0;i < n;i++){
		if(x[i] < s.size()*2+1) ans = (ans*(s.size()+1))%MOD;
		else s.push(x[i]);
	}
	cout << (ans*factrial(s.size())) % MOD << endl;
	return 0;
}


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

    using namespace std;
    template <typename T>
    void debug(string t, T input) {
        cout<<t<<"-> "<<input<<"\n";
    }
    template <typename T>
    void debug(int i,string t, T input) {
        cout<<"Case#"<<i<<" "<<t<<"-> "<<input<<"\n";
    }

    vector<int>a(200005);
    vector<int>p(200005);
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
            int x;
            cin>>x;
            p[i]=x;
            a[x]++;
        }
        long long total=0;
        for(int i=1;i<=n;i++){
            if(a[i]>0){
                total+=((long long)a[i]*(long long)(a[i]-1))/2;
            }
        }
        for(int i=0;i<n;i++){
            cout<<total-(long long)a[p[i]]+1LL<<"\n";
        }
        return 0;
    }


Measured memory_bytes: 4224
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;


int main(){
  int N,M;
  ll L;
  cin>>N>>M>>L;
  
  ll DIS[N][N],NEO[N][N];
  
  REP(i,N){
    REP(j,N){
      DIS[i][j]=INF;
      NEO[i][j]=INF;
    }
    DIS[i][i]=0;
    NEO[i][i]=0;
  }
  
  REP(i,M){
    ll A,B,C;
    cin>>A>>B>>C;
    DIS[A-1][B-1]=min(DIS[A-1][B-1],C);
    DIS[B-1][A-1]=min(DIS[B-1][A-1],C);
  }
  
  REP(k,N){
    REP(i,N){
      REP(j,N){
        DIS[i][j]=min(DIS[i][j],DIS[i][k]+DIS[k][j]);
      }
    }
  }
  
  REP(i,N){
    REP(j,N){
      if(i==j) continue;
      if(DIS[i][j]<=L) NEO[i][j]=min(DIS[i][j],1LL);
    }
  }
  
  
  int Q;
  cin>>Q;
  
  REP(k,N){
    REP(i,N){
      REP(j,N){
        NEO[i][j]=min(NEO[i][j],NEO[i][k]+NEO[k][j]);
      }
    }
  }
  
  REP(i,Q){
    int s,t;
    cin>>s>>t;
    
    if(NEO[s-1][t-1]<INF) cout<<NEO[s-1][t-1]-1<<endl;
    else cout<<-1<<endl;
  }
  
}

Measured memory_bytes: 1920
def sb(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
num=[0]*(10**5+1)
num2=[0]*(10**5+1)
cnt=[0]*(10**5+1)
num[2]+=1
for i in range(2,10**5+1):
    if i%2==1:
        n=sb(i)
        if len(n)==1 and n[0][1]==1:
            num[i]+=1
        if num[i]==1 and num[(i+1)//2]==1:
            num2[i]+=1
for i in range(1,len(num2)):
    cnt[i]=cnt[i-1]+num2[i]
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    print(cnt[r]-cnt[l-1])


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

int main() {
    int N;
    cin >> N;
    
    string s = "APPROVED";
    int num;
    rep(i, N) {
        cin >> num;
        if (num % 2 != 0) continue;
        else {
            if ((num % 3 == 0) || (num % 5 == 0)) continue;
            else {
                s = "DENIED";
                break;
            }
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256
Q = int(input())
lr = [list(map(int, input().split())) for _ in range(Q)]
max_v = 10**5
def is_prime(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: 
          continue
        for j in range(i * 2, n+1, i): 
          is_prime[j] = False
    return is_prime
prime = is_prime(max_v)
c = [0 for _ in range(max_v+1)]
for i in range(max_v):
    c[i+1] = c[i]
    if i % 2 == 1 and prime[i] and prime[((i+1)//2)]: 
        c[i+1] += 1
for i in range(Q):
    l = lr[i][0]
    r = lr[i][1]
    print(c[r+1] - c[l])

Measured memory_bytes: 30240
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
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 Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	int n;
	cin >> n;
	vector<p> a(n);
	int i;
	rep(i,n) {
		int c, d;
		cin >> c >> d;
		a[i].first = c + d;
		a[i].second = c - d;
	}
	sort(all(a));
	int ans = 1;
	int now = a[0].first;
	for (i = 1; i < n; i++) {
		if (now <= a[i].second) {
			ans++;
			now = a[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    ll N, K; cin >> N >> K;
    if(K % 2 == 1){
        ll x = N/K;
        x = pow(x, 3);
        cout << x << endl;
    } else {
        ll x = N/K;
        x = pow(x, 3);
        if(N - K/2 < 0){
            cout << x << endl;
            return 0;
        }
        ll y = (N - K/2) / K;
        y++;
        y = pow(y, 3);
        cout << x + y << endl;
    }

    return 0;
}

Measured memory_bytes: 3976
from collections import Counter
N = int(input())

#nを素因数分解したリストを返す
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def unique_count(n):
    res = 0
    while n>=0:
        res += 1
        n -= res
    # print(res)
    return res-1

Cnt = Counter(prime_decomposition(N))
# print(Cnt)
ans = 0
for c in Cnt.values():
    ans += unique_count(c)
print(ans)

Measured memory_bytes: 9468
# coding: utf-8
import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = list(map(int, input().split()))
INF = 10 ** 17

@lru_cache(None)
def F(index, n):
    '''index以降、n個選ぶ最大値を返す'''
    if index >= N: 
        return -INF
    if N - index < 2 * n - 1:  # n個選べない
        return -INF
    if n == 0:
        return 0
    elif n == 1:
        return max(A[index:])
    ret = max(A[index] + F(index+2, n-1), F(index+1, n))
    return ret

answer = F(0, N//2)
print(answer)


Measured memory_bytes: 173732
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// *st.find_by_order(index), 0-based
// order_of_key(e)

const int mx=1777;
const int mx2=1e6+777;
bool flag[mx];
vector<int> p;
int factor[mx2];


bool pc(vector<int> A) {
	for (auto x : A) {
		for (auto d : p) {
			if(d*d>=x) break;
			bool ok=false;
			while(x%d==0)
				x/=d, ok=true;
			if(ok) factor[d]++;
		}
		if(x>1) factor[x]++;
	}
	for (int i=0; i<mx2; i++)
		if(factor[i]>1)
			return false;
	return true;
}

bool sc(vector<int> &A) {
	int g=A[0];
	for (auto x : A)
		g=__gcd(g,x);
	return g==1;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	for (int i=0; i<mx; i++)
		flag[i]=true;
	flag[0]=flag[1]=false;
	for (int i=2; i*i<mx; i++)
		if(flag[i])
			for (int j=i; j*i<mx; j++)
				flag[i*j]=false;
	for (int i=0; i<mx; i++)
		if(flag[i])
			p.push_back(i);
	int N; cin>>N;
	vector<int> A(N);
	for (int i=0; i<N; i++)
		cin>>A[i];
	if(pc(A)) cout<<"pairwise coprime\n";
	else if(sc(A)) cout<<"setwise coprime\n";
	else cout<<"not coprime\n";
	return 0;
}

Measured memory_bytes: 14984
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	int r;
	cin >> r;

	cout << r * r << "\n";

	return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};
use std::collections::BTreeMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        s: [String; n],
    }

    let mut map = BTreeMap::new();

    for s in s {
        map.entry(s).and_modify(|e| *e += 1).or_insert(1);
    }

    println!("AC x {}", map.get("AC").unwrap_or(&0));
    println!("WA x {}", map.get("WA").unwrap_or(&0));
    println!("TLE x {}", map.get("TLE").unwrap_or(&0));
    println!("RE x {}", map.get("RE").unwrap_or(&0));
}


Measured memory_bytes: 7848
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vint r(n+5);
    rep(i,n){
        cin>>r[i];
    }
    int max=-999999999;
    int min=r[0];
    REP(i,1,n){
        chmax(max,r[i]-min);
        chmin(min,r[i]);
    }
    cout<<max<<'\n';
    return(0);
}


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

using namespace std;
using LL = long long;

constexpr LL INF = 1e15;

struct ListNode {
    ListNode() = default;
    ListNode(LL _data, LL _id) : data(_data), id(_id) {}
    bool operator<(const ListNode& other) const {
        return data == other.data ? id < other.id : data < other.data;
    }
    LL data = -INF, id = -1;
    list<ListNode>::iterator itr;
};

LL n, cnt, ans;
map<LL, bool> deleted;
list<ListNode> lst;
priority_queue<ListNode> q;

inline void calc(int tot = 0) {
    while (!q.empty() && tot < n / 2) {
        auto cur= q.top();
        q.pop();
        if (deleted[cur.id]) continue;
        ans += cur.data, tot++;

        LL data(0);
        auto itr = cur.itr;
        itr--;
        data += itr->data, deleted[itr->id] = true, itr = lst.erase(itr);
        data -= itr->data, deleted[itr->id] = true, itr = lst.erase(itr);
        data += itr->data, deleted[itr->id] = true, itr = lst.erase(itr);

        auto newNode = ListNode(data, cnt++);
        newNode.itr = lst.insert(itr, newNode);
        q.push(newNode);
    }
}

int main() {
    scanf("%d", &n);
    lst.emplace_back(ListNode(-INF, cnt++));
    for (int i = 0, tmp; i < n; i++) {
        scanf("%d", &tmp);
        auto newNode = ListNode(tmp, cnt++);
        newNode.itr = lst.insert(lst.end(), newNode);
        q.push(newNode);
    }
    lst.emplace_back(ListNode(-INF, cnt++));
    calc();
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 27912
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
const int N=100050;
int G[N*10],to[N*100],w[N*100],nxt[N*100],sz=0,tot,id1[N<<2],id2[N<<2],x,y,p,c;
ll d[N*10];
struct node{
	int p;
	ll d;
	node(){}
	node(int p,ll d):p(p),d(d){}
	inline bool operator <(const node &b)const{return d>b.d;}
};
priority_queue<node> Q;
inline void adde(int u,int v,int c){
	to[++sz]=v;w[sz]=c;nxt[sz]=G[u];G[u]=sz;
}
void build(int o,int L,int R){
	if(L==R){adde(L,id1[o]=++tot,0);adde(id2[o]=++tot,L,0);}
	else{
		int lc=o<<1,rc=lc|1,M=L+R>>1;
		build(lc,L,M);build(rc,M+1,R);
		adde(id1[lc],id1[o]=++tot,0);adde(id1[rc],id1[o],0);
		adde(id2[o]=++tot,id2[lc],0);adde(id2[o],id2[rc],0);
	}
}
void ask(int o,int L,int R){
	if(x<=L&&y>=R){adde(id1[o],p,c);adde(p,id2[o],0);}
	else{
		int lc=o<<1,rc=lc|1,M=L+R>>1;
		if(x<=M)ask(lc,L,M);
		if(y>M)ask(rc,M+1,R);
	}
}
int main(){
	int n,m,i,u,v;
	node h;
	scanf("%d%d",&n,&m);
	build(1,1,tot=n);
	while(m--){
		scanf("%d%d%d",&x,&y,&c);p=++tot;
		ask(1,1,n);
	}
	memset(d,0x3f,sizeof(d));
	Q.push(node(1,d[1]=0ll));
	while(!Q.empty()){
		h=Q.top();Q.pop();
		if(d[u=h.p]!=h.d)continue;
		if(u==n){
			printf("%lld\n",d[n]);
			return 0;
		}
		for(i=G[u];i;i=nxt[i])if(d[u]+w[i]<d[v=to[i]])Q.push(node(v,d[v]=d[u]+w[i]));
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 59764
N = int(input())
count = [0]*4
for i in range(N):
    S = input()
    if S == 'AC':
        count[0] += 1
    elif S == 'WA':
        count[1] += 1
    elif S == 'TLE':
        count[2] += 1
    else:
        count[3] += 1
print('AC x ' + str(count[0]))
print('WA x ' + str(count[1]))
print('TLE x ' + str(count[2]))
print('RE x ' + str(count[3]))


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

int main()
{
  ll a, b, x;
  cin >> a >> b >> x;
  ll c = b / x;
  ll d = (a - 1) / x;
  if(a == 0) d = 0, c++;
  cout << c - d << endl;
  
  return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main(){
    ll n;
    cin >> n;
    ll ans = n*(n-1)/2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

int main(){
    string S;
    cin >> S;
    if( S == "SUN") cout << 7 << endl;
    elif(S == "MON") cout << 6 << endl;
    elif(S == "TUE") cout << 5 << endl;
    elif(S == "WED") cout << 4 << endl;
    elif(S == "THU") cout << 3 << endl;
    elif(S == "FRI") cout << 2 << endl;
    elif(S == "SAT") cout << 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int h,w,k;cin>>h>>w>>k;
  vector<string> c(h);
  rep(i,h)cin>>c[i];
  int res=0;
  for(int bitx=0;bitx<(1<<w);++bitx){
    for(int bity=0;bity<(1<<h);++bity){
      int buf=0;
      rep(i,h){
        rep(j,w){
          if(!(bity&(1<<i))&&!(bitx&(1<<j))){
            if(c[i][j]=='#')++buf;
          }
        }
      }
      if(buf==k)++res;
    }
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 3628
while True:
    num = int(input())
    if num == 0:break
    else:
        #要素0が10個入ったリストを作る
        num_list = [0 for _ in range(10)]
        
        #標準入力で買われたアイスの番号を入力しリストに加える
        for _1 in range(num):
            n = int(input())
            num_list[n] += 1
            
        #0なら"-"を出力する
        for i in range(0,10):
            if num_list[i] == 0:print("-")
            
        #0でないなら"*"を買われた数出力する
            else:
                for j in range(num_list[i]):
                    print("*",end="")
                print()


Measured memory_bytes: 7588
#include<stdio.h>

int main(){
    int N, M, A;
    int K;
    int sum[40];
    int i,j;
    int ans = 0;

    for(i=0; i<40; i++){
        sum[i] = 0;
    }

    scanf("%d %d", &N, &M);

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

    for(i=1; i<=M; i++){
        if(sum[i] == N){
            ans += 1;
        }
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))

int main(){
	ll x,y;
	cin >> x >> y;
	ll ans = 0;
	ans += max(0LL,4LL-x);
	ans += max(0LL,4LL-y);
	if(ans==6)ans+=4;
	cout << ans*100000 << endl;

}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ans=0

  _ba=0
  _b=0
  _a=0
  for _ in range(n):
    s=S()
    ans+=s.count('AB')

    if s[0]=='B':
      if s[-1]=='A':
        _ba+=1
      else:
        _b+=1
    else:
      if s[-1]=='A':
        _a+=1

  ans+=max(0,_ba-1)

  if _ba>0:
    if _b>0:
      ans+=1
      _b-=1
    if _a>0:
      ans+=1
      _a-=1

  # if _ba>0:
  #   _b+=1
  #   _a+=1

  ans+=min(_b,_a)

  return ans

# main()
print(main())


Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;



int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	

	
	ini(n);
	ini(k);
	int h[51];
	int p[51];
	h[0] = 1;
	p[0] = 1;
	FOR(i,1,51){
		h[i] = 3+2*h[i-1];
		p[i] = 1+2*p[i-1];
	}
	int rick = 0;
	while(n>0 and k>0){
		if(k>=2+2*h[n-1]){
			rick+=1+2*p[n-1];
			k = 0;
			break;
		}
		else if (k>=h[n-1]+2){
			rick+=1+p[n-1];
			k-=2+h[n-1];
		}
		else k--;
		n--;
	}
	if(k)rick++;
	out(rick);







	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{  
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		
	if(x==0&&y==0)
		break;
	if(x>y)
	printf("%d %d\n",y,x);
	
	else printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

ll beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}

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

	int N; cin >> N;

	
	ll ans = 0;
	
	int big;
	vvi cnt(10,vi(10,0));

	rep1(A,N+1) {
		if(A%10 == 0) continue;
		if(A <= 9) big = 1;
		else if(A <= 99) big = 10;
		else if(A <= 999) big = 100;
		else if(A <= 9999) big = 1000;
		else if(A <= 99999) big = 10000;
		else big = 100000;
		string B = to_string(A);
		reverse(all(B));
		int Bi = stoi(B);
		cnt[A/big][A%10]++;
		
	
		
	}
	rep1(i,10) repk(j,i,10) {
		//cout << i << " " << j << ": " << cnt[i][j] << endl;
		if(i == j) ans += cnt[i][j] * cnt[i][j];
		else ans += cnt[i][j] * cnt[j][i] * 2;
	}
	cout << ans << endl;



	return 0;

	



}

Measured memory_bytes: 256
from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def nextLine(): return next(stdin)
def nextStrList(): return nextLine().split()
def nextIntList(): return [int(_) for _ in nextStrList()]

from collections import defaultdict

def main():
	n,m=nextIntList()
	hs=nextIntList()
	
	pairHeight=defaultdict(lambda:0)
	for mi in range(m):
		a,b=nextIntList()
		
		pairHeight[a]=max(hs[b-1],pairHeight[a])
		pairHeight[b]=max(hs[a-1],pairHeight[b])

	c=0
	for ni in range(1,n+1):
		if pairHeight[ni]<hs[ni-1]:
			c+=1
			
	print(c)
	

if __name__=="__main__":
	main()



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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve()
{
  int N, M;
  cin >> N >> M;
  vector<vector<int>> to(1000005);
  vector<vector<int>> co(1000005);
  vector<int> in(1000005);
  for (int i = 0; i < M; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    l--;
    r--;
    to[l].push_back(r);
    co[l].push_back(d);
    in[r]++; // 入次数
  }
  dumpv(to, N);
  dumpv(co, N);

  // 閉路検出
  stack<int> st;
  for (int i = 0; i < N; i++) {
    if (in[i] == 0)
      st.push(i);
  }
  int num = 0;
  while (st.size()) {
    int v = st.top();
    st.pop();
    num++;
    for (auto u : to[v]) {
      in[u]--;
      if (in[u] == 0)
        st.push(u);
    }
  }
  dump(num, N);
  if (num != N) {
    // 閉路が存在
    cout << "No" << endl;
    return;
  }

  vector<int> has_parent(1000005);
  for (int i = 0; i < N; i++) {
    for (auto v : to[i]) {
      has_parent[v] = 1;
    }
  }
  dumpv(has_parent, N);
  vector<int> pos(1000005, -1);
  int ans = true;
  function<void(int, int)> dfs = [&](int v, int p) {
    if (pos[v] == -1)
      pos[v] = p;
    else {
      if (pos[v] != p)
        ans = false;
      return;
    }
    dumpv(v, ans, pos, N);
    for (int i = 0; i < to[v].size(); i++) {
      dfs(to[v][i], p + co[v][i]);
    }
  };
  for (int i = 0; i < N; i++) {
    if (to[i].size() > 0 && !has_parent[i])
      dfs(i, 0);
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 71424
import java.util.*;

public class Main{
    
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        long n = Integer.parseInt(sc.next());
        
        long ans = n*(n+1)/2;
        for(int i=2; i<=(int)1e7; i++){
            //System.out.println(ans);
            long tmp = n/i;
            tmp = tmp*(tmp+1)/2*i;
            ans += tmp;
        }
        
        System.out.println(ans);
    }
    
}


Measured memory_bytes: 35592
#include <iostream>
#include <vector>

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

    std::vector<int> a;

    for (auto i = 0; i < N; ++i) {
        int value;
        std::cin >> value;
        a.push_back(value);
    }

    int result[2] = {0, 0};
    auto i = 0;

    while (a.size() > 0) {
        auto element = std::max_element(a.begin(), a.end());
        result[i % 2] += *element;
        a.erase(element);

        ++i;
    }

    std::cout << result[0] - result[1] << std::endl;

    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<pair<int,int> > rvpi(n), bvpi(n);
  rep(i,n) cin >> rvpi[i].first >> rvpi[i].second;
  rep(i,n) cin >> bvpi[i].first >> bvpi[i].second;
  sort(rvpi.begin(),rvpi.end());
  sort(bvpi.begin(),bvpi.end());
  
  int ans = 0;
  rep(i,n){
    int max_by_ind = -1;
    int max_by = -1;
    rep(j,rvpi.size()){
      if((bvpi[i].first>rvpi[j].first) && (bvpi[i].second>rvpi[j].second)){
        if(max_by < rvpi[j].second){
          max_by_ind = j;
          max_by = rvpi[j].second;
        }
      }
    }
    if(max_by != -1){
      rvpi.erase(rvpi.begin() + max_by_ind);
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n,k;cin>>n>>k;
  ll ans=0;
  // kの倍数を足す．
  ans+=ll(pow(int(n/k),3));
  // k が偶数のときは多くなる
  if(k%2==0){
    int multiple = n/k;
    int half = multiple + (0?1:(k/2<=n-k*multiple));
    // int half = multiple+1;
    ans+=ll(pow(half,3));
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
//
// Created by yamunaku on 2020/02/19.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    int n;
    cin >> n;
    map<string, int> mp;
    string s;
    rep(i, n){
        cin >> s;
        mp[s]++;
    }
    int ma = 0;
    for(auto &p:mp){
        ma = max(ma, p.second);
    }
    for(auto &p:mp){
        if(p.second == ma){
            cout << p.first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

int main(void)
{
	char S[5];
	int i = 0,j = 0;
	int count = 1;
	int charcount = 1;

	cin >> S;

	count = 1;

	for (i = 1; i < 4; i++)
	{
		for (j = 0; j < i; j++)
		{
			if (S[i] == S[j])
				break;
				
			if(j == i - 1)
				count++;
		}
	}

	if (count == 2)
	{
		for (i = 1; i < 4; i++)
		{
			if (S[i] == S[0])
				charcount++;
		}
	}

	if (charcount == 2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256