akhauriyash/Code-Regression huggingface dataset:
import copy
n=int(input())
a=input().split(" ")
count = 0
t=True
while t:
  b=[]
  for j in a:
    if int(j)%2 == 0:
      b.append(int(j)/2)
    elif int(j)<2:
      t=False
    else:
      t=False
  if t==False:
    break
  count = count+1
  a=copy.deepcopy(b)
print(count)


Measured memory_bytes: 3444
n=int(input())
c=list(map(str, input().split()))

def bubble(c:list, n:int) -> str:
    if not isinstance(c, list):
        return None

    for i in range(n):
        for j in range(n-1, i, -1):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j]

    return " ".join(c)

def selection(c:list, n:int) -> str:
    if not isinstance(c, list):
        return None

    for i in range(n):
        minj=i
        for j in range(i, n):
            if c[j][1] < c[minj][1]:
                minj=j
        c[i], c[minj] = c[minj], c[i]

    return " ".join(c)
d = c[:]
bub=bubble(c, n)
print(bub)
print("Stable")
sel=selection(d, n)
print(sel)
if sel == bub:
    print("Stable")
else :
    print("Not stable")


Measured memory_bytes: 5608
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        int to = ((int)(s[i] - 'A') + n) % 26;
        s[i] = 'A' + to;
    }
    cout << s << endl;
    return 0;
}

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

int main()
{
	int h, w;
	bool b[500][500];

	cin >> h >> w;

	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			int a;
			cin >> a;
			b[i][j] = a % 2;
		}

	bool f = 0;
	vector<int> p, q, r, s;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w - 1; j++) {
			if (i % 2 == 0) {
				if ((!f && b[i][j]) || (f && !b[i][j])) {
					p.push_back(i + 1);
					q.push_back(j + 1);
					r.push_back(i + 1);
					s.push_back(j + 2);
					f = 1;
				}
				else if (f && b[i][j])
					f = 0;
			}
			else if (i % 2 == 1) {
				if ((!f && b[i][w - j - 1]) || (f && !b[i][w - j - 1])) {
					p.push_back(i + 1);
					q.push_back(w - j);
					r.push_back(i + 1);
					s.push_back(w - j - 1);
					f = 1;
				}
				else if (f && b[i][w - j - 1])
					f = 0;
			}
		}

		if (i % 2 == 0 && i < h - 1) {
			if ((!f && b[i][w - 1]) || (f && !b[i][w - 1])) {
				p.push_back(i + 1);
				q.push_back(w);
				r.push_back(i + 2);
				s.push_back(w);
				f = 1;
			}
			else if (f && b[i][w - 1])
				f = 0;
		}
		else if (i % 2 == 1 && i < h - 1) {
			if ((!f && b[i][0]) || (f && !b[i][0])) {
				p.push_back(i + 1);
				q.push_back(1);
				r.push_back(i + 2);
				s.push_back(1);
				f = 1;
			}
			else if (f && b[i][0])
				f = 0;
		}
	}

	cout << p.size() << endl;

	for (int i = 0; i < p.size(); i++)
		cout << p[i] << " " << q[i] << " " << r[i] << " " << s[i] << endl;

	return 0;
}


Measured memory_bytes: 4452
import sys
import bisect
MAX_INT = int(10e12)
MIN_NUM = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def distance(list, index, x):
  res = abs(x - list[index][0])
  return res

def distance2(list, index, x):
  res = abs(x - list[index])
  return res

# 二分探索 #
def nibutan(list,n):
    left = -1
    right = len(list)
    while left+1 != right:
        middle = (left+right)//2
        if list[middle][0] <= n:
            left = middle
        else:
            right = middle
    return right

A,B,Q = IL()
a = [I() for i in range(A)] # 0
b = [I() for i in range(B)] # 1
q = [I() for i in range(Q)]
ab = []

a.sort()
b.sort()

for i in a:
  ab.append([i,0])
for i in b:
  ab.append([i,1])
ab.sort()

for x in q:
  ans = MAX_INT
  ID = nibutan(ab, x)
  for i in [-1,0]:
    if 0 <= ID+i < len(ab):
      if ab[ID+i][1] == 0: # a → b
        for j in [-1,0]:
          ID2 = bisect.bisect_left(b, ab[ID+i][0])
          if 0 <= ID2+j < len(b):
            dis = distance(ab, ID+i, x)
            dis += distance2(b, ID2+j, ab[ID+i][0])
            ans = min(ans, dis)
      else: # b → a
        for j in [-1,0]:
          ID2 = bisect.bisect_left(a, ab[ID+i][0])
          if 0 <= ID2+j < len(a):
            dis = distance(ab, ID+i, x)
            dis += distance2(a, ID2+j, ab[ID+i][0])
            ans = min(ans, dis)
  print(ans)

