akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;

int main() {

	int n; 
	cin >> n;

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

	ll ans;
	ll cnt = 0;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		int sig = 1 - (i % 2) * 2;
		sum += a[i];
		
		if (sum * sig <= 0) {
			cnt += abs(sig - sum);
			sum = sig;
		}
	}
	
	ans = cnt;
	

	cnt = 0;
	sum = 0;
	for (int i = 0; i < n; i++) {
		int sig = -1 + (i % 2) * 2;
		sum += a[i];
		
		if (sum * sig <= 0) {
			cnt += abs(sig - sum);
			sum = sig;
		}
	}

	ans = min(ans, cnt);
	cout << ans << endl;

}


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

int main(){
  double x,h;
  while(1){
    cin>>x>>h;
    if(x==0)break;
    h=sqrt(h*h+(x/2)*(x/2) );
    printf("%lf\n",2*h*x+x*x);
  }
  return 0;
}

	

Measured memory_bytes: 3096
n = int(input())
h_list = list(map(int, input().split()))
cost_list = [0, abs(h_list[0] - h_list[1])]
for i in range(2, n):
    cost = min(abs(h_list[i-2] - h_list[i]) + cost_list[i-2], abs(h_list[i-1] - h_list[i]) + cost_list[i-1])
    cost_list.append(cost)
print(cost_list[-1])


Measured memory_bytes: 13980
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

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

ll cum[210000];
int a[210000];

int main(){
    int N;  cin >> N;
    fill(cum, cum+N, 0);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    cum[0] = 0;
    for(int i = 0; i <= N; i++){
        cum[i+1] = a[i] + cum[i];
    }

    int l = 0, r = 0;
    int cur = 0;
    ll res = 0;
    while(r < N){
        while(true) {
            // cout << l << " " << r << " " << ((cur ^ a[r]) == cum[r + 1] - cum[l])  << " " << res << endl;
            if ((cur ^ a[r]) == cum[r + 1] - cum[l]) {
                res += (r + 1 - l);
                cur ^= a[r];
                r++;
                break;
            }
            cur -= a[l];
            l++;
        }
    }

    cout << res << endl;



    return 0;

}



Measured memory_bytes: 2560
#include <iostream>

int main() {
    int i = 1;
    while (true) {
        int x;
        std::cin >> x;
        if (x == 0) {
            break;
        } else {
            std::cout << "Case " << i << ": " << x << std::endl;
            i++;
        }
    }
    return 0;
}



Measured memory_bytes: 2976
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n;
int arr[105];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	rep(x,0,n) cin>>arr[x];
	
	sort(arr,arr+n);
	
	int ans=0;
	rep(x,0,n){
		rep(y,x+1,n){
			rep(z,y+1,n){
				if (arr[x]!=arr[y] && arr[y]!=arr[z] && arr[x]+arr[y]>arr[z]) ans++;
			}
		}
	}
	
	cout<<ans<<endl;
	
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define INF 10000

