akhauriyash/Code-Regression huggingface dataset:
// WIP

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

// Utility
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
template<typename T> struct is_container {
template<typename C> static char test(typename C::const_iterator*); template<typename> static int test(...);
static bool const value = sizeof(test<T>(nullptr)) == sizeof(char) && !std::is_same<std::string, T>::value;
};
namespace std {
template<class ...Ts>        istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { i >> x.first >> x.second; return i; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
istream& operator>>(istream& i, T& x) { for (auto& y : x) { i >> y; } return i; }
}

// Debugging
#ifndef DEBUG
#define DEBUG 0
#endif
#define dbg(X) do { if (DEBUG) { cout << #X ": " << (X) << endl << flush; } } while (0)
#define dbg2(X) do { if (DEBUG) { cout << #X ":" << endl; for (auto& __x : (X)) { cout << __x << endl << flush; } } } while (0)
#define dbgv(...) do { if (DEBUG) { cout << "(" #__VA_ARGS__ "): " << make_tuple(__VA_ARGS__) << endl << flush; } } while (0)
namespace std {
template<class ...Ts>        ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; apply([&](auto&& y, auto&&... ys){ o << y; ((o << ", " << ys), ...); }, x); o << ")"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { o << tie(x.first, x.second); return o; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
ostream& operator<<(ostream& o, const T& x) { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
}

// Main
void mainCase() {
  int n;
  cin >> n;
  vector<int> ls(n);
  cin >> ls;
  vector<array<int, 2>> edges(n - 1);
  cin >> edges;

  vector<vector<int>> adj(n);
  for (auto [x, y] : edges) {
    x--; y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }

  // DFS with LIS DP
  vector<int> dp;
  vector<int> res(n);
  vector<bool> done(n);
  function<void(int)> dfs = [&](int v) {
    done[v] = 1;

    // Usual LIS DP with log
    auto it = lower_bound(ALL(dp), ls[v]);
    array<int, 3> log; // (push/update, index, value)
    if (it == dp.end()) {
      log = {0, -1, -1};
      dp.push_back(ls[v]);
    } else {
      int j = distance(dp.begin(), it);
      log = {1, j, dp[j]};
      dp[j] = ls[v];
    }
    res[v] = dp.size();

    // Usual DFS recurse
    for (auto u : adj[v]) {
      if (done[u]) { continue; }
      dfs(u);
    }

    // Restore LIS DP state
    if (log[0] == 0) {
      dp.pop_back();
    } else {
      dp[log[1]] = log[2];
    }
  };
  dfs(0);
  dbg(res);

  for (auto x : res) { cout << x << endl; }
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  mainCase();
  return 0;
}

/*
python misc/run.py atcoder/abc165/f/main.cpp --check

%%%% begin
10
1 2 5 3 4 6 7 3 2 4
1 2
2 3
3 4
4 5
3 6
6 7
1 8
8 9
9 10
%%%%
1
2
3
3
4
4
5
2
2
3
%%%% end
*/


Measured memory_bytes: 34464
N, M = map(int, raw_input().split())
ks_list = []
p_list = []
for i in range(M):
    ks_list.append(map(int, raw_input().split()))
p_list.append(map(int, raw_input().split()))

ans_count = 0
for i in range(2**N):
    
    cond = 0
    switch_list = [0]*N
    for j in range(N):
        switch_list[j]=(i>>j)&1

    for m in range(M):
        tmp_count = 0
        for k in range(ks_list[m][0]):
            if switch_list[ks_list[m][1+k]-1] == 1:
                tmp_count = tmp_count + 1

        if p_list[0][m] == (tmp_count % 2):
            cond = 1
        else:
            cond = 0
            break
    if cond == 1:
        ans_count = ans_count + 1
print ans_count


Measured memory_bytes: 2696
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
using namespace std;

int n;
int main() {
	cin >> n;
	ll ans = 0;
	rep(i, 1, n+1){
		if(i%3 == 0 || i%5 == 0) continue;
		ans += i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  string S[3] ;
  cinf(3,S) ;
  if(S[0][S[0].size() -1] == S[1][0] && S[1][S[1].size() -1] == S[2][0]){
    cout << "YES" << endl;
  }
  else
    cout <<"NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<complex>
using namespace std;
typedef long long int llint;
int main() {
	int a, b;
	cin >> a;
	if (a % 2 == 0) {
		cout << a << endl;
	}
	else {
		cout << a * 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int samecount(string S){
    int A = 0;
    for(int i = 0;i < S.size();i++){
        int QA = 1;
        for(int j = i ;j < S.size() - 1;j++){
           if(S.at(j) == S.at(j + 1)){
               QA++ ;
           }
           if(S.at(j) != S.at(j + 1)){
               break;
           }
           
        }
        A = max(QA,A);
    }
    return A;
}

int64_t minn(int64_t a,int64_t b){
    if(a >= b) return b;
    else return a;
}
int main(){
    string s;
    cin >>s;
   char ans = 'a';
   bool frag = 0;
   for(int i = 0;i < 27;i++){
       if(count(s.begin(),s.end(),'a'+i) == 0){
           ans = 'a' + i;
           break;
       }
       if(i == 25 && count(s.begin(),s.end(),'a'+i) != 0){
           frag = 1;
       }
   }
   if(frag)cout << "None" << endl;
   else cout << ans << endl;
}
    

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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b<c+d)cout<<"Right"<<endl;
  else if(a+b>c+d)cout<<"Left"<<endl;
  else cout<<"Balanced"<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict as dd
a = []
for _ in range(3):
  temp = list(map(int,input().split()))
  a.append(temp)
  
m1 = dd(int)
n = int(input())

for _ in range(n):
  temp = int(input())
  m1[temp]+=1
  
cnt=0
flag=0
for i in range(3):
  cnt=0
  for j in range(3):
    if m1[a[i][j]]==1:
      cnt+=1
  if cnt==3:
    print("Yes")
    flag=1
    break

if flag==0:
  for i in range(3):
    cnt=0
    for j in range(3):
      if m1[a[j][i]]==1:
        cnt+=1
        
    if cnt==3:
      print("Yes")
      flag=1
      break
      
if flag==0:
  cnt=0
  for i in range(3):
    if m1[a[i][i]]==1:
      cnt+=1
  if cnt==3:
    print("Yes")
    flag=1
    
if flag==0:
  cnt=0;j=2
  for i in range(3):
    if m1[a[i][j]]==1:
      cnt+=1
    j-=1
  if cnt==3:
    print("Yes")
    flag=1
    
if flag==0:
  print("No")
  
  


Measured memory_bytes: 38384
import java.util.*;

public class Main {
    long MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        int ans = 0;
        for(int i = 1; i < n - 1; i++) {
            int[] pp = new int[3];
            for(int j = 0; j < 3; j++) {
                pp[j] = p[i - 1 + j];
            }
            Arrays.sort(pp);
            if(pp[1] == p[i]) ans++;
        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 21844
a, b = map(int, input().split())


def cum_xor(x):
    if x < 0:
        return 0
    if x < 4:
        t = [0, 1, 3, 0]
        return t[x]
    p = 1
    while (p << 1) <= x:
        p <<= 1
    mask = p * ((x - p + 1) & 1)
    return mask | cum_xor(x - p)


print(cum_xor(b) ^ cum_xor(a - 1))


Measured memory_bytes: 38384
N = int(input())
A = list(map(int, input().split()))

MOD = 10**9 + 7
A_mod = [a%MOD for a in A]

R = sum(A_mod)

ans = 0

for a in A_mod:
    R -= a
    ans = (ans + a%MOD * R%MOD)%MOD
    
print(ans)

Measured memory_bytes: 31548
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

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

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) { return false; }
    }

    return true;
};

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int A, B, C;
    cin >> A >> B >> C;
    if (A > B) swap(A, B);
    YESNO(A < C && C < B, "Yes", "No");

    return 0;
}


Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int n = stdIn.nextInt();
        long k = stdIn.nextLong();
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = stdIn.nextInt();
        }
        int[] visited = new int[n];
        for(int i=0; i<n; i++){
            visited[i] = -1;
        }

        int townNumber = 1;
        int counter;
        for(counter = 0; counter<k; counter++){
            if(visited[townNumber - 1] != -1){
                long res = (k - counter) % (counter - visited[townNumber - 1]);
                for(int i=0; i<res; i++){
                    townNumber = a[townNumber - 1];
                }
                System.out.println(townNumber);
                return;
            }
            visited[townNumber - 1] = counter;
            townNumber = a[townNumber - 1];
        }

        System.out.println(townNumber);
    }
}

Measured memory_bytes: 59800
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if(N>=64) {
			System.out.println(64);
		}else if(N>=32) {
			System.out.println(32);
		}else if(N>=16) {
			System.out.println(16);
		}else if(N>=8) {
			System.out.println(8);
		}else if(N>=4) {
			System.out.println(4);
		}else if(N>=2) {
			System.out.println(2);
		}else {
			System.out.println(1);
		}
	}
	public static int sample() {
		return 1;
	}

}


