akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n - 3; i++) {
		if (s[i] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			goto loop;
		}
	}
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			goto loop;
		}
	}
	cout << -1 << " " << -1 << endl;
loop:;
	getchar(); getchar();
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll> a;
    rep(i, 3*n) {
        ll t;cin>>t;
        a.push_back(t);
    }
    sort(all(a));
    ll ans = 0;
    for(ll i=n; i<3*n; i+=2){
        ans += a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SUM(x, y) ((x==0)?sum[y]:(sum[y]-sum[x-1]))
typedef long long ll;
typedef vector<int> vi;

int *a;
vector<vector<ll>> dp;
ll *sum;

ll cost(int l, int r){
    if(l==r)
        return 0;
    if(dp[r][l]>=0)
        return dp[r][l];
    ll c=INT64_MAX;
    FOR(i, l, r){
        ll x=cost(l, i)+cost(i+1, r);
        if(x<c)
            c=x;
    }
    dp[r][l]=c+SUM(l, r);
    return dp[r][l];
}

int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    a=new int[n];
    sum=new ll[n];
    ll x=0;
    FOR(i, 0, n){
        cin>>a[i];
        x=x+a[i];
        sum[i]=x;
    }
    dp.resize(n);
    FOR(i, 0, n){
        dp[i].resize(i+1, -1);
    }

    cout<<cost(0, n-1)<<endl;
    return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, vector<long long> A) {
  int a = 0;
  int b = 0;
  REP(i, N) {
    if (A[i] % 2 == 0)
      a++;
    else
      b++;
  }

  if (a + b == 1) {
    cout << "YES" << endl;
    return;
  }

  a += (b / 2);
  b = b % 2 == 0 ? 0 : 1;

  a = a == 0 ? 0 : 1;

  // cout << a << " " << b << endl;
  cout << (a + b == 1 ? "YES" : "NO") << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> A(N - 1 + 1);
  for (int i = 0; i <= N - 1; i++) {
    cin >> A[i];
  }
  solve(N, A);
  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>

using namespace std;

int n,m;
int dp[102][102][2][2];

const int MOD = 100000;

int main(){
	while(scanf("%d %d",&n,&m) && (n || m)){
		dp[2][1][0][0] = 1;
		dp[1][2][1][0] = 1;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if((i == 1 || j == 1) && (i == 2 || j == 2)){continue;}
				//(i,j)É¶©çÈªç¸Éé = (i-1,j)É¶©çÈªç¸É½ + (i-1,j)É¶©çÈªÁÄ½
				dp[i][j][0][0] = (dp[i-1][j][0][0] + dp[i-1][j][0][1]) % MOD;
				//(i,j)É¶©çÈªÁÄé = (i-1,j)Éº©çÈªç¸É½
				dp[i][j][0][1] = (dp[i-1][j][1][0]) % MOD;
				//(i,j)Éº©çÈªç¸Éé = (i,j-1)Éº©çÈªç¸É½ + (i,j-1)Éº©çÈªÁÄ½
				dp[i][j][1][0] = (dp[i][j-1][1][0] + dp[i][j-1][1][1]) % MOD;
				//(i,j)Éº©çÈªÁÄé = (i,j-1)É¶©çÈªç¸É½
				dp[i][j][1][1] = (dp[i][j-1][0][0]) % MOD;
			}
		}
		
		printf("%d\n",(dp[n][m][0][0]+dp[n][m][0][1]+dp[n][m][1][0]+dp[n][m][1][1]) % MOD);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long

signed main()
{
  int l, r; cin >> l >> r;
  
  if (r - l >= 2019) {
    cout << 0 << endl;
    return 0;
  }
  
  int ans = 2019;
  
  for (int i = l; i <= r; ++i) {
  	for (int j = l; j < i; ++j) {
    	ans = min(ans, i*j%2019);
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long ll;
const int N=1e5+11,INF=~0u>>2;
int n,l,q,dp[20][N],a[N];
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int bs(int x){
	int l=0,r=n-1,ret=0;
	while(l<=r){
		int mid=(l+r)>>1;
		if(a[mid]<=x) l=mid+1,ret=mid;
		else r=mid-1;
	}
	return ret;
}
int main(){
//	freopen("ex.in","r",stdin);
	n=read();
	rep(i,n) a[i]=read();
	l=read();q=read();
	rep(i,n) dp[0][i]=bs(a[i]+l);
	rep(k,19) rep(i,n) dp[k+1][i]=dp[k][dp[k][i]];
	rep(i,q){
		int a=read(),b=read();a--;b--;
		if(a>b) swap(a,b);
		int ans=0;
		for(int j=19;j>=0;j--){
			if(dp[j][a]<b){
				a=dp[j][a];
				ans+=1<<j;
			}
		}
		printf("%d\n",ans+1);
	}
	return 0;
}

Measured memory_bytes: 9088
import java.util.*;

class Main
{
    static int[][]M = new int[100][100];

    static void Sing(int n)
    {
	int minv;
	int[]d = new int[100];
	int[]cl = new int[100];

	for(int i = 0; i < n; i++)
	    {
		d[i] = 200000;
		cl[i] = 0;
	    }

	d[0] = 0;
	cl[0] = 1;

	while(true)
	    {
		minv = 200000;
		int u = -1;

		for(int i = 0; i < n; i++)
		    {
			if(minv > d[i] && cl[i] != 2)
			    {
				u = i; 
				minv = d[i];
			    }
		    }

		if(u == -1) break;
		cl[u] = 2;

		for(int i = 0; i < n; i++)
		    {
			if(cl[i] != 2 && M[u][i] != 200000)
			    {
				if(d[i] > d[u] + M[u][i])
				    {
					d[i] = d[u] + M[u][i];
					cl[i] = 1;
				    }
			    }
		    }
	    }

	for(int i = 0; i < n; i ++)
	    {
		System.out.println(i + " " + (d[i] == 200000 ? -1 : d[i]));
	    }
    }
 
    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);

	int n = In.nextInt();

	for(int i = 0; i < n; i++)
	    {
		for(int j = 0; j < n; j++)
		    {
			M[i][j] = 200000;
		    }
	    }

	int p,q,r,s;

	for(int i = 0; i < n; i++)
	    {
		p = In.nextInt();
	        q = In.nextInt();

		for(int j = 0; j < q; j++)
		    {
			r = In.nextInt();
			s = In.nextInt();
			M[p][r] = s;
		    }
	    }

	Sing(n);
    }
}

Measured memory_bytes: 39492
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forr(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define ford(i, n) for (int i = n; i > 0; i--)
#define forin(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define debug(x) cerr<<#x<<" "<<x<<"\n";
#define yn {puts("YES");}else{puts("NO");}
#define maxs(x,y) (x = max(x,y))
#define sz(x) (int)(x).size()
#define mins(x,y) (x = min(x,y))
#define newline cout<<"\n"
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll inf= 1e9+5;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
	ll dp[100001];
	forn(i,100001) dp[i]= inf;
	ll n,W,w,v;
	cin >> n >> W;
	forn(i,n){
		cin >> w >> v;
		forr(j,100001){
			if(dp[j]+w <= W) mins(dp[v+j],dp[j]+w);
		}
		mins(dp[v],w);
	}
	forr(i,100001){
		if(dp[i] != inf) {
			cout << i;
			break;
		}
	}
	return 0;
}




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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
int N, M;
char a[51][51];
char b[51][51];

bool check(int x, int z)
{
   int tmp = z;
   for(int i = 1; i <=  M; i++, x++)
   {
      for(int j = 1, z= tmp; j <= M; j++, z++)
      {
         if(a[x][z] != b[i][j])
         {
            return false;
         }

      }
   }
   return true;
}
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   cin >> N >> M;
   for(int i = 1; i <= N; i++)
   {
      for(int j = 1; j <= N; j++)
         cin >> a[i][j];
   }

   for(int i = 1; i <= M; i++)
   {
      for(int j = 1; j <= M; j++)
         cin >> b[i][j];
   }
   for(int i =1; i <= N-M+1; i++)
   {
      for(int j = 1; j <= N-M+1; j++)
      {
         if(check(i, j))
         {
            cout << "Yes" << nl;
            return 0;
         }
      }
   }
   cout << "No" <<nl;
   return 0;


}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
    vector<int> h;
    int input;
    for (int i=0; i<10; ++i) {
        cin >> input;
        h.push_back(input);
    }

    partial_sort(h.begin(), h.begin()+3, h.end(), greater<int>());

    cout << h[0] << endl;
    cout << h[1] << endl;
    cout << h[2] << endl;
    return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
	int n,a,b;

	std::cin >> n >> a >> b;

	if(n * a > b)
		std::cout << b << std::endl;
	else
		std::cout << n * a << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>

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

using namespace std;

typedef long long ll;

#define MOD (1000000007)

ll n;
ll c[20], v[20];
ll a[20];

int main() {
    cin >> n;
    
    REP(i, n) {
        cin >> c[i];
    }
    
    REP(i, n) {
        cin >> v[i];
        a[i] = c[i] - v[i];
    }
    
    ll result = 0;
    REP(i, n) {
        if (a[i] > 0) {
            result += a[i];
        }
    }
    
    cout << result << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int n, l, s = 0;
    vector<int> v;
    cin >> n;
    for (int i = 0; i < n;i++) {
        cin >> l;
        v.push_back(l);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n-2; i++) {
        for (int j = i + 1; j < n-1; j++) {
            for (int k = j + 1;k < n;k++) {
                if (v[i] + v[j] > v[k] ) {
                    s ++;
                }
            }
        }
    }
    cout << s << endl;
}
 

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


int main(){
  int n;
  cin >> n;
  int ans=0;
  for(int i=0; i<=n; i++){
    if(1 <= i && i <= 9)ans++;
    else if(100 <= i && i <= 999)ans++;
    else if(10000 <= i && i <= 99999)ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int n, A, B, s[100005];

signed main(){
  
  cin>>n>>A>>B;
  
  for(int i=0;i<n;i++) cin>>s[i];
  
  if( A == B ){
    
    int x = 0;
    
    for(int i=0;i<n;i++){
      
      x ^= s[i] % ( A + 1 );
      
    }
    
    if( x == 0 ) cout<<"Jiro"<<endl;
    else cout<<"Hanako"<<endl;
    
  }
  
  if( A > B ){
    
    int flag = 0;
    
    for(int i=0;i<n;i++)
      if( s[i] > B ) flag = 1;
    
    if( flag == 1 ) cout<<"Hanako"<<endl;
    else{
      
      int x = 0;
    
      for(int i=0;i<n;i++) x ^= s[i];
      
      if( x == 0 ) cout<<"Jiro"<<endl;
      else cout<<"Hanako"<<endl;
      
    }
    
  }

  if( A < B ){
    
    int cnt = 0, idx;
    
    for(int i=0;i<n;i++)
      if( A < s[i] ) cnt++, idx = i;
    
    if( cnt > 1 ) cout<<"Jiro"<<endl;
    else{
      
      if( cnt == 1 ){
	
	if( s[idx] - A <= A ){
	  
	  int x = 0;
    
	  for(int i=0;i<n;i++)
	    if( s[i] <= A ) x ^= s[i];

	  if( s[idx] > x && s[idx] - x <= A && x <= A ) cout<<"Hanako"<<endl;
	  else cout<<"Jiro"<<endl;
	  
	} else cout<<"Jiro"<<endl;
	
      }else{
	
	int x = 0;
    
	for(int i=0;i<n;i++)
	  if( s[i] <= A ) x ^= s[i];

	if( x == 0 ) cout<<"Jiro"<<endl;
	else cout<<"Hanako"<<endl;
	
      }
      
    }
    
  }
      
  return 0;
}



Measured memory_bytes: 3904
require 'pp'

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

s_list = gets_nsp_list
acgt = %w(A C G T)

acgt_list = []
count = 0
max_count = 0
s_list.each do |s|
  if acgt.include?(s)
    count += 1
  else
    count = 0
  end
  max_count = [count, max_count].max
end

puts max_count

Measured memory_bytes: 2172
def nC2(n):
    return n*(n-1)//2

n = int(input())
a = list(map(int, input().split()))

cnt = [0]*(n+1)
total = 0
ans = 0

for i in range(n):
    cnt[a[i]] += 1

for i in range(1, n+1):
    total += nC2(cnt[i])

for i in range(n):
    print(total - nC2(cnt[a[i]]) + nC2(cnt[a[i]] - 1))

Measured memory_bytes: 24744
x, y, a, b, c = gets.split.map(&:to_i)

ps = gets.split.map(&:to_i).sort.reverse
qs = gets.split.map(&:to_i).sort.reverse
rs = gets.split.map(&:to_i).sort.reverse

ps = ps[0..x-1]
qs = qs[0..y-1]

arr = ps + qs + rs

arr.sort!
arr.reverse!

ans = 0
(x+y).times do |i|
    ans += arr[i]
end

puts ans


Measured memory_bytes: 33460
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC 131 -A
int main(void) {
	char s[5];
	scanf("%s", s);
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3] ) 
		 printf("Bad\n");
	else printf("Good\n");

	return 0;
}

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

using namespace std;

int main()
{
  int c[3][3];
  int a[3], b[3];
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
    	cin >> c[i][j];
    }
  }
  
  int i;
  for(i=0; i<=100; i++){
    a[0] = i;
    b[0] = c[0][0] - i;
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];
    b[1] = c[0][1] - a[0];
    b[2] = c[0][2] - a[0];
    
    int ret = 1;
    for(int j=0; j<3; j++){
      for(int k=0; k<3; k++){
        //printf("%d/%d ", a[j], b[k]);
        if(c[j][k] != a[j]+b[k])
          ret = 0;
      }
      //printf("\n");
    }
    if(ret)
      break;
  }
  if(i!=101)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())