int main()
{
  int h,w;cin>>h>>w;
  vector<vector<char>> s(h+2,vector<char>(w+2));
  int i,j;
  for(i=0;i<=h+1;i++)
  {
    for(j=0;j<=w+1;j++)
    {
      if(i==0||j==0||i==h+1||j==w+1)s.at(i).at(j)='#';
      else cin>>s.at(i).at(j);
    }
  }
  int ans=0;
  int si,sj;
  for(si=1;si<=h;si++)
  {
    for(sj=1;sj<=w;sj++)
    {
      if(s.at(si).at(sj)=='.')
      {
        vector<vector<int>> dist(h+2,vector<int>(w+2,-1));
        queue<pair<int,int>> q;
        queue<pair<int,int>> q2;
        q.push(make_pair(si,sj));
        dist.at(si).at(sj)=0;
        int dis=1;
        while(!q.empty())
        {
          while(!q.empty())
          {
            int nowi=q.front().first;
            int nowj=q.front().second;
            q.pop();
            if(s.at(nowi-1).at(nowj)=='.'&&dist.at(nowi-1).at(nowj)==-1)
            {
              q2.push(make_pair(nowi-1,nowj));
              dist.at(nowi-1).at(nowj)=dis;
            }
            if(s.at(nowi+1).at(nowj)=='.'&&dist.at(nowi+1).at(nowj)==-1)
            {
              q2.push(make_pair(nowi+1,nowj));
              dist.at(nowi+1).at(nowj)=dis;
            }
            if(s.at(nowi).at(nowj-1)=='.'&&dist.at(nowi).at(nowj-1)==-1)
            {
              q2.push(make_pair(nowi,nowj-1));
              dist.at(nowi).at(nowj-1)=dis;
            }
            if(s.at(nowi).at(nowj+1)=='.'&&dist.at(nowi).at(nowj+1)==-1)
            {
              q2.push(make_pair(nowi,nowj+1));
              dist.at(nowi).at(nowj+1)=dis;
            }
          }
          while(!q2.empty())
          {
            q.push(q2.front());
            q2.pop();
          }
          dis++;
        }
        int dmax=0;
        for(i=1;i<=h;i++)for(j=1;j<=w;j++)
        {
          if(dist.at(i).at(j)>dmax)dmax=dist.at(i).at(j);
        }
        ans=max(dmax,ans);
      }
    } 
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
t = 1; mod = 10**9 + 7
def gcd(a,b):
  while b: a,b = b,a%b
  return a
lcm = lambda a,b: a*b//gcd(a,b)
for x in l: t = lcm(t,x)
print(sum(t//x for x in l)%mod)

Measured memory_bytes: 4084
import itertools

n = int(input())
p = [tuple(map(int, input().split())) for i in range(1)]
q = [tuple(map(int, input().split())) for i in range(1)]

seq = (1, 2, 3, 4, 5, 6, 7, 8)
seq = seq[:n]

jun = list(itertools.permutations(seq, n))

print(abs(jun.index(p[0]) - jun.index(q[0])))


Measured memory_bytes: 44656
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

c=0

for i in range(n):
    if a[i]<b[i]:
        c+=min(a[i]+a[i+1],b[i])
        a[i+1]=max(a[i+1]+a[i]-b[i],0)        
    else:
        c+=b[i]

print(c)

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    int a, b, c; cin >> a >> b >> c;
    int x, y; cin >> x >> y;
    int ans = 0;
    while (a + b > c * 2 && x && y)
        x--, y--, ans += c * 2;
    // cout << x << y << endl;
    if (x && a > 2 * c) ans += c * 2 * x, x = 0;
    if (y && b > c * 2) ans += c * 2 * y, y = 0;
    
    // cout << x << y << endl;
    cout << ans + x * a + y * b << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<int>> a(y,vector<int>(x))
#define vec1(a,n) vector<in> a(n);rep(i,n)cin>>a[i]

int main(){
int n,y;cin>>n>>y;
  y /=1000;
  for(int man=0;man<=n;man++){
     for(int gosen=0;gosen<=n-man;gosen ++){
       int sen =n-man-gosen;
       if(y==10*man+5*gosen+sen){cout<<man<<" "<<gosen<<" "<<sen;return 0;}
     }
  }
  cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    print(max(B*(N-2) - A*(N-2) + 1, (ll)0));

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int N,K;
  cin>>N>>K;
  int V[N];
  REP(i,N) cin>>V[i];
  
  int ans=0;
  for(int p=0; p<=min(N,K); ++p){
    for(int q=0; p+q<=min(N,K); ++q){
      int cnt=0;
      vector<ll> L;
      for(int i=0; i<p; ++i){
        L.PB(V[i]);
        cnt+=V[i];
      }
      for(int i=0; i<q; ++i){
        L.PB(V[N-1-i]);
        cnt+=V[N-1-i];
      }
      
      SORT(L);
      
      for(int i=0; i<min(K-p-q,(int)L.size()); ++i){
        if(L[i]<0) cnt-=L[i];
      }
      chmax(ans,cnt);
    }
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    long long q, h, s, d, n, min=INF, min2=INF;

    cin >> q >> h >> s >> d >> n;

    q *= 4;
    h *= 2;

    chmin(min, q);
    chmin(min, h);
    chmin(min, s);

    chmin(min2, min*2);
    chmin(min2, d);

    if(n%2==0){
        cout << min2*n/2 << endl;
    }

    else{
        cout << min2*(n/2)+min << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int A, B;
    std::cin >> A >> B;
    if (A == B + 1 || A + 1 == B)
    {
        cout << A + B << endl;
    }
    else if (A == B)
    {
        cout << A * 2 << endl;
    }
    else if (A + A - 1 >= B + B - 1)
    {
        cout << A + A - 1 << endl;
    }
    else if (A + A - 1 <= B + B - 1)
    {
        cout << B + B - 1 << endl;
    }
}

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

long count = 0;

void Merge(long *A, long left, long mid, long right) {
  long n1,n2,*L,*R,i,j,k;
  n1 = mid -left;
  n2 = right - mid;
  L = (long*)malloc(sizeof(long) * (n1+1));
  R = (long*)malloc(sizeof(long) * (n2+1));
  for (i = 0; i< n1; i++) {
    L[i] = A[left+i];
  }
  for (i = 0; i < n2; i++) {
    R[i] = A[mid+i];
  }
  L[n1] = LONG_MAX; R[n2] = LONG_MAX;
  i = 0;j = 0;
  for(k = left; k < right; k++) {
    if (L[i] < R[j]) {
      A[k] = L[i];
      i++;
    }else {
      A[k] = R[j];
      j++;
    }
    count++;
  }
  free(L);
  free(R);
}

void Merge_Sort(long *A, long left, long right) {
  if(left+1 < right) {
    long mid = (left + right)/2;
    Merge_Sort(A,left,mid);
    Merge_Sort(A,mid,right);
    Merge(A,left,mid,right);
  }
}

int main()
{
  long i,n,*S;
  scanf("%ld", &n);
  S = (long*)malloc(sizeof(long) * n);
  for (i = 0; i < n; i++) {
    scanf("%ld", S+i);
  }
  Merge_Sort(S,0,n);
  for (i = 0; i < n-1; i++) {
    printf("%ld ", S[i]);
  }
  printf("%ld\n", S[i]);
  printf("%ld\n", count);
  return 0;
}

Measured memory_bytes: 8284
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  cout << N*(1+(N&1))<<endl;
  return 0;
}


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

int *numbers, *used, n;

void sequence(int m)
{
  int i;
  if (n==m) {
    for (i=0; i<n-1; i++)
      printf("%d ", numbers[i]);
    printf("%d\n", numbers[i]);
  } else {
    for (int i=0; i<n; i++) {
      if (used[i]) continue;
      numbers[m] = i+1;
      used[i]=1;
      sequence(m+1);
      used[i]=0;
    }
  }
}


int main()
{
  fscanf(stdin, "%d", &n);
  numbers = (int*)malloc(sizeof(int)*n);
  used = (int*)malloc(sizeof(int)*n);
  for (int i=0; i<n; i++)  used[i]=0;
  sequence(0);
}



Measured memory_bytes: 2104
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    vector<LLONG> as(N); for (auto &ai : as) cin >> ai;
    vector<LLONG> sums(N + 1, 0LL);
    for (int i = 1; i <= N; ++i)
    {
        sums[i] = sums[i - 1] + as[i - 1];
    }
    LLONG minDiff = 1e15;
    for (int i = 1; i < N; ++i)
    {
        LLONG x = sums[i] - sums[0];
        LLONG y = sums[N] - sums[i];
        minDiff = min(minDiff, llabs(x - y));
    }
    cout << minDiff << endl;
}

Measured memory_bytes: 3328
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int count = 0;

        for (int i = 1; i <= N; i++) {
            count += i;
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(count);

        sc.close();
        out.flush();
    }
}

Measured memory_bytes: 35688
// inputに入力データ全体が入る
function Main(original_input) {
 input = original_input.trim().split("\n");
 var k = parseInt(input[0], 10);
 var str ="";

 for(let i=1; i<k+1; i++){
  str += 'ACL';
 }
 console.log(str);
} 

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if l[i] == l[j] or l[j] == l[k] or l[k] == l[i]:
                continue
            hens = []
            hens.append(l[i])
            hens.append(l[j])
            hens.append(l[k])
            hens.sort()
            if hens[0] + hens[1] > hens[2]:
                cnt += 1

print(cnt)


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

#define INF 2000000000

int main(){

  int n,k;
  cin >> n >> k;

  vector<int> h(n);
  vector<int> dp(n,INF);
  dp[0]=0;

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

  for(int i=0;i<n;i++){
    if(i==n-1){
      cout << dp[n-1] << endl;
    }else{
      //i→i+j
      for(int j=1;j<=k;j++){
        if(i+j>n-1){
          break;
        }else{
          dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
      }
    }
  }
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] heightInfo = new int[n];
		for(int i =0;i < n;i++) {
			heightInfo[i] = sc.nextInt();
		}
		int[] badInfo = new int[n];
		for(int i =0;i <m;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(heightInfo[a-1] < heightInfo[b-1]) {
				badInfo[a-1]++;
			}
			if(heightInfo[a-1] > heightInfo[b-1]) {
				badInfo[b-1]++;
			}

			if(heightInfo[a-1] == heightInfo[b-1]) {
				badInfo[a-1]++;
				badInfo[b-1]++;
			}

		}
		int jogai = 0;
		for(int i = 0;i < n;i++) {
			if(badInfo[i] >0) {
				jogai++;
			}
		}

		System.out.println(n -jogai);
	}
}

Measured memory_bytes: 50520
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n, m;

	cin>>n>>m;

	cout<<(n-1)*(m-1)<<endl;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <sstream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

int main(){
    ll n;
    while(cin>>n && n){
        ll f=0, t=0;
        for(ll i=2; i<=n;i++){
            ll x=i;
            while(x%2==0){
                t++;
                x/=2;
            }
            while(x%5==0){
                f++;
                x/=5;
            }
        }
        cout << min(t,f) << endl;
    }
}

Measured memory_bytes: 1156
import sys
def input(): return sys.stdin.readline().strip()
n,k=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort(key=lambda x:x[0])
c=0
i=0
while True:
    if c<k and c+l[i][1]>=k:
        print(l[i][0])
        exit()
    else:
        c+=l[i][1]
        i+=1

Measured memory_bytes: 29144
#include <iostream>
#include <queue>
#include <map>

using namespace std;

typedef pair<int, int> P;

int n;
int fish[1000001];

int main() {
    cin >> n;

    priority_queue<P> pq;

    for(int i = 0; i < n; i++) {
        int a, v;
        cin >> a >> v;
        fish[a] += v;
        pq.push(P(fish[a], a * (-1)));
    }

    P p = pq.top();
    cout << p.second * (-1) << " " << p.first << endl;
    return 0;
}

Measured memory_bytes: 3136
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define ll long long 
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << endl;    
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
template <class X>
void printarr(X arr[], int n) 
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << ' ';
    cout << endl;
}
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
ll modulo = 1e9 + 7;
 
ll fpow(ll a, ll n) {
    ll ans = 1;
    while (n) {
        if (n&1) ans = (ans*a)%modulo;
        a = (a*a)%modulo; n = n >> 1;
    }
    return ans;
}
 
void solve() {
	ll n,k,s; cin >> n >> k >> s;
	ll arr[n];
	if (s == 1e9) {
		For(i,0,k) arr[i] = s;
		For(i,k,n) arr[i] = 1;
	}
	else {
		For(i,0,k) arr[i] = s;
		For(i,k,n) arr[i] = s+1;
	}
	printarr(arr,n);    
}
 
int main() {
    fast_io();
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define all(x)     (x).begin() , (x).end()
typedef long long int ll;
using namespace std;

const ll     mod = 1e9+7;
const double eps = 1e-9;


int h,w;
const int N=1002;
ll a[N][N],dp[N][N];

void solve(){
    cin >> h >> w;
    for(int i=1;i<=h;++i) {
        for(int j=1;j<=w;++j) {
            char t;
            cin >> t;
            a[i][j] = (t=='.'?1:0);
        }
    }
    bool flag=1;
    for(int i=1;i<=h&&flag;++i)
        if(a[i][1])
            dp[i][1]=1;
        else 
            flag=0;
    flag=1;
    for(int i=1;i<=w&&flag;++i) {
        if(a[1][i])
            dp[1][i]=1;
        else 
            flag=0;
    }

    for(int i=2;i<=h;++i) {
        for(int j=2;j<=w;++j) {
            if(!a[i][j])
                dp[i][j]=0;
            else 
                dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
        }
    }

    cout << dp[h][w] << "\n";

}


int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--)
        solve();
    return  0;
}


