akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int n;
int a[200010];
bool cmp(int a, int b)
{
	return a > b;
}
long long ans;
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	sort(a+1, a+n+1, cmp);
	//for(int i = 1; i <= n; i++)
//	{
	//	cout << a[i] << " ";
//	}
	//cout << endl;
	ans = a[1];
	n-= 2;
	int p = 2;
	while(n)
	{
		ans += (a[p] * 2);
		n -= 2;
		if(n < 0)
		{
			ans -= a[p];
			break;
		}
		p++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int h, w, dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
	cin >> h >> w;
	vector<string> s(h);
	rep(snip_i, h) cin >> s.at(snip_i);
	queue<pair<int, int>> q;//x, y
	vector<vector<int>> d(h, vector<int>(w, -1));
	d.at(0).at(0) = 0;
	q.push(make_pair(0, 0));
	while(!q.empty()){
		int px, py;
		tie(px, py) = q.front(); q.pop();
		// cerr << px << " " << py << endl;
		rep(i, 4){
			int nx = px + dx[i], ny = py + dy[i];
			if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
			if(s.at(ny)[nx] == '#') continue;
			if(d.at(ny).at(nx) != -1) continue;
			d.at(ny).at(nx) = d.at(py).at(px) + 1;
			q.push(make_pair(nx, ny));
		}
	}
	int ans = 0;
	if(d.at(h-1).at(w-1) == -1){
		ans = -1;
	}else{
		int bkc = 0;
		rep(i, h){
			rep(j, w){
				if(s.at(i)[j] == '#') bkc++;
			}
		}
		ans = h*w - bkc - d.at(h-1).at(w-1) - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000
int A[MAX],n;

int main(){
  int i,k;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  k=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i) printf(" ");
    if(i==k) printf("[");
    printf("%d",A[i]);
    if(i==k) printf("]");
  }
  printf("\n");
  return 0;
}

int partition(int k,int m){
  int i,j;
  int t;
  int x=A[m];
  i=k-1;
  for(j=k;j<m;j++){
    if(A[j]<=x){
      i++;
      t=A[i];A[i]=A[j];A[j]=t;
    }
  }
  t=A[i+1];A[i+1]=A[m];A[m]=t;
  return i+1;
}



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

const long long modd = 1e9 + 7;

long long f(long long a) {
    a %= modd;
    if(a < 0) a += modd;
    return a;
}

long long n, dp[3003][3003];
string s;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> s;
    s = "#" + s;
    dp[1][1] = dp[1][2] = 1ll;
    for(long long i = 2; i <= n; ++i) {
        for(long long j = 1; j <= i; ++j) {
            if(s[i - 1] == '>') {
                dp[i][j] = f(dp[i - 1][i] - dp[i - 1][j - 1]);
            } else {
                dp[i][j] = dp[i - 1][j - 1];
            }
        }
        for(long long j = 2; j <= i + 1; ++j) {
            (dp[i][j] += dp[i][j - 1]) %= modd;
        }
    }
    cout << dp[n][n] << endl;
    return 0;
}

Measured memory_bytes: 68992
import sys
# input = sys.stdin.buffer.readline
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

import bisect
from string import ascii_lowercase
d = dict()
for i, c in enumerate(ascii_lowercase):
    d[c] = i

N = int(input())
S = list(input())
lst = [[] for _ in range(26)]
for i in range(N):
    lst[d[S[i]]].append(i)

Q = int(input())
for q in range(Q):
    a, b, c = input().split()
    if a=='1':
        i = int(b)-1
        if c == S[i]:   # 変更なし
            continue
        idx = bisect.bisect_left(lst[d[S[i]]],i)
        del lst[d[S[i]]][idx]
        bisect.insort_left(lst[d[c]],i)
        S[i] = c
    else:
        l = int(b)-1
        r = int(c)
        ans = 0
        for i in range(26):
            cnt = bisect.bisect_left(lst[i],r) - bisect.bisect_left(lst[i],l)
            if cnt:
                ans += 1
        print(ans)


Measured memory_bytes: 30852
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;
const int mod = 1000000007;

