akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

int n, a[100010], b[100010], c[100010];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	sort(a, a + n);
	sort(c, c + n);
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += (lower_bound(a, a + n, b[i]) - a)*(c + n - upper_bound(c, c + n, b[i]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
s = input()
t = input()

dp = [[0] * (len(s) + 1) for _ in range(len(t) + 1)]

for i in range(1, len(s) + 1):
  for j in range(1, len(t) + 1):
    if s[i-1] == t[j-1]:
      dp[j][i] = max(dp[j][i-1], dp[j-1][i], dp[j-1][i-1] + 1)
    else:
      dp[j][i] = max(dp[j][i-1], dp[j-1][i], dp[j-1][i-1])

ans = ""
x = len(s)
y = len(t)
d = dp[-1][-1]
while True:
  if d == 0:
    break
  if dp[y - 1][x] == d:
    y -= 1
  elif dp[y][x - 1] == d:
    x -= 1
  else:
    ans += t[y - 1]
    x -= 1
    y -= 1
    d -= 1
print(ans[::-1])

Measured memory_bytes: 114012
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N);
    var(string, s);

    i64 cnt[128]{};
    rep(i, 0, N) { cnt[s[i]] += 1; }

    i64 ans = cnt['R'] * cnt['G'] * cnt['B'];
    rep(i, 0, N) rep(j, i + 1, N) {
        const int k = j + (j - i);
        if (k < N) {
            if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k]) --ans;
        }
    }

    print(ans);

    return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n + 1], b[n];
    for (int i = 0; i < n + 1; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    long long ans = 0LL;
    for (int i = 0; i < n; ++i) {
        long long k = (long long) min(a[i], b[i]);
        ans += k;
        a[i] -= k;
        b[i] -= k;
        k = (long long) min(a[i + 1], b[i]);
        ans += k;
        a[i + 1] -= k;
        b[i] -= k;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

class Permutation {
// ���J�֐�
public:
	// �R���X�g���N�^
	Permutation();
	// �f�X�g���N�^
	~Permutation();
	// �������v�Z���郁�C���֐�
	const vector<vector<int>>& calc_main(int N);
// �����֐�
private:
	// �������v�Z���邽�߂̍ċA�֐�
	void calc_perm(vector<bool> jdg, vector<int> num);
// �����ϐ�
private:
	// �v�Z�����������i�[����vector�z��
	vector<vector<int>> ans;
	// �v�Z�����K������������
	int N = 1;
};

// �R���X�g���N�^
Permutation::Permutation() {
	// �������i�[���郁���o�ϐ���vector�z����������
	ans.clear();
}

// �f�X�g���N�^
Permutation::~Permutation() {
}

// �������v�Z���郁�C���֐�
const vector<vector<int>>& Permutation::calc_main(int N) {
	// �v�Z�����K�������������������ϐ��Ɋi�[
	this->N = N;

	// �����Ɋ܂܂��Ă��邩���m�F����bool�^��vector�z�����錾
	vector<bool> jdg(this->N, false);

	// �ċA�֐����p���ď������v�Z
	vector<int> num;
	// ������
	num.clear();
	calc_perm(jdg, num);

	// ���񂪊i�[���ꂽvector�z�����߂��l�Ƃ��ĕԂ�
	return ans;
}

// �������v�Z���邽�߂̍ċA�֐�
void Permutation::calc_perm(vector<bool> jdg, vector<int> num) {
	// ���ׂĂ̐������g���ď������쐬�����ꍇ
	if (jdg.end() == find(jdg.begin(), jdg.end(), false)) {
		// �������i�[
		ans.push_back(num);
	}

	// �����̃��[�v
	for (size_t i = 1; i <= N; i++) {
		if (jdg[i - 1] == false) {
			vector<int> dnum = num;
			dnum.push_back(i);
			jdg[i - 1] = true;
			calc_perm(jdg, dnum);
			jdg[i - 1] = false;
		}
	}
}

// ���C���֐�
int main() {

	// ���� N �̓Ǎ�
	int N;
	cin >> N;

	// ���� N �̏������쐬
	Permutation perm;
	const vector<vector<int>>& ans = perm.calc_main(N);

	// N �̍ő��l�� 8 �ł��邩���A�����𕶎����ŕ\��
	vector<string> p(ans.size(),"");
	for (size_t i = 0; i < ans.size(); i++) {
		for (size_t j = 0; j < ans[i].size(); j++) {
			p[i] += to_string(ans[i][j]);
		}
	}

	// �x�N�g���z�� p ���������ɕ��ёւ�
	sort(p.begin(), p.end());

	// �Q�̏����̓Ǎ�
	string p_str = "";
	string q_str = "";
	int d = 0;
	// P �̏������Ǎ�
	for (size_t i = 0; i < N; i++) {
		cin >> d;
		p_str += to_string(d);
	}
	// Q �̏������Ǎ�
	for (size_t i = 0; i < N; i++) {
		cin >> d;
		q_str += to_string(d);
	}

	size_t val = abs(distance(find(p.begin(), p.end(), p_str), find(p.begin(), p.end(), q_str)));

	cout << val << endl;

	return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  
  int ans = 1e9;
  int tmp = 0;
  for(int i = 1; i < n; i++){
    if(s[i] == 'E') tmp++;
  }
  ans = tmp;
  for(int i = 0; i < n; i++){
    if(s[i] == 'W') tmp++;
    if(s[i + 1] == 'E') tmp--;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

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


int main(){
	double a,b,c,d,x;
cin >>a>>b>>c>>d;    
    x = pow(pow(a-c,2) + pow(b-d,2),0.5);
    printf("%.7f\n",x);
    cout <<"\n";



	return 0;
}



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

#define N 110
int n;
struct node {
	string name;
	int a, id;
	void scan(int id) {
		this->id = id;
		cin >> name >> a;
	}
	bool operator < (const node &other) const {
		if (name != other.name) {
			return name < other.name;
		}
		return a > other.a;
	}
}arr[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	while (cin >> n) {
		for (int i = 1; i <= n; ++i) {
			arr[i].scan(i);
		}
		sort(arr + 1, arr + 1 + n);
		for (int i = 1; i <= n; ++i) {
			cout << arr[i].id << "\n";
		}
	}
	return 0;
}


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

const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

long long pow(long long a, long long n, long long m) {
    if (n == 0) return 1 % m;
    long long t = pow(a, n / 2, m);
    t = mod(t * t, m);
    if (n & 1) t = mod(t * a, m);
    return t;
}

long long dp[1100][1100];

int main() {
  long long n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  COMinit();
  for(int i=0;i<1100;++i) {
    for(int j=0;j<1100;++j) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  for(int i=0;i<=n;++i) {
    for(int j=0;j<=b-a+1;++j) {
      int num = a + j;

      dp[i][j+1] = (dp[i][j+1] + dp[i][j]) % MOD;

      for(int k=c;k<=d;++k) {
        int all = i + num * k;
        if(all > n) break;
        long long choose = COM(n - i, num * k);
        long long divide = fac[num*k] * pow(finv[num], k, MOD) % MOD;
        long long nonkubetsu = finv[k];
        long long mul = choose * divide % MOD * nonkubetsu % MOD;

        dp[all][j+1] = (dp[all][j+1] + dp[i][j] * mul % MOD) % MOD;
      }
    }
  }

  cout << dp[n][b-a+1] << endl;
}

Measured memory_bytes: 14592
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;

#define ll              long long
#define int             long long
#define ld             long double
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vi>
#define vip            vector<pii>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define lb(x)           (x&(-x))
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define itr(it,v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fir(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff               first 
#define ss               second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);

const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0,  1, -1, 1, -1, 0, 1 };

int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);

const int N=5*(1e5)+10;
vector<set<int>> adj(N);
int a[N];
int vis[N];
int maxz=0;
void  solve(){

}
void dfs(int s,int &nodes){
    vis[s]=1;
    nodes++;
    for(auto u:adj[s]){
        if(vis[u]) continue;
        dfs(u,nodes);
    }
}
int32_t main()
{
    FIO
    int n,m; cin>>n>>m;
    fi(i,n) vis[i]=0;
    for(int i=0;i<n;i++) adj[i].clear();
    ipgraph(m);
    maxz=0;
    for(int i=0;i<n;i++){
        if(vis[i]) continue;
        int curr=0;
        dfs(i,curr);
        maxz=max(maxz,curr);
    }
    cout<<maxz<<"\n";
    return 0;

}

void ipgraph(int m){
    int i, u, v;
    while(m--){
          cin>>u>>v;
         u--, v--;
    adj[u].insert(v);
    adj[v].insert(u);
    }
}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}

Measured memory_bytes: 56192
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int n, m;
    cin >> n >> m;
    vector<ll> dp(m + 1, 0);

    for(int i = 0; i < n; i++){
        int w, v;
        cin >> w >> v;
        for(int j = m; j >= w; j--){
            dp[j] = max(dp[j], dp[j - w] + v);
        }
    }

    cout << *max_element(iter(dp)) << "\n";

    return 0;
}

Measured memory_bytes: 1024
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var n = parseInt(input[0], 10);
    var d = new Array(n);
    for (var i = 0; i < n; i++) {
        d[i] = parseInt(input[i + 1], 10);
    }

    d.sort(function(a, b) {
        if (a > b) {
            return 1;
        }
        if (a < b) {
            return -1;
        }
        return 0;
    });

    var ans = 1;
    for (var i = 1; i < n; i++) {
        if (d[i] !== d[i - 1]) {
            ans++;
        }
    }

    console.log(ans);

    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

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

ll mod = 1000000007;

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

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

  int x,y;
  cin >> x >> y;
  if(y % 2 == 1){
    cout << "No" << endl;
  }else{
    if(x*4 >= y && x*2 <= y){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

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

static class Program
{
    static long Solve(int N, int M, int[] S, int[] T)
    {
        const long MOD = 1000000007;
        var dp = new long[N + 1][];
        for (int i = 0; i < N; ++i)
        {
            dp[i] = new long[M + 1];
            dp[i][M] = 1;
        }
        dp[N] = Enumerable.Repeat(1L, M + 1).ToArray();
        for (int i = N - 1; i >= 0; --i)
        {
            for (int j = M - 1; j >= 0; --j)
            {
                dp[i][j] = dp[i][j + 1] + dp[i + 1][j] - dp[i + 1][j + 1];
                if (S[i] == T[j]) { dp[i][j] += dp[i + 1][j + 1]; }
                dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;
            }
        }
        return dp[0][0];
    }

    static void Main(string[] args)
    {
        int[] V1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int[] S = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int[] T = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine(Solve(V1[0], V1[1], S, T));
    }
}


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

using namespace std;

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

    int length = s.length();

    for(int i = 0; i < length; ++i) {
        int ascii = ((int)s[i] - 65 + n) % 26 + 65;
        s[i] = (char)ascii;
    }

    cout << s;
  	return 0;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf);
    let mut it = buf.split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut a: Vec<u64> = (0..n).map(|_| {
        it.next().unwrap().parse().unwrap()
    }).collect();
    a.sort();
    println!("{}", a[n-1]-a[0]);
}


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

using namespace std;

#define MAX 110
#define INF 1e9

struct State{
  int v,s;
  State(int v,int s) : v(v),s(s) {}
};

int N,W[2][MAX];

int bfs(int s){
  queue<State> Q;
  Q.push(State(0,s));
  bool visited[2][MAX];
  memset(visited,false,sizeof(visited));
  int dist[2][MAX];
  fill(dist[0],dist[0]+MAX*2,INF);
  dist[s][0] = 0;
  
  while(!Q.empty()){
    int v = Q.front().v; 
    int s = Q.front().s;
    Q.pop();

    if(visited[s][v]) return INF;
    visited[s][v] = true;

    int cur = v;
    if(W[s][v] == 1){
      for(int i = v+1 ; i < N ; i++){
        if(W[s][i] != 1) break;
        dist[s][i] = min(dist[s][i],dist[s][v]);
        cur = i;
      }
    }else if(W[s][v] == 2){
      for(int i = v-1 ; i >= 0 ; i--){
        cur = i;
        dist[s][i] = min(dist[s][i],dist[s][v]);
        if(W[s][i] != 2) break;
      }
    }
   
    if(cur == N-1){
      return dist[s][v];
    }
    v = cur;
    for(int i = 0 ; i < 3 ; i++){
      if(dist[s][v] + 1 < dist[!s][v+i]){
        dist[!s][v+i] = dist[s][v] + 1;
        Q.push(State(v+i,!s));
      }   
    }
  }
  return INF;
}

int main(){
  while(cin >> N, N){
    for(int i = 0 ; i < 2 ; i++){
      for(int j = 0 ; j < N ; j++){
        cin >> W[i][j];
      }
    }
    int res = min(bfs(0),bfs(1));
    if(res == INF){
      cout << "NA" << endl;
    }else{
      cout << res << endl;
    }
  }
  return 0;
}

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

typedef long long Long;

void dout() { std::cout << std::endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
	#ifdef DESH
		std::cout << H << ' ';
		dout(T...);
	#endif
}

int main() {
	int n, k; scanf("%d %d", &n, &k);
	
	int MOD = 1000000007;
	Long ans = 0;
	for (int i = k; i <= n + 1; i++) {
		Long min = 1L * (i - 1) * i / 2;
		Long max = 1L * (n + (n - i + 1)) * i / 2;
		
		ans = (ans + (max - min + 1)) % MOD;
	}
	
	std::cout << ans;

	return 0;
}


Measured memory_bytes: 3764
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

template<class T>using p_queue=std::priority_queue<T, std::vector<T>, std::greater<>>;

template<class T>void warshall_floyd(boost::multi_array<T, 2>& ar, int N)
{
	for (int k : boost::irange(0, N))
	{
		for (int i : boost::irange(0, N))
		{
			for (int j : boost::irange(0, N))
			{
				ar[i][j] = std::min(ar[i][j], ar[i][k] + ar[k][j]);
			}
		}
	}
}


void Main()
{
	int N, M;
	std::int64_t L;
	std::cin >> N >> M >> L;
	boost::multi_array<std::int64_t, 2> distance(boost::extents[N][N]);
	boost::multi_array<int, 2> charge(boost::extents[N][N]);
	for (auto i : boost::irange(0, N))
	{
		for (auto j : boost::irange(0, N))
		{
			distance[i][j] = L + 1;
			charge[i][j] = N;
		}
	}
	for (auto _ : boost::irange(0, M))
	{
		index_t a, b;
		std::int64_t c;
		std::cin >> a >> b >> c;
		--a; --b;
		distance[a][b] = distance[b][a] = c;
	}
	warshall_floyd(distance, N);
	for (auto i : boost::irange(0, N))
	{
		for (auto j : boost::irange(0, N))
		{
			if (distance[i][j] <= L)
			{
				charge[i][j] = 1;
			}
		}
	}
	warshall_floyd(charge, N);

	int Q;
	std::cin >> Q;
	for (auto i : boost::irange(0, Q))
	{
		int s, t;
		std::cin >> s >> t;
		--s; --t;
		std::cout << (charge[s][t] == N ? -1 : charge[s][t] - 1) << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
	string s;
	cin >> s;
	if(s[0] == s[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
program H2020B
    implicit none
    integer(8)::A,B,M,i,ans
    integer(8),allocatable,dimension(:)::Ai,Bi,X,Y,C
    ans=1000000
    read(5,*)A,B,M
    allocate(Ai(A))
    allocate(Bi(B))
    allocate(X(M))
    allocate(Y(M))
    allocate(C(M))
    read(5,*)(Ai(i),i=1,A)
    read(5,*)(Bi(i),i=1,B)
    read(5,*)(X(i),Y(i),C(i),i=1,M)

    !割引券適用
    do i=1,M
        ans=min(ans,Ai(X(i))+Bi(Y(i))-C(i))
    end do
    
    ans=min(ans,minval(Ai)+minval(Bi))
    print'(i0)',ans
end program H2020B

Measured memory_bytes: 4736
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}
func upperbound(v []int, k int) int {
	l, r := -1, len(v)
	for r-l > 1 {
		m := l + (r-l)/2
		if v[m] > k {
			r = m
		} else {
			l = m
		}
	}
	return r
}

func lowerbound(v []int, k int) int {
	l, r := -1, len(v)
	for r-l > 1 {
		m := l + (r-l)/2
		if v[m] >= k {
			r = m
		} else {
			l = m
		}
	}
	return r
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt(sc)
	}
	// sort.Ints(a) // 二分探索のためにソートする
	q := nextInt(sc)
	l := make([]int, q)
	u := make([]int, q)
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < q; i++ {
		k := nextInt(sc)
		l[i] = n
		u[i] = n
		rl := lowerbound(a, k)
		ru := upperbound(a, k)
		if 0 <= rl && rl < n {
			l[i] = rl
		}
		if 0 <= ru && ru < n {
			u[i] = ru
		}
	}
	for i := 0; i < q; i++ {
		fmt.Fprintf(wtr, "%d %d\n", l[i], u[i])
	}
	wtr.Flush()
}



Measured memory_bytes: 9320
n=int(input())
a=list(map(int,input().split()))
m=0
curr=1
ans=0
for i in range(n):
  m+=a[i]
  if curr*m<=0:
    ans+=1-curr*m
    m=curr
  curr=-1*curr
ans2=0
m=0
curr=-1
for i in range(n):
  m+=a[i]
  if curr*m<=0:
    ans2+=1-curr*m
    m=curr
  curr=-1*curr
print(min(ans,ans2))

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

b_list = [int(x) for x in input().split()]

a_list = [0] * n
a_list[0] = b_list[0]
for i in range(1, n - 1):
    a_list[i] = min([b_list[i - 1], b_list[i]])
a_list[n - 1] = b_list[n - 2]

ans = sum(a_list)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	int s;
	cin>>s;
	cout<<s/3600<<":";
	s = s % 3600;
	cout<<s/60<<":"<<s%60<<endl;;
}

Measured memory_bytes: 3080
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>
#include<chrono>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 3e5 + 5;

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("output.txt", "w", stdout);
    ll sum = 0;
    ll n; cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            sum += j;
        }
    }
    cout << sum << endl;


    return 0;
}

/*

*/

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

int n,m,a,b;

int main(){
  string s;
  int i,j,k=0;

  cin >> s;
  for(i=0;i<s.length();i++){
    if(s[i]=='+')k++;
    else k--;
  }

  cout <<k<< endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc164_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            int C = int.Parse(input[2]);
            int D = int.Parse(input[3]);

            while (A > 0 && C > 0)
            {
                C -= B; //青木君のモンスターが高橋君に攻撃

                if (C <= 0)
                {
                    Console.WriteLine("Yes");
                    return;
                }

                A -= D; //高橋君のモンスターが青木君に攻撃

                if (A <= 0)
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.Read();

        }
    }
}


