akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef std::vector<ll> lls;

void cinv(lls& llVec, ll n) {
	ll val;
	llVec.reserve((size_t)(n));
	for (ll i = 0; i < n; i++) {
		cin >> val;
		llVec.push_back(val);
	}
}

struct Edge {
	ll to;     // 辺の行き先
	ll weight; // 辺の重み
	Edge(ll t, ll w) : to(t), weight(w) { }
};
using Graph = std::vector<std::vector<Edge>>;


void dfs(Graph &G, std::vector<int> &seen, ll v) {

	for (auto &edge: G[v]){
		ll to = edge.to;
		ll weight = edge.weight;
		if (seen[to] != -1) continue;

		if (weight % 2 == 0) seen[to] = seen[v];
		else                 seen[to] = 1 - seen[v];
		dfs(G, seen, to);
	}
}


int main()
{
	ll N;
	cin >> N;
	Graph G(N);
	std::vector<int> seen(N, -1); //-1:未処理、0:白、1:黒

	ll edgeNum;
	edgeNum = N - 1;
	for (ll i = 0; i < edgeNum; i++) {
		ll from, to, weight;
		cin >> from >> to >> weight;
		from--;
		to--;
		G[from].push_back(Edge(to,   weight));
		G[to  ].push_back(Edge(from, weight));
	}

	seen[0] = 0;
	dfs(G, seen, 0);

	for (auto i : seen) {
		cout << i << '\n';
	}

	return 0;
}



Measured memory_bytes: 10496
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""

input:
5 4
0 1
1 2
2 3
3 4

