akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val s0 = Array<String>(3) { next() }.sorted()
    val s = Array<String>(3) { s0[it] }
    val MX = 2001
    var ans = MX * 3
    val d = Array(3) { Array(3) { BooleanArray(MX) } }
    do {
        for (i in 0 until 3) for (j in 0 until 3) for (k in 0 until s[i].length) {
            if (i >= j) continue
            var ok = true
            for (ni in k until s[i].length) {
                val nj = ni - k
                if (nj >= s[j].length) break
                if (s[i][ni] == '?' || s[j][nj] == '?') continue
                if (s[i][ni] != s[j][nj]) ok = false
            }
            d[i][j][k] = ok
        }
        fun f(i: Int, j: Int, k: Int) = if (k >= s[i].length) true else d[i][j][k]
        for (x in 0 until MX) for (y in 0 until MX) {
            if (!f(0, 1, x)) continue
            if (!f(1, 2, y)) continue
            if (!f(0, 2, x + y)) continue
            val now = listOf(s[0].length, x + s[1].length, x + y + s[2].length).max()!!
            ans = Math.min(ans, now)
        }
    } while (nextPermutation(s))
    println(ans)
}
fun <T: Comparable<T>> nextPermutation(a: Array<T>): Boolean {
    fun find(dest: T, s: Int, e: Int): Int {
        if (s == e) return s
        val m = (s + e + 1) / 2
        return if (a[m] <= dest) find(dest, s, m - 1) else find(dest, m, e)
    }
    for (i in a.size - 1 downTo 1) {
        if (a[i - 1] < a[i]) {
            val swapIndex = find(a[i - 1], i, a.size - 1)
            val temp: T = a[swapIndex]
            a[swapIndex] = a[i - 1]
            a[i - 1] = temp
            a.sort(i, a.size)
            return true
        }
    }
    return false
}
fun next() = readLine()!!


Measured memory_bytes: 119796
using System;
using System.Linq;
using System.Collections.Generic;


class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        int C = int.Parse(input[2]);

        if((A==B && A==C) || (A!=B && A!=C && B!=C)){
            Console.WriteLine("No");
        }else{
            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 11092
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct shop {
  std::string city;
  int score;
  int id;
  shop(std::string s, int i, int j) {
    city  = s;
    score = i;
    id    = j;
  }
  bool operator>(const shop& another) const {
    if (city != another.city) {
      return city > another.city;
    } else {
      return score < another.score;
    }
  }
  bool operator<(const shop& another) const {
    if (city != another.city) {
      return city < another.city;
    } else {
      return score > another.score;
    }
  }
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  std::vector<shop> list;
  for (int i = 0; i < n; i++) {
    std::string s;
    cin >> s;
    int sc;
    cin >> sc;
    list.push_back(shop(s, sc, i + 1));
  }

  std::sort(list.begin(), list.end());

  std::vector<int> result(n);
  int itr = 0;
  for (auto x : list) {
    result[itr] = x.id;
    itr++;
  }

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

  return 0;
}


Measured memory_bytes: 256
s = input()
s_h = s[0]

for i in range(1, len(s)):
    if s_h[-1] == "0":
        s_h += "1"
    else:
        s_h += "0"

ans = 0
for i in range(len(s)):
    if s[i] != s_h[i]:
        ans += 1
    else:
        continue

print(ans)

Measured memory_bytes: 3188
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    return


def main():
    N = int(input())
    D = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            ans += D[i] * D[j]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n;
  cin >> n;
  set<i64> s;
  for (i64 i = 0; i < n; i++)
  {
    i64 a;
    cin >> a;
    s.insert(a);
  }
  cout << s.size() - (s.size() + 1) % 2 << endl;
  return 0;
}


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

typedef long long ll;

const ll INF = 1ll << 60;
const int MAX_N = 100000;

ll A[MAX_N], D[MAX_N];
ll stops[MAX_N];

int main() {
	ll N, T, Q;
	cin >> N >> T >> Q;

	for (int i = 0; i < N; i++) {
		cin >> A[i] >> D[i];
		stops[i] = INF;
	}

	ll s = -INF;
	if (D[0] == 2) stops[0] = s;

	for (int i = 1; i < N; i++) {

		if (D[i - 1] == 1 && D[i] == 2) {
			s = (A[i] + A[i - 1]) / 2;

			for (int j = i - 1; j >= 0 && D[j] == 1; j--)
				stops[j] = s;
		}
		
		if (D[i] == 2)
			stops[i] = s;

	}

	for (int i = 0; i < Q; i++) {
		ll x;
		cin >> x;
		x--;
		ll ans;
		if (D[x] == 1) ans = min(A[x] + T, stops[x]);
		else ans = max(A[x] - T, stops[x]);
		cout << ans << endl;
	}
}

Measured memory_bytes: 5368
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

