akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
struct edge{ll to,cost;};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vec A(n);
    rep(i,n) cin>>A[i];
    sort(all(A));
    if(A[0]==0){
        cout<<0;
        return 0;
    }
    ll ans=1,inf=1e18;
    rep(i,n){
        if(inf/ans>=A[i]) ans=ans*A[i];
        else{
            cout<<-1;
            return 0;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3972
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  printf("%d\n", a[0] * a[1] / 2);
  return 0;
}


Measured memory_bytes: 256
#e
H,W,M = map(int,input().split())
h = [None]*M
w = [None]*M
for i in range(M):
    a,b = map(int,input().split())
    h[i],w[i] = a-1,b-1

from collections import Counter
ch = Counter(h)
cw = Counter(w)

x_max=max(ch.values())
n_x_max = sum(ch[x]==x_max for x in range(H) if ch[x]==x_max)
y_max=max(cw.values())
n_y_max = sum(cw[y]==y_max for y in range(W) if cw[y]==y_max)
    
cnt =  sum(ch[h[i]]==x_max and cw[w[i]]==y_max for i in range(M))
if cnt < n_x_max*n_y_max:
    print(x_max+y_max)
else:
    print(x_max+y_max-1)


        

Measured memory_bytes: 193788
# -*- coding: utf-8 -*-
from collections import Counter

def count(s):
    cnt = 1
    res = 0
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            cnt += 1
        else:
            res += cnt//2
            cnt = 1
    res += cnt//2
    return res

s = input()
k = int(input())

c = Counter(s)

if len(c.keys())==1:
    print(len(s)*k//2)
    exit()

if s[0]!=s[-1]:
    print(count(s)*k)
    exit()

cs = count(s)
cs2 = count(s+s)
print((cs2-cs)*(k-1) + cs)

Measured memory_bytes: 38256
#include <iostream>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

bool solve() {
    int h, w;
    std::cin >> h >> w;
    if (h == 0) return false;

    auto grid = vec(h, vec(w, 0));
    for (auto& v : grid) {
        for (auto& x : v) std::cin >> x;
    }

    int ans = 0;
    for (int b = 0; b < (1 << h); ++b) {
        int sum = 0;

        for (int j = 0; j < w; ++j) {
            int cnt = 0;
            for (int i = 0; i < h; ++i) {
                cnt += (grid[i][j] ^ ((b >> i) & 1));
            }
            sum += std::max(cnt, h - cnt);
        }

        ans = std::max(ans, sum);
    }

    std::cout << ans << "\n";

    return true;
}

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

    while (solve()) {}

    return 0;
}



Measured memory_bytes: 3364
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int main(){

  string str,ans;

  cin >> str;

 for(int i=0;i<str.size();i++){
   ans[str.size()-1-i]=str[i];
}

 for(int i=0;i<str.size();i++){
   cout << ans[i];
   }
 cout << endl;

  return 0;
}

Measured memory_bytes: 1172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        long x = nl();
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = nl();
        }
        long ans = 0;
        if(a[0] > x){
            ans += (a[0] - x);
            a[0] = x; 
        }
        for (int i = 1; i < N; i++) {
            if(a[i] + a[i-1] > x){
                ans += a[i] - (x - a[i-1]);
                a[i] = x - a[i-1];
            }
        }
 
        out.println(ans);
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);

    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

int main()
{
    int a, b, c, d, e, k;

    cin >> a >> b >> c >> d >> e >> k;

    if(e-a > k)
        cout << ":(" << endl;
    else if (b-a > k || c-b > k || d-c > k || e-d > k)
        cout << ":(" << endl;
    else 
        cout << "Yay!" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w=sc.nextInt();
		int n=sc.nextInt();
		int[][] list=new int[n][2];
		int[] answer=new int[w];

		for(int i=0; i<n; i++){
			String str=sc.next();
			String[] ab=str.split(",");
			list[i][0]=Integer.parseInt(ab[0]);
			list[i][1]=Integer.parseInt(ab[1]);
		}




		sc.close();

		//MyBLAS.Calc.pMat(list);

		for(int i=1; i<=w; i++){
			int c=move(list,i);
			answer[c-1]=i;
		}

		for(int k=0; k<w; k++){
			System.out.println(answer[k]);
		}



	}

	public static int move(int[][] a,int b){

		for(int i=0; i<a.length; i++){
			if(b==a[i][0]){
				b=a[i][1];
			}else if(b==a[i][1]){
				b=a[i][0];
			}
		}
		return b;
	}
}

