akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 _main()
{
    array<string, 3> c;
    rep(i, 0, 3) cin >> c[i];
    rep(i, 0, 3) cout << c[i][i];
    cout << endl;
}


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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)

int sum_digits(int num);
vector<vector<int>> comb(int n, int r);
template <class T>
vector<T> copy_vector(vector<T> vec);

long calc_multiple_count(long size) {
    long rtn = 0;
    if(size < 2) {
        return 0;
    } else if(size < 3) {
        return comb(size, 2).size();
    } else {
        return comb(size, 2).size() + comb(size, 3).size();
    }
}

int main() {
    long n;
    cin >> n;
    map<char, long> counts;
    counts['M'] = 0;
    counts['A'] = 0;
    counts['R'] = 0;
    counts['C'] = 0;
    counts['H'] = 0;

    for(int i=0; i<n; i++) {
        string s;
        cin >> s;
        switch(s[0]) {
            case 'M':
            case 'A':
            case 'R':
            case 'C':
            case 'H':
                counts[s[0]]++;
                break;
        }
    }
    long m_size = counts['M'];
    long a_size = counts['A'];
    long r_size = counts['R'];
    long c_size = counts['C'];
    long h_size = counts['H'];

    long total = m_size * a_size * r_size + m_size * a_size * c_size + m_size * a_size * h_size 
        + m_size * r_size * c_size + m_size * r_size * h_size + m_size * c_size * h_size
        + a_size * r_size * c_size + a_size * r_size * h_size + a_size * c_size * h_size
        + r_size * c_size * h_size;

    cout << total << endl;
    //cout << "M_SIZE: " << counts['M'] << endl;
    //cout << "A_SIZE: " << counts['A'] << endl;
    //cout << "R_SIZE: " << counts['R'] << endl;
    //cout << "C_SIZE: " << counts['C'] << endl;
    //cout << "H_SIZE: " << counts['H'] << endl;

    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// nCr
vector<vector<int>> comb(int n, int r) {
    vector<vector<int>> v(n+1, vector<int>(n+1, 0));
    for(int i=0; i < v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(int i=1; i<v.size(); i++) {
        for(int j=1; j<i; j++) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]);
        }
    }
    return v;
}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}



Measured memory_bytes: 256
s=input()+"9";n=len(s);X=[(0,0)]*4;
while n:
 n-=1;k=4
 while k:k-=1;a=int(s[n]);X[k]=(X[k][0]+9*X[k-1][0],X[k][0]+(a-1)*X[k-1][0]+X[k-1][1]if a else X[k][1])if k else(1,1)
print(X[int(input())][1])

Measured memory_bytes: 38384
import copy

n = input()
a = {'7','5','3'}
for _ in range(len(n)-1):
    b = copy.copy(a)
    for s in a:
        for i in (7,5,3):
            b.add(s + str(i))
    a = b
a = {i for i in a if not ('3' not in i or '5' not in i or '7' not in i)}

n = int(n)
a = {i for i in a if int(i)<=n}
print(len(a))

Measured memory_bytes: 12092
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{
		map<char,int> mp;
		int n,j,i;
		string s;
		cin>>n>>s;
		int ans=0;
		for(i=0;i<n;i++)
		{
			mp[s[i]]++;
			for(j=1;(i-j)>=0&&(i+j)<n;j++)
			{
				map<char,int> tem;
				tem[s[i]]++;
				tem[s[i-j]]++;
				tem[s[i+j]]++;
				if(tem['R']&&tem['G']&&tem['B'])
					ans--;
			}
		}
		ans+=mp['R']*mp['G']*mp['B'];
		cout<<ans<<endl;

	}

	return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<math.h>

int isPrime(int);

int main() {
  
  int i, j, n, input, cnt = 0;
  

  
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++ ){
    scanf("%d" ,&input);
    if(isPrime(input)) cnt++;
  }
  printf("%d\n",cnt);
  
  return 0;
}