Measured memory_bytes: 101456
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        double a = sc.nextInt();
        int b = sc.nextInt();
        double x = sc.nextInt();

        double res;
        if(x >= a * a * b / 2) {
            double y = (a * a * b - x) / a / a * 2;
            res = Math.atan2(y, a);
        } else {
            double y = (x / a / b) * 2;
            res = Math.atan2(b, y);
        }
        System.out.println(res / Math.PI / 2 * 360);
    }
}


Measured memory_bytes: 21844
import Text.Printf
main = do
  ab_in <- (return . words) =<< getLine
  let a:b:[] = map (read::String->Integer) ab_in
  let (d,r) = a `divMod` b
  let f = (fromIntegral a / fromIntegral b) :: Double
  --putStrLn (show d ++ " " ++  show r ++ " " ++ show f)
  printf "%d %d %.10f" d r f



Measured memory_bytes: 4032
INF = 1000000000
N, K = list(map(int, input().split()))
items = list(map(int, input().split()))

mi = INF

for l_index in range(N-K+1):
  left = items[l_index]
  right = items[l_index+K-1]

  if right <= 0:
    mi = min(mi, 0-left)
  elif left >= 0:
    mi = min(mi, right)
  else:
    min_l = min(0-left, right)
    mi = min(mi, (0-left) + right + min_l)

print(mi)

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int r, c, n;
    cin >> r >> c >> n;
    
    VVP g(r + c);
    
    FOR(_,1,n) {
        int x, y, val;
        cin >> x >> y >> val; x--; y--;
        
        g[x].pb({r + y, val});
        g[r + y].pb({x, val});
    }
    
    VL value(r + c, -1);
    VVI component;
    
    queue <int> q;
    
    FOR(i,0,r+c-1) if (value[i] == -1) {
        component.emplace_back();
    
        q.push(i);
        value[i] = 0;
        
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            
            component.back().pb(v);
            
            for (auto e : g[v]) {
                int u = e.st;
                int newValue = e.nd - value[v];
                
                if (value[u] != -1 && value[u] != newValue) {
                    cout << "No";
                    return 0;
                }
                
                if (value[u] == -1) {
                    value[u] = newValue;
                    q.push(u);
                }
            }
        }
    }
    
    for (auto &c : component) {
        ll minRow = LINF;
        ll minCol = LINF;
        
        for (int v : c) {
            if (v < r) {
                minRow = min(minRow, value[v]);
            } else {
                minCol = min(minCol, value[v]);
            }
        }
        
        if (minRow + minCol < 0) {
            cout << "No";
            return 0;
        }
    }
    
    cout << "Yes";

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 19380
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
#define LINEY "YES\n"
#define Liney "Yes\n"
#define LINEN "NO\n"
#define Linen "No\n"

//R*r + G*g + B*b = N

int main(){
  int R,G,B,N; cin >>R>>G>>B>>N;
  int count = 0;
  REP(r,N/R+1){
    REP(g,N/G+1){
      int temp = N-r*R-g*G;
      if( temp%B==0 && temp/B>=0 ){count++;}
      else if(temp<0){break;}
    }
  }
  printf("%d\n",count);
}

Measured memory_bytes: 256
n = int(input())
Hs = list(map(int,input().split()))
f = [0 for _ in range(n)]
c = 0
r = 0
while r != n:
    r = 1
    for i in range(n):
        if f[i] < Hs[i] :
            if r > 0:
                c += 1
            r = 0
            f[i] += 1
        else:
            r += 1
    r -= 1   
print(c)

Measured memory_bytes: 9188
input_lines = gets.to_i
input_lines.times{
  res = "YES"
  b = []
  c = []
  b.push(0)
  c.push(0)
  s = gets.chomp.split(" ")
  s.map! {|x| x.to_i}
  s.each do |y|
   if b.last < y then
     b.push(y)
   elsif c.last < y then
     c.push(y)
   else
     res = "NO"
     break
   end
  end
puts res
}

Measured memory_bytes: 6104
#import 
#=input()
#=int(input())
n,d=map(int,input().split())
#=list(map(int,input().split()))
#xy=[list(map(int,input().split())) for _ in range(n)]

cnt = 0
d **= 2
for i in range(n):
    x,y = map(int,input().split())
    q = x ** 2 + y ** 2
    if q <= d:
        cnt += 1
print(cnt)

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int, int> pii;
const int mod = (int)1e9 + 7;


