akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    for i in range(len(S)):
        if(i%2 == 0 and S[i] in ('R', 'U', 'D')):
            continue
        elif(i%2 == 1 and S[i] in ('L', 'U', 'D')):
            continue
        else:
            # print(i)
            print(NO)
            exit()
    print(YES)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
#define vec vector<int>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
#define ll long long
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int gcd (int x,int y){
  int b=x%y;
  if(b==0) return y;
  gcd(y,b);
} 

int main(){
  int n,k,maxa=0;
  cin>>n>>k;
  priority_queue<int> c;
  for(int i=0;i<n;i++){
    int p;
    cin>>p;
    c.push(p);
    maxa=max(maxa,p);
  }
  while(c.size()!=1){
    int a,b;
    a=c.top();
    c.pop();
    b=c.top();
    c.pop();
    c.push(gcd(a,b));
  }
  int g=c.top();
  if(k%g==0&&maxa>=k){
    cout<<"POSSIBLE"<<endl;
  }
  else{
    cout<<"IMPOSSIBLE"<<endl;
  }
}


Measured memory_bytes: 892
def asindex(c):
    return ord(c) - ord('a')


def asstr(i):
    return chr(i + ord('a'))


def main():
    n = int(input())
    S = [[0 for _ in range(n)] for _ in range(26)]

    for i in range(n):
        for c in input():
            S[asindex(c)][i] += 1

    ans = ''
    for i in range(26):
        freq = min(S[i])
        
        for _ in range(freq):
            ans += asstr(i)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
typedef long long ll;
typedef long double ld;


int main(){
  ll N; cin>>N;
  vector<int> v = {};
  while(N!=0){
    int a = N%2;
    if(a<0) a = -a;
    N = (N-a) / (-2);
    v.push_back(a);
  }
  if(v.size()==0){ printf("0\n");}
  else{ REPR(i,v.size()-1){ printf("%d",v.at(i) );} }
}


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

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    int A[N], B[N], C[N];
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> B[i];
    for(int i=0; i<N; i++) cin >> C[i];

    sort(A, A+N);
    sort(B, B+N);
    sort(C, C+N);
    
    ll ans = 0;
    for(int i=0; i<N; i++){
        int ta = (lower_bound(A, A+N, B[i]) - A) - 1;
        if(ta<0) continue;

        int tc = upper_bound(C, C+N, B[i]) - C;
        if(tc >= N) continue;
        if(C[tc] == B[i]) tc++;
        if(tc >= N) continue;
        ans = ans + (ll)(N-tc) * (ta+1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int shihab;
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
    FI(); /// skip this line for compile
    int x,y;
    cin >> x >> y;
    cout << x+y/2 << endl;
    return 0;
    //code end
}
//okbye


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define vi vector<int>
#define pll pair<ll, ll>
#define pb push_back
#define inf 1000000007
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	// int t;
	// cin>>t;
	// while(t--){
		
	// }
	int h, n;
	cin>>h>>n;
	int a[n], b[n];
	int dp[n][h + 1];
	for(int i = 0; i < n; i++){
		cin>>a[i]>>b[i];
		if(i == 0){
			for(int j = 0; j <= h; j++){
				if(j <= a[i]){
					dp[i][j] = b[i];
				}
				else{
					dp[i][j] = b[i] + dp[i][j - a[i]];
				}
			}
		}
		else{
			for(int j = 0; j <= h; j++){
				if(j <= a[i]){
					dp[i][j] = min(b[i], dp[i - 1][j]);
				}
				else{
					dp[i][j] = min(b[i] + dp[i][j - a[i]], dp[i - 1][j]);
				}
			}
		}
	}
	cout<<dp[n - 1][h]<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()


ll gcd(ll n, ll m){
    while(true){
        if(n<m) swap(n, m);
        if(!m) break;
        n %= m;
    }
    return n;
}

int main(){
    cout << setprecision(20);

    ll K;
    cin >> K;

    vvll gcd2(201, vll(201, -1));
    REP(i, 1, 201) REP(j, 1, 201){
        gcd2[i][j] = gcd(i, j);
    }

    ll total = 0;
    REP(i, 1, K+1) REP(j, 1, K+1) REP(k, 1, K+1){
        total += gcd2[i][gcd2[j][k]];
    }
    cout << total << endl;
}


Measured memory_bytes: 3952
N, M = list(map(lambda x: int(x), input().split(" ")))
ans = [0] * N
for i in range(M):
  a, b = list(map(lambda c: int(c), input().split(" ")))
  ans[a - 1] += 1
  ans[b - 1] += 1

print("\n".join([str(s) for s in ans]))

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

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


    if ( s[k-1] == 'A') {
        s[k-1] = 'a';
    } else if ( s[k-1] == 'B') {
        s[k-1] = 'b';
    } else {
        s[k-1] = 'c';
    }

    cout << s << endl;
}

