akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int N=100001;
int n,mx=0,a[N],num[N+1];
int main()
{
	//freopen("txt.in","r",stdin);
	//freopen("txt.out","w",stdout);
	int i;
	cin>>n;
	memset(num,0,sizeof(num));
	for(i=1;i<=n;i++)	scanf("%d",&a[i]),num[a[i]]++,num[a[i]-1]++,num[a[i]+1]++;
	for(i=1;i<=N;i++)	if(num[i]>mx)	mx=num[i];
	cout<<mx;
	return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 998244353;

class mint {
  private: 
    ll x;

  public:
    constexpr mint(const ll x = 0) noexcept : x((x % MOD + MOD) % MOD) {}
    constexpr ll value() noexcept { return x; }
    constexpr mint operator += (const mint right) noexcept {
      if ((x += right.x) >= MOD) x -= MOD;
      return *this;
    }
    constexpr mint operator -= (const mint right) noexcept {
      if ((x += MOD - right.x) >= MOD) x -= MOD;
      return *this;
    }
    constexpr mint operator *= (const mint right) noexcept {
      x = x * right.x % MOD;
      return *this;
    }
    constexpr mint operator /= (const mint right) noexcept {
      return *this *= right.inv();
    }
    constexpr mint operator + (const mint right) const noexcept {
      return mint(*this) += right;
    }
    constexpr mint operator - (const mint right) const noexcept {
      return mint(*this) -= right;
    }
    constexpr mint operator / (const mint right) const noexcept {
      return mint(*this) /= right;
    }
    constexpr mint operator * (const mint right) const noexcept {
      return mint(*this) *= right;
    }
    constexpr mint inv() const {
      return pow(MOD-2);
    }
    constexpr mint pow(ll n) const {
      if (n == 0) return 1;
      mint a = pow(n>>1);
      a *= a;
      if (n & 1) a *= *this;
      return a;
    }
};

mint dp[200002];

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

  ll n, k; cin >> n >> k;
  vpi d(k);

  rep(i, k) cin >> d[i].fi >> d[i].se;

  dp[0] = 1;
  dp[1] = -1;

  rep(i, n) {
    dp[i+1] += dp[i];
    rep(j, k) {
      if (d[j].fi + i > n) continue;
      dp[d[j].fi + i] += dp[i];
      dp[min(n, d[j].se + i + 1)] -= dp[i];
    }
  }

  cout << dp[n-1].value() << endl;

  return (0);
}


Measured memory_bytes: 5212
#include<iostream>
using namespace std;
int main(){
	//freopen("input.txt","r",stdin);
	int n;cin>>n;
	int *arr=new int[n];
	for(int i=0;i<n;i++)cin>>arr[i];
	int*dp=new int[n+1]{};
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

struct dsu {
	ll n;
	vl p;

	dsu(ll n): n(n), p(n) { iota(all(p),0); }
	
	ll find(ll x) {
		if (x == p[x]) return x;
		return p[x] = find(p[x]);
	}

	bool unite(ll x, ll y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		
		if (rand() & 1) swap(x,y);
		p[y] = x;
		return true;
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, m;
	cin >> n >> m;

	dsu D(n);
	while (m--) {
		ll a, b;
		cin >> a >> b;
		a--, b--;
		D.unite(a,b);
	}
	
	vl s(n);
	FOR(i,0,n) s[D.find(i)]++;

	cout << *max_element(all(s)) << endl;


}



Measured memory_bytes: 9444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s,t;cin >> s >> t;
  vector<int>sa(s.length()+1,0);
  vector<int>sb(s.length()+1,0);
  vector<int>ta(t.length()+1,0);
  vector<int>tb(t.length()+1,0);
  rep(i,s.length()){
    if(s[i]=='A')++sa[i+1];
    else++sb[i+1];
  }
  rep(i,s.length()){
    sa[i+1] += sa[i];
    sb[i+1] += sb[i];
  }
  rep(i,t.length()){
    if(t[i]=='A')++ta[i+1];
    else++tb[i+1];
  }
  rep(i,t.length()){
    ta[i+1] += ta[i];
    tb[i+1] += tb[i];
  }

  int Q;cin >> Q;
  while(Q--){
    int a,b,c,d;cin >> a >> b >> c >> d;
    --a;--c;
    int SA = sa[b]-sa[a]+2*(sb[b]-sb[a]);
    int TA = ta[d]-ta[c]+2*(tb[d]-tb[c]);
    YESNO((SA-TA)%3==0);
  }
  return 0;
}


Measured memory_bytes: 2512
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>

using namespace std;

#define cn cout << '\n'
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

ll gcd(ll x, ll y) {
  if (x % y == 0) return y;
  return gcd(y, x % y);
}

ll lcm(ll x, ll y) {
  ll t = x / gcd(x, y);
  return t * y;
}

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  --a;
  ll k = (b - b / c - b / d + b / lcm(c, d)) - (a - a / c - a / d + a / lcm(c, d));
  cout << k << endl;
  return 0;
}