int main()
{

	//cin.tie(0); ios_base::sync_with_stdio(false);
	
	string mt[]={"dreamer", "eraser", "dream","erase"};
	int mc[] = {7,6,5,5};
	string s;
	cin >>s;
	
	int n=sz(s);
	
	for(int nxt=1; nxt;){
		nxt=0;
		rep(i,4){
			if(sz(s)>= mc[i] && s.substr(sz(s)-mc[i])==mt[i]){
				s=s.substr(0,sz(s)-mc[i]);
				nxt=1;
				break;
			}
		}
		if(sz(s)==0){puts("YES");return 0;}
		//cout << s <<"  ";
	}
	puts("NO");
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  int m[10005],e[10005],j[10005];
  char cl[10005];
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>m[i]>>e[i]>>j[i];
      int ave=(m[i]+e[i]+j[i])/3;
      if(max(max(m[i],e[i]),j[i])==100 || (m[i]+e[i])/2>=90 || ave>=80){
	cl[i]='A';
      }else if(ave>=70 || (ave>=50 && max(m[i],e[i])>=80)){
	cl[i]='B';
      }else{
	cl[i]='C';
      }
    }
    
    for(int i=0;i<n;i++){
      cout<<cl[i]<<"\n";
    }
  }
  return 0;
}



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

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { for (auto& _e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(8); } } pre__;

int main(void) {
	int N;
	cin >> N;
	vec<int> h(N);
	for (int i = 0; i < N; ++i) {
		cin >> h[i];
	}
	vec<int> dp(N + 10, 0);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < N; ++i) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxs = 797161, maxl = (int)2e5 + 1;
int n, tot, out[maxs];
struct TrieNode {
	int idx, tag, ch[3];
} p[maxs];
int main() {
	static char buf[maxl];
	scanf("%d%s", &n, buf);
	++tot;
	int sta = 0, pw = 1;
	for(int i = 0; i < n; ++i, sta += pw, pw *= 3)
		for(int j = 0; j < pw; ++j) {
			TrieNode &cur = p[sta + j];
			for(int k = 0, adt = 0; k < 3; ++k, adt += pw) {
				p[tot].idx = cur.idx + adt;
				cur.ch[k] = tot++;
			}
		}
	auto expand = [&](int rt) {
		TrieNode &cur = p[rt];
		if(cur.tag) {
			swap(cur.ch[1], cur.ch[2]);
			for(int i = 0; i < 3; ++i)
				p[cur.ch[i]].tag ^= 1;
			cur.tag = 0;
		}
	};
	for(int i = 0; buf[i]; ++i) {
		if(buf[i] == 'S') {
			p[0].tag ^= 1;
			continue;
		}
		for(int j = 0, rt = 0; j < n; ++j) {
			expand(rt);
			TrieNode &cur = p[rt];
			rotate(cur.ch, cur.ch + 2, cur.ch + 3);
			rt = cur.ch[0];
		}
	}
	function<void(int, int, int, int)> dfs = [&](int dep, int rt, int pw, int val) {
		TrieNode &cur = p[rt];
		if(dep == n) {
			out[cur.idx] = val;
		} else {
			expand(rt);
			int npw = pw * 3;
			dfs(dep + 1, cur.ch[0], npw, val);
			dfs(dep + 1, cur.ch[1], npw, val += pw);
			dfs(dep + 1, cur.ch[2], npw, val += pw);
		}
	};
	dfs(0, 0, 1, 0);
	for(int i = 0; i < pw; ++i)
		printf("%d%c", out[i], " \n"[i == pw - 1]);
	return 0;
}

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

int main(){
    string S;
    cin >> S;

    int ans = 10000; 


    for(int i=0; i+2<S.size(); i++){
        int a = S[i] - '0';
        int b = S[i+1] -'0';
        int c = S[i+2] -'0';
        int val = a*100 + b*10 +c;
        if(ans > abs(val-753)){
            ans = abs(val-753);
        }
        
    }

    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(string S)
        {
            int N = S.Length;
            var dp = new long[N + 1][];
            dp[N] = new long[4];
            dp[N][3] = 1;
            for (int i = N - 1; i >= 0; --i)
            {
                dp[i] = new long[4];
                if (S[i] == 'A' || S[i] == '?') { dp[i][0] = dp[i + 1][1]; }
                if (S[i] == 'B' || S[i] == '?') { dp[i][1] = dp[i + 1][2]; }
                if (S[i] == 'C' || S[i] == '?') { dp[i][2] = dp[i + 1][3]; }
                for (int j = 0; j < 4; ++j)
                {
                    dp[i][j] += (S[i] == '?') ? dp[i + 1][j] * 3 : dp[i + 1][j];
                    dp[i][j] %= 1000000007;
                }
            }
            return dp[0][0];
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Solve(Read()));
        }
    }
}


