akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int gcd(int a, int b){
    if(b > a) return gcd(b, a);
    else if(b == 0) return a;
    else return gcd(b, a % b);
}
int L[100010], R[100010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N) cin >> A[i];
    L[0] = R[N] = 0;
    rep(i, N) {
        L[i + 1] = gcd(L[i], A[i]);
    }
    RREP(i, N - 1, 0) {
        R[i] = gcd(R[i + 1], A[i]);
    }
    int ans = 1;
    rep(i, N) {
        ans = max(ans, gcd(L[i], R[i + 1]));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+2;
int d[101][101];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,m;
	cin>>n>>m;
	vector<pair<int,pii>> v;
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i==j) d[i][j]=0; else d[i][j]=1e12;
	for(int i=0;i<m;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;
		d[x][y]=min(d[x][y],z);
		d[y][x]=min(d[y][x],z);
		v.pb({z,{x,y}});
	}
	for(int k=1;k<=n;k++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	int ans=m;
	for(int i=0;i<m;i++)
	{
		bool ok=false;
		for(int j=1;j<=n;j++)
		{
			if(d[j][v[i].se.fi]+v[i].fi==d[j][v[i].se.se]){
				ok=true;
				break;
			}
		}
		if(ok) ans--;
	}
	cout<<ans;
}
// I never lose. I either win or I learn

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

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll n; cin >> n;

  auto f = [&](ll x) {
    int res = 0;
    while (x) {
      x /= 10;
      ++res;
    }
    return res;
  };

  ll ans = MOD;
  rep2(i, 1, sqrt(n)) {
    if (n % i == 0) {
      ll a = i, b = n / i;
      chmin(ans, max(f(a), f(b)));
    }
  }

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

Measured memory_bytes: 3628
class UnionFind:
    def __init__(self, n):
        self.par = [-1 for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if not x==y: # 根が同じでない場合のみ併合する
            if self.rank[x] < self.rank[y]:
                self.par[y] += self.par[x] # 要素数を併合
                self.par[x] = y # 根を付け替えている
            else:
                self.par[x] += self.par[y]
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
        
    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y) 

def main():
    import sys
    input = sys.stdin.readline
    N,M = map(int,input().split())
    P = list(map(int,input().split()))
    XY = [list(map(int,input().split())) for i in range(M)]
    A = UnionFind(N)
    
    for i in range(M):
        x,y = XY[i]
        A.union(x,y)
        
    ans = 0
    for i in range(N):
        j = i+1
        p = P[i]
        if A.same_check(j,p):
            ans += 1
    print(ans)
    
    
    
main()

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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

/* --------------- template start --------------- */
template <typename T> 
struct BinaryIndexTree { // [1, n]
    vector<T> array;
    int n;

    BinaryIndexTree(int _n) {
        array.resize(_n + 1, 0);
        n = _n;
    }

    T cumsum(int i) {
        T s = 0;
        while(i > 0) {
            s += array[i];
            i -= i & -i;
        }

        return s;
    }

    T sum(int i, int j) {
        T ret_i = cumsum(i - 1);
        T ret_j = cumsum(j);

        return ret_j - ret_i;
    }

    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i;
        }
    }
};

template<typename T>
struct UnionFind {
    vector<int> par;
    vector<T> sz;

    UnionFind(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

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

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;
        
        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }

    T size_of_tree(int x) {
        return sz[find_root(x)];
    }
};
/* --------------- template end --------------- */

/* --------------- function start --------------- */
llong my_gcd(llong a, llong b) {
    return (a ? my_gcd(b % a, a) : b);
}
llong my_lcm(llong a, llong b) {
    return a * b / my_gcd(a, b);    
}

llong facmod(llong n) {
    if (n == 0) return 1;

    llong res = n;
    for (int i = n - 1; i > 0; --i) {
        res = (res * i) % MOD;
    }

    return res;
}
llong powmod(llong a, llong n) {
    llong res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    }

    return res;
}
llong modinv(llong n) {
    return powmod(n, MOD - 2);
}
llong combmod(llong n, llong k) {
    llong res = 1;
    for (int i = 0; i < k; ++i) {
        res = (res * (n - i)) % MOD;
    }
    res = (res * modinv(facmod(k))) % MOD;

    return res;
}
/* --------------- function start --------------- */

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

    string S;
    cin >> S;
    if (S == "hi" || S == "hihi" || S == "hihihi" || S == "hihihihi" || S == "hihihihihi") cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}   

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using db = double;
using ii = pair <int, int>;

#define int long long
#define FOR(a, b, c) for(int a = b, _c = c; a <= _c; ++a)
#define FORD(a, b, c) for(int a = b, _c = c; a >= _c; --a)
#define REP(a, b, c) for(int a = b, _ = c; a < _; ++a)
#define ALL(a, b) for(auto &a : b)
#define pb push_back
#define mp make_pair
#define all(a) begin(a), end(a)
#define reset(f, x) memset(f, x, sizeof(f))
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll

