akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABCO087B
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Solve(Console.ReadLine(),
                   Console.ReadLine(),
                   Console.ReadLine(),
                   Console.ReadLine()));
        }

        static string Solve(params string[] args)
        {
            var n500 = int.Parse(args[0]);
            var n100 = int.Parse(args[1]);
            var n50 = int.Parse(args[2]);
            var target = int.Parse(args[3]);

            var cnt = 0;
            for (int i = 0; i <= n500; i++)
                for (int j = 0; j <= n100; j++)
                    for (int k = 0; k <= n50; k++)
                    {
                        if (500 * i + 100 * j + 50 * k == target) cnt++;
                    }

            return cnt.ToString();





























        }
    }
}


Measured memory_bytes: 13140
w,h,n=map(int, input().split())
sx=sy=0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:   sx=max(sx,x)
    elif a==2:  w=min(w,x)
    elif a==3: sy=max(sy,y)
    elif a==4:  h=min(h,y)
print(max(0,w-sx)*max(0,h-sy))

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<vector<int>> x(n), y(n);

    rep(i, n){
        int a;
        cin >> a;
        x[i].resize(a);
        y[i].resize(a);
        rep(j, a){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }

    bool ok = true;
    int ans = 0;
    for (int i = 0; i < (1 << n); ++i) {
        ok = true;
        rep(j, n){
            if(i & (1 << j)){
                rep(k, x[j].size()){
                    if(!(i & (1 << x[j][k])) && y[j][k]){
                        ok = false;
                        break;
                    }
                    if((i & (1 << x[j][k])) && !y[j][k]){
                        ok = false;
                        break;
                    }
                }
            }
        }
        if(ok){
            int tmp = i, ans2 = 0;
            while(tmp){
                if(tmp & 1){
                    ans2++;
                }
                tmp = tmp >> 1;
            }
            ans = max(ans, ans2);
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {

  for(;;) {

    char x[1000];
    scanf("%s", x);

    if(x[0] == '0') break;

    int sum = 0;
    for(int i = 0; i < strlen(x); i++) {
      sum += x[i] - '0';
    }
    printf("%d\n", sum);
  }
  
  return 0;
}



Measured memory_bytes: 2680
/* ex7_3
   bonbonc    */

#include <stdio.h> 
#include <stdlib.h>

int main(void){
    int row,column,copied_row,flag,i,j,k;
    scanf("%d %d",&row,&column);
    copied_row = row;//行数をコピー
    char **squares;
    
    // 各行の配列へのポインタ分のメモリ領域を確保 
    squares = (char**)calloc(row, sizeof(char*));
    if (squares == NULL){
        exit(1);//エラー処理
    }
    // 各行の要素分のメモリ領域を確保 
    for ( i = 0; i < row; i++){
        squares[i] = (char*)calloc(column, sizeof(char));
        if (squares[i] == NULL){
            exit(1);
        }
    }
    
    for ( i = 0; i < row; i++){
        for ( j = 0; j < column; j++){
            scanf(" %c",&squares[i][j]);//入力を受け取る
        }
    }
    //白のみの行を探索してその行を削除する
    for ( i = 0; i < row; i++){
        flag = 1;
        for ( j = 0; j < column; j++){
            if (squares[i][j] == '#'){
                flag = 0;
            }
        }
        //白のみだった場合
        if (flag==1){
            for (j = i;j < row-1;j++){
                for ( k = 0; k < column; k++){
                    //行を上に平行移動
                    squares[j][k] = squares[j+1][k];
                } 
            }
            row -= 1;
            i -= 1;
        }
        
        
    }
    //白のみの列を探してその列を削除する
    for ( i = 0; i < column; i++){
        flag = 1;
        for ( j = 0; j < row; j++){
            if (squares[j][i] == '#'){
                flag = 0;
            }
            
        }
        //白のみの列だった場合
        if (flag==1){
            for ( j = i; j < column-1; j++){
                for ( k = 0; k < row; k++){
                    squares[k][j] = squares[k][j+1];
                }                
            }
            column -= 1;
            i -= 1;
        }
    }
    
    for ( i = 0; i < row; i++){
        for ( j = 0; j < column; j++){
            printf("%c",squares[i][j]);//答えを出力
        }
        printf("\n"); 
    }

    for ( i = 0; i < row; i++){
        free(squares[i]);//各行メモリ解放
    }
    free(squares);//メモリ解放
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++)
  {
    cin >> A.at(i);
  }
  for (int i = n - 1; i >= 0; i--)
  {
    cout << A.at(i);
    if (i == 0)
    {
      cout << endl;
    }
    else
    {
      cout << " ";
    }
  }
}


Measured memory_bytes: 3096
S = input()[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1
current = 0
x = 1
for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current % 2019]
    mods[current % 2019] += 1
    x = x * 10 % 2019
print(ans)


Measured memory_bytes: 9248
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import qualified Data.IntMap as IMap
import qualified Data.Vector as V
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt

sqleft :: Seq a -> a
sqleft q = sqleft_(Sq.viewl q)
sqleft_ :: ViewL a -> a
sqleft_ (x :< xs) = x
sqright :: Seq a -> a
sqright q = sqright_(Sq.viewr q)
sqright_ :: ViewR a -> a
sqright_ (xs :> x) = x

--------------------------------------------------------------
facmod 0 = 1
facmod x = mod (x * facmod (x-1)) 1000000007

main = do
    [n,m] <- map bsreadInt . BC.words <$> BC.getLine
    let x = min n m
    let y = max n m
    if x == y then print $ mod (2 * (facmod y) * (facmod x)) 1000000007
              else if y-x == 1
                   then print $ mod ((facmod y) * (facmod x)) 1000000007
                   else print 0

    
    

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

#define ll long long
#define fr(i, n) for(int i=0;i<n;i++)
#define forall(i, j, n) for(int i=j; i<n; i++)
#define all(c) c.begin(), c.end()
#define tr(container, it) for (__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define rt(container, it) for (__typeof(container.rbegin()) it = container.rbegin(); it != container.rend(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresetn(container, element) (find(all(container)), element) != container.end())
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define si(n) scanf("%d", &n)
#define sll(n) scanf("%lld", &n)
#define pi(n) 0*printf("%d\n", n)
#define pll(n) 0*printf("%lld\n", n)
#define SET(container, value) memset(container, value, sizeof container)
#define MP make_pair
#define F first
#define S second

#define scan_all(...) __s(__VA_ARGS__)
template <typename Arg1>
void __s(Arg1&& arg1) {
  cin >> arg1;
}
template <typename Arg1, typename... Args>
void __s(Arg1&& arg1, Args&&... args) {
  cin >> arg1 ; __s(args...);
}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names+1, ',');
	cerr.write(names, comma-names) << " : " << arg1 << " | "; __f(comma+1, args...);
}

