akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> vc;
    while(n--) {
        int x;
        cin >> x;
        vc.push_back(x);
    }
    n = vc.size();
    bool flag = true;

    for (int i = 0; i < n; i++) {
        if (vc[i] % 2 == 0) {
            if (vc[i] % 3 != 0 && vc[i] % 5 != 0) {
                flag = false;
            }
        }
    }

    if (flag) {
        cout << "APPROVED" << '\n';
    } else {
        cout << "DENIED" << '\n';
    }

    return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
int main(void) {
    int num,i,j,count[6]={0};
    double height;
    scanf("%d",&num);
    for (i=0; i<num; i++) {
        scanf("%lf",&height);
        if (height<165.0) {
            count[0]++;
        } else if (height<170.0) {
            count[1]++;
        } else if (height<175.0) {
            count[2]++;
        } else if (height<180.0) {
            count[3]++;
        } else if (height<185.0) {
            count[4]++;
        } else {
            count[5]++;
        }
    }
    for (i=0; i<6; i++) {
        printf("%d:",i+1);
        for (j=0; j<count[i]; j++) printf("*");
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 640
s=gets.chomp
s="<"+s if s[0]==">"
s=s+">" if s[s.size-1]=="<"
n=s.size
cnt=0
l,r=0,0
n.times do |i|
  if s[i]=="<"
    l+=1
  else
    r+=1
  end
  if i==n-1 || (s[i]==">" && s[i+1]=="<")
    cnt+=(l*l-l)/2+(r*r-r)/2+[l,r].max
    l,r=0,0
  end
end
p cnt

Measured memory_bytes: 3852
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
    return a * a;
}

template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
    int H, W, d;
    cin >> H >> W >> d;

    string color = "RGBY";
    for (int x = 0; x < H; ++x) {
        for (int y = 0; y < W; ++y) {
            int u = x + y, v = x - y + 100000 * d;
            int kind = 0;
            kind += (u % (d * 2)) / d;
            kind += (v % (d * 2)) / d * 2;

            cout << color[kind];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#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<int, int>;

int main() {
   int N, M, K;
   cin >> N >> M >> K;
   vector<int> A(N);
   vector<int> B(M);
   rep(i, N) cin >> A[i];
   rep(i, M) cin >> B[i];

   ll tot = 0;
   rep(i, M) tot += B[i];

   int j = M;
   int ans = 0;
   rep(i, N+1) {
       while (j > 0 && tot > K) {
           j -= 1;
           tot -= B[j];
       }
       if (tot > K) break;
       ans = max(ans, i+j);
       if (i == N) break;
       tot += A[i];
   }
   cout << ans << endl;

}

Measured memory_bytes: 4836
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
using namespace std;
  
#define int long long int 
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
typedef vector<vi> vvi;
const int mod = 1e9 + 7; 

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define debug(...) cerr << "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define TC int t; cin >> t; while (t--) 

void Panda() {
    int n, m, k;
    cin >> n >> m >> k;
    UMO<int, int> row, col;
    set<pair<int, int>> in;
    vi r, c;
    for(int i = 0, x, y; i < k; i++) {
        cin >> x >> y;
        row[x]++, col[y]++;
        in.insert({x, y});
    }
    int x = 0, y = 0;
    for(auto i : row) x = max(x, i.second);
    for(auto i : col) y = max(y, i.second);
    for(auto i : row) if(i.second == x) r.EB(i.first);
    for(auto i : col) if(i.second == y) c.EB(i.first);
    int maxx = 0;
    for(int i = 0 ; i < size(r); i++) {
        for(int j = 0 ; j < size(c); j++) {
            if(in.find({r[i], c[j]}) == in.end()) {
                cout << x + y << endl;
                goto here;
            }
        }
    }
    cout << x + y - 1 << endl;
    here:;

}
  
int32_t main() {
 
    FAST;

    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout); 
    
    Panda();

    return 0; 
} 

Measured memory_bytes: 57276
use std::vec::Vec;

fn main() {
    let people = read_line().parse::<isize>().unwrap();
    let coords: Vec<isize> = read_line().split(' ').map(|s| s.parse::<isize>().unwrap()).collect();
    let take_place: isize = {
        let sum = coords.iter().sum::<isize>();
        (sum + (people / 2)) / people
    };
    let right = take_place * take_place;
    let hirou: isize = coords.iter().map(|coord| coord * coord - 2 * coord * take_place + right).sum::<isize>();
    println!("{}", hirou);
}
fn read_line() -> String {
    use std::io;
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line.pop();
    line
}

Measured memory_bytes: 4352
import static java.lang.Math.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int[] a = in.nextIntArray(n);
			Arrays.sort(a);

			long ans = INF;

			for (int i = 0; i < n; i++) {
				ans = min(ans, abs(a[i]-a[0])+abs(a[i]-a[n-1]));
			}

			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


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

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

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

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

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

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

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	while (b) {
		int r = a % b; a = b; b = r;
	}
	return a;
}
void solve() {
	int x; cin >> x;
	int g = gcd(x, 360);
	cout << 360 / g << "\n";
}


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


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

int main() {
	int A, B;
	cin >> A >> B;
	cout << (A + B) % 24;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

A+B時に始まるけど、次の日に始まる可能性があるので24時を過ぎたら24を引く操作が必要だね
これは24で割った余りに等しいよ
*/

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iterator>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include<functional>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <numeric>
//#include<unordered_map>
#define inf  2e9
#define seed 131
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) ((x)&(-x))
#define lrtnb srand(unsigned(time(NULL)))
#define lrtlh ios::sync_with_stdio(0)
#define lowb(a,n,x) lower_bound(a,a+n,x) - a
#define uppb(a,n,x) upper_bound(a,a+n,x) - a
#define lson l,mid,i<<1;
#define rson mid+1,r,i<<1|1;
#define ALL(x) x.begin(),x.end()
#define inv inline void
#define INS(x) inserter(x,x.begin())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> Si;
typedef set<ll> Sl;
ll gcd(ll n, ll m) { long long r; if (n < m)swap(n, m); while (m) { r = n % m; n = m; m = r; }return n; }
ll lcm(ll b, ll y) { return b * y / gcd(b, y); }
double dis(double x1, double y1, double x2, double y2) { double ans = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2); return sqrt(ans); }
double random(double start, double en) { return start + (en - start)*rand() / (RAND_MAX + 1.0); }
void read(int &n) { char c = '+'; int x = 0; bool flag = 0; while (c<'0' || c>'9') { c = getchar(); if (c == '-')flag = 1; }while (c >= '0'&&c <= '9')x = x * 10 + c - 48, c = getchar(); n = flag == 1 ? -x : x; }
int vis[15];
int a[15];
int main() {
	int n, k;
	cin >> n >> k;
	int x;
	mem(vis, 0);
	for (int i = 0; i < k; i++) {
		cin >> x;
		vis[x]++;
	}
	while (1) {
		int flag = 0;
		x = n;
		while (x) {
			int s = x % 10;
			//cout << s << endl;
			if (vis[s])
				flag = 1;
			x /= 10;
		}
		if (flag == 0)
			break;
		else
			n++;
	}
	cout << n << endl;
	//system("pause");
}

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