Measured memory_bytes: 19276
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* ]]] */

int n, l;
string s[100];

int main(){
  cin >> n >> l;
  rep(i, n) cin >> s[i];
  sort(s, s + n);
  rep(i, n) cout << s[i];
  cout << endl;
}



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

int main(){
  for(int i = 0; i < 4; i++){
    int t, n;
    cin >> t >> n;

    switch(t){
      case 1: cout << n * 6000 << endl; break;
      case 2: cout << n * 4000 << endl; break;
      case 3: cout << n * 3000 << endl; break;
      case 4: cout << n * 2000 << endl; break;
    }
  }
}

Measured memory_bytes: 1164
use whiteread::parse_line;

fn main() {
    let (n, m): (usize, usize) = parse_line().unwrap();
    let mut num: Vec<Option<u8>> = vec![None; n];

    for _ in 0..m {
        let (si, ci): (usize, u8) = parse_line().unwrap();
        if n != 1 && si == 1 && ci == 0 {
            println!("-1");
            return;
        }
        if let Some(c) = num[si - 1] {
            if ci != c {
                println!("-1");
                return;
            }
        } else {
            num[si - 1] = Some(ci);
        }
    }

    let mut num = num
        .iter()
        .map(|x| match x {
            Some(c) => *c,
            None => 0,
        })
        .collect::<Vec<_>>();
    if n != 1 && num[0] == 0 {
        num[0] = 1;
    }

    println!("{}", num.iter().fold(0_u32, |x, &y| x * 10 + y as u32));
}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, M;
vector<int> G[100100];
int dp[100100], nyu[100100];