int main() {
bool bingo=false;
  vector<vector<int>> A(3,vector<int>(3));
  for(int i=0; i<3; i++){for(int j=0; j<3; j++){cin>>A[i][j];}}
  int N;
  cin>>N;
  unordered_map<int,int> map(N);
  for(int i=0; i<N; i++){int a;cin>>a;map[a]=1;}
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if(!map.count(A[i][j]))break;
      if(j==2){cout<<"Yes"<<endl;bingo=true;goto end1;}
  }
  }
  end1 :N=N;
  if(!bingo){
    for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if(!map.count(A[j][i]))break;
      if(j==2){cout<<"Yes"<<endl;bingo=true;goto end2;}
  }
  }
  }end2 :N=N;
  if(!bingo){
int i=0,j=0,tmp=0;
    while(true){tmp++;
      if(map.count(A[i][j])){i++;j++;}
      if(i==3&&j==3){cout<<"Yes"<<endl;bingo=true;goto end3;}
        if(tmp==3)break;
    }
  }end3 :N=N;
  if(!bingo){
int i=2,j=0,tmp=0;
     while(true){tmp++;
      if(map.count(A[j][i])){i--;j++;}
      if(i==-1&&j==3){cout<<"Yes"<<endl;bingo=true;goto end4;}
  if(tmp==3)break;

     }
  }end4 :N=N;
if(!bingo)cout<<"No"<<endl;

}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        var ff = new int[n][];
        for (int i = 0; i < n; i++) {
            ff[i] = ToIntArray(input.ReadLine(), 10);
        }

        var pp = new int[n][];
        for (int i = 0; i < n; i++) {
            pp[i] = ToIntArray(input.ReadLine(), 10+1);
        }

        long max = long.MinValue;

        BitSearch bs = new BitSearch(10);
        bs.Next(); //skip 0
        
        do {
            long y = 0L;
            for(int i=0; i<n; i++) {
                var count = 0;
                for(int j=0; j<10; j++) {
                    if (bs[j] && ff[i][j] == 1) count++;
                }
                y += pp[i][count];
            }
            max = Math.Max(max, y);
        } while (bs.Next());

        return max;
    }

    class BitSearch
    {
        private int max;
        private int x;
        public int Length { get; }

        //0~n-1
        public bool this[int i] {
            get {
                var si = Length - i - 1;
                return ((x >> si) & 0x01) == 1;
            }
        }

        public BitSearch(int n) {
            this.Length = n;
            this.max = (int)Math.Pow(2, n) - 1;
            this.x = 0;
        }
        public bool Next() {
            if (x >= max) {
                return false;
            }
            x += 1;
            return true;
        }
        public void Reset() {
            x = 0;
        }
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <cmath>

using namespace std;

void solve()
{
	int N;
	cin >> N;
	while(N--)
	{
		double x[2];
		double y[2];
		double r[2];
		for(int i = 0; i < 2; ++i)
		{
			cin >> x[i] >> y[i] >> r[i];
		}
		double dist = sqrt((x[1] - x[0]) * (x[1] - x[0]) + (y[1] - y[0]) * (y[1] - y[0]));
		if(dist > r[0] + r[1])
		{
			cout << "0" << endl;
		}
		else if(dist + r[0] < r[1])
		{
			cout << "-2" << endl;
		}
		else if(dist + r[1] < r[0])
		{
			cout << "2" << endl;
		}
		else
		{
			cout << "1" << endl;
		}
	}
}

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

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

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

    vector<int> is_2017like(100005);
    REP(i, 100005) {
        if(i%2 == 0) continue;
        map<ll, ll> factors1 = prime_factor(i);
        map<ll, ll> factors2 = prime_factor((i+1)/2);

        if(factors1[i] == 1 && factors2[(i+1)/2] == 1)
            is_2017like[i] = 1;
    }

    vector<int> acum(100005);
    FOR(i, 1, 100005) {
        acum[i] = acum[i-1] + is_2017like[i];
    }

    REP(i, Q) {
        int l, r;
        cin >> l >> r;
        cout << acum[r] - acum[l-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 4028
#include <cstdio>
typedef long long int64;
static const int MAXN = 1e3 + 3;
static const int MODULUS = 1e9 + 7;
#define _  %  MODULUS
#define __ %= MODULUS

int binom[MAXN][MAXN] = {{ 0 }};
int64 fact[MAXN], fact_inv[MAXN];

inline int64 fpow(int64 base, int exp)
{
    int64 ans = 1;
    for (; exp; exp >>= 1, (base *= base)__) if (exp & 1) (ans *= base)__;
    return ans;
}
inline void preprocess_binomials()
{
    binom[0][0] = 1;
    for (int i = 1; i < MAXN; ++i) {
        binom[i][0] = 1;
        for (int j = 1; j <= i; ++j)
            binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j])_;
    }
    fact[0] = 1;
    for (int i = 1; i < MAXN; ++i) fact[i] = (fact[i - 1] * i)_;
    fact_inv[MAXN - 1] = fpow(fact[MAXN - 1], MODULUS - 2);
    for (int i = MAXN - 2; i >= 0; --i) fact_inv[i] = (fact_inv[i + 1] * (i + 1))_;
}
inline int64 group(int size, int groups)
{
    return fact[size * groups] * fpow(fact_inv[size], groups)_ * fact_inv[groups]_;
}

int n, a, b, c, d;
// f[size of group current considering][number of people assigned]
int64 f[MAXN][MAXN] = {{ 0 }};

int main()
{
    preprocess_binomials();
    scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);

    f[a - 1][0] = 1;
    for (int s = a; s <= b; ++s) {
        for (int i = 0; i <= n; ++i) f[s][i] = f[s - 1][i];
        for (int i = 0; i <= n; ++i) {
            for (int j = i + c * s; j <= n && j <= i + d * s; j += s) {
                // binom[n - i][j - i]: ways to choose people to fit into group size s
                // group(s, (j - i) / s): ways to group (j - i) people into groups of size s
                (f[s][j] += f[s - 1][i] * binom[n - i][j - i]_ * group(s, (j - i) / s))__;
            }
        }
    }

    printf("%lld\n", f[b][n]);
    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Tap Dance
            var S = Console.ReadLine();

            if (IsEasyToStep(S))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        static bool IsEasyToStep(string S)
        {
            for(int i = 0; i < S.Length; i++)
            {
                if (i % 2 == 0 && S[i] == 'L')
                {
                    return false;
                }
                else if (i % 2 == 1 && S[i] == 'R')
                {
                    return false;
                }
            }

            return true;
        }
    }
}