int main() {
	string s;

	cin >> s ;
	
	int ans = 0;

	if (s[0] == '1')ans++;
	if (s[1] == '1')ans++;
	if (s[2] == '1')ans++;

	cout << ans << endl;
	
}

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

int main(){
    int x, n, min=1000000000;
    cin >> x >> n;
    if(n == 0){
        cout << x << endl;
        return 0;
    }

    vector<int> p(n);
    for(int i=0; i<n; i++) cin >> p[i];
    for(int i=0; i<=200; i++){
        if(abs(i-x) < abs(min-x)){
            bool k = true;
            for(int t=0; t<n; t++){
                if(i == p[t]) k = false;
            }
            if(k) {
                min = i;
            }
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 3632
import copy

H, W, K = map(int, input().split())
c = []
for i in range(H):
	c.append(list(input()))
ans = 0

def tenchi(matrix, H, W):
	tmatrix = []
	for i in range(W):
		tmatrix_row = []
		for vector in matrix:
			tmatrix_row.append(vector[i])
		tmatrix.append(tmatrix_row)    
	return(tmatrix)
for i in range(2**(H+W)):
	tmp = i
	tmpc = copy.deepcopy(c)
	for j in range(H):
		if tmp % 2 == 1:
			tmpc[j] = ["."]*W
		tmp //= 2
	tmpc = tenchi(tmpc, H, W)
	for j in range(W):
		if tmp % 2 == 1:
			tmpc[j] = ['.']*H
		tmp //= 2
	
	count = 0
	for j in range(W):
		for k in range(H):
			if tmpc[j][k]=='#':
				count += 1
	if count == K:
		ans += 1

print(ans)

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

int dx[]{ 0,1,0,-1 }, dy[]{ 1,0,-1,0 };
char dir[] = "RDLU";
bool b[5][5][5][5];
int main() {
	rep(i, 9) {
		rep(j, i & 1 ? 5 : 4) {
			int d; scanf("%1d", &d);
			if (i & 1)b[i / 2][j][i / 2 + 1][j] = b[i / 2 + 1][j][i / 2][j] = d;
			else b[i / 2][j][i / 2][j + 1] = b[i / 2][j + 1][i / 2][j] = d;
		}
	}
	int id = 0, x = 0, y = 0;
	do {
		for (int i = 3; i <= 6; i++) {
			int nx = x + dx[(id + i) % 4], ny = y + dy[(id + i) % 4];
			if (0 <= nx&&nx < 5 && 0 <= ny&&ny < 5 && b[x][y][nx][ny]) {
				x = nx; y = ny; (id += i) %= 4; printf("%c", dir[id]); break;
			}
		}
	} while (x != 0 || y != 0);
	printf("\n");
}

Measured memory_bytes: 3024
N, L = [int(_) for _ in input().split()]

X = [L + i - 1 for i in range(1, N+1)]
if 0 in X:
    s = 0
elif abs(X[0]) < abs(X[-1]):
    s = X[0]
else:
    s = X[-1]

print(sum(X) - s)


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

// header area

int main(){
    string S; cin >> S;
    deque<char> dq;
    for(char c:S) dq.push_back(c);

    bool flip = false;
    int Q; cin >> Q;
    rep(i, Q){
        int ty;
        cin >> ty;
        if(ty == 1) {   // 反転はせず、反転flagを立てる（反転はO(S)かかる）
            flip = !flip;
        }else{  // 末尾
            int f; char c;
            cin >> f >> c;

            if(flip){   // 反転flagが立っている時、実際に反転するのではなく、入力方向を反転
                if(f==1) f=2;
                else if(f==2) f=1;
            }
            if(f==1){
                dq.push_front(c);
            } else{
                dq.push_back(c);
            }
        }
    }
    if(flip) reverse(dq.begin(), dq.end());
    string ans="";
    for (char c: dq) ans+=c;
    
    cout << ans << endl;

    return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
using lint=long long;
const int inf=1000000007;
int MOD;
long long modpow(lint x,lint n,lint rest){
    lint res=1;lint cur=x;
    while(n>0){
        if(n&1){
            res*=cur;res%=rest;
        }
        cur*=cur;cur%=rest;n/=2;
    }
    return res;
}
struct Nums{
    long long n;
    vector<long long> kaijo;
    Nums(int N){
        n=N;
        kaijo.push_back(1);
        for(long long i=1;i<=n;i++){
            kaijo.push_back((kaijo[i-1]*i)%MOD);
        }
    }
    long long modinv(long long a, long long m) {
        long long b = m, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }
    long long comb(long long N,long long K,long long rest){
        long long res=kaijo[N]*modinv(kaijo[K],rest)%rest;
        res*=modinv(kaijo[N-K],rest);
        res%=rest;
        return res;
    }
};

signed main(){
  int n,m;cin>>n>>m;MOD=m;
  Nums lib(n+5);
  vector<vector<lint>> S(n+5,vector<lint>(n+5,0));
  rep1(i,n+4){
      S[i][i]=1;
      S[i][1]=1;
  }
  for(int i=3;i<n+5;++i){
      rep1(j,n+4){
          if(j>i)break;
          S[i][j]=S[i-1][j]*j+S[i-1][j-1];
          S[i][j]%=m;
      }
  }
  lint res=modpow(2,modpow(2,n,m-1),m);
  lint sub=0;
  rep1(i,n){
      lint sm=0;
      lint last=-1;
      rep1(j,n){
          if(j>i)break;
          //case of 1
          lint case1=S[i][j];
          lint hoge=modpow(2,n-i,m-1);
          lint hogehoge=modpow(2,hoge,m);
          lint hogehogehoge=modpow(2,j*(n-i),m);
          case1*=hogehoge;case1%=m;
          case1*=hogehogehoge;case1%=m;
          //case of 0
          lint case2=S[i][j]*j%m;
          case2*=hogehoge;case2%=m;
          if(last==-1)case2*=modpow(2,(j-1)*(n-i),m);
          else case2*=last;case2%=m;
          last=hogehogehoge;
          //printf("case1=%lld, case2=%lld\n",case1,case2);
          sm+=case1+case2;
      }
      sm%=m;
      //printf("sm=%lld\n",sm);
      sm*=lib.comb(n,i,m);sm%=m;
      //cout<<sm<<"\n";
      if(i&1)sub+=sm;
      else{
          sub+=m-sm;
      }
      sub%=m;
  }
  res+=m-sub;res%=m;
  cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 73964
object Main extends App {
    val hands = List("Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge", "Paper", "Air", "Water", "Dragon", "Devil", "Lightning", "Gun") 
    val h = (hands ::: hands).sliding(8).take(15).map(l => (l.head, l.tail)).toMap
    val in = io.Source.stdin.getLines
    for (n <- in if n != "0") {
        val x = in.take(n.toInt).toList
        val y = x.map(h(_)).flatten.distinct
        x.filterNot(y.contains _) match {
            case x@(h::_) if x.size != n.toInt => println(h)
            case _ => println("Draw")
        }
    }
}

Measured memory_bytes: 63772
import java.util.*;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = sc.next().split("");

        int ans = 0;
        String last = "";
        for(String value : s) {
            if (!last.equals(value))  {
                ans++;
            }
            last = value;
        }

        // 出力
        System.out.println(ans);
    }
}

Measured memory_bytes: 32696
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  ll ans = 0;
  ll N;
  cin>>N;
  for(int i = 1;i<=N;i++){
    if(i%3 != 0 && i%5 != 0){
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
R, C, K = map(int, input().split())

V = [[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    V[r][c] = v

dp0 = [[0]*(C+1) for _ in range(R+1)]
dp1 = [[0]*(C+1) for _ in range(R+1)]
dp2 = [[0]*(C+1) for _ in range(R+1)]
dp3 = [[0]*(C+1) for _ in range(R+1)]
for i in range(R+1):
    for j in range(C+1):
        v = V[i][j]

        la = lb = lc = ld = 0
        if j > 0:
            la = dp0[i][j-1]
            lb = dp1[i][j-1]
            lc = dp2[i][j-1]
            ld = dp3[i][j-1]
            dp2[i][j] = max(dp2[i][j], lc, lb + v)
            dp3[i][j] = max(dp3[i][j], ld, lc + v)

        if i > 0:
            max_p = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
            dp0[i][j] = max(dp0[i][j], max_p, la)
            dp1[i][j] = max(dp0[i][j], max_p + v, lb, la + v)

print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]))


Measured memory_bytes: 433460
n = int(input())
D = [list(map(int, input().split())) for i in range(n)]
# [cost, order]
memo = {(2**n-1, i): (0, ()) for i in range(n)}
def dfs(state, pos, w):
    if (state, pos) in memo:
        return memo[state, pos]
    res = None
    for i in range(n):
        if (state >> i) & 1 == 0:
            d0 = D[pos][1]
            s, d1, v = D[i]
            r = dfs(state | (1 << i), i, w + 20*v)
            val = (r[0]+abs(d0-d1)*(70+w), r[1]+(s,))
            if res is None or val < res:
                res = val
    if res:
        memo[state, pos] = res
    return res
def solve():
    for i in range(n):
        s0, d0, v0 = D[i]
        result = dfs(1 << i, i, 20*v0)
        yield result[0], result[1]+(s0,)
ans = min(solve())
print(*reversed(ans[1]))

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

int f(ll x, ll y){
  int cnt=0;
  ll z=max(x,y);
  while(z>0){
    z/=10;
    cnt++;
  }
  return cnt;
}

int main() {
  ll n; cin >> n;
    int ans=f(n,1);
  for(ll i=1LL;i*i<=n;i++){
    if(n%i==0){
      ll p=n/i;
      int e=f(i,p);
       ans=min(ans,e);
      }
    }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define MOD 1000000007
using namespace std;

long long dp[2005][2005];

int main(int argc, char *argv[])
{
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];

  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
	dp[i + 1][j + 1] = ((dp[i + 1][j] + dp[i][j + 1]) % MOD + 1) % MOD;
      } else {
	dp[i + 1][j + 1] = ((dp[i + 1][j] + dp[i][j + 1]) % MOD + (MOD - dp[i][j])) % MOD;
      }
    }
  }

  cout << (dp[n][m] + 1) % MOD << endl;

  return 0;
}
			


Measured memory_bytes: 31616
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Problem solver = new Problem();
        solver.solve(0, in, out);
        out.close();
    }

    static class Problem {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int[][] arr = new int[N][3];
            for (int i = 0; i < N; i++) {
                arr[i][0] = in.nextInt();
                arr[i][1] = in.nextInt();
                arr[i][2] = in.nextInt();
            }

            int[][] dp = new int[N][3];

            int res = maxPoints(arr, -1, 0, dp);
            out.println(res);
        }

        public int maxPoints(int[][] arr, int chosen, int index, int[][] dp) {
            if (index == arr.length)
                return 0;

            if (chosen != -1 && dp[index][chosen] != 0)
                return dp[index][chosen];

            int max = 0;
            for (int i = 0; i <= 2; i++) {
                if (chosen == i) continue;
                max = Math.max(max, arr[index][i] + maxPoints(arr, i, index + 1, dp));
            }

            if(chosen != -1)
                dp[index][chosen] = max;
            return max;
        }

    }

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

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

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

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

    }
}



