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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF 10000000
#define MOD 998244353
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

int main(){
  ll N,W;
  cin>>N>>W;
  vector<ll>w(N),v(N);
  for(int i=0;i<N;i++)cin>>w[i]>>v[i];
  vector<vector<ll>>dp(N+1,vector<ll>(W+1,0));
  for(int i=1;i<=N;i++){
    for(int j=0;j<=W;j++){
      if(j-w[i-1]>=0)dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
      else dp[i][j]=max(dp[i][j],dp[i-1][j]);
    }
  }
  ll ans=0;

  for(int i=0;i<=W;i++){
    ans=max(ans,dp[N][i]);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 80256
// Code for D - Banned K
#include <iostream>
#include <vector>
#include <map>

using namespace std;

long long int cmb(int x, int y) {
  long long int a = 1;
  long long int b = 1;

  for (int i = 0; i < y; i++) {
    a = a * (x - i);
  }

  for (int i = 1; i <= y; i++) {
    b = b * i;
  }

  return a / b;
}

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

  vector<int> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  map<int, int> mp;

  for (vector<int>::iterator itr = A.begin(); itr != A.end(); ++itr) {
    mp[*itr]++;
  }

  long long int total = 0;
  for (map<int, int>::iterator itr = mp.begin(); itr != mp.end(); ++itr) {
    total += cmb(itr->second, 2);
  }

  for (int k = 0; k < N; k++) {
    int ak = A.at(k);
    cout << total - (mp[ak] - 1) << endl;
  }

	return 0;
}


Measured memory_bytes: 8320
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		Integer[] d = new Integer[n];
		int count = 1;

		for (int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}

		Arrays.sort(d, Collections.reverseOrder());

		for (int i = 1; i < n; i++) {
			if (d[i] >= d[i - 1]) {
				continue;
			}
			count++;
		}

		System.out.println(count);
	}

}


