akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll H, W, N, posH, posW, Sr, Sc;
string S, T;

void solve() {
	cin >> H >> W >> S;

	if (S[W - 1] == 'A') {
		S[W - 1] = 'a';
	}
	else if (S[W - 1] == 'B') {
		S[W - 1] = 'b';
	}
	else {
		S[W - 1] = 'c';
	}

	cout << S;
}

int main() {
	solve();
	cout << endl;
	return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

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

signed main() {
  int a, b;
  cin >> a >> b;
  if (b % a == 0) {
    cout << a + b << endl;
  } else {
    cout << b - a << endl;
  }

  return 0;
}

Measured memory_bytes: 256
// review
#include <iostream>
#include <vector>

using namespace std;
typedef pair<int, int> P;

int n;

void solve() {
  vector<P> v;
  for (int i=1;i<=n;i++) {
    for (int j=i+1;j<=n;j++) {
      if ((n & 1) && (j != n - i)) {
        v.push_back(P(i, j));
      } else if (!(n & 1) && (j != n - i + 1)) {
        v.push_back(P(i, j));
      }
    }
  }
  cout << v.size() << endl;
  for (int i = 0;i<v.size();i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
}

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


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 2019;

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

    ll N = S.size();

    map<ll, ll> mp;
    ll cur = 0;
    ll fac = 1;
    ++mp[cur];
    for (int i = 1; i <= N; ++i) {
        cur = (cur + (S[N - i] - '0') * fac) % mod;
        ++mp[cur];
        fac *= 10;
        fac %= mod;
    }

    ll ans = 0;
    for (auto &e : mp) {
        ans += e.second * (e.second - 1) / 2;
    }

    cout << ans << endl;
}

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

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

	int n, k;
	cin >> n >> k;
	vector<int> a(n+1);
	for(int i=1; i<=n; i++)
		cin >> a[i];

	vector<bool> dp(k+1);

	for(int i=1; i<=k; i++)
		for(int j=1; j<=n; j++)
			if(a[j]<=i)
				dp[i] = dp[i] or !dp[i-a[j]];

	if(dp[k])
		cout << "First" << endl;
	else
		cout << "Second" << endl;

	return 0;
}

Measured memory_bytes: 3616
//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;
 
template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}
 
    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};
 
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
template <class T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class K, class V> using Umap = gp_hash_table<K, V>;
using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;
 
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
//}}}


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    int n, x, m;
    cin >> n >> x >> m;

    int tmp = x;

    vector<int> cum(1e6);
    cum[1] = x;

    vector<int> f(1e6, -1);

    int l, r, k, len = -1;
    int res = 0;

    for(int i = 2; i <= n; ++i){
        res += tmp;
        int p = tmp * tmp % m; 
        tmp = p;
        if(~f[tmp]){
            l = f[tmp];
            r = i - 1;
            k = n - i + 1;
            len = i - l;
            break;
        }else{
            f[tmp] = i;
        }
        cum[i] = p + cum[i-1];
    }

    if(~len){
        res += k / len * (cum[r] - cum[l-1]);
        k %= len;
        res += cum[l + k - 1] - cum[l-1];
        cout << res << '\n';
    }else{
        cout << res + tmp << '\n';
    }

    return 0;
}

Measured memory_bytes: 18752
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[200001];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=n;i>=1;i-=2)
		printf("%d ",a[i]);
	if(n%2!=0)
		for(int i=2;i<=n;i+=2)
			printf("%d ",a[i]);
	else 
		for(int i=1;i<=n;i+=2)
			printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;


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

	string s,t,u;
	cin >> s>>t>>u;
	cout << s[0]<<t[0]<<u[0] << endl;
	return 0;
}

Measured memory_bytes: 256
//
// Created  on 20/03/22.
//

#include<iostream>

using namespace std;

int main()
{
    int m,n;
    cin>>n>>m;
    long long ans = 0;

   ans+=n>1?n*(n-1)/2:0;
    ans+=m>1? m*(m-1)/2 :0;
    cout<<ans<<endl;
    return 0;
}

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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
    int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    return x * fh;
}

void File() {
#ifdef zjp_shadow
	freopen ("f.in", "r", stdin);
	freopen ("f.out", "w", stdout);
#endif
}

const int N = (1 << 16) + 5, Mod = 1e9 + 7;

int n, m;

typedef long long ll;
ll fpm(ll x, int power) {
	ll res = 1;
	for (; power; power >>= 1, (x *= x) %= Mod)
		if (power & 1) (res *= x) %= Mod;
	return res;
}