Measured memory_bytes: 24412
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int q = in.nextInt();
		PriorityQueue<Long> sita = new PriorityQueue<>((e1,e2)->e1>e2?-1:1);
		PriorityQueue<Long> ue = new PriorityQueue<>((e1,e2)->e1<e2?-1:1);
		long sita_sum = 0;
		long ue_sum = 0;
		long b_sum = 0;
		for(int i=0;i<q;i++) {
			if(in.nextInt()==1) {
				long a = in.nextInt();
				long b = in.nextInt();
				b_sum += b;
				if(sita.isEmpty()&&ue.isEmpty()) {
					sita.add(a);
					sita_sum += a;
				}
				else if(ue.isEmpty()) {
					if(a<sita.peek()) {
						long tmp = sita.poll();
						ue.add(tmp);
						ue_sum += tmp;
						sita.add(a);
						sita_sum += a - tmp;
					}else {
						ue.add(a);
						ue_sum += a;
					}
				}
				else {
					if(sita.size()>ue.size()) {
						if(a<sita.peek()) {
							long tmp = sita.poll();
							ue.add(tmp);
							ue_sum += tmp;
							sita.add(a);
							sita_sum += a - tmp;
						}else {
							ue.add(a);
							ue_sum += a;
						}
					}else if(sita.size()==ue.size()) {
						if(a<=ue.peek()) {
							sita.add(a);
							sita_sum += a;
						}else {
							long tmp = ue.poll();
							sita.add(tmp);
							sita_sum += tmp;
							ue.add(a);
							ue_sum += a - tmp;
						}
					}
					
				}
			}else {
				if(sita.size()==ue.size()) {
					System.out.println(sita.peek()+" "+(ue_sum-sita_sum+b_sum));
				}else {
					System.out.println(sita.peek()+" "+(ue_sum-sita_sum+sita.peek()+b_sum));
				}
				
			}
		}
		in.close();

	}

}


Measured memory_bytes: 156808
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> a;
  while (1) {
    n /= a;
    ans++;
    if (n == 0) break;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 256
import java.io.*;import java.util.*;import java.util.function.*;public class Main{public static void main(String[] args)throws IOException{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));int n=Integer.parseInt(br.readLine());Map<String,Long> mp=new HashMap<>();Consumer<String>fun=(s)->mp.put(s,mp.getOrDefault(s,0L)+ 1L);for(int i=0;i<n;i++)fun.accept(Arrays.toString(br.readLine().chars().mapToObj(it->(char) it).sorted().toArray()));System.out.println(mp.values().stream().mapToLong(it->it*(it-1)/2).sum());}}

Measured memory_bytes: 96400
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int ans=0;
int n = Integer.parseInt(sc.next());
for (int i = 1; i <= n; i++) {
    ans+=800;
    if(i%15==0)ans-=200;
}
    out.println(ans);
}}

Measured memory_bytes: 23764
import java.util.*;
import java.io.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static String[] readLine = new String[2];
	static boolean A = true, B = false, C = false, temp = false;
	static char condition1, condition2;
	public static void main(String[] args) {
		while(read()){
			slove();
		}
		print();
	}
	static boolean read(){
		if(!sc.hasNext())return false;
		readLine = sc.next().split(",");
		condition1 = readLine[0].charAt(0);
		condition2 = readLine[1].charAt(0);
		return true;
	}
	static void slove(){
		if(condition1 == 'A' && condition2 == 'B'){
			temp = A; A = B; B = temp;
		}else if(condition1 == 'A' && condition2 == 'C'){
			temp = A; A = C; C = temp;
		}else if(condition1 == 'B' && condition2 == 'C'){
			temp = B; B = C; C = temp;
		}else if(condition1 == 'B' && condition2 == 'A'){
			temp = B; B = A; A = temp;
		}else if(condition1 == 'C' && condition2 == 'A'){
			temp = C; C = A; A = temp;
		}else if(condition1 == 'C' && condition2 == 'B'){
			temp = C; C = B; B = temp;
		}
	}
	static void print(){
		if(A == true){
			System.out.println("A");
		}else if(B == true){
			System.out.println("B");
		}else if(C == true){
			System.out.println("C");
		}
	}
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n,a,b,c;
    map<char,int> abc;
    
    cin>>n>>a>>b>>c;
    abc['A']=a;
    abc['B']=b;
    abc['C']=c;
    vc<string> str(n);
    rep(i,n)cin>>str[i];
    str.push_back("xx");

    if(abc['A']+abc['B']+abc['C']==0){
        cout<<"No\n";
        return 0;
    }

    string ans="";
    if(abc['A']+abc['B']+abc['C']==1){
        rep(i,n){
            if(abc[str[i][0]]+abc[str[i][1]]==0){
                cout<<"No\n";
                return 0;
            }
            if(abc[str[i][0]]){
                ans.push_back(str[i][1]);
                abc[str[i][1]]++;
                abc[str[i][0]]--;
            }else{
                ans.push_back(str[i][0]);
                abc[str[i][0]]++;
                abc[str[i][1]]--;
            } 
        }
    }else{
        //最初2つとも0
        if(abc[str[0][0]]==0 && abc[str[0][1]]==0){
            cout<<"No\n";
            return 0;
        }
        rep(i,n){
            //0の文字が1つえらばれてたら
            if(abc[str[i][0]]==0){
                ans.push_back(str[i][0]);
                abc[str[i][0]]++;
                abc[str[i][1]]--;
            }else if(abc[str[i][1]]==0){
                ans.push_back(str[i][1]);
                abc[str[i][1]]++;
                abc[str[i][0]]--;
            }
            //0の文字がえらばれてなかったら
            else{
                if(str[i+1][0]==str[i][0] || str[i+1][1]==str[i][0]){
                    ans.push_back(str[i][0]);
                    abc[str[i][0]]++;
                    abc[str[i][1]]--;
                }else{
                    ans.push_back(str[i][1]);
                    abc[str[i][1]]++;
                    abc[str[i][0]]--;
                }
            }
        }
    }
    
    cout<<"Yes\n";
    rep(i,ans.length()){
        cout<<ans[i]<<"\n";
    }

    return 0;
}

