akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main()
{	
	const int INF = 1000010001;
	int n;
	int c[3] = { INF, INF, INF };

	cin >> n;

	vector<int> a(n);

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

	sort(a.begin(), a.end());

	int u = 0;
	while (u < n && a[u] < a[2] * 10)
		u++;

	for (int i = 0; i < u; i++) {
		for (int j = 0; j < u; j++) {
			if (i != j) {
				int b = a[j], k = 0;

				while (b /= 10)
					k++;

				int w = a[i] * (int)pow(10, k + 1) + a[j];
				if (c[2] > w) {
					c[2] = w;
					sort(c, c + 3);
				}
			}
		}
	}

	cout << c[2] << endl;
	
	return 0;
}



Measured memory_bytes: 3320
#include <stdio.h>
#include <string.h>

int map[101][101];
int w, h;

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

int dfs(int xs, int ys, int c, int xg, int yg)
{
	int i;
	if (xs == xg && ys == yg){
		return (1);
	}
	
	map[ys][xs] = -1;
	
	for (i = 0; i < 4; i++){
		int nx = xs + dx[i], ny = ys + dy[i];
		if (1 <= nx && nx <= w && 1 <= ny && ny <= h && map[ny][nx] == c && dfs(nx, ny, c, xg, yg)){
			return (1);
		}
	}
	
	return (0);
}

int main(void)
{
	
	int i, j, k;
	int xs, ys, xg, yg;
	int n;
	int c, d, x, y;
	
	while (1){
		scanf("%d%d", &w, &h);
		
		if (!(w + h)){
			break;
		}
		
		scanf("%d%d", &xs, &ys);
		scanf("%d%d", &xg, &yg);
		scanf("%d", &n);
		
		memset(map, 0, sizeof(map));
		
		for (i = 0; i < n; i++){
			scanf("%d%d%d%d", &c, &d, &x, &y);
			
			if (d == 0){
				for (j = 0; j < 2; j++){
					for (k = 0; k < 4; k++){
						map[y + j][x + k] = c;
					}
				}
			}
			else {
				for (j = 0; j < 4; j++){
					for (k = 0; k < 2; k++){
						map[y + j][x + k] = c;
					}
				}
			}
		}
		if (map[ys][xs] && dfs(xs, ys, map[ys][xs], xg, yg) == 1){
			printf("OK\n");
		}
		else {
			printf("NG\n");
		}
	}
	return (0);
}

Measured memory_bytes: 632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n1 = sc.nextInt();
		int n2 = sc.nextInt();
		int res = 0;
		for(int i=1;i<=3;i++) {
			if(i != n1 && i!= n2) {
				res = i;
				break;
			}
		}
		// 出力
		System.out.println(res);

		//scclose
		sc.close();
	}

}


Measured memory_bytes: 20564
from collections import defaultdict
import sys

def tree_path_dict():
    def walk(i, c):
        if d[i] == -1:
            d[i] = c
            for node, dist in edge[i].items():
                walk(node, c + dist)

    sys.setrecursionlimit(100000)
    n = int(input())
    edge = defaultdict(lambda: defaultdict(lambda: float("inf")))
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        edge[u][v] = w
        edge[v][u] = w
    d = [-1] * (n + 1)
    walk(1, 0)
    for item in d[1:]:
        print(item % 2)

tree_path_dict()

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

const ll INF = pow(10, 9) + 7;