Measured memory_bytes: 26036
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

counter = 0
def main():
    N = II()
    def dp(number, has_seven, has_five, has_three):
        global counter
        if int(number+'7') <= N:
            if has_five and has_three:
                counter += 1
            dp(number+'7', True, has_five, has_three)
        if int(number+'5') <= N:
            if has_seven and has_three:
                counter += 1
            dp(number+'5', has_seven, True, has_three)
        if int(number+'3') <= N:
            if has_seven and has_five:
                counter += 1
            dp(number+'3', has_seven, has_five, True)
    dp('',False,False,False)
    print(counter)

main()

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n;;cin>>n;
    for(int i = 1; i<10; ++i){
        if(n%i==0&&n/i<10){cout<<"Yes"<<endl; return 0;}
    }
    cout<<"No"<<endl;return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a, b, c, d;
        a = Integer.parseInt(sc.next());
        b = Integer.parseInt(sc.next());
        c = Integer.parseInt(sc.next());
        d = Integer.parseInt(sc.next());
        int left = a + b;
        int right = c + d;
        if(left > right){
            System.out.println("Left");
        }else if(left < right){
            System.out.println("Right");
        }else{
            System.out.println("Balanced");
        }
        sc.close();
    }
}


Measured memory_bytes: 21716
#include<stdio.h>
#include<algorithm>
using namespace std;

struct Node {
	int location, l, r, d;
};

struct Point {
	int x, y, id;
};

int np = 0, n, c = 0, A[100];
Point P[500000];
Node T[500000];

bool X(const Point& a, const Point& b) { return a.x < b.x; }
bool Y(const Point& a, const Point& b) { return a.y < b.y; }

int make2DTree(int l, int r, int d) {
	if (l >= r) return -1;

	if (d % 2 == 0) sort(P + l, P + r, X);
	else sort(P + l, P + r, Y);

	int mid = (l + r) / 2, t = np++;
	T[t].location = mid; T[t].d = d;
	T[t].l = make2DTree(l, mid, d+1);
	T[t].r = make2DTree(mid + 1, r, d+1);

	return t;
}

void Find(int v, int sx, int tx, int sy, int ty) {
	int x = P[T[v].location].x, y = P[T[v].location].y;

	if (sx <= x && x <= tx && sy <= y && y <= ty) { A[c] = P[T[v].location].id; c++; }

	if (T[v].d%2 == 0) {
		if (T[v].l != -1 && sx <= x) Find(T[v].l, sx, tx, sy, ty);
		if (T[v].r != -1 && x <= tx) Find(T[v].r, sx, tx, sy, ty);
	}
	else {
		if (T[v].l != -1 && sy <= y) Find(T[v].l, sx, tx, sy, ty);
		if (T[v].r != -1 && y <= ty) Find(T[v].r, sx, tx, sy, ty);
	}
}

int main() {
	int q, sx, sy, tx, ty;
	scanf("%d", &n);;
	for (int i = 0; i < n; i++) { scanf("%d %d", &P[i].x, &P[i].y); P[i].id = i; }

	make2DTree(0, n, 0);

	scanf("%d", &q);
	for (int j = 0; j < q; j++) {
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		c=0; Find(0, sx, tx, sy, ty); sort(A, A+c);
		for (int i = 0; i < c; i++) printf("%d\n", A[i]); printf("\n");
	}
}



Measured memory_bytes: 15948
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	if(b%a==0){
		cout << a+b << endl;
	}else{
		cout << b-a << endl;
	}
}
	

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

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

bool b[6];

int main(){
    for(int i=0;i<5;i++){
        int n;
        cin >> n;
        b[n] = true;
    }
    for(int i=1;i<=5;i++){
        if(!b[i]) cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 3564
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<vector>
using namespace std;
int main(void){
	int a;
	double b;
	int c=0;
	double s;
	vector <int> q[19];
	int p=1;
	int n;
	int y;
	int g;
	int h;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)p = p * 2;
	for (int i = 0; i < p; i++){
		scanf("%d", &y);
		q[0].push_back(y);
	}
	for (int i = 0; i < n; i++){
		p = p / 2;
		for (int j = 0; j < p; j++){
			g = q[i][2 * j + 1];
			h = q[i][2 * j];
			if (g > h)q[i + 1].push_back(g - h);
			else if (g < h)q[i + 1].push_back(h-g);
			else q[i + 1].push_back(g);
		}
	}
printf("%d\n",q[n][0]);
	return 0;
}

Measured memory_bytes: 2292
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
		int A[] = new int[N];
		int B[] = new int[N];
		for(int i = 0 ; i < N ; ++i){
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
		}
		int dp[] = new int[H + 1];
		Arrays.fill(dp, Integer.MAX_VALUE / 2);
		dp[0] = 0;
		for(int i = 0 ; i < N ; ++i){
			int next[] = dp.clone();
			int a = A[i];
			int b = B[i];
			for(int h = 0 ; h <= H ; ++h){
				if(h + a >= H){
					next[H] = Math.min(next[H], dp[h] + b);
					next[H] = Math.min(next[H], next[h] + b);
				}else{
					next[h + a] = Math.min(next[h + a], dp[h] + b);
					next[h + a] = Math.min(next[h + a], next[h] + b);
				}
			}
			dp = next;
		}
		System.out.println(dp[H]);
//		System.out.println(Arrays.toString(dp));
	}
}