template <class T> void Max(T &x, T y) { x = (x > y) ? x : y;}

const int N = 55;
const ll mod = 1e9 + 7;
int n;
ll k, ans;
struct oo {
  int m[N][N];
};
oo a;
oo operator * (oo a, oo b) {
  oo c;
  FOR(i, 0, n) FOR(j, 0, n) c.m[i][j] = 0;
  FOR(t, 1, n) FOR(i, 1, n) FOR(j, 1, n) c.m[i][j] = (c.m[i][j] + a.m[i][t] * b.m[t][j] % mod) % mod;
  return c;
}
oo pw(oo a, int i) {
  oo b = a;
  i--;
  for(; i; i >>= 1, a = a * a) if(i & 1) b = b * a;
  return b;
}
main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> k;
  FOR(i, 1, n) FOR(j, 1, n) cin >> a.m[i][j];
  a = pw(a, k);
  FOR(i, 1, n) FOR(j, 1, n) ans = (ans + a.m[i][j]) % mod;
  cout << ans << '\n';
}


Measured memory_bytes: 512
using System;
using System.Linq;
class c
{
    static void Main()
    {
        var inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        inp = inp.OrderBy(f => f).ToArray();
        Console.WriteLine(inp[2] * 10 + inp[1] + inp[0]);
    }
}

Measured memory_bytes: 13396
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

template <class T>
vector<vector<T>> Imos2D(const vector<vector<T>> &a)
{
    int h = a.size();
    int w = a[0].size();
    vector<vector<T>> s(h + 1, vector<T>(w + 1, 0));
    rep(i, h) rep(j, w) s[i + 1][j + 1] = a[i][j];
    rep(i, h + 1) rep(j, w) s[i][j + 1] += s[i][j];
    rep(i, h) rep(j, w + 1) s[i + 1][j] += s[i][j];
    return s;
}

