akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

int main()
{
	long long a;
	char s[30];
	scanf("%lld%s", &a, s);
	long long ans = a * (s[0] - '0');
	long long p = 10 * (s[2] - '0') + s[3] - '0';
	ans = ans + p * a / 100;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3212
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--) 
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	int k; cin >> k;
	string s; cin >> s;
	if (s.size() <= k) {
		cout << s << endl;
	}
	else {
		rep(i, k) {
			cout << s[i];
		}
		cout << "..." << endl;
	}
}

	








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

int main(){
    int r,g,b,sum;
    cin >> r >> g >> b;
    sum = r * 100 + g * 10 + b;
    if(sum %4 ==0)cout<< "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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 <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int f (int n) {
    int ret = 1;
    while ((n >>= 1) != 0) ret++;
    return ret; 
}
int popcount (int n) {
    int ret = n % 2;
    while ((n >>= 1) != 0) ret += n % 2;
    return ret;
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int l; cin >> l;
    int n = f(l); int m = 2 * (n - 1) + popcount(l) - 1;
    cout << n << " " << m << "\n";
    rep (i, n - 1) {
        cout << i + 1 << " " << i + 2 << " 0\n"
             << i + 1 << " " << i + 2 << " " << (1 << i) << "\n";
    }
    int now = 0;
    reprev (i, 20) {
        int k = (1 << i);
        if ((l & k) != 0) {
            if (now != 0) cout << i + 1 << " " << n << " " << now << "\n";
            now += k;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if((a>=1&&a<=9)&&(b>=1&&b<=9))
    {
        cout<<a*b<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
}


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

int main(){
	int H, W;
	cin >> H >> W;
	char s[H+2][W+2];
	rep(i,H+2)rep(j,W+2) s[i][j] = '.';
	for (int i = 1; i <= H; i++) {	
		string st;
		cin >> st;
		for (int j = 1; j <= W; j++) {
			s[i][j] = st[j-1];
		}
	}
	
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (s[i][j] == '.') {
				int sum = 0;
				for (int k = -1; k < 2; k++) {
				for (int l = -1; l < 2; l++) {
					sum += s[i+k][j+l] == '#';
				}
				}
				cout << sum;
			}	
			else cout << '#';
		}	
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector< pii >
#define vpll vector< pll >
#define mpii map<int,int>
#define mpll map<ll,ll>
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define s(v) v.size()
#define test ll t;cin>>t;while(t--)
#define vec vector<ll>
#define read0(v,n) for(int i=0;i<n;i++)cin>>v[i];
#define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i];
#define trav(a,x) for (auto& a: x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cut(x) {cout<<x;return 0;}
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define nl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
ll gcd(ll a, ll b)
{
	if (b==0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
ll pow(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}
const int N=1e5+5;
vec g[N];
bool vis[N];
void dfs(int u)
{
    vis[u]=1;
    trav(it,g[u])
    {
        if(!vis[it])
            dfs(it);
    }
}

int main()
{
    int n,m;cin>>n>>m;
    FOR(i,0,m-1)
    {
        int x,y;
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    int c=0;
    FOR(i,1,n)
    {
        if(!vis[i])
        {
            c++;
            g[i-1].pb(i);
            g[i].pb(i-1);
            dfs(i);
        }
    }
    cout<<c;
}


Measured memory_bytes: 10840
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[][] used;
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ans = 0;
        String tmp = sc.next();
        char[] s = tmp.toCharArray();
        for(int i = 1; i < n; i++){
            if(s[i-1] == 'L' && s[i] == 'L'){
                ans++;
            }
        }
        for(int i = 0; i < n-1; i++){
            if(s[i] == 'R' && s[i+1] == 'R'){
                ans++;
            }
        }
        int cnt = 0;
        for(int i = 0; i < n-1; i++){
            if(s[i] == 'R' && s[i+1] == 'L'){
                cnt++;
            }
        }
        System.out.println(Math.min(n-1,ans + k*2));
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


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

int main() {
  string S, T;
  cin >> S >> T;
  
  int N = S.size();
  vector<char> VS(110), VT(220);
  
  for (int i = 0; i < N; i++) {
    VS[i] = S[i];
    VT[i] = T[i];
    VT[N+i] = T[i];
  }
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (VT[i+j] != S[j]) break;
        
      if (j == N-1) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
  return 0;
  
  

    
   
    
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll x, y, z;
        in >> x >> y >> z;
        ll ans = 1;
        while (true) {
            if (y * ans + z * (ans + 1) > x) {
                break;
            }
            ans++;
        }
        ans--;
        out << ans << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=110000;
int n;
int a[N];
int cmp(int x,int y){return x>y;}
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n,cmp);
	for(int i=1,j;i<=n;i++)
	{
		if(a[i]==i)
		{
			for(j=i;j<=n&&a[j]==a[i];j++);j--;
			return puts((j-i)&1 ? "First" : "Second"),0;
		}
		if(a[i]>i&&a[i+1]<i)
			return puts((a[i]-i)&1 ? "First" : "Second"),0;
		if(a[i]>i&&a[i+1]==i)
		{
			for(j=i+1;j<=n&&a[j]==a[i+1];j++);j--;
			int t=(j-i-1)&(a[i]-i-1);
			return puts(t&1 ? "Second" : "First"),0;
		}
	}
	return 0;
}


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

int n, k;

int main() {
  cin >> n >> k;
  
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    int x; cin >> x;
    int min_dist = min(x, k - x);
    // 往復するので2倍
    sum += min_dist * 2;
  }
  cout << sum << endl;
  
  return 0;
}

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

int main(){
  string a;
  cin >> a;
  if (a[0] == a[1] && a[2] == a[3] && a[0] != a[2]){
    cout << "Yes" << endl;
  }
  else if (a[0] == a[2] && a[1] == a[3] && a[0] != a[1]){
    cout << "Yes" << endl;
  }
  else if (a[0] == a[3] && a[1] == a[2] && a[0] != a[1]){
  	cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
// AtCoder ABC061 C - たくさんの数式 / Many Formulas
// 2020.1.22 bal4u

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

typedef long long ll;

// pのフォーマット 2+4-5  == 2+45
char *num(ll *a, char *p) {
	ll n = 0;
	while (isdigit(*p)) {
		n = 10*n + (*p++ & 0xf);
		if (*p == '-') p++;
	}
	*a = n;
	return p;
}

ll calc(char *p) {
	ll a, s = 0;
	while (*p) {
		p = num(&a, p);
		if (*p == '+') s += a, p++;
		else if (*p == '-') p++;
		else s += a;
	}
	return s;
}

int main()
{
	int i, j, k, w; ll ans;
	char s[30], S[30];
	
	scanf("%s", s);
	w = strlen(s);
	k = 0; for (i = 0; i < w; ++i) S[k++] = s[i], S[k++] = '-';
	S[k-1] = 0;
	
//printf("w=%d, %s\n", w, S);

	ans = 0;
	for (k = (1<<(w-1))-1; k >= 0; --k) {
		strcpy(s, S);
		for (i = w-1; i >= 0; --i) {
			if ((k >> i) & 1) s[2*i+1] = '+';
		}
		//printf("k=%d, %s\n", k, s);
		ans += calc(s);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <stack>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
#define print(x) printf("%d ", x)

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい



void Main(){
	int M, K, m;
	cin >> M >> K;
	//m = pow(2, M);
	m = (1 << M);
	if(K >= m){
		cout << -1 << endl;
		return;
	}else if(M == 1){
		if(K == 1){
			cout << -1 << endl;
			return;
		}else if(K == 0){
			cout << "0 0 1 1" << endl;
			return;
		}
	}

	rep(i, m){
		if(i == K) continue;
		cout << i << " ";
	}
	cout << K << " ";
	rep(i, m){
		if(m-1-i == K) continue;
		cout << m-1-i << " ";
	}
	cout << K << endl;

}

int main()
{
	cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();

  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

void solve(int n, vector<int> &a) {
  for (int i = 1; i < n; ++i) {
    auto v = a[i];
    int j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j+1] = a[j];
      --j;
    }
    a[j+1] = v;
    bool fst = true;
    for (auto &&x : a) {
      cout << (fst? "": " ") << x;
      fst = false;
    }
    cout << "\n";
  }
}

int main() {
  // cout << fixed << setprecision(10);
  int N; cin >> N;
  vector<int> as;
  REP(i, N) {
    int A;
    cin >> A;
    as.push_back(A);
  }
  bool fst = true;
  for (auto &&x : as) {
    cout << (fst? "": " ") << x;
    fst = false;
  }
  cout << "\n";
  solve(N, as);
  return 0;
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
long long int dz[200007];
long long int dp[200007];

long long int ads(long long int k){
	if(k<0)return -k;
	return k;
}

int main(){
	int n,k;
  	cin>>n>>k;
  	long long int max=190000000000;
  	for(int i=1;i<=n;i++)dp[i]=max;
 	for(int i=1;i<=n;i++)cin>>dz[i];
	dp[1]=0;
  	
	for(int i=2;i<=n;i++){
      for(int i1=1;i1<=k;i1++){
        if(i1>=i)break;
    	dp[i]=min((dp[i-i1]+ads(dz[i]-dz[i-i1])),dp[i]);
      }
     }
    
	cout<<dp[n];
  return 0;
}

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

using namespace std;

const int INF = 1e9 + 5;

int dp[100005][3], happy[100005][3];

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) scanf("%d", &happy[i][j]);
    }

    dp[0][0] = happy[0][0];
    dp[0][1] = happy[0][1];
    dp[0][2] = happy[0][2];

    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + happy[i][j]);
            }
        }
    }

    printf("%d\n", max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])));
}


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

