akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <bits/stdc++.h>
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;

//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) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

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

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL l(n);
	cin >> l;
	SORT(l);
	LL ans = 0;
	for (int a = 0; a < n; a++) {
		for (int b = a+1; b < n; b++) {
			LL c1 = l[a]-l[b]; // c > a-b
			LL c2 = l[b]-l[a]; // c > b-a // 加減
			LL c3 = l[b]+l[a]; // c < a+b // 上限
			auto c1_itr = upper_bound(ALL(l), c1);
			auto c2_itr = upper_bound(ALL(l), c2);
			auto c3_itr = lower_bound(ALL(l), c3);
			LL c1_d = c1_itr - l.begin();
			LL c2_d = c2_itr - l.begin();
			LL c3_d = c3_itr - l.begin() - 1;
			ans += max(0LL, c3_d - max(c1_d, max(c2_d, (LL)b)));
		}
	}
	cout << ans << endl;
	return 0;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
 ll gcd(ll a,ll b){
 if(b == 0) return a;
 return gcd(b,a%b);
 }

//最小公倍数
 ll lcm(ll a,ll b){
 ll g = gcd(a,b);
 return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 




int main() {

string s;
cin >> s;

for(int i = 0; i < s.size(); i += 2) cout << s.at(i);
cout << endl;


}

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

typedef long long ll;
const int Maxn=210000;
const ll mod=1000000007;

int to[Maxn],nxt[Maxn],first[Maxn],tot=1,n,u,v;
ll f[Maxn][2];

inline void add(int u,int v) {
	to[tot]=v;
	nxt[tot]=first[u];
	first[u]=tot++;
	to[tot]=u;
	nxt[tot]=first[v];
	first[v]=tot++;
}

int dp(int root,int fa,int x) {
	if(~f[root][x]) return f[root][x];
	f[root][x]=1;
	for(int i=first[root];i;i=nxt[i])
		if(to[i]!=fa) {
			if(x) f[root][x]=f[root][x]*dp(to[i],root,0)%mod;
			else f[root][x]=f[root][x]*(dp(to[i],root,0)+dp(to[i],root,1))%mod;
		}
	return f[root][x];
}

int main() {
	scanf("%d",&n);
	for(int i=1;i<n;i++) {
		scanf("%d%d",&u,&v);
		add(u,v);
	}
	memset(f,-1,sizeof(f));
	printf("%d\n",(dp(1,1,0)+dp(1,1,1))%mod);
	return 0;
}


Measured memory_bytes: 14208
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,n) for(ll i=a;i<n;i++)
#define all(x) x.begin(),x.end()
#define bs binary_search
#define gcd(a,b) __gcd(a,b)
#define PI 3.1415926535897932384626
#define lp lower_bound
#define up upper_bound
#define minimum(a)	*min_element(a.begin(), a.end())
#define maximum(a)	*max_element(a.begin(), a.end())
#define UNIQUE(x) (x).resize(unique(all(x))-(x).begin())
#define bp(x)  __bulitin_popcount(x)
using namespace std;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}


const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;

ll a[3001];

int main()
{
boost
ll n,s;
cin>>n>>s;
loop(i,0,n)cin>>a[i];
    ll sum=s;

    ll dp[n+1][sum+1];
    memset(dp,0,sizeof(dp));
  //loop(i,0,n+1)dp[i][0]++;
loop(i,1,n+1){
   dp[i-1][0]++;
    loop(j,0,sum+1){
        dp[i][j]=dp[i-1][j];
      
if(j>=a[i-1]){dp[i][j]=(dp[i-1][j-a[i-1]]+dp[i][j])%FMOD;   }
}}
ll ans=0;
/*loop(i,0,n+1){
    loop(j,0,sum+1)cout<<dp[i][j]<<" ";
    cout<<"\n"; 
}*/
loop(i,1,n+1)ans+=dp[i][sum],ans%=FMOD;
cout<<ans<<"\n";

return 0;
}