Measured memory_bytes: 13140
N, W = map(int, input().split())
v = []
w = []
for i in range(N):
    a, b = map(int, input().split())
    v.append(a)
    w.append(b)

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

for weight in range(W+1):
    for index in range(N):
        if weight >= w[index]:
            dp[weight] = max(dp[weight], dp[weight-w[index]] + v[index])

print(dp[W])


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

int main() {
  int x;
  cin >> x;
  int e500 = 0, e5 = 0;
  while (x >= 500) {
    x -= 500;
    e500++;
  }
  while (x >= 5) {
    x -= 5;
    e5++;
  }
  cout << e500 * 1000 + e5 * 5 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Scanner scanner;
    static PrintWriter out;
    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        out = new PrintWriter(System.out);
        
        int n = nextInt();
        boolean a = false;
        a:for (int i = 1; i <= 9; i++) {
            for (int j =1; j <= 9; j++) {
                if (i * j == n) {
                    a= true;
                    break a;
                }
            }
        }
        System.out.println(a ? "Yes" : "No");
        out.flush();
    }

    public static void println(Object o) {
        out.println(o);
    }

    public static void print(Object o) {
        out.print(o);
    }

    public static void printf(String format, Object... o) {
        out.printf(format, o);
    }

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

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

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

    public static short nextShort() {
        return Short.parseShort(scanner.next());
    }

    public static float nextFloat() {
        return Float.parseFloat(scanner.next());
    }

    public static void printYes() {
        System.out.println("Yes");
    }

    public static void printYES() {
        System.out.println("YES");
    }

    public static void printNo() {
        System.out.println("No");
    }

    public static void printNO() {
        System.out.println("NO");
    }

    public static String nextLine() {
        return scanner.nextLine();
    }

    public static double distance(double x, double y, double x2, double y2) {
        return Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
    }

    public static int MOD = 1_000_000_007;
    public static int MAX = 100000;
    public static long[] fac = new long[MAX];
    public static long[] finv = new long[MAX];
    public static long[] inv = new long[MAX];

    public static void combinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    public static long combination(int n, int k) {
        if (n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

    public static long factorial(long n) {
        return n <= 0 ? 1 : n * factorial(n - 1);
    }
}

Measured memory_bytes: 29384
def calc(array, i, j, H, W):
    move = [[1, -1], [1, 0], [1, 1], [0, -1], [0, 1], [-1, 0], [-1, -1], [-1, 1]]
    num_mine = 0
    for k in range(8):
        x = i+move[k][0]
        y = j+move[k][1]
        if x >= H or x < 0 or y >= W or y < 0:
            pass
        else:
            num_mine += 1 if array[x][y] == "#" else 0
    return num_mine


def main():
    num = input().split()
    num = [int(x) for x in num]
    H = num[0]
    W = num[1]

    array = []
    for i in range(H):
        array.append(list(input()))

    for i in range(H):
        for j in range(W):
            if array[i][j] == "#":
                pass
            else:
                array[i][j] = calc(array, i, j, H, W)

    for i in range(0, num[0]):
        print("".join(map(str, array[i])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

ll gcd(ll a, ll b){
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

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

ll a[100010];

int main(){
    int n;
    ll m;
    cin >> n >> m;
    rep(i, n) cin >> a[i];
    rep(i, n) a[i] /= 2;

    ll l = 1;
    rep(i, n) l = lcm(l, a[i]);

    bool flag = true;
    rep(i, n) flag &= ((l/a[i])%2!=0);
    if (!flag){
        cout << 0 << endl;
        return 0;
    }
    
    ll num = m / l;
    cout << (num + 1) / 2 << endl;

    return 0;
}

Measured memory_bytes: 1024
let ans, n = ref 0, read_int ()
let s = read_line ()
let _ = for i = 0 to 999 do if try List.fold_left (fun p n -> String.index_from s p (Char.chr (n + 48)) + 1) 0 [i / 100; i / 10 mod 10; i mod 10] >= 0 with _ -> false then incr ans done; Printf.printf "%d\n" !ans

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

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
	int t; cin >> t;
	int a[110] = {};
	rep(i, 0, t) {
		int n; cin >> n;
		rep(i, 0, n)cin >> a[i];
		int M = -INF, m = INF;
		rep(i, 1, n) {
			int diff = a[i] - a[i - 1];
			M = max(M, diff);
			m = min(m, diff);
		}
		if (M < 0)M = 0;
		if (m > 0)m = 0;
		cout << M << " " << -m << endl;
	}
	return 0;
}

Measured memory_bytes: 2968
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ull i=start;i<end;i++)
#define N 100001
#define INF 1e12
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
ll dp[100][N];
int main() 
{
    fastio();
    // #ifndef ONLINE_JUDGE
    // 	freopen("in.txt","r",stdin);
    // 	freopen("out.txt","w",stdout);
    // #endif

  ll s=0,d;
  cin>>d;
  ll tem=d;
  while(tem>0)
  {
  	s+=tem%10;
  	tem/=10;
  }
  loop(i,0,s+1)
  {
  	loop(j,0,d+1)
  		dp[i][j]=INF;
  }
  queue<pair<int,int> >q;
  q.push({0,0});
  dp[0][0]=0;
  int ans =s;
  while(!q.empty())
  {
  	int x = q.front().first;
  	int y = q.front().second;
  	q.pop();
  	for(int i=0;i<10;i++)
  	{
  		int xx = x+i;
  		int yy = (y*10 +i)%d;
  		if(xx>ans)continue;
  		if(dp[xx][yy]<=dp[x][y]+1)
  			continue;
  		if(yy==0)
  			ans = min(xx,ans);
  		dp[xx][yy]=dp[x][y]+1;
  		q.push({xx,yy});
  	}
  }
  cout<<ans<<endl;

  nl;

	return 0;
}

Measured memory_bytes: 47760
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
ll n,m,k,ans;
string s,t;
const ll powll = 1LL<<1;

int main(void){
  //dp[i+1][s][j] = (i桁目までで条件を満たす数の総数)　s 未満フラグ01、j3フラグ01
  int n; cin >> n;
  int r; cin >> r;
  int ans = 0;
  while(n >= r){
    ans++;
    n /= r;
  }
  if(n != 0) ans++;
  cout << ans << "\n";
}

Measured memory_bytes: 256
import collections

n = int(input())
s = [input() for _ in range(n)]

a = collections.Counter(s)
b = a.most_common()
c = 0

for i in range(len(b)):
	if b[i][1] == b[0][1]:
		c += 1
	else:
		break

d = sorted(b[:c])

for j in range(c):
	print(d[j][0])

Measured memory_bytes: 49172
#include<bits/stdc++.h>
using namespace std;
#define X first
#define S second

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,b) FOR(i,0,b)
#define reps FOR

int N;
int cnt[2];

int main() {
  cin >> N;
  rep(i, N) {
    int a;
    cin >> a;
    cnt[a%2]++;  
  }

  if (!cnt[1] || !cnt[0]) {
    cout << "0\n";
    return 0;
  }

  if (cnt[1]%2) cout << N-1 << endl;
  else cout << N - 2 << endl;
}



Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?9e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	ll n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	if(a>b)swap(a,b);
	bool h=false;
	n--;
	rep(i,n){
		ll t=a+(i-(n-i))*c;
		ll l=t-(d-c)*(n-i),r=t+(d-c)*i;
		if(l<=b&&b<=r)h=true;
	}
	if(h)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(long long i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
 
int main()
{
  ll l, r;
  cin >> l >> r;
  if (abs(r-l)>2025) {
    cout << "0" << endl;
    return 0;
  }
  ll ans = 2018;
  for (ll i=l; i<r; i++) {
    for (ll j=i+1; j<=r; j++) {
      ans = min(ans, (i*j)%2019);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int X,Y;
    cin >> X >> Y;
    int S = 0;
    if (X == 1 || Y == 1){
        S += 300000;
        if (X == 1 && Y == 1){
            S += 700000;
        }
    }
    if (X == 2 || Y == 2){
        S += 200000;
        if( X == 2 && Y == 2){
            S += 200000;
        }
    }
    if (X == 3 || Y == 3){
        S += 100000;
        if( X == 3 && Y == 3){
            S += 100000;
        }
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
int main(){
    int A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};
    int k;
    cin>>k;
    cout<<A[k-1]<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)
 
using namespace std;
 
 
ll mod = 1e9 + 7;
vector<ll> powmemo(1e5, 1);

void combInit(ll n){
    rep(i, n+10){
        if(i < 2)   continue;
        powmemo[i] = i*powmemo[i-1];
        powmemo[i] %= mod;
    }
}

//  b^c % m
ll powmod(ll b){
    ll r = 1;
    ll c = mod-2;
    for (; c>0; c>>=1, b=b*b%mod){
        if (c&1)    r = r*b%mod;
    }
    return r;
}
 
ll powdiv(ll a, ll b){
    return a * powmod(b) % mod;
}

ll combmod(ll all, ll select){
    if(select == 0)     return 1;
    if(all == select)   return 1;
    if(all == 0)        return 0;
    if(all < select)    return 0;

    ll a = powmemo[all];
    ll b = powmemo[select]*powmemo[all-select] % mod;

    return powdiv(a, b);
}
 
vector<ll> search(vector<ll> &a, ll n){
    vector<ll> m(n+1, -1);
    ll l, r;
    rep(i, n+1){
        if(m[a[i]] != -1){
            l = m[a[i]];
            r = i;
            break;
        }
        else{
            m[a[i]] = i;
        }
    }
    vector<ll> res(2);
    res[0] = l;
    res[1] = r;
    return res;
}
 
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n+1);
    rep(i, n+1) cin >> a[i];
 
    combInit(n+5);
    
    vector<ll> res = search(a, n);
    ll l = res[0];
    ll r = res[1];
 
    rep(i, n+1){
        ll v = combmod(n+1, i+1) + mod;
        ll mid = combmod(l+n-r, i);
        cout << (v - mid) % mod << endl;
    }
 
 
    return 0;
}

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

int main(){
  int n,d,cal,ab,i,j,k,num;
  cin >> n >> d;
  num=0;
  cal=0;
  vector<vector<int>> a(n,vector<int>(d));
  for(i=0;i<n;++i){
    for(j=0;j<d;j++){
      cin >> a[i][j];
    }
  }
  for(i=0;i<n;++i){
    for(j=i+1;j<n;j++){
      cal=0;
      for(k=0;k<d;++k){
        ab=abs(a[i][k]-a[j][k]);
        cal+=ab*ab;
      }
      bool flag = false;
      for(k=0;k<=cal;++k){
        if(k*k==cal){
          flag=true;
        }
      }
      if(flag==true)++num;

    }
  }
  cout << num << endl;
  return 0;
}

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

const double inf = 1e20;

int main() {
  for(int n, m; cin >> n >> m && (n|m);) {
    vector<vector<double> > g(n, vector<double>(n));
    for(int i = 0; i < n; ++i) {
      for(int j = 0; j < n; ++j) {
        cin >> g[i][j];
      }
    }
    vector<double> h(n, 1.0);
    for(int t = 0; t < m-1; ++t) {
      vector<double> nh(n, -inf);
      for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
          nh[j] = max(nh[j], h[i] * g[i][j]);
        }
      }
      h = nh;
    }
    printf("%.2f\n", *max_element(h.begin(), h.end()));
  }
  return 0;
}

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

int main(){
    int n, count[5][4][11];
    for(int i=1; i<=4; i++)
        for(int j=1; j<=3; j++)
            for(int k=1; k<=10; k++) count[i][j][k] = 0;

    cin >> n;
    for(int i=0; i<n; i++){
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        count[b][f][r] += v;
    }

    for(int i=1; i<=4; i++){
        if(i > 1) cout << "####################\n";
        for(int j=1; j<=3; j++){
            for(int k=1; k<=10; k++){
                cout << " " << count[i][j][k];
            }
            cout << endl;
        }
    }

    return 0;
}


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

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] arg) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int M = sc.nextInt();
			int L = sc.nextInt();
			int[][] d = new int[N][N];
			int[][] e = new int[N][N];
			for (int i = 0; i < M; ++i) {
				int A = sc.nextInt() - 1;
				int B = sc.nextInt() - 1;
				int D = sc.nextInt();
				d[A][B] = d[B][A] = D;
				int E = sc.nextInt();
				e[A][B] = e[B][A] = E;
			}
			boolean[][] visited = new boolean[N][L + 1];
			PriorityQueue<State> q = new PriorityQueue<State>();
			q.add(new State(0, L, 0));
			while (true) {
				State cur = q.poll();
				if (visited[cur.p][cur.m]) continue;
				visited[cur.p][cur.m] = true;
				if (cur.p == N - 1) {
					System.out.println(cur.e);
					break;
				}
				for (int i = 0; i < N; ++i) {
					if (d[cur.p][i] == 0) continue;
					if (!visited[i][cur.m]) {
						q.add(new State(i, cur.m, cur.e + e[cur.p][i]));
					}
					if (d[cur.p][i] <= cur.m && !visited[i][cur.m - d[cur.p][i]]) {
						q.add(new State(i, cur.m - d[cur.p][i], cur.e));
					}
				}
			}
		}
	}

	static class State implements Comparable<State> {
		int p, m, e;

		public State(int p, int m, int e) {
			this.p = p;
			this.m = m;
			this.e = e;
		}

		public int compareTo(State o) {
			return this.e - o.e;
		}
	}

}