int main() {
  vector<int> a(3,1);
  rep(i,2){
    int x;
    cin >> x;
    x--;
    a[x]--;
  }
  rep(i,3){
    if(a[i]==1){
      i++;
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	long long int N, M;
	cin >> N >> M;
	if (N == 1 && M == 1)
		cout << 1 << endl;
	else if (N == 1)
		cout << M - 2 << endl;
	else if (M == 1)
		cout << N - 2 << endl;
	else
		cout << (N - 2)*(M - 2) << endl;
		
	return 0;
}

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

    string s;
    cin >> s;
    
    int count = 0;
    for(int i=0; i<s.size(); i++) {
        if(s.substr(i,1)=="o") count++;
    }
    
    int remaind = 15-s.size();
    if(count+remaind>=8) cout  << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    
int condition;
char str[3];
scanf("%s", str);
    
    if(str[0]==str[1] && str[0]!=str[2]){
      condition = 0;     
    }
    
    else if(str[1]==str[2] && str[1]!=str[0]){
      condition = 0;     
    }    
    
    else if(str[0]==str[2] && str[0]!=str[1]){
      condition = 0;     
    } else {
        condition = 1;
    }
if (condition == 0){
   printf("Yes\n"); 
} else {
   printf("No\n");    
}    
    return 0;
}


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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

typedef tuple<int, int, int> T;

void solve()
{
  int H, W;
  cin >> H >> W;
  vector<vector<int>> s(H, vector<int>(W));
  int sum = 0;
  for (int i = 0; i < H; i++) {
    string ss;
    cin >> ss;
    for (int j = 0; j < W; j++) {
      if (ss[j] == '#') {
        s[i][j] = 1;
        sum++;
      }
    }
  }
  dumpv(s, H, W);
  deque<T> q;
  vector<vector<int>> used(H, vector<int>(W, INF));
  q.push_back(T(0, 0, 0));
  while (!q.empty()) {
    int x, y, len;
    tie(x, y, len) = q.front();
    q.pop_front();
    dump(x, y);
    if (used[y][x] <= len + 1)
      continue;
    used[y][x] = len;
    for (int i = 0; i < 4; i++) {
      int nx, ny;
      if (i == 0)
        nx = x - 1, ny = y;
      else if (i == 1)
        nx = x + 1, ny = y;
      else if (i == 2)
        nx = x, ny = y - 1;
      else
        nx = x, ny = y + 1;
      if (nx < 0 || W <= nx || ny < 0 || H <= ny)
        continue;
      if (s[ny][nx])
        continue;
      if (used[ny][nx] <= len + 1)
        continue;
      q.push_back(T(nx, ny, len + 1));
    }
  }
  dumpv(used, H, W);
  if (used[H - 1][W - 1] == INF) {
    cout << -1 << endl;
    return;
  }
  int ans = H * W - sum - (used[H - 1][W - 1] + 1);
  cout << ans << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>


using namespace std;
typedef long long ll;

int main(){
	int a,b;
	cin >> a >> b;
	if(a == 1 && b == 2) cout << 3;
	else if (a == 2 && b == 1) cout << 3;
	else if (a == 2 && b == 3 ) cout << 1;
	else if (a == 3 && b == 2) cout << 1;
	else if(a == 1 && b == 3) cout << 2;
	else if (a == 3 && b == 1) cout << 2;
}




Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque> 
using namespace std;

int main()
{
    // 整数の入力
    int A,B,C;
    cin >> A >> B >>C;
    if (A <= C && C<=B){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;

    int R, S, P;
    cin >> R >> S >> P;

    string T;
    cin >> T;

    string hand = "";
    for (int i = 0; i < K; i++) {
        hand += "a";
    }

    int score = 0;

    for (int i = 0; i < N; i++) {
        if (T[i] == 'r') {
            if (hand[i] != 'p') {
                hand += "p";
                score += P;
            } else {
                hand += "a";
            }
        } else if (T[i] == 'p') {
            if (hand[i] != 's') {
                hand += "s";
                score += S;
            } else {
                hand += "a";
            }
        } else {
            if (hand[i] != 'r') {
                hand += "r";
                score += R;
            } else {
                hand += "a";
            }
        }
    }

    cout << score << endl;

    return 0;
}


Measured memory_bytes: 3936
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#define ll long long

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<int> vec(N);

    for(int i = 0;i < N-1;i++){
        cin  >> vec[i];
    }

    ll ans = 0;

    for(int i = 0;i < N;i++){
        if(i == 0){
            ans += vec[0];
        }
        else if(i < N-1) {
            ans += min(vec[i],vec[i-1]);
        }
        else {
            ans += vec[i-1];
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int N; cin>>N;
    int a[N],b[N],c[N];
    rep(i, N) cin>>a[i]>>b[i]>>c[i];

    int dp[N][3];
    dp[0][0] = max(b[0], c[0]);
    dp[0][1] = max(a[0], c[0]);
    dp[0][2] = max(a[0], b[0]);
    for(int i=1; i<N; i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }

    cout << max(dp[N-1][2], max(dp[N-1][0], dp[N-1][1])) << endl;
}


Measured memory_bytes: 5948
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        var n = long.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();

        int c2 = 0;
        int c4 = 0;
        int c = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] % 4 == 0) c4++;
            else if (a[i] % 2 == 0) c2++;
            else c++;
        }

        string ans = "No";
        if (c2 == 0 && c4 + 1 >= c) ans ="Yes";
        if (c2 > 0 && c4 >= c) ans = "Yes";

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 22880
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool tris, dable;
int main(){
    int n, a, b, c, d, pang=0,  ping=0;
    string x, y;
    cin  >> n >> a >> b >> c >> d;
    cin >> y;
    a--; b--; c--; d--;
        
    ping = max(a, b);
    pang = min(c, d);

    for(int i=a; i<=c; i++){
        if(y[i]=='#' && y[i-1]=='#'){
            dable=true;
        }
    }
    for(int i=b; i<=d; i++){
        if(y[i]=='#' && y[i-1]=='#'){
            dable=true;
        }
    }

    if(dable==true){
        cout << "No" << endl;
        return 0;
    }
    
    if (c < d) tris = true;
    
    while(ping <= pang){
        if(y[ping]=='.' && y[ping-1]=='.' && y[ping+1]=='.'){
            tris = true;
        }
        ping++;
    }
    
    cout << (tris ? "Yes" : "No") << endl;
    return 0;
}

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

int main(){
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll p1 = max(x, y) * 2 * c;
    ll p2 = a * x + b * y;
    ll p3 = min(x, y) * 2 * c;
    if(x > y) p3 += (x - y) * a;
    else p3 += (y - x) * b;
    cout << min({p1, p2, p3}) << endl;
    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    string s;
    cin >> s;
    bool c_flg=false,f_flg=false;
    for (int i = 0; i < s.size(); i++) {
        if(s[i] == 'C'){
            c_flg = true;
        }
        if(c_flg == true && s[i] == 'F'){
            f_flg = true;
        }
    }
    if(c_flg && f_flg){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i, a, n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i, a, n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i, a, n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i, a, n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i, a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
//constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;

//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;
}

inline void init() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}

template<class T>
inline istream &operator>>(istream &input, vector<T> &v) {
    for (auto &elemnt : v)input >> elemnt;
    return input;
}

int main() {
    init();
    int m,f,b;
    cin >> m>> f>>b;
    if(m>=b){
        cout << 0 << endl;
        return 0;
    }else if((m+f)<b){
        cout <<"NA"<<endl;
        return 0;
    }else {
        cout << b - m << endl;
        return 0;
    }
}



Measured memory_bytes: 3160
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(v) (v).begin(),(v).end()
const ll MOD = 1e9 + 7;

int main() {
	int N, K;
	cin >> N >> K;
	if ((N - 1)*(N - 2) / 2 < K) {
		cout << -1 << endl;
		return 0;
	}
	queue<P> que;
	for (int i = 2; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			que.emplace(i, j);
		}
	}
	vector<P> edge;
	for (int i = 2; i <= N; i++) {
		edge.emplace_back(1, i);
	}
	int t = (N - 1)*(N - 2) / 2 - K;
	for (int i = 0; i < t; i++) {
		P p = que.front(); que.pop();
		edge.push_back(p);
	}
	cout << edge.size() << endl;
	for (int i = 0; i < edge.size(); i++) cout << edge[i].first << " " << edge[i].second << endl;
}


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

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i < (int)vec.size(); ++i) {
        os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
void dump_func() {
    cerr << "\n";
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
    cerr << head;
    if (sizeof...(Tail) == 0) {
        cerr << " ";
    } else {
        cerr << ", ";
    }
    dump_func(std::move(tail)...);
}
#define dump(...) cerr << "[" << to_string(__LINE__) << "]"        \
                       << "    " << string(#__VA_ARGS__) << " = ", \
                  dump_func(__VA_ARGS__)

using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<double>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PI = pair<int, int>;
using PL = pair<ll, ll>;
using VPI = vector<PI>;
using VPL = vector<PL>;
using VS = vector<string>;

#define ln '\n'
#define REP(t, n) for (int t = 0; t < (n); ++t)
#define FOR(t, a, b) for (int t = (a); t <= (b); ++t)
#define FORR(t, a, b) for (int t = (a); t >= (b); --t)
#define ALL(c) (c).begin(), (c).end()
#define CAUTO const auto&

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    // <to, cost>
    vector<VPI> edge(N);
    REP(i, N - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        edge[u - 1].emplace_back(make_pair(v - 1, w));
        edge[v - 1].emplace_back(make_pair(u - 1, w));
    }

    VI ans(N);
    REP(i, N)
    ans[i] = -1;
    ans[0] = 0;
    VI checked = {0};
    while (!checked.empty()) {
        int checking = checked.back();
        checked.pop_back();
        for (auto& e : edge[checking]) {
            if (ans[e.first] == -1) {
                ans[e.first] = ans[checking] + e.second;
                checked.emplace_back(e.first);
            }
        }
    }
    REP(i, N) {
        cout << (ans[i] % 2 ? 1 : 0) << ln;
    }

    return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  string S1, S2;
  cin >> S1;
  cin >> S2;

  ll dp = 0, nextDP = 0;
  bool two = false;

  REP(i, N) {
    if (i == 0) {
      if (S1[i] == S1[i + 1]) {
        nextDP = 6;
        two = true;
        i++;
      } else {
        nextDP = 3;
      }
    } else if (i == N - 1) {
      if (two) {
        nextDP = dp;
      } else {
        nextDP = dp * 2;
      }

    } else if (S1[i] == S1[i + 1]) {
      if (two) {
        nextDP = dp * 3;
      } else {
        nextDP = dp * 2;
        two = true;
      }
      i++;
    } else {
      if (two) {
        nextDP = dp;
      } else {
        nextDP = dp * 2;
      }
      two = false;
    }
    nextDP %= MOD;
    dp = nextDP;
  }
  cout << dp;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    long long aa[a];
    long long sum=0;
    for(long long i=0; i<a; i++)
    {
        cin>>aa[i];

    }
    sort(aa,aa+a);

    if(b>=a)
        cout<<"0"<<endl;
    else
    {
        for(long long i=0; i<a-b; i++)
        {
            sum+=aa[i];
        }
        cout<<sum<<endl;
    }

}



Measured memory_bytes: 1792
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <functional>
 
using namespace std;

using t = long long;

void bfs(t k) {
    t cnt=0;
    queue<t> q;
    for (int i = 1; i <= 9; ++i)
        q.push(i);
    while (!q.empty()) {
        t v = q.front();
        q.pop();
        ++cnt;
        if (cnt==k){
            cout<<v;
            exit(0);
        }
        int ld = v%10;
        if (ld == 0) {
            q.push(v*10+0);
            q.push(v*10+1);
        } else if (ld == 9) {
            q.push(v*10+8);
            q.push(v*10+9);
        } else {
            q.push(v*10+ld-1);
            q.push(v*10+ld);
            q.push(v*10+ld+1);
        }
    }
} 

int main() {
    int k;
    cin >> k;
    bfs(k);
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();


		// 最大
		int max = Math.min(a, b);

		// 最小
		int min = a+b-n;
		if(min < 0) {
			min = 0;
		}


		System.out.println(max + " " + min);


	}

}


Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>
#include <vector>
#define N 8000
using namespace std;