std::vector<std::string> tokenize(
				  const std::string& s,
				  const std::string& delims){
  std::vector<std::string> tokens;
  size_t offset = 0;

  while (true) {
    size_t nonDelim = s.find_first_not_of(delims, offset);

    if (nonDelim == std::string::npos) {
      break; // Nothing left.
    }

    size_t delim = s.find_first_of(delims, nonDelim);

    // Finish tokenizing if this is the last token,
    // or we've found enough tokens.
    if (delim == std::string::npos) {
      tokens.push_back(s.substr(nonDelim));
      break;
    }

    tokens.push_back(s.substr(nonDelim, delim - nonDelim));
    offset = delim;
  }

  return tokens;
}

int main(){
  int n;
  si(n);
  vector< vector<int> > h(n, vector<int>(3));
  fr(i, n) scan_all(h[i][0], h[i][1], h[i][2]);
  vector < vector<int> > dp(n, vector<int>(3));
  dp[0][0] = h[0][0]; dp[0][1] = h[0][1]; dp[0][2] = h[0][2];
  for (int i=1; i<n; i++) {
    dp[i][0] = h[i][0] + max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = h[i][1] + max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = h[i][2] + max(dp[i-1][1], dp[i-1][0]);
  }
  cout << *max_element(all(dp[n-1])) << endl;
  return 0;
}


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

