akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

signed main() {
  int N,K;
  string S;
  cin >> N >> S >> K;
  char sk = S[K-1];
  for(auto c : S) {
    if(sk == c) cout << c;
    else cout << "*";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
n, d = gets.split.map(&:to_i)
coordinates = n.times.map { gets.split.map(&:to_i) }

answer = coordinates.combination(2).count do |(y, z)|
  distance = Math.sqrt((0..(d - 1)).reduce(0) { |s, i| s += (y[i] - z[i]) ** 2 } )
  distance - distance.to_i == 0
end
puts answer

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const int mod = 1e9+7;

int main(){
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  rep(i,d) cin >> p[i] >> c[i];
  int ans = 1001001001;
  for(int i = 0; i < (1<<d); i++){
    bitset<10> b(i);
    int sum = 0;
    int tem = 0;
    rep(j,d){
      if(b.test(j)){
        sum += (j+1)*100*p[j] + c[j];
        tem += p[j];
      }
    }
    if(sum < g){
      for(int j = d-1; j >= 0; j--){
        if(!b.test(j)){
          REP(k,p[j]){
            if(sum >= g) break;
            sum += (j+1)*100;
            tem++;
          }
          break;
        }
      }
    }
    if(sum < g) continue;
    ans = min(ans, tem);
  }
  cout << ans << endl;
}




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

int main() {
  int A, B;
  cin >> A >> B;
  
  int ans = 0;
  if ( A > 9 || B > 9) {
    ans = -1;
  }
  else {
    ans = A * B;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 500000

void maxHeapify(int *,int);
int H;

int main(){
  int i,a[MAX+1];
  scanf("%d",&H);

  for ( i = 1; i <= H; i++ ){
    scanf("%d", &a[i]);
  }
  for ( i = H/2; i>=1; i-- ){
    maxHeapify(a,i);
  }
  for ( i = 1; i <= H; i++ ) {
    printf(" %d", a[i]);
  }
  printf("\n");
  
  return 0;
}


void maxHeapify(int a[],int i){
  int l, r, largest, x;
  l = 2*i;
  r = 2*i+1;
  if ( l <= H && a[l] > a[i] ){
    largest = l;
  }
  else {
    largest = i;
  }
  if ( r <= H && a[r] > a[largest] ) {
    largest = r;
  }
  if ( largest != i ){
    x = a[i];
    a[i] = a[largest];
    a[largest] = x;
    maxHeapify(a,largest);
  }
}



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

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

	vector<vector<pair<int, int>>> d(n+1);
	for (int i = 0; i < m; ++i) {
		int p, y;
		cin >> p >> y;
		d[p].push_back(pair<int,int>(y,i));
	}

	vector<string> ret(m);
	for (int i = 1; i <= n; ++i) {
		sort(d[i].begin(), d[i].end());
		for (int j = 0; j < d[i].size(); ++j) {
			char c1[7];
			sprintf(c1, "%06d", i);
			char c2[7];
			sprintf(c2, "%06d", j + 1);
			ret[d[i][j].second] = string(c1) + string(c2);
		}
	}

	for (auto& i : ret) {
		cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 12416
N, M, x, y = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
Xm = max(X + [x])
Ym = min(Y + [y])
# print(X < Y, Xm < Ym)
print('No War' if Xm < Ym else 'War')


Measured memory_bytes: 38384
n = int(input())
a = [int(i) for i in input().split()]
dic = {}

for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

a, b = 0, 0

for k,v in sorted(dic.items(), key=lambda x : -x[0]):
    if a==0:
        if 4 <= v:
            a, b = k, k
            break
        elif 2 <= v:
            a = k
    elif 2 <= v:
        b = k
        break

if not a==0 or not b==0:
    print(a*b)
else:
    print(0)


Measured memory_bytes: 24328
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int n,m;
string s;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		cin>>m>>s;
		int ans=0,num=(s[0]=='I')?1:0;
		for(int i=1;i<m;i++){
			if(s[i]==s[i-1]){
				if(s[i]=='O') num--;
				int res=num/2-n+1;
				if(res<0) res=0;
				ans+=res;
				num=(s[i]=='I')?0:-1;
			}
			num++;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3888
#include <stdio.h>

int max(int data[],int n){
  int i,mm=0;
  for(i=0;i<n;i++){
    if(data[mm]<data[i]) mm=i;
  }
  return mm;
}

main(){
 int a[10],b[10],j,k,x,y,amax[3],bmax[3],aa=0,bb=0;
 
 for(j=0;j<10;j++){
    scanf("%d",&a[j]);
  }
 for(k=0;k<10;k++){
    scanf("%d",&b[k]);
  }

 for(x=0;x<3;x++){
    aa=max(a,10);
    amax[x]=a[aa];
    a[aa]=0;
  }
 for(y=0;y<3;y++){
    bb=max(b,10);
    bmax[y]=b[bb];
    b[bb]=0;
  }

 printf("%d %d\n",amax[0]+amax[1]+amax[2],bmax[0]+bmax[1]+bmax[2]);

return 0; 
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
#define MAX 200010
int main(){
  int N,r[MAX],min[MAX],max[MAX];
  cin >> N;
  for(int i = 0; i < N ;i++){
    cin >>r[i];
  }
  min[0] = r[0];
  for(int i = 1; i < N; i++){
    if( r[i] < min[i-1] ) min[i] = r[i];
    else min[i] = min[i-1];
  }
  max[N-1] = r[N-1];
  for(int i = N-2; i >= 0; i--){
    if( r[i] > max[i+1] ) max[i] = r[i];
    else max[i] = max[i+1];
  }
  int ans = max[1]-min[0];
  for(int i = 0; i < N-1; i++){
    if(ans < (max[i+1]-min[i]) ) ans = max[i+1]-min[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3504
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

def main():
    n,m = map(int,input().split())
    s = [0] * m
    c = [0] * m
    for i in range(m):
        s[i],c[i] = map(int,input().split())
    num = [0] * n
    res = []
    if n==1 and m==0:
        print(0)
        return
    if n==1:
        cnt0 = 0
        cnt1 = 0
        for i in range(m):
            if c[i]:
                cnt1 += 1
            else:
                cnt0 += 1
        if cnt0 and cnt1:
            print(-1)
            return
        elif cnt0:
            print(0)
            return
    for i in range(m):
        if s[i]==1 and not c[i]:
            print(-1)
            return
        if not num[s[i]-1]:
            num[s[i]-1] = c[i]
        elif num[s[i]-1] == c[i]:
            continue
        else:
            print(-1)
            return
    if not num[0]:
        num[0] = 1
    ans = [str(x) for x in num]
    print(''.join(ans))
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	var k = Number(tmp[0])
	var x = Number(tmp[1]);

    for(var i=x-k+1; i<=x+k-1; i++)
    {
        process.stdout.write(i + ' ')
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8324
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long int ll;

int main() {
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  ll k=0;
  if(n==m) k=2;
  if(abs(n-m)==1) k=1;
  ll ans = 1;
  ll mod_num = 1000000007;
  while(n!=1){
    ans *= n;
    ans = ans % mod_num;
    --n;
  }
  while(m!=1){
    ans *= m;
    ans = ans % mod_num;
    --m;
  }
  ans = ans*k % mod_num;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define min(a, b) ((a) < (b) ? (a) : (b))
#define MAX_N 20

const int INF = 1000000000;

int cost[MAX_N][MAX_N];
int d[MAX_N];
bool used[MAX_N];
int n;

int
dijkstra(int s, int e)
{
	for (int i = 0; i < n; ++i)
	{
		d[i] = INF;
		used[i] = false;
	}

	d[s] = 0;
	while (true)
	{
		int v = -1;
		for (int u = 0; u < n; ++u)
		{
			if (!used[u] && (v == -1 || d[u] < d[v]))
				v = u;
		}

		if (v == -1)
			break;

		used[v] = true;
		for (int u = 0; u < n; ++u)
			d[u] = min(d[u], d[v] + cost[v][u]); 
	}

	return d[e];
}

int
main(int argc, char **argv)
{
	scanf("%d\n", &n);
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
			cost[i][j] = INF;
	}

	int m;
	int a, b, c, d;
	scanf("%d\n", &m);
	for (int i = 0; i < m; ++i)
	{
		scanf("%d,%d,%d,%d\n", &a, &b, &c, &d);
		cost[a - 1][b - 1] = c;
		cost[b - 1][a - 1] = d;
	}

	int s, g, V, P;
	scanf("%d,%d,%d,%d\n", &s, &g, &V, &P);
	s--, g--;
	printf("%d\n", V - P - dijkstra(s, g) - dijkstra(g, s));
	return 0;
}

Measured memory_bytes: 1808
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int A[100000];
int B[100000];
int C[100000];

ll AonB[100000];

int main()
{
	int N;
	ll ans = 0;

	cin >> N;
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	rep(i, N) cin >> C[i];

	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);

	rep(i, N) {
		int num;
		int* p = lower_bound(A, A + N, B[i]);
		if (p == A) num = 0;
		else {
			p--;
			num = p - A + 1;
		}
		AonB[i] = num;
	}

	rep(i, N - 1) AonB[i + 1] += AonB[i];

	rep(i, N) {
		int index;
		int* p = lower_bound(B, B + N, C[i]);
		if (p == B) continue;
		else {
			p--;
			index = p - B;
			ans += AonB[index];
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define setNil(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
#define setNegINF(x) memset((x),192,sizeof(x)) //NegINF=-INF-1
#define setNeg1(x) memset((x),255,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,pre,cnt,res;
vector<int> c;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(x==pre)cnt++;
		else{
			c.push_back(cnt);
			pre=x;
			cnt=1;
		}
	}
	c.push_back(cnt);
	for(int i=0;i<c.size();i++)res+=c[i]>>1;
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
N, Y = map(int,input().split())
for i in range(N+1):
    for j in range(N+1-i):
        k = N-i-j
        if i*10 + j*5 + k ==  Y // 1000:
            print(i,j,k)
            exit()
print('-1 -1 -1')


Measured memory_bytes: 2940
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   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) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

const int N = 22, MOD = (int)1e9 + 7;

int dp[N][1 << N];
int ar[N][N];
int n;

inline int add (int a, int b) { return ((a%MOD) + (b%MOD)) % MOD; };

void solve() {
   for (int i = 1; i <= n; ++i) {
      for (int j = 0; j < (1 << n); ++j) {
         dp[i][j] = 0;
      }
   }

   for (int k = 0; k < n; ++k) {
      if (ar[1][k+1]) dp[1][1 << k] = 1;
   }

   for (int i = 2; i <= n; ++i) {
      for (int j = 0; j < (1 << n); ++j) {
         if (__builtin_popcount(j) != i) continue;
         for (int k = 0; k < n; ++k) {
            if (ar[i][k+1] && (j & (1 << k))) dp[i][j] = add(dp[i][j], dp[i-1][j - (1 << k)]);
         }
      }
   }
   int total = dp[n][(1 << n)-1];
   cout << total << '\n';
}

signed main() {
   IOS; PREC;
   cin >> n;
   for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j)
         cin >> ar[i][j];
   solve();

   return EXIT_SUCCESS;
}




Measured memory_bytes: 215296
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

ll gcd(ll a,ll b) {
    if(a < b) swap(a,b);
    if(b == 0) return a;
    return gcd(b,a%b);
}
template<class T> struct factorizaion {
    using NP = pair<T,int>;
    T n;
    explicit factorizaion(T n):n(n) {
        assert(n > 0);
    }
    vector<NP> factorlist() {
        if(n == 1) return {};
        T nn = n;
        vector<NP> ret;
        T i = 2;
        while (i*i <= n) {
            if(nn%i == 0) {
                nn /= i;
                if(!ret.empty() && ret[ret.size()-1].first == i) ret[ret.size()-1].second++;
                else ret.emplace_back(i,1);
            } else i++;
        }
        if(nn != 1) ret.emplace_back(nn,1);
        return ret;
    }
    bool isprime() {
        auto v = factorlist();
        return v.size() == 1 && v[0].second == 1;
    }
    int divisor() {
        int ret = 1;
        vector<NP> fl = factorlist(n);
        for(auto p : fl) {
            ret *= p.second+1;
        }
        return ret;
    };
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a,b;
    cin >> a >> b;
    ll g = gcd(a,b);
    factorizaion<ll> f(g);
    auto v = f.factorlist();
    cout << v.size()+1 << endl;
}


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

int main()
{
    int k,a,b,f=0;
   cin>>k;
   cin>>a>>b;
   for(int i=a;i<=b;i++){
    if(i%k==0){
        f=1;
     }
   }

   if(f==1){
    cout<<"OK\n";
   }
   else if(f==0){
    cout<<"NG\n";
   }

}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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

constexpr int MOD = 1000000007;
constexpr ll inf = 1LL << 60;

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

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int 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;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int bitCount(int u){
for(int i=0;i<=30;i++){
if(u & 1<<i)return 1;

}
return 0;

}

bool is_nCk_odd(int n, int k){
    return (n&k)==k;
}



int main(){
int n;
cin>>n;
int a[n+1];
string s;
cin>>s;
rep(i,n){
	a[i]=s[i-1]-'0';
	a[i]--;
}

if(n==2){
	cout<<abs(a[1]-a[2])<<endl;
	return 0;
}


int sum=0;
for(int i=0;i<=n-1;i++){
if(is_nCk_odd(n-1,i)){
	sum+=a[i+1];
}
}

sum=sum%2;
if(sum)cout<<1<<endl;
else{ 
for(int i=0;i<n;i++){
if(s[i]=='2'){
	cout<<0<<endl;
	return 0;}
}
rep(i,n){
	a[i]/=2;
}
int sum=0;
for(int i=0;i<=n-1;i++){
if(is_nCk_odd(n-1,i)){
	sum+=a[i+1];
}
}
sum=sum%2;
if(sum)cout<<2<<endl;
else cout<<0<<endl;

}




return 0;

}



Measured memory_bytes: 5252
#include <array>
#include <iostream>
#include <map>
#include <vector>

template <typename Map, typename Value = typename Map::mapped_type>
Value &
MapIncrementCount(Map &map, typename Map::key_type key, Value value)
{
    auto [it, flag] = map.try_emplace(key, 0);
    (void)flag;
    auto &v = it->second;
    v += value;
    return v;
}

int
main()
{
    std::ios::sync_with_stdio(false);
    std::size_t n;
    std::cin >> n;

    long long sum = 0;
    std::map<int, int> valueCounts;
    for (std::size_t i = 0; i<n; ++i)
    {
        int input;
        std::cin >> input;
        MapIncrementCount(valueCounts, input, 1);
        sum += input;
    }

    std::size_t operationCount;
    std::cin >> operationCount;
    std::vector<std::pair<int, int>> operations;
    operations.reserve(operationCount);
    for (std::size_t i = 0; i<operationCount; ++i)
    {
        int b, c;
        std::cin >> b >> c;
        operations.emplace_back(b, c);
    }

    for (std::size_t i = 0; i<operationCount; ++i)
    {
        auto &[b, c] = operations[i];

        auto findB = valueCounts.find(b);
        if (findB==valueCounts.end())
        {
            std::cout << sum << "\n";
            continue;
        }

        sum -= static_cast<long long>(b)*findB->second;
        sum += static_cast<long long>(c)*findB->second;

        MapIncrementCount(valueCounts, c, findB->second);
        valueCounts.erase(b);
        std::cout << sum << "\n";
    }
}


Measured memory_bytes: 6956
def bubble_sort(c, n):
    for i in range(n):
        for j in reversed(range(i+1, n)):
            if c[j][1] < c[j-1][1]:
                c[j], c[j-1] = c[j-1], c[j]
    print(' '.join(map(str, c)))


def selection_sort(c, n):
    for i in range(n):
        m = i
        for j in range(i, n):
            if c[j][1] < c[m][1]:
                m = j
        c[i], c[m] = c[m], c[i]
    print(' '.join(map(str, c)))


n = int(input())
c = list(input().split())
b = list(c)
bubble_sort(c, n)
print('Stable')
selection_sort(b, n)
if c == b:
    print('Stable')
else:
    print('Not stable')



Measured memory_bytes: 5608
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= (_T)base;
	}
	return ans;
}

static void D();

int main()
{
	D();
	fflush(stdout);
	return 0;
}

static void D()
{
	int N;
	get(N);
	std::vector<int> ai(N), bi(N);
	for (int i = 0; i < N; i++) {
		get(ai[i]);
	}
	if (N == 1) {
		printf("%d\n", ai[0]);
		return;
	}
	int end1 = (N + 1) / 2;
	int first = N - 1, first2 = N % 2;

	for (int i = 0; i < end1; i++) {
		bi[i] = ai[first - (i * 2)];
	}
	for (int i = end1; i < N; i++) {
		bi[i] = ai[first2 + (i - end1) * 2];
	}
	std::string ans;
	for (int i = 0; i < N; i++) {
		if (ans.length()) ans += ' ';
		char tmp[16] = { 0 };
		sprintf(tmp, "%d", bi[i]);
		ans += tmp;
	}
	printf("%s\n", ans.c_str());
}


Measured memory_bytes: 8764
//#include <bits/stdc++.h>
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n), h(n);
  rep(i, n) cin >> x[i] >> y[i] >> h[i];

  rep(cx, 101) {
    rep(cy, 101) {
      set<int> H;
      rep(i, n) {
        if (h[i] != 0) {
          int tmp = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
          H.insert(tmp);
        }
      }
      // cout << H.size() << endl;
      if (H.size() == 1) {
        bool flag = true;
        rep(i, n) if (h[i] != max(*H.begin() - abs(x[i] - cx) - abs(y[i] - cy), 0LL)) flag = false;
        if (flag) {
          cout << cx << ' ' << cy << ' ' << *H.begin() << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}


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

int main(){
	int n, b;
	long min = 0;
	cin >> n;
	vector<int> B(n);
	for(int i=0; i<n; i++){
		cin >> B[i];
		B[i] -= (i+1);
	}
	sort(B.begin(), B.end());
	if(n%2){
		b = B[n/2];
	} else {
		b = (B[n/2 - 1] + B[n/2]) / 2;
	}
	for(int i=0; i<n; i++){
		min += abs(B[i] - b);
	}
	cout << min;
}



Measured memory_bytes: 1024
/******************************************
* AUTHOR : Lokesh goel*
* NICK : InsaneNerd *
* INSTITUTION : NIT Kurukshetra *
******************************************/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 1000000000
#define N 100005
#define pii pair<int,int>
#define vp vector<pair<int,int > >
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define gsz(x) ((int)(x).size())
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);
#define endl "\n"
#define ms(x,v) memset(x,v,sizeof(x))

int main()
{
	fastio;
	int n;
	cin>>n;
	while(n>0)
	{
		if(n%10==7)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
		n/=10;
	}
	cout<<"No"<<endl;


	return 0;
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main(void)
{
    long long N, T[102], M, P[102], X[102], i, sum=0;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> T[i];

        sum += T[i];
    }

    cin >> M;

    for(i=1; i<=M; i++){
        cin >> P[i] >> X[i];

        cout << sum - T[P[i]] + X[i] << endl;
    }

    return 0;
}

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

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

	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			for (int k = j + 1; k < n; k++)
			{
				if (a[i] != a[j] && a[j] != a[k] && a[k] != a[i])
				{
					if (a[i] + a[j] > a[k] && a[k] + a[i] > a[j] && a[j] + a[k] > a[i])
					{
						ans++;
					}
				}
			}
		}
	}

	cout << ans << endl;	
	return 0;
}

Measured memory_bytes: 3624
(let ((a (read))
    (b (read))
    )
    (if (= a 1)
        (if (= b 2)
        (princ "3")
        (princ "2"))
    )
    (if (= a 2)
        (if (= b 1)
        (princ "3")
        (princ "1"))
    )
        (if (= a 3)
        (if (= b 1)
        (princ "2")
        (princ "1"))
    )
)

Measured memory_bytes: 24116
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int imoss[60*60*24+100]={0};
        for(int i=0;i<n;i++){
            int t,m,s;
            scanf("%d:%d:%d",&t,&m,&s);
            imoss[t*3600+m*60+s]++;
            scanf("%d:%d:%d",&t,&m,&s);
            imoss[t*3600+m*60+s]--;
        }
        for(int i=1;i<=24*60*60;i++)imoss[i]+=imoss[i-1];
        int ma=0;
        for(int i=0;i<=24*60*60;i++)ma=max(ma,imoss[i]);
        printf("%d\n",ma);
    }
    return 0;
}

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

R = min(N,K)
point = 0
max_point = 0
hand = []

for i in range(R+1):
    for a in range(i+1):
        if i==a:
            hand = V[:a]
        else:
            hand = V[:a]+V[-(i-a):]
        negahand = [k for k in hand if k < 0]
        negahand.sort()
        if K-i > len(negahand):
            trash = -sum(negahand)
        else:
            trash = -sum(negahand[:K-i])
        point = sum(hand) + trash
        max_point = max(max_point,point)

print(max_point)

Measured memory_bytes: 9168
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <limits>
#include <numeric>

using namespace std;

int main(){
    int N;
    long long int A[100001];

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

    sort(A, A+N);

    long long int k=0, cnt=1;
    long long int tmp = A[0];
    for(int i = 1; i < N; i++){
        if(tmp == A[i]){
            cnt++;
        }else{
            if(cnt % 2 == 1) k++;
            cnt = 1;
            tmp = A[i];
        }
        if(i == N-1) k += cnt % 2;
    }

    cout << k << endl;

    return 0;
}


Measured memory_bytes: 1024
l = (0..9).map{|i| i}
while gets
  n,s = $_.split.map(&:to_i)
  an = 0
  break if n == 0
  if s <= ([0,(10-n)].max..9).inject(:+)
    l.combination(n){|c|
      an += 1 if s == c.inject(:+)
    }
  end
  puts an
end

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

#define MAX 100
#define INFTY 1 << 21
#define WHITE 0
#define GRAY 1
#define BLACK 2

// 隣接行列
int gMatrix[MAX][MAX];

int prim(int n){
    // 頂点
    int u;
    // 最小の重み
    int minV;
    // Tに属する頂点とV - Tに属する頂点をつなぐ辺の中で、重みが最小の辺の重みを記録する
    int weight[MAX];
    // MSTにおける頂点vの親を記録する
    int parent[MAX];
    // 訪問状態を記録する
    int color[MAX];
    
    for(int i = 0;i < n;++i){
        weight[i] = INFTY;
        parent[i] = -1;
        color[i] = WHITE;
    }
    
    weight[0] = 0;
    
    while(1){
        minV = INFTY;
        u = -1;
        
        for(int i = 0;i < n;++i){
            if(minV > weight[i] && color[i] != BLACK){
                // 最小の重みを記録する
                u = i;
                minV = weight[i];
            }
        }
        // 全て訪問した
        if(u == -1)break;
        // 訪問済み
        color[u] = BLACK;
        for(int v = 0;v < n;++v){
            if(color[v] != BLACK && gMatrix[u][v] != INFTY){
                if(weight[v] > gMatrix[u][v]){
                    weight[v] = gMatrix[u][v];
                    parent[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    for(int i = 0;i < n;++i){
        if(parent[i] != -1) sum += gMatrix[i][parent[i]];
    }
    
    return sum;
}

int main(){
    int n;
    cin >> n;
    
    for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
            int edge;
            cin >> edge;
            gMatrix[i][j] = (edge == -1) ? INFTY : edge;
        }
    }
    
    cout << prim(n) << endl;
    return 0;
}



Measured memory_bytes: 3064
fun main(args : Array<String>) {
    val (A, B) = readLine()!!.split(" ").map { it.toInt() }

    if(A >= 13) {
        println(B)
    } else if (6<= A && A<= 12) {
        println(B/2)
    } else{
        println(0)
    }
}

Measured memory_bytes: 36216
#include <bits/stdc++.h>
using namespace std;
pair<int, int> job;
vector<pair<int,int> > jobs;

bool pairCompare(pair<int,int> firstElof, pair<int,int> secondElof){
  return firstElof.second < secondElof.second;
}


unsigned long long int gdb(unsigned long long int a,unsigned long long int b){
  unsigned long long int x = a * b;

if(a<b){
  unsigned long long int tmp = a;
  a = b;
  b = tmp;
}

unsigned long long int r = a % b;
while(r!=0){
  a = b;
  b = r;
  r = a % b;
}
return x/b;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());
  unsigned long long int n;
  string str;
  cin >> n;
  jobs.resize(n);
  for(int i=0;i<n;i++){
    int a,b;
    cin >> jobs[i].first >> jobs[i].second;
  }
  sort(jobs.begin(),jobs.end(),pairCompare);
  int sumtime = 0;
  bool flag = false;
  for(int i=0;i<n;i++){
    sumtime += jobs[i].first;
    if(sumtime > jobs[i].second) flag = true;
  }
  if(flag) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

template <typename T=double>
pair<T,T> ternary(T l, T r, function<T(T)> f, bool V=true) {
    int round = 400;
    while (round--) {
        T m0 = l + (r-l)/3;
        T m1 = r - (r-l)/3;
        T f0 = f(m0);
        T f1 = f(m1);

        if ((f0 < f1) ^ V) {
            l = m0;
        } else {
            r = m1;
        }
    }
    return {l, f(l)};
}

void solve() {
    int n; cin >> n;
    vector<double> x(n), y(n);
    vector<int> sx(n, 0), sy(n, 0);
    for (int i = 0; i < n; i++) {
        char d;
        cin >> x[i] >> y[i] >> d;
        if (d == 'L') sx[i] = -1;
        if (d == 'R') sx[i] = +1;
        if (d == 'D') sy[i] = -1;
        if (d == 'U') sy[i] = +1;
    }

    double _, res;
    tie(_, res) = ternary<double>(0.0, 1e9, [&](double t){
            double INF = 1e18;
            double mx = INF, my = INF, Mx = -INF, My = -INF;
            for (int i = 0; i < n; i++) {
                double nx = x[i] + t * sx[i];
                double ny = y[i] + t * sy[i];
                mx = min(mx, nx);
                Mx = max(Mx, nx);
                my = min(my, ny);
                My = max(My, ny);
            }
            return (Mx-mx)*(My-my);
            });
    cout << fixed << setprecision(10) << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 2560
#include<cstdio>

using namespace std;

char S[300002];
int N;

int main() {
    scanf("%d", &N);
    scanf("%s", S);
    S[N] = '\0';
    int min = 0;
    for(int i = 1; i < N; ++i) {
        if(S[i] != 'W') {
            ++min;
        }
    }
    int right = min;
    int left = 0;
    for(int i = 1; i < N; ++i) {
        if(S[i] != 'W') {
            --right;
        }
        if(S[i-1] != 'E') {
            ++left;
        }
        if(right + left < min) {
            min = right + left;
        }
    }
    printf("%d\n", min);
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long a[] = new long[n];
		long sum[] = new long[n+1];

		sum[0]=0;
		for(int i=0; i<n; i++) {
			a[i]=sc.nextLong();
			sum[i+1] = sum[i]+a[i];
		}

		long ans = Long.MAX_VALUE;
		for(int i=1; i<n; i++) {
			long x = sum[i];
			long y = sum[n]-sum[i];
			ans = Math.min(Math.abs(x-y), ans);
		}
		System.out.println(ans);
		sc.close();
	}





}


Measured memory_bytes: 62900
#include <cstdio>
#include <string.h>
#include <iostream>
using namespace std;

#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))

struct C {
	long long sum[26];
	long long s;
	C() {
		memset(sum, 0, sizeof sum);
		s = 0;
	}
} F[1100];

C operator * (C x, long long y) {
	for (int i = 0; i < 26; i++)
		x.sum[i] *= y;
	x.s *= y;
	return x;
}

C operator + (C x, C y) {
	for (int i = 0; i < 26; i++)
		x.sum[i] += y.sum[i];
	x.s += y.s;
	return x;
}

C operator - (C x, C y) {
	for (int i = 0; i < 26; i++)
		x.sum[i] -= y.sum[i];
	x.s -= y.s;
	return x;
}

int len;
int n;
char S[210000];
int ne[210000];

C query(int k, long long l, long long r) {
	// printf("?? %d %lld %lld\n", k, l, r);
	if (k <= 1) {
		if (k == 0) {
			l = max(l, 1);
			r = min(r, n - ne[n]);
		}else {
			l = max(l, 1);
			r = min(r, n);
		}
		C ans;
		memset(ans.sum, 0, sizeof ans.sum);
		ans.s = 0;
		for (int i = l; i <= r; i++)
			ans.sum[S[i] - 'a'] += 1, ans.s += 1;
		return ans;
	}
	if (l <= 1 && r >= F[k].s)
		return F[k];
	if (r <= F[k - 1].s)
		return query(k - 1, l, r);
	else if (l > F[k - 1].s)
		return query(k - 2, l - F[k - 1].s, r - F[k - 1].s);
	else
		return query(k - 1, l, r) + query(k - 2, l - F[k - 1].s, r - F[k - 1].s);
}

int main() {
	scanf("%s", S + 1);
	n = strlen(S + 1) / 2;
	int p = 0;
	ne[1] = 0;
	for (int i = 2; i <= n; i++) {
		for (; p && S[p + 1] != S[i]; p = ne[p]);
		if (S[p + 1] == S[i])
			p ++;
		ne[i] = p;
	}

	long long l, r;
	cin >> l >> r;
	// if (ne[n] * 2 >= n) {
	// 	int c = n - ne[n];
	// 	C pp;
	// 	for (int i = 1; i <= c; i++)
	// 		pp.sum[S[i] - 'a'] += 1, pp.s += 1;
	// 	C ans = pp * (r / c);
	// 	for (int i = 1; i <= r % c; i++)
	// 		ans.sum[S[i] - 'a'] += 1;
	// 	l -= 1;
	// 	ans = ans - (pp * (l / c));
	// 	for (int i = 1; i <= l % c; i++)
	// 		ans.sum[S[i] - 'a'] -= 1;
	// 	for (int i = 0; i < 25; i++)
	// 		printf("%lld ", ans.sum[i]);
	// 	printf("%lld\n", ans.sum[25]);
	// }else {
		len = 1;
		for (int i = 1; i <= n - ne[n]; i++)
			F[0].sum[S[i] - 'a'] += 1, F[0].s += 1;
		for (int i = 1; i <= n; i++)
			F[1].sum[S[i] - 'a'] += 1, F[1].s += 1;
		while (F[len].s <= 1000000000000000000LL) {
			F[len + 1] = F[len] + F[len - 1];
			len += 1;
		}
		C ans = query(len, l, r);
		for (int i = 0; i < 25; i++)
			printf("%lld ", ans.sum[i]);
		printf("%lld\n", ans.sum[25]);
	// }
}


Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int N;
    cin >> N;
    vector<int> H(N+2);
    H[0] = 0;
    rep(i, N) cin >> H[i+1];

    int ans = 0;
    FOR(i, 1, N+1){
        bool flag = true;
        FOR(j, 0, i){
            if(H[i] < H[j]){
                flag = false;
            }
        }
        if(flag) ans++;

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200100;
int a[N],n,ans[N];
vector<int>g[N];

void dfs(int x,int lmx,int rmx,int mx,int chmx,int fa=-1){
	if(lmx<rmx)a[chmx]++;else a[mx]++;
	for(int i:g[x])if(i!=fa){
		if(i>mx)dfs(i,mx,0,i,0,x);
		else dfs(i,lmx,max(rmx,i),mx,!chmx?i:chmx,x);
	}
}

void dfs2(int x,int add=0,int fa=-1){
	add+=a[x];ans[x]=add;
	for(int i:g[x])if(i!=fa)dfs2(i,add,x);
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<n;++i){
		int x,y;cin>>x>>y;
		g[x].push_back(y);g[y].push_back(x);
	}
	dfs(1,0,0,1,0);dfs2(1);
	for(int i=2;i<=n;++i)cout<<ans[i]-1<<" \n"[i==n];
	return 0;
}



Measured memory_bytes: 29696
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
// #include <atcoder/all>

using boost::multiprecision::cpp_int;
using namespace std;
// using namespace atcoder;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;
ll n, x, m;

vector<ll> dp;
void f(ll a, ll m){
  set<ll> s;
  for (ll i = 1; i < a; ++i) {
    dp[i] = (dp[i-1] * dp[i-1]) % m;
    if(s.count((dp[i-1] * dp[i-1]) % m) == 1) break;
    s.insert(dp[i]);
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> x >> m;

  dp = vector<ll> (m+10, -1);
  dp[0] = x;

  f(n+1, m);

  ll res = 0;
  vector<ll> mp(m+10);
  // map<ll, ll> mp;
  ll tmp = 0;
  for (ll i = 0; i < 1000000; ++i) {
    mp[dp[i]] = i;
    if(dp[i+2] == -1){
      tmp = i;
      break;
    }
  }

  // rep(i, 100) cout << dp[i] << ' ';
  // cout << endl;
  // print(mp);
  ll syu = 0;
  for (ll i = 0; i < mp[dp[tmp+1]]; ++i) {
    res += dp[i];
    n--;
  }

  // cout << res << endl;
  for (ll i = mp[dp[tmp+1]]; i <= tmp; ++i) {
    syu += dp[i];
  }

  ll len = tmp - mp[dp[tmp+1]] + 1;

  res += (n/len)*syu;
  n %= len;
  for (ll i = mp[dp[tmp+1]]; i < mp[dp[tmp+1]] + n; ++i) {
    res += dp[i];
  }

  cout << res << endl;
}


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

using namespace std;

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

int main()
{
    canhazfast();

    ull s;
    uint q, r;
    constexpr uint m = 1e9;

    cin >> s;
    q = s/m;
    r = s%m;
    if (r) ++q, r = m-r;
    cout << "0 0 " << q << " 1 " << r << " 1000000000\n";

    return 0;
}


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

typedef long long ll;
const ll MOD = 1000000007;

//Fast Exponentiation
ll fexp(ll base, ll exp, ll mod) {
    if (base >= mod) base %= mod;
    ll result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) result = (result * base) % mod;
        exp >>= 1;
        base = (base * base) % mod;
    }
    return result;
}

const int N = 100003;
int dp[N]; // dp[i] = number of coprime sequences of length n, values between 1 and i only

// int ans[N]; // ans[i] = number of sequences of length n, val bw 1 and k, gcd = i

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

    // base case
    dp[1] = 1;

    // iterate
    for (int i = 2; i <= k; i++) {
        int up = 1;
        while (up * up < i) ++up;

        ll sub = 0;

        for (int j = 2; j < up; j++) {
            sub += dp[i / j];
            if (sub >= MOD) sub -= MOD;
        }

        int val = i / up;
        for (int j = 1; j <= val; j++) {
            int lo = i / (j + 1) + 1, hi = i / j;
            int amt = hi - lo + 1;

            ll prod = 1ll * amt * dp[j];
            if (prod >= MOD) prod %= MOD;

            sub += prod;
            if (sub >= MOD) sub -= MOD;
        }

        dp[i] = (fexp(i, n, MOD) + (MOD - sub)) % MOD;
    }

    // print the answer
    int ans = 0;

    for (int j = 1; j <= k; j++) {
        ll add = 1ll * j * dp[k / j];
        if (add >= MOD) add %= MOD;

        ans += add;
        if (ans >= MOD) ans -= MOD;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 4148
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;
ll N,K,a[200010],s[200100];
map<ll,ll> cnt;


int main(){
  cin>>N>>K;
  REP(i,N)cin>>a[i];
  s[0]=0;
  REP(i,N)s[i+1]+=s[i]+a[i];
  FOR(i,1,N+1)cnt[(s[i]-i)%K]=0;
  ll ans=0;
  FOR(i,0,N+1){
    if(i-K>=0)cnt[(s[i-K]-(i-K))%K]--;
    ans+=cnt[(s[i]-i)%K];
    cnt[(s[i]-i)%K]++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

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

	for (int i = 0; i <= 25; i++) {
		for (int j = 0; j <= 20; j++) {
			int sum = (i * 4) + (j * 7);
			if (sum == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
#define fu(i,a,b)   for(ll i=a;i<b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<" "
#define pr2(a,b)    cout<<a<<" "<<b<<" "
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(a.begin(),a.end(),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()						
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
void inline minize(ll& a,ll b){a=(a>b?b:a);};
void inline maxize(ll& a,ll b){a=(a<b?b:a);};
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e5;
ll n;
bitset <MAXN+5> came;
vi dske[MAXN+5];

ll DFS(ll cur){
	ll res=0,x,cntchild=0;
	came[cur]=1;
	
	fu(i,0,sz(dske[cur])){
		x=dske[cur][i];
		if(came[x])continue;
		cntchild++;
		res^=(DFS(x)+1);
	}
	//if(cntchild==1)res++;
	//debug(cur); debug(res);
	re res;
}

ll Solves(){
//	INPUT;
	ll x,k,cnt=0,ans=0,a,b;
	came.reset();
	// PROCESSING IN HERE
	sc(n);
	fu(i,0,n-1){
		sc2(a,b);
		dske[a].pb(b);
		dske[b].pb(a);
		
	}
	
	if(DFS(1))pr("Alice");
	else pr("Bob");
	
	re 0;
	// Hack it if you can :)
}
int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	Solves();
}

Measured memory_bytes: 10496
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int n= s.size();
    bool ok = true;
    for(int i=0; i<n-1; i++){
        if (s[i]==s[i+1]){
            ok = false;
            break;
        } 
    }
    if(ok) cout << "Good" << endl;
    else
    {
        cout << "Bad" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 888
n = int(input())
t, a = map(int, input().split())
h = [i for i in map(int, input().split())]
palace = 1
for x in range(n):
    diff_cand = abs(a - (t - (h[x] * 0.006)))
    diff_curr = abs(a - (t - (h[palace - 1] * 0.006)))
    if diff_cand < diff_curr:
        palace = x + 1
print(palace)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N, K;
	cin >> N >> K;

	vector<int> pos(N, 0);

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

	int result = 3e8 + 1;
	for (int i = 0; i <= N - K; i++)
	{
		int dist = abs(pos[i + K - 1] - pos[i]);
		int start_dist = min(abs(pos[i]), abs(pos[i + K - 1]));
		result = min(result, start_dist + dist);
	}

	cout << result;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n,v;
    cin>>n>>v;
    vector<ll> a(n),b(n),c(n),d(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>c[i];
    for(int i=0;i<n;i++) cin>>d[i];
    vector<ll> ab,cd;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)ab.push_back( a[i] + b[j] );
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cd.push_back( c[i] + d[j] );
    sort(ab.begin(),ab.end());
    sort(cd.begin(),cd.end());
    ll res = 0;
    for(int i=0;i<n*n;i++){
	auto s = lower_bound(cd.begin(),cd.end(),v-ab[i]);
	auto t = upper_bound(cd.begin(),cd.end(),v-ab[i]);
	res += (t-s);
    }
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 23128