akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define EFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)
#define INF 1e12
const int MOD = 1000000007;
typedef pair<ll,ll> P;

bool Palindrome(string s, int n){
    int f =  0;
    bool res = true;
    while(f <= n){
        if(s[f] != s[n]){
            res = false;
            break;
        }
        f++;
        n--;
    }
    return res;
}

int main(void){
    string s,s1,s2;
    int n,n1,n2;
    cin >> s;
    n = s.length();
    n1 = (n - 1) / 2;
    n2 = (n + 3) / 2;
    s1 = s.substr(0, n1);
    s2 = s.substr(n2 - 1);
    if(     Palindrome(s, n - 1) 
        &&  Palindrome(s1, s1.length() - 1)
        &&  Palindrome(s2, s2.length() - 1)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

#define int long long

const int N = 3001;
long double dp[N][N], p[N];
bool vis[N][N];
int n;

long double sol(int idx, int h) {
    if (idx == n + 1) return (2 * h > n) ? 1.0 : 0.0;
    long double &ans = dp[idx][h];
    if (vis[idx][h]) return ans;
    vis[idx][h] = true;
    ans = p[idx] * sol(idx + 1, h + 1) + (1 - p[idx]) * sol(idx + 1, h);
    return ans;
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << fixed << setprecision(12) << sol(1, 0) << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin>>t;
    while (t--) {
        solve();
    }
}

Measured memory_bytes: 150016
#include <bits/stdc++.h>
#define K 10005
#define T 105

using namespace std;

int k;
short t , x;
short b[K] , fr[T];

struct Element
{
    short x , fr;
}a[T];

bool inline Compare(Element a , Element b)
{
    return a.fr > b.fr;
}

int main()
{
    int i , j;

    cin >> k >> t;

    for(i = 1 ; i <= t ; i++)
        cin >> a[i].fr , a[i].x = i;

    sort(a + 1 , a + t + 1 , Compare);

    int ans = 0;
    bool x = 0;

    for(i = 1 ; i <= k ; i++)
    {
        sort(a + 1 , a + t + 1 , Compare);
        x = 0;

        for(j = 1 ; j <= t ; j++)
            if(a[j].fr && a[j].x != b[i - 1])
            {
                x = 1;
                b[i] = a[j].x;
                --a[j].fr;
                break;
            }

        if(!x)
        {
            for(j = 1 ; j <= t ; j++)
                if(a[j].fr)
                {
                    ++ans;
                    b[i] = a[j].x;
                    break;
                }
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int f(int n)
{
    int i = 1;
    while (true)
    {

        if (i * i >= n)
        {
            return i;
        }
        i++;
    }
}
bool issmall(int h1, int w1, int h2, int w2)
{
    return ((h1 * h1 + w1 * w1 < h2 * h2 + w2 * w2) || ((h1 * h1 + w1 * w1 == h2 * h2 + w2 * w2) && (h1 < h2)));
}

int main(int argc, char const *argv[])
{
    while (true)
    {
        double h, w;
        cin >> h >> w;
        if (h == 0)
            break;
        int ansh = 150, answ = 150;
        int ansl = 101010;
        rep(i, 1, 151)
        {
            rep(j, i + 1, 151)
            {

                if (issmall(h, w, i, j))
                {
                    if (issmall(i, j, ansh, answ))
                    {
                        ansh = i;
                        answ = j;
                    }
                }
            }
        }
        cout << ansh << " " << answ << endl;
    }
    return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);

#define pb push_back
#define all(v) v.begin(), v.end()



int main() {
   
    
    
	int n;
	cin>>n;
	int arr[n],dp[n];
	for(int i=0;i<n;i++)cin>>arr[i];
		dp[0] = 0;
		dp[1] = abs(arr[1] - arr[0]);
		for(int i=2;i<n;i++){
			int a = dp[i-1]+ abs(arr[i]-arr[i-1]);
			int b = dp[i-2]+abs(arr[i]-arr[i-2]);
			dp[i]= min(a,b);
		}

		cout<<dp[n-1];
	    
	    
	    
	
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int m,f,r;

  while(1){
    scanf("%d %d %d",&m,&f,&r);
    if(m==-1 && f==-1 && r==-1){
      break;
    }else{

  if(m==-1 || f==-1){
    printf("F\n");
  }else if(m+f >79){
    printf("A\n");
  }else if(m+f > 64){
    printf("B\n");
  }else if(m+f > 49){
    printf("C\n");
  }else if(m+f > 29){
    if(r > 49){
      printf("C\n");
    }else{
      printf("D\n");
    }
  }else if(m+f<30){
    printf("F\n");
  }
    }
  }
  return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    int f[n][5][2];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 5; ++j) {
        for (int k = 0; k < 2; ++k) {
          cin >> f[i][j][k];
        }
      }
    }
    int p[n][10];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j <= 10; ++j) {
        cin >> p[i][j];
      }
    }
    
    lli mx = -(1LL << 60);
    for (int bit = 1; bit < (1 << 10); ++bit) {
      lli sum = 0;
      for (int i = 0; i < n; ++i) {
        int cnt = 0;
        for (int j = 0; j < 10; ++j) {
          cnt += (bool)((bit & (1 << j)) && f[i][j / 2][j % 2]);
        }
        sum += p[i][cnt];
      }
      mx = max(mx, sum);
    }
    cout << mx << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
let ans, n = ref 0, read_int ()
let qs = Array.(init n @@ fun _ -> Scanf.(scanf " %d" @@ fun a -> init a @@ fun _ -> scanf " %d %d" @@ fun a b -> a - 1, b))
let f m = let c, b = ref 0, ref true in for i = 0 to n - 1 do if (m lsr i) land 1 = 1 then (incr c; b := !b && Array.fold_left (fun b (x, y) -> b && (m lsr x) land 1 = y) !b qs.(i)) done; if !b then !c else 0
let _ = for i = 0 to 1 lsl n - 1 do ans := max !ans @@ f i done; Printf.printf "%d\n" !ans

Measured memory_bytes: 2560
N, M = list(map(lambda a: int(a), input().split(" ")))
P = [(i + 1) for i in range(M)]
s = []
for j in range(N):
  A = list(map(lambda x: int(x), input().split(" ")))
  s.append(A[1:])
  
for k in range(len(s)):
  P = list(set(P) & set(s[k]))


print(len(P))

Measured memory_bytes: 9220
import java.math.BigDecimal
import java.math.RoundingMode

fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    val a = (1..5).map { readLine()!!.toLong() }.toTypedArray()
    println(solve(n, a))
}

private fun solve(n: Long, a: Array<Long>): Long {
    val min = findBottleNeck(a)
    val minVal = min.value
    val lot = BigDecimal.valueOf(n).divide(BigDecimal.valueOf(minVal), 0, RoundingMode.CEILING).toLong()
    return 4 + lot
}

private fun findBottleNeck(a: Array<Long>): IndexedValue<Long> {
    return a.withIndex().minBy { it.value }!!
}



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

long long c2(long long a)
{
    long long kekka = a * (a - 1) / 2;
    return kekka;
}

int main()
{
    int n;
    cin >> n;
    long long sum;
    vector<int> v(n);
    vector<int> a(n, 0);
    rep(i, n)
    {
        cin >> v[i];
        a[v[i] - 1]++;
    }
    rep(i, n)
    {
        sum += c2(a[i]);
    }
    rep(i, n)
    {
        long long answer = sum;
        answer -= c2(a[v[i] - 1]);
        answer += c2(a[v[i] - 1] - 1);
        cout << answer << endl;
    }
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string l;
    cin >> l;
    int n = l.size();
    vector<vector<mint>> dp(n, vector<mint>(2, 0));
    dp[0][0] = 2;
    dp[0][1] = 1;
    for (int i = 1; i < n; ++i) {
        if (l[i] == '1') {
            dp[i][0] = dp[i - 1][0] * 2;
            dp[i][1] = dp[i - 1][0] + dp[i - 1][1] * 3;
        } else {
            dp[i][0] = dp[i - 1][0];
            dp[i][1] = dp[i - 1][1] * 3;
        }
    }
    cout << dp[n - 1][0] + dp[n - 1][1] << "\n";
    return 0;
}

Measured memory_bytes: 7376
function main(input) {
  let args = input.split("\n");
  let s = args[0].trim();
  let n = s.length;
  let p = args[1].trim();
  s = s + s;

  let is_ok = false;
  for (let i = 0; i < n; i++) {
    if (s.substring(i, i + p.length) === p) {
      is_ok = true;
    }
  }
  console.log(is_ok ? "Yes" : "No");
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15348
import numpy as np

H, W = map(int, input().split())
h, w = map(int, input().split())

mat = np.ones((H, W), dtype=np.int)

for i in range(h):
    mat[i, :] = 0
for j in range(w):
    mat[:, j] = 0

print(np.sum(mat))


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

int main(){
  int n;cin>>n;
  int res = 0;
  char last = 'A';
  for(int i=0;i<n;++i){
    char cur;cin>>cur;
    if(last!=cur){
      res++;
      last = cur;
    }
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

vector<int> relation;

int myfind(int a, vector<int>& relation) {
    if (relation[a] == a) return a;
    int res = myfind(relation[a], relation);
    relation[a] = res;
    return res;
}

void myunion(int a, int b, vector<int>& relation) {
    int ta = myfind(a, relation);
    int tb = myfind(b, relation);
    if (ta == tb) return;
    relation[ta] = tb;
}

int main() { 
    int n, m;
    cin >> n >> m;
    relation = vector<int> (n + 1, 0);
    for (int i = 1; i <= n; i++) {
        relation[i] = i;
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        myunion(a, b, relation);
    }
    unordered_map<int, int> um;
    for (int i = 1; i <= n; i++) {
        um[myfind(i, relation)]++;
    }
    int res = 0;
    for (auto p : um) {
        res = max(p.second, res);
    }
    cout << res << endl;
}




Measured memory_bytes: 11992
from itertools import product

D, G = map(int, input().split(' '))
questions = [tuple(map(int, input().split(' '))) for _ in range(D)]
questions = [(100 * index, n, bonus) for index, (n, bonus) in enumerate(questions, start=1)]

min_answer = 1000

for bits in product((True, False), repeat=D):
    not_complete = []
    score = G
    answered = 0
    for index, bit in enumerate(bits):
        if not bit:
            not_complete.append(index)
            continue

        point, n, bonus = questions[index]
        score -= point * n + bonus
        answered += n

    if not_complete:
        index = max(not_complete)
        point, n, _ = questions[index]
        while score > 0 and n > 1:
            score -= point
            n -= 1
            answered += 1

    if score <= 0:
        min_answer = min(min_answer, answered)

print(min_answer)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='7')
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  using tsii = tuple<string, int, int>;
  vector<tsii> A(N);
  for (int i = 0; i < N; i++) {
    cin >> get<0>(A.at(i)) >> get<1>(A.at(i));
    get<2>(A.at(i)) = i + 1;
  }
  
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N - i - 1; j++) {
      if (get<0>(A.at(j)) > get<0>(A.at(j+1))) {
        swap (A.at(j), A.at(j+1));
        continue;
      }else if(get<0>(A.at(j)) == get<0>(A.at(j+1))){
      	if (get<1>(A.at(j)) < get<1>(A.at(j+1))) {
      	  swap (A.at(j), A.at(j+1));
      	}
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << get<2>(A.at(i)) << endl;
  }
}


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

using namespace std;

int main(){
    long long n,m,k;
    cin >> n >> m >> k;

    vector<long long> A(n),B(m);
    vector<long long> a(n+1,0),b(m+1,0);
    for(long long i=0; i<n; i++){
        cin >> A.at(i);
        //a[i] = 0;
    }
    for(long long i=0; i<m; i++){
        cin >> B.at(i);
        //b[i] = 0;
    }

    for(long long i=1; i<n+1; i++){
        a[i] = a[i-1] + A[i-1];
        //a.push_back(a[i] + A[i]);
        //cout << A[i] << endl;
        //cout << a[i] << endl;
    }
    for(long long i=1; i<m+1; i++){
        b[i] = b[i-1] + B[i-1];
        //b.push_back(b[i] + B[i]);
        //cout << b[i] << endl;
    }

    long long ans=0,j=m;
    for(long long i=0; i<n+1; i++){
        if(a[i] > k){
            break;
        }
        while(b[j] > (k - a[i])){
            j-=1;
        }
        //cout << ans << endl;
        ans = max(ans, i+j);
        //cout << ans << endl;
    }
    cout << ans << endl;

    /*
    long long n,m,k;
    cin >> n >> m >> k;

    vector<long long> a(n);
    vector<long long> b(m);

    for(long long i=0; i<n; i++){
        cin >> a.at(i);
    }
    for(long long i=0; i<m; i++){
        cin >> b.at(i);
    }

    long long i=0,j=0;
    long long total=0;
    long long count=0;
    while(1){
        long long tmp = min(a[i],b[j]);
        total += tmp;
        if(tmp == a[i]){
            i++;
        }
        else{
            j++;
        }
        if(total > k){
            break;
        }
        else if(i==n&&j==m){
            count++;
            break;
        }
        count++;
    }
    cout << count << endl;
    */
    return 0;
}

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 200016
#define LEN 1000016

int tsz;
string s[N];
vi msk[N];
int ch[LEN][26];
int cnt[LEN][26];

bool cmp(const string &x, const string &y)
{
    return x.size() > y.size();
}

int put(int u, int i, int j)
{
    int res;
    int c = s[i][j]-'a';

    if (j == 0) {
        res = cnt[u][c];
    } else {
        if (ch[u][c] == 0) ch[u][c] = ++tsz;
        res = put(ch[u][c], i, j-1);
    }
    for (int k = 0; k < 26; ++k) {
        if (msk[i][j]&(1<<k)) ++cnt[u][k];
    }
    return res;
}

int main()
{
    canhazfast();

    int n;
    ll ans = 0;
    constexpr int root = 0;

    cin >> n;
    for (int i = 0; i < n; ++i) cin >> s[i];
    sort(s, s+n, cmp);
    //cerr << "sorted:\n"; for (int i = 0; i < n; ++i) cerr << s[i] << '\n';
    for (int i = 0; i < n; ++i) {
        int sz = (int)s[i].size();
        int cur = 0;
        msk[i].resize(sz);
        for (int j = 0; j < sz; ++j) {
            cur |= 1<<(s[i][j]-'a');
            msk[i][j] = cur;
        }
        int res = put(root, i, sz-1);
        ans += res;
        //cerr << "res(" << i << ") = " << res << '\n';
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 249088
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define PI 3.14159265359

int main(){

  double a,b,h,m;
  cin >> a >> b >> h >> m;

  double time = h + m / 60;
  double theta = 2*PI / 12 * time;
  double phi = 2*PI * time;

  while(phi > 2*PI) phi = phi - 2*PI;

  double angle;

  if(phi > theta) angle = phi - theta;
  else angle = theta - phi;

  if(angle > 180) angle = 360 - angle;

  double ans = sqrt(a*a + b*b - 2*a*b*cos(angle));

  // cout << ans << endl;
  printf("%.10lf\r\n", ans);


  return 0;
}

Measured memory_bytes: 4192
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto hw = readln.split.to!(int[]);
    auto H = hw[0];
    auto W = hw[1];
    auto MAP = new char[][](H, W);
    foreach (i; 0..H) {
        foreach (j, c; readln.chomp) MAP[i][j] = c;
    }
    foreach (i; 0..H) foreach (j; 0..W) if (MAP[i][j] == '#') {
        bool ok;
        if (i > 0 && MAP[i-1][j] == '#') ok = true;
        if (i < H-1 && MAP[i+1][j] == '#') ok = true;
        if (j > 0 && MAP[i][j-1] == '#') ok = true;
        if (j < W-1 && MAP[i][j+1] == '#') ok = true;
        if (!ok) {
            writeln("No");
            return;
        }
    }
    writeln("Yes");
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#define _ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

int n, psa[200001], base, ans;
string s;
map<int, int> freq;

int main()
{_
    cin >> s;
    freq[0] = 1;
    base = 1;
    n = s.size();
    for (int i = n; i > 0; i--)
    {
        psa[i] = s[i - 1] - '0';
        psa[i] = (psa[i] * base) % 2019;
        base = (base * 10) % 2019;
    }

    for (int i = 1; i <= n; i++)
    {
        psa[i] = (psa[i] + psa[i - 1]) % 2019;
        ans += freq[psa[i]];
        freq[psa[i]]++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4104
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include <ios>     
#include <iomanip> 
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

llong gcd(llong a, llong b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}

//ここまで共通

int main() {
	int P[3];
	cin >> P[0] >> P[1] >> P[2];
	sort(P, P + 3);
	cout << P[0] + P[1];
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    D = sorted(list(map(int, input().split())))
    a = D[N//2 - 1]
    b = D[N//2]
    ans = 0
    if a < b:
        ans = b - a
    print(ans)


if __name__ == '__main__':
    main()


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

int main(void){
    int N;

    cin >> N;
    vector<int> p;

    for(int i = 1; i <= N; i++){
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }

    int min = 2*100000;
    int ans = 0;
    for(size_t i = 0; i < p.size(); i++){
//        min = *min_element(p.begin(), p.begin()+i);
        if(i == 0){
            min = p[i];
        }
        else if(min > p[i-1]){
            min = p[i-1];
        }

        if(min >= p[i]){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

void start() {
	ios::sync_with_stdio(false); cin.tie(0);
	cout<<fixed<<setprecision(10);
}

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define ii pair<int, int>
#define ll long long
#define endl '\n'
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()

int main() {
	start();

	int n; cin>>n;
	string s; cin>>s;

	if (s.size() <= n) cout<<s;
	else {
		for (int i = 0 ; i < n ; ++i) cout<<s[i];
		cout<<"...";
	}
}

// by Freyam

Measured memory_bytes: 3644
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = list(input())
    if len(set(s)) != 1:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():

    from heapq import heappop, heappush, heapify
    X,Y,Z,K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    sum_list = []
    seen_list = set()
    ans = []

    heappush(sum_list, (-(A[0]+B[0]+C[0]), 0, 0, 0))
    seen_list.add((0, 0, 0))

    for _ in range(K):
        s, i, j, k = heappop(sum_list)
        
        ans.append(-s)

        if i+1 < len(A) and (i+1, j, k) not in seen_list:
            heappush(sum_list, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
            seen_list.add((i+1, j, k))

        if j+1 < len(B) and (i, j+1, k) not in seen_list:
            heappush(sum_list, (-(A[i]+B[j+1]+C[k]), i, j+1, k))
            seen_list.add((i, j+1, k))

        if k+1 < len(C) and (i, j, k+1) not in seen_list:
            heappush(sum_list, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
            seen_list.add((i, j, k+1))

    for i in range(0, K):
        print(ans[i])

if __name__ == "__main__":
    main()

Measured memory_bytes: 53980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7, mod2 = 13, dp[15][100005];
ll modpow(ll base, ll power)
{
	ll res = 1;
	while (power) {
		if (power & 1)
			res = res * base % mod2;
		base = base * base % mod2;
		power >>= 1;
	}
	return res;
}
inline void shift(ll rem, ll pos)
{
	for (int i = 0; i < 13; ++i)
		dp[i][pos] = (dp[i][pos] + dp[(i - rem + mod2) % mod2][pos + 1]) % mod;
}
void solve(string &s)
{
	if (isdigit(s[s.length() - 1]))
		dp[s[s.length() - 1] - '0'][s.length() - 1] = 1;
	else
		for (int i = 0; i < 10; ++i)
			dp[i][s.length() - 1] = 1;
	for (int i = s.length() - 2, p = 1; i >= 0; --i, ++p) {
		ll t = modpow(10, p), rem;
		if (s[i] != '?') {
			ll num = s[i] - '0';
			rem = (num * t) % mod2;
			shift(rem, i);
		}
		else {
			for (int j = 0; j < 10; ++j) {
				rem = j * t % mod2;
				shift(rem, i);
			}
		}
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	solve(s);
	cout << dp[5][0] << '\n';
	return 0;
}

Measured memory_bytes: 10704
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
	ll n, cl = 0,cr = 0;
	string s, ans;
	cin >> n >> s;
	ans = s;
	for (int i = 0; i < n; i++) {
		if (s[i] =='(')for (int j = i + 1; j <n; j++) {
			if (s[j] == ')') {
				s[i] = s[j] = '0';
				break;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (s[i] == '(')cl++;
		if (s[i] == ')')cr++;
	}
	for (int i = 0; i < cr; i++)cout << '(';
	cout << ans;
	for (int i = 0; i < cl; i++)cout << ')';
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
//Basically the same as ~1
//Add the function of finding a certain key
#include <iostream>
using namespace std;

const int MAX = 500000;
const int ArSize = 30;

struct  Node
{
	int key;
	Node * pa;
	Node * left, *right;
};

char ins[ArSize];
Node * rec_tree[MAX];
int cnt = 0;

Node * root = nullptr;

void insert(Node * self);
Node * find(int val);
void print();
void pre_print(Node *);
void in_print(Node *);
void post_print(Node *);

int main()
{
	ios::sync_with_stdio(false);

	int m;
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> ins;
		if (ins[0] == 'i')
		{
			int v;
			cin >> v;
			Node * self = new Node({v, nullptr, nullptr, nullptr});

			rec_tree[cnt++] = self;
			insert(self);
		}
		else if (ins[0] == 'f')
		{
			int v;
			cin >> v;
			Node * res = find(v);
			if (res == nullptr)
				cout << "no" << endl;
			else
				cout << "yes" << endl;
		}
		else
		{
			print();
		}

		for (int i = 0; i < ArSize; i++)
			ins[i] = 0;
	}

	for (int i = 0; i < cnt; i++)
		delete rec_tree[i];

	return 0;
}

void insert(Node * self)
{
	Node * pa_can = nullptr;
	Node * self_can = root;

	while (self_can != nullptr)
	{
		pa_can = self_can;
		if (self->key < pa_can->key)
			self_can = pa_can->left;
		else
			self_can = pa_can->right;
	}

	self->pa = pa_can;

	if (self->pa == nullptr)
		root = self;
	else if (self->key < self->pa->key)
		self->pa->left = self;
	else
		self->pa->right = self;
	return;
}

Node * find(int val)
{
	Node * cur = root;
	while (cur != nullptr && cur->key != val)
	{
		if (val < cur->key)
			cur = cur->left;
		else
			cur = cur->right;
	}

	return cur;
}

void print()
{
        in_print(root);
	cout << endl;

	pre_print(root);
	cout << endl;

}

void pre_print(Node * cur)
{
	if (cur == nullptr)
		return;

	cout << " " << cur->key;
	pre_print(cur->left);
	pre_print(cur->right);
}

void in_print(Node * cur)
{
	if (cur == nullptr)
		return;

	in_print(cur->left);
	cout << " " << cur->key;
	in_print(cur->right);
}

void post_print(Node * cur)
{
	if (cur == nullptr)
		return;

	post_print(cur->left);
	post_print(cur->right);
	cout << " " << cur->key;
}

Measured memory_bytes: 24972
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramC
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var n = long.Parse(inputs[0]);
            var x = long.Parse(inputs[1]);
            var list = Console.ReadLine().Split(" ").Select(x => long.Parse(x)).ToList();
            var result = 0L;

            if (list[0] > x)
            {
                result += list[0] - x;
                list[0] = x;
            }

            for (var i = 1; i < n; i++)
            {
                if (list[i - 1] + list[i] <= x)
                {
                    continue;
                }
                else
                {
                    result += list[i] - (x - list[i - 1]);
                    list[i] = x - list[i - 1];
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 39400
#include <iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a == b){
        cout << "a == b" << endl;
    }else if(a <b){
        cout << "a < b" <<endl;
        
    }
    else if(a>b){
        cout << "a > b" << endl;
    }
}


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

int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0) {if(a<b) swap(a,b); a = a%b;} return max(a,b);
}

int main(){
  string s;
  cin >> s;
  int n= s.length();
  vector<int> ans(n);
  vector<vector<int>> sec(n,vector<int>(4));

  int count=0;
  rep(i,n-1){
    if(s[i]=='R'&&s[i+1]=='L'){
      sec[count][1]=i+1; sec[count][2]=i+2;
    }
    if(s[i]=='L'&&s[i+1]=='R'){
      sec[count][3]=i+1;
      count++;
    }
  }
  count++;
  sec.resize(count);
  sec[0][0]=1; sec[count-1][3]=n;
  rep(i,count-1) sec[i+1][0] = sec[i][3]+1;
/*rep(i,count){
  rep(j,4) cout << sec[i][j] << " ";
  cout << endl;
}*/
  rep(i,count){
    if((sec[i][3]-sec[i][0]+1)%2==0){
      ans[sec[i][1]-1]=(sec[i][3]-sec[i][0]+1)/2;
      ans[sec[i][2]-1]=(sec[i][3]-sec[i][0]+1)/2;
    }else{
      if((sec[i][1]-sec[i][0]+1)%2==1){        
      ans[sec[i][1]-1]=(sec[i][3]-sec[i][0]+1)/2+1;
      ans[sec[i][2]-1]=(sec[i][3]-sec[i][0]+1)/2;
      }else{        
      ans[sec[i][1]-1]=(sec[i][3]-sec[i][0]+1)/2;
      ans[sec[i][2]-1]=(sec[i][3]-sec[i][0]+1)/2+1;
      }
    }
  
  }

  rep(i,n) cout << ans[i] << " ";
  cout << endl;
  return 0;
}

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

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

	char S[55][55];
	string s;
	for (int i = 1; i <= H; i++)
	{
		cin >> s;
		for (int j = 1; j <= W; j++)
		{
			S[i][j] = s[j - 1];
		}
	}

	for (int i = 1; i <= H; i++)
	{
		for (int j = 1; j <= W; j++)
		{
			if (S[i][j]=='#' and S[i][j+1]!='#' and S[i][j - 1] != '#' and S[i+1][j] != '#' and S[i-1][j] != '#')
			{
				cout << "No";
				return 0;
			}
		}

	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long int N;
    cin >> N;
    long long int ans = 0;
    long long int cnt = 1;
    while(N != 0){
        N /= 2;
        ans += cnt;
        cnt *= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    if(A >= 13):
        print(B)
    elif(6 <= A <= 12):
        print(int(B/2))
    else:
        print(0)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

typedef long long int ll;
using namespace std;
 
int main (){
  ll n,k,ans = 1;
  cin >> n >> k;
  ans = k;

  rep(i,0,n-1){
    ans *= (k-1);
  }
  
  printf("%lld\n",ans);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
using ll=long long;

const int INF=1e9+5;
const int N=400+5;
const int mod=1e9+7;
const ll oo=1e18+5;

int n;
ll dp[N][N]; // dp[l][r] is the minimum possible total incurred
vector<int> a;

ll sum(int l,int r){
	ll S=0;
	for(int i=l;i<=r;++i){
		S+=a[i];
	}
	return S;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	cin>>n;
	a.resize(n);
	for(int& x:a) cin>>x;
	for(int l=0;l<N;++l){
		for(int r=0;r<N;++r){
			dp[l][r]=oo;
		}
	}
	for(int i=0;i<n;++i) dp[i][i]=0;
	for(int l=n-1;l>=0;--l){
		for(int r=0;r<n;++r){
			for(int k=l;k<r;++k){
				dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]+sum(l,r));
			}
		}
	}
	cout<<dp[0][n-1];			
	return 0;
}
		


Measured memory_bytes: 1536
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int a=in();int b=in();
	if(!(b%a))cout<<a+b;
	else cout<<b-a;
	
}

Measured memory_bytes: 3644
#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;

int seiyaku_check(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	
	int a,b;
	string s;
	cin >> a >> b ;
	cin >> s;
	
	seiyaku_check(a,1,50);
	seiyaku_check(b,1,a);
	if(s.length() != a)exit(1);

	if(s[b-1] == 'A')s[b-1] = 'a';
	if(s[b-1] == 'B')s[b-1] = 'b';
	if(s[b-1] == 'C')s[b-1] = 'c';
	
	cout << s << endl;

return 0;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    set<int> st;
    rep(i, N){
        int a; cin >> a;
        if(st.count(a)){
            cout << "NO" << endl;
            return 0;
        }
        st.insert(a);
    }
    cout << "YES" << endl;
    return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
    
  if ( a*b > c*d ){
    cout << a*b << endl;
  }
  else {
    cout << c*d << endl;
  }
  
}


Measured memory_bytes: 256
N = int(input())
S = input()

cnt = 0
min_cnt = 3 * 10**5
for i in range(1, N):
    if S[i] == 'E':
        cnt += 1
min_cnt = cnt
# print(cnt)

for i in range(1, N):
    if S[i-1:i+1] == "EE":
        cnt -= 1
    elif S[i-1:i+1] == "EW":
        cnt += 0
    elif S[i-1:i+1] == "WE":
        cnt += 0
    elif S[i-1:i+1] == "WW":
        cnt += 1
    min_cnt = min(min_cnt, cnt)
print(min_cnt)

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

int main()
{
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;

	if(
			(x-r) >=0 &&
			(y-r) >= 0 &&
			(x+r) <= w &&
			(y+r) <= h) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	cout << endl;

	return 0;
}

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

int main(){
    char S[111];
    long long int i;
    long long int K;
    cin >> S;
    cin >> K;
    long long int N = 0;
    while(S[N]) N++;
    for(i=0;i<=N-1;i++){
      if(S[i] != '1') {
      cout << S[i] << endl;
      break;
      }
      if(i+1 >= K){
        cout << 1 << endl;
        break;
      }
    }
}



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

int main(void){
    int x,y,z;
    z = -1;
    scanf("%d%d",&x,&y);
    while(z != 0){
        z = x % y;
        x = y;
        y = z;
    }
    printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
const int mod = 1000000007;
ll n,m;
std::vector<ll> b,ans;
int main(){
  cin >> n;
  b.resize(n+1);
  for (size_t i = 0; i < n; i++){
    cin >> b[i];
    m = max(m,b[i]);
  }
  for (size_t i = 0; i < n; i++) {
    bool a = false;
    for (size_t l = m; l >= 1; l--) {
      if(l == b[l-1]){
        a = true;
        ans.push_back(b[l-1]);
        b.erase(b.begin() + (l-1));
        break;
      }
    }
    if(!a)break;
  }
  if(ans.size() == n){
    reverse(all(ans));
    for (size_t i = 0; i < ans.size(); i++) cout << ans[i] << endl;
  }else{
    cout << -1 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long k;
const long long n = 50;
vector<long long> a(55, 0);
vector< vector<long long> > pmvec(50, vector<long long>(50, 0));

int main() {
    cin >> k;
    long long now = 1;
    for(int i = 0; i < n; ++i) {
        long long check = n-i;
        for(int j = 0; j < i+1; ++j) {
            pmvec.at(i).at(j) = -check;
        }
        for(int j = i+1; j < n; ++j) {
            pmvec.at(i).at(j) = now;
        }
        now++;
    }

    long long cnt = k/n;
    long long rest = k%n;

    // cout << cnt << " " << rest << endl;
    vector<long long> ans(55, 0);
    for(int i = 0; i < n; ++i) {
        ans.at(i) += pmvec.at(49).at(i)*cnt;
        if(rest != 0) ans.at(i) += pmvec.at(rest-1).at(i);
    }

    vector<long long> sum(55, 49);
    for(int i = 0; i < n; ++i) {
        sum.at(i) -= ans.at(i);
    }

    cout << n << endl;

    for(int i = 0; i < n; ++i) {
        cout << sum.at(i) << " ";
    }
}

Measured memory_bytes: 256
/**
 * C - Attack Survival
 * https://atcoder.jp/contests/abc141/tasks/abc141_c
 **/
#include<iostream>

using namespace std;

const int MAX_N = 100000;
const int MAX_Q = 100000;

int N, K, Q, W[MAX_N+1], A[MAX_Q+1];

void solve() {
    for(int i=1; i<Q+1; i++) {
        W[A[i]] += 1;
    }
    for(int j=1; j<N+1; j++) {
        if(Q-W[j]<K) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return;
}

int main() {
    cin >> N >> K >> Q;
    for (int i=1; i<Q+1; i++) {
        cin >> A[i];
    }
    solve();
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Long[] t = new Long[n];
        Arrays.setAll(t, i -> Long.parseLong(sc.next()));
        sc.close();

        // 主処理
        long result = t[0];
        for (int i = 1; i < n; i++) {
            result = lcm(result, t[i]);
        }

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

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        long gcd = gcd(a, b);
        return a / gcd * b;
    }
}


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

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

    int count = 0;
    for (int i=0; i<K+1; ++i)
    {
        for (int j=0; j<K+1; ++j)
        {
            if(S-i-j >=0 && S-i-j <= K) ++count;
        }
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  ll N;

  CIN(N);

  ll A[N];
  for (ll i = 0; i < N; i++) {
    CIN(A[i]);
  }

  ll count = 0;
  ll i = 0;
  ll a = 1;
  while (i < N) {
    if (a != A[i]) {
      // COUT("a: " << a << " " << A[i] << "--b");
      count++;
      i++;
    } else {
      // COUT("a: " << a << " " << A[i]);
      a++;
      i++;
    }
  }

  if (N <= count) {
    COUT(-1);
  } else {
    COUT(count);
  }

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

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

const ll MOD = 1E9+7;
ll cache[2001];

ll dp(int n)
{
    ll& c = cache[n];
    if (c != -1) return c;
    if (n == 0) return 1;
    //////////////////////////////
    ll ret = 0;
    for (int i = n; i >= 3; i--) ret = (ret+dp(n-i))%MOD;
    return c = ret;
}
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    memset(cache, -1, sizeof(cache));

    ll n; cin >> n;
    cout << dp(n) << endl;
}


Measured memory_bytes: 3656
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
	 public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();
	        int H = 1005;
	        int[] m = new int[H];
	        int[] p = new int[H];
	        int k=0;
	        for(int i=2;i<H;i++) {
	        	if(m[i]==0) {
	        		m[i]=1;
	        		p[k]=i;
	        		k++;
	        		for(int j=i+i;j<H;j=j+i) {
	        			m[j]=i;
	        		}
	        	}
	        }	        
	        
	        long tmp=1;
	        int[] list=new int[10001];
	        for(int i=2;i<=N;i++) {
	        	int t=i;
	        	while(m[t]>1) {
	        		list[m[t]]++;
	        		t=t/m[t];
	        	}
	        	list[t]++;
	        }
	        long ans=1;
	        for(int i=2;i<1000;i++) {
	        	ans=(ans*(list[i]+1))%mod;
	        }
	        System.out.println(ans);
	 }
	 

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define FOR(i, N) for (long i = 0; i < (N); i++)

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

    if (X < 30) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;

    vector<int> dpf(n+1), dpb(n+1);
    int pre = -INF;
    for (int i=1; i<n+1; ++i) {
        dpf.at(i) = dpf.at(i-1);
        if (s.at(i-1) == 'o' && i - pre > c) {
            ++dpf.at(i);
            pre = i;
        }
    }
    pre = INF;
    for (int i=n-1; i>=0; --i) {
        dpb.at(i) = dpb.at(i+1);
        if (s.at(i) == 'o' && pre - i > c) {
            ++dpb.at(i);
            pre = i;
        }
    }
    for (int i=0; i<n; ++i) {
        if (dpf.at(i) + dpb.at(i+1) < k) {
            cout << i+1 << '\n';
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

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

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

void Panda() {
    int n;
    cin >> n;
    vi in(n);
    for(auto &i : in) cin >> i;
    int cnt = 0;
    for(int i = 0 ; i < n - 2; i++) {
      for(int j = i + 1; j < n - 1; j++) {
        for(int k = j + 1; k < n; k++) {
          if(in[i] + in[j] > in[k] and in[i] != in[j] and in[j] != in[k] and in[i] != in[k] and in[j] + in[k] > in[i] and in[i] + in[k] > in[j]) {
            cnt++;
          }
        }
      }
    }
    cout << cnt << endl;
}
  
int32_t main() {
 
    FAST;

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

    return 0; 
} 

Measured memory_bytes: 3644
// Problem : C - Sentou
// Contest : AtCoder Regular Contest 073
// URL : https://atcoder.jp/contests/arc073/tasks/arc073_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

int n, t, pre = 1, a[N];
ll ans = 0;

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n >> t;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i - 1] + t < a[i]) {
			ans += a[i - 1] - a[pre] + t;
			pre = i;
		}
	}
	ans += a[n] - a[pre] + t;
	cout << ans;
}


Measured memory_bytes: 1024
def f(i, S, H, W):
    indices = [i - W, i - 1, i + 1, i + W]
    indices = [i for i in indices if 0 <= i < H * W]
    return any([S[i] == "#" for i in indices])


H, W = map(int, input().split())
S = ""
for _ in range(H):
    S += input()
for i in range(H * W):
    if S[i] == "#":
        if not f(i, S, H, W):
            print("No")
            break
else:
    print("Yes")


Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N,M;
ll A[100010];
ll C[100010];
map<ll,ll>s;


int main() {
    scanf("%lld%lld",&N,&M);
    rep(i,N) scanf("%lld",&A[i]);
    C[0] = 0;
    rep(i,N+1){
        C[i] = C[i-1]+A[i-1];
    }
    ll ans=0;
    rep(i,N+1){
        ans += s[C[i]%M];
        s[C[i]%M]++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  if(N%2==1){cout << "No" << endl;}
  else{
    if(S.substr(0,N/2)==S.substr(N/2,N/2)){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
  }
}

Measured memory_bytes: 256