signed main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        nyu[b]++;
        G[a].pb(b);
    }
    queue<int> que;
    for(int i = 0; i < N; i++){
        if(nyu[i] == 0){
            que.push(i);
        }
    }
    int ans = 0;
    while(que.size()){
        int pos = que.front();
        que.pop();
        for(int i = 0; i < G[pos].size(); i++){
            int to = G[pos][i];
            dp[to] = max(dp[to], dp[pos] + 1);
            ans = max(ans, dp[to]);
            nyu[to]--;
            if(nyu[to] == 0){
                que.push(to);
            }
        }
    }
    cout << ans << endl;

    return 0;
}
/*



*/



Measured memory_bytes: 7296
#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() {
    ll N, T; cin >> N >> T;
    ll X = 0;
    ll pt = -1;
    rep(i, N) {
        ll t; cin >> t;
        X += T;
        if(pt >= 0&&t-pt<T) X -= (pt+T-t);
        pt = t;
    }
    cout << X;
}


Measured memory_bytes: 256
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define INF (int)1e9 + (int)1e8
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    cpp();
    ll x;
    cin>>x;
    if(x>=30){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}






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

bool check(vector<int>& str){
    int l;
    l = str.size();
    /*
    for(int i=0;i<l;i++){
        cout << str[i] << " ";
    }
    cout << endl;
    */
    for(int i=0;i<l;i++){
        if(str[i] != str[0])
            return false;
    }
    return true;
}

