akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

import static java.lang.Math.abs;
import static java.lang.Math.min;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    n = in.ni();
    k = in.ni();
    h = new int[n];
    for (int i = 0; i < n; i++) {
      h[i] = in.ni();
    }
    dp = new Integer[n];
    out.println(recurse(0));
  }
  
  private int n, k;
  private int[] h;
  private Integer[] dp;
  
  private int recurse(int idx) {
    if (idx == n - 1) return 0;
    
    if (dp[idx] != null) return dp[idx];
    
    int ans = Integer.MAX_VALUE;
    for (int jump = 1; jump <= k; jump++) {
      if (idx + jump < n) {
        ans = min(ans, abs(h[idx + jump] - h[idx]) + recurse(idx + jump));
      }
    }
    
    return dp[idx] = ans;
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

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

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

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

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


Measured memory_bytes: 53972
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int a, b, mina, maxa, minb, maxb, left, right;
    sc(a) sc(b)
    if (100 * a % 8 == 0) mina = 100 * a / 8;
    else mina = 100 * a / 8 + 1;
    if (100 * (a + 1) % 8 == 0) maxa = 100 * (a + 1) /8;
    else maxa = 100 * (a + 1) / 8 + 1;
    minb = 10 * b;
    maxb = 10 * (b + 1);
    left = max(mina, minb);
    right = min(maxa, maxb);
    if (left >= right || right < 2 || left < 1) cout << -1 << endl;
    else cout << left << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll P = 1e9+7;
const ll N = 2e6+7;

//Modifiable-DSU
//Using path compression and union by size

vector<ll> parent(N);
vector<ll> SS(N);
void initialize(ll node)
{
	parent.at(node) = node;
	SS.at(node) = 1;
}
ll find_parent(ll node)
{
	if(parent.at(node) == node) return node;
	return parent.at(node) = find_parent(parent.at(node));
}
void merge_set(ll a, ll b)
{
	a = find_parent(a);
	b = find_parent(b);

	if(a != b)
	{
		if(SS.at(a) < SS.at(b))
			swap(a,b);
		parent.at(b) = a;
		SS.at(a) += SS.at(b);
	}
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll t=1;
	// cin>>t;

	while(t--){
		ll n,q;
		cin>>n>>q;

		ll x,a,b;
		for(ll i=1;i<=n;++i) initialize(i);

		while(q--){
			cin>>x>>a>>b;
			++a, ++b;
			if(!x){
				merge_set(a,b);
			}
			else{
				ll x = find_parent(a) , y = find_parent(b);
				if(x == y) cout<<"1\n";
				else cout<<"0\n";
			}
			
		}

	}	

	return 0;
}	

Measured memory_bytes: 34500
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}


int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}


int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}


int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}


int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}


