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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

// 単一始点最短経路(ダイクストラ法)
// 時間計算量はO((V+E)logV)
// 使用例:
// Dijkstra<int> dij(N);
// dij.AddEdge(f, t, c);  <- fからtのコストcの辺を追加
// dij.Run(s);            <- s始点での最短経路長
// dij.cost[t]            <- Run()で求めた始点からtへの最短経路長を取得
// dij.HasPath(t)         <- Run()で求めた始点からtへのパスは存在するか
// dij.GetShortestPath(t) <- Run()で求めた始点からtへのパスを取得
template <typename T>
struct Edge
{
    int from, to;
    T cost;
    Edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    Edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <typename T>
using Edges = vector<Edge<T>>;
template <typename T>
using AdjList = vector<Edges<T>>;

template <typename T>
class Dijkstra
{
  private:
    T INF = numeric_limits<T>::max() / 10;
    int V;
    AdjList<T> adj;
    vector<int> prever;

  public:
    Dijkstra(int n) : V(n + 1), adj(V), prever(vector<int>(V, -1)), cost(V, INF) {}
    vector<T> cost;
    void AddEdge(int f, int t, int c)
    {
        adj[f].push_back(Edge<T>(t, c));
    }
    bool HasPath(int t)
    {
        return cost[t] != INF;
    }
    vector<int> GetShortestPath(int t)
    {
        vector<int> path;
        for (; t != -1; t = prever[t]) path.push_back(t);
        reverse(path.begin(), path.end());
        return path;
    }
    void Run(int f)
    {
        cost.assign(V, INF);
        prever.assign(V, -1);

        using Pi = pair<T, int>;
        priority_queue<Pi, vector<Pi>, greater<Pi>> pq;

        cost[f] = 0;
        pq.push(Pi(cost[f], f));

        while (!pq.empty())
        {
            Pi currentEdge = pq.top();
            pq.pop();
            if (cost[currentEdge.second] < currentEdge.first) continue;

            for (Edge<T> tmp : adj[currentEdge.second])
            {
                T sumCost = currentEdge.first + tmp.cost;
                if (cost[tmp.to] > sumCost)
                {
                    cost[tmp.to] = sumCost;
                    prever[tmp.to] = currentEdge.second;
                    pq.push(Pi(cost[tmp.to], tmp.to));
                }
            }
        }
    }
};

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int v, e, r;
    cin >> v >> e >> r;
    Dijkstra<LL> dij(v);
    REP(i, e)
    {
        int s, t, d;
        cin >> s >> t >> d;
        dij.AddEdge(s, t, d);
    }
    dij.Run(r);
    REP(i, v)
    {
        cout << (dij.HasPath(i) ? to_string(dij.cost[i]) : "INF") << endl;
    }
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n, k, a[100001];
  cin >> n >> k;
  rep(i, 0, n) cin >> a[i];
  int ans = n / (k - 1);
  if(k == 2) {
    cout << ans - 1 << endl;
    return 0;
  }
  if(n % (k - 1) > 1) {
    cout << ans + 1 << endl;
  }else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int zhan(int x,int y){
	if(x<y) swap(x,y);
	if(x%y!=0) return zhan(y,x%y);
	return y;
}
int main(){
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long x=c*d/zhan(c,d);
	cout<<(b-a+1)-(b/c-(a-1)/c)-(b/d-(a-1)/d)+(b/x-(a-1)/x);
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const inf = 1 << 60

func solve() {
	n := getInt()
	hs := getIntSlice(n)

	dp := make([]int, n)
	for i := range dp {
		dp[i] = inf
	}
	dp[0] = 0

	for i := 0; i < n; i++ {
		if i >= 1 {
			dp[i] = min(dp[i], dp[i-1]+abs(hs[i]-hs[i-1]))
		}
		if i >= 2 {
			dp[i] = min(dp[i], dp[i-2]+abs(hs[i]-hs[i-2]))
		}
	}

	fmt.Fprintln(wr, dp[n-1])
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 2688
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cctype>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
using namespace std;
#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 vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
const int iadd[] = {0, 1, 0, -1}, jadd[] = {1, 0, -1, 0};
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 5;

int main(){
	int a, b, x;
	scanf("%d %d %d", &x, &a, &b);
	if(abs(x - a) < abs(x - b)) puts("A");
	else puts("B");
} 






Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i) 
#define pb insert
#define F first
#define S second
#define mp make_pair
#define debug1(a) cout<<" a : "<<a<<"\n"
#define debug2(a,b) cout<<" a : "<<a<<" b : "<<b<<"\n"
#define debug3(a,b,c) cout<<" a : "<<a<<" b : "<<b<<" c : "<<c<<"\n"
#define M 1000000007

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	int n;
	cin>>n;
	int a[n],dp[n]={0};
	rep(i,n) cin>>a[i];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	REP(i,2,n-1)
	{
		dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
	}
	cout<<dp[n-1];
	return 0;
}




Measured memory_bytes: 1792
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k; cin >> n >> k;
	vector<int> h(n);
	rep(i, n)cin >> h[i];
	sort(all(h));
	int ans = 0;
	rep(i, n - k) {
		ans += h[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

unordered_map<int, vector<int>> edges;
int f[100010], sz[100010];
int uniq[100010];
int n, m, x, y;

void dfs1(int u) {
    f[u] = sz[u] = uniq[u] = 1;
    if (edges.count(u)) {
        for (int v: edges[u]) {
            if (edges.count(v)) {
                edges[v].erase(remove(edges[v].begin(), edges[v].end(), u), edges[v].end());
            }
            dfs1(v);
            f[u] = (LL)f[u] * (f[v] + 1) % m;
            sz[u] += sz[v];
        }
        int preprod = 1;
        for (int i = 1; i < edges[u].size(); ++i) {
            preprod = (LL)preprod * (f[edges[u][i - 1]] + 1) % m;
            uniq[edges[u][i]] = (LL)uniq[edges[u][i]] * preprod % m;
        }
        int sufprod = 1;
        for (int i = edges[u].size() - 2; i >= 0; --i) {
            sufprod = (LL)sufprod * (f[edges[u][i + 1]] + 1) % m;
            uniq[edges[u][i]] = (LL)uniq[edges[u][i]] * sufprod % m;
        }
    }
}

void dfs2(int u) {
    if (edges.count(u)) {
        for (int v: edges[u]) {
            if (u != 1) {
                uniq[v] = (LL)uniq[v] * (uniq[u] + 1) % m;
            }
            f[v] = (LL)f[v] * (uniq[v] + 1) % m;
            dfs2(v);
        }
    }
}

inline void work() {
    cin >> n >> m;
    for (int i = 1; i < n; ++i) {
        cin >> x >> y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
    dfs1(1);
    dfs2(1);
    for (int i = 1; i <= n; ++i) {
        cout << f[i] << "\n";
    }
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 16676
using System;


namespace Gushwell.Etude {
    class Program {
        static void Main(string[] args) {
            var data=Console.ReadLine();
            string[] a_b=data.Split(' ');
            long A=long.Parse(a_b[0]);
            long B=long.Parse(a_b[1]);
            var lcm = Lcm(A, B);
            Console.WriteLine(lcm);
        }

        // 最小公倍数
        public static long Lcm(long a, long b) {
            return a * b / Gcd(a, b);
        }

        // ユークリッドの互除法 
        public static long Gcd(long a, long b) {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}

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

using namespace std;

const int N = 1234567;

vector <int> g[N];
bool know[N], res[N];
int a[N];

bool win(int v) {
  if (know[v]) {
    return res[v];
  }
  bool my = false;
  int sz = g[v].size();
  for (int j = 0; j < sz; j++) {
    int u = g[v][j];
    if (a[u] >= a[v]) {
      continue;
    }
    if (!win(u)) {
      my = true;
    }
  }
  know[v] = true;
  res[v] = my;
  return my;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 0; i < n; i++) {
    know[i] = false;
  }
  for (int i = 0; i < n; i++) {
    if (win(i)) {
      printf("%d ", i + 1);
    }
  }
  return 0;
}


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

int main(){
	int h,w,n;
	cin >> h >> w;
	cin >> n;
	vector<int> a(n+1);
	for(int i=1; i<=n; i++){
		cin >> a[i];
	}
	
	vector<vector<int> > grid(h, vector<int>(w));
	int now=1;
	for(int i=0; i<h; i++){
		if(i%2==0){
			for(int j=0; j<w; j++){
				if(a[now]==0) now++;
				a[now]--;
				grid[i][j]=now;
			}
		}else{
			for(int j=w-1; j>=0; j--){
				if(a[now]==0) now++;
				a[now]--;
				grid[i][j]=now;
			}
		}
	}
	
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cout << grid[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		long resultSum =0;
		List<Long> aList = new ArrayList<>(n+1);
		List<Long> bList = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			long a = Long.parseLong(sc.next());
			aList.add(a);
		}
		aList.add(Long.parseLong(sc.next()));

		for (int i = 0; i < n; i++) {
			long b = Long.parseLong(sc.next());
			bList.add(b);
			resultSum += b;
		}


		// System.out.println("aList " + aList);

		// System.out.println("bList " + bList);

		long prevAmari  = aList.get(n);
		for (int i = n-1; i >= 0 ; i--) {
			// System.out.println("i " + i);

			long b = bList.get(i);
			long ai = aList.get(i);
			long bPower = b;
			if(prevAmari>=0){
				if(bPower>=prevAmari){
					bPower = bPower - prevAmari;
				}else{
					bPower = 0;
				}
			}

			if(bPower >= ai){
				prevAmari =0;
				resultSum -= bPower-ai;
			}else{
				prevAmari = ai - bPower;
			}
			// System.out.println("b " + b);
			// System.out.println("ai " + ai);

			// System.out.println("prevAmari " + prevAmari);
			// System.out.println("bPower " + bPower);
			// System.out.println("resultSum " + resultSum);
		}
		System.out.println(resultSum);


	}

}


Measured memory_bytes: 66836
ans :: [Int] -> String
ans [] = []
ans (m:f:r:_)
  | (m==(-1)) || (f==(-1)) = "F"
  | (m+f) >= 80            = "A"
  | (m+f) >= 65            = "B"
  | (m+f) >= 50            = "C"
  | (m+f) >= 30 && (r>=50) = "C"
  | (m+f) >= 30            = "D"
  | otherwise              = "F"

main = do
  c <- getContents
  let i  = map (map read) $ map words $ lines c :: [[Int]]
      i' = takeWhile (/= [-1,-1,-1]) i
      o  = map ans i'
  mapM_ putStrLn o

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

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

  vector<double> a(N);
  double sum = 0;
  for(int i = 0;i < N;i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }

  sum /= N;
  double mini = 10000,ans = 0;
  for(int i = 0;i < N;i++) {
    double d = abs(a.at(i)-sum);
    if(mini > d) {
      mini = d;
      ans = i;
    }
  }

  cout << ans << endl;
}



Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f
inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
const int maxn = 110;
double n,m,a[maxn];
signed main() {
  IO;
  cin >> n >> m;
  double sum = 0;
  rep(i, 1, n){
    cin >> a[i];
    sum += a[i];
  }
  sum = sum / (4.0 * m);
  //cout << sum << endl;
  int cnt = 0;
  rep(i,1,n){
    if(a[i] >= sum) cnt++;
  }
  if(cnt >= (int)m) cout << "Yes" <<endl;
  else cout << "No" << endl;
  return 0;
}

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


int main(){
    char s[201];
    cin>>s;

    int l = strlen(s);
    for(int i=l-2; i>0; i-=2){
        if(strncmp(s, s+i/2, i/2) == 0){
            cout<< i<<endl;
            return 0;
        }
    }
    return 0;
}


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

ll n, m;
string s, t;
map<ll, char> mp;

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

int main() {
    cin >> n >> m;
    cin >> s >> t;

    ll l = n / gcd(n, m) * m;
    for(int i = 0; i < n; i++)
        mp[1 + l/n*i] = s[i];
    
    bool ok = true;
    for(int i = 0; i < m; i++) {
        if(mp[1 + l/m*i] == '\0')
            continue;

        if(mp[1 + l/m*i] != t[i])
            ok = false;
    }

    cout << (ok ? l : -1) << endl;
}

Measured memory_bytes: 10880
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll H, W, HNum[2000][2000] = {}, WNum[2000][2000] = {}, ans = 0;
char S[2010][2010] = {};

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '.') {
				if (j > 0) {
					HNum[i][j] = HNum[i][j - 1] + 1;
				}
				else {
					HNum[i][j] = 1;
				}
				if (j == W - 1) {
					for (int k = j - 1; S[i][k] == '.'; k--)HNum[i][k] = HNum[i][j];
				}
			}
			else if (j > 0) {
				for (int k = j - 1; S[i][k] == '.'; k--)HNum[i][k] = HNum[i][j - 1];
			}
		}
	}
	for (int i = 0; i < W; i++) {
		for (int j = 0; j < H; j++) {
			if (S[j][i] == '.') {
				if (j > 0) {
					WNum[j][i] = WNum[j - 1][i] + 1;
				}
				else {
					WNum[j][i] = 1;
				}
				if (j == H - 1) {
					for (int k = j - 1; S[k][i] == '.'; k--)WNum[k][i] = WNum[j][i];
				}
			}
			else if (j > 0) {
				for (int k = j - 1; S[k][i] == '.'; k--)WNum[k][i] = WNum[j - 1][i];
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)ans = max(ans, HNum[i][j] + WNum[i][j] - 1);
	}
	cout << ans << endl;
	return 0;
}

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

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

int main(){
    int H, W, dist[55][55];
    cin >> H >> W;
    vector<string> field(H);
    rep(h,H) cin >> field[h];
    int white = 0;
    rep(h,H)rep(w,W){
        if(field[h][w] == '.') white++;
        dist[h][w] = INF;
    }

    queue<pint> que;
    que.push(make_pair(0,0));
    dist[0][0] = 0;
    while(!que.empty()){
        pint p = que.front(); que.pop();
        int ph = p.first, pw = p.second;
        for(int dir = 0; dir < 4; dir++){
            int nh = ph + dx[dir], nw = pw + dy[dir];
            if(nh < 0 || H <= nh || nw < 0 || W <= nw) continue;
            if(field[nh][nw] == '#') continue;
            if(dist[nh][nw] == INF) que.push(make_pair(nh,nw));
            dist[nh][nw] = min(dist[nh][nw], dist[ph][pw]+1);
        }
    }
    int path = dist[H-1][W-1];
    if(path == INF){
        cout << -1 << endl;
        return 0;
    }
    int ans = white - path - 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
 int A,M,C,sum;
scanf("%d %d %d",&A,&M,&C);
sum=A+M+C;
if(sum>=22)
{
  printf("bust\n");
}
else 
{
 printf("win\n");
}
return 0;
}

Measured memory_bytes: 1628
n,k,q= map(int, input().split())#人数，初期ポイント，問題数
a = [0]*n
for i in range(q):
  a[int(input())-1]+=1
for i in range(n):
  if a[i]-q+k > 0:
    print("Yes")
  else:
    print("No")

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

int main(){
  bool Is_YYMM,Is_MMYY;

  int s,lower,upper;

  cin >> s;

  lower = s%100;
  upper = s/100;

  if( 1<=lower && lower<=12) Is_YYMM = true;
  else Is_YYMM = false;
  if( 1<=upper && upper<=12) Is_MMYY = true;
  else Is_MMYY = false;

  if(Is_YYMM){
    if(Is_MMYY) cout << "AMBIGUOUS" << endl;
    else cout << "YYMM" << endl;
  }
  else{
    if(Is_MMYY) cout << "MMYY" << endl;
    else cout << "NA" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

P dp[200005];

int main() {
  string s;
  cin>>s;
  if (s.size()==1) {
    cout<<1<<endl;
    return 0;
  }
  dp[0]={1,1};
  if (s[0]==s[1]) dp[1]={1,2};
  else dp[1]={2,1};
  for (int i=2; i<s.size(); i++) {
    if (!(dp[i-1].second==1&&s[i]==s[i-1])) {
      if (dp[i].first<dp[i-1].first+1) {
	dp[i].first=dp[i-1].first+1;
	dp[i].second=1;
      }
    }
    if (!(dp[i-2].second==2&&(s[i-3]==s[i-1]&&s[i-2]==s[i]))) {
      if (dp[i].first<dp[i-2].first+1) {
	dp[i].first=dp[i-2].first+1;
	dp[i].second=2;
      }
      if (dp[i].first==dp[i-2].first+1) {
	dp[i].second=3;
      }
    }
  }
  cout<<dp[s.size()-1].first<<endl;      
  return 0;
}

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

int main()
{
	int N;
	long long X;
	cin >> N >> X;
	vector<long long> x( N );
	for( int i = 0; i < N; i++ ) {
		cin >> x[i];
	}

	long long ans = abs( x[0] - X );
	for( int i = 1; i < N; i++ ) {
		ans = __gcd( ans, abs(x[i] - X) );
	}

	cout << ans << endl;
}


Measured memory_bytes: 4060
//package src.com.jetman.atcoder;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @description:
 * @author: Jetman
 * @create: 2020-08-29 14:39
 **/
public class Main {

    Scanner sc = new Scanner(System.in);

    long MOD = 1000000000 + 7;

    private void slove() {

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

        long ans = 0;
        for (int i = 0; i < n-1; i++) {
            ans = (ans + a[i]*((sum[n]-sum[i+1])%MOD))%MOD;
//            for (int j = i+1; j < n; j++) {
//                ans = (ans + a[i]*a[j])%MOD;
//            }
        }

        System.out.println(ans);

    }

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


Measured memory_bytes: 62692
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 2005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1e9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {

	fast
	// cases
	{
		ll x, y;
		cin >> x >> y;
		bool ok = 0;
		loop(i, x + 1)
		{
			if ((2 * i + 4 * (x - i)) == y)
				ok = 1;
		}
		if (ok)
			cout << "Yes\n";
		else
			cout << "No\n";
	}



	return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        System.out.println(s.substring(0, k - 1) + String.valueOf(s.charAt(k - 1)).toLowerCase() + s.substring(k, n));
    }
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

int N;

string solve() {
    while (N) {
        if (N%10 == 7) return "Yes";
        N /= 10;
    }
    return "No";
}

int main() {
    cin >> N;
    cout << solve() << endl;
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 2e6 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;
ll fact[N];

ll be(ll b, ll e) {
    if (e == 0)
        return 1;
    if (e % 2 == 0) {
        ll x = be(b, e / 2);
        return (x * x) % M;
    } else return (b * be(b, e - 1)) % M;
}

ll ncr(ll n, ll r) {
    return (fact[n] * ((be(fact[n - r], M - 2) * be(fact[r], M - 2)) % M)) % M;
}

int main() {
    fact[0] = 1;
    for (int j = 1; j < N; ++j) {
        fact[j] = (fact[j - 1] * j) % M;
    }
    ll k;
    string s;
    cin >> k >> s;
    ll n = (ll) s.size() + k;
    ll allPossible = be(26, n);
    ll noSubsequence = 0;
    for (int i = 0; i < s.size(); ++i) {
        noSubsequence = (noSubsequence + (ncr(n, i) * be(25, (n - i))) % M) % M;
    }
    cout << (allPossible - noSubsequence + M) % M << endl;
}



Measured memory_bytes: 20876
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    
    
  int main(){
        lint n;
        cin >>n; 
        map<lint,lint> mp;
        map<lint,lint> mp2;
        rep(i,n){
            lint a;
            cin>>a;
            if(i%2==0)mp[a]++;
            else mp2[a]++;
        }
        vector<P> p;
        vector<P> p2;
        for(auto x:mp){
            p.push_back(make_pair(x.second,x.first));
        }
        for(auto x:mp2){
            p2.push_back({x.second,x.first});
        }
         p.push_back({0,0});
          p2.push_back({0,0});
        sort(all(p),greater<P>());
        sort(all(p2),greater<P>());
        if(p[0].second!=p2[0].second){
            cout<<n-p[0].first-p2[0].first<<endl;
        }else{
            lint x=max(p[0].first+p2[1].first,p[1].first+p2[0].first);
            cout<<n-x<<endl;
        }
  } 
      
      
    

  
          
  

Measured memory_bytes: 8824
from collections import deque

class GraphWeighted(): #directed
    def __init__(self,n,edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0]-1].append((e[1]-1,e[2]))
            self.deg[e[1]-1] += 1
    def bellman_ford(self,s,INF=10**18):
        dist = [INF for _ in range(self.n)]
        dist[s] = 0
        update = True
        for i in range(self.n):
            update = False
            for node, g in enumerate(self.graph):
                for adj,adjcost in g:
                    if dist[node] != INF and dist[node]+adjcost < dist[adj]:
                        dist[adj] = dist[node]+adjcost
                        update = True
                        if i == self.n-1:
                            tmp = adj
            if not update:
                return dist
        visited = [0 for _ in range(self.n)]
        visited[tmp] = 1
        stack = [tmp]
        while stack:
            node = stack.pop()
            for adj,c in self.graph[node]:
                if not visited[adj]:
                    visited[adj] = 1
                    stack.append(adj)
        if visited[-1]:
            return -1
        else:
            return dist

class Graph(): #directed
    def __init__(self,n,edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0]-1].append(e[1]-1)
            self.deg[e[1]-1] += 1
    def BFS(self,s):
        dist = [None for _ in range(self.n)]
        dist[s] = 0
        queue = deque([s])
        while queue:
            node = queue.popleft()
            for adj in self.graph[node]:
                if dist[adj] is not None:
                    continue
                dist[adj] = dist[node]+1
                queue.append(adj)
        return dist

INF = 10**18

N,M,P = map(int,input().split())
E = [tuple(map(int,input().split())) for _ in range(M)]

rev = []
for e in E:
    rev.append((e[1],e[0]))

R = Graph(N,rev)
reachable = R.BFS(N-1)

edge = []
for e in E:
    if reachable[e[0]-1] is None or reachable[e[1]-1] is None:
        continue
    edge.append((e[0],e[1],P-e[2]))

G = GraphWeighted(N,edge)
A = G.bellman_ford(0)

print(max(-A[-1],0) if A!=-1 else -1)

Measured memory_bytes: 54744
n,a,b=map(int,input().split())
mod=10**9+7
n_max=2*(10**5+1)
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
FI[n_max-1]=pow(F[n_max-1],mod-2,mod)
for i in reversed(range(n_max-1)):
  FI[i]=(FI[i+1]*(i+1))%mod
ans=pow(2,n,mod)
c=1
for i in range(b):
  c=(c*(n-i))%mod
  if i==a-1:
    c1=c
c2=c
c1=(c1*FI[a])%mod
c2=(c2*FI[b])%mod
print((ans-c1-c2-1)%mod)

  


Measured memory_bytes: 18804
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int N_ = N - K;
		int K_ = K - 1;
		int X = N_ / K_;
		String ZZ = sc.nextLine();
		if(N_ % K_ == 0) {
			System.out.println(X + 1);
		}else {
			System.out.println(X + 2);
		}
	}

}

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

#include <vector>

using namespace std;

const long long MOD = 998244353;

long long dp[3001][3001];

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

