akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
ll dp[110][10] = {};

bool pairsCheck(int k, int w){
	for (int i = 0; i < 1 << (w - 1); i++) {
		if((k >> i) & 1 && (k >> (i + 1)) & 1) return true;
	}
	return false;
}

void solve() {

    int H, W , K;
	cin >> H >> W >> K;

	dp[0][1] = 1;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			int cntm = 0, cnt = 0, cntp = 0;
			for (int k = 0; k < 1 << (W - 1); k++) {
				if(pairsCheck(k,W)) continue;
				if(j >= 2 && (k >> (j - 2)) & 1) cntm++;
				else if(j >= 1 && (k >> (j - 1)) & 1) cntp++;
				else cnt++;
			}
			dp[i][j] += (cntm * dp[i-1][j-1]) % MOD;
			dp[i][j] += (cnt * dp[i-1][j]) % MOD;
			dp[i][j] += (cntp * dp[i-1][j+1]) % MOD;
		}
	}

	cout <<dp[H][K] % MOD<< endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

void bubbleSort(int A[], int N){
    int sw = 0;     // 交換回数を表す変数
    int flag = 1;
    int i = 0;
    while(flag == 1){
        flag = 0;
        for(int j=N-1; j>i; j--){
            if(A[j] < A[j-1]){
                swap(A[j], A[j-1]);
                flag = 1;
                sw++;
            }
        }
        i++;
    }
    // 出力
    rep(k,N){
        cout << A[k];
        if(k != N-1) cout << " ";
    }cout << endl;
    cout << sw << endl;
}

int main()
{
    int N; cin >> N;
    int A[N];
    rep(i,N){
        int Ai; cin >> Ai;
        A[i] = Ai;
    }
    bubbleSort(A, N);
}



Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int x; cin >> x;
  cout << (x < 1200 ? "ABC\n" : "ARC\n");
  return 0;
}


Measured memory_bytes: 256
// ※※※ 解答不能 ※※※
// Rubikun氏.
// https://atcoder.jp/contests/abc147/submissions/8865681
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define all(x) (x).begin(),(x).end()
#define repex(i, a, b, c) for(LL i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
const int MOD = 1000000007, MAX = 200005, INF = 1 << 30;

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

int main(){
    LL N, X, D;
    scanf("%lld %lld %lld", &N, &X, &D);
    LL ans = 0;
    if(X == 0 && D == 0){
        puts("1");
        return 0;
    }
    rep(i, N + 1) ans += i * (N - i) + 1;
    if(X < 0 && D < 0) X *= -1, D *= -1;
    if(X >= 0 && D >= 0){
        LL g = gcd(X, D);
        X /= g;
        D /= g;
        
        if(D > N){
            printf("%lld\n", ans);
            return 0;
        }
        LL diff = X;
        rep(i, N - D + 1){
            LL la = i * (i - 1) / 2, lb = i * (2 * N - i - 1) / 2;
            LL ra = (i + D) * (i + D - 1) / 2 + diff, rb = (i + D) * (2 * N - (i + D) - 1) / 2 + diff;
            LL a = min(lb, rb) - max(la, ra) + 1;
            ans -= max(a, 0LL);
        }
        printf("%lld\n", ans);
    }else{
        LL g = gcd(abs(X), abs(D));
        X /= g;
        D /= g;
        if(D < 0) X *= -1, D *= -1;
        if(D > N){
            printf("%lld\n", ans);
            return 0;
        }
        LL diff = X;
        rep(i, N - D + 1){
            LL la = i * (i - 1) / 2, lb = i * (2 * N - i - 1) / 2;
            LL ra = (i + D) * (i + D - 1) / 2 + diff, rb = (i + D) * (2 * N - (i + D) - 1) / 2 + diff;
            LL a = min(lb, rb) - max(la, ra) + 1;
            ans -= max(a, 0LL);
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int left=A+B;
  int right=C+D;
  if (right>left){
    cout << "Right" << endl;
  }
  if (right==left) {
    cout << "Balanced" << endl;
  }
  if (right<left){
    cout<<"Left"<<endl;
  }
}

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

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		bool a[21][21]={};
		int x,y;
		for (int i = 0; i < n; ++i) cin>>x>>y,a[x][y]=1;
		int m;
		cin>>m;
		int nx=10,ny=10,r;
		char c;
		for (int i = 0; i < m; ++i)
		{
			cin>>c>>r;
			if(c=='N')
			{
				for (int i = 1; i <= r; ++i) if(a[nx][ny+i]) a[nx][ny+i]=0,--n;
				ny+=r;
			}
			else if(c=='E')
			{
				for (int i = 1; i <= r; ++i) if(a[nx+i][ny]) a[nx+i][ny]=0,--n;
				nx+=r;
			}
			else if(c=='W')
			{
				for (int i = 1; i <= r; ++i) if(a[nx-i][ny]) a[nx-i][ny]=0,--n;
				nx-=r;
			}
			else
			{
				for (int i = 1; i <= r; ++i) if(a[nx][ny-i]) a[nx][ny-i]=0,--n;
				ny-=r;
			}
		}
		cout<<((n==0)?"Yes\n":"No\n");
	}
	return 0;
}



