akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX_L = 1E+09;
const int MAX_N = 1E+05;

int H, W, N;
long long ans[10];
int NN[MAX_N][2];
unordered_set<long long> bls;
unordered_set<long long> chks;

void check25grids(int a, int b);
long long gridToKey(int a, int b);

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

    cin >> H >> W >> N;

    for (int i = 0; i < N; i++) {
        int a;
        int b;
        cin >> a >> b;
        NN[i][0] = a - 1;
        NN[i][1] = b - 1;
        bls.insert(gridToKey(a - 1, b - 1));
    }

    for (int i = 0; i < N; i++) {
        check25grids(NN[i][0], NN[i][1]);
    }

    long long sum0 = static_cast<long long>(W - 2) * (H - 2);
    for (int i = 1; i < 10; i++) {
        sum0 -= ans[i];
    }
    ans[0] = sum0;

    for (int i = 0; i < 10; i++) {

        cout << ans[i] << "\n";
    }

    return 0;
}

long long gridToKey(int a, int b)
{
    return static_cast<long long>(W) * a + b;
}

int check9grids(int a, int b)
{
    int res = 0;
    for (int i = a - 1; i <= a + 1; i++) {
        for (int j = b - 1; j <= b + 1; j++) {
            auto ite = bls.find(gridToKey(i, j));
            if (ite != bls.end()) {
                res++;
            }
        }
    }
    return res;
}

void check25grids(int a, int b)
{
    for (int i = max(a - 1, 1); i <= min(a + 1, H - 2); i++) {
        for (int j = max(b - 1, 1); j <= min(b + 1, W - 2); j++) {
            auto ite = chks.find(gridToKey(i, j));
            if (ite == chks.end()) {
                ans[check9grids(i, j)]++;
                chks.insert(gridToKey(i, j));
            }
        }
    }
}

Measured memory_bytes: 44352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
using ll=long long;

int main()
{
  ll N;
  cin >> N;
  vector<ll> vec(N);
  rep(i,N-1)
  {
    cin >> vec.at(i+1);
  }
  vector<ll> ans(N);
  rep(i,N-1)
  {
    ans.at(vec.at(i+1)-1)++;
  }
  rep(i,N)
  {
    cout << ans.at(i) << endl;
  }  
  return 0;
}  
  

Measured memory_bytes: 6420
import numpy as np

N,K,*H = map(int,open(0).read().split())
H =np.array(sorted(H))

H = np.diff(H,n=1)
minH = 1e10

for i in range(N-K+1):
  minH = min(H[i:i+K-1].sum(),minH)
  #print(i,H[i:i+K-1])
print(minH)

Measured memory_bytes: 37724
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>

using namespace std;

typedef long long ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second

const int MAX_SIZE = 100;

ll A[MAX_SIZE];
ll dp[MAX_SIZE][2];

int main()
{
	ios_base::sync_with_stdio(false);
	dp[0][0] = 1;
	dp[0][1] = 0;
	int n, p;
	cin >> n >> p;
	for(int i = 1; i <= n; i++)
	{
		cin >> A[i];
		if(A[i] % 2 == 0)
		{
			dp[i][0] = 2L*dp[i - 1][0];
			dp[i][1] = 2L*dp[i - 1][1];
		}
		else
		{
			dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
			dp[i][1] = dp[i - 1][1] + dp[i - 1][0];
		}
	}
	cout << dp[n][p] << endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N,A,B=map(int,input().split())

if N==1:
    if A==B:
        print(1)
    else:
        print(0)

else:
    temp1=A+B+A*(N-2)
    temp2=A+B+B*(N-2)
    print(max(temp2-temp1+1,0))
    

Measured memory_bytes: 2940
num = gets.chomp.to_i
a = gets.chomp.split(' ').map {|o| o.to_i}

if num.even? && a.count(0) >= 1
  puts 0
  exit
end

if num.odd? && a.count(0) != 1
  puts 0
  exit
end

unless a.uniq.count == (num.to_f / 2).ceil
  puts 0
  exit
end
 
puts (2 ** (num / 2)) % (10 ** 9 + 7)


Measured memory_bytes: 13196
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;
using pr  = pair<ll, ll>;

const ll MOD = 998244353;

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

	cout << X / 500 * 1000 + (X % 500) / 5 * 5 << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
int n,a,b;
vector<int> arr;
bool solve(int x){
    ll need = 0;
    for(int i = 0; i < n; ++i)
        need += (max(arr[i]-x*b,0)+(a-b-1))/(a-b);
    return need <= x;
}
int main(){
    cin >> n >> a >> b;
    arr.resize(n);
    for(int i = 0; i < n; ++i)
        cin >> arr[i];
    int lo = 0, hi = int(2*MOD)/b, mid;
    while(lo < hi){
        mid = (lo+hi)/2;
        if(solve(mid))
            hi = mid;
        else
            lo = mid+1;
    }
    cout << lo << '\n';
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
  	static int mod = 1000000007;
  static int size = 200001;
	static long[] fac = new long[size];
	static long[] finv = new long[size];
	static long[] inv = new long[size];
	static int INF = Integer.MAX_VALUE;
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	int N = sc.nextInt();
  int[] p = new int[N];
  int i=0;
  int count=0;
  for(i=0;i<N;i++){
    p[i]=sc.nextInt();
    if(p[i]!=i+1){
     count++; 
    }
  }

  if(count==0){
    System.out.println("YES");
  }else if(count==2){
    System.out.println("YES");
  }else{
    System.out.println("NO");
  }


} 

 //fac, inv, finvテーブルの初期化、これ使う場合はinitComb()で初期化必要
	public static  void initComb(){
		fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
		for (int i = 2; i < size; ++i) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}
 
	//nCk % mod
	public static long 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;
	}
 
	//n! % mod
	public static long fact(int n){
		return fac[n];
	}
 
	//(n!)^-1 with % mod
	public static long finv(int n){
		return finv[n];
	}
  
}