int main()
{
    long long x,k,d;
    long long ans;
    cin>>x>>k>>d;
    x=abs(x);
    if(x/d>=k)
        ans=x-k*d;
    else if(x/d%2!=k%2)
        ans=d-x%d;
    else
        ans=x%d;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  vector<char> C(100);
  vector<int> t(26);
  for(int i=0;i<100;i++){
    cin >> C.at(i);
    if(C.at(i) != '\0'){
      t.at(int(C.at(i)-'a'))+=1;
    }
  }
 int count =0;
  for(int i=0;i<26;i++){
    if(t.at(i)%2 == 0){
      count++;
    }
  }
  
  if(count == 26){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
 
}

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

#define int long long int
#define vi vector<int>
#define pb push_back
#define vvi vector<vi>

vvi adj;

void bfs(vi& du, int u) {
    queue<vi> q;
    q.push({ u, 0 });
    while(!q.empty()) {
        auto f = q.front();
        q.pop();
        int node = f[0], steps = f[1];
        if(du[node] != -1)  continue;
        du[node] = steps;
        for(int v : adj[node]) {
            q.push({ v, steps + 1 });
        }
    }
}

signed main() {
    int n, u, v;
    cin >> n >> u >> v;
    adj.clear();
    adj.resize(n + 1);
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    vi du(n + 1, -1), dv(n + 1, -1);
    bfs(du, u);
    bfs(dv, v);
    int mx = 0;
    for(int i = 1; i <= n; i++) {
        if(du[i] > dv[i])   continue;
        // cout << i << " " << dv[i] << endl;
        mx = max(mx, dv[i]);
    }
    cout << mx - 1 << endl;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = (1LL<<31)-1;
const int mod = 1e9 + 7;

struct SegmentTree {
  vector<int> data, lazy;
  int sz;
  SegmentTree(int n) {
    sz = 1; while(sz < n) sz *= 2;
    data.resize(2*sz-1, inf);
    lazy.resize(2*sz-1, -1);
  }
  void push(int k, int l, int r) {
    if(~lazy[k]) {
      data[k] = lazy[k];
      if(r - l > 1) {
	lazy[2*k+1] = lazy[k];
	lazy[2*k+2] = lazy[k];
      }
      lazy[k] = -1;
    }
  }
  void update(int a, int b, int x, int k, int l, int r) {
    push(k, l, r);
    if(r <= a || b <= l) return;
    if(a <= l && r <= b) {
      lazy[k] = x;
      push(k, l, r);
      return;
    }
    update(a, b, x, 2*k+1, l, (l+r)/2);
    update(a, b, x, 2*k+2, (l+r)/2, r);
    data[k] = min(data[2*k+1], data[2*k+2]);
  }
  void update(int a, int b, int x) {
    update(a, b, x, 0, 0, sz);
  }
  int query(int a, int b, int k, int l, int r) {
    push(k, l, r);
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return data[k];
    return min(query(a, b, 2*k+1, l, (l+r)/2),
	       query(a, b, 2*k+2, (l+r)/2, r));
  }
  int query(int a, int b) {
    return query(a, b, 0, 0, sz);
  }
};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, q;
  cin >> n >> q;
  SegmentTree seg(n);
  rep(i, q) {
    int com, s, t, x;
    cin >> com >> s >> t;
    if(com == 0) cin >> x, seg.update(s, t+1, x);
    else cout << seg.query(s, t+1) << endl;
  }

  return 0;
}

Measured memory_bytes: 7036
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    int N, C; cin >> N >> C;
    vvi D(C, vi(C)), c(N, vi(N));
    REP(i, C){
        REP(j, C){
            cin >> D[i][j];
        }
    }
    
    REP(i, N){
        REP(j, N){
            cin >> c[i][j];
            c[i][j]--;
        }
    }

    vvi dC(3, vi(C, 0));
    REP(i, C) {

        vi dCsum(3, 0);
        REP(j, 2*N+1) {

            REP(k, j+1) {
                // cout << j << " : " << k << " " << j-k << endl;
                if (k >= N || j-k >= N) continue;
                dCsum[j%3] += D[c[k][j-k]][i];
            }
        
        }

        dC[0][i] = dCsum[0];
        dC[1][i] = dCsum[1];
        dC[2][i] = dCsum[2];
    }

    int ans = (1<<30);
    REP(i, C){
        REP(j, C) {
            REP(k, C){
                if (i == j || j == k || k == i) continue;
                ans = min(ans, dC[0][i] + dC[1][j] + dC[2][k] );
            }
        }
    }

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


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    int h, w, n;
    cin >> h >> w >> n;

    int L = 0, R = w + 1, U = 0, D = h + 1;

    int x, y;
    cin >> x >> y;

    string s, t;
    cin >> s >> t;

    for(int i = n - 1; i >= 0; i--) {
        if(t[i] == 'L' && R <= w) R++;
        if(t[i] == 'R' && 1 <= L) L--;
        if(t[i] == 'U' && D <= h) D++;
        if(t[i] == 'D' && 1 <= U) U--;
        if(s[i] == 'L') L++;
        if(s[i] == 'R') R--;
        if(s[i] == 'U') U++;
        if(s[i] == 'D') D--;
        if(w <= L || R <= 1 || h <= U || D <= 1) {
            cout << "NO\n";
            return 0;
        }
    }

    cout << (L < y && y < R && U < x && x < D ? "YES\n" : "NO\n");

    return 0;
}

Measured memory_bytes: 920
use std::io::{self, BufRead};
use std::collections::BTreeSet;

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
  let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let mut ys: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let mut zs: BTreeSet<usize> = BTreeSet::new();
  for i in 0..n {
    let j = (i + 1) % n;
    let k = (i + 2) % n;
    if ys[i] + ys[k] < ys[j] && xs[j] <= ys[j] - ys[i] - ys[k] {
      zs.insert(i);
    }
  }
  let mut count: usize = 0;
  while !zs.is_empty() {
    let &i = zs.iter().next().unwrap();
    let j = (i + 1) % n;
    let k = (i + 2) % n;
    let q = (ys[j] - xs[j]) / (ys[i] + ys[k]);
    ys[j] -= (ys[i] + ys[k]) * q;
    zs.remove(&i);
    let l = (i + n - 1) % n;
    let m = (i + 3) % n;
    if ys[i] + ys[k] < ys[j] && xs[j] <= ys[j] - ys[i] - ys[k] {
      zs.insert(i);
    }
    if ys[l] + ys[j] < ys[i] && xs[i] <= ys[i] - ys[l] - ys[j] {
      zs.insert(l);
    }
    if ys[j] + ys[m] < ys[k] && xs[k] <= ys[k] - ys[j] - ys[m] {
      zs.insert(j);
    }
    count += q;
  }
  if xs == ys {
    println!("{}", count);
  } else {
    println!("-1");
  }
}

Measured memory_bytes: 13560
#include <bits/stdc++.h>
using namespace std;
template<class T> inline T gcd(T a,T b) 
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);} 
template<class T> inline T lcm(T a,T b) 
  {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));} 