Measured memory_bytes: 3072
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    // cout << fixed << setprecision(15) << solve<vector<vector<int>>>() << endl;
    
    int n,d;
    while(cin >> n >> d,n){
        vector<vector<int>> c(n);
        
        vector<int> poten(n);
        for(int i = 0; i < n;i++){
            int m; cin >> m;
            c[i].resize(m);
            for(auto& in:c[i]) cin >> in;

            poten[i] = accumulate(c[i].begin(),c[i].end(),0);
        }
        
        auto f = [&](){
            bool ok = false;
            for(int i = 0; i < n;i++){
                if(c[i].empty()) continue;
                while(c[i].size()){
                    poten[i] -= c[i].back();
                    if(*max_element(poten.begin(), poten.end()) - poten[i] > d){
                        poten[i] += c[i].back();
                        break;
                    }else{
                        c[i].pop_back();
                        ok = true;
                    }
                }
            }
            return ok;
        };
        while(f());
        cout << (count_if(poten.begin(),poten.end(),[](int x){return x!=0;})?"No":"Yes") << endl;
    }
    return 0;
}



Measured memory_bytes: 3132
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll inf = 5e15;

int main() {
    ll N, L;
    cin >> N >> L;
    ll sum = 0;
    V<ll> app;
    for(ll i = 1; i <= N; i++) {
        app.push_back(L + i - 1);
        sum += app.back();
    }

    ll diff = inf;
    ll ans = 0;
    for(ll i = 0; i < N; i++) {
        ll tmp_s = sum - app[i];
        ll val = abs(tmp_s - sum);
        if(diff > val) {
            diff = val;
            ans = tmp_s;
        }
    }

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


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


namespace How_Many_Divisors
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a, b, c;
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            c = int.Parse(str[2]);

            int sum = 0;
            foreach (var item in Enumerable.Range(a, b - a + 1))
                if (c % item == 0)
                    sum = sum + 1;

            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 9524
use std::io::Read;


fn input() -> (usize,usize,Vec<i32>) {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n:usize = iter.next().unwrap().parse().unwrap();
    let s:usize = iter.next().unwrap().parse().unwrap();
    let a = (0..n).map(|_|{
            iter.next().unwrap().parse().unwrap()
        }).collect();
    (n,s,a)
}

const MOD: i64 = 998244353;

fn main() {
    
    let (n,s,a) = input();
    let mut dp = vec![vec![0;s+1];n+1];
    dp[0][0] = 1;
    for i in 0..n {
        for j in 0..(s+1) {
            dp[i+1][j] = (dp[i+1][j]+dp[i][j]*2)%MOD;
            let added = j + (a[i] as usize);
            if added<=s {
                dp[i+1][added] = (dp[i+1][added]+dp[i][j])%MOD;
            }
        }
    }

    println!("{}",dp[n][s]);

}



Measured memory_bytes: 72456
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include <cmath>

using namespace std;

using ll = long long int;

int main() {

    int N;
    int V[20] = {0};
    int C[20] = {0};

    cin >> N;
    for (int i = 0; i < N; i++) cin >> V[i];
    for (int i = 0; i < N; i++) cin >> C[i];

    int sub[20];
    for (int i = 0; i < N; i++) sub[i] = V[i] - C[i];

    sort(sub, sub + N, std::greater<>());

    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (sub[i] <= 0) {
            break;
        }
        sum += sub[i];
    }

    cout << sum;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
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; }



