akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	l <- readLn :: IO Double
	let x = (l / 3) ^ 3
	putStrLn $ showFFloat Nothing x ""


Measured memory_bytes: 508
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;


int main(){
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, n)cin >> a[i];
   int now = INF;
   ll res = 1000;
   rep(i, n){
      if(i == 0)now = a[i];
      else {
         if(now < a[i]){
            res = (res / now) * a[i] + res % now;
            now = a[i];
         }
         else {
            now = a[i];
         }
      }
     //cout << res << endl;
   }
   cout << res << endl;
}


Measured memory_bytes: 3624
import java.util.*;

public class Main{
    final int mx = 50001;
    boolean[] prm;

    void mkPrm(){
	prm = new boolean[mx];
	for(int i = 2; i < mx; i++)
	    prm[i] = true;
	prm[0] = prm[1] = false;

	for(int i = 2; i < mx; i++)
	    if(prm[i])
		for(int j = i+i; j < mx; j += i)
		    prm[j] = false;

	return ;
    }

    Main(){
	Scanner sc = new Scanner(System.in);
	mkPrm();

	while(sc.hasNext()){
	    int n = sc.nextInt(), cnt = 0;
	    if(n == 0) break;

	    for(int i = 2; i <= n/2; i++)
		if(prm[i] && prm[n-i]) cnt++;

	    System.out.println(Integer.toString(cnt));
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define f(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define ppi pair<int,pair<int,int> >
#define ll long long
#define pb push_back
#define mk make_pair
int i=0;int j=0;
int main()
{
 
     string str;cin>>str;
     int n=str.size();
     if(str[n-1]=='s')
     cout<<str<<"es"<<"\n";
     else
     cout<<str<<"s"<<"\n";
     
 
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
//const int mod = 1e9 + 7;
const int mod = 998244353;

int main(){
    ll n; cin >> n;
    vpl plus, minus;
    rep(i,n){
        string s; cin >> s;
        ll cnt = 0;
        ll mn = inf, mx = -inf;
        rep(j,s.size()){
            if(s[j]=='(') cnt++;
            else cnt--;
            chmin(mn,cnt);
        }
        if(cnt >= 0) plus.emplace_back(mn,cnt);
        else minus.emplace_back(cnt-mn,mn);
    }
    sort(rall(plus));
    sort(rall(minus));
    ll cnt = 0;
    rep(i,plus.size()){
        if(-plus[i].first > cnt){
            puts("No");
            return 0;
        }
        cnt += plus[i].second;
    }
    rep(i,minus.size()){
        if(-minus[i].second > cnt){
            puts("No");
            return 0;
        }
        cnt += minus[i].second + minus[i].first;
    }
    if(cnt != 0){
        puts("No");
    }else{
        puts("Yes");
    }
}

Measured memory_bytes: 18984
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<utility>

using namespace std;


const int MAXL = 301;


pair<string, int> getLCS(string s1, string s2) {
  int L1 = (int) s1.size(), L2 = (int) s2.size();
  s1 = " " + s1;
  s2 = " " + s2;
  vector<vector<int> > D(s1.size(), vector<int>(s2.size(), 0));
  vector<vector<string> > common_subs(s1.size(), vector<string>(s2.size(), ""));

  for (size_t i = 1; i < s1.size(); ++i) {
    for (size_t j = 1; j < s2.size(); ++j) {
      if (s1[i] == s2[j]) {
        D[i][j] = D[i-1][j-1] + 1;
        common_subs[i][j] = common_subs[i-1][j-1] + s1[i];
      }
      else {
        D[i][j] = max(D[i-1][j], D[i][j-1]);
        if (D[i-1][j] > D[i][j-1]) common_subs[i][j] = common_subs[i-1][j];
        else common_subs[i][j] = common_subs[i][j-1];
      }
    }
  }

  return make_pair(common_subs[L1][L2], D[L1][L2]);
}


void solve(string s) {
  int len = (int) s.size();
  
  string ans = "";
  int max_l = 0;
  for (int k = 1; k < len; ++k) {
    string sub1 = s.substr(0, k);
    string sub2 = s.substr(k, len-k);

    if ((int) min(sub1.size(), sub2.size()) <= max_l) continue;

    pair<string, int> res;
    res = getLCS(sub1, sub2);
    if (res.second > max_l) {
      ans = res.first;
      max_l = res.second;
    }
  }

  printf("%s\n", ans.c_str());
}


int main() {
  char s[MAXL];

  while (scanf("%s", s) != EOF) {
    if (strcmp(s, "#END") == 0) break;

    solve(s);
  }
  return 0;
}



Measured memory_bytes: 5364
//碁石は白→黒…、黒→白…の塊の先頭でしか
//色を変える操作は起こりえない。
//また、色を変えるときには、塊ごと色が変わる。
#include<iostream>
using namespace std;

int N;
int stone[100000];
int sento;
int taba[100000];
int first[100000];

int main(){
	int i,j,tcorsole,ccorsole = 0;
	int count[1000] = {0};
	while(1){
		tcorsole = 0;
		cin >> N;
		if(N == 0)
			break;
		for(i = 0;i < N;i++){
			cin >> stone[i]; 
			taba[i] = 1;
		}
		sento = stone[0];
		first[0] = 0;
		for(i = 0;i < N-1;i++){
			if(stone[i+1] == stone[i]){
				taba[tcorsole]++;
			}
			else{
				tcorsole++;
				first[tcorsole] = i+1;
			}
		}
		//もちろん碁石をひっくり返す順番は昇順
		for(i = 1;i <= tcorsole;i++){
			if(first[i]%2 == 0)
				continue;
			//碁石を同じ色の石があるとこまでひっくり返す
			for(j = i-1;j >= 0;j--){
				if((i-j)%2 == 0){
					if(taba[j] != 0)
						break;
				}
				else{
					taba[i] += taba[j];
					taba[j] = 0;
				}
			}
		}
		for(i = 0;i <= tcorsole;i++){
			if((i+sento)%2 == 0)
				count[ccorsole] += taba[i];
		}
		ccorsole++;
	}
	for(i = 0;i < ccorsole;i++){
		cout << count[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 2148
k = int(input())
checked = [False] * k

surplus = 0
ans = 1
while 1:
    surplus = ((surplus * 10) + 7) % k
    if checked[surplus]:
        print(-1)
        exit()
    if surplus == 0:
        break
    checked[surplus] = True
    ans += 1

print(ans)


Measured memory_bytes: 16696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll L;
    ll ans = 0;
    cin >> L;
    long double a = (long double)L / 3;
    cout << fixed << setprecision(20) << a*a*a << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){
  
  int n;
  cin >> n;
  ll ry[100];
  ry[0] = 2;
  ry[1] = 1;
  for(int i = 2;i <= 86;i++){
    ry[i] = ry[i-1]+ry[i-2];
  }
  cout << ry[n] << endl;



  
  


  return 0;
}


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

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

  double L;
  cin >> L;

  double max_vol = 0;
  for(double i = 0.000001; i <= L / 3; i += 0.000001) {
    max_vol = max(max_vol, (i * i * (L - i - i)));
  }

  cout << setprecision(10) << max_vol << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        StringBuffer sb = new StringBuffer();

        for(int i=0; i<s.length(); i++) {
            String l = String.valueOf(s.charAt(i));
            if(l.equals("0") || l.equals("1")) {
                sb.append(l);
            } else if(l.equals("B") && sb.length() > 0) {
                sb.deleteCharAt(sb.length() - 1);
            }
        }

        System.out.println(sb.toString());

        in.close();
    }
}


Measured memory_bytes: 9300
#include <iostream>
using namespace std;
typedef unsigned long long u64;

u64 binpow(u64 n, u64 x, u64 mod)
{
  u64 tgt = 1;
  u64 dig = n;
  while (x > 0) {
    if (x%2) {
      tgt = (tgt * dig) % mod;
    }
    dig = (dig * dig) % mod;
    x /= 2;
  }
  return tgt;
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  u64 n;
  cin >> n;
  u64 ab[n+1];
  for (u64 i = 0; i <= n; ++i) {
    ab[i] = 0;
  }
  int p = (n-1)%2;
  for (u64 i = 0; i < n; ++i) {
    u64 a;
    cin >> a;
    ab[a]++;
    if (ab[a] > 2 || a%2 != p || ab[0] > 1) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << binpow(2, n/2, 1000000007) << endl;
  return 0;
}


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

const int N = 100 * 1000 + 5;
int n, a[N], b[N];

int main()
{
    cin >> n;
    for(int i=1; i<=n; ++i) scanf("%d",a+i);
    for(int i=1; i<n; ++i) {
        if (a[i] > a[i+1]){
            int j = i-1;
            while (b[j] == 0 && a[j] == a[i]) --j;
            if (a[j] < a[i]) a[i] -= 1, b[i] = 1;
        }
        if (a[i] > a[i+1]) {puts("No"); return 0;}
    }
    puts("Yes");

}


Measured memory_bytes: 1024
import java.util.*;
public class Main
{
 static int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
  
  public static void main(String []args)
  {
    Scanner sc = new Scanner(System.in);
    int n = 1000000;
    int prime[] = new int[n+1]; 
        for(int i=0;i<n;i++) 
            prime[i] = i; 
          
        for(int p = 2; p*p <=n; p++) 
        { 
            // If prime[p] is not changed, then it is a prime 
            if(prime[p] == p) 
            { 
                // Update all multiples of p 
                for(int i = p*p; i <= n; i += p) 
                    prime[i] = p;
            } 
        }
    
    int k = sc.nextInt();
    int arr[] = new int[k];
    arr[0] = sc.nextInt();
    int gg = arr[0];
    for(int i = 1 ; i < k ; i++)
    {
      arr[i] =  sc.nextInt();
      gg = gcd(gg,arr[i]);
    }
    if(gg > 1)
      System.out.println("not coprime");
    
    else
    {
      boolean pr[] = new boolean[1000001];
      boolean bl = true;
      for(int i = 0 ; i < k ; i++)
      {
        while(arr[i] > 1)
        {
          int x = prime[arr[i]];
          if(pr[x] == true)
          {
            bl = false;
            break;
          }
          
          else
          {
            pr[x] = true;
            while(arr[i]%x == 0)
            {
              arr[i] = arr[i]/x;
            }
              
          }
        }
      }
      if(bl)
        System.out.println("pairwise coprime");
      
      else
        System.out.println("setwise coprime");
    }
    
  }
}

Measured memory_bytes: 65656
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n;
  std::cin >> n;
  vt<int> a(1e5);

  rep(i,n) {
    int p1;
    std::cin >> p1;
    a[p1]++;
  }

  int ans = 0;
  for (int i = 0; i < 1e5-2; i++) {
    int tmp = a[i]  + a[i+1] + a[i+2];
    if(ans < tmp)
      ans = tmp;
  }



  std::cout << ans << '\n';
  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  int M = nextInt();

  map<int,int> count;
  REP(i, N) {
    int K = nextInt();
    REP(_, K) {
      int a = nextInt();
      ++count[a];
    }
  }

  int ans = 0;
  for (auto it = count.begin(); it != count.end(); ++it) {
    if (it->second == N) ++ans;
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main()
{
	int a,b;
	cin>>a>>b;
	
	int p,m,t;
	p=a+b;
	m=a-b;
	t=a*b;
	
	cout<<max(max(p,m),max(m,t))<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Good" : "Bad") << endl
int main()
{
    string s;cin >> s;
    bool Good = true;
    for(int i = 0;i < 4;i++)
    {
        if(i == 3)
        {

        }
        else
        {
            if(s[i] == s[1 + i])
            {
                Good = false;
            }
        }
        
    }
    Yes(Good);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];
    sort(a,a+n);
    ll roop=(n-2)/2;
    ll res=(n-2)%2;
    ll ans=0;
    for(ll i=n-1;i>=n-1-roop;i--){
        if(i==n-1){
            ans+=a[i];
        } 
        else ans+=a[i]*2;
    }
    if(res==1)ans+=a[n-2-roop];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> gr[100005];
ll ans=0;
ll dfs(ll curr,vector<ll> &dp)
{
	ll d=0;
	if(dp[curr]!=-1)
		return dp[curr];
	for(auto it:gr[curr])
	{
		d=max(d,dfs(it,dp));
	}
	return dp[curr]=1+d;
}
int main()
{
	ll n,m,x,y;
	cin>>n>>m;
	vector<ll> dp(n+1,-1);
	for(ll i=0;i<m;i++)
	{
		cin>>x>>y;
		gr[x].push_back(y);
	}
	for(ll i=1;i<=n;i++)
	{
		ans=max(ans,dfs(i,dp));
	}
	cout<<ans-1;
}

Measured memory_bytes: 11640
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,d,p,x,y;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> p;
	x = p*a;
	if(c<p)	y = b+(p-c)*d;
	else	y=b;
	cout << min(x,y) << endl;
	return 0;
}


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

int n, m;
int town[1000];
int day[1000];
int dp[1001][1001];
int INF = 999999999;

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> town[i];
	for (int i = 0; i < m; i++) cin >> day[i];

	for (int i = 0; i <= m; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			dp[i][j] = INF;
		}
	}

	dp[0][0] = 0;

	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (dp[i][j] == INF) continue;
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + town[j] * day[i]);
		}
	}

	int ans = INF;
	for (int i = 0; i <= m; i++)
	{
		ans = min(ans, dp[i][n]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5080
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define ll int long long
 main()
{
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll ini=a[0],sum=0;
    for(ll i=0;i<n;i++){
        if(a[i]<ini){
            sum+=(ini-a[i]);
            ini=max(a[i],ini);
        }
        else{
            ini=a[i];
        }
    }
    cout<<sum;
	
}

Measured memory_bytes: 5152
#include<stdio.h>
#include<string.h>

int main(void) {
    int a,b;
    scanf("%d%d",&a,&b);
    int n = 1;
    int m = 0;
    while(n < b) {
        n += a-1;
        m++;
    }
    printf("%d\n",m);
}

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

#define len(s) int(s.size())
#define res(x) cout<<((x) ? "Yes" : "No")
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define st first
#define nd second

typedef long long int ll;
typedef long double ld;

int main() {
	
	int n;
	cin >> n;
	
	map<string, int> m;
	string s;
	while(n--) {
		cin >> s;
		++m[s];
	}
	
	cout << "AC x " << m["AC"] << endl;
	cout << "WA x " << m["WA"] << endl;
	cout << "TLE x " << m["TLE"] << endl;
	cout << "RE x " << m["RE"] << endl;
	
	return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc, out);

		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		
		int res = 0;
		
		for(int i = 0; i <= a; i++) {
			for(int j = 0; j <= b; j++){
				for(int k = 0; k <= c; k++) {
					if(i*500+j*100+k*50==x) {
						res++;
					}
				}
			}
		}
		out.println(res);
	}
	
	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 22868
object Main extends App {
  val array: Array[Long] = readLine().split(' ').map(_.toLong)
  val A = array(0)
  val B = array(1)
  val K = array(2)

  val (a, b) = if (A + B <= K) {
    (0, 0)
  } else if (A >= K) {
    ((A - K), B)
  } else {
    (0, (A + B - K))
  }
  println(s"$a $b")
}

Measured memory_bytes: 25556
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll A,B;
int main(){
    cin>>A>>B;
    for(ll i=B*10;i<(B+1)*10;i++){
        if(A <= i*0.08 && i*0.08 < A+1){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int n, a, b;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> a >> b;
    int d = b - a;
    if (d % 2)
        return cout << "Borys", 0;
    else
        return cout << "Alice", 0;
}


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

int main() {
double N,K;
  cin >> N >> K;
  
  double a;
  vector<double> retu(N);
  for(int i = 0; i < N; i++){
  	cin >> a;
    retu.at(i) = a+1;
  }
  
  double mm = 0;
  for(int i = 0; i < K; i++){
  	mm += retu.at(i);
  }
  //これでmmはまずi = 0からK個の期待値の和
  vector<double> kitai(N);
  kitai[0] = mm;
  for(int i = 0; i < N-K; i++){
  	kitai.at(i+1) = kitai.at(i) - retu.at(i) + retu.at(i+K);
    mm = max(mm, kitai.at(i+1));
  }
/*  for(int i = 0; i < N+1-K; i++){
  	cout << kitai.at(i) << endl;
  }
*/
  cout << fixed << setprecision(12) << mm/2 << endl;
}


Measured memory_bytes: 3328
N = int(input())
tell = []
f = True
last = ""
for i in range(N):
    W = input()
    if i != 0 and W[0] != last:
        f = False
        break
    elif i != 0 and W in tell:
        f = False
        break
    last = W[-1]
    tell.append(W)
if f:
    print("Yes")
else:
    print("No")



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

using namespace std;

typedef long long LL;

int n,m,a[1005],sum;

int main()
{
	cin>>n>>m;
	for (int i=1;i<=n;++i) cin>>a[i],sum+=a[i];
	sort(a+1,a+n+1);
	bool flag=true;
	for (int i=n;i>=n-m+1;--i)
	{
		if (a[i]*4*m<sum) flag=false;
	}
	if (flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;
    vector<ll> a(87);
    a[0] = 2;
    a[1] = 1;
    for (int i = 2; i < 87; ++i)
        a[i] = a[i - 1] + a[i - 2];
    cout << a[n];
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Beginner068
{
    public class ABC068C_CatSnukeandaVoyage
    {
        public static void Main(string[] args)
        {

            int[] nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = nums[0];
            int m = nums[1];

            List<int> edge1 = new List<int>();
            List<int> edge2 = new List<int>();

            for(int i=0; i<m;i++)
            {
                nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

                if(nums[0] == 1)
                {
                    edge1.Add(nums[1]);
                }
                if(nums[1] == n)
                {
                    edge2.Add(nums[0]);
                }
            }

            if(edge1.Intersect(edge2).Count() == 0)
            {
                Console.WriteLine("IMPOSSIBLE");
            }
            else
            {
                Console.WriteLine("POSSIBLE");
            }

        }
    }
}

Measured memory_bytes: 23312
N, M = list(map(int, input().split()))
a = [int(input()) for i in range(M)] + [10**20]

dp = [1] + [0 for i in range(N+2)]

next_a = a.pop(0)

for i in range(N):
    if next_a == i:
        dp[i] = 0
        next_a = a.pop(0)
    else:
        dp[i+1] += dp[i]
        dp[i+2] += dp[i]
print(dp[N]%1000000007)


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

int main() {
    int N;
    bool flag = false;
    char c;
    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> c;
        if (c == 'Y') flag = true;
    }
    if (flag)
        cout << "Four" << endl;
    else
        cout << "Three" << endl;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, t = MAP()

print(max(0, X-t))


Measured memory_bytes: 5328
#include <bits/stdc++.h>
#define ll long long
const ll MOD = 1e9 + 7;
using namespace std;
int main(){
	int N;
	cin >> N;
        ll pairs[N];	
	for(int i = 0; i < N; ++i){
		cin >> pairs[i];
	}
	ll Sum1 = pairs[N-1] % MOD;
	ll Sum2 = 0;
	for(int i = N-2; i >= 0; --i){
		Sum2+=((pairs[i]%MOD)*(Sum1%MOD))%MOD;
		Sum1+=pairs[i]%MOD;
	}
	cout << Sum2 % MOD;
}


Measured memory_bytes: 5192
#include<stdio.h>

void trace(int r[100], int n)
{
    int i;

    for(i = 0; i < n; i++){

        if(i > 0) printf(" ");

        printf("%d", r[i]);
    }
    printf("\n");
}

void co(int c){

    printf("%d\n", c);
}

void bubblesort(int r[100], int n)
{
    int i, j, a;
    int count = 0;
    int flag = 1;

    while(flag){
        flag = 0;
        for(j = n-1; j >= 1; j--){
            if(r[j] < r[j-1]){
                a       = r[j];
                r[j]    = r[j-1];
                r[j-1] = a;
                flag = 1;
                count++;
            }
        }
    }
    trace(r,n);
    co(count);
}              
int main()
{
    int a,  i,  j, n, r[100];

    scanf("%d", &n);

    for(i = 0; i < n; i++){

        scanf("%d", &r[i]);

    }

    bubblesort(r, n);

   
    return 0;
}


Measured memory_bytes: 1984
a,b,c,d=[int(_) for _ in input().split()]
if c%b!=0:
    count_1=c//b+1
else:
    count_1=c//b
if a%d!=0:
    count_2=a//d+1
else:
    count_2=a//d

if count_1<=count_2:
    ans='Yes'
else:
    ans='No'
print(ans)

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define itr(itr, map) for (auto itr = map.begin(); itr != map.end(); ++itr)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, w, c;
    cin >> N;
    vector<int> v(N);
    rep(i,N) {
        cin >> w;
        v[i] = w;
    }
    sort(v.rbegin(), v.rend());
    w = -1;
    c = 0;
    rep(i,N) {
        if(v[i] != w) {
            c++;
            w = v[i];
        }
    }
    cout << c << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin >>a>>b>>c;
  if(a>b){
    d=a;
    a=b;
    b=d;
  }
  if(b>c){
    d=b;
    b=c;
    c=d;
  }
   if(a>b){
    d=a;
    a=b;
    b=d;
  }
  cout<<a<<" "<<b<<" "<<c<<"\n";

  return 0;
}

Measured memory_bytes: 1164
# -*- coding: utf-8 -*-

n,m = map(int,input().split() )
b = [0]*m
for i in range(n):
	a = list(map(int, input().split()))
	for j in range(1, len(a)):
		b[a[j]-1] += 1
ans = b.count(n)
print(ans)



Measured memory_bytes: 2940
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<vector>
using namespace std;
int n,E[300010],W[300010],mn=1e9;
string s;
int main()
{
	cin>>n>>s;
	if (s[0]=='E') E[0]++;
	for (int i=1;i<n;i++){
		E[i]=E[i-1];
		if (s[i]=='E') E[i]++;
	}
	if (s[n-1]=='W') W[n-1]++;
	for (int i=n-2;i>=0;i--){
		W[i]=W[i+1];
		if (s[i]=='W') W[i]++;
	}
	for (int i=1;i<n;i++){
		mn=min(mn,abs(i-E[i-1])+abs(W[i+1]-n+i)-1);
	}
	mn=min(mn,abs(W[0]-n));
	cout<<mn<<endl;
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int main(){
    int a[6];
    for (int i = 0; i < 6; i++) {
        cin >> a[i];
    }
    bool ans = true;
    for (int i = 0; i < 5; i++) {
        for (int j = i+1; j < 5; j++) {
            if (abs(a[i] - a[j]) > a[5] ) ans = false;
        }
    }
    if (ans) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}



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

int main()
{
    int n, hi, ans;
    double t, a, e = 1000;
    cin >> n >> t >> a;
    for(int i = 0; i < n; i++){
        cin >> hi;
        double dif = fabs((t - hi*0.006) - a);
        if(dif < e) e = dif, ans = i;
    }
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,m,ans;
vector<int>g[55];
bool vis[55];
int ord[55],low[55];
void dfs(int v,int p,int k){
    vis[v]=true;
    ord[v]=k++;
    low[v]=ord[v];
    for(int i=0;i<g[v].size();i++){
        if(!vis[g[v][i]]){
            dfs(g[v][i],v,k);
            low[v]=min(low[v],low[g[v][i]]);
            if(ord[v]<low[g[v][i]])ans++;
        }else if(g[v][i]!=p){
            low[v]=min(low[v],ord[g[v][i]]);
        }
    }
}
int main(void){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int s,t;
        cin>>s>>t;
        g[--s].push_back(--t);
        g[t].push_back(s);
    }
    for(int i=0;i<n;i++)vis[i]=false;
    dfs(0,-1,0);
    cout<<ans<<endl;
}

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

// CGL_1_A
C projection(C p, C p1, C p2) {
    return C(((p-p1) / (p2-p1)).real(), 0.0) * (p2-p1) + p1;
}

void solve_CGL_1_A() {
    int x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    C p1(x1,y1), p2(x2,y2);
    int q;
    std::cin >> q;
    rep(i,q) {
        int x, y;
        std::cin >> x >> y;
        C p = C(x,y);
        C res = projection(p, p1, p2);
        printf("%.20lf %.20lf\n", res.real(), res.imag());
    }
}

// CGL_1_B
C reflection(C p, C p1, C p2) {
    return std::conj(((p-p1) / (p2-p1))) * (p2-p1) + p1;
}

void solve_CGL_1_B() {
    int x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    C p1(x1,y1), p2(x2,y2);
    int q;
    std::cin >> q;
    rep(i,q) {
        int x, y;
        std::cin >> x >> y;
        C p = C(x,y);
        C res = reflection(p, p1, p2);
        printf("%.20lf %.20lf\n", res.real(), res.imag());
    }
}

int main() {
    solve_CGL_1_B();
}



Measured memory_bytes: 3232
using System;
using System.Collections.Generic;

public class AtCoderB
{
    static void Main()
    {
        int n;
        int d;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            d = int.Parse(words[1]);
        }

        int[,] map = new int[n, d];
        for (int i = 0; i < n; i++)
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            for (int j = 0; j < d; j++)
            {
                map[i, j] = int.Parse(words[j]);
            }
        }

        int answer = 0;

        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                int sum = 0;
                for (int k = 0; k < d; k++)
                {
                    sum += (map[i, k] - map[j, k]) * (map[i, k] - map[j, k]);
                }
                double sqrt = Math.Sqrt(sum);
                int sq = (int)Math.Floor(sqrt);
                if (sq * sq == sum)
                {
                    answer++;
                }
            }
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 11092
N, K, C = map(int, input().split())
S = input()

if N==1:
  print(1)
  exit()

Af = [0]*N
Rf = [0]*N
d = 0
f = 0
for i, s in enumerate(S):
    f-=1
    if s=='o' and f<0:
        d+=1
        f=C
    Af[i]=d
    Rf[i]=C-f

Ab = [0]*N
Rb = [0]*N
d = 0
f = 0
for i, s in enumerate(S[::-1]):
    f-=1
    if s=='o' and f<0:
        d+=1
        f=C
    Ab[N-i-1]=d
    Rb[N-i-1]=C-f

if Ab[1]<K:
    print(1)

for i in range(1, N-1):
    if Af[i-1]+Ab[i+1]>K: continue
    if Af[i-1]+Ab[i+1]==K and Rf[i-1]+Rb[i+1]+1>=C: continue
    print(i+1)

if Af[-2]<K:
    print(N)


Measured memory_bytes: 23764
# 青 > 緑 > 赤
def main():
    red,green,blue = map(int,input().split())
    k = int(input())
    while k > 0:
        k -= 1
        if green <= red:
            green *= 2
        else:
            blue *= 2

    if blue > green and green > red:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int K;
    string S;
    cin >> K >> S;
    int slen = (int) S.size();

    if (slen <= K) {
        cout << S << endl;
    } else {
        for (int i = 0; i < K; i++) {
            cout << S[i];
        }
        cout << "..." << endl;
    }

    return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <algorithm>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")

const int H_MAX = 300;
const int W_MAX = 300;
const int Q_MAX = 100000;
const int N_MAX = H_MAX * W_MAX;
const int N_LOG = 16;

int H, W, D;
int A[H_MAX][W_MAX];
int Q;
int L[Q_MAX];
int R[Q_MAX];

int N;
int h[N_MAX];
int w[N_MAX];
int m[N_LOG + 1][N_MAX];

void solve() {
  N = H * W;
  REP(i, H) REP(j, W) {
    h[A[i][j] - 1] = i;
    w[A[i][j] - 1] = j;
  }
  REP(i, N - D) {
    m[0][i] = abs(h[i] - h[i + D]) + abs(w[i] - w[i + D]);
  }

  int d = D;
  REP(j, N_LOG) {
    REP(i, N - d) {
      m[j + 1][i] = m[j][i] + m[j][i + d];
    }
    d *= 2;
    if (d >= N) break;
  }

  // DUMP2D(m, 5, N);

  REP(i, Q) {
    int ans = 0;
    int f = L[i] - 1, t = R[i] - 1;
    int l = (t - f) / D;
    int k = 0, d = D;
    while (l > 0) {
      if (l & 1) {
        ans += m[k][f];
        f += d;
      }
      l /= 2;
      k++;
      d *= 2;
    }
    printf("%d\n", ans);
  }
}

void input() {
  scanf("%d%d%d", &H, &W, &D);
  REP(i, H) REP(j, W) scanf("%d", &A[i][j]);
  scanf("%d", &Q);
  REP(i, Q) scanf("%d%d", L + i, R + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 8832
N = int(input())
S = []
for i in range(N):
  S.append(''.join(sorted(input())))

import collections
import math

c = collections.Counter(S)
ans = 0
for i in c.values():
    if i == 1:
      continue
    else:
      ans += i*(i-1)//2
print(int(ans))
    
  


Measured memory_bytes: 68312
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000000;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> A(N, vector<int>(N));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      cin >> A[i][j];
    }
  }
  long long ans = 0;
  bool ok = true;
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      bool use = true;
      for (int k = 0; k < N; k++){
        if (k != i && k != j && A[i][j] == A[i][k] + A[k][j]){
          use = false;
        }
        if (A[i][j] > A[i][k] + A[k][j]){
          ok = false;
        }
      }
      if (use){
        ans += A[i][j];
      }
    }
  }
  if (!ok){
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 3984
N = gets.to_i
A = gets.split.map(&:to_i)

nums = A.map(&:abs)
min_v = nums.min

0.upto(N - 2) do |i|
  if A[i] < 0
    A[i] = -A[i]
    A[i + 1] = -A[i + 1]
  end
end

last = A[-2..-1]

if last.include?(0)
  puts nums.inject(:+)
elsif last.inject(:*) < 0
  puts nums.inject(:+) - 2 * min_v
else
  puts nums.inject(:+)
end


Measured memory_bytes: 9476
#include <stdio.h>

int main(void){
  int i,e;
  static int n[26];
  char st,al[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
  do{
    e = scanf("%c", &st);

    for(i=0;i<52;i++)
      if(al[i] == st){
        n[ i%26 ]++;
      }

  }while(e != EOF);

  for(i=0;i<26;i++)
    printf("%c : %d\n", al[i] , n[i]);

  return 0;
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
int main()
{
    string s;
    cin>>s;
    int cnt=0;
    int len=s.length();
    int x=len/2;
    for(int i=0;i<x;++i)
    {
        if(s[i]!=s[len-i-1])
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

using Graph = vector<vector<int>>;
int N,Q;
Graph G;

void dfs(int v,int p,vector<long long> &res){
    if(p != -1)res[v] += res[p];
    for(auto e:G[v]){
        if(e == p) continue;
        dfs(e,v,res);
    }
}

int main(){
    cin >> N >> Q;
    G.assign(N,vector<int>());
    for(int i = 0; i < N - 1;i++){
        int a,b;
        cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<long long> val(N,0);
    for(int i = 0; i < Q;i++){
        int p,x;
        cin >> p >> x;
        --p;
        val[p]+=x;
    }
    dfs(0,-1,val);
    for(auto v:val)cout << v <<" ";
    cout <<endl;
}

Measured memory_bytes: 24320
#include<iostream>
using namespace std;
int main()
{
  int n,m;
  cin >> n >> m;
  float arr[n],sum=0;
  int count=0;
  for(int i=0;i<n;i++)
  {
    cin >> arr[i];
    sum += arr[i];
  }
  float k = 4*m;
  for(int i=0;i<n;i++)
  {
    if(arr[i] >= sum/k  )
      count ++;
  }
  if(count >= m)
    cout << "Yes";
  else
    cout << "No";
}


Measured memory_bytes: 256
# https://img.atcoder.jp/abc138/editorial.pdf
# https://www.youtube.com/watch?v=lWETOlGiuaI
# このコードは公式解説動画をまんまpythonにしたものです。

# 解説動画
# s = abacaababc (10文字)の場合は
# a: [0, 2, 4, 5, 7, 10, 12, 14, 15, 17]
# b: [1, 6, 8, 11, 16, 18]
# c: [3, 9, 13, 19]
# という二重配列をまず作る。

# 例えばt = 'bbcca'だと
# 現在位置0、bを探す→1
# 現在位置1、bを探す→6
# 現在位置6、cを探す→9
# 現在位置9、cを探す→13(3に戻す)
# 現在位置3、aを探す→4
# で答えは14。


# 解説pdf曰く：
# next(ch, i):=「s'のi文字目以降で文字種chが最初に現れる位置」を
# をO(文字種数×|S|)かけて事前に全て求める

# 文字の先頭に戻る可能性があるので、2回連結しておくと処理が楽になる

from bisect import bisect_left

s = input()
t = input()
n = len(s)
m = len(t)

index_list = [[] for _ in range(26)]

for i in range(n):
    index_list[ord(s[i]) - ord('a')].append(i)
for i in range(n):
    index_list[ord(s[i]) - ord('a')].append(i+n)

p = 0  # p以降
ans = 0
for j in range(m):
    ch = ord(t[j]) - ord('a')
    if len(index_list[ch]) == 0:
        # t内に出現する文字が、sに全く登場しないので、不可
        print(-1)
        exit()
    next_pos = bisect_left(index_list[ch], p)
    p = index_list[ch][next_pos] + 1
    if p >= n:
        p -= n
        ans += n
    # print(p)

ans += p
print(ans)



Measured memory_bytes: 11892
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    cout << (n-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        int max=0,k=0;
        int game=0;
        int[][] g=null;
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null) {
            	if(first){
            		game=Integer.parseInt(line);
            		g=new int[game][3];
            		first=false;
            	}else{
            		String[] str=line.split(" ");
            		for(int i=0;i<3;i++){
            			g[k][i]=Integer.parseInt(str[i]);
            		}
            		k++;
                    if(game==k){
                        break;
                    }
            	}
            }
            int[] result=new int[game];
            int[] store;
            for(k=0;k<3;k++){
            	store=new int[game];
            	for(int j=0;j<game;j++){
            		for(int l=j+1;l<game;l++){
            			
                		if(g[j][k]==g[l][k]){
                			store[j]=-1;
                			store[l]=-1;
                		}
                	}
            	}
            	for(int l=0;l<game;l++){
        			if(store[l]!=-1){
        				result[l]+=g[l][k];
        			}
        			if(k==2){
        				System.out.println(result[l]);
        			}
        		}
            }
        }
    }

}

Measured memory_bytes: 24812
from copy import deepcopy
from collections import deque
from itertools import product
import numpy as np
inputs = open(0).readlines()
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, row in zip(range(h), grid):
            for j, val in zip(range(w), row):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, row)) for row in self.grid])
    def __getitem__(self, x):
        return self.grid[x]
    def __setitem__(self, x, val):
        self.grid[x] = val
        
h, w = map(int, inputs[0].split())
grid_origin = Grid(inputs[1:], function=lambda x: int(x == '.'))

def bfs(root):
    x, y, _ = root
    grid[y, x] = 0
    queue = deque([root])
    while queue:
        x, y, d = queue.popleft()
        for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
            if grid.is_valid_xy(x+dx, y+dy) and grid[y+dy, x+dx]:
                queue.append((x+dx, y+dy, d+1))
                grid[y+dy, x+dx] = 0
    return d
    
ans = 0
for i, j in product(range(h), range(w)):
    if grid_origin[i, j]:
        grid = deepcopy(grid_origin)
        ans = max(ans, bfs((j, i, 0)))
print(ans)

Measured memory_bytes: 12532