using namespace std;
using Graph = vector<vector<int>>;

int main() {
  long double n,m,sum=0; cin >> n >> m;
  vector<long double> a(n);

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

  sort(a.begin(),a.end());
  
  if (a[n-m]<sum/(4*m))
  {
      cout << "No";
  }
  else cout << "Yes";
  return 0;
}




Measured memory_bytes: 256
n= int(input())
l={}
a=0

for i in range(n):
  s=input()
  if s in l:
    l[s]+=1
  else:
    l[s]=1
  if a<l[s]:
    a=l[s]
  
ans=[]
for i in l.keys():
  if l[i]==a:
    ans.append(i)

ans.sort()
for j in ans:
  print(j)

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

void solve(long long D){
    if (D == 25) cout << "Christmas" << '\n';
    if (D == 24) cout << "Christmas Eve" << '\n';
    if (D == 23) cout << "Christmas Eve Eve" << '\n';
    if (D == 22) cout << "Christmas Eve Eve Eve" << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long D;
    scanf("%lld",&D);
    solve(D);
    return 0;
}


Measured memory_bytes: 256
program main
implicit none
character*16 :: a
integer :: n,i,j,x
integer,allocatable :: p(:)

read(*,*)n
allocate(p(n))
read(*, *)(p(i), i = 1,n)

