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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<string> S(N);

    REP(i, N){
        cin >> S[i];
    }

    vector<map<char,ll>> M(N);

    REP(i, N){
        for(char c: S[i]){
            M[i][c]++;
        }
    }

    string ans;
    for(char c='a'; c<='z'; c++){
        ll temp=LINF;
        REP(i, N){
            temp = min(temp, M[i][c]);
        }
        REP(i, temp){
            ans += c;
        }
    }
    
    sort(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
//Name: Dimensional Analysis
//Level: 3
//Category: 構文解析
//Note:

/**
 * 次元のみを考えて構文解析する。
 * チェックすべき点は、加減算で次元が一致していることと、乗除算で次元の変換が発生すること。
 *
 * オーダーは O(|S|N)。
 */
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <map>

using namespace std;

typedef vector<int> Unit;
typedef string::const_iterator Iterator;

struct DimensionMismatch{};

struct Parser {
    map<string,Unit> &vars;
    Parser(map<string,Unit> &vars) : vars(vars) {}

    Unit variable(Iterator &it) {
        string buf;
        while(isalpha(*it)) buf += *it++;
        return vars[buf];
    }

    Unit factor(Iterator &it) {
        if(*it == '(') {
            ++it;
            Unit val = formula(it);
            ++it;
            return val;
        } else {
            return variable(it);
        }
    }

    Unit term(Iterator &it) {
        Unit lhs = factor(it);
        while(*it == '*' || *it == '/') {
            const char op = *it++;
            Unit rhs = factor(it);
            const int f = (op == '*' ? 1 : -1);
            for(int i = 0; i < lhs.size(); ++i) {
                lhs[i] += rhs[i] * f;
            }
        }
        return lhs;
    }

    Unit formula(Iterator &it) {
        Unit lhs = term(it);
        while(*it == '+' || *it == '-') {
            ++it;
            Unit rhs = term(it);
            if(lhs != rhs) throw DimensionMismatch();
        }
        return lhs;
    }

    Unit parse(const string &str) {
        Iterator it = str.begin();
        return formula(it);
    }
};

bool solve() {
    int N, M, P;
    if(!(cin >> N >> M >> P)) return false;
    if(!N && !M && !P) return false;

    map<string,Unit> dict, vars;
    map<Unit,string> rev_dict;
    for(int i = 0; i < M; ++i) {
        string name;
        cin >> name;
        Unit u(N);
        for(int j = 0; j < N; ++j) {
            cin >> u[j];
        }
        dict[name] = u;
        rev_dict[u] = name;
    }
    string formula;
    cin >> formula;
    for(int i = 0; i < P; ++i) {
        string name, uname;
        cin >> name >> uname;
        vars[name] = dict[uname];
    }
    try {
        Parser parser(vars);
        Unit res = parser.parse(formula);
        if(rev_dict.count(res)) {
            cout << rev_dict[res] << endl;
        } else {
            cout << "undefined" << endl;
        }
    } catch(DimensionMismatch &d) {
        cout << "error" << endl;
    }
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1316
#include <iostream>
#include <string>
#include <algorithm>

int main() {
    std::string o, e;
    std::cin >> o >> e;

    std::string result = "";
    int index = 0;
    for (auto odd_c:o) {
        std::string even(1, e[index]);
        result += odd_c;
        if (index < e.size()) {
            result += even;
        }
        index++;
    }

    std::cout << result << std::endl;
}

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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
using vi  = vector<int>;

vector<int> divisor(int n){ // O(√n)約数列挙
  vector<int> res;
  for(int i = 1; i * i <= n; i++){
    if(n % i == 0){
      res.push_back(i);
      if(i * i != n) res.push_back(n/i);
    }
  }
  return res;
}

int main(){
  int in;
  while(cin >> in, in){
    in *= 2;
    vi div = divisor(in);
 
    int sans, lenans = -1;
    rep(i,div.size()){
      int x = div[i], y = in / div[i];
      if((x+y-1) % 2 == 1 or (x-y+1) % 2 == 1) continue;
      int s = min((x+y-1)/2, (x-y+1)/2);
      if(lenans < y and s > 0){
	lenans = y;
	sans = s;
      }
    }
    cout << sans << " " << lenans << endl;
  }
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
/* S.size() s.substr(l,r=s.size()-l) -> l文字目からr文字分
__gcd()　lower_bound(a+l,a+r,x)-a でindex
// 配列  -> min/max({}) 
// vector-> *min_element(a+l,a+r)  *忘れず lとrで[l,r) 
//reverse(a+l,a+r)   配列aの[l,r)を逆順に strはreverse(all(s))
//sort(a+l,a+r,greater <int>()) 配列aの[l,r)昇順sort,大きい順はgreater<type>()
//vectorならall(v)
clock()/CLOCKS_PER_SEC で秒数
vector v.push_back(x),v.pop_back()
q.push(x),front()で先頭を返す,pop()で削除, size(),empty()
<deque>(push/pop)_(front/back)/fornt/back/insert/
priority_queue 宣言は priority_queue< Type, vector<Type>, greater<Type>> Q1; 
// pq.push(x),top()で参照 pop()で削除   greaterで最小 lessで最大がtopに*/
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repl(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i,n) for(int (i)=(n)-1;(i)!=-1;(i)--)
#define vep(i,v) for(auto (i)=v.begin();(i)<(v.end());(i)++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
inline long long ceildiv(long long a, long long  b) { return (a+b-1)/b; }

const long long inf = 10e17;

//int |x|<=2*10**9     long |x|<= 9*10**18
//printf(".(小数点以下の桁数)lf(double時、float ならf)")
#define ll long long
#define print(i) std::cout << (i) << '\n'
typedef  vector<ll> vec;
typedef vector<vec> mat ;
const ll mod =1000000007;
vec mul(vec &A,vec &B){
    vec ret(A.size(),0ll);
    int n=A.size();
    rep(i,n){
      rep(j,n){
        ret[(i+j)%n]=(ret[(i+j)%n]+A[i]*B[j]%mod)%mod;
      }
    }
    return ret;
}
vec pow(vec A,ll n){
    vec ret(A.size(),0ll);
    ret[0]=1ll;
    while(n>0ll){
        if(n&1ll)ret=mul(ret,A);
        A=mul(A,A);
        n>>=1ll;
    }
    return ret;
}
int main(){
int n,m;
ll k;
cin>>n>>m>>k;
vec a(n,0ll);
a[0]++;
rep(b,m){
    int p;
    cin>>p;
    p%=n;
    a[p]++;
}

vec V=pow(a,k);
rep(i,n){
    cout<<V[i]<<endl;
}
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(2,vector<int>(n));
    rep(j,2){
        rep(i,n){
            cin >> a[j][i];
        }
    }
    int ans = 0;
    rep(i, n)
    {
        int cur = 0,tmp = 0;
        rep(j, n)
        {
            if(j==i){
                tmp += a[cur][j];
                cur++;
                tmp += a[cur][j];
            }else{
                tmp += a[cur][j];
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,a[111],sum;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sum=(sum+4*m-1)/(4*m);
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]>=sum)
		{
			cnt++;
		}
	}
	if(cnt>=m)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())
count = 0 
for i in range(A, B+1):
    num = str(i)
    judge = 1
    for j in range(len(num) // 2):
        if num[j] != num[-j-1]:
            judge = 0
            break
    if judge:
        count += 1

print(count)

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

/* 平面幾何の基本要素 */
 
#define EPS (1e-10)
#define equals(a,b) (fabs((a) - (b)) < EPS )
 
class Point { // 点を表すクラス
public:
  double x,y;
  
  Point(double x=0,double y=0): x(x),y(y) {}
  
  Point operator + (Point p) { return Point(x + p.x, y + p.y); }
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double a) { return Point(a * x, a * y); }
  Point operator / (double a) { return Point(x / a, y / a); }
  
  double abs() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  
  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }
  
  bool operator == (const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }
};

typedef Point Vector; // ベクトルを表す構造体

struct Segment { // 線分を表す構造体
  Point p1,p2;
};

typedef Segment Line; // 直線を表す構造体

class Circle { // 円を表すクラス
public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0.0): c(c),r(r) {}
};
typedef vector < Point > Polygon; // 多角形

double dot(Vector a, Vector b) {
  return a.x * b.x + a.y * b.y;
}
 
double cross(Vector a, Vector b) {
  return a.x * b.y - a.y * b.x;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
 
int ccw(Point p0, Point p1, Point p2) {
  Vector a = p1 - p0;
  Vector b = p2 - p0;
 
  if( cross(a,b) > EPS ) return COUNTER_CLOCKWISE;
  if( cross(a,b) < -EPS ) return CLOCKWISE;
  if( dot(a,b) < -EPS ) return ONLINE_BACK;
  if( a.norm() < b.norm() ) return ONLINE_FRONT;
 
  return ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
  return ( ccw(p1,p2,p3) * ccw(p1,p2,p4) <= 0 && 
	   ccw(p3,p4,p1) * ccw(p3,p4,p2) <= 0);
}

bool intersect(Segment s1,Segment s2){
  return intersect(s1.p1,s2.p1,s1.p2,s2.p2);
}

int main(){
  Point p1,p2,p3,p4;
  char o;
  while(cin >> p1.x >> o >> p1.y >> o >> p2.x >> o >> p2.y >> o >> p3.x >> o >> p3.y >> o >> p4.x >> o >> p4.y){
    Segment s1,s2;
    s1.p1 = p1;
    s1.p2 = p2;
    s2.p1 = p3;
    s2.p2 = p4;
    if(intersect(s1,s2)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 1216
N,M = map(int,input().split())
 
if N == 2 or M == 2:
    print(0)
    exit()

if N == 1:
    if M == 1:
        print(1)
    else:
        print(M-2)
    exit()

if M == 1:
    print(N-2)
    exit()

print((N-2)*(M-2))

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

bool array[100001];
int main(){
    int n, k;
    int a;
    int i;
    bool blank;
    int count;
    int m;
    cin >> n >> k;
    while(n || k){
        count = 0;
        m = 0;
        blank = false;
        for(i=0;i<n;i++){
            array[i] = false;
        }
        array[n] = false;
        for(i=0;i<k;i++){
            cin >> a;
            array[a] = true;
        }
        blank = array[0];
        for(i=1;i<=n;i++){
            if(array[i]){
                count++;
            }else if(blank){
                count++;
                blank = false;
            }else{
                if(count > m){
                    m = count;
                }
                i -= count;
                count = 0;
                blank = array[0];
            }
        }
        if(count > m){
            m = count;
        }
        cout << m << endl;
        cin >> n >> k;
    }
}

Measured memory_bytes: 960
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \|     |//  `.
            /  \|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            pass the Test!
*/
#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;

int main(){
    string S;
    cin >> S;
    ll a=0;
    while(a<S.size()-1){
        if(S[a]=='B'&&S[a+1]=='C'){
            S=S.substr(0,a)+'D'+S.substr(a+2);
        }a++;
    }
    ll ans=0;
    ll acounter=0;
    for(ll i=0;i<S.size();i++){
        if(S[i]=='A')acounter++;
        else if(S[i]=='D')ans+=acounter;
        else acounter=0;
    ;}
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    string S;
    cin >> S;
    i32 ans = 0;
    for (i32 i = 0; i < S.size(); i++) {
        i32 d = S[i] - '0';
        ans = (ans + d) % 9;
    }
    cout << YN("Yes", "No", ans == 0) << endl;
}


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

int main() {

    string s;
    cin >> s;
    sort(s.begin(), s.end());
    
    string t;
    cin >> t;
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if(s < t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
Int mod = 1e9+7;
//Int mod = 1e6+3;

Int res;

void f(string s) {
    Int n = (Int)s.size();
    Int cnt = 0;
    //dump(s);
    for (Int i = n - 1; i >= 0; i--) {
        if (s[i] == 'B') {
            cnt++;
        }
        else {
            res += cnt;
        }
    }
}

int main() {
    string s;
    cin >> s;
    Int n = (Int)s.size();
    string t = "";
    for (Int i = 0; i < n; i++) {
        if (s[i] == 'A') {
            t = t + 'A';
        }
        else if (i < n - 1 && s[i] == 'B' && s[i + 1] == 'C') {
            t = t + 'B';
            i++;
        }
        else {
            t = t + 'C';
        }
    }
    Int m = (Int)t.size();
    //Int res = 0;
    Int cnt = 0;
   /*  string u = "";
    vector<string> v;
    for (Int i = 0; i < m; i++) {
        if (t[i] == 'A' || t[i] == 'B') {
            u = u + t[i];
        }
        else {
            v.push_back(u);
            u = "";
        }
    }
    if (u != "") v.push_back(u);
    for (Int i = 0; i < (Int)v.size(); i++) f(v[i]); */
    for (Int i = m - 1; i >= 0; i--) {
        if (t[i] == 'B') {
            cnt++;
        }
        else if (t[i] == 'A') {
            res += cnt;
        }
        else {
            cnt = 0;
        }
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 1436
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>

#define DEBUG 0
#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;
const int N = 2e5 + 3;

int n;
bool p[N];
int a[N], b[N];

int main() {
    if (DEBUG) {
        freopen("CP.inp", "r", stdin);
        //freopen("CP.out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    fort(i, 1, n) cin >> a[i];
    ford(i, n, 1) {
        int sum = 0;
        for (int j = 2 * i; j <= n; j += i) sum ^= b[j];
        b[i] = sum ^ a[i];
    }
    vi ans;
    fort(i, 1, n) if (b[i]) ans.pb(i);
    cout << ans.size() << '\n';
    for (int &x : ans) cout << x << ' ';
    return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)

int main()
{
	fast;
	int n,i,j;
	cin>>n;
	int x=n/1000;
    if(n%1000==0)
    {
    	cout<<0;
	}
	else
	{
		cout<<1000-n%1000;
	}
    
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 079_abc_d / Link: https://abc079.contest.atcoder.jp/tasks/abc079_d  ----- */
/* ------問題------

魔法少女のjoisinoお姉ちゃんは、この世にあるすべての数字を 1 に変えてやろうと思い立ちました。
1 つの数字を i から j(0≦i,j≦9) に書き変えるには魔力 ci,j が必要です。
今、目の前にある壁は縦方向に H、横方向に W のマス目になっていて、1 つ以上のマス目に 0 以上 9 以下の整数が 1 つずつ書かれています。
上から i(1≦i≦H) 番目、左から j(1≦j≦W) 番目のマスの情報として Ai,j が与えられ、
Ai,j≠−1 の場合はマスに Ai,j が書かれている
Ai,j=−1 の場合はマスに数字が書かれていない
ことを意味します。

この壁に書かれている数字を最終的に全て 1 に変えるのに必要な魔力の最小量を求めてください。

-----問題ここまで----- */
/* -----解説等-----

制約が小さいことを活かしてワーシャルフロイドのノリで解ける。

----解説ここまで---- */

LL H,W;

LL ans = 0LL;

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

	cin >> H>>W;
	VVI c(10, VI(10, 0));
	FOR(i, 0, 10)FOR(j, 0, 10) {
		cin >> c[i][j];
	}
	int N = 10;
	FOR(k, 0, N)FOR(i, 0, N)FOR(j, 0, N) {
		c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
	}
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			int a;
			cin >> a;
			if (a != -1) {
				ans += c[a][1];
			}
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
#include<list>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	int n, q;
	int S[10000], T[500];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> S[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> T[i];
	}

	int ans = 0;
	for (int i = 0; i < q; i++)
	{
		int x = T[i];
		for (int j = 0; j < n; j++)
		{
			if (x == S[j])
			{
				ans++;
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}


int main() {
  int N, K;
  cin >> N >> K;
  vector< pair< int, int > > st;
  string S;
  cin >> S;
  for(int i = 0; i < N; i++) {
    if(st.empty() || st.back().first != S[i]) {
      st.emplace_back(S[i], 1);
    } else {
      st.back().second++;
    }
  }
  int ret = 0, ptr = 0, sum = 0, all = 0;
  for(auto &p : st) {
    while(ptr < st.size() && sum + (st[ptr].first == '0') <= K) {
      sum += st[ptr].first == '0';
      all += st[ptr].second;
      ++ptr;
    }
    chmax(ret, all);
    sum -= p.first == '0';
    all -= p.second;
  }
  cout << ret << endl;
}




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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int X;

int ng(ll v) {
	int i;
	FOR(i,X) {
		if(v%2) v=v/2;
		else v=(v-1)/2;
	}
	if(v>2) return 1;
	return 0;
}

void solve() {
	int i,j,k,l,r,x,y,z; string s;
	
	cin>>X;
	ll A=(1LL<<60)-1;
	for(i=59;i>=0;i--) if(ng(A-(1LL<<i))) A-=1LL<<i;
	cout<<(A-1)<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

int main(){
  int N, x;
  int alice = 0;
  int bob = 0;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }//入力
  for(int i = 0; i < N; i++){
    int max = 0;
    for(int j = i; j < N; j++){
      if(max <= a[j]){
        max = a[j];
      }
    }//maxが求まる
    x = a[i];//写し取る
    //ここから入れ替え,a[i]=maxなら入れ替えなくてもよい
    if(a[i] != max){
      for(int j = i+1; j < N; j++){
        if(a[j] == max){
          a[j] = x;
          break;
        }
      }
      a[i] = max;
    }
  }
  if(N%2 == 0){
    for(int i = 0; i < N; i += 2){
      alice += a[i];
      bob +=a[i+1];
    }
    cout << alice - bob << endl;
  }
  else if(N%2 == 1){
    for(int i = 0; i < N-1; i += 2){
      alice += a[i];
      bob +=a[i+1];
    }
    alice += a[N-1];
    cout << alice - bob << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int h, w;
    while(cin >> w >> h, h || w) {
        bool board[40][40][4];
        rep(i,0,h) rep(j,0,w) rep(k,0,4) board[i][j][k] = true;

        rep(i,0,h) board[i][0][3]   = false; // left
        rep(i,0,h) board[i][w-1][2] = false; // right
        rep(i,0,w) board[0][i][1]   = false; // up
        rep(i,0,w) board[h-1][i][0] = false; // down

        int inp;
        rep(i,0,2*h-1) {
            int l;
            if(i % 2 == 0) l = w-1;
            else l = w;
            rep(j,0,l) {
                cin >> inp;
                if(inp == 1) {
                    if(i % 2 == 0) {
                        board[i/2][j][2] = false;
                        board[i/2][j+1][3] = false;
                    }
                    else {
                        board[i/2][j][0] = false;
                        board[i/2+1][j][1] = false;
                    }
                }
            }
        }

        int dist[40][40];
        rep(i,0,h) rep(j,0,w) dist[i][j] = INF;
        dist[0][0] = 1;
        queue<pii> q;
        q.push(pii(0, 0));

        while(!q.empty()) {
            pii t = q.front(); q.pop();
            rep(i,0,4) {
                if(!board[t.fr][t.sc][i]) continue;
                int x = t.fr + dx[i];
                int y = t.sc + dy[i];
                if(dist[x][y] <= dist[t.fr][t.sc] + 1) continue;
                dist[x][y] = dist[t.fr][t.sc] + 1;
                q.push(pii(x, y));
            }
        }

        if(dist[h-1][w-1] == INF) cout << 0 << endl;
        else cout << dist[h-1][w-1] << endl;
    }
    return 0;
}

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define BR "\n"

vector<int> face(6);
void rotate(char d) {
  vector<int> newFace(6);
  newFace = face;
  if (d == 'N') {
    newFace[0] = face[1];
    newFace[1] = face[5];
    newFace[5] = face[4];
    newFace[4] = face[0];
  } else if (d == 'S') {
    newFace[0] = face[4];
    newFace[1] = face[0];
    newFace[5] = face[1];
    newFace[4] = face[5];
  } else if (d == 'E') {
    newFace[0] = face[3];
    newFace[2] = face[0];
    newFace[5] = face[2];
    newFace[3] = face[5];
  } else if (d == 'W') {
    newFace[0] = face[2];
    newFace[2] = face[5];
    newFace[5] = face[3];
    newFace[3] = face[0];
  }
  face = newFace;
}

int main() {
  rep0(i, 6) cin >> face[i];
  string s; cin >> s;
  rep0(i, s.size()) rotate(s[i]);
  cout << face[0] << BR;

  return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int main()
{

	int n;
	cin>>n;
	int dp[n+1][3];
	int a[n+1];
	int b[n+1];
	int c[n+1];
	

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

	dp[1][0]=a[1];
	dp[1][1]=b[1];
	dp[1][2]=c[1];
	dp[0][0]=0;
	dp[0][1]=0;
	dp[0][2]=0;

	for(int i=2;i<=n;i++)
	{
		dp[i][0]=a[i]+std::max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+std::max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=c[i]+std::max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<std::max(std::max(dp[n][1],dp[n][0]),dp[n][2])<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){
int N;
cin>>N;
int res=N;
for(int i=0;i<=N;i++){
    int c=0;
    int t=i;
    //NをiとN-iに分けてそれぞれ6、９で分担して引き出す。
    while(t>0)c+=t%6,t/=6;
    t=N-i;
    while(t>0)c+=t%9,t/=9;
    if(res>c)res=c;//最小値の更新
}

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

*/

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

using namespace std;

#define ll long long
#define ld long double

ll a[100005];

int main()
{
	ll n,m;
	cin>>n>>m;

	// cout<<n<<m;

	for(ll i = 0 ; i < m ;i++)
	{
		ll l,r;
		cin>>l>>r;

		a[l]++;
		a[r + 1]--;

	}	

	for(ll i = 1 ; i < 100005; i++)
	{
		a[i] += a[i - 1];
	}

	ll cnt = 0;

	for(ll i = 1 ; i <= n; i++)
	{
		//cout<<a[i]<<endl;
		if(a[i] == m)
		{
			cnt++;
		}
	}

	cout<<cnt<<endl;

}	

Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        if(abs(a-c) <= d)
            printf("Yes\n");
        else
        {
            if(abs(a-b)<= d &&abs(b-c)<=d)
                printf("Yes\n");
            else printf("No\n");
        }
 
       return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,i;
  long long a,max,min,g;
  max = -1000000;
  min=1000000;
  g=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%lld",&a);
    if(a>max) max=a;
     if(a<min) min=a;
      g+=a;
  }  
  printf("%lld %lld %lld\n",min,max,g);
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
ll res[12345678][2];//番号、ヨコ、タテ
ll aa[1234][1234], bb[1234][1234];
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
signed main() {
	for (int zz = 0; zz < 10000; zz++) {
		ll n, w, d, p, s; cin >> n >> w >> d;
		if (n == 0 && w == 0 && d == 0) { return 0; }
		//w横、d縦
		res[1][0] = w; res[1][1] = d;
		for (int h = 1; h <= n; h++) {
			cin >> p >> s;
			int yoko = res[p][0], tate = res[p][1];
			for (int i = p + 1; i <= h; i++) {
				res[i - 1][0] = res[i][0]; res[i - 1][1] = res[i][1];
			}
			s %= (yoko + tate);
			if (s < yoko) {
				res[h][0] = min(s, yoko - s); res[h][1] = tate;
				res[h + 1][0] = max(s, yoko - s); res[h + 1][1] = tate;
			}
			else {
				s -= yoko;
				res[h][0] = yoko; res[h][1] = min(s, tate - s);
				res[h + 1][0] = yoko; res[h + 1][1] = max(s, tate - s);
			}
		}
		vector<ll> ans;
		for (int h = 1; h <= n + 1; h++) {
			ans.push_back(res[h][0] * res[h][1]);
		}
		sort(ans.begin(), ans.end());
		for (int h = 0; h <= n; h++) {
			if (h == 0) { cout << ans[h]; }
			else { cout << ' ' << ans[h]; }
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3152
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;



long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}

long long N,wa, K,c,ans,a,b,d;
char s[100];

int main() {
	cin >> N;
	ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		if (s[i] == 'Y') {
			ans = 1;
			break;
		}
	}
	

	if(ans==1){
		cout<<"Four"<<endl;
	}
	else {
		cout << "Three" << endl;
	}
	return 0;
}




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

const int MOD = 2019;
long long L, R;

void solve()
{
	if(L+1 == R){
		cout << (L*R)%MOD << endl;
		return;
	}
    const int k = (L+2018)/2019; 
    if(R<k*2019){
        long long ans = 2019;
		for(long long i=L;i<R;++i)for(long long j=i+1;j<=R;++j){
			ans = min(ans, (i*j)%MOD);
		}
		cout << ans << endl;
    }else{
        cout << 0 << endl;
    }
}

int main()
{
	cin >> L >> R;
	solve();
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=1'000'000'007;
const double EPS=1e-14;
const bool DEBUG=false;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////
void answer(){
    unsigned long long H, W;
    cin>>H>>W;
    vector<string> HW(H);
    for(auto &s : HW){
        cin>>s;
    }

    vector<vector<int>> dp(H, vector<int>(W, INF));
    if(HW[0][0] == '#'){
        dp[0][0] = 1;
    }else{
        dp[0][0] = 0;
    }
    debug(dp[0][0]);
    for(int i=1; i<H; ++i){
        if(HW[i-1][0] == '.' && HW[i][0] == '#'){
            dp[i][0] = dp[i-1][0] + 1;
            debug(dp[i][0]);
        }else{
            dp[i][0] = dp[i-1][0];
        }
    }
    for(int j=1; j<W; ++j){
        if(HW[0][j-1] == '.' && HW[0][j] == '#'){
            dp[0][j] = dp[0][j-1] + 1;
            debug(dp[0][j]);
        }else{
            dp[0][j] = dp[0][j-1];
        }
    }

    for(int i=1; i<H; ++i){
        for(int j=1; j<W; ++j){
            int down_cost = 0;
            int right_cost = 0;
            if(HW[i-1][j] == '.' && HW[i][j] == '#'){
                right_cost++;
            }
            if(HW[i][j-1] == '.' && HW[i][j] == '#'){
                down_cost++;
            }
            dp[i][j] = min(dp[i-1][j]+right_cost, dp[i][j-1]+down_cost);
            debug(dp[i][j]);
        }
    }

    cout<<dp[H-1][W-1]<<endl;

    return;
}
/////

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(16);

    answer();

    return 0;
}


Measured memory_bytes: 3676
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
int U[100000], R[100000];

int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}

void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (R[x] < R[y]) swap(x, y);
  U[y] = x;
  R[x] += R[y];
  R[y] = 0;
}

bool same(int x, int y) {
  return find(x) == find(y);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  while (cin >> N >> M) {
    if (N == 0 && M == 0) break;
    vector<P2> edges;
    rep(i, M) {
      int a, b, c;
      cin >> a >> b >> c;
      edges.pb(P2(c, P(a, b)));
    }
    sort(all(edges));
    for (int i=0; i<N; i++) U[i] = i, R[i] = 1;
    int s = 0;
    for (P2 e : edges) {
      int a = e._2._1, b = e._2._2;
      if (!same(a, b)) {
        s += e._1;
        unite(a, b);
      }
    }
    cout << s << "\n";
  }
  return 0;
}

Measured memory_bytes: 3216
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var x int
	con.Scan(&x)
	if x < 1200 {
		con.Println("ABC")
	} else {
		con.Println("ARC")
	}
	return nil
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;

#define ll long long

#define file_io 0

struct spell {
	int a,b;
} a[1005];

struct dpp {
	int cnt;
	bool ok;
} dp[10005];

int i,t,j;
int h,n,ans;

int main() {
	if (file_io) {
		freopen(".in","r",stdin);
		freopen(".out","w",stdout);
	}

	scanf("%d%d",&h,&n);

	for (i=1; i<=n; ++i) {
		scanf("%d%d",&a[i].a,&a[i].b);
	}


	dp[0].ok=1;
	for (i=1; i<=n; ++i) {
		for (t=a[i].a; t<=10000; ++t) {
			if (dp[t-a[i].a].ok) {
				if (dp[t].ok) {
					dp[t].cnt = min(dp[t].cnt,dp[t-a[i].a].cnt+a[i].b);
				} else {
					dp[t].ok=1;
 					dp[t].cnt = dp[t-a[i].a].cnt+a[i].b;
				}
			}
		}
	}

	ans=2e9;
	for (i=h; i<=10000; ++i) {
		if (dp[i].ok) {
			ans=min(ans,dp[i].cnt);
		}
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    N,Y = map(int,input().split())
    
    Y //= 1000
    for i in range(N+1):
        for j in range(N+1-i):
            k = (N-i-j)
            m = i*10 + j*5 + k*1
            if m == Y:
                print("{} {} {}".format(i,j,k))
                return
    print("-1 -1 -1")

if __name__ == '__main__':
    main()


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

using namespace std;

int q_sort(int d[],int left,int right){
	if(left >= right) return 0;
	int pipot = d[(left+right)/2], l = left, r = right, tmp;
	while(l<r){
		while(d[l] < pipot) l++;
		while(d[r] > pipot) r--;
		if( l <=  r){
			tmp = d[l];
			d[l] = d[r];
			d[r] = tmp;
			l++;
			r--;
		}
	}
	q_sort(d,left,r);
	q_sort(d,l,right);
}

int x,y,a,b,c;
int main(void)
{
	cin>>x>>y>>a>>b>>c;
	int p[a],q[b],r[c];
	int p_index,q_index,r_index;
	for(int i = 0; i < a; i++){
		cin>>p[i];
	}
	for(int i = 0; i < b; i++){
		cin>>q[i];
	}
	for(int i = 0; i < c; i++){
		cin>>r[i];
	}
	q_sort(p,0,a-1);
	q_sort(q,0,b-1);
	q_sort(r,0,c-1);
	
	
	
	
	r_index = c-1;
	p_index = a-x;
	q_index = b-y;
	long long ans = 0;
	for(int i = p_index; i < a; i++){
		ans += p[i];
	}
	for(int i = q_index; i < b; i++){
		ans += q[i];
	}
	
	
	
	while((p[p_index] < r[r_index] && p_index < a) || (q[q_index] < r[r_index] && q_index < b)){
		int min;
		if(p_index >= a){
			min = q[q_index];
			q_index++;
		}
		else if(q_index >= b){
			min = p[p_index];
			p_index++;
		}
		else if(p[p_index] < q[q_index]){
			min = p[p_index];
			p_index++;
		}
		else{
			min = q[q_index];
			q_index++;
		}
		ans -= min;
		ans += r[r_index];
		if(r_index == 0) break;
		r_index--;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > miti(n, vector<int> (0));
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        miti[a].emplace_back(b);
        miti[b].emplace_back(a);
    }

    queue<int> room;
    room.push(0);
    vector<int> ans(n, -1);
    while (!room.empty()) {
        int cu = room.front(); room.pop();
        for (int i : miti[cu]) {
            if (ans[i] != -1) continue;
            ans[i] = cu;
            room.push(i);
        }
    }

    cout << "Yes" << endl;
    rep(i, n) {
        if (i == 0) continue;
        cout << ans[i] + 1 << endl;
    }
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 10228
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>
#include<time.h>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。


for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}


*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

int dy[] = { 0, 1, 0, -1 };
int dx[] = { 1, 0, -1, 0 };


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}
*/

/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/

/*実行開始からの経過時間を表すよ。
while (clock() < 1900000) { ; }
*/

/*まだ使えないテクニックのメモだよ。
for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ
*/

/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/

int main() {
	int p, q, r; cin >> p >> q >> r;

	cout << min({ p + q, p + r, q + r }) << endl;


	return 0;
}


Measured memory_bytes: 764
import java.util.*;

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

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

    private void run() {
        int n = sc.nextInt();
        int m = sc.nextInt();
        Queue<Long> a = new PriorityQueue<>(Collections.reverseOrder());

        for (int i = 0; i < n; i++) {
            a.add(sc.nextLong());
        }

        for (int i = 0; i < m; i++) {
            long t = a.poll();
            a.add(t / 2);
        }

        long ans = a.stream().mapToLong(val -> val).sum();
        System.out.println(ans);
    }
}



Measured memory_bytes: 60320
#include <iostream>

using namespace std;

int main()
{
  int N, M;
  int a[100], b[100]; //念のため
  int path[100] = { 0 }; //念のため

  cin >> N >> M;

  for (int i = 0; i < M; i++)
  {
    cin >> a[i] >> b[i];
    path[a[i] - 1]++;
    path[b[i] - 1]++;
  }

  for (int i = 0; i < N; i++)
    cout << path[i] << endl;
}


Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
main()
{   int cnt=0;
    string s;
    cin>>s;
    int sz=s.size();
    int tmp=sz/2;
    for(int i=0,j=sz-1;i<tmp;i++,j--)
    {
        if(s[i]!=s[j])
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256