int isPrime(int n) {
  int sq = sqrt(n);
  int i,x;	
  	
  if(n == 2) return 1;
  else if(n < 2 || n % 2 == 0) return 0;

  for(i = 2 ; i <= sq ; i++) {
      x = n % i ;
      if(x == 0) return 0;
    
  }
  return 1;
	
}

Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#define ll long long
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>QUE;//きゅー
int length(char* str) {
    int len = strlen(str);
    return len;
}
ll GCD(ll a, ll b)
{

    ll r, tmp;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }


    return b;
}
ll LCM(ll a, ll b)
{

    ll r, x, tmp;
    ll i, j;
    ll lcm;
    i = a;
    j = b;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    lcm = (i / b) * j;

    return lcm;
}
ll checkTen(ll a) {
    ll ans = 0;
    while (true) {
        ans++;
        if ((a / 10) % 10 != 0) {
            break;
        }
        a = a / 10;
    }
    return ans;
}
ll checkFive(ll a) {
    ll ans = 0;
    while (true) {
        ans++;
        if ((a / 5) % 5 != 0) {
            break;
        }
        a = a / 5;
    }
    return ans;
}
ll checkTwo(ll a) {
    ll ans = 0;
    while (true) {
        ans++;
        if ((a / 2) % 2 != 0) {
            break;
        }
        a = a / 2;
    }
    return ans;
}
ll checkf(ll a) {
    ll ans = 0;
    while (true) {
        ans++;
        if ((a / 10) % 10 != 0) {
            break;
        }
        a = a / 10;
    }
    return a;
}
int main()
{
    ll L, R;
    ll Min = 2019;
    cin >> L >> R;
    for (ll i = L; i < R; i++) {
        for (ll j = L + 1; j <= R; j++) {
            Min = min(Min, (i * j)%2019);
            if (Min == 0) {
                cout << Min << endl;
                return 0;
            }
        }
    }
    cout << Min << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<vector>
#define INF 100000000

#define MAX_N 10000
#define MAX_M 100

typedef long long int ll;
using namespace std;



int main(){

	int a[3];

	scanf("%d %d %d", &a[0], &a[1], &a[2]);

	for(int i = 0; i < 3; i++){
		for(int j = i+1; j < 3; j++){
			if(a[i] > a[j]){
				int kari = a[i];
				a[i] = a[j];
				a[j] = kari;
			}
		}
	}

	printf("%d %d %d\n", a[0], a[1], a[2]);



	return 0;

}

Measured memory_bytes: 1192
//107 B - Grid Compression 2018/08/25
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int h , w; cin >> h >> w;
    string a[h];
    int counter=0;
    rep(i, h) cin >> a[i];
    rep(i ,h){
        rep(j ,w){
            if(a[i][j]=='#') continue;
            ++counter;
        }
        if(counter==a[i].size()){
            rep(k ,w) a[i][k]='0';
        }
        counter = 0;
    }
    counter = 0;
    rep(i ,w){
        rep(j ,h){
            if(a[j][i]=='#') continue;
            ++counter;
        }
        if(counter==h){
            rep(j ,h) a[j][i]='0';
        }
        counter = 0;
    }
    counter = 0;
    rep(i ,h){
        rep(j , w){
            if(a[i][j]=='0') continue;
            else cout << a[i][j];
        }
        rep(k ,w){
            if(a[i][k]=='0') ++counter;
        }
        if (counter!=w) cout << endl;
        counter = 0;
        }
}
       

Measured memory_bytes: 256
def main(): 
    _, _, m = map(int,input().split())
    reizo = list(map(int,input().split()))
    renzi = list(map(int,input().split()))
    waribiki = [list(map(int,input().split())) for i in range(m)]

    min_cost = min(reizo) + min(renzi)

    for i in range(m):
        cost = reizo[waribiki[i][0]-1] + renzi[waribiki[i][1]-1] - waribiki[i][2]

        if cost < min_cost:
            min_cost = cost
    
    print(min_cost)


main()

Measured memory_bytes: 38564
#include "iostream"
using namespace std;
int main(){
int W,a,b;
cin>>W>>a>>b;
if(abs(a-b)<=W){
cout<<0<<endl;
}
else{
if(a==b){
cout<<0<<endl;
}
else if(a<b){
cout<<b-a-W<<endl;
}
else{
cout<<a-b-W<<endl;
}
}
return 0;
}


Measured memory_bytes: 256
n,d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n-1):#xの何番目のリストが対象なのか
    main = x[i]
    for j in range(i+1,n):#その時に合計で何人の相手と距離を求めるか
        li = []
        for k in range(d):
            num = (abs(main[k]-x[j][k]))**2
            li.append(num)
            
        target = (sum(li))**(1/2)
        if target.is_integer():
            ans += 1
print(ans)

Measured memory_bytes: 3064
s = gets.chomp.to_s.split(//).map(&:to_i)
i = 0
j = 1
ary_from_0 = []
ary_from_1 = []

s.size.times do |k|
    if k % 2 == 0
        ary_from_0 << i
        ary_from_1 << j
    else
        ary_from_0 << j
        ary_from_1 << i
    end
end

cnt_0 = 0
cnt_1 = 0

s.each do |x|
    if x == ary_from_0[i]
        cnt_0 += 1
    else
        cnt_1 += 1
    end
    i += 1
end

puts s.size - [cnt_0, cnt_1].max


Measured memory_bytes: 9452
n,k=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9+7
dp=[INF]*n
dp[0]=0

for i in range(1,n):
    s=min(k,i)
    for j in range(1,s+1):
        dp[i]=min(dp[i],abs(h[i]-h[i-j])+dp[i-j])
print(dp[n-1])

Measured memory_bytes: 84780
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }



signed main(){

    int A, B, C; cin >> A >> B >> C;
    cout << A * B * C / max(A, max(B, C)) / 2;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int p[100100];
int n;
vector<pair<pii, int> > ord1, ord2;
vector<pair<int, pii> > g;

int dsu_get(int v){
	if(v == p[v])
		return v;
	return p[v] = dsu_get(p[v]);
}

void dsu_unite(int x, int y){
	x = dsu_get(x);
	y = dsu_get(y);
	if(x != y)
		p[x] = y;
}

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen(fname".in", "r", stdin);
	// freopen(fname".out", "w", stdout);
	cin >> n;
	// cout << n;
	for(int i = 0, x, y; i < n; ++i){
		cin >> x >> y;
		ord1.pb(mp(mp(x, y), i));
		ord2.pb(mp(mp(y, x), i));
		// cout << i;
	}
	sort(all(ord1));
	sort(all(ord2));
	for(int i = 1; i < n; ++i){
		int ax = ord1[i - 1].f.f, ay = ord1[i - 1].f.s, aind = ord1[i - 1].s;
		int bx = ord1[i].f.f, by = ord1[i].f.s, bind = ord1[i].s;
		g.pb(mp(min(abs(ax - bx), abs(ay - by)), mp(aind, bind)));
		g.pb(mp(min(abs(ax - bx), abs(ay - by)), mp(bind, aind)));

		ax = ord2[i - 1].f.f, ay = ord2[i - 1].f.s, aind = ord2[i - 1].s;
		bx = ord2[i].f.f, by = ord2[i].f.s, bind = ord2[i].s;
		g.pb(mp(min(abs(ax - bx), abs(ay - by)), mp(aind, bind)));
		g.pb(mp(min(abs(ax - bx), abs(ay - by)), mp(bind, aind)));
	}
	sort(all(g));
	g.erase(unique(all(g)), g.end());
	// for(int i = 0; i < sz(g); ++i){
	// 	printf("%d %d %d\n", g[i].f, g[i].s.f, g[i].s.s);
	// }
	ll cost = 0;
	for(int i = 0; i < n; ++i){
		p[i] = i;
	}
	for(int i = 0; i < sz(g); ++i){
		int x = g[i].s.f, y = g[i].s.s, w = g[i].f;
		if(dsu_get(x) != dsu_get(y)){
			cost += 1ll * w;
			dsu_unite(x, y);
		}
	}
	cout << cost << "\n";
	return 0;
}

Measured memory_bytes: 10664
N = int(input())
A = list(map(int, input().split()))

def puts(s): # 個人的にこのほうが解りやすいので。。。
    print(s)

def puti(i): # put integer
    print(str(i))

A.sort(reverse=True)

alice = 0
bob = 0

for i in range(N):
    if i % 2 == 0:
        alice += A[i]
    else:
        bob += A[i]

puti(alice - bob)


Measured memory_bytes: 3060
Public Class Program
  Shared Sub Main()
    Dim whxy As Long() = Array.ConvertAll(Of String, Long)(Console.ReadLine().Split(" "), AddressOf Long.Parse)
    Dim w As Long = whxy(0)
    Dim h As Long = whxy(1)
    Dim x As Long = whxy(2)
    Dim y As Long = whxy(3)
    Dim s As Double = w * h / 2
    Dim output As String = s.ToString("F")
    If w / 2 = x AndAlso h / 2 = y Then
      output &= " 1"
    Else
      output &= " 0"
    End If
    Console.WriteLine(output)
  End Sub
End Class

Measured memory_bytes: 11092
#include<stdio.h>
int main ()
{
    int a,b,c,d,e,f;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);

    d=b+c;
    e=d-a;
    if(a>=d)
    {
        printf("0");
    }
    else
{printf("%d",e); }
return 0;
}



Measured memory_bytes: 128
class UnionFind():
    
    def __init__(self,n):
        self.n = n
        self.parents = [-1]*n
        
    def find(self, a):
        if self.parents[a] < 0:
            return a
        else:
            self.parents[a]=self.find(self.parents[a])
            return self.parents[a]
        
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        else:
            if self.parents[x]<self.parents[y]:
                x,y = y,x
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            
    def size(self,x):
        return -self.parents[self.find(x)]
    
    def same(self,x,y):
        if self.find(x)==self.find(y):
            return True
        else:
            return False
    
N,M,K = map(int,input().split())
uf = UnionFind(N)
friend = [list(map(int,input().split())) for i in range(M)]
block = [list(map(int,input().split())) for i in range(K)]
ff = [[] for i in range(N)]
bb = [[] for i in range(N)]
ans = []
for i in range(M):
    uf.union(friend[i][0]-1,friend[i][1]-1)
    ff[friend[i][0]-1].append(friend[i][1]-1)
    ff[friend[i][1]-1].append(friend[i][0]-1)
for i in range(K):
    bb[block[i][0]-1].append(block[i][1]-1)
    bb[block[i][1]-1].append(block[i][0]-1)
for i in range(N):
    ans.append(uf.size(i)-1-len(ff[i]))
    for j in bb[i]:
        if uf.same(j,i)==True:
            ans[i] -= 1
answer=[str(ans[i]) for i in range(len(ans))]
print(" ".join(answer))

Measured memory_bytes: 92824
N = int(input())
A = [input() for i in range(N)]
if len(A) != len(set(A)):
    print('No')
else:
    for i in range(N - 1):
        if A[i][-1] != A[i + 1][0]:
            print('No')
            break
    else:
        print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const ll MOD=1e9+7;
const int MAX=1e5+10;

string S;
int N;
void input(){
  cin>>S;
  N=sz(S);
}