Measured memory_bytes: 256
N, = map(int, input().split())
As = list(map(int, input().split()))
a,b = max(As), min(As)
ai = As.index(a)
bi = As.index(b)
print(N-1+N-1)
if a > -b:
    for i in range(N):
        if i != ai:
            print(ai+1, i+1)
    for i in range(N-1):
        print(i+1, i+2)
else:
    for i in range(N):
        if i != bi:
            print(bi+1, i+1)
    for i in range(N-1):
        print(N-i, N-i-1)


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

using namespace std;
using ll = long long;

int main() {
	const ll MOD = 1e9 + 7;
	int N;
	cin >> N;
	vector<ll> T(N + 2, 0);
	vector<ll> A(N + 2, 0);
	for (int i = 1; i <= N; ++i) { cin >> T[i]; }
	for (int i = 1; i <= N; ++i) { cin >> A[i]; }

	ll res = 1;
	for (int i = 1; i <= N; ++i) {
		ll tmp = 0;
		if (T[i] == T[i - 1]) {
			if (A[i] == A[i + 1]) { tmp = min(T[i], A[i]); }
			else if (T[i] >= A[i]) { tmp = 1; }
		} else {
			if ((A[i] == A[i + 1] && A[i] >= T[i]) || (A[i] != A[i + 1] && A[i] == T[i])) {
				tmp = 1;
			}
		}
		res = (res * tmp) % MOD;
	}

	cout << res % MOD << endl;

	return 0;
}


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



//“Remember, Hope is a good thing, maybe the best of things, and no good thing ever dies.”

//― Stephen King

const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define in insert
#define ff first
#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue
#define sz(s) (int) s.size()
#define pf(a) printf("%d ",a)
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
//#define scan(v) for(int i = 0; i<n; i++){int x;cin>>x;v.pb(x);}
#define pi 2 * acos (0.0)
#define inf 1e9
#define co cout
#define en '\n'
#define re return
#define con continue
#define dbg cout<<"___________ok____________"<<endl;
#define yes() printf("YES\n")
#define no() puts("NO\n")
#define FOR(i, j, k) for(int i=(j); i<(k); i++)
#define REV(i, j, k) for(int i=(n-1); i>=k; i--)
#define all(v) v.begin(), v.end()
#define unq(a) sort(all(a)), a.erase(unique(all(a)),a.end())
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(x, y) memset(x, y, sizeof(x))
#define prn(v) for(auto x: v)cout<<x<<" ";
const double EPS = 1e-9;
const int MXX = 4e3 + 5;


int main ()
{
    FAST_IO;
    double a, b, c;cin>>a>>b>>c;
    if(a/c<=b)co<<"Yes"<<en;
    else co<<"No"<<en;
    return 0;
}


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

int main() {
	int n,ans=0,prime[1000000];
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;++i){ prime[i]=1; }
	for(int i=2;i<1000000;++i){
		if(prime[i]==1) {
			++ans;
			if(i<1000) for(int j=i*i;j<1000000;j+=i) prime[j]=0;
		}
		prime[i]=ans;
	}
	while(scanf("%d",&n) != EOF) { printf("%d\n",prime[n]); }
	return 0;
}

Measured memory_bytes: 4928
use std::io::stdin;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