Measured memory_bytes: 21972
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, _ := strconv.Atoi(input())
	a := make([]int, 2*n)
	for i := 0; i < 2*n; i++ {
		a[i], _ = strconv.Atoi(input())
	}
	sort.Ints(a)
	ans := 0
	for i := 0; i < n; i++ {
		ans += a[2*i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::io::*;
use std::str::FromStr;

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

#[allow(dead_code)]
fn readu() -> usize {
    read::<usize>()
}

#[allow(dead_code)]
fn readi() -> i32 {
    read::<i32>()
}

fn main() {
    input! {
        r: usize,
    }
    println!("{}", 3 * r * r);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000007
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;


bool bet(int i , int a ,int b)
{
     int sum =0;

     while(i)
     {
         sum+=i%10;
         i/=10;
     }
     if(sum<a||sum>b)
        return false;
     return true;
}
int main(){
   std::ios::sync_with_stdio(false);
   cin.tie(0);
int n,a,b;
cin>>n>>a>>b;

int ans=0;
for(int index = 1 ;index <= n ;index++)
    if(bet(index,a,b))
    ans+=index;

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


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using namespace boost::math;
typedef long long i64;

i64 gcd_z(i64 x, i64 y) {
    if (x == -1) return y;
    if (y == -1) return x;
    else return gcd(x, y);
}


int main(void) {
    i64 n, ans;
    cin >> n;
    vector<i64> a(n), l(n), r(n);
    for (i64 i = 0; i < n; i++) cin >> a[i];
    l[0] = a[0]; r[n - 1] = a[n - 1];
    for (i64 i = 1; i < n; i++) l[i] = gcd(l[i - 1], a[i]);
    for (i64 i = n - 2; i >= 0; i--) r[i] = gcd(r[i + 1], a[i]);
    ans = r[1];
    for (i64 i = 1; i < n - 1; i++) {
        ans = max(ans, gcd(l[i - 1], r[i + 1]));
    }
    ans = max(ans, l[n - 2]);
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

string S, T;

int main() {
    cin >> S >> T;

    string target = S + S;
    if (target.find(T) == string::npos) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

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

using namespace std;
int n;

vector<long long int> v;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
	{
		long long int a;scanf("%lld",&a);
		v.push_back(a);
	}
	for(int i=1;i<n;i++){
		v[i]+=v[i-1];
	}
	long long int sum=v.back();
	long long int f=LLONG_MAX;
	for(int i=0;i<v.size();i++){
		f=min(f,abs(sum-v[i]-v[i]));
	}
	printf("%lld\n",f);
	return 0;
}


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

int n,m,x[100005],dis[100005],ans;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for(int i = 0; i < m; i++) cin >> x[i];
	sort(x,x+m);
	for(int i = 0; i < m - 1; i++) 
		dis[i] = x[i+1] - x[i];
	sort(dis,dis+m-1);
	for(int i = 0; i < m - n; i++)
		ans += dis[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
using ll = long long;

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(a >= k){
        cout << k << endl;
        return 0;
    }
    if(a + b >= k){
        cout << a << endl;
        return 0;
    }
    if(a + b + c >= k){
        cout << a + (-1)*(k-a-b) << endl;
        return 0;
    }
}

Measured memory_bytes: 3512
n = int(input())
s = list(input())
type = "A"
count = 0
for char in s:
    if char == "A":
        type = "B"
    elif char == "B" and type == "B":
        type = "C"
    elif char == "C" and type == "C":
        count += 1
        type = "A"
    else:
        type = "A"
print(count)

Measured memory_bytes: 38256
def is_palindrome(s):
    # str(reversed(s))
    return s == s[::-1]

S = input().strip()
N = len(S)
Sl = S[:(N-1)//2]
Sr = S[(N+1)//2:]
# print(Sl, Sr)
print('Yes' if is_palindrome(S) and is_palindrome(Sl) and is_palindrome(Sr) else 'No')



Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;
 
int main()
{
 string s,t;
 int c=0;
 cin >> s >> t;
 for(int i=0;i<3;i++){
   if(s[i]==t[i]) c++;
 }    
 cout << c;
 return 0;
}


Measured memory_bytes: 256
A, B, C, K = map(int, input().split())

x = 0
if K >= A:
    x += A
    K = K - A
    #print(K)
    if K >= B:
        K = K - B
        #print(K)
        if K >= C:
            x += -1 * C
        else:
            x += -1 * K
    else:
        pass
else:
    x += K
print(x)

Measured memory_bytes: 9208
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ShekharN
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] c = new int[n - 1];
            int[] s = new int[n - 1];
            int[] f = new int[n - 1];
            for (int i = 0; i < n - 1; i++) {
                c[i] = in.nextInt();
                s[i] = in.nextInt();
                f[i] = in.nextInt();
            }
            int[] result = new int[n - 1];
            for (int i = 0; i < n - 1; i++) {
                result[i] = s[i] + c[i];
                for (int j = i + 1; j < n - 1; j++) {
                    int wait = 0;
                    if (result[i] < s[j])
                        wait = s[j] - result[i];
                    else {
                        if (result[i] % f[j] != 0)
                            wait = f[j] - result[i] % f[j];
                    }
                    result[i] += wait + c[j];
                }
                out.println(result[i]);
            }
            out.println(0);
        }

    }

    static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        public String nextString() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,K,a=0;
  cin>>N>>K;
  vector<int> A(N);
  for(int &i:A){
    cin>>i;
    a=max(a,i);
  }
  int mn=0,mx=a;
  while(mx-mn>1){
    int n=(mn+mx)/2,sum=0;
    if(n==0)break;
    for(int i=0;i<N;i++)sum+=(A[i]+n-1)/n-1;
    if(sum<=K)mx=n;
    else mn=n;
  }
  int sum=0;
  if(mn==0){
    cout<<mx<<endl;
    return 0;
  }
  for(int i=0;i<N;i++)sum+=(A[i]+mn-1)/mn-1;
  if(sum<=K)cout<<mn<<endl;
  else cout<<mx<<endl;
}

Measured memory_bytes: 4664
#include <stdio.h>
#include <cstring>

const int MAXN = 100002;

char s[MAXN];

int main ()
{

	scanf("%s", s);
	int n = strlen(s);

	if(s[n - 1] == '1' || s[0] == '0') {
		printf("-1");
		return 0;
	}
	bool rau = false;
	for(int i = 0; i < n / 2; i++) {
		if(s[i] != s[n - 2 - i]) {
			rau = true;
		}
	}
	if(rau) {
		printf("-1");
		return 0;
	}
	printf("1 2\n");
	int nod = 2;
	for(int i = 1; i < n - 1; i++) {
		printf("%d %d\n", i + 2, nod);
		if(s[i] == '1') {
			nod = i + 2;
		}
	}

	// 7 1011010
	// 8 110101100.
	return 0;
}

Measured memory_bytes: 1408
import java.io.*;
class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		
		String str=br.readLine();
		double r=Double.parseDouble(str);
		
		System.out.println(String.format("%.6f",r*r*Math.PI)+" "+String.format("%.6f",2*r*Math.PI));
	}
}

Measured memory_bytes: 24664
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
const int MAXN = 1e5 + 10;
int N, S;
int X[MAXN]; ll P[MAXN];
ll ans;

int main() {
	register int i;
	scanf("%d%d", &N, &S);
	for(i = 1; i <= N; ++i)
		scanf("%d%lld", X + i, P + i);
	int l = 1, r = N, las = 0;
	while(X[l] <= S && S <= X[r]) {
		if(P[l] >= P[r]) P[l] += P[r], ans += (X[r--] - X[l]) * (las != 1), las = 1;
		else P[r] += P[l], ans += (X[r] - X[l++]) * (las != 2), las = 2;
	}
	if(l <= r) {
		if(X[l] <= S) ans += S - X[l];
		else ans += X[r] - S;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1280
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = input()
    result = [abs(int(N[i:i + 3]) - 753)for i in range(len(N) - 2)]
    result.sort()
    print(result[0])


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

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

    int in[n];
    int ans[n];
    int temp = 0;

    rep(i, n) {
        cin >> temp;
        in[temp - 1] = i + 1;
    }

    rep(i, n) { cout << in[i] << " "; }
    cout << endl;
}

Measured memory_bytes: 1152
n = gets.to_i
a = gets.split(" ").map(&:to_i)
gets
b = gets.split(" ").map(&:to_i)

i = 0
list = {}

1.upto(n) do |i|
  if i == n then
    break
  end
  a.combination(i).each do |num|
    list[num.inject(:+)] = nil
  end
end

b.each do |num|
  puts list.has_key?(num) ?  "yes" : "no"
end

Measured memory_bytes: 9512
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double total = 0.0;
        for (int i = 0; i < N; i++) {
        	total += 1.0/sc.nextDouble();
        }
        System.out.println(1.0/total);
    }
}