class State{
public:
  int x;
  int y;
  int cost;
  int scrolling;
  State(int _x,int _y,int _c,int _s) : x(_x),y(_y),cost(_c),scrolling(_s) {}
  bool operator<(const State& s) const {
    return cost < s.cost;
  }
  bool operator>(const State& s) const {
    return cost > s.cost;
  }
};

int main(){
  int W,H;
  while(~scanf("%d %d",&W,&H)){
    char stage[101][101];
    int times[101][101];
    int scrolling2idx[101][101];

    vector<P> holes;

    int sx,sy;
    int gx,gy;
    int scrolling_size = 0;
    for(int y=0; y<H;y++){
      char buf[128];
      scanf("%s",buf);
      for(int x=0; x<W;x++){
        stage[y][x] = buf[x];
        if(buf[x] == '#'){
          holes.push_back(P(x,y));
        }
        else if(buf[x] == 'M'){
          scrolling2idx[y][x] = scrolling_size++;
        }
        else if(buf[x] == 'S'){
          sy = y;
          sx = x;
        }
        else if(buf[x] == 'G'){
          gy = y;
          gx = x;
        }
      }
    }
    for(int y=0; y<H;y++){
      for(int x=0; x<W;x++){
        int dist = INF;
        for(int i=0;i<holes.size();i++){
          dist = min(dist,max(abs(y - holes[i].second),abs(x - holes[i].first)));
        }
        times[y][x] = max(1,4-dist);
      }
    }

    priority_queue<State,vector<State>,greater<State> > que;
    que.push(State(sx,sy,0,0));

    int dp[101][101][1<<5];
    memset(dp,0x3f,sizeof(dp));

    while(!que.empty()){
      State s = que.top();
      que.pop();
      dp[s.x][s.y][s.scrolling] = s.cost;

      for(int i=0;i<4;i++){
        int dx = s.x + tx[i];
        int dy = s.y + ty[i];
        if(dx < 0 || dy < 0 || dx >= W || dy >=H ) continue;
        if(stage[dy][dx] == '#') continue;

        int next_scrolling = s.scrolling;
        if(stage[dy][dx] == 'M'){
           next_scrolling |= (1 << scrolling2idx[dy][dx]);
        }
        if(dp[dx][dy][next_scrolling] <= s.cost + times[s.y][s.x]) continue;
        dp[dx][dy][next_scrolling] = s.cost + times[s.y][s.x];
        que.push(State(dx,dy,s.cost + times[s.y][s.x],next_scrolling));
      }
    }
    printf("%d\n",dp[gx][gy][(1<<scrolling_size)-1]);
  }
}