ll dp[MAX][13];
void solve(){
  dp[0][0]=1;
  rep(i,N){
    if(S[i]=='?'){
      rep(r,13)rep(j,10){
       dp[i+1][(10*r+j)%13]=(dp[i][r]+dp[i+1][(10*r+j)%13])%MOD;
      }
    }
    else{
      int j=S[i]-'0';
      rep(r,13){
       dp[i+1][(10*r+j)%13]=dp[i][r];
     }
    }
  }
  cout<<dp[N][5]<<endl;
}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

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

int dp[200010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string s;
	cin >> s;
	int N = s.size();
	int bit = 0;
	map<int, int> m;
	m[0] = 0;
	for(int i = 0; i < N; i++){
		//cout << i << endl;
		dp[i + 1] = dp[i] + 1;
		int id = s[i] - 'a';
		// 全部余ってない
		int zero = bit;
		if(m.count(zero)){
			dp[i + 1] = min(dp[i + 1], m[zero] + 1);
		}
		// idが余ってて他余ってない
		int one = bit ^ (1 << id);
		if(m.count(one)){
			dp[i + 1] = min(dp[i + 1], m[one] + 1);
		}
		// idが余ってて他1つ余ってる
		for(int j = 0; j < 26; j++){
			if(j == id) continue;
			one = bit ^ (1 << id) ^ (1 << j);
			if(m.count(one)){
				//cout << char('a' + j) << endl;
				dp[i + 1] = min(dp[i + 1], m[one] + 1);
			}
		}

		if(!m.count(bit)){
			m[bit] = dp[i];
		}
		else{
			m[bit] = min(m[bit], dp[i]);
		}
		bit ^= 1 << id;
	}

	cout << dp[N] << endl;
}


Measured memory_bytes: 10644
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

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

    int ax, ay, bx, by;
    cin >> ax >> ay >> bx >> by;
    int vecabx = bx - ax, vecaby = by - ay;
    cout << bx - vecaby << " " << by + vecabx << " " << ax - vecaby << " "
         << ay + vecabx << endl;

    return 0;
}


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