Measured memory_bytes: 60756
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

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

  cout << s.substr (0, s.size() - 8) << endl;;
}

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

using namespace std;

//Warsaw debug template
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1,debug&>::type operator<<(c i){
sim > struct rge {c b,e;};
sim > rge<c> range(c i, c j) {return rge<c>{i,j};}
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug{
#ifdef LOCAL
~debug() {cerr<<endl; }
eni(!=) cerr<< boolalpha << i; ris;}
eni(==) ris <<range(begin(i),end(i)); }
sim, class b dor(pair<b,c> d){
ris<<"("<<d.first<<","<<d.second<<")";
}
sim dor(rge<c> d){
    *this << "[";
    for(auto it=d.b;it!=d.e;++it)
        *this <<"," +(it==d.b)<< *it;
    ris<<"]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) "["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"
//End of debug template        


int main(){
    string s,t;
    cin>>s>>t;
    map<char,char> m;
    map<char,char> m2;
    for(int i=0;i<(int)s.size();++i){
        if(m.find(s[i])!=m.end()){
            if(m[s[i]]!=t[i]){
                cout<<"No";
                return 0;
            }
        }
        if(m2.find(t[i])!=m2.end()){
            if(m2[t[i]]!=s[i]){
                cout<<"No";
                return 0;
            }
        }
        m[s[i]]=t[i];
        m2[t[i]]=s[i];
//        debug()<<imie(i) imie(s[i]) imie(t[i]) imie(m[s[i]]) imie(m2[t[i]]);
    }
    cout<<"Yes";
    cout<<endl;   
    return 0;
}


Measured memory_bytes: 776
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        br.lines().forEach(s -> {
            List<Integer> list = Arrays.stream(s.split(" "))
                    .map(Integer::parseInt)
                    .collect(Collectors.toList());

            int h = list.get(0);
            int w = list.get(1);

            if (h == 0 && w == 0) {
                return;
            }

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if ((i + j) % 2 == 0) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        });
    }
}

