akhauriyash/Code-Regression huggingface dataset:
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

double solve(double m, const vector<double>& p, const vector<double>& q) {
  double ret = 0;
  for (int i = 0; i < 6; ++i) {
    ret += max(m * p[i], (1 - m) * q[i]);
  }
  return ret;
}

int main() {
  vector<double> p(6), q(6);
  for (int i = 0; i < 6; ++i) {
    cin >> p[i];
    p[i] /= 100;
  }
  for (int i = 0; i < 6; ++i) {
    cin >> q[i];
    q[i] /= 100;
  }
  double low = 0, high = 1;
  for (int k = 0; k < 60; ++k) {
    double m1 = (low * 2 + high) / 3;
    double m2 = (low + high * 2) / 3;
    if (solve(m1, p, q) < solve(m2, p, q)) {
      high = m2;
    } else {
      low = m1;
    }
  }
  cout << solve(high, p, q) << '\n';
  return 0;
}


Measured memory_bytes: 3268
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    H, N = MI()
    A = [0] * N
    B = [0] * N
    dp = [IINF] * (H+1)
    dp[0] = 0

    for i in range(N):
        A[i], B[i] = MI()
        # AB[i] = (A / B, A, B)

    for i in range(N):
        dp_next = [IINF] * (H + 1)
        for j in range(H+1):
            dp_next[j] = min(dp[j], dp_next[j])
            if j + A[i] <= H:
                dp_next[j+A[i]] = min(dp_next[j+A[i]], dp_next[j] + B[i])
            else:
                # print(i, j, dp_next[j] + B[i], dp_next[j])
                dp_next[H] = min(dp_next[H], dp_next[j] + B[i])
                # print(dp_next[H])
        dp = dp_next
        # print(dp)

    print(dp[H])


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
    int zei_mae;
    int zei_ato;
    int sum_mae;

    int sum_ato;
    list<int> sum_atos;

    int foo, bar;
    int fuga, piyo;
    while (1) {
        cin >> zei_mae;
        cin >> zei_ato;
        cin >> sum_mae;

        if (zei_mae == 0 && zei_ato == 0 && sum_mae == 0)
            break;

        sum_ato = 0;

        for (int i = 1; i < sum_mae; i++) {
            for (int j = 1; j < sum_mae; j++) {
                foo = i * (100 + zei_mae) / 100;
                bar = j * (100 + zei_mae) / 100;
                if (foo + bar == sum_mae) {
                    fuga = i * (100 + zei_ato) / 100;
                    piyo = j * (100 + zei_ato) / 100;
                    if (sum_ato < fuga + piyo)
                        sum_ato = fuga + piyo;
                }
            }
        }
        sum_atos.push_back(sum_ato);
    }

    for (auto itr = sum_atos.begin(); itr != sum_atos.end(); itr++)
        cout << *itr << endl;

    return 0;
}




Measured memory_bytes: 3088
#include<stdio.h>

int binarySearch(int n,int *S,int key){
    int left = 0, right = n,mid;
    while(left<right){
        mid = (left + right)/2;
        if(key == S[mid]){
            return 1;
        }
        if(key > S[mid]){
            left = mid + 1;
        }
        else if(key < S[mid]){
            right = mid;
        }
    }
    return 0;
}

int main(){
    int i,j,n,q,S[100000],T[50000],count = 0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&S[i]);
    }
    scanf("%d",&q);
    for(j=0;j<q;j++){
        scanf("%d",&T[j]);
    }

    for(j=0;j<q;j++){
        if(binarySearch(n,S,T[j]) == 1)
        count++;
    }

    printf("%d\n",count);
}


