akhauriyash/Code-Regression huggingface dataset:
N = int(input())

#高速化dijkstra
import heapq
def dijkstra_heap(s,edge):
  #始点sから各頂点への最短距離
  d = [float("inf")] * (N+1)
  used = [False] * (N+1)
  d[s] = 0
  used[s] = True
  edgelist = []
  #edgelist : (sからの暫定(未確定)最短距離,頂点)のリスト
  #edge[s] : sから出る枝の(重み,終点)の配列
  for w,v in edge[s]:
    heapq.heappush(edgelist,w*10**6+v) #sの隣の点は枝の重さがそのまま暫定最短距離となる
  while len(edgelist):
    #まだ使われてない頂点の中から最小の距離のものを探す→確定させる
    minedge = heapq.heappop(edgelist)
    #minedge : (sからの(確定)最短距離,頂点)
    v = minedge%10**6
    if used[v]:
      continue
    d[v] = minedge//10**6
    used[v] = True
    for w,u in edge[v]:
      if not used[u]:
        heapq.heappush(edgelist,(d[v]+w)*10**6+u)
  return d

################################

edge = [[] for _ in range(N+1)]

for _ in range(N-1):
  A, B, C = map(int, input().split())
  edge[A].append((C,B))
  edge[B].append((C,A))

Q,K = map(int, input().split())

d = dijkstra_heap(K,edge)

ans = []
for q in range(Q):
  x,y = map(int, input().split())
  ans.append(d[x]+d[y])
#print(ans)

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


Measured memory_bytes: 101024
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
sunuke = sum(A)
ara = 0
ans = float("inf")
for i in range(N-1, 0, -1):
    sunuke -= A[i]
    ara += A[i]
    ans = min(ans, abs(sunuke - ara))
print(ans)

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

int main(){
  long long int N;
  cin >> N;
  if (N%2==1)cout << 0;
  else {
    long long int ans=0;
    for(long long int i=10;i<=N;i=i*5){
      ans+=N/i;
    }
    cout << ans;
  }
}


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

typedef long long ll;
typedef unsigned long long ull;

bool pcomp(pair<ll, ll> l, pair<ll, ll> r) {
  return l.second > r.second;
}

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

  vector<ll> v(n, 0);
  for (ll i = 0; i < n; ++i) {
    cin >> v[i];
  }

  map<ll, ll> lm;
  map<ll, ll> rm;
  for (ll i = 0; i < n; i+=2) {
    if (lm.find(v[i]) == lm.end()) {
      lm[v[i]] = 1;
    } else {
      lm[v[i]]++;
    }

    if (rm.find(v[i+1]) == rm.end()) {
      rm[v[i+1]] = 1;
    } else {
      rm[v[i+1]]++;
    }
  }


  for (auto itr = rm.begin(); itr != rm.end(); ++itr) {
    if (lm.find(itr->first) != lm.end()) {
      if (lm[itr->first] < itr->second) {
        lm[itr->first] = itr->second;
      }
    } else {
      lm[itr->first] = itr->second;
    }
  }

  vector<pair<ll, ll>> vv;
  for (auto itr = lm.begin(); itr != lm.end(); ++itr) {
    vv.push_back(pair<ll, ll>(itr->first, itr->second));
  }
  sort(vv.begin(), vv.end(), pcomp);

  if (vv.size() == 1) {
    cout << n/2 << endl;
    return 0;
  }
  cout << n - vv[0].second - vv[1].second << endl;
    
  return 0;
}

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

int main()
{
	ll N;
	map<string,ll> M;
	cin>>N;
	for(ll i=0;i<N;i++){
		string A="";
		cin>>A;
		M[A]++;
	}
	cout<<M.size()<<endl;
	return 0;
}



Measured memory_bytes: 19224
N = int(input())
A = list(map(int, input().split())) # 0からN(N+1個)
B = list(map(int, input().split())) # 0からN-1(N個)

ans = 0

for i in range(N): # 0からN-1
    if A[i] <= B[i]:
        ans += A[i]
        B[i] -= A[i]
        A[i] = 0
        if A[i+1] <= B[i]:
            ans += A[i+1]
            A[i+1] = 0
        else:
            ans += B[i]
            A[i+1] -= B[i]
    else:
        ans += B[i]
        A[i] -= B[i]

print(ans)