Measured memory_bytes: 25300
def f(a,b): return [Card[a][0], Card[b][1]]
n = int(raw_input())
Card = [[] for _ in [0]*n]
Cost = {}
for i in range(n):
  Card[i] = map(int, raw_input().split())
  Cost[(i, i)] = 0
for i in range(1, n):
  for j in range(0, n-i):
    a = j+i
    Cost[(j, a)] = min([reduce(lambda a,b: a*b, f(j, k) + f(k+1, a)) + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)])
print Cost[0, n-1]

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

typedef long long ll;
ll mod = 1000000007;

ll power(ll x, ll y)
{
    ll res = 1;
    x = x%mod;
    while (y)
    {
        if (y&1) res = ((res%mod)*(x%mod))%mod;

        y>>=1;
        x = ((x%mod)*(x%mod))%mod;
    }
    return res;
}

int main(){

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

    ll n;
    cin >> n;
    ll count=1;

    ll x;
    cin >> x;
    ll minElement = x;

    n=n-1;
    
    while (n>0)
    {
        cin >> x;
        if(x<=minElement) count++;
        minElement=min(x,minElement);
        n--;
    }
    cout << count << "\n";

    return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for(int i=1; i>0; i++)
		{
			String str = br.readLine();
			int num = Integer.parseInt(str);
			if(num==0)
				break;
			System.out.println("Case "+ i + ": " + num);
		}

	}
}

