akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

ll N, K, ans=0;

int main() {

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

  cin>>N>>K;
  ll lsum=0,rsum=0;
  for(int i = 0;i <= N;i++) {
    lsum += i;
    rsum += N-i;
    if(i+1>=K) {
      ans += (rsum-lsum+1);
      ans%=mod;
    }

  }
  cout<<ans<<endl;

  return 0;
}


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

int main() {
  ll N, K;
  cin >> N >> K;
  rep(i, 1000000){
    if (N / K) N = N % K;
    else if (N > K/2) N = abs(N - K);
    else break;
  }
  cout << N << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

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

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;

ll sumXOR(ll arr[], int n)
{
    ll sum = 0;
    for (ll i = 0; i <= 62; i++)
    {
        ll zc = 0, oc = 0;
        ll idsum = 0;
        for (int j = 0; j < n; j++)
        {
            if (arr[j]%2LL==0)
                zc++;
            else
                oc++;
            arr[j] /= 2LL;
        }
        idsum = ((oc%MOD) * (zc%MOD))%MOD;
        idsum = ((idsum)%MOD * ((1LL<<i)%MOD))%MOD;
        sum = ((sum%MOD) + (idsum%MOD))%MOD;
    }
    return sum%MOD;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    int n;
    cin>>n;
    ll a[n+5];
    for(int i = 0; i < n; i++)
        cin>>a[i];

    ll ans = sumXOR(a, n);
    cout<<ans<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 2688
def main():
    s = input()
    dp = []
    curr = s[0]
    count = 0
    for i in s:
        if i == curr:
            count += 1
        else:
            dp.append((curr,count))
            curr = i
            count = 1

    dp.append((curr,count))
            
    ans = []
    for i in range(len(dp)):
        if i+1 < len(dp) and dp[i][0] == 'R' and dp[i+1][0] == 'L':
            moves = min(dp[i][1],dp[i+1][1])-1
            for j in range(dp[i][1]-1):
                ans.append(0)
            total = dp[i][1]+dp[i+1][1]
            if total%2 == 0:
                ans.append(total//2)
                ans.append(total//2)
            else:
                first = total//2
                second = first+1
                if moves%2 != 0:
                    if dp[i][1] > dp[i+1][1]:
                        ans.append(second)
                        ans.append(first)
                    else:
                        ans.append(first)
                        ans.append(second)
                else:
                    if dp[i][1] > dp[i+1][1]:
                        ans.append(first)
                        ans.append(second)
                    else:
                        ans.append(second)
                        ans.append(first)

            for j in range(dp[i+1][1]-1):
                ans.append(0)

    for i in ans:
        print(i,end = ' ')

main()


Measured memory_bytes: 12016
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
 
#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mk(arr,n,type)  type *arr=new type[n];
 
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
int main(){
	 ll A, B; cin >> A >> B;
    char C; cin >> C;
    int D; cin >> D;
    B *= 100; B += D;
    ll X = A*B; X /= 100;
    cout << X << endl;
	
	return 0;
}



Measured memory_bytes: 3196
import heapq
N,K=map(int,input().split())
V=list(map(int,input().split()))

#a:左からとる b:右からとる K-a-b:捨てる
score=0
torikata=[]
for d in range(101):
    for a in range(101):
        for b in range(101):
            if d+a+b<=K and a+b<=N:
                torikata.append((a,b,d))

for i in range(len(torikata)):
    A,B,D=torikata[i][0],torikata[i][1],torikata[i][2]
    H=[]
    for i in range(A):
        H.append(V[i])
    for i in range(B):
        H.append(V[-(i+1)])
    heapq.heapify(H)
    for i in range(min(D,A+B)):
        heapq.heappop(H)
    score=max(score,sum(H))

print(score)

Measured memory_bytes: 10312
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int x, a, b;
  cin >> x >> a >> b;
  if (abs(x - a) > abs(x - b)) {
    cout << "B" << endl;
  } else {
    cout << "A" << endl;
  }
}

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

int main() {
  string s;
  cin >> s;
  int sum = 700;
  for(int i = 0; i < 3; i++) {
    if(s[i] == 'o') sum += 100;
  }
  cout << sum << "\n";
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n,a,b;cin>>n>>a>>b&&n|a|b;){
		cout<<(b-a-1&1?"Alice":"Borys")<<endl;
	}
}


Measured memory_bytes: 384
/*
 © 2020-06-27 07:00:49 Franco1010 All Rights Reserved
*/

#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
#define deb(x) cout << #x": " << (x) << endl;
const int N = 1e7 + 5;
lli d[N];
int main(){ _
  fore(i, 0, N){
    fore(j, 0, N){
      if(i * j >= N) break;
      d[i * j]++;
    }
  }
  lli res = 0;
  lli n; cin >> n;
  fore(i, 1, n + 1) res += lli(i) * d[i];
  cout << res << ENDL;
  return 0;
}


Measured memory_bytes: 81696
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 1e5 + 5;
const int OO = 2e9;

void init() {

}

int n,k,ans,a;

int main() {

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

    cin >> n >> k;

    ans++, n-=k;

    for(int i=0;i<n;++i) cin >> a;

    while(n>0) {

        n -= (k-1);
        ++ans;

    }

    cout << ans << '\n';

    return 0;

}

Measured memory_bytes: 256
/* ユークリッドの互除法を用いて２自然数の最大公約数を求めるプログラム*/
#include <stdio.h>

int calc_gcd(int, int);

int main()
{
  int x, y;

  scanf("%d%d", &x, &y);

  printf("%d\n", calc_gcd(x, y));

  return 0;
}

/*ユークリッドの互除法を用いて２つの自然数の最大公約数を求める関数*/
int calc_gcd(int x, int y)
{
  int tmp;

  /* x >= y の状態にする*/
  if( y > x )
    {
      tmp = x;
      x = y;
      y = tmp;
    }

  while( x % y != 0 )
    {
      tmp = y;
      y = x % y;
      x = tmp;
    }

  return y;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> l(n);
  for (int i = 0; i < n; i++) cin >> l[i];
  sort(l.rbegin(), l.rend());
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += l[i];
  }
  cout << sum << endl;
}


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

int main() {
  int n;
  cin >> n;
  
  int ans = 0, c = -1;
  for(int i = 0; i < n; i++){
    int k;
    cin >> k;
    if(c == k) ans++, c = -1;
    else c = k;
  }
  
  cout << ans << endl;
}

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

int main(){
    int n, rank;
    bool cards[4][14];
    char suit;

    for(int i=0; i<4; i++){
        for(int j=1; j<=13; j++){
            cards[i][j] = 0;
        }
    }

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> suit >> rank;
        if(suit == 'S') cards[0][rank] = 1;
        if(suit == 'H') cards[1][rank] = 1;
        if(suit == 'C') cards[2][rank] = 1;
        if(suit == 'D') cards[3][rank] = 1;
    }

    for(int i=0; i<4; i++){
        for(int j=1; j<=13; j++){
            if(cards[i][j]) continue;
            if(i == 0) suit = 'S';
            if(i == 1) suit = 'H';
            if(i == 2) suit = 'C';
            if(i == 3) suit = 'D';
            cout << suit << " " << j << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3104
def main():
    n = int(input())
    f = [0] * n
    for x in range(1, n):
        if x * x > n:
            break
        for y in range(1, n):
            if x * x + y * y + x * y > n:
                break
            for z in range(1, n):
                if x * x + y * y + z * z + x * y + y * z + z * x > n:
                    break
                f[x * x + y * y + z * z + x * y + y * z + z * x - 1] += 1
    print(*f, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9220
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 3e2+10;
pii pos[N*N];
int dis(int i,int j){
    return abs(pos[i].F-pos[j].F)+abs(pos[i].S-pos[j].S);
}
int a[N][N];
vector<int> vec[N*N],dp[N*N];
int cnt[N*N];
int pos2[N*N];
/*
6
4
8
10
9
3
4

5 5 6
2 5 6 3 1
4 8 9 7 10
12 11 13 15 25
14 16 17 18 19
20 21 22 23 24
8
6 12
6 18
6 24
4 16
8 14
8 20
7 1
1 1
*/
main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int h,w,d;cin>>h>>w>>d;
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++){
            cin>>a[i][j];
            pos[a[i][j]]={i,j};
            int t=a[i][j]%d;
            if(vec[t].size()==0)
                vec[t].pb(0);
            vec[t].pb(a[i][j]);
            cnt[t]++;
        }
    for(int i=0;i<d;i++){
        if(cnt[i]>0){
            sort(vec[i].begin(),vec[i].end());
            pos2[vec[i][1]]=1;
            dp[i].resize(vec[i].size()+10);
            for(int j=2;j<=cnt[i];j++)
                pos2[vec[i][j]]=j,dp[i][j]=dp[i][j-1]+dis(vec[i][j],vec[i][j-1]);//,cout<<vec[i][j]<<" "<<dp[i][j]<<endl;
        }
    }
    int q;cin>>q;
    while(q--){
        int l,r;cin>>l>>r;
        int pl=pos2[l],pr=pos2[r];
        //cout<<pl<<" "<<pr<<endl;
        cout<<abs(dp[l%d][pr]-dp[l%d][pl])<<endl;
    }
}


Measured memory_bytes: 21248
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{
constexpr long long modPow(long long n, long long p, const int mod = int(1e9)+7)
{
    long long ret = 1;
    while(p) {
        if (p & 1) ret = (ret * n) % mod;
        n = (n * n) % mod;
        p >>= 1;
    }
    return ret;
}
// }}}


signed main()
{
    i64 m, n;
    cin >> m >> n;

    cout << modPow(m, n) << endl;
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
using namespace std;
int main () {
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    int cnt = 0;
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            for(int k=0; k<n; k++) {
                if(a[i]!=a[j] && a[i]!=a[k] && a[k]!=a[j]){
                    if(a[i]+a[j]>a[k] && a[j]+a[k]>a[i] && a[i]+a[k]>a[j]) {
                        cnt++;
                    }
                }
            }
        }
    } cout << cnt/6 << endl;
    return 0;
}

Measured memory_bytes: 3664
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s; i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;


int main(){
    IOS;
    int n; cin >> n;
    vector<vector<int>> g(n);

    vector<pair<int, int>> e(n-1);
    REP(i, n-1){
        int a, b; cin >> a >> b;
        --a; --b;
        g[a].push_back(b); g[b].push_back(a);
        e[i] = make_pair(a, b);
    }
    
    map<pair<int, int>, int> im; //辺と色
    int k = 0;
    vector<int> clfrp(n, 0); //親との間の色
    vector<bool> searched(n, false);
    queue<int> que;
    searched[0] = true;
    que.push(0);
    while(!que.empty()){
        int v = que.front(); que.pop();
        k = max(k, (int)g[v].size());
        int cur = 1;
        for(int u : g[v]){
            if(searched[u]) continue;
            if(cur == clfrp[v]) ++cur;
            clfrp[u] = im[make_pair(u, v)] = im[make_pair(v, u)] = cur++;
            searched[u] = true;
            que.push(u);
        }
    }

    cout << k << "\n";
    REP(i, n-1) cout << im[e[i]] << "\n";
    return 0;
}


Measured memory_bytes: 19712
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define S set<int>
#define pb(v) push_back(v)
vector<string> vec1,vec2;
int M;
bool check(int a,int b){
    REP(c,M){
        REP(d,M){
            if(vec1.at(a+c).at(d+b)!=vec2.at(c).at(d)){
                //cout<<vec1.at(a+c).at(d+b);
                return false;
            }
        }
        //cout<<endl;
    }
    return true;
}
int main(){
    CIN(N);cin >> M;
    REP(i,N){
        string str;cin >> str;
        vec1.pb(str);
    }
    REP(i,M){
        string str;cin >> str;
        vec2.pb(str);
    }
    bool result = false;
    REP(a,N-M+1){
        REP(b,N-M+1){
            if(check(a,b))result = true;
        }
    }
    Yes(result);
    return 0;
}


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



using namespace std;

int main()
{
	string a, b, c;
	cin >> a >> b >> c;

	int asize, bsize;
	asize = a.size();
	bsize = b.size();

	if (a[asize - 1] == b[0] && b[bsize - 1] == c[0]) cout << "YES" << endl;
	else cout << "NO" << endl;

    return 0;
}

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

int main() {
	int N, M, L;
	cin >> N;

	M = N / 10;
	L = N - (N / 1000) * 1000;

	if (M % 111 == 0 || L % 111 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
 
    vector<ll>a(5005);
    vector<ll>b(5005);
    vector<ll>track;
    bool vis[5005];
 
    void dfs(int u , long long total_cycle){
        if(vis[u]) return ;
        vis[u]=true;
        total_cycle+=b[u];
        track.push_back(total_cycle);
        dfs(a[u],total_cycle);
    }
    void solve(){
        int n,k;
        cin>>n>>k;
        for(int i=0;i<n;i++){
            cin>>a[i];
            a[i]--;
        }
        for(int i=0;i<n;i++)
            cin>>b[i];
        ll ans=-(1e18);
        for(int i=0;i<n;i++){
            memset(vis,false,sizeof(vis));
            dfs(i,0);
            if(track.back()>0 && k>=(int)(track.size())){
                ll cycles=(ll)(k/(int)track.size());
                ll left=(ll)(k%(int)track.size());
                ll maxi=-1e18;
                for(int x=0;x<(int)track.size();x++)
                    maxi=max(maxi,track[x]);
                ans=max(ans,(cycles-1LL)*(track.back())+maxi);
                maxi=-1e18;
                for(int x=0;x<left;x++)
                    maxi=max(maxi,track[x]);
                ans=max(ans,(cycles*track.back()) + maxi);
            }
            else{
                for(int j=0;j<(min((int)track.size(),k));j++){
                    ans=max(ans,track[j]);
                }
            }
            track.clear();
        }
        cout<<ans;
        return;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;

        }



Measured memory_bytes: 3964
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

#define MAX_SIZE 1000100
// int a[100010]={0};
ll all[MAX_SIZE - 1], part[MAX_SIZE - 1]; // segment tree
void add(int a,int b,int x,int k,int l,int r){
	if(a<=l&&r<=b){
		all[k]+=x;
	}
	else if(l<b&&a<r){
		part[k]+=(min(b,r)-max(a,l))*x;
		add(a,b,x,k*2+1,l,(l+r)/2);
		add(a,b,x,k*2+2,(l+r)/2,r);
	}
}

ll sum(int a,int b,int k,int l,int r){
	// if(k>100010) cout<<"hoge"<<endl;
	// cout<<k<<" "<<l<<" "<<r<<endl;
	if(r<=a||b<=l){
		return 0;
	}
	if(a<=l&&r<=b){
		return all[k]*(r-l)+part[k];
	}

	else{

		ll res;
		res=(min(b,r)-max(a,l))*all[k];
		res+=sum(a,b,k*2+1,l,(l+r)/2);
		res+=sum(a,b,k*2+2,(l+r)/2,r);
		return res;
	}
	return 0;
	// return getsum(a,b,k,l,(l+r)/2)+getsum(a,b,k,(l+r)/2,r));
}



int main(){
	int n;
	cin>>n;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		// cout<<a<<" "<<b<<endl;
		add(a,b+1,1,0,0,100005);
		// cout<<sum(a,b,0,0,100005)<<endl;
	}
	// ll ans=0;
	// cout<<0<<endl;
	int ans=0;
	rep(i,100005){
		ll t=sum(i+1,i+2,0,0,100005);
		if(i<=(int)t){
			ans=max(ans,i);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 8328
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;

typedef struct Node{
  int value;
  Node *parent, *left, *right;
} Node;

Node *NIL, *root;

void insert(int k){
  Node *y = NIL, *x = root, *z;

  z = (Node *)malloc(sizeof(Node));
  z->value = k;
  z->left = z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->value < x->value) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->value < y->value) y->left = z;
  else y->right = z;
}

Node* find(Node *x, int k){
  if(x == NIL || x->value == k) return x;

  if(k < x->value) return find(x->left, k);
  else return find(x->right, k);
}

Node* treeMinimum(Node *x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node* treeSuccessor(Node *x){
  Node *y;

  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void Delete(Node *z){
  Node *x, *y;

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->value = y->value;
}

void preParse(Node *node){
  if(node == NIL) return ;

  cout << " " << node->value;
  if(node->left != NIL) preParse(node->left);
  if(node->right != NIL) preParse(node->right);
}

void inParse(Node *node){
  if(node == NIL) return ;

  if(node->left != NIL) inParse(node->left);
  cout << " " << node->value;
  if(node->right != NIL) inParse(node->right);
}

int main(){

  int n, key;
  string command;

  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> command;
    if(command == "insert"){
      cin >> key;
      insert(key);
    }else if(command == "print"){
      inParse(root);
      cout << endl;
      preParse(root);
      cout << endl;
    }else if(command == "find"){
      cin >> key;
      if(find(root, key)) cout << "yes" << endl;
      else cout << "no" << endl;
    }else if(command == "delete"){
      cin >> key;
      Delete(find(root, key));
    }
  }

  return 0;
}



Measured memory_bytes: 21916
import java.io.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] split = str.split(" ",0);
			int a = Integer.parseInt(split[0]);
			int b = Integer.parseInt(split[1]);
			System.out.println(a * b + " " + 2 * (a + b));
		} catch (Exception e) {
			System.out.println("??¨??????");
		}
	}
}

			

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

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
    boost();
    string s,t;
    cin >> s >> t;
    ll n = s.length();
    ll m = t.length();
    
    ll dp[n+1][m+1];
    ll i,j;
    for(i=0;i<=n;i++){
        for(j=0;j<=m;j++){
            if(i==0||j==0)
            dp[i][j]=0;
            else if(s[i-1]==t[j-1])
            dp[i][j] = 1+dp[i-1][j-1];
            else
            dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    ll l = dp[n][m];
    //cout << l << endl;
    char lcs[l+1];
    lcs[l]='\0';
    i=n,j=m;
    while(i>0&&j>0){
        if(s[i-1]==t[j-1]){
            lcs[l-1]=s[i-1];
            i--;j--;l--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
        i--;
        else
        j--;
    }
    
    cout << lcs << endl;
}

Measured memory_bytes: 74016
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
string s;
bool ck(int l,int r){
	//cout<<l<<" "<<r<<endl;
	while(l<r){
		if(s[l]!=s[r])return false;
		l++,r--;
	}
	return true;
}

int main()
{
	cin>>s;
	int len=s.length();
	for(int i=len;i>=1;i--)s[i]=s[i-1];
	if(ck(1,len)&&ck(1,(len-1)/2)&&ck((len+3)/2,len))puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   int n,s=0,t=0;
   cin>>n;
   vector<int> d(n);
   rep(i,n){
     cin>>d.at(i);
     s+=d.at(i);
   }
   s=s*s;
   rep(i,n)s=s-(d.at(i))*(d.at(i));
   cout<<s/2<<endl;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

H, W, K = map(int, input().split())
K -= 1
# 0-indexed

dp = [[0 for _ in range(W)] for _ in range(H + 1)]
dp[0][0] = 1
# dp[h][k]
# h段のあみだくじで横線kに到達する本数

for h in range(H):
    # h: 移動前の高さ
    for b in range(1 << (W - 1)):
        # 各段はW - 1箇所の横線配置位置をもつ

        if '11' in bin(b): continue
        # 横線同士がつながっているケースは不適

        goto = [i for i in range(W)]
        # goto[i]: 縦線iからの移動先

        for j in range(W - 1):
            # j: 横線の番号 かつ 横線の左側の縦線の番号
            if (b >> j) & 1 == 1:
                # 横線が存在する場合
                goto[j], goto[j + 1] = goto[j + 1], goto[j]
        # gotoで横線配置bによる移動を表現する

        for i in range(W):
            # i: 移動前の縦線
            dp[h + 1][goto[i]] += dp[h][i]
            dp[h + 1][goto[i]] %= MOD

print(dp[H][K])


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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];

    map<int, int> cnt;

    rep(i, N) {
        if (cnt.count(a[i]) == 0) {
            cnt[a[i]] = 1;
        }
        else {
            cnt[a[i]]++;
        }
    }

    ll ma=0;
    for (auto t : cnt) {
        int f = t.first;
        int s = t.second;

        if (s >= 2) {
            ma = max((ll)f, ma);
        }

    }

    cnt[ma] -= 2;
    ll ma2=0;

    for (auto t : cnt) {
        int f = t.first;
        int s = t.second;

        if (s >= 2) {
            ma2 = max(ma2, (ll)f);
        }

    }

    cout << ma*ma2 << endl;
}


Measured memory_bytes: 5376
using System;

namespace FindingMissingCards
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			bool[,] card = new bool[4, 13];

			for (int i = 0; i < n; i++)
			{
				string[] rstr = Console.ReadLine().Split();
				int rank = int.Parse(rstr[1]);
				Card(card, rstr, rank);
			}

			WriteShortageCard(card);

		}

		private static void Card(bool[,] card, string[] s, int rank)
		{
			switch (s [0]) {

			case "S":
				card[0, rank - 1] = true;
				break;
			case "H":
				card[1, rank - 1] = true;
				break;
			case "C":
				card[2, rank - 1] = true;
				break;
			case "D":
				card[3, rank - 1] = true;
				break;
			default:
				break;
			}
		}

		private static void WriteShortageCard(bool[,] card)
		{
			string[] picture = { "S", "H", "C", "D" };

			for (int i = 0; i < 4; i++)
			{
				for (int j = 0; j < 13; j++)
				{
					if (false == card[i, j])
					{
						Console.WriteLine("{0} {1}", picture[i], j + 1);
					}
				}
			}
		}
	}
}