	int N, S;
	cin >> N >> S;

	vector<long long> numlist(N + 1, 0);
	for (int i = 1; i <= N; i++)
	{
		cin >> numlist[i];
	}

	long long result = 0;
	for (int i = 1; i <= N; i++)
	{
		dp[i - 1][0] = i;

		for (int j = S; j >= 0; j--)
		{
			dp[i][j] = dp[i - 1][j];
			if (j >= numlist[i])
			{
				dp[i][j] = (dp[i][j] + dp[i - 1][j - numlist[i]]) % MOD;
			}
		}

		result = (result + dp[i][S]) % MOD;
	}

	cout << result;

	return 0;
}


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

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

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l;
        string s,t;
        cin>>s>>t;
        ll dp[3003][3003];
        clr(dp,0);
        ll n=s.size(),m=t.size();
        dp[0][0]=0;
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));
                if(s[i-1]==t[j-1])
                    dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
            }
        }
        string ans;
        i=n;j=m;
        while(ans.size()!=dp[n][m])
        {
            if(i!=0&&dp[i][j]==dp[i-1][j])
            {
                i--;
                continue;
            }
            if(j!=0&&dp[i][j]==dp[i][j-1])
            {
                j--;
                continue;
            }
            if(dp[i][j]==dp[i-1][j-1]+1)
            {
                ans.pb(s[i-1]);
                i--;j--;
                continue;
            }
        }
        reverse(all(ans));
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
pair<int,int> a[200005];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        int k=(int)s[i]+n;
        if(k<=90){
            cout<<(char)(s[i]+n);
        }
        else{
            k-=90;
            cout<<(char)(65+k-1);
        }
    }
    return 0;
}


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