Measured memory_bytes: 27460
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	int n; cin>>n;
	vector<int> ans(1000000);
	fore(x,1,101) fore(y,1,101) fore(z,1,101){
		ans[x*x+y*y+z*z+x*y+y*z+z*x]++;
	}
	fore(i,1,n+1) cout<<ans[i]<<"\n";
}

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

int st, dr, d, sol, x;

int main() {
    cin >> st >> dr >> d;
    x = d;
    while(x <= dr) {
        if(x >= st) {
            sol++;
        }
        x += d;
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 3552
score_t = 0
score_h = 0

n = int(input())
for _ in range(n):
    a, b = input().split()
    if a > b:
        score_t += 3
    elif b > a:
        score_h += 3
    else:
        score_t += 1
        score_h += 1

print(score_t, score_h)



Measured memory_bytes: 5596
#include <iostream>
#include <queue>

using namespace std;

using ll = long long;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

ll mypow(ll b, ll n) {
    return n == 0 ? 1 : b * mypow(b, n - 1);
}

// 桁和を求める
ll dsum(ll n) {
    ll ret = 0;
    while (n > 0) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

// n以上で最小のすぬけ数を求める
ll snuke(ll n) {
    GPQ<pair<double, ll>> val;
    // (g(m), m)

    ll dig = 0;
    // 9が連続する桁数

    while (mypow(10, dig) <= n) {
        for (ll i = 1; i <= 9; ++i) {
            ll v = n - n % mypow(10, dig + 1) + i * mypow(10, dig) - 1;
            // 下dig桁が9
            // 1つ上は1~9
            // それより上はnと一致

            if (v >= n) {
                val.push(make_pair(v * 1.0 / dsum(v), v));
            }
        }
        ++dig;
    }
    --dig;

    // 1桁もnと一致しないものを列挙
    for (ll i = 1; i <= 100; ++i) {
        ll v = i * mypow(10, dig) - 1;
        if (v >= n) {
            val.push(make_pair(v * 1.0 / dsum(v), v));
        }
    }

    auto ret = val.top();
    // g(m)とmが最小となる(g(m), m)の組

    return ret.second;
}


int main() {
    ll K;
    cin >> K;
    ll pre = 1;

    for (ll i = 0; i < K; ++i) {
        cout << pre << endl;
        pre = snuke(pre + 1);
    }

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<string> blue(N);
  for (int i=0; i<N; i++) {
    cin >> blue.at(i);
  }
  int M;
  cin >> M;
  vector<string> red(M);
  for (int i=0; i<M; i++) {
    cin >> red.at(i);
  }
  
  int count;
  int MAX=0;
  for (int i=0; i<N; i++) {
    count =0;
    for (int j=0; j<N; j++) {
      if (blue.at(i)==blue.at(j))
        count++;
    }
    for (int j=0; j<M; j++) {
      if (blue.at(i)==red.at(j))
        count--;
    }
    if (count > MAX)
      MAX = count;
  }
  cout << MAX << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<iostream>
#include<iomanip>
#include<set>
#include<string>
#include<math.h>

using namespace std;

class zahyo{
	public:
	int x;
	int y;
	zahyo(){
		x=0;
		y=0;
	}
	zahyo(int x_,int y_){
		x=x_;
		y=y_;
	}
	void print(){
		cout<<x<<" "<<y;
	}
	zahyo operator+(zahyo add){
		add.x=this->x+add.x;
		add.y=this->y+add.y;
		return add;
	}
	zahyo operator-(zahyo add){
		add.x=this->x-add.x;
		add.y=this->y-add.y;
		return add;
	}
	bool operator==(const zahyo add) const{
		if(add.x==this->x and add.y==this->y){return true;}
		else{return false;}
	}
	bool operator!=(const zahyo add) const{
		if(add.x==this->x or add.y==this->y){return false;}
		else{return true;}
	}
	bool operator<(const zahyo add) const{
		if(this->x<add.x){return true;}
		else if(this->x==add.x and this->y<add.y){return true;}
		else{return false;}
	}
	bool operator>(const zahyo add) const{
		if(this->x>add.x){return true;}
		else if(this->x==add.x and this->y>add.y){return true;}
		else{return false;}
	}
	void input(){
		cin>>x>>y;
	}
};

int n;
int counter=0;
int field[50][50]={{}};
int arrived[50][50]={{}};
int ways[8][2]={{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1},{0,1}};
int h,w;
void depthsearch(int h_,int w_){
	arrived[h_][w_]=1;
	for(int i=0;i<8;i++){
		int newh=h_+ways[i][0];
		int neww=w_+ways[i][1];
		if(newh>=0 and newh<h and neww>=0 and neww<w){
			if(arrived[newh][neww]==0 and field[newh][neww]==1){
				depthsearch(newh,neww);
			}
		}
	}
}

int main(){

	while(1){
		cin>>w>>h;
		if(w==0 and h==0){break;}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin>>field[i][j];
				arrived[i][j]=0;
			}
		}
		int ans=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(arrived[i][j]==0 and field[i][j]==1){
					depthsearch(i,j);
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3164
# -*- coding:utf-8 -*-
import math
count = 0
while True:
    try:
        n = int(input())
        if n == 2 or n == 3 or n == 5 or n == 7:
            count += 1
        if n > 3 and n % 2 != 0:
            for i in range(3,int(math.sqrt(n))+1):
                if n % i == 0:
                    break
                elif i == int(math.sqrt(n)):
                    count += 1
    except  EOFError:
        break
print(count)

Measured memory_bytes: 7740
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const long long MOD=(long long)1e9+7;

long long memo[100010];

long long rec(int x,const vector<bool>& ok){ 
    if(x<0||!ok[x]) return 0;
    else if(x==0) return 1;
    else if(memo[x]>=0) return memo[x];
    return memo[x]=(rec(x-1,ok) + rec(x-2,ok))%MOD;
}

int main() {
    int N,M; 
    cin>>N>>M;
    vector<bool> ok(N+1,true);
    memset(memo,-1,sizeof(memo));
    for(int i=0;i<M;++i){
        int tmp; cin>>tmp;
        ok[tmp]=false;
    }
    cout<<rec(N,ok)<<endl;
    return 0;
}


Measured memory_bytes: 5760
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args){
		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			try{
				String[] strA = insBR.readLine().split(" ");
				int intA = Integer.parseInt(strA[0]);
				int intB = Integer.parseInt(strA[2]);
				int intResult = 0;
				if("+".equals(strA[1])){
					intResult = intA + intB;
				}else if("-".equals(strA[1])){
					intResult = intA - intB;
				}else if("*".equals(strA[1])){
					intResult = intA * intB;
				}else if("/".equals(strA[1])){
					intResult = intA / intB;
				}else{
					break;
				}

				System.out.println(intResult);

			}catch(IOException e){
				System.out.println("入力が無効です。");
			}catch(NumberFormatException e){
				System.out.println("数値を入力してください。");
			}
		}
	}

}



Measured memory_bytes: 24412
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    for(int i=0; i<3000; i++) {
      int x = scan.nextInt(); int y = scan.nextInt();
      if(x==0 && y==0) {
        break;
      }
      int z;
      if(x > y) {
        z = x; x = y; y = z;
      }
      System.out.println(x + " " + y);
    }
  }
}