Measured memory_bytes: 27104
h,w = map(int,input().split())
if h%3 == 0 or w%3 == 0:
  print(0)
else:
  ret = h*w
  for hi in range(max(1,h//3-10),min(h,h//3+10)):
    s1 = hi*w
    for wi in range(max(1,w//2-10),min(w,w//2+10)):
      s2 = (h-hi)*wi
      s3 = (h-hi)*(w-wi)
      d = max(abs(s1-s2),abs(s2-s3),abs(s3-s1))
      ret = min(ret,d)
  for wi in range(max(1,w//3-10),min(w,w//3+10)):
    s1 = wi*h
    for hi in range(max(1,h//2-10),min(h,h//2+10)):
      s2 = (w-wi)*hi
      s3 = (w-wi)*(h-hi)
      d = max(abs(s1-s2),abs(s2-s3),abs(s3-s1))
      ret = min(ret,d)
  ret = min(ret,h,w)
  print(ret)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define int long long

signed main(){
	int n, m;
	cin >> n >> m;
	cout << n*(n - 1)/2 + m*(m - 1)/2 << endl;
	return 0;
}

Measured memory_bytes: 3512
import sys
sys.setrecursionlimit(1000000)

class Node:
    def __init__(self, parent = -1, left = -1, right = -1, depth = 0):
        self.parent = parent
        self.left = left
        self.right = right
        self.depth = depth
    
def print_node(i):
    global node
    print("node " + str(i) + ": ", end = "")
    print("parent = " + str(node[i].parent) +", ", end = "")
    print("depth = " + str(node[i].depth) + ", ", end = "")
    if node[i].parent == -1:
        print("root, [", end = "")
    elif node[i].left != -1:
        print("internal node, [", end = "")
    else:
        print("leaf, [", end = "")
    if node[i].left != -1:
        print(str(node[i].left), end = "")
        j = node[i].left
        while node[j].right != -1:
            j = node[j].right
            print(", " + str(j), end = "")
    print("]")
            

n = int(input())
node = [Node() for i in range(n)]
def input_depth(i, n):
    global node
    node[i].depth = n
    if node[i].right != -1:
        input_depth(node[i].right, n)
    if node[i].left != -1:
        input_depth(node[i].left, n + 1)

for i in range(n):
    p, k, *c = list(map(int, input().split()))
    if k > 0:
        node[p].left = c[0]
    for j in range(k):
        node[c[j]].parent = p
        if j != k - 1:
            node[c[j]].right = c[j + 1]

for i in range(n):
    if node[i].parent == -1:
        input_depth(i, 0)
        break

for i in range(n):
    print_node(i)

    


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

int main(){
  int h,w;
  int count=0;
  vector<int> dx={0,1,0,-1};
  vector<int> dy={1,0,-1,0};  
  cin >> h >> w;
  vector<string> s(h);
  for(int i=h-1;i>=0;i--) cin >> s.at(i);
  
  vector<vector<int>> map(h,vector<int>(w,0));
  bool can = false; // result
  bool can2 = true;
  bool can3 = true;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s.at(i).at(j) == '#'){
        can2 = false;
        bool tmp = false;
        for(int k=0;k<4;k++){
          if(i+dy.at(k)<h && i+dy.at(k) >=0 && j+dx.at(k)<w && j+dx.at(k) >=0){
            if(s.at(i+dy.at(k)).at(j+dx.at(k)) == '#') tmp = true;
          }
        }
        if(tmp != true) can3 = false;
      } //roop if #
    } //roop j
  } // roop i
  if((can2 == false && can3 == true) or (can2 == true && can3 == true)) can =true;
  if(can == true) cout << "Yes" << endl;
//  if(can==true && can2 == true) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int i;
	char serves[200];
	int a_score,b_score;
	while(1) {
		scanf("%s",serves);
		if(serves[0]=='0')break;
		a_score=b_score=0;
		for(i=1;serves[i];i++) {
			if(serves[i]=='A')a_score++;
			else if(serves[i]=='B')b_score++;
		}
		if(a_score>b_score)a_score++;
		else if(a_score<b_score)b_score++;
		printf("%d %d\n",a_score,b_score);
	}
	return 0;
}

Measured memory_bytes: 0
s = list(x for x in input())
s2 = s + s
s_num = s.count(s[0])
count = 0
count2 = 0
k = int(input())

for i in range(len(s)-1):
  if s[i] == s[i+1]:
    s[i+1] = 0
    count += 1
for i in range(len(s2)-1):
  if s2[i] == s2[i+1]:
    s2[i+1] = 0
    count2 += 1

if len(s) == 1:
  print(k//2)
elif s_num == len(s):
  if k%2 == 0:
    print(count2*(k//2))
  else:
    print(count2*(k//2)+count)
else:
  print((count2-count)*(k-1) + count)

Measured memory_bytes: 3064
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve(int tc)
{
	int n;
	cin >> n;
	v32 arr(n, 0);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int x = 0;
	for (int i = 0; i < n; i += 2)
		x ^= (arr[i] ^ arr[i + 1]);
	for (int i = 0; i < n; i++)
		cout << (x ^ arr[i]) << " ";
	cout << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve(tc);
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 3992
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;

long long MOD = 1000000007;
long long dp[100005][4];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int N;
	cin >> N;

	vector<int>A(N);
	for (int i = 0; i < N; ++i)cin >> A[i];
	vector<int>B(N);
	for (int i = 0; i < N; ++i)cin >> B[i];
	vector<int>C(N-1);
	for (int i = 0; i < N-1; ++i)cin >> C[i];

	int ans = 0;
	int before = 0;
	for (int i = 0; i < N;++i) {
		int current = A[i];
		ans += B[current - 1];
		if (i != 0 && before == current - 1)ans += C[before - 1];
		before = current;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
d=[0]*4
for i in range(n):
    s=input()
    if s=="AC":
        d[0]+=1
    elif s=="WA":
        d[1]+=1
    elif s=="TLE":
        d[2]+=1
    else:
        d[3]+=1
print("AC x",d[0])
print("WA x",d[1])
print("TLE x",d[2])
print("RE x",d[3])

Measured memory_bytes: 69968
#include<bits/stdc++.h>
using namespace std;
#define deb(x)   cout<<"> "<<#x<<" : "<<x<<endl;
#define deb2(x,y)cout<<"> "<<#x<<"->"<<x<<"  "<<#y<<"->"<<y<<endl;
#define LINE   cout << "--- LINE NO : " << __LINE__ <<"  ---"<< endl;
#define pnr(a)   for(auto x:a){cout<<x<<" ";}cout<<endl;
#define pnr2(a)  for(auto x:a){cout<<x.first<<" "<<x.second<<endl;}
#define   pi       2*acos(0.0)
#define   inf      (int)1e18
const int mod =    1e9 + 7, mxn =    2e5 + 5;

#define   vt       vector
#define   ff       first
#define   ss       second
#define   int      long long
#define   db       long double
#define   pii      pair<int,int>
#define   Maxpq(x) priority_queue<x>
#define   Minpq(x) priority_queue<x,vt<x>,greater<x>>

#define   pb       push_back
#define   si(x)    (int)x.size()
#define   all(x)   x.begin(),x.end()
#define   mem(a,x) memset(a,x,sizeof(a))
#define   rep(n)    for(int i =0 ; i<n ; i++)
#define   forr(i,n) for(int i=0;i<n;i++)
#define   FOR(a)   for(auto& x :  a )

int mainx() {
    int a , b , c , d , x , y , ans = 1;
    cin >> a >> b >> c >> d;
    if (a >= 0 and c >= 0)
    {
        cout << b*d << endl;
    }
    else
    {
        int ans = -inf;
        ans = max(ans , a * c);
        ans = max(ans , b * d);
        // ans = max(ans , 0);
        ans = max(ans , c * b);
        ans = max(ans , d * a);

        if (a <= 0 and 0 <= b)
            ans = max(ans , 0LL);
        if ( c <= 0 and d >= 0)
            ans = max(ans , 0LL);

        cout << ans << endl;

    }
    return 0;
}


bool cmp(pii &a , pii &b) {
    if (a.ff < b.ff)return true;
    if (a.ff == b.ff )return a.ss < b.ss;
    return false;
}
inline void INCLUDE() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
//freopen("out.txt","w",stdout);
#endif
}
int32_t main() {

    //INCLUDE();

    ios::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    //cout << fixed << setprecision(20);

    int tt = 1;
    //cin>>tt;
    for (int t = 1 ; t <= tt ; t++ )
    {
        // cout<<"Case #"<<t<<": ";
        mainx();
    }
    return 0 ;
}



Measured memory_bytes: 3660
N = int(input())

lst_A = input().split()

after = 0

for i in range(len(lst_A)):
    lst_A[i] = float(lst_A[i])
    after += lst_A[i]

after = after/2

i = 0
while 1:
    before = after
    after -= lst_A[i]
    if after <= 0:
        break
    i += 1

after = abs(after)

if after < before:
    ans = int(after * 2)
else:
    ans = int(before * 2)

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

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

int H;
int A[500001];

int main()
{
  int i;

  scanf("%d", &H);
  for(i=1;i<=H;i++)
    {
      scanf("%d", &A[i]);
    }

  buildMaxHeap(A);

  for(i=1;i<=H;i++)
    {
      printf(" %d", A[i]);
    }
  printf("\n");
  
  return 0;
}

void maxHeapify(int A[], int i)
{
  int l, r, largest, swap;
  l = 2 * i;
  r = 2 * i + 1;

  if(l <= H && A[l] > A[i])largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest])largest = r;

  if(largest != i)
    {
      swap = A[i]; A[i] = A[largest]; A[largest] = swap;
      maxHeapify(A, largest);
    }
}

void buildMaxHeap(int A[])
{
  int i;
  for(i=H/2;i>=1;i--)
    {
      maxHeapify(A, i);
    }
}




Measured memory_bytes: 3808
package main

import (
	"fmt"
	"strings"
)

func main() {
	var input string
	fmt.Scan(&input)
	var input_array []string
	input_array = strings.Split(input,"")
	count := 0
	for _,number := range input_array{
		if number == "1"{
			count+=1
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		for (int i = 1; i < 2000; i++) {
			if (i * 8 / 100 == a && i * 10 / 100 == b) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	VL a(5);
	int k;
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	cin >> k;
	for (int i = 1; i < 5; i++) {
		if (a[i] - a[0] > k) {
			cout << ":(" << endl;
			return 0;
		}
	}
	cout << "Yay!" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    string s;
    cin>>n>>s;
    ll x=0,y=0;
    ll a;
    for(int i=0;i<n;i++){
        a=s[i]-'a';
        if(a>=0&&a<26){
            if(a>12){
                x--;
            }
            else{
                x++;
            }
        }else{
            a=s[i]-'A';
            if(a>12){
                y--;
            }
            else{
                y++;
            }
        }
    }
    string ans="";
    if(x>0){
        for(int i=0;i<x;i++){
            ans+="a";
        }
    }
    else{
        x=-x;
        for(int i=0;i<x;i++){
            ans+="z";
        }
    }

    if(y>0){
        for(int i=0;i<y;i++){
            ans+="A";
        }
    }
    else{
        y=-y;
        for(int i=0;i<y;i++){
            ans+="Z";
        }
    }
    cout << (ans.length())<<endl;
    cout << ans<<endl;
    return 0;
}




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

class D
{
	static void Main()
	{
		var M = 1000000007;
		var t = 1L;
		var p = Enumerable.Range(0, 60).Select(i => i == 0 ? t : t *= 2).ToArray();

		var b = new long[60];
		var n = int.Parse(Console.ReadLine());
		foreach (var x in Console.ReadLine().Split().Select(long.Parse))
			for (int i = 0; i < 60; i++)
				if ((x & p[i]) > 0) b[i]++;
		Console.WriteLine(b.Select((x, i) => x * (n - x) % M * (p[i] % M)).Sum() % M);
	}
}


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

const int INF = 100000000;

typedef pair<int, int> P;

char maze[50][50];
int H, W;
int sy, sx;
int gy, gx;
int cnt;

int d[50][50];

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

int bfs(){
  queue<P> que;
  for(int i = 0; i < H; i++)
    for(int j = 0; j < W; j++) d[i][j] = INF;
  que.push(P(sy, sx));
  d[sy][sx] = 0;
  
  while(que.size()){
    P p = que.front();
    que.pop();
    if(p.first == gy && p.second == gx) break;
    for(int i = 0; i < 4; i++){
      int ny = p.first + dy[i], nx = p.second + dx[i];
      if(0 <= ny && ny < H && 0 <= nx && nx < W && maze[ny][nx] != '#' && d[ny][nx] == INF){
        que.push(P(ny, nx));
        d[ny][nx] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[gy][gx];
}

void solve(){
  sy = 0, sx = 0;
  gy = H-1, gx = W-1;
  int res = bfs();
  if(res == INF) cout << -1 << endl;
  else cout << cnt - res - 1 << endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  cnt = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> maze[i][j];
      if(maze[i][j] == '.') cnt++;
    }
  }
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i, N, K, h[100000], count = 0;

	scanf("%d %d", &N, &K);

	for (i = 0; i < N; i++) {
		scanf("%d", &h[i]);
		if (K <= h[i]) {
			count++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
using namespace std;
int main(){
    int n;
    int cnt[100100];
    memset(cnt,0,sizeof(cnt));
    cin>>n;
    REP(i,n){
        int a,b;
        cin>>a>>b;
        cnt[a]++;cnt[b+1]--;
    }
    int ans=0;
    REP(i,100000)cnt[i+1]+=cnt[i];
    REP(i,n+2){
        if(cnt[i]+1>=i){
            ans=i-1;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3460
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX + 1];

int solve() {
    int ans = 0;
    
    bool V[MAX];
    for (int i = 0; i < n; i++) {
        B[i] = A[i];
        V[i] = false;
    }
    sort(B, B + n);
    for (int i = 0; i < n; i++) T[B[i]] = i;
    for (int i = 0; i < n; i++) {
        if (V[i]) continue;
        int cur = i;
        int S = 0;
        int m = VMAX;
        int an = 0;
        while (1) {
            V[cur] = true;
            an++;
            int v = A[cur];
            m = min(m, v);
            S += v;
            cur = T[v];
            if (V[cur]) break;
        }
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
    }
    return ans;
}

int main() {
    cin >> n;
    s = VMAX;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        s = min(s, A[i]);
    }
    int ans = solve();
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
 
typedef pair<char,int> P;
vector<P> A,B,C;
void input(vector<P> &a){
  while( true ){
    char c; cin >> c;
    if( c == '$' ) return;
    int l; cin >> l;
    a.push_back( P(c,l) );
  }
}
int main(){
  input(A);  input(B);  input(C);
  vector<P> res;
  for(int i=0;i<(int)A.size();i++){
    if( A[i].first == B[0].first && A[i].second >= B[0].second ){
      int n = (int)B.size();
      bool ok = true;
      for(int j=1;j<n-1;j++){
        if( !(A[i+j].first == B[j].first && A[i+j].second == B[j].second) ){
          ok = false; break;
        }
      }
      if( ok && ( A[i+n-1].first == B[n-1].first && A[i+n-1].second >= B[n-1].second ) ){
 
        for(int j=0;j<i;j++) res.push_back( A[j] );
        if(n == 1 ) {
          for(int j=0;j<(int)C.size();j++) res.push_back( C[j] );        
          res.push_back( P(A[i].first, A[i].second - B[0].second) );
          for(int j=i+n;j<(int)A.size();j++) res.push_back( A[j] );
        } else {
          res.push_back( P(A[i].first, A[i].second - B[0].second) );
          for(int j=0;j<(int)C.size();j++) res.push_back( C[j] );
          res.push_back( P(A[i+n-1].first, A[i+n-1].second-B[n-1].second) );
          for(int j=i+n;j<(int)A.size();j++) res.push_back( A[j] );
        }
        break;
 
      }
    }
  }
  if( res.empty() ){
    for(int i=0;i<(int)A.size();i++)
      cout << A[i].first << " " << A[i].second << " ";  
    cout << "$" << endl;    
    return 0;
  }
  bool modf=false;
  do{
    modf = false;
    for(int i=0;i<(int)res.size();i++){
      if( res[i].second == 0 ) {
        res.erase(res.begin()+i);
        modf = true;
        break;
      }
    }
    if(modf)continue;
    for(int i=0;i<(int)res.size()-1;i++){
      if( res[i].first == res[i+1].first ){
        res[i].second += res[i+1].second;
        res[i+1].second = 0;
        modf = true;
        break;
      }
    }
  }while( modf );
 
  for(int i=0;i<(int)res.size();i++)
    cout << res[i].first << " " << res[i].second << " ";  
  cout << "$" << endl;
}

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

int main(){
  int N, K, l;
  cin >> N >> K;
  vector<int> L(N);
  for(int n = 0; n < N; n++){
    cin >> l;
    L[n] = l;
  }
  
  sort(L.begin(), L.end(), greater<int>());
  int ans;
  for(int i = 0; i < K; i++){
    ans += L[i];
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int N;
	string S;
	cin >> N >> S;
	vector<char> S_v(S.begin(), S.end());
	vector<int> ruisekiwa(N);
	ruisekiwa[0] = 0;

	//Wの累積和を求める
	for (int i = 1; i < N; i++) {
		if (S_v[i - 1] == 'W') {
			ruisekiwa[i] = ruisekiwa[i - 1] + 1;
		}
		else {
			ruisekiwa[i] = ruisekiwa[i - 1];
		}
	}
	int W_total = ruisekiwa[N - 1];
	if (S_v[N - 1] == 'W') {
		W_total++;
	}

	int tmp_ret, min_ret = INF;
	for (int i = 0; i < N; i++) {
		if (i != N - 1) {
			tmp_ret = ruisekiwa[i] + ((N - i - 1) - (W_total - ruisekiwa[i + 1]));
		}
		else {
			tmp_ret = ruisekiwa[i];
		}
		if (tmp_ret < min_ret) {
			min_ret = tmp_ret;
		}
	}
	cout << min_ret;
	return 0;
}

Measured memory_bytes: 2180