Measured memory_bytes: 2284
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n;
int he[400005],to[400005],ne[400005],e;
int inv[400005];
int a[1<<20],b[1<<20],rot[1<<20],invg[1<<20],g[1<<20];
const int mod=924844033;
int sz[1<<20];
long long qpow(long long x,long long y){
       long long res=1;
	   while(y){
	      if(y&1)res=res*x%mod;
		  x=x*x%mod;
		  y>>=1;
	   }
	   return res;
}
void add(int x,int y){
  to[++e]=y;
  ne[e]=he[x];
  he[x]=e;
}
void dfs(int x,int fa){
   a[n]++;
   sz[x]=1;
   for(int i=he[x];i;i=ne[i]){
        int v=to[i];
	   if(v==fa)continue;
	   dfs(v,x);
	   sz[x]+=sz[v];
     if(--a[sz[v]]<0)a[sz[v]]+=mod;
   }
   if(--a[n-sz[x]]<0)a[n-sz[x]]+=mod;
}
void ntt(int *x,int ts,int opt){
        F(i,0,ts-1){
		  if(i<rot[i])swap(x[i],x[rot[i]]);
		}
        for(int i=2;i<=ts;i<<=1){
		   int wn=opt==1?g[i]:invg[i];
		   for(int j=0;j<ts;j+=i){
		      for(int k=0,w=1;k<(i>>1);w=1ll*w*wn%mod,k++){
			        int xx=x[j+k],yy=1ll*w*x[(i>>1)+j+k]%mod;
					x[j+k]=(xx+yy)%mod;
					x[(i>>1)+j+k]=(xx-yy+mod)%mod;
			  }
		   }
		}
	   if(opt==-1){
	      int gg=qpow(ts,mod-2);
		  F(i,0,ts-1)x[i]=1ll*x[i]*gg%mod;
	   }
}
int main () {
#ifndef ONLINE_JUDGE
//file("at2064");
#endif
    n=read();
	F(i,1,n-1){
	    int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	dfs(1,0);
	int ff=1;
	F(i,1,n)a[i]=1ll*a[i]*(ff=1ll*ff*i%mod)%mod;
	inv[n]=qpow(ff,mod-2);
	f(i,n-1,0)inv[i]=1ll*inv[i+1]*(i+1)%mod;
	F(i,1,n)b[i]=inv[n-i];
	int len=1,ts=0;
	for(;len<=2*n;len<<=1)ts++;
	F(i,0,len-1)rot[i]=(rot[i>>1]>>1)|((i&1)<<(ts-1));
	int gg=qpow(5,mod-2);
	F(i,1,len){
	   g[i]=qpow(5,(mod-1)/i),invg[i]=qpow(gg,(mod-1)/i);
	}
	ntt(a,len,1);
	ntt(b,len,1);
	F(i,0,len)a[i]=1ll*a[i]*b[i]%mod;
	ntt(a,len,-1);
	F(i,1,n){
	   printf("%lld\n",1ll*a[i+n]*inv[i]%mod);
	}
    return 0;
}

Measured memory_bytes: 37632
#include<iostream>
#include<vector>
#include<string>

using namespace std;
using vec = vector<int>;
using mat = vector<vec>;

void init(vec & parent, vec & size)
{
	for (int i = 0; i < parent.size(); ++i)
	{
		parent[i] = i;
		size[i] = 1;
	}
}


int find(vec & parent, int x)
{
	if (parent[x] == x)
	{
		return x;
	}
	return x = find(parent,parent[x]);
}


void unite(vec & parent, vec & size, int x, int y)
{
	x = find(parent, x);
	y = find(parent, y);

	if (x == y)return;

	parent[y] = x;
	size[x] += size[y];
}


int change(int y,int x,int W)
{
	return y*W + x;
}


int main()
{
	while (true)
	{
		int W, H;
		cin >> W >> H;
		if (W == 0 && H == 0)return 0;

		mat color(H, vec(W));
		vec parent(W*H);
		vec size(W*H);

		init(parent, size);

		int start;

		for (int y = 0; y < H; ++y)
		{
			string c;
			cin >> c;

			for (int x = 0; x < W; ++x)
			{
				
				if (c[x] == '.') { 
					
					color[y][x] = 0; 
					
				}
				else if (c[x] == '#') { color[y][x] = 1; }
				else
				{
					color[y][x] = 0;
					start = change(y, x, W);
				}

				if (x != 0 && color[y][x] == color[y][x - 1])
				{
					unite(parent, size, change(y, x, W), change(y, x - 1, W));
				}
				if (y != 0 && color[y][x] == color[y - 1][x])
				{	
					unite(parent, size, change(y, x, W), change(y - 1, x, W));
				}
				
			}
		}

		cout << size[find(parent, start)] << endl;
	}
}


Measured memory_bytes: 3020
#include<stdio.h>

int main()

{
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    if(A==5 && B==5 && C==7)
    {
        printf("YES\n");
    }
    else if(A==5 && B==7 && C==5)
    {
        printf("YES\n");
    }
    else if(A==7 && B==5 && C==5)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;
}

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

const int N = 60;
const int M = N*N;
int h[N], e[M], ne[M], idx;
int dfn[N], low[N], timestamp;
int cnt;
int n, m;

void add(int a, int b){
    e[idx] = b;
    ne[idx] = h[a];
    h[a] = idx ++;
}

void tarjan(int curr, int prev){
    dfn[curr] = low[curr]= ++ timestamp;
    for(int i = h[curr]; i != - 1; i = ne[i]){
        int next = e[i];
        if(!dfn[next]){
            tarjan(next, curr);
            low[curr] = min(low[curr], low[next]);
            if(low[next] > dfn[curr]){
                cnt ++;
            }
        } else if(next != prev){
            low[curr] = min(low[curr], low[next]);
        }
    }
}

int main(){
    cin >> n >> m;
    memset(h, -1, sizeof h);
    while(m --){
        int a, b;
        cin >> a >> b;
        add(a, b);
        add(b, a);
    }
    for(int i = 1; i <= n; i ++)
    {
        if(!dfn[i]) tarjan(1, -1);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    int n,  max = 0;
    cin >> n;
    cin >> s;

    for (int i = 1; i < n - 1; ++i) {
        string s1 = s.substr(0, i);
        string s2 = s.substr(i);
        int tmp = 0;
        for (int j = 0; j < 26; ++j) {
            char c = 'a' + j;
            auto it1 = s1.find(c);
            auto it2 = s2.find(c);
            if (it1 != string::npos && it2 != string::npos) ++tmp;
        }
        if (max < tmp) max = tmp;
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
void main() {
	bool[int] a;
	auto N = ri;
	foreach(_; 0..N) {
		a[ri] ^= true;
	}
	a.values.count!(a => a).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 8572
#include <stdio.h>
int main(void)
{
	int S;
	int a, b;
	scanf("%d", &S);
	a = S / 100;
	b = S - a * 100;

	if(a <= 12 && a > 0) {
		if(b <= 12 && b > 0) {
			printf("AMBIGUOUS");
		} else {
			printf("MMYY");
		}
	} else if(b <= 12 && b > 0) {
		printf("YYMM");
	} else {
		printf("NA");
	}
	return 0;
}

Measured memory_bytes: 128
from itertools import accumulate

N, M = map(int, input().split())
acc = [0] * N
for _ in range(M):
    a, b = map(int, input().split())
    if a > b:
        a, b = b, a
    acc[a - 1] += 1
    acc[b - 1] -= 1
print("NO") if any(a % 2 for a in accumulate(acc)) else print("YES")


Measured memory_bytes: 9912
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> g(10);
vector<bool> visited(10, false);
int ans = 0;
int n, m;

void dfs(vector<int> ARR, int s, int cnt) {
	visited[s] = true;
	if (cnt + 1 == n) {
		bool ok = true;
		rep (i, n) if (!visited[i]) ok = false;
		if (ok) ans++;
		return;
	}
	for (auto to: g[s]) {
		if (visited[to]) continue;
		if (to == ARR[cnt]) {
			dfs(ARR, to, cnt + 1);
		}
	}
}

int main(void) {

	cin >> n >> m;
	rep (i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].pb(b);
		g[b].pb(a);
	}

	vector<int> arr(n - 1);
	rep (i, n - 1) arr[i] = i + 1;

	
	do {
		rep (i, n) visited[i] = false;
		dfs(arr, 0, 0);
	} while (next_permutation(rng(arr)));

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


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;

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 abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int abs_B(long long num, long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}



const long long MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    int count = 0;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        count = 0;
        if (i % 2 == 0) {
            continue;
        }
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) {
                count++;
            }
            if (count == 8) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
k = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[k-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	vector<int> a(n), b(n);
	set<pair<int, int>> S;
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &b[i]);
		S.insert({b[i], i});
	}
	auto no = [&]() {
		printf("-1\n");
		exit(0);
	};
	ll ans = 0;
	while (!S.empty()) {
		auto x = *S.rbegin();
		S.erase(x);
		int id = x.second;
		if (b[id] == a[id]) continue;
		if (b[id] < a[id]) no();
		int v = b[(id + n - 1) % n] + b[(id + 1) % n];
		if (b[id] <= v) no();
		if (a[id] >= v) {
			if ((b[id] - a[id]) % v) no();
			ans += (b[id] - a[id]) / v;
			b[id] = a[id];
		} else {
			int t = b[id] % v;
			ans += (b[id] - t) / v;
			b[id] = t;
			S.insert({b[id], id});
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
int main(void) {
    queue<pair<string, int> > que;
    
    int n, q;
    cin >> n >> q;
    string s;
    int t;
    while(n--) {
        cin >> s >> t;
        que.push(pair<string, int>(s, t));
    }
    int naw = 0;
    
    while(que.size()) {
        s = que.front().first;
        t = que.front().second;
        que.pop();
        naw += min(q, t);
        if(q >= t) {
            cout << s + " " << naw << endl;
        }
        else {
            que.push(pair<string, int>(s, t - q));
        }
    }
}


Measured memory_bytes: 6248
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define fi first
#define se second
#define pii pair<int,int>

int n,m;
main()
{
   cin>>n>>m;
   cout<<n*(n-1)/2+m*(m-1)/2;
}


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

const int INF = 1e9L + 5;

int main()
{
  int n, k;
  scanf("%d%dd", &n, &k);
  vector<int> a(n);
  for(int& i : a)
  {
    scanf("%d", &i);
  }
  vector<int> dp(n + 1, INF);
  dp[0] = 0;
  for(int i = 0; i < n; i++)
  {
    for(int j = i + 1; j < n and j < k + i + 1; j++)
    {
      dp[j] = min(dp[j], dp[i] + abs(a[j] - a[i]));
    }
  }
  cout << dp[n - 1];
  
  return 0;
}


Measured memory_bytes: 1024
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
//#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll maxn = 300005;
const ll mm = 1e+18;
void solve()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int an=0;
    an+=min(a,k);
    k-=min(a,k);
    k-=min(k,b);
    an-=min(c,k);
    pr(an);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    // srand(time(0));
    //freopen("sp.txt","r",stdin);
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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

  int N, W;
  cin >> N >> W;
  pair<int, int> P[N+1];
  for(int i=1;i<=N;i++){
    cin >> P[i].first >> P[i].second;
  }
  int64_t dp[N+1][W+1] = {};
  for(int i=1;i<=N;i++){
    for(int k=0;k<=W;k++){
      if(P[i].first > k){
        dp[i][k] = dp[i-1][k];
      }
      else{
        dp[i][k] = max(dp[i-1][k], dp[i-1][k - P[i].first] + P[i].second);
      }
    }
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 79232
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> P;

int main() {
    int X;
    scanf("%d", &X);
    printf("%s\n", X == 3 || X == 5 || X == 7 ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define MAX 100000

void swap(int*,int*);
void Partirion(int,int,int*);

int n, test;

void Printf(int i,int* A)
{
    int j;
    for(j = 0;  j < n; j++)
    {
        if(j != 0) printf(" ");
        if(j == i) printf("[%d]",A[j]);
        else printf("%d",A[j]);
    }
    printf("\n");
}

void swap(int* a,int* b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

void Partirion(int l,int r,int* A)
{
    int x = A[r];
    int i = l, j;
    
    for(j = l; j < r; j++)
    {
        if (A[j] <= x) swap(&A[i++],&A[j]);
    }
    swap(&A[i],&A[j]);
    
    Printf(i,A);
} 

int  main(void){
    int i,A[MAX];
    
    scanf("%d",&n);
    for(i = 0 ; i < n ; i++) scanf("%d",&A[i]);
    
    Partirion(0,n-1,A);
    return 0;
}



Measured memory_bytes: 2104
#include <stdio.h> /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h> /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h> /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/

//---------------------------------------------------

#define rep(i, n) for(int i = 0; i < (n); i++)
#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)

int main(void)
{
int n, k, x, y;
scanf("%d %d %d %d\n",&n, &k , &x ,&y );
int ans = 0;
if (k >= n) {
ans = n*x;
}else{
ans = k * x;
n -= k;
ans += n*y;
}
printf("%d\n", ans);
return 0;
}



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

using namespace std;

#define INF 1e9

int idx,size;
bool found;
map<string,int> mp;

int getNum(const string &s){
  int res = 0, w = 1;
  string str;
  while(isdigit(s[idx])){
    str += s[idx];
    idx++;
  }
  for(int i = str.size()-1 ; i >= 0 ; i--){
    res += (str[i]-'0')*w;
    w *= 10;
  }
  return res;
}

int parse(const string &s){
  if(idx >= size){ return 0; }
  int num = 1;
  if(s[idx] == '('){
    idx++;
    int n = parse(s),a = 0;
    idx++;
    if(idx < size){
      if(isdigit(s[idx])){
        num = getNum(s);
      }
    }
    if(idx < size && s[idx] != ')'){
      a = parse(s);
    }
    return n*num + a;
  }else if(isalpha(s[idx])){
    int res = 0;
    string str;
    while(idx < size && isalpha(s[idx])){
      int f = -1;
      str += s[idx++];
      if(idx < size && !islower(s[idx])){
        if(mp.find(str) != mp.end()){
          f = mp[str];
          str = "";
        }else{
          found = false;
        }
      }
      if(f != -1 && idx < size && isdigit(s[idx])){
        f *= getNum(s);
      }
      if(f != -1){ res += f; }
    }
    if(!str.empty()){
      int f = -1;
       if(mp.find(str) != mp.end()){
         f = mp[str];
       }else{
         found = false;
       }
       if(f != -1 && idx + 1 < size && isdigit(s[idx+1])){
         idx++;
         f *= getNum(s);
       }
       if(f != -1){ res += f; }
    }
    if(!found){ return -1; }
    int a = 0;
    if(idx < size && s[idx] != ')'){
      a = parse(s);
    }
    return res + a;
  }
}

int main(){
  string s;
  int num;
  while(cin >> s, s != "END_OF_FIRST_PART"){
    cin >> num;
    mp[s] = num;
  }
  while(cin >> s, s != "0"){
    idx = 0;
    found = true;
    size = s.size();
    int ans = parse(s);
    if(found){
      cout << ans << endl;
    }else{
      cout << "UNKNOWN" << endl;
    }
  }
  return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)

void FIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int n;
int a[100005][4];
int dp[100005][4];

int solve(int day, int tasks)
{
	if (day >= n)
	{
		return 0;
	}

	if (dp[day][tasks] != -1)
	{
		return dp[day][tasks];
	}

	int ans = INT_MIN;
	if (tasks == 0)
	{
		ans = max(ans, a[day + 1][1] + solve(day + 1, 1));
		ans = max(ans, a[day + 1][2] + solve(day + 1, 2));
		ans = max(ans, a[day + 1][3] + solve(day + 1, 3));
	}
	else if (tasks == 1)
	{
		ans = max(ans, a[day + 1][2] + solve(day + 1, 2));
		ans = max(ans, a[day + 1][3] + solve(day + 1, 3));
	}
	else if (tasks == 2)
	{
		ans = max(ans, a[day + 1][1] + solve(day + 1, 1));
		ans = max(ans, a[day + 1][3] + solve(day + 1, 3));
	}
	else if (tasks == 3)
	{
		ans = max(ans, a[day + 1][1] + solve(day + 1, 1));
		ans = max(ans, a[day + 1][2] + solve(day + 1, 2));
	}

	return dp[day][tasks] = ans;
}

int32_t main()
{
	FIO();
	cin >> n;
	memset(dp, -1, sizeof(dp));

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= 3; j++)
		{
			cin >> a[i][j];
		}
	}
	cout << solve(0, 0) << '\n';
	return 0;
}

Measured memory_bytes: 17648
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	if a == b && b == c {
		fmt.Println("No")
	} else if a != b && b != c && a != c {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N; cin >> N;
    vector<string> s(N);
    for(int i=0; i<N; i++){
        cin >> s[i];
    }
    ll c = 0;
    ll a = 0;
    ll b = 0;
    ll d = 0;
    for(int i=0; i<N; i++){
        ll l = s[i].size();
        for(int j=0; j<l-1; j++){
            if(s[i][j] == 'A'&&s[i][j+1] == 'B'){
                c++;
            }
        }
        if(s[i][0] == 'B'){
            b++;
        }
        if(s[i][l-1] == 'A'){
            a++;
        }
        if(s[i][0] == 'B'&&s[i][l-1] == 'A'){
            d++;
        }
    }
    c += min(a, b);
    if(d == a&&d == b&&d!=0){
        c--;
    }
    cout << c;
}

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

#define ll long long
#define ld long long
#define pi 3.14159265359

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(M);
    int sum = 0;
    for (int i = 0; i < M; i++) {
        cin >> A.at(i);
        sum += A.at(i);
    }
    int ans = max(N - sum, -1);
    cout << ans << endl;
}

Measured memory_bytes: 3672
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define LINF (ll)1e18
#define INF (int)1e9
struct aaa{aaa(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(10);};}aaaaaaa;
inline void in() {}
template <class Head, class... Tail>
inline void in(Head&& head,Tail&&... tail){
    cin>>head;
    in(move(tail)...);
}
template <class T>
inline void out(T t) {
    cout<<t<<'\n';
}
template <class Head, class... Tail>
inline void out(Head head,Tail... tail){
    cout<<head<<' ';
    out(move(tail)...);
}

int main(){
    string a,b;
    in(a,b);
    int n=a.size();
    rep(i,0,n){
        if(a==b){
            out("Yes");
            return 0;
        }
        b=b.back()+b;
        b.pop_back();
    }
    out("No");
}



















Measured memory_bytes: 256
import copy

def bubbleSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        for j in range(len(C) - 1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j-1], C[j] = C[j], C[j-1]
    return C

def selectionSort(cards):
    C = copy.copy(cards)
    for i in range(0, len(C)):
        min = i
        for j in range(i, len(C)):
            if C[j][1] < C[min][1]:
                min = j
        C[i], C[min] = C[min], C[i]
    return C


N = int(input())
cards = input().split()

CB = bubbleSort(cards)
CS = selectionSort(cards)
print(' '.join(CB))
print('Stable')
print(' '.join(CS))
if CB == CS:
    print('Stable')
else:
    print('Not stable')

Measured memory_bytes: 8228
# -*- coding: utf-8 -*-

a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())

cnt = [0] * 4
cnt[a1-1] += 1
cnt[b1-1] += 1
cnt[a2-1] += 1
cnt[b2-1] += 1
cnt[a3-1] += 1
cnt[b3-1] += 1

flag = True
for c in cnt:
    if c == 0 or c > 2:
        flag = False
        break

if flag:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include<vector>
#include <queue>
using namespace std;
int main()
{
	long long n, k;
	cin >> n >> k;
	long long ans = 0;
	if (k == 0)ans = n * n;
	else {
		for (int i = 1; i <= n; i++) {
			if(i-k>-1)ans += (i - k)*(n / i);
			if (n%i >= k)ans += (n%i - k + 1);
			//cout << ans<<endl;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0507

"""
import sys
from sys import stdin
input = stdin.readline


def solve(n, a=0):
    result = []
    in_progress = [[[], n]]
    while in_progress:
        arr, rem = in_progress.pop()
        ub = min(arr[-1] if arr else rem, rem)
        for i in range(ub, 0, -1):
            if rem - i == 0:
                result.append(arr + [i])
            else:
                in_progress.append([arr + [i], rem - i])
    return sorted(result, reverse=True)


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        ans = solve(n)
        for row in ans:
            print(*row, sep=' ')


if __name__ == '__main__':
    main(sys.argv[1:])
    



Measured memory_bytes: 7364
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rep1(i,n) for(int i=1; (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
int main(){
    int n; cin >> n;
    vector<int> v(n), c(n); rep(i,n) cin >> v[i]; rep(i,n) cin >> c[i];
    int ans = 0;
    rep(i,n) if(v[i]>c[i]) ans += v[i]-c[i];
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 200005;

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

    int n;
    cin >> n;
    LL a[SIZE];
    LL a_sort[SIZE];
    for( int i = 0; i < n; ++i ) {
        cin >> a[i];
        a_sort[i] = a[i] - ( i + 1 );

    }

    sort( a_sort, a_sort + n );
    LL cent = a_sort[n / 2];

    LL res = 0;
    for( int i = 0; i < n; ++i ) {
        res += llabs( a[i] - ( i + 1 + cent ) );

    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int h, w; cin >> h >> w;
  for(int i=1; i<=h; i++) {
    for(int j=1; j<=w; j++) {
      string s; cin >> s;
      if (s == "snuke") {
        cout << (char)('A' + j - 1) << i << endl;
      }
    }
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <sstream>
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[])
{
    string s;
    std::cin >> s;
    int c = 0;
    for (int i = 0; i < 8; i++) {
        if (s[i] == '1') {
            c++;
        }
    }
    std::cout << c << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    int N;
    cin>>N;
    pair<int,int> xy[N];
    rep(i,N) cin>>xy[i].first>>xy[i].second;
    sort(xy,xy+N);
    map<pair<int,int>,int> sa;
    rep(i,N){
        for(int j=0; j<i; j++){
            sa[mp(xy[i].first-xy[j].first,xy[i].second-xy[j].second)]++;
        }
    }
    int cnt=0;
    for(auto i:sa){
        cnt=max(cnt,i.second);
    }
    cout<<N-cnt<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
class IDisplay
{
public:
	virtual void disp(bool result) =0;
	virtual ~IDisplay(){}
};
class Display:public IDisplay
{
	static string msg[2];//;; = { "Yes","No" };
public:
	void disp(bool result) { 
		cout << msg[result] << endl;
	}
};
string Display::msg[2]= { "Yes","No" };
class Circle
{
	int x, y,r;
	bool under(int b, int r){return (b - r < 0) ? true : false;}
	bool over(int b, int r, int m){	return (b + r > m) ? true : false;}
public:
	Circle(int x, int y ,int r) :x(x), y(y),r(r) {}
	bool error(int W, int H)
	{if (!under(x, r) && !under(y, r) && !over(x, r, W) && !over(y, r, H)) return false;
		return true;
	}
};
class Rect
{
	int W, H;
public :
	Rect(int w, int h) :W(w), H(h) {}
	bool over(Circle& circle) {return circle.error(W, H);}
};

int main()
{
	int w,h,x,y,r;
	cin >> w>>h>>x>>y>>r;
	Display dspp;
	IDisplay* dsp= &dspp;
	Rect rect(w, h);
	Circle circle(x, y, r);
	dsp->disp(rect.over(circle));
	return 0;

}

Measured memory_bytes: 3192
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int v[n],c[n];
  for(int i=0;i<n;i++)
  {
    cin>>v[i];
  }
  for(int i=0;i<n;i++)
  {
    cin>>c[i];
  }
  int x=0,y=0;
  for(int i=0;i<n;i++)
  {
    if(v[i]>c[i])
    {
      x+=v[i];
      y+=c[i];
    }
  }
  cout<<(x-y);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
  cin >>n >>m;
  int x[m];
  for(int i=0;i<m;i++)cin >>x[i];
  
  if (n>=m)cout << 0 <<endl;
  
  else {
  	sort(x,x+m);
    int xa[m-1],ans=0;
    for(int i=0;i<m-1;i++){
      xa[i]=x[i+1]-x[i];
    }
    sort(xa,xa+m-1);
    for(int i=0;i<m-n;i++){
      ans+=xa[i];
    }
    cout << ans <<endl;
  }
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 99999999
 
using namespace std;
 
 
int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };
 
 
 
 
ll m = 1000000007;
 
long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; i--) {
		ans *= i;
	}
	for (int i = 1; i <= r; i++) {
		ans /= i;
	}
	return ans;
}
 
ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
 
ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}
int a[10000], b[10000];
int c=0;
void binary(int bina) {
	int ans = 0;
	for (int i = 0; bina>0; i++)
	{
		a[i]=bina % 2;
		bina = bina / 2;
		c++;
	}
}
 
int main() {
  int A,B;
  cin>>A>>B;
  cout<<(A-1)*(B-1)<<endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3 4 240", "60 90 120", "80 150 80 150" ].solve == 3 );
	assert( [ "3 4 730", "60 90 120", "80 150 80 150" ].solve == 7 );
	assert( [ "5 4 1", "1000000000 1000000000 1000000000 1000000000 1000000000", "1000000000 1000000000 1000000000 1000000000" ].solve == 0 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s %s"( n, m, k );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	input.popFront;
	auto bs = input.front.split.to!( long[] );
	
	auto ans = 0L;
	auto c = 0L;
	auto t = 0L;
	auto bi = 0L;
	auto ai = 0L;
	while( ai < as.length && t + as[ ai ] <= k )
	{
		t += as[ ai ];
		ai++;
		c++;
	}
	while( bi < bs.length && t + bs[ bi ] <= k )
	{
		t += bs[ bi ];
		bi++;
		c++;
	}
	ans = c;
	
	while( 0 < ai )
	{
		c--;
		ai--;
		t -= as[ ai ];
		while( bi < bs.length && t + bs[ bi ] <= k )
		{
			t += bs[ bi ];
			bi++;
			c++;
		}
		ans = max( ans, c );
	}
	return ans;
}


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

int main()
{
  for(;;){
    int n,m;
    cin >> n >> m;
    if(n==0){return 0;}
    double map[n][n];
 
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> map[i][j];
      }
    }
  
    double dp[m][n];

   
  
    for(int i=0;i<m;i++){for(int j=0;j<n;j++){dp[i][j]=-1.0;}}
    for(int i=0;i<n;i++){dp[0][i]=1.0;}
  
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  dp[i+1][k]=max(dp[i+1][k],dp[i][j]*map[j][k]);
	}
      }
    }
  
    //cout << endl;
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	//cout << dp[i][j] << " ";
      }
      //cout << endl;
    }

    double max1=-1.0;
    for(int i=0;i<n;i++){
      max1=max(max1,dp[m-1][i]);
    }
    //printf("%f",max1);
    printf("%.2f\n",max1);
  }
}

Measured memory_bytes: 1332
import itertools, heapq, bisect
from collections import defaultdict as ddic, deque, Counter

rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())
MOD = 10 ** 9 + 7

###
N = rri()
S, T = rr().split()

ans = []
for i in xrange(N):
    ans.append(S[i])
    ans.append(T[i])
print "".join(ans)


Measured memory_bytes: 27884
//??\???
//pi???????????????????????????m???0??§?¶??????????

#include <stdio.h>
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#define PB push_back
#define in scanf
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using	namespace std;
int dis,t1,t2,k,n,N,M;
void solve(){
while(cin >> N>>M,N!=0){
	vector <pair<int,int> > data;//first = Expected value second = distance
REP(l,N){
	cin >> t1 >> t2 ;
	data.push_back(make_pair(t2,t1));

}
//sort(data.begin(),data.end(),greater<int>());
sort(data.begin(),data.end());
int h=data.size()-1;
while(M>0){
	if(data[h].second<=M){
		M-=data[h].second;
		data[h].first=0;
	}else{
		data[h].second -= M;
M=0;
	}
	h--;
	if(h<0)break;
}
//TESTOUTPUT REP(i,data.size()) cout << "("<<data[i].first<<','<<data[i].second<<')'<<endl;
int res=0;
REP(i,N)res+= data[i].first*data[i].second;
cout << res <<endl;
}
}



	
int main(){
	solve();

}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
  int64_t n;
  cin >> n;

  vector<int64_t> t(n);
  int64_t s = 0;
  for (auto&& tt : t) {
    cin >> tt;
    s += tt;
  }

  int64_t m;
  cin >> m;
  vector<int64_t> ans(m);
  for (auto&& aa : ans) {
    int64_t p, x;
    cin >> p >> x;

    aa = s - t[p - 1] + x;
  }

  for (const auto& aa : ans) {
    cout << aa << "\n";
  }
}

Measured memory_bytes: 256
from itertools import product
from copy import copy


def count(f):
    ret = 0
    for h in f:
        for w in h:
            if w == '#':
                ret += 1

    return ret


(h, w, k) = [int(s) for s in input().split()]

f = []

for _ in range(h):
    f.append(list(input()))

tmp = [range(2)] * h
bit_h = list(product(*tmp))

tmp = [range(2)] * w
bit_w = list(product(*tmp))

ans = 0

for bh in bit_h:
    for bw in bit_w:
        d = []

        for i, hh in enumerate(bh):
            if hh == 1:
                d.append(['-'] * w)
            else:
                d.append(copy(f[i]))

        for i, ww in enumerate(bw):
            if ww == 1:
                for dd in d:
                    dd[i] = '-'

        if count(d) == k:
            ans += 1


print(ans)

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

int main(){
  int N;
  cin >> N;
  vector<int64_t> A(N);
  rep(i, N){
    cin >> A.at(i);
  }
  
  int64_t ans = 0;
  
  int64_t sum_rest = 0;
  for(int i = 0; i <N; i++){
    sum_rest += A.at(i);
    sum_rest %= 1000000007LL;
  }
  
  rep(i, N-1){
    if(sum_rest >= A.at(i)){
      sum_rest -= A.at(i);
    }else{
      sum_rest += 1000000007LL - A.at(i);
    }
    ans += A.at(i) * sum_rest % 1000000007LL; 
    ans %= 1000000007LL;
  }//end rep i 
  cout << ans << endl;
}


Measured memory_bytes: 4784
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;



int main(){
	int n;
	cin >> n;

	vector<int> v(101010);
	rep(i, 0, n) {
		int x;
		cin >> x;
		v[x]++;
		v[x+1]++;
		v[x + 2]++;
	}

	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	cout << v[0] << endl;


	return 0;
}


Measured memory_bytes: 640
function Main(input) {
	input = input.trim();
  var len = parseInt(input.split("\n")[0]);
  var list = input.split("\n")[1].split(" ").map((list)=>Number(list));
  var output = "Yes";
  var four = 0;//4の倍数
  var two = 0;//2の倍数（4の倍数でない）
  for(var i = 0; i < list.length; i++){
    if(list[i] % 2 == 0 && list[i] % 4 != 0){
       two++;
    }else if(list[i] % 4 == 0){
      four++;
    }
  }
  //console.log("2の倍数:" + two);
  //console.log("4の倍数:" + four);
  //4の倍数がMath.floor(N/2)個以上あればOK
  //ない場合、2の倍数が足りない分*2個以上あればOKなはず
  if(Math.floor(len / 2) > four){
     var husoku = Math.floor(len / 2) - four;
     if(husoku * 2 > two){
        output = "No";
     }else{
       //console.log("2の倍数も使ってYes");
     }
  }else{
    //console.log("4の倍数だけでYes");
  }
  console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 17484