int x, y, cnt, z;
int d[4005][16005];
int e[4005][N * 2];
string s;
vector<int> v[2];

bool f(int p) {
    int i;
    d[0][v[0][0]+N] = 1;
    for(i = 1; i < v[0].size(); i++)
    {
        int t = v[0][i];
        for(int j = 0; j <= 2 * N; j++)
        {
            if(j >= t && d[i-1][j-t]) d[i][j] = 1;
            if(j + t <= 2 * N && d[i-1][j+t]) d[i][j] = 1;
        }
    }
    return d[i-1][p + N];
}

bool g(int p) {
    int i;
    e[0][v[1][0] + N] = 1;
    for(int i = 1; i < v[1].size(); i++)
    {
        int k = v[1][i];
        for(int j = 0; j <= 2 * N; j++)
        {
            if(j >= k && e[i - 1][j - k]) e[i][j] = 1;
            if(j + k <= 2 * N && e[i - 1][j + k]) e[i][j] = 1;
        }
    }
    return e[v[1].size() - 1][p + N];
}

int main()
{
    int i;
    cin>>s>>x>>y;
    s += 'T';
    v[1].push_back(0);
    for(int i = 0; s[i]; i++) {
        if(s[i]=='F') cnt++;
        else {
            v[z].push_back(cnt);
            z = !z;
            cnt = 0;
        }
    }
    if(f(x) & g(y)) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 498048
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long
#define pii pair<int,int>
#define x first
#define y second

const int N=2e5+5;
int n,d,k;
long long tr[N],ans;
pii a[N];

#define lowbit(x) (x&(-x))

void up(int x,int v){
	while(x<=n){
		tr[x]+=v;
		x+=lowbit(x);
	}
}

long long que(int x){
	int res=0;
	while(x){
		res+=tr[x];
		x-=lowbit(x);
	}
	return res;
}

signed main(){
	read(n);read(d);read(k);d<<=1;
	for(int i=1;i<=n;i++) read(a[i].x),read(a[i].y);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		long long path=que(i);
		if(1ll*path*k>=a[i].y) continue;
		int ned=(a[i].y-path*k-1)/k+1;
		ans+=ned;
		int l=i,r=n,lim=i;
		while(l<=r){
			int mid=l+r>>1;
			if(a[i].x+d>=a[mid].x) l=mid+1,lim=mid;
			else r=mid-1;
		}
//		printf("%d %d %d %d\n",i,lim,ned,path);
		up(i,ned);up(lim+1,-ned);
	}
	write(ans);
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
bool use[3];
int main()
{
	int d[3];
	int n,m;
	cin>>n>>m;
	int s,c;
	bool flag=true;
	for(int i=0;i<m;i++)
	{                                                
		cin>>s>>c;
		s--;
		if(n!=1 and s==0 and c==0)
		{
			flag=false;
			break;
		}
		else if(s>n)
		{
			flag=false;
			break;
		}
		else if(use[s] and c!=d[s])
		{
			flag=false;
			break;
		}
		else
		{
			d[s]=c;
			use[s]=true;
		}
	}
	if(n!=1 and !use[0]) 
	{
		d[0]=1;
		for(int i=1;i<n;i++)
		{
			if(!use[i]) d[i]=0;
		}
	}
	else
	{
		for(int i=0;i<n;i++)
	{
		
		if(!use[i])
		d[i]=0;
	}
	}
	
	if(!flag) cout<<-1<<endl;
	else 
	{
		for(int i=0;i<n;i++)
		{
			cout<<d[i];
		}
		cout<<endl;
	}
	//cout<<use[2]<<endl;
	return 0;
}

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

int main() {
    int n,ans=0;
    cin>>n;
    vector<int> p(n);

    rep(i,n) cin>>p[i];

    int mini = 9999999;

    rep(i,n) {
        mini = min(mini, p[i]);
        if (mini == p[i]) ans++;
    }

    cout<<ans<<endl;
}


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

vector<int> getFail(const string& s) {
	vector<int> fail = {-1};
	for (int i = 0; i < int(s.size()); i++) {
		int cur = fail.back();
		while (cur != -1 && s[i] != s[cur]) {
			cur = fail[cur];
		}
		fail.push_back(cur + 1);
	}
	return fail;
}

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

	string s; cin >> s;
	int N = int(s.size());

	vector<int> fail = getFail(s);
	vector<int> rfail = getFail(string(s.rbegin(), s.rend()));

//	for (int v : fail) { cerr << v << ' '; } cerr << endl;
//	for (int v : rfail) { cerr << v << ' '; } cerr << endl;

	if (fail.back() == N-1) {
		cout << N << '\n';
		cout << 1 << '\n';
		exit(0);
	}

	// whether s[0...i) is cyclic
	auto isCyclic = [](const vector<int>& f, int i) -> bool {
		return i > 1 && f[i] != 0 && i % (i - f[i]) == 0;
	};

	if (!isCyclic(fail, N)) {
		cout << 1 << '\n';
		cout << 1 << '\n';
		exit(0);
	}

	int ways = 0;
	for (int i = 1; i < N; i++) {
		if (!isCyclic(fail, i) && !isCyclic(rfail, N - i)) {
			ways++;
		}
	}

	cout << 2 << '\n';
	cout << ways << '\n';

	return 0;
}