int main() {
    ll n;
    cin >> n;
    ll ans = 1e13;
    for(ll i = 1;i*i<=n;i++) {
        if(n%i != 0) continue;
        ll j = n/i;
        ans = min(ans,i+j-2);
    }
    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    vector<int> dp(n);
    for(int i=0;i<n;i++){
        cin >> h.at(i);
        dp.at(i)=1000000000;
    }
    //dp.at(0)=0;
    dp.at(0)=0;
    dp.at(1)=abs(h.at(1)-h.at(0));
    for(int i=2;i<n;i++){
        dp.at(i)=min(dp.at(i-1)+abs(h.at(i)-h.at(i-1)),dp.at(i-2)+abs(h.at(i)-h.at(i-2)));
    }
    cout << dp.at(n-1);

}

Measured memory_bytes: 1024
R, G, B, N = map(int, input().split())

ans = 0
a = N // R
for r in range(a + 1):
    m = N - r * R
    b = m // G
    for g in range(b + 1):
        k = m - g * G
        if k % B == 0:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;

//ll bit[200010];
//ll kai[3010];
//ll Cnt[10010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }



/*ll sum(ll i)
{
	i += 1;
	ll t = 0;
	while (i > 0)
	{
		t += bit[i];
		i -= i & -i;
	}
	return t;
}

void add(ll i, ll x)
{
	i += 1;
	while (i <= 200005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

/*`ll SAIKI(ll S) {
	for (ll T = S; ; T = (T - 1) & S) {

	}
}*/



void test() {
	cout << "888888888888888888888888" << endl;
}

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

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}


/*map<ll, ll> pres;
ll ct;

void makePrimeList(ll x) {
	ll X = x;
	for (ll j = 2; j * j <= x; j++) {
		ll cnt = 0;
		while (X % j == 0) {
			cnt++;
			X /= j;
		}
		if (cnt) {
			if (pres[j] == 0) {
				ct++;
				pres[j] = ct;
			}
			Cnt[pres[j]] += cnt;
		}
	}
	if (X != 1) {
		if (pres[X] == 0) {
			ct++;
			pres[X] = ct;
		}
		Cnt[pres[X]] += 1;
	}
}*/

string S, T, U;
ll a, b;

void solve() {
	cin >> S >> T >> a >> b >> U;
	if (S == U) {
		a--;
	}
	if (T == U) {
		b--;
	}
	cout << a << ' ' << b << endl;
}

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

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

// constexpr const int mod = 1000000007;
constexpr const int mod = 998244353;
class mint {
 public:
  long long x;
  constexpr mint(long long x = 0) noexcept : x((x % mod + mod) % mod) {}
  constexpr int getmod() { return mod; }
  constexpr mint operator-() const noexcept { return mint(-x); }