ll fac[N], ifac[N];

void Init(int maxn) {
	fac[0] = ifac[0] = 1;
	For (i, 1, maxn) fac[i] = fac[i - 1] * i % Mod;
	ifac[maxn] = fpm(fac[maxn], Mod - 2);
	Fordown (i, maxn - 1, 1)
		ifac[i] = ifac[i + 1] * (i + 1) % Mod;
}

ll C(int n, int m) {
	if (n < 0 || m < 0 || n < m) return false;
	return fac[n] * ifac[m] % Mod * ifac[n - m] % Mod;
}

int maxsta, dp[17][N], a[17], bit[N];

inline void Add(int &a, int b) { if ((a += b) >= Mod ) a -= Mod; }

#define lowbit(x) (x & -x)
int main () {

	File();

	n = read(); m = read();

	For (i, 0, n) bit[1 << i] = i;

	Init((maxsta = ((1 << n) - 1)));

	For (i, 1, m) a[i] = read(); reverse(a + 1, a + m + 1);

	dp[0][0] = 1;
	For (i, 0, m - 1) For (sta, 0, maxsta) if (dp[i][sta]) {
		Add(dp[i + 1][sta], dp[i][sta]);
		for (register int nxt = maxsta ^ sta, j = bit[lowbit(nxt)]; nxt; nxt ^= lowbit(nxt), j = bit[lowbit(nxt)]) {
			Add(dp[i + 1][sta | (1 << j)], 
					dp[i][sta] * fac[1 << j] % Mod * C((1 << n) - sta - a[i + 1], (1 << j) - 1) % Mod);
		}
	}

	int ans = 0;
	For (sta, 0, maxsta) if (dp[m][sta]) {
		(ans += ((__builtin_popcount(sta) & 1) ? -1 : 1) * fac[(1 << n) - sta - 1] * dp[m][sta] % Mod) %= Mod;
		if (ans < 0) ans += Mod;
	}

	printf ("%lld\n", ans * (1ll << n) % Mod);

	return 0;

}


Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <queue>
#define USED 1
using namespace std;
typedef pair<int, int> pi;
int graph[200][200];
int used[200];
// first:weight, second:key
priority_queue<pi, vector<pi>, greater<pi>> pqueue;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> graph[i][j];   
    }
  }
  
 
  int ans = 0, key;
  pqueue.push(make_pair(0,0));
  for (int i = 0; i < n; i++) {
    pi p = pqueue.top();
    pqueue.pop();
    key = p.second;
    if (used[key] == USED) {
      i--;
      continue;
    }
    used[key] = USED;
    ans += p.first;
    //cout << "Distance: " << p.first << ", Key: " << p.second << endl;
    for (int j = 0; j < n; j++) {
      if (graph[key][j] != -1 && used[j] != USED) {
        pqueue.push(make_pair(graph[key][j],j));
      }
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 3252
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int aoki[100010], taka[100010];

void dfs(int key, vector<vector<int>> &p, int q[]){
	for(int i=0; i<p[key].size(); ++i){
		if(q[p[key][i]]<0){
			q[p[key][i]]=q[key]+1;
			dfs(p[key][i], p, q);
		}
	}
}

int main() {
	int N, u, v;
	cin >> N >> u >> v;
	vector<vector<int>> G(N+1);
	for(int i=1; i<N; ++i){
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i=1; i<=N; ++i){
		aoki[i]=-1;
		taka[i]=-1;
	}
	aoki[v]=0;
	dfs(v, G, aoki);
	taka[u]=0;
	dfs(u, G, taka);
	int ans=0;
	for(int i=1; i<=N; ++i){
		if(aoki[i]>taka[i]) ans=max(ans, aoki[i]);
	}
	cout << ans-1 << endl;
	return 0;
}

Measured memory_bytes: 10368
import java.util.Scanner;

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

        int cnt = 0;
        for(int i=1; i<=n; i++) {
            if(String.valueOf(i).length() % 2 != 0) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}


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

#define N 3003
#define endl '\n'
typedef long long ll;

int n;
double dp[N][N], p[N];

double f(int  i, int h){
  if(i==1 && h==1) return dp[i][h]=p[i];
  if(i==1 && h==0) return dp[i][h]=1-p[i];
  if(h>i) return dp[i][h]=0;
  if(dp[i][h]!=-1) return dp[i][h];
  return dp[i][h]=(1-p[i])*f(i-1,h) + p[i]*f(i-1, h-1);
}

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

  cin >> n;
  for(int i=1; i<=n; i++) cin >> p[i];

  for(int i=1; i<=n; i++){
    for(int j=0; j<=n; j++){
      dp[i][j]=-1;
    }
  }

  double ans=0;
  for(int i=n/2+1; i<=n; i++){
    ans+=f(n, i);
  }
  /*
  for(int i=1; i<=n; i++){
    for(int j=0; j<=n; j++){
      cout << dp[i][j] << '\t';
    }
    cout << endl;
  }*/
  cout << fixed;
  cout << setprecision(10) << ans << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l,m,n;
        cin>>n;
        vi v(n);
        cin>>v;
        ll dp[500][500],sum[500];
        clr(sum,0);
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
                dp[i][j]=peak;
        }
        sum[0]=0;
        for(i=1;i<=n;i++)
            sum[i]=sum[i-1]+v[i-1];
        for(i=0;i<n;i++)
        {
            dp[i][i]=0;
            for(j=i-1;j>=0;j--)
            {
                for(k=i;k>j;k--)
                {
                    dp[j][i]=min(dp[j][i],dp[j][k-1]+dp[k][i]+sum[i+1]-sum[j]);
                }
            }
        }
        cout<<dp[0][n-1];
    }
    return 0;
}