//元のでーたで(i-1,j-1)を頂点とし、１辺がh,wの長方形の中のsum
template <class T>
int sum(const std::vector<std::vector<T>> &s, int i, int j, int h, int w)
{
    return s[i + h][j + w] - s[i][j + w] + s[i][j] - s[i + h][j];
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<vector<int>> vwhite(2 * k, vector<int>(2 * k, 0));
    vector<vector<int>> vblack(2 * k, vector<int>(2 * k, 0));

    int sumb, sumw;
    sumb = sumw = 0;

    rep(i, n)
    {
        int x, y;
        string s;
        cin >> x >> y >> s;
        if (s[0] == 'B')
        {
            vblack[x % (2 * k)][y % (2 * k)]++;
            sumb++;
        }
        else
        {
            vwhite[x % (2 * k)][y % (2 * k)]++;
            sumw++;
        }
    }

    auto imos_white = Imos2D(vwhite);
    auto imos_black = Imos2D(vblack);

    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < k; j++)
        {
            int answ = 0, ansb = 0;
            int x[5] = {i, 0, 0, i + k, i + k};
            int y[5] = {j, j + k, 0, j + k, 0};
            int dx[5] = {k, i, i, k - i, k - i};
            int dy[5] = {k, k - j, j, k - j, j};
            rep(k, 5)
            {
                answ += sum(imos_white, x[k], y[k], dx[k], dy[k]);
                ansb += sum(imos_black, x[k], y[k], dx[k], dy[k]);
            }
            ans = max({ans, answ + (sumb - ansb), ansb + (sumw - answ)});
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 63104
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int ss[100001];
int dp[30];
string S;
int main(){
        REP(i,30){
           dp[i]=0;
        }
	cin>>S;
	REP(i,S.size()){
	   ss[i]=S[i]-'a';
	}
	if(S.size()==2){
	   if(S[0]==S[1]){
	      cout<<1<<" "<<2<<endl;
	   }else{
	      cout<<-1<<" "<<-1<<endl;
	   }
	   return 0;
	}

	if(S[0]==S[1]){
	   cout<<1<<" "<<2<<endl;
	   return 0;
	}
	if(S[1]==S[2]){
	   cout<<2<<" "<<3<<endl;
	   return 0;
	}
	if(S[0]==S[2]){
	   cout<<1<<" "<<3<<endl;
	   return 0;
	}
	int s=-2;
	int t=-2;
	dp[ss[0]]++;
        dp[ss[1]]++;
        dp[ss[2]]++;
	REP(i,S.size()-3){
	   dp[ss[i]]--;
	   dp[ss[i+3]]++;
	   if(dp[ss[i+3]]>=2){
	      s=i+1;
	      t=i+3;
	      break;
	   } 
	}
	cout<<s+1<<" "<<t+1<<endl;
	return(0);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

const int MAX_S = 1000000;

int main() {
    int D; cin >> D;
    vector<ll> cvec(26, 0);
    for(int i = 0; i < 26; ++i) cin >> cvec.at(i);
    vector< vector<ll> > smap(D, vector<ll>(26, 0));
    for(int i = 0; i < D; ++i) {
        for(int j = 0; j < 26; ++j) {
            cin >> smap.at(i).at(j);
        }
    }

    vector<ll> vvec(D, 0);
    vector<int> tvec(D, 0);
    vector<int> lastvec(26, 0);
    vector< vector<int> > lastmap(26, vector<int>(D, 0));
    ll sum = 0;
    for(int i = 0; i < D; ++i) {
        int t; cin >> t; t--;
        tvec.at(i) = t;
        // その日のコンテストの満足度
        sum += smap.at(i).at(t);
        // コンテストが行われた記録
        lastvec.at(t) = (i+1);
        // 行われなかったコンテストの不満
        for(int j = 0; j < 26; ++j) {
            sum -= (cvec.at(j)*((i+1) - lastvec.at(j)));
            lastmap.at(j).at(i) = (i+1) - lastvec.at(j);
        }
        vvec.at(i) = sum;
    }

    /*for(int i = 0; i < D; ++i) {
        cout << vvec.at(i) << endl;
    }*/

    // 最初のパターンでの満足度が計算されている
    // クエリ処理

    /*for(int i = 0; i < D; ++i) {
        for(int j = 0; j < 26; ++j) {
            cout << lastmap.at(j).at(i) << " ";
        }
        cout << endl;
    }*/

    int m; cin >> m;
    vector<ll> nvvec(m, 0);
    for(int i = 0; i < m; ++i) {
        int d, q; cin >> d >> q;
        d--; q--;
        // tvec.at(d)をqに変える
        int pq = tvec.at(d);
        tvec.at(d) = q;
        // 満足度の増減
        sum -= smap.at(d).at(pq);
        sum += smap.at(d).at(q);

        // 不満の増減
        int cnt = 0;
        // 新しく加えた方
        for(int j = d; j < D; ++j) {
            if(j != d) {
                if(lastmap.at(q).at(j) == 0) break;
            }
            sum += (cvec.at(q))*(lastmap.at(q).at(j) - cnt);
            lastmap.at(q).at(j) = cnt;
            cnt++;
        }
        if(d == 0) cnt = 1;
        else cnt = lastmap.at(pq).at(d-1)+1;
        // 昔の値
        for(int j = d; j < D; ++j) {
            if(j != d) {
                if(lastmap.at(pq).at(j) == 0) break;
            }
            sum -= (cvec.at(pq)*(cnt - lastmap.at(pq).at(j)));
            lastmap.at(pq).at(j) = cnt;
            cnt++;
        }
        /*for(int i = 0; i < D; ++i) {
            for(int j = 0; j < 26; ++j) {
                cout << lastmap.at(j).at(i) << " ";
            }
            cout << endl;
        }*/
        nvvec.at(i) = sum;
    }


    for(int i = 0; i < m; ++i) {
        cout << nvvec.at(i) << endl;
    }
}

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

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	string ans;
	for (int i = sy;i < ty;i++)ans.push_back('U');
	
	for (int i = sx;i < tx;i++)ans.push_back('R');

	for (int i = sy;i < ty;i++)ans.push_back('D');

	for (int i = sx;i <= tx;i++)ans.push_back('L');

	for (int i = sy;i <= ty;i++)ans.push_back('U');

	for (int i = sx;i <= tx;i++)ans.push_back('R');

	ans.push_back('D');
	ans.push_back('R');

	for (int i = sy;i <= ty;i++)ans.push_back('D');

	for (int i = sx;i <= tx;i++)ans.push_back('L');
	ans.push_back('U');
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  int t1, t2;
  t1 = h1*60 + m1;
  t2 = h2*60 + m2;
  
  int t = t2 - t1 -k;
  cout << t << endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> sum(N + 2, 0);
  ll ans = 0;
  for (int i = 0; i < N + 1; i++) {
    sum[i + 1] += sum[i] + i;
    //cout << sum[i + 1] << endl;
  }
  for (int i = K; i < N + 2; i++) {
    ll l = sum[i] - 1;
    ll r = sum[N + 1] - sum[N + 1 - i];
    ans += (r - l);
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4836
N,M=map(int, input().split())
H=list(map(int,input().split()))
List=[list(map(int,input().split())) for i in range(M)]

sup_list=[1 for i in range(N)]

for j in range(M):
    if H[List[j][0]-1]>H[List[j][1]-1]:
        sup_list[List[j][1]-1]=0
    elif H[List[j][0]-1]==H[List[j][1]-1]:
        sup_list[List[j][0]-1]=0
        sup_list[List[j][1]-1]=0
    else:
        sup_list[List[j][0]-1]=0


print(sum(sup_list))

Measured memory_bytes: 31928
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	double N, K; cin >> N >> K;
	double ans = 0;
	REP(i, 1, N + 1) {
		double cnt = 1 / N;
		int a = i;
		while (a < K) {
				cnt /= 2;
				a *= 2;
			}
		ans += cnt;
	}
	printf("%.15f\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
#include<queue>
#include<climits>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef queue<int> IntQueue;

const int MAX=100005;//1e5+4;
vector<vector<int>> A(MAX);
int U[MAX];
int V[MAX];
int Cu[MAX];
int Cv[MAX];

void solve(){
  int N,Su,Sv,a,b,u;
  cin>>N>>Su>>Sv;
  for(int i=1;i<N+1;i++){
    if (i==Su){
      U[i]=0;
    }
    else{
      U[i]=N;
    }
    if (i==Sv){
      V[i]=0;
    }
    else{ 
      V[i]=N;
    }
    Cu[i]=0;
    Cv[i]=0;
  }
  rep(i,N-1){
    cin>>a>>b;
    A[a].push_back(b);
    A[b].push_back(a);
  }
  IntQueue Qu;
  IntQueue Qv;
  /*
  for(int i=1;i<N+1;i++){
    Qu.push(i);
    Qv.push(i);
  }*/
  Qu.push(Su);
  Qv.push(Sv);
  Cu[Su]=1;
  Cv[Sv]=1;
    
  //uに関する探索
  while(!Qu.empty()){
    u=Qu.front();
    Qu.pop();
    rep(i,A[u].size()){
      int v=A[u][i];
      if (!Cu[v]){
        Cu[v]=1;
        U[v]=U[u]+1;
        Qu.push(v);
      }
    }
  }
  //vに関する探索
  while(!Qv.empty()){
    u=Qv.front();
    Qv.pop();
    rep(i,A[u].size()){
      int v=A[u][i];
      if (!Cv[v]){
        Cv[v]=1;
        V[v]=V[u]+1;
        Qv.push(v);
      }
    } 
  }
  int ans=-1;
  for(int i=1;i<N+1;i++){
    if(U[i]<V[i])ans=max(ans,V[i]);
  }
  cout<<ans-1<<endl;
  return;
}

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


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

static const int MAX = 100;

int main() {
  int n, a[MAX], count = 0;

  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", &a[i]);

  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > i; j--) {
      if ( a[j] < a[j - 1] ) {
        swap(a[j], a[j - 1]);
        count++;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (i > 0) {
      printf(" ");
    }

    printf("%d", a[i]);
  }

  printf("\n");

  printf("%d", count);

  printf("\n");

  return 0;
}



Measured memory_bytes: 2712
n = int(input())

nm = 0
na = 0
nr = 0
nc = 0
nh = 0

for i in range(n):
    a = input()
    for j in a:
        b = j
        break
    if b == "M":
        nm += 1
    elif b == "A":
        na += 1
    elif b == "R":
        nr += 1
    elif b == "C":
        nc += 1
    elif b == "H":
        nh += 1

count = 0

count += nm * na * nr
count += nm * na * nc
count += nm * na * nh
count += nm * nr * nc
count += nm * nr * nh
count += nm * nc * nh
count += na * nr * nc
count += na * nr * nh
count += na * nc * nh
count += nr * nc * nh

print(count)

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

#define reg register
#define ll long long

using namespace std;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int a, b;
int ans = 0, res = 1;

int main() {
    cin >> a >> b;
    while (res < b) {
        res += a - 1;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())
A = [a11, a12, a13, a21, a22, a23, a31, a32, a33]
N = int(input())
b = []
for _ in range(N):
    try:
        A[A.index(int(input()))] = '○'
    except ValueError:
        pass

ans = 'No'
if A[0] == '○' and A[1] == '○' and A[2] == '○':
    ans = 'Yes'
if A[3] == '○' and A[4] == '○' and A[5] == '○':
    ans = 'Yes'
if A[6] == '○' and A[7] == '○' and A[8] == '○':
    ans = 'Yes'

if A[0] == '○' and A[3] == '○' and A[6] == '○':
    ans = 'Yes'
if A[1] == '○' and A[4] == '○' and A[7] == '○':
    ans = 'Yes'
if A[2] == '○' and A[5] == '○' and A[8] == '○':
    ans = 'Yes'

if A[0] == '○' and A[4] == '○' and A[8] == '○':
    ans = 'Yes'
if A[2] == '○' and A[4] == '○' and A[6] == '○':
    ans = 'Yes'

print(ans)


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

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int, vector<int>, less<int> > q;
  rep(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i, m) {
    int t = q.top();
    q.pop();
    t /= 2;
    q.push(t);
  }
  ll ans = 0;
  while (!q.empty()) {
    int t = q.top();
    q.pop();
    ans += t;
  }

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

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int A, B;
  cin >> A >> B;
  int max;

  max = A + B;

  if(max < A-B) max = A - B;
  if(max < A*B) max = A * B;

  cout << max << endl;

  return 0;
}


Measured memory_bytes: 256
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    frame = ""
    for i in range(0, w): frame += "#"
    print(frame)
    ans = "#"
    for i in range(0, w - 2): ans += "."
    ans += "#"
    for i in range(0, h - 2): print(ans)
    print(frame)
    print()


Measured memory_bytes: 5612
#include <iostream>

int main(int argc, char* argv[]){
  
  while(true){
    double d;
    
    std::cin >> d;
    
    if(d < 0){
      break;
    }
    
    int i = d;
    int array_i[8] = {0, 0, 0, 0, 0, 0, 0, 0};
    
    if(i > 255){
      std::cout << "NA" << std::endl;
      continue;
    }
    
    for(int k = 0; k < 8; k++){
      array_i[k] = i % 2;
      i /= 2;
    }
    
    double r_d = d - (int)(d);
    int array_d[4] = {0, 0, 0, 0};
    
    {
      double jj = 0.5;
      for(int k = 0; k < 4; k++){
        if(r_d >= jj){
          r_d -= jj;
          array_d[k] = 1;
        }
        jj /= 2;
      }
    }
    
    if(r_d > 0){
      std::cout << "NA" << std::endl;
      continue;
    }
    
    for(int k = 7; k >= 0; k--){
      std::cout << array_i[k];
    }
    std::cout << ".";
    for(int k = 0; k < 4; k++){
      std::cout << array_d[k];
    }
    std::cout << std::endl;
  }
  
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
  
using namespace std;
  
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
  
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;
  
#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))
  
int F()
{
    char ch;
    int x, a;
    while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
    if (ch == '-') ch = getchar(), a = -1;
    else a = 1;
    x = ch - '0';
    while (ch = getchar(), ch >= '0' && ch <= '9')
        x = (x << 1) + (x << 3) + ch - '0';
    return a * x;
}
  
int H, W;
  
char str[110][110];
  
int cnt[110][110];
  
int sum(int x1, int y1, int x2, int y2)
{
    x1 = max(x1, 1), x1 = min(x1, H);
    x2 = max(x2, 1), x2 = min(x2, H);
    y1 = max(y1, 1), y1 = min(y1, W);
    y2 = max(y2, 1), y2 = min(y2, W);
    if (x1 > x2) return 0;
    if (y1 > y2) return 0;
    //cerr << x1 << ", " << y1 << " and " << x2 << ", " << y2 << endl;
    return cnt[x2][y2] + cnt[x1 - 1][y1 - 1] - cnt[x1 - 1][y2] - cnt[x2][y1 - 1];
}
  
int f[2][110][110][110];
  
int main()
{
    gii(H, W);
    for (int i = 1; i <= H; ++i)
        scanf("%s", str[i] + 1);
    int x = 0, y = 0;
    for (int i = 1; i <= H; ++i)
        for (int j = 1; j <= W; ++j)
            if (cnt[i][j] = (str[i][j] == 'o'), str[i][j] == 'E')
                x = i, y = j;
    for (int i = 1; i <= H; ++i)
        for (int j = 1; j <= W; ++j)
            cnt[i][j] += cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1];
    int ans = 0;
    for (int l = 0; x + l <= H; ++l)
        for (int r = 0; x - r > 0; ++r)
            for (int u = 0; y + u <= W; ++u)
                for (int d = 0; y - d > 0; ++d)
                {
                    int L = l & 1;
                    f[L][r][u][d] = 0;
                    int left = x - r, right = x + l;
                    int up = y - d, down = y + u;
                    left = max(1 + l, left);
                    right = min(H - r, right);
                    up = max(up, 1 + u);
                    down = min(down, W - d);
                    if (l && l + r + x <= H) f[L][r][u][d] = max(f[L][r][u][d], f[L ^ 1][r][u][d] + sum(x + l, up, x + l, down));
                    if (r && l + r <= x - 1) f[L][r][u][d] = max(f[L][r][u][d], f[L][r - 1][u][d] + sum(x - r, up, x - r, down));
                    if (u && u + d + y <= W) f[L][r][u][d] = max(f[L][r][u][d], f[L][r][u - 1][d] + sum(left, y + u, right, y + u));
                    if (d && u + d <= y - 1) f[L][r][u][d] = max(f[L][r][u][d], f[L][r][u][d - 1] + sum(left, y - d, right, y - d));
                    //cerr << l << ", " << r << ", " << u << ", " << d << " : " << f[l][r][u][d] << endl;
                    ans = max(ans, f[L][r][u][d]);
                }
    printf("%d\n", ans);
    return 0;
}

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

int main(){
  int n;
  char c;
  int f;

  cin >> n;
  getchar();

  f = 0;
  while(n){
    c = getchar();
    
    if(f == 1){
      if(c == 'o')f++;
      else f = 0;
    }else if(f == 2){
      if(c == 's')f++;
      else f = 0;
    }else if(f == 3){
      if(c == 'h')f++;
      else f = 0;
    }else if(f == 4){
      if(c == 'i')f++;
      else f = 0;
    }else if(f == 5){
      if(c == 'n')f++;
      else f = 0;
    }else if(f == 6){
      if(c == 'o'){
	putchar('a');
	f++;
      }else f = 0;
    }

    if(c == 'H')f = 1;

    if(c == '\n')n--;

    if(f==7)f = 0;
    else putchar(c);
  }
}

Measured memory_bytes: 0
x[3]={1,0,0};
main(t)
{
  char a,b;
  for(;~scanf(" %c,%c",&a,&b);)
    {
      t=x[a-65];
      x[a-65]=x[b-65];
      x[b-65]=t;
    }
  for(t=0;t<3;t++)
    if(x[t]==1)
      printf("%c\n",65+t);
  exit(0);      
}

Measured memory_bytes: 0
def main():
    import sys
    input=sys.stdin.readline
    #ダイクストラ法
    import heapq
    def dijkstra_heap(st):
        infi=10**18
        #始点sから各頂点への最短距離
        d = [infi] * h*w
        d[st] = 0
        edgelist = [(0,st)]
        while edgelist:
            dist,idx = heapq.heappop(edgelist)
            x=idx//w
            y=idx%w
            for dx in range(-2,3):
                for dy in range(-2,3):
                    nx=x+dx
                    ny=y+dy
                    if not (0<=nx<h and 0<=ny<w):
                        continue
                    if dx==0 and dy==0:
                        continue
                    if s[nx][ny]=="#":
                        continue
                    idx1=nx*w+ny
                    if abs(dx)+abs(dy)==1:
                        if d[idx1]>dist:
                            d[idx1]=d[idx]
                            heapq.heappush(edgelist,(d[idx1],idx1))
                    else:
                        if d[idx1]>dist+1:
                            d[idx1]=dist+1
                            heapq.heappush(edgelist,(d[idx1],idx1))
        return d


    h,w=map(int,input().split())
    ch,cw=map(int,input().split())
    dh,dw=map(int,input().split())
    ch-=1
    cw-=1
    dh-=1
    dw-=1
    s=[input() for _ in range(h)]
    st=ch*w+cw
    g=dh*w+dw
    d=dijkstra_heap(st)
    ans=d[g]
    if ans==10**18:
        print(-1)
    else:
        print(ans)
if __name__=="__main__":
    main()


Measured memory_bytes: 98076
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int i,l,n;
	char x[1001];
	while(1){
		cin>>x;
		l=strlen(x);
		n=0;
		for(i=0;i<l;i++){
			n=n+x[i]-'0';
		}
		if(n==0) break;
		cout<<n<<endl;
	}
	return 0;
}



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

int N;

int main(){
  cin >> N;
  int ans = 1000000000;
  for(int i = 1 ; i<N;++i){
    int a = i;
    int b = N-i;
    int digit_sum = 0;
    
    while(a>0||b>0){
     digit_sum = digit_sum + a%10 + b%10;
     a /=10;
     b /=10;
    }
    
    ans = min(ans,digit_sum);
    
  }
  
      cout << ans << endl;
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

void solve(long long N, std::vector<long long> a){
    vp b(N);
    vl ma;
    rep(i,N){
        if(ma.empty()||a[ma.back()]<a[i]){
            ma.push_back(i);
        }
    }
    ll M=ma.size();
    vl sum1(M+1),sumr(M+1);
    rep(i,N){
        ll hi=M,lo=-1;
        while(hi-lo>1){
            ll mid=(hi+lo)/2;
            if(a[ma[mid]]<=a[i])lo=mid;
            else hi=mid;
        }
        if(hi==0){
            sumr[0]+=a[i];
        }else{
            sum1[0]++;
            sum1[hi]--;
            sumr[hi]+=a[i]-a[ma[lo]];
        }
    }
    rep(i,M)sum1[i+1]+=sum1[i];
    rep(i,M){
        if(i==0)sum1[i]*=a[ma[i]];
        else sum1[i]*=a[ma[i]]-a[ma[i-1]];
    }
    vl ans(N);
    rep(i,M)ans[ma[i]]=sum1[i]+sumr[i];
    rep(i,N)cout<<ans[i]<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
}


Measured memory_bytes: 6644
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;


int main() {
    int X,Y;
    cin>>X>>Y;

    cout<<X+(Y/2)<<endl;
     return 0;
}



Measured memory_bytes: 256
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}

int main()
{
    ll n,d;
    cin>>n>>d;
    ll x,y;
    ll cnt=0;
    for(int i=1;i<=n;i++){
        cin>>x>>y;
        ll dist=x*x + y*y;
        if(dist<=d*d){
            cnt++;
        }
    }

    cout<<cnt<<endl;

    return 0;
}




Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;


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

	char s[256];
	cin >> s;
	map<char, int> a;
	int n = 1;
	for (int i = 0; s[i]; i++) {
		a[s[i]]++;
		n++;
		if (a[s[i]] == 2) {
			puts("-1");
			return 0;
		}
	}
	for (int c = 'z'; c >= 'a'; c--)
		if (!a[c]) s[n++] = c;
	if (next_permutation(s, s + n))
		cout << s << endl;
	else
		puts("-1");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int const nmax = 1e5;
int dp[1 + nmax];
int v[1 + nmax];

int main() {

  int n, k;
  cin >> n >> k;
  v[0] = - 1e4;
  cin >> v[1];
  for(int i = 2;i <= n;i++){
    cin >> v[i];
    dp[i] = (1LL<<31)-1;
    //dp[i] = min(dp[i-1] + abs(v[i] - v[i-1]), dp[i-2] + abs(v[i] - v[i-2]));
    for(int j = max(1, i - k);j < i;j++){
      dp[i] = min(dp[j] + abs(v[i] - v[j]), dp[i]);
    }
  }
  cout << dp[n];
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL =LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};


int main() {
    string s;cin>>s;
    int x, y;cin>>x>>y;
    set<int> x1,x2;
    set<int> y1,y2;
    y1.insert(0);
    int flag = 0;
    
    s.push_back('T');
    int fst = 0;
    for(auto j = 0; j<s.size();j++){
        
        if(s[j]=='T'){
            
            x1.insert(j);
            fst = j+1;
            break;
            
        }
        
    }
    
    if (x1.size()==0) x1.insert(0);
    int hv = 1;
    flag = fst;
    for(auto j = fst; j<s.size();j++){
        
        if(s[j]=='T'){
            
            if(hv == 0){
                
                for(auto i:x1){
                    x2.insert(i+(j-flag));
                    x2.insert(i-(j-flag));
                }
                
                swap(x1,x2);
                x2.clear();
                hv = 1;
                
            }else{
                
                for(auto i:y1){
                    y2.insert(i+(j-flag));
                    y2.insert(i-(j-flag));
                }
                
                swap(y1,y2);
                y2.clear();
                
                hv = 0;
                
            }
            flag = j+1;
        }

        
    }
    
    for(auto j:x1){
        
        if(j!=x) continue;
        
        
        for(auto k:y1){
            
            if(k !=y)continue;
            
            cout<<"Yes"<<endl;
            return 0;
        }
        
    }
    
    
    cout<<"No"<<endl;
    
    return 0;
}










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

const int INF = numeric_limits<int>::max();

int main() {
  int n;
  cin >> n;
  vector<vector<int>> F(n, vector<int>(10));
  vector<vector<int>> P(n, vector<int>(11));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> F[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 11; ++j) {
      cin >> P[i][j];
    }
  }

  int ans = -INF;
  for (int i = 1; i < 1024; ++i) {
    int res = 0;
    for (int j = 0; j < n; ++j) {
      int c = 0;
      for (int k = 0; k < 10; ++k) {
        if (F[j][k] and (i & (1 << k))) ++c;
      }
      res += P[j][c];
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        for(int i=a;i<=b;i++){
            if(0==i%k){
                System.out.println("OK");
                return;
            }
        }
        System.out.println("NG");
    }
}

Measured memory_bytes: 35772
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int h, w;
vector< vector<int> > senbei(15, vector<int>(10100, 0));
vector<ll> senbeicnt(10100, 0);     // 表の枚数が入っている
vector<ll> osenbeicnt(10100, 0);
vector<int> hcheck(15, 0);

int main() {
    while(1) {
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                cin >> senbei.at(i).at(j);
            }
        }
        for(int j = 0; j < w; ++j) senbeicnt.at(j) = 0;
        for(int j = 0; j < w; ++j) {
            for(int i = 0; i < h; ++i) {
                if(senbei.at(i).at(j)) senbeicnt.at(j)++;
            }
        }

        ll ans = 0;
        for(int bit = 0; bit < (1<<h); ++bit) {
            ll sum = 0;
            osenbeicnt = senbeicnt;
            for(int i = 0; i < h; ++i) {
                if(bit&(1<<i)) hcheck.at(i) = 1;
                else hcheck.at(i) = 0;
            }
            for(int i = 0; i < h; ++i) {
                if(hcheck.at(i)) {
                    // 横一列裏返す
                    for(int j = 0; j < w; ++j) {
                        if(senbei.at(i).at(j)) osenbeicnt.at(j)--;
                        else osenbeicnt.at(j)++;
                    }
                }
            }

            for(int j = 0; j < w; ++j) {
                ll omote = osenbeicnt.at(j);
                ll ura = h-omote;
                sum += max(omote, ura);
            }
            chmax(ans, sum);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3736
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



k, q = LI()
D = LI()
for _ in range(q):
    n, x, m = LI()
    ret = x
    D_m = [d % m for d in D]
    zero_or_one = [0] + list(accumulate([1 if d == 0 else 0 for d in D_m]))
    Dm_acc = [0] + list(accumulate(D_m))
    ret = x + (n - 1) // k * Dm_acc[-1] + Dm_acc[(n - 1) % k]
    zero_ret = (n - 1) // k * zero_or_one[-1] + zero_or_one[(n - 1) % k]
    print(n - 1 - (ret // m - x // m) - zero_ret)

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

int n, p, odd, even, a; long long ans = 1;

long long power(int a, int n) {
    if(n < 0) return 0;
    if(n == 0) return 1;
    if(n == 1) return a;
    long long b = power(a, n/2);
    b *= b;
    if(n&1) b *= a;
    return b;
}

int main() {
    scanf("%d%d", &n, &p);
    for(int i = 0; i < n; i++) {
        scanf("%d", &a);
        odd += (a&1);
        even += (not (a&1));
    }
    ans = power(2, even);
    if(odd > 0 || p == 1) ans *= power(2, odd-1);
    printf("%lld", ans);
}

Measured memory_bytes: 256
N = int(input())
point = [[0,0,0]]
tmp = []
for i in range(N):
    tmp = list(map(int,input().split()))
    point.append(list(tmp))

for i in range(N):

    if i == len(point):
        break

    Np = point[i][0]
    xp = point[i][1]
    yp = point[i][2]

    Nn = point[i+1][0]
    xn = point[i+1][1]
    yn = point[i+1][2]

    dist = abs(xn-xp) + abs(yn-yp)

    if dist != Nn - Np:
        if dist > Nn - Np:
            print('No')
            exit()
        else:
            if dist % 2 != (Nn - Np) % 2:
                print('No')
                exit()

print('Yes')



Measured memory_bytes: 27372
class SegTree:
    X_unit = -10**10
    X_f = max

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)

from bisect import bisect_left
mod = 998244353
N = int(input())
robots = []
for i in range(N):
    Xi,Di = map(int,input().split())
    robots.append((Xi,Di))
robots.sort(key=lambda x:x[0])
X = [rob[0] for rob in robots]
D = [rob[1] for rob in robots]

ST = SegTree(N)
ST.set_val(N-1,N-1)
for i in range(N-1)[::-1]:
    r = bisect_left(X,X[i]+D[i])
    if i+1 == r:
        ST.set_val(i,i)
    else:
        ST.set_val(i,ST.fold(i+1,r))
to = ST.X[N:]
dp = [0]*(N+1)
dp[0] = 1
for i in range(N):
    dp[to[i]+1] += dp[i]
    dp[to[i]+1] %= mod
    dp[i+1] += dp[i]
    dp[i+1] %= mod
print(dp[N])

Measured memory_bytes: 132364
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

/*bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}*/
/*ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/
/*ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}*/
/*ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}*/
//printf("%.10f\n", n);

signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	string s, t;
	ll n, m, a = 0, b = 0, c = 0, cnt = 0, ans = 0;
	cin >> n >> m >> a >> b;
	cout << max(max(n * a, n * b), max(m * a, m * b)) << endl;


	return 0;
}

Measured memory_bytes: 3648
object Main {
  def main(args: Array[String]): Unit = {
    var cost = 0
    val factors = scala.io.StdIn.readLine.split(" ").map{_.toInt}.sorted

    for(i <- 0 to 1) {
      cost += factors(i + 1) - factors(i)
    }

    println(cost)
  }
}

Measured memory_bytes: 27320
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int N;
string P="";
string Q="";
void full_search(int cnt, vector<int> &ret, string tmp){
    //cout << tmp << endl;
    if(cnt==N){
        ret[2]++;
        if(tmp==P){
            ret[0]=ret[2];
        }
        if(tmp==Q){
            ret[1]=ret[2];
        }
        return;
    }
    for(int i=1; i<=N; i++){
        if(tmp.find(to_string(i))==string::npos){
            full_search(cnt+1, ret, tmp+to_string(i));
        }
    }
}

int main(){
    cin >> N;
    for(int i=0; i<N; i++){
        int p;
        cin >> p;
        P+=to_string(p);
    }
    for(int i=0; i<N; i++){
        int q;
        cin >> q;
        Q+=to_string(q);
    }
    vector<int> ans(3,0);
    full_search(0, ans, "");

    cout << abs(ans[1]-ans[0]) << endl;
}

Measured memory_bytes: 256
N = int(input())
d=list(map(int, input().split()))
 
toori=int((N*(N-1))/2)
p=1
k=0
list_x=[0]*toori
for i in range(N):
  for j in range(N-i-1):
    list_x[(k)]=d[i]*d[p]
    p=p+1
    k=k+1
  p=i+2
kaihuku=0
for i in range(toori):
  kaihuku=kaihuku+(list_x[i])
print(kaihuku)

Measured memory_bytes: 3064