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

long long const MOD = 1000000007LL;

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> vec;
    for (int i = 0; i < h; i++) {
        string str;
        cin >> str;
        vec.push_back(str);
    }

    int width[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (vec[i][j] == '#') {
                width[i][j] = 0;
            } else {
                width[i][j] = 0;
                if (j > 0 && width[i][j - 1] != 0) {
                    width[i][j] += width[i][j - 1];
                } else {
                    for (int k = j - 1; k >= 0; k--) {
                        if (vec[i][k] == '#') {
                            break;
                        } else {
                            ++width[i][j];
                        }
                    }
                    for (int k = j + 1; k < w; k++) {
                        if (vec[i][k] == '#') {
                            break;
                        } else {
                            ++width[i][j];
                        }
                    }
                }
            }
        }
    }

    int height[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (vec[i][j] == '#') {
            height[i][j] = 0;
            } else {
                height[i][j] = 0;
                if (i > 0 && height[i - 1][j] != 0) {
                    height[i][j] += height[i - 1][j];
                } else {
                    for (int k = i - 1; k >= 0; k--) {
                        if (vec[k][j] == '#') {
                            break;
                        } else {
                            ++height[i][j];
                        }
                    }
                    for (int k = i + 1; k < h; k++) {
                        if (vec[k][j] == '#') {
                            break;
                        } else {
                            ++height[i][j];
                        }
                    }
                }
            }
        }
    }
    int res = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            res = max(res, width[i][j] + height[i][j] + 1);
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()

typedef long long ll;

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

bool edge[8][8];
bool visited[8];
int cnt = 0;
int n,m;


void init(){
    rep(i,n) visited[i] = 0;
    visited[0] = true;
}

bool check(){
    bool ans = 1;
    rep(i,n){
        if(!visited[i]) ans = 0;
    }
    
    return ans;
}

void dfs(int x){
    
    if(check()) {
        cnt++;
        return;
    }
    
    rep(i,n){
        if(edge[x][i] and !visited[i]){
            visited[i] = 1;
            dfs(i);
            visited[i] = false;
        }
    }
    
    
    return;
}



int main(){
    cin >> n >> m;
    
    rep(i,m){
        int x,y;
        cin >> x >> y;
        
        edge[x-1][y-1] = edge[y-1][x-1] = 1;
    }
    
    init();
    dfs(0);
    
    cout << cnt << endl;
}






Measured memory_bytes: 256
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())), np.int64)
B = np.array(list(map(int, input().split())), np.int64)
if sum(B) > sum(A):
    print(-1)
else:
    diff = A - B
    sort_idx = diff.argsort()
    # A = A[sort_idx]
    # B = B[sort_idx]
    diff = diff[sort_idx]
    l = 0
    r = N-1
    ans = sum(diff < 0)
    if ans != 0:
        ans += 1
    while True:
        if diff[l] >= 0:
            break
        if diff[r] >= -diff[l]:
            diff[r] += diff[l]
            diff[l] = 0
            l += 1
        else:
            diff[l] += diff[r]
            diff[r] = 0
            r -= 1
            ans += 1
    print(ans)


Measured memory_bytes: 23896
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
typedef long long int ll;

int compare(const void* x, const void* y){
  if(*(int*)x<*(int*)y) return -1;
  else if(*(int*)x>*(int*)y) return 1;
  return 0;
}

int main(){
  int N;
  scanf("%d",&N);
  int *A;
  A=(int *)malloc(N*sizeof(int));
  for(int i=0;i<N;i++) scanf("%d",&A[i]);
  qsort(A,N,sizeof(int),compare);

  int *B;
  B=(int *)malloc(N*sizeof(int));
  for(int i=0;i<N;i++) B[i]=A[i]%A[0];
  qsort(B,N,sizeof(int),compare);

  int divider=A[0];
  while(1){
    //Bが全部ゼロ
    int check=0;
    for(int i=0;i<N;i++){
      if(B[i]!=0) check=1;
    }
    if(check==0){
      printf("%d\n",divider);
      return 0;
    }

    //Bに1がある
    for(int i=0;i<N;i++){
      if(B[i]==1){
        printf("1\n");
        return 0;
      }
    }

    //どちらでもない
    divider=B[N-1];
    for(int i=0;i<N;i++) B[i]=A[i]%divider;
    qsort(B,N,sizeof(int),compare);
  }

  return 0;
}

Measured memory_bytes: 1396
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for y in range(n):
    choku = 0
    for x in range(m):
        choku += a[y][x]*b[x]
    if choku+c > 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
let rec repeat_while f a =
  match f a with
  | None -> a
  | Some a -> repeat_while f a