Measured memory_bytes: 45592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << a + b + c + 9 * max({a, b, c}) << endl;
}

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


public class Main{
    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        try{
            while(true){
                //initialize
                String[] inits = br.readLine().split(" " , 2);
                int people = Integer.valueOf(inits[0]);
                int questions = Integer.parseInt(inits[1]);

                if(people != 0 && questions != 0){
                    //initialize
                    int[] score = new int[questions];

                    for(int i = 0; i < people; i++){
                        String[] answers = br.readLine().split(" " , questions);
                        for(int j = 0; j < questions; j++){
                            if(answers[j].equals("1")){
                                score[j]++;
                            }
                        }
                    }

                StringBuilder result = new StringBuilder();

                for(int i = people; i >= 0; i--){
                    for(int j = 0; j < questions; j++){
                        if(score[j] == i){
                            result.append((j+1) + " ");
                        }
                    }
                }
                System.out.println(result.toString().substring(0,result.length()-1));

                }else break;
            }
        }catch(IOException e){
            System.out.println("Error!");
        }
    }
}

Measured memory_bytes: 40200
#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 ll long long
#define ld long double
#define fo(i,v,e) for(v=i;v<e;v++)
#define rfo(i,v,e) for(v=i;v>e;v--)
#define pb(x) push_back(x)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first 
#define se second
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define sz(x) (int)x.size()
#define ull unsigned long long
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pii>
#define vpl vector<pll>
ll mod = 1000000007;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define openfile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x);
#define fastio
#else
#define openfile
#define deb(x...)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#endif
void init()
{
    
}
void solve()
{
    ll n,i,j,comf = 0;cin>>n;
    vl arr(n),ans;
    fo(0,i,n)
    {
        cin>>arr[i];
    }
    sort(all(arr),greater<ll>());
    ans.push_back(arr[0]);
    j = 1;
    while(sz(ans)<n)
    {
        ans.push_back(arr[j]);
        ans.push_back(arr[j]);
        j++;
    }
    fo(0,i,n-1)
    {
        comf+=ans[i];
    }
    cout<<comf<<endl;
}
int main()
{
    init();
    // openfile;fastio;
    int T = 1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
}

Measured memory_bytes: 6928
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int solve(int n, int x){
    int res = 0;
    for(int i = 1; i <= n; ++i){
        for(int j = i+1; j <= n; ++j){
            for(int k = j+1; k <= n; ++k){
                if(i+j+k == x)res++;
            }
        }
    }

    return res;
}

int main(){
    vector<int> ans;
     while(true){
        int a, b;
        cin >> a >>  b;
        if(a == b && a == 0)break;
        ans.push_back(solve(a, b));
    }

    rep(i, ans.size())cout << ans[i] << endl;
}


Measured memory_bytes: 3080
program C;
    var N,x,i:longint;
    var a:array [1..120000] of longint;
    var u,v:longint;
    var ans:int64;
begin
    readln(N,x);ans:=0;
    for i:=1 to N do read(a[i]);
    for i:=2 to N do
    begin
        u:=a[i-1];v:=a[i];
        if u+v>x then
        begin
            if v>=u+v-x then a[i]:=x-u
            else
            begin
                a[i]:=0;
                a[i-1]:=x;
            end;    
            ans:=ans+u+v-x;
        end; 
    end;
    writeln(ans);
end.