Measured memory_bytes: 23892
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<i64> A, B;
  tools::read(A, N + 1);
  tools::read(B, N);

  i64 answer = 0;
  for (i64 i = N; i >= 0; --i) {
    if (i < N) {
      const i64 cancel = std::min(A[i], B[i]);
      A[i] -= cancel;
      B[i] -= cancel;
      answer += cancel;
    }
    if (i > 0) {
      const i64 cancel = std::min(A[i], B[i - 1]);
      A[i] -= cancel;
      B[i - 1] -= cancel;
      answer += cancel;
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int a = sc.nextInt();
            int p = sc.nextInt();

            System.out.println((a*3 + p)/2);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

bool cmp(pii& a, pii& b) {
  return a.second > b.second;
}
int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  int n, m;
  cin >> n >> m;
  int arr[n];
  vii bc(m);
  fi(0, n) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  fi(0, m) {
    cin >> bc[i].first >> bc[i].second;
  }
  sort(all(bc), cmp);
  int i = 0, end = 0;
  for(pii p: bc) {
    // cout << p.first << "," << p.second << endl;
    fj(0, p.first) {
      if(i >= n) {
        end = 1;
        break;
      }
      if(arr[i] < p.second)
        arr[i++] = p.second;
      else {
        end = 1;
        break;
      }
    }
    if(end)
      break;
  }
  // fi(0, n)
  //   cout << arr[i] << " ";
  // cout << endl;
  ans = accumulate(arr, arr + n, 0ll);
  cout << ans << endl;
  return 0;
}



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

int main() {
    int X,N;
    int p[110];
    cin >> X >> N;
    for (int i=0; i<N; i++) cin >> p[i];

    int flag = true;
    int m_ans = 1000;
    int count=0;
    while (flag) {
        int num;
        bool res = true;

        num = X + count;
        for (int i=0; i<N; i++) {
            if (num == p[i]) res = false;
        }
        if (res) {
            m_ans = num;
            flag = false;
        }

        num = X - count;
        res = true;
        for (int i=0; i<N; i++) {
            if (num == p[i]) res = false;
        }
        if (res) {
            m_ans = min(m_ans, num);
            flag = false;
        }

        count++;
    }

    cout << m_ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#define int long long
using namespace std;
int cost[101][101];
int d[101];
bool used[101];
int V,k,o,a,b,c,di,e,ans;
void dij(int s){
    fill(d,d+101,10000000);
    fill(used,used+101,false);
    d[s]=0;
    while(true){
        int v=-1;
        for(int u=0;u<V;u++){
            if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
        }
        if(v==-1)break;
        used[v]=true;
        for(int u=0;u<V;u++){
            d[u]=min(d[u],d[v]+cost[v][u]);
        }
    }
}
signed main(){
    for(;;){
        cin>>V>>k;
        if(V==0&&k==0)break;
        fill(cost[0],cost[0]+101*101,10000000);
        for(int i=0;i<k;i++){
            cin>>o;
            if(o==1){
                cin>>c>>di>>e;
                cost[c-1][di-1]=min(cost[c-1][di-1],e);
                cost[di-1][c-1]=min(cost[di-1][c-1],e);
            }
            if(o==0){
                cin>>a>>b;
                dij(a-1);
                if(d[b-1]==10000000)cout<<-1<<endl;
                else cout<<d[b-1]<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

int main(){
    int n, m;
    cin >> n >> m;
    vector<bool> exist_ai(n + 1, false);
    vector<pair<int, int>> edges_vec;
    
    int num1 = 0;
    for(int i = 0; i < m; i++){
        pair<int, int> e;
        cin >> e.first >> e.second;
        exist_ai[e.first] = true;
        edges_vec.push_back(e);
        if(e.first == 1) num1++;
    }

    if(num1 == 0){
        cout << "IMPOSSIBLE" << endl;
    }else{
        sort(edges_vec.begin(), edges_vec.end());

        int step = 0, current_island = 1;
        for(int i = 0; i < num1; i++){
            step = 1;
            if(exist_ai[edges_vec[i].second]){
                current_island = edges_vec[i].second;
                for(int j = num1; j < (int)edges_vec.size(); j++){
                    if(edges_vec[j].first == current_island && edges_vec[j].second == n){
                        step = 2;
                        current_island = edges_vec[j].second;
                        i = num1;
                        break;
                    }
                }
            }
        }

        string ans = (step == 2)? "POSSIBLE" : "IMPOSSIBLE";
        
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2424
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int N, K;
vector<int> e[100000];
ll vec[2][100000][301];
ll tmp[2][301] = {0};
int sz[100000];

void dfs(int v, int p) {
    rep(i,e[v].size()) {
        if (e[v][i] == p) continue;
        dfs(e[v][i], v);
    }
    vec[0][v][0] = 1;
    vec[1][v][1] = 1;
    sz[v] = 1;
    rep(i,e[v].size()) {
        if (e[v][i] == p) continue;
        memset(tmp, 0, sizeof(tmp));
        for (int j = sz[v]; j >= 0; j--) {
            for (int k = 0; k <= sz[e[v][i]]; k++) {
                if (j+k > K+1) break;
                if (k == K+1) continue;
                if (k+j != K+1) tmp[0][k+j] = (tmp[0][k+j] + vec[0][v][j] * (vec[0][e[v][i]][k] + vec[1][e[v][i]][k])) % MOD;
                if (k+j != K+1) tmp[1][k+j] = (tmp[1][k+j] + vec[1][v][j] * (vec[1][e[v][i]][k] + vec[0][e[v][i]][k])) % MOD;
                if (k+j != 0) tmp[1][k+j-1] = (tmp[1][k+j-1] + vec[1][v][j] * vec[1][e[v][i]][k]) % MOD;
            }
        }
        sz[v] = min(K, sz[v]+sz[e[v][i]]);
        rep(j,2) rep(k,sz[v]+1) vec[j][v][k] = tmp[j][k];
        /*
        cerr << "i: " << i << endl;
        cerr << sz[v] << " " << sz[e[v][i]] << endl;
        rep(j,2) { rep(k,K+1) {
            cerr << tmp[j][k] << " "; } cerr << endl;
        }
        */
    }
}

int main() {
    cin >> N >> K;
    rep(i,N-1) {
        int u, v; cin >> u >> v;
        u--; v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(0, 0);
    cout << (vec[0][0][K] + vec[1][0][K]) % MOD << endl;
}



Measured memory_bytes: 489600
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
S = [0]*(N+1)
dic = defaultdict(int)
dic[0] = 1
for i in range(1,N+1):
    S[i] = S[i-1] + A[i-1]
    dic[S[i]] += 1
ans = 0
for _,v in dic.items():
    if v > 0:
        ans += v*(v-1)//2
print(ans)


Measured memory_bytes: 40796
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
	int used[26] {0};
	string w;
	cin >> w;
	for (int i = 0; i < (int) w.size(); i++){
		used[w[i]-'a']++;
	}
	for (int c: used){
		if (c & 1){
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
}

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

    //int t; cin >> t; while (t--)
        solve();
}


Measured memory_bytes: 3608
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
};


int binomialmod2(ll a, ll b) {
    if ((b<0) || (b>a)) {  return 0;  }
    int ret = 1;
    while (b>0) {
        int digb = b%2, diga = a%2;
        a/=2; b/=2;
        if (digb>diga) { ret = 0; break; }
    }
    return ret;
};

int no_of_pts(vector<pair<ll,ll>>& pts, ll y_min, ll x) {  // return no of pts less or equal than x (mod 2)
  int ret = 0;
  for(auto p : pts) {
      ll x_ = p.first, y_ = p.second;
      if ((x >= x_) && (x <= x_+y_-y_min)) {
          ll a = y_-y_min, b = x-x_;
          ret += binomialmod2(a-1,b);
          ret = ret % 2;
      }
  }
  return ret;
};

int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readll(n);
        vector<pair<ll,ll>> pts;
        forr(i,0,n) {
            readll(x); readll(y);
            pts.push_back(make_pair(x,y));
        }

        ll ypow2 = -1;
        while (-modd*modd<=ypow2) {ypow2*=2;}

/*        forr(i,-3,20) {
            cout << i << " " << no_of_pts(pts, ypow2, i) << endl;
        } */

        ll start = modd*modd/2;

        ll ret = binary_search([&pts, ypow2](ll x) {
            return (no_of_pts(pts, ypow2, x)==1);
        }, -modd*modd/10, start+1);

        cout << ret << endl;

    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}


Measured memory_bytes: 5360
p = 10 ** 9 + 7 # mod
N = (10 ** 6) * 2 + 10  # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

def cmb(r, n, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

a = list(map(int,input().split()))
ans = cmb(a[2]+1,a[2]+a[3]+2,p) - cmb(a[1],a[2]+a[1]+1,p) - cmb(a[0],a[3]+a[0]+1,p) + cmb(a[0],a[0]+a[1],p)
print(ans%p)

Measured memory_bytes: 134212
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String buf = br.readLine();
			String[] list = buf.split(" ");
			int a = Integer.parseInt(list[0]);
			int b = Integer.parseInt(list[1]);
			if (a > b) {
				System.out.println("a > b");
			} else if (a < b) {
				System.out.println("a < b");
			} else {
				System.out.println("a == b");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
using ll = long long;
const ll INF = 1e16;
int main() {
	int x; cin >> x;
    bitset<1> b(x);
  cout << ~b << endl;

   return 0;
}


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

int main()
{
	long long n,k,sum=0ll;
	cin>>n>>k;
	
	long long x,y;
	for(long long i=k;i<=n+1ll;i++)
	{
		x=i*(i-1ll)/2ll;
		y=(2ll*n-i+1ll)*i/2ll;
		sum=(sum+y-x+1)%1000000007ll;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3644
#define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
//#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
ll pi = acos(-1) ;
ll z =  1000000007 ;
ll inf = 6000000000000000000 ;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 =  202976689 ;
ll mod2 =  203034253 ;
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll min(ll a , ll b){if(a < b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return ((2*i) + 2) ;}
void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
//__builtin_popcount(n) -> returns number of set bits in n

 
void solve()
{
    ll n , k ;
    cin >> n >> k ;
    ll ans[k+1] ;
    for(ll i = k ; i >= 1 ; i--)
    {
    	ans[i] = power(k/i , n , z) ;
    	ll j = 2*i ;
    	while(j <= k)
    	{
    		ans[i] -= ans[j] ;
    		j += i ;
    	}
    	ans[i] %= z ;
    	ans[i] += z ;
    	ans[i] %= z ;
    }
    ll fin_ans = 0 ;
    for(ll i = 1 ; i <= k ; i++)
    {
    	fin_ans += (i * ans[i]) ;
    	fin_ans %= z ;
    }
	cout << fin_ans << endl ;
	return ;    
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
   /* #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif*/
    
    ll t ;
    //cin >> t ;
    t = 1 ;
   
    while(t--)
    {
        solve() ;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
 
    return 0;
}

Measured memory_bytes: 4524
n,k=map(int,input().split())
alist=list(map(int,input().split()))

one_count = [0]*41

for a in alist:
    for i,b in enumerate(format(a,'b')[::-1]):
        one_count[i] += int(b)

x = 0
adj = 0
for i,count in enumerate(one_count[::-1]):
    tmp = (count < n/2) * (2**(40-i))
    if x + tmp <= k :
        x += tmp
        adj += (n-2*count) * tmp
print(sum(alist)+adj)

Measured memory_bytes: 14620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<endl
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define PI 3.14159265358979323846264338327
#define INF 2e14
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 200005

class LazySegmentTree{
private:
	int size_;
	vector<ll> v,lazy;
	
	void update(int s, int e, ll val, int k, int l, int r){
		push(k,l,r);
		if(r < s || e < l) return;
		if(s <= l && r <= e){
			lazy[k] += val;
			push(k, l, r);
		}
		else{
			update(s, e, val, k*2, l, (l+r)>>1);
			update(s, e, val, k*2+1, ((l+r)>>1)+1, r);
			v[k] = merge(v[k*2], v[k*2+1]);
		}
	}
	
	ll query(int s, int e, int k, int l, int r){
		push(k,l,r);
		if(r < s || e < l) return 0;
		if(s <= l && r <= e) return v[k];
		ll lc = query(s, e, k*2, l, (l+r)>>1);
		ll rc = query(s, e, k*2+1, ((l+r)>>1)+1, r);
		return merge(lc, rc);
	}
 
public:
	LazySegmentTree(): v(vector<ll>()), lazy(vector<ll>()) {};
	LazySegmentTree(int n){
		for(size_=1;size_<n;) size_<<=1;
		v.resize(size_*4);
		lazy.resize(size_*4);
	}
	inline void push(int k, int l, int r){
		if(lazy[k]!=0){
			v[k]+=lazy[k];
			if(l!=r){
				lazy[k*2]+=lazy[k];
				lazy[k*2+1]+=lazy[k];
			}
			lazy[k]=0;
		}
	}
	inline ll merge(ll x, ll y){
		return x+y;
	}
	inline void update(int l, int r, ll val){
		update(l, r, val, 1, 0, size_-1);
	}
	inline ll query(int l, int r){
		return query(l, r, 1, 0, size_-1);
	}
};

int n,q;
vi adj[MAXN];
ll arr[MAXN];
int in[MAXN],out[MAXN];
int tmr=0;

void dfs(int u, int p){
	in[u]=tmr++;
	for(int v: adj[u]){
		if(v==p) continue;
		dfs(v,u);
	}
	out[u]=tmr;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin>>n>>q;
	LazySegmentTree st(n);
	
	forn(i,0,n-1){
		int u,v; cin>>u>>v; u--; v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	
	dfs(0,-1);
	
	forn(it,0,q)
	{
		int u; ll inc; cin>>u>>inc; u--;
		st.update(in[u],out[u]-1,inc);
	}
	
	forn(i,0,n){
		cout<<st.query(in[i],in[i])<<" ";
	}
	cout<<'\n';
	
	return 0;
}


Measured memory_bytes: 41728
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,a,s=0;
    vector<long long>v;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        v.push_back(a-i);
    }
    sort(v.begin(),v.end());
    for(i=0;i<v.size();i++)
    {
        s+=abs(v[i]-v[n/2]);
    }
    cout<<s<<endl;
}


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

using namespace std;

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

    vector<int> A(N);
    int abs_min_index = 0;

    if (L >= 0) abs_min_index = 0;
    else abs_min_index = min(-L, (N - 1));

    long long int sum = 0;
    for (int index = 0; index < N; index++)
        if (index != abs_min_index)
            sum += (L + index);

    cout << sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << '\n';
    }
    else
        cout << "No" << '\n';
}


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

using namespace std;

int main() {
    int n;
    string s, t, out = "";
    cin >> n >> s >> t;

    for (int i = 0; i < n; ++i) {
        out += s[i];
        out += t[i];
    }

    cout << out << endl;

    return 0;
}


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

int main() {
  string S;
  cin >> S;
  string ans = "Good";
  if (S[0] == S[1])
    ans = "Bad";
  if (S[1] == S[2])
    ans = "Bad";
  if (S[2] == S[3])
    ans = "Bad";
  cout << ans << endl;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;


int main() {
    ll n,k;cin>>n>>k;
    vector<ll>x(n);
    rep(i,n){
        cin>>x[i];
    }

    ll ans=inf;
    ll m=0;

    rep(i,n-k+1){
        m=abs(x[i+k-1]-x[i])+min(abs(x[i]),abs(x[i+k-1]));
        ans=min(ans,m);
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
int n, m;
std::vector<int> vec;
int l, r;
int main() {
    std::cin >> n >> m;
    vec.assign(n + 2, 0);
    for (int i = 0; i < m; i++) {
        std::cin >> l >> r;
        vec[l]++;
        vec[r+1]--;
    }
    for (int i = 2; i <= n + 1; i++) {
        vec[i] += vec[i - 1];
    }
    std::cout << std::count(vec.begin(), vec.end(), m) << std::endl;
}


Measured memory_bytes: 640
function main(input) {
  const args = input.split(' ');
  const a = parseInt(args[0], 10);
  const b = parseInt(args[1], 10);
  
  if((a * b) % 2 === 0) {
    console.log('Even');
  } else {
    console.log('Odd');
  }
}

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

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "C"
int n;
ll t;
ll a[200001];
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(n);
    read(t);
    FOR(i, 1, n) read(a[i]);
    a[0]=-t;
    ll ans=0;
    FOR(i, 1, n){
        if(a[i]-a[i-1]<t) ans+=a[i]-a[i-1];
        else ans+=t;
    }
    writeln(ans);
}

Measured memory_bytes: 1792
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List
import Data.Array.IO

main = do
  n <- readLn :: IO Int
  a <- getIntListBC
  switch <- newArray (1, n) 0 :: IO (IOUArray Int Int)
  initS switch [1..n] a
  check <- newArray (1, n) False :: IO (IOUArray Int Bool)
  ans <- solve check switch 1 0
  print ans

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getIntBC :: IO Int
getIntBC = bsToInt <$> BC.getLine

getIntListBC :: IO [Int]
getIntListBC = map bsToInt . BC.lines <$> BC.getContents

initS :: IOUArray Int Int -> [Int] -> [Int] -> IO (IOUArray Int Int)
initS memo []     []     = return memo
initS memo (i:is) (a:as) = do
  writeArray memo i a
  initS memo is as

solve :: IOUArray Int Bool -> IOUArray Int Int -> Int -> Int -> IO Int
solve check switch 2 c = return c
solve check switch i c = do
  b <- readArray check i
  if b then return (-1)
       else do
         writeArray check i True
         next <- readArray switch i
         solve check switch next $ c + 1


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
 string S; 
  cin>>S;
  string i,j,k,l,m,n;
 i=S.at(0);
 j=S.at(1);
 k=i+j;
 l= S.at(2);
 m= S.at(3);
 n=l+m;
  int o = stoi(k);
  int p = stoi(n);
   
 while(true){ 
  if(o==0){
       if(p==0){
         cout<<"NA"<<endl;
         break;
        }else if(p<13){
        cout<<"YYMM"<<endl;
         break;
      }else if(p>=13){
        cout<<"NA"<<endl;
         break;
      }
     }  
    if(o<13){
      if(p==0){
        cout<<"MMYY"<<endl;
         break;
      }else if(p<13){
        cout<<"AMBIGUOUS"<<endl;
         break;
      }else if(p>=13){
        cout<<"MMYY"<<endl;
         break;
      }
    }
   if(o>=13){
     if(p==0){
        cout<<"NA"<<endl;
         break;
      }else if(p<13){
        cout<<"YYMM"<<endl;
         break;
      }else if(p>=13){
        cout<<"NA"<<endl;
         break;
     } 
    }     
  }

  return 0;
}

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

int main(){
int a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
int ans=0;
while(a[1]!=a[2])
{
    ans++;
    a[1]++;
    a[0]++;
}
if(a[1]%2!=a[0]%2)
{
    ans++;
    a[1]++;
}
ans+=(a[1]-a[0])/2;
cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#define N 200005
#define lowbit(o) o&(-o)
using namespace std;
int i,j,k,l,s,n,m,R[N],L[N],q[N],ans,G[N],r;
int a[N],b[N];
char c[N];
inline bool cmp(int x,int y) {
	return R[x]<R[y];
}
int main() {
	scanf("%s",c+1);
	n=strlen(c+1);
	for (i=1;i<=n;i++) a[i]=c[i]-48,L[i]=R[i]=100000000;
	scanf("%s",c+1);
	for (i=1;i<=n;i++) b[i]=c[i]-48;
	for (i=1;i<=n;i++) for (j=1;j<=n;j++) if (b[j]) L[i]=min(L[i],(i-j+n)%n),R[i]=min(R[i],(j-i+n)%n);
	ans=100000000;
	for (i=1;i<=n;i++) {
		r=0; k=i;
		for (j=1;j<=n;j++) {
			if (a[k]!=b[j]) q[++r]=k;
			k%=n; k++;
		}//printf("%d\n\n",j);
		sort(q+1,q+1+r,cmp);
		G[r+1]=0;
		for (k=r;k;k--) G[k]=max(G[k+1],L[q[k]]);
		
		for (k=0;k<=r;k++) {
			//workL:
			ans=min(ans,(R[q[k]]+max((i-(n+1)+n)%n,G[k+1]))*2-(i-(n+1)+n)%n+r);
			//workR:
			ans=min(ans,(G[k+1]+max(((n+1)-i+n)%n,R[q[k]]))*2-((n+1)-i+n)%n+r);
		}
	}
	if (ans>=100000000) ans=-1;
	printf("%d\n",ans);
}

Measured memory_bytes: 2304
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

// ll dp[]

int main(){
char s[4];


  scanf("%s", &s);

  if(s[1] == 'R'){
      s[1] = 'B';
  }else
  {
      s[1] = 'R';
  }
  
  
  
  printf("%s\n", s);

  return 0;
}

Measured memory_bytes: 1660
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;

set<int64_t> lunluns;

void lunlun_generator(int64_t n) {
  if (n > 3234566667LL) return;
  lunluns.insert(n);

  lunlun_generator(n*10+n%10);
  if (n % 10 == 0) lunlun_generator(n*10+1);
  else if (n % 10 == 9) lunlun_generator(n*10+8);
  else lunlun_generator(n*10+(n%10-1)), lunlun_generator(n*10+(n%10+1));
  return;
}

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

  int k;
  cin >> k;

  rep(i,9) lunlun_generator(i+1);

  int idx = 0;
  for (int64_t res : lunluns) {
    //cout << res << endl;
    idx++;
    if (idx == k) { cout << res << endl; return 0; }
  }
  return 0;
}

Measured memory_bytes: 8308
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <iomanip>


using namespace std;

int main() {
    

    int a,b,c;
    cin >> a >> b >> c;
    if (a < b and b < c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


}



Measured memory_bytes: 3084
//
//  main.cpp
//  DPu
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using P=pair<int,int>;
using ll = long long;
ll dp[1<<16]={};
ll cost[1<<16]={};
int main(int argc, const char * argv[]) {
    int n;
    cin >>n;
    ll a[n][n];
    rep(i,n) rep(j,n) cin>>a[i][j];
    
    for (int s=1; s<(1<<n); s++) {
        for (int i=0; i<n; i++) {
            if((s>>i)%2==0) continue;
            for (int j=i+1;j<n; j++) {
                if((s>>j)%2==0)continue;
                cost[s]+=a[i][j];
            }
        }
    }
    for (int s=1; s<(1<<n); s++) { // 全集合
       for (int t=(1<<n)-1; t>=0; --t) { // 集合Sの部分集合T
           t&=s;    // 部分集合tの全列挙の方法、処理はこの下に書く
                    // https://primenumber.hatenadiary.jp/entry/2016/12/01/000000
           dp[s]=max(dp[s],dp[s-t]+cost[t]);
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
    return 0;
}


Measured memory_bytes: 4104
#include<iostream>
using namespace std;
const int N = 2e6 + 5 , mod = 1e9 + 7;
int power(int n , int p ){
    int ans = 1;
    while(p){
        if(p&1){
            ans = ( (long long) ans * n )%mod;
        }
        p>>=1;
        n = ( (long long)n * n )%mod;
    }
    return ans;
}
int fct[N] , invfct[N] ; 
void init(){
    fct[0] = invfct[0] = 1;
    for(int i = 1 ; i<N ; i++){
        fct[i] = ( (long long) fct[i-1] * i)%mod;
invfct[i] = power(fct[i]  , mod-2); 
    }
}
int ncr(int n , int r){
    int ans = ( ( long long )fct[n] * invfct[r] ) %mod;
    ans = ( (long long)ans * invfct[n-r] )%mod;
    return ans;
}
int main(){
    init();
    int k ;     
    cin >> k;
    string s;
    cin >>s;
    
    int n = s.size();
    int ans = power(26, n + k );
    for(int sz = 0 ; sz <= n-1 ; sz++){
        int f = ncr( n+k , sz);
        int s = power( 25 , n + k - sz );
        int val = ( (long long)f * s )%mod;
        ans = ans  - val;
        if(ans<0)ans+=mod;    
    }
    cout<<ans;
}


Measured memory_bytes: 20960
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
#define debug(x) (cout << "#x = " << (x) << endl)
#define lowbit(x) (x & -x)
#define Set(x, i) memset(x, i, sizeof x)
#define R register
#define For( i, j, k ) for(R int i = (j); i <= (k); ++i)
#define Rep( i, j, k ) for(R int i = (j); i >= (k); --i)
#define Cross( i, j, k ) for(R int i = (j); i; i = (k))
typedef long long ll;
using namespace std;
const ll N = 100011;
const ll INF = 5e16;

namespace IO {

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar ( x % 10 | 48 );
	}

	inline void wrn ( ll x ) { write(x); putchar (' '); }

	inline void wln ( ll x ) { write(x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x); wln (y); }

}

using namespace IO;

namespace Cesare {
	
	ll k, x;
	
	int main() {
		k = read(), x = read();
		For ( i, -k + 1, k - 1 ) 
			if (x + i <= 1e6 && x + i >= -1e6) wrn(x + i);
		return 0;
	}
	
}

int main()
{
	return Cesare::main();
}

/*

*/



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int j;
	char x[1005];
	while( true ){
		cin >> x;
		j = 0;
		for (int i=0; i < 1000; i++){
			if (x[i] == '\0'){ break; }
			j = j + x[i]-48;
		}
		if (j == 0){ break; }
		cout << j << endl;
	}
	return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>

using namespace std;

static void FirstChangeDirection(int startIndex, const string &input, int &time, int &index, char &direction)
{
    const auto firstDirection = input[startIndex];
    int t = 0;
    auto position = startIndex;
    auto delta = (input[position] == 'R') ? 1 : -1;

    while (true)
    {
        position += delta;
        t++;
        auto newDirection = input[position];
        if (newDirection != firstDirection)
        {
            time = t;
            index = position;
            direction = newDirection;
            return;
        }
    }
}

int main()
{
    string input;
    cin >> input;
    const auto size = input.size();
    auto childCounts = vector<int>(size, 0);
    int time = -1;
    int index = -1;
    char direction = ' ';
    for (int i = 0; i < size; i++)
    {
        if (i > 0 && input[i] == input[i - 1])
        {
            if (time % 2 == 0 && direction == 'L')
            {
                childCounts[index == 0 ? 1 : (index - 1)]++;
            }
            else if (time % 2 == 0 && direction == 'R' && index < size - 1)
            {
                childCounts[index == size - 1 ? (size - 2) : (index + 1)]++;
            }
            else
            {
                childCounts[index]++;
            }
            time++;
            continue;
        }
        FirstChangeDirection(i, input, time, index, direction);
        int finalIndex = -1;
        if (time % 2 == 0)
        {
            finalIndex = index;
        }
        else
        {
            if (direction == 'L')
            {
                finalIndex = index - 1;
            }
            else
            {
                finalIndex = index + 1;
            }
        }
        childCounts[finalIndex]++;
    }
    for (auto count : childCounts)
    {
        cout << count << " ";
    }
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApplication2
{

    class Program
    {
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split(' ');

            int number = int.Parse(input[0]);

            int oneNumber = number % 10;

            string read;

            if(oneNumber==2||oneNumber==4||oneNumber==5||oneNumber==7||oneNumber==9)
            {
                read = "hon";
            }
            else if(oneNumber == 0 || oneNumber == 1 || oneNumber == 6 || oneNumber == 8)
            {
                read = "pon";
            }
            else
            {
                read = "bon";
            }


            Console.WriteLine(read);
            

        }
    }
}


Measured memory_bytes: 17848
// Hint: Don't look, No need, Let'em Play.

#pragma optimize("O2")
#include <bits/stdc++.h>
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

void solve() {
    int n, x, sum = 0;
    map<int,int> mp;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        sum += x;
        mp[x]++;
    }
    int q, y;
    cin >> q;
    while (q--) {
        cin >> x >> y;
        sum -= mp[x] * x;
        sum += y * mp[x];
        mp[y] += mp[x];
        mp.erase(x);
        cout << sum << '\n';
    }
}

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


  return 0;
}

Measured memory_bytes: 7556
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b;cin>>a>>b;
  a--;b--;
  cout<<a*b<<endl;
  return 0;
}


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

int main() {
  int sx, sy;
  int tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int a, b;
  a = tx - sx;
  b = ty - sy;
  string ans;
  for(int i = 0; i < a; i++){
     ans += "R";
  }
  for(int i = 0; i < b+1; i++){
    ans += "U";
  }
  for (int i =0; i < a+1; i++){
    ans += "L";
  }
  for(int i = 0; i < b+1; i++){
    ans += "D";
  }
  ans += "RD";
  for(int i = 0; i < a+1; i++){
    ans += "R";
  }
  for(int i = 0; i < b+1; i++){
    ans += "U";
  }
  for (int i =0; i < a+1; i++){
    ans += "L";
  }
  for (int i = 0; i < b; i++) {
    ans += "D";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, n) for (int i = (n)-1; i >= 0; i--)
#define pp(v) cout << #v << "=" << (v) << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  // input
  int n,m; cin >> n >> m;
  vector<int> k(m),p(m);
  vector<vector<int>> s(m);
  rep(i,m) {
    cin >> k[i];
    int len = k[i];
    s[i].resize(len);
    rep(j,len) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  rep(i,m) cin >> p[i];

  // スイッチのon／offを全探索
  int ans = 0; // 組み合わせの戸数
  rep(bit, 1<<n) { // スイッチのon/off状態
    bool on = true;
    rep(i,m) { // 電球i
      int cnt = 0; // 電球iが繋がっているスイッチの数
      int len = k[i]; // 電球に繋がっているスイッチの個数
      rep(j,len) {
        int sw = s[i][j]; // スイッチ番号
        if (bit >> sw & 1) cnt++; // スイッチonならカウント
      }
      if (cnt % 2 != p[i]) { // 点灯していないスイッチがあったら
        on = false;
        break;
      }
    }
    if (on) ans++; // 全部の電球が点灯したらカウント
  }

  cout << ans << endl;
}


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

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

bool f(string  S, int A, int B) {
  REP(i,A) {
    if(! isdigit(S[i])) return false;
  }
  if(S[A] != '-') return false;
  REP(i,B) {
    if(! isdigit(S[A+1+i])) return false;
  }
  return true;
}

int main() {
  int A, B;
  cin >> A >> B;
  string S;
  cin >> S;
  bool ans = f(S, A, B);
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <map>
using namespace std;
const int maxn = 200100;
int n;
int a[maxn];
map<int, int> th;
int p[maxn], num[maxn] = {0};
bool flag[maxn] = {0};
int get(int x)
{
	for(int i = 0; i <= 31; i ++)
		if((1 << i) >= x)
			return (1 << i);
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	th[a[1]] = 1;
	num[1] = 1;
	for(int i = 2; i <= n; i ++)
	{
		if(a[i] != a[i - 1])
		{
			th[a[i]] = i;
			num[i] = 1;
		}
		else
			num[th[a[i]]] ++;
	}
	int ans = 0, sum = 0;
	for(int i = n; i >= 0; i --)
	{
		int c = th[a[i]];
		if(num[c])
		{
			int x = get(a[i]) - a[i];
			int b = th[x];
			if(!x)
				flag[c] = 1;
			else if(b && num[b])
			{
				num[b] --;
				num[c] --;
				ans ++;
			}
		}
	}
	for(int i = 1; i <= n; i ++)
		if(flag[i])
			ans += num[i] / 2;
	cout << ans << endl;
	return 0;
}
/*
8
9 4 2 4 8 9 1 8 
*/

Measured memory_bytes: 20608
#include <stdio.h>
int main(void){
    int n, m, i, j;
    int a[100][100], b[100], c[100];
    
    scanf("%d %d\n", &n, &m);
    
    for(i=0; i<n; i++) {
        for(j=0; j<m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    
    for(i=0; i<m; i++) {
        scanf("%d\n", &b[i]);
    }
    
    for(i=0; i<n; i++) {
        for(j=0; j<m; j++) {
            c[i] += a[i][j] * b[j];
        }
        printf("%d\n", c[i]);
    }

    return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];

void push(int x) {
  // top を加算してからその位置へ挿入
  S[++top] = x;
}

int pop() {
  top--;
  // topが指していた要素を返す
  return S[top+1];
}

int main() {
  int a, b;
  top = 0;
  char s[100];

  while( scanf("%s", s) != EOF ) {
    if ( s[0] == '+' ) {
      b = pop();
      a = pop();
      push(a + b);
    } else if ( s[0] == '-' ) {
      b = pop();
      a = pop();
      push(a - b);
    } else if ( s[0] == '*' ) {
      b = pop();
      a = pop();
      push(a * b);
    } else {
      push(atoi(s));  // atoi()は文字列で表現された数値をint型の数値に変化する
    }                 // C言語の標準ライブラリの関数
  }

  printf("%d\n", pop());

  return 0;
}


Measured memory_bytes: 2736