akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int p=sc.nextInt();
		int q=sc.nextInt();
		int r=sc.nextInt();
		if(p>r && p>q)
			System.out.print(q+r);
		else if(r>q)
			System.out.print(p+q);
		else
			System.out.print(p+r);
	}
}

Measured memory_bytes: 24020
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


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

		cout << (N - 2)*(M - 2) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
nm = input().split(" ");
n = int(nm[0]);
m = int(nm[1]);
mod = 10**9+7
if n - m == 1 or m - n == 1:
	ansn = 1;
	for i in range(n) :
		ansn = (ansn % mod)*((n-i) % mod);
		ansm = 1;
	for j in range(m) :
	 	ansm = (ansm % mod)*((m-j) % mod);
	print((ansn*ansm) % mod);
elif n == m :
	ansn = 1;
	for i in range(n) :
		ansn = (ansn % mod)*((n-i) % mod);
		ansm = 1;
	for j in range(m) :
  		ansm = (ansm % mod)*((m-j) % mod);
	print((ansn*ansm*2) % mod);
else :
	print(0);

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int M;
  ll K;
  cin >> M >> K;
  if (M == 1) {
    if (K == 0) {
      cout << "0 0 1 1" << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }

  
  if (0 <= K && K < (1 << M)) {
    cout << K << " ";
    for (int i = (1 << M) - 1; i >= 0; i--) {
      if (i == K) {
        continue;
      }
      cout << i << " ";
    }
    cout << K << " ";
    for (int i = 0; i <= (1 << M) - 1; i++) {
      if (i == K) {
        continue;
      }
      cout << i << " ";
    }
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];

    map<lint, lint> m;
    rep(i, n) m[a[i]]++;

    lint res = 0;
    for (auto&& p : m) {
        res += p.second * (p.second - 1) / 2;
    }

    rep(i, n) {
        lint pat = m[a[i]];
        lint ress = res;
        ress -= pat * (pat - 1) / 2;
        ress += (pat - 1) * (pat - 2) / 2;
        cout << ress << endl;
    }
    return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<int> a(3 * n);
    rep(i, 0, 3 * n){
        cin >> a[i];
    }
    sort(all(a));
    reverse(all(a));
    int ans = 0;
    for(int i = 1; i < 2 * n ; i += 2){
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int INF = 100000000;
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h, vector<char>(w));
    int whiteCount = 0;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            char a;
            cin >> a;
            s[i][j] = a;
            if(a == '.') whiteCount++;
        }
    }
    vector<vector<int>> d(h, vector<int>(w));
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            d[i][j] = INF;
        }
    }
    vector<int> dx = {1, 0, -1, 0};
    vector<int> dy = {0, -1, 0, 1};


    using P = pair<int, int>;
    queue<P> que;
    que.push(P(0, 0));
    d[0][0] = 1;

    while(!que.empty())
    {
        P p = que.front();
        que.pop();
        int x = p.first;
        int y = p.second;
        if(x == h-1 && y == w-1) break;

        for(int i = 0; i < 4; i++)
        {
            int sx = x + dx[i];
            int sy = y + dy[i];
            if(sx >= 0 && sx <= h-1 && sy >= 0 && sy <= w-1 && s[sx][sy] != '#' && d[sx][sy] == INF)
            {
                que.push(P(sx, sy));
                d[sx][sy] = d[x][y] + 1;
            }
        }
    }
    if(d[h-1][w-1] != INF)
        cout << whiteCount - d[h-1][w-1] << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 256
using System;


class Program
{
    static void Main(string[] args)

    {
        string line;

        while (true)
        {
            line = Console.ReadLine();
            int judge = int.Parse(line);
            if (judge == 0) break;


            int[] score = new int[judge];
            int sum = 0;

            for (int i = 0; i < judge; i++)
            {
                score[i] = int.Parse(Console.ReadLine());
                sum += score[i];
            }


            int max, min;
            min = max = score[0];
            for(int i = 0; i < judge; i++)
            {
                if (score[i] < min) min = score[i];
                if (score[i] > max) max = score[i];
            }

            int average = (sum - max - min) / (judge - 2);
            Console.WriteLine(average);

          
        }
    }
}

Measured memory_bytes: 9120
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
 
typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;