Measured memory_bytes: 9608
#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    n = int(input())
    p = list(map(int, input().split()))
    count = 0
    for i in range(n):
        if p[i] != i + 1:
            count += 1
    if count <= 2:
        print('YES')
    else:
        print('NO')
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<long long>A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  vector<long long>B1(N);
  vector<long long>B2(N);
  B1.at(0)=A.at(0);
  B2.at(0)=(-1)*A.at(0);
  for(int i=0;i<N-2;i++){
    B1.at(i+1)=max(B1.at(i)+A.at(i+1),B2.at(i)-A.at(i+1));
    B2.at(i+1)=max(B2.at(i)+A.at(i+1),B1.at(i)-A.at(i+1));
  }
  B1.at(N-1)=B1.at(N-2)+A.at(N-1);
  B2.at(N-1)=B2.at(N-2)-A.at(N-1);
  cout<<max(B1.at(N-1),B2.at(N-1))<<endl;
}
            
  
  
  
  


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include <stdlib.h>
#include <stdio.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(10) << ans << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n,m;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


signed main(){
    cin >> n >> m;
    double ans = (double)n*m/(n+m);
    printD(ans);

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  if (A+B < C+D) {
    cout << "Right" << endl;
  } else if (A+B > C+D) {
    cout << "Left" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

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

r = [[0 for i in range(c)] for j in range(100000)]  # テレビ局の番組表
for dummy in range(n):  # 入力
    s, t, c = map(int, input().split())
    for j in range(s - 1, t):
        r[j][c - 1] = 1  # 放送中なら1

ans = 0
for i in range(100000):
    if sum(r[i]) > ans:
        ans = sum(r[i])  # 同時に放送されている番組の最大数

print(ans)

Measured memory_bytes: 40308
from collections import defaultdict

N, P = map(int, input().split())
dic = defaultdict(int)

MAX = int(P**0.5)+1
for p in range(2, MAX):
    while P % p == 0:
        dic[p] += 1
        P //= p
if P > 1:
    dic[P] += 1

ans = 1
for p, cnt in dic.items():
    ans *= pow(p, cnt//N)
print(ans)

Measured memory_bytes: 66416
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>
#include <stdlib.h>

using namespace std;


bool checkNum(int arr[],int arrc,int num){

	for(int k=0; k<arrc; k++){
		if(num==arr[k]) return true;
	}

	return false;

}


//int main(int argc, char *argv[]){
int main(void){

	int x=0;
	int N=0;
	
	int mindiff=10000000;

	cin >> x >> N;

	int p[N];	

    int l, i=0;
    while(cin>>l){
        p[i] = l;
        //cout << p[i] << endl;
        i++;
    }

    if(i==0){
    	cout << x << endl;
    	return 0;
    }

    int ii=0;

    while(1){

    	int neg = x - ii;
    	int pos = x + ii;
    	if(!checkNum(p,N,neg)){
    		cout << neg << endl;
    		break;
    	}
    	if(!checkNum(p,N,pos)){
    		cout << pos << endl;
    		break;
    	}

    	ii++;
    }

    return 0;

}

Measured memory_bytes: 3632
def     process(tab, first, end):
    #print(tab)
    #print(first, end)
    total = first
    for i in tab:
        if (i[1] > total):
            return ("No")
        total += i[0]
        if (total < 0):
            return ("No")
    if (total == end):
        return ("Yes")
    return ("No")




N  = int(input())

first = 0
last = 0
clean = 0
tab = []
total = 0
for i in range(N):
    s = input()
    avant = 0
    apres = 0
    for j in s:
        if (j == '('):
            apres += 1
        elif (j == ')'):
            if (apres > 0):
                apres -= 1
            else:
                avant += 1
    if (avant == 0 and apres > 0):
        first += apres
    elif (apres == 0 and avant > 0):
        last += avant
    elif (avant > 0 or apres > 0):
        tab.append((apres - avant, avant, apres, s))
    else:
        clean += 1
    total += avant - apres
if (first == -1 and clean > 0):
    first = 0
    clean -= 1
if (last == -1 and clean > 0):
    last = 0


tab = sorted(tab)
tab = tab[::-1]
if (total == 0 and first > -1 and last > -1):
    res = process(tab, first, last)
else:
    if (total == 0 and N == 1):
        res = "Yes"
    else:
        res = "No"
print(res)


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

int main() {
  int n, m;
  cin >> n;
  
  vector<int> t(n);
  for(int i=0; i<n; i++){
    cin >> t.at(i);
  }
  
  cin >> m;
  vector<int> p(m), x(m);
  for(int i=0; i<m; i++){
    cin >> p.at(i) >> x.at(i);
  }

  int t_sum;
  for(int i=0; i<m; i++){
    t_sum = 0;
    for(int j=0; j<n; j++){
      if(j == (p.at(i) - 1)){
        t_sum += x.at(i);
      }else{
        t_sum += t.at(j);
      }
    }
    cout << t_sum << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
using namespace std;
int gh[1000][1000],w[2000];
int main()
{
    int i,j,k,l,n,m,a,b,c;
    cin>>n;
    j=n%10;
    n=n/10;
    if (n==9 || j==9)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
    return 0;
}
        
    
    


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

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  int countx= -111, county = 111;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    countx = max(countx, a);
  }
  for (int i = 0; i < m; i++) {
    cin >> a;
    county = min(county, a);
  }
  countx = max(countx, x);
  county = min(county, y);
  if (countx < county) {
    cout<< "No War" << endl;
  }
  else if (countx == county) {
    cout << "War" << endl;
  }
  else  {
    cout << "War" << endl;
  }
}



Measured memory_bytes: 256
#include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n) for(int i = 1; i < n; ++i)

int main(void) {
  int n, i, j;
  scanf("%d", &n);
  int a[n];
  rep(i, n)scanf("%d", &a[i]);
  repi(i, n) {
    rep(j, n) {
      if(j) printf(" %d", a[j]);
      else printf("%d", a[j]);
    }
    printf("\n");
    int v = a[i];
    j = i - 1;
    while(j >= 0 && a[j] > v) {
      a[j + 1] = a[j];
      --j;
    }
    a[j + 1] = v;
  }
  rep(j, n) {
    if(j) printf(" %d", a[j]);
    else printf("%d", a[j]);
  }
    printf("\n");
  return 0;
}


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

int main() {
	multiset<pair<int, int>> L;
	multiset<pair<int, int>> R;
	int n; cin >> n;
	int ll[n], rr[n];
	for(int i = 0; i < n; ++i) {
		cin >> ll[i] >> rr[i];
	}
	int64_t ans = 0;
	{
		int64_t tmp = 0;
		int64_t now = 0;
		for(int i = 0; i < n; ++i) {
			L.emplace(ll[i], rr[i]);
			R.emplace(rr[i], ll[i]);
		}
		while(not L.empty()) {
			{
				auto itr = prev(L.end());
				auto [l, r] = *itr;
				if(now < l) {
					tmp += abs(now - l);
					now = l;
				} else if(r < now) {
					tmp += abs(now - r);
					now = r;
				}
				L.erase(itr);
				R.erase(R.find({r, l}));
			}
			if(not L.empty()) {
				auto itr = R.begin();
				auto [r, l] = *itr;
				if(now < l) {
					tmp += abs(now - l);
					now = l;
				} else if(r < now) {
					tmp += abs(now - r);
					now = r;
				}
				R.erase(itr);
				L.erase(L.find({l, r}));
			}
		}
		ans = max(ans, tmp + abs(now));
	}
	{
		int64_t tmp = 0;
		int64_t now = 0;
		for(int i = 0; i < n; ++i) {
			L.emplace(ll[i], rr[i]);
			R.emplace(rr[i], ll[i]);
		}
		while(not R.empty()) {
			{
				auto itr = R.begin();
				auto [r, l] = *itr;
				if(now < l) {
					tmp += abs(now - l);
					now = l;
				} else if(r < now) {
					tmp += abs(now - r);
					now = r;
				}
				R.erase(itr);
				L.erase(L.find({l, r}));
			}
			if(not R.empty()) {
				auto itr = prev(L.end());
				auto [l, r] = *itr;
				if(now < l) {
					tmp += abs(now - l);
					now = l;
				} else if(r < now) {
					tmp += abs(now - r);
					now = r;
				}
				L.erase(itr);
				R.erase(R.find({r, l}));
			}
		}
		ans = max(ans, tmp + abs(now));
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 13772
package main

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

// --- define queue data structure

type process struct {
	name string
	remain int
}

type queue struct {
	processes []process
	length int
}

func newQueue(initialCapacity int) *queue {
	q := make([]process, 0, initialCapacity)
	return &queue {
		processes: q,
		length: 0,
	}
}

func (q *queue) enqueue(p process) {
	q.processes = append(q.processes, p)
	q.length++
}

func (q *queue) dequeue() process {
	p := q.processes[0]
	q.processes = q.processes[1:]
	q.length--
	return p
}

// --- solution

type result struct {
	name string
	time int
}

func (r result) String() string {
	return fmt.Sprintf("%s %d", r.name, r.time)
}

func solve(quantum int, q *queue) []result {
	results := make([]result, 0, q.length)
	currentTime := 0

	for q.length > 0 {
		p := q.dequeue()
		if p.remain > quantum {
			currentTime += quantum
			p.remain -= quantum
			q.enqueue(p)
		} else {
			currentTime += p.remain
			results = append(results, result{name: p.name, time: currentTime})
		}
	}

	return results
}

// --- main (and parse)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	queue := newQueue(n)

	quantum, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		name := nextText(sc)
		remain, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		queue.enqueue(process{name: name, remain: remain})
	}

	results := solve(quantum, queue)

	for _, result := range results {
		fmt.Println(result)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}


Measured memory_bytes: 11112
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main(): 
	nums = []
	while True:
		x = int(input())
		if x == 0:
			break
		nums.append(x)
	for i in range(len(nums)):
		print("Case %d: %d" % (i + 1, nums[i]))
	
if __name__ == '__main__':
  main()

Measured memory_bytes: 8076
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
ll power(ll x, ll y, ll p) {
    ll res = 1;    x = x % p;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y = y>>1;    x = (x*x) % p;
    } return res;
}

int main()
{
    Imposter

    ll a[5];
    input(a,5);
    f(5)
    {

        if(a[i]==0)
        {
            cout<<i+1;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define mod 1000000007
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i,x,y=1,count = 0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>x;
        if(x==y){
            count++;
            y++;
        }
    }
    if(count==0)cout<<-1;
    else cout<<n-count;
    return 0;
}


Measured memory_bytes: 256
loop do
  n = gets.to_i
  break if n == 0
  taro = []
  n.times { taro << gets.to_i }
  taro.sort!
  hanako = (1..2*n).to_a - taro

  stage = 0
  loop do
    put_taro = false
    taro.each_with_index do |c, i|
      if c > stage
        stage = c
        taro.delete(c)
        put_taro = true
        break
      end
    end
    unless put_taro
      stage = 0
    end

    break if taro.empty? || hanako.empty?

    put_hanako = false
    hanako.each_with_index do |c, i|
      if c > stage
        stage = c
        hanako.delete(c)
        put_hanako = true
        break
      end
    end
    unless put_hanako
      stage = 0
    end

    break if taro.empty? || hanako.empty?
  end

  puts hanako.size, taro.size
end

Measured memory_bytes: 8764
#include <stdio.h>
#include <algorithm>
#include <string.h>

using namespace std;

const int MAXN = 105;

pair<int, int> A[MAXN], B[MAXN];

int adj[MAXN][MAXN], N;

bool bm(int u, int del[], int match[]){
	for(int i=1; i<=N; ++i){
		if(adj[u][i] && !del[i]){
			del[i] = true;
			if(match[i] < 0 || bm(match[i], del, match)){
				match[i] = u;
				return true;
			}
		}
	}
	return false;
}

int solve(){
	int res = 0;
	int match[MAXN], del[MAXN];
	memset(match, -1, sizeof(match));
	for(int i=1; i<=N; ++i){
		memset(del, 0, sizeof(del));
		if(bm(i, del, match)) res++;
	}
	return res;
}

int main(){
	scanf("%d", &N);
	for(int i=1; i<=N; ++i) scanf("%d %d", &A[i].first, &A[i].second);
	for(int i=1; i<=N; ++i) scanf("%d %d", &B[i].first, &B[i].second);
	for(int i=N; i>=1; --i)
		for(int j=N; j>=1; --j)
			if(A[i].first < B[j].first && A[i].second < B[j].second) adj[i][j] = 1;
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 256
import math
n, k = list(map(int,input().split()))
a = list(map(int,input().split()))

def lte_k(x, len_list):
    counter = 0
    for item in len_list:
        counter += math.ceil(item / x) - 1
    return counter <= k

def binary_search():
    low = 0
    high = max(a)

    while low < high-1:
        mid = (low + high) // 2
        guess = lte_k(mid, a)
        if guess:
            high = mid
        else:
            low = mid
    return high

print(binary_search())

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

int main() {
    int N, Y;
    cin >> N >> Y;
    int x = -1, y = -1, z = -1;

    rep(i, N + 1) rep(j, N + 1) {
        if (9*i + 4*j == Y/1000 - N) {
            int k = N - (i + j);
            if (k >= 0) x = i, y = j, z = k;
        }
    }

    printf("%d %d %d\n", x, y, z);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n;
    vector<vector<LL>> a,wf,ch;
    Problem(LL n):n(n), a (n,vector<LL>(n)),ch (n,vector<LL>(n)){};
    LL solve(){
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                cin >> a[i][j];
            }
        }
        wf=a;
        for(int k=0; k<n; ++k){
            for(int i=0; i<n; ++i){
                for(int j=0; j<n; ++j){
                    if(wf[i][j]>wf[i][k]+wf[k][j])return -1;
                    else if(wf[i][j] == wf[i][k]+wf[k][j] and k!=i and k!= j)ch[i][j]=1;
                }
            }
        }
        LL ans =0;
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                if(ch[i][j]==0)ans+=a[i][j];
            }
        }
        return ans/2;

    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    cout << p.solve() << "\n";
    return 0;
}



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

int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) printf("Possible\n");
	else printf("Impossible\n");
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vector<char> pos = {'M', 'A', 'R', 'C', 'H'};
	map<char, ll> m;
	rep(i, n){
		string s;
		cin >> s;
		m[s[0]]++;
	}
	ll ans = 0;
	rep(i, pos.size()) repn(j, i + 1, pos.size()) repn(k, j + 1, pos.size()){
		ans += (ll)(m[pos[i]] * m[pos[j]] * m[pos[k]]);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include <iostream>

int main() {
  using namespace std;

  int x, n, p[100];

  cin >> x >> n;

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

  bool flag[102] = { };

  for (int i = 0; i < n; i++) {
    flag[p[i]] = true;
  }

  int ans = 0;
  for (int i = 0; i < 102; i++) {
    if (!flag[i]) {
      if (std::abs(x - ans) > std::abs(x - i)) {
        ans = i;
      }
    }
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}


int main(){
    string s;
    cin >> s;
    if(s=="AAA" || s=="BBB")cout << "No" << endl;
    else cout << "Yes"<<endl;
    return 0;
}

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

using namespace std;
using std::vector;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

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

int main(){
 
  int x, y, z; cin >> x >> y >> z;
  int k; cin >> k;
  vector<long long> a(x), b(y), c(z);

  rep(i, x)cin >> a[i];
  rep(i, y)cin >> b[i];
  rep(i, z)cin >> c[i];

  vector<long long> ab;
  rep(i, x){
    rep(j, y){
      ab.pb(a[i] + b[j]);
    }
  }

  sort(rall(ab));
  vector<long long> ans;

  for(int i = 0; i < min(k, (int)ab.size()); i++)
  {
    rep(j, z){
      ans.pb(ab[i] + c[j]);
    }
  }
  
  sort(rall(ans));
  
  rep(i, k)
    pr(ans[i]);

  return 0;
}


Measured memory_bytes: 43368
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

inline int cnt(int d,const vector<li>& a){
  // d以上の数
  auto itr=lower_bound(a.begin(),a.end(),d);
  if(df)print(a.end()-itr);
  return a.end()-itr;
}

inline int judge(li m,int c,const vector<li>& a){
  int n=a.size();
  li t=0;
  if(df)print("judge",c);
  rep(i,n){
    t+=cnt(c-a[i],a);
  }
  if(df)print("->",t>=m?1:0);
  return t>=m;
}

int main(){
  int n; li m; cin >>n >>m;
  vector<li> a(n); rep(i,n) cin >>a[i];
  sort(a.begin(),a.end());
  if(df)print(a);
  int ok=0,ng=a[n-1]*2+1;
  while(ng-ok>1){
    int c=(ok+ng)/2;
    (judge(m,c,a)?ok:ng)=c;
  }
  
  vector<li> s(n+1,0);
  rep(i,n) s[i+1]=s[i]+a[i];
  if(df)print(s);
  li ans=0,c=0;
  rep(i,n){
    int t=cnt(ok-a[i],a); c+=t;
    if(df)print(n,n-t,"->",s[n]-s[n-t],a[i]);
    ans+=(s[n]-s[n-t]) +a[i]*t;
  }
  ans-=(c-m)*ok;
  print(ans);
}


Measured memory_bytes: 4820
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1


def main():
    series = [int(input())]
    for i in range(1000000):
        s = f(series[-1])
        if s in series:
            print(i + 2)
            return
        else:
            series.append(s)


main()


Measured memory_bytes: 2940