Measured memory_bytes: 1920
import * as fs from 'fs';

function Main(input: string) {
    let result = false;
    for(let i=0; i<3; i++) {
        if(input[i] === '7') {
            result = true;
            break;
        }
    }

    //output
    console.log(result ? 'Yes' : 'No');
}

// Don't edit this line!
Main(fs.readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29624
#include<bits/stdc++.h>
using namespace std;
int main(){
	char str[20];
	scanf("%s",str);
	int ans = 0;
	int len = strlen(str);
	for(int i=0;i<len;i++)
		ans +=str[i]-'0';
	int sum = str[0]-'0'-1+9*(len-1);
	printf("%d\n",max(sum,ans));
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int count = 0;
    String W = sc.next().toLowerCase();
    while(true){
      String s = sc.next();
      if(s.equals("END_OF_TEXT")){
        break;
      }
      else if(s.toLowerCase().equals(W)){
        count++;
      }
    }
    System.out.printf("%d\n", count);
  }
}


Measured memory_bytes: 26496
// 4/26 リアルタイム参加

#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;

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

    string S[N];
    set<string> ans;

    for (int i = 0; i < N; i++) {
        cin >> S[i];
        ans.insert(S[i]);
    }

    cout << ans.size() << endl;
}

Measured memory_bytes: 25452
#include <stdio.h>

int main(){
  int n,m,l;
  int a[100][100],b[100][100],i,j,k;
 unsigned long int c[100][100];
  scanf("%d %d %d",&n,&m,&l);
  for(i=0; i<n; i++){
    for(j=0; j<m; j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i=0; i<m; i++){
    for(j=0; j<l; j++){
      scanf("%d",&b[i][j]);
    }
  }
  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      c[i][j]=0;
    }
  }//----       
 for(i=0; i<n; i++){//                                                         
    for(j=0; j<l; j++){
      for(k=0; k<m; k++){
        c[i][j]+=(a[i][k]*b[k][j]);
      }
    }
  }
  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      if(j==l-1)printf("%ld\n",c[i][j]);
      else printf("%ld ",c[i][j]);
    }
  }
  return 0;
}

Measured memory_bytes: 756
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

int s[6001][6001];