Measured memory_bytes: 37052
#include<iostream>
using namespace std;
struct data{int i,p,q,r;};
int n,P,Q,R,C;
bool flag;
data t[1000];
int main(){
  while(cin>>n&&n){
    flag=true;
    for(int i=0;i<n;i++)cin>>t[i].i>>t[i].p>>t[i].q>>t[i].r;
    cin>>P>>Q>>R>>C;
    for(int i=0;i<n;i++){
      if(t[i].p>P)continue;
      if(t[i].q>Q)continue;
      if(t[i].r>R)continue;
      if(t[i].p*4+t[i].q*9+t[i].r*4>C)continue;
      cout<<t[i].i<<endl;
      flag=false;
    }
    if(flag)cout<<"NA"<<endl;
  }
  return 0;
}

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



int main() {

  int N, K;
  cin >> N >> K;

  int a = 1;
  for (int i = 0; i < N; i++) {
   if ( a + K > a * 2) a*= 2;
    else a+= K;

  }

  cout << a << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,K,ans;
    cin >> A >> B >> C >> K;
    if(A>=K){
        ans=K;
    }else if(A+B>=K){
        ans=A;
    }else{
        ans=A-(K-A-B);
    }
    cout << ans;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 1000005
#define MOD 1000000007
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, fact[maxN], invFact[maxN], f[maxN];

int power(int x, int n) {
    if (n == 0) return 1;
    if (n%2 == 1) return (1LL*x*power(x, n-1))%MOD;
    int p = power(x, n/2);
    return (1LL*p*p)%MOD;
}

int C(int n, int k) {
    if (k > n) return 0;
    int p = fact[n];
    int q = (1LL*invFact[k]*invFact[n-k])%MOD;
    return (1LL*p*q)%MOD;
}

int main () {
    scanf("%d", &n);
    fact[0] = invFact[0] = 1;
    fto(i, 1, n) {
        fact[i] = (1LL*fact[i-1]*i)%MOD;
        invFact[i] = power(fact[i], MOD-2);
    }

    int ans = 0;
    fto(t, 1, n-1) {
        int cof = C(t-1, n-t-1);
        int perm = (1LL*fact[t]*fact[n-1-t])%MOD;
        f[t] = (1LL*cof*perm)%MOD;
//        printf("%d %d %d %d\n", t, cof, perm, f[t]);
    }
    fto(t, 1, n-1) {
        int cnt = (f[t]-f[t-1]+MOD)%MOD;
        ans = (ans+1LL*cnt*t)%MOD;
    }

    printf("%d", ans);

    return 0;
}


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

using namespace std;
 
#define MAX_N 201
#define MAX_L 10001
#define INF 1e9
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define FOR(i,a,b) for(int i = a ; i < b ; i++)
#define all(p) (p).begin(),(p).end() 
 
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
 
int N,K,T,U,V,L;
bool road[MAX_L];
 
double getTime(double v){
    return (double)L / v;
}
 
double solve(){
    int speed = 0, carr = 0;
    double res = 0;
 
    rep(i,L){
	if(road[i]){
	    carr++;
	}
	if(speed == 0 && carr > 0){
	    carr--;
	    speed = V*T;
	}
	if(carr > K){
	    carr--;
	    speed = V*T;
	}
	if(speed > 0){
	    speed--;
	    res += 1./ V;
	}else{
	    res += 1./ U;
	}
    }  
    return res;
}
 
int main(){
    int D;
    memset(road,false,sizeof(road));
    cin >> N >> K >> T >> U >> V >> L;
    rep(i,N){
	cin >> D;
	road[D] = true;
    }
    printf("%.8f\n",solve());
    return 0;
}

Measured memory_bytes: 3212
fn read() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let v: Vec<usize> = read()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    let (n, k, q) = (v[0], v[1], v[2]);
    let mut points = vec![0_usize; n];
    for _ in 0..q {
        let i: usize = read().trim().parse().unwrap();
        points[i - 1] += 1;
    }
    for p in points {
        println!("{}", if k + p > q { "Yes" } else { "No" });
    }
}