Measured memory_bytes: 34208
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl
#define first(v) get<0>(v)
#define second(v) get<1>(v)
#define third(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;



int main(){
    ll n;
    cin >> n;
    vector<ll> v(n,0);
    Map even,odd;
    for(ll i=0;i<n;i++){
        cin>>v[i];
        if(i%2)odd[v[i]]++;
        else even[v[i]]++;
    ;}
    vector<P> Even(0),Odd(0);
    for(auto p: odd){
        Odd.emplace_back(P(second(p),first(p)))
    ;}
    for(auto p: even){
        Even.emplace_back(P(second(p),first(p)))
    ;}
    sort(Even.rbegin(), Even.rend());
    sort(Odd.rbegin(), Odd.rend());
    ll ans=INF;
    if((*Odd.begin()).second!=(*Even.begin()).second){
        ans=n-(*Even.begin()).first-(*Odd.begin()).first;
    }
    ll k=0;if(Odd.size()>1)k=(*next(Odd.begin())).first;
    chmin(ans,n-(*Even.begin()).first+-k);
    k=0;if(Even.size()>1)k=(*next(Even.begin())).first;
    chmin(ans,n-(*Odd.begin()).first-k);

    print(ans);
    


    
    return 0;
}


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

struct Stack{
    long long table[1000];
    long long top;
    void init(){
        top=0;
    }
    bool empty(){
        return top==0;
    }
    long long pop(){
        if(empty()) return 0;
        top--;
        return table[top];
    }
    void push(long long x){
        table[top]=x;
        top++;
    }
};
long long calc(long long x, string op, long long y){
    if(op=="+") return x+y;
    if(op=="-") return x-y;
    if(op=="*") return x*y;
}