Measured memory_bytes: 6292
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int n; cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	vector<int> dp(n);
	int sum = 0;
	for(int i = n-1; i>=0; i--){
		sum = 0;
		for(int j = (i+1)*2-1; j<n; j+=(i+1))
			sum+=dp[j];
		dp[i] = (sum%2)==a[i] ? 0 : 1;
	}
	out(sum+dp[0]);
	rep(i,n){
		if(dp[i])cout << i+1 << " ";
	}
	cout << endl;
}




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

const int MAX = 510000;
 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){
     if (n < k) return 0;
     if (n < 0 || k < 0) return 0;
     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
 }
 
  long long modpow(long long a, long long n) {
      long long res = 1;
      while (n > 0) {
          if (n & 1) res = res * a % MOD;
          a = a * a % MOD;
          n >>= 1;
      }
      return res;
  }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,x,y;
    std::cin >> n>>x>>y;
    x--;
    y--;

    for (int i = 1; i < n; i++) {
        ll ans = 0;
        for (int j = 0; j < n-1; j++) {
            if(i+j>=n)continue;
            if(i+j>=y+(i-abs(j-x)-1)&&i+j<=n-1){
                ans++;
                continue;
            }
            if((i-abs(j-x)-1)>=0){
                set<ll> s;
                if(i+j)
                if(i+j<=n-1&&i+j<=y-(i-abs(j-x)-1))s.insert(i+j);
                if(y+(i-abs(j-x)-1)<=n-1&&y+(i-abs(j-x)-1)>=i+j)s.insert(y+(i-abs(j-x)-1));
                if(y-(i-abs(j-x)-1)>=0  &&y-(i-abs(j-x)-1)>=i+j)s.insert(y-(i-abs(j-x)-1));
                
                // for (auto e : s) {
                //     std::cout << e<<" ";
                // }
                // std::cout <<"dd"<<" "<<i<<" "<<j <<std::endl;
                ans += s.size();
                // std::cout << i<<" "<<j<<" "<<ans << std::endl;
            }else{
                if(i+j<=n-1){
                    ans++;
                }
            }
            // std::cout << ans << std::endl;
        }
        std::cout << ans << std::endl;
        // std::cout  << std::endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin>>p[i];
    }
    int a=0;
    for (int i = 0; i < n-2; i++)
    {
        if (p[i+1]!=max({p[i],p[i+1],p[i+2]}) and p[i+1]!=min({p[i],p[i+1],p[i+2]}))
        {
            a++;
        }
        
    }
    cout<<a<<endl;

    
    
    
    

    return 0;
}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    ll N; cin >>N;
    vector<ll> a(N);
    int c2 = 0;
    int c4 = 0;
    rep(i, N) {
        cin >> a[i];
        if (a[i] % 4 == 0) c4++;
        else if (a[i] % 2 == 0) c2++;
    }

    Yes(N/2 <= c4 || N-c4*2 <= c2);
}