x=0
do i=1,n-2
if ((p(i) <= p(i+1)) .and. (p(i+1) < p(i+2))) then
x = x +1
else if ((p(i) > p(i+1)) .and. (p(i+1) >= p(i+2))) then
x = x + 1
end if
end do

write(*,*) x

end program main

Measured memory_bytes: 256
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;
#define prev tavas
#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i)
const int N = (int) 2e5 + 5, mod = (int) 0, oo = 1e9 + 9;
int n, m, mark[N], to[N], head[N], prev[N], cap[N], cnt = 0;
string mat[N];
int f(int i, int j) { return i * m + j; }
bool outer(int i, int j) {
    return (i == 0 || j == 0 || i == n - 1 || j == m - 1);
}
void add_edge(int u, int v, int uv) {
    to[cnt] = v, cap[cnt] = uv, prev[cnt] = head[u], head[u] = cnt++;
    to[cnt] = u, cap[cnt] = +0, prev[cnt] = head[v], head[v] = cnt++;
}
int dfs(int v, int sink, int flow = oo) {
    if (mark[v]++) return 0;
    if (v == sink) return flow;
    for (int e = head[v]; e != -1; e = prev[e]) {
        int u = to[e];
        if (cap[e]) {
            int x = dfs(u, sink, min(flow, cap[e]));
            if (x > 0) {
                cap[e ^ 0] -= x;
                cap[e ^ 1] += x;
                return x;
            }
        }
    }
    return 0;
}
int max_flow(int source, int sink) {
    int res = 0;
    while (true) {
        memset(mark, 0, sizeof mark);
        int x = dfs(source, sink);
        if (!x) break;
        res += x;
    }
    return res;
}
int dx[] = {0, -1, 0, 1};
int dy[] = {1, 0, -1, 0};
int32_t main() {
    memset(head, -1, sizeof head);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> mat[i];
    int sink = N - 1, source = N - 2;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j) {
            for (int d = 0; d < 4; ++d) {
                int x = i + dx[d], y = j + dy[d];
                if (x >= 0 && y >= 0 && x < n && y < m) {
                    add_edge(f(i, j) << 1 | 1, f(x, y) << 1, oo);
                }
            }
            if (mat[i][j] == 'X')
                add_edge(source, f(i, j) << 1, oo);
            add_edge(f(i, j) << 1, f(i, j) << 1 | 1, 1 + oo * (mat[i][j] == 'X'));
            if (outer(i, j)) {
                if (mat[i][j] == 'X') {
                    cout << -1 << endl;
                    return 0;
                }
                add_edge(f(i, j) << 1 | 1, sink, oo);
            }
        }
    cout << max_flow(source, sink) << endl;

}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 300000;
const int MAXM = 200010;
const int MAXK = 110;
const int MAXQ = 200010;