Measured memory_bytes: 2672
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int N;
  cin >> N;
  vector<string> W(N);
  REP(i, N) cin >> W[i];
  
  int flag = 0;
  FOR(i,1,N){
    REP(j,i){
      if(W.at(j)==W.at(i)){
        flag = 1;
      }
    }
    if(W.at(i).at(0) != W.at(i-1).at(W.at(i-1).size()-1)){
      flag = 1;
    }
  }

  if(flag == 1){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <list>
#include <algorithm>

using namespace std;

int main(int, char**)
{
	unsigned int n;
	unsigned long long ans = 0;

	std::cin >> n;

	if (n % 10 == 2)
		ans++;
	if ((n / 10) % 10 == 2)
		ans++;
	if ((n / 100) % 10 == 2)
		ans++;
	if ((n / 1000) % 10 == 2)
		ans++;
	
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

bool visited[MAXN];

vector<int> val;
vector<int> permu;

void dfs(int here)
{
    visited[here] = true;
    val.push_back(here);
    permu.push_back(A[here]);

    int there;

    for(int i=0;i<graph[here].size();i++)
    {
        there = graph[here][i];
        if(visited[there])continue;
        dfs(there);
    }
    return;
}

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;

    for(int i=1;i<=n;i++)
        cin>>A[i];

    graph = vector<vector<int> > (n+1);

    for(int i=0;i<m;i++){
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    int sz;
    int R = 0;

    for(int i=1;i<=n;i++){
        if(visited[i])continue;
        val.clear();
        permu.clear();
        dfs(i);

        sz = val.size();

        sort(val.begin(),val.end());
        sort(permu.begin(),permu.end());

        R = 0;
        for(int i=0;i<sz;i++){
            while(R<sz&&permu[R]<val[i])R++;
            if(R==sz||permu[R]>val[i])continue;
            cnt++;
        }
    }

    cout<<cnt<<"\n";

    return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

class ar {
  public:
    vector<ll> inner_array;
    int state = 0;
    void reset() {
        inner_array.resize(0);
        state = 0;
    }
    bool add(ll n) {
        if (inner_array.size() == 0) {
            inner_array.push_back(n);
            return false;
        }
        ll len = inner_array.size();
        ll last = inner_array[len - 1];
        bool result = false;
        if (state == 1) {
            if (last > n) {
                reset();
                result = true;
            }
        } else if (state == 0) {
            if (last < n) {
                state = 1;
            } else if (last > n) {
                state = -1;
            }
        } else if (state == -1) {
            if (last < n) {
                reset();
                result = true;
            }
        }
        inner_array.push_back(n);

        return result;
    }
};

int main() {
source:
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }

    ar ar_temp;
    ll ans = 1;
    rep(i, n) {
        bool result = ar_temp.add(a[i]);
        if (result) {
            ans++;
        }
    }

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



Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f,oo = inf;
#define IL inline
#define RG register
#define rep(i,a,b) for(RG int i=(a);i<int(b);++i)
#define Rep(i,a,b) for(RG int i=(a);i<=(b);++i)
#define Dep(i,a,b) for(RG int i=(a);i>=(b);--i)
#define pc putchar
#define gc getchar
IL ll read(){
    RG ll x=0;char f=0;RG char c=gc();
    for(;!isdigit(c);c=gc())f|=(c=='-');
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return f?-x:x;
}
IL void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);pc(x%10+'0');}
IL void writeln(ll x){write(x);puts("");}
#define rd() read()
#define mem(x,v) memset(x,v,sizeof(x))
const int maxn = 2e5+233;
int n;
ll s1[maxn],s2[maxn],a[maxn];
int main(){
	n = rd();
	s1[0] = s2[0] = 0;
	Rep(i,1,n){
		a[i] = rd();
		s1[i] = s1[i-1] ^ a[i];
		s2[i] = s2[i-1] + a[i];
	}
	int l = 0;
	ll ans = 0;
	for(int r=1;r<=n;r++){
		while((s1[r]^s1[l]) != s2[r]-s2[l]){
//			printf("%d %d\n",s1[r]^s1[l] , s2[r]-s2[l]);
			++l;
		}
		ans += (r-1-(l)+1);
	}
	writeln(ans);
}

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

n = int(input())
li = list(map(int,input().split()))
li.sort()
count = 0
for i in range(n-1):
    for j in range(i+1,n-1):
        if li[i] == li[j]:
            continue
        else:
            count += len([k for k in li[j+1:] if k < (li[i] + li[j]) and k != li[i] and k != li[j]])
print(count)

Measured memory_bytes: 9236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

string n;

array<vector<ll>, 2> dp;
array<vector<bool>, 2> flag;

ll solve(ll pos, ll state){
    if(flag.at(state).at(pos)){
        return dp.at(state).at(pos);
    }

    ll d = n.at(pos) - '0';
    if(state == 1){
        d = 10 - d;
    }
    ll ret = 0;

    if(pos == n.size() - 1){
        if(d <= 5){
            ret = d;
        }else{
            ret = 1 + solve(pos, 1 - state);
        }
    }else{
        if(state == 0){
            ret = min(
                d + solve(pos + 1, state),
                d + 1 + solve(pos + 1, 1 - state)
            );
        }else{
            assert(d > 0);
            ret = min(
                d - 1 + solve(pos + 1, state),
                d + solve(pos + 1, 1 - state)
            );
        }
    }

    flag.at(state).at(pos) = true;
    dp.at(state).at(pos) = ret;
    return ret;
}

int main(){
    cin >> n;
    n.insert(0, 1, '0');
    REP(i, 2){
        dp.at(i).resize(n.size());
        flag.at(i).resize(n.size());
        fill(flag.at(i).begin(), flag.at(i).end(), false);
    }
    cout << solve(0, 0) << endl;
    return 0;
}


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

using namespace std;

int main() {
  int n; cin >> n;
  map<char, int> m;
  bool f = true;
  while (n--) {
    string s; cin >> s;
    map<char, int> t;
    for (char c : s) {
      if (f) m[c]++;
      t[c]++;
    }
    f = false;
    for (char c = 'a'; c <= 'z'; c++) {
      m[c] = min(m[c], t[c]);
    }
  }
  for (char c = 'a'; c <= 'z'; c++) {
    while (m[c]--) cout << c;
  }
  cout << endl;
}



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

using namespace std;

int main(){
    long long n;
    cin>>n;
    vector<char> hoge={'M','A','R','C','H'};
    map<char,long long> name;
    for(char a='A';a<='Z';a++) name[a]=0;
    
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        char h=s.at(0);
        
        name[h]++;
    }
    
    long long ans=0;
    
    for(long long i=0;i<3;i++){
        for(long long j=i+1;j<4;j++){
            for(long long k=j+1;k<5;k++){
                ans+=name.at(hoge.at(i))*name.at(hoge.at(j))*name.at(hoge.at(k));
            }
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}

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

multimap<int,int> AB;
multiset<int> B;

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

  for( int i=0; i<N; ++i) {
    int a,b;
    cin >> a >> b;
    AB.emplace(a,b);
  }

//  for( auto a: AB ) cout << a.first << ":" << a.second << endl;
  
  int64_t ans = 0;
  // M日目から探す
  decltype(AB)::iterator nit = AB.begin();
  for( int64_t t=M-1; t>=0; --t) {
//    cout << "--- " << t << " ---" << endl;
    // 現在の日で受けれるもの(t+A<=M)の中で、B最大のものを選ぶ
    auto at = AB.upper_bound( M-t );
//    cout << at->first << ":" << at->second << endl;
    
    int64_t bmax=0;
    while( distance( nit, at ) > 0 ) {
      B.insert( nit->second );
      nit++;
    }
    if ( !B.empty() ) {
      auto bit = B.end();
      bit--;
//      cout << *bit << endl;
      ans += *bit;
      B.erase(bit);
    }
  }

  cout << ans<< endl;

}


Measured memory_bytes: 9600
import numpy as np

inf = np.iinfo(np.uint32).max



# def solve():
#     dists_y = [abs(y-a) for a in range(0,n+1)]
#     dists_x = [abs(x-a) for a in range(0,n+1)]
#     count_dists = np.zeros(n+1, dtype=int)
#     for a in range(1,n+1):
#         for b in range(1,a+1):
#             dis = min(abs(b-a), dists_x[a] + dists_y[b] + 1, dists_y[a] + dists_x[b] + 1)
#             count_dists[dis] += 1
#     #print(min_dists)
#     for j in range(1,n):
#         print(count_dists[j])

def solve():
    dists_y = [abs(y-a) for a in range(1,n+1)]
    dists_x = [abs(x-a) for a in range(1,n+1)]

    aa = np.tile(np.arange(1, n+1), (n, 1))
    bb = aa.transpose().copy()
    base_dists = np.abs(aa-bb).copy()
    aa = np.tile(dists_y, (n, 1))
    bb = np.tile(dists_x, (n, 1)).transpose().copy()
    ab_dists = aa + bb + 1
    ba_dists = ab_dists.transpose().copy()
    min_dists = np.minimum(ab_dists, ba_dists)
    min_dists = np.minimum(min_dists, base_dists)
    count_dists = np.bincount(min_dists.reshape(n**2))
    for j in range(1,n):
        if j+1>len(count_dists):
            print(0)
        else:
            print(count_dists[j]//2)



#
# def ceildiv(a, b):
#     return a // b + a % b



n, x, y = [int(i) for i in input().split(" ")]

# import time
# t = time.time()
# n, x, y = 2000, 200, 600


solve()
#print(time.time()- t)

Measured memory_bytes: 231184
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vector<P> p(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        p[i] = make_pair(b, a);
    }
    sort(all(p));

    bool ok = true;
    ll now = 0;
    rep(i, n) {
        now += p[i].second;
        if(p[i].first < now) {
            ok = false;
        }
    }

    if(ok) {
        out("Yes");
    }
    else {
        out("No");
    }
    
    re0;
}

Measured memory_bytes: 3328
s[1<<17],t[1<<17];a,b,c;main(d){for(;d=getchar(a++)/11;)s[a+1]=s[a]+d-4;for(;d=getchar(b++)/11;)t[b+1]=t[b]+d-4;for(gets(s);~scanf("%d%d%d%d",&a,&b,&c,&d);)puts((s[b+1]-s[a]-t[d+1]+t[c])%3?"NO":"YES");}

Measured memory_bytes: 1280
#1行に入力が複数の場合
a, b, c = map(int, input().split())
#容器1に入れることができる水の量
can_ad_a = a - b
#aに追加で注げる水の量は
#「aに入れることができる水の量」、「cに入っている水の量」のうち小さい値
#「aに入れた水の量」を「c」から引けば「cに残る水の量」
#min(value, value)で最小値を取得
print(c - min(can_ad_a, c))


Measured memory_bytes: 38256
n = int(input())
arrayOfNumber = list(map(int, input().split()))
MOD = 10**9+7
 
res = 0
for dig in range(61):
    one = 0
    for i in arrayOfNumber:
        if i & (1<<dig) != 0:
            one += 1
    res = (res + one*(n-one)*(1<<dig))%MOD
print(res)

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

using namespace std;
using llint = long long;
using pint = pair<int,int>;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl

const int INF = 1<<28;
const llint LLINF = 1LL<<60;

int n, c=0;
vector<int> p;

int main() {
    // Input
    cin >> n;
    p.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> p.at(i);
    }

    // Solve
    for (int i = 1; i < n-1; ++i) {
        if ((p.at(i-1) < p.at(i) && p.at(i) < p.at(i+1)) || (p.at(i+1) < p.at(i) && p.at(i) < p.at(i-1)))
        {
            c++;
        }
    }

    // Output
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int N;
	long long A[100009];
	int count = 0, sum = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (A[i] == A[j])count++;
			else break;
		}
		i += count;
		if (count % 2 == 0) {
			sum++;
		}
		count = 0;
	}
	cout << sum << endl;
}

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