Measured memory_bytes: 1024
#include <iostream>
#include<map>
#include<vector>
#include<string>
#include <climits>
#include<set>
#include<cmath>
#include<bitset>
using namespace std;
#define ll long long
int main() {
  ll d,t,s;
  cin>>d>>t>>s;
  if(d<=(t*s))
  {
      cout<<"Yes"<<endl;
  }
  else{
      cout<<"No"<<endl;
  }
    return 0;
}


Measured memory_bytes: 3120
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CurryMaking solver = new CurryMaking();
        solver.solve(1, in, out);
        out.close();
    }

    static class CurryMaking {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int r0 = in.nextInt(), w0 = in.nextInt(), c = in.nextInt(), r = in.nextInt();
            while (r0 != 0 && w0 != 0 && c != 0 && r != 0) {
                int ans = 0;
                while (r0 < c * w0) {
                    r0 += r;
                    ans++;
                }
                out.println(ans);

                r0 = in.nextInt();
                w0 = in.nextInt();
                c = in.nextInt();
                r = in.nextInt();
            }
        }

    }
}




Measured memory_bytes: 26492
#include <iostream>
#include <algorithm>
#include <cstring>
#include <climits>
using namespace std;

int n, m;
int hp[102];
int mp[102], isAll[102], dam[102];
int minMp[100002], minAllMp[100002];