Measured memory_bytes: 67380
N = int(input())
M = [[0 for _ in range(10)] for _ in range(10)]
ans = 0
for n in range(1,N+1):
    M[ord(str(n)[-1])-48][ord(str(n)[0])-48] += 1
for i in range(1,10):
    for j in range(1,10):
        ans += M[i][j] * M[j][i]
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>
#include <iomanip>


using namespace std;
using ll = long long;

template <int N>
struct Dominator {
    int idom[N], sdom[N];
    vector<int> g[N], rg[N];
    void init() {
        for (int i = 0; i < N; i++) {
            g[i].clear(); rg[i].clear();
        }
    }
    void add(int a, int b) {
        g[a].push_back(b);
        rg[b].push_back(a);
    }

    int idc, id[N], rid[N], par[N];
    void dfs(int p, int b) {
        if (id[p] != -1) return;
        par[p] = b;
        id[p] = idc; rid[idc] = p; idc++;
        for (int d: g[p]) {
            dfs(d, p);
        }
    }

    // unionfind
    int p[N];
    int mv[N];
    void merge(int a, int b) {
        p[a] = b;
    }
    int group(int a) {
        if (p[a] == -1) return a;
        int pa = group(p[a]);
        if (id[sdom[mv[a]]] > id[sdom[mv[p[a]]]]) {
            mv[a] = mv[p[a]];
        }
        return p[a] = pa;
    }