Measured memory_bytes: 18624
import java.util.Scanner;
     
    public class Main{
        public static void main(String[] args){
            Scanner scanner = new Scanner(System.in);
     
            int a, b;
            a = scanner.nextInt();
            b = scanner.nextInt();
            if(b % a == 0){
                System.out.println(a + b);
            }
            else{
                System.out.println(b - a);
            }
        }
    }

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

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    ll ans = 1;
    for(int i=0;i<n;i++){
        if(ans!=0){
            ll d = 1000000000000000000/ans;
            if(d<a[i]){cout << -1 << endl; return 0;}
        }
        ans *= a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Util{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		int K = ri();
        string S = rs();

        if(S.Length > K) {
            S = S.Substring(0, K) + "...";
        }

		Console.WriteLine(S);
		Console.ReadLine();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
    static int[] generateNums(int num, int N){return Enumerable.Repeat(num, N).ToArray();}
    static int[] generateSuretsu(int N){return Enumerable.Range(0, N).ToArray();}
}

public static class Combination {
	//使い方:int[][] Is = Combination.Enumerate(nums, k, withRepetition:false).ToArray();
    public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition) {
        if (k == 1) {
            foreach (var item in items)
                yield return new T[] { item };
            yield break;
        }
        foreach (var item in items) {
            var leftside = new T[] { item };

            // item よりも前のものを除く （順列と組み合わせの違い)
            // 重複を許さないので、unusedから item そのものも取り除く
            var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();

            foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
                yield return leftside.Concat(rightside).ToArray();
            }
        }
    }
}


Measured memory_bytes: 27452
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main() {
    string s,t;
    cin >> s >> t;
    char tmp;
    for(int i = 0; i < s.size(); i++) {
        for(int j = 0; j < i; j++) {
            if(s[i] < s[j]) {
                tmp = s[i];
                s[i] = s[j];
                s[j] = tmp;
            }
        }
    }
    for(int i = 0; i < t.size(); i++) {
        for(int j = 0; j < i; j++) {
            if(t[i] > t[j]) {
                tmp = t[i];
                t[i] = t[j];
                t[j] = tmp;
            }
        }
    }
    if(s < t) {
        cout << "Yes";
    }else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;
struct edge{
  int to;
  int id;
};
int n;
vector<vector<edge>> G;
vector<int> C;
int max_c = 0;

void dfs(int v, int p = -1, int c = -1){
  int k = 1;
  for(auto e:G[v]){
    if(e.to == p) continue;
    if(c == k) k++;
    chmax(max_c,k);
    C[e.id] = k;
    dfs(e.to,v,k);
    k++;
  }
}

int main(){
  cin >> n;
  G.resize(n);
  C.resize(n-1,0);
  
  rep(i,n-1){
    int a,b; cin >> a >> b;
    a--,b--;
    edge e1; e1.to = b; e1.id = i;
    edge e2; e2.to = a; e2.id = i;
    G[a].push_back(e1);
    G[b].push_back(e2);
  }
  
  dfs(0);
  cout << max_c << endl;
  rep(i,n-1) cout << C[i] << endl;
  
  return 0;
}

Measured memory_bytes: 8320
#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 100000 + 10;
struct TreeNode{
    vector<int> sons;
    bool flag = false;
};
TreeNode tree[MAXN];
vector<int> seq;

int dis(int root, int fa) {
    if (root == 1) {
        tree[root].flag = true;
        seq.push_back(root);
        return 0;
    }

    int tmp = -1;
    for (int son : tree[root].sons) {
        if (son == fa) continue;
        tmp = dis(son, root);
        if (tmp != -1) {
            tree[root].flag = true;
            seq.push_back(root);
            return tmp+1;

        }
    }
    return tmp;
}
int cnt(int root, int fa) {
    int ret = 1;
    for (int son : tree[root].sons) {
        if (son == fa) continue;
        ret += cnt(son, root);
    }
    return ret;
}


int main() {
//    freopen("test.txt", "r", stdin);
    int n, a, b;
    scanf("%d", &n);
    for (int i = 1; i <= n-1; i++) {
        scanf("%d%d", &a, &b);
        tree[a].sons.push_back(b);
        tree[b].sons.push_back(a);
    }
    dis(n, n+1);
    int snu = seq.size() / 2;
    int fen = seq.size() - snu;
    vector<int> ret(2, 0);
    for (int i = 0; i < fen; i++) {
        int root = seq[i];
        ret[0]++;
        for (int son : tree[root].sons) {
            if (tree[son].flag) continue;
            ret[0] += cnt(son ,root);
        }
    }
    for (int i = 0; i < snu; i++) {
        int pos = seq.size()-1 - i;
        int root = seq[pos];
        ret[1]++;
        for (int son : tree[root].sons) {
            if (tree[son].flag) continue;
            ret[1] += cnt(son ,root);
        }

    }
    if (ret[0] > ret[1]) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;


    return 0;
}

Measured memory_bytes: 11772
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for j in range(N)]  
m = -9999999999  
for i in range(1, 2**10):
    s = 0
    for j in range(N):
        count = 0
        for k in range(10):
            if ((i >> k)&1) == 1 and F[j][k] == 1:
                count += 1
        s += P[j][count]
    m = max(m, s)  
print(m)