int main() {
  int ans=0;
  rep(i,4){
    char a;
    cin >> a;
    if(a == '+') ans++;
    else ans--;
  }
  cout << ans << endl;
  return 0;
  
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

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

    if(abs(a-x) < abs(b-x)) {
        cout << "A";
    } else {
        cout << "B";
    }
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100010
#define F first
#define S second
using namespace std;
vector<pair<long long,long long> > hn;
long long n,k,t,d,ans,kd=0,num[N]={},del=0;
bool cmp(pair<long long,long long> a,pair<long long,long long> b)
{
	if(a.S>b.S)
	{
		return true;
	}
	return false;
}
int main(){
	int i,cnt=0;
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		cin>>t>>d;
		hn.push_back(make_pair(t,d));
	}
	sort(hn.begin(),hn.end(),cmp);
	for(i=0;i<k;i++)
	{
		del+=hn[i].S;
		num[hn[i].F]++;
		if(num[hn[i].F]==1)
		{
			kd++;
		}
	}
	ans=kd*kd+del;
	cnt=k-1;
	for(i=k;i<n;i++)
	{
		if(cnt<0)
		{
			break;
		}
		while(num[hn[cnt].F]<=1)
		{
			cnt--;
			if(cnt<0)
			{
				break;
			}
		}
		if(cnt<0)
		{
			break;
		}
		if(num[hn[i].F]>0)
		{
			continue;
		}
		num[hn[cnt].F]--;
		num[hn[i].F]++;
		del-=hn[cnt].S;
		del+=hn[i].S;
		kd++;
		ans=max(ans,kd*kd+del);
		cnt--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2672
//
//  4.cpp
//  Algorithms and Data Structures
//
//  Created by kawauso on 2018/04/06.
//

#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <sstream>
#include <tuple>
#include <queue>

void c_4_2();
void c_4_3();

#define MAIN() c_4_3()
#ifdef MAIN
int main(int argc, const char * argv[]) {
	std::ios::sync_with_stdio(false);
	MAIN();
	return 0;
}
#else
#include "4.hpp"
#endif

void c_4_3() {
	int n;
	int q;
	int elapsed;

	std::cin >> n;
	std::cin >> q;
	std::queue<std::tuple<std::string, int>> queue;
	for (int i = 0; i < n; i++) {
		std::string name;
		int time;

		std::cin >> name;
		std::cin >> time;
		queue.push(std::make_tuple(name, time));
	}
	elapsed = 0;
	while (queue.size() > 0) {
		int min_qt;

		min_qt = 0;
		for (int i = 0; i < queue.size(); i++) {
			std::tuple<std::string, int> p;

			p = queue.front();
			queue.pop();
			if (std::get<1>(p) <= q) {
				// the process ends
				elapsed += std::get<1>(p);
				std::cout << std::get<0>(p) << " " << elapsed << std::endl;
				continue;
			}
			std::get<1>(p) -= q;
			queue.push(p);
			elapsed += q;
			if (min_qt == 0 || min_qt > std::get<1>(p)) {
				min_qt = std::get<1>(p);
			}
		}
	}
}

void c_4_2() {
	std::string line;
	std::string s;

	// input
	std::getline(std::cin, line);
	std::istringstream iss(line);
	std::vector<std::string> a;
	while (iss >> s) {
		if (s == "+") {
			const auto result = std::stoi(a[1]) + std::stoi(a[0]);
			a.erase(a.begin(), a.begin() + 2);
			a.insert(a.begin(), std::to_string(result));
		} else if (s == "-") {
			const auto result = std::stoi(a[1]) - std::stoi(a[0]);
			a.erase(a.begin(), a.begin() + 2);
			a.insert(a.begin(), std::to_string(result));
		} else if (s == "*") {
			const auto result = std::stoi(a[1]) * std::stoi(a[0]);
			a.erase(a.begin(), a.begin() + 2);
			a.insert(a.begin(), std::to_string(result));
		} else {
			a.insert(a.begin(), s);
		}
	}
	std::cout << a[0] << std::endl;
}
// 正解との相違: 演算子は格納しなくてよいので配列の要素の型は整数でよい
// C++で実装するならstd::stackを使ってよいだろう



Measured memory_bytes: 6348
s = input()
n = len(s)
i = 0
a = 0
while i<n:
    c,j = 0,i
    while j < n:
        t = (s[j:j+1])
        if t == "A" or t == "C" or t == "G" or t == "T":
            j += 1
            c += 1
        else:
            if c > a:
                a = c
            break
    if j==n:
        if c > a:
            a = c
    i = j+1
print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll N;
    cin >> N;
    vector<ll> as(N);
    rep(i, N){
        cin >> as[i];
    }

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

    ll ans = 0;
    ll i = 0;
    ll res = N - 1;
    while(i<N){
        if(i==0){
            ans += as[i];
            -- res;
            ++ i;
        }else if(res==1){
            ans += as[i];
            break;
        }else{
            ans += as[i] * 2;
            res -= 2;
            i += 1;
        }
        if(res==0){
            break;
        }

    }

    cout << ans << endl;

}

int main(){
    Main();
}

Measured memory_bytes: 4464
#include <bits/stdc++.h>
#define DAU  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
unordered_map<string, int> M;
int a, b;
string s, t, u;
int main() {
    DAU
    cin >> s >> t >> a >> b >> u;
    M[s] = a, M[t] = b, --M[u];
    cout << M[s] << ' ' << M[t];
    PLEC
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif


struct UnionFind{
    // par[i] parent. if i == par[i] i is root
    vector<ll> par;
    // sizes[i] sizeof tree i if i is root
    vector<ll> sizes;

    UnionFind(ll n) : par(n), sizes(n, 1){
        // init: all node is root i
        rep(i, n) par[i] = i;
    }

    // find root of x
    ll find(ll x){
        if (x == par[x])
            return x;
        return par[x] = find(par[x]); // recursive, editing root
    }

    // merge x, y
    void unite(ll x, ll y){
        // root
        x = find(x);
        y = find(y);

        // do not merge if same tree
        if (x == y)
            return;

        // force size x > y
        if (sizes[x] < sizes[y])
            swap(x, y);

        // unite: x is parent of y
        par[y] = x;
        sizes[x] += sizes[y];
    }

    // x, y same root
    bool same(ll x, ll y){
        return find(x) == find(y);
    }

    // size of tree containing x
    ll size(ll x){
        return sizes[find(x)];
    }
};

vvll lng;

void pr(bool f){
    cout << (f ? "YES" : "NO") << endl;
    exit(0);
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, m;
    cin >> n >> m;
    lng.resize(m);
    vll k(n);
    vvll l(n);
    rep(i, n){
        cin >> k[i];
        l[i].resize(k[i]);
        rep(j, k[i]){
            cin >> l[i][j];
            l[i][j]--;
            lng[l[i][j]].emplace_back(i);
        }
    }
    rep(i, m) dump(lng[i]);
    UnionFind uf(n);
    rep(i, m){
        ll nn = SZ(lng[i]);
        if(nn >= 2){
            repr(j, 1, nn){
                uf.unite(lng[i][j], lng[i][0]);
            }
        }
    }
    pr(uf.size(0) == n);
    return 0;
}

Measured memory_bytes: 11252
#include <cstdio>

int n, s, res;

void dfs(int prev, int deep, int sum);

int main(void)
{
	while (scanf("%d %d", &n, &s)){
		if (n == s && s == 0) break;
		
		res = 0;
		for (int i = 0; i < 10; i++){
			dfs(i, 1, i);
		}
		
		printf("%d\n", res);
	}
	
	return (0);
}

void dfs(int prev, int deep, int sum)
{
	if (deep == n && sum == s){
		res++;
		return;
	}
	if (n < deep) return;
	if (s < sum) return;
	
	for (int i = prev + 1; i < 10; i++){
		dfs(i, deep + 1, sum + i);
	}
	
	return;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstdio>

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
	string str;
	string order;
	int q;
	cin >> str;
	cin >> q;

	
	int a = 0, b = 0;

	for (int i = 0; i < q ; i++) {
		cin >> order;

		if (order == "reverse") {
			cin >> a >> b;
			reverse(str.begin() + a, str.begin() + b + 1);
	
		}
		else if (order == "replace") {
			cin >> a >> b;
			string p;
			cin >> p;
			int  n = p.size();
			for (int k = 0; k < b-a+1 ; k++) {
				str[a + k] = p[k];
			}
			
		}
		
	

	if (order == "print") {
		cin >> a >> b;
		for (int i = a; i <= b; i++) {
			cout << str[i];
		}
		cout << endl;
	}
}

	


	return 0;
}


Measured memory_bytes: 3180
#!/usr/bin/python3


(n, m) = map(int, input().split())

xti = {}
yti = {}
xti[0] = -1
yti[0] = -1

lvs = []
for i in range(n):
    (a, b, c) = map(int, input().split())
    yti[a] = -1
    yti[b] = -1   
    xti[c] = -1
    lvs.append((a, b, c))

lhs = []
for i in range(m):
    (d, e, f) = map(int, input().split())
    yti[d] = -1
    xti[e] = -1   
    xti[f] = -1
    lhs.append((d, e, f))

xs = sorted(xti.keys())
for (i, x) in enumerate(xs):
    xti[x] = i
    
ys = sorted(yti.keys())
for (i, y) in enumerate(ys):
    yti[y] = i

xsl = len(xs) * 2
ysl = len(ys) * 2

fi = [ [ 0 for x in range(xsl) ] for y in range(ysl) ]

for (a, b, c) in lvs:
    x = xti[c] * 2
    for y in range(yti[a] * 2, yti[b] * 2 + 1):
        fi[y][x] = 2

for (d, e, f) in lhs:
    y = yti[d] * 2
    for x in range(xti[e] * 2, xti[f] * 2 + 1):
        fi[y][x] = 2

(cx, cy) = (xti[0] * 2 + 1, yti[0] * 2 + 1)
if cx < 0 or cx >= xsl - 1 or cy < 0 or cy >= ysl - 1:
    print('INF')
    exit()
q = []
q.append((cx, cy))
fi[cy][cx] = 1
s = (xs[(cx + 1) // 2] - xs[cx // 2]) * (ys[(cy + 1) // 2] - ys[cy // 2])
dxs = [0, 1, 0, -1]
dys = [1, 0, -1, 0]

while q:
    (x, y) = q.pop(-1)

    for i in range(4):
        cx = x + dxs[i] * 2
        cy = y + dys[i] * 2
    
        if fi[cy][cx] != 0:
            continue

        pcx = x + dxs[i]
        pcy = y + dys[i]
        if fi[pcy][pcx] == 2:
            continue
        
        
        if cx < 0 or cx >= xsl - 1 or cy < 0 or cy >= ysl - 1:
            print('INF')
            exit()

        fi[cy][cx] = 1
        s += (xs[(cx + 1) // 2] - xs[cx // 2]) * (ys[(cy + 1) // 2] - ys[cy // 2])
        q.append((cx, cy))

print(s)

#for xl in fi:
#    print(xl)




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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

//---------------------------------------------------------//
const int MOD = 1e9+7;
const int MAXR = 510000;
//---------------------------------------------------------//

template<ll mod> class modint{
public:
    ll val=0;
    //コンストラクタ
    modint(ll x=0){while(x<0)x+=mod;val=x%mod;}
    //コピーコンストラクタ
    modint(const modint &r){val=r.val;}
    //算術演算子
    modint operator -(){return modint(-val);} //単項
    modint operator +(const modint &r){return modint(*this)+=r;}
    modint operator -(const modint &r){return modint(*this)-=r;}
    modint operator *(const modint &r){return modint(*this)*=r;}
    modint operator /(const modint &r){return modint(*this)/=r;}
    //代入演算子
    modint &operator +=(const modint &r){
        val+=r.val;
        if(val>=mod)val-=mod;
        return *this;
    }
    modint &operator -=(const modint &r){
        if(val<r.val)val+=mod;
        val-=r.val;
        return *this;
    }
    modint &operator *=(const modint &r){
        val=val*r.val%mod;
        return *this;
    }
    modint &operator /=(const modint &r){
        ll a=r.val,b=mod,u=1,v=0;
        while(b){
            ll t=a/b;
            a-=t*b;swap(a,b);
            u-=t*v;swap(u,v);
        }
        val=val*u%mod;
        if(val<0)val+=mod;
        return *this;
    }
    //等価比較演算子
    bool operator ==(const modint& r){return this->val==r.val;}
    bool operator <(const modint& r){return this->val<r.val;}
    bool operator !=(const modint& r){return this->val!=r.val;}
};

using mint = modint<MOD>;

//入出力ストリーム
istream &operator >>(istream &is,mint& x){//xにconst付けない
    ll t;is >> t;
    x=t;
    return (is);
}
ostream &operator <<(ostream &os,const mint& x){
    return os<<x.val;
}

//累乗
mint modpow(const mint &a,ll n){
    if(n==0)return 1;
    mint t=modpow(a,n/2);
    t=t*t;
    if(n&1)t=t*a;
    return t;
}

//二項係数の計算
mint fac[MAXR+1],finv[MAXR+1],inv[MAXR+1];
//テーブルの作成
void com_init() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    FOR(i,2,MAXR){
        fac[i]=fac[i-1]*mint(i);
        inv[i]=-inv[MOD%i]*mint(MOD/i);
        finv[i]=finv[i-1]*inv[i];
    }
}
//演算部分
mint com(ll n,ll k){
    if(n<k)return 0;
    if(n<0)return 0;
    if(k==0) return 1;
    return fac[n]*finv[k]*finv[n-k];
}

int main() {
    com_init();

    int N; cin >> N; 
    vector<int> A(N+1, -1);

    int L,R,S;
    S = N+1;

    REP(i,N+1){
        int a; cin >> a;
        if(A[a] != -1){
            L = A[a]-1;
            R = S-i-1;
            break;
        }else{
            A[a] = i+1;
        }
    }
    //cout << L << " " << R << endl;

    FOR(i,1,N+2){
        if(i==1){
            cout << N << endl;
        }else if(i==N+1){
            cout << 1 << endl;
        }else{
            cout << com(S,i) - com(L+R, i-1) << endl;
        }
    }

    


    return 0;
}

Measured memory_bytes: 15616
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12);
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que; //昇順

using namespace std;

const int mod=1e9+7;

void run();

void init() {
}

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

void run(){
    vi a(3);
    rep(i,3)cin >> a[i];
    SORT(a);
    int ans = 0;
    rep(i,2)
    {
        ans += abs(a[i]-a[i+1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/*
    Created by Rahul Goel.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*******************************************************************************/
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*******************************************************************************/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
ll mod_sum() { return 0LL; }
template < typename T, typename... Args >
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%MOD + MOD)%MOD; }
/*******************************************************************************/
ll mod_prod() { return 1LL; }
template< typename T, typename... Args >
T mod_prod(T a, Args... args) { return (a * mod_prod(args...))%MOD; }
/*******************************************************************************/
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
/*******************************************************************************/
//.-.. . -. -.- .- .. ... .-.. --- ...- .
/*
    Code begins after this.
*/

bool valid(ll a, ll b, ll c) {
    return (a + b > c) && (b + c > a) && (c + a > b);
}

ll solve() {
    ll n;
    cin >> n;
    vi vec(n);
    for (ll &x : vec) {
        cin >> x;
    }
    ll ans = 0;
    sort(all(vec));
    for (ll i = 0; i < n; i++) {
        for (ll j = i + 1; j < n; j++) {
            for (ll k = j + 1; k < n; k++) {
                if (vec[i] == vec[j] || vec[j] == vec[k]) {
                    continue;
                }
                if (valid(vec[i], vec[j], vec[k])) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

signed main() {
    fastio;

    ll t = 1;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3660
import sys
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.readline


n, m, energy = map(int, input().split())
edges = [[float('INF')]*n for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    edges[a-1][b-1] = c
    edges[b-1][a-1] = c

G = csgraph_from_dense(edges, null_value=float('INF'))
dist = floyd_warshall(G, directed=False)

L_edges = [[0]*n for _ in range(n)]
for i in range(n-1):
    for j in range(i, n):
        if dist[i][j] <= energy:
            L_edges[i][j] = 1
            L_edges[j][i] = 1

G = csgraph_from_dense(L_edges, null_value=0)
answers = floyd_warshall(G, directed=False)

Q = int(input())
for i in range(Q):
    s, t = map(int, input().split())
    ans = answers[s-1][t-1] - 1
    if ans == float('INF'):
        print(-1)
    else:
        print(int(ans))


Measured memory_bytes: 20776
#ifndef ___Rank_Union_Find
#define ___Rank_Union_Find

// ------ Required ------ //
#include <vector>

// ------ Class ------ //
class RankUnionFind {
private:
	std::size_t size_; std::vector<std::size_t> par, rank;
public:
	RankUnionFind() : size_(0), par(std::vector<std::size_t>()), rank(std::vector<std::size_t>()) {};
	RankUnionFind(std::size_t size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (std::size_t i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	inline std::size_t size() { return size_; }
	inline std::size_t root(std::size_t x) { return par[x] == x ? x : par[x] = root(par[x]); }
	inline bool same(std::size_t x, std::size_t y) { return root(x) == root(y); }
	inline void unite(std::size_t x, std::size_t y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	inline bool operator==(const RankUnionFind &u) { return par == u.par; }
	inline bool operator!=(const RankUnionFind &u) { return par != u.par; }
};

#endif

#include <iostream>
#include <algorithm>
using namespace std;
struct Edge { int a, b, w; };
bool operator<(const Edge& e1, const Edge& e2) { return e1.w < e2.w; }
int N, M, a, b, w; Edge G[5000];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> N >> M, N | M) {
		for (int i = 0; i < M; i++) cin >> G[i].a >> G[i].b >> G[i].w, G[i].a--, G[i].b--;
		sort(G, G + M);
		int ret = 999999999;
		for (int i = 0; i < M; i++) {
			int r = 0, c = 0;
			RankUnionFind uf(N);
			for (int j = i; j < M; j++) {
				if (!uf.same(G[j].a, G[j].b)) {
					uf.unite(G[j].a, G[j].b);
					r = G[j].w; c++;
					if (c == N - 1) break;
				}
			}
			if (c == N - 1) ret = min(ret, r - G[i].w);
		}
		if (ret == 999999999) cout << -1 << endl;
		else cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  ll Y;
  cin >> N >> Y;
  for(int n=0;n<=N;n++){
    for(int h=0;n+h<=N;h++){
      int y = N-(n+h);
      if(y<0) continue;
      if(n+h+y == N){
        if(n*1000+h*5000+y*10000==Y){
          cout << y << " " << h << " " << n << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))

steps = 0
human_mae = -1
for a in As:
    if human_mae == -1:
        human_mae = a
        continue
    if a < human_mae:
        step = human_mae - a
        steps += step
        human_mae = a + step
        continue
    human_mae = a

print(steps)

Measured memory_bytes: 32296
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

char c;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> c;
	cout << (islower(c) ? 'a' : 'A');
}

Measured memory_bytes: 3636
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com

#include<bits/stdc++.h>
using namespace std;
#define sz size()
#define mk make_pair
#define clr clear()
#define B begin()
#define E end()
#define EM empty()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define all(cont) cont.begin(),cont.end()
#define pb push_back
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
typedef long long int LL;
typedef unsigned long long int ULL;
int main()
{
//    fast;
    int i,j,k,n,m,l,s=0,x,y,tc=1;
    while(cin>>n)
    {
        vi a;
        int f=0,t=0,tn=0,o=0, c=0;
        rep(i,n)
        {
            cin>>x;
            a.pb(x);
            c++;
            if(x%4==0)
                f++;
            else if(x%2==0)
                t++;
        }
        if(f>=(n/2)) cout<<"Yes"<<endl;
        else if((t/2)+f>=(n/2)) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}



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

int main() {
  int N;
  cin >> N;
  vector<int> C(N-1);
  vector<int> S(N-1);
  vector<int> F(N-1);
  for(int i=0; i<N-1; i++){
    cin >> C.at(i);
    cin >> S.at(i);
    cin >> F.at(i);
  }
  
  int64_t time = 0;
  for(int j=0; j<N-1; j++){
    time += S.at(j);
    time += C.at(j);
   for(int k=j+1; k<N-1; k++){
     if(time < S.at(k)){
       time = S.at(k);
     }
     if((time - S.at(k)) %F.at(k) != 0){
       time += F.at(k) - (time - S.at(k)) %F.at(k);
     }
     time += C.at(k);
   }
    cout << time << endl;
    time = 0;
  }
  cout << 0 << endl;      
}

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

int n;
int xs[112345];
int ys[112345]; // sorted
std::map<int, int> compress;

int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; ++i) {
    scanf("%d", &xs[i]);
    ys[i] = xs[i];
  }
  std::sort(ys, ys + n);
  for(int i = 0; i < n; ++i) {
    compress[ys[i]] = i;
  }

  int res = 0;
  for(int i = 0; i < n; ++i) {
    res += std::abs(compress[xs[i]] - i) % 2;
  }
  printf("%d\n", res / 2);
  
  return 0;
}



Measured memory_bytes: 5760
sum  = 0
min1 = 101
min2 = 101
for i in range(4):
    n = int(input())
    sum += n
    if n < min1:
        min1 = n
for i in range(2):
    n = int(input())
    sum += n
    if n < min2:
        min2 = n
print(sum-min1-min2)

Measured memory_bytes: 7540
n,m,c = map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for i in range(n)]

ans=0
for i in range(n):
  tmp=c
  for j in range(m):
    tmp += a[i][j]*b[j]
  if tmp>0:
    ans += 1
print(ans)

Measured memory_bytes: 38384
def main():
    paramX = int(input())
    size = 200
    for a in range(size * -1, size):
        for b in range(size * -1, size):
            if pow(a, 5) - pow(b, 5) == paramX:
                print(a, b)
                return
    print(1, 1)
main()

Measured memory_bytes: 9172
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#define N 100020
using namespace std;

char a[N];
int f[N], g[N];
int q[N];

void Output(int x)
{
    if(!x)
        return;

    Output(g[x]);
    printf("%d ", x - g[x]);

    return;
}

int main(void)
{
    int n, m;
    int i, l, r;

    scanf("%d %d %s", &n, &m, a);
    f[0] = l = r = 0;
    q[r ++] = 0;
    for(i = 1; i <= n; i ++)
    {
        while(l < r && i - q[l] > m)
            l ++;
        if(l >= r || a[i] == '1')
            f[i] = n + 1;
        else
        {
            f[i] = f[q[l]] + 1;
            g[i] = q[l];
            while(l < r && f[q[r - 1]] > f[i])
                r --;
            q[r ++] = i;
        }
    }

    // for(i=1;i<=n;i++)cout<<g[i]<<' ';cout<<endl;

    if(f[n] == n + 1)
        printf("-1\n");
    else
    {
        Output(n);
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 3840