int main(){
    string str;
    Stack stack;
    long long numA, numB;
    stack.init();
    
    while(cin>>str){
        if(str=="+"||str=="-"||str=="*"){
            numA=stack.pop();
            numB=stack.pop();
            stack.push(calc(numB,str,numA));
        }else{
            numA=0;
            for(int i=0; i<(int)str.size(); i++){
                numA*=10;
                numA+=str[i]-'0';
            }
            stack.push(numA);
        }
    }
    cout<<stack.pop()<<endl;
    return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define COUTDOUBLE(v) cout << std::setprecision(10)<<(v)<<endl;
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);CIN(T);CIN(A);
    I vec;
    int ans = -1;
    double ins = INF;
    REP(a,N){
        CIN(b);
        if(abs(1.0*T-b * 0.006-A) < ins){
            ins = abs(1.0*T-b * 0.006-A);
            ans = a;
        }
    }
    COUT(ans+1);
}


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

#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod = 1000000007;
const int tMAX = 5;

inline void init(mat &A, int n, int m){
  A = mat(n,vec(m,0));
}

inline mat add(mat A, mat B){
  mat res = A;
  rep(i,A.size())rep(j,A[i].size())(res[i][j] += B[i][j]) %= mod;
  return res;
}

inline mat mul(mat A, mat B){
  mat res; init(res,A.size(),B[0].size());
  rep(i,A.size())rep(j,B[0].size()){
    rep(k,B.size())res[i][j] += (A[i][k] * B[k][j]) % mod;
    res[i][j] %= mod;
  }
  return res;
}