typedef	long long ll;

const int MAXN = 2e5+1;
const ll MOD = 1e9 + 7;

ll ways[MAXN];
ll fact_inv[MAXN];
ll fact[MAXN];
int sz[MAXN];
int n;
vector<int> G[MAXN];

ll bin_pow(ll a, ll b)
{
	ll p = a;
	ll ret = 1;
	while (b > 0)
	{
		if (b%2)
			ret = (ret*p)%MOD;
		p = (p*p)%MOD;
		b /= 2;
	}
	return ret;
}

ll get_inv(ll a)
{
	return bin_pow(a, MOD-2);
}

void calc_fact(void)
{
	fact[0] = 1;
	fact_inv[0] = 1;
	for (int i(1); i < MAXN; ++i)
	{
		fact[i] = (fact[i-1] *i)%MOD;
		fact_inv[i] = get_inv(fact[i]);
	}
}


int calc_sz(int u, int p)
{
	sz[u] = 1;
	for (auto v :G[u])
		if (v != p)
			sz[u] += calc_sz(v, u);
	return sz[u];
}

ll solve_root(int u, int p)
{
	ways[u] = fact[sz[u]-1];

	for (auto v : G[u])
		if (v != p)
		{
			ll mul = (fact_inv[sz[v]] * solve_root(v, u))%MOD;
			ways[u] = (ways[u] * mul)%MOD;
		}
	return ways[u];
}