int main(){
    string s;
    cin >> s;
    
    int l, ans, min = 100, l2;
    l = s.length();
    vector<int> str, shrink, tmp;
    for(int i=0;i<l;i++){
        str.push_back(s[i] - 'a');
    }
    for(int i=0;i<26;i++){
        ans = 0;
        shrink = str;
        l2 = l;
        while( !check(shrink) ){
            tmp = shrink;
            shrink.clear();
            for(int j=0;j<l2-1;j++){
                if(tmp[j] == i)
                    shrink.push_back(tmp[j]);
                else
                    shrink.push_back(tmp[j+1]);
            }
            l2--;
            ans++;
        }
        // cout << "ans = " << ans << " " << "min = " << min << endl;
        if(ans < min)
            min = ans;
    }
    
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define re return
#define ll long long
#define oo 1e9
#define mm(o,k) memset(o,k,sizeof o)
using namespace std;
ll m,n,k,a[500000],ans,x,z,o,zz,h;
string s;
int main()
{
     cin>>s;
     if (s.find('9')!=-1)cout<<"Yes";
     else cout<<"No";

    return 0;
}


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

using namespace std;

void move (vector <vector <int> >& curr, int j )
{
	int temp;

	switch (j){
		case 0: // North
			temp = curr[1][3];
			curr[1][3] = curr[0][1];
			curr[0][1] = curr[1][1];
			curr[1][1] = curr[2][1];
			curr[2][1] = temp;
			break;
		case 1: // East
			temp = curr[1][3];
			curr[1][3] = curr[1][2];
			curr[1][2] = curr[1][1];
			curr[1][1] = curr[1][0];
			curr[1][0] = temp;
			break;
		case 2: // South
			temp = curr[2][1];
			curr[2][1] = curr[1][1];
			curr[1][1] = curr[0][1];
			curr[0][1] = curr[1][3];
			curr[1][3] = temp;
			break;
		case 3: // West
			temp = curr[1][0];
			curr[1][0] = curr[1][1];
			curr[1][1] = curr[1][2];
			curr[1][2] = curr[1][3];
			curr[1][3] = temp;
			break;
		case 4: // Left
			temp = curr[1][2];
			curr[1][2] = curr[2][1];
			curr[2][1] = curr[1][0];
			curr[1][0] = curr[0][1];
			curr[0][1] = temp;
			break;
		case 5: // Right
			temp = curr[1][2];
			curr[1][2] = curr[0][1];
			curr[0][1] = curr[1][0];
			curr[1][0] = curr[2][1];
			curr[2][1] = temp;
			break;
	} // end switch
}
 	
int main()
{
	const string ope[] = { "North", "East", "South", "West", "Left", "Right" };
	const int init_pos[][4] = { {0, 5, 0, 0}, {4, 1, 3, 6}, {0, 2, 0, 0} };	//  expansion plan of dice

//	cut here before submit 
//	freopen ("testcase.dice3", "r", stdin );
	
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;
		if (n == 0 ){
			break;
		} // end if

		vector< vector <int> > curr_pos (3, vector<int> (4, 0 ) );
		int i,j;

		for (i = 0; i < 3; ++i){
			for (j = 0; j < 4; ++j){
				curr_pos[i][j] = init_pos[i][j];
			} // end for
		} // end for

		int res = curr_pos[1][1];

		for (i = 0; i < n; ++i){
			getline (cin, str );
			stringstream ss (str );
			ss >> str;
			for (j = 0; j < sizeof(ope)/sizeof(ope[0]); ++j){
				if (str == ope[j] ){
					move (curr_pos, j );
					break;
				} // end if
			} // end for
			res += curr_pos[1][1];
		} // end for
		cout << res << endl;
	} // end loop
		
	return 0;
}

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