int main()
{
 
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI t(n), v(n);
	rep(i,n) cin >> t[i];
	rep(i,n) cin >> v[i];
	
	vector<double> dp(105, -1);
	dp[0] =0;
	rep(i,n) rep(j, t[i]){
		vector<double> np(105, -1);
		rep(k, v[i]+1) if(dp[k] >=0){
			np[k] = max(np[k], dp[k] +k);
			if(k < v[i]){
				np[k]   = max(np[k], dp[k]+k+0.25);
				np[k+1] = max(np[k+1], dp[k]+k+0.5);
			}
			if(k>0) np[k-1] = max(np[k-1], dp[k]+k-0.5);
		
		}
			swap(dp, np);
	}
			printf("%.10f\n", dp[0]);

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("avx,avx2,fma,sse,sse2")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;

#define N 200007

typedef tree<int, null_type, less<int>,rb_tree_tag,
tree_order_statistics_node_update> new_data;
int main()
{
    ll n;
    cin>>n;
    vector<ll>a(n);
    for(auto &i:a)cin>>i;
    ll k=a[0],ans=0;
    for(ll i=1;i<n;i++)
    {
        ans+=max(0ll,k-a[i]);
        k=max(k,a[i]);
    }
    cout<<ans<<endl;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vector<P> ab(m);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    ab[i] = make_pair(b, a);
  }
  sort(ab.begin(), ab.end());
  int ans = 1, end = ab[0].first;
  rep(i, m){
    if (end <= ab[i].second){
      ans++;
      end = ab[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4020
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = 0

for i in range(N):
  
  if B[i]>A[i]:
    cnt+=A[i]
    r = B[i]-A[i]
  else:
    cnt+=B[i]
    r = 0
  
  if r>A[i+1]:
    cnt+=A[i+1]
    A[i+1]=0
  else:
    cnt+=r
    A[i+1]-=r

print(cnt)

Measured memory_bytes: 24128
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890123456789LL
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

struct trie {
	vector< vector<int> > son;
	vector<int> SZ, ends;

	trie() {
		son.push_back(vector<int>(26,-1));
		SZ.resize(1);
		ends.resize(1,-1);
	}

	void put(string &S, int id) {
		int akt =0;
		for(int i =0; i < (int)S.length(); i++) {
			if(son[akt][S[i]-'a'] == -1) {
				son[akt][S[i]-'a'] =son.size();
				son.push_back(vector<int>(26,-1));
				SZ.push_back(0);
				ends.push_back(-1);
			}
			akt =son[akt][S[i]-'a'];
		}
		ends[akt] =id;
	}

	void DFS(int R) {
		SZ[R] =(ends[R] != -1);
		for(int i =0; i < 26; i++) if(son[R][i] != -1) {
			DFS(son[R][i]);
			SZ[R] +=SZ[son[R][i]];
		}
	}

	vector< vector<int> > sum;
	int sum0;

	void solve(int R, auto &Qs, auto &P, auto &ans) {
		if(ends[R] != -1) ALL_THE(Qs[ends[R]],it) {
			for(int i =0; i < 26; i++) for(int j =0; j < i; j++)
				ans[*it] +=sum[P[*it][i]-'a'][P[*it][j]-'a'];
			ans[*it] +=sum0;
		}

		if(ends[R] != -1) sum0++;
		for(int i =0; i < 26; i++) if(son[R][i] != -1) {
			for(int j =0; j < 26; j++) if(son[R][j] != -1 && i != j)
				sum[i][j] +=SZ[son[R][j]];
			solve(son[R][i],Qs,P,ans);
			for(int j =0; j < 26; j++) if(son[R][j] != -1 && i != j)
				sum[i][j] -=SZ[son[R][j]];
		}
		if(ends[R] != -1) sum0--;
	}
};

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	trie T;
	for(int i =0; i < N; i++) {
		string S;
		cin >> S;
		T.put(S,i);
	}
	T.DFS(0);

	int Q;
	cin >> Q;
	vector<string> P(Q);
	vector< vector<int> > Qs(N);
	for(int i =0; i < Q; i++) {
		int k;
		cin >> k >> P[i];
		Qs[k-1].push_back(i);
	}
	vector<int> ans(Q,1);

	T.sum =vector< vector<int> >(26,vector<int>(26,0));
	T.sum0 =0;
	T.solve(0,Qs,P,ans);

	for(int i =0; i < Q; i++) cout << ans[i] << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 97152
#include <iostream>
#define MAX 111
using namespace std;

int main() {
    static int m, n;
    static char a[MAX][MAX];
    static bool row[MAX], col[MAX];
    cin >> m >> n;
    for (int i = 0; i < m; ++i)
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
            if (a[i][j] == '#')
                row[i] = true, col[j] = true;
        }
    for (int i = 0; i < m; ++i) {
        if (row[i]) {
            for (int j = 0; j < n; ++j)
                if (col[j])
                    cout << a[i][j];
            cout << endl;
        }
    }
    
    return 0;
}

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

int main(){
  int H,N;
  cin >> H >> N;
  vector<int> A(N);
  int i,attack;
  attack=0;
  for(i=0;i<N;i++){
    cin >> A.at(i);
    attack=attack+A.at(i);
  }
  
  if(attack>=H){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  string n;
  cin >> n;
  rep(i, n.size()){
    if(n[i] == '7'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3128
## AABB
## ABBA
## ABAB

S = input().strip()
first_char = ['', 0]
second_char = ['', 0]
counter = 0
ans = True
for c in S:
    if counter == 0:
        first_char[0] = c
        first_char[1] += 1
    
    if counter == 1:
        if c != first_char[0]:
            second_char[0] = c
            second_char[1] += 1
        else:
            first_char[1] += 1
            
    if counter >1:
        if second_char[0] == '':
            second_char[0] = c
            
        if(first_char[0] != c and second_char[0] != c):
            ans = False
            break
        if c == first_char[0]:
            first_char[1] += 1
            if first_char[1] > 2:
                ans = False
                break
                
        if c == second_char[0]:
            second_char[1] += 1
            if second_char[1] > 2:
                ans = False
                break
    counter += 1

if ans:
    print('Yes')
else:
    print('No')
        

Measured memory_bytes: 3064
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int n, k;
    cin >> n >> k;
    
    vector<int> v(n);
    for (auto &x : v) cin >> x;
    
    vector<int> dp(n, INF);
    dp[0] = 0, dp[1] = abs(v[1] - v[0]);
    for (int i = 2; i < n; ++i) {
        for (int j = 1; j <= min(i, k); ++j) {
            dp[i] = min(dp[i], dp[i-j] + abs(v[i] - v[i-j]));
        }
    }
    
    cout << dp[n - 1] << "\n";
    
    return 0;
}

Measured memory_bytes: 4780
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;


int n;
pair<int, int> a[55];
int dx, dy;
bool used[55];


void dfs(int x) {
    used[x] = true;
    for (int i = 1; i <= n; ++i) if (used[i] == false) {
        if ((a[i].first - a[x].first == dx && a[i].second - a[x].second == dy) || (a[x].first - a[i].first == dx && a[x].second - a[i].second == dy)) dfs(i);
    }
    return;
}

int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
    //freopen("/Users/danya.smelskiy/Documents/Danya/Danya/output.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    int ans = n;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            dx = a[i].first - a[j].first;
            dy = a[i].second - a[j].second;
            for (int k = 1; k <= n; ++k) used[k] = false;
            int cur = 0;
            for (int k = 1; k <= n; ++k) if (!used[k]) dfs(k), ++cur;
            ans = min(ans, cur);
        }
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 256
N = int(input())
p = list(map(float, input().split()))

# i-1 まで見たときに表が j 枚出る確率
dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1, N+1):
    for j in range(N+1):
        dp[i][j] += (1-p[i-1])*dp[i-1][j]
        if j >= 1:
            dp[i][j] += p[i-1]*dp[i-1][j-1]

print(sum([dp[N][N-j] for j in range((N+1)//2)]))

Measured memory_bytes: 252168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int a, b, c; cin >> a >> b >> c;
    if (c >= a && c <= b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 200013
#define INF 1000000000000000000LL
#define MOD 1000000007LL
#define IINF 1000000000
#define mp make_pair
#define pb push_back
#define remove pop
#define all(x) x.begin(), x.end()

char values[MAXN];

int dp[MAXN][2];
pair2 from[MAXN][2];

int main() {
	if (fopen("FILENAME.in", "r")) {
		freopen("FILENAME.in", "r", stdin);
		freopen("FILENAME.out", "w", stdout);
	}
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);

	string s;
	ll k;

	cin >> s >> k;

	if (s.size() == 1) {
		cout << (k / 2) << endl;
		return 0;
	}

	int n = s.size();

	s = s + s + s;

	set<char> uvals;
	for (int i = 0; i < s.size(); i++) {
		values[i] = s[i];
		uvals.insert(s[i]);
	}

	if (uvals.size() == 1) {
		cout << ((k * ((long long)n)) / 2) << endl;
		return 0;
	}


	for (int i = 0; i <= s.size() + 1; i++) {
		dp[i][0] = IINF;
		dp[i][1] = IINF;
	}

	dp[0][0] = 0;
	for (int i = 0; i < s.size(); i++) {
		if (dp[i + 1][0] > dp[i][1]) {
			dp[i + 1][0] = dp[i][1];
			from[i + 1][0] = mp(i, 1);
		}

		if (dp[i + 1][1] > dp[i][0] + 1) {
			dp[i + 1][1] = dp[i][0] + 1;
			from[i + 1][1] = mp(i, 0);
		}

		if (dp[i + 1][1] > dp[i][1] + 1) {
			dp[i + 1][1] = dp[i][1] + 1;
			from[i + 1][1] = mp(i, 1);
		}

		if (i == 0 || values[i - 1] != values[i]) {
			if (dp[i + 1][0] > dp[i][0]) {
				dp[i + 1][0] = dp[i][0];
				from[i + 1][0] = mp(i, 0);
			}
		}
	}

	pair2 anspos = mp(s.size(), 0);
	if (dp[s.size()][1] < dp[s.size()][0]) {
		anspos.second = 1;
	}

	int totalCost = dp[anspos.first][anspos.second];

	int endCost = 0;
	int startCost = 0;
	int midCost = 0;

	while (anspos.first != 0) {
		if (anspos.first == n * 2) {
			endCost = totalCost - dp[anspos.first][anspos.second];
		}
		if (anspos.first == n) {
			startCost = dp[anspos.first][anspos.second];
			midCost = totalCost - endCost - startCost;
		}
		anspos = from[anspos.first][anspos.second];
	}

	//cout << "have " << startCost << ' ' << midCost << ' ' << endCost << endl;

	//assert(midCost % 10 == 0);

	//midCost /= 10;

	if (k == 1) {
		cout << startCost << endl;
	} else {
		cout << (startCost + endCost + (1LL * midCost * (k - 2)));
	}


}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vecll = vector<long long>;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

int main()
{
    ll n, m;
    cin >> n;
    vecll a(n), b, result;
    for (auto &x : a)
        cin >> x;

    cin >> m;
    b.resize(m);
    for (auto &y : b)
        cin >> y;

    set_symmetric_difference(all(a), all(b), inserter(result, end(result)));

    for (auto &z : result)
        cout << z << endl;
}


Measured memory_bytes: 10116
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define PI 3.14159265359
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define tr(con, it) \
    for (auto it = con.begin(); it != con.end(); it++)
#define present(con, ele) (con.find(ele) != con.end())
#define cpresent(con, ele) (find(all(con), ele) != con.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double lf;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  int n;
  cin >> n;
  vi d(n);
  rep(i,n) cin >> d[i];
  sort(d.begin(),d.end());
  int cnt =0;
  rep(k,1000000){
    if(distance(lower_bound(d.begin(),d.end(),k),d.end())==n/2) cnt++;
    }
  cout << cnt << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
 
int heap[2000000];
int size;
 
void max_heapify(int heap[], int i) {
    int l = 2 * i + 1;
    int r = 2 * i + 2;
    int largest;
 
    if (l <= size && heap[l] > heap[i]) {
        largest = l;
    } else {
        largest = i;
    }
    if (r <= size && heap[r] > heap[largest]) {
        largest = r;
    }
 
    if (largest != i) {
        int tmp = heap[i];
        heap[i] = heap[largest];
        heap[largest] = tmp;
        max_heapify(heap, largest);
    }
}
 
void insert(int k){
    int child = size;
    int parent = (child - 1) / 2;
 
    heap[size] = k;
 
    while(1){
        if(heap[parent] > heap[child] || child == 0)
            break;
        int tmp = heap[child];
        heap[child] = heap[parent];
        heap[parent] = tmp;
 
        child = parent;
        parent = (child - 1) / 2;
    }
 
    size++;
}
 
int extract_max(){
    int ret = heap[0];
    heap[0] = heap[size-1];
    size--;
    max_heapify(heap, 0);
    return ret;
}
 
int main(){
    char cmd[8];
    int k;
 
    while(1) {
        scanf("%s", cmd);
        if(cmd[0] == 'i'){
            scanf("%d", &k);
            insert(k);
        }else if(cmd[1] == 'x'){
            printf("%d\n", extract_max());
        }else{
            return 0;
        }
    }
}



Measured memory_bytes: 5608
#include <stdio.h>

int search(int A[],int key,int n){
    int i=0;
    A[n]=key;
    while(A[i]!=key){
        i++;
    }
    if(i!=n){
        return 1;
    }
    return 0;
}

int main(){
    int flag,n,A[10000+1],q,key,sum=0;

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d",&key);
        flag=search(A,key,n);
        if(flag==1){
            sum+=1;
        }
    }
    printf("%d\n",sum);
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
 int k,s;
  cin >> k  >> s ;
  ll sum=0;
  rep(i,k+1){
    rep(j,k+1){
      if(i+j<=s && s-i-j<=k)sum++;
    }
  }
  cout << sum << endl;
}

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

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int main(void){
  char s[3010], t[3010];
  scanf("%s", s);
  scanf("%s", t);

  int N, M;
  N = strlen(s);
  M = strlen(t);

  int dp[N+1][M+1];
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      dp[i][j] = 0;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j]+1;
      else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
    }
  }

  char ans[3010];
  int num = 0;
  while(N > 0 && M > 0){
    if(dp[N][M] == dp[N-1][M]) N--;
    else if(dp[N][M] == dp[N][M-1]) M--;
    else{
      N--, M--;
      ans[num++] = s[N];
    }
  }

  for (int i = num-1; i >= 0; i--) {
    printf("%c", ans[i]);
  }
  printf("\n");


  return 0;
}

Measured memory_bytes: 35328
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    int max1 = 0;
    int max2 = 0;
    for(int i = 0; i < n; i++) {
        if(max1 >= a[i]) {
            max2 = max(max2, a[i]);
        }
        max1 = max(max1, a[i]);
    }
    
    for(int i = 0; i < n; i++) {
        if(a[i] != max1) {
            cout << max1 << endl;
        }
        else {
            cout << max2 << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 2432
#include <iostream>
#include <stack>

using namespace std;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define out(v) cout<<v<<"\n"
const int INF = 1e6;

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

  if (N == 2) {
    cout << 2 << "\n";
    return 0;
  }
  int in[N];
  rep(i, N) in[i] = 0;

  bool edge[N][N];
  rep(i, N) rep(j, N) {
    char c; cin >> c;
    edge[i][j] = (c == '1');
    if (i < j && c == '1') {
      ++in[i];
      ++in[j];
    }
  }

  int d[N][N];
  rep(i, N) rep(j, N) d[i][j] = edge[i][j] ? 1 : INF;
  rep(k, N) rep(i, N) rep(j, N) {
    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }

  int color[N];
  rep(i, N) color[i] = INF;
  color[0] = 0;
  stack<int> st;
  st.push(0);
  bool is_nibu = true;
  while (!st.empty()) {
    int p = st.top(); st.pop();
    rep(i, N) {
      if (edge[i][p]) {
        if (color[i] == color[p]) {
          is_nibu = false;
        } else if (color[i] == INF) {
          color[i] = 1 - color[p];
          st.push(i);
        }
      }
    }
  }
  if (!is_nibu) {
    out(-1);
    return 0;
  }

  int r = 0;
  rep(i, N) rep(j, N) {
    r = max(r, d[i][j]);
  }
  out(r+1);
  return 0;
}


Measured memory_bytes: 512
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};

int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int x,y;
    cin>>x>>y;
    ll cntr=0;
    if(x==3){
        cntr+=100000;
    }
    if(x==2){
        cntr+=200000;
    }
    if(x==1){
        cntr+=300000;
    }

    if(y==3){
        cntr+=100000;
    }
    if(y==2){
        cntr+=200000;
    }
    if(y==1){
        cntr+=300000;
    }
    if(x==1 && y==1){
        cntr+=400000;
    }
    cout<<cntr;
	exit(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

P f(int x){
    int a = x % 10;
    int b;
    while(x){
        b = x % 10;
        x /= 10;
    }
    return P(a, b);
}

int main(){
    int n;
    cin >> n;
    map<P, int> mp;
    for(int i = 1; i <= n; i++){
        P p = f(i);
        mp[p]++;
    }

    int ans = 0;
    for(int i = 1; i <= n; i++){
        P p = f(i);
        P to = P(p.second, p.first);
        ans += mp[to];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
//https://atcoder.jp/contests/abc178/tasks/abc178_f
#include <bits/stdc++.h>

using namespace std;

const int MAXN=2e5+4;
long long a[MAXN];
long long b[MAXN];

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

    reverse(b, b+n);

#if 0
    cout<<"\n";
    for (int i=0; i<n; i++) {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
    for (int i=0; i<n; i++) {
        cout<<b[i]<<" ";
    }
    cout<<"\n";
#endif

    //寻找重合的区间
    int c=-1;
    int l=n;
    int r=-1;
#if 0
    for (int i=0; i<n; i++) {
        if (-1==c && a[i]==b[i]) {
            //第一次出现相等
            c=a[i];
            l=i;
        } else if (-1!=c && (!(c==a[i] && c==b[i]))) {
            //最后一次出现相等
            r=i-1;
            break;
        }
    }
    //cout<<l<<" "<<r<<"\n";
#else
    l=n;
    r=-1;
    for (int i=0; i<n; i++) {
        if (a[i]==b[i]) {
            c=a[i];
            break;
        }
    }
    for (int i=0; i<n; i++) {
        if (c==a[i] && c==b[i]) {
            l=min(l, i);
            r=max(r, i);
        }
    }
    //cout<<l<<" "<<r<<"\n";
#endif

    //交换数据
    for (int i=0; i<n; i++) {
        if (c!=a[i] && c!=b[i] && l<=r) {
            swap(b[i], b[l]);
            l++;
        }
    }

    if (l<=r) {
        cout<<"No\n";
    } else {
        cout<<"Yes\n";
        for (int i=0; i<n; i++) {
            cout<<b[i]<<" ";
        }
    }

    return 0;
}

Measured memory_bytes: 6772
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int MAXN = 300005;
struct TR {
	int l,r;
	int max,add;
}tr[MAXN * 4];
#define ls ro << 1
#define rs ro << 1 | 1
void build(int ro,int lt,int rt)
{
	tr[ro].l = lt;
	tr[ro].r = rt;
	tr[ro].max = 0;
	tr[ro].add = 0;
	if(lt != rt) {
		int mid = (lt + rt) >> 1;
		build(ls,lt,mid);
		build(rs,mid+1,rt);
	}
}
void Add(int ro,int c)
{
	tr[ro].add += c;
	tr[ro].max += c;
}
void pushdown(int ro)
{
	Add(ls,tr[ro].add);
	Add(rs,tr[ro].add);
	tr[ro].add = 0;
}
void pushup(int ro)
{
	tr[ro].max = max(tr[ls].max , tr[rs].max);
}
void ins_add(int ro,int lt,int rt,int c)
{
	if(lt > rt)
		return ;
	if(tr[ro].l == lt && tr[ro].r == rt) 
		Add(ro,c);
	else {
		pushdown(ro);
		int mid = (tr[ro].l + tr[ro].r) >> 1;
		if(rt <= mid)
			ins_add(ls,lt,rt,c);
		else if(lt > mid)
			ins_add(rs,lt,rt,c);
		else {
			ins_add(ls,lt,mid,c);
			ins_add(rs,mid+1,rt,c);
		}
		pushup(ro);
	}
}
void prn(int ro)
{
	if(tr[ro].l == tr[ro].r)
		cout << tr[ro].max << ' ';
	else {
		pushdown(ro);
		prn(ls);
		prn(rs);
	}
}
#undef ls
#undef rs
static pii g[MAXN];
int W,H,n;
int ans = 0;
void work()
{
	static int toV[MAXN];
	int totv = 0;
	for(int i=1;i<=n;i++)
		toV[++totv] = g[i].first;
	sort(toV+1,toV+1+totv);
	totv = unique(toV+1,toV+1+totv) - (toV+1);
	for(int i=1;i<=n;i++)
		g[i].first = lower_bound(toV+1,toV+1+totv,g[i].first) - toV;

	static int st0[MAXN];
	static int st1[MAXN];
	sort(g+1,g+1+n);
	build(1,1,totv);
	ins_add(1,1,totv,H);
	int t0 = 0;
	int t1 = 0;
	st0[++t0] = 1;
	st1[++t1] = 1;
	for(int i=2;i<=n;i++) {
		ins_add(1 , 1 , g[i].first-1 , toV[g[i].first] - toV[g[i-1].first]);
		ans = max(ans , tr[1].max * 2);
		if(g[i].second >= H/2) {
			ins_add(1 , g[st0[t0]].first , g[i].first-1 , g[i].second - H);
			while(t0 > 1 && g[st0[t0]].second >= g[i].second)
				ins_add(1 , g[st0[t0-1]].first , g[st0[t0]].first-1 , g[i].second - g[st0[t0]].second),
				t0--;
			st0[++t0] = i;
		} else {
			ins_add(1 , g[st1[t1]].first , g[i].first-1 , -g[i].second);
			while(t1 > 1 && g[st1[t1]].second <= g[i].second)
				ins_add(1 , g[st1[t1-1]].first , g[st1[t1]].first-1 , g[st1[t1]].second - g[i].second),
				t1--;
			st1[++t1] = i;
		}
	}
	for(int i=1;i<=n;i++)
		g[i].first = toV[g[i].first];
}
int main()
{
	//freopen("1.in","r",stdin);
	ios::sync_with_stdio(0);
	cin >> W >> H >> n;
	for(int i=1;i<=n;i++)
		cin >> g[i].first >> g[i].second;
	g[++n] = pii(0,0);
	g[++n] = pii(W,H);

	ans = 0;
	work();
	for(int i=1;i<=n;i++)
		swap(g[i].first , g[i].second);
	swap(W , H);
	work();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 24832
#include<iostream> 
#include<cmath>
#include<vector>
using namespace std;
int main()
{
int n;
cin>> n;
vector<int> A;

for(int i =1;i<n;i++)
{
	int a;
	cin>>a;
	A.push_back(a);
	if(i==1) A.push_back(a);
}
A.push_back(A[A.size()-1]);
int sum =0;
for(int i =0;i<A.size()-1;i++)
{
	sum+=min(A[i], A[i+1]);
}
cout<<sum;
return 0;
}



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

typedef long long int ll;

int main(){
    ll cmp[100005] = {0};
    ll n;
    cin >> n;
    ll a, ans = 0;
    for(ll i = 1; i <= n; ++i){
        cin >> a;
        ans += a;
        ++cmp[a];
    }

    ll q, b, c;
    cin >> q;
    for(ll i = 0; i < q; ++i){
        cin >> b >> c;
        cmp[c] += cmp[b];
        ans = ans - cmp[b] * b + cmp[b] * c;
        cmp[b] = 0;
        cout << ans << endl;
    }

    return 0;
}


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

int main() {
  int N, i, mochi=101, r=0;
  cin >> N;
  vector<int> d(N);
  
  for(i=0; i<N; i++)
    cin >> d.at(i);
  
  for(i=0; i<N; i++) {
    int max = 0, max_idx;
    for(int j=0; j<N; j++)
      if(max <= d.at(j)) {
        max = d.at(j);
        max_idx = j;
      }
    d.at(max_idx) = 0;
    
    if(mochi > max)
     r++;
    mochi = max;
  }
  
  cout << r << endl;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

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

#define MAX 100005
#define INF 1001001001

int main(int, char**)
{
  map<string, int> a;
  int q;
  cin >> q;
  vector<string> ans;
  rep(i,q) {
    int command; cin >> command;
    if (command == 0) {
      string key;
      int x;
       cin >> key >> x;
      a[key] = x;
    } else if (command == 1) {
      string key; cin >> key;
      stringstream ss;
      if (a.count(key)) ss << a[key];
      else ss << 0;
      ans.push_back(ss.str());
    } else if (command == 2) {
      string key; cin >> key;
      a.erase(key);
    } else if (command == 3) {
      string l, r; cin >> l >> r;
      auto itr1 = a.lower_bound(l);
      auto itr2 = a.upper_bound(r);
      for (auto itr = itr1; itr != itr2; itr++) {
        stringstream ss;
        ss << (*itr).first << " " << (*itr).second;
        ans.push_back(ss.str());
      }
    }
  }

  for (auto a : ans) cout << a << endl;

  return 0;
}



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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int A, B;
	cin >> A >> B;
	string S;
	cin >> S;
	for (int i = 0; i < A; ++i) {
		if (S[i] < '0' || S[i] > '9') {
			cout << "No" << '\n';
			return 0;
		}
	}
	if (S[A] != '-') {
		cout << "No" << '\n';
		return 0;	
	}
	for (int i = A + 1; i < A + B; ++i) {
		if (S[i] < '0' || S[i] > '9') {
			cout << "No" << '\n';
			return 0;
		}
	}
	cout << "Yes" << '\n';
	
	return 0;
}


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

int main()
{
    string str;
    bool flag = false;
    getline(cin,str);

    for(int i=0; i<str.size(); i++){
        for(int j=0;i+j<str.size();j++){
            if((str[i+j] == ' ' || str[i+j] == ',' || str[i+j] == '.' || i+j == str.size() - 1) && j>2 && j<7){
                if(i+j == str.size() - 1 && str[i+j] != '.' && str[i+j] != ',' && str[i+j] != ' ')j++;
                if(flag){
                    cout << ' ';

                }
                flag = true;
                for(int k=0; k<j; k++){
                    cout << str[i+k];
                }

                i += j;
                break;
            }
            else if((str[i+j] == ' ' || str[i+j] == ',' || str[i+j] == '.')){
                i += j;
                break;
            }
        }
    }
    cout << '\n';

    return 0;
}

Measured memory_bytes: 1168
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int n=s[0],m=s[1];
		long inf=long.MaxValue/3;
		var dp1=new long[n+1][];
		for(int i=1;i<=n;i++){
			dp1[i]=new long[n+1];
			for(int j=1;j<=n;j++){
				if(i!=j){dp1[i][j]=inf;}
			}
		}
		for(int i=0;i<m;i++){
			var e=sc.Ia;
			if(e[2]<=s[2]){
				dp1[e[0]][e[1]]=e[2];
				dp1[e[1]][e[0]]=e[2];
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				for(int k=1;k<=n;k++){dp1[j][k]=Min(dp1[j][k],dp1[j][i]+dp1[i][k]);}
			}
		}
		var dp2=new long[n+1][];
		for(int i=1;i<=n;i++){
			dp2[i]=new long[n+1];
			for(int j=1;j<=n;j++){
				if(dp1[i][j]>s[2]){dp2[i][j]=inf;}
				else{dp2[i][j]=1;}
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				for(int k=1;k<=n;k++){dp2[j][k]=Min(dp2[j][k],dp2[j][i]+dp2[i][k]);}
			}
		}
		var q=sc.I;
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<q;i++) {
			int[] e=sc.Ia;
			sb.Append((dp2[e[0]][e[1]]==inf?-1:dp2[e[0]][e[1]]-1)+"\n");
		}
		Console.Write(sb);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

using namespace std;

const int MAX_N = 50;
int n, p;

int64_t mod_pow(int64_t a, int64_t b)
{
  if (b == 0) return 1;
  int64_t ret = mod_pow(a, b/2);
  ret = ret * ret % 1LL;
  if (b % 2 == 1) ret = a * ret % 1LL;
  return ret;
}

int64_t comb(int64_t a, int64_t b)
{
  if (b > a - b) return comb(a, a - b);

  int64_t num = 1;

  for (int i = 1; i <= b; i++) {
    num = num * (a - i + 1) / i;
  }

  return num;
}

int main()
{
  cin >> n >> p;
  int a, odd = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (a % 2 == 1) odd++;
  }

  int i = p == 0 ? 0 : 1;
  int64_t oddc = 0, evenc = 0;
  for (; i <= odd; i += 2) {
    oddc += comb(odd, i);
  }
  for (i = 0; i <= n - odd; i++) {
    evenc += comb(n - odd, i);
  }

  cout << oddc * evenc << endl;

  return 0;
}


Measured memory_bytes: 256
#[allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }

    use std::cmp::Ordering;
    let result = match a.cmp(&b) {
        Ordering::Less => {
            std::iter::repeat(a.to_string()).take(b).collect::<String>()
        },
        Ordering::Greater => {
            std::iter::repeat(b.to_string()).take(a).collect::<String>()
        },
        Ordering::Equal => {
            std::iter::repeat(a.to_string()).take(b).collect::<String>()
        }
    };

    println!("{}", result);

}


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

using namespace std;
int main()
{


  long long int a,b,n,x,c;
  cin >> a>>b>>n;
if(n>=b)
{

  x=b-1;
}
else x=n;

  c= (a*x)/b - a*(x/b);
cout << c;


return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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




int main() {
    ll h, w;
    cin >> h >> w;
    vector<vector<char>> camp(h+2, vector<char>(w+2));
    FOR(i, 1, h+1) {
        FOR(j, 1, w+1) {
            cin >> camp[i][j];
        }
    }
    string ans = "Yes";
    FOR(i, 0, h) {
        FOR(j, 0, w) {
            char target = camp[i][j];
            if(target == '#') {
                if(camp[i-1][j] != '#' and camp[i+1][j] != '#' and camp[i][j-1] != '#' and camp[i][j+1] != '#') {
                    ans = "No";
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    

}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define ZERO(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define eb emplace_back
#define mp make_pair

int main() {
    string s;
    while(cin>>s) {
        string t = "";
        for(auto& i : s) {
            if(i=='0') t+='0';
            if(i=='1') t+='1';
            if(i=='B') {
                string tt = "";
                rep(j, SZ(t)-1) tt+=t[j];
                t = tt;
            }
        }
        cout << t << "\n";
    }


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int h, w;
	int i, j;
	for (;;)
	{
		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0)
			break;
		for (i = 0; i < h; i++)
		{
			for (j = 0; j < w; j++)
			{
				if ((i + j) % 2 == 0)
					printf("#");
				else
					printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2036
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
using namespace std;

int main() {
  int n;
  double p[3000];
  static double dp[3000][3000];

  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> p[i];
    }
    for (int i = 0; i <= n; i++) {
      fill(dp[i], dp[i] + n + 1, 0);
    }

    dp[0][0] = 1.0;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= i; j++) {
        dp[i + 1][j + 1] += dp[i][j] * p[i];
        dp[i + 1][j] += dp[i][j] * (1 - p[i]);
      }
    }

    double ans = 0;

    for (int i = n; i > n - i; i--) {
      ans += dp[n][i];
    }

    printf("%.10f\n", ans);
  }

}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int d=(a*100)+(b*10)+c;
    
    if(d%4==0)
        cout<<"YES"<<endl;
    
    else
        cout<<"NO"<<endl;



    return 0;
}





Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MN 12

int main() {
	int l, m[MN], n[MN];
	while (cin >> l, l) {
		for (int i=0; i<MN; i++)
			cin >> m[i] >> n[i];

		int sum = 0;
		int ans=-1;
		for (int i=0; i<MN; i++) {
			sum += m[i]-n[i];
			if (sum >= l) { ans=i+1; break; }
		}

		if (ans!=-1)
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
x, y = map(int,input().split())

mod = 10**9 + 7
n = (2*y - x) // 3 # (+1, +2)
m = (2*x - y) // 3 # (+2, +1)
N = 10**6
g1 = [1,1]
g2 = [1,1]
inverse = [0,1]

def comb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r,n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


if __name__ == '__main__':
    if (x+y) % 3 != 0:
        print(0)
        exit()
    if n < 0 or m < 0:
        print(0)
        exit()
    sum = n + m
    r = min(n,m)

    for i in range(2, N+1):
        g1.append((g1[-1]*i) % mod)
        inverse.append((-inverse[mod%i] * (mod//i)) % mod)
        g2.append((g2[-1]*inverse[-1]) % mod)

    print(comb(sum,r,mod))


Measured memory_bytes: 122048