akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

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; }

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

	//std::ifstream in("../../test.txt");
	//std::cin.rdbuf(in.rdbuf());

	ll N, M;
	string S;

	cin >> S;

	bool flg = false;
	rep(i, 3) {
		if (S[i] == S[i + 1])flg = true;
	}

	if (flg) {
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}



	return 0;
}



Measured memory_bytes: 760
l = int(input())
ed = []
n = 20
for i in range(2, n):
    ed.append([i, i + 1, 0])
    ed.append([i, i + 1, 2 ** (n - 1 - i)])
now = 0
if l >= 2 ** 19:
    now += 1 << 19
    i = 1
    ed.append([i, i + 1, 0])
    ed.append([i, i + 1, 2 ** (n - 1 - i)])
for i in range(18, -1, -1):
    if (l >> i) & 1 == 1:
        ed.append([1, n - i, now])
        now += 1 << i
print(n, len(ed))
for i in ed:
    print(i[0], i[1], i[2])


Measured memory_bytes: 3064
#pragma region template
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
template <typename T>
constexpr T GCD(T a, T b) {
  if(a == 0)return b;
    while(a){
        swap(a, b);
        a %= b;
    }
    return b;
}
template <typename T>
constexpr T LCM(T a, T b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  using boost::multiprecision::cpp_int;
  using boost::multiprecision::integer_modulus;
  ll n;
  cin >> n;
  cpp_int a, g, c = 1, ans = 0;
  rep(i, n){
    cin >> a;
    g = GCD(c, a);
    ans *= integer_modulus(a / g, MOD);
    ans += integer_modulus(c / g, MOD);
    c /= g;
    c *= a;
  }
  print(ans%MOD);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int k1=s.size(),k2=t.size();
	int minn=k2;
	for(int i=0;i<=k1-k2;i++)
	{
		int l=0;
		for(int j=0;j<k2;j++)
		{
			if(s[i+j]!=t[j]) l++;
		}
		minn=min(l,minn);
	}
	cout<<minn<<endl;
}

Measured memory_bytes: 3632
n,a,b = map(int,input().split())
s = list(input())
cap = a+b

for i in s:
    if i == 'a' and cap > 0:
        print('Yes')
        cap -= 1
    elif i == 'b' and cap > 0 and b > 0:
        print('Yes')
        cap -= 1
        b -= 1
    else:
        print('No')
        


Measured memory_bytes: 9924
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n+10, 0);
    REP(i, 100){
        REP(j, 100){
            REP(k, 100){
                ll now = i*i+j*j+k*k+i*j+j*k+k*i;
                if(now < n+10)a[now-1]++;
            }
        }
    }
    rep(i, n)cout << a[i] << endl;
}


Measured memory_bytes: 3628
N = int(input())
ans = set()

def check(N, k):
    if k<2:
        return False
    N //= k
    while N:
        if (N-1)%k==0:
            return True
        if N%k:
            return False
        N //= k
    return False


for k in range(1, int(N**0.5)+1):
    if (N-1)%k==0:
        k1, k2 = k, (N-1)//k
        ans.add(k1)
        ans.add(k2)
    if N%k==0:
        k1, k2 = k, N//k
        if check(N, k1):
            ans.add(k1)
        if check(N, k2):
            ans.add(k2)

ans.remove(1)
print(len(ans))

Measured memory_bytes: 9408
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define scan(n,v) v.resize(n); rep(i,n){ cin>>v[i];}
#define MOD 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define be begin
#define pb push_back
#define fi first
#define se second
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
//------------------------------------------------------
int k,t;
vector<int> a;
void input(){
    cin>>k>>t;
    scan(t,a);
}
void src(){
    cout<<max(0,(*max_element(ALL(a))-(k-*max_element(ALL(a))) )-1 );
}   
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

const ll INF=1e18;
const int MAX_N=114514;
const int MAX_E=214514;

struct edge{
	int u;
	int v;
	int cost;
};

int root[MAX_N], depth[MAX_N];

edge es[MAX_E];
int V, E;

bool comp(const edge& e1, const edge& e2){
	return e1.cost<e2.cost;
}

// n要素で初期化
void init_union_find(int n){
	REP(i, n){
		root[i]=i;
		depth[i]=0;
	}
}

// xの根を求める
int find(int x){
	if(root[x]==x){
		return x;
	}
	else{
		return root[x]=find(root[x]);
	}
}

// xとyが属する集合を併合
void unite(int x, int y){
	x=find(x);
	y=find(y);
	if(x==y){
		return;
	}
	if(depth[x]<depth[y]){
		root[x]=y;
	}
	else{
		root[y]=x;
		if(depth[x]==depth[y]){
			++depth[x];
		}
	}
	return;
}