Measured memory_bytes: 26068
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll H, W; cin >> H >> W;
	vector<vector<ll>> dp(H + 1, vector<ll>(W + 1, 0));
	for (int i = 1;i <= H;i++) {
		for (int j = 1;j <= W;j++) {
			ll c; cin >> c;
			if (c == 0) {
				dp[i][j] = 1;
			}
		}
	}
	ll res = 0;
	for (int i = 1;i <= H;i++) {
		for (int j = 1;j <= W;j++) {
			if (dp[i][j] == 0)continue;
			dp[i][j] = min({
				dp[i - 1][j - 1],
				dp[i - 1][j],
				dp[i][j - 1]
			}) + 1;
			res = max(res, dp[i][j]);
		}
	}
	cout << res*res << endl;
	return 0;
}

Measured memory_bytes: 18204
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

///#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,avx,sse4.1,sse4.2,mmx")
///#pragma GCC optimize ("unroll-loops")
///#pragma GCC optimize ("Ofast")
///#pragma GCC optimize ("O3")

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define ff first
#define ss second
#define db double
#define ld long double
#define pb push_back
#define what(x) cerr << #x << " = " << x << '\n'

const int N = 1e6 + 5, M = 3e3 + 5;
const int inf = 1e18 + 100, mod = 1e9 + 7;
const ld eps = 1e-9, Pi = atan2(0, -1);

template < class T >
using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;

template < class T >
using ordered_multiset = tree < T, null_type, less_equal < T >, rb_tree_tag, tree_order_statistics_node_update >;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
    return mt_rnd_64() % (r - l + 1) + l;
}

int a[N], cnt[N];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; ++i)
    {
        int x;
        cin >> x;
        cnt[x]++;
    }

    for (int i = 1; i <= n; ++i)
        cout << cnt[i] << '\n';
    return 0;
}
/// hto ya? zvychayna domohospodarka chy president Ykrainy?


Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
V<> VEC(ll n) {
	V<> v(n);
	REP(i, n) cin >> v[i];
	return v;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n; cin >> n;
    auto x = VEC(n);
    ll l, q, a, b; cin >> l >> q;
    VV<> next(20, V<>(n));
    REP(j, n) next[0][j] = upper_bound(all(x), x[j] + l) - x.begin() - 1;
    REP(i, 19) REP(j, n) next[i+1][j] = next[i][next[i][j]];
    while(cin >> a >> b){
        a--; b--;
        if(a > b) swap(a, b);
        ll res = 1;
        RREP(i, 20){
            if(next[i][a] < b){
                a = next[i][a];
                res += (1ll << i);
            }
        }
        cout << res << '\n';
    }
}

Measured memory_bytes: 20336
sx,sy,tx,ty=map(int,input().split())
x,y=tx-sx,ty-sy
print('U'*y+'R'*x+'D'*y+'L'*(x+1)+'U'*(y+1)+'R'*(x+1)+'DR'+'D'*(y+1)+'L'*(x+1)+'U')

Measured memory_bytes: 9000
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    n--;
    string ans;
    int nums = 1;
    ll limit = 26;
    while(n >= limit){
        nums++;
        n -= limit;
        limit *= 26;
    }
    while(n){
        printde(n);
        ans += n % 26 + 'a';
        n /= 26;
    }
    while((int)ans.size() < nums){
        ans += 'a';
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
}


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

int main(void)
{
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(x - a) < abs(x - b)){cout << "A" << endl;}
    else{cout << "B" << endl;}
    return 0;
}

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

