akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

ll kaizyo(int x){
  ll ans = 1;
  if(x == 0) {
    return 1;
  }
  for(int i = x; i > 0; i--){
    ans = ans * i;
  }

  return ans;
}

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

 if(n < 3) {
   cout << 0 << endl;
   return 0;
 }
 int count=0;
 ll m=0,a=0,r=0,c=0,h=0;
 rep(i,n) {
   string s; cin >> s;
   if(s.at(0) == 'M') {
     if(m == 0) count++;
     m++;
   }
   if(s.at(0) == 'A') {
     if(a == 0) count++;
     a++;
   }
   if(s.at(0) == 'R') {
     if(r == 0) count++;
     r++;
   }
   if(s.at(0) == 'C') {
     if(c == 0) count++;
     c++;
   }
   if(s.at(0) == 'H') {
     if(h == 0) count++;
     h++;
   }
 }

 ll ans=0;
 ans = ans + m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;

 cout << ans << endl;
}

 
 




Measured memory_bytes: 256
A,B,C,X,Y  = map(int,input().split())
price_1=A*X+B*Y

if X>Y:
	price_2=C*2*Y+(X-Y)*A
	price_3=C*X*2
else:
	price_2=C*2*X+(Y-X)*B
	price_3=C*Y*2

cheapest=price_1
if price_2<cheapest:
	cheapest=price_2
if price_3<cheapest:
	cheapest=price_3
print(cheapest)


Measured memory_bytes: 3060
#include <iostream>
#include <array>