using namespace std;

typedef pair<int, int> P;

int main() {
  int n, x, l;
  cin >> n;
  vector<P> xl;
  for (int i = 0; i < n; i++) {
    cin >> x >> l;
    xl.emplace_back(x + l, x - l);
  }
  sort(xl.begin(), xl.end());

  int cur = -1e9, ans = 0;
  for (auto &v : xl) {
    if (cur <= v.second) {
      ans++;
      cur = v.first;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    ll A, B, K;
    cin >> A >> B >> K;

    if(K <= A) cout << A- K << " " << B << endl;
    else if(K <= A + B) cout << 0 << " " << B - (K - A) << endl;
    else cout << 0 << " " << 0 << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// 初期化
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		String[] list = sc.next().split("");
		
		List<Integer> one_zero_list = new ArrayList<Integer>();
		
		// 現在見ている数
		int now=1;
		// 上記数が何個続いたかカウント
		int cnt=0;
		
		for(int i=0;i<list.length;i++) {
			//
			if(list[i].charAt(0) == (char)('0'+now)) {
				cnt++;
			}
			else {
				one_zero_list.add(cnt);
				cnt=1;
				// 現在見ている数を反転する。
				now = 1 - now;
			}
		}
		
		// 最後のカウントを足す
		if(cnt != 0) {
			one_zero_list.add(cnt);
		}
		
         // 1-0-1-0-1-0-1のように最後は1のカウントで終わらしたいので、
         // 1-0-1-0-1-0 で終わっていたら1を足す
        if (one_zero_list.size() % 2 == 0) {
        	one_zero_list.add(0);
        }
        
        // 累積和を取得する。
        // ruiseki_waのindex  0 1 2 3 4 5 6  7  8  9
        // ruiseki_waのvalue  0 3 4 5 6 7 8 10 12 14
        int[] ruiseki_wa = new int[one_zero_list.size() + 1];
        
		for(int i=0;i<one_zero_list.size();i++) {
			ruiseki_wa[i+1] = ruiseki_wa[i] + one_zero_list.get(i);
			
		}
		
		// 反転回数の次までをrightとする。
		int countRange = 2 * K + 1;
		int result=0;
		
		for(int i=0;i<ruiseki_wa.length;i+=2) {
			// left、rightの計算
			int left=i;
			int right = Math.min(i + countRange, one_zero_list.size());
			int temp = ruiseki_wa[right] - ruiseki_wa[left];
			result = Math.max(result, temp);
			
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 32448
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

//aとbの最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}

//aとbの最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}

int main(){
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    int g = gcd(A[0], A[1]);
    rep2(i, 2, N-1) g = gcd(g, A[i]);
    cout << g;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int card[110];
  for (int i=0; i<n; i++) {
    cin >> card[i];
  }
  sort(card,card+n);
  reverse(card,card+n);
  int alice=0;
  int bob=0;
  for (int i=0; i<n; i++) {
    if (i%2 == 0) {
      alice += card[i];
    } else {
      bob += card[i];
    }
  }
  cout << alice-bob << endl;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
count = 0

for i in range(N-1):
  n = num_list[i] + num_list[i+1]
  if n > x:
    if n - num_list[i+1] > x:
      count += n - x
      num_list[i+1] = 0
    else:
      count += n - x
      num_list[i+1] -= (n-x)

print(count)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
/* テンプレートここまで */
void yes(){
  cout << "YES" << endl;
  exit(0);
}

void no(){
  cout << "NO" << endl;
  exit(0);
}
int main() {
  ll a,b; cin >> a >> b;
  cout << (a+b) % 24 << endl;
}


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

using namespace std;
typedef long long ll;

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

  int first = 0;
  int last = 0;
  int n = 0;

  for (int i = 0; i < N; i++) {
    if (S[i] == '(') {
      n++;
    } else {
      n--;
      if (n < 0) {
        n = 0;
        first++;
      }
    }
  }
  last = n;

  for (int i = 0; i < first; i++) {
    cout << '(';
  }
  cout << S;
  for (int i = 0; i < last; i++) {
    cout << ')';
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

int main() {
	int n,m,q,k;
	int s,t;
	int i,j;
	queue<int> nq;
	vector<vector<int> > node;
	vector<int> ngrp;

	scanf("%d%d",&n,&m);
	node.resize(n);
	ngrp.resize(n);

	for(i=0;i<m;++i) {
		scanf("%d%d",&s,&t);
		node[s].push_back(t);
		node[t].push_back(s);
	}

	for(i=0;i<n;++i) {
		ngrp[i]=-1;
	}

	for(i=0; i<n; ++i) {
		if(ngrp[i]==-1) {
			nq.push(i);
			ngrp[i]=i;
			while(!nq.empty()) {
				k=nq.front();
				for(j=0;j<(int)node[k].size();++j) {
					if(ngrp[node[k][j]]==-1) {
						ngrp[node[k][j]]=i;
						nq.push(node[k][j]);
					}
				}
				nq.pop();
			}
		}
	}
	scanf("%d",&q);
	for(i=0;i<q;++i) {
		scanf("%d%d",&s,&t);
		printf((ngrp[s]==ngrp[t])?"yes\n":"no\n");
	}
	return 0;
}

Measured memory_bytes: 8132
n=int(input())
s=[input() for i in range(n)]
ans=0
ab=a=b=0
for ss in s:
  ans+=ss.count("AB")
  if ss[0]=="B" and ss[-1]=="A":
    ab+=1
  elif ss[0]=="B" and ss[-1]!="A":
    b+=1
  elif ss[0]!="B" and ss[-1]=="A":
    a+=1
# print(ans)
cnt_min=min(a,b)
if ab==0:
  ans+=cnt_min
else:
  if a+b>0:
    ans+=ab+cnt_min
  else:
    ans+=ab-1
print(ans)


Measured memory_bytes: 3700
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma") 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN
#ifdef LOCAL // setting up print debugging (yes lol)
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.x<<','<<p.y<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
#endif
using namespace std;

const size_t MAXN = 2*(1e5 +7);

pair<ll ,ll> a[MAXN];

void check(){
	ll n;
	cin >> n;
	for(ll i =0 ; i < n ; i++){
		cin >> a[i].F >> a[i].S;
	}
	sort(a ,a+n);
	ll ans = 0LL;

	ll mxabve = -a[0].F + a[0].S;
	ll mnbelow = a[0].F + a[0].S;

	for(ll i = 1; i < n; i++){
		ans = max({ans ,a[i].F-a[i].S+mxabve ,a[i].F+a[i].S-mnbelow});
		mxabve = max(mxabve ,-a[i].F + a[i].S);
		mnbelow = min(mnbelow ,a[i].F + a[i].S); 
	}
	cout << ans;
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); 
	cin.exceptions(cin.failbit);
	int t = 1;	
	// cin >> t;
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		check();
	}
	return 0;
}


Measured memory_bytes: 6788
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
q = gets.to_i
m = gets.chomp.split.map(&:to_i)
sum_list = {}

1.upto(n) do |i|
  a.combination(i).each { |c| sum_list[c.inject(&:+)] = true }
end

m.each do |key|
  puts (sum_list.has_key?(key) ? "yes" : "no")
end




Measured memory_bytes: 9200
import sys
input = sys.stdin.readline
N = int(input())
c2 = [int(input()) for _ in range(N)]
mod = 10**9+7
#圧縮
c = [c2[0]-1]
n = N
for i in range(1,N):
    if c2[i] == c2[i-1]:
        n -= 1
        continue
    c.append(c2[i]-1)

#used[i]:色iが最後に登場したindex
#初期値:-1
used = [-1]*(max(c)+1)
used[c[0]] = 0
#dp[i]:i番目まででの場合の数
dp = [0]*n
dp[0] = 1
for i in range(1,n):
    if used[c[i]] == -1:
        dp[i] = dp[i-1]
    else:
        dp[i] = (dp[i-1]+dp[used[c[i]]])%mod
    used[c[i]] = i

print(dp[-1])


Measured memory_bytes: 28404
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int X[100005];
int dp[100005][18];

int main() {
  int n;
  S(n);
  rep(i,1,n+1) {
    S(X[i]);
  }
  int l;
  S(l);

  int id = 1;
  rep(j,0,18) {
    rep(i,1,n+1) {
      if(!j) {
        while(id <= n && X[id] - X[i] <= l) id++;
        if(id > n) {
          dp[i][0] = n + 1;
        } else {
          id--;
          dp[i][0] = id;
        }
      } else {
        int idx = dp[i][j-1];
        if(idx != n + 1) {
          dp[i][j] = dp[idx][j-1];
        } else {
          dp[i][j] = n + 1;
        }
      }
    }
  }

  int q;
  S(q);
  while(q--) {
    int a,b;
    S2(a,b);
    if(a > b) swap(a,b);
    if(a == b) {
      P(0);
      continue;
    }
    int days = 0;
    for(int i = 17; i >= 0; i--) {
      if(dp[a][i] < b) {
        days += 1<<i;
        a = dp[a][i];
      }
    }
    P(days+1);
  }
  return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*/
#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
    vector <string> v;
    stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x);
    return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
    cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
    err(++it, args...);
}
 
int ini(){int x; scanf("%d",&x);return x;}
long long inl(){ long long x;scanf("%lld",&x); return x;}
double ind(){double x; scanf("%lf",&x);return x;}
#define Iin ini();
#define Lin inl();
#define Din ind();

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int t=1,te=0;


    while(t--){
        int n;
        cin>>n;
        string s;

        cin>>s;

        int shift=n%26;

        for(int i=0;s[i];i++){
            int x=s[i]-'A';
            int r=x+shift;
            if(r >=26){
                r = r-26;
            }
            printf("%c",'A' + r);
        }

        //printf("Case %d: ",++te);
    }
    return 0;
}




Measured memory_bytes: 256
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>


//pair sort firstに揃う

#define int long long
#define pb(n) push_back(n)
#define Rap(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define F first
#define S second
#define Vector1  vector<int>
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ctoi(c) (int)(c-'0')
#define incin(n) int (n); cin>>(n);
#define stcin(s) string (s); cin>>(s);
#define all(v) (v).begin() , (v).end()
#define PI 3.14
#define Rad2Deg  57.29578

using namespace std;

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

    stcin(s);
    int n=s.size();

    int min = 100000;
    for(int i=0;i<n-2;i++){
        string a = {s[i],s[i+1],s[i+2]};
        int x = stoi(a);
        if(abs(x-753)<min){
            min=abs(x-753);
        }
    }
    Pr(min);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,b,f,r,v,recode[4][3][10]={0},i,k,j;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		recode[b-1][f-1][r-1]+=v;
	}
	for(i=0;i<4;i++){
		for(k=0;k<3;k++){
			for(j=0;j<10;j++){
				printf(" %d",recode[i][k][j]);
			}
			printf("\n");
		}
		if(i!=3){
			printf("####################\n");
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
const int maxM=(2e5)+5;

long long a[maxM],sp[maxM],f[maxM];
long long n;
long long x,m,dim;
int pos;
int main()
{
    scanf("%lld%lld%lld",&n,&x,&m);
//    printf("%d\n",x);

    a[1]=x;
    f[a[1]]=1;

    dim=1;

    while(dim<n)
    {
        dim++;
        a[dim]=(1LL*a[dim-1]*a[dim-1])%m;
        if(f[a[dim]])
        {
            pos=f[a[dim]];
            dim--;
            break;
        }
            else f[a[dim]]=dim;

    }
   // printf("AM AJUNS AICI");

 //   printf("%d\n",a[1]);

   // printf("%d\n",dim);

   // printf("%d",dim);

    for(int i=1;i<=dim;i++)
    {
        sp[i]=(sp[i-1]+a[i]);
    }

    //printf("%d\n",dim);
    //printf("%d\n",pos);
    //printf("%lld %lld\n",a[pos],a[dim]);


    long long sol=0;

    if(n<=dim) sol=sp[n];
        else
    {
        sol=sp[pos-1];
        int len=dim-pos+1;
        long long add=sp[dim]-sp[pos-1];

        sol=(sol+(n-pos+1)/len*add+sp[pos+(n-pos+1)%len-1]-sp[pos-1]);


    }
    //long long sol=((sp[dim]*(n/dim))+sp[n%dim]);

    printf("%lld\n",sol);



    return 0;
}

Measured memory_bytes: 5380
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            long n = cin.ReadLong;
            long[] a = new long[n];

            for (int i = 0; i < n; i++)
            {
                a[i] = cin.ReadLong;
            }

            double avg = a.Average();
            int ans = 0;

            double diff = Math.Abs(a[0] - avg);
            double tmp = 0;

            for (int i = 1; i < n; i++)
            {
                tmp = Math.Abs(a[i] - avg);
                if(tmp < diff)
                {
                    diff = tmp;
                    ans = i;
                }
            }

            Console.WriteLine(ans);
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    vector <int> input(100, 0);
    int num;
    
    while (cin >> num) 
        input[num - 1]++;

    int max = 0;
    for (int i = 0; i < input.size(); i++) 
        if (input[i] > max)
            max = input[i];

    for (int i = 0; i < input.size(); i++)
        if (input[i] == max)
            cout << i + 1 << endl;

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int a, b, cnt=0;
  cin >> a >> b;
  for(int i=a; i<=b; i++){
    string c = to_string(i);
    if(c[0]==c[4] && c[1]==c[3]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

H, W=map(int, input().split())
S=["" for i in range(H)]
for i in range(H):
    S[i] = input()

def ncell(i, j):
    DX = [i-1, i, i+1, i-1, i+1, i-1, i, i+1]
    DY = [j-1, j-1, j-1, j, j, j+1, j+1, j+1]
    XX = []
    YY = []
    for k in range(8):
        if (0<=DX[k]<=H-1 and 0<=DY[k]<=W-1):
            XX.append(DX[k]); YY.append(DY[k])
    return [XX, YY]
for i in range(H):
    st = ""
    for j in range(W):
        if S[i][j] == ".":
            dd = ncell(i, j)
            dx = dd[0]; dy = dd[1];
            m = 0
            for k in range(len(dx)):
                if S[dx[k]][dy[k]] == "#":
                    m += 1
            st += str(m)
        else:
            st += "#"
    print(st)

    

Measured memory_bytes: 3064
# coding: utf-8

N = int(input())

count = 0
for i in range(1, N+1, 2):
    i_yakusu = 0
    for j in range(1, i+1):
        if i % j == 0:
            i_yakusu += 1
    if i_yakusu == 8:
        count += 1

print(count)

Measured memory_bytes: 9092
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int leapyear(int year)
{
  if(year%4)
    return 0;
  if(year%100==0){
    if(year%400==0)
      return 1;
    else 
      return 0;
  }else 
    return 1;
}

int main()
{
  int y1,m1,d1,y2,m2,d2;
  int i,j,k;
  int day[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
		  {0,31,29,31,30,31,30,31,31,30,31,30,31}};

  while(1){
    cin>>y1>>m1>>d1>>y2>>m2>>d2;
    if(y1<0 || m1<0 || d1<0 || y2<0 || m2<0 || d2<0)break;
    int days=0;

    if(y1==y2){

      if(m1==m2)
	days=d2-d1;
      else{
	days=day[leapyear(y1)][m1]-d1;
	for(i=m1+1;i<m2;i++)
	  days+=day[leapyear(y1)][i];
	days+=m2;
      }

    }else{

      days=day[leapyear(y1)][m1]-d1;
      for(i=m1+1;i<=12;i++)
	days+=day[leapyear(y1)][i];
      for(i=y1+1;i<y2;i++)
	days+=365+leapyear(i);
      for(i=1;i<m2;i++)
	days+=day[leapyear(y2)][i];
      days+=d2;

    }
    cout<<days<<endl;

  }
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        int c[] = new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
            b[i]=sc.nextInt();
            c[i]=sc.nextInt();
        }
        long dp[][] = new long[n][3];
        dp[0][0]=a[0];
        dp[0][1]=b[0];
        dp[0][2]=c[0];

        for(int i=1;i<n;i++){
            dp[i][0]=Math.max(dp[i-1][1],dp[i-1][2])+a[i];
            dp[i][1]=Math.max(dp[i-1][0],dp[i-1][2])+b[i];
            dp[i][2]=Math.max(dp[i-1][0],dp[i-1][1])+c[i];
        }
        System.out.println(Math.max(dp[n-1][0],Math.max(dp[n-1][1],dp[n-1][2])));


    }
}


Measured memory_bytes: 93132
/*
3hiki 8hon
*/
function main(input){
 input = input.trim();
 var hiki = parseInt(input.split(" ")[0]);
 var asi = parseInt(input.split(" ")[1]);
 var hantei=(2*hiki<=asi && 4*hiki>=asi && asi%2==0);
 if(hantei==true){console.log("Yes");}
 else{console.log("No");}
}
main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 29628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N;
    cin >> N;
    vector<pair<ll,ll>> r(N);
    rep(i, 0, N) cin >> r[i].second >> r[i].first;
    sort(r.begin(), r.end());
    ll timer = 0;
    rep(i, 0, N){
        timer += r[i].second;
        if(r[i].first < timer){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3328
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#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 CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef int64_t LL;
typedef uint64_t ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
template<class T, class... U> void DEBUG(const T &head, const U &... tail) { 
#ifdef HOME
    _W('#'); _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);
#endif
}
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int n;
int d[SIZE];
int main(){
    R(n);
    FOR(i,1,n)R(d[i]);
    LL ll=2,rr=2;
    for(int i=n;i>0;i--){
        LL nxt_ll=((ll-1)/d[i]+1)*d[i];
        LL nxt_rr=(rr/d[i]+1)*d[i]-1;
        if(nxt_ll>nxt_rr){
            W(-1);
            return 0;
        }
        ll=nxt_ll;
        rr=nxt_rr;
    }
    W(ll,rr);
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
    ll n,m,l,r,ans=0;
    cin>>n>>m;
    vector<ll> s(n+1);
    fr(i,m){
        cin>>l>>r;
        s[l-1]+=1;s[r]-=1;
    }
    fr(i,n) s[i+1]+=s[i];
    fr(i,n+1){
        ans+=(s[i]==m);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll n; cin>>n;
  ll a[n];
  ll x[1000000];
  ll s0=0;
  rep(i, n) {
    cin>>a[i];
    x[a[i]]++;
    s0+=a[i];
  }
  ll q; cin>>q;
  rep(i, q) {
    ll b, c;cin>>b>>c;
    cout<<s0+(c-b)*x[b]<<endl;
    
    s0=s0+(c-b)*x[b];
    x[c]+=x[b];
    x[b]=0;
  }
}

Measured memory_bytes: 5140