fn main() {
    let s: String = read();
    let mut flag = false;
    let ans =s.chars().filter(|_| {
        flag = !flag;
        flag
    } ).collect::<String>();

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    int i = 0;
    while(a > 0 && c > 0){
        if(i % 2 == 0){
            c -= b;
        }else{
            a -= d;
        }
        i++;
    }
    if(a <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(int i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<P,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
struct edge{
	ll cost;
	int num;
	vector<int> roa;
	bool operator<(const edge& e)const{
		return cost==e.cost?num<e.num:cost<e.cost;
	}
	bool operator>(const edge& e)const{
		return cost==e.cost?num>e.num:cost>e.cost;
	}


};
const int MAX_N=100005;
struct road{ll cost;int to;};

ll k;
vector<ll> b;
ll ma[100005];
int main() {
	memset(ma,-1,sizeof(ma));
	int n,k;
	cin>>n>>k;
	int t;
	ll d;
	rep(i,0,n){
		cin>>t>>d;
		if(ma[t]==-1)ma[t]=d;
		else{
			b.push_back(min(ma[t],d));
			ma[t]=max(ma[t],d);
		}
	}
	while(b.size()<k){
		b.push_back(0);
	}
	sort(ma,ma+n+1,greater<ll>());
	sort(b.rbegin(),b.rend());
	ll ans=0,h=0,c=0;
	rep(i,0,k){
		c+=b[i];
	}
	for(ll i=0;i<k;++i){

		if(ma[i]==-1)break;
		h+=ma[i];
		c-=b[k-i-1];
//		cout<<i<<" "<<h<<" "<<c<<" "<<(h+c)+(i+1)*(i+1)<<endl;
		ans=max(ans,(h+c)+(i+1)*(i+1));
	}
	cout<<ans<<endl;
	return 0;
}








Measured memory_bytes: 2168
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, D, L, R, K,X;
ll A;
ll B;
ll ans;
string S;
char s[52][52];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll x[100000];
int main() {
	map<string, bool> m;
	string w;
	cin >> N;
	cin >> w;
	m[w]=true;
	char tmp = w[w.size() - 1];
	rep(i, 1, N) {
		cin >> w;
		if (w[0] != tmp || m[w]) {
			cout << "No" << endl;
			return 0;
		}
		m[w]=true;
		tmp = w[w.size() - 1];
	}
	cout << "Yes" << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 256
n,y=map(int,input().split())

for i in range(n+1):
 for j in range(n+1-i):
  z_m=y-(10000*i+5000*j)
  z_n=n-(i+j)
  if z_m>=0 and z_m//1000==z_n:
   print(i,j,z_n)
   exit()
print(-1,-1,-1)

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

#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

using namespace std;

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

  int x[n], y[n];
  rep (i, n)
	cin >> x[i] >> y[i];

  map<pair<int, int>, int> pass;
  rep (i, n)
	rep (j, n) {
	  if (j == i)
		continue;
	  int tmp_x = x[i] - x[j];
	  int tmp_y = y[i] - y[j];
	  if (pass.find(make_pair(tmp_x, tmp_y)) == pass.end())
		pass.insert(make_pair(make_pair(tmp_x, tmp_y), 1));
	  else 
		pass[make_pair(tmp_x, tmp_y)]++;
	}

  int tmp = 0;
  for (auto it = pass.begin(); it != pass.end(); it++)
	tmp = max(tmp, it->second);
 
  cout << n - tmp << endl;
  
  return 0;
}


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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    string s;
    cin >> s;
    rep(i,3) cout << s[i];
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int main(){
    
    string S;

    cin >> S;

    if(S=="Sunny"){
        cout << "Cloudy";
    }else if(S=="Cloudy"){
        cout << "Rainy";
    }else{
        cout << "Sunny";
    }

    return 0;
}

Measured memory_bytes: 764
n,k = map(int, input().split())
senku = [0 for _ in range(n)]
while k:
    d = int(input())
    a = list(map(int, input().split()))
    a = [i-1 for i in a]
    for i in a:
        if not senku[i]:
            senku[i] = 1
    k-=1
print(n - sum(senku))

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

int main(){
    int n, m, i, j;
    while (cin >> n >> m && (n != 0 || m != 0)){
        for (i = 0; i < n; i++){
            for (j = 0; j < m; j++){
                if ((i + j) % 2 == 0) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
}

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

int main(){
	int n,m;
	cin>>n>>m;
	vector<pair<long long int,long long int>> ab(n);
	for (int i = 0; i < n; i++) {
		cin>>ab[i].first>>ab[i].second;
	}
	sort(
		ab.begin(),
		ab.end(),
		[](const pair<long long int,long long int> x,const pair<long long int,long long int> y){return x.first<y.first;}
	);
	long long int ans=0;
	long long int num=0;
	for (int i = 0; i < n; i++) {
		if (num+ab[i].second<=m) {
			ans+=ab[i].first*ab[i].second;
			num+=ab[i].second;
		}else {
			ans+=(m-num)*ab[i].first;
			break;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

ll box(double a)
{
	ll b = a;
	return b;
}

int main() {
	double a, b, n;
	cin >> a >> b >> n;
	cout << box(a * min(n, b - 1) / b) - a * box(min(n, b - 1) / b) << endl;
	return 0;
}

Measured memory_bytes: 3776
a = int(input())
b = int(input())
c = int(input())
x = int(input())
num = 0

# a:500yen b:100yen c:50yen x:sum_kingaku

for i in range(a+1):
    if 500 * i == x:
        num = num + 1
        break
    
    elif 500 * i > x:
        break
    
    else:
        for j in range(b+1):
            if 500 * i + 100 * j == x:
                num = num + 1
                break

            elif 500 * i + 100 * j > x:
                break

            else:
                for k in range(c+1):
                    if 500 * i + 100 * j + 50 * k == x:
                        num = num + 1
                        break

                    elif 500 * i + 100 * j + 50 * k > x:
                        break

print(num)


Measured memory_bytes: 3064
a, b, c, x, y = map(int, input().split())

if 2 * c == min(2 * c, a, b):
    print(c * 2 * max(x, y))
elif 2 * c <= max(a, b) and a == max(a, b):
    print(c * 2 * x + b * max(y - x, 0))
elif 2 * c <= max(a, b) and b == max(a, b):
    print(c * 2 * y + a * max(x - y, 0))
elif 2 * c <= a + b and x <= y:
    print(c * 2 * x + b * (y - x))
elif 2 * c <= a + b and x > y:
    print(c * 2 * y + a * (x - y))
else:
    print(a * x + b * y)

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

using namespace std;
using ll = long long;
using ld = long double;
const ll MOD=1e9+7;

#define int long long
signed main(){
//int main() {
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    int n;
    cin >> n;
    ll a[n];
    ll mx=0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        mx=max(mx,a[i]);
    }
    int m=60;
    //int m=log2(mx)+1;
    int bcnt[m]={};
    for(int i = 0; i < n; i++) {
        ll bit=a[i];
//        cout << bitset<60>(bit) << "\n";
        for(int j = 0; j < m; j++) {
            if(bit & ((ll)1<<j)) bcnt[j]++;
        }
    }
//    for(int i = 0; i < 60-m; i++) {
//        cout << "0";
//    }
//    for(int i = 0; i < m; i++) {
//        cout << bcnt[m-i-1];
//    }
//    cout << "\n";

    ll ans=0;
    ll bn =1;
    for(int i = 0; i < m; i++) {
        ll tmp=((n-bcnt[i])*bcnt[i])%MOD;
        ans=(ans+tmp*bn)%MOD;
        bn=(bn*2)%MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	int n;
	int sum = 0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	sort(a.begin(), a.end());
	for (int i = 0; i < n-1; i++) {
		sum += a[i + 1] - a[i];
	}
	
	cout << sum << endl;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')


def solve():
    n = ni()
    a = nl()
    ok = -1
    ng = 10**18
    ans = -1
    while ng - ok > 1:
        v = mid = (ok + ng) // 2
        c = 0
        cnt = 0
        for x in a[:0:-1]:
            cnt += c + x
            c += x
            d = (c - 1) // 2 + 1
            if v > c - d:
                v -= c - d
                d = c
            elif v > 0:
                d += v
                v = 0
            c = d
        if a[0] + c > 1:
            ng = mid
        else:
            ok = mid
            ans = cnt + 1
    print(ans)
    return

solve()


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

int main() {
    int N;
  cin >> N;
  vector<int> A(N);
   for (int i = 0; i < N; i++) {
   cin >> A.at(i);
  }  
  vector<int> B = A;
  
  sort(A.begin(), A.end());
  int ICHIBAN = A.at(N-1);
  int NIBAN = A.at(N-2);
  
  for (int i = 0; i < N; i++) {
    if ( B.at(i) == ICHIBAN )
    cout << NIBAN << endl;
    else
    cout << ICHIBAN << endl;
  } 
}

Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
  int n;
  std::cin>>n;
  
  int64_t aMax=0;
  std::vector<int64_t> a(n);
  for(int i=0;i!=n;i++)
  {
    std::cin>>a[i];
    if(a[i]>aMax)
      aMax=a[i];
  }
  
  std::vector<bool> dp(aMax+1,true);
  std::vector<bool> seen(aMax+1,false);
  
  std::sort(a.begin(),a.end());
  
  int result=0;
  
  for(int i=0;i!=n;i++)
  {
    if(dp[a[i]]==false)
      continue;
    
    if(seen[a[i]])
    {
      dp[a[i]]=false;
      continue;
    }
    
    seen[a[i]]=true;
    
    for(int j=2*a[i];j<=aMax;j+=a[i])
    {
      dp[j]=false;
    }
  }
  
  for(int i=0;i!=n;i++)
    if(dp[a[i]])
      result++;
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 5048
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
pair<int,int> union_tree[300000];
int union_find(int now) {
	if (union_tree[now].first == now) return now;
	return union_tree[now].first = union_find(union_tree[now].first);
}
void union_merge(int a, int b) {
	a = union_find(a);
	b = union_find(b);
	if (a == b) return;
	union_tree[a].second += union_tree[b].second;
	union_tree[b].first = union_tree[a].first;
	return;
}
int main() {
#define int long long
	iostream::sync_with_stdio(false);
	cin.tie(false);
	int n, h, w;
	cin >> n >> h >> w;
	vector<tuple<int, int, int>> inputs;
	REP(i, n) {
		long long a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		inputs.push_back(make_tuple(c, a, b));
	}
	for (int i = 0; i < 300000; ++i) {
		union_tree[i] = make_pair(i, 1);
	}
	sort(inputs.begin(), inputs.end());
	reverse(inputs.begin(), inputs.end());
	long long ans = 0;
	for (int i = 0; i < inputs.size(); ++i) {
		int a = get<1>(inputs[i]);
		int b = h + get<2>(inputs[i]);
		a = union_find(a);
		b = union_find(b);
		if (union_tree[a].second + union_tree[b].second >= 1) {
			union_merge(a, b);
			union_tree[a].second--;
			ans += get<0>(inputs[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5872
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,a[200005];
vector<ll> v,d,used(200002,0);
main(){
cin>>n>>m;

for(int k=1;k<=n;k++){
    cin>>a[k];
}
v.push_back(1);
used[1]=1;
int x=a[1];
while(used[x]!=1){
        used[x]=1;
    v.push_back(x);
    x=a[x];
}
d.push_back(x);
used.resize(0);
used.resize(n+1,0);
used[x]=1;
x=a[x];
while(used[x]!=1){
        used[x]=1;
    d.push_back(x);
    x=a[x];
}
if(m<v.size())
    cout<<v[m];
else{
    m-=v.size();
    m=m%d.size();
    cout<<d[m];
}
return 0;
}


Measured memory_bytes: 10772
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
int A,B,k;
int main(){
	scanf("%d%d%d",&A,&B,&k);
	fo(i,1,k)
		if (i&1){
			B+=(A>>1);
			A>>=1;
		}else{
			A+=(B>>1);
			B>>=1;
		}
	printf("%d %d\n",A,B);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x, n;
    cin >> x >> n;
    map<int, int> p;
    for (int i = 0; i < n; ++i) {
        int pp;
        cin >> pp;
        p[pp]++;
    }
    int dist = 0;
    while (true) {
        if (p[x - dist] == 0) {
            cout << x - dist << "\n";
            return 0;
        }
        if (p[x + dist] == 0) {
            cout << x + dist << "\n";
            return 0;
        }
        dist++;
    }
    return 0;
}

Measured memory_bytes: 3660
// AOJ 2139: Memory Match
// 2017.11.13

#include <stdio.h>
#include <string.h>

double m[1001][1001];
char f[1001][1001];

double calc(int unopen, int known)
{
	double u, k, r;
	
	if (unopen == known) { f[unopen][known] = 1; return 0; }
	if (f[unopen][known]) return m[unopen][known];

	u = unopen, k = known, r = 0;
	if (known > 0) r += (k/u) * calc(unopen-1, known-1);
	r += ((u-k)/u) * (1.0/(u-1)) * calc(unopen-2, known);
	if (known > 0) r += ((u-k)/u)*(k/(u-1)) * (calc(unopen-2, known)+1);
	if (unopen - known > 2) r += ((u-k)/u)*((u-k-2)/(u-1)) * (calc(unopen-2, known+2)+1);

	f[unopen][known] = 1;
	m[unopen][known] = r;
	return r;
}

int main()
{
	int n;
	
	memset(f[0], 1, sizeof(f[0]));
	while (scanf("%d", &n) && n > 0) printf("%.10lf\n", calc(n, 0));
	return 0;
}

Measured memory_bytes: 8648
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10



int main() {
	ll N, K; cin >> N >> K;
	ll cnt;
	if (K % 2 == 1) {
		cnt = N / K;
		cnt = cnt * cnt * cnt;
	}
	else {
		ll ttt = N / K;
		ll tmp = N / (K / 2);
		tmp -= ttt;
		cnt = (tmp * tmp * tmp) + (ttt * ttt*ttt);
	}
	print(cnt);


	return 0;
}


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

int main(){
    int h,w,k2;
    cin >> h >> w >> k2;
    vector <vector <int>> m(h,vector <int> (w,0));
    vector <string> s(h);
    vector <int> hh(h),ww(w);
    int k,all=0;
    rep(i,h){
        k=0;
        cin >> s[i];
        rep(j,w){
            string s2;
            s2=s[i][j];
            if(s2=="#"){
                m[i][j]=1;
                ++k;
                ++all;
            }
        }
        hh[i]=k;
    }

    
    string s3;
    rep(i,w){
        k=0;
        rep(j,h){
            s3=s[j][i];
            if(s3=="#"){
                ++k;
            }
        }
        ww[i]=k;
    }

    vector <int> hhh(h,0);
    vector <int> www(w,0);
    vector <int> hhhh,wwww;
    hhhh=hhh;
    wwww=www;

    int kk;
    int ans,ans2=0;
    rep(i,pow(2,h+w)){
        hhh=hhhh;
        www=wwww;
        kk=0;
        ans=0;
        rep(i2,h){
            if((i>>i2)&1==1){
                //kk+=hh[i2];
                hhh[i2]=1;
            }
        }
        rep(j2,w){
            if(((i>>(h+j2))&1)==1){
                //kk+=ww[j2];
                www[j2]=1;
            }
        }

        rep(i2,h){
            rep(j2,w){
                if(hhh[i2]==0 and www[j2]==0 and m[i2][j2]==1){
                    ++ans;
                }
            }
        }

        if(k2==ans){
            ++ans2;
        }

    }

    cout << ans2 << endl;

    

    return 0;
}

Measured memory_bytes: 4112
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)
import heapq

def main():
    N = int(input())
    V = [int(c) for c in input().split()]
    heap = []
    for i in range(N):
        heapq.heappush(heap, V[i])

    for i in range(N -1 ):
        mini = heapq.heappop(heap)
        mini2 = heapq.heappop(heap)
        mean = (mini + mini2) / 2
        heapq.heappush(heap, mean)
    print(heap[0])



if __name__ == '__main__':
    main()

Measured memory_bytes: 12500
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{ 
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nmq = Input.ar;
        var lr = Input.ar2D(nmq[1]);
        var res = new List<long>();
        var sum = new int[nmq[0] + 1, nmq[0] + 1];
        for (var i = 0; i < nmq[1]; i++)
            sum[lr[i][0], lr[i][1]]++;
        for (var i = 1; i <= nmq[0]; i++)
            for (var j = 1; j <= nmq[0]; j++)
                sum[i, j] += sum[i, j - 1] + sum[i - 1, j] - sum[i - 1, j - 1];
        while (nmq[2]-- > 0)
        {
            var pq = Input.ar;
            res.Add(sum[pq[1], pq[1]] - sum[pq[0] - 1, pq[1]] - sum[pq[1], pq[0]-1] + sum[pq[0] - 1, pq[0] - 1]);
        }
        WriteLine(string.Join("\n", res));
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(_ => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    vector<ll> cur(3);
    for (int i=0; i<3; ++i) {
        cin >> cur.at(i);
    }
    vector<string> ope(n);
    for (int i=0; i<n; ++i) {
        cin >> ope.at(i);
    }

    string res = "";
    for (int i=0; i<n; ++i) {
        int a = (int)(ope.at(i).at(0) - 'A'), b = (int)(ope.at(i).at(1) - 'A');
        if (cur.at(a) == 0 && cur.at(b) == 0) {
            cout << "No" << '\n';
            return;
        }
        if (cur.at(a) == 1 && cur.at(b) == 1) {
            if (i == n-1) {
                res += ope.at(i).at(1);
            } else {
                string ne = ope.at(i+1);
                if (ne.at(0) == ope.at(i).at(0) || ne.at(1) == ope.at(i).at(0)) {
                    cur.at(a)++;
                    cur.at(b)--;
                    res += ope.at(i).at(0);
                } else {
                    cur.at(a)--;
                    cur.at(b)++;
                    res += ope.at(i).at(1);
                }
            }
        } else if (cur.at(a) > cur.at(b)) {
            cur.at(a)--;
            cur.at(b)++;
            res += ope.at(i).at(1);
        } else {
            cur.at(a)++;
            cur.at(b)--;
            res += ope.at(i).at(0);
        }
    }
    cout << "Yes" << '\n';
    for (char c : res) {
        cout << c << '\n';
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 6696
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
template <typename CT, typename T> inline void reset_container(CT &c, int sz, T v){c.resize(sz); for(auto &x: c) x=v;}
#define taskname "agc026_b"
ll a, b, c, d;
void solve(){
    read(a);
    read(b);
    read(c);
    read(d);
    if(a<b) puts("No");
    else{
        ///a>=b;
        if(d<b) puts("No");
        else{
            ///a%b>c
            d%=b;
            a%=b;
            ///a+d, a+2d, a+3d, ...
            d=__gcd(d, b);
            if(d==0){
                if(a>c) puts("No");
                else puts("Yes");
            }
            else{
                a%=d;
                ///a+x*d>c
                ll x=(c-a)/d;
                while(a+x*d<=c) x++;
                if(a+x*d>=b) puts("Yes");
                else puts("No");
            }
        }
    }
}
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    int t;
    read(t);
    while(t--) solve();
}

Measured memory_bytes: 256
def splittingplie(n , a):

    ans = 10**18
    allsum = int(sum(a))
    asum = 0

    for i in range(n - 1):
        asum += a[i]
        rldifference = abs(allsum - asum*2)
        ans = min(ans , rldifference)

    return ans

def main():
    n = int(input())
    a = list(map(int , input().split()))
    print(splittingplie(n , a))

if __name__ == '__main__':
    main()

Measured memory_bytes: 24824
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	int K;
	cin >> S >> K;
	vector<string>Set;
	for (int i = 1; i <= K; ++i) {
		for (int j = 0; j < S.size(); ++j) {
			Set.push_back(S.substr(j, i));
		}
	}
	sort(Set.begin(), Set.end());
	std::unique(Set.begin(), Set.end());
	cout << Set[K - 1] << endl;
	return 0;
}


Measured memory_bytes: 4240
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

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

    vector<ll> ans(3);

    ans[0] = a + b;
    ans[1] = a - b;
    ans[2] = a * b;

    sort(ans.begin(), ans.end(), greater<ll>());    

    cout << ans[0] << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
idx=0
m=1000000000
for i in range(n):
    tmp=t-(h[i]*0.006)
    if abs(a-tmp)<m:
        idx=i
        m=abs(a-tmp)
print(idx+1)

Measured memory_bytes: 62432
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int64_t sum=0;
  for(int i=1;i<=N;i++){
    if(i%3!=0&&i%5!=0){
      sum+=i;
    }
  }
  cout << sum << endl;
}



Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#define MAX(a,b,c) std::max(a, std::max(b,c))

int main() {
  int N;
  std::cin >> N;
  std::vector<std::vector<int>> days(N+1, std::vector<int>(3));
  for(int i = 1; i < N+1; ++i) {
    std::cin >> days[i][0];
    std::cin >> days[i][1];
    std::cin >> days[i][2];
  }
  std::vector<std::vector<long>> dp(N+1, std::vector<long>(3));
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;
  for(int i = 1; i <= N; ++i) {
    dp[i][0] = days[i][0] + std::max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = days[i][1] + std::max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = days[i][2] + std::max(dp[i-1][0], dp[i-1][1]);
  }
  std::cout << MAX(dp[N][0], dp[N][1], dp[N][2]) << "\n";
  return 0;
}

Measured memory_bytes: 14324
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		  int n;
           cin>>n;
           int ans=0;
           int r,l;
           rep(i,0,n){
             cin>>l>>r;
             ans+=r-l+1;
           }
           cout<<ans<<endl;
}

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

const ll mod=1000000007;

int main() {
  int x,n;
  cin >> x >> n;
  map<int,int> mp;
  r(i,n){
    int a;
    cin >> a;
    mp[a]++;
  }
  bool flag1=true,flag2=true;
  if(mp[x]<=0){
    cout<<x<<endl;
    flag1=false;
  }
  int i = 1;
  
  
  while(flag1){
    if(flag2){
      if(mp[x-i]==0){
        cout<<x-i<<endl;
        flag1=false;
      }
      flag2=false;
    }
    else{
      if(mp[x+i]==0){
        cout<<x+i<<endl;
        flag1=false;
      }
      flag2=true;
    }
    if(flag2)i++;
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

using ll = long long;
const int INF=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

constexpr int MAX = 310;
ll G[MAX][MAX];

using pll = pair<long long, long long>;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, M, L;
    cin >> N >> M >> L;

    for (int i = 0; i < MAX; i++) {
        for (int j = 0; j < MAX; j++) G[i][j] = INF;
        G[i][i] = 0;
    }

    for (int i= 0; i < M; i++) {
        int a, b; ll c;
        cin >> a >> b >> c; --a; --b;
        G[a][b] = G[b][a] = c;
    }

    vector<vector<pll>> dist(N, vector<pll>(N, {INF, INF}));

    for (int s = 0; s < N; ++s) {
        dist[s][s] = {0, 0};
        priority_queue<pair<pll, int>,
        vector<pair<pll, int>>,
        greater<pair<pll, int>>> que;
        que.push(make_pair(pll(0, 0), s));
        while(!que.empty()) {
            auto p = que.top();
            que.pop();

            ll v = p.second;
            ll kaisuu = p.first.first;
            ll used = p.first.second;

            if (p.first > dist[s][v]) continue;
            for (int nv = 0; nv < N; nv++) {
                if (nv == v) continue;
                if (G[v][nv] > L) continue;
                ll nused = used + G[v][nv];
                pll np = {0, 0};
                if (nused > L) np = {kaisuu + 1, G[v][nv]};
                else np = {kaisuu, nused};

                if (chmin(dist[s][nv], np)) que.push(make_pair(np, nv));

            }
        }
    }

    int Q; cin >> Q;
    while (Q--) {
        int a, b; cin >> a >> b; --a; --b;

        ll res = dist[a][b].first;
        if (res >= INF) cout << -1 << endl;
        else cout << res << endl;
    }
}

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

int main()
{
    int N, H, W;
    cin >> N >> H >> W;
    cout << (N - H + 1) * (N - W + 1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long N,i,j,k,n,ans;
    char a;
    cin>>N;
    string s[N];
    for(i=0;i<N;i++){
        cin>>s[i];
        for(j=0;j<10;j++){
            for(k=0;k<9;k++){
                if(s[i][k]>s[i][k+1]){
                    a=s[i][k];
                    s[i][k]=s[i][k+1];
                    s[i][k+1]=a;
                }
            }
        }
    }
    sort(s,s+N);
    ans=0;n=1;
    for(i=1;i<N;i++){
        if(s[i]==s[i-1]){
            n++;
        }else{
            ans+=n*(n-1)/2;
            n=1;
        }
    }
    if(s[N-2]==s[N-1]){
        ans+=n*(n-1)/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

void solve() 
{   
    int n;cin>>n;
    ll sum=0,mn=INF,a[n],count=0;
    REP(i,n)cin>>a[i],sum+=abs(a[i]),mn=min(mn,abs(a[i])),a[i]<0?count++:0;
    if(count%2)cout<<sum-mn-mn<<endl;
    else cout<<sum<<endl;
}

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


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
int A, B, C;
int main(void) {

	cin >> A >> B >> C;

	int max_num = A;
	if (B > max_num) { max_num = B; }
	if (C > max_num) { max_num = C; }

	int num = 0;
	num += (max_num - A) + (max_num - B) + (max_num - C);

	if (num % 2 == 1) { num += 3; }

	cout << num / 2 << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
const ll INF = 1LL << 60;


int N;
int main(){
    cin >> N;
    vector<ll> a(N);
    REP(i,N){
        ll t;
        cin >> t;
        a[i] = t - i - 1;
    }
    sort(a.begin(),a.end());
    ll b = a[N/2];
    ll ans = 0;
    REP(i,N) ans += abs(a[i]-b);
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

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

    ll n;cin>>n;
    vector<ll> a(n+1);
    vector<P> v;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        v.push_back(P(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    v.push_back(P(0,0));
    vector<ll> res(n+1,0);
    ll mi=v[0].second;
    for(int i=0;i<n;i++){
        mi=min(mi,v[i].second);
        res[mi] += (i+1)*(v[i].first-v[i+1].first);
    }
    for(int i=1;i<=n;i++) cout<<res[i]<<endl;
}


Measured memory_bytes: 4208
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    long long n,k;
    scanf("%lld%lld",&n,&k);
    n=n%k;
    if(n<=k-n)
        printf("%lld\n",n);
    else
        printf("%lld\n",k-n);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
template<class T> inline bool chmin(T& a, T b){
  if (a > b){
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b){
  if (a < b){
    a = b;
    return true;
  }
  return false;
}

int main(){
  cout << fixed << setprecision(15);
  int a, b; cin >> a >> b;
  int ans = 0;
  ans = a - 2 * b > 0 ? a - 2 * b : 0;
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << min(b/a,c) << endl;
}


Measured memory_bytes: 256