output:
1
2
3
"""

import sys

sys.setrecursionlimit(int(1e6))


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        source, target = map(int, v_detail)
        init_adj_table[source].append(target)
        init_adj_table[target].append(source)
    return init_adj_table


def Tarjan(current, parents, visited, disc, low):
    global timer
    current_children_count = 0
    visited[current] = True
    disc[current] = low[current] = timer
    timer += 1

    for adj in adj_table[current]:
        if not visited[adj]:
            parents[adj] = current
            current_children_count += 1

            Tarjan(adj, parents, visited, disc, low)

            low[current] = min(low[current], low[adj])
            # current is root of DFS tree
            if parents[current] == -1 and current_children_count > 1:
                art_set.add(current)
            elif parents[current] != -1 and low[adj] >= disc[current]:
                art_set.add(current)

        elif adj != parents[current]:
            low[current] = min(low[current], disc[adj])

    return None


def art_points():
    parents = [-1] * vertices
    visited = [False] * vertices
    disc = [float('inf')] * vertices
    low = [float('inf')] * vertices

    for v in range(vertices):
        if not visited[v]:
            Tarjan(v, parents, visited, disc, low)

    return art_set


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])
    init_adj_table = tuple([] for _ in range(vertices))
    adj_table = generate_adj_table(v_info)

    timer = 0
    art_set = set()

    ans = art_points()
    if ans:
        print(*sorted(ans), sep='\n')

Measured memory_bytes: 23836
#include <iostream>
using namespace std;
int main(){
  int N,K;
  bool p = 0;
  cin>>N>>K;
  if(N%2 == 0){
    if(N>=2*K){
      p = 0;
    }
    else{
      p = 1;
    }
  }
  else{
    if(N+1>=2*K){
      p = 0;
    }
    else{
      p = 1;
    }
  }
  if(p == 0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
cost = []
yen = []
for i in range(N):
    n, a = input().split()
    cost.append(float(n))
    yen.append(a)
ans = 0
for i in range(N):
    if yen[i] == "JPY":
        ans += cost[i]
    else:
        ans += cost[i] * 380000
print(ans)

Measured memory_bytes: 9004
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		InputStream is = System.in;
		solve(is);
	}

	private static void solve(InputStream is) {
		try (Scanner cin = new Scanner(is)) {
			int n = cin.nextInt();
			int[] a = new int[n];
			int[] b = new int[n];

			for (int i = 0; i < n; i++) {
				a[i] = cin.nextInt();
			}
			for (int i = 0; i < n; i++) {
				b[i] = cin.nextInt();
			}

			int ans = 0;
			int candy = 0;

			for (int x = 0; x < n; x++) {
				for (int i = 0; i <= x; i++) {
					candy += a[i];
				}
				for (int i = x; i < n; i++) {
					candy += b[i];
				}
				ans = ans > candy ? ans : candy;
				candy = 0;
			}

			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 23892
H,W = [int(i) for i in input().split(" ")]

def divide_h(h,w):
    mindiff = 1e12
    for x in range(1,h):
        rem_h = h - x
        s_A = x*w

        #vertical
        w1 = w//2
        s_B = w1*rem_h
        s_C = (w-w1)*rem_h

        tmp = max(s_A,s_C) - min(s_A,s_B)

        if mindiff > tmp:
            mindiff = tmp

        #horizontal
        h1 = rem_h // 2
        s_B = w * h1
        s_C = w * (rem_h - h1)
        tmp = max(s_A,s_C) - min(s_A, s_B)

        if mindiff > tmp:
            mindiff = tmp

    return mindiff

a1 = divide_h(W,H)
a2 = divide_h(H,W)

print(min(a1,a2))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000009
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<string> v;
	for(int i=0;i<n;i++){
		string tmp;
		cin>>tmp;
		sort(tmp.begin(),tmp.end());
		v.pb(tmp);
	}
	ll cur = 1;
	string cst;
	sort(v.begin(),v.end());
	cst = v[0];
	ll ans = 0;
	for(int i=1;i<n;i++){
		if(v[i-1] == v[i]){
			cur++;
		}
		else{
			ans += cur * (cur - 1) / 2;
			cur = 1;
		}
	}
	ans += cur * (cur - 1) / 2;
	cout<<ans<<endl;
	return 0;
}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
char st[22][22];

int dis[22][22];

vector<ii> moves = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};

int h, w;

int solve(int X, int Y) {
  memset(dis, -1, sizeof dis);
  queue<ii> q;
  q.push({X, Y});
  dis[X][Y] = 0;
  while(!q.empty()) {
    auto f = q.front();
    int x = f.fi, y = f.se;
    q.pop();
    for(auto m: moves) {
      int xx = x + m.fi, yy = y + m.se;
      if(xx<0 || yy<0 || xx>=h || yy >= w) {
        continue;
      }
      if(dis[xx][yy] != -1 || st[xx][yy] == '#') {
        continue;
      }
      else {
        dis[xx][yy] = dis[x][y] + 1;
        q.push({xx, yy});
      }
    }
  }
  int f = 0;
  rep(i,0,h) {
    rep(j,0,w) {
      f = max(f, dis[i][j]);
    }
  }
  return f;
}


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  cin>>h>>w;
  rep(i,0,h) {
    rep(j,0,w) cin>>st[i][j];
  }
  int ans = 0;
  rep(i,0,h) {
    rep(j,0,w) {
      if(st[i][j] == '.')
      ans = max(ans, solve(i,j));
    }
  }
  cout<<ans<<endl;
}



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

struct LazySegmentTree{
    private:
        int n;
        vector<int> node, lazy;
        vector<bool> lazyFlag;
    
    public:
        LazySegmentTree(vector<int> v){
            int sz = (int)v.size();
            n = 1; while(n < sz) n*= 2;
            node.resize(2 * n - 1);
            lazy.resize(2 * n - 1, INT_MAX);
            lazyFlag.resize(2 * n - 1, false);

            for(int i = 0; i < sz; i++) node[i+n-1] = v[i];
            for(int i = n - 2; i >= 0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
        }

        void lazyEvaluate(int k, int l, int r){
            if(lazyFlag[k]){
                node[k] = lazy[k];
                if(r - l > 1){
                    lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                    lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
                }
                lazyFlag[k] = false;
            }
        }
        void update(int a, int b, int x, int k = 0, int l = 0, int r = -1){
            if(r < 0) r = n;
            lazyEvaluate(k, l, r);
            if(b <= l || r <= a) return;
            if(a <= l && r <= b){
                lazy[k] = x;
                lazyFlag[k] = true;
                lazyEvaluate(k, l, r);
            }
            else{
                update(a, b, x, 2 * k + 1, l, (l + r) / 2);
                update(a, b, x, 2 * k + 2, (l + r) / 2, r);
                node[k] = min(node[2*k+1], node[2*k+2]);
            }
        }

        int find(int a, int b, int k = 0, int l = 0, int r = -1){
            if(r < 0) r = n;
            lazyEvaluate(k, l, r);
            if(b <= l || r <= a) return INT_MAX;
            if(a <= l && r <= b) return node[k];
            int vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
            int vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
};

int main(){
    int n, q; cin >> n >> q;
    LazySegmentTree seg(vector<int>(n, INT_MAX));
    while(q--){
        int query; cin >> query;
        if(query == 0){
            int s,t,x; cin >> s >> t >> x;
            seg.update(s, t + 1, x);
        }else{
            int s,t; cin >> s >> t;
            cout << seg.find(s, t + 1) << endl;
        }
    }
}


Measured memory_bytes: 5224
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main() {

    fast

    string s;
    cin>>s;

    int n=s.size();
    string target="keyence";
    int len=7;
    int j=0;
    	if(s == target){
		puts("YES");
		return 0;
	}
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
                string S="";


            for(int k=0;k<n;k++){
                if(k>=i && k<=j)continue;

                    else S.push_back(s[k]);

                }



            if(S == target){
                puts("YES");
                return 0;
                }

    }
    }
    puts("NO");





	return 0;
}


/*
ll  modularExponentiation(ll x,ll n,ll M)
{

    ll result=1;

    while(n>0)
    {

	if(n%2==1)

 result=(result*x)%M;

  x=(x*x)%M;

  n=n/2;

}

  return result;
}



*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	for(int i=1;i<=5;i++){
		int x;
		cin>>x;
		if(x==0){
			cout<<i;
			return 0;
		}
	}
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using lint=long long;
void debug_impl(){std::cerr<<'\n';}
template<class Head,class...Tail>void debug_impl(Head head, Tail... tail){std::cerr << " " << head;debug_impl(tail...);}
    template<class Container,class Value=typename Container::value_type,std::enable_if_t<!std::is_same<Container,std::string>::value,std::nullptr_t> = nullptr>
std::ostream&operator<<(std::ostream&os,Container const&v)
{os<<"{";for(auto it=v.begin();it!=v.end();it++){os<<(it!=v.begin()?",":"")<<*it;}return os<<"}";}
    template<template<class...>class Tuple,class...Args,std::size_t...Inds,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&tuple_output_impl(std::ostream&os,const Tuple<Args...>&tuple,std::integer_sequence<std::size_t,Inds...>)
{os<<"(";(void)std::initializer_list<int>{((void)(os<<(Inds>0?",":"")<<std::get<Inds>(tuple)),0)...};return os<<")";}
    template<template<class...>class Tuple,class...Args,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&operator<<(std::ostream&os,const Tuple<Args...>&tuple)
{return tuple_output_impl(os,tuple,std::index_sequence_for<Args...>());}
#define DEBUG 1
#if DEBUG
#define debug(...)do{std::cerr<<std::boolalpha<<"["<<#__VA_ARGS__<<"]:";debug_impl(__VA_ARGS__);std::cerr<<std::noboolalpha;}while(false)
#else
#define debug(...) {}
#endif
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,k;std::cin>>n>>k;
    lint ans=0;
    for(lint b=k+1;b<=n;b++){
        ans+=n/b*(b-k)+std::max(0ll,n%b-k+1);
        ans-=(k==0);
    }
    std::cout<<ans<<'\n';
}
/*
 * b (>k) を決め打ちです。
 * a=qb+r の q で、余りがなんでもよいものは、
 * qb+b-1<=n ですから、q<=(n-b+1)/b となり、(n-b+1)/b+1 = (n+1)/b 個です。
 * とくに、0..n/b-1 の n/b 個は大丈夫です。
 * n/b は途中までで、n/b+1 は既に超えていますから、見る必要がありません。　
 * q=n/b とすると、r<=n-qb=n-n/b*b=n%b となり、max(0,n%b-k+1) です。
 * k=0 のとき、(b,0) が毎回入りますから、引きましょう。
 */


Measured memory_bytes: 256
import random

def Magic2():
    
    num = list(map(int,input().split()))

    count = int(input())

    for i in range(count):
        if num[0] >= num[1]:
            num[1] = 2*num[1]
            
        elif num[1] >= num[2]:
            num[2] = 2*num[2]
        
        else:
            num[2] = 2*num[2]
            
        
    if num[0] < num[1] and num[1] < num[2]:
        print('Yes')
        
    else:
        print('No')
        

if __name__ == '__main__':
    Magic2()




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

int main() {
  int N, X;
  cin >> N;
  if (N % 2 == 1) {
    X = N / 2 + 1;
  }
  
  else {
    X = N / 2;
  }
  
  cout << X << endl;

  
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std; 

int n,w;
vector <pii> v;
map <pii,int> mp;

int fun(int i,int j){
    if (j>w) return -10000000000LL;
    if (i==n) return 0;
    if (mp.count({i,j})) return mp[{i,j}];
    return mp[{i,j}] = max(fun(i+1,j),fun(i+1,j+v[i].ff)+v[i].ss);
}

inline void solve(){
    cin>>n>>w; 
    v.resize(n);
    for (int i=0;i<n;i++){
        int a,b; cin>>a>>b;
        v[i].ff=a;
        v[i].ss=b;
    }
    cout << fun(0,0) << endl; 
}

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


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

const long long MOD = (long long) 1e9 + 7;

long long modpow(long long b, long long p) {
  if (p == 0) {
    return 1;
  }
  long long ans = modpow(b * b % MOD, p / 2);
  if (p % 2 == 1) {
    ans = (ans * b) % MOD;
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<long long> dp(k + 1);
  for (int i = k; i >= 1; i--) {
    dp[i] = modpow(k / i, n);
    for (int j = 2 * i; j <= k; j += i) {
      dp[i] = ((dp[i] - dp[j]) % MOD + MOD) % MOD;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= k; i++) {
    ans = (ans + i * dp[i]) % MOD;
  }
  cout << ans << '\n';
  return 0;
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int N;
    cin >> N;

    vector<string> W(N);
    rep(i,N) cin >> W[i];

    set<string> used;
    used.insert(W[0]);
    char last_ward = W[0][W[0].size()-1];

    REP(i, 1, N)
    {
        if( last_ward != W[i][0] )
        {
            cout << "No" << endl;
            return 0;
        }
        else if( used.find(W[i]) != used.end() )
        {
            cout << "No" << endl;
            return 0;
        }

        last_ward = W[i][W[i].size()-1];
        used.insert(W[i]);
    }
    cout << "Yes" << endl;

}


Measured memory_bytes: 256
h,w = map(int,input().split())
s=[]
for _ in range(h):
    s.append(list(input()))
for i in range(h):
    for j in range(w):
        if s[i][j]!="#":
            cnt = 0
            for k in range(-1,2):
                for l in range(-1,2):
                    if 0<=i+k<h and 0<=j+l<w and s[i+k][j+l]=="#":
                        cnt += 1
            s[i][j]=str(cnt)
for ss in s:
    print("".join(ss))


Measured memory_bytes: 3188
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Majk
 */

#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
#include <queue>
using namespace std;

#define x first
#define y second
constexpr int MOD = 1000000007;

typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned int ui;

template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

namespace std {
    template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

// #include "../l/mod.h"

class C {
public:
	void solve(istream& cin, ostream& cout) {
		int X; cin >> X;
		cout << bsl(0, 50000, [&](int a) { return (ll)a*(a+1)/2 >= X; }) << endl;
	}
};


int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	C solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

char S[50];
int N;
int K;

int main() {
    cin >> N >> K;
    cin >> S;
    for (int i = 0; i < N; i++) {
        if (S[i] != 'A' && S[i] != 'B' && S[i] != 'C') {
            return 0;
        }
    }
    for (int i = 0; i < N; i++) {
        if (i == (K - 1)) {
            putchar(tolower(S[i]));
        }
        else {
            cout << S[i];
        }
    }
}


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

int main(){
	int N;
	cin >> N;
	vector<int> Ass(N);
	
	for(int i = 0;i<N;i++){
		cin >> Ass.at(i);
	}
	
	int Alice = 0;
	int Bob = 0;
	int DBAB = 0;
	
	for(int j = 0;j<N;j++){
		int MXP = 0;
		int MXK = 0;
		
		for(int k = 0;k<N;k++){
			int c = Ass.at(k);
			
			if(c>MXP){
				MXP = c;
				MXK = k;
			}
		}
		
		Ass.at(MXK) = -1;
		
		if(j%2==0)
			Alice = Alice + MXP;
		else
			Bob = Bob + MXP;
	}
	
	DBAB = Alice - Bob;
	
	cout << DBAB << endl;
}

Measured memory_bytes: 256
import sys

N,M = map(int, input().split())

tmp1 = 0
tmp2 = float('inf')
val = [[] for i in range(M)]
ans = 0
for i in range(M):
    L,R = map(int, input().split())
    val[i].append(L)
    val[i].append(R)
    if R < tmp1:
        print(ans)
        sys.exit()
    if L > tmp1:
        tmp1 = L
    if R < tmp2:
        tmp2 = R
if tmp2-tmp1+1 < 0:
    print(0)
else:
    print(tmp2-tmp1+1)

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

int main() {
	int x,a,b;
	cin >> x >> a >> b;
	string k = "A";
	int n,m;
	if(x > a)
	{
		n = x - a;
	}
	else
	{
		n = a - x;
	}
	if(x > b)
	{
		m = x - b;
	}
	else
	{
		m = b - x;
	}
	if(m < n)
	{
		k = "B";
	}
    cout << k << endl;
	return 0;
}


Measured memory_bytes: 256
a = list(input().split(" "))
animal = int(a[0])
foot = int(a[1])
 
saisyo = 2 * animal
saidai = 4 * animal
 
if (foot % 2 == 0) and (saisyo <= foot <= saidai):
	print("Yes")
else:
    print("No")

Measured memory_bytes: 9176
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
k = INT()
ans = 0
a = 0
b = 0
if s[0] == s[-1]:
    if len(set(s)) == 1:
        ans = len(s) * k // 2
        print(ans)
        exit()
    for j in range(len(s)):
        if s[0] == s[j]:
            a += 1
        else:
            break
    for j in reversed(range(len(s))):
        if s[-1] == s[j]:
            b += 1
        else:
            break
    ans = a // 2 + b // 2 + (a + b) // 2 * (k - 1)
i = a
ans2 = 0
while i < len(s) - b:
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    i += tmp
    tmp //= 2
    ans2 += tmp
print(ans + ans2 * k)

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int a,b; cin>>a>>b;
  if (a%3==0) out("Possible");
  if (b%3==0) out("Possible");
  a += b;
  if (a%3==0) out("Possible");
  out("Impossible");
  

  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

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

template<typename T>
vector<T> smallest_prime_factors(T n) {

    vector<T> spf(n + 1);
    for (int i = 0; i <= n; i++) spf[i] = i;


    for (T i = 2; i * i <= n; i++) {

        // 素数だったら
        if (spf[i] == i) {

            for (T j = i * i; j <= n; j += i) {

                // iを持つ整数かつまだ素数が決まっていないなら
                if (spf[j] == j) {
                    spf[j] = i;
                }
            }
        }
    }

    return spf;
}

template<typename T>
map<T, T> factolization(T x, vector<T> &spf) {
    map<T, T> ret;
    while (x != 1) {
        ret[spf[x]] += 1;
        x /= spf[x];
    }
    return ret;
}

int main() {
  
  constexpr int MAX = 1000010;

  auto spf = smallest_prime_factors(MAX);

  int n;cin >> n;
  int ans = 0;
  n--;
  while (n > 1) {
    auto result = factolization(n, spf);
    int ans_temp = 1;
    for (auto z = result.begin();  z!=result.end(); z++){
      ans_temp *= (z->second+1);
    }
    ans += ans_temp;
    n--;
  }
  cout << ans + 1 << endl;
}

Measured memory_bytes: 7036
(defun c2 ()
  (let* ((n (read))
         (l (loop for i below n collect (read)))
         (ll (loop for x in l collect x))
         (sl))
    (setf sl (sort ll #'>))
    (dolist (x l)
      (format t "~a~%"
              (if (= x (first sl))
                  (second sl)
                  (first sl))))))
(c2)

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

int main() {
	// your code goes here
	
	int n; cin>>n; int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int cnt=0;
	int max=-1;
	for( int i=1; i<n; i++){
      if(h[i-1]>=h[i]){
        cnt++;
      }
      else{
        if(max<=cnt){
          max=cnt;
        }
        cnt=0;
      }
    }
    if(max <= cnt){
      max = cnt;
    }
	cout<<max;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <stack>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
const int mxn = 1e6+10;
int l[mxn];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int n; cin>>n;
	for(int i=1; i<=2*n; i++) cin>>l[i];
	sort(l+1, l+2*n+1);

	int sum = 0;
	for(int i=1; i<=2*n; i+=2) {
		sum+=min(l[i], l[i+1]);
	}

	cout << sum <<'\n';




	return 0;
}
//comparator function in sorting
//swapping arguments
//missing cases in dp
//dividing in modulo
//Beware of overflow and modulo
//Be mindful of overflow
//s is a matrix but forget
//length of ranges
//working with bit using ull

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int N,M,A;
   cin >> N >> M;
   for (int i=0;i<M;i++) {
       cin >> A;
       N-=A;
   }
   if(N<0) {
       cout << -1 << endl;
   }
   else {
       cout << N << endl;
   }
    
}


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

const int lim=60*12;

int main(){
	int n;
	scanf(" %d", &n);
	for(int i=0; i<n;++i){
		int h, m;
		scanf(" %d:%d", &h, &m);
		
		//printf("h=%d,m=%d\n", h, m);
		
		int now=h*60+m;
		
		double arg1=(double)now/(double)lim*360;
		double arg2=m*6;
		
		double arg=fabs(arg1-arg2);
		if(arg>180) arg=360-arg;
		
		if(arg<30) printf("alert\n");
		else if(arg<90) printf("warning\n");
		else if(arg<=180) printf("safe\n");
	}
	return 0;
}

Measured memory_bytes: 1164
#include <cstdio>
#define MOD 1000000007
typedef long long LL;

int s;
LL dp[2010];

int main() {
    scanf("%d", &s);
    dp[0] = 1;
    for (int i = 1 ; i <= s ; i++) {
        for (int j = 3 ; j <= s ; j++) {
            if (i - j < 0) break;
            dp[i] += dp[i - j];
            dp[i] %= MOD;
        }
    }
    printf("%lld", dp[s]);
}


Measured memory_bytes: 1744
class NormalInput{
  input: string[];
  pointer: number;
  constructor(raw:string){
    this.input=raw.split(/ |\n/);
    this.pointer=0;
  }
  int():number{
    const ret= parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }  
  ints(length:number):number[]{
    let ret:number[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.int());
    }
    return ret;
  }
  str():string{
    const ret= this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs(length:number):string[]{
    let ret:string[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.str());
    }
    return ret;
  }
}
function Main(_: NormalInput) {
  const N=_.int();
  const p=_.ints(N);
  let count=0;
  for(let i=0;i<N;i++){
    if(p[i]!==i+1)count++;
  }
  console.log((count<=2)?"YES":"NO")
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
S = list(input().split()[0])

flg = False

if S[0] == S[1] and S[1] == S[2] and S[2] == S[3]:
    flg = True

S_0 = S[0]
del S[0]
for i in range(0,3):
    if S[i] == S_0:
        del S[i]
        break
S_1 = S[0]
del S[0]
if S[0] == S_1:
    del S[0]
if not flg:
    if len(S) == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll k = 0, m = 1000;
  rep(i, n - 1) {
    if(k == 0) {
      if(a[i] < a[i + 1]) {
        k += m / a[i];
        m %= a[i];
      }
    } else {
      if(a[i] > a[i + 1]) {
        m += k * a[i];
        k = 0;
      }
    }
  }
  m += k * a[n - 1];
  cout << m << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n;
    cin >> n;
    ll a[n], offset = 0;
    rep (i, n) {
        cin >> a[i];
        a[i] *= 2;
    }
    rep (i, n) offset = a[i] - offset;
    offset /= 2;
    rep (i, n) {
        cout << offset << " ";
        offset = a[i] - offset;
    }
    cout << "\n";
}


Measured memory_bytes: 2048
from collections import deque

N = int(input())
Sss = [input() for _ in range(N)]

adjL = [[] for _ in range(N)]
for i, Ss in enumerate(Sss):
    for j, S in enumerate(Ss):
        if S == '1':
            adjL[i].append(j)

def IsBipartiteGraph(adjList):
    def bfs(vSt):
        colors[vSt] = 1
        Q = deque([vSt])
        while Q:
            vNow = Q.popleft()
            color = colors[vNow]
            for v2 in adjList[vNow]:
                if colors[v2] == color:
                    return False
                elif colors[v2] == 0:
                    colors[v2] = -color
                    Q.append(v2)
        return True
    numV = len(adjList)
    colors = [0] * numV
    for vSt in range(numV):
        if colors[vSt] != 0: continue
        if not bfs(vSt):
            return False
    return True

def WarshallFloyd(adjList):
    numV = len(adjList)
    D = [[float('inf')]*numV for _ in range(numV)]
    for u, adj in enumerate(adjList):
        for v in adj:
            D[u][v] = 1
        D[u][u] = 0
    for k in range(numV):
        Dk = D[k]
        for i in range(numV):
            Di = D[i]
            Dik = Di[k]
            for j in range(numV):
                D2 = Dik + Dk[j]
                if D2 < Di[j]:
                    D[i][j] = D2
    return D


if not IsBipartiteGraph(adjL):
    print(-1)
else:
    distss = WarshallFloyd(adjL)
    maxDist = max(map(max, distss))
    print(maxDist+1)


Measured memory_bytes: 3948
S=input()
p=''
i=0
a=0
while i<len(S):
    if p==S[i]:
        if i==len(S)-1:
            break
        p=S[i:i+2]
        i+=2
    else:
        p=S[i]
        i+=1
    a+=1
print(a)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	int a[n];
	for( int i = 0; i < n; ++i ){
		cin >> a[i];
	}
	vector<int> cntx(100000);
	vector<int> cnty(100000);
	for( int i = 0; i < 100000; ++i ){
		cntx[i] = 0;
		cnty[i] = 0;
	}
	for( int i = 0; i < n; i+=2 ){
		++cntx[a[i]-1];
		++cnty[a[i+1]-1];
	}
	int max_x = -1;
	int max_index = -1;
	int max_y = -1;
	int max_indey = -1;
	for( int i = 0; i < 100000; ++i ){
		if( max_x < cntx[i] ){
			max_x = cntx[i];
			max_index = i;
		}
		if( max_y < cnty[i] ){
			max_y = cnty[i];
			max_indey = i;
		}
	}
	if( max_index != max_indey ){
		cout << n - max_x - max_y << endl; 
	} else {
		sort(cntx.rbegin(), cntx.rend());
		sort(cnty.rbegin(), cnty.rend());
		// cout << cntx[0] << " " << cntx[1] << " " << cnty[0] << " " << cnty[1] << endl;
		cout << n - max( cntx[0] + cnty[1], cntx[1] + cnty[0] ) << endl;  
	}
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long diff = Math.abs(a - b);
        if (diff % 2 == 0) {
            System.out.println(diff/2);
        } else {
            long min = Math.min(a-1, n-b) + 1 + (b-a-1)/2;
            System.out.println(min);
        }
    }
}

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

int main() {
  int n, k, s;
  cin>>n>>k>>s;
  for (int i=0; i<k; i++) {
    cout<<s;
    if (i != n - 1) {
      cout<<" ";
    }
  }
  int t;
  if (s != 1e9) {
    t = 1e9;
  } else {
    t = 1;
  }
  for (int i=k; i<n; i++) {
    cout<<t;
    if (i != n - 1) {
      cout<<" ";
    }
  }
}

Measured memory_bytes: 1280
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

//Code Short
#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define DSORT(n) sort(n.begin(),n.end())
#define QECHO(n) cout << n
#define QECHOS(n) cout << n << " "

//Define Math
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;
typedef long long ll;
/* prototype */
int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    //START
    int A,B,K;
  cin >> A >> B >> K;
  REP(i,K){
    if(i%2==0){//TYO
      if(A%2==1)A--;
      B+=A/2;
      A/=2;
    }else{
      if(B%2==1)B--;
      A+=B/2;
      B/=2;
    }
  }
  cout << A <<" "<<B<<endl;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}

vector < int > SOE(int min, int max) {
  if (min < 2) min = 2;
  vector < int > int_array;
  for (int i = min; i <= max; i++) int_array.push_back(i);
  vector < int > sosu;
  double stop = sqrt(max);
  while (true) {
    sosu.push_back(int_array.front());
    int_array.erase(int_array.begin());
    if (stop < (double)(sosu.back())) break;
    for (int i = 0; i < (int) int_array.size(); i++) {
      if (int_array[i] % sosu.back() == 0)
        int_array.erase(int_array.begin() + i);
    }
  }
  sosu.insert(sosu.end(), int_array.begin(), int_array.end());
  return sosu;
}

int MinCM(int a, int b) {
  int c = a * b;
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

int MaxCD(int a, int b) {
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
vector < int > igets(int N) {
  vector < int > A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}

ll nPr(ll n, ll r) {
  ll ans = 1;
  r = n - r;
  while (n != r) {
    ans *= n;
    --n;
  }
  return ans;
}

ll nE(ll n) {
  return nPr(n, n);
}

ll nCr(ll n, ll r) {
  if (r == 0) return -1;
  else {
    if (0 != n - r && n - r < r) r = n - r;
    return nPr(n, r) / nE(r);
  }
}









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

int main(){
  unsigned long N,M;
  cin >> N >> M;
  vector<pair<unsigned long,unsigned long>> data(N,std::make_pair(0,0));
  for(int i=0;i<N;i++){
    cin >> data[i].first >> data[i].second;
  }
  sort(data.begin(),data.end());


  unsigned long sum = 0;
  unsigned long total = 0;
  for(int i=0;i<N;i++){
    if(total + data[i].second >= M){
      unsigned long diff = (M-total);
      sum = sum + data[i].first*diff;
      break;
    }
    else{
      sum = sum + data[i].first*data[i].second;
      total = total + data[i].second;
    }
  }

  cout << sum << endl;
  return 0;
}


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

int main() {
  string n;
  cin >> n;
  if (n[0] == n[1] && n[1] == n[2]){
    cout << "Yes" << endl;
  }
  else if (n[1] == n[2] && n[2] == n[3]){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s;
  getline(cin,s);
  r(i,s.size()-4){
    if(s[i]=='a'&&s[i+1]=='p'&&s[i+2]=='p'&&s[i+3]=='l'&&s[i+4]=='e'){s[i]='p';s[i+1]='e';s[i+2]='a';s[i+3]='c';s[i+4]='h';}
    else if(s[i]=='p'&&s[i+1]=='e'&&s[i+2]=='a'&&s[i+3]=='c'&&s[i+4]=='h'){s[i]='a';s[i+1]='p';s[i+2]='p';s[i+3]='l';s[i+4]='e';}
  }
  cout<<s<<endl;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  LL x;
  vector<int> a;
  Solver(LL n) : n(n), a(n){};

  void solve() {
    cin >> x;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = 0;
    LL sum = 0;
    for (int i = 0; i < n - 1; ++i) {
      if (sum + a[i] <= x) {
        ans++;
        sum += a[i];
      }
    }
    if (sum + a[n - 1] == x) ans++;
    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class A, int N, class T>
void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

int n, m;
ll l;
ll d[305][305];
void solve() {
    cin >> n >> m >> l;
    fillArray(d, inf);
    rep(i, n) d[i][i] = 0;
    rep(i, m) {
        int s, t;
        ll c;
        cin >> s >> t >> c;
        --s, --t;
        d[s][t] = d[t][s] = c;
    }

    rep(k, n) rep(i, n) rep(j, n) {
        mins(d[i][j], d[i][k] + d[k][j]);
    }

    rep(i, n) rep(j, n) {
        if (i == j) continue;
        if (d[i][j] <= l)
            d[i][j] = 1;
        else
            d[i][j] = inf;
    }

    rep(k, n) rep(i, n) rep(j, n) {
        mins(d[i][j], d[i][k] + d[k][j]);
    }

    int q;
    cin >> q;
    rep(i, q) {
        int s, t;
        cin >> s >> t;
        --s, --t;
        if (d[s][t] >= inf)
            cout << -1 << endl;
        else
            cout << d[s][t] - 1 << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int main() {
	fastio;
	int N;
	cin >> N;

	int arr[200000], cnt[200001]{};
	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		cin >> arr[i];
		cnt[arr[i]]++;
	}

	for (int i = 1; i <= 200000; ++i) {
		ans += cnt[i] * ll(cnt[i] - 1) / 2;
	}

	for (int i = 0; i < N; ++i) {
		cout << ans - cnt[arr[i]] + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int h,w;
    cin>>h>>w;
    if(h==1||w==1)
    {
        cout<<1<<endl;
        return 0;
    }
    if(w%2==1)
    {
        cout<<(h*(w-1))/2+((h+1)/2)<<endl;
    }
    else
    {
        cout<<h*w/2<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long X = Long.parseLong(scan.nextLine());
		long P = 100;
		int cnt = 0;

		for (int i = 0; i < 3800; i++){
			if (X > P){
				P += P / 100;
				cnt++;
			}else {
				System.out.println(cnt);
				return;
			}
		}
	}
}


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

namespace Aizu {
    public class OnlineJudge {
        static void Main() {
            const int Max = 100000000;
            var p = new bool[Max + 1];
            p[0] = p[1] = true;
            for (var i = 3; i <= 10000; i += 2) {
                if (p[i]) {
                    continue;
                }

                for (var j = i; i * j <= Max; j += 2) {
                    p[i * j] = true;
                }
            }

            Console.WriteLine(
                Enumerable
                    .Range(0, int.Parse(Console.ReadLine()))
                    .Select(_ => int.Parse(Console.ReadLine()))
                    .Where(q => q == 2 || (q & 1) == 1)
                    .Count(i => !p[i])
            );
        }
    }
}



Measured memory_bytes: 107696
a = int(input())
from math import sqrt
M = 10**6
p = [1]*(M+1)
p[0] = p[1] = 0
for x in range(2, int(sqrt(M))+1):
    if p[x]:
        for y in range(x*x, M+1, x):
            p[y] = 0
for i in range(len(p)):
    if p[i] == 1 and i >= a:
        print(i)
        exit()

Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main(){
    int H,W,N; cin>>H>>W>>N;
    int a;
    vector<int> num;
    for (int i = 1; i <= N; ++i) {
        cin>>a;
        for (int j = 0; j < a; ++j) {
            num.push_back(i);
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if(i%2==0){
                cout<<num[i*W+j];
            }else{
                cout<<num[W*(i+1)-j-1];
            }
            if(j<W-1) cout<<" ";
        }
        cout<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second

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

const int MOD = 1e9+7;
const int INF = 1e9+7;

int n;
ll memo[3000][3000];
ll v[3000];

ll f(int a, int b){
	if(memo[a][b] != -1){
		return memo[a][b];
	}
	if(a == b){
		memo[a][b] = v[a];
		return v[a];
	}
	if(a+1 == b){
		memo[a][b] = max(v[a], v[b]);
		return memo[a][b];
	}

	memo[a][b] = max(min(f(a+2, b), f(a+1, b-1)) + v[a],
		         min(f(a, b-2), f(a+1, b-1)) + v[b]);
	return memo[a][b];
}

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

	memset(memo, -1, sizeof(memo));

	cin >> n;
	ll sum = 0;
	FOR(i, n){
		cin >> v[i];
		sum += v[i];
	}

	cout << 2*f(0, n-1) - sum << '\n';

	return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e9 + 15;
int vis[maxn];
int dp[maxn];
vector<int> orden;
vector<int> adj[maxn];
void dfs(int x){
    vis[x]=1;
    for(auto e: adj[x]){
        if(vis[e]==-1){
            dfs(e);
        }
    }
    orden.push_back(x);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    memset(vis,-1,sizeof vis);
    rep(i,0,m){
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
    }
    rep(i,1,n+1){
        if(vis[i]==-1){
            dfs(i);
        }
    }
    memset(dp,0,sizeof dp);
    reverse(all(orden));
    rep(i,0,n){
        for(auto e:adj[orden[i]]){
            // cout<<e<<" "<<orden[i]<<endl;
            dp[e]=max(dp[e],dp[orden[i]]+1);
        }
    }
    int ans=0;
    rep(i,1,n+1)ans=max(ans,dp[i]);
    cout<<ans<<"\n";
    return 0;   
}

Measured memory_bytes: 9080