const int mod = 1e9+7;

int32_t main(){

    int w , a , b;  cin >> w >> a >> b;

    if(b <= a+w and a+w <= b+w){
        cout << 0;
    }else if(b+w >= a and b <= a){
        cout << 0;
    }else{
        int one = abs(b - a - w);
        int two = abs(b+w - a);

        cout << min(one , two) << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 aa, bb;
	cin >> aa >> bb;
	for(int64 ii = 1;ii < 1100;ii++)
	{
		if(ii * 2 / 25 == aa && ii / 10 == bb)
		{
			cout << ii << endl;
			return 0;
		}
	}
	puts("-1");
	return 0;
}


Measured memory_bytes: 3644
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	
	N := ScanInt(scanner)
	L := make([]int, 2 * N)
	for i := 0; i < 2 * N; i++ {
	    L[i] = ScanInt(scanner)
	}
	sort.Sort(sort.IntSlice(L))
	
	ans := 0
	for i := 0; i < 2 * N; i += 2 {
	    ans += L[i]
	}
	fmt.Println(ans)
}

func ScanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func ScanFloat64(scanner *bufio.Scanner) float64 {
	scanner.Scan()
	f, e := strconv.ParseFloat(scanner.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func ScanText(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func Max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Abs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

Measured memory_bytes: 640
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda x: [ni() for _ in range(x)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

from collections import deque

n = ni()
ab = nan(n - 1)

to = [[] for i in range(n)]
for i in range(n - 1):
    a, b = ab[i][0] - 1, ab[i][1] - 1
    to[a].append(b)
    to[b].append(a)

q = deque()
q.append((0, 0, -1))
color = 0
d = dict()
m = 0
while len(q):
    p = q.pop()
    j = 0
    for i in to[p[0]]:
        if i == p[2]:
            continue
        j += 1
        if j == p[1]:
            j += 1
        m = max(m, j)
        q.append((i, j, p[0]))
        d[(p[0], i)] = j

print(m)
for i in range(n - 1):
    print(d[(ab[i][0] - 1, ab[i][1] - 1)])

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

constexpr int inf = 1e9;

int main() {
    int n;
    cin >> n;
    vector<int> coin = {1};
    for(int i = 6; i <= n; i *= 6) {
        coin.push_back(i);
    }
    for(int i = 9; i <= n; i *= 9) {
        coin.push_back(i);
    }
    vector<int> dp(n + 1, inf);
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        for(auto c : coin) {
            if(c + i <= n) {
                dp[i + c] = min(dp[i + c], dp[i] + 1);
            }
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 640
import math
from math import pi
import numpy

mNum = map(int, input().split())
lNum = list(mNum)

minRad = 2 * pi * lNum[3] / 60
hourRad = 2 * pi * (lNum[2] * 60 + lNum[3]) / 720

minHand = numpy.array([lNum[1] * math.cos(minRad), lNum[1] * math.sin(minRad)])
hourHand = numpy.array([lNum[0] * math.cos(hourRad), lNum[0] * math.sin(hourRad)])

length = numpy.linalg.norm(hourHand - minHand)

print(length)

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

public class Main {

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String[] strArray = br.readLine().split("\\s");
            int[] intArray = new int[5];
            int w,h,x,y,r;
            
            for (int i = 0; i < strArray.length; i++) {
                intArray[i] = Integer.valueOf(strArray[i]);
            }
            
            w = intArray[0];
            h = intArray[1];
            x = intArray[2];
            y = intArray[3];
            r = intArray[4];
            
            if(r <= x & x <= h-r & r <= y & y <= h-r){
                System.out.println("Yes");
            }else{
            	System.out.println("No");
            }
        } catch (IOException e) {
            System.err.println(e);
        }

    }
}

Measured memory_bytes: 17060
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int r, g; cin >> r >> g;
    cout << 2 * g - r << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    ll A[n][n];
    rep(i,n) rep(j,n) cin>>A[i][j];
    vector<pair<ll,pair<int,int>>> v;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            v.push_back({A[i][j],{i,j}});
        }
    }
    sort(all(v));
    reverse(all(v));
    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=A[i][j];
        }
    }

    for(auto p : v){
        ll c=p.first;
        int a=p.second.first;
        int b=p.second.second;
        if(A[a][b]==INF) continue;

        rep(i,n){
            if(i!=a && i!=b && A[a][i]!=INF && A[i][b]!=INF){
                if(A[a][i]+A[i][b]==c){
                    ans-=c;
                    A[a][b]=A[b][a]=INF;
                    break;
                }
                else if(A[a][i]+A[i][b]<c){
                    cout<<-1<<endl;
                    return 0;
                }
            }
        }

        
    }

    cout<<ans<<endl;

}


 