    vector<int> bucket[N];
    int V[N];
    void exec(int s, int n = N) {
        // uf init
        fill_n(p, n, -1);
        iota(mv, mv+n, 0);

        fill_n(id, n, -1);
        idc = 0;
        dfs(s, -1);
        iota(sdom, sdom+n, 0);

        for (int i = n-1; i > 0; i--) {
            int u = rid[i];
            for (int v: rg[u]) {
                group(v);
                sdom[u] = rid[min(id[sdom[u]], id[sdom[mv[v]]])];
            }
            bucket[sdom[u]].push_back(u);
            for (int v: bucket[par[u]]) {
                group(v);
                V[v] = mv[v];
            }
            bucket[par[u]].clear();
            merge(u, par[u]);
        }

        idom[s] = -1;
        for (int i = 1; i < n; i++) {
            int u = rid[i], v = V[u];
            if (sdom[u] == sdom[v]) idom[u] = sdom[u];
            else idom[u] = idom[v];
        }
    }
};

const int MN = 100100;
Dominator<MN> dn;

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t; s--; t--;
        dn.add(s, t);
    }
    dn.exec(0, n);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int r;
        cin >> r; r--;
        if (dn.idom[r] != 0) {
            cout << dn.idom[r]+1 << endl;
        } else {
            cout << r+1 << endl;
        }
    }
    return 0;
}

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