int main() {
    i64 n, k;
    cin >> n >> k;
    for (int z = 0; z < n; ++z) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        int d = c == 'B';
        x %= 2 * k;
        y %= 2 * k;
        for (int i = 0; i < 4; ++i) {
            for (int j = 0; j < 4; ++j) {
                if ((i + j + d) & 1) continue;
                int tx = x + k * i, ty = y + k * j;
                s[tx][ty]++;
                s[tx + k][ty]--;
                s[tx][ty + k]--;
                s[tx + k][ty + k]++;
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i < 6 * k; ++i) {
        for (int j = 0; j < 6 * k; ++j) {
            if (i > 0) s[i][j] += s[i - 1][j];
            if (j > 0) s[i][j] += s[i][j - 1];
            if (i > 0 && j > 0) s[i][j] -= s[i - 1][j - 1];
            ans = max(ans, s[i][j]);
        }
    }

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

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


int main(){
  ll n,a;
  ll ans=0;
  ll mina=2;
  cin>>n;
  cin>>a;
  if(a>1) ans+=(a-1);
  n--;
  while(n--){
    cin>>a;
    if(a>mina)ans+=(a-1)/mina;
    else if(mina==a) mina++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//DFS使った全探索か。
//11111→11112→11113...11115→11122→...→55555
ll N,M,Q,ans=0,sum=0;
vector<ll> Z(11),A(55),B(55),C(55),D(55);
void dfs(ll d, ll p){
  for(int i=p; i<=M; i++){
    Z[d]=i;
    if(d<N-1) dfs(d+1,i);
    if(d==N-1){//Zでそろったら判定
      sum=0;
      for(int j=0; j<Q; j++) if(Z[B[j]-1]-Z[A[j]-1]==C[j]) sum+=D[j];
      ans=max(ans,sum);  
    }
  }
}
int main(){
  cin>>N>>M>>Q;
  for(int i=0; i<Q; i++) cin>>A[i]>>B[i]>>C[i]>>D[i];
  dfs(0,1);//深さと最初の数
  cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair

void solve(int test)
{

    long long n;
    cin>>n;
    long long hell = 998244353;

    long long i,j;

    vector<long long>dp(n+1,0LL);

    long long k;
    cin>>k;

    vector<pair<long long, long long > >v(k);

    for(i=0;i<k;i++)
    {
        cin>>v[i].first;
        cin>>v[i].second;
    }
    sort(v.begin(),v.end());

    dp[1] = 1;
    vector<long long>prefix(n+2,0LL);
    prefix[1] = 1LL;

    for(i=2;i<=n;i++)
    {
       for(j=0;j<v.size();j++)
       {
          if(v[j].first>=i)
            break;
          long long l = max(1LL, i-v[j].first);
          long long r = max(1LL, i-v[j].second);

          //cout<<l<<" "<<r<<endl;

          dp[i] = (dp[i] + prefix[l] - prefix[r-1])%hell;
       }

       dp[i] = dp[i]%hell;
       if(dp[i]<0)dp[i] = dp[i]+hell;
       dp[i]  =dp[i]%hell;

       prefix[i] = (prefix[i-1] + dp[i])%hell;
    }


    cout<<dp[n]<<endl;

    return;
}

int main() {

 int t = 1;
// cin>>t;

 for(int x=1;x<=t;x++)
 {
    solve(x);
 }
  return 0;
}


Measured memory_bytes: 6420
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s, t = "CODEFESTIVAL2016";
    cin >> s;
    int ans = 0;
    rep(i, 16) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    VL d(n);
    REP(i,n)cin>>d[i];
    SORT(d);
    LL x = d[n/2 - 1];
    LL y = d[n/2];
    PUTS(y - x);

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int R;
	char C;

	cin >> C;
	
	if ((C == 'a') ||(C == 'i') ||(C == 'u') ||(C == 'e') ||(C == 'o') ){
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
	
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
 int x,y;
 for(int a=1; ;a++){
   scanf("%d%d",&x,&y);
   if(x==0&&y==0)
   break;
   if(x>y)
   printf("%d %d\n",y,x);
   else
   printf("%d %d\n",x,y);
 }
 return 0;
}


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

double dp[3001][3001];

double solve(vector<double>& ar,int i,int x)
{
    if(x==0)  // no matter how many coins we can get 1 head
        return 1;
    if(i==0)//0 coins
        return 0;

    if(dp[i][x]>-0.9)// if value is precomputed
       return dp[i][x];

       return dp[i][x] = ar[i]*solve(ar,i-1,x-1)+ (1-ar[i])*solve(ar,i-1,x);

}
int main()
{
    int n;
    cin>>n;
    memset(dp,-1,sizeof dp);
     vector<double>ar(n+1);

     for(int i=1;i<=n;i++)
        cin>>ar[i];

       cout<<fixed<<setprecision(10)<<solve(ar,n,(n+1)/2);
        return 0;
}


Measured memory_bytes: 70784
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<list>

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<pair<int,int>> AB(N);

	for (int i = 0; i < N; i++)
	{
		int A, B;
		cin >> A >> B;
		AB[i] = make_pair(A, B);
	}
	sort(AB.begin(), AB.end());
	int looking = 0;
	long long output = 0;
	while (M != 0)
	{
		if (M >= AB[looking].second)
		{
			//ザイコ　タリナイ
			output += (long long)AB[looking].first * AB[looking].second;
			M -= AB[looking].second;
			looking++;
		}
		else
		{
			output += (long long)AB[looking].first * M;
			M = 0;
		}
	}
	cout << output << endl;


	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    ll A, B, M;
    cin >> A >> B >> M;
    vi a(A);
    REP(i, A)
    {
        cin >> a[i];
    }
    vi b(B);
    REP(i, B)
    {
        cin >> b[i];
    }
    vi x(M), y(M), c(M);
    REP(i, M)
    {
        cin >> x[i] >> y[i] >> c[i];
    }
    ll z = INF;
    REP(i, B)
    {
        z = min(z, b[i]);
    }
    vi dp(A + 1, INF);
    REP(i, M)
    {
        dp[x[i]] = min(dp[x[i]], a[x[i] - 1] + b[y[i] - 1] - c[i]);
    }
    ll ans = INF;
    REP(i, A)
    {
        ans = min({ans, dp[i + 1], a[i] + z});
    }

    OUT(ans);
}

Measured memory_bytes: 6272
from decimal import *
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())
getcontext().prec=20
if A==B:
    print("YES")
elif A<B:
    if (V>W):
        if 0<=B-A<=T*(V-W):
            print("YES")
        else:
            print("NO")
    elif (V<=W):
        print("NO")
else:   #A>B
    if V>W:
        if 0<=A-B<=T*(V-W):
            print("YES")
        else:
            print("NO")
    elif (V<=W):
        print("NO")


Measured memory_bytes: 71112
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 110;
const int MAXK = 510;

string s;
stack<int> st;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> s;
    int res = 0;
    FOR(i,0,SZ(s)-1)
        if (st.empty()) st.push(s[i] - '0');
        else {
            if (st.top() == s[i] - '0') st.push(s[i]-'0');
            else {
                st.pop();
                //cout << i << endl;
                res += 2;
            }
        }
    cout << res;
    return 0;
}

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

int ans[100000][3];

int main(){
	int n;
	cin>>n;
	int arr[n][3];
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}
	ans[0][0]=arr[0][0];
	ans[0][1]=arr[0][1];
	ans[0][2]=arr[0][2];
	for(int i=1;i<n;i++){
		if(ans[i-1][1]>ans[i-1][2])
			ans[i][0]=ans[i-1][1]+arr[i][0];
		else
			ans[i][0]=ans[i-1][2]+arr[i][0];
		if(ans[i-1][0]>ans[i-1][2])
			ans[i][1]=ans[i-1][0]+arr[i][1];
		else
			ans[i][1]=ans[i-1][2]+arr[i][1];
		if(ans[i-1][0]>ans[i-1][1])
			ans[i][2]=ans[i-1][0]+arr[i][2];
		else
			ans[i][2]=ans[i-1][1]+arr[i][2];
		//cout<<arr[i][0]<<endl<<arr[i][1]<<endl<<arr[i][2]<<endl;
		
	}
	int max=0;
	for(int i=0;i<3;i++){
		if(ans[n-1][i]>max)
			max=ans[n-1][i];
	}
	cout<<max<<endl;
}

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

int main() {
  int n; cin >> n;
  vector<int> l(n);
  for (int i=0; i<n; i++){
    cin >> l.at(i);
  }

  bool flag = true;
  int ans = 0;
  while (flag) {
    flag = false;
    for (int i=n-1; i>0; i--){
      if (l.at(i-1) > l.at(i)) {
        swap(l.at(i-1), l.at(i));
        ans++;
        flag = true;
      }
    }
  }
  for (int i=0; i<n-1; i++){
    cout << l.at(i) << " ";
  }
  cout << l.at(n-1) << endl;
  cout << ans << endl;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
typedef long long ll;
ll binaryPow(ll a, ll b, ll m)
{
    if(b == 0)
        return 1;
    else if(b % 2 == 1)
        return a * binaryPow(a, b - 1, m) % m;
    else
    {
        ll num = binaryPow(a, b/2, m) % m;
        return num * num % m;
    }
}
ll C(ll n,ll m)
{
    if(n < m) return 0;
    ll res = 1;
    for(int i=1; i<=m; i++)
    {
        ll a = (n+i-m)%mod;
        ll b = i%mod;
        res = res*(a*binaryPow(b,mod-2,mod)%mod)%mod;
    }
    return res;
}
ll Lucas(ll n,ll m)
{
    if(m == 0) return 1;
    return C(n%mod, m%mod) * Lucas(n/mod,m/mod)%mod;
}
int main()
{
    ll n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);
    ll ans=binaryPow(2,n,mod)-1;
    ans=(ans-Lucas(n,a)+mod)%mod;
    ans=(ans-Lucas(n,b)+mod)%mod;
    printf("%lld\n",ans);
    return 0;
}


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

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


const int MAX = 100010;
const int INF = 2e9;
const lint LNF = 2e18;

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

	lint c=0, lb=0, rb=0;
	priority_queue<lint> L;
	priority_queue<lint, vector<lint>, greater<lint>> R;

	for(int i=1, sp=0, zp=0; i<=n; i++){
		int s, e, z; cin>>s>>e; z = e-s;
		lb -= z, rb += zp;
		lint l0 = (L.empty() ? -LNF : L.top()+lb);
		lint r0 = (R.empty() ? +LNF : R.top()+rb);
		if(l0<=s && s<=r0){
			L.push(s-lb); R.push(s-rb);
		}
		else if(s<l0){
			L.push(s-lb); L.push(s-lb);
			L.pop(); R.push(l0-rb);
			c += l0-s;
		}
		else if(r0<s){
			R.push(s-rb); R.push(s-rb);
			R.pop(); L.push(r0-lb);
			c += s-r0;
		}
		sp = s, zp = z;
	}

	cout<<c<<'\n';

	return 0;
}

Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
#define repe(i,n) for(int i=0;i<=n;i++)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(abs(A-C)<=D) cout << "Yes" << endl;
  else if(abs(A-B)<=D && abs(B-C)<=D) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
  int n,q;
  cin>>n;
  int S[n];
  for(int i=0;i<n;i++){
    cin>>S[i];
  }

  cin>>q;
  int T[q];
  for(int i=0;i<q;i++){
    cin>>T[i];
  }

  int cnt=0;
  for(int i=0;i<q;i++){
    for(int j=0;j<n;j++){
      if(S[j]==T[i]){cnt++;break;}
    }
  }
  cout<<cnt<<endl;
}