Measured memory_bytes: 2040
fun main(arr:Array<String>) {
    val q = readLine()!!.toInt()
    val ans = (1..q).map { readLine()!!.split(" ").map { it.toLong() }.sorted().let { getAns(it[0], it[1]) }}
    ans.forEach { println(it) }
}

fun getAns(a:Long, b:Long):Long {
    if(b-a <= 1) {
        return (a-1)+(a-1)
    }
    val c = sqrt(a*b-1, 1, Math.min(a*b-1, 1e9.toLong()))
    if(c*(c+1) >= a*b) {
        return 2*c-2
    }
    return 2*c-1
}

fun sqrt(num:Long, min:Long, max:Long):Long {
    if(max - min <= 1) {
        if(max*max <= num) {
            return max
        } else {
            return min
        }
    }
    val mid = (max+min)/2
    val tmp = mid*mid
    if(tmp > num) {
        return sqrt(num, min, mid)
    } else if(tmp < num) {
        return sqrt(num, mid, max)
    }
    return mid
}


Measured memory_bytes: 35980
n, p = map(int,input().split())
if n == 1:
    print(p)
    exit()
l = int((p + 1) ** 0.5)
k = p
rom = [0] * l
for i in range(100):
    if k % 2 == 0:
        k = k // 2
        rom[1] += 1
    else:
        break

for i in range(3, l+1, 2):
    while k % i == 0:
        k = k // i
        rom[i-1] += 1