int main(){

  int n;
  while(1){
    cin >> n;
    if(n == -1) break;

    int ans = 0;

    for(int i=11;i<=n;i++){
      if(i > 30) ans += 160;
      else if(i > 20) ans += 140;
      else ans += 125;
    }

    cout << 4280 - (ans + 1150) << endl;

  }
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int s[]=new int[N];
		int count =0;
		for(int i=0;i<N;i++){
			s[i]=sc.nextInt();
			while(s[i]%2==0){
				s[i]/=2;
				count++;
			}
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 32424
ans = 10 ** 7
n, m = map(int, input().split())
dp = [float('inf')] * (2 ** n)
dp[0] = 0
prices = []
for i in range(m):
    a, s = map(int, input().split())
    prices.append(a)
    f = 0
    for k in map(int, input().split()):
        f += 2 ** (k - 1)
    for j in range(2 ** n - 1, -1, -1):
        dp[j | f] = min(dp[j] + a, dp[j | f])
print(-1 if dp[-1] == float('inf') else dp[-1])

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

using namespace std;

const int N = 1e5 + 100;

int n, pos[26];
char s[N];

int main() {
	int now = 0;
	scanf("%s", s);
	for(int i = 0;i < 26; ++i)
		pos[i] = -5;
	while(s[now]) {
		// cout << now << " " << pos[s[now] - 'a'] << endl;
		if(now - pos[s[now] - 'a'] <= 2) {
			printf("%d %d", pos[s[now] - 'a'] + 1, now + 1);
			return 0;
		}
		pos[s[now] - 'a'] = now; now++;
	}
	puts("-1 -1");
	return 0;
}

Measured memory_bytes: 3840
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<double, int> PDI;

struct bar {
  ll x, y, r;
};

int main() {
  ios::sync_with_stdio(false);
  bar s, t;
  cin >> s.x >> s.y >> t.x >> t.y;
  int N;
  cin >> N;
  vector<bar> ps(N);
  FOR(p,ps) {
    cin >> p.x >> p.y >> p.r;
  }
  ps.push_back({s.x, s.y, 0});
  ps.push_back({t.x, t.y, 0});
  vector<vector<double>> cost(N+2, vector<double>(N+2));
  REP(i,0,N+2) {
    REP(j,0,N+2) {
      if(i == j) {
        cost[i][j] = 0.0;
      } else {
        double dst = sqrt((ps[i].x - ps[j].x) * (ps[i].x - ps[j].x) +
                          (ps[i].y - ps[j].y) * (ps[i].y - ps[j].y));
        cost[i][j] = max(0.0, dst - ps[i].r - ps[j].r);
      }
    }
  }
  vector<bool> visited(N+2, false);
  int current = N;
  while (!visited[N+1]) {
    visited[current] = true;
    int next = -1;
    double next_cost = 1e30;
    REP(i,0,N+2) {
      if (!visited[i] && cost[N][i] < next_cost) {
        next_cost = cost[N][i];
        next = i;
      }
    }
    if (next_cost == 1e30) {
      break;
    }
    current = next;
    REP(i,0,N+2) {
      cost[N][i] = min(cost[N][i], cost[N][current] + cost[current][i]);
    }
  }

  cout << setprecision(12) << cost[N][N+1] << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

ll ans[260000];
ll n, a, b;

bool solve() {
  ll humming = 0;
  vector<ll> diff, same;
  for (int i = 0; i < n; i++) {
    if ((a >> i) % 2 != (b >> i) % 2) {
      humming++;
      diff.push_back(i);
    } else {
      same.push_back(i);
    }
  }
  if (humming % 2 == 0) {
    cout << "NO" << endl;
    return true;
  }

  ll okbit = 0;
  ll fir = diff[0];
  ans[(1LL << (n - okbit - 1))] = fir;
  okbit += 1;
  for (int i = 1; i < diff.size(); i += 2) {
    ll c = 0;
    ll size = 1LL << (n - okbit);
    for (ll j = 0; j < size * 2; j++) {
      if (j % size == 0)
        continue;
      if (j % (size >> 2) == 0) {
        ans[j] = diff[i + c % 2];
        c++;
      }
    }
    for (ll j = size * 2; j < (1LL << n); j++) {
      if (j % size == 0)
        continue;
      if (j % (size >> 1) == 0) {
        ans[j] = diff[i];
      } else if (j % (size >> 2) == 0) {
        ans[j] = diff[i + 1];
      }
    }
    okbit += 2;
  }
  for (int i = 0; i < same.size(); i++) {
    ll size = 1LL << (n - okbit);
    for (ll j = 0; j < (1LL << n); j++) {
      if (j % size == 0)
        continue;
      if (j % (size >> 1) == 0) {
        ans[j] = same[i];
      }
    }
    okbit++;
  }

  vector<bool> used(1LL << n);
  ans[0] = a;
  used[ans[0]] = true;
  cout << "YES" << endl;
  cout << ans[0];
  for (int i = 1; i < (1LL << n); i++) {
    ans[i] = ans[i - 1] ^ (1LL << (ans[i]));
    used[ans[i]] = true;
    cout << " " << ans[i];
  }
  cout << endl;

  return true;
  if (ans[(1LL << n) - 1] == b) {
    cerr << "same" << endl;
    bool ok = true;
    for (int i = 0; i < (1LL << n); i++)
      if (!used[i])
        ok = false;
    if (!ok) {
      cerr << "ng" << endl;
      return false;
    }
  } else {
    cerr << ans[(1LL << n) - 1] << endl;
    return false;
  }
  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a >> b;

  solve();
  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    string s;
    set <string> a;
    for (int i = 0; i < n; i++) {
        cin >> s;
        a.insert(s);
    }
    cout << sz(a) << '\n';
}


Measured memory_bytes: 19256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int N, M;
  cin >> N >> M;
  vector<int> X(M);

  REP(i, M) cin >> X[i];
  vector<int> koma(N);
  sort(X.begin(), X.end());
  ll ans = X[M-1]-X[0];
  vector<int> aida(M - 1);
  REP(i, M - 1) { aida[i] = X[i + 1] - X[i]; }
  sort(aida.begin(), aida.end());
  REP(i, N-1) {
    if (M - 2 - i < 0) break;
    ans -= aida[M - 2 - i];
  }
  ans = max(ans, (ll)0);
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
ll h,n,a[1005],b[1005],f[20005];
ll read()
{
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return f*x;
}
ll calc(ll x)
{
	if(x==1) return 1;
	return 2*calc(x/2)+1;
}
int main()
{
	h=read();
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
		b[i]=read();
	}
	memset(f,0x3f3f3f,sizeof(f));
	for(int i=1;i<=10000;++i) f[i]=0;
	for(int i=1;i<=n;++i)
	{
		for(int j=10000;j<=h+10000;++j)
		{
			f[j]=min(f[j],f[j-a[i]]+b[i]);
		}
	}
	printf("%lld",f[h+10000]);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < int(n); ++i)
 
int x[111];
 
int main() {
  int n, t, e;
  cin >> n >> t >> e;
  rep (i, n) cin >> x[i];
  rep (i, n) {
    for (int time = 0; time <= t + e; time += x[i]) {
      if (t - e <= time) {
	cout << i + 1 << endl;
	return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  string s[3];
  rep(i, 3) cin >> s[i];

  rep(i, 3){
    char c = s[i][0] + ('A' - 'a');
    cout << c;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()
 
n=ii()
h=lmi()
cnt=1
max_h=0
for i in range(n-1):
  max_h=max(max_h,h[i])
  if h[i]<=h[i+1] and h[i+1]>=max_h:
    cnt+=1
    
print(cnt)


Measured memory_bytes: 9044
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int a,b;
  vector<pair<int,pair<int,int> > >pii;
  for(int i=1;i<=150;i++){
    for(int j=i+1;j<=150;j++){
      pii.pb(mp(i*i+j*j,mp(i,j)));
    }
  }
  sort(pii.begin(),pii.end());
  while(cin>>a>>b,a+b){
    for(int i=0;i<pii.size();i++){
      if(pii[i].S.F==a&&pii[i].S.S==b){
	cout<<pii[i+1].S.F<<" "<<pii[i+1].S.S<<endl;
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3208
module Main where

import           Control.Monad

main :: IO ()
main = do
    [h, _] <- (map read . words) <$> getLine :: IO [Int]
    list   <- map (map read . words) <$> (replicateM h) getLine :: IO [[Int]]
    let res1 = (map goRight . enumerate2d) list
    let
        result = concat
            [(concatMap fst) res1, (fst . goRight . map (last . snd)) res1]

    putStr
        $ (unlines . (((show . length) result) :) . map
              (unwords . (\((a, b), (c, d)) -> (map show) [a, b, c, d]))
          )
              result

    return ()
goRight
    :: [((Int, Int), Int)] -> ([((Int, Int), (Int, Int))], [((Int, Int), Int)])
goRight []  = ([], [])
goRight [x] = ([], [x])
goRight (a@(aPoint, aValue) : b@(bPoint, _) : xs) = if even aValue
    then mapSnd (a :) (goRight (b : xs))
    else
        let (resMove, resMap) = goRight (mapSnd (+ 1) b : xs)
        in  ((aPoint, bPoint) : resMove, mapSnd (subtract 1) a : resMap)

enumerate :: [a] -> [(Int, a)]
enumerate = zip [1 ..]

enumerate2d :: [[a]] -> [[((Int, Int), a)]]
enumerate2d =
    (map (\(y, a) -> (map (\(x, b) -> ((y, x), b)) . enumerate) a) . enumerate)

mapTuple :: (t1 -> a) -> (t2 -> b) -> (t1, t2) -> (a, b)
mapTuple f1 f2 (a, b) = (f1 a, f2 b)

mapFst :: (t1 -> a) -> (t1, b) -> (a, b)
mapFst = flip mapTuple id

mapSnd :: (t2 -> b) -> (a, t2) -> (a, b)
mapSnd = mapTuple id


Measured memory_bytes: 63100
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()

	c := chars(next())
	for i := 0; i < n-1; i++ {
		d := chars(next())
		for k, v := range c {
			c[k] = min(v, d[k])
		}
	}

	for i := byte('a'); i <= 'z'; i++ {
		for ; c[i] > 0; c[i]-- {
			putf("%c", i)
		}
	}
	putf("\n")
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func chars(s string) map[byte]int {
	m := map[byte]int{}
	for i := range s {
		m[s[i]]++
	}
	return m
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}


Measured memory_bytes: 640
import java.util.Scanner;

class UnionFindTree {
    int[] par;
    int[] rank;
    int[] size;
    UnionFindTree(int maxSize){
        par = new int[maxSize];
        rank = new int[maxSize];
        size = new int[maxSize];
        for(int i=0;i<maxSize;i++){
            par[i] = i;
            size[i] = 1;
        }
    }

    public int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }
    public void unite(int x,int y){
        x = find(x);
        y = find(y);

        if(x == y)return;
        
        if(rank[x] < rank[y]){
            par[x] = y;
            size[y]+=size[x];
        }else{
            par[y] = x;
            size[x]+=size[y];
            if(rank[x] == rank[y])rank[x]++;
        }
    }
    public boolean same(int x,int y){
        return find(x) == find(y);
    }
    public int size(int x){
        return size[find(x)];
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] p = new int[n];
        int[] x = new int[m];
        int[] y = new int[m];
        for(int i=0;i<n;i++)p[i] = Integer.parseInt(sc.next())-1;
        for(int i=0;i<m;i++){
            x[i] = Integer.parseInt(sc.next())-1;
            y[i] = Integer.parseInt(sc.next())-1;
        }
        sc.close();
        UnionFindTree tree = new UnionFindTree(n);
        for(int i=0;i<m;i++){
            tree.unite(x[i], y[i]);
        }
        int res = 0;;
        for(int i=0;i<n;i++){
            if(tree.same(i, p[i])){
               res++;
            }
        }
        System.out.println(res);
    }
    
}

Measured memory_bytes: 63640
#include <iostream>
#include <string>

int main() {
  std::string A, B, a, b;
  std::cin >> a >> b;
  size_t la{a.length()};
  size_t lb{b.length()};

  A = std::string(lb, '0') + a;
  B = std::string(la, '0') + b;
  // std::cout << A << '\n' << B << std::endl;
  if (A == B)
    std::cout << "EQUAL" << std::endl;
  else if (A > B)
    std::cout << "GREATER" << std::endl;
  else
    std::cout << "LESS" << std::endl;
}


Measured memory_bytes: 256
using System;
class A{static void Main(){
    while(true){string s=Console.ReadLine();
        if(s==null){break;}
        int a=int.Parse(s);
        a%=39;
        if(a==0){a=39;}
        Console.Write("3C");
        Console.WriteLine(a<10?"0"+a.ToString():a.ToString());
    }
    
    
    
    
    
    
    
}}

Measured memory_bytes: 9080
//19
#include<iostream>

using namespace std;

int main(){
  for(char c[10003];cin>>c;){
    int j=0,i=0;
    for(int k=0;c[k];k++){
      j+=c[k]=='J'&&c[k+1]=='O'&&c[k+2]=='I';
      i+=c[k]=='I'&&c[k+1]=='O'&&c[k+2]=='I';
    }
    cout<<j<<endl<<i<<endl;
  }
  return 0;
}
  

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;
#define ll long long

int main(){
    ll A,B,C,D,tmp,tmp2;
    ll L,R,l,r;
    ll ans = 100000000;
    cin >> L >> R;

    if(R - L > 2019){
		cout << 0 << endl;
		return 0;
	}

    l = L % 2019;
    r = R % 2019;
    
    for(ll i = l; i < r; i++){
        for(ll j = i+1; j <= r; j++){
            ans = min(ans, (i*j) % 2019);
        }
    }
   
    cout << ans << endl;
}

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

using namespace std;

int main(){
    int N;
    long long K;
    cin >> N >> K;
    int a[N+10],b[N+10];
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i];
    }
    long long c[100010];
    for(int i = 0; i < 100010; i++){
        c[i] = 0;
    }
    for(int i = 0; i < N; i++){
        c[a[i]] += b[i];
    }
    long long  count = 0;
    for(int i = 1; i < 100010; i++){
        count += c[i];
        if(count >= K){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vpi vector<pair<int,int> >
#define ll long long 
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
// #define mod 998244353
#define mod 1000000007
#define MAXN  1000001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)



void solve()
{
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}


int main()
{
    fast;
    int t;
    t = 1;
    // cin>>t;
    while(t--)
    solve();
    return 0;
}

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

using namespace std;

int main(){
    int k; int n;
    cin >> n >> k;
    int arr[n];
    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            if (arr[i] > arr[j]){
                swap(arr[i], arr[j]);
            }
        }
    }
    int sum = 0;
    for (int i = 0; i < k; i++){
        sum += arr[i];
    }
    cout << sum;
}

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

int main(){
    string c = "YES";
  	int cnt = 0;
	string s;
  	cin >> s;
    for(int i=0;i<s.size();i++){
      if(s.at(i)=='o')
        cnt++;
    }
  	if(8<=s.size()&&cnt<=s.size()-8)
      c = "NO";
    cout << c << endl;
}


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

int main(){
    int N,T;
    cin >> N >> T;
    int ans = 1001;
    vector<int> c(N),t(N);
    rep(i,N)cin >> c[i] >> t[i];
    rep(i,N){
        if(t[i] <= T){
            ans = min(ans,c[i]);
        }
    }
    if(ans <= 1000)cout << ans << endl;
    else cout << "TLE" << endl;
}


Measured memory_bytes: 256
#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;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, K;
  cin >> N >> K;
  if (N == K) {
    cout << 1 << endl;
    return 0;
  }
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  dumpv(a);
  int mi = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == 1) {
      mi = i;
    }
  }
  dump(mi);
  int ans = 0;
  ans = (N - 2) / (K - 1) + 1;
  // dump(ans);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

template <class It> string join(It i1, It i2)
{
    ostringstream ss;
    for (auto it = i1; it != i2; ++it)
        ss << ((it == i1) ? "" : ", ") << (*it);
    return ss.str();
}

#ifdef DEBUG
#define Dump(x) cerr << #x << " = " << x << endl;
#define Dumps(x) cerr << #x << " : { " << join(x.begin(), x.end()) << " }" << endl;
#else
#define Dump(x)
#define Dumps(x)
#endif


using ull_t = unsigned long long;


int main()
{
    int N;
    cin >> N;
    
    vector<ull_t> A(N);
    for (auto &a : A)
        cin >> a;

    ull_t s(0);
    for (auto a : A)
        s += (a - 1);

    cout << s << endl;
}


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

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

int gcd(int x, int y){
    if(x<y){
        swap(&x, &y);
    }
    if(y==0){
        return x;
    }else{
        return gcd(y, x%y);
    }
}

int main(){
    int x, y;
    
    cin >> x >> y;
    
    cout << gcd(x, y) << "\n";
}



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

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

    ll n, m;
    cin >> n >> m;
    pair <ll, ll> ab[n];

    for (ll i = 0; i < n; ++i){
        ll a, b;
        cin >> a >> b;

        ab[i] = make_pair(a, b);
    }
    sort(ab, ab+n);

    ll res = 0;
    ll cnt = 0;

    for (ll i = 0; i < n; ++i){
        if(cnt + ab[i].second < m){
            res += ab[i].first * ab[i].second;
            cnt += ab[i].second;
        }
        else{
            res += ab[i].first * (m - cnt);
            cnt += m - cnt;
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
//
// ALDS1_4 - A Linear Search
// You are given a sequence of n integers S and a sequence of different q integers T. 
// Write a program which outputs C,the number of integers in T which are also in the set S.
//
#include <iostream>
using namespace std;

void read(int** ppSArray, int& n, int** ppTArray, int& q);
int calc(int* pSArray, const int n, int* pTArray, const int q);
void write(const int count);

int main()
{
    int n = 0, q = 0, ret = 0;
    int* pTArray = NULL;
    int* pSArray = NULL;

    read(&pSArray, n, &pTArray, q);
    ret = calc(pSArray, n, pTArray, q);
    write(ret);
}

// Required which delete two pointers of heap area.
void read(int** ppSArray, int& n, int** ppTArray, int& q)
{
    if (((NULL == ppSArray) || (NULL != *ppSArray)) ||
        ((NULL == ppTArray) || (NULL != *ppTArray))) {
        return;
    }
    cin >> n;
    if (10000 < n)
        return;
    *ppSArray = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> *(*ppSArray + i);
    }
    cin >> q;
    if (500 < q)
        return;
    *ppTArray = new int[q];
    for (int i = 0; i < q; i++) {
        cin >> *(*ppTArray + i);
    }
}

int calc(int* pSArray, const int n, int* pTArray, const int q)
{
    int count = 0;

    for (int i = 0; i < q; i++) {
        for (int j = 0; j < n; j++) {
            if (pTArray[i] == pSArray[j]) {
                count++;
                break;
            }
        }
    }

    return count;
}

void write(const int count)
{
    cout << count << endl;
}

Measured memory_bytes: 3132
import math
n,p = map(int,input().split())
ls = list(map(int,input().split()))
lo = []
le = []
def combinations_count(n, r): #組み合わせ(nCr)
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in ls:
    if i % 2 == 0:
        le.append(i)
    else:
        lo.append(i)
x = len(lo)
y = len(le)
if p == 0:
    a = 1
    if x != 0:
        if x % 2 == 0:
            r = x
        else:
            r = x - 1
        a = 0
        for j in range(0,r+1,2):
            a += combinations_count(x, j)
    b = 1
    if y != 0:
        b = 0
        for k in range(y+1):
            b += combinations_count(y, k)
    print(a*b)
else:
    if x != 0:
        if x % 2 == 0:
            r = x - 1
        else:
            r = x
        a = 0
        for j in range(1,r+1,2):
            a += combinations_count(x, j)
    else:
        a = 0
    b = 1
    if y != 0:
        b = 0
        for k in range(y+1):
            b += combinations_count(y, k)
    print(a*b)


Measured memory_bytes: 9272
import itertools
import math

n = int(input())
distances = []
for index in range(n):
    distance = list(map(int, input().split()))
    distances.append(distance)

output = []
permutation = list(itertools.permutations(range(n)))
for p in permutation:
    total = 0
    for index in range(len(p) - 1):
        idx1, idx2 = p[index], p[index+1]
        d0 = distances[idx1]
        d1 = distances[idx2]
        
        total += math.sqrt((d0[0] - d1[0]) * (d0[0] - d1[0]) + (d0[1] - d1[1]) * (d0[1] - d1[1]))
    output.append(total)
print(sum(output) / len(permutation))


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

using namespace std;
using ll = long long;
struct AB
{
    int A, B, idx;
    AB(int A, int B):A(A),B(B){}
};

bool comp_A(const AB &AB0, const AB &AB1){
    return AB0.A < AB1.A;
}
bool comp_B(const AB &AB0, const AB &AB1){
    return AB0.B < AB1.B;
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N), B(N), P(N);
    for (int i=0; i < N; i++)
        cin >> A[i];
    for (int i=0; i < N; i++)
        cin >> B[i];
    vector<AB> ABs;
    for (int i = 0; i < N; i++)
        ABs.push_back(AB(A[i],B[i]));
    
    stable_sort(ABs.begin(), ABs.end(), comp_A);
    stable_sort(ABs.begin(), ABs.end(), comp_B);
    for (int i = 0; i < N; i++)
        ABs[i].idx = i;
    stable_sort(ABs.begin(), ABs.end(), comp_A);
    for (int i = 0; i < N; i++)
        P[i] = ABs[i].idx;
    stable_sort(ABs.begin(), ABs.end(), comp_B);
    
    for (int i = 0; i < N; i++){
        if (ABs[P[i]].A > ABs[i].B)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    int x = 0, cnt = 1;
    while (P[x] != 0)
    {
        x = P[x];
        cnt++;
    }
    if (cnt != N){
        cout << "Yes" << endl;
        return 0;
    }
    for (int i = 0; i < N-1; i++)
    {
        if (ABs[i].B >= ABs[P[i+1]].A)
        {
            cout << "Yes" << endl;
            return 0;
        }
        
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int r;
    cin>>r;
    long double pi = 3.141592653589793238;
    cout<<setprecision(6)<<((long double)(((long double)2.000000000)*pi*((long double)r* 1.0000000)))<<endl;
    return 0;
}

Measured memory_bytes: 3804
require 'prime'

N = gets.to_i

def divisors(n)
  n.prime_division.inject([1]) do |ary, (p, e)|
    (0..e).map{ |e1| p ** e1 }.product(ary).map{ |a, b| a * b }
  end.sort
end

ans = 0
1.step(N, 2){|n|
  ans += 1 if divisors(n).size == 8
}

puts ans


Measured memory_bytes: 2428
# -*- coding: utf-8 -*-
"""
C - Inserting 'x'
https://atcoder.jp/contests/code-festival-2017-qualc/tasks/code_festival_2017_qualc_c

"""
import sys


from collections import deque

def solve(s):
    d = deque(s)
    ans = 0
    while len(d) > 1:
        if d[0] == 'x' or d[-1] == 'x':
            if d[0] == 'x' and d[-1] == 'x':
                d.popleft()
                d.pop()
            elif d[0] == 'x':
                d.popleft()
                ans += 1
            else:
                d.pop()
                ans += 1
        else:
            if d[0] == d[-1]:
                d.popleft()
                d.pop()
            else:
                return -1
    return ans


def main(args):
    s = input()
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

struct ques {
	int l,r,d;
}q[200100];
int n,m;
int fa[100100],dep[100100];
bool flag=1;

int find(int x)
{
	if (x==fa[x]) return x; else
	{
		int k=fa[x];
		fa[x]=find(fa[x]);
		dep[x]+=dep[k];
		return fa[x];
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) fa[i]=i;
	for (int i=1;i<=m;i++)
		scanf("%d%d%d",&q[i].l,&q[i].r,&q[i].d);

	for (int i=1;i<=m;i++)
	{
		int x=q[i].l,y=q[i].r,z=q[i].d;
		int fx=find(x),fy=find(y);
		if (fx!=fy) {
			fa[fx]=fy;
			dep[fx]=z-dep[x]+dep[y];
		} else
		if (dep[x]-dep[y]!=z) {
			puts("No");
			flag=0;
			break;
		}
	}
	
	if (flag) puts("Yes");
	return 0;
}

Measured memory_bytes: 3328
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        long[] dp = new long[n];
        Arrays.fill(dp, Long.MAX_VALUE);
        dp[0] = 0;
        for (int i = 1; i < n; i++) {
            if (i == 1) {
                dp[i] = Math.abs(ary[i] - ary[i - 1]);
            } else {
                dp[i] = Math.min(dp[i], dp[i - 1] + Math.abs(ary[i] - ary[i - 1]));
                dp[i] = Math.min(dp[i], dp[i - 2] + Math.abs(ary[i] - ary[i - 2]));
            }
        }
        System.out.println(dp[n - 1]);
    }
}

Measured memory_bytes: 48792
# 圧縮
# 001101 -> [0,1,0,1],[2,2,1,1]
def press(array):
    pressed = []
    cnts = []
    remark = array[0]
    cnt = 0
    for i in range(len(array)):
        cnt += 1
        if i == len(array)-1:
            pressed.append(remark)
            cnts.append(cnt)
        elif array[i] != array[i+1]:
            pressed.append(remark)
            cnts.append(cnt)
            remark = array[i+1]
            cnt = 0
    return pressed,cnts

S = input()
K = int(input())

N = len(S)
pressed, cnt = press(S)
if len(cnt) == 1:
    ans = N*K // 2
elif S[0] != S[-1]:
    ans = 0
    for c in cnt:
        ans += (c // 2) * K
else:
    ans = (cnt[0] + cnt[-1])//2 * (K-1)+ cnt[0]//2 + cnt[-1]//2
    for i in range(1,len(cnt)-1):
        ans += (cnt[i] // 2) * K

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 1e9 + 7;

ll ctoi(char c) {
	switch (c) {
		case 'A': return 0;
		case 'C': return 1;
		case 'G': return 2;
		case 'T': return 3;
	}
	return -1;
}
int main(){
	ll N; cin >> N;

	vector<string> nono = {
		"AGC",
		"GAC",
		"ACG",
		"ATGC",
		"AGGC",
		"ACGC",
		"AGTC",
		"AGAC"
	};

	vvl graph(100, vl(4, 0));
	ll nxt = 1;
	ll bad = 99;

	for (string s : nono) {
		ll cur = 0;
		FOR(i, 0, sz(s)) {
			ll &edge = graph[cur][ctoi(s[i])];
			if (i == sz(s) - 1) {
				edge = bad;
			} else if (edge == 0) {
				edge = nxt++;
			}
			cur = edge;
			if (cur == bad) {
				break;
			}
		}
	}

	//FOR(i, 0, nxt) { cout << i << endl; FOR(j, 0, 4) { cout << "ACGT"[j] << " : " << graph[i][j] << endl; } }

	graph[4][ctoi('G')] = 2;
	graph[4][ctoi('T')] = 6;

	graph[10][ctoi('G')] = 2;
	graph[10][ctoi('T')] = 6;

	//graph[2][ctoi('A')] = 4;
	graph[8][ctoi('A')] = 4;
	graph[7][ctoi('A')] = 4;

	vl cnts(sz(graph));
	cnts[0] = 1;
	FOR(i, 0, N) {
		vl new_count(sz(graph));
		FOR(j, 0, bad) {
			for (char nei : string("ACGT")) {
				ll tmp = graph[j][ctoi(nei)];
				if (tmp == 0) {
					tmp = graph[0][ctoi(nei)];
				}
				new_count[tmp] += cnts[j];
				new_count[tmp] %= MOD;
			}
		}
		new_count[bad] = new_count[bad] + (cnts[bad] * 4) % MOD;
		swap(cnts, new_count);
	}

	//TR(cnts[bad]);
	ll ans = 0;
	FOR(i, 0, bad) {
		ans = (ans + cnts[i] ) % MOD;
	}
	cout << ans << endl;

} //cin.tie(0) bei schnellem Wechseln


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, k;
llong h[100005];
llong mem[100005];

llong dfs(int i) {
    if (i == n - 1) return 0;
    if (i >= n) return (1 << 30);
    if (mem[i] != -1) return mem[i];

    llong res = 1ll << 30ll;

    for (int j = 1; j <= k; j++) {
        res = min(res, dfs(i + j) + llabs(h[i + j] - h[i]));
    }

    return mem[i] = res;
}


int main() {
    for (int i = 0; i < 100005; i++) {
        mem[i] = -1;
    }
    
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    cout << dfs(0) << endl;
    
    return 0;
}


Measured memory_bytes: 6528
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    vector<int> a(100001,0);
    for(int i=2;i<=100000;i++){
        if(i%2==0) continue;
        int num=i,cnt=0;
        for(int j=1;j*j<=num;j++)
        if(num%j==0) cnt++;
        if(cnt>1) continue;
        num=(i+1)/2; cnt=0;
        for(int j=1;j*j<=num;j++)
        if(num%j==0) cnt++;
        if(cnt>1) continue;
        a[i]=1;
    }
    vector<int> sum(100002,0);
    rep(i,100001) sum[i+1]=sum[i]+a[i];
    int q; cin>>q;
    rep(i,q){
        int l,r; cin>>l>>r;
        printf("%d\n",sum[r+1]-sum[l]);
    }
}

Measured memory_bytes: 1408
N, M = map(int, input().split())
P = list(enumerate(map(int, input().split())))


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

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

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


UF = UnionFind(N)
for i in range(M):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    UF.union(x, y)


UF.all_find()

ans = 0
for index, number in P:
    ans += UF.same(index, number - 1)

print(ans)


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)


int main()
{
	string s;cin>>s;
	if( s[0]==s[1]||s[1]==s[2]||s[2]==s[3] )
	{
		cout<<"Bad"<<endl;
	}
	else
	{
		cout<<"Good"<<endl;
	}

	return 0;
}

Measured memory_bytes: 256