  constexpr mint& operator+=(const mint& a) noexcept {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr mint& operator-=(const mint& a) noexcept {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr mint& operator*=(const mint& a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint& operator/=(const mint& a) noexcept {
    return (*this) *= a.inv();
  }

  constexpr mint operator+(const mint& a) const noexcept {
    return mint(*this) += a;
  }
  constexpr mint operator-(const mint& a) const noexcept {
    return mint(*this) -= a;
  }
  constexpr mint operator*(const mint& a) const noexcept {
    return mint(*this) *= a;
  }
  constexpr mint operator/(const mint& a) const noexcept {
    return mint(*this) /= a;
  }

  constexpr mint inv() const noexcept { return pow(mod - 2); }
  constexpr mint pow(long long t) const noexcept {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  friend istream& operator>>(istream& is, mint& a) noexcept {
    return is >> a.x;
  }
  friend ostream& operator<<(ostream& os, const mint& a) noexcept {
    return os << a.x;
  }
};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];

  vector<mint> dp(n + 1);
  vector<mint> dpsum(n + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    rep(j, k) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0) continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 6412
#include <iostream>
#include <vector>

int main()
{
	size_t N;
	std::cin >> N;
	std::vector<int64_t> A(N+2);
	A[0] = 0;
	A[N] = 0;
	for (size_t i = 1; i <= N; ++i)
	{
		std::cin >> A[i];
	}
	
	int64_t c = 0;
	for (size_t i = 1; i <= N+1; ++i)
	{
		c += abs(A[i-1] - A[i]);
	}

	for (size_t i = 1; i <= N; ++i)
	{
		std::cout << -abs(A[i-1] - A[i]) - abs(A[i] - A[i+1]) + 
			abs(A[i-1] - A[i+1]) + c << std::endl;
	}

	return 0;
}


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

int main() {
    ll N, T;
    cin >> N >> T;
    vector<ll> t(N);
    rep(i, N) cin >> t[i];

    ll X = 0;
    for (int i = 1; i < N; i++) {
        X += min(t[i] - t[i - 1], T);
    }
    X += T;

    cout << X << endl;
    return 0;
}


Measured memory_bytes: 1792
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    string a, b;
    cin >> a >> b;

    reverse(a.begin(), a.end());
    cout << (a == b ? "YES" : "NO") << endl;

    return 0;
}



Measured memory_bytes: 632
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
  int n;
  cin>>n;
  vector<vector<int>> a0((n+1)/2, vector<int>(3)), a1(n/2, vector<int>(3));
  for(int i=0; i<3; i++){
    for(int j=0; j<n; j++){
      if(j&1) cin>>a1[j/2][i];
      else cin>>a0[j/2][i];
    }
  }
  auto a1s=a1, a0s=a0;
  sort(a1s.begin(), a1s.end());
  sort(a0s.begin(), a0s.end());
  int d0=0, d1=0;
  for(int i=0; i<(n+1)/2; i++){
    if(a0s[i][1]!=6*i+2){
      cout<<"No"<<endl;
      return 0;
    }
    if(!(a0s[i][0]==6*i+1 && a0s[i][2]==6*i+3) && !(a0s[i][0]==6*i+3 && a0s[i][2]==6*i+1)){
      cout<<"No"<<endl;
      return 0;
    }
    if(a0s[i][0]==6*i+3) d0^=1;
  }
  for(int i=0; i<n/2; i++){
    if(a1s[i][1]!=6*i+5){
      cout<<"No"<<endl;
      return 0;
    }
    if(!(a1s[i][0]==6*i+4 && a1s[i][2]==6*i+6) && !(a1s[i][0]==6*i+6 && a1s[i][2]==6*i+4)){
      cout<<"No"<<endl;
      return 0;
    }
    if(a1s[i][0]==6*i+6) d1^=1;
  }
  int p0[50050], p1[50050];
  for(int i=0; i<(n+1)/2; i++){
    p0[i]=(a0[i][0]-1)/6;
  }
  for(int i=0; i<n/2; i++){
    p1[i]=(a1[i][0]-1)/6;
  }
  bool used[50050]={};
  int c0=((n+1)/2), c1=n/2;
  for(int i=0; i<(n+1)/2; i++){
    if(!used[i]){
      int x=i;
      while(!used[x]){
        used[x]=1;
        x=p0[x];
      }
      c0--;
    }
  }
  fill(used, used+n/2, 0);
  for(int i=0; i<n/2; i++){
    if(!used[i]){
      int x=i;
      while(!used[x]){
        used[x]=1;
        x=p1[x];
      }
      c1--;
    }
  }
  c0%=2, c1%=2;
  if((c0==0 && d0==0 && c1==0 && d1==0) || (c0==1 && d0==0 && c1==0 && d1==1) || (c0==0 && d0==1 && c1==1 && d1==0) || (c0==1 && d0==1 && c1==1 && d1==1)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
	return 0;
}

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


int main() {
  map<char, char> enki_map_;
  enki_map_['A'] = 'T';
  enki_map_['T'] = 'A';
  enki_map_['C'] = 'G';
  enki_map_['G'] = 'C';
  
  char enki;
  enki = getchar();
  
  cout << enki_map_[enki] << endl;
}

Measured memory_bytes: 256
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        if i==0 or i==H-1:
            for j in range(W):
                print('#',end='')
            print()
        else:
            for j in range(W):
                if j==0 or j==W-1:
                    print("#",end='')
                else:
                    print('.',end='')
            print('')
    print('')


Measured memory_bytes: 7008
#include <iostream>
#include <vector>

int main() {
    int N, a, cnt = 0;
    std::vector<int> v {0};
    std::cin >> N;
    for (int i = 0; i < N; ++i) {
        std::cin >> a;
        v.push_back(a);
    }
    for (int i = 1; i < v.size(); ++i) {
        int t = v[i];
        if (v[t] == i) ++cnt;
    }
    std::cout << cnt/2 << std::endl;
    return 0;
}

Measured memory_bytes: 892
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define N 200002

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
bool b[N],d[N];
char ch;
int n,m,x,y;

inline void read(int &x){x=0;do{ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');}

int main(void)
{
	read(n),read(m);
	rep(i,1,m)
	{
		read(x),read(y);
		if(x==1)b[y]=true;
		if(y==n)d[x]=true;
	}
	rep(i,1,n)if(b[i]&&d[i])
	{
		printf("POSSIBLE");
		return 0;
	}
	printf("IMPOSSIBLE");
	return 0;
}


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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int main(){
    fcin;
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for(int& i : a) cin >> i;
    vector<int> d;
    for(int i = 0; i < n - 1; i++){
        d.pb(a[i+1]-a[i]);
    }
    d.pb((a[0]-a[n-1]+k) % k);
    sort(all(d));
    ll ans = 0;
    for(int i = 0; i < n - 1; i++) ans += d[i];
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2168
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        List<Data> D = new ArrayList<Data>();
        int n = sc.nextInt();
        for(int i = 0 ; i < n ; i++){
            long v = sc.nextLong();
            long w = sc.nextLong();
            char t = sc.next().charAt(0);
            long d = sc.nextLong();
            String s = sc.next();
            D.add(new Data(v,w,t,d,s));
        }
        Collections.sort(D);
        Iterator<Data> it = D.iterator();
        while(it.hasNext()){
            Data a = it.next();
            a.print();
        }
    }
}
class Data implements Comparable<Data>{
    long v;
    long w;
    char t;
    long d;
    String s;
    Data(long v, long w, char t, long d, String s){
        this.v = v;
        this.w = w;
        this.t = t;
        this.d = d;
        this.s = s;
    }
    public void print(){
        System.out.println(v + " " + w + " " + t + " " + d + " " + s);
    }
    public int compareTo(Data x){
        if(v < x.v)
            return -1;
        else if(v == x.v){
            if(w < x.w)
                return -1;
            else if(w == x.w){
                if(t < x.t)
                    return -1;
                else if(t == x.t){
                    if(d < x.d)
                        return -1;
                    else if(d == x.d){
                        return s.compareTo(x.s);
                    }
                    else
                        return 1;
                }
                else
                    return 1;
            }
            else
                return 1;
        }
        else
            return 1;
    }
}


Measured memory_bytes: 195764
/* ex 3_2
  kt125 */

#include <stdio.h>

int main(void) {
  int num;  //number
  scanf("%d", &num);
  
  switch(num % 10){ // nの一の位で場合分け
    case 2: case 4: case 5: case 7: case 9:
      printf("hon\n"); break;
    case 0: case 1: case 6: case 8:
      printf("pon\n"); break;
    case 3:
      printf("bon\n"); break;
  }
  return 0;
}



Measured memory_bytes: 1660
// Author : MohamedSameh
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<deque>
#include <sstream>
#include <string.h>

typedef long long ll ;
// random in each run --> srand(time(NULL));

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
#define debug(x) cout<<#x<<" = { "<<x<<" }\n"
void fo (){fflush(stdout);}
using namespace std;
int dp[3000][3000];
int n , m ;
string x  , y , ans = "";
int sol (int i , int j )
{
  if (i == n || j == m )return 0;
  if (x[i] == y[j])return dp[i][j] = 1 + sol (i+1 , j+1);
  int &ret = dp[i][j] ;
  if (~ret)return ret ;
  return ret = max (sol(i+1 , j ) , sol (i , j+1 ));
}
int main ()
{
  memset (dp , -1 ,sizeof dp );
  cin >> x >> y  ;
  n = SZ(x) ;
  m = SZ(y);
  int ret = sol(0,0);
  for (int i = 0 , j = 0 ; i < n || j < m ; )
  {
    if (j < m && i+1 < n && dp[i+1][j] == dp[i][j])
    i++;
    else if (i < n && j+1 < m && dp[i][j+1] == dp[i][j])
    j++;
    else
    {
      if (i < n && j < m && x[i] == y[j])ans += x[i];
      i++;
      j++;
    }
  }
cout << ans <<"\n";
  return 0;
}


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

int main() {
  int n, k;
  double cnt; //解(期待値の最大値)
  double cndty; //期待値の最大値の候補を代入する
  cin >> n >> k;
  
  //C++では、動的配列の代わりにベクトルを使用すると超便利・・・らしい
  vector<double> p(n);
  
  for (int i = 0; i < n; i++){
    double p_in;
    cin >> p_in;
    p[i] = (p_in+1.0) / 2.0; //期待値はサイコロの最大の値さえわかれば、求められる
    //p.at(i) = (p+1.0) / 2.0;
  }
  
  vector<double> s(n+1);//累積和を求めるための配列（ベクトルだけども
  s[0] = 0;
  
  for( int i = 1 ; i < n+1 ; i++){
    s[i] = p[i-1] + s[i-1];
  }
  
  for( int i = 0;  n - k - i >= 0 ; i++){
    cndty = s[k+i] - s[i];
    
    if(cndty > cnt){
      cnt = cndty;
    }
  }
  
  cout << fixed << setprecision(12) << cnt << endl;
  
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100001

int main() {
    int F;
    cin >> F;
    cout << (F-30)/2 << endl;
}


Measured memory_bytes: 3104
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

tab_sum = [0]
sum_tmp = 0
for ai in a:
    sum_tmp += ai
    tab_sum.append(sum_tmp)

ans = [[None] * W for _ in range(H)]
    
tab_idx = 1
for idx in range(H * W):
    y = idx // W
    if y % 2 == 0:
        x = idx % W
    else:
        x = (W - 1 - idx) % W
    #
    if idx >= tab_sum[tab_idx]: tab_idx += 1
    ans[y][x] = tab_idx

for ansi in ans:
    print(' '.join(map(str, ansi)))

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

ifstream in ("test.in" );
ofstream out("test.out");

const int DIM = 3e2 + 5;

int mat[DIM][DIM], oki[DIM], cnt[DIM];

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int n, m;
    cin >> n >> m;
    
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> mat[i][j];
            oki[j] = 1;
        }
        
        ++cnt[mat[i][1]];
    }
    
    int ans = 1e9;
    for (int k = 1; k <= m; ++k) {
        int pos = -1, mxm = -1;
        
        for (int i = 1; i <= m; ++i) {
            if (mxm < cnt[i])
                mxm = cnt[i], pos = i;
            cnt[i] = 0;
        }
        
        ans = min(ans, mxm); oki[pos] = 0;
        
        if (k == m)
            break;
        
        for (int i = 1; i <= n; ++i) {
            int j = 1;
            while (oki[mat[i][j]] == 0)
                ++j;
            
            ++cnt[mat[i][j]];
        }
    }
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/








int R, G, B, N;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> R >> G >> B >> N;

	int ans = 0;
	rep(r, 0, N + 1) rep(g, 0, N + 1) {
		int b = N - r - g;
		if (0 <= b and r % R == 0 and g % G == 0 and b % B == 0) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  char s[27];
  int i,a[26]={0};
  scanf("%s",s);
  
  for(i=0;i<strlen(s);i++){
    a[(s[i]-'a')]++;
    if(a[(s[i]-'a')]>1){
      printf("no");
      return 0;
    }
  }
  printf("yes");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,q;
    cin>>n>>q;
    int a[n-1],b[n-1],x[q],p[q];
    int cnt[n]={};
    vector<vector<int>>pas(n);
    for(int i=0;i<n-1;i++){
        cin>>a[i]>>b[i];
        pas[a[i]-1].push_back(b[i]-1);
        pas[b[i]-1].push_back(a[i]-1);
    }
    for(int i=0;i<q;i++){
        cin>>p[i]>>x[i];
        cnt[p[i]-1]+=x[i];
    }
    queue<int>s;
    s.push(0);
    bool seen[n]={};
    seen[0]=true;
    while(s.size()){
        int t=s.front();
        s.pop();
        for(int i=0;i<pas[t].size();i++){
            if(seen[pas[t][i]]==false){
                seen[pas[t][i]]=true;
                s.push(pas[t][i]);
                cnt[pas[t][i]]+=cnt[t];
                
            }
        }
    }
    for(int i=0;i<n;i++)cout<<cnt[i]<<endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair

using namespace std;

using uint=unsigned int;
using ll=long long;

uint xor128(){
	static uint d[]={1145141919,1919810893,810893364,364114514};
	uint t=d[0]^(d[0]<<11);
	REP(i,3)
		d[i]=d[i+1];
	return d[3]=d[3]^(d[3]>>19)^(t^(t>>8));
}

struct Node{
	Node *l,*r;
	uint pri;
	int s,v,mn;
} buf[200000];

using NP=Node*;

NP newNode(int v){
	static int c=0;
	buf[c]=Node{NULL,NULL,xor128(),1,v,v};
	return &buf[c++];
}

const int inf=1145141919;

inline int Mini(NP x){
	return x?x->mn:inf;
}

inline int Size(NP x){
	return x?x->s:0;
}

inline NP Update(NP x){
	x->s=1;
	x->mn=x->v;
	if(x->l){
		x->s+=x->l->s;
		x->mn=x->mn<x->l->mn?x->mn:x->l->mn;
	}
	if(x->r){
		x->s+=x->r->s;
		x->mn=x->mn<x->r->mn?x->mn:x->r->mn;
	}
	return x;
}

inline NP LinkL(NP x,NP l){
	x->l=l;
	return Update(x);
}

inline NP LinkR(NP x,NP r){
	x->r=r;
	return Update(x);
}

inline NP CutL(NP x){
	x->l=NULL;
	return Update(x);
}

inline NP CutR(NP x){
	x->r=NULL;
	return Update(x);
}

inline NP Merge(NP a,NP b){
	if(!a)
		return b;
	else if(!b)
		return a;
	else if(a->pri>b->pri)
		return LinkR(a,Merge(a->r,b));
	else
		return LinkL(b,Merge(a,b->l));
}

using Res=Node;

inline Res Split(NP x,int k){
	if(k<=0)
		return Res{NULL,x};
	else if(x->s<=k)
		return Res{x,NULL};
	else if(k<=Size(x->l)){
		Res s=Split(x->l,k);
		return Res{s.l,Merge(s.r,CutL(x))};
	}else{
		Res s=Split(x->r,k-Size(x->l)-1);
		return Res{Merge(CutR(x),s.l),s.r};
	}
}

inline void Set(NP x,int k,int v){
	int ls=Size(x->l);
	if(k<ls)
		Set(x->l,k,v);
	else if(k==ls)
		x->v=v;
	else
		Set(x->r,k-ls-1,v);
	Update(x);
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

NP t[200000];

int main(){
	int n=read(),q=read();
	REP(i,n)
		t[i]=newNode(read());
	while(n>1){
		int k=n/2;
		REP(i,k)
			t[i]=Merge(t[i*2],t[i*2+1]);
		if(k*2<n)
			t[k]=t[k*2];
		n=(n+1)/2;
	}
	NP root=t[0];
	REP(_,q){
		int x=read(),y=read(),z=read();
		if(x==0){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y-1);
			Res s3=Split(s2.r,1);
			root=Merge(Merge(s1.l,s3.l),Merge(s2.l,s3.r));
		}else if(x==1){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y);
			printf("%d\n",Mini(s2.l));
			root=Merge(s1.l,Merge(s2.l,s2.r));
		}else if(x==2){
			Set(root,y,z);
		}
	}
}

Measured memory_bytes: 11024
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <unordered_set>
#include <functional>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?n=0,false:(n=in<T>(c),true);}
_SCAN(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

int main() {
	for (int n; (n = in());) {
		int k = in();
		vector<int> c(n);
		for (int &i: c)
			i = in();
		unordered_set<int> s;
		function<void(int, int, int)> check = [&](int i, int x, int v){
			if (i == k) {
				s.insert(x);
				return;
			}
			for (int j: range(n)) {
				if (!(v & (1 << j))) {
					int t {x};
					for (int k {c[j]}; k; k /= 10)
						t = t * 10 + k % 10;
					check(i + 1, t, v | (1 << j));
				}
			}
		};
		check(0, 0, 0);
		outl((int) s.size());
	}
}


Measured memory_bytes: 2600
from collections import Counter

N=int(raw_input())
s=[raw_input() for j in xrange(N)]
st1 = Counter(s)

M=int(raw_input())
t=[raw_input() for j in xrange(M)]
st2 = Counter(t)

best = 0
for k,v in st1.items():
  score = v - st2[k]
  best = max(best, score)
print best

Measured memory_bytes: 2808
import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			SortedMap<Integer, Integer> map = new TreeMap<>();
			IntStream.range(0, n).forEach(i -> {
				int a = scanner.nextInt();
				map.put(a, map.getOrDefault(a, 0) + 1);
			});
			IntStream.range(0, m).forEach(i -> {
				int b = scanner.nextInt(), c = scanner.nextInt();
				while ((b > 0) && (map.firstKey() < c)) {
					int exists = map.get(map.firstKey());
					if (exists > b) {
						map.put(map.firstKey(), exists - b);
						map.put(c, map.getOrDefault(c, 0) + b);
						b = 0;
					} else {
						map.put(c, map.getOrDefault(c, 0) + exists);
						map.remove(map.firstKey());
						b -= exists;
					}
				}
			});
			System.out.println(
					map.entrySet().stream().mapToLong(entry -> entry.getKey() * (long) entry.getValue()).sum());
		}
	}
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
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 (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    map<ll, ll> first;
    vector<ll> next(N);
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    for(int i = N-1; i >= 0; i--){
        ll a = A[i];
        if(first.find(a) == first.end()){
            next[i] = -1;
        }
        else{
            next[i] = first[a];
        }
        first[a] = i;
    }

    ll last = A[0];
    ll period = 1;
    vector<ll> P;
    //while(1){
    //    ll point = first[last];
    //    if(period==1) point = next[point] + 1;
    //    else point += 1;

    //    if(point != 0)
    //        while(1){
    //            ll tmp = next[point] + 1;
    //            if(tmp == 0)
    //                break;
    //            else
    //                point = tmp;
    //            if(point == N)
    //                break;
    //        }

    //    if(point == N)
    //        break;

    //    period++;
    //    P.push_back(point);
    //    last = A[point];
    //}
    
    //period++;
    ll point = next[first[last]] + 1;
    if(point == 0){
        period++;
        P.push_back(point);
        point = first[A[point]]+1;
    }
    while(1){
        ll tmp = next[point] + 1;
        if(tmp == 0){
            period++;
            P.push_back(point);
            point = first[A[point]] + 1;
        }
        else{
            point = tmp;
        }

        if(point == N)
            break;
    }

    P.push_back(N);
    //cout << period << endl;

    ll num = (K-1) % period;
    //cout << P[num] << endl;
    //cout << A[P[num]] << endl;

    vector<ll> ans;
    point = P[num];

    if(point == N){
        cout << endl;
        return 0;
    }

    while(1){
        ll tmp = next[point];
        if(tmp == -1){
            ans.push_back(A[point]);
            point++;
        }
        else
            point = tmp+1;

        if(point == N)
            break;
    }

    for(auto&& a : ans){
        printf("%lld ", a);
    }
    printf("\n");

    return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

ll s[333333];
ll t[333333];

int main() {
   int n;
   cin >> n;
   vec<ll> a(3*n);
   rep (i, 3*n) {
      cin >> a[i];
   }

   pq<ll, vec<ll>, greater<ll>> Q;
   ll sum = 0;
   for (int i = 0; i < 3*n; i++) {
      Q.push(a[i]);
      sum += a[i];
      if (Q.size() > n) {
         sum -= Q.top();
         Q.pop();
      }
      s[i] = sum;
   }

   pq<ll> P;
   sum = 0;
   for (int i = 3*n-1; i >= 0; i--) {
      P.push(a[i]);
      sum += a[i];
      if (P.size() > n) {
         sum -= P.top();
         P.pop();
      }
      t[i] = sum;
   }

   ll ans = -1e18;
   for (int i = n-1; i < 2*n; i++) {
      ans = max(ans, s[i] - t[i+1]);
   }
   cout << ans << endl;

   return 0;
}

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

 

using namespace std;

const int N=1e5+8;

 

int n, h[N];

int brain[N];

 

 

int dp(int i)

{

    if(i==n-1){

        return 0;

    }
  if(i>n-1) return 2e5;

    if(brain[i]!=-1)return brain[i];

 

    int path1= abs(h[i]-h[i+1])+ dp(i+1);

    int path2= abs(h[i]-h[i+2])+ dp(i+2);

 

    int ans=min(path1 , path2);

 

    brain[i]=ans;

 

    return brain[i];

 

}

 

 

int main()

{

    scanf("%d", &n);

    for(int i=0 ; i<n ;i++)scanf("%d", &h[i]);

 

    memset(brain , -1 , sizeof brain);

 

    printf("%d\n", dp(0));

 

}



Measured memory_bytes: 4096
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=200001;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int a='A'-'a';
	char s[3][11];
	for(int i=0;i<3;i++){
		cin>>s[i];
	}
	cout<<(char)(s[0][0]+a)<<(char)(s[1][0]+a)<<(char)(s[2][0]+a)<<endl;
	return 0;
}

Measured memory_bytes: 256