Measured memory_bytes: 512
import java.util.*;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] cnt = new int[M];
    int ans = 0;
    for (int i = 0; i < N; i++) {
      int roop = sc.nextInt();
      for (int j = 0; j < roop; j++) {
        cnt[sc.nextInt() - 1]++;
      }
    }
    for (int i = 0; i < M; i++) {
      if (cnt[i] == N) {
        ans++;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
/*ll t;
cin>>t;
while(t--)
{
}*/
ll s,w;
cin>>s>>w;
if(w>=s)
cout<<"unsafe"<<endl;
else
cout<<"safe"<<endl;
return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int x,y;
    cin >> x >> y;
    
    rep(i,100) rep(j,100) if(i+j == x && 2*i+j*4==y){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 3576
#include<stdio.h>
#include<stdlib.h>
#define N 3
#define LIMIT 100
#define TRUE 1
#define FALSE 0
#define NIL -1

typedef struct{
  int map[N*N];
  int space,MD;
}PUZZLE;

int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};
char vector[4]={'r','u','l','d'};
int limit,path[LIMIT];
int MDT[N*N][N*N];
PUZZLE status,in;

int getHeur(PUZZLE);//マンハッタン距離の総和を計算し、その値をヒューリスティック値とする。
int dfs(int,int);//深さ優先探索
void getAns(PUZZLE);//IDA


int main(){
  int i,j,memory;
  PUZZLE p;
  //  for(i=0;i<LIMIT;i++)path[i]=NIL;
   
  
  for(i=0;i<N*N;i++){
    for(j=0;j<N*N;j++){
      MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
    }
  }

  for(i=0;i<N*N;i++){
    scanf("%d",&p.map[i]);
    if(p.map[i]==0)memory=i;
  }
  p.map[memory]=N*N;
  p.space=memory;

  getAns(p);
  // for(i=0;i<100;i++)printf("%d\n",path[i]);
  
  return 0;
}


int getHeur(PUZZLE p){
  int i;
  int h=0;//ヒューリスティック値
  for(i=0;i<N*N;i++){
    if(p.map[i]==N*N){
      continue;
    }
    h+=MDT[i][p.map[i]-1];
  }
  return h;
}

int dfs(int depth,int prev){
  int i;
  PUZZLE pTemp;
  int sx,sy,tx,ty,temp;

  
  if(status.MD==0) return TRUE;
  if(depth+status.MD>limit)return FALSE;

  sx=status.space/N;
  sy=status.space%N;

  for(i=0;i<4;i++){
    tx=sx+dx[i];
    ty=sy+dy[i];
    if(!(tx>=0&&tx<N&&ty>=0&&ty<N))continue;
    if(abs(prev-i)==2)continue;
    
    pTemp=status;
    status.MD+=MDT[sx*N+sy][status.map[tx*N+ty]-1];
    status.MD-=MDT[tx*N+ty][status.map[tx*N+ty]-1];
    temp=status.map[tx*N+ty];
    status.map[tx*N+ty]= status.map[sx*N+sy];
    status.map[sx*N+sy]=temp;
    status.space=tx*N+ty;
    if(dfs(depth+1,i)==TRUE){
      path[depth]=i;
      return TRUE;
    }
    status=pTemp;
  }
  return FALSE;
}



void getAns(PUZZLE p){
  int i,result=0;
  p.MD=getHeur(p);
  for(limit=p.MD;limit<=LIMIT;limit++){
    status=p;
    if(dfs(0,-100)==TRUE){
      for(i=0;i<limit;i++){
	//if(path[i]!=NIL)
	result++;      
      }
      printf("%d\n",result);
      return;
    }
  }
}




Measured memory_bytes: 2056
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    string S;
    cin >> S;
    int zero_start = 0;
    int one_start = 0;
    for (int i = 0; i < S.length(); i++) {
        if (i % 2 == 0) {
            if (S[i] == '0') one_start++;
            else zero_start++;
        } else {
            if (S[i] == '1') one_start++;
            else zero_start++;
        }
    }
    cout << min(one_start, zero_start) << endl;
    return 0;
}

Measured memory_bytes: 512
n,m = map(int,input().split())
conditions = [ tuple(map(int,input().split())) for _ in range(m)]
max_l = 0
min_r = float("INF")
for l,r in conditions:
  max_l = max(max_l,l)
  min_r = min(min_r,r)
if min_r < max_l:
  print(0)
else:
  print(min_r - max_l + 1)

Measured memory_bytes: 16624
/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int N = 200005;

int k = 60;
LL v[N],Qcnt;

void printVals()
{
    for (int i = 0; i <= 40; i++)
        cout << v[i] << " ";
    cout << endl;
}

void add(int a, int b, int c)
{
    Qcnt++;
#ifndef death
    cout << "+ " << a << " " << b << " " << c << endl;
#endif
    v[c] = v[a] + v[b];
    //printVals();
}


void ham(int a, int b, int c)
{
    Qcnt++;
#ifndef death
    cout << "< " << a << " " << b << " " << c << endl;
#endif
    v[c] = (v[a] < v[b]);
    //printVals();
}

int ind2(int i)
{
    return 2 + i;
}

void inv(int pos)
{
    ham(pos, ind2(0), pos);
}

void AND(int a, int b, int c)
{
    add(a, b, c);
    ham(ind2(0), c, c);
}

void mult01(int p, int b, int c)
{
    if (p == 0)
    {
        AND(ind2(0), b, 6666);
        add(6666, c, c);
        return;
    }
    add(666, 666, 6666+p);
    mult01(p - 1, b, 6666+p);
    add(6666+p, c, c);
    add(6666+p, c, c);
}

int main()
{
    fastIO;
    v[0] = 3;
    v[1] = 80;
    cout << 85835 << endl;
    
    add(0, 1, 2);
    ham(3, 2, 2);
    for (int i = 1; i < k; i++)
        add(2 + i - 1, 2 + i - 1, 2 + i);

    int pos1 = 1000;
    int pos2 = 2000;

    add(666, 666, 69);
    for (int i = k/2 - 1; i >= 0; i--)
    {
        add(69, ind2(i), pos1 + k);
        ham(0, pos1 + k, pos1 + i);
        inv(pos1 + i);
        mult01(i, pos1 + i, 69);
    }


    add(666, 666, 69);
    for (int i = k / 2 - 1; i >= 0; i--)
    {
        add(69, ind2(i), pos2 + k);
        ham(1, pos2 + k, pos2 + i);
        inv(pos2 + i);
        mult01(i, pos2 + i, 69);
    }
    add(666, 666, 69);


    for (int i = k / 2 - 1; i >= 0; i--)
        for (int j = k / 2 - 1; j >= 0; j--)
        {
            AND(pos1 + i, pos2 + j, 6666);
            mult01( i + j, 6666, 69);
        }

    add(666, 69, 2);

#ifdef death
    printVals();
    cout << Qcnt << endl;
#endif

    return 0;
}

/*



*/

Measured memory_bytes: 3120
from collections import deque
s=deque(list(input()))
n=int(input())
Q=[]
for i in range(n) :
    Q.append(list(input().split()))
 
count=0
for q in Q :
    if q[0]=="1" :
        count+=1
    elif q[0]=="2" and count%2==0 :
        if q[1]=="1" :
            s.appendleft(q[2])
        else :
            s.append(q[2])
    else :
        if q[1]=="1" :
            s.append(q[2])
        else :
            s.appendleft(q[2])
 
ans="".join(s)
if count%2==0 :
    print(ans)
else :
    print(ans[::-1])

Measured memory_bytes: 35008
#include <iostream>
#include <cmath>
#define INF (1e9)
using namespace std;

int main(){
  int a,b,c,x,y;
  while(1){
    x=y=INF;
    cin>>a>>b>>c;
    if(!a&&!b&&!c) break;
    for(int i=0;i<=100000000;i+=a){
      int x1,y1,k=abs(i-c);
      if(k%b==0) x1=i/a,y1=k/b;
      if(x1+y1<x+y) x=x1,y=y1;
      if(x1+y1==x+y&&x1*a+y1*a<x*a+y*a) x=x1,y=y1;
    }
    for(int i=0;i<=100000000;i+=b){
      int x1,y1,k=abs(i-c);
      if(k%a==0) x1=k/a,y1=i/b;
      if(x1+y1<x+y) x=x1,y=y1;
      if(x1+y1==x+y&&x1*a+y1*a<x*a+y*a) x=x1,y=y1;
    }
    cout<<x<<' '<<y<<endl;
  }
  return 0;
}

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

int N , K , sum;

int solve(int x , int y){
	if(x < y) return 0;
	if(x % y == 0) return x / y;
	int t = x / y + 1 , tms = (x - y * (x / y) + t - 1) / t;
	return solve(x - t * tms , y);
}

int main(){
	cin >> N; for(int i = 1 ; i <= N ; ++i){int x , y; cin >> x >> y; sum ^= solve(x , y);}
	puts(sum ? "Takahashi" : "Aoki");
	return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        int n, k; cin >> n >> k;
        vector<ll> freq(k);
        for (int a = 1; a <= n; a++) {
                freq[a % k]++;
        }

        ll ans = 0;

        ans = freq[0] * freq[0] * freq[0];
        if (k % 2 == 0) ans += freq[k / 2] * freq[k / 2] * freq[k / 2];

        cout << ans;
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 4700
N = int( input() )
S = input()

R = len( S.replace("W", "") ) 
L = 0
ret = L + R 
for i in range( N ):
  if S[ i ] == "E":
    R -= 1
  ret = min( ret, L + R )
  if S[ i ] == "W":
    L += 1

print( ret )

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

struct UnionFind {
  vector<int> data;

  UnionFind(int n){
    data.resize(n+1);
    fill(data.begin(), data.end(), -1);
  }

  int root(int x){
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  void unite(int x, int y){
    int rx=root(x);
    int ry=root(y);

    if(rx!=ry){
      if(data[ry] < data[rx])swap(rx, ry);

      data[rx]+=data[ry];
      data[ry]=rx;
    }
  }

  bool same(int x, int y){
    return root(x)==root(y);
  }

  int size(int x){
    return -data[root(x)];
  }
};

int main(){
  int n,k;cin>>n>>k;
  UnionFind uf(n);
  rep(i, k){
    int c,x,y;cin>>c>>x>>y;
    if(c==0)uf.unite(x, y);
    else cout<<(uf.same(x,y)? 1 : 0)<<endl;
  }

  return 0;
}



Measured memory_bytes: 3176
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	var A []int
	var count int

	for i := 0; i < N; i++ {
		A = append(A, nextInt())
	}

	m := make(map[int]bool)
	uniq := []int{}

	for _, ele := range A {
		if !m[ele] {
			count++
			m[ele] = true
			uniq = append(uniq, ele)
		}
	}

	if count == len(A) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 16384
#include<iostream>
using namespace std;
int main()
{
    int l;
    cin >> l;

    string s;
    cin >> s;

    int count=0;
    for(int i=1; i<(l-1) ; i++)
    {
        if(s[i-1] == 'A' && s[i] == 'B' && s[i+1] == 'C')
            count++;
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3588
import sys
import numpy as np
n = int(sys.stdin.readline())
a1 = list(map(int, sys.stdin.readline().split()))
a2 = list(map(int, sys.stdin.readline().split()))
maxc, maxi = 0, 0
for i in range(n+1):
    s = np.sum(a1[:i+1])+np.sum(a2[i:])
    if s > maxc:
        maxc, maxi = s, i
print(maxc)

Measured memory_bytes: 21512
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    a = tuple(map(int,input().split()))
    mod = 998244353

    v = max(a)
    inv = [0]*(v+1)
    inv[1] = 1
    for i in range(2,v+1):
        inv[i] = mod - (mod//i)*inv[mod%i]%mod
    #w
    w = [1]*(v+1)
    for i in range(2,v+1):
        w[i] = (inv[i]-w[i])%mod
        for j in range(i*2,v+1,i):
            w[j] = (w[j] + w[i])%mod


    #res
    res = 0
    num = [0]*(v+1)
    for e in a:
        num[e] += 1


    for d in range(1,v+1):
        s = 0
        t = 0
        for j in range(d,v+1,d):
            s = (s + num[j]*(j//d))
            t = (t + (num[j]*(j//d))*(j//d))
        AA = ((((s**2-t)//2)%mod*d)%mod)*d%mod
        res = (res + w[d]*AA%mod)%mod

    print(res%mod)

if __name__ == '__main__':
    main()

Measured memory_bytes: 101196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int N, K, A, B;

int main() {
	cin >> N >> K;
	for(int i = 1; i <= N; i++) {
		if(!(i % K)) A++;
		else if(!(K&1) && !(i % (K/2))) B++;
	}

	cout << ll(A)*A*A + ll(B)*B*B << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def Eratosthenes(n):
    from math import sqrt
    res = [True] * (n+1)
    res[0] = False
    res[1] = False
    
    for i in range(2,int(sqrt(n))+1):
        if res[i]:
            for j in range(2*i,n+1,i):
                res[j] = False
    return res

class BIT():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n+1)

    #bit_indexにxをO(log(n))で加算する
    def add(self,i,x):
        #if(i<=0 or i>n):return iに0以下の数字は代入しない
        while i <= self.n:
            self.bit[i] += x
            i += (i & -i)
    #bit_1 + bit_2 + …  + bit_n をO(log(n))で求める
    def sum(self,i):
        s = 0
        #iに0以下の数字は代入しない。
        while i > 0:
            s+=self.bit[i]
            i -= (i & -i)
        return s
    
    def rangesum(self,i,k):
        return self.sum(k) - self.sum(i)
    #a_1 + a_2 + … + a_i >= x となるような最小のiを求める(a_k >= 0)
    #xが0以下の場合は該当するものなし→0を返す
    def lower_bound(self,x):
        if x <= 0:
            return 0
        else:
            i = 0
            r = 1
            #最大としてありうる区間の長さを取得する
            #n以下の最小の二乗のべき(BITで管理する数列の区間で最大のもの)を求める
            while(r<self.n):
                r=r<<1
            len = r
            while len > 0:
                if(i+len<self.n and self.bit[i+len]<x):
                    x-=self.bit[i+len]
                    i+=len
                len = len >> 1
            return i+1

def main():
    max_num = 100000
    Q = I()
    S = Eratosthenes(max_num)
    bit = BIT(max_num)
    
    #bitの初期化
    for a in range(1,max_num, 2):
        b = (a+1) // 2
        if S[a] and S[b]:
            bit.add(a, 1)
    
    #queryの処理
    
    for q in range(Q):
        l, r = MI()
        print(bit.sum(r)-bit.sum(l-1))

if __name__ == "__main__":
    main()


Measured memory_bytes: 11464
// Problem : F - LCS
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
 
#define endl "\n"
#define int long long
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define rep(n) for(int i=0;i<(n);i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define INF (long long) 1e18
#define MOD 1000000007
#define MAX 200005;
string s,t;
int dp[3001][3001];
void solve(){
      cin>>s>>t;
      int n = s.length(),m = t.length();
      for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                  if(s[i]==t[j]){
                        dp[i+1][j+1] = dp[i][j] +1;
                  } else dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
            }
      }
      string ans;
      int i = n,j = m;
      while(i!=0&&j!=0){
            if(dp[i][j]==dp[i-1][j]) i--;
            else if(dp[i][j]==dp[i][j-1]) j--;
            else {
                  i--;j--;
                  ans.pb(s[i]);
            }
      }
      reverse(all(ans));
      cout<<ans<<endl;
}

int32_t main(){
      FAST
      int t=1;
      //cin>>t;
      while(t--)
            solve();
      return 0;
}




Measured memory_bytes: 73972
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

ll N,M,K;

#define MAX_N 200020
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r);
}

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

  ll ansx=0;
  for(ll i=1;i<=N;i++){
    ll tmp=i*(i-1)/2;
    //ll res=(N-i+1)*(N-i)/2;

    //ll po=(tmp+res)%MOD;
    ansx=(ansx+tmp)%MOD;
  }

  ll ansy=0;
  for(ll i=1;i<=M;i++){
    ll tmp=i*(i-1)/2;
    //ll res=(M-i+1)*(M-i)/2;

    //ll po=(tmp+res)%MOD;
    ansy=(ansy+tmp)%MOD;
  }

  //ansx=(ansx*(-MOD/2)%MOD);
  //ansy=(ansy*(-MOD/2)%MOD);

  ansx=ansx*M%MOD*M%MOD;
  ansy=ansy*N%MOD*N%MOD;

  ansx=(ansx+MOD)%MOD;
  ansy=(ansy+MOD)%MOD;

  ll ans=(ansx+ansy+MOD)%MOD;

  setComb();
  ll k=comb(N*M-2,K-2);

  ans=ans*k%MOD;
  cout<<ans<<endl;
  //cout<<(ansx+ansy+MOD)%MOD<<endl;


  return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll t1,t2;
  pll a, b;
  cin >> t1 >> t2;
  cin >> a.FI >> a.SE;
  cin >> b.FI >> b.SE;

  if(a.FI > b.FI){
    ll tmp = a.FI;
    a.FI = b.FI;
    b.FI = tmp;

    tmp = a.SE;
    a.SE = b.SE;
    b.SE = tmp;
  }


  ll ans = 0;
  if(a.FI*t1 + a.SE*t2 < b.FI*t1 + b.SE*t2)
    ans = 0;
  else if(a.FI*t1 + a.SE*t2 == b.FI*t1 + b.SE*t2){
    cout << "infinity" << endl;
    return 0;
  }
  else{
    ll bunsi = (b.FI-a.FI)*t1;
    ll bunbo = ((a.FI-b.FI)*t1 + (a.SE-b.SE)*t2);
    if(bunsi % bunbo == 0)
      ans = bunsi/bunbo*2;
    else
      ans = bunsi/bunbo*2+1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline

N=int(input())
A=tuple(map(int,input().split()))

mod=10**9+7
X=[0]*61
for x in A:
    i=0
    while x!=0:
        X[i]+=x&1
        x>>=1
        i+=1
ans=0
for x in A:
    x%=mod
    ans=(ans+x)%mod
ans=(ans*(N-1))%mod

for c,x in enumerate(X):
    if x>=2:ans=(ans-(x*(x-1)%mod)*pow(2,c,mod))%mod
print(ans)

Measured memory_bytes: 123132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;



int main() {
	int N, S;
	cin >> N;
	vector<int> B(N - 1);
	S = 0;

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

	S = B.at(0);

	for (int i = 1; i < N-1 ; i++) {
		S+= min(B.at(i-1), B.at(i));
	}
	
	S += B.at(N - 2);

	cout << S << endl;

	



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int k, ans = 0;
	cin >> k;

	for(int i=1;i<k;i++){
		for(int j=i+1;j<=k;j++){
			if(i%2==0 && j%2==1) ans++;
			else if(i%2==1 && j%2==0) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

long P = 10^^9+7;
long[10^^6+50] F, RF;

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

long inv(long x)
{
    return pow(x, P-2);
}

void init()
{
    F[0] = F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}

long comb(N)(N n, N k)
{
    if (k > n) return 0;
    auto n_b = F[n];    // n!
    auto nk_b = RF[n-k]; // 1 / (n-k)!
    auto k_b = RF[k];    // 1 / k!

    auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!

    return (n_b * nk_b_k_b) % P;  // n! / (n-k)!k!
}

Tuple!(N, N)[] prime_division(N)(N n)
{
    Tuple!(N, N)[] res;
    foreach (N i; 2..10^^6+1) {
        if (n%i == 0) {
            N cnt;
            while (n%i == 0) {
                ++cnt;
                n /= i;
            }
            res ~= tuple(i, cnt);
        }
    }
    if (n != cast(N)1) res ~= tuple(n, cast(N)1);
    return res;
}

void main()
{
    init();
    auto nm = readln.split.to!(long[]);
    auto N = nm[0];
    auto M = nm[1];
    auto ps = prime_division(M);
    long r = 1;
    foreach (p; ps) {
        r = r * comb(p[1]+N-1, N-1) % P;
    }
    writeln(r);
}

Measured memory_bytes: 15872
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    int n, q; cin >> n >> q;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    for(int j = 0; j < q; j++) {
        ll x; cin >> x;
        ll res = 0;

        int right = 0;
        ll sum = 0;
        for(int left = 0; left < n; left++) {
            while(right < n && sum + a[right] <= x) {
                sum += a[right];
                ++right;
            }

            res += (right - left);

            if(right == left) ++right;
            else sum -= a[left];
        }
        cout << res << endl;
    }
}



Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    int a;
    cin>>a;
    cout<<a + a*a + a*a*a<<"\n";
    return 0;
}

Measured memory_bytes: 3676
using System;
using System.Linq;

class D
{
	static void Main()
	{
		var n = long.Parse(Console.ReadLine());
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var a = read();
		var b = read();
		Console.WriteLine(Exchange(Exchange(n, a, b), b, a));
	}

	static long Exchange(long n, int[] a, int[] b)
	{
		var r = a.Zip(b, (p, q) => new[] { p, q }).Where(x => x[0] < x[1]).ToArray();
		var dp = new long[n + 1];
		for (int i = 1; i <= n; i++)
		{
			dp[i] = i;
			foreach (var x in r) if (x[0] <= i) dp[i] = Math.Max(dp[i], dp[i - x[0]] + x[1]);
		}
		return dp[n];
	}
}


Measured memory_bytes: 206688
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    int m=s.length(),n=t.length();
    int lcs[m+1][n+1];
    for(int i=0;i<=m;i++){
        for(int j=0;j<=n;j++){
            if(i==0||j==0) lcs[i][j]=0;
            else if(s[i-1]==t[j-1]){
                lcs[i][j]=lcs[i-1][j-1]+1;
            }
            else 
                lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
        }
    }
    string ans="";
    int i=m,j=n;
    while(i>0&&j>0){
        if(s[i-1]==t[j-1]) {
            ans=s[i-1]+ans;
            i--;j--;
        }
        else if(lcs[i-1][j]>lcs[i][j-1]){
            i--;
        }
        else {
            j--;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 35456