let rec factors acc = function
  | [] -> acc
  | x :: xs ->
      let xs' =
        List.map (fun y -> repeat_while (fun (y, n) ->
          if y mod x = 0 then Some (y / x, n + 1) else None) (y, 0)) xs in
      factors (List.fold_left ( + ) 1 (List.map snd xs') :: acc) @@ List.filter (( <> ) 1) @@ List.map fst xs'
let factors = factors []

let n = 1000000007
let ( *^ ) x y = (x * y) mod n

let () = Scanf.scanf "%d" (fun n ->
  Array.init (n - 1) (fun i -> i + 2)
  |> Array.to_list
  |> factors
  |> List.map (( + ) 1)
  |> List.fold_left ( *^ ) 1
  |> Printf.printf "%d\n")

Measured memory_bytes: 2688
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(void){
   char s[201];
   char p[101];
   int i,j;
   int lp;

   scanf("%s",s);
   scanf("%s",p);
   sprintf(s,"%s%s",s,s);
   lp=strlen(p);

   i=0;
   while(i<200){
      if(s[i]==p[0]){
         for(j=0;j<lp;j++){
            if(s[i+j]!=p[j]){
               break;
            }
            else if(j==lp-1){
               printf("Yes\n");
               return 0;
            }
         }
      }
      i++;
   }
   printf("No\n");
   return 0;
}

Measured memory_bytes: 552
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;



int main(int argc, const char * argv[]) {

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

	int AB,BC,CA;
	int ans;

	cin >> AB >> BC >> CA;

	ans= AB * BC / 2;

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<ll> first_pl(N), first_mi(N), first_pl_r(N), first_mi_r(N);
    ll pl_sum = 0, mi_sum = 0, pl_sum_r = 0, mi_sum_r = 0;
    rep(i, N) {
        if (i%2 == 0) {
            // 0, 2, 4, ...のとき
            pl_sum += A[i];
            mi_sum -= A[i];
            first_pl[i] = pl_sum;
            first_mi[i] = mi_sum;
            pl_sum_r += A[N-1-i];
            mi_sum_r -= A[N-1-i];
            first_pl_r[N-1-i] = pl_sum_r;
            first_mi_r[N-1-i] = mi_sum_r;
        } else {
            // 1, 3, 5, ...のとき
            pl_sum -= A[i];
            mi_sum += A[i];
            first_pl[i] = pl_sum;
            first_mi[i] = mi_sum;
            pl_sum_r -= A[N-1-i];
            mi_sum_r += A[N-1-i];
            first_pl_r[N-1-i] = pl_sum_r;
            first_mi_r[N-1-i] = mi_sum_r;
        }
    }
    // 山1の分
    cout << pl_sum << " ";
    // 山2~N-1までの分
    repr(i, 1, N-1) {
        if (i%2 == 1) {
            // 山偶数の分
            cout << (first_pl[i-1] + A[i] + first_mi_r[i+1]) << " ";
        } else {
            // 山奇数の文
            cout << (first_mi[i-1] + A[i] + first_pl_r[i+1]) << " ";
        }
    }
    // 山Nの分
    cout << first_mi[N-2] + A[N-1] << endl;
    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
typedef unsigned long long ll;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
typedef std::vector<long long > vi ;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define endl '\n'
#define show(a) for(auto el:a)cout<<el<<" "
const ll INF=LLONG_MAX/2;
const ll N=2e5+1;
#define yesno(f) yes(f);no(f);
#define yes(f) if(f)cout<<"YES\n";
#define no(f) if(!f)cout<<"NO\n";
using  namespace std;
ll pow1(ll n,ll p)
{
	if(p==0)	return 1;
	ll x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}
int main()
{
    fast;
   ll t=1;
   //std::cin >> t;
   while(t--)
   {
       ll n,i,j=0,a,b,c,d;
       std::cin >>n;
       cout<<(pow1(10,n)-((2*pow1(9,n))%mod)+pow1(8,n)+mod)%mod<<"\n";
   }
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 105
using namespace std;
int n,a[M],b[M];
int main()
{
    while (~scanf("%d", &n)) {
        REP(i,1,n-1) scanf("%d", &b[i]);
 
        REP(i,1,n) a[i] = 2000000000;
        REP(i,1,n-1) {
            a[i] = min(a[i], b[i]);
            a[i+1] = min(a[i+1], b[i]);
        }
        printf("%d\n", accumulate(a+1, a+n+1, 0));
 
    }
    return 0;
}


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

int main() {
  int n, d, x;
  cin >> n >> d >> x;
  
  int ans = 0;
  REP(i, n) {
    int tmp;
    cin >> tmp;
    ans += (d - 1) / tmp + 1;
  }
  
  cout << ans + x << endl;
  
  return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc106/tasks/abc106_b
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main() {
  ll N; cin>>N;
  ll ans=0;
  FOR(i,1,N+1){
    if(i%2!=1)continue;
    auto result = divisor(i);
    if(result.size()==8)++ans;
  }
  cout<<ans<<endl;  
  return 0;
}

Measured memory_bytes: 256
import bisect
n=int(input())
A=[]
for i in range(n):
  A.append(int(input()))
Ans=[A[-1]]
for i in reversed(range(n-1)):
  a=A[i]
  if a>=Ans[-1]:
    Ans.append(a)
  else:

    Ans[bisect.bisect_right(Ans,a)]=a

print(len(Ans))

Measured memory_bytes: 7960
// ConsoleApplication1.cpp : アプリケーションのエントリ ポイントを定義します。
//

//#include "stdafx.h"

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <set>

//047 B

using namespace std;
int main()
{
	int W, H, N;
	cin >> W >> H >> N;
	int x1 = 0, x2 = W, y1 = 0, y2 = H;
	int x, y, a;

	for (int i = 0; i < N; i++) {
		cin >> x >> y >> a;
		switch (a) {
		case 1:
			x1 = max(x, x1);
			break;
		case 2:
			x2 = min(x, x2);
			break;
		case 3:
			y1 = max(y, y1);
			break;
		case 4:
			y2 = min(y, y2);
			break;
		}
	}
	
	W = x2 - x1;
	H = y2 - y1;

	if (W > 0 && H > 0) {
		cout << W * H << endl;
	}
	else cout << 0 << endl;

	

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
 
int32_t main() 
{
    IO;
    int m;
    cin>>m;
    int n;
    cin>>n;
    int a[n];
    int sum = 0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum += a[i];
    }
    int x = m - sum;
    if(x < 0)
    cout<<-1;
    else
    cout<<x;
    // cout<<lower_bound(v.begin(),v.end(),10) - v.begin();
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  for(int i=0; i<N; i++){
    if(A[i]%2==0){
      if(A[i]%3!=0 && A[i]%5!=0){
        cout <<"DENIED"<<endl;
        return 0;
      }
    }
  }
  cout <<"APPROVED"<<endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){
    return (a%b+b)%b;
}
ll gcd(ll a, ll b){
    return b ? gcd(b, a%b) : a;
}
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}
void Yes(){
    cout << "Yes" << endl;
}
void No(){
    cout << "No" << endl;
}
void Judge(bool b){
    b ? Yes() : No();
}
void YES(){
    cout << "YES" << endl;
}
void NO(){
    cout << "NO" << endl;
}
void JUDGE(bool b){
    b ? YES() : NO();
}
ll powmod(ll b, ll e){
    ll r = 1; while(e > 0) {if(e&1) r = (r%MOD)*(b%MOD)%MOD; b = (b%MOD)*(b%MOD)%MOD; e >>= 1;} return r;
}
double distance(ll x1, ll y1, ll x2, ll y2){
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

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;
}
template<typename T>
void ppp(T n){
    cout << n << endl;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for(int i = 0; i < len; ++i) {
        s << v[i]; if(i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa {
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    }
} fastio;

int main(){

    int k, x;
    cin >> k >> x;
    for(int i = x-k+1; i < k+x; ++i){
        cout << i << sp;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>

typedef long long ll;
const int N=201000;

char s[N];
int cnt[26];
int n;

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	ll ans=(ll)n*(n-1)/2+1;
	for(int i=1;i<=n;i++)
		cnt[s[i]-'a']++;
	for(int i=0;i<26;i++)
		ans-=(ll)cnt[i]*(cnt[i]-1)/2;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 384
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
#from collections import deque
#from collections import defaultdict
# from collections import Counter
#from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n,*a=map(int,read().split())
	
	aa=max(a)
	
	li=[[] for _ in range(aa+1)]
	
	for i in range(n):
		li[a[i]].append(i)
	
	if len(li[0])>3 or len(li[0])==0:
		print(0)
		exit(0)
	else:
		ans=3 if len(li[0])==1 else 6
	for i in range(1,aa+1):
		if len(li[i])>3 or len(li[i])==0 or len(li[i])>len(li[i-1]):
			print(0)
			exit(0)
		else:
			k=bisect.bisect_right(li[i-1],li[i][0])
			ans*=k
			ans%=MOD
			
			if len(li[i])>1:
				k=bisect.bisect_right(li[i-1],li[i][1])-1
				ans *= k
				ans %= MOD
		
	print(ans)
	
	
if __name__ == "__main__":
		main()


Measured memory_bytes: 59392
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#define N 10000
int main() {
	int i, j, cnt = 0, p[N] = { 0 },n;
	for (i = 2; i <= (int)sqrt(N); ++i) if (!p[i]) for (j = 2; j*i < N; j++) p[i*j] = 1;
	for (;~fscanf(stdin, "%d", &n); fprintf(stdout, "%d\n", cnt))
		for (cnt = 0, i = 2; i < n; ++i) if (!(p[i] + p[n - i + 1]))++cnt;
	return 0;
}

Measured memory_bytes: 648
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
namespace MF{
	#define MAXN 25252
	#define MAXM 5001001//実際の辺の2倍必要！！
	#define wint int
	const wint wEPS=0;
	const wint wINF=1001001001;
	int n,m,ptr[MAXN],next[MAXM],zu[MAXM];
	int from[MAXM];
	wint capa[MAXM],tof;
	int lev[MAXN],see[MAXN],que[MAXN],*qb,*qe;
	void init(int _n){
		n=_n;m=0;memset(ptr,~0,n*4);
	}
	void ae(int u,int v,wint w0,wint w1=0){
		from[m]=u;
		next[m]=ptr[u];ptr[u]=m;zu[m]=v;capa[m]=w0;++m;
		from[m]=v;
		next[m]=ptr[v];ptr[v]=m;zu[m]=u;capa[m]=w1;++m;
	}
	/*void save(void){
		memcpy(cap2,capa,sizeof(capa));
	}
	void load(void){
		memcpy(capa,cap2,sizeof(cap2));
	}*/
	wint augment(int src,int ink,wint flo){
		if(src==ink) return flo;
		wint f;
		for(int &i=see[src];~i;i=next[i]) if(capa[i]>wEPS && lev[src]<lev[zu[i]]){
			if((f=augment(zu[i],ink,min(flo,capa[i])))>wEPS){
				capa[i]-=f;capa[i^1]+=f;return f;
			}
		}
		return 0;
	}
	bool solve(int src,int ink,wint flo=wINF){
		wint f;
		int i,u,v;
		for(tof=0;tof+wEPS<flo;){
			qb=qe=que;
			memset(lev,~0,n*4);
			for(lev[*qe++=src]=0,see[src]=ptr[src];qb!=qe;){
				for(i=ptr[u=*qb++];~i;i=next[i]) if(capa[i]>wEPS && !~lev[v=zu[i]]){
					lev[*qe++=v]=lev[u]+1;see[v]=ptr[v];
					if(v==ink) goto au;
				}
			}
			return 0;
		au:	for(;(f=augment(src,ink,flo-tof))>wEPS;tof+=f);
		}
		return 1;
	}
}
string ma[110];
int main()
{
	int h,w;
	cin>>h>>w;
	rep(i,h) cin>>ma[i];
	MF::init(2*h*w+2);
	rep(i,h) rep(j,w){
		if(ma[i][j]=='o') MF::ae(i*w+j,h*w+i*w+j,1);
		if(ma[i][j]=='S') MF::ae(h*w*2,i*w+j,MF::wINF),MF::ae(i*w+j,h*w+i*w+j,MF::wINF);
		if(ma[i][j]=='T') MF::ae(h*w+i*w+j,h*w*2+1,MF::wINF),MF::ae(i*w+j,h*w+i*w+j,MF::wINF);
	}
	rep(i,h) rep(j,w){
		int s=h*w+i*w+j;
		rep(k,h) MF::ae(s,k*w+j,MF::wINF);
		rep(k,w) MF::ae(s,i*w+k,MF::wINF);
	}
	MF::solve(h*w*2,h*w*2+1);
	if(MF::tof>=MF::wINF) cout<<-1<<endl;
	else cout<<MF::tof<<endl;
}


Measured memory_bytes: 69888
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int a,b;
    cin>>a>>b;
    FOR(i,0,1010){
        if(i*8/100==a&&i*10/100==b){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 256
// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    string s, t;
    cin >> s >> t;

    int ans = 0;

    const int n = s.size();

    for (int i = 0; i < n; i++) {
        if (s[i] != t[i]) ans++;
    }

    cout << ans << endl;
}


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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	
	vector<int> rate(8, 0);
	int wild = 0;
	rep(i, n){
		if(a[i] < 3200){
			rate[a[i] / 400]++;
		}
		else{
			wild++;
		}
	}
	
	int count = 0;
	rep(i, 8){
		if(0 < rate[i]) count++;
	}
	
	int mn = max(1, count);
	int mx = wild + count;
	
	cout << mn << " " << mx << endl;
	return 0;
}



Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//(int)'a'は97 (int)'A'は65
//おまじない



int main() {
	
	int t, a, b;
	cin >> t >> a >> b;

	cout << min(t*a, b) << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
    long long x, y;
    cin >> x >> y;

    if(x == 0 and y > 0){
        printf("%lld\n", y);
    }
    else if(x == 0 and y < 0){
        printf("%lld\n", 1-y);
    }
    else if(x > 0 and y == 0){
        printf("%lld\n", 1+x);
    }
    else if(x < 0 and y == 0){
        printf("%lld\n", -1*x);
    }
    else if(x > 0 and y > 0){
        if(y > x){
            printf("%lld\n", y-x);
        }
        else{
            printf("%lld\n", 2-y+x);
        }
    }
    else if(x > 0 and y < 0){
        if(x == -1*y){
            printf("1\n");
        }
        else if(abs(x) < abs(y)){
            printf("%lld\n", 1-x-y);
        }
        else{
            printf("%lld\n", 1+y+x);
        }
    }
    else if(x < 0 and y > 0){
        if(x == -1*y){
            printf("1\n");//OK
        }
        else if(abs(x) < abs(y)){
            printf("%lld\n", 1+y+x);
        }
        else{
            printf("%lld\n", 1-y-x);
        }
    }
    else if(x < 0 and y < 0){
        if(x < y){
            printf("%lld\n", y-x);
        }
        else{
            printf("%lld\n", 2-y+x);
        }
    }

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

void mainsolve(){

	string s;
	cin >> s;
	if(s=="AAA" || s=="BBB"){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}

	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func floatSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	r, c, k := iScan(), iScan(), iScan()
	x := make([][]int, r+1)
	for i := 0; i < r+1; i++ {
		x[i] = make([]int, c+1)
	}
	for i := 0; i < k; i++ {
		x[iScan()][iScan()] = iScan()
	}
	dp := make([][][]int, r+1)
	for i := 0; i < r+1; i++ {
		dp[i] = make([][]int, c+1)
		for j := 0; j < c+1; j++ {
			dp[i][j] = make([]int, 4)
		}
	}
	for i := 1; i < r+1; i++ {
		for j := 1; j < c+1; j++ {
			dp[i][j][0] = max(dp[i-1][j])
			if x[i][j] > 0 {
				dp[i][j][1] = larger(dp[i][j-1][0]+x[i][j], dp[i][j-1][1])
				dp[i][j][1] = larger(dp[i][j][1], dp[i][j][0]+x[i][j])
				dp[i][j][2] = larger(dp[i][j-1][1]+x[i][j], dp[i][j-1][2])
				dp[i][j][3] = larger(dp[i][j-1][2]+x[i][j], dp[i][j-1][3])
			} else {
				dp[i][j][1] = dp[i][j-1][1]
				dp[i][j][2] = dp[i][j-1][2]
				dp[i][j][3] = dp[i][j-1][3]
			}
		}
	}
	fmt.Println(max(dp[r][c]))
}


Measured memory_bytes: 598864
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair <a, b>
#define ll long long
#define ld long double
#define all(a) a.begin(), a.end()
#define pi pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
#define int ll
#define endl "\n"
 
using namespace __gnu_pbds;
using namespace std;
 
template <class T> T printr(T p) { cout << p << '\n'; return 0; }
template <class T> T printe(T p) { cout << p << '\n'; exit(0); }
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
template <typename T> using ordered_set =
 tree<T, null_type, less<T>, rb_tree_tag, 
 tree_order_statistics_node_update>;
 
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
 
ll power(ll x, ll y, ll p){ 
   ll res = 1;
   x = x % p;  
   while (y > 0) {
      if (y & 1) 
         res = (res * x) % p; 
      y = y >> 1;
      x = (x * x) % p; 
   }
   return res;
}
 
const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
 
const int W = 1e5+5;
const int N = 105;

int dp[N][W];

int32_t main()
{
    IOS;
    #ifndef ONLINe5E_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif

    int n, w;
    cin >> n >> w;

    int v[n+1], wt[n+1];
    for(int i=1; i<=n; i++) cin >> wt[i] >> v[i];

    for(int i=0; i<=n; i++) {
        for(int j=0; j<=w; j++) {
            if(i==0) continue;
            if(j-wt[i] >= 0) dp[i][j] = max(dp[i-1][j-wt[i]] + v[i], dp[i-1][j]);
            else dp[i][j] = dp[i-1][j];
        }
        // cout << dp[i][w] << endl;
    }
    cout << dp[n][w] << endl;

    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}

/* g++ -DLOCAL -DDEBUG -std=c++17 -Wshadow -Wall -o "c" "icpc.cpp" 
-fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g */

Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main() {
    string s;
    cin >> s;
    if (s.substr(5,2) < "05") cout << "Heisei" << endl;
    else cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

ll x, y, z, a, b, c, n;

void naive()
{
	vector<ll> ans(n);
	REP(i, x)REP(j, y)REP(k, z)
	{
		ll p = (abs(i - a) + abs(j - b) + abs(k - c)) % n;
		ans[p]++;
	}
	REP(i, n) cout << ans[i] << (i == n - 1 ? "\n" : " ");
}

int main()
{
	cin >> x >> y >> z >> a >> b >> c >> n;

	//naive();

	vector<ll> baseline(n);
	REP(i, n)
	{
		baseline[i] += (a + 1) / n;
		baseline[i] += (x - a) / n;
	}
	REP(i, (a + 1 + n) % n) baseline[i]++;
	REP(i, (x - a + n) % n) baseline[i]++;
	baseline[0]--;

	vector<ll> baseplane(n);
	REP(i, n)
	{
		baseplane[i] += (b + 1) / n * x;
		baseplane[i] += (y - b) / n * x;
	}
	ll k = (b + 1) % n;
	ll s = 0;
	REP(i, k) s += baseline[i];
	REP(i, n)
	{
		baseplane[(i + k - 1 + n) % n] += s;
		s -= baseline[i];
		s += baseline[(i + k + n) % n];
	}
	k = (y - b) % n;
	s = 0;
	REP(i, k) s += baseline[i];
	REP(i, n)
	{
		baseplane[(i + k - 1 + n) % n] += s;
		s -= baseline[i];
		s += baseline[(i + k + n) % n];
	}
	REP(i, n) baseplane[i] -= baseline[i];

	vector<ll> ans(n);
	REP(i, n)
	{
		ans[i] += (c + 1) / n * x * y;
		ans[i] += (z - c) / n * x * y;
	}
	k = (c + 1 + n) % n;
	s = 0;
	REP(i, k) s += baseplane[i];
	REP(i, n)
	{
		ans[(i + k - 1 + n) % n] += s;
		s -= baseplane[i];
		s += baseplane[(i + k + n) % n];
	}
	k = (z - c + n) % n;
	s = 0;
	REP(i, k) s += baseplane[i];
	REP(i, n)
	{
		ans[(i + k - 1 + n) % n] += s;
		s -= baseplane[i];
		s += baseplane[(i + k + n) % n];
	}
	REP(i, n) ans[i] -= baseplane[i];
	REP(i, n) cout << ans[i] << (i == n - 1 ? "\n" : " ");
	return 0;
}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int j=0, k=0;
	int n=s.size();
	for(int i=0; i<n; i++)
	{
		if(s[i]=='S')
		{
			j++;
		}
		if(s[i]=='T' && j>0)
		{
			j--;
			k++;
		}
	}
	cout << n-(2*k);
}


Measured memory_bytes: 640
#include <stdio.h>
#define rep(i,n)for(int i=0;i<(int)(n);i++)
int main(){
    int n,m,x,c[12]={0},a[12][12]={0},y,z[12],b,d=2e9;
    scanf("%d%d%d",&n,&m,&x);
    rep(i,n){
    scanf("%d",&c[i]);
        rep(j,m){
            scanf("%d",&a[i][j]);
        }
    }
    rep(i,2){rep(j,2){rep(k,2){rep(l,2){rep(o,2){rep(p,2){rep(q,2){rep(r,2){rep(s,2){rep(t,2){rep(u,2){rep(v,2){
        y=i*c[0]+j*c[1]+k*c[2]+l*c[3]+o*c[4]+p*c[5]+q*c[6]+r*c[7]+s*c[8]+t*c[9]+u*c[10]+v*c[11];
        for(b=0;b<m;b++){
            z[b]=i*a[0][b]+j*a[1][b]+k*a[2][b]+l*a[3][b]+o*a[4][b]+p*a[5][b]+q*a[6][b]+r*a[7][b]+s*a[8][b]+t*a[9][b]+u*a[10][b]+v*a[11][b];
            if(z[b]<x)break;
        }
        if(b==m&&y<d)d=y;
    }}}}}}}}}}}}
    if(d==(int)2e9)puts("-1");
    else printf("%d",d);
    return 0;
}

Measured memory_bytes: 1700
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val A, B, Q = in.next().toInt
  val s = new Array[Long](A+1)
  val t = new Array[Long](B+1)
  val _x = new Array[(Long, Int)](Q+1)
  for(i <- 1 to A)
    s(i) = in.next().toLong
  for(i <- 1 to B)
    t(i) = in.next().toLong
  for(i <- 1 to Q)
    _x(i) = (in.next().toLong -> i)

  _x(0) = (0L -> 0)
  val x = _x.sorted
  

  //
  val dps = new Array[Long](A+1)
  var ind = 2
  for (i <- 1 to A) {
    val now = s(i)
    breakable {
      while (ind <= B)
        if (t(ind) > now)
          break
        else
          ind += 1
    }

    if (ind == B+1) {
      dps(i) = Math.abs(s(i) - t(ind-1))
    }
    else {
      dps(i) = Math.min(Math.abs(s(i) - t(ind-1)), Math.abs(s(i) - t(ind)))
    }
  }

  val dpt = new Array[Long](B+1)
  ind = 2
  for (i <- 1 to B) {
    val now = t(i)
    breakable {
      while (ind <= A)
        if (s(ind) > now)
          break
        else
          ind += 1
    }

    if (ind == A+1) {
      dpt(i) = Math.abs(t(i) - s(ind-1))
    }
    else {
      dpt(i) = Math.min(Math.abs(t(i) - s(ind-1)), Math.abs(t(i) - s(ind)))
    }
  }


  //////

  var si = 2
  var ti = 2

  val ans = new Array[Long](Q+1)
  for (i <- 1 to Q) {
    val now = x(i)._1

    breakable {
      while (si <= A)
        if (s(si) > now)
          break
        else
          si += 1
    }
    breakable {
      while (ti <= B)
        if (t(ti) > now)
          break
        else
          ti += 1
    }

    var tmp = 0L
    if (si == A+1)
      tmp = Math.abs(s(si-1) - now) + dps(si-1)
    else
      tmp = Math.min(Math.abs(s(si) - now) + dps(si), Math.abs(s(si-1) - now) + dps(si-1))

    if (ti == B+1)
      tmp = tmp min (Math.abs(t(ti-1) - now) + dpt(ti-1))
    else
      tmp = tmp min Math.min(Math.abs(t(ti) - now) + dpt(ti), Math.abs(t(ti-1) - now) + dpt(ti-1))

    ans(x(i)._2) = tmp
  }

  for(i <- 1 to Q)
    pw.println(ans(i))
  pw.flush()
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 64032
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
struct edge{ ll to; ll cap; ll rev;};
const ll MAXN=2600;
vector<edge> G[MAXN];


const ll Start=2598, Goal=2599;
bool used[MAXN];

void addEdge0(ll from, ll to, ll cap){
    edge A={to,cap,(ll)G[to].size()};
    edge B={from,0,(ll)G[from].size()};
    G[from].push_back(A);
    G[to].push_back(B);
    return;
}//有向グラフを作る

void addEdge1(ll a, ll b, ll cap){
    edge A={b,cap,(ll)G[b].size()};
    edge B={a,cap,(ll)G[a].size()};
    G[a].push_back(A);
    G[b].push_back(B);
    return;
}//無向グラフを作る

ll dfs(ll v, ll t, ll f){
    if(v==t) return f;
    used[v]=true;
    rep(i,G[v].size()){
        edge &e=G[v][i];
        if(!used[e.to] && e.cap>0){
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}



ll MaxFlow(){
    ll ans=0;
    while(true){
        rep(i,MAXN) used[i]=false;
        ll P=dfs(Start,Goal,INF);
        if(P==0) break;
        ans+=P;
    }
    return ans;
}

ll h,w,W;
ll B[51][51];

ll bakkin(ll i,ll j){
    if(h==2 || w==2) return B[i][j]+B[i][j+1]+B[i+1][j]+B[i+1][j+1];
    ll ans=0;
    if(i==0) ans+= B[0][j]+B[0][j+1];
    if(i==h-2) ans+=B[h-1][j]+B[h-1][j+1];
    if(j==0) ans+=B[i][0]+B[i+1][0];
    if(j==w-2) ans+=B[i][w-1]+B[i+1][w-1];
    if(i*(h-2-i)==0 && j*(w-2-j)==0) {
        ll a=i, b=j;
        if(i!=0) a++;
        if(j!=0) b++;
        ans-=B[a][b];
    }
    //cout<<i<<' '<<j<<' '<<ans<<endl;
    return ans;
}

int main(){
    cin>>h>>w>>W;
    ll SUM=0;
    rep(i,h) rep(j,w) cin>>B[i][j];
    rep(i,h) rep(j,w) SUM+=B[i][j];

    rep(i,h-1) rep(j,w-1) if((i+j)%2==0){
        ll K=i*51+j;
        if(i%2==0) {addEdge0(Start,K,W); addEdge0(K,Goal,bakkin(i,j));}
        if(j%2==1) {addEdge0(K,Goal,W); addEdge0(Start,K,0);}
    }

    if(h>2 || w>2){
        for(ll i=1;i<h-1;i+=2){
            for(ll j=1;j<w-1;j+=2){
                ll K=i*51+j;
                addEdge0(K-52,K,B[i][j]);
                addEdge0(K-50,K,B[i][j+1]);
                addEdge0(K+50,K,B[i+1][j]);
                addEdge0(K+52,K,B[i+1][j+1]);
            }
        }
    }

    cout<<SUM-MaxFlow()<<endl;



}


Measured memory_bytes: 3472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1505,mod=998244353;
int n,tot,a[N][N],head[N],nex[N*N<<1],to[N*N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
char s[N][N];
vector<int>v[N][N];
bool vis[N];
int num,c[N][N],vt[N],e[N];
void solve(int x,int y,int dx,int dy,int tot)
{
    while(x>=0&&x<=n&&y>=0&&y<=n)
    {
        v[x][y].push_back(tot);
        x+=dx;y+=dy;
    }
}
void dfs(int u)
{
    if(vis[u]) return;
    vis[u]=true;num^=vt[u];
    for(int i=head[u];i;i=nex[i])
        dfs(to[i]);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
        scanf("%s",s[i]+1);
    for(int i=0;i<=n;i++)
    {
        int x=0,y=i,dx=1,dy=1;
        for(int j=1;j<=(i>0&&i<n?2*n:n);j++)
        {
            v[x][y].push_back(i);
            if(x+dx<0||x+dx>n) dx*=-1;
            if(y+dy<0||y+dy>n) dy*=-1;
            x+=dx;y+=dy;
        }
    }
    for(int i=1;i<n;i++)
        for(int j=1;j<n;j++)
        if(s[i][j]=='o') a[i][j]=1;
    else if(s[i][j]=='x') a[i][j]=2;
    for(int i=1;i<n;i++)
        for(int j=1;j<n;j++)
    {
        int x=v[i][j][0],y=v[i][j][1];
        c[x][y]|=a[i][j];
        if(c[x][y]==3){cout<<0<<endl;return 0;}
    }
    for(int i=0;i<=n;i++)
        for(int j=i+2;j<=n;j+=2)
        if(c[i][j]==0) add(i,j),add(j,i),e[i&1]++;
    else vt[i]^=c[i][j]-1,vt[j]^=c[i][j]-1;
    int ans=1;
    for(int d=0;d<2;d++)
    {
        int nt=(n-d)/2+1;
        if(nt&1)
        {
            int cnt=0;
            for(int i=d;i<=n;i+=2)
                if(!vis[i])
            {
                cnt++;num=0;
                dfs(i);
                if(num&1){cout<<0<<endl;return 0;}
            }
            for(int i=1;i<=e[d]-nt+cnt;i++)
                ans=(ans<<1)%mod;
        }
        else for(int i=1;i<=e[d];i++) ans=(ans<<1)%mod;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 157696
#!/usr/bin/env python3
n, m, *x = map(int, open(0).read().split())
if n >= m:
    print(0)
    quit()
x.sort()
a = []
for i in range(m-1):
    a += [x[i+1]-x[i]]
a.sort()
ans = sum(a[:m-n])
print(ans)


Measured memory_bytes: 13964
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		label:while(true){
			int[] a = new int[5];
			boolean[] b = new boolean[4];
			boolean[] win = new boolean[4];
			int cnt=0;
			for(int i = 0;i<5;i++){
				a[i]=cin.nextInt();
				if(i==0&&a[i]==0){
					break label;
				}
				if(!b[a[i]]){
					b[a[i]]=true;
					cnt++;
				}
			}
			if(cnt==1||cnt==3){
				for(int i = 0;i<5;i++){
					System.out.println(3);
				}
				continue;
			}
			if(b[1]&&b[2]){
				win[1]=true;
				win[2]=false;
			}
			else if(b[2]&&b[3]){
				win[2]=true;
				win[3]=false;
			}
			else if(b[3]&&b[1]){
				win[3]=true;
				win[1]=false;
			}
			for(int i = 0;i<5;i++){
				if(win[a[i]]){
					System.out.println(1);
				}
				else{
					System.out.println(2);
				}
			}
		}

	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  if (A==1){
    A=14;
  }
  if (B==1){
    B=14;
  }
  if (A>B){
    cout << "Alice";
  } else if (A<B){
    cout << "Bob";
  } else {
    cout << "Draw";
  }
}

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

int main() {
    string o, e; cin >> o >> e;
    for (int i=0; i<o.size(); ++i) {
        cout << o[i];
        if (i != o.size()-1) cout << e[i];
        if (o.size() == e.size() && i == o.size()-1) {
            cout << e[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main( void ){
  int N;
  double sum = 0;
  double A;

  scanf("%d", &N);

  for(int i = 0; i < N; i++){
    scanf("%lf", &A);
    A = 1.0/A;
    sum += A;
  }

  printf("%lf\n", 1.0/sum);

  return 0;
}



Measured memory_bytes: 128
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
#define rep(i,n) for (ll i=0;i<n;i++)
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll s=0;
    ll mod = 1000000007;
    rep(i,n) {
        cin >> a[i];
        s+= a[i];
    }
    ll ans = 0;
    rep(i,n){
        s = s - a[i];
        ll tmp;
        tmp = (s%mod) * a[i] % mod;
        ans += tmp;
        ans%=mod; 
    }

    cout << ans ;



    return 0;
}

Measured memory_bytes: 4760
//abc100d

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>
#include<numeric>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで


using namespace std;
lint n,m;
lint x[2000];
lint y[2000];
lint z[2000];
lint summ[2000];
lint ans;
vector<lint> v[8];

int main(){
  cin >> n >> m;
  REP(i,n){
    cin >> x[i] >> y[i] >> z[i];
  }
  REP(i,8){
    int k = i;
    int k1 = k%2;
    k/=2;
    int k2 = k%2;
    k/= 2;
    int k3 = k%2;
    REP(j,n){
      v[i].pb(pow(-1,k1)*x[j]+pow(-1,k2)*y[j]+pow(-1,k3)*z[j]);
    }
    sort(v[i].begin(),v[i].end());
    reverse(v[i].begin(),v[i].end());
    lint ac = 0;
    REP(l,m){
      ac += v[i][l];
    }
    ans = max(ac,ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
def myAnswer(N:int,dic:dict) -> None:
   MAX = max(dic.values())
   dic2 = sorted(dic.items())
   for key,value in dic2:
      if(MAX == value):
         print(key)

def main():
   N = int(input())
   dic = {}
   for _ in range(N):
      s = input()
      if(s in dic.keys()):
         dic[s]+=1
      else:
         dic[s]=1
   myAnswer(N,dic)
if __name__ == '__main__':
   main()

Measured memory_bytes: 44124
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<Int, Int>;
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
struct SetupIO {
    SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;

template <template <class, class...> class TT, class... Args>
ostream& operator<<(ostream& out, TT<Args...> const& cont) {
    for (auto&& elem : cont) out << elem << " ";
    return out;
}
template <class T> ostream& operator<<(ostream& out, const vector<vector<T>>& vs) {
    for (auto&& v : vs) cout << v << endl;
    return out;
}
template <class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> const& val) {
    return (out << "{" << val.first << " " << val.second << "}");
}

void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) {
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#ifdef _MY_DEBUG
#define dump(...)                                                                                                    \
    cerr << "/* " << #__VA_ARGS__ << " [" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
#else
#define dump(...)
#endif

/**
 *    author:  knshnb
 *    created: CREATED_TIMESTAMP
 **/

signed main() {
    Int n;
    cin >> n;
    vector<vector<ii>> g(n);
    REP(i, n - 1) {
        Int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back({v, i});
        g[v].push_back({u, i});
    }
    vector<Int> ans(n - 1);
    // auto dfs = [&](auto f, Int v, Int prv) -> void {
    //     for (ii& p : g[v])
    //         if (p.fi != prv) {
    //             dfs(f, p.fi, v);
    //         }
    // };
    // dfs(dfs, 0, -1);
    vector<Int> c(n, -1);
    Int ma = -1;
    function<void(Int, Int)> dfs = [&](Int v, Int prv) {
        Int cur = 0;
        for (ii& p : g[v])
            if (p.fi != prv) {
                if (prv != -1 && c[prv] == cur) cur++;
                c[v] = cur;
                ans[p.se] = cur++;
                chmax(ma, cur);
                dfs(p.fi, v);
            }
    };
    dfs(0, -1);
    cout << ma << endl;
    for (Int x : ans) cout << x + 1 << endl;
}


Measured memory_bytes: 11136