Measured memory_bytes: 20076
// ref. https://img.atcoder.jp/arc064/editorial.pdf

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  string s;
  cin >> s;
  ll n = s.size();
  bool even = (n%2 == 0);
  bool same = (s[0] == s[n-1]);
  if (even^same) {
    cout << "Second" << endl;
  } else {
    cout << "First" << endl;
  }
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    string s,t;
    cin >> s >> t;

    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    
    if(s<t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
sss = [input() for _ in range(N)]

ans = 0
for ss in sss:
    ans += ss.count('AB')

num_A = numB_ = numBA = 0
for ss in sss:
    is_A = ss.endswith('A')
    isB_ = ss.startswith('B')
    if is_A:
        if isB_:
            numBA += 1
        else:
            num_A += 1
    else:
        if isB_:
            numB_ += 1

if numBA > 0:
    ans += numBA - 1
    if num_A > 0:
        ans += 1
        num_A -= 1
    if numB_ > 0:
        ans += 1
        numB_ -= 1

ans += min(num_A, numB_)

print(ans)


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

int main(){
    vector<int> v(3,0);
    cin >> v[0] >> v[1] >> v[2];
    sort(v.begin(), v.end());
    if(v.at(2)==v.at(1) + v.at(0)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    let mut h: Vec<isize> = (0..n).map(|_| read()).collect();

    h.sort();
    let mut ans = 10000000000;
    for i in 0..n - k + 1 {
        ans = min(ans, h[i + k - 1] - h[i]);
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
# input here
_INPUT = """\
2 5
1 WA
1 AC
2 WA
2 AC
2 WA
2 AC
"""

def main():
    n, m= map(int, input().split())
    ps = [list(map(str,input().split())) for _ in range(m)]

    str_l = ["WA"]*n
    int_l = [0]*n
    num = 0
    ac = 0

    for pp, s in ps:
        p = int(pp)-1
        if s == "AC":
            str_l[p] = "AC"
        else:
            if str_l[p] != "AC":
                int_l[p] += 1

    for i in range(n):
        if str_l[i] == "AC":
            num += int_l[i]
            ac += 1

    print(ac,num)
    # n, m = map(int, input().split())

    # seikai = [False] * n
    # matigai = [0] * n

    # for i in range(m):
    #     p,q = map(str, input().split())
    #     p = int(p)-1

    #     if q == "AC":
    #         seikai[p] = True
    #     else:
    #         if seikai[p] != True:
    #             matigai[p] += 1


    # correct = seikai.count(True)
    # mistake = sum(matigai)
    # print(correct, mistake)
            
if __name__ == '__main__':
    import io
    import sys
    import math
    import itertools
    from collections import deque

    # sys.stdin = io.StringIO(_INPUT)
    main()

Measured memory_bytes: 98212
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        map<int, bool> m;
        for(int i = 1; i < n; i++){
            m[(i * i) % n] = true;
        }
        vector<int> v;
        for(pair<int, bool> p : m){
            v.push_back(p.first);
        }
        int cnt[11000] = {};
        for(int i = 0; i < v.size(); i++){
            for(int j = 0; j < v.size(); j++){
                if(i == j){
                    continue;
                }
                int num = v[i] - v[j];
                if(num < 0){
                    num += n;
                }
                if(num > (n - 1) / 2){
                    num = n - num;
                }
                cnt[num] += 1;
            }
        }
        for(int i = 1; i <= (n - 1) / 2; i++){
            cout << cnt[i] << endl;
        }
    }
    return 0;
}


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

int main(){

    string s,t;
    cin>>s>>t;
    
    int ans=0;
    
    for(int l=1;l<=min(s.size(),t.size());l++){
        map<array<int,26>,bool> mp;
        array<int,26> a,b;
        rep(i,26)a[i]=b[i]=0;
        
        
        rep(i,l)a[s[i]-'a']++;
        mp[a]=true;
        
        rep(i,s.size()-l){
            a[s[i]-'a']--;
            a[s[i+l]-'a']++;
            mp[a]=true;
        }
        
        
        rep(i,l)b[t[i]-'a']++;
        if(mp.count(b))ans = max(ans,l);
        
        rep(i,t.size()-l){
            b[t[i]-'a']--;
            b[t[i+l]-'a']++;
            if(mp.count(b))ans = max(ans,l);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3688
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

#include <bits/stdc++.h>
using namespace std;

class CXYZTriplets {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
int n;
cin>>n;
int s=sqrt(n);
vector<int> c(n);

            for (int i = 1; i <= s; i++) {
                for (int j = 1; j <= s; j++) {
                    for (int k = 1; k <=s; k++) {
                        int tmp=i*i+j*j+k*k+i*j+j*k+k*i;
                        if (tmp<=n) c[tmp-1]++;
                        else if (tmp>n) break;
                    }
                }
            }
        for (auto& l : c) {
            cout << l << endl;
        }
        cout << "\n";
	}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    CXYZTriplets solver;
    solver.solve(in, out);
}


Measured memory_bytes: 3648
#include <stdio.h>
 
int main(){
 
  int a, b, c;
 
  scanf("%d %d",&a,&b);
 
  /* ?????¶??° a > b ????¢?????????\??? */
  if(a < b){
    a += b;
    b = a - b;
    a -= b;
  }
 
  /* ?????????????????????????????? */
  while(b != 0){
    c = a % b;
    a = b;
    b = c;
  }
 
  /* ?????§??¬?´???°????????? */
  printf("%d\n",a);
 
  return 0;
}

Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
long long N, A;
int x[50];
map<pair<int,int>, long long> memo;
long long f(int p, int s) {
	if (p == N) return s == 0 ? 1 : 0;
	if (memo.count({p, s})) return memo[{p, s}];
	return memo[{p, s}] = f(p+1, s) + f(p+1, s + x[p]-A);
}
int main() {
	cin >> N >> A;
	for (int i = 0; i < N; ++ i) cin >> x[i];
	cout << f(0, 0) - 1 << endl;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin >>a>>b>>c;
int output=0;
int flag = 0;
if(a==b&&b==c&&b%2==0){
output = -1;
flag =1;
}
if(a==b&&b==c&&b%2!=0){
output = 0;
flag =1;
}
while(a%2==0&&b%2==0&&c%2==0&&flag==0){
int aa,bb,cc;
aa = a/2;
bb = b/2;
cc = c/2;
a=bb+cc;
b=aa+cc;
c=aa+bb;
output++;
}

cout << output <<endl; 
}

Measured memory_bytes: 3572
#include <iostream>
using namespace std;
int main() {
  string data;
  int index,n;
  while (cin>>data,data!="-"){
    cin >> n;
    for (int i=0;i<n;i++){
      cin >> index;
      data=data.substr(index)+data.substr(0,index);
    }
    cout<<data<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef long double lld;

const ll MOD = 1000000007;

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

	int n; cin >> n;
	
	vector<lld> p(n, 0);
	for(int i = 0; i < n; i++) cin >> p[i];

	vector<lld> x(n + 1, 0), y(n + 1, 0);
	
	x[0] = 1 - p[0]; x[1] = p[0];
	for(int i = 1; i < n; i++) {
		for(int j = 0; j <= n; j++) {
			y[j] = x[j] * (1 - p[i]);
			if(j > 0) {
				y[j] += x[j - 1] * p[i];
			}
		}

		for(int j = 0; j <= n; j++) {
			x[j] = y[j];
		}
	}


	lld ans = 0;
	for(int i = n; i > n - i; i--) {
		ans = ans + x[i];
	}

	cout.precision(10);
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
int ans ;
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
const int nmax = 1e5+4;
void solve(){
    int n ;
    cin >> n ;
    vector < ll > a(n);
    for( int i = 0 ; i < n ; i++) cin >> a[i] ;
    vector < ll > hash(2*nmax,0),dp(n,0);
    hash[a[0]]++;
    dp[0] = 1 ;
    for( int i = 1 ; i < n ; i++){
                if(a[i]==a[i-1]){
                    dp[i]=dp[i-1];
                    continue;
                }
                dp[i] = add(dp[i-1],hash[a[i]]);
                hash[a[i]]=dp[i];
    }
    cout << dp[n-1] ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


Measured memory_bytes: 4992
import math

def main():
    a, b, h, m = map(int, input().split())

    hourAngle = math.pi * (h * 30 + m * 0.5) / 180
    minuteAngle = math.pi * (m * 6) / 180

    hourX = a * math.sin(hourAngle)
    hourY = a * math.cos(hourAngle)

    minuteX = b * math.sin(minuteAngle)
    minuteY = b * math.cos(minuteAngle)

    res = ((hourX - minuteX)**2 + (hourY - minuteY)**2)**0.5

    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9528
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

// Overkill

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

    int n;
    cin >> n;

    const int M = 10000;
    int dp[M + 1] = { 1 };

    for (int i = 0; i < n; i++) {
        int s;
        cin >> s;
        for (int j = M - s; j >= 0; j--) {
            if (dp[j]) dp[j + s] = 1;
        }
    }
    for (int j = M; j >= 0; j--) {
        if (dp[j] && j % 10 != 0) {
            cout << j << endl;
            quick_exit(0);
        }
    }
    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<int,int> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x7fffffffffffffff;

Finline uint rnd()
{
	static uint seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
	read(t);read(args...);
}
Finline int read_str(char *s)
{
	char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=605;
int n;
bool a[N][N];
void solve(int d)
{
	int qwq=0;
	while(!(d&3)) d>>=2,++qwq;
	if(d&1)
	{
		for(int i=0;i<n;++i)
		{
			for(int j=0;j<n;++j)
			{
				if(((i>>qwq)+(j>>qwq))&1)
				{
					a[i][j]=0;
				}
			}
		}
	}
	else
	{
		for(int i=0;i<n;++i)
		{
			for(int j=0;j<n;++j)
			{
				if((i>>qwq)&1)
				{
					a[i][j]=0;
				}
			}
		}
	}
}
int main()
{
	memset(a,1,sizeof(a));
	int d1,d2;
	read(n,d1,d2);
	int cnt=n*n;
	n<<=1;
	solve(d1);
	solve(d2);
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			if(a[i][j])
			{
				printf("%d %d\n",i,j);
				if(!--cnt) return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 1280
n = int(input())
jun = [int(s) for s in input().split()]
r = [int(s) for s in input().split()]
m = [int(s) for s in input().split()]

point = 0
for i in range(n):
    point += r[jun[i]-1]
    if jun[i]-1 == jun[i-1] and i > 0:
        point += m[jun[i-1]-1]
print(point)

Measured memory_bytes: 61284
n,k= map(int,input().split())
ans=0
if k==0:print(n*n)
else:
    g=0
    for b in range(k+1,n+1):
        t = n//b
        g += t*(b-k)
        if t*b+k <= n < (t+1)*b:g += n-(t*b+k)+1
    print(g)

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

using namespace std;

bool f = 0;
int N;
vector<int> ways,v(100001);
vector<vector<int>> to(100001);

void dfs(int now,vector<int> &t){
	if(f)return;
	if(now == N-1){
		ways = t;
		f = 1;
		return;
	}
	for(auto next:to[now]){
		if(v[next]==0){
			v[next] = 1;
			t.push_back(next);
			dfs(next,t);
			t.pop_back();
			v[next] = 0;
		}
	}
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i,N-1){
		int x,y;
		cin >> x >> y;
		x--;y--;
		to[x].push_back(y);
		to[y].push_back(x);
	}
	vector<int> t(1,0);
	v[0] = 1;
	dfs(0,t);
	v[0] = 0;
	// waysには0からN-1までの最短経路が入っている
	queue<int> a,b;
	for(int i=0;i<ways.size();i++){
		if(i < (ways.size()+1)/2){
			a.push(ways[i]);
		}
		else {
			b.push(ways[i]);
		}
		v[ways[i]]=1;
	}
	bool astart = 0,bstart = 0;
	if(ways.size()%2==0)astart = 1;
	else bstart = 1;
	while(1){
		//aのターン 0になったら塗れたことにする
		bool aturn = 1,bturn = 1;
		//現時点から行ける場所にとりあえず行く
		if(astart){
			while(aturn && !a.empty()){
				int now = a.front();
				for(auto next:to[now]){
					if(v[next]==0){
						v[next]=1;
						a.push(next);
						aturn = 0;
						break;
					}
				}
				if(aturn)a.pop();
			}
			if(aturn){
				cout << "Snuke" << endl;
				return 0;
			}
			bstart = 1;
		}else {
			astart = 1;
			bstart = 1;
		}
		//bのターン
		//現時点から行ける場所にとりあえず行く
		if(bstart){
			while(bturn && !b.empty()){
				int now = b.front();
				for(auto next:to[now]){
					if(v[next]==0){
						v[next]=2;
						b.push(next);
						bturn = 0;
						break;
					}
				}
				if(bturn)b.pop();
			}
			if(bturn){
				cout << "Fennec" << endl;
				return 0;
			}
			astart = 1;
		}else{
			bstart = 1;
		}
	}
}

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

int main() {
	string s;
	cin >> s;
	string ans;
	rep(i, (int)s.size()) {
		if (s[i] == 'B') {
			if(!ans.empty()) ans.pop_back();
		}
		else ans += s[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3600