Measured memory_bytes: 4732
import java.util.*;
import java.util.stream.Collectors;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int k = sc.nextInt();
    ArrayList<String> ss = new ArrayList<>();
    int n = s.length();
    for(int i=0; i<n; i++) {
      for(int j=1; j<=k; j++) {
        if(i + j <= n) {
          ss.add(s.substring(i, i + j));
        }
      }
    }
    List<String> us = ss.stream().sorted().distinct().collect(Collectors.toList());
    System.out.println(us.get(k-1));
  }
}

Measured memory_bytes: 29480
// Problem : E - Dist Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
	ARIJIT SUR 
	@duke_knight
	@surcode
    @comeback
	IIT ISM 
 */
#include<bits/stdc++.h>
#define SIZE (ll)(1e6)
#define mod (ll)(1e9+7)
#define vi vector<ll>
#define INF 0x3f3f3f3f
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(a) ((a)>0?(a):-(a))
#define sc(a) scanf("%d\n",&a);
#define all(a) a.begin(),a.end()
#define maxelem(a) *max_element(all(a))
#define minelem(a) *min_element(all(a))
#define pb push_back
#define pi pair<int,int>
#define pqq priority_queue
#define sort(a) sort(all(a))
#define reverse(a) reverse(all(a))
#define input(a) {for(int i1=0;i1<a.size();i1++) cin>>a[i1];}
#define display(a) {for(int i1=0;i1<a.size();i1++) cout<<a[i1]<<" "; cout<<endl;}
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned ll
using namespace std;
#define manhat(a,b) (abs((a[0]-b[0])) + abs((a[1]-b[1])))
void solve(){
	int n; cin>>n; vector< vi> a(n,vi(2,0)); ull ans = 0;
	for(int i=0;i<n;i++) input(a[i]);
	vi plus,minus;
	for(int i=0;i<n;i++) plus.pb(a[i][0]+a[i][1]);
	for(int i=0;i<n;i++) minus.pb(a[i][0]-a[i][1]);
	ll x = maxelem(plus)-minelem(plus) , y = maxelem(minus)-minelem(minus);
	cout<<max(x,y)<<endl;
}
int main()
{
    IOS
    //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}

Measured memory_bytes: 18900
#include <iostream>
#include <vector>
using namespace std;
/*
int rec(vector<int> t, int s, int g, int N, vector< vector<int> > C){
  bool f = true;
  for(int i = 0; i < N; ++i){
    if(t[i]){
      f = false;
      break;
    }
  }

  if(f) return C[s][g];
  
  int ret = 0;
  for(int i = 0; i < N; ++i){
    if(t[i]){
      vector<int> t_ = t;
      t_[i] = 0;
      ret = max(ret,rec(t_,i,g,N,C) + C[s][i]);
    }
  }
  return ret;
}

int main(){
  int N;
  cin >> N;
  vector< vector<int> > C(N,vector<int>(N));
  int sum = 0;
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < N; ++j){
      cin >> C[i][j];
      sum += C[i][j];
    }
  }
  int ans = 0;
  vector<int> init(N,1);
  for(int i = 0; i < N; ++i){

    vector<int> t = init;
    t[i] = 0;
    //cout << rec(t,i,i,N,C) << endl;
    ans = max(ans,rec(t,i,i,N,C));
  }
  cout << sum - ans << endl;
  return 0;
}


int main(){
  int N, INF = 1000000000;
  cin >> N;
  vector< vector<int> > G(N,vector<int>(N));
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < N; ++j) cin >> G[i][j];
  }
  int ans = INF;
  for(int s = 0; s < N; ++s){
    int t = 0, m, v = s;
    vector<bool> connected(N,false);
    connected[s] = true;
    for(int j = 1; j < N; ++j){
      m = INF;
      for(int i = 0; i < N; ++i){
        if(!connected[i] && G[s][i] < m){
          m = G[v][i];
          v = i;
        }
      }
      t += m;
      connected[v] = true;
    }
    t += min(G[s][v],G[v][s]);
    ans = min(t,ans);
  }
  cout << ans << endl;
  return 0;
}
*/

int main(){
  int N, INF = 1000000000;
  cin >> N;
  vector< vector<int> > G(N,vector<int>(N));
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < N; ++j) cin >> G[i][j];
  }
  long long int ans = 0;
  for(int i = 0; i < N; ++i){
    for(int j = i+1; j < N; ++j){
      ans += min(G[i][j],G[j][i]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3208
a=list(map(int,input().split()))
a=sorted(a)

if (a[1]-a[0]) % 2 ==0:
    print(a[2]-a[1] + (a[1]-a[0])//2)
else:
    print(1+ a[2]+1-a[1] + (a[1]-a[0]-1)//2)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		
		String s1 = "";
		String s2 = "";
		
		for(int i = 0 ; i < w ; i++) {
			if(a > i) {
				s1 += "1";
				s2 += "0";
			}
			else {
				s1 += "0";
				s2 += "1";
			}
		}
		
		
		for(int i = 0 ; i < h ;i++) {
			if(i < b) {
				System.out.println(s1);
			}
			else {
				System.out.println(s2);
			}
		}
		
	}
}



Measured memory_bytes: 33108
#include <stdio.h>
#include <string.h>
int main(){
    char arry[20];
    scanf("%s",&arry);
    int ln=strlen(arry),i;
    for(i=ln-1;i>=0;i--)
    {
        printf("%c",arry[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 932
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let n = readInt()
    var aryA = readInts()
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    aryA.sort(by: >)
    var value = aryA[0]
    var ans = 0
    for i in 1..<n {
        if i % 2 == 0 {
            value = aryA[i / 2]
        }
        ans += value
    }
    print(ans)
}
main()


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

string S;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int H, W;
    cin >> H >> W;

    for(int i=1; i<=H; i++)
    {
        cin >> S;
        cout << S << "\n";
        cout << S << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(){
  int N,D;
  cin >> N >> D;
  int a = N % (2*D + 1);
  if(a == 0) cout <<  N / (2*D + 1) << endl;
  else cout <<  (N / (2*D + 1))+1 << endl;
}


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

#define int long long

int a[500][500];
bool memo[500][500];

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

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

    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            for(int k = 0;k < n;k++){
                if(a[j][k] > a[j][i] + a[i][k]){
                    cout << -1 << endl;
                    return 0;
                }else if(a[j][k] == a[j][i] + a[i][k] && i != j && i != k){
                    memo[j][k] = true;
                }
            }
        }
    }


    int ans = 0;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            if(!memo[i][j]){
                ans += a[i][j];
            }
        }
    }

    cout << ans/2 << endl;

    return 0;
}


Measured memory_bytes: 1536