akhauriyash/Code-Regression huggingface dataset:
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
ll dp[100001];

int main(int argc, char const* argv[])
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n)cin >> a[i];
  dp[0] = 0;
  FOR(i, 1, k+1){
    set<ll> st;
    rep(j, n){
      if(i-a[j]>=0)st.insert(dp[i-a[j]]);
    }
    if(st.size() == 0)dp[i] = 0;
    else{
      int curr = 0;
      bool flag = true;
      for(auto itr = st.begin(); itr != st.end(); ++itr){
        if(*itr != curr){
          dp[i] = curr;
          flag = false;
          break;
        }
        curr++;
      }
      if(flag)dp[i] = st.size();
    }
  }
  if(dp[k] > 0)cout << "First" << endl;
  else cout << "Second" << endl;
	return 0;
}


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

int main(){
    int x[3];
    int y;
    cin>>x[0]>>x[1]>>x[2]; 
    sort(x,x+3);
    cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<endl;
    
    return 0;
}


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

int main() {
	int N, K;
	cin >> N >> K;
	int ans = 1;
	for (int i = 0; i < N; i++) {
		if (ans > K) {
			ans += K;
		}
		else {
			ans *= 2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def insertion_sort(A):
    for i in range(1, len(A)):
        temp = A[i]
        j = i - 1
        while j >= 0 and A[j] > temp:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = temp
        print(' '.join(list(map(str,A))))

if __name__ == '__main__':
    n = int(input())
    l = list(map(int, input().split()))
    print(' '.join(list(map(str,l))))
    insertion_sort(l)


Measured memory_bytes: 5600
N = int(input())
H = list(map(int,input().split()))
Score = []
count = 0
i = 0
while True:
    if i >= N-1:
        Score.append(count)
        break
    elif H[i+1] > H[i]:#elifを使う
        Score.append(count)
        count = 0
        i += 1
    elif H[i+1] <= H[i]:
        count += 1
        i += 1
print(max(Score))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin >>n;
    ll a[n],i,sum=0,sum_ind[n];
    for(i=0;i<n;i++){
        cin >>a[i];
        sum=(sum+a[i])%mod;
        if(i==0) sum_ind[i]=a[i];
        else sum_ind[i]=(a[i]+sum_ind[i-1])%mod;
    }
    ll ans=0;
    for(i=0;i<n;i++){
        ans=(ans+(((sum-sum_ind[i]+mod)%mod)*(a[i]))%mod)%mod;
    }
    cout <<ans<<endl;
}   

Measured memory_bytes: 6664
#include <iostream>

int main()
{
    int X,A,B;
    std::cin>>X;
    std::cin>>A;
    std::cin>>B;

    

    if(B-A<=0 ){
        std::cout<<"delicious"<<std::endl;
    }
    else if(B-A <= X){
        std::cout<<"safe"<<std::endl;
    }
    else{
        std::cout<<"dangerous"<<std::endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

string tostr(ll x){
    if(x  <= 0)return "";
    char c = '0'+x%10;
    return tostr(x/10) + c;
}
ll tonum(string s){
    reverse(ALL(s));
    ll num = 0;
    rep(i, s.size()){
        num += (s[i]-'0')*pow(10, i);
    }
    return num;
}
int main(){
    int k, x;
    cin >> k >> x;
    for(int i = x - (k-1); i < x + k; ++i)cout << i << " ";
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> H(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> H[i];
  }
  vector<int64_t> costs(N, INT64_MAX);
  costs[0] = 0;
  for (int64_t i = 0; i < N; ++i) {
    if (i + 1 < N) {
      costs[i + 1] = min(costs[i + 1], costs[i] + abs(H[i + 1] - H[i]));
    }
    if (i + 2 < N) {
      costs[i + 2] = min(costs[i + 2], costs[i] + abs(H[i + 2] - H[i]));
    }
  }
  cout << costs[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll qpow(ll a, ll b, ll MOD)
{
    ll ans = 1; a %= MOD;
    while (b)
    {
        if (b & 1) ans = (ans * a) % MOD;
        a = (a * a) % MOD; b >>= 1;
    }
    return ans;
}
int main()
{
    ll n; cin >> n;
    if (n % 7 == 0) n /= 7;
    ll ans = 9 * n, rec = 9 * n;
    for (int i = 2; i * i <= rec; ++i)
    {
        if (rec % i == 0) ans = ans / i * (i - 1);
        while (rec % i == 0) rec /= i;
    }
    if (rec > 1) ans = ans / rec * (rec - 1);
    vector <ll> factor;
    for (int i = 1; i * i <= ans; ++i)
    {
        if (ans % i == 0)
        {
            if (i * i == ans) factor.push_back(i);
            else factor.push_back(i), factor.push_back(ans / i);
        }
    }
    sort(factor.begin(), factor.end());
    for (auto &i : factor)
    {
        if (qpow(10, i, 9 * n) == 1)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3620
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
tmp = []
for i in range(0, n, 2):
    tmp.append(v[i])
c = Counter(tmp)
c1 = c.most_common(2)
tmp = []
for i in range(1, n, 2):
    tmp.append(v[i])
c = Counter(tmp)
c2 = c.most_common(2)
if c1[0][0] != c2[0][0]:
    print(n - (c1[0][1] + c2[0][1]))
    exit()
else:
    c1.append((-1, 0))
    c2.append((-1, 0))
    ans = min(n-c1[0][1]-c2[1][1], n-c1[1][1]-c2[0][1])
    print(ans)
    exit()

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

using namespace std;

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

    string s;
    cin >> s;

    for (int i = 0; i < a; i++) {
        if ('0' <= s[i] && s[i] <= '9')
            continue;

        cout << "No" << endl;
        return 0;
    }

    if (s[a] != '-') {
        cout << "No" << endl;
        return 0;
    }

    for (int i = a + 1; i < a + 1 + b; i++) {
        if ('0' <= s[i] && s[i] <= '9')
            continue;

        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

#define A

#ifdef A
int main(void) {
	double stx, sty, enx, eny;
	cin >> stx >> sty >> enx >> eny;

	printf("%.6lf\n", sqrt(pow(enx - stx, 2) + pow(eny - sty, 2)));


	return 0;
}
#endif // A

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

int main(){
  int n,m,q;
  int l[200000],r[200000];
  cin >> n >> m >> q;
  for(int i = 0;i < m;i++){
    cin >> l[i] >> r[i];
  }

  int rui[501][501] = {};

  for(int i = 0;i < m;i++){
    rui[l[i]][r[i]]++;
  }

  for(int i = 1;i <= 500;i++){
    for(int j = 0;j < 500;j++){
      rui[i][j+1] += rui[i][j];
    }
  }

  int a,b;

  for(int i = 0;i < q;i++){
    cin >> a >> b;
    int ans = 0;
    for(int i = a;i <= b;i++){
      ans += rui[i][b] - rui[i][a-1];
    }
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            //List<string> lstDel = new List<string>();
            //lstDel.Add("");
            string sOrg = "keyence";
            string sOut = "NO";
            if (sS == sOrg) { sOut = "YES"; }
            else
            {
                for (int i = 0; i < sS.Length; i++)
                {
                    for (int j = 1; j <= sS.Length - i; j++)
                    {
                        //lstDel.Add(sS.Substring(i, j));                               // 全ての連続部分文字列の取得 ←必要なかった
                        string sZan = "";                                               // 全ての連続部分文字列の取得後の残り
                        sZan = sS.Substring(0, i) + sS.Substring(j + i);
                        //lstDel.Add(sZan);
                        if (sZan == sOrg) { sOut = "YES"; break; }
                    }
                    if (sOut == "YES") { break; }
                }
            }
            //DispDebug(lstDel);

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
int n;
string S;
int check(int x){
    string s = S;
    int len = 0;
    for(int i = 1; i <= n; i++){
        if(len){
            len--;
            if(s[i] == '1') s[i] = '0';
            else s[i] = '1';
        }
        if(s[i] == '1'){
            if(i - 1 < x){
                if(n - i < x){
                    len = x - 1;
                }
            }
        }
    }
    if(len) return 0;
    return 1;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>S; S = " " + S;
    n = S.size() - 1;
    int l = 1, r = n;
    while(l < r){
        int mid = (l + r + 1)>>1;
        if(check(mid)) l = mid;
        else r = mid - 1;
    }
    cout<<l;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> xs(n);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        xs[i] = x;
    }
    vector<int> original = xs;
    sort(xs.begin(), xs.end());
    int mid1 = xs[n/2-1];
    int mid2 = xs[n/2];
    for (int i = 0; i < n; i++) {
        if (original[i] <= mid1) {
            cout << mid2 << endl;
        }
        else {
            cout << mid1 << endl;
        }
    }
}

Measured memory_bytes: 3712
n = int(input())
num_list = list(map(int,input().split()))
flag = True
for i in num_list:
    if i %2 ==0:
        if (i%3 == 0) or (i%5 == 0):
            flag = True
        else:
            flag = False
            break
            
if flag:
    print('APPROVED')
    
else:
    print('DENIED')
    

Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string.h>
#include<cmath>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    if(b%a==0)cout<<a+b;
    else cout<<b-a;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);i++)
#define FORE(x,arr) for(auto &x:arr)
#define FOR(i,a,n) for(int i=a;i<(int)(n);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;

const int MOD=1e9+7;
ll H,W,A,B;

ll modpow(ll a,ll b,ll mod) {
    if(a==0) return 1;
    a%=mod;
    ll pro=1;
    while(b>0) {
        if(b&1) {
            pro *= a;
            pro %= mod;
        }
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return pro%mod;
}

ll fact[200001];
ll fact_inv[200001];

int main(int argc, char const *argv[]) {
    cin>>H>>W>>A>>B;
    fact[0]=1, fact_inv[0]=1;
    FOR(i,1,H+W) {
        fact[i]=(fact[i-1]*i)%MOD;
        fact_inv[i]=modpow(fact[i],MOD-2,MOD);
    }

    ll ans = 0;
    FOR(x,B,W) {
        // a = (x+H-A-1)C(x)
        // b = (A-1+W-x-1)C(A-1)
        ll a = (((fact[x+H-A-1]*fact_inv[H-A-1])%MOD)*fact_inv[x])%MOD;
        ll b = (((fact[A+W-x-2]*fact_inv[W-x-1])%MOD)*fact_inv[A-1])%MOD;
        ans += (a*b)%MOD;
        ans %= MOD;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
import numpy as np
    
N,D=map(int, input().split())
X=[list(map(int,list(input().split()))) for i in range(N)] 

count = 0

for i in range(N):
    Z = np.sqrt(X[i][0]**2 + X[i][1]**2)
    if Z <= D:
        count = count + 1
        
print(count)

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

int main() 
{
    int h, w;
    cin >> h >> w;
    string S[h];
    rep(i,h) cin >> S[i];

    int V[h][w];
    rep(i,h)rep(j,w) V[i][j] = 0;

    rep(i,h) {
        int start=0;
        while(start < w) {
            if (S[i][start] == '#') {
                start++;
                continue;
            }
            int end=start;
            while (end+1 < w && S[i][end+1] != '#') {
                end++;
            }
            int x = end - start + 1;
            for (int j= start; j<=end; j++) {
                V[i][j] += x;
            }
            start=end+1;
        }       
    }

    rep(i,w) {
        int start=0;
        while(start <  h) {
            if (S[start][i] == '#') {
                start++;
                continue;
            }
            int end=start;
            while (end+1 < h && S[end+1][i] != '#') {
                end++;
            }
            int x = end - start + 1;
            for (int j= start; j<=end; j++) {
                V[j][i] += x;
            }
            start=end+1;
        }       
    }

    int ans = -1;
    rep(i,h)rep(j,w) ans = max(V[i][j], ans);
    ans--;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 19968
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void _main();
int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); return 0;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-5,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;

void _main(){
  int N;
  cin >> N ;
  vi cnt(3);
  rep(i,N){
    int a; cin >> a ;
    cnt[a-1]++;
  }
  vvvd dp(N+1,vvd(N+1,vd(N+1,-1.0)));
  dp[0][0][0] = 0;
  function<double(int,int,int)> solve = [&](int i,int j,int k){
    double& res = dp[i][j][k];
    if(res!=-1.0) return res;
    using D = double;
    int s = i + j + k;
    res = D(i)/D(s) * (i!=0 ? solve(i-1,j,k) : 0)
         + D(j)/D(s) * (j!=0 ? solve(i+1,j-1,k) : 0)
         + D(k)/D(s) * (k!=0 ? solve(i,j+1,k-1) : 0)
         + D(N)/D(s);
    return res;
  };
  cout << fixed;
  cout << setprecision(10) << solve(cnt[0],cnt[1],cnt[2]) << endl;
}

Measured memory_bytes: 216960
from collections import deque

n=int(input())
data=deque()
for i in range(n):
    order=input().split()
    if(order[0]=="insert"):
        data.appendleft(order[1])
    elif(order[0]=="delete"):
        try:
            data.remove(order[1])
        except:
            pass
    elif(order[0]=="deleteFirst"):
        data.popleft()
    else:
        data.pop()
print(" ".join(data))


Measured memory_bytes: 69732
#include<bits/stdc++.h>
using namespace std;
int main(){
  char n;
  string al = "abcdefghijklmnopqrstuvwxyz";
  cin >> n;
  for(int i =0; i<25; i++){
    if(al[i]==n){
      cout<<al[i+1];
      break;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
	ll l,r,d;
	cin>>l>>r>>d;
	ll cnt=0;
	for(ll i=l;i<=r;i++){
		if(i%d==0) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3560
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int D;
	cin >> D;
	if(D == 25){
		cout << "Christmas" << endl;
	}
	else if(D == 24){
		cout << "Christmas Eve" << endl;
	}
	else if(D == 23){
		cout << "Christmas Eve Eve" << endl;
	}
	else{
		cout << "Christmas Eve Eve Eve" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
function Main(input){
    var splited = [];
    var goukei = 0;
    splited = input.split("");
    for(var i = 0; i < 4; i++){
      if(splited[i] == '+') goukei = goukei + 1;
      if(splited[i] == '-') goukei = goukei - 1;
    }
  console.log(goukei);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  int N;
  int A = 1;
  bool flag = false;
  cin >> N;
  while (true){
    if (N <= 2*A-1) flag = true;
    if (flag==true) break;
    A = 2*A;
  }
      cout << A <<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    train = N * A
    taxi = B

    if train < taxi:
        print(train)
    elif train == taxi:
        print(train)
    else:
        print(taxi)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys


def memoize(f):
    memo = {}

    def main(*args):
        if args in memo:
            return memo[args]
        result = memo[args] = f(*args)
        return result

    return main


def get_num(remains):
    i = 0
    while remains:
        if remains & 1:
            yield i
        i += 1
        remains >>= 1


@memoize
def calc(n, s, remains):
    if n == 1:
        if remains & (1 << s):
            return 1
        else:
            return 0
    if s <= 0:
        return 0

    return sum(calc(n - 1, s - n * m, remains ^ (1 << m)) for m in get_num(remains) if s - n * m >= 0)


for line in sys.stdin:
    n, s = map(int, line.split())
    print(calc(n, s, (1 << 10) - 1))

Measured memory_bytes: 79396
#include<iostream>
using namespace std;
#include<vector>
pair<int,int>p[500];
#include<algorithm>
int ans[500*500];
main()
{
	int n;cin>>n;
	for(int i=0;i<n;p[i].second=i,i++)cin>>p[i].first;
	sort(p,p+n);
	int les=0,pre=0;
	for(int i=0;i<n;i++)
	{
		les+=p[i].first-pre-1;
		les-=p[i].second;
		if(les<0)
		{
			cout<<"No"<<endl;
			return 0;
		}
		int cnt=0;
		for(int j=0;cnt<p[i].second;)
		{
			if(ans[j]);
			else ans[j]=p[i].second+1,cnt++;
			j++;
			if(j>=n*n)
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
		ans[p[i].first-1]=p[i].second+1;
		pre=p[i].first;
	}
	for(int i=1;i<=n;i++)
	{
		int cnt=n-i;
		int lastp=0;
		for(int j=0;j<n*n;j++)if(ans[j]==i)lastp=j;
		for(int j=lastp+1;cnt;)
		{
			if(ans[j]);
			else ans[j]=i,cnt--;
			j++;
			if(j>=n*n&&cnt>0)
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<n*n;i++)cout<<(i?" ":"")<<ans[i];
	cout<<endl;
}


Measured memory_bytes: 2176
#include <stdio.h>
 
int main(void) {
  int N,Ans;
  scanf("%d", &N);
  if (N%2==0) {
    Ans = N/2;
  }
  else {
    Ans = (N+1)/2;
  }
  printf("%d", Ans);
  return 0;
}

Measured memory_bytes: 128
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function hpush(h::Array{Tuple{Int,Int},1},x::Tuple{Int,Int})
	push!(h,x)
	if length(h) > 1
		l = length(h)
		k = div(l,2)
		while h[k][2]>x[2]&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(div(k,2),1)
			l = div(l,2)
		end
	end
end

function hpop(h::Array{Tuple{Int,Int},1})
	x = h[1]
	z = pop!(h)
	if !isempty(h)
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>=l
				break
			elseif 2*k+1>=l
				if h[2*k][2]>=z[2]
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if h[2*k][2]>=z[2]&&h[2*k+1][2]>=z[2]
					break
				else
					t = h[2*k][2]<h[2*k+1][2]?2*k:2*k+1
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end


function main()
	n,m = readline() |> split |> parseMap
	e = [Int[] for i in 1:3*n]
	for i in 1:m
		u,v = readline() |> split |> parseMap
		push!(e[u],n+v)
		push!(e[n+u],2*n+v)
		push!(e[2*n+u],v)
	end
	s,t = readline() |> split |> parseMap
	dis = -ones(Int,3*n)
	h = Array{Tuple{Int,Int},1}()
	push!(h,(s,0))
	while !isempty(h)
		v,w = hpop(h)
		dis[v]=dis[v]<0?w:min(dis[v],w)
		if v == t
			break
		end
		for i in 1:length(e[v])
			if dis[e[v][i]]<0　|| dis[e[v][i]]>w+1
				dis[e[v][i]] = w+1
				hpush(h,(e[v][i],w+1))
			end
		end
	end
	println(dis[t]>=0?div(dis[t],3):-1)

end

main()

Measured memory_bytes: 167908
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,x;
  cin>>n;
  if(n>=1 && n<=9)
  cout<<"Yes"<<endl;
  else
  {
    int flag=0, count=1;
    for(i=2; i<=9; i++)
    {
      for(j=i; j<=9; j++)
      {
        if(i*j==n)
        flag=1;
      }
    }
    if(flag==1)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define fi first
#define se second

const int mod=1e9+7;
int n,k,ret;
int get(int u,int v){
    int z=v-u+1;
    return (u+v)*z/2;
}
int sum(int A) { return get(0,A-1);}
int sum1(int A) {return get(n-A+1,n);}
main()
{
    cin>>n>>k;
    forinc(i,k,n+1){
        int A=sum(i),B=sum1(i);
        //cout<<A<<" "<<B<<"\n";
        ret=(ret+(B-A+1+mod)%mod)%mod;
    }
    cout<<ret;
}


Measured memory_bytes: 3632
//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
忘文件操作，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
map<string,bool> mp;
int n=read();
signed main(){
	int ans=0;
	while(n--){
		string s;cin>>s;
		if(!mp[s])	ans++;
		mp[s]=1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 19136
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  ll n;
  cin>>n;
  vector<P> v;
  for(int i=0;i<n;i++){
    ll a,b;
    cin>>a>>b;
    v.push_back(P(b,a));
  }
  sort(v.begin(),v.end());
  ll t=0;
  for(int i=0;i<n;i++){
    t+=v[i].second;
    if(t>v[i].first) {
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 6384
#include <iostream>

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int flag = 0, cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] - flag == 'A') flag++;
    else if (s[i] == 'A') flag = 1;
    else flag = 0;
    if (flag == 3) {
      flag = 0;
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 31; i++) {
		if ((b / (1 << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long S, sum, L[25000009], LIM = 25000000, mod = 1000000007;

int main() {
	cin >> S;
	for (int i = 1; i <= LIM; i++) {
		int cx = i; while (cx >= 1) { cx /= 10; L[i]++; }
		L[i] += L[i - 1];
	}
	for (int i = 0; i < 9999999; i++) {
		int pos1 = lower_bound(L, L + LIM, L[i] + S) - L;
		if (L[pos1] == L[i] + S) sum++;
	}
	for (int i = S / 8; i >= 1; i--) {
		if (S%i == 0) sum += (9LL * modpow(10, (S / i) - 1, mod) - i + 1 + mod) % mod;
		else sum++;
	}
	cout << sum%mod << endl;
	return 0;
}

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

int GCD(int a, int b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

int gcd(int a, int b, int c) {
  int N = 3;
  int g = 0;
  for (int i = 0; i < N; ++i) {
    if (i == 0) {
      g = GCD(g, a);
    } else if (i == 1) {
      g = GCD(g, b);
    } else {
      g = GCD(g, c);
    }
  }
  return g;
}

int main() {
  int k;
  ll s = 0;
  cin >> k;
  for (int i = 1; i <= k; ++i) {
    for (int j = 1; j <= k; ++j) {
      for (int t = 1; t <= k; ++t) {
        s += gcd(i, j, t);
      }
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>

using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define int long long

const int MOD = 1000000007;

int mod(int &x)
{
    x = (1ll * MOD * MOD + x) % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, k; cin >> n >> k;
    int dp[n+2][n*k+1];
    memset(dp, 0, sizeof dp);

	int curmax = 0;
    dp[n+1][0] = 1;
//    cout << "S" << dp[1][3] << endl;
    for (int i = n; i >= 1; --i) {
		int newmax = curmax;

		// put <= i at position i
        for (int j = 0; j <= curmax; ++j) {
        	int j1 = j - (j % i) + i;
			int l = j, r = j + min(i, k);
//			cerr << i << ' ' << j << ": " << l << ' ' << j1 << ' ' << r << endl;

			dp[i][j+j/i] += (1ll * dp[i+1][j] * (min(j1-1, r) - j + 1)) % MOD;
			dp[i][j+j/i] %= MOD;

			dp[i][j+j/i+1] += (1ll * dp[i+1][j] * (r - min(j1, r+1) + 1)) % MOD;
			dp[i][j+j/i+1] %= MOD;
			newmax = max(newmax, j+j/i+1);
        }

        // put > i at position i
        for (int j = 0; j <= curmax; ++j) {
            dp[i][j] += (1ll * dp[i+1][j] * max(k-i, 0)) % MOD;
            dp[i][j] %= MOD;
        }
        curmax = newmax;
        while (curmax >= 0 && dp[i][curmax] == 0) --curmax;

//        for (int j = 0; j <= curmax; ++j) cout << dp[i][j] << ' '; cerr << endl;
    }

    int t2 = 0;
    for (int j = 0; j <= curmax; ++j) {
        t2 += dp[1][j] * j;
        t2 %= MOD;
    }

    int t1 = 1;
    for (int i = 0; i < n-1; ++i) {
        t1 = (1ll * t1 * (k+1)) % MOD;
    }
    t1 = (1ll * t1 * n) % MOD;
    t1 = (1ll * t1 * k * (k+1) / 2) % MOD;

    int ans = t1 - t2;
    mod(ans);
    cout << ans << endl;
}


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

int main()
{
    string S;
    int count = 0;
    int longestCount = 0;
    cin >> S;
    for (int i = 0;i < S.length();i++) {
        if ((S[i]=='A')||(S[i]=='T')||(S[i]=='G')||(S[i]=='C')) {
            count++;
        }
        else {
            count = 0;
        }
        if (count > longestCount) {
            longestCount++;
        }
    }
    cout << longestCount << endl;
    return 0;
}

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

constexpr int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> x(N);
    for(int i=0; i<N; ++i) {
        cin >> x[i];
    }
    int L, Q;
    cin >> L >> Q;
    vector<vector<int>> v(20, vector<int>(N));
    for(int i=0; i<N; ++i) {
        v[0][i] = upper_bound(x.begin(), x.end(), x[i]+L) - x.begin() - 1;
    }
    for(int i=1; i<20; ++i) {
        for(int j=0; j<N; ++j) {
            v[i][j] = v[i-1][v[i-1][j]];
        }
    }
    for(int i=0; i<Q; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(a > b) {
            swap(a, b);
        }
        int res = 0;
        for(int j=19; j>=0; --j) {
            if(v[j][a] < b) {
                a = v[j][a];
                res += (1 << j);
            }
        }
        cout << res+1 << endl;
    }
}


Measured memory_bytes: 9080
class union_find:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.rank = [0 for _ in range(n)]
    
  def root(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.root(self.par[x])
      return self.par[x]
      
  def same(self, x, y):
    return self.par[x] == self.par[y]
        
  def unite(self, x, y):
    x, y = self.root(x), self.root(y)
    if x != y:
      if self.rank[x] < self.rank[y]:
        self.par[x] = y
      else:
        self.par[y] = x
        if self.rank[x] == self.rank[y]:
          self.rank[x] += 1

N, M = map(int, input().split())
uf = union_find(N)
for i in range(M):
  a, b = map(int, input().split())
  uf.unite(a-1, b-1)
for i in range(N):
  uf.par[i] = uf.root(i)
D = {}
L = [uf.par[i] for i in range(N)]
for i in range(N):
  if L[i] in D:
    D[L[i]] += 1
  else:
    D[L[i]] = 1
print(max(D[i] for i in D))

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

int main(){
  
  int n;
  cin >> n;
  cout << pow(n,2) << endl;

}

Measured memory_bytes: 256
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = new int[]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
            var k = int.Parse(Console.ReadLine());

            Console.WriteLine(s[k-1]);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long

using namespace std;
const int maxn=56;
const int MAXN=330000; 
int prime[MAXN];//保存素数   
bool vis[MAXN];//初始化
int ans[66];
int Prime(int n)  
{  
    int cnt=0;  
    memset(vis,0,sizeof(vis));  
    for(int i=2;i<n;i++)  
    {  
        if(!vis[i])  
        prime[cnt++]=i;  
        for(int j=0;j<cnt&&i*prime[j]<n;j++)  
        {  
            vis[i*prime[j]]=1;  
            if(i%prime[j]==0)//关键   
            break;  
        }  
    }  
    return cnt;//返回小于n的素数的个数   
}	
int main()
{
	Prime(55556);
	int n;
	cin>>n;
	int cnt=1;
	cout<<11;
	for(int i=6;i<5300;i++){
		if( cnt<n && prime[i]%10 == 1){
			cnt++;
			cout<<" "<<prime[i];
		}
	}
	cout<<endl;
}

Measured memory_bytes: 640
#include<iostream>

int main(){

    size_t n;
    std::cin >> n;

    for(size_t i = 0; i < n; i++){
        size_t a;
        std::cin >> a;

        if(a % 2 == 0){
            if(a % 3 != 0 && a % 5 != 0){
                std::cout << "DENIED" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "APPROVED" << std::endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ll tmp[200001];
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	for (int k = 4; k < 8; k++) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	const int m = (1 << 20) - 1;
	int N = getint(), K = getint();
	ll A[200001];
	A[0] = 0;
	rep(i, N) {
		ll kari = (A[i] >> 32) + (getint() - 1) % K;
		if (kari >= K) kari -= K;
		A[i + 1] = (kari << 32) + i + 1;
	}

	pakuri_sort(N + 1, A);
	int kazu = 0;
	int mae = A[0] >> 32;
	rep(i, N + 1) {
		if (mae != A[i] >> 32) {
			kazu++;
			mae = A[i] >> 32;
		}
		tmp[A[i] & m] = kazu;
	}
	rep(i, N + 1) A[i] = 0;

	ll kotae = 0;
	rep(i, N + 1) {
		kotae += A[tmp[i]];
		A[tmp[i]]++;
		if (i - K + 1 >= 0) A[tmp[i - K + 1]]--;
	}

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 3456
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    int ans=1;
    int p,q,r;
    p=q=r=0;
    rep(i,n){
        ans=ans*((a[i]==p)+(a[i]==q)+(a[i]==r))%mod;
        if(a[i]==p){
            p++;
            continue;
        }
        if(a[i]==q){
            q++;
            continue;
        }
        r++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  i64 A, B, N;
  cin >> A >> B >> N;
  if(B - 1 <= N) {
    cout << (A * (B - 1)) / B - A * ((B - 1) / B) << endl;
  }
  else {
    cout << (A * N) / B - A * (N / B) << endl;
  }
}



Measured memory_bytes: 3624
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 305;

int i,j,k,n,m,l,q,d[N][N];

void solve()
{
    cin>>n>>m>>l;
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
        {
            d[i][j]=INF;
        }
        d[i][i]=0;
    }
    for(i=1;i<=m;++i)
    {
        int a,b,c;
        cin>>a>>b>>c;
        d[a][b]=d[b][a]=c;
    }
    for(k=1;k<=n;++k)
    {
        for(i=1;i<=n;++i)
        {
            for(j=1;j<=n;++j)
            {
                if(d[i][k]==INF || d[k][j]==INF)
                    continue;
                if(d[i][j]>d[i][k]+d[k][j])
                {
                    d[i][j]=d[i][k]+d[k][j];
                }
            }
        }
    }
    for(i=1;i<=n;++i)
    {
    	for(j=1;j<=n;++j)
    	{
    		if(d[i][j]<=l)
    			d[i][j]=1;
    		else
    			d[i][j]=INF;
    	}
    }
    for(k=1;k<=n;++k)
    {
        for(i=1;i<=n;++i)
        {
            for(j=1;j<=n;++j)
            {
                if(d[i][k]==INF || d[k][j]==INF)
                    continue;
                if(d[i][j]>d[i][k]+d[k][j])
                {
                    d[i][j]=d[i][k]+d[k][j];
                }
            }
        }
    }
    cin>>q;
    while(q--)
    {
        int s,t;
        cin>>s>>t;
        d[s][t]--;
        if(d[s][t]==INF-1)
        	d[s][t]=-1;
        cout<<d[s][t]<<endl;
    }
}

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

Measured memory_bytes: 4360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
P solve(ll x,ll y,ll z){
  //xyyyyyyyyyyyyyyy
  if(y==0) return P(z,x);
  ll kans=0;
  if(x==0){
    x=y;
    z--;
  }
  ll now=x;
  ll cnt=0;
  do{
    if(now+y<10){
      now=now+y;
      kans++;
    }
    else{
      now=now+y-9;
      kans+=2;
    }
  //  if(cnt<15) cout<<"X:"<<x<<"NOW:"<<now<<endl;
    cnt++;
  }while(now!=x);

//  cout<<"CNT"<<cnt<<" kans:"<<kans<<endl;

  ll ans=kans*(z/cnt);
  z%=cnt;
  ll ret=x;
  for(int i=0;i<z;i++){
    if(ret+y<10){
      ret=ret+y;
      ans++;
    }
    else{
      ret=ret+y-9;
      ans+=2;
    }
  }
  return P(ans,ret);
}
int main(){

  ll m;
  cin>>m;
  ll ans=0;
  ll v=0;
  for(int i=0;i<m;i++){
    ll d,c;
    cin>>d>>c;
    P p=solve(v,d,c);
    ans+=p.first;
    v=p.second;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

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

    vector<ll> a(m), b(m), c(m);
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        ll x = 0;
        for(int j = 0; j < b[i]; j++){
            ll ct ;
            cin >> ct;
            x += (1LL<<(ct-1));
        }
        c[i] = x;
    }
    ll MAX_VAL = 1LL<<60;
    vector<vector<ll>> dp(m+1,vector<ll>((1LL<<n), MAX_VAL));
    dp[0][0] = 0;

    for(int i = 0; i < m; i++){
        for(int j = 0; j < (1LL<<n); j++){
            if(dp[i][j] == MAX_VAL){
                ;
            }else{
                dp[i+1][(int)(j|c[i])] = min(dp[i+1][(int)(j|c[i])],dp[i][j]+a[i]);
                dp[i+1][j] = min(dp[i][j],dp[i+1][j]);
            }
        }
    }
    if(dp[m][(1LL<<n)-1] == MAX_VAL){
        cout << -1 << endl;
    }else{
        cout << dp[m][(1LL<<n)-1] << endl;
    }
    return 0;

}


Measured memory_bytes: 32384
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  vi A(5);
  REP(i, 5) {
    cin >> A.at(i);
    if (A.at(i) == 0) cout << i+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3612
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.IArray             as IA
import qualified Data.Array.IO                 as AI
import qualified Data.Array.MArray             as MA
import qualified Data.Array.ST                 as STA
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Graph                    as G
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.IntSet                   as IS
import           Data.List
import qualified Data.Map.Strict               as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence                 as SQ
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Tree                     as T
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

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

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n     ] = put n
putList (n : ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n     ] = putStr n
putStrList (n : ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b | b         = putStrLn "YES"
             | otherwise = putStrLn "NO"

yesNo b | b         = putStrLn "Yes"
        | otherwise = putStrLn "No"

main = do
  [a, b] <- readInt
  yesNo $ (== 2) $ maximum $ map length $ map
    (filter (\x -> x == a || x == b))
    [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 1], [2]]


Measured memory_bytes: 380
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a*b%2==0) {
			System.out.println("Even");
		}else {
			System.out.println("Odd");
		}
	}
}

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

#define ll long long

int price[6]={100, 101, 102, 103, 104, 105};

void solve(){
    bool dp[101000];memset(dp, 0, sizeof dp);
    dp[0]=true;
    int x;
    cin>>x;
    for(int i=0; i<x; i++){
        for(int j=0; j<6; j++){
            dp[i+price[j]]|=dp[i];
        }
    }
    if(dp[x]){
        cout<<'1'<<endl;
    }else{
        cout<<'0'<<endl;
    }
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
int B[101];
bool rm[101];

int main(){

    fastStream();
    cin >> N;
    for(int i = 0; i < N; i++) cin >> B[i];
    vector<int> ans;
    vector<int> seq(B, B + N);
    for(int j = 0; j < N; j++){
        for(int i = (int)seq.size() - 1; i >= 0; i--){
            if(i + 1 == seq[i]){
                ans.push_back(seq[i]);
                seq.erase(seq.begin() + i);
                break;
            }
        }
    }
    if((int)ans.size() != N){
        cout << -1 << endl;
        return 0;
    }
    
    reverse(ans.begin(), ans.end());
    for(int a : ans){
        cout << a << endl;
    }
    

    return 0;
}


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

int main() {
  string A, B;
  cin >> A >> B;
  bool b = true;
  for(int i = 0; i < A.size(); i++) {
    if(A.at(i) != B.at(i)) {
      b = false;
      break;
    }
  }
  if(b) cout<< "Yes" << endl;
  else cout<< "No" << endl;
}


Measured memory_bytes: 3576