int n, k;
string s;
vector<int> a, l, r;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    cin >> s;
    int cnt = 1;
    FOR(i,1,SZ(s)) {
        if (i == SZ(s)) {
            a.emplace_back(cnt);
            break;
        }
        if (s[i] == s[i-1]) cnt++;
        else {
            a.emplace_back(cnt);
            cnt = 1;
        }
    }
    int K = k + k + 1;
    if (K >= SZ(a)) cout << n-1;
    else {
        int res = 0;
        int cnt = 0;
        FOR(i,0,K-1) cnt += a[i];
        FOR(i,0,SZ(a)-1) {
            l.emplace_back(0);
            r.emplace_back(0);
        }
        FOR(i,0,SZ(a)-1) {
            if (i < 1) l[i] = a[i]-1;
            else l[i] = l[i-1] + a[i]-1;
        }
        FORE(i,SZ(a)-1,0) {
            if (i >= SZ(a)-1) r[i] = a[i]-1;
            else r[i] = r[i+1] + a[i]-1;
        }
        if (K < SZ(a)) res = max(res, cnt - 1 + r[K]);
        else res = max(res, cnt - 1);
        
        FOR(i,K,SZ(a)-1) {
            cnt += a[i];
            cnt -= a[i-K];
            int kq = cnt - 1;
            int lef = i-K+1, rig = i;
            if (rig + 1 < SZ(a)) kq += r[rig+1];
            if (lef - 1 >= 0) kq += l[lef-1];
            res = max(res, kq);
        }
        cout << res;
    }
    return 0;
}

Measured memory_bytes: 1992
package main

import (
	"fmt"
)

type drink struct {
	index int
	time  int
}

func main() {
	var N int
	fmt.Scan(&N)
	T := make([]int, N)
	for i := range T {
		fmt.Scan(&T[i])
	}
	var M int
	fmt.Scan(&M)
	D := make([]drink, M)
	for i := 0; i < M; i++ {
		var p, x int
		fmt.Scan(&p, &x)
		D[i].index = p - 1
		D[i].time = x
	}
	var sum int
	for i := 0; i < M; i++ {
		sum = 0
		for j := 0; j < N; j++ {
			if D[i].index == j {
				sum += D[i].time
			} else {
				sum += T[j]
			}
		}
		fmt.Println(sum)
	}
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int n,A[100];
    cin >> n;
    for (int i = 0;i < n;i++) cin >> A[i];
    for (int j = n-1;j >= 0;j--) {
        if (j != n-1) cout << " ";
        cout << A[j];
    }
    cout << endl;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, mi, x;
    int ans=0;
    cin >> n;
    mi = n;
    for( int i=0; i<n; i++){
        cin >> x;
        if(mi>=x){
            mi=x;
            ans++;
        }
    }
    cout << ans << endl;
}




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

using namespace std;

int N, x[4];
const int lim = 1e7;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

for (int i=0; i<3; i++)
    scanf ("%d", &x[i]);