void reroot(int u, int p)
{
	ll new_ways_p = (ways[p] * get_inv((fact_inv[sz[u]] * ways[u])%MOD))%MOD;
	new_ways_p *= fact_inv[n-1];
	new_ways_p %= MOD;
	new_ways_p *= fact[n - 1 - sz[u]];
	new_ways_p %= MOD;
	ways[u] = (ways[u] * fact_inv[sz[u]-1]) % MOD;
	ways[u] = (ways[u] * fact[n-1])%MOD;
	ways[u] = (ways[u] * fact_inv[n-sz[u]])%MOD;
	ways[u]  = (ways[u] * new_ways_p)%MOD;

}

void solve(int u, int p)
{
	for (auto v : G[u])
		if (v != p)
		{
			reroot(v, u);
			solve(v, u);
		}
}

int main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> n;
	for (int i(1); i < n; ++i)
	{
		int u,v;
		cin >> u >> v;
		--u, --v;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	calc_fact();
	calc_sz(0,0);
	solve_root(0,0);
	solve(0,0);
	for (int i(0); i< n; ++i)
		cout << ways[i] << ' ';
	cout << endl;
}



Measured memory_bytes: 19444
#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_V 1002
using namespace std;
struct edge {
	int to, cap, rev;
	edge(int to_, int cap_, int rev_) : to(to_), cap(cap_), rev(rev_) {};
};