inline mat pow_mat(mat &A, ll n){
  if(n==1LL)return A;
  mat B = pow_mat(A,n/2), res = mul(B,B);
  if(n&1)res = mul(A,res);
  return res;
}

ll N,K,C,T,tr;
ll a, b, t;
vec shuffle(50), perm(50);
mat perm_mat[10], dp[500100], tmp;
mat large_mat, thin_mat;

int main(){
  cin >> N >> K >> C >> T;

  rep(i,tMAX+1)init(perm_mat[i],N,N);
  rep(i,N)perm[i] = i;

  rep(i,K){
    cin >> a >> b >> t;
    rep(j,b)shuffle[j] = perm[j+a-1];
    rep(j,a-1)shuffle[b+j] = perm[j];
    for(int j=a+b-1;j<N;j++)shuffle[j] = perm[j];
    rep(j,N)perm_mat[t][j][shuffle[j]]++;
  }

  rep(i,tMAX+1)init(dp[i],N,N);
  rep(i,N)dp[0][i][i] = 1;
 
  rep(i,tMAX)rep(j,tMAX){
    if(i+j+1<=tMAX){
      tmp = mul(perm_mat[j+1],dp[i]);
      dp[i+j+1] = add(dp[i+j+1],tmp);
    }
  }

  init(large_mat,N*tMAX,N*tMAX);
  rep(id,tMAX){
    rep(i,N)rep(j,N)large_mat[i][j+id*N] = perm_mat[id+1][i][j];
  }
  rep(i,N*(tMAX-1))large_mat[i+N][i] = 1;

  init(thin_mat,N*tMAX,N);
  rep(id,tMAX){
    rep(i,N)rep(j,N)thin_mat[i+id*N][j] = dp[tMAX-1-id][i][j];
  }

  tmp = pow_mat(large_mat,T);
  cout << mul(tmp,thin_mat)[(tMAX-1)*N][C-1] << endl;
}

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

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int[] values = {sc.nextInt(),sc.nextInt(),sc.nextInt()};
		Arrays.sort(values);
		if(values[0]+values[1] == values[2]) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35596
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <sstream>
#include <cstdlib>
#include <vector>
typedef long long  ll;
using namespace std;
int main()
{
	int N,M;
	cin >> N >> M;
	vector<int> dataa(M,0);
	vector<int> datab(M,0);
	vector<int> center;
	for(int i=0;i<M;i++){
		cin >> dataa[i] >> datab[i];
	}
	for (int i=0;i<M;i++){
		if(datab[i]==N ){
			center.push_back(dataa[i]);
		}else if(dataa[i]==1){
			center.push_back(datab[i]);
		}
	}
	int NUM=center.size();
	sort(center.begin(),center.end());
	center.erase(unique(center.begin(), center.end()), center.end());
	if(center.size()==NUM){
		cout << "IMPOSSIBLE" << endl;
	}else{
		cout << "POSSIBLE" << endl;
	}
}