int steps = 0;
while (steps <= lim)
{
    if (x[0] % 2 == 1 || x[1] % 2 == 1 || x[2] % 2 == 1)
        break;
    int sum = 0;
    for (int i=0; i<3; i++)
        x[i] >>= 1, sum += x[i];
    for (int i=0; i<3; i++)
        x[i] = sum - x[i];
    steps ++;
}
if (steps >= lim) steps = -1;
printf ("%d\n", steps);
return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

	int ans = 0;
	switch(X){
		case 1: ans += 300000; break;
		case 2: ans += 200000; break;
		case 3: ans += 100000; break;
	}
	switch(Y){
		case 1: ans += 300000; break;
		case 2: ans += 200000; break;
		case 3: ans += 100000; break;
	}

	if(X == 1 && Y == 1){
		ans += 400000;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
sub f{my$i=$_;
	return$m[$i]if$m[$i];
	for(@$i){
		$t=&f+1;
		if($t>$m[$i]){
			$m[$i]=$t;
			$z[$i]=$_
		}
	}
	$m[$i]
}
map{/ /,push@{$'+0},$`for<>;f,print$z[$_]+0,$/}1..<>


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

using namespace std;

typedef long long LL;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<bool> v(n);
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;
        a[i] = b - 1;
    }

    int cnt = 0;
    int i = 0;
    while (true) {
        cnt++;
        v[i] = true;
        i = a[i];
        if (v[i] == true) {
            cout << -1 << endl;
            break;
        } else if (i == 1) {
            cout << cnt << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 640
//CGL_2_C
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    double xp0, xp1, yp0, yp1, xp2, yp2, xp3, yp3;
    int q;
    int i;
    double s0x, s0y, s1x, s1y, s, t, x, y;

    q = sc.nextInt();
    for(i = 0;i < q;i++){
      xp0 = sc.nextDouble();
      yp0 = sc.nextDouble();
      xp1 = sc.nextDouble();
      yp1 = sc.nextDouble();
      xp2 = sc.nextDouble();
      yp2 = sc.nextDouble();
      xp3 = sc.nextDouble();
      yp3 = sc.nextDouble();

      s0x = xp1 - xp0;
      s0y = yp1 - yp0;
      s1x = xp3 - xp2;
      s1y = yp3 - yp2;

      s = s0x * s1y - s1x * s0y;

      if(xp0 == xp2 && yp0 == yp2){
        x = xp0;
        y = yp0;
      }else if(xp0 == xp3 && yp0 == yp3){
        x = xp0;
        y = yp0;
      }else if(xp1 == xp2 && yp1 == yp2){
        x = xp1;
        y = yp1;
      }else if(xp1 == xp3 && yp1 == yp3){
        x = xp1;
        y = yp1;
      }else{
        t = (s1y * (xp2 - xp0) - s1x * (yp2 - yp0)) / s;
        x = xp0 + t * s0x;
        y = yp0 + t * s0y;
      }

      System.out.println(x + " " + y);
    }

/*fin*/
    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 52940
#include<stdio.h>
#include<math.h>

int main(){
  int W, a, b, d;
  scanf("%d %d %d", &W, &a, &b);
  
  d = (fabs(b - (a + W)) <= (fabs)(a - (b + W))) ? (b - (a + W)):(a - (b + W));
  
  if(d > 0){
    printf("%d\n", d);
  } else {
    printf("0\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
n, x = map(int, input().split())
a = list(map(int, input().split()))

result = 0
mode = 0
if a[0] > x:
    result += a[1]
    a[1] = 0
    result += a[0] - x
    a[0] = x
for i in range(1, n):
    s = a[i] + a[i - 1]
    if s > x:
        t = s - x
        result += t
        a[i] -= t

print(result)

Measured memory_bytes: 14068
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
int compare(string a, string b) {
	int i;
	for (i = 0; i < a[i] != '\0'; i++) {
		if (b[i] == '\0')
			return -1;
		else if (a[i] < b[i])
			return 1;
		else if (a[i] > b[i])
			return -1;
	}
	if (b[i] != '\0')
		return 1;
	else
		return 0;
}
int main() {
	int n, q, s[222222], t[222222], x[222222], d[222222],i,g[222222],l,r,c,l2,r2[222222],j,w[222222];
	cin >> n >> q;
	vector<pair<int,pair<int,int>>> m(n);
	for (i = 0; i < n; i++) {
		scanf("%d%d%d",&s[i],&t[i],&x[i]);
		s[i] -= x[i];
		t[i] -= x[i];
		m[i] = make_pair(x[i], make_pair(s[i], t[i]));
	}
	sort(m.begin(), m.end());
	for (i = 0; i < q; i++) {
		scanf("%d",&d[i]);
		g[i] = -1;
	}
	for (i = 0; i < n; i++) {
		s[i] = m[i].second.first;
		t[i] = m[i].second.second;
      if(s[i]<=d[q-1]&&t[i]>d[0]){
		l = 0;
		r = q - 1;
		while (l != r) {
			c = (l + r) / 2;
			if (s[i] <= d[c]) {
				if (l + 1 == r) {
					c = l;
					if (s[i] <= d[c])
						r--;
					else
						l++;
				}
				else {
					r = c;
				}
			}
			else {
				if (l + 1 == r) {
					c = l;
					if (s[i] <= d[c])
						r--;
					else
						l++;
				}
				else {
					l = c;
				}
			}
		}
		l2 = l;
		l = 0;
		r = q - 1;
		while (l != r) {
			c = (l + r) / 2;
			if (t[i] > d[c]) {
				if (l + 1 == r) {
					c = r;
					if (t[i] > d[c])
						l++;
					else
						r--;
				}
				else {
					l = c;
				}
			}
			else {
				if (l + 1 == r) {
					c = r;
					if (t[i] > d[c])
						l++;
					else
						r--;
				}
				else {
					r = c;
				}
			}
		}
		r2[i] = l;
		for (j = l2; j <= r2[i]; j++) {
			if (g[j] != -1)
				j = r2[w[j]];
			else {
				g[j] = m[i].first;
				w[j] = i;
			}
		}
      }
	}
	for (i = 0; i < q; i++)
		cout << g[i] << endl;
}


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

using namespace std;

const int mod = 1e9 + 7;

void add_self (int& a, int b) {
  a += b;
  if (a >= mod)
    a -= mod;
}
void sub_self (int& a, int b) {
  a -= b;
  if (a < 0)
    a += mod;
}

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector < int > dp(k + 1);
  dp[0] = 1;
  for (int child = 0; child < n; ++child) {
    int up_to;
    cin >> up_to;
    vector < int > fake(k + 1);
    for (int used = k; used >= 0; --used) {
      int tmp = dp[used];
      int L = used + 1;
      int R = used + min (up_to, k - used);
      if (L <= R) {
        add_self (fake[L], tmp);
        if (R < k)
          sub_self (fake[R + 1], tmp);
      }
    }
    int prefix_sum = 0;
    for (int i = 0; i <= k; ++i) {
      add_self (prefix_sum, fake[i]);
      add_self (dp[i], prefix_sum);
    }
  }
  cout << dp[k];
}


Measured memory_bytes: 3968
#include <stdio.h>

int S=0;
int h=0;
int m=0;
int s=0;

main(){

scanf("%d",&S);

if(S>=0 && S<86400){

h = S/3600;
m =(S-h*3600)/60;
s =(S-h*3600)%60;

printf("%d:%d:%d\n",h,m,s);

}
return 0;
}

Measured memory_bytes: 592
c = [4,1,4,1,2,1,2,1]
while True:
	try:
		que = map(int, raw_input().split())
		mx,mxc = 0, "99999999"
		for sp in range(8):
			sm = 0
			for num in range(8):
				sm += c[(sp+num)%8] if c[(sp+num)%8] <= que[num] else que[num]
			if sm > mx:
				mx = sm
				mxc = "".join(map(str, c[sp:]+c[:sp]))
			elif sm == mx:
				ac = "".join(map(str, c[sp:]+c[:sp]))
				if int(mxc) > int(ac):
					mxc = ac
		print " ".join(map(str, mxc))
	except:
		break

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX = 1000100;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    COMinit();
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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

    if((2*y-x)%3 == 0 && (2*x-y)%3 == 0){
        ll a = (2*y-x)/3;
        ll b = (2*x-y)/3;
        cout << COM(a+b, a) << endl;
    }else{
        cout << 0 << endl;
    }
    
}

Measured memory_bytes: 27072
import sys

input = sys.stdin.readline
INF = float("inf")


def main():
    n = int(input())
    r = [None] * n
    c = [None] * n
    for i in range(n):
        r[i], c[i] = map(int, input().split())

    dp = [[INF] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = 0

    for width in range(2, n + 1):
        for i in range(n - width + 1):
            j = i + width - 1
            for m in range(i, j):
                dp[i][j] = min(dp[i][j], dp[i][m] + dp[m + 1][j] + r[i] * c[m] * c[j])

    ans = dp[0][n - 1]
    print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5688
n=gets.chomp.to_i

def sum_number(s)
  s=s.to_s
  leng = s.length
  sum = 0

  for i in 0..leng-1 do
    sum += s[i].to_i
  end
  return sum
end

if n%sum_number(n) == 0
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int a, b, c;
	cin >> a;
	int x[3];
	for (int i = 0;a > 0;i++) {
		x[i] = a % 10;
		a /= 10;
	}
	if (x[0] == x[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

int main(){
  string sa,sb,sc,s(3,1);
  cin>>sa>>sb>>sc;
  s[0]=sa[0]-32;
  s[1]=sb[0]-32;
  s[2]=sc[0]-32;
  cout<<s<<endl;
  
 return 0; 
}

Measured memory_bytes: 256
#include <stdio.h>
#pragma warning(disable : 4996)

int main(){

	int i, a;

	for (i = 1; 1; i++){
		scanf("%d", &a);
		if (a == 0){
			break;
		}
		printf("Case %d: %d\n", i, a);
	}

	return 0;
}

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

ll Gcd(int a,int b)
{
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(Gcd(b,a%b));
    }
}

int main()
{
	int n;
	cin >> n;
	ll ans = 0;
	for(int i = 1;i<=n;++i)
	for(int j = 1;j<=n;++j)
	for(int k = 1;k<=n;++k)
	ans += Gcd(i,Gcd(j,k));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b;
    cin>>a>>b;
    a--;
    long long tmp=a;
    if(tmp&1)
        tmp=0;
    long long tot=a;
    if(tot%4==1||tot%4==2)
        tot=1;
    else
        tot=0;
    long long tt=tmp+tot;
    long long ttmp=b;
    if(ttmp&1)
        ttmp=0;
    long long ttot=b;
    if(ttot%4==1||ttot%4==2)
        ttot=1;
    else
        ttot=0;
    long long ttt=ttmp+ttot;
    long long ans=tt^ttt;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a, b, c;

	scanf("%d %d %d",&a, &b, &c);

	if (a < b){
		if (b < c){ printf("Yes\n"); }
		else{
			printf("No\n");
		}
	}
	else{ printf("No\n"); }
	
	




		return(0);
}

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

int main()
{
    long long t,i,k,n,x,y=1,z=1,s=1;
    cin>>n;
   for(i=0;i<n;i++)
   {
       s=(s*10)%1000000007;
   }
    for(i=0;i<n;i++)
   {
       y=(y*9)%1000000007;
   }
    for(i=0;i<n;i++)
   {
       z=(z*8)%1000000007;
   }
   cout<<(((s-(2*y)+z)%1000000007)+1000000007)%1000000007;

    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
string s[2];
string::iterator p;
int fact();
int term();
int exp();
int k;
bool f[2];

int fact() {
  int x;string num;
  int mi=1;
  while(*p=='-') {
    mi*=-1;
    ++p;
  }
  while(isdigit(*p)){num+=*p;++p;}
  if(num.size()>1&&num[0]=='0') f[k]=0;
  if(num.size()) {
    x=0;
    for(int i=num.size()-1,j=0; i>=0; i--,j++) x+=(1<<j)*(num[i]=='1');
  } else if(p!=s[k].end()){
    if(*p!='(') f[k]=0;
    bool ff=(*p=='(');
    if(p!=s[k].end()&&*p=='(')++p;
    x=exp();
    if(ff&&*p!=')') f[k]=0;
    if(p!=s[k].end()&&*p==')')++p;
  } else f[k]=0;
  return x*mi;
}
 
int term() {
  int x=fact();
  while(*p=='*') {
    ++p;
    x*=fact();
  }
  return x;
}
 
int exp() {
  int x=term();
  while(*p=='+'||*p=='-') {
    if(*p=='+') {
      ++p;
      x+=term();
    } else {
      ++p;
      x-=term();
    }
  }
  return x;
}

int main() {
  string r="01+-*()=";
  sort(r.begin(),r.end());
  string t;
  cin >> t;
  map<char,int> m;
  for(int i=0; i<t.size(); i++) {
    if(isalpha(t[i])&&!m.count(t[i])) {
      int x=m.size();
      m[t[i]]=x;
    }
  }
  if(m.size()>r.size()) {
    cout << 0 << endl;
    return 0;
  }
  set<string> se;
  do {
    string e=t;
    for(int i=0; i<e.size(); i++) {
      if(isalpha(e[i])) e[i]=r[m[e[i]]];
    }
    int c=0;
    for(int i=0; i<e.size(); i++) {
      if(e[i]=='=') c++;
    }
    if(c!=1) continue;
    c=0;
    s[0]=s[1]="";
    for(int i=0; i<e.size(); i++) {
      if(e[i]=='=') {
        c++;
        continue;
      }
      s[c]+=e[i];
    }
    if(!s[0].size()||!s[1].size()) continue;
    int x[2]={0,0};
    for(k=0; k<2; k++) {
      f[k]=1;
      p=s[k].begin();
      int d=0,z=0;
      for(int i=0; i<s[k].size(); i++) {
        if(isdigit(s[k][i])) z++;
        if(s[k][i]=='(') {
          d++;
          if(i&&(isdigit(s[k][i-1])||s[k][i-1]==')')) f[k]=0;
          if(i!=s[k].size()-1&&(!isdigit(s[k][i+1])&&s[k][i+1]!='('&&s[k][i+1]!='-')) f[k]=0;
        }
        if(s[k][i]==')') {
          d--;
          if(i&&(!isdigit(s[k][i-1])&&s[k][i-1]!=')')) f[k]=0;
          if(i!=s[k].size()-1&&isdigit(s[k][i+1])) f[k]=0;
        }
        if(i) {
          if(s[k][i]=='+'||s[k][i]=='*') {
            if(s[k][i-1]=='+'||s[k][i-1]=='*'||s[k][i-1]=='-') f[k]=0;
          }
        } else if(s[k][i]=='+'||s[k][i]=='*') f[k]=0;
        if(d<0) f[k]=0;
      }
      if(d||!z) f[k]=0;
      if(f[k]) x[k]=exp();
    }
    if(f[0]&&f[1]&&x[0]==x[1]) {
      se.insert(r.substr(0,m.size()));
    }
  } while(next_permutation(r.begin(),r.end()));
  cout << se.size() << endl;
  return 0;
}

Measured memory_bytes: 3236
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<int> even(1e5 + 1), odd(1e5 + 1);
    for (int i = 0; i < n; i++) {
        int a; std::cin >> a;
        (i & 1 ? odd[a] : even[a])++;
    }
    std::vector<int> ie(1e5 + 1), io(1e5 + 1);
    std::iota(ie.begin(), ie.end(), 0);
    std::iota(io.begin(), io.end(), 0);
    std::sort(ie.begin(), ie.end(), [&](int i, int j) {
        return even[i] > even[j];
    });
    std::sort(io.begin(), io.end(), [&](int i, int j) {
        return odd[i] > odd[j];
    });
    if (ie[0] != io[0]) {
        std::cout << n - even[ie[0]] - odd[io[0]] << std::endl;
    }
    else {
        std::cout << n -
            std::max(even[ie[0]] + odd[io[1]], even[ie[1]] + odd[io[0]])
            << std::endl;
    }
    return 0;
}


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

string itoa(int source, int base, int digit = 0) {
    static const char char_set[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int current = source;
    string result;
    int length;
    
    while(current) {
        result += char_set[current % base];
        current /= base;
    }
    
    if (result == "") {
        result = "0";
    }
    
    reverse(result.begin(), result.end());
    length = result.length();
    
    for (int i = 0; i < (digit - length); i++) {
        result = "0" + result;
    }
    
    return result;
}

int main() {
    int n;
    int t[3];
    int l[8];
    int patterns, mp;
    string pattern;
    int take[3];
    int ans = INT_MAX;
    
    cin >> n;
    
    for (int i = 0; i < 3; i++) {
        cin >> t[i];
    }
    
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    
    patterns = (int)pow(4, n);
    
    for (int i = 0; i < patterns; i++) {
        mp = 0;
        pattern = itoa(i, 4, n);
        
        for (int ii = 0; ii < 3; ii++) {
            take[ii] = 0;
        }
        
        for (int ii = 0; ii < n; ii++) {
            if (pattern[ii] == '3') {
                continue;
            }
            
            if (take[pattern[ii] - '0']) {
                mp += 10;
            }
            
            take[pattern[ii] - '0'] += l[ii];
        }
        
        for (int ii = 0; ii < 3; ii++) {
            if (!take[ii]) {
                mp = -1;
                break;
            }
            
            mp += abs(take[ii] - t[ii]);
        }
        
        if (mp != -1) {
            ans = min(ans, mp);
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
	long long n, m;
	std::cin >> n >> m;
	if(n > m) {
		std::swap(n, m);
	}
	if(n == 1) {
		if(m == 1) {
			std::cout << "1\n";
		} else {
			std::cout << m - 2 << "\n";
		}
	} else {
		std::cout << (n - 2) * (m - 2) << '\n';
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define double long double

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define EPS 1e-8

typedef vector<double> vec;
typedef vector<vec> mat;

vec gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      B[i][j]=A[i][j];
    }
    B[i][n]=b[i];
  }

  for (int k = 0; k < n-1; k++) {
    for (int i = k + 1; i < n; i++) {
      double d = B[i][k] / B[k][k];
      for (int j = k + 1; j <= n; j++){
        B[i][j] -= B[k][j] * d;
      }
    }
  }

  for (int i = n - 1; i >= 0; i--) {
    double d = B[i][n];
    for (int j = i + 1; j < n; j++){
      d -= B[i][j] * B[j][n];
    }
    B[i][n] = d / B[i][i];
  }

  vec x(n);
  for(int i=0;i<n;i++)x[i]=B[i][n];
  return x;
}

int H,W,N;
vector<vector<int> > ps;
vector<int> crt;
vector<string> sb,tb;
double p;

vector<int> calc(const vector<string>& a){
  vector<int> res;
  int mn=H;
  for(int j=W-1;j>=0;j--){
    int tmp=0;
    for(int i=H-1;i>=0;i--){
      if(tb[i][j]!=a[i][j]){
        break;
      }
      tmp++;
    }
    minch(mn,tmp);
    res.push_back(mn);
  }
  reverse(all(res));
  return res;
}

void predfs(int i,int j){
  if(i==W){
    ps.push_back(crt);
    return ;
  }
  repl(k,j,H+1){
    crt.push_back(k);
    predfs(i+1,k);
    crt.pop_back();
  }
}
void dfs(int i0,int j0,mat& A,vec &b){
  if(i0==W){
    vector<string> crtb;
    crtb.resize(H);
    rep(i,H)crtb[i]=tb[i];
    rep(j,W){
      rep(i,H-crt[j])crtb[i][j]='.';
    }
    int crtidx=lower_bound(all(ps),crt)-ps.begin();
    rep(i,H)rep(j,W)rep(c,2){
      vector<string> tmp(H);
      rep(ni,H)tmp[ni]=crtb[ni];
      rep(ni,i+1)rep(nj,j+1){
        if(c==0) tmp[ni][nj]='W';
        else tmp[ni][nj]='B';
      }
      int nxtidx=lower_bound(all(ps),calc(tmp))-ps.begin();
      A[crtidx][nxtidx]-=p; b[crtidx]+=p*(double)(i+1)*(double)(j+1);
    }
    return ;
  }
  repl(k,j0,H+1){
    crt.push_back(k);
    dfs(i0+1,k,A,b);
    crt.pop_back();
  }
}

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

  while(1){
    cin>>H>>W;
    if(H==0)break;

    ps.clear(); p=1.0/(double)(H*W*2.0);
    sb.resize(H); tb.resize(H);

    rep(i,H)cin>>sb[i];
    rep(i,H)cin>>tb[i];

    predfs(0,0);
    N=ps.size();
    mat A(N,vec(N,0)); vec b(N,0.0);
    dfs(0,0,A,b);

    int startidx=lower_bound(all(ps),calc(sb))-ps.begin();
    int endidx=lower_bound(all(ps),calc(tb))-ps.begin();
    rep(i,N)A[i][i]+=1.0;
    rep(j,N)A[endidx][j]=0.0;
    A[endidx][endidx]=1.0; b[endidx]=0.0;
    vec res=gauss_jordan(A,b);
    printf("%.10Lf\n", res[startidx]);
  }

  return 0;
}



Measured memory_bytes: 5164
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
  int x, t;
  cin >> x >> t;
  if(x-t < 0) cout << 0;
  else cout << x - t;
}


Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N;
	std::cin >> N;
	std::cout << (N*N*N) << "\n";
}


Measured memory_bytes: 384