akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	int n, w;
	cin >> n >> w;
	vector<mp> v(n+1);
	rep(i, n) cin >> v[i].sec >> v[i].fir;
	if(v[0].sec > 300){
		int u = v[0].sec;
		sort(v.rbegin(), v.rend());
		int c = 0;
		rep(i, w/(u+3)) c += v[i].fir;
		w -= (w/(u+3)+1)*(u-1);
		if(w <= 0){cout << c << endl; return 0;}
		rep(i, n) v[i].sec -= u-1;
		vector<int> d(min(w, n*4)+1, -1); d[0] = 0;
		rep(i, n) irep(j, d.size()) if(d[j] != -1 && j+v[i].sec < d.size()) d[j+v[i].sec] = max(d[j+v[i].sec], d[j]+v[i].fir);
		cout << max(c, *max_element(d.begin(), d.end())) << endl;
	}else{
		vector<int> d(min(w, n*(v[0].sec+3))+1, -1); d[0] = 0;
		rep(i, n) irep(j, d.size()) if(d[j] != -1 && j+v[i].sec < d.size()) d[j+v[i].sec] = max(d[j+v[i].sec], d[j]+v[i].fir);
		cout << *max_element(d.begin(), d.end()) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <numeric>
#include <ctime>
using namespace std;

typedef long long ll;

vector<ll> v;

ll pow10_(ll x){
	ll res = 1;
	for(ll i = 0; i < x; i++){
		res *= 10;
	}
	
	return res;
}

string i_to_s(ll n){
	string s;
	
	do{
		s.push_back( (n % 10) + '0' );
		n /= 10;
	}while(n != 0);
	
	reverse(s.begin(), s.end());
	
	return s;
}

ll search(ll k, ll d, ll &x){
	ll low = 0, high = 1e+18;
	while(high - low > 1){
		ll mid = (low + high) / 2;
		ll n = (d + 1) * mid;
		
		if(n < k){
			low = mid;
		}else{
			high = mid;
		}
	}
	
	ll a = (d + 1) * low;
	ll b = (d + 1) * high;
	
	if(b <= k){
		x = high;
		return b;
	}
	x = low;
	return a;
}

char solve(ll pos){	
	for(int i = 0; i < v.size(); i++){
		if(0 <= pos - v[i]){
			pos -= v[i];
		}else{
			ll x;
			ll n = search(pos, i, x);
			pos -= n;
			x = x + pow10_(i);
			string s = i_to_s(x);
			
			for(int j = 0; j < s.size(); j++){
				if(pos == 0){
					return s[j];
				}
				
				pos--;
			}
		}
	}
	
	return 0;
}
 
int main(){
	
	for(ll i = 1, n = 9; i <= 19; i++, n*= 10){
		v.push_back(n * i);
	}
	
	ll N, K;
	
	while(cin >> N >> K, N || K){
		for(int i = N - 1; i < N + K - 1; i++){
			cout << solve(i);
		}
		cout << endl;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll n; cin >> n;
  string s; cin >> s;
  ll ans = 0;
  REP(i, n-1){
    ll cnt[2][26] = {0};
    REP(j, i+1) cnt[0][s[j]-'a']++;
    FOR(j, i+1, n) cnt[1][s[j]-'a']++;
    ll tmp = 0;
    REP(j, 26){
      if(cnt[0][j] > 0 && cnt[1][j] > 0) tmp++;
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string n;
	cin>>n;
	for(int i=0;i<n.size();i++){
		
		if(n[i]=='?'){
			cout<<"D";
		}else{
			cout<<n[i];
		}
	}
	return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

typedef long long ll;
using namespace std;

int main() {
    
    int n, k;
    cin >> n >> k;
    
    vector<int> x(n, 0), y(n, 0);
    
    int s = k * 2;
    
    for (int i = 0; i < n; i++) {
        char c;
        cin >> x[i] >> y[i] >> c;
        x[i] %= s;
        y[i] = (y[i] % s + (c == 'B' ? k : 0)) % s;
    }
    
    vector<vector<int>> imos(s + 1, vector<int>(s + 1, 0));
    for (int i = 0; i < n; i++) {
        imos[x[i] + 1][y[i] + 1]++;
    }
    for (int v = 0; v <= s; v++) {
        for (int u = 1; u <= s; u++) {
            imos[u][v] += imos[u-1][v];
        }
    }
    for (int u = 0; u <= s; u++) {
        for (int v = 1; v <= s; v++) {
            imos[u][v] += imos[u][v-1];
        }
    }
    
    int ans = 0;
    for (int u = 0; u < s; u++) {
        for (int v = 0; v < s; v++) {
            int cand = 0;
            for (int q = -2; q <= 2; q++) {
                for (int w = -2; w <= 2; w++) {
                    if (((q + w) % 2 + 2) % 2 == 1) continue;
                    int us = min(s, max(0, u + q * k));
                    int vs = min(s, max(0, v + w * k));
                    int ue = min(s, max(0, u + (q + 1) * k));
                    int ve = min(s, max(0, v + (w + 1) * k));
                    cand += imos[ue][ve] - imos[us][ve] - imos[ue][vs] + imos[us][vs];
                }
            }
            if (cand > ans) ans = cand;
        }
    }
    
    cout << ans << endl;
    
}

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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{

	int ii, jj;
	int slen;
	int plen;
	char p[101];
	char s[101];
	int is_ok;
	int is_same;
	char c;

	scanf("%s", s);
	scanf("%c", &c);
	scanf("%s", p);

	slen = strlen(s);
	plen = strlen(p);

	is_same = 0;
	is_ok = 0;
	for (ii = 0; ii < slen; ii++) {
		if (s[ii] == p[0]) {
			is_same = 1;
			for (jj = 1; jj < plen; jj++) {
				if (s[(ii + jj)%slen] != p[jj]) {
					is_same = 0;
					break;
				}
			}
			if (is_same == 1) {
				is_ok = 1;
				break;
			}
		}
	}
	if (is_ok == 1) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;

}

Measured memory_bytes: 524
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
xs = na()
xs.sort()

ds = []
for i in range(m-1):
    ds.append(xs[i+1] - xs[i])

ds.sort()

to = m - n
print(sum(ds[0:to]) if to > 0 else 0)


Measured memory_bytes: 14076
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    double N, K;
    cin >> N >> K;
    
    double ans = 0;
    for(int i=1;i<=N;i++){  // サイコロを振る
        int p = i;
        if(p >= K){
            ans += 1/N;
        }else{
            int count = 0;
            while(p < K){
                p = p*2;
                count++;
            }
            ans += (1/N)*pow(0.5, count);
        }
    }
   
    printf("%.12lf\n", ans);

}

Measured memory_bytes: 512
#!/usr/bin/env python3

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

def f(n):
    ans = 0 
    while n%2 == 0:
        n //= 2
        ans += 1
    return ans 

ans = 0 
for i in a:
    ans += f(i)

print(ans)


Measured memory_bytes: 4148
/* ex7_1 
melo */
#include <stdio.h>
#include <math.h>
typedef struct{//構造体"point"
    double x_elem;//x座標
    double y_elem;//y座標
}point;
point square_point(point top1,point top2){//top2の隣の正方形の頂点を求める関数
    point top3;//もうひとつの頂点
    point deg45 ={cos(M_PI/4),sin(M_PI/4)};//半径１の円の45度の座標
    //45度回してsqrt(2)をかけた座標を求める
    top3.x_elem=sqrt(2)*(deg45.x_elem*(top2.x_elem-top1.x_elem)-deg45.y_elem*(top2.y_elem-top1.y_elem))+top1.x_elem;
    top3.y_elem=sqrt(2)*(deg45.x_elem*(top2.y_elem-top1.y_elem)+deg45.y_elem*(top2.x_elem-top1.x_elem))+top1.y_elem;
    return top3;//もうひとつの頂点を返す
}
int main(void){
    point top1,top2,top3,top4;//4頂点
    scanf("%lf %lf %lf %lf",&top1.x_elem,&top1.y_elem,&top2.x_elem,&top2.y_elem);//頂点1,2を入力する
    top3=square_point(top1,top2);//２の隣の頂点を求める
    top4=square_point(top2,top3);//3の隣の頂点を求める
    printf("%.0lf %.0lf %.0lf %.0lf\n",top3.x_elem,top3.y_elem,top4.x_elem,top4.y_elem);//頂点3,4の整数部を出力する
    return 0;//正常終了
}


Measured memory_bytes: 1728
S = input()
n = len(S)
s0 = 0
s1 = 0

for i in range(n):
    if i % 2 == 0:
        if S[i] != "0":
            s0 += 1
        else :
            s1 += 1
    
    else:
        if S[i] != "1":
            s0 += 1
        else:
            s1 += 1

if s0 > s1:
    print(s1)
else:
    print(s0)

Measured memory_bytes: 3188
n = int(input())
a = list(map(int, input().split()))
a.append(0)
a.insert(0,0)
cnt = 0
for i in range(n+1):
	cnt += abs(a[i+1] - a[i])

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



Measured memory_bytes: 14048
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

int main(){
  string buff;
  int ccc = 0;
  while(getline(cin,buff)){
    char strt[2048];
    int len = 0;

    for(int i=0; i<buff.size(); i++)
      if(isalpha(buff[i]))
        strt[len++] = toupper(buff[i]);
    strt[len++] = '\0';

    string str(strt);
    set<string> ans;
    set<string> bad;

    for(int l = str.size(); l >= 3; l--){
      for(int i = 0; i+l-1 < str.size(); i++){
        int ll = i;
        int rr = i + l - 1;
        bool f = true;
        //cout << "test: " << str.substr(i, l) << endl;
        while(ll < rr){
          if(str[ll] == str[rr]){
            ll++; rr--;
          }else{
            f = false;
            break;
          }
        }

        if(f){
          string nstr = str.substr(i, l);
          if(bad.find(nstr) == bad.end()){
            // bad.insert(nstr);
            ans.insert(nstr);
            for(int ii=1; ii<(int)nstr.size(); ii++){
              int jj = nstr.size() - 1 - ii;
              int ln = jj - ii + 1;
              if(ln > 1)
                bad.insert(nstr.substr(ii,ln));
            }
          }
        }
      }
    }

    int cc = 0;
    FOR(it,ans){
      if(bad.count(*it) == 0){
        if(cc++ != 0) printf(" ");
        printf("%s",it->c_str());
      }
      bad.insert(*it);
    }

    puts("");
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define N 100007
int main() {
	int arr1[N]{};
	int arr11[N]{};
	int arr2[N]{};
	int arr22[N]{};
	int A, B, M, X, Y, C;
	std::cin >> A >> B >> M;
	for (int x = 0; x < A; x++)std::cin >> arr1[x],arr11[x]=arr1[x];
	for (int x = 0; x < B; x++)std::cin >> arr2[x],arr22[x]=arr2[x];

	std::sort(arr11, arr11 + A);
	std::sort(arr22, arr22 + B);
	int mn = 2000000;
	for (int x = 0; x < M; x++) {
		std::cin >> X >> Y >> C;
		mn=std::min((arr1[X-1] + arr2[Y-1] - C),mn);
	}
	mn = std::min((arr11[0] + arr22[0]), mn);
	std::cout << mn;
}

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

int main()
{
  int n;

  cin >> n;

  long long ans = 0, ans_2 = 0;

  vector<char> c(n);

  rep(i, n)
  {
    cin >> c.at(i);
  }

  int x = 0;
  int y = n - 1;

  while (1)
  {
    if (x > y)
      break;
    else if (c.at(x) == 'W' && c.at(y) == 'R')
    {
      ans++;
      x++;
      y--;
    }
    else if (c.at(x) == 'R')
    {
      x++;
    }
    else if (c.at(y) == 'W')
    {
      y--;
    }
  }
  cout << ans;
}


Measured memory_bytes: 3600
#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

int n,H,W;
int memo[65536];
int visi[65536];
int Q[65537];
int head = 0 , size = 0;
vector<int> mask1,mask2;

vector< vector<char> > goal(4,vector<char>(4));

int w[20],h[20];

int gen(int s,int x,int y){
	rep(k,3){
		int a=0,b=0;
		rep(i,h[s]){
			rep(j,w[s]){
				int tx = x + j;
				int ty = y + i;
				if(tx >= 0 && tx < 4 && ty < 4 && ty >= 0){
						a |= 1<<(ty*4+tx);
						b |= (goal[ty][tx] == k)<<(ty*4+tx);
				}
			}
		}
		mask1.push_back(a);
		mask2.push_back(b);
	}
}
int f(int init){
	Q[size++] = init;
	memo[init] = 0;
	int good = (1<<16)-1;
	while(head < size){
		int q = Q[head++];
		int cost = memo[q];
		if(good == q) return cost;
		
		rep(i,mask1.size()){
			int bit = (q & ~mask1[i]) | mask2[i];
			if(!visi[bit]){
				visi[bit] = 1;
				memo[bit] = cost + 1;
				Q[size++] = bit;
			}
		}
	}
	

}

int main(){
	cin >> n;
	rep(i,n) cin >> h[i] >> w[i];
	rep(i,4)rep(j,4){
		char c;cin >> c;
		if(c=='R')c = 0;
		if(c=='G')c = 1;
		if(c=='B')c = 2;
		goal[i][j] = c;
	}
	
	rep(k,n){
		rep(i,7)rep(j,7){
			gen(k,i-3,j-3);
		}
	}

	
	cout << f(0) << endl;
	
	
}

Measured memory_bytes: 1680
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { return a = b; } return false; }

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
   
    int n,ans=0; cin>>n; int a[n],b[n];
    for (int i = 0; i < n; i++){cin>>a[i]; b[i]=a[i];}
    sort(a,a+n);
    for (int i = 0; i < n; i++)if(distance(a,lower_bound(a,a+n,b[i]))%2!=i%2)ans++;
    cout<<ans/2<<'\n';
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<typename T>
vector<T> convert_base(T x, T b){
    vector<T> ret;
    T t = 1;        // 正負フラグ
    T k = abs(b);   // 基数の絶対値を取る
    while(x){
        ret.emplace_back((x * t) % k);          // 見ている桁の変換後の数を求める (mod(abs(b)))
        if(ret.back() < 0)  ret.back() += k;    // 負であれば正にする
        x -= ret.back() * t;    // 余りに正負フラグを掛けたものを減算してから
        x /= k;         // 除算処理をする
        t *= b / k;     // 負の進数へ変換する場合はこれが必要 (偶数桁目を調べているときは、t = -1 になる)
    }
    if(ret.empty()) ret.emplace_back(0);
    reverse(begin(ret), end(ret));
    return ret;
}

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

    ll n;
    cin >> n;
    vector<ll> ans = convert_base<ll>(n, -2);
    for(auto x : ans)   cout << x;
    cout << endl;
}

Measured memory_bytes: 256
//package AtCoder.Nekkei;

import java.io.*;
import java.util.*;

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

        int n = s.nextInt();
        pair[] arr = new pair[n];
        for (int i = 0; i < n; i++) {
            arr[i] = new pair(s.nextInt(), s.nextInt());
        }

        Arrays.sort(arr);
//        System.out.println(Arrays.toString(arr));

        long first = 0;
        long sec = 0;
        for (int i = 0; i < n; i++) {
            if(i % 2 == 0) {
                first += arr[i].first;
            } else {
                sec += arr[i].second;
            }
        }

        System.out.println(first - sec);

   }

    private static class pair implements Comparable<pair> {
        long first;
        long second;

        public pair(long first, long second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public boolean equals(Object obj) {
            pair p = (pair) obj;
            return this.first == p.first && this.second == p.second;
        }

        @Override
        public String toString() {
            return this.first + " " + this.second;
        }

        @Override
        public int compareTo(pair o) {

            return Long.compare(o.first + o.second, this.first + this.second);
        }
    }
}

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

typedef pair<int,int> P;

int N;
void solve() {
    vector<int> shop(N);
    for (auto& i : shop) cin >> i;

    vector<int> diff(N);
    for (int i = 0; i < N; i++) {
        int d = shop[i] % 1000;
        if (d == 0) diff[i] = 500;
        else if (d < 500) diff[i] = 0;
        else diff[i] = d - 500;
    }

    vector<vector<P> > dp(N + 1, vector<P>(500 * N + 1, P(-1, 0)));
    dp[0][0] = P(0, 0);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= 500 * i; j++) {
            auto coin = dp[i][j];
            if (coin.first == - 1) continue;
            dp[i+1][j] = max(dp[i+1][j], coin);
            if (diff[i] == 0) {
                P ncoin = P(coin.first + 1, coin.second - shop[i]);
                int f = j + 500 - (shop[i] % 1000);
                dp[i+1][f] = max(dp[i+1][f], ncoin);
            } else {
                if (diff[i] <= j) {
                    P ncoin = P(coin.first + 1, coin.second - shop[i]);
                    int f = j - diff[i];
                    dp[i+1][f] = max(dp[i+1][f], ncoin);
                }

                P pcoin = P(coin.first, coin.second - shop[i]);
                int f_ = j + (shop[i] % 1000 ? 1000 - shop[i] % 1000 : 0);
                dp[i+1][f_] = max(dp[i+1][f_], pcoin);
            }
        }
    }

    P ans(0, 0);
    for (auto p : dp[N]) {
        ans = max(ans, p);
    }

    cout << ans.first << " " << -ans.second << endl;
}

int main() {
    while (cin >> N, N) solve();

    return 0;
}

Measured memory_bytes: 42680
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define rev(r) reverse(r.begin(),r.end())
#define SORT(ar) sort(ar.begin(), ar.end())
#define sz(x) (int)(x).size()
#define len(x) (int)x.length()
#define in(a) scanf("%d",&a)
#define pr(x) printf("%d ",x)
#define endl '\n'
#define read(v,n) for(int h=0;h<n;h++) cin>>v[h];
#define fo(i,a,b) for(i=a;i<b;i++)
#define fi(i,a,b) for(i=a;i>=b;i--)
#define mo 1000000007
#define N 200007
ll a[51][51],res[51][51],t[51][51],n,k;

void power()
{
    int i,j,r;
    fo(i,0,n) res[i][i]=1;
    while (k > 0)
    {
       if (k & (1ll)){
            fo(i,0,n)
            {
                fo(j,0,n)
                {
                    t[i][j]=0;
                    fo(r,0,n)
                    {
                        t[i][j]=(t[i][j] + ((res[i][r])*(a[r][j]))%mo)%mo;
                    }
                }
            }
            fo(i,0,n)
            {
                fo(j,0,n) res[i][j]=t[i][j];
            }
       }
        k = k>>(1ll);
        fo(i,0,n)
        {
            fo(j,0,n)
            {
                t[i][j]=0;
                fo(r,0,n)
                {
                    t[i][j]=(t[i][j] + ((a[i][r])*(a[r][j]))%mo)%mo;
                }
            }
        }
        fo(i,0,n)
        {
            fo(j,0,n) a[i][j]=t[i][j];
        }
    }
}

int main()
{
    ll i,j,x,y,ans=0;
    cin>>n>>k;
    fo(i,0,n)
    {
        fo(j,0,n) cin>>a[i][j];
    }
    power();
    fo(i,0,n)
    {
        fo(j,0,n) ans=(ans + res[i][j])%mo;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll n, m, x;
    cin >> n >> m;
    ll ans = pow(2, m) * ((m * 1900) + (n-m) * 100);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4012
#include<bits/stdc++.h>
#define int long long
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)
using namespace std;
const int N = 10010;
inline int read()
{
	register char cc = getchar(); register int cn(0), flus(1);
	while(cc < '0' || cc > '9') {if(cc == '-') flus = - flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - '0'; cc = getchar();}
	return cn * flus;
}
long long h;
long long abc(long long i)
{
	if(i==1)return 1;
	return 2*abc(i/2)+1;
}
signed main()
{
	h = read();
	printf("%lld",abc(h));
	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 printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N, R;
  cin >> N >> R;
  int ans = R;
  if (N < 10)
  {
    ans += 100 * (10 - N);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,ans,k,kk;
int main(){
    cin>>a>>b>>c>>k;
    ans=a+b+c;
    ans=ans-max(max(a,b),c);
    kk=max(max(a,b),c);
    for(int i=0;i<k;i++){
        kk*=2;
    }

    cout<<ans+kk<<endl;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
l = [0 for i in range(N)]
ans = []
cnt = 0
for i in reversed(range(N)):
    j = 2
    memo = 0
    while (i+1)*j <= N:
        memo += l[(i+1)*j-1]
        j += 1
    memo = memo%2
    
    if memo != a[i]:
        l[i] = 1
        cnt += 1
        ans.append(str(i+1))
ans.sort()
print(cnt)
print(" ".join(ans))

Measured memory_bytes: 17336
#include <iostream>

using namespace std;

int main(){
	int x, y;

	while(1){
		cin >> x >> y;
		if(x==0 && y==0){
			break;
		}

		else if(x > y){
			cout << y << " " << x << endl;
		}
		else if(x <= y){
			cout << x << " " << y << endl;
		}
	}
}

Measured memory_bytes: 1156
#include<stdio.h>
int main(){
 int a,b,d,r;
 double f;
 
 scanf("%d %d\n",&a,&b);

 d=a/b;
 r=a%b;
 f=(double)a/(double)b;


 printf("%d %d %f\n",d,r,f);

return 0;
}

Measured memory_bytes: 640
#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>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
    string x; cin>>x;
    int n=x.size();
    string ans;
    for(int i=0; i<n; i++){
        if(!ans.empty() && ans.back()=='S' && x[i]=='T'){
            ans.pop_back();
        }else{
            ans.push_back(x[i]);
        }
    }
    cout<<ans.size()<<endl;
    return 0;
}

Measured memory_bytes: 776
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define com bool operator<(const node &b)
using namespace std;
const int maxn = (ll) 3e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;
bool vis[maxn];

void solve() {
    int x, n;
    cin >> x >> n;
    rep(i, 1, n) {
        int z;
        cin >> z;
        vis[z] = true;
    }
    int minNum = inf, ans = 0;
    rep(i, 0, 105) {
        if (!vis[i]) {
            if (minNum > abs(i - x)) {
                minNum = abs(i - x);
                ans = i;
            }
        }
    }
    cout << ans;
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 200010;

struct BIT {
    int n;
    vi bit;
    BIT(int num):bit(num+1,0){n=num;}
    void add(int i, int w){
        for(int x=i; x<=n; x+=x&-x) bit[x]+=w;
    }
    int sum(int i){
        int ret=0;
        for(int x=i; x>0; x-=x&-x) ret+=bit[x];
        return ret;
    }
    int sum(int l, int r){return sum(r)-sum(l);}
};

int main() {
	int n;cin>>n;
	int p[N];
	rep(i,n) cin>>p[i];
	BIT tree(n+3);
	int ans=0;
	rep(i,n){
		tree.add(p[i],1);
		if(tree.sum(p[i]-1)==0) ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
#define int long long
signed main(void){
    int a,b,c; cin>>a>>b>>c;
    if(2*b == c + a) cout<<"YES"<<endl; else cout<<"NO"<<endl;
}


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

int main() {
  int a, b, c, d, left, right;
  cin >> a >> b >> c >> d;
  left = a + b;
  right = c + d;
  if(left == right) {
    cout << "Balanced" << endl;
  }
  else if(left > right){
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		String[] s = Console.ReadLine().Split(' ');

		Boolean exist_odd = false;
		int res = 0;

		while (true)
		{
			for (int i = 0; i < N; i++)
			{
				if (int.Parse(s[i]) % 2 != 0) exist_odd = true;
			}

			if (exist_odd) break;

			for (int i=0; i < N; i++)
			{
				s[i] = (int.Parse(s[i]) / 2).ToString();
			}

			res++;
		}
		//出力
		Console.WriteLine(res);
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t;
    // cin >> t;
    // vector<lli> v;
    string s;
    cin >> s;
    t = s.length();
    if (s[t - 1] == 's')
    {
        cout << s << "es" << endl;
    }
    else
    {
        cout << s << "s" << endl;
    }
}

Measured memory_bytes: 3660
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int check[110];
set<int> s;

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

	int x, y, z;
	cin >> x;
	vector<int> X(x);
	for (int i = 0; i < x; i++)cin >> X[i];

	cin >> y;
	vector<int> Y(y);
	for (int i = 0; i < y; i++)cin >> Y[i];

	cin >> z;
	vector<int> Z(z);
	for (int i = 0; i < z; i++)cin >> Z[i];
		
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	sort(Z.begin(), Z.end());

	vector<int> v1,v2,v3;
	set_intersection(Y.begin(), Y.end(), Z.begin(), Z.end(), back_inserter(v1));
	set_difference(Z.begin(),Z.end(),X.begin(),X.end(),back_inserter(v2));
	set_union(v1.begin(),v1.end(),v2.begin(),v2.end(),back_inserter(v3));

	cout << v3.size() << endl;
	return 0;
}

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

int main(){
	stack<int> s1;
  	stack<pair<int,int>> s2;
  	char ch;
  	int sum=0;
  	for(int i=0;cin>>ch;i++){
        if(ch=='\\') s1.push(i);
      	else if(ch=='/' && s1.size()>0){
        	int j=s1.top();s1.pop();
          	sum+=i-j;
          	int a=i-j;
          while(s2.size()>0 && s2.top().first>j){
          	a+=s2.top().second;s2.pop();
          }
          s2.push(make_pair(j,a));
        }
    }
  
  vector<int> ans;
  while(s2.size()>0){
  	ans.push_back(s2.top().second);
    s2.pop();
  }
  cout<<sum<<endl;
  cout<<ans.size();
  for(int i=ans.size()-1;i>=0;i--){
  	cout<<" ";
    cout<<ans.at(i);
  }
  cout<<endl;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int a,b;
    cin >> a >> b;
    cout << a*b << " " << (a+b)*2 << endl;
}



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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if(s.substr(0, 4) == "YAKI") cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

int dfs(unordered_map<int, vector<int>>& graph, int start, int goal, int pre, int d, vector<int>& path, vector<int>& ans_path) {
    if (start == goal) {
        ans_path = path;
        return d;
    }
    int ans = INF;
    for (auto &adj : graph[start]) {
        if (adj == pre) continue;
        path.push_back(adj);
        ans = min(ans, dfs(graph, adj, goal, start, d + 1, path, ans_path));
        path.pop_back();

    }
    return ans;
}
int dfs2(unordered_map<int, vector<int>>& graph, int start, int pre, int d) {

    int ans = d;
    for (auto &adj : graph[start]) {
        if (adj == pre) continue;
        ans = max(ans, dfs2(graph, adj, start, d + 1));

    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, u, v;
    cin >> N >> u >> v;
    unordered_map<int, vector<int>> graph;
    rep(i, N - 1) {
        int A, B;
        cin >> A >> B;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    vector<int> path, ans_path;
    int d = dfs(graph, u, v, 0, 0, path, ans_path);
    //cout << N << endl;
    int ans = (d - 1) / 2  + (d - 1) % 2;
    int new_start = u;
    if ((d - 1) / 2 > 0)
        new_start = ans_path[(d - 1) / 2 - 1];
    int dont_move = ans_path[(d - 1) / 2];
    ans += dfs2(graph, new_start, dont_move, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16036
#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 = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }


int D[32][32];
int C[502][502];
int RC[3][32];

const ll INF = 1LL << 60;

ll f(int c, int r, int y){
    ll res = 0;
    rep(x, c){
        res += D[x][y] * RC[r][x];
    }
    return res;
}

int main(){
    int n, c;
    cin >> n >> c;
    rep(i,c) rep(j,c){
        cin >> D[i][j];
    }
    rep(i, n) rep(j,n){
        cin >> C[i][j];
        C[i][j]--;
    }

    rep(i, n) rep(j, n){
        int r = (i + j + 2) % 3;
        int col = C[i][j];
        RC[r][col]++;
    }

    ll ans = INF;
    rep(y0, c){
        rep(y1, c){
            if (y0 == y1) continue;
            rep(y2, c){
                if (y0 == y2 || y1 == y2) continue;
                ll sum = 0;
                sum += f(c, 0, y0);
                sum += f(c, 1, y1);
                sum += f(c, 2, y2);
                ans = min(ans, sum);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4576
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

const string lefth = "qwertasdfgzxcvb";
const string righth = "yuiophjklnm";

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

    while (true) {
        string s; cin >> s;
        if (s=="#") break;

        int ans = 0;
        int state = 0;
        for(auto c: s) {
            if (state == 0) {
                if (count(all(lefth), c)) state = -1;
                else state = 1;
                continue;
            }
            if (count(all(lefth), c) && state==1) {
                ans++; state=-1;
            }
            else if (count(all(righth), c) && state==-1) {
                ans++; state=1;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3192
use std::io;
use std::io::{stdin, Read};
use std::process::exit;
use std::cmp::min;

fn main() {

    let mut scan = stdin();
    let mut line = String::new();

    let _ = scan.read_line(&mut line);
    let _ = scan.read_line(&mut line);
    let inputs: Vec<&str> = line.split_whitespace().collect();

    let n: i32 = inputs[0].parse().unwrap();
    let s: String = inputs[1].to_string();

    let char_set = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];

    for i in s.as_str().chars(){
        let char_number = str2i(i);
        let index = (char_number + n) % 26;
        print!("{}", char_set[index as usize]);
    }
}

fn str2i(c: char) -> i32 {
    let char_set = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
    let mut position: i32 = 0;

    for i in char_set.iter(){
        let ch = i;
        if c == ch.parse().unwrap() {
            return position;
        }
        position += 1;
    }
    return 0;
}

Measured memory_bytes: 2100
#include<stdio.h>
#include<string.h>
int main(void){
    char s[7];
    scanf("%s",s);
    if(s[0]=='S')
    printf("Cloudy");
    else if(s[0]=='C')
    printf("Rainy");
    else if(s[0]=='R')
    printf("Sunny");
    return 0;
}

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

int main(){
  string s;
  cin>>s;
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='N')a=1;
    if(s[i]=='S')b=1;
    if(s[i]=='W')c=1;
    if(s[i]=='E')d=1;
  }
  if(a==b&&c==d){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MOD = 1000000007; // 10^9 + 7
const double PI = 3.14159265358979323846;
const int N = 10000000; // 10^7
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    cout<<fixed;
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    auto ang=PI*2*(h/12.0 + (m/60.0)/12.0 - m/60.0);
    auto ans=sqrt(a*a + b*b - 2*a*b*cos(ang));
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4216
#include<stdio.h>
 
int cnt=0,N,A[1000005],i,G[1000005],m=0;
void f(int g)
{
    int i,j,v;
    for(i=g;i<N;i++)
    {
        v=A[i];
        for(j=i-g;j>=0&&A[j]>v;j-=g)
        {
            A[j+g]=A[j];
            cnt++;
        }
        A[j+g]=v;
    }
}
 
int main()
{
    scanf("%d",&N);
    for(i=0;i<N;i++)scanf("%d",A+i);
    for(m=0,G[0]=1;G[m]<=N;G[++m]=G[m-1]*3+1);
    printf("%d\n",m);
    for(i=0;i<m;i++)
    {
        printf("%d%c",G[m-i-1],i==m-1?'\n':' ');
        f(G[m-i-1]);
    }
    printf("%d\n",cnt);
    for(i=0;i<N;i++)printf("%d\n",A[i]);
    return 0;
}


Measured memory_bytes: 5620
#include<stdio.h>
#include<stdlib.h>
int a[101];
int b[101];
int main()
{
	int i, j = 1;
	int n, d, x, ans = 0;
	scanf("%d", &n);
	scanf("%d%d", &d, &x);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		int j = 1;
		while (a[i] * j + 1 <= d)
			j++;
		b[i] = j;
			
	}
	for (i = 0; i < n; i++)
		ans += b[i];
	ans = ans + x;
	printf("%d", ans);
	return 0;
}


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

#define ll long long 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	ll n; cin >> n;
	ll a[n]; map<int, int> count;
	ll ans = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];	
		if(count.find(a[i]) == count.end()) count[a[i]] = 0;
		count[a[i]]++;
	}
	for(auto it: count){
		ll x = it.second;
		ans += (x * (x - 1)) / 2;
	}
	for(int i = 0; i < n; i++){
		cout << ans - (count[a[i]] - 1) << "\n";
	}
	return 0; 	
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

const int MOD = 1e9+7;

int a[100001];
ll fact[100001];

int modinv(ll x) {
    int n = MOD - 2, ret = 1;
    while (n) {
        if (n % 2) ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }
    return ret;
}

int main(void) {
    int i, n;
    scanf("%d",&n);
    n++;
    REP (i,n) scanf("%d",&a[i]);
    set<int> st;
    int l, r;
    REP (i,n) {
        if (st.count(a[i])) r = i;
        st.insert(a[i]);
    }
    RREP (i,n) if (a[i] == a[r]) l = i;
    fact[0] = 1;
    REP (i,1,n) fact[i] = (ll) fact[i-1] * i % MOD;
    REP (i,1,n) {
        int ans = fact[n] * modinv(fact[n-i]) % MOD * modinv(fact[i]) % MOD;
        if (n - (r - l + 1) - (i - 1) >= 0) ans -= fact[n-(r-l+1)] * modinv(fact[n-(r-l+1)-(i-1)]) % MOD * modinv(fact[i-1]) % MOD;
        ans = (ans + MOD) % MOD;
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 7040
#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define FOR(i,s,e) for(int i = (s);i <=(e);i++)

typedef long long ll;

int N;
ll A[300][300];
int A_n[300][300];
int main()
{
	cin >> N;
	FOR(i,0,N - 1)
	{
		FOR(j,0,N - 1)
		{
			cin >> A[i][j];
		}
	}

	FOR(i,0,N - 1)
	{
		FOR(j,0,N - 1)
		{
			FOR(k,0,N-1)
			{
				ll x = A[i][j];
				ll y = A[i][k] + A[k][j];

				if(x > y)
				{
					cout << -1 << endl;
					return 0;
				}
				if(x == y && A[i][k] > 0 && A[k][j] > 0)
				{
					A_n[i][j] = -1;
				}
			}
		}
	}
	ll res = 0;
	FOR(i,0,N - 1)
	{
		FOR(j,0,N - 1)
		{
			if(A_n[i][j] != -1)
			{
				res += A[i][j];
			}
		}

	}

	cout << res / 2 << endl;
	return 0;
}


Measured memory_bytes: 1280
import java.util.Arrays;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n1 = sc.nextInt();
        int[] intArray = new int[100];
        Arrays.fill(intArray, -1);
        for (int i = 0; i < n1; i++) {
            intArray[i] = sc.nextInt();
        }

        int count = 0;
        for (int i= 0; i < intArray.length; i++) {
            for (int j = i + 1; j < intArray.length && intArray[j] != -1; j++) {
                if (intArray[i] == intArray[j]) {
                   continue;
                }
                for (int k = j + 1; k < intArray.length && intArray[k] != -1; k++) {
                    if ((intArray[i] + intArray[j] > intArray[k]) && (intArray[j] + intArray[k] > intArray[i]) && (intArray[k] + intArray[i] > intArray[j])) {
                        if (intArray[i] != intArray[k] && intArray[j] != intArray[k]) {
                            count++;
                        }
                    }
                }
            }
        }
        System.out.println(count);
    }

}


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

#define F first
#define S second
#define pb(x) push_back(x)
#define in(x) insert(x)
#define forr(i, a, b) for(int i = a;i <= b;i++)
#define sz(s) int(s.size())
#define ioi ios_base::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define tie cin.tie(nullptr);cout.tie(nullptr);
//#define int long long

using namespace std;

const int INF =  2147483646;
const int  N = 2e6 + 667;
int n;

main() {
	string s;cin >> s;
	int n = (int)(sz(s));
	string a = s.substr(0, n >> 1);
	string b = s.substr(n + 1 >> 1, n - 1);
	if(a == b)cout << "Yes";
	else cout << "No";
	return 0;
}
// 
// 0 1 2 3 4
// d a m d a
// (n * (n - 1)) >> 1;
//Coded by LoliThief


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

int exp_mod(int a, int b) {
  int res = 1;
  for(int i=0;i<b;i++) {
    res=(res*a)%mod;
  }
  // while(b) {
  //   if(b&1)
  //     res=(res*a)%mod;
  //   a=(a*a)%mod;
  //   b>>=1;
  // }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  int a[n];
  unordered_map<int,int> store;
  for(int i=0;i<n;i++) cin>>a[i],store[a[i]]++;
  int start = n-1;
  bool invalid = false;
  if(store[0]!=(n&1))
    invalid=true;
  if(!invalid) {
    while(start > 0) {
      if(store[start]!=2) {
        invalid=true;
        break;
      }
      start-=2;
    }
  }
  if(invalid)
    cout<<"0";
  else {
    cout<<exp_mod(2,n>>1);
  }
  cout<<"\n";
  return 0;
}

Measured memory_bytes: 4108
#include<bits/stdc++.h>
 
#define si(x) scanf("%d",&x)
#define sf(x) scanf("%lf",&x)
#define sl(x) scanf("%lld",&x)
#define pr(x) printf("%d\n",x)
#define prll(x) printf("%lld\n",x)
 
#define ll long long int
#define ull unsigned long long int
#define F first
#define S second
 
#define rep(i,x,y) for(int i=x;i<y;i++)
#define ii pair<int,int> 
#define pll pair<ll,ll> 
#define vi vector<int> 
#define vvi vector< vi > 
#define vl vector<long long int>
#define vvl vector< vl >
#define vii vector< ii >
#define vvii vector< vii >
#define priority_queue pq;
#define sz(a) ll((a).size()) 
#define pb push_back 
#define mp make_pair
 
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define SET(a,b) memset(a,b,sizeof(a))
#define all(c) (c).begin(),(c).end() 
#define tr(i,c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ison(x,i) (((x) >> (i)) & 1)	//checks if ith bit is on
#define set0(x,i) (x & ~(1 << i))		//set ith bit in x to be zero
#define clr(a) memset(a,0,sizeof(a))
 
#define MOD 1000000007
#define INF 4000000000000000000
#define MAX 100000+5
using namespace std;

char a[MAX];

int main()
{
	ll n;
	sl(n);
	getchar();
	rep(i,0,n)
		a[i] = getchar();
	ll ans = 3;
	if(n > 1 && a[0]==a[1])
		ans=6;
	rep(i,1,n)
	if(a[i]!=a[i-1])
	{
		if(i>=2 && a[i-1]==a[i-2])
		{
			if(i<n-1 && a[i]==a[i+1])
				ans*=3;
		}
		else
			ans*=2;
		ans%=MOD;
	}

	prll(ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << ' ' << x << ' ' << y;
  return 0;
}

// g++ lo.cpp
// ./a.exe
// g++ -o つくりたいふぁいるめい　もとのふぁいる.cpp
/*
for (int i = 0; i < n - 2; i++) {
  for (int j = i + 1; j < n - 1; j++) {
    int k = 2 * j - i;*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>

#define INF 100000000

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int sum = 0;
    for (int i = 0; i < n - 1; i++)
    {
        sum += a[i];
    }
    if (sum > a[n - 1])
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,k,x,ans = 0;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> x;
        int a = x;
        int b = abs(k-x);
        if(a<b || a==b) ans += 2*x;
        else ans += 2*b;
    
    }
    cout<<ans;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,n,len,c=0,x,y,c1=0,c2=0;
    string s;
    cin>>s;
    len=s.size();
    x=(len-1)/2;
    y=(len+1)/2;
    for(i=0;i<len;i++){
        if(s[i]==s[len-1-i]){
            c++;
        }
    }
    for(i=0;i<x;i++){
        if(s[i]==s[x-1-i]){
            c1++;
        }
    }
    for(i=y;i<len;i++){
        if(s[i]==s[len-1-i]){
            c2++;
        }
    }
    //cout<<len<<" "<<x<<" "<<y<<endl;
    //cout<<c<<" "<<c1<<" "<<c2;
    if(len+x+y-1==c+c1+c2){
        cout<<"Yes";
    }
    else
        cout<<"No";
}


Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#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, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair; 
priority_queue< ll, vector <ll> , greater<ll>>pq1,pq2;
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,m,k;
    string str[30];
    cin>>n>>m>>k;

    for(i=0;i<n;i++)
    cin>>str[i];

    ll st=pow(2,n);
    ll st2=pow(2,m);
    ll ans=0;
    for(i=0;i<=st-1;i++)
    {
        ll a=i;
        ll pl=0,cnt1[30]={0};
        while(a>0)
        {
            ll b=a%2;
            if(b==1)
            {
                cnt1[pl]++;
            }
            pl++;
            a/=2;
        }
        for(ll j=0;j<=st2-1;j++)
        {
            ll a=j;
            ll pl=0,cnt2[20]={0};
            while(a>0)
            {
                ll b=a%2;
                if(b==1)
                {
                    cnt2[pl]++;
                }         
                pl++;
                a/=2;
            }
            ll fl=0;
            for(ll q=0;q<n;q++)
            {
                for(ll d=0;d<m;d++)
                {
                    if(cnt1[q]==0 && cnt2[d]==0 && str[q][d]=='#')
                    fl++;
                }
            }
            
            if(fl==k)
            ans++;


        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4056