int V;
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

int GCD(int a, int b) {
	return b ? GCD(b, a % b) : a;
}

void AddEdge(int from, int to, int cap) {
	G[from].push_back(edge(to, cap, G[to].size()));
	G[to].push_back(edge(from, 0, G[from].size() - 1));
}

void BFS(int s) {
	fill(level, level + V, -1);
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (size_t i = 0; i < G[v].size(); i++) {
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int DFS(int v, int t, int f) {
	if (v == t) return f;
	for (int &i = iter[v]; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			int d = DFS(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int Dinic(int s, int t) {
	int flow = 0;
	while (true) {
		BFS(s);
		if (level[t] < 0) return flow;
		fill(iter, iter + V, 0);
		int f;
		while ((f = DFS(s, t, INF)) > 0) {
			flow += f;
		}
	}
}

int main()
{
	int m, n;
	while (cin >> m >> n, m || n) {
		vector<int> b(m), r(n);
		V = m + n + 2;
		for (int i = 0; i < m; i++) {
			cin >> b[i];
			AddEdge(m + n, i, 1);
		}
		for (int i = 0; i < n; i++) {
			cin >> r[i];
			AddEdge(m + i, m + n + 1, 1);
		}
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				if (GCD(b[i], r[j]) != 1) {
					AddEdge(i, m + j, 1);
				}
			}
		}
		cout << Dinic(m + n, m + n + 1) << endl;
		for (int i = 0; i < V; i++) {
			G[i].clear();
		}
	}
	return 0;
}

Measured memory_bytes: 9456
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	int N;
   	cin>>N;
   	string str;
   	cin>>str;

   	int count[N][3];
   	count[N-1][0]=count[N-1][1]=count[N-1][2]=0;
   	int x=0,y=0,z=0;
   	if(str[N-1]=='R')
   		x++;
   	else if(str[N-1]=='G')
   		y++;
   	else
   		z++;
   	for(int i=N-2;i>=0;i--)
   	{
   		count[i][0]=x;
   		count[i][1]=y;
   		count[i][2]=z;
   		if(str[i]=='R')
   			x++;
   		else if(str[i]=='G')
   			y++;
   		else
   			z++;
   	}


   	long long ans=0;
   	for(int i=0;i<N;i++)
   	{
   		for(int j=i+1;j<N;j++)
   		{
   			if(str[j]==str[i])
   				continue;

   			int dist=j-i;
   			int color=0;
   			if((str[i]=='R' && str[j]=='G') || (str[i]=='G' && str[j]=='R'))
   				color=2;
   			if((str[i]=='B' && str[j]=='G') || (str[i]=='G' && str[j]=='B'))
   				color=0;
   			if((str[i]=='R' && str[j]=='B') || (str[i]=='B' && str[j]=='R'))
   				color=1;

   			ans+=count[j][color];
   			if(j+dist<N && ((color==2 && str[j+dist]=='B') || (color==1 && str[j+dist]=='G') || (color==0 && str[j+dist]=='R')))
   				ans--;
   		}
   	}
   	cout<<ans<<endl;
    
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, ans = 0; cin >> n;
	string s; cin >> s;
	for(int i = 0; i <= n - 3; i++){
		if(s.substr(i, 3) == "ABC") ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
function main(NS) {
    const [N, S]= NS.split("\n")
    const N1 = parseInt(N)

    const T1 = S.slice(0, N1 / 2)
    const T2 = S.slice(N1 / 2, N1)

    const result = T1 === T2 ? "Yes" : "No"
    console.log(result)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
vi cnt(555555);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  for(auto &a:A){cin>>a;cnt[a]++;}
  ll ans = 0;
  for(int i=1;i<=n;i++){
    ans += cnt[i]*(cnt[i]-1)/2;
  }
  //cout<<ans<<endl;
  for(int i=0;i<n;i++){
    cout<<ans-cnt[A[i]]+1<<endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

int n;
const ll maxn = 21+5;
ll MOD = 1e9+7;
bool a[maxn][maxn];
ll dp[maxn][1ll<<22];

ll dfs(int i, bitset<21> s) //now to choose, remaining
{
  ll ls = ll(s.to_ulong());
  if(dp[i][ls] != -1ll) return dp[i][ls];
  if(i == n) {assert(ls == 0ll); return 1ll;}
  if(ls==0ll) return 0ll;
  ll ret = 0ll;
  for(int j = 0; j < n; j++)
  if(a[i][j] && s.test(j))
  {
    s.reset(j);
    ret = (ret+dfs(i+1, s))%MOD;
    s.set(j);
  }
  return dp[i][ls] = ret;
}

int main()
{
  cin >> n;
  for(int i = 0; i < n; i++)for(int j = 0; j < n; j++) cin >> a[i][j];
  bitset<21> u;
  for(int i = 0; i < n; i++) u.set(i);
  //cout << u << endl;
  memset(dp, -1ll, sizeof(dp));
  ll ans = dfs(0, u);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 852352
var i,j,k:Longint;
s:String;
begin
readln(s);
i:=1;
while s[i]<>' 'do inc(i);
j:=i;
for k:=i+1 to length(s)do write(s[k]);
for k:=1 to i-1 do write(s[k]);
writeln;
end.

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

int n;
vector<int> a, b, res;

bool solve();

int main() {
  cin >> n;
  a.resize(n);
  for (auto &p : a) cin >> p;
  b.resize(n);
  for (auto &p : b) cin >> p;
  if (solve()) {
    cout << "Yes" << endl;
    for (int i = 0; i < n; ++i) cout << res[i] << " \n"[i == n - 1];
  } else
    cout << "No" << endl;
  return 0;
}

bool solve() {
  vector<int> cnta(n + 1, 0), cntb(n + 1, 0);
  for (int i = 0; i < n; ++i) {
    ++cnta[a[i]];
    ++cntb[b[i]];
  }
  for (int i = 1; i <= n; ++i) {
    if (cnta[i] + cntb[i] > n) return 0;
    cnta[i] += cnta[i - 1];
    cntb[i] += cntb[i - 1];
  }
  int dif = 0;
  for (int i = 1; i <= n; ++i) dif = max(dif, cnta[i] - cntb[i - 1]);
  res.resize(n);
  for (int i = 0; i < n; ++i) res[(i + dif) % n] = b[i];
  return 1;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int week = a * 7 + b;
  int day = a;
  cout << min((c / week) * 7 + ((c % week + day - 1) / day), ((c + week - 1) / week) * 7) << endl;
  return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[200005],fl=0;

  cin>>n;

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

  sort(a,a+n);

  for(int i=0; i<n-1; i++){
    if(a[i]==a[i+1])fl=1;
  }

  if(fl)cout<<"NO"<<'\n';
  else cout<<"YES"<<'\n';

  return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

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

	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int tmp;

	if (a > b) {
	    tmp = a;
	    a = b;
	    b = tmp;
	}
	if (a > c) {
	    tmp = a;
	    a = c;
	    c = tmp;
	}
	if (b > c) {
	    tmp = b;
	    b = c;
	    c = tmp;
	}

	System.out.println(a + " " + b + " " + c);
    }
}

Measured memory_bytes: 26056
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    cunt_a=0
    cunt_b=0
    cunt_ba=0
    cunt_ab=0
    for i in range(n):
        s=input()
        if s[0]=='B' and s[-1]=='A':
            cunt_ba+=1
        elif s[0]=='B': 
            cunt_b+=1
        elif s[-1]=='A':
            cunt_a+=1
        for j in range(len(s)-1):
            if s[j:j+2]=="AB":
                cunt_ab+=1
    if cunt_a==0 and cunt_b==0 and cunt_ba>0:
        print(cunt_ab+cunt_ba-1)
    else:
        print(cunt_ab+cunt_ba+min(cunt_a,cunt_b))
    
if __name__=='__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>

#define N 100
#define min(a, b) ( a < b ? a : b )
#define max(a, b) ( a > b ? a : b )
#define INF 999999

int main(void)
{
    int i, j, l, k ,q;
    int n;
    int r, c;
    int p[N+1] = {0};
    int m[(N+1)*(N+1)] = {0};

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

    for( i=1; i<=n; ++i )
        m[i*n+i] = 0;

    for( l=2; l<=n; ++l ) {
        for( i=1; i<=n-l+1; ++i ) {
            j = i + l - 1;
            m[i*n+j] = INF;
            for( k=i; k<=j-1; ++k ) {
                q = m[i*n+k] + m[(k+1)*n+j] + p[i-1] * p[k] * p[j];
                m[i*n+j] = min( m[i*n+j], q );
            }
        }
    }

    printf( "%d\n", m[1*n+n] );

    return 0;
}

Measured memory_bytes: 644
#include <stdio.h>

int main()
{
	int i, n;
	double m = 0;

	while (scanf("%d", &n) != EOF) {
		m = 0;
		for (i = 0; i * n < 600; i++) {
			m += (i * n) * (i * n) * n;
		}
		printf("%d\n", (int)m);
	}
	return 0;
}

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

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9 + 7;
    static vector<modint> factorial;
 
    modint(): num(0) {};
    modint(ll num_): num((num_ + MOD) % MOD) {
        assert(num >= 0);
    }
    modint(const modint &r): num(r.num) {}
    operator ll() const { return num; }
 
    template <typename T>
    void check_type(const T &num_) const {
        assert(num_ >= 0 && num_ < MOD);
        static_assert(is_integral<T>() || is_same<T,modint>(), "T is not integral.");
    }
 
    template <typename T>
    modint operator+(const T &r) const { check_type(r); return num + r; }
    template <typename T>
    modint operator-(const T &r) const { check_type(r); return num - r; }
    template <typename T>
    modint operator*(const T &r) const { check_type(r); return num * r; }
    template <typename T>
    modint operator/(const T &r) const { check_type(r); return num * pow(r, MOD-2); }
 
    template <typename T>
    modint operator+=(const T &r) { return *this = *this + r; }
    template <typename T>
    modint operator-=(const T &r) { return *this = *this - r; }
    template <typename T>
    modint operator*=(const T &r) { return *this = *this * r; }
    template <typename T>
    modint operator/=(const T &r) { return *this = *this / r; }
 
    static modint pow(const modint &x, const ll &r) {
        if(r == 0) return 1;
        return pow(x*x, r/2) * modint(r&1 ? x : modint(1));
    }
 
    static modint fact(int n){
        if((int)factorial.size() <= n) {
            int size = factorial.size();
            factorial.resize(n+1);
            for (int k = size; k <= n; k++) {
                factorial[k] = factorial[k-1] * k;
            }
        }
        return factorial[n];
    }
 
    static modint C(int n, int r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
 
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
};
vector<modint> modint::factorial = {1};
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)
 
 
int main() {
    int X,Y;
    cin>>X>>Y;
    int x = 2 * Y - X;
    int y = 2 * X - Y;
    ll ans;
    if(x >= 0 && y >= 0 && x % 3 == 0 && y % 3 ==0){
        x /= 3;
        y /= 3;
        ans = H(x,y);
    }
    else{
        ans = 0;
    }
    cout<<ans<<endl;
}

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

const int MAXN = 110000;
int dp[MAXN];

int rec_bank(int n) {
  int ret = n;
  if (n == 0)
    return 0;
  if (dp[n] != -1)
    return dp[n];

  for (int pow6 = 1; pow6 <= n; pow6 *= 6)
    ret = min(ret, rec_bank(n - pow6) + 1);
  for (int pow9 = 1; pow9 <= n; pow9 *= 9)
    ret = min(ret, rec_bank(n - pow9) + 1);
  return dp[n] = ret;
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < MAXN; i++)
    dp[i] = -1;
  cout << rec_bank(N) << endl;
  return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define ld          long double
#define endl        "\n"

const int mod = 1e9+7;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }

void solve() {  
    int n; cin >> n;
    int pos[n+1]; pos[0] = 0;
    for(int i=1; i<=n; i++) {
        int x; cin >> x;
        pos[x] = i;
    }
    int ans = 0;
    multiset<int> s;
    s.insert(0); s.insert(0);
    s.insert(n+1); s.insert(n+1);
    s.insert(pos[n]);
    for(int cur=n-1; cur>0; cur--) {
        int l1, l2, r1, r2;
        int cp = pos[cur];
        auto it = s.lower_bound(cp); 
        r1 = *it; 
        auto it2 = it;
        it2++;
        r2 = *it2;
        it2 = (--it);
        l1 = *it2;
        l2 = *(--it2);
        //cout << l1 << " " << l2 << " " << r1 << " " << r2 << endl;
        ans += cur * ((cp-l1)*(r2-r1) + (l1-l2)*(r1-cp));
        s.insert(cp);
    }
    cout << ans << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(18);

    int T = 1;
    //cin >> T;

    while(T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main(){
    string answer="Yay!";
    int a,e,k,dummy;
    scanf("%d%d%d%d%d%d",&a,&dummy,&dummy,&dummy,&e,&k);
    if(e-a>k) answer=":(";
    cout << answer;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))

    r = sum(A)
    l = 0
    min_diff = r
    for ai in A:
        r -= ai
        l += ai
        min_diff = min(min_diff, abs(r - l))

    print(min_diff)

if __name__ == "__main__":
    main()


Measured memory_bytes: 26220
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
 
// https://atcoder.jp/contests/abc122/submissions/492095626
 
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
 
int main(void) {
    int N, Q;
    char S[100001];
    scanf("%d %d", &N, &Q);
    scanf("%s", S);
 
    int ans[100001]={0};
    int i, j;
    for( i=0; i<N; i++) {
      // 「右隣がCであるようなA」を数える
      ans[i+1] = ans[i];
      if( S[i]=='A' && S[i+1]=='C') {
        ans[i+1]++;
      }
    }
 
    int ans2[100001];
    int l, r;
    for( i=0; i<Q; i++) {
      scanf("%d %d", &l, &r);
      ans2[i] = ans[r-1]-ans[l-1];
    }
 
    for( i=0; i<Q; i++) {
      printf("%d\n", ans2[i]);
    }
 
return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
int a[N];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,i,su=0;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=1;i<n;i++)
	{
		if(i&1)su+=a[i];
		else su-=a[i];
	}
	int x=(a[0]+su)/2;
	a[0]=x;
	vector<int>ans;
	for(i=0;i<n-1;i++)
	{
		ans.push_back(a[i]*2);
		a[i+1]-=a[i];
	}
	cout<<a[i]*2;
	for(auto y:ans)
		cout<<" "<<y;
	cout<<'\n';
}


Measured memory_bytes: 2296
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;
ll A,B,C;

ll F(ll a,ll b, ll c){
    if(a==0||b==0||c==0)return INF;
    return abs(a-A)+abs(b-B)+abs(c-C);
}

int main(){
    ll N;
    cin >> N;
    cin >> A;
    cin >> B;
    cin >> C;
    vector<ll> l(N+1,0);
    for(ll i=0;i<N;i++){
        cin>>l[i+1]
    ;}
    ll ans=INF;
    for(ll bits=0;bits<(1<<(2*N));bits++){
        ll a=0,b=0,c=0;
        ll cost=0;
        for(ll j=1;j<=N;j++){
            bool s=0,t=0;
            if(bits&(1<<(2*j-2)))s=1;
            if(bits&(1<<(2*j-1)))t=1;
            if(s&&t){if(a>0)cost+=10;a+=l[j];}
            if(s&&(!t)){if(b>0)cost+=10;b+=l[j];}
            if((!s)&&t){if(c>0)cost+=10;c+=l[j];}
        ;}
        cost+=F(a,b,c);
        ans=min(ans,cost);
    ;}
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
typedef long long ll;
const int N=305;
const ll inf=1ll<<60;
int n;
ll path[N][N],ans=0;
using namespace std;

/*struct node
{
	int t,next;
}adj[N<<1];
void add(int s,int t)
{
	adj[++now]=(node){t,head[s]};
	head[s]=now;
}*/
inline int read()
{
	char c;int x;
	while (c=getchar(),c<'0' || c>'9');x=c^'0';
	while (c=getchar(),c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x;
}
void write(int x)
{
	if (x==0) return;
	write(x/10);
	putchar((x%10)+'0');
}
void upd(int& x,int y){if (x==-1) x=y;else x=max(x,y);}
int main()
{
	#ifdef Kay
		freopen ("code.in","r",stdin);
		freopen ("code.out","w",stdout);
	#endif
	cin>>n;
	int i,j,k;
	for (i=1;i<=n;i++)
	for (j=1;j<=n;j++)
	cin>>path[i][j];
	for (i=1;i<=n;i++)
	for (j=1;j<=n;j++)
	for (k=1;k<=n;k++)
	if (path[i][j]+path[j][k]<path[i][k]){puts("-1");return 0;}
	for (i=1;i<=n;i++)
	for (j=i+1;j<=n;j++)
	ans+=path[i][j];
	for (i=1;i<=n;i++)
	for (j=i+1;j<=n;j++)
	{
		for (k=1;k<=n;k++)
		if (i!=k && j!=k && path[i][k]+path[k][j]==path[i][j]) break;
		if (k<=n) ans-=path[i][j];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
ll a[70][2];
ll res;
ll md=1e9+7;
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		ll x;
		scanf("%lld",&x);
		for (ll j=0;j<60;j++)
		{
			if (x & ((ll)1<<j)) a[j][1]++;
			else a[j][0]++;
		}
	}
	for (int i=0;i<60;i++)
		res=(res+(((a[i][0]*a[i][1])%md)*(((ll)1<<i)%md))%md)%md;
	printf("%lld",res);
	return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int gcd(int a,int b){
  if(a%b==0){
    return b;
  }else{
    return(gcd(b,a%b));
  }
}
int main(){
  ll a,b;
  cin>>a>>b;
  ll ans=a*b;
  
  if(a>=b){
    ans/=gcd(a,b);
  }else{
    ans/=gcd(b,a);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n, a, b, c, x;

int next_rand() {
    x = (a * x + b) % c;
    return x;
}

int main() {
    while (cin >> n >> a >> b >> c >> x) {
        if ((n || a || b || c || x) == 0) break;
        int slot[n];
        for (int i = 0; i < n; i++) cin >> slot[i];

        int frame = 0;
        int next = x;
        for (int i = 0; i < n; i++) {
            while (frame <= 10000) {
                if (next == slot[i]) {
                    next = next_rand();
                    if (i == n-1) break;
                    else {
                        frame++;
                        break;
                    }
                }
                next = next_rand();
                frame++;
            }
        }

        if (frame > 10000) cout << -1 << endl;
        else cout << frame << endl;
    }
    return 0;
}

Measured memory_bytes: 864
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;

int main(){
	int n;
	while(scanf("%d",&n)==1,n){
		int sdiv = 1;
		for(int x=2;x<=sqrt(n);++x){
			if(n%x==0){
				sdiv += x + (n/x);
				if(x*x==n)sdiv-=x;
			}
		}
		if(n==1)sdiv = 0;
		if(sdiv==n)cout<<"perfect number"<<endl;
		if(sdiv>n)cout<<"abundant number"<<endl;
		if(sdiv<n)cout<<"deficient number"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {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;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)
template <class T> bool is_prime(T IN) { if (IN <= 1) return false; for (long long i = 2; i * i <= IN; i++) { if (IN % i == 0) { return false; } } return true; } template <class T> vector<pair<long long, long long>> primefact(T x) { vector<pair<long long, long long>> ret; ll cpyx=x; for (long long i = 1; i * i <= x; i++) { if (x % i == 0) { vector<long long> alt = {i, x / i}; if (alt[0] == alt[1]) alt[1] = 1; for (long long j = 0; j < alt.size(); j++) { if (is_prime(alt[j])) { pair<long long, long long> t = make_pair(alt[j], 0); while (cpyx % alt[j] == 0) { cpyx /= alt[j]; t.second++; } ret.push_back(t); } } } } return ret; }
long long INF = 1LL<<60;
int main( ){
    ll n;
    cin>>n;
    vpllll pf=primefact(n);
    ll ans=0;
    for(pllll t:pf){
        ll minu=1;
        while(minu<=t.second){
            t.second-=minu;ans++;minu++;
        }
    }
    cout<<ans<<endl;
    return 0;
}




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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll n,ans=0,abc[3];
	cin>>n;
	ll dp[n+1][3];
	memset(dp,0,sizeof(dp));
	forni(i,n+1){
		forn(j,3) cin>>abc[j];
		forn(j,3){
			forn(k,3) if(j!=k) dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[j]);
		}
	}
	forn(i,3) ans = max(ans,dp[n][i]);
	cout<<ans<<'\n';
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""
 


Measured memory_bytes: 5968
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int V,E;

vector<int> G[10000];
vector<int> reverse_G[10000];
stack<int> S;

int topo_rank[10000];
bool check[10000];

void dfs(int node_id){
	check[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		if(!check[G[node_id][i]])dfs(G[node_id][i]);
	}
	S.push(node_id);
}

void reverse_dfs(int node_id,int num){
	check[node_id] = true;
	topo_rank[node_id] = num;

	for(int i = 0; i < reverse_G[node_id].size(); i++){
		if(!check[reverse_G[node_id][i]])reverse_dfs(reverse_G[node_id][i],num);
	}
}


int main(){

	scanf("%d %d",&V,&E);

	for(int i = 0; i < V;i++)check[i] = false;

	int from,to;

	for(int loop = 0; loop < E; loop++){
		scanf("%d %d",&from,&to);
		G[from].push_back(to);
		reverse_G[to].push_back(from);
	}

	for(int i = 0; i < V;i++){
		if(!check[i])dfs(i);
	}

	int num = 0;

	for(int i = 0; i < V;i++)check[i] = false;

	while(!S.empty()){
		if(!check[S.top()])reverse_dfs(S.top(),num++);
		S.pop();
	}

	int Q,left,right;
	scanf("%d",&Q);

	for(int loop = 0; loop < Q; loop++){
		scanf("%d %d",&left,&right);
		if(topo_rank[left] == topo_rank[right]){
			printf("1\n");
		}else{
			printf("0\n");
		}
	}

	return 0;
}

Measured memory_bytes: 4816
#include<stdio.h>
#include<string.h>
int main()
{
    int n,a=0,b=0,i,x;
    char s[10];
    gets(s);
    x=strlen(s);
    for(i=0;i<x;i++)
    {
        if(s[i]=='+')
            a++;
        if(s[i]=='-')
            b++;
    }
    n=a-b;
    printf("%d\n",n);
    return 0;

}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int n, x, *m;

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

    int minimum = m[0];
    int sum = m[0];
    for (i = 1; i < n; i++) {
        minimum = min(minimum, m[i]);
        sum += m[i];
    }
    


    cout << n + (x - sum) / minimum << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

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

    if(n/10 == 9 || n%10 == 9) cout << "Yes" << endl;
    else cout << "No" << endl;
 }

Measured memory_bytes: 256