int main() {
    int X, N;
    std::cin >> X >> N;
    std::array<bool, 102> p;
    for (auto&& e : p)
       e = true;
    for (int i=0; i<N; i++) {
        int tmp;
        std::cin >> tmp;
        p[tmp] = false;
    }
    int i = 0;
    while (0 <= X-i && X+i < p.size()) { // TODO
        if (p[X-i]) {
            std::cout << X-i << std::endl;
            return 0;
        } else if (p[X+i]) {
            std::cout << X+i << std::endl;
            return 0;
        }
        i++;
    }
    if (X-i < 0) {
        std::cout << X - i << std::endl;
        return 0;
    }
    if (X+i >= p.size()) {
        std::cout << X+1 << std::endl;
        return 0;
    }
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

constexpr int64_t maxN = 5000 * 5000;
int64_t dp[5][maxN + 1] = {};
// ナップサック問題を解く関数
int64_t solve(int64_t W, vector<int64_t> weight, vector<int64_t> value) {
  fill(dp[0], dp[0] + maxN, 0);
  fill(dp[1], dp[1] + maxN, 0);
  fill(dp[2], dp[2] + maxN, 0);
  fill(dp[3], dp[3] + maxN, 0);
  fill(dp[4], dp[4] + maxN, 0);
  if (weight.size() == 0) {
    return 0;
  }
  for (size_t i = 0; i < weight.size(); i++) {
    for (int w = 0; w <= W; w++) {
      if (w < weight[i]) {
        dp[i + 1][w] = dp[i][w];
      } else {
        dp[i + 1][w] = max(dp[i][w], dp[i + 1][w - weight[i]] + value[i]);
      }
    }
  }
  return dp[weight.size()][W];
}

int main() {
  int64_t N;
  int64_t gold[2], silver[2], bronze[2];
  cin >> N;
  cin >> gold[0] >> silver[0] >> bronze[0];
  cin >> gold[1] >> silver[1] >> bronze[1];
  vector<int64_t> weightAtoB;
  vector<int64_t> weightBtoA;
  vector<int64_t> valueAtoB;
  vector<int64_t> valueBtoA;
  if (gold[0] < gold[1]) {
    weightAtoB.push_back(gold[0]);
    valueAtoB.push_back(gold[1] - gold[0]);
  } else if (gold[0] > gold[1]) {
    weightBtoA.push_back(gold[1]);
    valueBtoA.push_back(gold[0] - gold[1]);
  }
  if (silver[0] < silver[1]) {
    weightAtoB.push_back(silver[0]);
    valueAtoB.push_back(silver[1] - silver[0]);
  } else if (silver[0] > silver[1]) {
    weightBtoA.push_back(silver[1]);
    valueBtoA.push_back(silver[0] - silver[1]);
  }
  if (bronze[0] < bronze[1]) {
    weightAtoB.push_back(bronze[0]);
    valueAtoB.push_back(bronze[1] - bronze[0]);
  } else if (bronze[0] > bronze[1]) {
    weightBtoA.push_back(bronze[1]);
    valueBtoA.push_back(bronze[0] - bronze[1]);
  }
  // 正の場合はA->Bの時に換金
  N += solve(N, weightAtoB, valueAtoB);
  // 負の場合はB->Aの時に換金
  N += solve(N, weightBtoA, valueBtoA);
  cout << N << endl;
  return 0;
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int W, H;
char c;
int main() {
    std::cin >> W >> H >> c;

    REP(i, H) {
        if(i == 0 || i == H-1) {
            std::cout << '+';
            REP(j, W-2) {
                std::cout << '-';
            }
            std::cout << '+';
        } else{
            std::cout << '|';
            REP(j, W-2) {
                if(i == H/2 && (j+1) == W/2) {
                    std::cout << c;
                } else {
                    std::cout << '.';
                }
            }
            std::cout << '|';
        }
        std::cout << std::endl;
    }
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    REP(i, 5) {
        ll x; cin >> x;
        if (x == 0) {
            cout << i+1 << "\n";
            return 0;
        }
    }

}


Measured memory_bytes: 3620
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
    int n, h;
    scanf("%d %d", &n, &h);
    int a[n], b[n+1];
    for(int i = 0; i < n; i++){
        scanf("%d %d", &a[i], &b[i]);
    }
    int dp[n+1];
    fill(dp, dp + n + 1, 0);
    b[n] = 0;
    sort(b, b + n);
    int mx = 0;
    for(int i = 0; i < n; i++){
        if (mx < a[i]) mx = a[i];
    }

    if (h % mx == 0) dp[0] += h / mx;
    else dp[0] = h / mx + 1;
    int throwing = 0;
    for(int i = 0; i < n; i++){
        throwing += b[n - i - 1];
        int d = h - throwing;
        if (d > 0){
            if (d % mx == 0) dp[i+1] += d / mx;
            else dp[i+1] += d / mx + 1;
        }
        dp[i+1] += i+1;
    }

    int ans = 1000000001;
    for(int i = 0; i <= n; i++){
        if (dp[i] < ans) ans = dp[i];
        // printf("%d\n", dp[i]);
    }
    
    printf("%d\n", ans);
    
    
}

Measured memory_bytes: 1280
if __name__ == "__main__":
    N = int(input())
    T = list(map(int, input().split()))
    M = int(input())
    data = []
    for x in range(M):
        p,x = map(int, input().split())
        p -= 1
        data.append([p, x])
    result = 2 ** 60
    for p,x in data:
        res = 0
        for i,t in enumerate(T):
            if (i == p):
                res += x
            else:
                res += t
        print (res)

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

int main() {
	char s;
	while (true) {
		cin >> s;
		if (s != 'Y') {
			cout << "No" << endl;
			break;
		}
		cin >> s;
		if (s != 'A') {
			cout << "No" << endl;
			break;
		}
		cin >> s;
		if (s != 'K') {
			cout << "No" << endl;
			break;
		}
		cin >> s;
		if (s != 'I') {
			cout << "No" << endl;
			break;
		}
		cout << "Yes" << endl;
		break;
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    if(b - a == c - b)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		StringBuilder builder = new StringBuilder();
		while (n-- > 0) {
			int a = scanner.nextInt();
			boolean[][] map = new boolean[a + 4][a + 4];
			for (int i = 0; i < a + 4; i++) {
				for (int j = 0; j < a + 4; j++) {
					if (i == 0 || j == 0 || i == a + 3 || j == a + 3) {
						map[i][j] = true;
					}
				}
			}
			int x = 2;
			int y = a + 1;
			int h = 0;
			int[][] dxy = { { 1, 0 }, { 0, -1 }, { -1, 0 }, { 0, 1 } };
			boolean flag = false;
			loop: while (true) {
				if (flag) {
					for (int i = 0; i < 4; i++) {
						if (i == h) {
							continue;
						}
						int py = y + dxy[i][0];
						int px = x + dxy[i][1];
						if (map[py][px]) {
							break loop;
						}
					}
				}
				flag = false;
				map[y][x] = true;
				if (h == 0) {
					if (map[y - 2][x]) {
						x++;
						h = 1;
						flag = true;
					} else {
						y--;
					}
				} else if (h == 1) {
					if (map[y][x + 2]) {
						y++;
						h = 2;
						flag = true;
					} else {
						x++;
					}
				} else if (h == 2) {
					if (map[y + 2][x]) {
						x--;
						h = 3;
						flag = true;
					} else {
						y++;
					}
				} else {
					if (map[y][x - 2]) {
						y--;
						h = 0;
						flag = true;
					} else {
						x--;
					}
				}
			}

			for (int i = 2; i < a + 2; i++) {
				for (int j = 2; j < a + 2; j++) {
					builder.append(map[i][j] ? '#' : ' ');
				}
				builder.append('\n');
			}
			if (n != 0) {
				builder.append('\n');
			}
		}
		System.out.print(builder);
	}
}

Measured memory_bytes: 17068
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	string S;
	cin >> S;
	string day[7] = { "SUN","MON","TUE","WED","THU","FRI","SAT" };


	for (int i = 0; i < 7; i++) {
		if (day[i] == S) {
			cout << 7 - i << endl;
		}
	}
	
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
//#include<vector>
#include<algorithm>


#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;
const int MAXN=1005;


int main(){
	#ifdef L_JUDGE
		freopen("in.txt","r",stdin);
//		freopen("out.txt","w",stdout);
	#endif
    char s1,s2;
    cin>>s1>>s2;
    if(s1!='H'){
        if(s2=='H')s2='D';
        else s2='H';
    }
    printf("%c\n",s2);

	#ifdef L_JUDGE
		fclose(stdin);
		fclose(stdout);
//		system("out.txt");
	#endif

	return 0;
}


Measured memory_bytes: 256
from collections import deque
N = int(input())

def dfs(str):
    if len(str) == N:
        print(*str, sep="")
        return

    M = max(str)

    for i in range(ord(M) - ord("a") + 2):
        char = alpha[i]
        str.append(char)
        dfs(str)
        str.pop()

alpha = 'abcdefghijklmnopqrstuvwxyz'
s = deque(["a"])
dfs(s)



Measured memory_bytes: 5864
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
 
int main()
{
    std::string s;
    int slong;
    bool ans[26];

    std::cin >> s;
    slong = s.length();
    for(int i = 0;i < 26;i++){
        ans[i] = false;
    }
    for(int i = 0;i < slong;i++){
        if(ans[s[i] - 'a'] == true){
            std::cout << "no";

            return 0;
        }
        ans[s[i] - 'a'] = true;
    }

    std::cout << "yes";

    return 0;
}

Measured memory_bytes: 256
/*
    Mbak Rose Dong
*/
#include<bits/stdc++.h>
using namespace std;
long long int weight[105], value[105];
long long int dp[100100];
int main()
{
    int n, i, j, k, curr, m, ans;
    int tc;
    int w;
    scanf("%d %d",&n,&w);
    for(i=1;i<=n;i++)
    {
        scanf("%lld %lld",&weight[i], &value[i]);
    }
    for(i=1;i<=100000;i++)
        dp[i] = 1e15;
    dp[0] = 0;
    for(i=1;i<=n;i++)
    {
        for(j=100000-value[i];j>=0;j--)
        {
            dp[j+value[i]] = min(dp[j+value[i]], dp[j] + weight[i]);
        }
    }
    for(i=100000;i>=0;i--)
    {
        if(dp[i] <= w)
        {
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.Scanner;

public class Main{
    public static boolean Odd(int a, int b)
    {
        for(int i=1;i<=3;i++)
        {
            if((a*b*i)%2!=0)
                return true;
        }
        return false;
    }
    public static void main(String []args) throws IOException
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(Odd(a,b)==true)
            System.out.println("Yes");
        else
            System.out.println("No");

    }
}

Measured memory_bytes: 22100
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


# 8近傍（右, 下, 左, 上，右上, 右下, 左下, 左上）
dy = [0, -1, 0, 1, 1, -1, -1, 1]
dx = [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y: int, x: int, H: int, W: int) -> bool:
    return 0 <= y < H and 0 <= x < W

def main():
    H, W = map(int, input().split())
    f = []
    for _ in range(H):
        S = input()
        f.append(S)

    ans = [[0] * W for _ in range(H)]
    for y in range(H):
        for x in range(W):
            if f[y][x] == "#":
                ans[y][x] = "#"
            else:
                n = 0
                for i in range(8):
                    ny = y + dy[i]
                    nx = x + dx[i]
                    if inside(ny, nx, H, W) and f[ny][nx] == "#":
                        n += 1
                ans[y][x] = str(n)

    for line in ans:
        print(*line, sep="")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
N, C, K = map(int, input().split(' '))
bus = []
ans = 0
T = [int(input()) for _ in range(N)]
T.sort()

min_t = 0
i = 0
while i < N:
    ans += 1
    start = i
    while i < N and T[i] - T[start] <= K and i - start < C:
        i += 1
print(ans)

Measured memory_bytes: 7420
import qualified Control.Arrow         as Arrow
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Char             as Char
import qualified Data.Vector           as V
import qualified Data.Vector.Unboxed   as VU

type Parser a = BSC8.ByteString -> Maybe (a, BSC8.ByteString)
parseInt :: Parser Int
parseInt = fmap (Arrow.second BSC8.tail) . BSC8.readInt
parse1 :: IO Int
parse1 = readLn
parse4 :: IO (Int, Int, Int, Int)
parse4 = (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2, vec VU.! 3)) . VU.unfoldrN 4 parseInt <$> BSC8.getLine
parseNM :: Int -> Int -> IO (V.Vector (VU.Vector Int))
parseNM n m = V.replicateM n $ VU.unfoldrN m parseInt <$> BSC8.getLine

main :: IO ()
main = do
  t    <- parse1
  nmab <- parseNM t 4
  putStr . unlines . map show . V.toList $ V.map sumOfFloorLinear nmab

sumOfFloorLinear :: VU.Vector Int -> Int
sumOfFloorLinear nmab = iter n m a b 0
  where
    n = nmab VU.! 0
    m = nmab VU.! 1
    a = nmab VU.! 2
    b = nmab VU.! 3
    iter :: Int -> Int -> Int -> Int -> Int -> Int
    iter p q r s ret
      | r >= q && s >= q = if y1 == 0 then ret1' else ret1'' + iter y1 a1 q ((a1 - x1 `mod` a1) `mod` a1) 0
      | r >= q && s <  q = if y2 == 0 then ret2' else ret2'' + iter y2 a2 q ((a2 - x2 `mod` a2) `mod` a2) 0
      | r <  q && s >= q = if y3 == 0 then ret3' else ret3'' + iter y3 a3 q ((a3 - x3 `mod` a3) `mod` a3) 0
      | otherwise        = if y4 == 0 then ret4' else ret4'' + iter y4 a4 q ((a4 - x4 `mod` a4) `mod` a4) 0
      where
        ret1  = ret + (p - 1) * p * (r `div` q)
        a1    = r `mod` q
        ret1' = ret1 + p * (s `div` q)
        b1    = s `mod` q
        y1    = (a1 * p + b1) `div` q
        x1    = y1 * q - b1
        ret1'' = ret1' + (p - (x1 + a1 - 1) `div` a1) * y1
        
        ret2' = ret + (p - 1) * p * (r `div` q) `div` 2
        a2    = r `mod` q
        b2    = s
        y2    = (a2 * p + b2) `div` q
        x2    = y2 * q - b2
        ret2'' = ret2' + (p - (x2 + a2 - 1) `div` a2) * y2

        ret3' = ret + p * (s `div` q)
        a3    = r
        b3    = s `mod` q
        y3    = (a3 * p + b3) `div` q
        x3    = y3 * q - b3
        ret3'' = ret3' + (p - (x3 + a3 - 1) `div` a3) * y3
        
        ret4' = ret
        a4    = r
        b4    = s
        y4    = (a4 * p + b4) `div` q
        x4    = y4 * q - b4
        ret4'' = ret4' + (p - (x4 + a4 - 1) `div` a4) * y4


Measured memory_bytes: 24840
#include <stdio.h>
#include <string.h>
typedef struct dice_st {
  char t; char b; char n; char e; char w; char s;
}dice;
char north(dice *d)
{
  char t;
  t = d->n; d->n = d->t; d->t = d->s; d->s = d->b; d->b = t;
  return d->t;
}
char south(dice *d)
{
  char t;
  t = d->s; d->s = d->t; d->t = d->n; d->n = d->b; d->b = t;
  return d->t;
}
char east(dice *d)
{
  char t;
  t = d->e; d->e = d->t; d->t = d->w; d->w = d->b; d->b = t;
  return d->t;
}
char west(dice *d)
{
  char t;
  t = d->w; d->w = d->t; d->t = d->e; d->e = d->b; d->b = t;
  return d->t;
}
char right(dice *d)
{
  char t;
  t = d->s; d->s = d->e; d->e = d->n; d->n = d->w; d->w = t;
  return d->t;
}
char left(dice *d)
{
  char t;
  t = d->s; d->s = d->w; d->w = d->n; d->n = d->e; d->e = t;
  return d->t;
}
void reset(dice *d)
{
  d->t = 1; d->s = 2; d->e = 3; d->w = 4; d->n = 5; d->b = 6;
}
int main()
{
  char buf[10];
  int n,s;
  dice d;
  for(;;){
    scanf("%d",&n);
    if(n == 0) break;
    reset(&d);
    s = 1;
    while(n > 0){
      scanf("%s",buf);
      if(strcmp(buf,"North") == 0){
	s += north(&d);
      }else if(strcmp(buf,"East") == 0){
	s += east(&d);
      }else if(strcmp(buf,"West") == 0){
	s += west(&d);
      }else if(strcmp(buf,"South") == 0){
	s += south(&d);
      }else if(strcmp(buf,"Right") == 0){
	s += right(&d);
      }else if(strcmp(buf,"Left") == 0){
	s += left(&d);
      }
      n--;
    }
    printf("%d\n", s);
  }
  return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (abs(a - c) <= d || (abs(a - b) <= d && abs(c - b) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pll pair<long long, long long >
#define ll long long
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define maxn 100000
#define endl '\n'
#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
int mod(int x,int y)
{
  int s;
  s = abs(x)/y;
  if(x<0)s--;
  return x-y*s;
}
int dir8[2][8] = {{1,-1,0,0,1,-1,1,-1},{0,0,1,-1,1,-1,-1,1}};
int dir4[2][4] = {{1,-1,0,0},{0,0,1,-1}};
ll m,n,row,col;
ll ara[3005];
ll memo[2][3005][3005];
ll dp(int t,int i,int j)
{
  if(i == j)
  {
    if(t == 0)return ara[i];
    return -ara[i];
  }
  ll p1,p2;
  if(memo[t][i][j]!=-1)return memo[t][i][j];
  if(t == 0)
  {
    p1 = ara[i] + dp(1,i+1,j);
    p2 = ara[j] + dp(1,i,j-1);
    return memo[t][i][j] =max(p1,p2);
  }
  else
  {
    p1 = -ara[i] + dp(0,i+1,j);
    p2 = -ara[j] + dp(0,i,j-1);
    return memo[t][i][j] = min(p1,p2);
  }
}
void solve()
{
  scanf("%lld",&n);
  memset(memo,-1,sizeof memo);
  for(int w=0;w<n;w++)scanf("%lld",&ara[w]);
  ll ans = dp(0,0,n-1);
  cout << ans << endl;

}
void test()
{
  int t;
  //scanf("%d",&t);
  t = 1;
  for(int test=1;test<=t;test++)
  {
    solve();
  }
}
int main()
{
  test();
  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

const int N=2e5+5;

int n;
int a[N], b[N];

int32_t main()
{
    IOS;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b+1, b+n+1);
    int mid1=b[n/2];
    int mid2=b[n/2 + 1];
    for(int i=1;i<=n;i++)
    {
        if(a[i]>=mid2)
        {
            cout<<mid1<<endl;
        }
        else
        {
            cout<<mid2<<endl;
        }
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;


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

    set<pii> bomb;
    vector<int> row_num(h, 0), col_num(w, 0);
    int h_, w_;
    for (int i = 0; i < m; ++i) {
        cin >> h_ >> w_;
        h_--; w_--;
        bomb.insert(pii(h_, w_));
        row_num[h_]++;
        col_num[w_]++;
    }

    int hmax = 0;
    int wmax = 0;
    for (int i = 0; i < h; ++i) {
        hmax = max(hmax, row_num[i]);        
    }
    for (int i = 0; i < w; ++i) {
        wmax = max(wmax, col_num[i]);
    }
    vector<int> row_max, col_max;
    for (int i = 0; i < h; ++i) {
        if (row_num[i] == hmax) row_max.push_back(i);
    }
    for (int i = 0; i < w; ++i) {
        if (col_num[i] == wmax) col_max.push_back(i);
    }
    
    for (int i = 0; i < row_max.size(); ++i) {
        for (int j = 0; j < col_max.size(); ++j) {
            if (bomb.count(pii(row_max[i], col_max[j])) == 0){
                cout << hmax + wmax << endl;
                return 0;
            }
        }
    }
    cout << hmax + wmax - 1 << endl;
}

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

const int64_t MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n,a,b,c;
  cin >> n >> a >> b >> c;
  
  int l[n] = {};
  for(int i=0;i<n;i++){
    cin >> l[i];
  }
  
  int pattern = 0;
  int aTotal, bTotal, cTotal;
  int minMp = 1000000000;
  for(int i=0;i<=pow(4,n);i++){
    int val = i;
    int mp = 0;
    aTotal = bTotal = cTotal = 0;
    for(int j=0;j<n;j++){
      int sel = (val>>(j*2)) & 3;
      switch(sel){
        case 1:
          aTotal += l[j];
          if(aTotal != l[j]){
            mp += 10;
          }
          break;
        case 2:
          bTotal += l[j];
          if(bTotal != l[j]){
            mp += 10;
          }
          break;
        case 3:
          cTotal += l[j];
          if(cTotal != l[j]){
            mp += 10;
          }
          break;
        default:
          break;
      };
    }
    if(aTotal==0 || bTotal==0 || cTotal==0) continue;
    mp += abs(a-aTotal);
    mp += abs(b-bTotal);
    mp += abs(c-cTotal);
    minMp = min(minMp,mp);
  }
  
  cout << minMp << endl;
  return 0;
}



Measured memory_bytes: 4020
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    s = [SS() for _ in range(N)]
    M = I()
    t = [SS() for _ in range(M)]

    cnt_s = collections.Counter(s)
    cnt_t = collections.Counter(t)
    ans = max([max(cnt_s[i] - cnt_t[i], 0) for i in (cnt_s.keys() | cnt_t.keys())])
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9972
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();//Aの入力
		int b = sc.nextInt();//Bの入力
		int c = sc.nextInt();//Bの入力
		for(int i = 1; i <= b; i++) {
			if((a * i) % b == c) {
				System.out.print("YES");
				break;
			}
			if(i == b) {
				System.out.print("NO");
			}
		}
	}
}


Measured memory_bytes: 21844
L, R = map(int, input().split())

if L == 0 or R-L >= 2019:
    ans = 0
else:
    ans = 10**18
    for i in range(L, R):
        for j in range(i+1, R+1):
            tmp = (i*j)%2019
            ans = min(ans, tmp)
            if not ans:
                break
print(ans)


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


void solve(long long N, long long M, std::vector<long long> H, std::vector<long long> A, std::vector<long long> B){
  unordered_map<int, bool> m;
  for (int i=0; i<N; i++) m[i] = true;

  for (int i=0; i<M; i++) {
    if (H[A[i]-1] <= H[B[i]-1]) m[A[i]-1] = false;
    if (H[B[i]-1] <= H[A[i]-1]) m[B[i]-1] = false;
  }

  int cnt = 0;
  for (int i=0; i<N; i++) if (m[i]) cnt++;
  cout << cnt << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(H), std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9732
#include "bits/stdc++.h"
using namespace std;

int main() {

	int n, k;
	cin >> n >> k;
	int r, s, p;
	cin >> r >> s >> p;
	string g;
	cin >> g;
	int po = 0;
	bool st[n];
	for (int i=0; i<n; i++) {
		if (i < k) {
			if (g[i] == 'r') po += p;
			if (g[i] == 'p') po += s;
			if (g[i] == 's') po += r;
			st[i] = 1;
		}
		else {
			if (g[i] == g[i-k]) {
				st[i] = !st[i-k];
				if (st[i]) {
					if (g[i] == 'r') po += p;
					if (g[i] == 'p') po += s;
					if (g[i] == 's') po += r;
				}
			}
			else {
				if (g[i] == 'r') po += p;
				if (g[i] == 'p') po += s;
				if (g[i] == 's') po += r;
				st[i] = 1;
			}
		}
	}
	
	cout << po << endl;
	
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
    using namespace std;
     
    int getdata(long long i){
      int ans = 0;
      while(i > 0){
        ans++;
        i = i / 10;
      }
      return ans;
    }
     
    int main(){
      long long n;
      cin >> n;
      int ans = INT_MAX;
      for(long long i = 1;i * i <= n;i++){
        if(n % i == 0){
          ans = min(ans,max(getdata(i),getdata(n/i)));
        }
      }
      cout << ans << endl;
      return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair

using namespace std;

const int N=1e5+5;
int n,m;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m;
    int cur=1;
    for(int i=1;i<=30;i++)
    {
        cur*=m;
        if(cur>n) return cout<<i,0;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.math.BigDecimal;

/**
 * Debt Hell<br/>
 * n を入力したとき、n 週間後の借金の残高を出力し終了するプログラム。n は 100 以下とします。 <br/>
 * 10 万円の借金に対し、一週間ごとに 5% の利子を借金に加え、さらに借金の 1,000 円未満を切り上げます。<br/>
 */
public class Main {
    public static void main(String args[]) throws IOException {
        //n週間の入力を取得
        int nWeeks = Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());
        
        int debt = 100000;
        for(int i = 0; i < nWeeks; i++) {
            //5％の利子を加え、1000円未満を切り上げ
            debt = new BigDecimal(debt * 1.05).setScale(-3, BigDecimal.ROUND_CEILING).intValue();
        }
        System.out.println(debt);

    }
} 

Measured memory_bytes: 17172
#include <bits/stdc++.h>
#define ll long long
#define lf double
#define E complex<lf>
#define eps 1e-9
#define inf 0x7fffffff
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define pa pair<int,int>
#define pb push_back
#define mod
#define FIO "problem"
#define N 100010
using namespace std;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
inline void fre() {
	freopen(FIO".in","r",stdin);
	freopen(FIO".out","w",stdout);
}
int n;
int num[N],opt[N];
ll sum;
int sta[N],top=0;
int main() {
	n=read();
	for (int i=1; i<n; i++) {
		num[i]=read(),sum+=num[i];
		char s[5];
		scanf("%s",s);
		if (s[0]=='-') opt[i]=-1;
		else opt[i]=1;
	}
	num[n]=read(),sum+=num[n];
	ll ans=-inf,hhh=0;
	for (int i=1; i<n; i++) if (opt[i]==-1) {
		ll tmp=sum;
		ll sum2=num[i+1];
		for (int j=i+1; j<n; j++) {
			if (opt[j]==1) sum2+=num[j+1];
			else break;
		}
		tmp-=2*(sum2+hhh);
		ans=max(ans,tmp);
		hhh+=num[i+1];
	}
	ans=max(ans,sum-2*hhh);
	cout << ans << endl;
}

Measured memory_bytes: 1024
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
def debug(k,v) puts "#{k}: #{v}" end
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

#$stdin = File.open('input.txt')
k = gi #10**6
ans = 0
now = 7
(10**6).times do
  ans += 1
  if (now%=k)==0
    puts ans
    exit
  end
  now = now*10+7
end
puts -1


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

int main()
{
  int a, b;
  cin >> a >> b;
  if (sqrt(pow(10, (int)log10(b)+1) * a + b) - (int)sqrt(pow(10, (int)log10(b)+1) * a + b) > 0.001)
  {
    cout << "No"
         << "\n";
  }
  else
  {
    cout << "Yes"
         << "\n";
  }

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <iomanip>

typedef long long ll;
typedef long double ld;

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

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)
#define ALL(a) (a).begin(),(a).end()

const ll inf = 1e18+7;
const ll mod = 1e9+7;

ll GetDigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(){
    ll N,M,acs=0,ps=0,p=0;
    cin >> N >> M;
    string S;
    vector<ll> fl(N,0);
    vector<ll> WA(N,0);
    rep(i,M){
        cin >> p >> S;
        if(fl[p-1]==0){
            if(S=="AC"){
                acs++;
                fl[p-1] = 1;
        }else{
            WA[p-1]++;
        }
    }
    }
    for(ll i=0;i<N;i++){
        if(fl[i]==1){
            ps+=WA[i];
        }
    }
    
        cout <<acs <<" "<< ps << endl;
    	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
bool ex[777][777];
int v[777][2];
int c[777];
bool checked[777];
int N,M;
void rec(int u, int col, int times){
  if(checked[u]){
    if(c[u]!=col){
      cout<<-1<<endl;
      exit(0);
    }
    return;
  }
  checked[u]=true;
  c[u]=col;
  v[times][col]++;
  FOR(i,1,N+1){
    if(u!=i&&!ex[u][i]){
      rec(i,col^1,times);
    }
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>N>>M;
  FOR(i,0,M){
    int a,b;
    cin>>a>>b;
    ex[a][b]=true;
    ex[b][a]=true;
  }
  int t=0;
  FOR(i,1,N+1){
    if(!checked[i]){
      rec(i,0,t);
    }
    t++;
  }
  bool dp[777][N+1];
  CLR(dp);
  dp[0][0] = true;
  FOR(t,0,707){
    FOR(i,0,N+1){
      if(dp[t][i]){
        // 0を選ぶ
        if(i+v[t][0]<=N) dp[t+1][i+v[t][0]] = true;
        // 1を選ぶ
        if(i+v[t][1]<=N) dp[t+1][i+v[t][1]] = true;
      }
    }
  }
  int ans = 1e9;
  FOR(i,1,N+1){
    if(dp[707][i]){
      int tmp = 0;
      int x = i;
      int y = N - i;
      if(x>0) tmp += x * (x - 1) / 2;
      if(y>0) tmp += y * (y - 1) / 2;
      ans = min(ans, tmp);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1280
// Created by Nikolay Budin

#ifdef DEBUG
#  define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define szof(x) ((int)x.size())
#ifndef LOCAL
#  define cerr __get_ce
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
#ifdef LOCAL
	mt19937 tw(9450189);
#else
	mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }


void solve() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> field(n, vector<int>(m));
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < m; ++j) {
			field[i][j] = s[j] == '#';
		}
	}

	vector<vector<int>> dp(n, vector<int>(m, INF));
	dp[0][0] = field[0][0];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (i) {
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + (field[i - 1][j] == 0 && field[i][j] == 1));
			}
			if (j) {
				dp[i][j] = min(dp[i][j], dp[i][j - 1] + (field[i][j - 1] == 0 && field[i][j] == 1));
			}

			// cerr << dp[i][j] << " ";
		}
		// cerr << endl;
	}

	cout << dp[n - 1][m - 1] << "\n";
}


int main() {
#ifdef LOCAL
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test_count = 1;
	// cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}

#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};




int main(){
  
  int n,m;
  ll res = 0;
  cin >> n >> m;
  vector<vector<int>> v(100000);
  REP(i,n){
    int x,y;cin >> x >> y;
    x--;
    v[x].push_back(y);
  }
  priority_queue<int,vector<int>,less<int>> que;
  
  REPD(i,m){
    for(auto au : v[m-i-1])que.push(au);
    if(que.empty())continue;
    res += que.top();que.pop();
  }
  cout << res << endl;



  


  return 0;
}


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <deque>
#include <unordered_map>
#include <unordered_set>

const int b = 1000000007;

int main(void)
{
  int N, M;
  std::cin >> N >> M;

  if(std::abs(N-M) >= 2){
    std::cerr << "no case" << std::endl;
    std::cout << 0 << std::endl;
    return 0;
  }

  long long pN = 1, pM = 1;

  for(int i = 1; i <= N; ++i){
    pN *= i;
    if(pN > b){
      pN = pN % b;
    }
  }
  for(int i = 1; i <= M; ++i){
    pM *= i;
    if(pM > b){
      pM = pM % b;
    }
  }

  std::cerr << pN << " " << pM << std::endl;

  if(std::abs(N-M) == 1){
    std::cout << (pN * pM) % b << std::endl;
    return 0;
  } else {
    std::cout << (pN * pM * 2) % b << std::endl;
    return 0;
  }
}


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

const int mxN = 1e5 + 1;

typedef long long int64;

int main() {
	int64 x;
	cin >> x;
	if(x == 1 || x == 0 || x == 2)
	{
		cout << "2\n";
		return 0;
	}
	for(int i = x; ; i++)
	{
		bool can = true;
		//cout << i << endl;
		if(i % 2 == 0) continue;
		for(int j = 3; j < i; j += 2)
		{
			if(i % j == 0)
			{
				can = false;
				break;
			}
		}
		if(can)
		{
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
    
n=I()
a=LI()

a.sort()

def check(n,a):
    if n%3!=0:
        if a[-1]==0 and a[0]==0:
            return True
        else:
            return False
    else:
        m=n//3
        c=a[0]
        for i in range(m):
            if a[i]!=c:
                k=0
                return False
        c=a[m]
        for i in range(m):
            if a[m+i]!=c:
                k=0
                return False
                
        c=a[2*m]    
        for i in range(m):
            if a[2*m+i]!=c:
                k=0
                return False
        if a[0]^a[m]==a[m*2]:
            return True
            
if check(n,a):
    k=0
else:
    k=1
ans=['Yes','No']

print(['Yes','No'][k])


Measured memory_bytes: 60784
#[allow(unused_macros)]
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(unused_macros)]
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(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        b: [usize; n - 1],
    }
    let mut a = vec![0; n];
    a[0] = b[0];
    a[n - 1] = b[n - 2];
    for i in 1..n-1 {
        a[i] = std::cmp::min(b[i - 1], b[i]);
    }
    let mut result = 0;
    for ai in a {
        result += ai;
    }
    println!("{}", result);
}


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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const ll mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    cout << (n + 1) / 2;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N,X,Y;
	cin>>N>>X>>Y;
	if(Y-X==0){
		cout<<"Borys"<<endl;
		return 0;
	}
	if((Y-X)%2==0)
		cout<<"Alice"<<endl;
	else
		cout<<"Borys"<<endl;
	
	return 0;
}

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

using namespace std;

typedef long long lint;

lint rez;

string s;

int main()
{
    cin >> s;

    int b = 0;
    for(int i = 0; i < s.size(); i ++)
    {
        if(s[i] == 'B')
            b ++;

        else
            rez += b;
    }

    cout << rez << "\n";

    return 0;
}


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

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        public static List<long> GeneratePrime(long max)
        {
            long prime;
            double sqrtMax = Math.Sqrt(max);
            var primeList = new List<long>();

            List<long> searchList = new List<long>();
            for (long i = 2; i <= max - 1; i++)
            {
                searchList.Add(i);
            }

            do
            {
                prime = searchList.First();
                primeList.Add(prime);
                searchList.RemoveAll(n => n % prime == 0);
            } while (prime < sqrtMax);

            primeList.AddRange(searchList);

            return primeList;
        }

        void Omame()
        {
            cin = new Scanner();
            long K = cin.nextLong();
            long X = cin.nextLong();

            if(500 * K >= X)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11220
MOD = 10**9+7

H, W, A, B = gets.split.map(&:to_i)

def power(base, exp, mod)
  return 1 if exp == 0
  return (base ** (exp % 2) * power(base, exp/2, mod) ** 2) % mod
end

fac = [1]
rfac = [power(fac[0], MOD-2, MOD)]

1.upto(H + W - 2) do |x|
    fac << fac[x-1] * x % MOD
    rfac << power(fac[x], MOD-2, MOD)
end

ans = 0

0.upto(H-A-1) do |hd|
    h1 = hd
    w1 = B-1
    h2 = H-hd-1
    w2 = W-B-1
    p1 = fac[h1 + w1] * rfac[h1] % MOD * rfac[w1] % MOD
    p2 = fac[h2 + w2] * rfac[h2] % MOD * rfac[w2] % MOD
    ans += p1 * p2 % MOD
end

puts ans % MOD

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

int main()
{
	long n = 0 , b = 0 , f = 0 , r = 0 , v = 0 ,room[4][3][10] = {};
	cin >> n ;
	for ( int i = 0 ; i < n ; i++ )
	{
		cin >> b >> f >> r >> v ;
		room[b-1][f-1][r-1] += v ;
	}
	for ( int i = 0 ; i < 4 ; i++ )
	{
		for ( int j = 0 ; j < 3 ; j++ )
		{
			for ( int k = 0 ; k < 10 ; k++ ) cout << " " << room[i][j][k] ;
			cout << endl ;
		}
		if ( i != 3 )cout << "####################" << endl ;
	}
	return 0;
}



Measured memory_bytes: 3100