Measured memory_bytes: 2936
#include<bits/stdc++.h>
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define ll long long int
using namespace std;
int main()
{


        ll a,b,c,n,x,y,z,cnt=0,sum=0;
        string str;
        cin>>a>>b>>c;
        for(int i=a;i<=b;i++)
        {
            if(i%c==0)cnt++;
        }
cout<<cnt<<endl;

}



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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    ll money = 1000;
    ll store = 0;
    bool isbuy = true;
    //買うなら全買い売るなら全売り
  
    for(int i = 0; i < n-1 ; i++)
    {
        bool ok = false;

        for(int j = i+1; j < n; j++)
        {
            if(isbuy)
            {
                if(a[i] < a[j])
                {
                    ok = true;
                    break;
                }
                else if(a[i] > a[j])
                {
                    ok = false;
                    break;
                }
            }
            else
            {
                if(a[i] > a[j])
                {
                    ok = true;
                    break;
                }
                else if(a[i] < a[j])
                {
                    ok = false;
                    break;
                }
            }
        }
        if(isbuy)
        {
            if(ok) 
            {
                store = money / a[i];
                money = money %a[i];
                isbuy = false;
              //  cout <<  "buy " << a[i] << endl;
            }
        } else {
            if(ok) 
            {
                money += store * a[i]; 
                store = 0;
                isbuy = true;
               //cout << "sell " << a[i] << endl;
            }
        }
    }

    if(!isbuy)
    {
        money += store * a[n-1]; 
    }
    if(money > 1000) cout << money << endl;
    else cout << "1000" << endl;
}