int main(){
    priority_queue<int> PQ;
    int N, M; cin >> N >> M;
    vector<pair<int, int>> pairs(N);
    for(int i = 0; i < N; i++) cin >> pairs[i].first >> pairs[i].second;

    sort(pairs.begin(), pairs.end());
    int index = 0;
    ll res = 0;

    for(int i = 1; i <= M; i++){
        for(int j = index; j < N; j++){
            if(pairs[j].first > i){
                index = j;
                break;
            }
            PQ.push(pairs[j].second);
            if(j == N - 1) index = N;
        }
        if(!PQ.empty()){
            res += PQ.top();
            PQ.pop();
        }
    }
    cout << res << endl;
}


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

using namespace std;

void hawawa()
{
	string str;
	string str2;
	cin >> str;
	cin >> str2;
	string str3 = str2;
	do {
		if (str2 == str) {
			cout << "Yes\n";
			return;
		}
		str2 = str2.substr(1) + str2[0];
	} while (str2 != str3);
	cout << "No\n";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> ii;
typedef std::pair<int, ii> iii;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<ii> vii;
typedef std::vector<iii> viii;
const int INF=10000000;
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define all(x) (x).begin(), (x).end()
const int NMAX=300000;

struct union_find {
  vi p; union_find(int n) : p(n, -1) { }
  int find(int x) { return p[x] < 0 ? x : p[x] = find(p[x]); }
  bool unite(int x, int y) {
    int xp = find(x), yp = find(y);
    if (xp == yp)       return false;
    if (p[xp] > p[yp])  std::swap(xp,yp);
    p[xp] += p[yp], p[yp] = xp;
    return true;
  }
  int size(int x) { return -p[find(x)]; }
};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int N,K,L;
  cin >> N >> K >> L;
  vector<int> p(K);
  vector<int> q(K);
  vector<int> r(L);
  vector<int> s(L);
  union_find A(N);
  union_find B(N);
  for (int i=0; i<K; i++){
    cin >> p[i] >> q[i];
    p[i]--; q[i]--;
    A.unite(p[i],q[i]);
  } 
  for (int i=0; i<L; i++){

    cin >> r[i] >> s[i];
    r[i]--; s[i]--;
    B.unite(r[i],s[i]);
  }
  int a,b;
  map<pair<int,int>,int> counter;
  for (int i=0; i<N; i++){
    a=A.find(i);
    b=B.find(i);
    if (counter.find({a,b})==counter.end()){
      counter[{a,b}]=0;
    }
    counter[{a,b}]++;
  }

  for (int i=0; i<N; i++){
    a=A.find(i);
    b=B.find(i);
    cout<<counter[{a,b}]<<" ";
  }





}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n;
  cin >> n;
  unordered_set<ll> st;

  ll a;
  rep(i, n) {
    cin >> a;
    if (st.count(a) != 0) {
      cout << "NO" << endl;
      return 0;
    }
    st.insert(a);
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 8520
n = int(input())
ls = list(map(int, input().split()))

ans = 0

for i in range(n):
    if i != n - 1:
        if ls[i] == i + 1:
            ls[i], ls[i + 1] = ls[i + 1], ls[i]
            ans += 1
    elif i == n - 1:
        if ls[i] == i + 1:
            ls[i], ls[i - 1] = ls[i - 1], ls[i]
            ans += 1

print(ans)

Measured memory_bytes: 14008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n;
int p[30],ans;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>p[i];
    for(int i=2;i<n;i++){
        int f=0;
        if(p[i]<p[i-1]){f++;}
        if(p[i]<p[i+1]){f++;}
        if(f==1){ans++;}
    }
    cout<<ans<<newl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int N = 1e5+10;

struct node{
    int v, pos;
    bool operator < (node o) {
        if(v == o.v) return pos < o.pos;
        return v < o.v;
    }
};
node b[N], c[N];
int a[N], vis[N];

int main() {
    int n; 
    while(~scanf("%d", &n)) {
        memset(vis, 0, sizeof(vis));
        for(int i = 0; i < n; ++ i) {
            scanf("%d", &a[i]);
        }
        for(int i = 0; i < n; ++ i) {
            int v; scanf("%d", &v);
            b[i] = {v, i};
        }
        std::sort(b, b+n);
        for(int i = 0; i < n; ++ i) {
            c[i] = {a[b[i].pos], i};
            // printf("%d ", b[i].pos);
        }
        // puts("");

        std::sort(c, c+n);
        // for(int i = 0; i < n; ++ i) {
        //     printf("%d ", i);
        // }
        // puts("");
        // for(int i = 0; i < n; ++ i) {
        //     printf("%d ", c[i].pos);
        // }
        // puts("");

        int s = c[0].pos;
        int t = c[s].pos;
        vis[0] = 1;
        vis[s] = 1;
        while(t != s) {
            vis[t] = 1;
            t = c[t].pos;
        }
        bool flag = false;
        for(int i = 0; i < n; ++ i) if(!vis[i]) flag = true;

        for(int i = 1; i < n; ++ i) {
            if(c[i].v <= b[i-1].v) flag = true;
        }
        for(int i = 0; i < n; ++ i) {
            if(c[i].v > b[i].v) flag = false;
        }
        if(flag) puts("Yes");
        else puts("No");
    }
}


Measured memory_bytes: 2560
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		100000									// 最大配列数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1AVal[D_ARRAY_MAX];								// 配列A
static int siACnt;												// 配列数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 配列数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列A - 取得
	for (i = 0; i < siACnt; i++) {
		fscanf(szpFpI, "%d", &si1AVal[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 配列B - 取得
	long long llACnt = 0;
	long long llBCnt = 0;
	for (i = 0; i < siACnt; i++) {
		int liBVal;
		fscanf(szpFpI, "%d", &liBVal);

		// 差
		int liDF = liBVal - si1AVal[i];

		// 加算回数
		if (liDF <= 0) {
			llBCnt -= liDF;
		}
		else {
			llACnt += liDF / 2;
			if (liDF % 2 == 1) {
				llACnt++;
				llBCnt++;
			}
		}
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 結果 - セット
	if (llACnt >= llBCnt) {
		sprintf(lc1Out, "Yes\n");
	}
	else {
		sprintf(lc1Out, "No\n");
	}

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

using namespace std;

int main()
{
  int N, A[1000];

  cin >> N;
  multiset< int > s;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    s.insert(A[i]);
  }


  double ret = 0.0;
  for(int i = 0; i < N; i++) {
    s.erase(s.find(A[i]));
    for(int j = 0; j < N; j++) {
      if(i != j) {
        s.erase(s.find(A[j]));
        ret = max(ret, double(*--s.end() + *--(--s.end())) / (A[i] - A[j]));
        s.insert(A[j]);
      }
    }
    s.insert(A[i]);
  }

  cout << fixed << setprecision(10) << ret << endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll ans = 0;
  auto base = a;
  if(x < a[0]){
    a[0] -= a[0] - x;
  }
  for(int i = 0; i < n-1;++i){
    if(a[i+1] + a[i] > x){
      a[i+1] -= (a[i+1] + a[i]) - x;
    }
  }
  for(int i = 0; i < n; ++i){
    ans += base[i] - a[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  string S;
  cin >> S;

  int ans = 0;
  int now = 0;

  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'A' || S[i] == 'T' ||S[i] == 'C' || S[i] == 'G') {
      now++;
      ans = max(now, ans);
    } else {
      now = 0;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;




int main() {
 long long dp[1000000];
 int a;
 cin>>a;
 rep(i,1000000){
   dp[i]=i;
 }
 dp[0]=0;
 rep(i,100000){
   long long sum3=6;
   long long sum9=9;
   rep(j,6){
    chmin(dp[i+sum3],dp[i]+1);
    sum3*=6;
   }
   rep(j,6){
     chmin(dp[i+sum9],dp[i]+1);
     sum9*=9;
   }
 }
 cout<<dp[a]<<endl;
}


Measured memory_bytes: 8064
# E - Rotation Matching

n, m = map(int, input().split())

if n % 2 == 1:
    l, r = 1, n - 1
    for i in range(m):
        print(l, r)
        l, r = l + 1, r - 1
else:
    l, r = 1, n
    x = (m + 1) // 2
    for i in range(x):
        print(l, r)
        l, r = l + 1, r - 1
    l += 1
    for i in range(m - x):
        print(l, r)
        l, r = l + 1, r - 1


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

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

using namespace std;
using ll = long long;

int main(void) {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  vector<ll> vec;
  rep(i, max(x, y) + 1) {
    ll val = 2 * c * i + max(0, x - i) * a + max(0, y - i) * b;
    vec.push_back(val);
  }
  vector<ll>::iterator iter = min_element(all(vec));
  cout << *iter << endl; 
  return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define rgt register
#define rint rgt int
#define LL long long
#define rll rgt LL
#define inf 0x7f7f7f7f
using namespace std;
template<class K>inline bool cmax(K&a,const K&b){return (a<b)?a=b,1:0;}
template<class K>inline bool cmin(K&a,const K&b){return (a>b)?a=b,1:0;}
inline int read() {
	rint s=0;
	rgt char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) s=(s<<1)+(s<<3)+c-'0',c=getchar();
	return s;
}
LL n,ans=LONG_LONG_MAX;
int main()
{
	scanf("%lld",&n);
	for(rll i=1;i*i<=n;i++)
		if(n%i==0) ans=min(ans,n/i+i);
	printf("%lld",ans-2);
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  int k;
  for (int i=1; i<=n; i++) {
    long tmp = i * (i + 1);
    if (tmp > 2 * n) {
      cout<<"No"<<endl;
      return 0;
    }
    if (tmp == 2 * n) {
      k = i;
      break;
    }
  }
  int ans[k+1][k];
  int v = 1, start = 0;
  while (start < k) {
    for (int i=start; i<k; i++) {
      ans[start][i] = v + i - start;
    }
    for (int i=start; i<k; i++) {
      ans[i+1][start] = v + i - start;
    }
    v += k - start;
    ++start;
  }
  cout<<"Yes"<<endl<<k+1<<endl;
  for (int i=0; i<k+1; i++) {
    cout<<k<<" ";
    for (int j=0; j<k; j++) {
      cout<<ans[i][j];
      if (j != k - 1) {
        cout<<" ";
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << endl; 
#define TIME (ld)clock()/CLOCKS_PER_SEC
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3000 + 7, mod = 998244353, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll INF = 1e18, inf = 1e15;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int a, b, c, d; 
int dp[maxn][maxn][3];
  
void solve() {
    cin >> a >> b >> c >> d; 
    dp[a][b][0] = 1;   
    for (int j = b + 1; j < maxn; ++j) {
        dp[a][j][0] = dp[a][j - 1][0] * a;  
        dp[a][j][0] %= mod; 
    }
    for (int i = a + 1; i < maxn; ++i) {
        for (int j = b; j < maxn; ++j) {
            if (i == a && j == b) continue; 
            dp[i][j][1] += (dp[i - 1][j][0] + dp[i - 1][j][1] + dp[i - 1][j][2]) * j;

            dp[i][j][2] += dp[i][j - 1][2] * i;
            dp[i][j][2] += dp[i][j - 1][1];                 

            dp[i][j][0] %= mod; 
            dp[i][j][1] %= mod; 
            dp[i][j][2] %= mod; 
        }             
    }   
    cout << (dp[c][d][0] + dp[c][d][1] + dp[c][d][2]) % mod; 
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

Measured memory_bytes: 215436
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,m = readline() |> split |> parseMap
	e = [[Int[],Int[]] for i in 1:n]
	for i in 1:m
		l,r,d = readline() |> split |> parseMap
		push!(e[l][1], r)
		push!(e[l][2], d)
		push!(e[r][1], l)
		push!(e[r][2], -d)
	end
	flg = 0
	num = zeros(Int,n)
	vstc = 1
	vst = zeros(Int,n)
	vst[1] = 1
	stack = [1]
	ov = 1
	while !isempty(stack) || vstc < n
		if isempty(stack)
			for i in ov:n
				if vst[i] == 0
					push!(stack,i)
					vst[i] = 1
					vstc += 1
					ov = i
					break
				end
			end
		else
			now = pop!(stack)
			for i in 1:length(e[now][1])
				if vst[e[now][1][i]] == 0
					vst[e[now][1][i]] = 1
					vstc += 1
					num[e[now][1][i]] = num[now]+e[now][2][i]
					push!(stack, e[now][1][i])
				elseif num[e[now][1][i]] != num[now]+e[now][2][i]
					flg = 1
					break
				end
			end
		end
		if flg == 1
			break
		end
	end
	println(flg==0?"Yes":"No")
end

main()

Measured memory_bytes: 174652