Measured memory_bytes: 3116
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
//#include <map>
#include <iomanip>
#include <vector>
#include <queue>

using namespace std;



int main()
{
	int n, s;
	char p[9], ne[5];
	
	cin >> n;
	for (int i=1; i<=n; i++)
	{
		cin >> s;
		cout << "Case " << i << ":" << endl;
		for (int j=0; j<10; j++)
		{
			sprintf(p, "%08d", s*s);
			ne[0]=p[2];ne[1]=p[3];ne[2]=p[4];ne[3]=p[5];ne[4]=0;
			printf("%d\n", atoi(ne));
			s = atoi(ne);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int >    vecint;
typedef vector<ll >      vecll;
typedef vector<double >   vecd;
typedef vector<string > vecstr;
typedef vector<char >  vecchar;
typedef vector<bool >  vecbool;
typedef vector<vector<bool> >  vec2bool;
typedef vector<vector<int> >    vec2int;
typedef vector<vector<double> >   vec2d;
////////////////////////////////////////////////
int main()
{
  int n; cin >> n;
  vecint b(n,0); REP(i,n)cin >> b[i];
  vecint ans(n,0);
  bool ok = false;
  REP(i,n){
    // REP(i,b.size() - 1)cout << b[i] << " ";
    // cout << endl;
    int ind = 0;
    ok = false;
    for(int j = b.size() - 1; j >= 0; j --){
      if(b[j] == j + 1){
	ind = j;
	ok = true;
	break;
      }
    }
    if(ok){
      ans[n - i - 1] = b[ind];
      b.erase(b.begin() + ind);
    }else{
      break;
    }
  }
  // cout << "finish" << endl;
  if(!ok){cout << -1 << endl;return 0;}
  REP(i,n){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
    int A,B,C,D,E,F,i,j,a,b,c,d,solution,solute,solvent,m_solution,m_solute;
    cin>>A>>B>>C>>D>>E>>F;
    A*=100;B*=100;
    double m=-1.0;
    for(a=0;a*A<=F;a++){
        for(b=0;a*A+b*B<=F;b++){
            solvent=a*A+b*B;
            for(c=0;c*C<=F;c++){
                for(d=0;c*C+d*D<=F;d++){
                    solute=c*C+d*D;
                    solution=solvent+solute;
                    if(solution>F)break;
                    if(solute<=E*solvent/100){
                        if(m<(double)solute/solution){
                            m=(double)solute/solution;
                            m_solution=solution;
                            m_solute=solute;
                        }
                    }
                }
            }
        }
    }
    cout<<m_solution<<" "<<m_solute<<endl;
    return 0;
}

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

#define rep(i,n) for(auto i=0*(n);i<(n);++i)

using namespace std;

int main(){
  string s;
  string s2="CODEFESTIVAL2016";
  cin >> s;

  int cnt = 0;

  rep(i,s.size()){
    if(s[i] != s2[i])++cnt;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+9;
typedef long long ll;
int main() {

	int n;
	cin >> n;
	int mn = n + 1, ans = 0;
	vector<int> v;
	for(int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		if(x < mn)
			ans++;
		mn = min(mn, x);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let _z:Vec<i64>=r();
    let v:Vec<i64>=r();
    let min=v.iter().min().unwrap();
    let max=v.iter().max().unwrap();
    let sum=v.iter().fold(0, |sum, i|sum + i);
    println!("{} {} {}",min,max,sum);
}
fn r<T:std::str::FromStr>()->Vec<T>{
    let mut b=String::new();
    let s=std::io::stdin();
    s.read_line(&mut b).unwrap();
    b.split_whitespace().flat_map(str::parse).collect()
}


Measured memory_bytes: 5036
import sys

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    K = int(input())
    A, B = map(int, input().split())
    ans = 'NG'
    for i in range(A,B+1):
        if i%K==0:
            ans  ='OK'
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
void out(ll x,ll y,ll z){
    printf("%lld %lld %lld\n",x,y,z);
    exit(0);
}
void f(){
    ll c,m;
    for(ll i=1;i<=3500;i++)
        for(ll j=1;j<=3500;j++){
            c=n*i*j;
            m=4*i*j-n*i-n*j;
            if(m>0&&c%m==0)out(i,j,c/m);
        }
}
int main(){
    cin>>n;
    if(n%2==0)out(n,n,n/2);
    if(n%3==0)out(n,n/3*2,n/3*2);
    if((n-3)%4==0)out((n+1)/4,(n+1)*(n+1)/4,(n+1)*(n+1)*n/4);
    if((n-1)%4==0)f();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N, numin, numax, res = 0;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++) cin >> vec[i];
  while(true) {
    while(true) {
      if(vec[0] == 0 && !vec.empty()) {
        vec.erase(vec.begin());
      }
      else {
        break;
      }
    }
    N = vec.size();
    for(int i = 0; i < N; i++) {
      if(vec[i] != 0) {
        numin = min(vec[i], numin);
      }
      else {
        break;
      }
    }
    for(int i = 0; i < N; i++) {
      if(vec[i] != 0) {
        vec[i] -= numin;
      }
      else {
        break;
      }
    }
    if(vec.empty()) break;
    else res += numin;
  }
  cout << res << endl;
}

Measured memory_bytes: 3608
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: u64 = iter.next().unwrap().parse().unwrap();
    let mut nums = vec![];
    dfs(0, n, &mut nums);


    println!("{}",
        nums.into_iter()
        .filter(|&i| sft_only(i))
        .count()
    );
}

fn dfs(k: u64, n: u64, acc: &mut Vec<u64>) {
    if k > n {
        return;
    }
    acc.push(k);
    dfs(k * 10 + 7, n, acc);
    dfs(k * 10 + 5, n, acc);
    dfs(k * 10 + 3, n, acc);
}

fn sft_only(mut k: u64) -> bool {
    let mut hmap = std::collections::HashMap::new();
    while k != 0 {
        *hmap.entry(k%10).or_insert(0) += 1;
        k /= 10;
    }
    *hmap.get(&7).unwrap_or(&0) >= 1 &&
    *hmap.get(&5).unwrap_or(&0) >= 1 &&
    *hmap.get(&3).unwrap_or(&0) >= 1 &&
    *hmap.get(&0).unwrap_or(&0) == 0
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>L;X--)
#define DEP2(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
#define X first
#define Y second
#define lson(X) ((X)<<1)
#define rson(X) ((X)<<1|1)
const int maxn=1e5+5;

int n,m,a[maxn];
int b[maxn],c[maxn];
int main(){
	int t;
	cin>>t;
	while(t--)
	{
		int n=10;
		REP(i,n) cin>>a[i];
		CLR(b,0);CLR(c,0);
		b[0]=a[0];
		int p=0,q=0,i=1;
		for(i=1;i<n;i++){
			int num=a[i];
			if(b[p]>=c[q]){
				if(num>b[p] && num>c[q]) b[++p]=num;
				else if(num>c[q] && num<b[p]) c[++q]=num;	
				else break;
			}
			
			else{
				if(num>b[p] && num>c[q]) c[++q]=num;
				else if(num>b[p] && num<c[q]) b[++p]=num;	
				else break;				
			}
		}
		if(i==n) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }


int main(){
    int N, K;
    cin >> N >> K;

    vector<ll> V(N, 0);
    rep(i, N) cin >> V[i];

    ll ans = 0;
    for (int l=0;l<=K;++l) {
        for (int r=0;r<=(K-l);++r) {
            if (l + r > N ) break;
            int d = K - l - r;
            ll now = 0;
            vector<ll> s;
            for (int i=0;i<l;++i) {
                now += V[i];
                s.push_back(V[i]);
            }
            for (int i=(N-r);i<N;++i) {
                now += V[i];
                s.push_back(V[i]);
            }
            sort(all(s));

            for (int i=0;i<min(d, (int)s.size());++i) {
                if (s[i] < 0) now -= s[i];
            }
            ans = max(ans, now);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define INF 10000000
#define N 500
//nil = -1, white = 0, black = 1

int main(){
  int i,j,min,x,sum=0;
  int n,A[N][N],B[N],C[N],color[N];

  //input
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      scanf("%d",&A[i][j]);
    }
  }
  //processing
  for(i=1;i<=n;i++){
    B[i] = INF;
    C[i] = -1;
    color[i] = 0;
  }
  B[1] = 0;
  while(1){
    min=INF;
    for(i=1;i<=n;i++){
      if(color[i]!=1&&B[i]<min){
	min=B[i];
	x=i;
      }
    }
    if(min==INF)break;
    color[x]=1;
    for(j=1;j<=n;j++){
      if(color[j]!=1&&A[x][j]<B[j]&&A[x][j]!=-1){
	C[j]=x;
	B[j]=A[x][j];
      }
    }
  }
  for(i=1;i<=n;i++){
    sum+=B[i];
  }
  printf("%d\n",sum);
  return 0;
}


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

  
void st(int a,vector<int> u){
  for(int i=a; ;i++){
    int n=i;
    while(n>0){
    if(u[n%10]){
      break;
    }
    n/=10;
    }
    if(n==0){
      cout<<i<<endl;
      break;
    }
  }
}
  

int main()
{

  
  
  
  int n,k;
  cin>>n>>k;
  vector<int> a(10);
  for(int i=0;i<k;i++){
    int f=0;
   
cin>>f;
    a[f]=1;
  }


  st(n,a);

}
 

Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <vector>

std::vector<int> edges[100000];
bool visited[100000];

std::deque<int> path;
bool dfs(int cur, bool rev) {
	if (!visited[cur]) {
		if (rev)
			path.push_front(cur);
		else
			path.push_back(cur);
	}
	visited[cur] = true;

	bool isLast = true;
	for (auto&& e : edges[cur]) {
		if (visited[e])
			continue;

		dfs(e, rev);
		isLast = false;
		break;
	}

	return isLast;
}

int main() {
	int n, m;
	std::cin >> n >> m;

	for (int i = 0; i < m; ++i) {
		int a, b;
		std::cin >> a >> b;
		--a, --b;

		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	int startIdx, minNumEdges = 20000000;
	for (int i = 0; i < n; ++i) {
		if (minNumEdges > edges[i].size()) {
			minNumEdges = edges[i].size();
			startIdx = i;
		}
	}
	
	dfs(startIdx, false);

	while (!dfs(path[0], true)) {}

	std::cout << path.size() << std::endl;
	std::cout << path[0] + 1;
	for (int i = 1; i < path.size(); ++i)
		std::cout << " " << path[i] + 1;

	std::cout << std::endl;
}

Measured memory_bytes: 11520
using System;
using System.Collections.Generic;

namespace AtCoder.ABC100
{
    class c
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var N = int.Parse(line);
            line = Console.ReadLine().Trim();
            var A = Array.ConvertAll<string, int>(line.Split(' '), new Converter<string, int>(s => int.Parse(s)));
            var cnt = 0L;
            foreach(int t in A)
            {
                var l = t;
                while (l % 2 == 0)
                {
                    ++cnt;
                    l /= 2;
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13792
#include <bits/stdc++.h>
        using namespace std;
        #define ll long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 1000000007
        #define inf 2e18

        int main() {

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

        ll count=1,ans=0;
        while(h>=1){
            ans+=count;
            h/=2;
            count*=2;
        }
        cout<<ans;


        return 0;
        }

Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App {
  val Array(n, m) = readLine.split(" ").map(_.toInt)
  val stairs = new Array[Boolean](n + 1)
  (1 to m).foreach{i => stairs(readInt) = true}

  def step(stair: Int, cur: Long, pre: Long): Long = {
    if (stair > n) cur
    else step(stair + 1, if (stairs(stair)) 0 else (cur + pre) % 1000000007, cur)
  }

  println(step(1, 1, 0))
}

Measured memory_bytes: 33000