int main(){
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      cin >> hp[i];
    }
    cin >> m;
    for(int i = 0; i < m; i++){
      string s;
      cin >> s >> mp[i] >> s >> dam[i];
      isAll[i] = (s == "All");
    }

    fill(minMp, minMp + 100002, INT_MAX);
    fill(minAllMp, minAllMp + 100002, INT_MAX);
    minMp[0] = 0;
    minAllMp[0] = 0;

    for(int i = 0; i < 100000; i++){
      if(minMp[i] != INT_MAX){
        for(int j = 0; j < m; j++){
          if(isAll[j]) continue;
          int ni = min(100000, i + dam[j]);
          minMp[ni] = min(minMp[ni], minMp[i] + mp[j]);
        }
      }

      if(minAllMp[i] != INT_MAX){
        for(int j = 0; j < m; j++){
          if(!isAll[j]) continue;
          int ni = min(100000, i + dam[j]);
          minAllMp[ni] = min(minAllMp[ni], minAllMp[i] + mp[j]);
        }
      }
    }

    for(int i = 99999; i >= 0; i--){
      minMp[i] = min(minMp[i], minMp[i + 1]);
      minAllMp[i] = min(minAllMp[i], minAllMp[i + 1]);
    }

    int ans = INT_MAX;

    for(int i = 0; i <= 100000; i++){
      if(minAllMp[i] == INT_MAX) continue;

      int sum = minAllMp[i];

      for(int j = 0; j < n; j++){
        int remHp = max(0, hp[j] - i);

        if(minMp[remHp] == INT_MAX){
          sum = INT_MAX;
          break;
        }

        sum += minMp[remHp];
      }

      ans = min(ans, sum);
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 2000
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	int arr[3];
	arr[0] = a + b;
	arr[1] = a - b;
	arr[2] = a * b;
	int max = arr[0]; 
	int i;
	for(i=1; i<3; i++){
  		if(arr[i] > max)
          max = arr[i];}
  cout << max;}

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

using namespace std;

char str[123456];

