akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) {cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl;}

using namespace std;

template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}
bool operator<(const TRI&_)const{return(fi==_.fi)?((se==_.se)?(th<_.th):(se<_.se)):(fi<_.fi);}};
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,TRI<S,T,U>&t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}

typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef TRI<int, int, int> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if(n % 2 == 0){
        cout << n*(n-2)/2 << "\n";
        srep(i,1,n+1){
            srep(j,i+1,n+1){
                if(i + j == n + 1) continue;
                cout << i << " " << j << "\n";
            }
        }
    }else{
        cout << (n-1)*(n-3)/2+n-1 << "\n";
        srep(i,1,n){
            srep(j,i+1,n){
                if(i + j == n) continue;
                cout << i << " " << j << "\n";
            }
        }
        srep(i,1,n){
            cout << i << " " << n << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 
int main()
{
	int n,m;
	string s[100],t[100];
	cin>>n;
	for(int i=0;i<n;i++) cin>>s[i];
	cin>>m;
	for(int i=0;i<m;i++) cin>>t[i];
	
	int maxv=0;
	for(int i=0;i<n;i++){
		int v=0;
		for(int j=0;j<n;j++){
			if(s[i]==s[j]) v++;
		}
		for(int j=0;j<m;j++){
			if(s[i]==t[j]) v--;
		}
		maxv=max(maxv,v);
	}
	
	cout<<maxv<<endl;
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

signed main(){

	lli x;
	cin>>x;

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

	return 0;
}

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

template<typename T>
class NodeAllocator {
public:
    NodeAllocator() = default;
    explicit NodeAllocator(int num): reserved_(num), assigned_(0) {
        buf_ = new T[num];
    };

    T* GetAlloc(int num) {
        if (assigned_ + num >= reserved_) {
            return nullptr;
        }
        int retp = assigned_;
        assigned_ += num;
        return buf_ + retp;
    }

    void ReAlloc(int num){
        DeleteAlloc();
        buf_ = new T[num];
        reserved_ = num;
    }

    ~NodeAllocator() {
        DeleteAlloc();
    }

private:
    void DeleteAlloc() {
        if (reserved_ == 0) {
            return;
        }
        if (reserved_ > 1) {
            delete [] buf_;
        }else{
            delete buf_;
        }

        assigned_ = 0;
        reserved_ = 0;
    }

    int reserved_;
    int assigned_;
    T *buf_;
};
struct Node {
    int key;
    Node *p = nullptr;
    Node *l = nullptr;
    Node *r = nullptr;
};

NodeAllocator<Node> Alloc;

Node *root;

void Insert(int v) {
    Node *p= nullptr;
    Node *x = root;
    Node *k = Alloc.GetAlloc(1);
    k->key = v;
    while (x != nullptr) {
        p = x;
        if (k->key < x->key) {
            x = x->l;
        }else{
            x = x->r;
        }
    }
    k->p = p;
    if (p == nullptr) {
        root = k;
    } else if (k->key < p->key) {
        p->l = k;
    } else{
        p->r = k;
    }
}

void Preorder(Node* tgt) {
    if (tgt == nullptr) {
        return;
    }
    std::cout << " " << tgt->key;
    Preorder(tgt->l);
    Preorder(tgt->r);
}

void Inorder(Node* tgt) {
    if (tgt == nullptr) {
        return;
    }
    Inorder(tgt->l);
    std::cout << " " << tgt->key;
    Inorder(tgt->r);
}

int main() {
    int n;
    std::cin >> n;
    Alloc.ReAlloc(n);
    for (int i = 0; i < n; i++) {
        std::string str;
        std::cin >> str;
        if (str == "print") {
            Inorder(root);
            std::cout << std::endl;
            Preorder(root);
            std::cout << std::endl;
            continue;
        }
        int k;
        std::cin >> k;
        if (str == "insert") {
            Insert(k);
        }
//        if (str == "find") {
//        }
    }
}



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

int main()
{
    ll x;
    cin >> x;
    double ans = x / 5.5 + 1;
    if((ll)ans > (x-1) / 5.5 + 1) ans -= 1;
    cout << ll(ans) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    string s;
    cin >> s;
    cout << (s[0] == s[2] ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;

int n;
vector<vector<string> > s;
vector<string> m;
set<string> se;

int main(void) {
    while (cin>>n && n) {;
        m.clear();
        s.clear();
        se.clear();
        for (int i = 0; i < n; i++) {
            string t;
            vector<string> u;
            cin >> t;
            int l = 0, r = 0;
            while (t[r] != ':') r++;
            u.push_back(t.substr(l,r-l));
            m.push_back(t.substr(l,r-l));
            
            r++;
            while (1) {
                l = r;
                while (t[r] != '.' && t[r] != ',') r++;
                u.push_back(t.substr(l,r-l));
                m.push_back(t.substr(l,r-l));
                if (t[r] == '.') break;
                r++;
            }
            s.push_back(u);
        }
        sort(m.begin(), m.end());
        m.erase(unique(m.begin(), m.end()), m.end());
        
        for (int i = 0; i < s[0].size(); i++) se.insert(s[0][i]);
        s.erase(s.begin());
        bool f = true;
        int cnt = 1;
        while (f) {
            f = false;
            for (int i = 0; i < s.size(); i++) {
                set<string>::iterator it = se.find(s[i][0]);
                if (it != se.end()) {
                    for (int j = 1; j < s[i].size(); j++) se.insert(s[i][j]);
                    s.erase(s.begin()+i);
                    cnt++;
                    f = true;
                }
            }
        }
        cout << se.size()-cnt << endl;
    }
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1e9 + 7

template < typename T >
void printVector (const vector < T > & vec) {
	for (const T x : vec) {
		cout << x << " ";
	}
	cout << endl;
}

template < typename T >
void printMatrix (const vector < vector < T > > & mat) {
	for (const vector < T > vec : mat) {
		printVector (vec);
	}
	cout << endl;
}

const ll INF = 1e18L + 5;

template < typename T >
void min_self (T& a, T b) {
	a = min (a, b);
}

template < typename T >
void max_self (T& a, T b) {
	a = max (a, b);
}

template < typename T >
void add_self (T & a, T b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

template < typename T >
void sub_self (T & a, T b) {
	a -= b;
	if (a < 0) {
		a += MOD;
	}
}

int main() {
	int n, k;
	scanf ("%d %d", &n, &k);
	vector < int > a (n);
	for (int & x : a) scanf ("%d", & x);
	vector < int > dp (k + 1);
	dp[0] = 1;
	for (int child = 0; child < n; child++) {
		// upper bound = a[child]
		// lower bound = 0
		vector < int > vec (k + 1, 0);
		for (int used = k; used >= 0; used--) {
			// used -> #used (distributed) candies
			// toGive >= 0 and toGive <= a[child] and toGive + used <= k
			// => toGive is in [0, min (a[child], k - used)]
			int to = min (a[child], k - used);
			// x = toGive + used
			// toGive = 1 -> toGive + used = used + 1
			// toGive = to -> toGive + used = used + to
			int y = used + 1, z = used + to;
			int temp = dp[used];

			// for (int x = y; x <= z; x++) {
			// 	add_self (dp[x], temp);
			// }
			if (y <= z) {
				add_self (vec[y], temp);
				if (z < k) sub_self (vec[z + 1], temp);
			}
		}
		int prefix_sum = 0;
		for (int i = 0; i <= k; i++) {
			add_self (prefix_sum, vec[i]);
			add_self (dp[i], prefix_sum);
		}
	}
	printf ("%d\n", dp[k]);
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N, Q;
    cin >> N >> Q;

    vector<int> A(N), X(Q);
    rep(i, N) scanf("%lld", &A[i]);
    rep(i, Q) scanf("%lld", &X[i]);

    if (N % 2) {
        A.insert(A.begin(), 0);
        N++;
    }

    int sum = 0;
    REP(i, N / 2, N - 1) sum += A[i];

    set<pair<int, int>>st;
    st.insert(mp(0, sum));

    int pt1 = 1;
    int pt2 = N / 2;
    while (pt2 < N - 1) {
        int val = (A[pt1] + A[pt2]) / 2 + 1;
        sum += A[pt1];
        sum -= A[pt2];
        st.insert(mp(val, sum));
        pt1 += 2;
        pt2++;
    }

    rep(i, Q) {
        auto it = st.upper_bound(mp(X[i] + 1, -100));
        it--;
        cout << it->second << endl;
    }

    return 0;
}


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

int main(){
	int q1,b,c1,c2,q2;
	while(cin >> q1 && q1){
		cin >> b >> c1 >> c2 >> q2;
		int X = 0 , Y = 0;
		while( X < q2 && b - c1 >= 0 ) X++ , b -= c1;
		while( b - c2 >= 0 ){
			Y++;
			b -= c2;
		}
		while( X && X+Y < q1){
			X --;
			b += c1;
			while( b - c2 >= 0 ){
				Y++;
				b -= c2;
			}
		}
		while( b - c2 >= 0 ){
			Y++;
			b -= c2;
		}
		if( X+Y < q1 || !X || b < 0) cout << "NA" << endl;
		else cout << X << " " << Y << endl;
	}
	
}

Measured memory_bytes: 1160
input()
a=set(map(int,input().split()))
n=int(input())
b=sorted(map(int,input().split()))
def bs(b,x):
    ma=len(b)
    mi=0
    while abs(ma-mi)>1:
        mid=(ma+mi)//2
        if b[mid]<x:
            mi=mid
        else:
            ma=mid
    if b[mi]==x:
        return True
    elif ma!=n and b[ma]==x:
        return True
    return False


print(sum([bs(b,i)for i in a]))


Measured memory_bytes: 16192
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

void solve(long long N, long long K, vector<long long> A){
	cout<<ceil(double(N-1)/(K-1))<<endl;
}

int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	long long K;
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	scanf("%lld",&K);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, K, A);
	return 0;
}



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

int main(){
	int n,*a,i,k_2=0,k_4=0;
	scanf("%d",&n);
	a=new int[n];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%4==0){
			k_4++;
		}
		else if(a[i]%2==0){
			k_2++;
		}
	}
	if(k_4>=n/2){
		printf("Yes");
	}
	else{
		if((2*k_4+k_2)>=n){
			printf("Yes");
		}
		else{
			printf("No");
		}
	}
	return 0;
	system("pause");
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //freopen("input.txt", "r", stdin);
  #endif // LOCAL
  LL n;
  cin >> n;
  LL ans = (n/500) * 1000;
  n -= (n/500) * 500;

  ans += (n/5) * 5;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
    m = (l + r) // 2
    res = n * n - a.searchsorted(m - a).sum()
    if res >= k:
        l = m
    else:
        r = m
b = np.array([0] * (n + 1))
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
    t = n - a.searchsorted(l - x)
    ans += b[t] + x * t
    cnt += t
print(ans - (cnt - k) * l)


Measured memory_bytes: 23364
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
    return '"' + s + '"';
}
string to_string(const char* s) {
    return to_string((string) s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
template<typename T>
void read(T& val){
    cin >> val;
}
template<typename T>
void read(vector<T>& a){
    for(int i = 0; i < (int)a.size(); ++i){
      read(a[i]);
    }
}
template<typename Head, typename... Tail>
void read(Head& H, Tail&... T){
    read(H);
    read(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define vec vector
#define i64 long long
#define endl '\n'
#define sz(x) (x).size()
#define times(n) for(int i = 0; i < (n); ++i)
#define bits(x) __builtin_popcount(x)
#define int i64
int test_case_number = 1;

void print_case(){
    #ifdef LOCAL
    cout << "Case #" << test_case_number++ << ": ";
    #endif
}

void solve(){
    int n; cin >> n;
    vector<int> a(n);
    read(a);
    int ans = 0;
    for(int i = 1; i < n; ++i){
        if(a[i] < a[i - 1]){
            ans += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    cout << ans << endl;
}
 
int32_t main(){
    solve();
}

Measured memory_bytes: 4760
#include <cstddef>
#include <limits>
#include <climits>
#include <cfloat>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <new>
#include <typeinfo>
#include <exception>
#include <initializer_list>
#include <stdexcept>
#include <cassert>
#include <cerrno>
#include <system_error>
#include <string>
#include <utility>
#include <tuple>
#include <bitset>
#include <cctype>


#if __has_include(<string_view>)
#   include <string_view>
#endif

#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>

#if __has_include(<filesystem>)
#   include <filesystem>
#endif

#include <cstdio>
#include <cinttypes>


#include <regex>
#include <atomic>
#include <thread>
#include <mutex>
#include <shared_mutex>
#include <condition_variable>
#include <future>

using namespace std;

int main(){
    int N;
    int M;
    
    cin >> N >> M;
    
//    偶数+偶数のとき
    int n = (N*(N-1))/2;
    
//    奇数+奇数のとき
    int m = (M*(M-1))/2;
    
    int sum = n+m;
    
    cout << sum << endl;
}


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

int main(){
    int n;
    cin >> n;
    char s[n];
    cin >> s;

    int counter = 0;
    for(int i=0; i<n; i++){
        if(i==0){
            counter = 1;
        }else{
            if(s[i] != s[i-1]){
                counter++;
            }
        }
    }

    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,t;
    cin>>a>>b>>c;
	if(a>b) {t=a;a=b;b=t;}
	if(b>c) {t=b;b=c;c=t;}
	if(a>b) {t=a;a=b;b=t;}
	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}

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

int main(void){
    int k,v,u;
    cin>>k;
    vector<int> dp(k,46);
    dp[1] = 1;
    deque<int> deq = {1};
    while(v = deq.front()){
        deq.pop_front();
        u = (v*10)%k;
        if(dp[u] > dp[v]){
            dp[u] = dp[v];
            deq.push_front(u);
        }
        u = (v+1)%k;
        if(dp[u] > dp[v]+1){
            dp[u] = dp[v]+1;
            deq.push_back(u);
        }
    }
    cout<<dp[0]<<endl;
}


Measured memory_bytes: 896
n = int(input())
a = [int(i) for i in input().split()]
a.sort()

ma = 2 * 10 ** 6
tab = [False] * (ma)

mapp = {}
for i in a:
    if i in mapp:
        mapp[i] += 1
    else:
        mapp[i] = 1

ans = 0
for i in a:
    if not tab[i]:
        if mapp[i] == 1:
            ans += 1
        for j in range(i, ma, i):
            tab[j] = True
print(ans)


Measured memory_bytes: 137000
#include<iostream>
 using namespace std ;
 int main()
{
 int A, B, C, D, x, y, z, k;
 cin>>A;
 cin>>B;
 cin>>C;
 cin>>D;
x=(A+C);
y=(A+D);
z=(B+C);
k=(B+D);
if (x<=y&&x<=z&&x<=k)
{
  cout<<x<<endl;
}
if  (y<=k&&y<x&&y<=z)
{
  cout<<y<<endl;
}
if (z<y&&z<x&&z<=k)
{
  cout<<z<<endl;
}
if (k<y&&k<z&&k<x)
{
  cout<<k<<endl;
}
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 30;
const ll MOD = 1000000007;

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    ll r, d, x; cin >> r >> d >> x;
    for(int i = 0; i < 10; ++i){
        x = r * x - d;
        cout << x << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 100005
#define INF 1e9
using namespace std;

typedef long long ll;

ll solve(ll s[], ll t[], int a, int b, ll n)
{
    int idx1 = lower_bound(s, s + a, n) - s, idx2;
    if(idx1 == a)
        idx1--;
    ll res1, res2;
    if(idx1 == 0){
        res1 = abs(s[idx1] - n);
        idx2 = lower_bound(t, t + b, s[idx1]) - t;
        if(idx2 == b)
            idx2--;
        if(idx2 == 0){
            res1 += abs(t[idx2] - s[idx1]);
            return res1;
        }
        else{
            ll temp1 = abs(t[idx2] - s[idx1]);
            ll temp2 = abs(t[idx2-1] - s[idx1]);
            res1 += min(temp1, temp2);
            return res1;
        }
    }
    else{
        //cout<<"I AM HERE"<<endl;
        res1 = abs(s[idx1] - n);
        res2 = abs(s[idx1-1] - n);
        idx2 = lower_bound(t, t + b, s[idx1]) - t;
        if(idx2 == b)
            idx2--;
        if(idx2 == 0){
            res1 += abs(t[idx2] - s[idx1]);
        }
        else{
            ll temp1 = abs(t[idx2] - s[idx1]);
            ll temp2 = abs(t[idx2-1] - s[idx1]);
            res1 += min(temp1, temp2);
        }
        idx2 = lower_bound(t, t + b, s[idx1-1]) - t;
        if(idx2 == b)
            idx2--;
        if(idx2 == 0){
            res2 += abs(t[idx2] - s[idx1-1]);
        }
        else{
            ll temp1 = abs(t[idx2] - s[idx1-1]);
            ll temp2 = abs(t[idx2-1] - s[idx1-1]);
            res2 += min(temp1, temp2);
        }
        return min(res1, res2);
    }
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int q, a, b;
    ll s[MAX], n, t[MAX];

    cin>>a>>b>>q;

    for(int i = 0; i < a; i++){
        cin>>s[i];
    }
    for(int j = 0; j < b; j++){
        cin>>t[j];
    }

    for(int i = 0; i < q; i++){
        cin>>n;
        ll ans1 = solve(s, t, a, b, n);
        ll ans2 = solve(t, s, b, a, n);
        cout<<min(ans1, ans2)<<endl;
    }

    return 0;
}

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

int main (int argc, char **argv) {
  int i = 1; // counter
  int x; // input

  while(cin >> x) {
    if (x == 0) break;
    cout << "Case " << i << ": " << x << endl;
    i++;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>

using namespace std;

void solve(int n, vector<int> a) {
    vector<bool> flag(8, false);
    int target = 0;
    int rating[] = {0, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200};
    for (int i = 0; i < n; i++) {
        if (a[i] >= rating[8]) {
            target += 1;
            continue;
        }
        for (int j = 0; j < 8; j++) {
            if (a[i] >= rating[j] && a[i] < rating[j+1]) {
                flag[j] = true;
                break;
            }
        }
    }
    int maxcolor = 0;
    int mincolor = 0;
    for (int i = 0; i < 8; i++) {
        if (flag[i] == true) {
            maxcolor += 1;
            mincolor += 1;
        }
    }
    if (target > 0) {
        maxcolor += target;
        if (mincolor == 0) {
            mincolor = 1;
        }
    }
    std::cout << mincolor << " " << maxcolor << std::endl;

}

int main() {
    struct timeval start,end;
    long long span;
    int n;

    gettimeofday(&start,NULL);

    std::cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    solve(n, a);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define max(a, b) a<b?b:a
#define min(a, b) a>b?b:a
#define INF 1010001000

int n;
int bef[100001], aft[100001];
char s[100001];

int main(void)
{
    int i, j, a, b;
    int max, min, sum = 0;
    char cod[100] = "CODEFESTIVAL2016";
    
    scanf("%s", s);

    for (i = 0; s[i] != '\0'; i++) {
        if (cod[i] != s[i]) {
            sum++;
        }
    }

    printf("%d\n",sum);




    return 0;
}







Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    private static long n;
    private static int result;

    private static void dfs(long x) {
        if (x > n) {
            return;
        }
        if (String.valueOf(x).contains("3")
                && String.valueOf(x).contains("5")
                && String.valueOf(x).contains("7")) {
            result++;
        }
        if (x <= 999999999) {
            dfs(10 * x + 3);
            dfs(10 * x + 5);
            dfs(10 * x + 7);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextLong();
        dfs(0);
        System.out.println(result);
    }

}


Measured memory_bytes: 28244
n,k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)

num1 = Array.new(2000,0)
for i in 1..a.size do
    num1[a[-i]-1] += 1
end

num2 = Array.new(2000,0)

for i in 1..1999 do
    num2[i] = num2[i-1] + num1[i-1]
end

num1 = Array.new(2000,0)
cnt = 0
for i in 1..a.size do
    # print "--",a[-i],"--\n"
    tar = a[-i]-1
    a0 = 0
    d = num2[tar]
    for j in 1..a[-i]-1 do
        a0 += num1[j-1]
    end
    cnt += a0*k + d*k*(k-1)/2
    # print "a0 = ",a0,"\n"
    # print "d = ", d,"\n"
    num1[a[-i]-1] += 1
    # p cnt
end

# p ""
p cnt % (10**9 +7)

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


int main(){
  int n;
  cin >> n;
  
  n %= 10;
  if(n == 3) cout << "bon" << endl;
  else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
  else cout << "hon" << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){int m,n,x,y,num[30],g[30][30];cin>>m>>n;rep(i,m){num[i]=0;rep(j,m)g[i][j]=0;}rep(i,n){cin>>x>>y;g[x][y]=1;num[y]++;}rep(i,m)rep(j,m){if(!num[j]){rep(k,m)num[k]-=g[j][k];num[j]--;cout<<j<<endl;break;}}}

Measured memory_bytes: 1164
A,B,C,D,E,F = map(int,input().split())

use_water = [] #使える水の量を100で割った値
for i in range(0,31):
  for j in range(0,31):
    tmp = A*i + B*j
    if((tmp != 0)and(tmp <= 30)): 
      if(tmp*100 <= F):
        use_water.append(tmp)
use_water = list(set(use_water))
use_water.sort()
#砂糖の入れ方は多く見積もってもせいぜい
#0,C,2C,...,100C
#D,C+D,...,100C+D
#...
#50D,C+50D,...,100C+50D
#-> 100*50 = 5000通り

Conc = [] #濃度格納用
for i in range(101):
  for j in range(51):
    for k in range(len(use_water)):
      sugar = C*i + D*j
      water = use_water[k]*100
      if(sugar + water <= F):
       if(sugar <= use_water[k]*E):
        #濃度
        #print('sugar:',sugar,'water:',water,'max_sugar:',use_water[k]*E)
        conc = sugar/(sugar + water)
        Conc.append([conc,water+sugar,sugar])

Conc.sort(reverse = True)
ans_water,ans_sugar = Conc[0][1],Conc[0][2]
print(ans_water,ans_sugar)

Measured memory_bytes: 9548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vi P(N), Q(N);
	rp(i,0,N) cin>>P[i];
	rp(i,0,N) cin>>Q[i];

	int ip=0;
	vi b(N);

	rp(i,0,N) b[i]=i+1;
	do{
		bool ok = true;
		rp(i,0,N){
			if(b[i]!=P[i]){
				ok=false;
				break;
			}
		}
		if(ok)break;
		ip++;
	}while(next_permutation(all(b)));

	int iq=0;
	rp(i,0,N) b[i]=i+1;
	do{
		bool ok = true;
		rp(i,0,N){
			if(b[i]!=Q[i]){
				ok=false;
				break;
			}
		}
		if(ok)break;
		iq++;
	}while(next_permutation(all(b)));

	// ote(ip);
	// ote(iq);
	ote(abs(ip-iq));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  ll N;
  cin >> N;
  vector<int> A(N);
  vector<int>  ans(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  for(int i = 0; i < N; i++){
    ans[A[i]-1] = i+1;
  }
  for(int i = 0; i < N; i++){
    cout << ans[i] << " ";
  }

  cout << endl;
  
}

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

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    int oddcnt=0;
    vector<ll> even;
    rep(i,n){
        cin>>a[i];
        if(a[i]%2==1) oddcnt++;
        else even.push_back(a[i]);
    }

    if(oddcnt==n){
        cout<<0<<"\n";
        return 0;
    }
    int cnt=0;
    
    for(auto x : even){
        while(x%2==0){
            x/=2;
            cnt++;
        }
    }

    cout<<cnt<<"\n";

    return 0;
}

Measured memory_bytes: 3840
#include<stdio.h>
#include<string.h>
int main(void){
  int alen,blen,clen;
  char a[11],b[11],c[11];
  scanf("%s %s %s",a,b,c);
  if(b[0] == a[(strlen(a)-1)] && c[0] == b[(strlen(b)-1)]) printf("YES");
  else printf("NO");
  return 0;
}

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

int main(){
    long k;
    long n;
    long result;
    cin >> n >> k;

    long mod;
    mod = n % k;
    if(abs(mod-k)<mod){
        result = abs(mod-k);
    }else if(abs(mod-k)>mod){
        result = mod;
    }else if(mod==0){
        result = 0;
    }
    cout << result << endl;

}

Measured memory_bytes: 256
#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 pb          push_back
#define ff          first
#define ss          second
#define ll          int64_t
#define ld          long double
#define mod         1000000007
#define mod2        998244353
#define inf         1000000000000007
#define pi          3.14159265358979323846
#define nl          cout<<"\n"
#define dbg(x)      cerr<<#x<<" = "<<x<<"\n"
#define all(v)      v.begin(),v.end()
#define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i)
#define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i)
#define fastio()    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

template<typename T,typename U> static inline void amin(T &x,U y)   {if(y<x)x=y;}
template<typename T,typename U> static inline void amax(T &x,U y)   {if(x<y)x=y;}  

ll lcm(ll a,ll b)       {return (a*b)/__gcd(a,b);} 
ll count_digits(ll n)   {ll dig=floor(log10(n)+1);return dig;}
ll mpow(ll x,ll y,ll p) {ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;} 
string dec_bin_32(ll n) {string s;for(ll i=31;i>=0;i--){ll k=n>>i;s+=(k&1)?'1':'0';}return s;} 
string dec_bin_64(ll n) {string s;for(ll i=63;i>=0;i--){ll k=n>>i;s+=(k&1)?'1':'0';}return s;} 
ll mod_inv(ll a,ll m)   {ll m0=m,y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;} 

//-------------------------------L_I_Erq34-------------------------------

ll dp[100007];

int main()
{
	fastio();
	ll z,n,m,t,k,i,j,l,d,h,r;
	cin>>n>>k;
	pair<ll,ll> a[n];
	forn(i,0,n)
		cin>>a[i].ff>>a[i].ss;
	forn(i,0,n)
		forb(j,k,a[i].ff)
			dp[j]=max(dp[j-a[i].ff]+a[i].ss,dp[j]);
	z=0;
	forn(i,0,k+1)
		z=max(z,dp[i]);
	cout<<z<<"\n";
	cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
	return 0;
}


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

int main() {
  int a,b;
  cin >> a >>  b;
  int ave = a+b;
  if(ave == 0) cout << 0 << endl;
  else if(ave % 2 == 0)cout << ave/2 << endl;
  else cout << ave /2 +1 << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0

for i in range(2**n):
    status = ['+']*n
    for j in range(n):
        if ((i>>j)&1):
            status[j] = '-'
    num = 0
    for m, k in enumerate(s):
        count = 0
        for l in k:
            if status[l-1] == '+':
                count += 1
        if count%2 != p[m]:
            break
        else:
            num += 1
    if num == m+1:
        ans += 1
print(ans)


Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

const int INF=1001001001;

int main() {
  int K;
  cin>>K;
  int x=7;
  for(int i=0;i<=K;i++){
    x%=K;
    if(x==0){cout<<i+1<<endl;return 0;}
    x*=10;
    
    x+=7;
    
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

ld dp[310][310][310];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin >> n;
    ll ia = 0;
    ll ja = 0;
    ll ka = 0;
    for (int z=0;z<n;z++){
        ll temp;
        cin >> temp;
        if (temp == 1) ia++;
        if (temp == 2) ja++;
        if (temp == 3) ka++;
    }
    for (int i=0;i<=n;i++){
        for (int j=0;j<=n;j++){
            for (int k=0;k<=n;k++){
                dp[i][j][k] = 0;
            }
        }
    }   
    for (int k=0;k<=n;k++){
        for (int j=0;j<=n;j++){
            for (int i=0;i<=n;i++){
                if (i+j+k == 0) continue;
                ld p = ld(i+j+k)/ld(n);
                dp[i][j][k]++;
                // rolled on 3
                if (j < n && k > 0){
                    dp[i][j][k] += dp[i][j+1][k-1]*ld(k)/ld(n);
                }
                // rolled on 2
                if (i < n && j > 0){
                    dp[i][j][k] += dp[i+1][j-1][k]*ld(j)/ld(n);
                }
                // rolled on 1
                if (i > 0){
                    dp[i][j][k] += dp[i-1][j][k]*ld(i)/ld(n);
                }
                dp[i][j][k] /= p;
                
            }
        }
    }
    ld ans = 0;
    cout << fixed << setprecision(60) << dp[ia][ja][ka] << endl;
}

Measured memory_bytes: 452864
#include <bits/stdc++.h>
#define lli long long int
using namespace std;


int main()
{
	lli n, m, val, b, c;
	
	cin >> n >> m;
	
	map<lli, lli> mp;
	
	for(int i = 0; i < n; i++){
		cin >> val;
		mp[val]++;
	}
	
	while(m--){
		cin >> b >> c;
		mp[c] += b;
	}
	
	vector< pair<lli, lli> > v;
	
	for(auto it = mp.begin(); it != mp.end(); it++){
		v.push_back({it->first, it->second});
	}
	
	sort(v.begin(), v.end());
	
	lli l = v.size(), sz;
	
	lli sum = 0;
	
	for(int i = l-1; i >= 0; i--){
		if(n == 0) break;
		
		val = v[i].first;
		sz = v[i].second;
		
		if(n >= sz){
			n -= sz;
			sum += (val * sz);
		}
		else{
			sum += (val * n);
			n = 0;
		}
	}
	
	cout << sum << "\n";
	
	return 0;
}


Measured memory_bytes: 18800
N = int(input())
 
li = [list(map(int,input().split())) for _ in range(N)]

k = 0
while li[k][2] == 0:
    k += 1
 
for x in range(101):
    for y in range(101):

        H = li[k][2]+abs(li[k][0]-x)+abs(li[k][1]-y)
        f = True

        for i in range(N):
            if li[i][2] > 0 and H != li[i][2]+abs(li[i][0]-x)+abs(li[i][1]-y):
                f = False
                break
            # 下2行を書き忘れていた
            elif li[i][2] == 0 and H > abs(li[i][0]-x)+abs(li[i][1]-y):
                f = False
                break
        if f == 1:
            print(x,y,H)
            break
    else:
        continue
    break
 

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

// const long long INF = 1LL << 60;

ll n, m, l;

template <typename T>
struct Edge {
  int to;
  T cost;
};

// Dijkstra
template <typename T>
class Dijkstra {
 private:
  vector<vector<Edge<T>>> G;
  int num_v;

 public:
  Dijkstra(int num_v) : G(num_v), num_v(num_v) {
  }

  void add_edge(int from, int to, T cost) {
    G[from].push_back((Edge<T>){to, cost});
  }

  // start: Start point
  // result: result
  void solve(int start, vector<T>& result) {
    vector<int> tmp;
    solve(start, result, tmp);
  }

  void solve(int start, vector<T>& result, vector<int>& prev) {
    result.resize(num_v, make_pair(INF, INF));
    prev.resize(num_v, -1);

    // get<0>(T): cost
    // get<1>(T): index
    // get<2>(T): ... ( for extent)
    using Tup = tuple<T, int>;
    priority_queue<Tup, vector<Tup>, greater<Tup>> que;

    que.emplace(make_pair(0ll, 0ll), start);
    result[start] = make_pair(0ll, 0ll);

    while (!que.empty()) {
      Tup p = que.top();
      que.pop();

      T t = get<0>(p);
      int v = get<1>(p);

      if (result[v] != t) {
        continue;
      }

      // vの各辺に対しよりコストの低い経路があるかを確認
      for (auto& e : G[v]) {
        auto pr = result[v];
        pr.second += e.cost.second;
        if (pr.second > l) {
          pr.first++;
          pr.second = e.cost.second;
        }
        if (result[e.to] > pr) {
          prev[e.to] = v;
          result[e.to] = pr;
          que.emplace(pr, e.to);
        }
      }
    }
  }

  // t: 目的地
  vector<int> get_path(const vector<int>& prev, int t) {
    vector<int> path;

    for (int v = t; v != -1; v = prev[v]) {
      path.push_back(v);
    }

    reverse(path.begin(), path.end());
    return path;
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  cin >> n >> m >> l;

  Dijkstra<P> g(n + 1);

  rep(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    if (c <= l) {
      auto p = make_pair(0ll, c);
      g.add_edge(a, b, p);
      g.add_edge(b, a, p);
    }
  }

  vector<vector<P>> ans(n + 1);
  REP(i, n + 1) {
    g.solve(i, ans[i]);
  }

  ll q;
  cin >> q;
  rep(i, q) {
    ll s, t;
    cin >> s >> t;
    ll v = ans[s][t].first;
    if (v == INF) {
      v = -1;
    }
    cout << v << endl;
  }

  return 0;
}


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

public class Main {


    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int n = Integer.parseInt(str);
        if( 0 <= n && n <= 86400 ){
            int a = n / 3600;
            int b = (n % 3600) / 60;
            int c = (n % 3600) % 60;
            System.out.println(a + ":" + b + ":" + c);
        }
    }
}

Measured memory_bytes: 24440
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<fstream>
#include <stdio.h>
#include <string.h>
#include<queue>
using namespace std;
 
void winter_is_coming()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL );
}
 
int main()
{
    //freopen(".in", "r", stdin); //fclose (stdout);
	winter_is_coming();
  
	int a,b;
	cin>>a>>b;
	if((a*b)%2==0) cout<<"Even\n";
	else           cout<<"Odd\n";
 
   // system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int x, a, b;
  scanf("%d%d%d", &x, &a, &b);
  if(b<=x)
    printf("delicious\n");
  else if(x+a>=b)
    printf("safe\n");
  else
    printf("dangerous\n");

  return 0;
}


Measured memory_bytes: 128
if __FILE__==$0
	r_s=lambda{|str|str.strip}
	a=r_s[gets].split("")
	b=r_s[gets].split("")
	c=Array.new(a.length+b.length){""}
	for i in 0..a.length-1
		c[i*2]=a[i]
	end
	for i in 0..b.length-1
		c[i*2+1]=b[i]
	end
	#aattccooddeerrbreeggiunlnaerrccoonntteesstt
	#aattccooddeerrbreeggiunlnaerrccoonntteesstt
	puts c.join("")
end

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

int main()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<n;i++)
    {
        if(n%i==0)
        {
            ans+=n/i-1;
        }
        else
        {
            ans+=n/i;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int bubbleSort(int A[],int N){
  int sw =0;
  bool flag =1;
  for(int i=0;flag;i++){
    flag =0;
    for(int j = N-1;j >= i+1 ;j--){
      if(A[j] < A[j-1]){
	swap(A[j],A[j-1]);
	flag = 1;
	sw++;
      }
    }
  }
  return sw;
} 

int main(){
  int A[100], N, sw;
  cin >> N;
  for(int i=0;i<N;i++) cin >> A[i];

  sw = bubbleSort(A,N);

  for(int i=0;i<N;i++){
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}



Measured memory_bytes: 3096
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        String b = scan.next();
        char[] c = b.toCharArray();
        int d=0;
        int e=0;//100
        int f=0;//10
        int g=0;//1
        int ans=0;
        int cou=0;
        for(int l=0;l<1000;l++){
            d=g;
            loop : for(int i=0;i<a;i++){
                if(d==(int)c[i]-48){
                    switch(cou){
                        case 0:d=f;cou++;break;
                        case 1:d=e;cou++;break;
                        case 2:ans++;break loop;
                    }
                }
            }
            cou=0;
            g++;
            if(g==10){
                g=0;
                f++;
                if(f==10){
                    f=0;
                    e++;
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 2*(int)1e5 + 10;

int n, k;
vector<int> a;

#define ll int
ll power(ll a, ll b, ll m = mod){if(b < 0)b += m-1; ll r = 1; while(b){if(b&1)r=(r*a)%m; a = (a*a)%m; b>>=1;}return r;}

int fact[N+10], ifact[N+10];
void pre(int N){
   fact[0] = 1;
   for (int i = 1; i <= N; ++i)
   {
      fact[i] = (i*fact[i-1])%mod;
   }
   ifact[N] = power(fact[N], -1);
   for (int i = N-1; i >= 0; --i)
   {
      ifact[i] = ((i+1)*ifact[i+1])%mod;
   }
}

int nCr(int n, int r){
   if(n < r)return 0;
   if(n < 0 or r < 0)
      return 0;
   return ((fact[n]*ifact[r])%mod * ifact[n-r])%mod;
}

int32_t main(){_
   
   cin>>n>>k;
   a.resize(n+1);

   pre(N);

   for (int i = 1; i <= n; ++i)
   {
      cin>>a[i];
   }

   sort(a.begin()+1, a.end());

   int sumneg = 0, sumpos = 0;;
   for (int i = 1; i <= n; ++i)
   {
      sumneg += a[i] *  nCr(n-i, k-1) % mod;
      sumneg %= mod; 
      sumneg += mod;
      sumneg %= mod; 
   }
   
   for (int i = n; i >= 1; --i)
   {
      sumpos += a[i] *  nCr(i-1, k-1) % mod;
      sumpos %= mod; 
      sumpos += mod;
      sumpos %= mod; 
   }

   int ans = (sumpos - sumneg + mod) % mod;

   assert(ans >= 0);
   cout<<ans;

   return 0;
}


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

string input;

bool isPa(int l, int r) {
    while (l < r) {
        if (input[l] == input[r]) {
            l++;
            r--;
        } else {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> input;
    int len = input.length();
    if (isPa(0, len - 1) && isPa(0, (len - 3) / 2) && isPa((len + 1) / 2, len - 1)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 256
n,m=map(int,input().split())
pos1=[list(map(int,input().split())) for _ in range(n)]
pos2=[list(map(int,input().split())) for _ in range(m)]
ans=[0]*n
for i in range(n):
  lim=10**9
  for j in range(m):
    tmp=abs(pos1[i][0]-pos2[j][0])+abs(pos1[i][1]-pos2[j][1])
    if tmp<lim:
      lim=tmp
      ans[i]=j+1
for i in range(n):
  print(ans[i])

Measured memory_bytes: 3064