int main(){
	int n;
	cin>>n;
	vector<long long> vec(n, 0);
	srand(time(NULL));
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
		//vec[i] = rand() % 100000;
	}
	long long x = 0;
	for(int i = 0; i < n; ++i){
		x += vec[i] - 1;
	}
	long long total = 0;
	//x--;
	cout<<x<<endl;
	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

ll N,K;
ll Fa[404040];
ll i, j, k,ans;

int main(){
    scanf("%lld%lld", &N,&K);
    Fa[0] = 1;
    fornum(i,0,N*2){
        Fa[i + 1] = Fa[i] * (i + 1) % MOD;
    }
    if(N-1<=K){       
        printf("%lld", moddiv(Fa[N * 2 - 1], Fa[N - 1]*Fa[N]));
    }else{
        ans = moddiv(Fa[N * 2 - 1], Fa[N - 1] * Fa[N]);
        fornum (i,0,N-K-1){
            ans = (ans - moddiv(Fa[N], Fa[N - i - 1] * Fa[i + 1]) * moddiv(Fa[N - 1], Fa[N-i-1] * Fa[i]) % MOD + MOD) % MOD;
        }
        printf("%lld", ans);
    }
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <regex>
#include <set>
#include <cmath>
#include <sstream>
#include <numeric>
#include <set>

using namespace std;

int main()
{
    long long a, b, k;

    std::cin >> a >> b >> k;

    if(a > k)
    {
        a -= k;
    }else if(b + a > k)
    {
        b = b + a - k;
        a = 0;
    } else {
        a = 0;
        b = 0;
    }
    std::cout << a << " " << b;

    return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
//const int mod=998244353;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int i,j,n;cin>>n;
	int mod;cin>>mod;
	static llint dp[2001][8001]={};//3 2or1
	for(i=0;i<=n;i++){dp[i][n+i*3]=1;}
	for(i=0;i<=n;i++){dp[0][n-i]=1;}
	for(i=1;i<=n;i++){
		for(j=n+i*3-1;j>=i;j--){
			int m;
			m=i*3-(j-n);
			dp[i][j]=dp[i-1][j]*(m-1)*(m-2)+dp[i][j+1]+dp[i-1][j-1]*(m-1);
			dp[i][j]%=mod;
			
		}
		
	}
	/*for(i=0;i<=n;i++){
		for(j=0;j<=n+i*3;j++){
			cerr<<dp[i][j]<<" ";
		}
		cerr<<endl;
	}*/
	cout<<dp[n][n]<<endl;
}


Measured memory_bytes: 123904
#include<iostream>
#include<cstring>
#define mod 1000000007
using namespace std;
int n, i, ii, sol, sum;
int ff[200];
char s[100005];
int main(){
    cin>> n;
    cin>> s + 1;
    for(i = 1; i <= n; i++){
        ff[ s[i] ]++;
        sum = 1;
        for(ii = 'a'; ii <= 'z'; ii++){
            if(ii != s[i]){
                sum = sum * 1LL * (ff[ii] + 1) % mod;
            }
        }
        sol = (sum + sol) % mod;
    }
    cout<< sol;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
int main() {
    for (int n, k; std::cin >> n >> k; ) {
        std::vector<int> steps(n);
        for (auto &it : steps) std::cin >> it;
        std::vector<bool> win(1+k, false);
        for (int i = 1; i <= k; i++) {
            for (int s : steps) {
                if (i - s >= 0 && !win[i - s]) {
                    win[i] = true;
                    break;
                }
            }
        }
        std::cout << (win[k] ? "First" : "Second") << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(x) cout<<#x<<":";cout<<x<<endl;
#define debugs(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll a,b,n;cin>>a>>b>>n;
    cout<<a*min(n,(b-1))/b<<endl;
    return 0;
}


Measured memory_bytes: 3568
#include<stdio.h>
#include<string.h>
#include<stdbool.h>

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

void Bsort(int data[], int size) {
	int i, j;
    for(i=0;i<size-1;i++){
        for(j=0;j<size-1;j++){
            if(data[j]>data[j+1]){
                swap(&data[j],&data[j+1]);
            }
        }
    }
}

int main(void){
    unsigned long long int N=0;
    scanf("%llu",&N);
    long int a[N];
    unsigned long long int sum=0;
    for(unsigned long long int n=0;n<N;n++){
        if((n+1)%3==0&&(n+1)%5==0){
            a[n]=0;
        }else if((n+1)%3==0){
            a[n]=0;
        }else if((n+1)%5==0){
            a[n]=0;
        }else a[n]=n+1;
    }
    for(unsigned long long int n=0;n<N;n++){
        sum+=a[n];
    }
    printf("%llu",sum);    
}

Measured memory_bytes: 9484
from collections import Counter
import math
n,m = map(int, input().split())
def combinations_count(n, r):
    l = 1
    for num in range(1,r+1):
      l *= (n+num)
      l = l // num
    return l
def prime_decomposition(n, table):
    i = 2
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
table = []
prime_decomposition(m, table)
c = Counter(table).values()
cc = Counter(c)
ans = 1
N = n-1
for i,j in cc.items():
  ans *= ((combinations_count(N,i))**j)%(10**9+7)
print(ans%(10**9+7))

Measured memory_bytes: 3316
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Vector.Unboxed (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed.Mutable (IOVector, STVector)
import qualified Data.Vector.Unboxed.Mutable as VM

main :: IO ()
main = do
  n <- readLn
  solve n <$> replicateM n f >>= print
  where
    f = map read <$> words <$> getLine

solve :: Int -> [[Int]] -> Int
solve n xs = subtract 1 $ runST $ do
  v <- VM.replicate 100003 0 :: ST s (STVector s Int)
  forM_ xs $ \[a, b] -> do
    s <- VM.read v a
    VM.write v a (s+1)
    t <- VM.read v (b+1)
    VM.write v (b+1) (t-1)
  forM_ [1..100002] $ \i -> do
    s <- VM.read v (i-1)
    t <- VM.read v i
    VM.write v i (s + t)
  foldM (\c i -> do
            s <- VM.read v i
            if s >= i - 1
              then return $ max c i
              else return c
         ) 1 [1..100001]



Measured memory_bytes: 89664
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e5+5;
ll n,k,ans,a[N],b[N];
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    cin>>n>>k;
    for(ll i=0;i<n;i++){
        cin>>a[i]>>b[i];
        if((a[i]&k)==a[i])ans+=b[i];
    }
    for(ll i=1;i<=(1ll<<30);i<<=1){
        if(!(k&i))continue;
        ll sum=0,t=(k^i)|(i-1);
        for(ll j=0;j<n;j++)if((a[j]&t)==a[j])sum+=b[j];
        ans=max(ans,sum);
    }
    cout<<ans;
}

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

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

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

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  int h1,m1,h2,m2,k; cin >> h1 >> m1 >> h2 >> m2 >> k;

  int t1 = h1*60+m1, t2 = h2*60+m2;
  int ans = (t2-t1)-k;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
n = int(input())
a = sorted(list(map(int, input().split())))

if n%2 == 0: # 人数が偶数の場合に不整合があるか確認
  for i in range(0,n,2):
    if a[i] != i+1 or a[i+1] != i+1:
      print(0)
      exit()
else: # 人数が奇数の場合に不整合があるか確認
  if a[0] != 0: # 差分が0存在していることを確認
    print(0)
    exit()
  else:
    for i in range(1,n,2):
      if a[i] != i + 1 or a[i+1] != i + 1:
        print(0)
        exit()
        
ans = 1        
for i in range(n//2):
  ans = ans*2%(10**9+7)
print(ans)

Measured memory_bytes: 20508
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
#def MXI(): return [LI() for i in range(n)]　
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
dp=[0 for i in range(n)]
height=LI()
dp[1]=abs(height[1]-height[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(height[i]-height[i-1]),dp[i-2]+abs(height[i]-height[i-2]))
#print(dp)
print(dp[-1])

Measured memory_bytes: 21652
S = str(input())
T = str(input())

S_len = len(S)
T_len = len(T)

max_match_count = 0

if T in S:
    print(0)
else:
    for i in range(S_len - T_len + 1):
        match_count = 0
        for j in range(T_len):
            if S[i+j:i+j+1] == T[j:j+1]:
                match_count += 1
                max_match_count = max(max_match_count,match_count)

    print(T_len - max_match_count)


Measured memory_bytes: 8976
int main(void){
           
    int a,b;
    char op;


while(1){
    scanf("%d %s %d", &a, &op, &b);
if(op=='+'){
  printf("%d\n",a+b);
} else if (op== '-'){
  printf("%d\n",a-b);
} else if (op== '*'){
  printf("%d\n",a*b);
} else if (op=='/'){
  printf("%d\n",a/b);
} else if (op=='?'){
  break;
}

}


    return 0;    
}

Measured memory_bytes: 600
#include<map>
#include<algorithm>
using namespace std;
#define SIZE 100002
#define QUERY 10001
int shop[SIZE];

int Bsearch(int n,int target){
  int l=0,r=n-1;
  int mid;
  while(l < r){
    mid = (r+l)/2;
    if ( shop[mid]> target){
      r=mid;
    }else if ( shop[mid]<target){
      l=mid;
    }else return 0;
    if ( l+1== r )break;
  }
  int ret1 = max(shop[mid],target)-min(shop[mid],target);
  int ret2 = max(shop[(mid+1)%n],target)-min(shop[(mid+1)%n],target);
  int ret3 = max(shop[(mid+n-1)%n],target)-min(shop[(mid+n-1)%n],target);  
  return min(ret1,min(ret2,ret3));
}

int solve(int n,map<int,int> &M){
  map<int,int>::iterator itr = M.begin();
  int ret =0;
  while(itr != M.end()){
    ret+= Bsearch(n,(*itr).first) * (*itr).second;
    itr++;
  }
  return ret;
}

main(){
  int d,n,m;
  while(cin>>d>>n>>m && d){
    shop[0]=0;
    for(int i=1;i<n;i++){
      int tmp;
      cin>>tmp;
      shop[i]=tmp;
    }
    shop[n++]=d;
    sort(shop,shop+n);
    map<int,int> M;
    for(int i=0;i<m;i++){
      int tmp;
      cin>>tmp;
      M[tmp]++;
    }
    cout <<solve(n,M)<<endl;
    
  }
  return false;
}

Measured memory_bytes: 1548
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

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

    rep(i,a.size()){
        cout << a[i];
        if(b.size() <= i) break;
        cout << b[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
int main()
{
    string s;
    cin >> s;
    int rain = 0;
    int maxRain = 0;
    rep(i,3){
        if(s[i] == 'R'){
            rain++; 
        } 
        else{
            if(maxRain < rain) maxRain = rain;
            rain = 0;
        } 
    }
    if(maxRain < rain) maxRain = rain;
    cout << maxRain << endl;   
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define MN 200005
#define LL long long
#define mp make_pair
#define fir first
#define sec second
#define pii pair<int,int>
inline void chkmax(int &a,int b){if(a<b)a=b;}
inline void chkmin(int &a,int b){if(a>b)a=b;}
inline int read(){
	   int a=0,fh=1;char c=getchar();
	   while(c>'9'||c<'0'){if(c=='-')fh=-1;c=getchar();}
	   while('0'<=c&&c<='9'){
		   a=a*10+c-48;
		   c=getchar();
	   }
	   return a*fh;
}
LL n,a[MN],f[MN][3];
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	if(n%2==0){
		LL tmp=0,tmp1=0;
		for(int i=2;i<=n;i+=2)tmp+=a[i];
		for(int i=1;i<=n;i+=2)tmp1+=a[i];
		tmp=max(tmp,tmp1);
		memset(f,-0x3f,sizeof(f));
		f[1][0]=a[1];f[1][1]=0;
		f[0][0]=0;
		f[2][1]=a[2];f[2][2]=0;
		for(int i=3;i<=n;++i){
			f[i][0]=f[i-2][0]+a[i];
			f[i][1]=f[i-3][0]+a[i];
			f[i][1]=max(f[i][1],f[i-2][1]+a[i]);
			f[i][2]=max(f[i-2][2]+a[i],f[i-3][1]+a[i]);
		}
		printf("%lld\n",max(f[n][1],max(f[n][0],tmp)));
	}
	else{
		LL tmp=0;
		for(int i=2;i<=n;i+=2)tmp+=a[i];
		memset(f,-0x3f,sizeof(f));
		f[1][0]=a[1];f[1][1]=0;
		f[0][0]=0;
		f[2][1]=a[2];f[2][2]=0;
		for(int i=3;i<=n;++i){
			f[i][0]=f[i-2][0]+a[i];
			f[i][1]=f[i-3][0]+a[i];
			f[i][1]=max(f[i][1],f[i-2][1]+a[i]);
			f[i][2]=max(f[i-2][2]+a[i],f[i-3][1]+a[i]);
		}
		tmp=max(tmp,f[n-1][1]);tmp=max(tmp,f[n-1][0]);
		printf("%lld\n",max(f[n][1],max(tmp,f[n][2])));
	}
	return 0;
}


Measured memory_bytes: 10012
h, w = map(int, input().split())
t = []
goodx = [0]*110
goody = [0]*110

for i in range(h):
    t.append(input())

for i in range(h):
    for j in range(w):
        if t[i][j] == "#":
            goodx[i] = 1
            goody[j] = 1

for i in range(h):
    if goodx[i]:
        for j in range(w):
            if goody[j]:
                print(t[i][j], end="")
        print()

Measured memory_bytes: 4468
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()

s = []
tmp = N
if N == 0:
	print(0)
	sys.exit()
while tmp != 1:
	s.append(str(-1*(tmp%(-2))))
	tmp = ceil(tmp/(-2))
s.append("1")
print("".join(s)[::-1])


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

using namespace std;

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

  // 最初がマイナス
  long long sum1 = 0, count1 = 0;
  for(int i = 0; i < n; i++) {
    sum1 += a[i];
    if(i % 2 == 0) {
      count1 += max(0LL, sum1 + 1);
      sum1 -= max(0LL, sum1 + 1);
    }
    else {
      count1 += max(0LL, -sum1 + 1);
      sum1 += max(0LL, -sum1 + 1);
    }
  }

  // 最初がプラス
  long long sum2 = 0, count2 = 0;
  for(int i = 0; i < n; i++) {
    sum2 += a[i];
    if(i % 2 == 1) {
      count2 += max(0LL, sum2 + 1);
      sum2 -= max(0LL, sum2 + 1);
    }
    else {
      count2 += max(0LL, -sum2 + 1);
      sum2 += max(0LL, -sum2 + 1);
    }
  }

  cout << min(count1, count2) << endl;
}

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

int main() {
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int ice[10000], count[10]={0};
		for(int i=0; i<n; i++){
			cin >> ice[i];
			count[ice[i]]++;
		}
		for(int j=0; j<10; j++){
			if(count[j]==0) cout << "-" << endl;
			else{
				for(int k=0; k<count[j]; k++){
					cout << "*";
				}
				cout << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include <algorithm>
#include<string.h>
#define ll long long
#define ull unsigned long long
using namespace std;
struct edge{
	int to, nxt;
}e[70];
int head[10], tot = 1;
void add(int v, int u)
{
	e[tot].to = u, e[tot].nxt = head[v], head[v] = tot++;
}
int gt[10], used[10], n, m;
set<int> st; 
void dfs(int x, int dep)
{
	if (dep == n - 1)
	{
		int ans = 0;
		for (int i = 0; i < dep; i++)
			ans = ans * 10 + gt[i];
		st.insert(ans);
		return;
	}
	for (int u = head[x]; u; u = e[u].nxt)
	{
		int v = e[u].to;
		if (!used[v])
		{
			gt[dep] = v;
			used[v] = 1;
			dfs(v, dep + 1);
			used[v] = 0;
		}
	}
}
signed main() 
{
	used[1] = 1;
	while (~scanf("%d%d", &n, &m))
	{
		memset(head, 0, sizeof(head));
		st.clear();
		for (int i = 0; i < m; i++)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			add(a, b), add(b, a);
		}
		dfs(1, 0);
		printf("%d\n", st.size());
	}
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	final static long MOD = 1000000007;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String Str = in.readLine();

		int N=0;
		int S=0;
		int W=0;
		int E=0;
		for(int i=0;i<Str.length();i++){
			switch (Str.charAt(i)){
			case 'N':
				N++;
				break;
			case 'S':
				S++;
				break;
			case 'W':
				W++;
				break;
			case 'E':
				E++;
				break;
			}
		}

		String ans = "Yes";
		if((N==0&&S!=0) || (N!=0&&S==0) ||(E==0&&W!=0) || (E!=0&&W==0)){
			ans="No";
		}

		System.out.println(ans);


	}
}


Measured memory_bytes: 21332
#include <boost/math/common_factor.hpp>
#include <cstdio>

using ull = unsigned long long;

int main() {
    ull a, b, c, d;
    std::scanf("%llu %llu %llu %llu", &a, &b, &c, &d);

    a -= 1;

    auto cm = [=](auto n) { return b / n - a / n; };

    std::printf("%llu", b - a - cm(c) - cm(d) + cm(boost::math::lcm(c, d)));
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
constexpr int inv(LL x, int m) { return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
constexpr int mpow(LL a, LL k, int m) { int r(1); for (a %= m; k; k >>= 1, a = a * a % m) if (k & 1)r = r * a % m; return r; }

const int N = 1e5 + 5;
int n, H[N], F[N];

int main() {
    cin >> n;
    FI(i, 1, n) scanf("%d", H + i);
    F[2] = abs(H[1] - H[2]);
    FI(i, 3, n) F[i] = min(F[i - 1] + abs(H[i] - H[i - 1]), F[i - 2] + abs(H[i] - H[i - 2]));
    cout << F[n] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <algorithm>

void process_dataset() {
	size_t n;
	size_t k;
	std::cin >> n >> k;

	std::multiset<int, std::greater<int>> distances;
	int old_dist = -1;
	for (size_t i = 0; i < n; ++i) {
		int dist;
		std::cin >> dist;
		if (i != 0) {
			distances.emplace(dist - old_dist);
		}
		old_dist = dist;
	}

	if (distances.size() < k) {
		std::cout << 0 << std::endl;
	} else {
		auto it = distances.cbegin();
		std::advance(it, k - 1);
		std::cout << std::accumulate(it, distances.cend(), 0) << std::endl;
	}
}

int main() {
	int set_count;
	std::cin >> set_count;
	for (int i = 0; i < set_count; i++) {
		process_dataset();
	}
}

Measured memory_bytes: 7712
#include<bits/stdc++.h>
#define LL long long
using namespace std;

char a[1005],b[1005];
int main()
{
	int i,j;
	int ans=1005;
	scanf("%s",a+1);
	scanf("%s",b+1);
	int la=strlen(a+1),lb=strlen(b+1);
	for(i=lb;i<=la;i++)
	{
		int cnt=0;
		for(j=0;j<lb;j++)
			if(a[i-j]!=b[lb-j]) cnt++;
		ans=min(ans,cnt);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3816
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    string s;
    cin >> s;

    char check = s[0];
    int ans = 0;
    for(int i = 1; i < s.size(); i++){
        if(check != s[i]){
            ans++;
            check = s[i];
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 512
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());
        int k = Integer.parseInt(sc.next());

        System.out.println(solve(a, b, c, k));
    }

    static int solve(int a, int b, int c, int k) {
        int max = Math.max(Math.max(a, b), c);
        return (a + b + c - max) + max * (int)Math.pow(2, k);

    }
}

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

int main(){
    int n,x ;
    cin >> n >> x ;
    int mn = 10000000 ;
    for(int i=0;i<n;i++){
        int m ; cin >> m ;
        x  -= m ;
        if(mn>m) mn = m ;
    }
    cout << n+x/mn << endl ;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Main {
	public static void main(String[] args) throws IOException {
		ArrayList<Integer> heights = new ArrayList<Integer>();
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		
		for (int i = 0; i < 10; i++) {
			int h = Integer.parseInt(br.readLine());
			
			heights.add(h);
		}
		
		Collections.sort(heights);
		Collections.reverse(heights);
		
		for (int i = 0; i < 3; i++) {
			System.out.println(heights.get(i));
		}
	}
}

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

int     main() {
        int N;
        cin >>N;
        vector<long> A(N+1);
        vector<long> B(N);
        for (int i=0; i<=N; i++) cin >>A.at(i);
        for (int i=0; i<N; i++) cin >>B.at(i);
        long S=0;
        for (int i=0; i<N; i++) {
                S += min(A.at(i), B.at(i));
                B.at(i) -= A.at(i);
                if (0<B.at(i)) {
                        S += min(A.at(i+1), B.at(i));
                        A.at(i+1) -= B.at(i);
                        if (0>A.at(i+1)) A.at(i+1)=0;
                }
        }
        cout << S << endl;
        return 0;
};

Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map(String::toInt)
    val aMap = Array(h) { readLine()!!.split(' ').map(String::toLong).toLongArray() }
    val bMap = Array(h) { readLine()!!.split(' ').map(String::toLong).toLongArray() }
    val diffMap = Array(h) { IntArray(w) }
    for (r in 0 until h) {
        for (c in 0 until w) {
            diffMap[r][c] = Math.abs(aMap[r][c] - bMap[r][c]).toInt()
        }
    }

    val size = (h + w) * 80
    val dp =
            Array(h) {
                Array(w) {
                    BooleanArray(size) { false }
                }
            }
    dp[0][0][Math.abs(aMap[0][0] - bMap[0][0]).toInt()] = true
    for (r in 0 until h) {
        for (c in 0 until w) {
            val diff = diffMap[r][c]
            for (i in 0 until size) {
                val minus = Math.abs(i - diff)
                val plus = i + diff
                if (r - 1 >= 0 && dp[r - 1][c][i]) {
                    if (dp[r][c].size > plus) dp[r][c][plus] = true
                    dp[r][c][minus] = true
                } else if (c - 1 >= 0 && dp[r][c - 1][i]) {
                    if (dp[r][c].size > plus) dp[r][c][plus] = true
                    dp[r][c][minus] = true
                }
            }
        }
    }

    val min = dp[h - 1][w - 1].indexOfFirst { it }
    println(min)
}


Measured memory_bytes: 158392
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    if(n < 105)
    {
      cout << 0 << endl;
      return 0;
    }
    int count = 0;
    for(int j = 105; j <= n; j += 2)
    {
        int ans = 0;
        for(int i = 1; i <= j; i++)
        {
            if (j % i == 0)
            {
                ans++;
            }
        }
        if(ans == 8)
        {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    const char *UNRESTORABLE = "UNRESTORABLE";
    const char Q = '?';
    const char A = 'a';

    char SD[51];
    char T[51];

    if (scanf("%s%s", SD, T) <2) return 0;

    int sdlen = strlen(SD);
    int tlen = strlen(T);

    int cnt = 0;
    char tmp[51];
    bool flg = false;
    for (int i = sdlen - tlen; 0 <= i; i--)
    {
        int tidx = 0;
        strcpy(tmp, SD);
        flg = true;
        for (int j = i; j < i + tlen; j++)
        {
            if (SD[j] == T[tidx] || SD[j] == Q)
            {
                SD[j] = T[tidx];
                tidx++;
            }
            else
            {
                flg = false;
                strcpy(SD, tmp);
                break;
            }
        }

        if (flg)
        {
            for (int k = 0; k < sdlen; k++)
            {
                if (SD[k] == Q) SD[k] = A;
            }
            break;
        }
    }

    printf("%s\n", flg ? SD : UNRESTORABLE);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int e[101][101];
    int R, C, r, c;
    int s, total;
 
    scanf("%d%d", &R, &C);
    for (r = 1; r <= R; r++) {
        for (c= 1; c <= C; c++) scanf("%d", &e[r][c]);
    }
     
    for (r = 1; r <= R; r++) {
        s = 0;
        for (c = 1; c <= C; c++) s += e[r][c];
        e[r][0] = s;
    }
    total = 0;
    for (c = 1; c <= C; c++) {
        s = 0;
        for (r = 1; r <= R; r++) s += e[r][c];
        e[0][c] = s;
        total += s;
    }
    for (r = 1; r <= R; r++) {
        for (c = 1; c <= C; c++) printf("%d ", e[r][c]);
        printf("%d\n", e[r][0]);
    }
    for (c = 1; c <= C; c++) printf("%d ", e[0][c]);
    printf("%d\n", total);
    return 0;
}


Measured memory_bytes: 2052
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> s(n);
    int sum = 0;
    rep(i,n){
        cin >> s[i];
        sum += s[i];
    }
    sort(s.begin(), s.end());
    rep(i,n){
        if(sum%10 != 0) break;
        sum -= s[i];
        if(sum%10 != 0) break;
        sum += s[i];
    }
    if(sum%10 == 0) sum = 0;
    cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256