ans = 1
for i in range(l):
    if rom[i] >= n:
        ans *= (i+1) ** (rom[i] // n)
print(ans)


Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
int N, A[100];

void Out() {
	cout << A[0];
	for (int i = 1; i < N; i++)
		cout << ' ' << A[i];
	cout << endl;
}

void InsertionSort() {
	for (int i = 1; i < N; i++) {
		int v = A[i], j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		Out();
	}
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A[i];
	Out();
	InsertionSort();
	return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b;
	cin>>a>>b;
	int ans=0;
	if(a>=13)
	{
		ans=b;
	}
	else if(a>=6 && a<=12)
	{
		ans=b/2;
	}
	else
	{
		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll MOD = 1e9 + 7;
#define rep(i,k) for(int i=0;i<k;i++)
ll n, i, j, k, o, p, l, z,x,y,h,w,sa=0;
ll a[200010], b[200010], inf = 1000000000000;
map <ll, ll> cnt;
l_l pp;
string s;
vector<pair<ll, ll>> m;

int main() {
	cin >> h>>w>>n;
	z = 0;
	if (n == 0) {
		cout << (h - 2) * (w - 2)<<"\n";
		rep(i, 9)cout << 0 << "\n";

		return 0;
	}
	rep(i, n) {
		cin >> o >> p;
		rep(j, 3) {
			ll gg = p - 1 + j;
			rep(k, 3) {
				ll rr = o - 1 + k;
				if ((rr > 1 && rr < h) && (gg > 1 && gg < w)) {
				//	cout << " " << rr << " " << gg << "\n";
					pp = make_pair(rr, gg);
					m.push_back(pp);
				}
			}
		}
	}
	sort(m.begin(), m.end());
	pp = m[0]; z = 1;
	for (i = 1; i < m.size();i++) {
		if (pp == m[i])z++;	
		else {
			a[z]++;
			sa++;
			z = 1;
		}
		pp = m[i];
	}
	a[z]++;
	sa++;


	cout << ((h-2)*(w-2)-sa)<<"\n";
	rep(i, 9)cout << a[i + 1]<<"\n";
	


	
}

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

vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}
 
int main() {
  int N;
  int sum=0;
  cin >> N;
  vector<int> A;
  A = input(N);
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  for (int i = 0; i < A.size(); i++) {
    if (i%2 == 0){//0の時奇数
      sum += A[i];
    }
    else{
      sum -= A[i];
    }
  }
  cout << sum << endl;
}

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

struct Data{
  int depth;
  string comment;
  Data(int d,string c):depth(d),comment(c){}
};

int main(){
  int n;
  while(cin>>n,n){
    vector<Data> v;
    v.reserve(n);
    for(int i=0;i<n;i++){
      string str;
      cin>>str;
      int t = 0;
      while(str[t] == '.') t++;
      v.push_back(Data(t,str.substr(t)));
    }
    cout<<v[0].comment<<endl;
    for(int i=1;i<n;i++){
      for(int j=1;j<v[i].depth;j++){
	bool flg = false;
	for(int k=i+1;k<n;k++){
	  if(v[k].depth == j){
	    flg = true;
	    break;
	  }
	  if(v[k].depth == j-1) break;
	}
	if(flg) cout<<'|';
	else cout<<' ';
      }
      cout<<'+'<<v[i].comment<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1320
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn = new Scanner(System.in);
        long n = stdIn.nextLong();
        long k = stdIn.nextLong();
        
        System.out.println(Math.min(n % k, k - (n % k)));
        
    }
}


Measured memory_bytes: 22996
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Score = Tuple!(long, "p", long, "c");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto n = lread();
    auto a = aryread();
    auto z = new long[](1);
    a = z ~ a ~ z;
    auto changes = new long[](n);
    long cost;
    foreach (i; iota(1, n + 1))
    {
        changes[i - 1] = abs(a[i + 1] - a[i - 1]) - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]);
        cost += abs(a[i] - a[i - 1]);
    }
    cost += abs(a[$ - 2]);
    foreach(e; changes)
    {
        writeln(cost + e);
    }
}


Measured memory_bytes: 7688
#include<stdio.h>
#include<algorithm>
using namespace std;
struct node{
	int u;
	long long d;
	bool operator<(node b) const
	{
		return d<b.d;
	}
};
node nn[131072];
int size[131072],fa[131072],d[131072];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		nn[i].u=i;
		scanf("%lld",&nn[i].d);
		size[i]=1;
	}
	sort(nn+1,nn+n+1);
	for(int i=n;i>1;i--)
	{
		int l=1,r=i-1;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(nn[mid].d==nn[i].d+size[i]-(n-size[i]))
			{
				fa[i]=mid;
				break;
			}
			if(nn[mid].d>nn[i].d+size[i]-(n-size[i]))
			{
				r=mid-1;
			}
			else
			{
				l=mid+1;
			}
		}
		if(!fa[i])
		{
			printf("-1\n");
			return 0;
		}
		size[fa[i]]+=size[i];
	}
	long long sd=0;
	for(int i=2;i<=n;i++)
	{
		d[i]=d[fa[i]]+1;
		sd+=d[i];
	}
	if(sd!=nn[1].d)
	{
		printf("-1\n");
		return 0;
	}
	for(int i=2;i<=n;i++)
	{
		printf("%d %d\n",nn[fa[i]].u,nn[i].u);
	}
	return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;

ll  S;

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

  cin >> S;
  ll M = 1000000000;
  ll x0 = 0;
  ll y0 = S / M;
  ll x1 = M;
  ll y1 = min(M, y0 + 1);
  ll x2 = S - y0 * M;
  ll y2 = 0;
  cout << x0 << " ";
  cout << y0 << " ";
  cout << x1 << " ";
  cout << y1 << " ";
  cout << x2 << " ";
  cout << y2;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 256