Measured memory_bytes: 70656
#define DEBUG 0
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2019/8/4 20:55:31
 * Powered by Visual Studio Code
 */
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using ll = long long;
class mint
{
public:
  static ll MOD;
  ll x;
  mint() : x(0) {}
  mint(ll x) : x(x % MOD) {}
  mint operator-() const { return x ? MOD - x : 0; }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= MOD)
    {
      x -= MOD;
    }
    return *this;
  }
  mint &operator-=(const mint &a) { return *this += -a; }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint &operator/=(const mint &a)
  {
    mint b{a};
    return *this *= b.power(MOD - 2);
  }
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
  const mint power(ll N)
  {
    if (N == 0)
    {
      return 1;
    }
    else if (N % 2 == 1)
    {
      return *this * power(N - 1);
    }
    else
    {
      mint half = power(N / 2);
      return half * half;
    }
  }
};
ll mint::MOD = 1e9 + 7;
istream &operator>>(istream &stream, mint &a) { return stream >> a.x; }
ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; }
class combination
{
public:
  vector<mint> inv, fact, factinv;
  static int MAX_SIZE;
  combination() : inv(MAX_SIZE), fact(MAX_SIZE), factinv(MAX_SIZE)
  {
    inv[1] = 1;
    for (auto i = 2; i < MAX_SIZE; i++)
    {
      inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
    }
    fact[0] = factinv[0] = 1;
    for (auto i = 1; i < MAX_SIZE; i++)
    {
      fact[i] = mint(i) * fact[i - 1];
      factinv[i] = inv[i] * factinv[i - 1];
    }
  }
  mint operator()(int n, int k)
  {
    if (n >= 0 && k >= 0 && n - k >= 0)
    {
      return fact[n] * factinv[k] * factinv[n - k];
    }
    return 0;
  }
};
int combination::MAX_SIZE = 3000010;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// constexpr double epsilon = 1e-10;
// constexpr ll infty = 1000000000000000LL;
// constexpr int dx[4] = {1, 0, -1, 0};
// constexpr int dy[4] = {0, 1, 0, -1};
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}
void No()
{
  cout << "No" << endl;
  exit(0);
}

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  cout << max(C - (A - B), 0) << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int y = Integer.valueOf(s.substring(0,4));
    int m = Integer.valueOf(s.substring(5,7));
    int d = Integer.valueOf(s.substring(8));
    if(y<=2019){
      if(m<=4){
        if(d<=30){
          System.out.println("Heisei");
          return;
        }
      }
    }
    System.out.println("TBD");
  }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string[] line = S.Split(' ');
            int N = int.Parse(line[0]);
            int K = int.Parse(line[1]);
            S = Console.ReadLine();
            char[] C = new char[N];

            for(int i=0; i<N; i++)
            {
                C[i] = S[i];
                if (i != K - 1)
                {
                    Console.Write(C[i]);
                }
                else
                {
                    C[i] = Char.ToLower(C[i]);
                    Console.Write(C[i]);
                }

            }

            Console.WriteLine();


        }
    }
}

Measured memory_bytes: 11092
use std::io;

fn solve(){
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut l = buf.trim().parse::<i32>().unwrap();
    let res = (l as f64)/3f64;
    println!("{}",res*res*res);
}