Measured memory_bytes: 3628
<?php
fscanf(STDIN,"%d%d",$d,$n);
$c=0;
if($d==0){
    if($n==100){
	  echo "101\n";
    }else{
  echo $n."\n";
    }
}

if($d==1){
  if($n==100){
	  echo "10100\n";
    }else{
  echo 100*$n."\n";
    }
}

if($d==2){
   if($n==100){
	  echo "1010000\n";
    }else{
  echo 10000*$n."\n";
    }
}

Measured memory_bytes: 4604
N,K=map(int,input().split())
ans=0
if K%2==0:
  A=[]
  B=[]
  for i in range(1,N+1):
    if i%K==0:
      A.append(i)
    elif i%K==K//2:
      B.append(i)
  ans=(len(A))**3+(len(B))**3
else:
  C=[]
  for i in range(1,N+1):
    if i%K==0:
      C.append(i)
  ans=(len(C))**3
print(ans)

Measured memory_bytes: 11044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		int min = 999;

		for (int i = 0; i < s.length() - 2; i++) {
			if (Math.abs(Integer.parseInt(s.substring(i, i + 3)) - 753) < min) {
				min = Math.abs(Integer.parseInt(s.substring(i, i + 3)) - 753);
			}
		}

		System.out.println(min);

	}
}

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