Measured memory_bytes: 3160
#! /usr/local/bin/python3
# coding: utf-8

def stack_op2(s, op):
    v2 = s.pop()
    v1 = s.pop()
    s.append(op(v1, v2))

def calc(terms):
    s = []
    for t in terms:
        if t == "+":
            stack_op2(s, lambda v1, v2: v1 + v2)
        elif t == "-":
            stack_op2(s, lambda v1, v2: v1 - v2)
        elif t == "*":
            stack_op2(s, lambda v1, v2: v1 * v2)
        else:
            s.append(int(t))
    return s.pop()

print(calc(input().split()))



Measured memory_bytes: 5600
#include <cstdio>

int main (){
    int N;
    scanf("%d",&N);
    int B[N-1];
    for (int i = 0; i < N-1; i++){
        scanf("%d",&B[i]);
    }
    long int a_sum = B[0]+B[N-2];
    int a=B[0];
    for (int i = 1; i < N-1; i++){
        if(B[i-1]>=B[i]) a=B[i];
        else a=B[i-1];
        a_sum+=a;
    }
    if(N==2) a_sum = 2*B[0];
    printf("%ld",a_sum);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define pdd pair<double,double>
#define cpdd const pdd
int main(){
    char c[200005];
    MEM(c);
    scanf("%s",c);
    int cnt=1;
    for(int i = 1;c[i]!=0;i++){
        if(c[i]==c[i-1]){
            i++;
            if(c[i]!=0){
                cnt++;
                i++;
                if(c[i]!=0){
                    cnt++;
                }
            }
        }
        else{
            cnt++;
        }
    }
    printf("%d\n",cnt);
}
/*
100
2 3
0 500000000 1000000000
1000000000 1000000000 1000000000
 */

Measured memory_bytes: 384
import math
N = []
while 1:
    n = int(input())
    if n == 0:
        break
    N.append(n)
# print(N)

for n in N:
    dp = [0]*(n+5)
    dp[0] = 1
    for i in range(n):
        dp[i+1] += dp[i]
        dp[i+2] += dp[i]
        dp[i+3] += dp[i]
    print(math.ceil(dp[n]/3650))



Measured memory_bytes: 5660
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    map<int, int> mp;
    REP(i, N) mp[A[i]]++;

    int ans = 0;
    for(auto p : mp) {
        if (p.first < p.second) {
            ans += p.second - p.first;
        } else if (p.first > p.second) {
            ans += p.second;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <queue>

#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//abc088_D
//dp[i][j]: [x][y]への移動にかかる最小値
//各地点から4方向_行き止まりなら探索終了 初期値 INF  行き止まり -1
//4方向からいけるか調べないと、行き止まりかわからない?→障害物だとわかる

//マップ文字列

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//マップ
int dist[110][110];

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

    ll bCnt = 0;

    vector <string> dangeon(H);
    REP(i,H)
    {
        cin >> dangeon[i];
        REP(j,W)
        {
            if(dangeon[i][j] == '#')++bCnt;
        }
    }


    //初期化
    for(ll i = 0; i  < 110; ++i)
    {
        for(ll j = 0; j  < 110; ++j)
        {
            dist[i][j] = -1;
        }
    }

    dist[0][0] = 1;

    queue <pair<ll, ll>> que;
    que.push(pair<ll,ll>(0,0));

    while(!que.empty())
    {
        pair<ll, ll> cur = que.front();
        que.pop();

        ll x = cur.first;
        ll y = cur.second;

        for(ll i = 0; i < 4; ++i)
        {
            ll nx = x + dx[i];
            ll ny = y + dy[i];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W)continue;
            if(dangeon[nx][ny] == '#')continue;

            //定義済は、行わない→幅優先探索は根からの距離が短いものから優先して探索
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push(pair <ll,ll> (nx,ny));
            }
        }
    }


    if(dist[H-1][W-1] == -1)
    {
        cout << -1 << endl;
    }
    else
    {
        ll res = H * W - bCnt - dist[H-1][W-1];
        cout << res << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main(){
	ll n,tmp;
  	cin>>n;
  	vector<ll> v;
  	for(int i=0;i<n;i++){
    	cin>>tmp;
      	v.pb(tmp);
    }
  	v.pb(0);
  	vector<ll> dp(n+1,0);
  	dp[0]=0;
  	dp[1]=abs(v[1]-v[0]);
  	for(int i=2;i<n;i++){
    	dp[i]=min(dp[i-2]+abs(v[i-2]-v[i]),dp[i-1]+abs(v[i-1]-v[i]));
    }
  	cout<<dp[n-1]<<endl;
  	return 0;
}


Measured memory_bytes: 4824
let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int

let rec count c q =
    if q % 100 = 0 then count (c + 1) (q / 100) else c

readIntArray ()
|> fun [| d; n |] ->
    Seq.initInfinite ((+) 1)
    |> Seq.filter (fun x -> (count 0 x) = d)
    |> Seq.skip (n - 1)
    |> Seq.head
    |> printfn "%d"


Measured memory_bytes: 48700
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 100005
#define pie 3.14159265358979323
#define minuss 1e-6
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 100000000
#define N 10000
ll tra[10000];
int main()
{
    ll n;
    cin>>n;
    ll lock=0;
    ll sum=0;
   for(ll i=1;i<=n;i++)
   {
       for(ll j=1;j<=n;j++)
       {
           for(ll k=1;k<=n;k++)
           {
               ll s=__gcd(j,k);
               sum+=__gcd(i,s);
           }

       }
   }
   cout<<sum<<endl;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  string A,B;
  cin >> A >> B;
  int a = A.size();
  int b = B.size();
  if(a > b){
    cout << "GREATER" << endl;
    return 0;
  }
  if(a < b){
    cout << "LESS" << endl;
    return 0;
  }
  if(A > B) cout << "GREATER" << endl;
  if(A == B) cout << "EQUAL" << endl;
  if(A < B) cout << "LESS" << endl;
}

Measured memory_bytes: 256
n,q=map(int,input().split())
s=input()
c=[0]
t=0

for i in range(0,n-1):
    if s[i]=="A" and s[i+1]=="C":
        t+=1
        c.append(t)
    else:
        c.append(t)

for i in range(q):
    l,r=map(int,input().split())
    print(c[r-1]-c[l-1])


Measured memory_bytes: 6100
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
   ll n;cin>>n;
   ll sum=0;
   for(ll i=0;i<n;i++){
       ll x;cin>>x;
       sum^=x;
   }
   if(sum==0)cout<<"Yes";
   else cout<<"No";
}

Measured memory_bytes: 256
if __name__ == '__main__':
	K = int(input())
	A, B = map(int, input().split())
	c = 0
	for i in range(A,B+1):
		if i % K == 0:
			c = 1

	if c == 1:
		print('OK')
	else:
		print('NG')

Measured memory_bytes: 9176
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#define ll long long
using namespace std;

int main(void){
    int a, b;
    cin >> a >> b;
    if (a == 1) a = 14;
    if (b == 1) b = 14;

    if (a > b){
        cout << "Alice";
    } else if (a < b){
        cout << "Bob";
    } else {
        cout << "Draw";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
  	if(n==k){
      return 1;
    }
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// vector<vector<int>> A(3, vector<int>(4));
int main() {
    int H,W;
    cin>>H>>W;
    vector<bool>A(H);
    vector<bool>B(W);
    vector<vector<char>> C(H, vector<char>(W));
  	rep(i,H){
      A[i]=false;
    }
  rep(i,W){
    B[i]=false;
  }
    rep(i,H){
        rep(j,W){
            cin>>C[i][j];
            if(C[i][j]=='#'){
                A[i]=true;
                B[j]=true;
            }
        }
    }
    rep(i,H){
      	int cnt=0;
        rep(j,W){
            if(A[i]==true&&B[j]==true){
                cout<<C[i][j];
              	cnt++;
            }
        }
      	if(cnt!=0){
        cout<<""<<endl;
        }
    }
}


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

#define vi vector<int>

int main() {

    int N;
    cin >> N;

    for (int i = 1; i < 10; i++) {
        if (N % i == 0 && (N / i) < 10) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	string s;
	cin>>s;
	int n = SZ(s),ans=0;
	
	for (int i = 0; i < n/2; ++i)
	{
		if(s[i]!=s[n-i-1]){
			ans++;
		}
	}
	cout<<ans;
	

   return 0;
}


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

const int INF = 1001001001;
vector<int> to[100005];

int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(n, INF);
    vector<int> pre(n, -1);

    dist[0] = 0;
    q.push(0);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int u : to[v]){
            if(dist[u] != INF) continue;
            dist[u] = dist[v] + 1;
            pre[u] = v;
            q.push(u);
        }
    }

    cout << "Yes" << endl;
    for(int i = 1; i < n; i++){
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }
}

Measured memory_bytes: 10588
#include <iostream>
#include <fstream>
#include <utility>
#include <queue>
#include <vector>
#include <array>
#include <stack>
#include <list>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define bs(n) (1ull<<(n))

map<pair<int, int>,int> mks(vector<pair<pair<int, int>, int>> abc) {
	int n = abc.size();
	map<pair<int, int>, int> r;
	r[make_pair(0,0)] = 0;
	for (unsigned i = 0; i < (1u << n); i++) {
		int sa = 0, sb = 0, sc = 0;
		for (unsigned j = 0; j < n; j++) {
			if (i & (1u << j)) {
				sa += abc[j].first.first;
				sb += abc[j].first.second;
				sc += abc[j].second;
			}
		}
		if (r.find(make_pair(sa, sb)) == r.end()) r[make_pair(sa, sb)] = sc;
		else [](int a, int& b) {b = min(a, b); }(sc, r[make_pair(sa, sb)]);
	}
	return r;
}

int main() {
	int n, ma, mb;
	cin >> n >> ma >> mb;
	vector<pair<pair<int, int>, int>> abc[2];
	abc[0].resize(n/2);
	abc[1].resize(n - (n / 2));
	for (auto& f : abc)	for (auto& e : f) cin >> e.first.first >> e.first.second >> e.second;
	auto s1 = mks(abc[0]), s2 = mks(abc[1]);
	int r = 1000000;
	for (auto& e : s1) {
		for (int i = 1; i <= 400; i++) {
			auto v = s2.find(make_pair(ma * i - e.first.first, mb * i - e.first.second));
			if (v != s2.end()) {
				r = min(r, e.second + v->second);
			}
		}
	}
	cout << (r == 1000000 ? -1 : r) << endl;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i<(int)n;i++)
#define ll long long 
using namespace std;
bool prime(int x){
  int key=0;
  rep2(i,2,sqrt(x)+1) if(x%i==0) key=1;
  if(key==0) return true;
  else return false;
}
  
int main() {
  int x;
  cin >>x;
  int ans;
  rep(i,1000000) {
    if(i>=x&&prime(i)==true) {
      ans=i;
      break;
    }
  }
    cout <<ans<<endl;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int x = 0;
  int ans = 0;
  for(char c:s){
    if(c=='I') x++;
    else x--;
    ans = max(ans,x);
  }  
  cout << ans << endl;
}

Measured memory_bytes: 256
sa = list(str(input()))
sb = list(str(input()))
sc = list(str(input()))

m = {'a': sa, 'b': sb, 'c': sc}
ans = {'a': 'A', 'b': 'B', 'c': 'C'}
turn = 'a'
while True:
  if len(m[turn]) == 0:
    break
  next_turn = m[turn][0]
  next_l = m[turn][1:]
  m[turn] = next_l
  turn = next_turn
print(ans[turn])


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

class Program {

    static void Main (string[] args) {
        string[] str = Console.ReadLine ().Split (' ');
        int A = int.Parse (str[0]);
        int B = int.Parse (str[1]);
        int H = int.Parse (str[2]);
        int M = int.Parse (str[3]);
        double theta1 = ((double) H + (double) M / 60) * Math.PI / 6;
        double theta2 = (double) M * Math.PI / 30;
        double temp1 = (double) A * Math.Cos (theta1) - (double) B * Math.Cos (theta2);
        double temp2 = (double) A * Math.Sin (theta1) - (double) B * Math.Sin (theta2);
        Console.WriteLine (Math.Sqrt ((temp1 * temp1) + (temp2 * temp2)));
    }
}
//dotnet run --project test

Measured memory_bytes: 27856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll n, ans=0;
    vector<P> v;
    cin >> n;
    REP(i,n){
        ll a, b;
        cin >> a >> b;
        v.push_back({a+b,a});
    }
    SORT(v);
    reverse(ALL(v));
    REP(i,n){
        if(i%2) ans -= v[i].first - v[i].second;
        else ans += v[i].second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>
#define MAX 500001

long long A[MAX];

void maxHeapify(int,int);

int main(){
  int i,n;
  
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%lld",&A[i]);
  }

  for(i=n/2;i>=1;i--){
    maxHeapify(i,n);
  }

  for(i=1;i<=n;i++){
    printf(" %lld",A[i]);
  }

  printf("\n");

  return 0;
}


void maxHeapify(int i,int n){
  int large;
  int temp;

  if(2*i<=n && A[2*i]>A[i]) large=2*i;
  else large=i;
  if(2*i+1<=n && A[2*i+1]>A[large]) large=2*i+1;

  if(large!=i){
    temp=A[i];
    A[i]=A[large];
    A[large]=temp;
    maxHeapify(large,n);
  }
}

Measured memory_bytes: 4504
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	if(a<=0 && 0<=b){
		cout << "Zero" << endl;
	}else if(0<a){
		cout << "Positive" << endl;
	}else if(b<0){
		if((b-a+1)%2==0){
			cout << "Positive" << endl;
		}else{
			cout << "Negative" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define pq          priority_queue
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define vll         vector<pll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

bool comp(pll a, pll b)
{
    return a.F>b.F;
}

void solve()
{
    ll n,k; cin>>n>>k;
    pll a[n+2];
    rep(i,1,n+1) cin>>a[i].S>>a[i].F;
    sort(a+1,a+1+n,comp);
    bool vis[n+1];
    mset(vis);
    stack<ll>s;
    ll cnt=0, tp=0, ans=0, res=0;
    rep(i,1,n+1){
        if(cnt<k){
            if(vis[a[i].S]) s.push(a[i].F);
            else { vis[a[i].S]=1, tp++; }
            res+=a[i].F;
            cnt++;
            ans=max(ans, res+tp*tp);
        }
        else{
            if(s.empty()) break;
            if(vis[a[i].S]) continue;
            vis[a[i].S]=1;
            tp++;
            res-=s.top(); s.pop();
            res+=a[i].F;
            ans=max(ans, res+tp*tp);
        }
    }
    cout<<ans;
}

int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
 int main()
{
	int n,m;
	cin>> m >> n ;
	int a;
	cin>> a ;
	int sum=0;
	for (int i=m;i<=n;i++){
		if (i%a==0){
			sum++;
		}
	}
	cout<< sum ;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    set<string> s1;
    string s;
    int N,cnt=0;
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        cin>>s;
        if(s1.find(s)==s1.end())
        {
            s1.insert(s);
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Union Find tree
//-------------------------------------------------
class UnionFind
{
private:
    ::std::vector<int> par;
    ::std::vector<int> rank;
    ::std::vector<int> diff;
public:
    UnionFind(int n):par(n), rank(n), diff(n){
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
            diff[i] = 0;
        }
    }
    int root(int x){
        if (par[x]==x) return x;
        int rx = root(par[x]);
        diff[x] += diff[par[x]];
        return par[x] = rx;
    }
    int weight(int x){
        root(x);
        return diff[x];
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    void unite(int x, int y, int w){
        int rx = root(x);
        int ry = root(y);
        if (rx==ry) return;
        w += weight(x)-weight(y);
        if (rank[rx]>rank[ry]){
            diff[ry] = w;
            par[ry] = rx;
        }else{
            diff[rx] = -w;
            par[rx] = ry;
            if (rx==ry) rank[ry]++;
        }
    }
};

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        int l,r,d; cin>>l>>r>>d; l--; r--;
        if (uf.same(l,r)){
            if (uf.weight(r)-uf.weight(l)!=d){
                cout<<"No\n";
                return 0;
            }
        }else{
            uf.unite(l,r,d);
        }
    }
    cout<<"Yes\n";
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

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

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

int N;

int main(){
    cin >> N;

    int X = N;
    int x = 0;
    while(0 < X){
        x += X % 10;
        X /= 10;
    }

    string ans;
    ans = ((N % x == 0)? "Yes" : "No");

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool T=false;
int main(){
    int L,R,d;cin>>L>>R>>d;
    int cnt=0;
    for (int i = L; i <= R; i++)
    {
        if(i%d==0)cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
	int i, N, T, least = INT_INF;
	cin >> N >> T;
	for (i = 0; i < N; i++) {
		int c, t;
		cin >> c >> t;
		if (t <= T) {
			least = min(least, c);
		}
	}
	if (least == INT_INF) cout << "TLE" << endl;
	else cout << least << endl;
	return 0;
}




Measured memory_bytes: 256
import java.util.*;

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

        long sum = 0;
        
        for(int i = 1; i <= n; i++){
            if(i % 3 != 0 && i % 5 != 0){
                sum += i;
            }
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 35712
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
#define PI = 3.14159265358979323846
/*------------------------------------------------------------------------------*/

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

  string s;
  cin >> s;

  VI ans(N);
  //0 -> S, 1 -> W
  vector<bool> sample = {0, 0, 0, 1, 1, 0, 1, 1};
  int cnt = 0;
  bool b = false;

  while(cnt < 4){
    ans[0] = sample[cnt*2];
    ans[1] = sample[cnt*2+1];
    REP(i, 2, N){
      if(s[i-1] == 'o' && !ans[i-1]){
        ans[i] = ans[i-2];
      }
      if(s[i-1] == 'x' && !ans[i-1]){
        ans[i] = !ans[i-2];
      }
      if(s[i-1] == 'o' && ans[i-1]){
        ans[i] = !ans[i-2];
      }
      if(s[i-1] == 'x' && ans[i-1]){
        ans[i] = ans[i-2];
      }
    }
    bool order1 = false, order2 = false;
    if(s[0] == 'o' && !ans[0]){
      order1 = ans[1] == ans[N-1];
    }
    if(s[0] == 'x' && !ans[0]){
      order1 = ans[1] == !ans[N-1];
    }
    if(s[0] == 'o' && ans[0]){
      order1 = ans[1] == !ans[N-1];
    }
    if(s[0] == 'x' && ans[0]){
      order1 = ans[1] == ans[N-1];
    }
    if(s[N-1] == 'o' && !ans[N-1]){
      order2 = ans[0] == ans[N-2];
    }
    if(s[N-1] == 'x' && !ans[N-1]){
      order2 = ans[0] == !ans[N-2];
    }
    if(s[N-1] == 'o' && ans[N-1]){
      order2 = ans[0] == !ans[N-2];
    }
    if(s[N-1] == 'x' && ans[N-1]){
      order2 = ans[0] == ans[N-2];
    }
    if(order1 && order2){
      b = true;
      break;
    }
    cnt++;
  }
  if(b){
    REP(i, 0, N){
      if(ans[i]){
        cout << 'W';
      } else {
        cout << 'S';
      }
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


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

const int T_MAX = 401;
const int INF = 1e+8;
int M, g[51][51];
// dp[i][j][t] := (i,j) = (Aaronの位置,Bruceの位置), ターン数 t のときの
int dp[51][51][T_MAX];

// 初期化
void init(){
	for(int i=0 ; i < 51 ; i++ ){
		for(int j=0 ; j < 51 ; j++ ){
			g[i][j] = 0;
			for(int k=0 ; k < T_MAX ; k++ ){
				dp[i][j][k] = -1;
			}
		}
	}
}

// (a,b) = (Aaronの位置,Bruceの位置), t : ターン数
int dfs(int a, int b, int t){
	if( a == b ) return t;
	if( t >= T_MAX ) return INF;
	if( dp[a][b][t] >= 0 ) return dp[a][b][t];
	
	if( t % 2 == 0 ){ // 偶数ターン(Aaronが動く)
		dp[a][b][t] = 0;
		for(int i=0 ; i < M ; i++ ){
			if( g[a][i] ){
				dp[a][b][t] = max( dp[a][b][t] , dfs(i,b,t+1) );
			}
		}
		return dp[a][b][t];
	}else{ // 奇数ターン(Bruceが動く)
		dp[a][b][t] = INF;
		for(int i=0 ; i < M ; i++ ){
			if( g[b][i] ){
				dp[a][b][t] = min( dp[a][b][t] , dfs(a,i,t+1) );
			}
		}
		return dp[a][b][t];
	}
}

int main(){
	int T;
	cin >> T;
	for(int t_ = 0 ; t_ < T ; t_++ ){
		// 初期化
		init();
		
		cin >> M;
		for(int i=0 ; i < M ; i++ ){
			for(int j=0 ; j < M ; j++ ){
				cin >> g[i][j];
				if( i == j ) g[i][j] = 1;
			}
		}
		int a, b;
		cin >> a >> b;
		int ans = dfs(a,b,0);
		if( ans > T_MAX ){
			cout << "infinity" << endl;
		}else{
			cout << ans/2 << endl;
		}
	}
}

Measured memory_bytes: 5272
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18
const int N = 100010;//10^5+10

int main() {

	string s, t; cin >> s >> t;
	map<char,LL> sm;
	map<char,LL> st;



	for (int i = 0; i < s.length(); i++) {
		sm[s[i]]++;
		st[t[i]]++;
	}

	for (int i = 0; i < s.length(); i++) {
		
			if (sm[s[i]] != st[t[i]]) {
				cout << "No" << endl;
				return 0;
			}
		
	}

	cout << "Yes" << endl;

	return 0;
}

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

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
   int n,k;
    cin >> n >> k;
   
   int p[n];
    f(i,n) cin >> p[i];
    f(i,n) p[i]--;
    
   int c[n];
    f(i,n) cin >> c[i];
    
   int res = -2e18;
    
   f(i,n)
   {
       if(k <= n)
       {
           int temp = 0;
           int cur = i;
           
           f(j,k)
           {
               cur = p[cur];
               temp+=c[cur];
               res = max(res,temp);
           }
       }
       else
       {
           
       int cur = p[i];
    
       vi vis(n+1,0);
       vi go;
       
       while(1)
       {
           if(vis[cur] == 1) break;
           vis[cur] = 1;
           go.pb(cur);
           cur = p[cur];
       }
      
       //find position of cur in go
       int id = -1;
       f(j,go.size()) if(go[j] == cur) id = j;
       
       int temp = 0;
      
       f(j,id)
       {
           temp+=c[go[j]];
           res = max(res,temp);
       }
           
       //now we have a cycle from id to end of the array
       int ssum = 0;
           
       for(int j=id;j<go.size();j++) ssum+=c[go[j]];
           
       int kk = k - id;
           
       int len = (int)go.size() - id;   
           
       if(ssum > 0 && kk > n+n)
       {
           int complete = (kk/len) - 2;
           temp+=ssum*complete;
           kk-=(complete*len);
       }
           
       if(ssum <= 0) kk = min(kk,n);    
        
       id = go[id];  
           
       //bruteforce for atmost 2*length
       while(kk > 0)
       {
           temp+=c[id];
           res = max(res,temp);
           id = p[id];
           kk--;
       }
           
       res = max(res,temp);
       }   
   }
    
   cout << res ; 
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 3880
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    const Q = parseInt(arg[0].split(" ")[2]);
    
    const A = arg.slice(1, Q + 1).map(n=>parseInt(n));
    let points = new Array(N).fill(0);
    
    for(let i=0; i<Q; i++) {
        points[A[i]-1]++;
    }
    
    let answer = points.map(n=>(n + K) - Q > 0 ? "Yes" : "No");

    console.log(answer.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 28236
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k, bool b) {
    if (k < 0 || k > n) return 0;
    if(b) return fact[n]*ifact[k]*ifact[n-k];
    else return fact[n]*ifact[n-k];
  }
}comb(1000005);

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

    mint ans = 0;

    rep2(i,K,N+2){
      ans += i* N - i*(i - 1) + 1;
    }


    cout << ans << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 18616
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

using P = pair<int, int>;

vector<int> imos(100000, 0);

bool solve() {
    int n;
    cin >> n;
    if(n == 0) {
        return false;
    }
    imos.assign(100000, 0);
    for(int i = 0; i < n; i++) {
        string s, e;
        cin >> s >> e;
        // print(s.substr(0, 2), s.substr(3, 2), s.substr(6, 2));
        int l = stoi(s.substr(0, 2)) * 3600 + stoi(s.substr(3, 2)) * 60 +
                stoi(s.substr(6, 2));
        int r = stoi(e.substr(0, 2)) * 3600 + stoi(e.substr(3, 2)) * 60 +
                stoi(e.substr(6, 2));
        imos[l]++;
        imos[r]--;
    }
    for(int i = 1; i < 100000; i++) {
        imos[i] += imos[i - 1];
    }
    print(*max_element(ALL(imos)));
    return 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1) {
        if(!solve()) {
            break;
        }
    }
}


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

int main(){
    string a, b;
    cin >> a >> b;
    bool ans = false;
    for(int i = 0; i < a.size(); i++){
        // 後ろを先頭に持ってくる
        if(a == b){
            ans = true;
            break;
        }
        a = a.back() + a.substr(0, a.size() - 1);
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
  int N;
  cin >> N;
  double x[N];
  string u[N];
  for (int i = 0; i < N; i++){
    cin >> x[i] >> u[i];
  }
  double money = 0;
  for(int i = 0; i < N; i++){
    if(u[i] == "JPY") money += x[i];
    else money += (x[i]*380000.0);
  }
  cout << money << endl;
  return 0;
}


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

using namespace std;

int n, m;
string s;
vector<int> moves;

signed main(){
	cin >> n >> m >> s;
	bool ok = true;
	for(int i = 1, now = 0; i <= n; ++i){
		if(i == n || s[i] == '0') 
			moves.push_back(i - now), ok &= (i - now <= m), now = i;
	}
	if(!ok) cout << -1;
	else {
		for(int i = (int)moves.size() - 1; i > 0; --i)
			if(moves[i] + moves[i - 1] <= m) moves[i - 1] += moves[i], moves[i] = 0;
		for(auto e : moves) if(e) cout << e << ' ';
	}
}

Measured memory_bytes: 4008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

/**
 * The Code A Doctor Loved
 */
public class Main {

	static final HashMap<Character, String> c1 = new HashMap<Character, String>() {
		{
			put(' ', "101");
			put('\'', "000000");
			put(',', "000011");
			put('-', "10010001");
			put('.', "010001");
			put('?', "000001");
			put('A', "100101");
			put('B', "10011010");
			put('C', "0101");
			put('D', "0001");
			put('E', "110");
			put('F', "01001");
			put('G', "10011011");
			put('H', "010000");
			put('I', "0111");
			put('J', "10011000");
			put('K', "0110");
			put('L', "00100");
			put('M', "10011001");
			put('N', "10011110");
			put('O', "00101");
			put('P', "111");
			put('Q', "10011111");
			put('R', "1000");
			put('S', "00110");
			put('T', "00111");
			put('U', "10011100");
			put('V', "10011101");
			put('W', "000010");
			put('X', "10010010");
			put('Y', "10010011");
			put('Z', "10010000");
		}
	};

	static final HashMap<String, Character> c2 = new HashMap<String, Character>() {
		{
			put("00000", 'A');
			put("00001", 'B');
			put("00010", 'C');
			put("00011", 'D');
			put("00100", 'E');
			put("00101", 'F');
			put("00110", 'G');
			put("00111", 'H');
			put("01000", 'I');
			put("01001", 'J');
			put("01010", 'K');
			put("01011", 'L');
			put("01100", 'M');
			put("01101", 'N');
			put("01110", 'O');
			put("01111", 'P');
			put("10000", 'Q');
			put("10001", 'R');
			put("10010", 'S');
			put("10011", 'T');
			put("10100", 'U');
			put("10101", 'V');
			put("10110", 'W');
			put("10111", 'X');
			put("11000", 'Y');
			put("11001", 'Z');
			put("11010", ' ');
			put("11011", '.');
			put("11100", ',');
			put("11101", '-');
			put("11110", '\'');
			put("11111", '?');
		}
	};

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {
			//
			if (line.isEmpty()) {
				System.out.println("");
				continue;
			}
			StringBuilder sb1, sb2;
			sb1 = new StringBuilder();
			sb2 = new StringBuilder();
			for (char c : line.toCharArray()) {
				sb1.append(c1.get(c));
			}
			//
			sb1.append("00000");
			//
			String line2 = sb1.toString();
			for (int i = 0; i < line2.length() - 5; i += 5) {
				sb2.append(c2.get(line2.substring(i, i + 5)));
			}
			System.out.println(sb2.toString());
		}
	}
}

Measured memory_bytes: 23916