int main(){
    scanf("%s",str);
    int l=0,r=strlen(str)-1;
    int ans=0;
    while(l<r){
        if(str[l] == str[r]){
            l++;
            r--;
        } else if(str[l]=='x' && str[r] != 'x'){
            l++;
            ans++;
        } else if(str[l]!='x' && str[r] == 'x'){
            r--;
            ans++;
        } else {
            puts("-1");
            return 0;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    cin >> n;
    vector<char> c(n);
    for (int i = 0; i < n; i++) cin >> c[i];
    int ans = 0;
    int l = 0;
    int r = n - 1;
    while (true) {
        while (c[l] == 'R') l++;
        while (c[r] == 'W') r--;
        if (!(l < r)) break;
        ans += 1;
        l++;
        r--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
//在 POJ 和小白菜中，该库禁用！
//在 USACO中请用文件。
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#define inf 1000000001

using namespace std;
typedef long long ll;

struct e{
	int to,cst;
	e(int x=0,int y=0){
		to=x;cst=y;
	}
};
vector <e> adj[100005];
bool vis[100005],b;
int n,m,l,r,d,dis[100005];
void dfs(int x,int cur_dis){
	vis[x] = true;
	dis[x] = cur_dis;
//	bool f = true;
	for(int i=0;i<adj[x].size();i++){
		if(!vis[adj[x][i].to])
		dfs(adj[x][i].to,cur_dis+adj[x][i].cst);
		else{
			int ndis = cur_dis+adj[x][i].cst;
			if(ndis != dis[adj[x][i].to]) b = 0;
		}
	}
	return;
}
int main(){
//	ios::sync_with_stdio(false);
//	cin.tie(0);
	memset(dis,-1,sizeof(dis));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&l,&r,&d);
		adj[l].push_back(e(r,d));
		adj[r].push_back(e(l,-d));
	}

	b = true;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			dfs(i,0);
		}
		if(!b){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
  return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n>>t;
      if(n>=10)cout<<t;
      else cout<<t+100*(10-n);    
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;
use std::collections::HashSet;

fn nCr(n: i64, r: i64) -> i64 {
    let mut ans = 1;
    for i in r + 1..n + 1 {
        ans *= i;
    }

    for i in 1..r + 1 {
        ans /= i;
    }
    return ans;
}

use std::cmp::{max, min};
fn main() {
    let n: i64 = read();
    let mut ans = 0;
    let mut dist_top: HashMap<i64, i64> = HashMap::new();

    for i in 1..n + 1 {
        let mut num = i;
        let mut dist: HashMap<i64, i64> = HashMap::new();
        let prime_num = vec![
            2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83,
            89, 97,
        ];
        for j in prime_num {
            if j <= i {
                loop {
                    if num % j != 0 {
                        break;
                    }
                    if dist.contains_key(&j) {
                        let current = dist.get_mut(&j).unwrap();
                        *current += 1;
                    } else {
                        dist.insert(j, 1);
                    }
                    num = num / j;
                }
            }
        }

        for (k, v) in dist.iter() {
            if dist_top.contains_key(&k) {
                let current = dist_top.get_mut(&k).unwrap();
                *current += *v;
            } else {
                dist_top.insert(*k, *v);
            }
        }
    }

    // println!("{:?}", dist_top);
    let mut a = vec![];
    for (k, v) in dist_top.iter() {
        a.push(v);
    }

    let cnt_74 = a.iter().filter(|&x| **x >= 74).count();
    let cnt_24 = a.iter().filter(|&x| **x >= 24).count();
    let cnt_2 = a.iter().filter(|&x| **x >= 2).count();
    let cnt_4 = a.iter().filter(|&x| **x >= 4).count();
    let cnt_14 = a.iter().filter(|&x| **x >= 14).count();

    // 74
    ans += cnt_74;

    // 24 * 2
    ans += cnt_24 * (cnt_2 - 1);

    // 14 * 4
    ans += cnt_14 * (cnt_4 - 1);

    // 2 * 4 * 4
    ans += cnt_4 * (cnt_4 - 1) / 2 * (cnt_2 - 2);

    println!("{}", ans)
}


Measured memory_bytes: 4352
#include<stdio.h>
int main()
{
int i=0;
int sum=0;
char ch[1001]={0};

while(1)
{
	i=0;
scanf("%s",ch);
if(ch[0]-'0'==0)break;
sum=0;
while(1)
{
if(ch[i]=='\0')break;
sum+=(ch[i]-'0');
i++;
}
printf("%d\n",sum);
}
return 0;
}

Measured memory_bytes: 964
#include<iostream>
#include<string>
using namespace std;
int main(){
  int a[]={1,3,5,7,9,11,15,17,19,21,23,25};
  int n;
  cin >>n;
  cin.ignore();
  while(n--){
    string s,t;
    getline(cin,s);
    t = s;
    for(int i=0; i<12; i++){
      for(int j=0; j<26; j++){
	for(int k=0; k<s.size(); k++){
	  if(s[k]>='a' && s[k]<='z') t[k] = ((s[k]-'a')*a[i]+j)%26+'a';
	  else t[k] = s[k];
	}
	string::size_type pos_this = t.find("this");
	string::size_type pos_that = t.find("that");
	if(pos_this!=string::npos) cout <<t<<endl;
	else if(pos_that!=string::npos) cout <<t<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1216
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

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

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

int solve() {
	ll n , m;
	cin >> n >> m;
	if (n == 1 && m == 1) {
		cout << 1LL << endl;
	}
	else if (n != 1 && m == 1) {
		cout << n - 2LL << endl;
	}
	else if (n == 1 && m != 1) {
		cout << m - 2LL << endl;
	}
	else {
		cout << (m - 2LL) * (n - 2LL) << endl;
	}

	return 0;
}

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

	solve();

	return 0;
}


Measured memory_bytes: 256
import numpy as np

def main():
    rule = {1:[0, 10], 2:[10, 100], 3:[100, 1000]}
    args = input().rstrip().split(' ')
    N, M = int(args[0]), int(args[1])
    query = []
    for i in range(M):
        args = input().rstrip().split(' ')
        query.append([int(args[0]), int(args[1])])
        
    global_flag = False
    for i in range(rule[N][0], rule[N][1]):
        if(N==1):
            val = np.array([i, -1,-1, -1, -1])
        elif(N==2):
            val = np.array([int(i/10), i%10, -1, -1, -1])
        else:
            val = np.array([int(i/100), int(i%100/10), i%10, -1, -1])
        
        flag = True
        for q in query:
            if(val[q[0]-1] != q[1]):
                flag = False
                break
        if(flag == True):
            print(i)
            global_flag = True
            break
    if(global_flag == False):
        print('-1')
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 12496
# -*- coding: utf-8 -*-
import heapq
import sys
from collections import defaultdict

input = sys.stdin.buffer.readline
INF = 2**62-1


def read_int_n():
    return list(map(int, input().split()))


def read_str_n():
    return list(map(str, input().split()))


def Dijkstra(g, s):
    d = defaultdict(lambda: INF)
    d[s] = 0
    q = []
    heapq.heappush(q, (d[s], s))

    prev = {}
    done = set()
    while q:
        c, u = heapq.heappop(q)
        if u in done:
            continue
        done.add(u)
        for v in g[u]:
            alt = g[u][v] + d[u]
            if d[v] > alt:
                d[v] = alt
                prev[v] = u
                heapq.heappush(q, (d[v], v))
    return d

def slv(N, M, S, UVAB, CD):
    g = defaultdict(dict)
    V = {}
    for u, v, a, b in UVAB:
        g[u][v] = (a, b)
        g[v][u] = (a, b)

    for i, (c, d) in enumerate(CD, 1):
        V[i] = (c, d)

    MA = (N-1)*max(a for u, v, a, b in UVAB)
    S = min(S, MA)
    d = [[INF] * (MA+1) for _ in range(N+1)]
    d[1][S] = 0
    q = []

    def p(q, u, m, alt):
        if m >= 0 and d[u][m] > alt:
            d[u][m] = alt
            heapq.heappush(q, (d[u][m], (u, m)))

    heapq.heappush(q, (d[1][S], (1, S)))
    while q:
        c, (u, s) = heapq.heappop(q)
        if d[u][s] < c:
            continue
        c, dd = V[u]
        if s != MA:
            m = min(MA, s+c)
            alt = d[u][s] + dd
            p(q, u, m, alt)

        for v in g[u]:
            a, b = g[u][v]
            alt = b + d[u][s]
            m = s - a
            p(q, v, m, alt)

    for i in range(2, N+1):
        print(min(d[i]))


def main():
    N, M, S = read_int_n()
    UVAB = [read_int_n() for _ in range(M)]
    CD = [read_int_n() for _ in range(N)]
    (slv(N, M, S, UVAB, CD))


if __name__ == '__main__':
    main()


Measured memory_bytes: 94364
#include <iostream>
#include <string>

using namespace std;

int main(){
  string S, T;
  cin >> S >> T;

  int fit_index = -1;

  for(int i = S.length() - T.length(); 0 <= i; --i){
    if(0 <= fit_index) break;
    for(int j = 0; j < T.length(); ++j){
      if(S[i+j] != '?' && S[i+j] != T[j]) break;
      if(j == T.length()-1) fit_index = i;
    }
  }

  if(fit_index < 0){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for(int i = 0; i < S.length(); ++i){
    if(fit_index <= i && i <= fit_index+T.length()-1){
      S[i] = T[i-fit_index];
      continue;
    }
    if(S[i] == '?') S[i] = 'a';
  }

  cout << S << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << max(0, min(B, D) - max(A, C)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;

int main(){
    int H, W;
    while(cin >> H >> W){
        vector<string> str(H);
        REP(i, H) cin >> str[i];

        const int MAXS = 1 << W;

        int bp[MAXS];
        for(int s = 0; s < MAXS; s++) bp[s] = __builtin_popcount(s);
        
        int dp[2][MAXS];
        int* curr = dp[0], *next = dp[1];
        for(int s = 0; s < MAXS; s++) curr[s] = -1;
        curr[0] = 0;

        for(int y = 0; y < H; y++){
            for(int x = 0; x < W; x++){
                for(int s = 0; s < MAXS; s++) next[s] = -1;
                for(int s = 0; s < MAXS; s++) if(curr[s] >= 0){
                    int cu = bp[s >> x]; // count of upper
                    int cl = bp[s & ((1 << x) - 1)]; // count of lower

                    if(cl + (W - 1 - x) >= str[y].size())
                        next[s & ~(1 << x)] = max(next[s & ~(1 << x)], curr[s]); // path through

                    if(cl == str[y].size()) continue;

                    int add = 0;
                    if(cl > 0 && str[y][cl] == str[y][cl - 1] && (s >> (x - 1) & 1)){
                        add += 2;
                    }
                    if(y > 0 && (s >> x & 1) && str[y - 1][str[y - 1].size() - cu] == str[y][cl]){
                        add += 2;
                    }
                    next[s | (1 << x)] = max(next[s | (1 << x)], curr[s] + add);
                }
                swap(curr, next);
            }
        }

        int ans = 0;
        for(int s = 0; s < MAXS; s++) ans = max(ans, curr[s]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1984
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



int main() {
    ll n;
    cin >> n;
    
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
        a[i]--;
    }
    
    ll ans = 0;
    REP(i, n){
        if(a[a[i]] == i)ans++;
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 1024
import sys
from itertools import zip_longest
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        l = l[0:n]
        break
print(sum(list(map(lambda x: x[1] if x[0] < x[1] else x[0], zip_longest(a,l,fillvalue=0)))))


Measured memory_bytes: 75816