// xとyが同じ集合に属するか判定
bool same(int x, int y){
	return find(x)==find(y);
}

ll kruskal(){
	sort(es, es+E, comp);
	init_union_find(V);
	ll res=0;
	REP(i, E){
		edge e=es[i];
		if(!same(e.u, e.v)){
			unite(e.u, e.v);
			res+=e.cost;
		}
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	pii x[114514], y[114514];
	cin>>n;
	V=n;
	E=2*(n-1);
	REP(i, n){
		cin>>x[i].first>>y[i].first;
		x[i].second=i;
		y[i].second=i;
	}
	sort(x, x+n);
	REP(i, n-1){
		edge e;
		e.u=x[i].second;
		e.v=x[i+1].second;
		e.cost=x[i+1].first-x[i].first;
		es[i]=e;
	}
	sort(y, y+n);
	REP(i, n-1){
		edge e;
		e.u=y[i].second;
		e.v=y[i+1].second;
		e.cost=y[i+1].first-y[i].first;
		es[n-1+i]=e;
	}
	cout<<kruskal()<<'\n';
	return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 998244353;

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

    int r; cin >> r;
    cout << r*r << endl;

    return 0;
}

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

int main() {
  int  n; cin>>n;  
  vector<int>A(n);
  vector<int>checked(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  int button=A[0];
  checked[0]=1;
  int flag=0;
  int sum=1;
  for(int i=1;i<n;i++){
    if(checked[button-1]!=1 && button!=2){
      checked[button-1]=1;
      button=A[button-1];
      sum++;
    }
    else if(checked[button-1]!=1 && button==2){
      flag=1;
      break;
    }
    else{
      flag=0;
      break;
    }
  }
  if(flag==0)cout<<-1<<endl;
  else cout<<sum<<endl;
}

    
  


Measured memory_bytes: 1024
n, k = map(int, input().split())
a = list(map(int, input().split()))

for index, item in enumerate(a):
    a[index] -= 1

mp = dict()
now = 0
step = 0
rec = []
while not now in mp:
    mp[now] = step
    rec.append(now)
    step += 1
    now = a[now]

path = rec[mp[now]:step]

if k < mp[now]:
    print(rec[k] + 1)
else:
    k = (k - mp[now]) % len(path)
    print(path[k] + 1)

Measured memory_bytes: 124676
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
stack<int> s;
//char op[3333];
string op;
int main(){
//    gets(op);
//    int len = strlen(op);
    getline(cin, op);
    int len = op.length();
    int n = 0;
    for(int i = 0; i < len; i++){
        if(op[i] >= '0' && op[i] <= '9'){
            n = n*10 + (op[i]-'0');
        }
        else if(op[i] == ' ' && op[i-1] >= '0' && op[i-1] <= '9'){
            s.push(n);
            n = 0;
        }
        else if(op[i] == '+' || op[i] == '-' || op[i] == '*' || op[i] == '/'){
            int y = s.top();
            s.pop();
            int x = s.top();
            s.pop();
            if(op[i] == '+'){
                s.push(x+y);
            }
            else if(op[i] == '-'){
                s.push(x-y);
            }
            else if(op[i] == '*'){
                s.push(x*y);
            }
            else if(op[i] == '/'){
                s.push(x/y);
            }
        }
    }
    cout << s.top() << endl;
}



Measured memory_bytes: 3224
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <assert.h>
#include <set>
#include <cstring>
using namespace std;
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int n,q;
int A[200005];
int C[200005];
LL f ( int x ){
  return x * 1LL * C[x];
}

int main(){
  
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  cin >> n;
  LL tot = 0;
  for ( int i = 1; i <= n; i++ ) {
    cin >> A[i];
    tot -= f(A[i]);
    C[A[i]]++;
    tot += f(A[i]);
  }
  
  cin >> q;
  while ( q-- ){
    int b,c;
    cin >> b >> c;
    tot -= f(b);
    tot -= f(c);
    C[c] += C[b];
    tot += f(c);
    C[b] = 0;
    cout << tot << endl;
  }
  return 0;
}








    

Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define vector std::vector
#define string std::string
typedef long long ll;
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define min(a, b) std::min(a, b)
#define max(a, b) std::max(a, b)

template <class T = int>
T in() { T x; std::cin >> x; return x; }
#define output(e) std::cout << e << '\n'

#ifdef LOCAL
#define db std::cout << "L" << __LINE__ <<
#define de << "\n"
#define dv(x) << " " << #x << "->" << x
#else
#define db
#define de
#define dv(x)
#endif

//
// Implementation
//

int main() {
  ll x = in<ll>();
  ll cnt = ((ll)(x / 11)) * 2;
  ll amari = x % 11;
  if (amari > 6) {
    cnt += 2;
  } else if (amari > 0) {
    cnt += 1;
  }
  output(cnt);
}


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

int main(){

    ll n,a,b;
    cin>>n>>a>>b;
    ll d = a+b;
    if(n < d){
        d = d-n;
    }else{
        d = 0;
    }
    cout<<min(a,b)<<" "<<d;
    return 0;
}




//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);


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

int main(){
  int n,i;
  cin >> n;
  vector<int> d(n);
  for(i=0;i<n;i++){
    cin >> d.at(i);
  }
  
  sort(d.begin(),d.end());
  
  cout << d.at(n/2)-d.at(n/2-1) << endl;
}

Measured memory_bytes: 3792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;

int main(void){
    int A,B,C;cin>>A>>B>>C;
    vector<int> array(3);
    array[0] = A;
    array[1] = B;
    array[2] = C;
    sort(array.begin(),array.end());
    if(array[0]==array[1]&&array[1]!=array[2]){
        cout << "Yes" << endl;
    }else if(array[0]!=array[1]&&array[1]==array[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;

const int N=370;
const int M=30;

int D,t,ans;
int s[N][M],lst[M],c[M];

int main(){
	scanf("%d",&D);
	for (int i=1;i<=26;i++) scanf("%d",&c[i]);
	for (int i=1;i<=D;i++)
		for (int j=1;j<=26;j++) scanf("%d",&s[i][j]);
	for (int i=1;i<=D;i++){
		scanf("%d",&t);
		ans+=s[i][t];
		lst[t]=i;
		for (int j=1;j<=26;j++) ans-=c[j]*(i-lst[j]);
		printf("%d\n",ans);
	} 
	return 0;
}

Measured memory_bytes: 3864
#include <iostream>
#include <cstdlib>

int main()
{
    int N;
    int M;
    
    std::cin >> N;
    
    std::cin >> M;
    
    int result = ((N + M) * (N + M - 1)) / (2 * 1) - (N * M);
    
    std::cout << result;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll MOD = 998244353;
int main()
{
    int n;
    cin >> n;
    vector<ll> d(n);
    vector<ll> count(n+1);
    for(int i = 0; i < n; i++)
    {
        cin >> d[i];
        if(d[i] >= n)
        {
            cout << 0 << endl;
            return 0;
        }
        count[d[i]]++;
    }
    ll ans = 0;
    if(d[0] != 0 || count[0] != 1)
    {
        cout << ans << endl;
        return 0;
    }
    if(count[1] == 0)
    {
      cout << 0 << endl;
      return 0;
    }
    ans = 1;
    for(int i = 1; i < n; i++)
    {
        ll c = count[i];
        ll x = count[i-1];
        ll res = 1;
        while(c > 0)
        {
            if(c & 1) res = res * x % MOD;
            x = x * x % MOD;
            c >>= 1;
        }
        ans = ans * res % MOD;
    }
    cout << ans << endl;
}




Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    A,B,C,D = cin.mapInt()
    A -= 1
    S = B // C + B // D - B // Math.lcm(C,D)
    T = A // C + A // D - A // Math.lcm(C,D)
    print(B - S - (A - T))
    return

if __name__ == "__main__":
    main()


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

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

    int four = 0, two = 0, others = 0, A;
    for (int i = 0; i < N; ++i) {
        std::cin >> A;
        if (A % 4 == 0) {
            ++four;
        } else if (A % 2 == 0) {
            ++two;
        } else {
            ++others;
        } 
    }

    if (four >= (others + two % 2 - 1)) {
        std::cout << "Yes\n"; 
    } else {
        std::cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	m := make([]int, n)
	l := make([]int, n-1)
	r := make([]int, n-1)
	l[0] = a[0]
	r[0] = a[n-1]

	for i := 1; i < n-1; i++ {
		l[i] = gcd(l[i-1], a[i])
		r[i] = gcd(r[i-1], a[n-1-i])
	}

	for i := 0; i < n; i++ {
		if i == 0 {
			m[i] = r[n-i-2]
		} else if i == n-1 {
			m[i] = l[n-2]
		} else {
			m[i] = gcd(l[i-1], r[n-i-2])
		}
	}

	ret := m[0]
	for i := 1; i < n; i++ {
		if m[i] > ret {
			ret = m[i]
		}
	}

	fmt.Println(ret)
}

func gcd(a int, b int) int {
	for {
		if b > a {
			a, b = b, a
		}
		c := a % b
		if c == 0 {
			return b
		}
		a, b = b, c
	}
}


Measured memory_bytes: 7552
#include <cstdio>
int main(){
 int a,b,c,i,x;
 x=0;
 scanf("%d %d %d",&a,&b,&c);
 for(i=a;i<=b;i++){
  if(c%i==0) ++x;
 };
 printf("%d\n",x);
 return 0;
};
 

Measured memory_bytes: 1028
// Problem : C - Go Home
// Contest : AtCoder - AtCoder Beginner Contest 056
// URL : https://atcoder.jp/contests/abc056/tasks/arc070_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define spc ' '
#define endl '\n'

using namespace std;


int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int i = 1;
	while(n>0){
	    n-=i;
	    i++;
	}
	cout << i-1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

constexpr lli inf = 10000 * 10000;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

bool one_to_a[200001] = {}, a_to_n[200001] = {};


int main(void) {

	lli n, m;
	cin >> n >> m;

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

		if (a == 1) {
			one_to_a[b] = true;
		}
		if (b == 1) {
			one_to_a[a] = true;
		}
		if (a == n) {
			a_to_n[b] = true;
		}
		if (b == n) {
			a_to_n[a] = true;
		}
	}

	for (int i = 0; i <= n; i++) {
		if (one_to_a[i] && a_to_n[i]) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}

	cout << "IMPOSSIBLE" << endl;

	return 0;
}


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

using namespace std;

vector<int64_t> nums;
using It = decltype(nums.begin());
vector<It> sorted_its;
multiset<It> seen;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  nums.reserve(N + 1);
  nums.emplace_back();
  for (int i = 1; i <= N; ++i) {
    int n;
    cin >> n;
    nums.emplace_back(n);
    sorted_its.push_back(nums.end() - 1);
  }

  seen.emplace(nums.begin());
  seen.emplace(nums.begin());
  seen.emplace(nums.end());
  seen.emplace(nums.end());

  sort(sorted_its.begin(), sorted_its.end(),
       [](auto&& a, auto&& b) { return *a > *b; });

  int64_t result = 0;

  for (auto&& it : sorted_its) {
    auto r1_it = seen.upper_bound(it);
    auto right1 = *r1_it;
    auto right2 = *next(r1_it);
    auto l1_it = prev(r1_it);
    auto left1 = *l1_it;
    auto left2 = *prev(l1_it);
    result += *it * ((left1 - left2) * (right1 - it) +
                     (right2 - right1) * (it - left1));
    seen.emplace(it);
  }

  cout << result << endl;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> cnt(m, 0);
    rep(i, 0, n){
        int k;
        cin >> k;
        rep(j, 0, k){
            int f;
            cin >> f;
            cnt[f-1] ++; 
        }
    }
    int food = 0;
    for (auto c:cnt){
        if (c == n) food ++; 
    }    
    cout << food << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
  public static void main(String args[ ]) {
  Scanner in = new Scanner(System.in);
  int n = in.nextInt();
  if (n < 1000){
    System.out.print("ABC");
  }else{
     System.out.print("ABD");
  }
  }
}

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


int32_t main() {

    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

    int n;
    cin>>n;
    vector<int> v(n,0);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int c = 0;
    for(int i=0;i<n;i++){
        if(v[i]!=i+1) c++;
    }
    if(c>2) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}

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

int mod(int a, int b) {
  return ((a-b) % 2 + 2) % 2;
}

template <typename T>
class BIT {
  int n;
  vector<T> bit;
public:
  BIT(int _n) {
    n = _n;
    bit = vector<T>(n+1,(T)0);
  }
  T sum(int i) {
    T s = 0;
    while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
  }
  void add(int i, T x) {
    while(i <= n){
    bit[i] += x;
    i += i & -i;
    }
  }
};

int main(){
  int n;
  cin >> n;
  int a[n], b[n];
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  int ans = INF;
  rep(i,1<<n) {
    vector<vector<P>> v(51);
    rep(j,n) {
      if((1<<j) & i) v[a[j]].push_back(P(j,0));
      else v[b[j]].push_back(P(j,1));
    }
    bool can = true;
    vector<int> p(n,2);
    int c = 0;
    rep(j,51) {
      sort(v[j].begin(),v[j].end());
      int l = v[j].size();
      int f = c, s = c+1;
  
      for(auto k : v[j]) {
        if(mod(c,k.first) == k.second) {
          if(f >= c+l) {
            can = false;
            break;
          }
          p[f] = k.first;
          f += 2;
        } else {
          if(s >= c+l) {
            can = false;
            break;
          }
          p[s] = k.first;
          s += 2;
        }
      }
      c += l;
    }
    if(can) {
      int res = 0;
      BIT<int> bit(n);
      rep(j,n) {
        res += j - bit.sum(p[j]+1);
        bit.add(p[j]+1,1);
      }
      ans = min(ans,res);
    }
  }
  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		String S = sc.next();
		
	
		boolean isYM=true,isMY=true;
		
		int left = Integer.parseInt(S.substring(0, 2));
		int right = Integer.parseInt(S.substring(2,4));
		
		if(left>12) {
			isMY = false;
		}
		
		if(right>12){
			isYM = false;
		}
		
		if(left==0){
			isMY = false;
		}
		
		if(right==0) {
			isYM = false;
		}
		
		
		if(isMY&&isYM) {
			System.out.println("AMBIGUOUS");
		}else if(isMY&&!isYM){
			System.out.println("MMYY");
		}else if(!isMY&&isYM){
			System.out.println("YYMM");
		}else if(!isMY&&!isYM){
			System.out.println("NA");
		}
		
	}
}

Measured memory_bytes: 23636
#include <iostream>

using namespace std;
using ll = long long;

int main(){
  ll x;
  cin >> x;

  ll m = 100;
  for(auto i=1; ; ++i) {
    m *= 1.01;
    if(m>=x) {
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

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

    int length = s.size();

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

Measured memory_bytes: 3628
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <climits>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <deque>
#include <list>
#include <map>
#include <set>
using namespace std;

/*** typedef ***/
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ULL;
typedef pair < int , int > ii;
typedef pair < LL  , LL  > ll;
typedef vector <int>  vint;
typedef vector <bool> vbool;
typedef vector <long> vlong;

/*** define ***/
#define sz(x)			((int)x.size())
#define tin(x)			scanf("%d",&x)
#define all(x)			x.begin(),x.end()
#define Set(b,a)		memset(b,a,sizeof b)
#define print1(x)		printf("Case %d:",x++)
#define tin2(x,y)		scanf("%d%d",&x,&y)
#define tin3(x,y,z)		scanf("%d%d%d",&x,&y,&z)
#define loop(i,i0,in)	for(int i=i0 ; i<in ; i++)
#define rep(i,n)		for(int i=0 ; i<(n) ; i++)
#define _rep(i,n)		for(int i=n-1 ; i>=0 ; i--)
#define _loop(i,in,i0)	for(int i=in-1 ; i>=i0 ; i--)
#define Fore(it, x)		for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)

const int       maxn = 100+5;
const long double PI = 3.1415926535897932384626433832795;

LL gcd(LL a,LL b)
{
	return b==0 ? a : gcd(b,a%b);
}

int main()  
{  
#ifdef Online_Judge
	freopen("a.in","r",stdin);
#endif
	LL a,b;
	cin >> a >> b;
	cout << gcd(a,b) << endl;
	return 0;
}

Measured memory_bytes: 1156
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=3e5+5;

ll sum[N];

int main()
{ 

IOS;

ll n;cin>>n;

vpll a(n+1);

string s;cin>>s;

ll e=0,w=0;

for(int i=1;i<=n;i++){
  if(s[i-1]=='W')w++;
  else e++;
  a[i]={e,w};
}

ll ans=INT_MAX;

for(int i=1;i<=n;i++){
  ll wl=a[i-1].ss;
  ll er=a[n].ff-a[i].ff;
  ans=min(ans,wl+er);
}



cout<<ans<<endl;



return 0;
 
}



Measured memory_bytes: 8548
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
    int N; cin >> N;
    string S; cin >> S;
    vector<int> RED;
    vector<int> GR;
    vector<int> BLUE;
    rep(i, S.size()) {
        if (S[i] == 'R') {
            RED.push_back(i);
        } else if (S[i] == 'G') {
            GR.push_back(i);
        } else {
            BLUE.push_back(i);
        }
    }
    long long res = 0;
    // for(auto r : RED) {
    //     for(auto g : GR) {
    //         // for(auto b : BLUE) {
    //         //     if (abs(r-g) == abs(g-b) || abs(r-b) == abs(b-g) || abs(g- r) == abs(r-b)) continue;
    //         //     res++;
    //         // }
    //         int diff = abs(r-g);
    //     }
    // }
    res += RED.size() * BLUE.size() * GR.size();
    // cout << res << endl;
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            if(j+j-i >= N) continue;
            if(S[i] != S[j] && S[i] != S[j+j-i] && S[j] != S[j+j-i]) {
                // cout << i << j;
                res--;
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("in.txt");ofstream coutt("out.txt");
int poww(int a,int b,int m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}

signed main(){
    FASTER;
    int k;cin>>k;
    
    deque<int> dq;
    for(int i=1;i<=9;i++)dq.push_back(i);
    
    int cur;
    while(k--){
        cur=dq.front();dq.pop_front();
        
        if(cur%10!=0)dq.push_back(cur*10+cur%10-1);
        dq.push_back(cur*10+cur%10);
        if(cur%10!=9)dq.push_back(cur*10+cur%10+1);
        
    }
    cout<<cur;
}



Measured memory_bytes: 4792
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> L(M), R(M);
    for (ll i = 0; i < M; i++)
    {
        cin >> L.at(i) >> R.at(i);
    }

    ll LL = L.at(0);
    ll RR = R.at(0);

    for (ll i = 1; i < M; i++)
    {
        if (RR < L.at(i) || LL > R.at(i))
        {
            // 0
            cout << 0 << endl;
            return;
        }

        if (LL < L.at(i))
        {
            LL = L.at(i);
        }

        if (RR > R.at(i))
        {
            RR = R.at(i);
        }
    }

    cout << (RR - LL + 1) << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int maxn=2000004;
const int mod=1000000007,inf=1000000007;

std::string s;
inline long long powmod(long long a,long long b)
{
	long long res=1;
	while(b>0)
	{
		if(b&1) (res*=a)%=mod;
		(a*=a)%=mod,b>>=1;
	}
	return res;
}
long long fact[maxn],invfact[maxn];
inline void init()
{
	fact[0]=invfact[0]=1;
	for(int i=1;i<maxn;++i)
		fact[i]=fact[i-1]*i%mod,invfact[i]=powmod(fact[i],mod-2);
}
inline long long C(long long n,long long m) {return fact[n]*invfact[m]%mod*invfact[n-m]%mod;}
signed main(){
	int n;
	cin>>n>>s; 
	init();
	int len=s.length()-1;
	long long ans=0;
	for(int i=0;i<=n;++i)
		(ans+=powmod(26,i)*powmod(25,n-i)%mod*C(n-i+len,len))%=mod;
	cout<<ans;
	return 0;
}

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

#define fi first
#define se second

const int N = 1001;
const int mod = 1e9 + 7;

using namespace std;

int n;
int d[N];
char a[N], b[N];

void add(int &x, int y)
{
        x += y;
        if(x >= mod){
                x -= mod;
        }
}

int main()
{
        ios_base::sync_with_stdio(0);

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

        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        for(int i = 1; i <= n; i++){
                cin >> b[i];
        }
        vector < int > v;
        for(int i = 1; i <= n; i++){
                if(a[i] == b[i]){
                        v.push_back(1);
                } else{
                        v.push_back(2);
                        i += 1;
                }
        }

        if(v[0] == 1){
                d[0] = 3;
        } else{
                d[0] = 6;
        }
        for(int i = 1; i < v.size(); i++){
                if(v[i] == 1){
                        if(v[i - 1] == 2){
                                d[i] = d[i - 1];
                        } else{
                                d[i] = 1ll * d[i - 1] * 2 % mod;
                        }
                } else{
                        if(v[i - 1] == 1){
                                d[i] = 1ll * d[i - 1] * 2 % mod;
                        } else{
                                d[i] = 1ll * d[i - 1] * 3 % mod;
                        }
                }
        }
        cout << d[v.size() - 1] << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const int MAX_V = 300008;
ll n, m, u, v, s, t, min_dst[MAX_V];
vector<P> G[MAX_V];//to, cost

void dijkstra(int s){//1-origin
	priority_queue<P, vector<P>, greater<P>> que;
	fill(min_dst, min_dst+MAX_V, -1);
	min_dst[s] = 0;
	que.push(P(0, s));
	
	while(!que.empty()){
		P p = que.top(); que.pop();
		int at = p.second;
		if(min_dst[at] < p.first){continue;}
		for(int i = 0; i < G[at].size(); i++){
			int to = G[at][i].first;
			ll cost = G[at][i].second;
			if(min_dst[to] == -1 || min_dst[at]+cost < min_dst[to]){
				min_dst[to] = min_dst[at]+cost;
				que.push(P(min_dst[to], to));
			}
		}
	}
}


int main(){
	cin >> n >> m;
	
	for(ll i = 1; i <= m; i++){
		cin >> u >> v;
		G[u].push_back(P(v+n, 1));
		G[u+n].push_back(P(v+2*n, 1));
		G[u+2*n].push_back(P(v, 1));
	}

	cin >> s >> t;
	
	dijkstra(s);
	
	ll ans = (min_dst[t] > 0)? min_dst[t]/3 : -1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 18944
from bisect import bisect_right
N,C,K = map(int,input().split())
T = sorted([int(input()) for _ in range(N)])
cnt = 0
cur = 0
while cur<N:
    i = min(cur+C,N)-1
    if T[i]-T[cur]<=K:
        cnt += 1
        cur = i+1
    else:
        i = bisect_right(T,T[cur]+K)-1
        cnt += 1
        cur = i+1
print(cnt)

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string st;
typedef vector<int> vi;
#define all(v) ((v).begin()),((v).end())
#define allr(v) v.rbegin(),v.rend()
#define repi(n)  for(int i = 0; i < (int)(n); ++i)
#define repj(n)  for(int j = 0; j < (int)(n); ++j)
#define endl "\n"
#define sz(n) n.size()
#define RT(v) return cout<<v,0
#define watch(x) cout<<#x<<" = { "<<x<<" }\n"
ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }
void run() {
#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
#endif
}
void Ahmed_Meky()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}


int main()
{

	Ahmed_Meky();  		   /*█▀▀▄░░░░░░░░░░░▄▀▀█
							░█░░░▀▄░▄▄▄▄▄░▄▀░░░█  
							░░▀▄░░░▀░░░░░▀░░░▄▀
							░░░░▌░▄▄░░░▄▄░▐▀▀
							░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█
							░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█
							▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█
							█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀
							░▀▄░░▀░░▀▀▀░░▀░░░▄█▀
							░░░█░░░░░░░░░░░▄▀▄░▀▄
							░░░█░░░░░░░░░▄▀█░░█░░█
							░░░█░░░░░░░░░░░█▄█░░▄▀
							░░░█░░░░░░░░░░░████▀
							░░░▀█▄▄▄▀▀▀▀▄▄▄█▀*/

	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 0; i <= n;i++){
		if (i %3!=0 && i%5!=0)ans+=i;

	}
    
	cout << ans;

	
   // system("pause");
	return 0;

}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    ll res=0;
    for(ll i=1;i<=n;i++) res+=(i*(n-i+1));
    for(int i=0;i<n-1;i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>b) swap(a,b);
        res-=(a*(n-b+1));
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pi acos(-1)

using namespace std;

int main() {
    nl // Bazzi - Paradise

    int h, a; cin >> h >> a;
    int cnt = 0;
    while (h > 0) {
        h = h-a;
        cnt++;
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    int i,n,flag=0;
    char s[15]={},t[15]={};
    scanf("%s %s",s,t);
    n=strlen(s);
    for(i=0; i<n; i++){
        if(s[i]!=t[i])flag=1;
    }
    if(flag==1)printf("No");
    else printf("Yes");
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string S; cin >> S;
    if(S == "RRR"){
        cout << 3 << endl;
    }else if(S == "SRR" || S == "RRS"){
        cout << 2 << endl;
    }else if(S == "SSS"){
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }
}

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
#define MAX 100000

int parent(int i){
    return i/2;
}

int left(int i){
    return 2*i;
}

int right(int i){
    return 2*i+1;
}

int main(){
    int H;
    int A[MAX+1];

    cin>>H;
    for(int i=1;i<=H;i++)
        cin>>A[i];

    for(int i=1;i<=H;i++){
        cout<<"node "<<i<<": key = "<<A[i]<<", ";
        if(parent(i)>=1)
            cout<<"parent key = "<<A[parent(i)]<<", ";
        if(left(i)<=H)
            cout<<"left key = "<<A[left(i)]<<", ";
        if(right(i)<=H)
            cout<<"right key = "<<A[right(i)]<<", ";
        cout<<endl;
    }
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
const int N=1e5+5,mo=1e9+7;
int n,x[N],inv[N],i,ans,val;
int main(){
	for(i=1;i<N;++i)inv[i]=i==1?1:1ll*(mo-mo/i)*inv[mo%i]%mo;
	scanf("%d",&n);for(i=1;i<=n;++i)scanf("%d",x+i);
	for(i=1;i<n;++i)val=(val+inv[i])%mo,ans=(ans+1ll*val*(x[i+1]-x[i]))%mo;
	for(i=1;i<n;++i)ans=1ll*ans*i%mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main()
{
    int n,k;cin>>n>>k;
   vector<int>v(n);
   for(int i=0;i<n;i++)
   {
       cin>>v[i];
   }
   sort(v.begin(),v.begin()+n);
   int c=0;
   for(int i=0;i<k;i++)
   {
       c+=v[i];
   }
   cout<<c<<endl;
}


Measured memory_bytes: 3620
x, y = map(int, input().split())

ok = False
for i in range(x):
    turu = i
    kame = x-i
    legs = turu*2 + kame*4
    if legs == y:
        ok = True
        break

    kame = i
    turu = x - i
    legs = turu*2 + kame*4
    if legs == y:
        ok = True
        break

if ok:
    print("Yes")
else:
    print("No")

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

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

  long long result = 0;

  for(int i=1;i<N;i++){
    if(A[i-1]>A[i]){
      int tmp = A[i-1] - A[i];
      result += tmp;
      A[i] = A[i-1];
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 4412
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]); // even
    const M = parseInt(arg[0].split(" ")[1]); // odd
    
    // 偶奇を選んだ時だけが答えになる
    // 4C2, 3C2
    
    let temp1 = (N * (N - 1)) / 2
    let temp2 = (M * (M - 1)) / 2;
    
    console.log(temp1 + temp2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

typedef long long ll;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll N, M, ans = 0, MOD = 1e9 + 7;
    cin >> N >> M;
    vector<ll> f(500001, 1);
    rep(i, 500000) f[i + 1] = (f[i] * (i + 1)) % MOD;
    for (ll k = 0; k <= N; k++) {
        ll x = (f[N] * mod_pow(f[k], MOD - 2, MOD)) % MOD;
        x = (x * mod_pow(f[N - k], MOD - 2, MOD)) % MOD;
        x = (x * f[M - k]) % MOD;
        x = (x * mod_pow(f[M - N], MOD - 2, MOD)) % MOD;
        if (k % 2) x = (MOD - x) % MOD;
        ans += x;
        ans %= MOD;
    }
    ans *= f[M];
    ans %= MOD;
    ans *= mod_pow(f[M - N], MOD - 2, MOD);
    ans %= MOD;
    cout << ans << "\n";
}

Measured memory_bytes: 7200
n,k = map(int,input().split())
l = list(map(int,input().split()))
mo = [0]
mod = [0]
for i in range(n):
    a = l[i]%k
    mo.append((a+mo[-1])%k)
    mod.append((mo[-1]-(i+1))%k)
dic = {0:1}
le = 1
ans = 0
for i in range(1,n+1):
    if le < k:
        if mod[i] in dic:
            ans += dic[mod[i]]
            dic[mod[i]] += 1
        else:
            dic[mod[i]] = 1
        le += 1
    else:
        dic[mod[i-k]] -= 1
        if mod[i] in dic:
            ans += dic[mod[i]]
            dic[mod[i]] += 1
        else:
            dic[mod[i]] = 1
    
print(ans)


Measured memory_bytes: 48936
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
string a[105];
int n;
int main()
{
	scanf("%d%*d",&n);
	for(int i=0; i<n; i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0; i<n; i++)
		cout<<a[i];
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main{
    public static void main(String args[])throws IOException{
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
            String[] input = br.readLine().split(" ");
            double A = Double.parseDouble(input[0]);
            double B = Double.parseDouble(input[1]);
            double H = Double.parseDouble(input[2]);
            double M = Double.parseDouble(input[3]);

            double h_r = 0;
            double m_r = 0;
            double r = 0;
            double result = 0;

            if(M == 0){
              m_r = 360;
              h_r = H * 30;
            }else{
              m_r = M * 6;
              h_r = H * 30 + M * 0.5;
            }

            //System.out.println(h_r);
            //System.out.println(m_r);

            if(H == 0 && M == 0){
              result = A - B;
            }else{
              r = Math.abs(h_r - m_r);
              if(r == 0){
                result = 0;
              }else{
                double cos = Math.cos(Math.toRadians(r));
                double a = Math.pow(A, 2);
                double b = Math.pow(B, 2);
                double tmp = a + b - (2 * A * B * cos);
                result = Math.sqrt(tmp);
              }
            }

            System.out.println(result);
        }

    }
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

template<typename T>
void trace(T *a, int s, int n) {
    for (int i=s; i<n; i++) {
	cout<<a[i]<<" ";
    }
    cout<<endl;
}



typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


int n;
ll x,d;

ll asum(ll i) {
    return i*(i+1)/2;
}

map<ll, vector<pair<ll,ll>>> mp;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>x>>d;
    
    if (d == 0 && x == 0) {
	out(1); //0
    }

    if (d == 0 && x != 0) {
	out(n+1);
    }

    if (x == 0 && d != 0) {
	//0 and D, 2D...(n-1)*D
	out(asum(n-1) + 1);
    }



    assert(x!=0 && d!=0);

    


    //[X*take + sum_{i=0..take-1}i*D ...... X*take + sum{i=n-l..n-1}i*D]
    //count "collisions" modulo D, the arithmetic part won't change the modulo
    
    // # of elems that set S will take
    for (ll take=0; take<=n; take++) {
	ll base = x*take;

	ll losum = asum(take-1);
	ll hisum = asum(n-1) - asum(n-take-1);

	mp[base%d].push_back({base/d + losum, base/d + hisum});
    }

    // for (auto p: mp) {
    // 	watch(p.first);
    // 	for (auto i: p.second) {
    // 	    cout<<i.first<<" "<<i.second<<", ";
    // 	}
    // 	cout<<endl;
    // }


    ll ans = 0;


    for (auto p: mp) {
	auto v = p.second;
	assert(v.size());
	sort(v.begin(), v.end());
	pair<ll,ll> cur=v.front();
	for (int i=1; i<(int)v.size(); i++) {
	    ll s=v[i].first; ll e=v[i].second;
	    if (s<=cur.second) {
		cur.second=max(cur.second,e);
	    } else {
		ans += cur.second-cur.first+1;
		cur=v[i];
	    }
	}
	ans += cur.second-cur.first+1;
    }


    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 22144