int main(){
  int n,k;
  cin>>n>>k;
  vector<int> h;
  lint dp[110000];
  for(int i=0;i<n;i++){
    int j;
    cin>>j;
    h.pb(j);
  }
  for(int i=0;i<110000;i++){
    dp[i]=INF;
  }
  
  dp[0]=0;
  for(int i=0;i<n;++i){
    for(int j=1;j<=k;++j){
      chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    }
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 1656
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>

typedef long long ll;
typedef std::vector< int > VI;

const double EPS = 1e-10;
const double PI  = acos(-1);
const ll     INF = 1 << 30;

int main(int argc, char* argv[])
{
  ll n;
  std::vector< ll > march(5, 0);

  std::cin >> n;
  for (ll i = 0; i < n; i++) {
    std::string str;
    std::cin >> str;
    if (str[0] == 'M') { march[0]++; }
    if (str[0] == 'A') { march[1]++; }
    if (str[0] == 'R') { march[2]++; }
    if (str[0] == 'C') { march[3]++; }
    if (str[0] == 'H') { march[4]++; }
  }

  ll size = march.size();
  ll cnt = 0;
  for (ll i = 0; i < size; i++) {
    for (ll j = i+1; j < size; j++) {
      for (ll k = j+1; k < size; k++) {
	//std::cout << march[i] << " " << march[j] << " " << march[k] << std::endl;
	cnt += march[i] * march[j] * march[k];
      }
    }
  }

  std::cout << cnt << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

ll n, a, ans, M=1e9+7, s[100005]={0,1};

ll pow(ll p, ll q) {
	ll re=1;
	while(q) {
		if(q&1) re = re * p % M;
		p = p * p % M;
		q >>= 1;
	}
	return re;
}

int main() {
	ll i;
	cin >> n;
	for(i=2; i<=n; i++) s[i] = (s[i-1] + pow(i, M-2)) % M;
	for(i=0; i<n; i++) {
		scanf("%lld", &a);
		ans += a * ((s[i+1] + s[n-i] - 1 + M) % M) % M;
	}
	for(i=1; i<=n; i++) (ans *= i) %= M;
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
N,M,X,Y =map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
Z='War'
for i in range(X+1,Y+1):

    if max(x)< i <= min(y) :

        Z='No War'

    else:

        continue

print(Z)


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	string s, t;
  	cin >> s >> t;
  	int n = s.size();
  	map<char, char> mp;
  	rep(i,n) {
      	auto iter = mp.find(s[i]);
      	if(iter == mp.end()) mp[s[i]] = t[i];
      	else if(mp[s[i]] != t[i]) {
        	puts("No");
          	return;
        }
    }
	
  	map<char, char> mpinv;
  	for(auto m:mp) {
      	auto iter = mpinv.find(m.second);
    	if(iter == mpinv.end()) mpinv[m.second] = m.first;
      	else if(mpinv[m.second] != m.first){
        	puts("No");
          	return;
        }
    }
  	puts("Yes");
  	return;
}

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

Measured memory_bytes: 916
#include <iostream>

using namespace std;

int main()
{
    int A,B;
    cin>>A>>B;

    if (A+B>A-B&&A+B>A*B){
        cout<<A+B<<endl;
    }
     else if (A*B>A+B&&A*B>A-B){
        cout<<A*B<<endl;
    }
    else {
        cout<<A-B<<endl;
    }


    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int sum = 0;
    
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;

}

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;

int n;
int x[200020], y[200020];
char u[200020];

void rotate(){
	for(int i = 0; i < n; i++){
		int nx = y[i], ny = 200000 - x[i];
		char nu;
		if(u[i] == 'U') nu = 'R';
		if(u[i] == 'R') nu = 'D';
		if(u[i] == 'D') nu = 'L';
		if(u[i] == 'L') nu = 'U';
		x[i] = nx; y[i] = ny; u[i] = nu;
	}
}
vector<vector<pair<int, char>>> par;
ll solve01(){
	ll ans = 1001001001;
	par.resize(400010);
	rep(i,400010) par.at(i).clear();
	for(int i = 0; i < n; i++){
		par.at(y[i]).push_back({x[i], u[i]});
	}
	for(int i = 0; i < 400001; i++){
		sort(par.at(i).begin(), par.at(i).end());
		for(int j = 0; j < (int)par.at(i).size() - 1; j++){
			if(!(par.at(i).at(j).second == 'R' && par.at(i).at(j+1).second == 'L')) continue;
			ans = min(ans, 5ll*(par.at(i).at(j+1).first - par.at(i).at(j).first));
		}
	}
	return ans;
}
vector<vector<pair<int, char>>> cro;
ll solve02(){
	ll ans = 1001001001;
	cro.resize(400010);
	rep(i,400010) cro.at(i).clear();
	for(int i = 0; i < n; i++){
		cro.at(x[i] + y[i]).push_back({x[i], u[i]});
	}
	for(int i = 0; i < 400001; i++){
		sort(cro.at(i).begin(), cro.at(i).end());
		for(int j = 0; j < (int)cro.at(i).size() - 1; j++){
			if(!(cro.at(i).at(j).second == 'R' && cro.at(i).at(j+1).second == 'U')) continue;
			ans = min(ans, 10ll*(cro.at(i).at(j+1).first - cro.at(i).at(j).first));
		}
	}
	return ans;
}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	cin >> n;
	rep(i,n) cin >> x[i] >> y[i] >> u[i];
	ll FA = 1001001001;
	for(int i = 0; i < 4; i++){
		FA = min(FA, solve01());
		FA = min(FA, solve02());
		rotate();
	}
	if(FA == 1001001001) cout << "SAFE" << endl;
	else cout << FA << endl;
} 

Measured memory_bytes: 45524
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; 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 ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    int n; cin >> n;
    vector<ll> a(n+1);
    REP(i,n+1) cin >> a[i];
    ll ans = 0;
    REP(i,n) {
        ll b; cin >> b;
        ans += min(a[i],b);
        b -= min(a[i],b);
        ans += min(a[i+1],b);
        a[i+1] -= min(a[i+1],b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, W; cin >> N >> W;
    long long value[100001] = {};
    for (int i = 0; i < N; i++) {
        int w, v; cin >> w >> v;
        for (int j = W - w; j >= 0; j--) {
            value[j + w] = max(value[j + w], value[j] + v);
        }
    }
    cout << value[W] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int i,n,hess,bell[100],riri=0,math=32;
  while(1){
    riri=0;
    cin >> n;
    if(n==0){
      break;
    }
    for(i=0;i<n;i++){
      cin >> bell[i];
    }
    hess=i;
    while(1){
      math-=(math-1)%5;

      if(math<0){
	math=0;
      }
      cout << math << endl;
      if(math<=0){
	math=32;
	break;
      }
      math-=bell[riri];
      riri++;

      if(math<0){
	math=0;
      }
      cout << math << endl;
      if(riri==hess){
	riri=0;
      }
      if(math<=0){
	math=32;
	break;
      }
    }
  }
  return (0);
}

Measured memory_bytes: 1160
def createMatrix():
    matrix = [[INFTY] * n for i in range(n)]
    for i in range(n):
        u, k, *v = map(int, input().split())
        for j in range(0, k*2, 2):
            matrix[i][v[j]] = v[j+1]
    return matrix

def dijkstra():
    d[0] = 0
    p[0] = -1

    while True:
        mincost = INFTY
        # cost が最小の node を選択
        for i in range(n):
            if status[i] != VISITED and d[i] < mincost:
                mincost = d[i]
                u = i

        if mincost == INFTY:
            break

        status[u] = VISITED

        # u と v をつなぐ edge のうち最小の経路のコストの合計に更新
        for v in range(n):
            if status[v] != VISITED and matrix[u][v] != INFTY:
                if d[u] + matrix[u][v] < d[v]:
                    d[v] = d[u] + matrix[u][v]
                    p[v] = u
                    status[v] = VISITING

import sys
# sys.stdin = open('input.txt')

n = int(input())
NOT_VISITED = 0 # WHITE
VISITING = 1 # GRAY
VISITED = 2 # BLACK
INFTY = 10**21

matrix = createMatrix()
status =  [NOT_VISITED] * n
d = [INFTY] * n
p = [-1] * n

dijkstra()

for i in range(n):
    print(i, d[i])


Measured memory_bytes: 5752
#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int64_t read_int() {
    int64_t ret = 0, sgn = 1;
    int ch = getchar_unlocked();
    while (isspace(ch)) { ch = getchar_unlocked(); }
    if (ch == '-') { sgn = -1; ch = getchar_unlocked(); }
    for (; isdigit(ch); ch = getchar_unlocked())
        ret = (ret * 10) + (ch - '0');
    ungetc(ch, stdin);
    return sgn * ret;
}

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()

template <typename T> inline void assign_min(T& x, const T& value) noexcept { x = min(x, value); }
template <typename T> inline void assign_max(T& x, const T& value) noexcept { x = max(x, value); }

constexpr char LF = '\n';

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

int main() {
    auto X = read_int();
    for (int64_t A = -118; A <= 119; ++A) {
        for (int64_t B = -119; B <= 119; ++B) {
            if (A*A*A*A*A - B*B*B*B*B == X) {
                cout << A << " " << B << LF;
                return 0;
            }
        }
    }
}


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

using namespace std;

int main(){
	int a, b, c, d, e, f, raa = 0, rbb = 0, rcc = 0, rdd = 0, maxdn = 0, maxdd = 0;
	cin >> a >> b >> c >> d >> e >> f;
	for(long iaa = 0; iaa * a * 100 <= f; iaa++){
		for(long ibb = 0; ibb * b * 100 <= f; ibb++){
			for(long icc = 0; icc * c <= f; icc++){
				for(long idd = 0; idd * d <= f; idd++){
					if(iaa * a * 100 + ibb * b * 100 + icc * c + idd * d <= f){
						if((iaa * a + ibb * b) * e >= (icc * c + idd * d)){
							if((iaa * a + ibb * b) * maxdn <= (icc * c + idd * d) * maxdd){
								maxdn = (icc * c + idd * d);
								maxdd = (iaa * a + ibb * b);
								raa = iaa;
								rbb = ibb;
								rcc = icc;
								rdd = idd;
							}
						}
					}
				}		
			}		
		}		
	}
	cout << (raa * a * 100 + rbb * b * 100 + rcc * c + rdd * d) << " " << (rcc * c + rdd * d);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef complex<double> P;
#define EPS (1e-6)

P readP() {
    double x, y;
    scanf("%lf%lf", &x, &y);
    return P(x, y);
}

double radius(const vector<P>& ps) {
    P p = P(0, 0);
    double cur = 1.0;
    rep (dep, 30) {
        rep (_, 20) {
            double mx = norm(ps[0]-p);
            int ix = 0;
            rep (i, ps.size()) {
                const double d = norm(ps[i]-p);
                if (mx < d) mx = d, ix = i;
            }
            p += cur*(ps[ix]-p);
        }
        cur *= 0.5;
    }
    double ans = 0;
    rep (i, ps.size()) ans = max(ans, abs(ps[i]-p));
    return ans;
}

int n, m;
double rs[128], ts[128];
bool used[128];

bool can(int k) {
    vector<double> a, b;
    rep (i, n) if (!used[i]) a.push_back(rs[i]);
    rep (i, m) if (i >= k) b.push_back(ts[i]);
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    rep (i, b.size()) if (b[i] > a[i]+EPS) return false;
    return true;
}

int main() {
    scanf("%d%d", &n, &m);
    rep (i, n) scanf("%lf", rs+i);
    rep (i, m) {
        int K;
        scanf("%d", &K);
        vector<P> ps;
        rep (_, K) ps.push_back(readP());
        ts[i] = radius(ps);
    }
    if (!can(0)) puts("NG");
    else {
        rep (k, m) rep (i, n) if (!used[i] && ts[k] <= rs[i]+EPS) {
            used[i] = 1;
            if (can(k+1)) { printf("%d\n", i+1); break; }
            used[i] = 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1120
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n,k = map(int,input().strip().split())
    sunuke = [1 for i in range(n)]
    for i in range(k):
        x = int(input().strip())
        a = list(map(int, input().strip().split()))
        for j in a:
            sunuke[j-1] = 0
    print(sum([sunuke[i]==1 for i in range(n)]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 78492
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    vector<int> v(1 << n);
    rep(i,0,1<<n) cin >> v[i];

    rep(c,0,n) {
        for(size_t i=0; i<v.size(); i+=2) {
            if(v[i] < v[i+1]) {
                v[i+1] -= v[i];
                v[i]    =   -1;
            }
            if(v[i] > v[i+1]) {
                v[i]  -= v[i+1];
                v[i+1] = -1;
            }
        }
        v.erase(remove(v.begin(), v.end(), -1), v.end());
    }
    cout << v[0] << endl;
    return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
long long n,p,a[1000],b[1000],c[1000],d[1000],cnt;
vector<long long>v1,v2;
int main(){
	cin>>n>>p;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n;i++)cin>>c[i];
	for(int i=0;i<n;i++)cin>>d[i];
	for(int i=0;i<n*n;i++){v1.emplace_back(a[i/n]+b[i%n]);v2.emplace_back(c[i/n]+d[i%n]);}
	sort(v2.begin(),v2.end());
	for(int i=0;i<(int)v1.size();i++){  
		long long pos1=lower_bound(v2.begin(),v2.end(),p-v1[i])-v2.begin();
		long long pos2=lower_bound(v2.begin(),v2.end(),p-v1[i]+1)-v2.begin();
		cnt+=(pos2-pos1);
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 18868
import java.util.Scanner;

public class Main{
	static public void  main(String[] args){
		Scanner scan = new Scanner(System.in);

		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		if(c <= a + b) {
			System.out.println(b+c);
		}else{
			long _c = (a + b + 1 <= c)?  a + b + 1 : c;
			System.out.println(b + _c);
		}
	}
}


Measured memory_bytes: 21716
x = int(input())
prim = x
flag = True

while(flag):
  if x==2:
    break
  for j in reversed(range(2, x)):
    if x % j == 0:
      #print('{} is not prime.'.format(x))
      flag = True
      break
    else:
      prim = x
      flag = False
  x += 1
print(prim)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}


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

ll calc(ll x) {
	if (x == 0)return 0;
	return 2 * calc(x / 2)+1;
}
void solve() {
	ll h; cin >> h;
	cout << calc(h) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	//while (cin >> n, n)solve();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 16640
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;


int main() {
	int n, x, t;
	cin >> n >> x >> t;

	int m = n / x * t;
	if (n % x != 0) {
		m += t;

	}

	cout << m << endl;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());

		System.out.println(b / a <= c ? b / a : c);

	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
constexpr i64 INF = 1LL << 60;

struct edge {
	int to;
	i64 cost;
	edge(int t, i64 c) : to(t), cost(c) {}
};

vector<edge> g[100000];

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

	int n, a, b, q, k, x, y; cin >> n;
	i64 c;
	rep(i, 0, n - 1) {
		cin >> a >> b >> c;
		--a, --b;
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	cin >> q >> k;
	--k;

	queue<int> que;
	vector<i64> dist(n, INF);
	que.emplace(k);
	dist[k] = 0;
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (edge e : g[v]) {
			if (dist[e.to] == INF) {
				que.emplace(e.to);
				dist[e.to] = e.cost + dist[v];
			}
		}
	}

	rep(i, 0, q) {
		cin >> x >> y;
		--x, --y;
		cout << dist[x] + dist[y] << '\n';
	}
	return 0;
}

Measured memory_bytes: 11624
#include <stdio.h>
#include <set>
int n, k;
std::set<int> x;
int main()
{
	scanf("%d%d", &n, &k);
	while (k--)
	{
		int d;
		scanf("%d", &d);
		while (d--)
		{
			int a;
			scanf("%d", &a);
			x.insert(a);
		}
	}
	printf("%d\n", n - x.size());
	return 0;
}

Measured memory_bytes: 3280
#include <stdio.h>

int main() {
	int H, W, D;
	int A[350][350];
	int s[100050][2];
	int Q;
	int LR[100050][2];
	int turn[100000] = {};
	int i, j;
	int MP;

	for (i = 0; i < 330; i++)
	{
		for (j = 0; j < 330; j++)
		{
			A[i][j] = 0;
		}
	}

	for (i = 0; i < 100040; i++)
	{
		s[i][0] = 0;
		s[i][1] = 0;
		LR[i][0] = 0;
		LR[i][1] = 0;
	}

	scanf("%d%d%d", &H, &W, &D);

	for (i = 0; i < H; i++)
	{
		for (j = 0; j < W; j++)
		{
			scanf("%d", &A[i][j]);
			s[A[i][j]][0] = i;
			s[A[i][j]][1] = j;
		}
	}

	scanf("%d", &Q);


	for (i = 0; i < Q; i++)
	{
		scanf("%d", &LR[i][0]);//開始時の数

		scanf("%d", &LR[i][1]);//終了時の数
	}
	for (int i = D+1; i <= H*W; i++) {
		MP = 0;
		
		if (s[i][0] >= s[i-D][0])
		{
			MP = MP + s[i][0] - s[i-D][0];
		}
		else
		{
			MP = MP + s[i-D][0] - s[i][0];
		}

		if (s[i][1] >= s[i-D][1])
		{
			MP = MP + s[i][1] - s[i-D][1];
		}
		else
		{
			MP = MP + s[i-D][1] - s[i][1];
		}

		turn[i] = turn[i - D] + MP;
	}

	for (i = 0; i < Q; i++)//Q回の試験
	{
		MP = turn[LR[i][1]]-turn[LR[i][0]];
		

		printf("%d\n", MP);

	}

	return 0;
}

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

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	int a[n];
	map<int, int> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		m[a[i]]++;
	}
	long long count = 0;;
	for (auto& e : m) {
		if (e.second >= 2) {
			count += (long long)e.second * ((long long)e.second-1)/2;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << count - (m[a[i]]-1) << endl;
	}
	return 0;
}

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

int main(int argc, char *argv[]) {
  int a;
  string s;

  cin >> a >> s;
  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
  return 0;
}


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

int main(){
    string n;
    cin >> n;
    if(n=="RRR") cout << 3 <<endl;
    else if(n=="SSS") cout << 0 << endl;
    else if(n=="RRS" || n=="SRR") cout << 2 << endl;
    else cout << 1 << endl;

    return 0;
}

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

int main() {
  int n,i;
  char c;
  cin >> n;
  for(i=0; i<n; i++){
    cin >> c;
    if(c=='Y'){
      cout << "Four"; return 0;
    }
  }
  cout << "Three"; 
}

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

ll n,k;

double win(int i){
  double p = 1;
  while(i < k) {
    p /= 2;
    i *= 2;
  }
  return p;
}

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

  double ans = 0;
  for(int i = 1; i <=n; i++){
    ans += win(i)/n;
  }
  printf("%.12f\n",ans);
}


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

bool input(int& mid_score, int& fin_score, int& mu_score);
std::string gradeing(int mid_score, int fin_score, int mu_score);
void output(std::vector<std::string> grade);

int main()
{
	int mid_score, fin_score, mu_score;
	std::vector<std::string> grade;

	while (input(mid_score, fin_score, mu_score))
	{
		grade.emplace_back(gradeing(mid_score,fin_score, mu_score));
	}

	output(grade);
	
	return 0;
}

bool input(int& mid_score, int& fin_score, int& mu_score)
{
	std::cin >> mid_score >> fin_score >> mu_score;

	if (mid_score == -1 && fin_score == -1 && mu_score == -1)
	{
		return false;
	}
	else
	{
		return true;
	}
}

std::string gradeing(int mid_score, int fin_score, int mu_score)
{
	std::string score = "";
	int sum_score = mid_score + fin_score;

	if (mid_score == -1 || fin_score == -1)
	{
		score = "F";
	}
	else if (sum_score < 30)
	{
		score = "F";
	}
	else if (sum_score >= 80)
	{
		score = "A";
	}
	else if (sum_score >= 65)
	{
		score = "B";
	}
	else if (sum_score >= 50)
	{
		score = "C";
	}
	else if (sum_score >= 30 && mu_score >= 50)
	{
		score = "C";
	}
	else if (sum_score >= 30)
	{
		score = "D";
	}
	
	return score;
}

void output(std::vector<std::string> grade)
{
	for (auto student : grade)
	{
		std::cout << student << std::endl;
	}
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=1e5+10;
int f[mx];
vector<int>g[mx];
void dfs(int u,int pu=0){
  f[u]=0;
  for(int v:g[u])if(v!=pu){
    dfs(v,u);
    f[u]^=f[v];
  }
  f[u]++;
}
int main(){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n-1;i++){
    int u,v;
    scanf("%d %d",&u,&v);
    g[--u].push_back(--v);
    g[v].push_back(u);
  }
  dfs(0);
  int x=0;
  for(int v:g[0])x^=f[v];
  if(x==0)puts("Bob");
  else puts("Alice");

  return 0;
}


Measured memory_bytes: 12288
fun main(args: Array<String>) {
    tenka12019beginnerc()
}

fun tenka12019beginnerc() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    var leftSharp = 0
    var rightPeriod = s.count { it == '.' }
    var answer = leftSharp + rightPeriod
    for (i in 0..s.lastIndex) {
        if (s[i] == '#') leftSharp++ else rightPeriod--
        val count = leftSharp + rightPeriod
        answer = Math.min(answer, count)
    }

    println(answer)
}


Measured memory_bytes: 34656
#include <bits/stdc++.h>
#define nmax 10005
using namespace std;
ifstream f("aranjare3.in");
ofstream g("aranjare3.out");
unsigned long long n,m;
int main()
{
    cin>>n>>m;
    cout<<min(n%m,m-n%m);
    return 0;
}


Measured memory_bytes: 256
def div2(h, w):
    if h % 2 == 0 or w % 2 == 0:
        return [h * w // 2] * 2
    if h > w:
        h, w = w, h
    return [h * (w - 1) // 2, h * (w + 1) // 2]


def solve(h, w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    d1 = w // 3
    areas1 = sorted([h * d1] + div2(h, w - d1))
    ans1 = areas1[-1] - areas1[0]
    d1 += 1
    areas2 = sorted([h * d1] + div2(h, w - d1))
    ans2 = areas2[-1] - areas2[0]

    d2 = h // 3
    areas3 = sorted([d2 * w] + div2(h - d2, w))
    ans3 = areas3[-1] - areas3[0]
    d2 += 1
    areas4 = sorted([d2 * w] + div2(h - d2, w))
    ans4 = areas4[-1] - areas4[0]

    return min(ans1, ans2, ans3, ans4)


print(solve(*map(int, input().split())))


Measured memory_bytes: 3188
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(K, inputs):
    balls = string_to_int(inputs[0])
    distance = 0
    for b in balls:
        if b > abs(b - K):
            distance += abs(b - K) * 2
        else:
            distance += b * 2
    return distance


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    K = int(input())
    ret = solve(K, inputs(1))
    print(ret)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#define mod 1000000007
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define srep(i,s,t) for (ll i = s; i < t; i++)
#define drep(i,n) for(ll i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef vector<vector<char>> field_t;
typedef unsigned long long ull;
typedef pair<ll, ll> point_t;


int main()
{
    ll n;
    cin >> n;
    if(n%1000!=0){
        cout<<1000-(n%1000)<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}

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

    public class Program
    {
        public static void Main(string[] args)
        {
            new A().test();
        }
    }

	public class A
	{
		public void test()
		{
			// 普通の文字列
			var input = CommonRead.ReadStr();

			if(input == "ABC")
			{
				Console.WriteLine("ARC");
			}
			else
			{
				Console.WriteLine("ABC");
			}


		}
	}


static class CommonRead
{
    public static string ReadStr()
    {
        return Console.ReadLine();
    }
    public static string[] ReadStrA()
    {
        return ReadStr().Split(' ');
    }
    public static List<string> ReadStrL()
    {
        return ReadStrA().ToList();
    }
    public static int ReadInt()
    {
        return Convert.ToInt32(ReadStr());
    }
    public static int[] ReadIntA()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray();
    }
    public static List<int> ReadIntL()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToList();
    }
    public static long ReadLong()
    {
        return Convert.ToInt64(ReadStr());
    }
    public static long[] ReadLongA()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray();
    }
    public static List<long> ReadLongL()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToList();
    }

    public static decimal ReadDecimal()
    {
        return Convert.ToDecimal(ReadStr());
    }
    public static decimal[] ReadDecimalA()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray();
    }
    public static List<decimal> ReadDecimalL()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList();
    }

    public static double ReadDouble()
    {
        return Convert.ToDouble(ReadStr());
    }
    public static double[] ReadDoubleA()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray();
    }
    public static List<double> ReadDoubleL()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToList();
    }

}


Measured memory_bytes: 25812
// J4180449 三宅亮輔
// 問題名
// - Area of Polygon
// 問題URL
// - https://onlinejudge.u-aizu.ac.jp/problems/0079
// 所要時間
// - 40分
// 学んだこと
//  最初はコンマの存在に気づかず謎に0という結果が出て苦労した
//  ライブラリがあれば便利だと思った
//  ヘロンの公式を恥ずかしながら忘れかけていて焦った。

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

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

int n;

vector<P> p;

// double nijo(double a) { return a * a; }

// double dist(P a, P b) {
//     return sqrt(nijo(a.first - b.first) + nijo(a.second - b.second));
// }

// double pm(P a, P b, P c) {
//     P x = P(b.first - a.first, b.second - a.second);
//     P y = P(c.first - a.first, c.second - a.second);

//     if(x.first * y.second - x.second * y.second > 0)
//         return -1;
//     else
//         return 1;
// }
// double calc(P a, P b, P c) {
//     double x = dist(a, b);
//     double y = dist(b, c);
//     double z = dist(c, a);
//     double s = (x + y + z) / 2;

//     return sqrt(s * abs(s - x) * abs(s - y) * abs(s - z)) * pm(a, b, c);
// }

double det(P p1, P p2) { return p1.first * p2.second - p1.second * p2.first; }

int main() {

    int n;
    double x, y;
    cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> x >> y;
        p.push_back(P(x, y));
    }

    for(int i = 1; i < n; i++) {
        p[i] = P(p[i].first - p[0].first, p[i].second - p[0].second);
    }

    double ans = 0;
    for(int i = 1; i + 1 < n; i++) {
        ans += (det(p[i], p[i + 1]) / 2);
    }
    printf("%.1f\n", ans);
}