int main(){
  int n,x,y,b,p;

  cin >> n;
  while(n--){
    cin >> x >> y >> b >> p;
    cout << min(x*b+y*p, (x*max(b,5)+y*max(p,2))*4/5) << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

//最大公約数
ll gcd(ll a, ll b) {
	if(a*b == 0)return max(a, b);
	if (a < b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	if (a%b == 0)return b;
	return gcd(b, a%b);
}

int main(){

	int N;
	cin >> N;
	vector<ll> A, LGCD, RGCD;
	ll a;
	A.pb(0);
	for(int i = 0; i < N; i ++){
		cin >> a;
		A.pb(a);
	}
	A.pb(0);
	LGCD.pb(0);
	for(int i = 1; i <= N; i ++){
		LGCD.pb(gcd(A[i], LGCD[i - 1]));
	}
	LGCD.pb(0);
	RGCD.pb(0);
	for(int i = 1; i <= N; i ++){
		RGCD.pb(gcd(A[N - i + 1], RGCD[i - 1]));
	}
	RGCD.pb(0);
	reverse(all(RGCD));
	ll ans = 0;
	for(int i = 1; i <= N; i ++){
		//cout << RGCD[i + 1] << endl;
		ans = max(ans, gcd(LGCD[i - 1], RGCD[i + 1]));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N;
ll K;
vector<ll> v;

bool solve(int id){
  if(id < 0) return true;
  if(id >= N) return false;

  vector<vector<int>> dp(N+5, vector<int>(K+5,0));
  dp[0][0] = 1;
  int cnt = 0;
  rep(i,N){
    if(i == id) continue;
    rep(j,K+2){
      if(dp[cnt][j] == 1){
        dp[cnt+1][j] = 1;

        ll x = j+v[i];
        x = min(x, K+1);
        dp[cnt+1][x] = 1;
      }
    }
    cnt++;
  }

  rep(i,K+2){
    if(dp[N-1][i]==1 && i+v[id] >= K){
      if(i < K) return false;
    }
  }
  return true;
}

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

  rep(i,N){
    ll x;
    cin >> x;
    v.push_back(x);
  }
  sort(ALLOF(v));

  int lb = -1, ub = K+1;
  while(ub-lb>1){
    int mid = (lb+ub)/2;
    if(solve(mid)) lb = mid;
    else ub = mid;
  }
  cout << lb+1 << endl;
  /*
  int ret = 0;
  rep(i,N){
    ret += solve(i);
  }
  cout << ret << endl;
  */
  return 0;
}


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

int main(){
   string s,t;
   cin >> s >> t;
   int ans=0;
   rep(i,s.length()){
      if(s[i]!=t[i]){
         ans++;
      }
   }
   cout << ans << endl;
   return 0;  
}

Measured memory_bytes: 3844
n=int(input())
d=sorted(list(map(int,input().split())))
d.append(-1)
m=int(input())
t=sorted(list(map(int,input().split())))
x=0
f=0
for i in range(m):
    while d[x]!=t[i]:
        x+=1
        if x==n:
            print("NO")
            exit()
    x+=1
print("YES")



Measured memory_bytes: 111200
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string a;
  cin >> a;
  vector<string> week;
  week = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
  for (int i = 0; i < 7; i++) {
    if (a == week.at(i)) {
      cout << i + 1 << endl;
    }
  }
}

Measured memory_bytes: 3636
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 文字列の入力
		String s = sc.next();
		String[] S = s.split("");

		String ans = "Good";

		if(S[0].equals(S[1])||S[1].equals(S[2])||S[2].equals(S[3]))ans="Bad";

		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

const int64_t MOD = 1000000007;

void solve()
{
    int64_t N;
	std::cin >> N;
	std::vector<int64_t> A(N);
	for (auto& v : A)
	{
		std::cin >> v;
	}

	int64_t ans = 0;
	int64_t base = 1;
	for (int64_t d = 0; d < 60; d++)
	{
        int64_t even = 0;
		int64_t odd = 0;
        for (int64_t i = 0; i < N; i++)
		{
            if (A[i] & (((int64_t)1)<<d)) odd++;
            else even++;
        }
        int64_t add = (odd * even) % MOD * base % MOD;
        ans = (ans + add) % MOD;
        base = (base * 2) % MOD;
    }
	std::cout << ans << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 5524
#include <iostream>

#define DIV (1000000000 + 7)

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

  unsigned long long power = 1;
  while (N > 1)
  {
    power = (power * N) % DIV;
    --N;
  }

  std::cout << power << std::endl;

  return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

ll gcd(ll a,ll b){
  if(a%b == 0) return b;
  else return gcd(b,a%b);
}

int main(){
  int n,m;
  cin >> n >> m;
  vector<char> digit(n+1);
  for(int i=0;i<n+1;i++){
    digit[i] = '.';
  }
  int s;
  char c;
  for(int i=0;i<m;i++){
    cin >> s >> c;
    if(digit[s] == '.'){
      digit[s] = c;
      continue;
    }
    if(digit[s] != c){
      cout << -1 << endl;
      return 0;
    }
  }

  if(digit[1] == '0' && n != 1){
    cout << -1 << endl;
    return 0;
  }
  if(n == 1 && digit[1] == '.'){
    cout << 0 << endl;
    return 0;
  }
  string ans = "";
  for(int i=1;i<n+1;i++){
    if(digit[i] == '.'){
      if(i == 1) ans = ans + "1";
      else ans = ans + "0";
      continue;
    }
    ans = ans + digit[i];
  }
  cout << ans << endl;
  return 0;
}


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

const int N = 1e5+15;

vector<int> adj[N];

int par[N];

int sz[N];

int find(int a){
    if(a==par[a])return a;
    return par[a]= find(par[a]);
}

void merge(int a,int b){
    a = find(a),b = find(b);
    if(a==b)return;
    par[b]= a;
    sz[a]+=sz[b];
}

int type[N];

int color[N];

int dfs(int x,int c){
    
    
    if(color[x]!=-1){
        if(color[x]!=c)return 1;

        return 0;
    }
    color[x]= c;
    
    int u,i,ret = 0;
    for(i=0;i<adj[x].size();++i){
        u = adj[x][i];

        ret |= dfs(u,c^1);
    }
    return ret;
}

int num[3];
int main(){

    int n,m,i,a,b;
    cin>>n>>m;

    for(i=1;i<=n;++i)par[i]= i,sz[i]= 1;
    for(i=0;i<m;++i){
        scanf("%d%d",&a,&b);
        
        adj[a].push_back(b);
        adj[b].push_back(a);
        merge(a,b);
    }   

    vector<int> id;
    memset(color,-1,sizeof(color));

    
    for(i=1;i<=n;++i)
        if(find(i)==i)
            id.push_back(i);

    for(i=0;i<id.size();++i){
        a = id[i];
        
        if(sz[a]==1){
            type[a]= 0;
        }
        else {

            
            if(!dfs(a,0))
                type[a]= 1;
            else
                type[a]= 2;
        }
        ++num[type[a]];
    }       
    //0 --> sz1 , 1--> (0-1 graph) , 2--> cyle 포함하는 그래프
           
    
    
    long long ret = 0;
    
    for(i=0;i<id.size();++i){
        a = id[i];
            
        if(type[a]==0)
            ret+=n;
        else if(type[a]==1){

            ret+= (long long)sz[a]*num[0];

            ret+= (long long)num[1]*2;
            
            ret+= num[2];
        }   
        else{
            ret+= (long long)sz[a]*num[0];

            ret+= (long long)num[1] + num[2];
        }   
    }  
    cout<<ret<<endl;
}           


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

using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string a,b,c;
  cin >> a>>b>>c;
  string ret;
  ret.resize(3);
  ret[0] = a[0] ^ 32;
  ret[1] = b[0] ^ 32;
  ret[2] = c[0] ^ 32;
  cout << ret << "\n";
}



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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
int main(){
  int N;
  cin >> N;
  
  cout << "ABC" << N << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

ll N;

void judge(ll n, ll use, ll &counter){

    if(use==0b111) counter++;
    if(n*10+3<=N) judge(n*10+3,use|0b001,counter);
    if(n*10+5<=N) judge(n*10+5,use|0b010,counter);
    if(n*10+7<=N) judge(n*10+7,use|0b100,counter);

    else
    {
        return;
    }
    



}

int main(){
    cin>>N;
    ll res=0;
    judge(0,0,res);
    cout<<res<<endl;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int n;
	ll k;
	cin >> n >> k;
	vector<int> a(n);
	vector<P> p(n*2);
	REP(i, n) {
		cin >> a[i];
		p[i].first = a[i];
		p[i].second = i;
		p[i+n].first = a[i];
		p[i+n].second = i+n;
	}
	if (n == 1) {
		if (k % 2 == 0) {
			put("");
		} else {
			put(a[0]);
		}
		return 0;
	}
	sort(all(p));
	vector<int> b(n);
	REP(i, n * 2) {
		if (p[i].second < n) {
			int t = p[i].second;
			b[t] = p[i + 1].second;
		}
	}
	int t = 0;//n=1がやばい
	int now = 0;
	while (true) {
		now = b[now] + 1;
		if (now % n == 0) {
			t += now / n;
			break;
		}
		if (now > n) {
			t += now / n;
			now %= n;
		}
	}
	k %= t;
	vector<int> res;
	ll cnt = k * n;
	now = 0;
  	while (cnt) {
		int pre = now;
		now = b[now] + 1;
		if (now - pre > cnt) {
			now = pre;
			cnt--;
			res.push_back(a[now]);
			now++;
			now %= n;
			//break;
		} else {
			cnt -= now - pre;
			now %= n;
		}
		
	}
	put(res);
	return 0;
}


Measured memory_bytes: 10228