Measured memory_bytes: 42092
#include<iostream>
using namespace std;
int main(){
	int m,f,r;

	while(1){
		cin >> m >> f >> r;
		if((m == -1)&&(f == -1)&&(r == -1)) break;

		if((m == -1)||(f == -1)){
			cout << "F" << endl;

		}else if(m + f >= 80){
			cout << "A" << endl;

		}else if((m + f < 80)&&(m + f >= 65)){
			cout << "B" << endl;

		}else if((m + f < 65)&&(m + f >= 50)){
			cout << "C" << endl;

		}else if((m + f < 50)&&(m + f >= 30)&&(r < 50)){
			cout << "D" << endl;

		}else if((m + f < 50)&&(m + f >= 30)&&(r >= 50)){
			cout << "C" << endl;

		}else if(m + f < 30){
			cout << "F" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
//const ll INFL = 1LL << 60;//10^18 = 2^60
const ll INFL = 1LL << 60;
const int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

ll kai_mod(ll x){
  if(x == 1) return 1;
  return x * kai_mod(x-1) % MOD;
}


ll N, Q;

vector<ll> E[200010];
vector<ll> ans(200010);
vector<ll> query(200010);

void dfs(ll now, ll from){
  ans[now] += query[now];
  for(ll to : E[now]){
    if(to == from) continue;
    query[to] += query[now];
    dfs(to, now);
  }
}

int main(void){
  cin >> N >> Q;
  rep(i, N-1){
    ll a, b;
    cin >> a >> b;
    a--, b--;
    E[a].pb(b);
    E[b].pb(a);
  }
  rep(i, Q){
    ll p, x;
    cin >> p >> x;
    p--;
    query[p] += x;
  }
  dfs(0, -1);
  rep(i, N){
    cout << ans[i] << endl;
  }

}


Measured memory_bytes: 27264
n = int(input())
A = list(map(int, input().split()))

dp = [0] * (10**6+1)

for a in A:
    dp[a] += 1

ans = 0

for i in range(10**6+1):
    if dp[i] == 1:
        ans += 1
    if dp[i] != 0:
        for j in range(2*i, 10**6+1, i):
            if dp[j] != 0:
                dp[j] += 1

print(ans)

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

#define _BIGNUM_ 100000000

using namespace std;
typedef long long ll;

const ll mod = 1e9+7;

int main() {
  string S;
  cin >> S;
  int len = S.size();
  int w = S.size() - 7;
  for (int j=0; j < len-w+1; ++j) {
    string t = S.substr(0, j) + S.substr(w+j);
    if (t == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    char s[6];
    scanf("%s",s);

    if(s[0]=='S'){
    printf("Cloudy");
  }

    else if(s[0]=='C')
    printf("Rainy");

else if(s[0]=='R'){
    printf("Sunny");
  }




    return 0;
}


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

using namespace std;

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

    int i = 1;
    int a = s;
    set <int> hoge = {s};
    while(true) {
        // cout << "i: " << i << ", a: " << a << endl;
        if (a % 2 == 0) {
            a = a / 2;
        } else {
            a = 3 * a + 1;
        }
        i++;
        if (!hoge.insert(a).second) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
n,x=map(int,input().split())
a=list(map(int,input().split()))
count=0

for i in range(n):
    if x<a[i]:
        count+=a[i]-x
        a[i]=x
#print(a)
for i in range(n-1):
    if a[i]+a[i+1]>x:
        count+=a[i]+a[i+1]-x
        a[i+1]-=a[i]+a[i+1]-x
#print(a)
print(count)

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

int main() {
  int N;
  cin >> N;
  int Y = 0;
  int64_t A = 2;
  int64_t B = 1;
  int64_t C = A + B;
  if (N == 1){
    cout << 1 << endl;
     Y = 1;
  }
  for (int i = 1; i < N; i++){
    int64_t A1 = A;
    int64_t B1 = B;
    int64_t C1 = A + B;
    A = B1;
    B = C1;
    C = A1 + B1;
  }
  if (Y == 0){
    cout << C << endl;
  }
  
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
const ll MAXN=5050;

int main(){
  fastIO();
  int x;
  cin>>x;
  if(x>=30){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

int b[222222];
int w[222222];

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	int n;cin >> n;
	string str;cin >> str;

	int cou = 0;
	REP(i, n){
		if(str[i] == '#')cou++;
		b[i] = cou;
	}
	cou = 0;
	REV(i, n){
		if(str[i] == '.')cou++;
		w[i] = cou;
	}

	int ans = w[0];
	REP(i, n){
		ans = min(ans, b[i] + w[i+1]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i = a:i<b;i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const string D_blue    = "\x1b[36m";
const string D_green   = "\x1b[32m";
const string D_red     = "\x1b[31m";
const string D_yellow  = "\x1b[33m";
const string Db_red    = "\x1b[41m";
const string Db_yellow = "\x1b[43m";
const string D_end     = "\x1b[39m";
const string Db_end    = "\x1b[49m";

int main (){
  int n;
  while (cin >> n){
    int ans = 0;
    int a,b;
    cin >> a >> b;
    
    REP(i,n + 1){      
      int sum = 0;
      int r;
      for(int num = i; num > 0; num /= 10){
	sum += num % 10;
      }
      if(sum >= a && sum <= b){
	ans += i;
      }
    }    
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;

ll perm(ll n) {
  ll ans = 1;
  for (ll i = 1; i <= n; i++) {
    ans *= i;
  }
  return ans;
}

int main() {
  const ll N = 8;
  ll n;
  ll p[N];
  ll q[N];
  cin >> n;
  for (ll i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (ll i = 0; i < n; i++) {
    cin >> q[i];
  }

  ll pcnt = 0, qcnt = 0, dig;
  ll selected[N];

  for (ll i = 0; i < n - 1; i++) {
    dig = p[i] - 1;
    for (ll j = 0; j < i; j++) {
      if (selected[j] < p[i]) {
        dig--;
      }
    }
    pcnt += perm(n - i - 1) * dig;
    selected[i] = p[i];
  }
  
  for (ll i = 0; i < n - 1; i++) {
    dig = q[i] - 1;
    for (ll j = 0; j < i; j++) {
      if (selected[j] < q[i]) {
        dig--;
      }
    }
    qcnt += perm(n - i - 1) * dig;
    selected[i] = q[i];
  }

  cout << abs(pcnt - qcnt) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
#define rep1(i,n) for(decltype(n) i=1; i<=n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

template <ll Mod>
class modint {
    public:
    ll n=0;
    modint(){}
    modint(ll n):n(n){}
    modint& operator = (modint const& a) = default;
    modint& operator = (int a) {
        n = a;
        clamp();
        return *this;
    }
    friend modint operator * (modint a, modint b) {
        a.n *= b.n;
        a.clamp();
        return a;
    }
    modint operator - () {
        modint t = *this;
        t.n = -t.n;
        t.clamp();
        return t;
    }
    modint& operator *= (modint const& a) {
        n *= a.n;
        clamp();
        return *this;
    }
    modint& operator *= (ll const& a) {
        n *= a;
        clamp();
        return *this;
    }
    modint& operator += (modint const& a) {
        n += a.n;
        clamp();
        return *this;
    }
    modint& operator %= (modint const& a) {
        n %= a.n;
        clamp();
        return *this;
    }
    void clamp() {
        n %= Mod;
        if (n < 0)
            n += Mod;
    }
    friend ostream& operator << (ostream& os, modint const& a) {
        os << a.n;
        return os;
    }
    friend bool operator == (modint const& a, int b) {
        return a.n == b;
    }
    modint& pow(ll p) {
        ll a=1;
        ll e=n;
        while (p > 0) {
            if (p&1) {
                a *= e;
                a %= Mod;
            }
            e *= e;
            e %= Mod;
            p >>= 1;
        }
        n = a;
        clamp();
        return *this;
    }
    modint& inv() {
        return pow(Mod-2);
    }
};

template <class T>
class perm {
    vector<T> facts, ifacts;
public:
    perm(int n): facts(n+1), ifacts(n+1) {
        facts[0] = 1;
        rep1(i,n) facts[i] = facts[i-1] * i;
        ifacts[n] = facts[n];
        ifacts[n].inv();
        for (int i=n; i> 0; --i)
            ifacts[i-1] = ifacts[i] * i;
    }
    T const& f(int n) const {
        return facts[n];
    }
    T c(int n, int k) const {
        return facts[n] * ifacts[k] * ifacts[n-k];
    }
    T p(int n, int k) const {
        return facts[n] * ifacts[n-k];
    }
};

int main() {
    using mint = modint<(ll)1e9+7>;
    perm<mint> perm(5e5);
    mint ans=0LL;
    ll N, M;
    cin >> N >> M;
    rep(i,N+1) {
        mint t = perm.c(N,i);
        t *= perm.p(M-i,N-i);
        if (i%2) t = -t;
        ans += t;
    }
    ans *= perm.p(M,N);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10680
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
using namespace std;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
inline int read(){
	int x = 0;char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + c - '0' , c = getchar();
	return x;
}
inline void write(int x){
	if (!x){
       ptc('0');
       return;
	}
	int dg[20] , len = 0;
	while (x) dg[len++] = x % 10 , x /= 10;
	while (len--) ptc(dg[len]+'0');
}
inline void writeln(int x){
	write(x);
	ptc('\n');
}

const int N = 1e5 + 10;

vector<int> solve(int len,int ed){
	if (len == 2){
		vector <int> res(0 , 0);
		res.push_back(0);
		res.push_back(ed);
		return res;
	}
	
	if (ed & (len >> 1)){
		vector<int> lef = solve(len >> 1 , 1) , rig = solve(len >> 1 , ed ^ ((len >> 1) + 1));
		
		for (int i = 0;i < (len >> 1);i++){
			rig[i] ^= ((len >> 1) + 1);
			lef.push_back(rig[i]);
		}
		return lef;
	}else{
		vector<int> lef = solve(len >> 1 , ed) , rig = solve(len >> 1 , lef[1]) , res;
		
		
		for (int i = 0;i < (len >> 1);i++){
			rig[i] ^= (len >> 1);
		}
		res.push_back(lef[0]);
		for (int i = 0;i < (len >> 1);i++) res.push_back(rig[i]);
		for (int i = 1;i < (len >> 1);i++) res.push_back(lef[i]);
		return res;
	}
}
/*
auto auto(auto auto){
	for (auto auto = auto;auto != auto;auto ++){
	}
	 
}*/



int n , a , b;

int main(){
	scanf("%d%d%d",&n,&a,&b);
	b ^= a;
	
	if ( !(__builtin_popcount(b) & 1) ){
		puts("NO");
	}else{
		puts("YES");
		vector<int> res = solve(1 << n , b);
		for (int i = 0;i < 1 << n;i++) res[i] ^= a;
		for (int i = 0;i < 1 << n;i++) printf("%d ",res[i]);
	}
	return 0;
}

Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n-1; i++) a[i+1] += a[i];
  ll res =  1e18;
  for (int i = 0; i < n-1; i++) {
    ll x, y;
    x = a[i];
    y = a[n-1]-a[i];
    res = min(res, abs(x-y));
  }
  dump(res);
  return 0;
}


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int baseNum = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		int num01 = 1;
		int num02 = 2;

		while(num > baseNum){
			if (num <= baseNum) {
				break;
			}
			num = num/baseNum;
			list.add(num%baseNum);
		}
		if(num == baseNum){
			System.out.println((list.size()+num02));
		}else{
			System.out.println((list.size()+num01));
		}
		sc.close();
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline long long in(){long long x=0;char c=getchar();bool neg=false;while(c!='-'&&('0'>c||c>'9')) c=getchar();if(c=='-') neg=true,c=getchar();while('0'<=c&&c<='9') x=10*x+c-'0',c=getchar();if(neg) x=-x;return x;}
inline void out(long long x){if(x<0) putchar('-'),x=-x;if(x>9) out(x/10);putchar(x%10+'0');}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "d"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define _ putchar(' ')
#define __ putchar('\n')
const int N=110;
int n,w,kq,lim;
int a[N],b[N];
int f[N][100010];
main()
{
    fasty;
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    cin>>n>>w;
    forinc(i,1,n) cin>>a[i]>>b[i];
    reset(f,127);
    lim=f[0][0];
    f[0][0]=0;
    forinc(i,0,n-1) forinc(j,0,100000) if(f[i][j]<=w)
    {
        f[i+1][j+b[i+1]]=min(f[i+1][j+b[i+1]],f[i][j]+a[i+1]);
        f[i+1][j]=min(f[i+1][j],f[i][j]);
    }
    fordec(j,100000,0) if(f[n][j]<=w) return cout<<j,0;
}


Measured memory_bytes: 86272
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.typecons, std.math;

  int h, w, d; rd(h, w, d);
  auto c=new int[][](h, w);
  foreach(i; 0..h) c[i]=readln.split.to!(int[]);
  foreach(i; 0..h)foreach(j; 0..w) c[i][j]--;

  alias P=Tuple!(int, "i", int, "j");
  auto map=new P[](h*w);
  foreach(int i; 0..h)foreach(int j; 0..w) map[c[i][j]]=P(i, j);

  long cost(P a, P b){
    return (a.i-b.i).abs+(a.j-b.j).abs;
  }
  auto dp=new long[](h*w);
  foreach(i; d..(h*w)) dp[i]=dp[i-d]+cost(map[i-d], map[i]);
  int q; rd(q);
  while(q--){
    int l, r; rd(l, r); l--; r--;
    writeln(dp[r]-dp[l]);
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 12924
#include<bits/stdc++.h>
#define ri register int
using namespace std;
typedef vector<int> poly;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define rez resize
#define ppp pop_back
#define fi first
#define se second
const int rlen=1<<18|1;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read() {
  static int ans,f;
  static char ch;
  for(ans=0,f=1,ch=gc();!isdigit(ch);f^=ch=='-',ch=gc());
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
namespace modular {
  const int mod=998244353;
  inline int add(int a,int b) { return a+b<mod?a+b:a+b-mod; }
  inline int dec(int a,int b) { return a<b?a-b+mod:a-b; }
  inline int mul(int a,int b) { return (ll)a*b%mod; }
  inline void Add(int&a,int b) { a=a+b<mod?a+b:a+b-mod; }
  inline void Dec(int&a,int b) { a=a<b?a-b+mod:a-b; }
  inline void Mul(int&a,int b) { a=(ll)a*b%mod; }
  inline int ksm(int a,int p) { int ret=1;for(;p;p>>=1,Mul(a,a)) (p&1)&&(Mul(ret,a),1);return ret; }
  inline int Inv(int a) { return ksm(a,mod-2); }
} using namespace modular;
const int N=1e6+5;
int n,m,S[N],dis[N],tot=0;
bool vs[N];
vector<pii> e[N];
map<int,int> idx[N];
inline int getid(int x,int c) { return idx[x].count(c)?idx[x][c]:idx[x][c]=++tot; }
inline void ins(int x,int y,int w) { e[x].pb(pii(y,w)),e[y].pb(pii(x,w)); }
int main() {
  #ifdef ldxcaicai
  freopen("lx.in","r",stdin);
  #endif
  n=read(),m=read();
  for(ri i=1;i<=n;++i) S[i]=getid(i,0);
  for(ri i=1,u,v,c,x,y;i<=m;++i) {
    u=read(),v=read(),c=read();
    x=getid(u,c),y=getid(v,c);
    ins(x,y,0),ins(S[u],x,1),ins(S[v],y,1);
  }
  deque<int> q;
  memset(dis,0x3f,sizeof(dis));
  dis[S[1]]=1,q.push_front(S[1]);
  while(q.size()) {
    int x=q.front();
    q.pop_front();
    if(vs[x]) continue;
    vs[x]=1;
    for(ri i=0,v;i<e[x].size();++i) if(dis[v=e[x][i].fi]>dis[x]+e[x][i].se) {
      dis[v]=dis[x]+e[x][i].se;
      if(!e[x][i].se) q.push_front(v);
      else q.push_back(v);
    }
  }
  cout<<(dis[S[n]]==dis[0]?-1:dis[S[n]]/2);
  return 0;
}

Measured memory_bytes: 118144
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

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

    let mut dsu = DSU::new(n);
    for _ in 0..q {
        input! {
            t: u8, u: usize, v: usize,
        }
        match t {
            0 => {
                dsu.merge(u, v);
            }
            1 => {
                let res = dsu.same(u, v) as u8;
                println!("{}", res);
            }
            _ => unreachable!()
        }
    }
}
#[allow(dead_code)]
pub struct DSU {
    parent_or_size: Vec<isize>,
}

#[allow(dead_code)]
impl DSU {
    pub fn new(n: usize) -> Self {
        assert!(n <= std::isize::MAX as usize);
        Self {
            parent_or_size: vec![-1; n],
        }
    }

    pub fn merge(&mut self, a: usize, b: usize) -> usize {
        let mut x = self.leader(a);
        let mut y = self.leader(b);
        if x == y {
            return x;
        }
        if self.parent_or_size[x] > self.parent_or_size[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.parent_or_size[x] += self.parent_or_size[y];
        self.parent_or_size[y] = x as isize;
        x
    }

    pub fn same(&mut self, a: usize, b: usize) -> bool {
        self.leader(a) == self.leader(b)
    }

    pub fn leader(&mut self, mut a: usize) -> usize {
        while self.parent_or_size[a] >= 0 {
            a = self.parent_or_size[a] as usize;
        }
        a
    }

    pub fn size(&mut self, a: usize) -> usize {
        let leader = self.leader(a);
        -self.parent_or_size[leader] as usize
    }

    pub fn groups(&mut self) -> Vec<Vec<usize>> {
        let mut leader_buf = vec![0usize; self.parent_or_size.len()];
        let mut group_size = vec![0usize; self.parent_or_size.len()];
        for i in 0..self.parent_or_size.len() {
            leader_buf[i] = self.leader(i);
            group_size[leader_buf[i]] += 1;
        }
        let mut result = vec![Vec::new(); self.parent_or_size.len()];
        for i in 0..self.parent_or_size.len() {
            result[i].reserve(group_size[i]);
        }
        for i in 0..self.parent_or_size.len() {
            result[leader_buf[i]].push(i);
        }
        result.retain(|v| !v.is_empty());
        result
    }
}

Measured memory_bytes: 5620
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

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

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;

int n, k, a[N], ans;
int dp[N], cnt[N];
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	dp[1] = 1;
	for (int i = 2; i <= n; i++){
		if (a[i - 1] < a[i]) dp[i] = dp[i - 1] + 1;
		else dp[i] = 1;
	}
	for (int i = 1; i <= n; i++){
		cnt[i] = cnt[i - 1];
		if (dp[i] >= k) cnt[i] ++;
	}
	ans = n - k + 1;
	set<int> myset;
	if (n == k) return cout << 1, 0;
	for (int i = 1; i <= k + 1; i++){
		myset.insert(a[i]);
	}
	if (*(myset.rbegin()) == a[k + 1] && *(myset.begin()) == a[1]){
		ans--;
	}
	for (int i = k + 2; i <= n; i++){
		myset.erase(a[i - (k + 1)]);
		myset.insert(a[i]);
		if (*(myset.rbegin()) == a[i] && *(myset.begin()) == a[i - k]) ans --;
		else if(dp[i] >= k && cnt[i - k] > 0) ans --;
	}
	cout << ans;







	return 0;
}


Measured memory_bytes: 11904
n=int(input())
s=input()
dic={}
cntr=s.count("R")
cntg=s.count("G")
cntb=s.count("B")
for i in range(n):
    if s[i]=="R":
        dic[i]="R"
    if s[i]=="G":
        dic[i]="G"
    if s[i]=="B":
        dic[i]="B"

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if 2*j-i<=n-1:
            if dic[i]!= dic[j] and dic[i]!=dic[2*j-i] and dic[j]!=dic[2*j-i]:
                cnt+=1
        else:
            break
print(cntr*cntg*cntb-cnt)

        

Measured memory_bytes: 9412
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.Map.Strict               as M
import           Data.Char


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las



main = do
    (a, b) <- readTuple2
    print $ (b + (a - 2) - 1) `div` (a - 1)





Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
map<ll,int> mp;
int main(){
	int n=read();
	mp[0]=1;
	ll ans=0,res=0;
	REP(i,1,n){
		res+=read();
		ans+=mp[res];
		mp[res]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 12800
from scipy.sparse.csgraph import dijkstra
import numpy as np
from collections import Counter

n,x,y = map(int,input().split())

l = np.zeros((n,n))
l[range(n-1),range(1,n)] = 1
l[x-1,y-1] = 1
dis = dijkstra(l,directed = False)

ans = Counter(dis.reshape(-1))

for i in range(1,n):
    print(ans.get(i,0)//2)

    

Measured memory_bytes: 138060
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    string str;
    cin >> str;
    int N = str.size();
    // cout << N << endl;
    
    int N1 = (N - 1) / 2;
    int N2 = (N + 3) / 2;
    
    int flag = 1;
    for(int i = 0; i< N1; i++){
        if(str.at(i) != str.at(N-1-i)){
            // cout << "str.at(i):" << str.at(i) << endl;
            flag = 0;
            break;
        }
    }
    // abc d efg
    // N = 7, N1 = 3, i=2, N2 = 5, i=4
    // abcd e fghi
    // N = 9, N1 = 4, i=3, N2 = 6, i=5
    int N3 = (N1 - 1) / 2;
    // N1=3, N3=1;
    // N1=4, N3=1;

    for(int i = 0; i<=N3; i++){
        if(str.at(i) != str.at(N1-1-i)){
            // cout << "str.at(i):" << str.at(i) << endl;
            flag = 0;
            break;
        }
    }

    for(int i = N2 - 1; i<N; i++){
        if(str.at(i) != str.at(N - 1 - (i - (N2 - 1)))){
            // cout << "str.at(i):" << str.at(i) << endl;
            flag = 0;
            break;
        }
    }

    // cout << "flag: " << flag << endl;

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

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    if (a <= x && x <= a + b) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}


Measured memory_bytes: 256
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws IOException {
      InputStreamReader is = new InputStreamReader(System.in);
      BufferedReader br = new BufferedReader(is);
        
        
        //キーボードから1列目を読み込み
        String str = br.readLine();
        //読み込みを分割
        String[] gazou = str.split(" ",0);
        int n = Integer.parseInt(gazou[0]);
        int m = Integer.parseInt(gazou[1]);
        //aとbの配列を作る
        String[][] a = new String[n][n];
        String[][] b = new String[m][m];
        //配列に代入(a)
        for(int i=0; i<n; i++){
        	String str1 = br.readLine();
        	String[] bunkai = str1.split("",0);
        	for(int j=0; j<n; j++){
        		a[i][j] = bunkai[j];
        	} 
        }
        //配列に代入(b)
        for(int i=0; i<m; i++){
        	String str2 = br.readLine();
        	String[] bunkai = str2.split("",0);
        	for(int j=0; j<m; j++){
        		b[i][j] = bunkai[j];
        	}
        }
        //比較
        for(int i=0; i<n-m+1; i++){
        	for(int j=0; j<n-m+1; j++){
                
        		//bの左上一致の場合
        		if(b[0][0].equals(a[i][j])){
        			//停止して比較開始
                    boolean t = true;
        			for(int l=0; l<m; l++){
        				for(int k=0; k<m; k++){
        					//
        					if(!(b[l][k].equals(a[l+i][k+j]))){t=false;}       					
        				}
        			}
        			//異なるものがなかった場合
                    if(t==true){
        			System.out.println("Yes");
        			System.exit(0);}
        		}
        		
        	}
        }
        //比較して完全になかった場合
        System.out.println("No");
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define For(i , j , k) for (register int i = (j) , i##_end_ = (k) ; i <= i##_end_ ; ++ i)
#define Fordown(i , j , k) for (register int i = (j) , i##_end_ = (k) ; i >= i##_end_ ; -- i)
using namespace std;
typedef long long LL;
template <typename T> inline bool chkmax(T &a , T b) { return a < b ? (a = b , 1) : 0; }
int _ , __; char c_;
inline int read() {
	for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-') __ = -1;
	for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48); return _ * __;
}
const int maxn = 100010;
struct Item
{
	int x , y , z;
	bool operator < (const Item &item) const { return x - y > item.x - item.y; }
}a[maxn];
int X, Y, Z, n, q[maxn], cnt;
LL Ans, Sumy, Sumz, pre[maxn];
inline void Init()
{
	X = read(); Y = read(); Z = read(); n = X + Y + Z;
	For(i, 1, n) a[i].x = read(), a[i].y = read(), a[i].z = read();
	sort(a + 1 , a + 1 + n);
	For(i, 1, n) a[i].x -= a[i].z, a[i].y -= a[i].z, Sumz += a[i].z;
}
inline void Solve()
{
	For(i, 1, X) q[cnt ++] = -a[i].x, pre[X] += a[i].x;
	make_heap(q , q + cnt);
	For(i, X + 1, n - Y) q[cnt ++] = -a[i].x, push_heap(q, q + cnt), pre[i] = (pre[i - 1] + a[i].x + q[0]), pop_heap(q, q + (cnt --));
	cnt = 0; For(i, n - Y + 1, n) q[cnt ++] = -a[i].y, Sumy += a[i].y;
	make_heap(q, q + cnt);
	Ans = Sumy + pre[n - Y];
	Fordown(i, n - Y, X + 1)
	{
		q[cnt ++] = -a[i].y, push_heap(q, q + cnt), Sumy += a[i].y + q[0], chkmax(Ans, Sumy + pre[i - 1]), pop_heap(q, q + (cnt --));
	}
	printf("%lld\n" , Ans + Sumz);
}
int main()
{
	Init();
	Solve();
	return 0;
}

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

int main()
{
int a,amin,amax,n;
long sum;
cin >> n ;
amin = 1000000;
amax = -1000000;
sum = 0;
for (int i=0;i<n;i++)
{
cin >> a;
amin=min(a,amin);
amax=max(a,amax);
sum += a;
}
cout << amin << " " << amax << " " << sum << endl;
}


Measured memory_bytes: 3112
h1 , m1 , h2 , m2 , k = map(int , input().split())
hr = h2-h1
m = m2-m1
#print(hr,m)
diff = hr*60+m
ans = diff - k
#print(diff1,diff2,diff,ans)
if ans <=0:
	print(0)
else:
	print(ans)

Measured memory_bytes: 9172
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
string s;
cin>>s;
int sum=0;

for(int i=0;i<s.size();i++)
{
	sum = (int(s[i]-'0')%9 + sum)%9 ;
}

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

	
	

}

 
 

 


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    string s, t;
    cin >> s >> t;
    int res = 0;
    int i = 0;
    for (char a : s)
    {
        if (a != t[i])
            res++;

        i++;
    }
    c(res);
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int main()
{
    int n,m;cin>>n>>m;
    vector<int>r(n,1e8);
    REP(i,m)
    {
        int a,b;cin>>a>>b;a--;b--;
        r[a]=min(r[a],b);
    }
    int curr=1e8,ans=0;
    REP(i,n)
    {
        curr=min(r[i],curr);
        if(i==curr){ans++;curr=r[i];}
    }cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    const auto isOK = [&]()
    {
        for (ll ai=0;ai<=K;++ai)
        for (ll bi=0;(ai+bi)<=K;++bi)
        for (ll ci=0;(ai+bi+ci)<=K;++ci)
        {
            const auto aa = A << ai;
            const auto bb = B << bi;
            const auto cc = C << ci;

            if (bb > aa && cc > bb) { return true; }
        }

        return false;
    };

    cout << (isOK() ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

#define ll long long

int main()
{
    multiset<ll> st;
    ll n, m;
    cin >> n >> m;

    for (ll i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        st.insert(a);
    }

    for (ll i = 0; i < m; i++)
    {
        auto it = --st.end();
        st.erase(it);
        st.insert(*it / 2);
    }

    ll ans = 0;
    for (auto it = st.begin(); it != st.end(); it++) ans += *it;
    
    cout << ans << "\n";
}

Measured memory_bytes: 8260
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

const int INF = 1 << 30;

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

		vint mincost(n, INF);
		vector<bool> used(n, false);
		vector<vint> cost(n, vint(n, INF));
		rep(i, m)
		{
			int from, to, c;
			char k;
			cin >> from >> k >> to >> k >> c;

			cost[from][to] = cost[to][from] = c;
		}

		mincost[0] = 0;
		int res = 0;

		while(true)
		{
			int v = -1;
			rep(u, n)
				if(!used[u] && (v == -1 || mincost[u] < mincost[v]))
					v = u;

			if(v == -1) break;
			used[v] = true;
			res += mincost[v] - 100;

			rep(u, n)
				chmin(mincost[u], cost[v][u]);
		}

		cout << (res + 100) / 100 << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include <cstring>
using namespace std;
int dp[100000];
int n,a[100000];

int ans2(int i)
{
	if(i==n-1)
		return 0;

	if(i==n-2)
		return abs(a[i]-a[i+1]);

	if(dp[i]!=-1)
		return dp[i];

	int p = abs(a[i]-a[i+1]) + ans2(i+1);
	int q = abs(a[i]-a[i+2]) +ans2(i+2);

	return dp[i]=min(p,q);
}

int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];

	cout<<ans2(0);

	return 0;
}

Measured memory_bytes: 9048
import sys

input = sys.stdin.readline


class Node:
    def __init__(self, parent_id=None):
        self.val = 0
        self.parent_id = parent_id


n, q = map(int, input().split())
tree = [Node() for _ in range(n)]

for _ in range(1, n):
    a, b = map(int, input().split())
    tree[b - 1].parent_id = a - 1

for _ in range(q):
    p, x = map(int, input().split())
    tree[p - 1].val += x

for i in range(1, n):
    tree[i].val += tree[tree[i].parent_id].val

print(*[node.val for node in tree])


Measured memory_bytes: 57480