Measured memory_bytes: 3284
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

typedef priority_queue<int, vector<int>, greater<int>> priority_queue_asc;

int main() {
    long long N;
    cin >> N;

    string ans;
    while (N > 0) {
        long long n = N % 26;
        // cout << "* " << n << endl;
        if (n == 0) {
            n = 26;
        }
        ans.push_back('a' + n - 1);
        if (n == 26) {
            N = N / 26 - 1;
        } else {
            N = N / 26;
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3064
import sys

for S in sys.stdin:
    break
S = S.strip()
le = len(S)

mod = 10**9 + 7

mo = 1

dp = ([1]*10 if S[-1] == "?" else [int(x == int(S[-1])) for x in range(10)]) + [0]*3

i = 1
while i != le:
    mo = (mo * 10)%13
    a = [0]*13
    if S[-i-1] == "?":
        j = 0
        while j != 10:
            k = 0
            while k != 13:
                a[(k+mo*j)%13] += dp[k]
                a[(k+mo*j)%13] %= mod
                k += 1
            j += 1
    else:
        j = int(S[-i-1])
        k = 0
        while k != 13:
            a[(k+mo*j)%13] += dp[k]
            a[(k+mo*j)%13] %= mod
            k += 1
    dp = a
    i += 1

print(dp[5])

Measured memory_bytes: 42476
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,j,k,cnt(5),ans
    character(10),allocatable:: s(:)
    character(5),parameter:: march = 'MARCH'
    character(1):: initial
    logical:: change

    read*, n
    allocate(s(n))
    cnt(:) = 0
    do i=1,n
        read*, s(i)
        initial = s(i)(1:1)
        do j=1,5
            if (initial == march(j:j)) then
                cnt(j)=cnt(j)+1
                exit
            end if
        end do
    end do
    change=.true.
    do while(change)
        change=.false.
        do i=1,4
            if (cnt(i) < cnt(i+1)) then
                change=.true.
                call swap(cnt(i),cnt(i+1))
            end if
        end do
    end do

    ans=0
    do i=1,3
        do j=i+1,4
            do k=j+1,5
                ans=ans+cnt(i)*cnt(j)*cnt(k)
            end do
        end do
    end do
    print'(i0)', ans
contains
subroutine swap(x,y)
    integer(int64):: x,y,t
    t=x;x=y;y=t
end subroutine
end program name

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  int count = 1;
  for(int i=1;i<N;i++){
    if(d.at(i-1) != d.at(i)){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)((n>>m)&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)


ll ans;
int main(){
	int n;
	scanf("%d",&n);
	rep(i,1,262200){
		ll a[99];
		ll t=i,cnt=0,f=0;
		while(t){
			a[cnt++]=t%4;
			f|=1LL<<(t%4);
			t/=4;
		}
		if(f!=14)continue;
		ll ss=0;
		for(int j=cnt-1;j>=0;j--)ss=ss*10+(a[j]==1?3:a[j]==2?5:7);
		if(ss>n)break;
		ans++;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
package main

import "fmt"

const m = 1000000007

func comb(n, k int) int {
	if k < 1 || k > n {
		return 0
	}
	nu, de := 1, 1
	for i := 0; i < k; i++ {
		nu = nu * (n - i) % m
		de = de * (i + 1) % m
	}
	return nu * repSquare(de, m-2) % m
}

func repSquare(n, p int) int {
	if p == 0 {
		return 1
	}
	if p%2 == 0 {
		t := repSquare(n, p/2)
		return t * t % m
	}
	return n * repSquare(n, p-1) % m
}

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

	all := repSquare(2, n)

	ca := comb(n, a)
	cb := comb(n, b)
	ans := all - 1 - (ca + cb)

	ans = (ans%m + m) % m // negative mod -> positive mod
	fmt.Println(ans)
}


Measured memory_bytes: 512
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)    (x).begin(),(x).end()
# define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
# define mp        make_pair
# define eb        emplace_back
# define REP(i, a) for (int i = 0; i < (a); i++)
# define INIT      std::ios::sync_with_stdio(false);std::cin.tie(0);


int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int ans;
	if (a < 0) {
		ans = -1 * a * c + d + b * e;
	}
	else {
		ans = (b - a) * e;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3096
/*
First, solve the problem.Then write the code. - John Johnson
@author: returnAC
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define need_for_speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // Thanks Joshua :)
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);

signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	need_for_speed;
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(),a.end());
	int res = a[n/2]-a[n/2-1];
	cout<<res<<endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int H,W,K;

const int INF = INT_MAX;

//-------------------------------------------------
//--Grid BFS
//-------------------------------------------------

template<typename T>
vector<vector<int> > gBFS(int si, int sj, vector<T> &field)
{
    int dx[]={0,1,0,-1};
    int dy[]={1,0,-1,0};
    int h = field.size();
    int w = field[0].size();
    using P = pair<int,int>;
    queue<P> que;
    que.emplace(si,sj);
    vector<vector<int> > dist(h,vector<int>(w,INF));
    dist[si][sj] = 0;
    while(que.size()){
        int x,y;
        tie(y,x) = que.front(); que.pop();
        for(int i=0; i<4; i++){
            FOR(j,1,K){
                int tx = x+j*dx[i];
                int ty = y+j*dy[i];
                if (!(0<=tx&&tx<w&&0<=ty&&ty<h)) break;
                if (field[ty][tx]=='@') break;
                if (dist[ty][tx]<dist[y][x]+1) break;
                if (dist[ty][tx]!=INF) continue;
                dist[ty][tx] = dist[y][x]+1;
                que.emplace(ty,tx);
            }
        }
    }
    return dist;
}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>H>>W>>K;
    int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
    vector<string> f(H);
    rep(i,H) cin>>f[i];
    auto dist = gBFS(x1-1,y1-1,f);
    // rep(i,H){
    //     rep(j,W){
    //         if (dist[i][j]!=INF){
    //             cout<<dist[i][j]<<" ";
    //         }else{
    //             cout<<"I ";
    //         }
    //     }cout<<endl;
    // }
    if (dist[x2-1][y2-1]!=INF){
        cout<<dist[x2-1][y2-1]<<endl;
    }else{
        cout<<"-1\n";
    }
    return 0;
}


Measured memory_bytes: 12164
s = input()
t = input()
d_s = dict()
d_t = dict()
for i in range(len(s)):
  if not s[i] in d_s:
    d_s[s[i]] = t[i]
  elif d_s[s[i]] != t[i]:
    print('No')
    exit()
  if not t[i] in d_t:
    d_t[t[i]] = s[i]
  elif d_t[t[i]] != s[i]:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3632