int gcd_euclid(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r; /* swap */
  }
  return u;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  	}
  for(int j=1;j<n;j++){
    a[j]=gcd_euclid(a[j],a[j-1]);
  }
  cout << a[n-1] << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
const int mod=1000000007;
long long quick_pow(long long a,long long b)
{
	long long ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%mod;
		b>>=1;
		a=(a*a)%mod;
	}
	return ans%mod;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    long long n,a,b,ans=1,MOD=mod-1;
    cin>>n;
    map<pair<long long,long long>,pair<long long,long long>>m;
    for(long long i=0;i<n;i++)
	{
        cin>>a>>b;
        if(!a&&!b) 
			MOD++;
        else
		{
            long long g=__gcd(a,b);
            a/=g,b/=g;
            if(b<0) 
				a=-a,b=-b;
            if(a<=0) 
				m[{b,-a}].second++;
            else 
				m[{a,b}].first++;
        }
    }
    for(auto u:m) 
		ans=ans*(quick_pow(2,u.second.first)+quick_pow(2,u.second.second)-1+mod)%mod;
    cout<<(ans+MOD)%mod;
    return 0;
}

Measured memory_bytes: 19204
using System;
using System.Linq;

class Program
{
    public static void Main(string[] args) {
        char[] str = Console.ReadLine().ToCharArray();
        int q = int.Parse(Console.ReadLine());
        for (int i = 0; i < q; i ++) {
            string[] s = Console.ReadLine().Split().ToArray();
            int a = int.Parse(s[1]);
            int b = int.Parse(s[2]);
            if (s[0] == "print") {
                string S = new String(str);
                Console.WriteLine(S.Substring(a, b-a+1));
            }
            if (s[0] == "reverse") {
                while(a<b) {
                    Swap(ref str[a], ref str[b]);
                    a++;
                    b--;
                }
            }
            if (s[0] == "replace") {
                char[] y = s[3].ToCharArray();
                int k = 0;
                for (int j = a; j <= b; j ++) {
                    str[j] = y[k];
                    k ++;
                }
            }
        }
    }
    public static void Swap<T>(ref T a, ref T b) {
        var t = a;
        a = b;
        b = t;
    }
}


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

int main() {
  
  int N, count;
  count = 0;
  string S;
  cin >> N >> S;
  
  for(int i = 1; i < N - 1; i++){
    if(S.at(i - 1) == 'A' && S.at(i) == 'B' && S.at(i + 1) == 'C'){
      count++;
    }
    //if(i == N - 2){
      // cout << S.at(i) << endl;
    //}
  }
      
  cout << count << endl;
  
}

Measured memory_bytes: 256
import math
n,m = map(int, input().split())

ans = 0

time = (n-m) * 100 + m * 1900
for i in range(1, 1000000):
  ans += pow(1-pow(0.5,m),i-1) * pow(0.5,m) * time * i

temp = math.ceil(ans)
if str(temp)[-1] == "1":
  print(temp - 1)
elif str(temp)[-1] == "9":
  print(temp + 1)
else:
  print(temp)

Measured memory_bytes: 9596