fn main(){
    let mut t_cases = 1;
    // let mut buf = String::new();
    // io::stdin().read_line(&mut buf);
    // t_cases = buf.trim().parse::<i32>();
    for _ in 0..t_cases{
        solve();
    }
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 605;

char g[MAXN][MAXN];

int dp[MAXN][MAXN];

bool has_coin(int i, int j) {
	return i > 0 && j > 0 && i < MAXN && j < MAXN && g[i][j] == '#';
}

void solve(){
	int n, m;
	scanf("%d%d", &n, &m);
	REPN(i, 1, n) {
		scanf("%s", &g[i][1]);
	}
	ll ans = 0ll;
	REP(l, 0, 2) {
		REPN(s, 2, n + m) {
			REPN(i, 1, n) {
				dp[s][i] = 0;
			}
		}
		
		REPN(s, 2, n + m) {
			int i0 = 1;
			int j0 = s - i0;
			if (j0 > m) {
				i0 += j0 - m;
				j0 = m;
			}
			for(; i0 <= n; i0++, j0--) {
				dp[s][i0] = dp[s][i0 - 1] + (g[i0][j0] == '#' ? 1 : 0);
			}
		}
		
		REPN(i1, 1, n) {
			REPN(j1, 1, m) {
				if (!has_coin(i1, j1)) {
					continue;
				}
				REPN(i2, i1 + 1, n) {
					int j2 = j1 - (i2 - i1);
					if (j2 < 1) {
						break;
					}
					if (!has_coin(i2, j2)) {
						continue;
					}
					int s1 = (i1 + j1) - 2 * (i2 - i1);
					int ir = i1;
					int il = max(1, i1 - (i2 - i1));
					if (s1 >= 2) {
						int add = dp[s1][ir] - dp[s1][il - 1];
						ans += add;
						
						/*if (add != 0) {
							printf("%d %d %d %d: u %d\n", i1, j1, i2, j2, add);
						}*/
					}
					
					int s2 = (i1 + j1) + 2 * (i2 - i1);
					ir = min(n, i2 + (i2 - i1));
					il = i2;
					if (s2 <= n + m) {
						int add = dp[s2][ir] - dp[s2][il - 1];
						ans += add;
						
						/*if (add != 0) {
							printf("%d %d %d %d: d %d\n", i1, j1, i2, j2, add);
						}*/
					}
				}
			}
		}
		
		REPN(i, 1, n) {
			reverse(g[i] + 1, g[i] + m + 1);
		}
	}
	
	//printf("%d\n", ans);
	
	REPN(i1, 1, n) {
		REPN(j1, 1, m) {
			if (!has_coin(i1, j1)) {
				continue;
			}
			REPN(k, 1, n) {
				int i2 = i1 + k, j2 = j1 + k;
				int i3 = i1 - k, j3 = j1 + k;
				int i4 = i1 - k, j4 = j1 - k;
				int i5 = i1 + k, j5 = j1 - k;
				if (has_coin(i2, j2) && has_coin(i3, j3)) {
					ans--;
				}
				if (has_coin(i3, j3) && has_coin(i4, j4)) {
					ans--;
				}
				if (has_coin(i4, j4) && has_coin(i5, j5)) {
					ans--;
				}
				if (has_coin(i5, j5) && has_coin(i2, j2)) {
					ans--;
				}
			}
		}
		/*for(int i2 = i1 + 2; i2 <= n; i2 += 2) {
			REPN(j, 1, m) {
				if (g[i1][j] = '#' && g[i2][j] == '#') {
					
				}
			}
		}*/
	}
	
	printf("%d\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 1792
#include <stdio.h>

#define TWO 2

int getMostCandies (int N, int **matrix) {
    int max = 0;
    for (int i=0; i < N; i++) {
        int sum = 0;
        for (int j=0; j <= i; j++) {
            sum += matrix[0][j];
        }
        for (int j=i; j < N; j++) {
            sum += matrix[1][j];
        }
        if (sum > max) {
            max = sum;
        }
    }
    return max;
}

int main () {
    int N;
    int result;
    scanf("%d", &N);

    // Allocate Memory
    int **matrix = new int*[TWO];
    for (int i=0; i < TWO; i++) {
        matrix[i] = new int[N];
    }

    // Input Matrix
    for (int i=0; i < TWO; i++) {
        for (int j=0; j < N; j++) {
            scanf("%d", &matrix[i][j]);
        }
    }
    
    result = getMostCandies(N, matrix);
    printf("%d\n", result);

    // Delete Memory
    for (int i=0; i < TWO; i++) {
        delete[] matrix[i];
        matrix[i] = 0;
    }
    delete[] matrix;
    matrix = 0;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <utility>
using namespace std;
 
int main(){
  long long m, n;
  scanf("%lld %lld", &m, &n);
 
  if (m > n) swap(m, n);
 
  if (m == 1) {
    if (n == 1) printf("1\n");
    else if (n == 2) printf("0\n");
    else printf("%lld\n", n - 2);
  } else if (m == 2) {
    printf("0\n");
  } else printf("%lld\n", (n - 2) * (m - 2));
 
  return 0;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    string s; cin>>s;
    int len=sz(s),i=0,j=0;
    vi res(len,-1);
    while (i<len){
    	if (s[i]=='B') j--;
    	else if (s[i]=='1') res[j]=1,j++;
    	else res[j]=0,j++;
    	j=max(j,0LL);
    	i++;
    }
    for (int i=0;i<j;i++) cout << res[i] ; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> a(N,0);
    for(int i=0; i<N; ++i) {
        cin >> a[i];
    }

    int ro = 1;
    for(int i=0; i<N; ++i) {
        ro = a[ro-1];
        if(ro == 2) {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

long long int sum, a[100005];
long long int i, q, n, x, b, c;

int main()
{
    scanf("%lld", &n);
    for (i = 0; i < n; i++) {
        scanf("%lld", &x);
        a[x]++;
        sum += x;
    }
    scanf("%lld", &q);
    for (i = 0; i < q; i++) {
        scanf("%lld %lld", &b, &c);
        sum -= b*a[b];
        sum += c*a[b];
        a[c] += a[b];
        a[b] = 0;
        printf("%lld\n", sum);
    }
    return 0;
}

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

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

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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


    S = "Z" + S + "ZZZ";
    string T;
    REP(i,0,SZ(S)-2) {
        if(S.substr(i, 3) == "ABC") {
            T += "X";
            i += 2;
        }
        else if(S.substr(i, 2) == "BC") {
            T += "Y";
            ++i;
        }
        else T += S[i];
    }

    string P = T, Q = T;
    REP(i,0,SZ(P)) {
        if(P[i] == 'X' || i == 0) {
            ll r = i + 1;
            while(P[r] == 'Y' && P[r] != 'Z') ++r;
            while(P[r] != 'X' && P[r] != 'Z') {
                P[r] = 'Z';
                ++r;
            }
        }
    }
    REP(i,0,SZ(Q)) {
        if(P[i] == 'X' || i == SZ(Q) - 1) {
            ll l = i - 1;
            while(Q[l] == 'A' && Q[l] != 'Z') --l;
            while(Q[l] != 'X' && Q[l] != 'Z') {
                Q[l] = 'Z';
                --l;
            }
        }
    }
    REP(i,0,SZ(P)) P[i] = MIN(P[i],Q[i]);
    P = P.substr(1,SZ(P)-1);

    vector<string> R;
    string U;
    bool f = true;
    REP(i,0,SZ(P)) {
        if(P[i] == 'Z' && f) {
            R.pb(U);
            U = "";
            f = false;
        }
        else if(P[i] != 'Z'){
            if(P[i] == 'X') U += "AY";
            else U += P[i];
            f = true;
        }
    }
    
    ll cnt = 0;
    FORR(u,R) {
        ll c = 0;
        REP(i,0,SZ(u)) {
            if(u[i] == 'Y') {
                cnt += i - c;
                ++c;
            }
        }
    }
    PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    VI a(n), b(n), c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(all(a));
    sort(all(b));
    sort(all(c));

    ll ans = 0;
    for(int i = 0; i < n; i++){
        int bi = b[i];
        auto itrA = lower_bound(all(a), bi);
        if (itrA == a.begin()) continue;
        itrA--;
        auto itrC = upper_bound(all(c), bi);

        ll numA = itrA - a.begin() + 1;
        ll numC = n - (itrC - c.begin());
        ans += numA * numC;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4548
H,W = map(int,input().split())

if((H != 1)and(W != 1)):
  cnt1 = ((H+1)//2)*((W+1)//2)
  cnt2 = (H//2)*(W//2)
  ans = cnt1 + cnt2
else:
  ans = 1
  
print(ans)

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

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

int main() {
	
	//vector<int> a(n);  sort(a.begin(),a.end());
	//cout << "test" << "\n";
	cin.tie(0);
	ios::sync_with_stdio(false);
	//string ans="YES";
	
	
	ll ans=0;
	
	int n,m;
	cin >> n >> m; // n:カード m:ゲート
	
	vector<int> a(m),b(m);
	rep(i,m) cin >> a[i] >> b[i];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	
	ans=b[0]-a[m-1]+1; // b:min - a:max +1
	
	if(ans<0) ans=0;
	
	
	
	cout << ans << "\n";
	
	
	return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val N = nextInt()
    val S = next()
    var cnt = 0
    for (n in 0 until 1000) {
        val c = intArrayOf(n / 100, (n / 10) % 10, n % 10)
        var f = 0
        for (m in 0 until N) {
            if (S[m] == ('0' + c[f])) f += 1
            if (f == 3) break
        }
        if (f == 3) cnt += 1
    }

    println(cnt)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta

Measured memory_bytes: 34320
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int fact(int n){
    int p = 1;
    for(int i = 1; i <= n; i++){
        p = (p * i) % MOD;
    }
    return p;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n, m;
        cin >> n >> m;
        if(abs(n - m) > 1){
            cout << "0\n";
        }else if(n == m){
            cout << (fact(n) * fact(m) * 2) % MOD << '\n';
        }else{
            cout << (fact(n) * fact(m)) % MOD << '\n';
        }
    }
}

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long

const int N = 100 + 10;
const int MOD = 1e9 + 7;

int32_t main(){
    boost;
    //code
    
    char c;
    cin >> c;
    cout <<  ( ( c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u' ) ? "vowel" : "consonant"); 
    return 0;
}

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

int main() {
  // ここにプログラムを追記
  int N,A,B;
  cin >> N >> A >> B;
  int T = N*A;
  if(T<=B){
    cout << T << endl;
  }else{
    cout << B << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <queue>
using namespace std;
#define N 100050
int n,a[N];
int cmp(int x,int y) {return x>y;}
int main() {
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1,cmp);
	int x=0,y=0,p1=0,p2=0;
	for(;x<n&&y<a[x+1];x++,y++) ;
	for(;x+p1<=n&&y<=a[x+p1];p1++) ;
	for(;x<=n&&y+p2<=a[x];p2++) ;
	puts(((p1&1)&(p2&1))?"Second":"First");
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
string s,t;
char sp[26],tp[26];
main()
{
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
	{
		if(sp[s[i]-'a'])
		{
			if(sp[s[i]-'a']!=t[i])
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
		else sp[s[i]-'a']=t[i];
		if(tp[t[i]-'a'])
		{
			if(tp[t[i]-'a']!=s[i])
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
		else tp[t[i]-'a']=s[i];
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 776
import java.util.*;

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

        int[] times = new int[n];
        for(int i = 0; i < n; i++)
            times[i] = sc.nextInt();

        long total = 0;
        int start = 0;

        for(int i = 1; i < n; i++) {
            if(times[i] > times[i-1] + t) {
                total += times[i-1] - start + t;
                start = times[i];
            }
        }
        total += times[n-1] - start + t;

        System.out.println(total);
    }
}



Measured memory_bytes: 66304
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
	bool is(int x){
		for(int i=2;i*i<=x;i++)if(x%i==0)return false;
		return true;
	}
int main(){
	int n,p;

	while(cin>>n>>p,n!=-1||p!=-1){
		int cnt=0;
		n++;
		if(n==1)n++;
		vector<int>primes;
		vector<int>sums;
		while(true){
			if(is(n)){
				cnt++;
				primes.push_back(n);
			}
			if(cnt==78)break;
			n++;
		}
		//for(int i=0;i<primes.size();i++)cout<<primes[i]<<endl;
		for(int i=0;i<primes.size();i++){
			for(int j=0;j<primes.size();j++){
				if(j>primes.size())break;
				if(i<j)break;
				sums.push_back(primes[i]+primes[j]);
			}
		}
		sort(sums.begin(),sums.end());
		cout<<sums[p-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1252
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int h, w, k;
int dp[200][20];
//dp[i][j]=1番からi階層でjにたどり着くあみだくじのi番目までの作り方の総和
signed main() {
	cin >> h >> w >> k;
	dp[0][0] = 1;
	for (int i = 1; i <= h; i++) {
		for (int k = 0; k < (1 << (w - 1)); k++) {
			for (int j = 0; j < w - 2; j++) {
				if (k & (1 << j) && k & (1 << (j + 1))) {
					goto loop;
				}
			}
			for (int j = 0; j < w; j++) {
				if (k & (1 << j)) {
					dp[i][j] = (dp[i][j] + dp[i - 1][j + 1]) % Mod;
					dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j]) % Mod;
					j++;
				}
				else {
					dp[i][j] = (dp[i][j] + dp[i - 1][j]) % Mod;
				}
			}
		loop:;
		}
	}
	cout << dp[h][k - 1] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void){
    long long N;
    int answer=0,count=0;
    scanf("%lld",&N);
    double sqrtN=sqrt(N);
    for(int i=2;i<=sqrtN;i++){
        while(N%i==0){
            N/=i;
            count++;
        }
        int j=1;
        while(count>=j){
            answer++;
            count-=j;
            j++;
        }
        count=0;
    }
    if(N>sqrtN){
        answer++;
    }
    printf("%d\n",answer);
    return 0;
}

Measured memory_bytes: 2152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if(b<=a)
    {
        cout<<"delicious\n";
    }
    else if(b>a)
    {
        if(b-a<=x)
        {
            cout<<"safe\n";
        }
        else
        {
            cout<<"dangerous\n";
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,m,i=2,a=1;
    scanf("%d%d",&n,&m);
    while(n>=i)
    {
        if(n%i==0&&m%i==0)
        {
        a*=i;
        n/=i;m/=i;}
        else i++;
    }
    printf("%d\n",a);
    return 0;
}

Measured memory_bytes: 3192
def c_IrohaObsession(N, K, D):
    d = [str(i) for i in D]
    i = N
    while True:
        for c in str(i):
            if c in d:
                break
        else:
            return i
        i += 1
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
print(c_IrohaObsession(N, K, D))

Measured memory_bytes: 3064
S = input()
N = len(S)
i = 0
while True:
    if i%2==0:
        if S[i]=='L':
            print('No')
            break
    elif i%2==1:
        if S[i]=='R':
            print('No')
            break
    i = i+1
    if i==N:
        print('Yes')
        break

Measured memory_bytes: 3060
from collections import deque

N = int(input())
v = list(map(int, input().split()))

v.sort()

d = deque(v)

for _ in range(N-1):
    tmp1 = d.popleft()
    tmp2 = d.popleft()
    d.appendleft((tmp1+tmp2)/2)

print(d.pop())

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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

void solve(ll N, vector<ll> A) {
  sort(A.begin(), A.end());

  vector<bool> prime(A.back() + 1, false);
  REP(i, N)
    prime[A[i]] = true;

  REP(i, N) {

    if (!prime[A[i]])
      continue;

    if (i < N - 1 && A[i] == A[i + 1])
      prime[A[i]] = false;

    FOR(j, 2, A.back() / A[i] + 1)
      prime[A[i] * j] = false;
  }

  ll ans(0);
  REP(i, N) {
    if (prime[A[i]])
      ans++;
  }
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) {
    cin >> A[i];
  }

  solve(N, move(A));

  return 0;
}


Measured memory_bytes: 5060
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<lli> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

void solve()
{

    lli n, m;
    cin>>n>>m;
    string s[n];
    for(int  i = 0; i < n; i ++) {
        cin>>s[i];
    }
    sort(s, s + n);
    for(int i = 0; i < n; i ++) {
        cout<<s[i];
    }
    cout<<"\n";
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define long long ll
using namespace std;
int c[3][3];
int A[3], B[3];
int main(){
  for(int i=0;i<3;i++) for(int j=0;j<3;j++) cin >> c[i][j];
  for(int a1=0;a1<=100;a1++) for(int a2=0;a2<=100;a2++) for(int a3=0;a3<=100;a3++){
    int b1 = c[0][0]-a1;
    int b2 = c[0][1]-a1;
    int b3 = c[0][2]-a1;

    A[0] = a1;
    A[1] = a2;
    A[2] = a3;
    B[0] = b1;
    B[1] = b2;
    B[2] = b3;

    bool frag = true;
    for(int i=0;i<3;i++) for(int j=0;j<3;j++) if (A[i] + B[j] != c[i][j]) frag = false;
    if(frag){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


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

int main(){
    int n;
    long long ans=0;
    cin >> n;
    vector<int> d(n);
    rep(i,n){
        cin >> d[i];
    }
    rep(i,n){
        for(int j=i+1;j<n;++j){
            ans+=d[i]*d[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

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

	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		/* code */
		cin >> A[i];
		sum += A[i];
	}

	int cnt = 0;
	for (int i = 0; i < N; i++)
	{
		/* code */
		if(A[i] * 4 * M >= sum){
			cnt++;
		}
	}
	if(cnt >= M){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define ll long long
using namespace std;

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

	ll n; string s;
	cin >> n >> s;
	stack<char> cnt;
	for(int i = 0; i < n; ++i) {
		if(cnt.empty()) {
			cnt.push(s[i]);
		}
		else if(cnt.top() != s[i]) {
			cnt.push(s[i]);
		} 
	}
	cout << cnt.size();
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
namespace my_header {
#define pb push_back
#define mp make_pair
#define pir pair<int, int>
#define vec vector<int>
#define pc putchar
#define clr(t) memset(t, 0, sizeof t)
#define pse(t, v) memset(t, v, sizeof t)
#define bl puts("")
#define wn(x) wr(x), bl
#define ws(x) wr(x), pc(' ')
	const int INF = 0x3f3f3f3f;
	typedef long long LL;
	typedef double DB;
	inline char gchar() {
		char ret = getchar();
		for(; (ret == '\n' || ret == '\r' || ret == ' ') && ret != EOF; ret = getchar());
		return ret; }
	template<class T> inline void fr(T &ret, char c = ' ', int flg = 1) {
		for(c = getchar(); (c < '0' || '9' < c) && c != '-'; c = getchar());
		if (c == '-') { flg = -1; c = getchar(); }
		for(ret = 0; '0' <= c && c <= '9'; c = getchar())
			ret = ret * 10 + c - '0';
		ret = ret * flg; }
	inline int fr() { int t; fr(t); return t; }
	template<class T> inline void fr(T&a, T&b) { fr(a), fr(b); }
	template<class T> inline void fr(T&a, T&b, T&c) { fr(a), fr(b), fr(c); }
	template<class T> inline char wr(T a, int b = 10, bool p = 1) {
		return a < 0 ? pc('-'), wr(-a, b, 0) : (a == 0 ? (p ? pc('0') : p) : 
			(wr(a/b, b, 0), pc('0' + a % b)));
	}
	template<class T> inline void wt(T a) { wn(a); }
	template<class T> inline void wt(T a, T b) { ws(a), wn(b); }
	template<class T> inline void wt(T a, T b, T c) { ws(a), ws(b), wn(c); }
	template<class T> inline void wt(T a, T b, T c, T d) { ws(a), ws(b), ws(c), wn(d); }
	template<class T> inline T gcd(T a, T b) {
		return b == 0 ? a : gcd(b, a % b); }
	template<class T> inline T fpw(T b, T i, T _m, T r = 1) {
		for(; i; i >>= 1, b = b * b % _m)
			if(i & 1) r = r * b % _m;
		return r; }
};
using namespace my_header;

const int MAXN = 1e5 + 100;
const int MAXE = MAXN << 1;
int e, h[MAXN], nxt[MAXE], to[MAXE];
bool vis[MAXN][11];
int col[MAXN], qh, qt;
pair<int, int> que[MAXN];
int inq[MAXN];

int n, m, q, cnt;

void bfs(int u, int c, int d) {
	++cnt;
	que[qh = qt = 0] = make_pair(u, d);
	inq[u] = cnt;
	while (qh <= qt) {
		int x = que[qh].first;
		int y = que[qh++].second - 1;
		if (col[x] == 0)
			col[x] = c;
		if (y < 0)
			continue;
		for (int i = h[x]; i != -1; i = nxt[i]) {
			int v = to[i];
			if (inq[v] != cnt && !vis[v][y]) {
				vis[v][y] = true;
				inq[v] = cnt;
				que[++qt] = make_pair(v, y);
			}
		}
	}
}

struct Query {
	int u, c, d;
	void read() {
		fr(u, d, c);
	}
} qry[MAXN];

int main() {
#ifdef lol
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif

	fr(n, m);
	memset(h, -1, sizeof h);
	e = 0;
	for (int i = 1; i <= m; ++i) {
		int u, v;
		fr(u, v);
		to[e] = v, nxt[e] = h[u], h[u] = e++;
		to[e] = u, nxt[e] = h[v], h[v] = e++;
	}
	fr(q);
	for (int i = 1; i <= q; ++i) {
		qry[i].read();
	}
	for (int i = q; 0 < i; --i) {
		bfs(qry[i].u, qry[i].c, qry[i].d);
	}
	for (int i = 1; i <= n; ++i) {
		wt(col[i]);
	}

	return 0;
}

Measured memory_bytes: 6400
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n,r;
  cin >> n >> r;

  if(n > 10) cout << r;
  else
  {
    cout << r + 100 * (10 - n);
  }
  


  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class Monoid> struct RMQ {
    const Monoid INF;
    int SIZE_R;
    vector<pair<Monoid,int> > dat;
    
    RMQ(int n, const Monoid &inf): INF(inf) { init(n); }
    void init(int n) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, pair<Monoid,int>(INF, -1));
    }
    
    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE_R] = make_pair(v, a); }
    void build() {
        for (int k = SIZE_R - 1; k > 0; --k) {
            dat[k] = min(dat[k*2], dat[k*2+1]);
        }
    }
    
    /* update, a is 0-indexed */
    void update(int a, const Monoid &v) {
        int k = a + SIZE_R;
        dat[k] = make_pair(v, a);
        while (k >>= 1) dat[k] = min(dat[k*2], dat[k*2+1]);
    }

    void chmin(int a, const Monoid &v) {
        long long pv = get(a, a+1).first;
        if (pv <= v) return;
        update(a, v);
    }
    
    /* get {min-value, min-index}, a and b are 0-indexed */
    pair<Monoid,int> get(int a, int b) {
        pair<Monoid,int> vleft = make_pair(INF, -1), vright = make_pair(INF, -1);
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if (left & 1) vleft = min(vleft, dat[left++]);
            if (right & 1) vright = min(dat[--right], vright);
        }
        return min(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R].first; }
    
    /* debug */
    void print() {
        for (int i = 0; i < SIZE_R; ++i) {
            Monoid val = (*this)[i];
            if (val < INF) cout << val;
            else cout << "INF";
            if (i != SIZE_R-1) cout << ",";
        }
        cout << endl;
    }
};

const long long INF = 1LL<<60;
using pint = pair<int,int>;

int N, Q;
vector<int> b;
vector<vector<int>> rs;

long long f(int i) { return b[i] == 0 ? -1 : 1; }
long long solve() {
    long long offset = 0;
    for (int i = 0; i < N; ++i) if (b[i] == 0) ++offset;

    RMQ<long long> dp(N+2, INF);
    dp.update(0, 0);
    for (auto r : rs[0]) dp.update(r, 0);
    for (int i = 1; i <= N; ++i) {
        for (auto r : rs[i]) {
            long long mi = dp.get(i, r+1).first;
            dp.chmin(r, mi);
            dp.chmin(r, dp.get(i-1, i).first + f(i-1));
        }
        dp.chmin(i, dp.get(i-1, i).first + f(i-1));
    }
    return dp.get(N, N+1).first + offset;
}

int main() {
    cin >> N; b.resize(N);
    for (int i = 0; i < N; ++i) cin >> b[i];
    rs.assign(N+1, vector<int>());
    cin >> Q;
    for (int i = 0; i < Q; ++i) {
        int l, r; cin >> l >> r; --l;
        rs[l].push_back(r);
    }
    for (int l = 0; l <= N; ++l)
        sort(rs[l].begin(), rs[l].end(), greater<int>());
    cout << solve() << endl;
}


Measured memory_bytes: 17920
program bm
implicit none
integer::A,B,C,K
integer::ans=0
integer::cnt
read*,A,B,C,K
ans=ans+min(A,K)
K=K-A
if(K>0)then
    K=K-B
    if(K>0)then
        ans=ans-min(C,K)
    endif
endif
print"(i0)",ans
end program bm

Measured memory_bytes: 2860
import java.math.BigInteger;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			final int V = sc.nextInt();
			final int D = sc.nextInt();
			
			if(V == 0 && D == 0){
				break;
			}
			
			int fibs[] = new int[V+1];
			
			BigInteger[] bfi = new BigInteger[V+1];
			BigInteger mod = new BigInteger("1001");
			
			bfi[0] = new BigInteger("1");
			bfi[1] = new BigInteger("2");
			for(int i = 2; i <= V; i++){
				bfi[i] = bfi[i-1].add(bfi[i-2]);
			}
			
			for(int i = 1; i <= V; i++){
				fibs[i] = bfi[i].mod(mod).intValue();
			}
			
			Arrays.sort(fibs);
			
			int count = 0;
			
			for(int i = 1; i <= V; i ++){
				if(i != 1 && fibs[i-1] + D <= fibs[i]){
					count++;
				}
				
				
				//System.out.println(count + " " + fibs[i] + " " + (fibs[i] - fibs[i-1]));
			}
			
			
			System.out.println(count + 1);
			
		}
	}

}

Measured memory_bytes: 13000
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
using namespace std;

typedef long long ll;
vector<vector< pair<int, ll>>> path(100010);
ll depth[100010];

void dfs(int v, int p, ll d){
    depth[v] = d;
    for(int i = 0; i < path[v].size(); i++){
        if(path[v][i].first == p) continue;
        dfs(path[v][i].first, v, path[v][i].second+d);
    }

}
int main() {
    int N;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        pair<int, ll> p = make_pair(b, c);
        path[a].push_back(p);
        p.first = a;
        path[b].push_back(p);
    }

    int Q, K;
    cin >> Q >> K;
    int x[2][Q];
    for(int i = 0; i < Q; i++){
        cin >>x[0][i] >>x[1][i];
    }

    dfs(K, -1, 0);
    for(int i = 0; i < Q; i++){
        cout <<depth[x[0][i]] + depth[x[1][i]]<<endl;
    }
}

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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


int main() {
    ll x, k, d;
    cin >> x >> k >> d;

    if (abs(x) / d > k) {
        prt(abs(x) - k * d);
    } else {
        if ((k - abs(x) / d) % 2 == 0) {
            prt(abs(x) - (abs(x) / d) * d);
        } else {
            prt((abs(x) / d + 1) * d - abs(x));
        }
    }

    return 0;
}


Measured memory_bytes: 3624
N = input()

# 3つ以上の同じ数字が連続して並んだ 4桁の整数を 良い整数 とします。
# N が良い整数 ならば Yes を、そうでなければ No を出力せよ。

if N[1] == N[2]:
    if N[0] == N[1] or N[2] == N[3]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 8892
#include<bits/stdc++.h>
#define endl enjoy_codeforces
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    long long n,m;std::cin>>n>>m;
    long long mod=1'000'000'007;
    std::vector<long long>a(n+3);
    a.at(1)=0;
    a.at(2)=1;
    for(long long i=3;i<=n+2;i++){
        a.at(i)=a.at(i-1)+a.at(i-2);
        if(mod<=a.at(i))a.at(i)-=mod;
    }
    long long ans=1;
    for(long long i=0,j=-1;i<=m;i++){
        long long x;
        if(i<m)std::cin>>x;
        else x=n+1;
        ans=(ans*a.at(x-j))%mod;
        j=x;
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 1024