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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  ll n,m;cin>>n>>m;
  vector<ll> a(n);
  int i;
  rep(i,n)cin>>a.at(i);
  sort(all(a));
  vector<ll> sum(n+1,0);
  rep(i,n)sum[i+1]=sum[i]+a[i];
  int right=200001;
  int left=1;
  int lasok=1;
  ll anspat=0;
  ll ans=0;
  while(left<=right) 
  {
    int x=(left+right)/2;
    int vec=0;
    int ind=n-1;
    ll tpat=0;
    ll pat=0;
    ll total=0;
    //cout<<left<<' '<<right<<endl;
    while(ind>=0&&vec<n)
    {
      if(a[ind]>=x-a[vec])
      {
        pat++;
        ind--;
      }
      else
      {
        tpat+=pat;
        total+=sum[n]-sum[ind+1];
        total+=a[vec]*pat;
        vec++;
      }
    }
    if(ind<0)
    {
      while(vec<n)
      {
        tpat+=pat;
        total+=sum[n]-sum[ind+1];
        total+=a[vec]*pat;
        vec++;
      }
    }
    if(tpat<m)
    {
      right=x-1;
    }
    else
    {
      lasok=x;
      ans=total;
      anspat=tpat;
      left=x+1;
    }
    if(left>right)break;
  }
  cout<<ans-(anspat-m)*lasok<<endl;
}


Measured memory_bytes: 1792
N = int(input())
S = " "+input()
pos = [[0 for _ in range(4000*2+10)] for _ in range(3)]
s = [0 for _ in range(3)]

for i in range(1, N+1):
    if S[i] == "R":
        pos[0][i] = 1
        s[0] += 1
    elif S[i] == "G":
        pos[1][i] = 1
        s[1] += 1 
    else:
        pos[2][i] = 1
        s[2] += 1

ans = 0
for i in range(N+1):
    if pos[0][i] == 0:
        continue
    for j in range(N+1):
        if pos[1][j] == 0:
            continue
        ans += s[2]
        if 2*i-j >= 0 and pos[2][2*i-j] == 1:
            ans -= 1
        if 2*j-i >= 0 and pos[2][2*j-i] == 1:
            ans -= 1
        if (i+j)%2 == 0 and pos[2][(i+j)//2] == 1:
            ans -= 1

print(ans)

Measured memory_bytes: 9376
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int m = sc.nextInt();
            if(n == 0 && m == 0){
                break;
            }else{
                for(int i = 0; i < n; i++){
                    for(int j = 0; j < m; j++){
                        System.out.print("#");
                        
                    }
                    System.out.println("");
                }
                
            }
            System.out.println();
            
        }
    }
}


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

int main() {

	string res = "";
	long N; cin >> N; if(N == 0) res = "0";
	long mysign = 1, mypower = 1;
	while (N != 0) {

		int mod2 = abs(N % 2);
		N = N - mod2 * mysign; N /= 2;
        
		res = to_string(mod2) + res;
        mypower *= 2;
        mysign *= -1; //符号を交代。
	}

	cout << res << endl;

}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

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

template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}

template <typename T> void print(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void print(const T &value, const Args&... args){std::cout << value << " ";print(args...);}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int A, B;
  while(cin >> A >> B){
    print(A * B);
  }

  return 0;
}


Measured memory_bytes: 3608
import java.util.*;

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

        while(ans >= b){
            ans -= b;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
n = int(input())
red = [list(map(int, input().split())) for i in range(n)]
blue = [list(map(int, input().split())) for i in range(n)]
red = sorted(red, key = lambda x: x[1])
blue.sort()
ans = 0
for i in range(n):
    a = 0
    for j in range(len(red)):
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
            a = j
    if blue[i][0] > red[a][0] and blue[i][1] > red[a][1]:
        ans += 1
        del red[a]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
vector<int> cnt;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N >> M;
    cnt.assign(M+1,0);
    for (int i = 0; i < N; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int a;
            cin >> a;
            a--;
            cnt[a]++;
        }
        
    }
    
}

int solve(){
    int ans=0;
    for (int i = 0; i < M; i++)
    {
        if(cnt[i]==N) ans++;
    }
    cout << ans << endl;
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
flag = false
(0..(N/7)).each do |donut|
  (0..(N/4)).each do |cake|
    if donut*7 + cake*4 == N
      puts "Yes"
      flag = true
    end
    break if flag
  end
  break if flag
end
puts "No" unless flag


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 2e5 + 5;
const int MOD = 1e9 + 7;
int paths[2][MAX];
ll dis[2][MAX];
vector<ii> adj[MAX];
int s, t;
int n, m;

inline int add(int a, int b) {
	a += b;
	if(a >= MOD) {
		a -= MOD;
	}
	return a;
}

inline int mult(int a, int b) {
	return (1LL * a * b) % MOD;
}

inline int sub(int a, int b) {
	a -= b;
	if(0 > a) {
		a += MOD;
	}
	return a;
}

void bfs(int source, int P[MAX], ll D[MAX]) {
	priority_queue< pair<ll, int>, vector< pair<ll, int> >, greater< pair<ll, int> > > pq;

	D[source] = 0;
	P[source] = 1;

	pq.emplace(D[source], source);

	while(!pq.empty()) {
		pair<ll, int> top = pq.top(); pq.pop();

		ll w;
		int cur;
		tie(w, cur) = top;

		if(w > D[cur]) {
			continue;
		}

		for(auto &each : adj[cur]) {
			int other, weight;
			tie(other, weight) = each;

			if(D[other] > D[cur] + weight) {
				D[other] = D[cur] + weight;
				P[other] = P[cur];
				pq.emplace(D[other], other);
			}
			else if(D[other] == D[cur] + weight) {
				P[other] = add(P[other], P[cur]);
			}
		}
	}
}

pair<ll, ll> intersection(ll sa, ll ea, ll sb, ll eb) {
	return make_pair(max(sa, sb), min(ea, eb));
}

int main() {
	scanf("%d %d", &n, &m);
	scanf("%d %d", &s, &t);

	fori(i, 1, m + 1) {
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		adj[u].emplace_back(v, w);
		adj[v].emplace_back(u, w);
	}

	memset(dis, 0x7F, sizeof dis);
	bfs(s, paths[0], dis[0]);
	bfs(t, paths[1], dis[1]);

	ll best = dis[0][t];
	int paj = paths[0][t];

	int ans = mult(paj, paj);

	fori(i, 1, n + 1) {
		if(dis[0][i] == dis[1][i] && 2 * dis[0][i] == best) {
			int p = mult(paths[0][i], paths[1][i]);
			int bad = mult(p, p);
			ans = sub(ans, bad);
		}
	}

	fori(i, 1, n + 1) {
		for(auto &each : adj[i]) {
			int j, w;
			tie(j, w) = each;

			if(i > j) {
				continue;
			}

			if((dis[0][i] + dis[1][j] + w) == best) {
				ll S_start = dis[0][i];
				ll S_end = dis[0][i] + w;

				ll T_start = dis[1][j];
				ll T_end = dis[1][j] + w;

				pair<ll, ll> inter = intersection(S_start, S_end, T_start, T_end);
				if(inter.first < inter.second) {
					int p = mult(paths[0][i], paths[1][j]);
					int bad = mult(p, p);
					ans = sub(ans, bad);
				}
			}
			else if((dis[1][i] + dis[0][j] + w) == best) {
				ll S_start = dis[1][i];
				ll S_end = dis[1][i] + w;

				ll T_start = dis[0][j];
				ll T_end = dis[0][j] + w;

				pair<ll, ll> inter = intersection(S_start, S_end, T_start, T_end);
				if(inter.first < inter.second) {
					int p = mult(paths[1][i], paths[0][j]);
					int bad = mult(p, p);
					ans = sub(ans, bad);
				}
			}
		}
	}

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

	return 0;
}


Measured memory_bytes: 18260
// https://atcoder.jp/contests/abc084/tasks/abc084_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// constexprな素数列挙(エラトステネスの篩)
// https://259-momone.hatenablog.com/entry/2018/05/06/015026
template <int_fast64_t max_N> struct Prime {
    bool sieve[max_N];
    constexpr Prime() : sieve() {
        for (int_fast64_t i = 0; i < max_N; ++i)
            sieve[i] = true;
        sieve[0] = sieve[1] = false;
        for (int_fast64_t i = 2; i < max_N; ++i) {
            for (int_fast64_t j = i * i; j < max_N; j += i)
                sieve[j] = false;
        }
    }
};

// BIT(Binary-Indexed-Tree) 別名：Fenwick Tree
class BIT {
  public:
    vector<int> bit;
    int M;

    BIT(int M) : bit(vector<int>(M + 1, 0)), M(M) {}

    int sum(int i) {
        if (!i)
            return 0;
        return bit[i] + sum(i - (i & -i));
    }

    void add(int i, int x) {
        if (i > M)
            return;
        bit[i] += x;
        add(i + (i & -i), x);
    }
};

const int SZ = 1e5 + 1;
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    constexpr auto p = Prime<SZ>();
    BIT bit(SZ);
    for (int i = 1; i < SZ; i += 2) {
        if (p.sieve[i] && p.sieve[(i + 1) / 2]) {
            bit.add(i, 1);
        }
    }
    int Q;
    cin >> Q;
    while (Q--) {
        int l, r;
        cin >> l >> r;
        cout << bit.sum(r) - bit.sum(l - 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 4180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll A, B, N, M; cin >> A >> B >> N;
  if(B-1<=N){
    M=B-1;
  }
  else M=N;
  cout << (A*M)/B << endl;
  return 0;
}

Measured memory_bytes: 3568
import sys
input = sys.stdin.readline
from collections import *

H, W = map(int, input().split())
s = [input()[:-1] for _ in range(H)]
dp = [[10**18]*W for _ in range(H)]

if s[0][0]=='.':
    dp[0][0] = 0
else:
    dp[0][0] = 1
    
for i in range(H):
    for j in range(W):
        if i>0:
            if s[i-1][j]=='.' and s[i][j]=='#':
                dp[i][j] = min(dp[i][j], dp[i-1][j]+1)
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
        
        if j>0:
            if s[i][j-1]=='.' and s[i][j]=='#':
                dp[i][j] = min(dp[i][j], dp[i][j-1]+1)
            else:
                dp[i][j] = min(dp[i][j], dp[i][j-1])

print(dp[-1][-1])

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

int main(){
	string s;
	cin >> s;
	vector<int> vec(26);
	string sam="abcdefghijklmnopqrstuvwxyz";
	for(int i=0; i<s.size(); i++){
		for(int j=0; j<26; j++){
			if(s.at(i)==sam.at(j)){
				vec.at(j)++;
			}
		}
	}
	for(int i=0; i<26; i++){
		if(vec.at(i)==0){
			cout << sam.at(i) << endl;
			break;
		}
		if(i==25 && vec.at(i)!=0){
			cout << "None" << endl;
		}
	}
}


Measured memory_bytes: 3788
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();
		System.out.println(S.substring(0,K-1)+Character.toLowerCase(S.charAt(K-1))+S.substring(K));
	}

}


Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <set>
#include <cmath>
#include <algorithm>
#define llint long long
#define eps 1e-9
#define inf 1e18
#define PI 3.14159265358979323846264

using namespace std;

struct vec2d{
	double x, y;
	vec2d(){}
	vec2d(double x, double y){
		this->x = x, this->y = y;
	}
	double add(double a, double b){
		if(fabs(a+b) < eps * (fabs(a) + fabs(b))) return 0.0;
		return a+b;
	}
	vec2d operator+(vec2d ope){
		return vec2d(add(x, ope.x), add(y, ope.y));
	}
	vec2d operator-(vec2d ope){
		return vec2d(add(x, -ope.x), add(y, -ope.y));
	}
	vec2d operator*(double t){
		return vec2d(x*t, y*t);
	}
	vec2d operator/(double t){
		return vec2d(x/t, y/t);
	}
	double dot(vec2d ope){
		return add(x*ope.x, y*ope.y);
	}
	double cross(vec2d ope){
		return add(x*ope.y, -y*ope.x);
	}
	double norm(){
		double d2 = dot(*this);
		if(d2 > 0) return sqrt(d2);
		return 0.0;
	}
};

double distPP(vec2d p, vec2d q){
	return (p-q).norm();
}

llint n;
vec2d p[305];

llint check(vec2d c)
{
	//cout << c.x << " " << c.y << endl;
	
	llint ret = 0;
	for(int i = 1; i <= n; i++){
		if(distPP(c, p[i]) <= 1+eps) ret++;
	}
	return ret;
}

int main(void)
{
	while(1){
		cin >> n;
		if(n == 0) break;
		for(int i = 1; i <= n; i++) cin >> p[i].x >> p[i].y;
		
		llint ans = 1;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(i >= j) continue;
				if(distPP(p[i], p[j]) > 2) continue;
				vec2d v = p[i]-p[j];
				double d = v.norm(), x = sqrt(1 - d*d/4);
				
				vec2d n = vec2d(v.y, -v.x);
				n = n / n.norm() * x;
				
				ans = max(ans, check(p[j]+v/2+n));
				ans = max(ans, check(p[j]+v/2-n));
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1 << 50;
const int WMAX = 1e+5;
const int NIL = -1;
/* global variables */
/* function */
/* main */
int main(){
    int N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

    vector<ll> dp(WMAX+1, 0);
    for (int i = 0; i < N; i++) {
        for (int j = WMAX - 1; j >= 0; j--) {
            dp[j+1] = max(dp[j+1], dp[j]);
            if (j + w[i] <= WMAX) dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
        }
    }
    cout << dp[W] << '\n';
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
int N;
ll sum = 0;
int main()
{
    cin >> N;
    vector<ll> a(N);
    rep(i, 0, N)
    {
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());

    for (int i = 0; i < (N + 1) / 2; i++)
    {
        sum += a[i];
    }
    for (int i = 1; i < N / 2; i++)
    {
        sum += a[i];
    }
    cout << sum << endl;
    return 0;
}

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

int main() {
  int N, count=0;
  cin >> N;
  for(int i=1; i<7; i++) {
    for(int j=0; j<N+1; j++) {
      if(pow(2,i)==j) {
        count++;
      }
    }
  }
  cout << pow(2, count) <<endl;
}

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

using namespace std;

int main() {
  string S, T;
  while (cin >> S >> T) {
    int ans = 0;
    for (int i = 0;i < S.length();i++) {
      if (S[i] == T[i])
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
#import numpy as np
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s,n,node):
    #頂点が探索済みかどうかのチェック配列
    check=[False for _ in range(n)]
    check[s]=True
    #次見る頂点を格納するキュー
    queue=deque([s])
    visited_num=1

    #問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color=[-1 for _ in range(n)]
    color[s]=0
    
    while visited_num<n:
        #グラフが全連結ではない場合
        if len(queue)==0:
            #空配列を返す
            #現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex=queue.popleft()
        #インデックスがない場合は
        for next_vertex in node[now_vertex]:


            if check[next_vertex]==True:
                continue

            queue.append(next_vertex)
            check[next_vertex]=True

            #問題固有の計算
            color[next_vertex]=color[now_vertex]+1
            visited_num+=1

    return color

mod=10**9+7
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))

n=int(input())
tmp=list(map(int,input().split()))
ans=sum(tmp)
tmp=Counter(tmp)
di=defaultdict(int)
for i in tmp.keys():
    di[i]+=tmp[i]

q_num=int(input())

for _ in range(q_num):
    #print(di)
    v,w=map(int,input().split())
    #print(ans)
    ans=ans-di[v]*v+di[v]*w
    di[w]+=di[v]
    del di[v]
    print(ans)
    

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

int main() {
  int X1, Y1, X2, Y2;
  cin >> X1 >> Y1 >> X2 >> Y2;

  int dx = X2 - X1;
  int dy = Y2 - Y1;
  int x3 = X2 - dy;
  int y3 = Y2 + dx;
  int x4 = X1 - dy;
  int y4 = Y1 + dx;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI                acos(-1)
#define pb                emplace_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define forr(i, b, e)     for(ll i = b; i < e; i++)
#define forg(i, b, e, m)  for(ll i = b; i < e; i+=m)
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

typedef long long       ll;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = ll(1e9 + 7);
const ll MOD = (1e9+7);
#define tam 123456
ll n;
ll dp[500][3][3];
ll f(int bit,int maax,int extra)
{
    if (bit==60)
    {
        return(maax==0)&(extra==0);
    }
    if (dp[bit][maax][extra]!=-1)
        return dp[bit][maax][extra];
    ll tot=0;
    if (extra)
    {
        if ((1ll<<bit)&n)
        {
            tot+=f(bit+1,0,1);
            tot+=f(bit+1,maax,1);
            tot+=f(bit+1,maax,0);
        }
        else
        {
            tot+=f(bit+1,maax,1);
            tot+=f(bit+1,1,0);
            tot+=f(bit+1,1,1);
        }
    }
    else
    {
        if ((1ll<<bit)&n)
        {
            tot+=f(bit+1,maax,0);
            tot+=f(bit+1,0,0);
            tot+=f(bit+1,0,1);
        }   
        else
        {
            tot+=f(bit+1,1,0);
            tot+=f(bit+1,maax,0);
            tot+=f(bit+1,maax,1);
        }
    }
    tot%=MOD;
    return dp[bit][maax][extra]=tot;
}
int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    memset(dp,-1,sizeof dp);
    cout<<f(0,0,0)<<endl;
}
// PLUS ULTRA!

Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
S = list(input())

for i in range(min(a, b), max(c, d)):
  if S[i-1] == "#" and S[i] == "#":
    print("No")
    exit()
if a < b and c > d or a > b and c < d:
#  print("mark")
  for i in range(max(a, b)-1, min(c, d)):
    if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
      print("Yes")
      exit()
  print("No")
  exit()
print("Yes")

Measured memory_bytes: 4916
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, p, q, c;
vector<int>P, Q, v;

int get() {
	int x;
	cin >> x;
	return x;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		P.push_back(get());
	}
	for (int i = 0; i < N; i++) {
		Q.push_back(get());
	}
	for (int i = 1; i <= N; i++) {
		v.push_back(i);
	}
	do {
		if (P == v)p = c;
		if (Q == v)q = c;
		c++;
	} while (next_permutation(v.begin(), v.end()));
	cout << abs(p - q) << endl;
}

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

typedef long long ll;
const int maxn = 105;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int mod;
inline int add(int x, int y) {return x + y > mod ? x + y - mod : x + y;}
inline int sub(int x, int y) {return x < y ? x - y + mod : x - y;}
inline void inc(int &x, int y) {x += y; if (x >= mod) x -= mod;}
inline void dec(int &x, int y) {x -= y; if (x < 0) x += mod;} 

int n, m, t;
int c[maxn][maxn], pw[maxn][maxn * maxn], f[2][maxn][maxn], tr[maxn][maxn];

void init()
{
	for (int i = 0; i <= n; ++i)
		for (int j = c[i][0] = 1; j <= i; ++j)
			c[i][j] = add(c[i - 1][j - 1], c[i - 1][j]);
	for (int i = 0; i <= t; ++i)
		for (int j = pw[i][0] = 1; j <= n * m; ++j) pw[i][j] = (ll)pw[i][j - 1] * i % mod;
}

int main()
{
	n = gi(); m = gi(); t = gi(); mod = gi();
	if (n < m) swap(n, m);
	init();

	int cur = 0;
	f[0][0][0] = 1;
	for (int k = 1; k <= t; ++k) {
		cur ^= 1; memset(f[cur], 0, sizeof(f[cur]));
		for (int j = 0; j <= m; ++j)
			for (int i = 0; i <= n; ++i) tr[j][i] = (ll)pw[k][i * (m - j)] * pw[t - k + 1][i * j] % mod;
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= m; ++j)
				if (f[cur ^ 1][i][j]) {
					for (int l = 0; l + i <= n; ++l)
						f[cur][i + l][j] = (f[cur][i + l][j] + (ll)f[cur ^ 1][i][j] * c[i + l][i] % mod * tr[j][l]) % mod;
				}
		cur ^= 1; memset(f[cur], 0, sizeof(f[cur]));
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= m; ++j) tr[i][j] = (ll)pw[k][j * (n - i)] * pw[t - k + 1][i * j] % mod;
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= m; ++j)
				if (f[cur ^ 1][i][j]) {
					for (int l = 0; l + j <= m; ++l)
						f[cur][i][j + l] = (f[cur][i][j + l] + (ll)f[cur ^ 1][i][j] * c[j + l][j] % mod * tr[i][l]) % mod;
				}
		cur ^= 1; memset(f[cur], 0, sizeof(f[cur]));
		for (int j = 0; j <= m; ++j)
			for (int i = 0; i <= n; ++i) tr[j][i] = (ll)pw[k][i * (m - j)] * pw[t - k][i * j] % mod;
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= m; ++j)
				if (f[cur ^ 1][i][j]) {
					for (int l = 0; l + i <= n; ++l)
						if (~l & 1) f[cur][i + l][j] = (f[cur][i + l][j] + (ll)f[cur ^ 1][i][j] * c[i + l][i] % mod * tr[j][l]) % mod;
						else f[cur][i + l][j] = (f[cur][i + l][j] + (ll)(mod - f[cur ^ 1][i][j]) * c[i + l][i] % mod * tr[j][l]) % mod;
				}
		cur ^= 1; memset(f[cur], 0, sizeof(f[cur]));
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= m; ++j) tr[i][j] = (ll)pw[k][j * (n - i)] * pw[t - k][i * j] % mod;
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= m; ++j)
				if (f[cur ^ 1][i][j]) {
					for (int l = 0; l + j <= m; ++l)
						if (~l & 1) f[cur][i][j + l] = (f[cur][i][j + l] +  (ll)f[cur ^ 1][i][j] * c[j + l][j] % mod * tr[i][l]) % mod;
						else f[cur][i][j + l] = (f[cur][i][j + l] + (ll)(mod - f[cur ^ 1][i][j]) * c[j + l][j] % mod * tr[i][l]) % mod;
				}
	}
	printf("%d\n", f[cur][n][m]);
	
	return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int N;  cin >> N;
vector<int> H(N);
for (int i = 0; i < N; i++) {
    cin >> H[i];
}

int ans = 0;
int tmp = 0;
for (int i = 0; i < N - 1; i++) {
    if (H[i] >= H[i + 1]) {
        tmp++;
        if (i == N - 2) {
            ans = max(ans, tmp);
        }
    } else {
        ans = max(ans, tmp);
        tmp = 0;
    }
}

cout << ans << endl;

}

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

int main() {
    vector<int> abc(3);
    cin >> abc[0] >> abc[1] >> abc[2];
    sort(abc.begin(), abc.end());
    int x = abc[2] - abc[0];
    int y = abc[2] - abc[1];
    int ans;
    if (x % 2 == 0 && y % 2 == 0) {
        ans = x / 2 + y / 2;
    } else if (x % 2 == 1 && y % 2 == 1) {
        ans = 1 + (x - 1) / 2 + (y - 1) / 2;
    } else {
        if (x % 2 == 1) swap(x, y);
        ans = 1 + x / 2 + (y + 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int X = Integer.parseInt(sc.next());
	  int A = Integer.parseInt(sc.next());
	  
	  if(X < A)
		  System.out.println(0);
	  else
		  System.out.println(10);
	  sc.close();
	  
  }
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    vector<ll> z(n-1);
    vector<ll> ans(n);
    ll a = 0;
    for (int i = 0; i < n-1; i++) {
        cin >> z[i];
    }
    ans[0] = z[0];
    ans[n - 1] = z[n - 2];
    for (int i = 1; i < n-1; i++) {
        ans[i] = min(z[i], z[i - 1]);
    }
    for (int i = 0; i < n; i++) {
        a += ans[i];
    }
    cout << a << endl;
}

Measured memory_bytes: 3612
{-# OPTIONS_GHC -Wall -Werror #-}

solve :: [Int] -> [Int]
solve = snd . foldl foldFunc ([], [])
  where foldFunc (x:xs, ys) 0 = (xs, ys ++ [x])
        foldFunc (xs, ys)   n = (n:xs, ys)

main :: IO ()
main = getContents >>= mapM_ (putStrLn . show) . solve . map read . words

Measured memory_bytes: 3872
import java.io.*;
//import java.util.Arrays;
import java.io.BufferedReader;
import java.io.InputStreamReader;
//import java.io.*;

class Main{
	public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    //double fval = 0.0, lval;
    //koch(n, 
    ans(0.0, 0.0);
    koch(n, 0.0, 0.0, 100.0, 0.0);
    ans(100.0, 0.0);
  }
  static void koch(int n, double p1x, double p1y, double p2x, double p2y){
    if(n == 0) return;
    double sx = (2 * p1x + p2x) / 3;
    double sy = (2 * p1y + p2y) / 3;
    double tx = (p1x + 2 * p2x) / 3;
    double ty = (p1y + 2 * p2y) / 3;

    double ux = (tx - sx) * Math.cos(60 * (Math.PI / 180)) - (ty - sy) * Math.sin(60 * (Math.PI / 180)) + sx;
    double uy = (tx - sx) * Math.sin(60 * (Math.PI / 180)) + (ty - sy) * Math.cos(60 * (Math.PI / 180)) + sy;

    koch(n - 1, p1x, p1y, sx, sy);
    ans(sx, sy);

    koch(n - 1, sx, sy, ux, uy);
    ans(ux, uy);

    koch(n - 1, ux, uy, tx, ty);
    ans(tx, ty);

    koch(n - 1, tx, ty, p2x, p2y);
  }
  static void ans(double x, double y){
    System.out.println(x+" "+y);
  }
}



Measured memory_bytes: 30548
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define endl '\n'

//Constants
const int N = 9;

//Data
int n;
int p[N], q[N];
vector<vector<int>> per;

//Methods
void pre()
{
  vector<int> v(n);
  for(int i = 0 ; i < n;  i++)
    v[i] = i + 1;
  do{
    per.push_back(v);
  }while(next_permutation(all(v)));
}

int get(int* arr)
{
  for(int i = 0 ; i < sz(per) ; i++){
    bool eq = true;
    for(int j = 0 ; j < n && eq ; j++)
      if(per[i][j] != arr[j])
        eq = false;
    if(eq)
      return i;
  }
  assert(false);
  return -1;
}

int main()
{
  cin >> n;
  pre();
  for(int i = 0 ; i < n ;i++)
    cin >> p[i];
  for(int i = 0 ; i < n ; i++)
    cin >> q[i];
  cout << abs(get(p) - get(q)) << endl;
  return 0;
}


Measured memory_bytes: 3256
#include<iostream>
//#include<cmath>
#include <string>
#include<vector>
#include <iomanip>
using namespace std;

class Dice{
private:
  int surface1;
  int surface2;
  int surface3;
  int surface4;
  int surface5;
  int surface6;
public:
  Dice(vector<int> dice){
    surface1=dice.at(0);
    surface2=dice.at(1);
    surface3=dice.at(2);
    surface4=dice.at(3);
    surface5=dice.at(4);
    surface6=dice.at(5);
  }

  void roll_dice(char direction){
    if(direction=='N'){
      int temp=surface1;
      surface1=surface2;
      surface2=surface6;
      surface6=surface5;
      surface5=temp;
    }
    else if(direction=='E'){
      int temp=surface1;
      surface1=surface4;
      surface4=surface6;
      surface6=surface3;
      surface3=temp;
    }
    else if(direction=='S'){
      int temp=surface1;
      surface1=surface5;
      surface5=surface6;
      surface6=surface2;
      surface2=temp;
    }
    else{
      int temp=surface1;
      surface1=surface3;
      surface3=surface6;
      surface6=surface4;
      surface4=temp;
    }
  }

  void disp_topdice(){
    cout<<surface1<<endl;
  }

};

int main(void){
  vector<int> dice(6);
  string str;

  for(int i=0;i<6;i++)cin>>dice.at(i);
  Dice dice1(dice);
  cin>>str;
  for(int i=0;i<str.size();i++) dice1.roll_dice(str[i]);

  dice1.disp_topdice();
  return 0;


}



Measured memory_bytes: 3168
/******************************************
* AUTHOR : AMAN SAXENA *
* "There's some good in this world, and it's worth fighting for." *
* INSTITUTION : KIET Group of Institutions *
******************************************/
#include <bits/stdc++.h>

const long long MODULO=1000000007;
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FOR1(i,a,n) for(int i=a;i<=n;i++)
#define FOR2(i,a,n) for(int i=a;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

template <typename TYPE> void in(TYPE &x){cin>>x;}

void solve()
{
    ll a,b;
    cin>>a>>b;
    cout << a*b ;
}

void test()
{
    int t;
    cin>>t;
    while(t--) //for(int j=1;j<=t;j++) cout << "Case #" << j << ": ";
    {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    // test();
    solve();
    
    return 0;
}

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

using namespace std;

long long gcd(long long a, long long b){ return a%b ? gcd(b, a%b) : b; }
long long lcm(long long a, long long b){ return a/gcd(a,b)*b; }

int solve(vector<int> a, int M){
    int m = 1;
    while(true){
        int cnt = 0;
        for(auto& t : a) if(t%4 == 0) ++cnt;
        if(cnt == 0) break;
        if(cnt != a.size()) return 0;
        for(auto& t : a) t /= 2;
        m *= 2;
    }
    long long res = 1;
    for(auto& t : a){
        res = lcm(res, t);
        if(res / 2 * m > M) return 0;
    }
    res *= m;
    long long base = res/2;
    if(M < base) return 0;
    return 1 + (M-base)/res;
}

int main(){
    int N, M;
    while(cin >> N >> M){
        vector<int> a(N);
        for(auto& t : a) cin >> t;
        cout << solve(a, M) << endl;
    }
}

Measured memory_bytes: 1024
def main():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(2)]
    lst = [[0 for _ in range(N)] for _ in range(2)]
    lst[0][0] = A[0][0]
    lst[1][0] = A[0][0] + A[1][0]

    for i in range(1, N):
        lst[0][i] = lst[0][i - 1] + A[0][i]

    for i in range(1, N):
        lst[1][i] = max(lst[0][i], lst[1][i - 1]) + A[1][i]

    print(lst[1][N - 1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 9220
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int N, A, B, C, D;
string S;

int check(int left, int right) {
	int ma = 0;
	int cnt = 0;
	left--, right--;
	for (int i = left; i <= right; i++) {
		if (S[i] == '#') {
			cnt++;
			ma = max(ma, cnt);
		}
		else cnt = 0;
	}
	return ma <= 1;
}
int check2(int left, int right) {
	left--, right--;
	int ok = 0;
	for (int i = left; i <= right; i++) {
		if (i == 0 || i == N-1)continue;
		if (S[i] == '#')continue;
		else{
			if (S[i - 1] == '#' || S[i + 1] == '#')continue;
			else ok = 1;
		}
	}
	return ok;
}

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


	cin >> N >> A >> B >> C >> D >> S;
	if (C <= B) {
		if (check(A, C) && check(B, D))puts("Yes");
		else puts("No");
	}
	else {
		if (C < D) {
			if (check(A, C) && check(B, D))puts("Yes");
			else puts("No");
		}
		else if (C == D)puts("No");
		else {
			if (check(A, C) && check(B, D)) {
				if (check2(B, D)) {
					puts("Yes");
				}
				else {
					puts("No");
				}
			}
			else {
				puts("No");
			}
		}
	}

	return 0;
}



Measured memory_bytes: 592
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

const int N = 430000;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    forn(i, n)
    {
        forn(j, m)
        {
            string s;
            cin >> s;
            if (s == "snuke")
            {
                cout << (char)(j + 'A') << i + 1 << "\n";
            }
        }
    }
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,l,r) for(int i = l; i <= r; ++i)
#define debug(x) cerr << #x << " = " << x << '\n';
#define int long long
using namespace std;
const int maxn = 1000034;
int N = 0;
const int mod = 998244353;
int powmod(int x, int k)
{
    int res = 1;
    for(; k; k >>= 1)
    {
        if(k&1)
            res = 1ll*res*x%mod;
        x = 1ll*x*x%mod;
    }
    return res;
}
#define task "LCMS"
int n;
int w[maxn] = {0}, f[maxn] = {0};
int cnt[maxn] = {0};
int ans = 0;
int a[maxn];
main()
{
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    FOR(i, 1, n)
    {
        int cur;
        cin >> cur;
        a[i] = cur;
        N = max(cur, N);
        cnt[cur]++;
    }
    FOR(i, 1, N)
    {
        w[i] = (mod + w[i] +  powmod(i, mod - 2))%mod;
        for(int j = 2; i*j <= N; j ++)
            w[i*j] = (w[i*j] - w[i] + mod*mod)%mod;
    }
    FOR(i, 1, N)
    for(int j = 1; i*j <= N; j ++)
        f[i] = (f[i] + 1ll*cnt[i*j]*i*j)%mod;
    FOR(i, 1, N) f[i] = f[i]*f[i]%mod;
    FOR(i, 1, N)
    for(int j = 1; i*j <= N; j ++)
        f[i] = (f[i] - (cnt[i*j]*i*j%mod)*(i*j%mod)%mod + mod*mod)%mod;
    FOR(i, 1, N) f[i] = f[i]*powmod(2, mod - 2)%mod;
    FOR(i, 1, N) ans =  (ans + w[i]*f[i])%mod;
    cout << ans;
    return 0;
}


Measured memory_bytes: 26880
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;

int main() {
  int N;
  cin >> N;
  map<int, int> mp0, mp1;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (i % 2 == 0) {
      mp0[x]++;
    } else {
      mp1[x]++;
    }
  }
  vector<pair<int, int>> v0, v1;
  for (auto e : mp0) v0.emplace_back(e.second, e.first);
  for (auto e : mp1) v1.emplace_back(e.second, e.first);
  v0.emplace_back(0, -1);
  v0.emplace_back(0, -1);
  v1.emplace_back(0, -2);
  v1.emplace_back(0, -2);
  sort(v0.begin(), v0.end(), greater<pair<int, int>>());
  sort(v1.begin(), v1.end(), greater<pair<int, int>>());
  int ans = 1e9;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      if (v0[i].second != v1[j].second) {
        int c0 = (N + 1) / 2 - v0[i].first;
        int c1 = (N + 0) / 2 - v1[j].first;
        ans = min(ans, c0 + c1);
      }
    }
  }
  cout << ans << '\n';
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	int n,m;
	cin >> n >> m;
	priority_queue<int> que;
	rep(i,n){
		int a;
		cin >> a;
		que.push(a);
	}

	for(int i = 0; i < m; i++){
		int num = que.top();
		que.pop();
		que.push(num/2);
	}

	ll sum = 0;
	for(int i = 0; i < n; i++){
		sum += que.top();
		que.pop();
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 892
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define llong long long
using namespace std;

void read(int &x)
{
    int f=1;x=0;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    x*=f;
}

const int N = 2e5;
llong a[N+3];
llong s[N+3];
int n; llong m,ans;

void solve()
{
	s[0] = 0ll; for(int i=1; i<=n; i++) s[i] = s[i-1]+a[i];
	for(int i=1; i<=n; i++)
	{
		llong tmp;
		if(i&1)
		{
			int x = (i-1)>>1;
			tmp = (m*x-(s[n]-s[n-x]))*2+a[n-x]+(s[n-x-1]-s[n-x-x-1])*2;
		}
		else
		{
			int x = i>>1;
			tmp = (m*(x-1)-(s[n]-s[n-x+1]))*2+(m-a[n-x+1])+(s[n-x]-s[n-x-x])*2;
		}
		ans = max(ans,tmp);
	}
}

int main()
{
	scanf("%lld%d",&m,&n);
	for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
	solve();
	for(int i=1; i<=n; i++) a[i] = m-a[i];
	reverse(a+1,a+n+1);
	solve();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+ 8;

LL x[MAXN];

int main()
{
    #ifdef LOCAL
    freopen("a.txt", "r", stdin);
    //freopen("a.out", "w", stdout);
    int T = 4;
    while(T--){
    #endif // LOCAL
    ios::sync_with_stdio(false); cin.tie(0);

    LL n, ans = 0, i, a = -1, b = -1;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> x[i];
    }
    sort(x, x + n);
    for(i = n-2; i >= 0; i--){
        if(x[i] == x[i+1]){
            if(a == -1){
                a = x[i];
            }
            else if(b == -1){
                b = x[i];
            }
            i--;
        }
    }
    if(b == -1){
        cout << 0 << "\n";
    }
    else cout << a*b << "\n";


    #ifdef LOCAL
    cout << endl;
    }
    #endif // LOCAL
    return 0;
}



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

using namespace std;

int main(){
    char a, b; cin >> a >> b;

    if(a == 'H'){
        if(b == 'H'){
            cout << 'H' << endl;
        }else{
            cout << 'D' << endl;
        }
    }else{
        if(b == 'D'){
            cout << 'H' << endl;
        }else{
            cout << 'D' << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main(){
    string s; cin >> s;
    int ans = 0;

    rep(i,s.length()){
        ans += (int)(s[i]-'0');
        ans %= 9;
    }
    if(ans == 0) cout <<"Yes";
    else cout <<"No";
}

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

int main() {
  int C,R,a,b;
  cin >> C >> R;
  vector<int> v(C,0);
  for(int i=0;i<R;i++){
    cin >> a >> b;
    v.at(a-1)++;
    v.at(b-1)++;
  }
  for(int i=0;i<C;i++){
    cout << v.at(i) << endl;
  }
}


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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)

#define pb push_back
#define pf push_front
#define mp make_pair
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define len(str) str.size()


using namespace std;

typedef complex<double> P;
typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }
inline int gcd(int a, int b) {
    if (b == 0) return a;
    return a < b? gcd(b, a) : gcd(b, a % b);
}
ll mo=1000000007;


int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }


    int s, k;
    cin >> k >> s;
    int cnt = 0;

    FO(i, k + 1) {
        if (s >= i && s <= i + 2 * k) {
            int s1 = s - i;
            FO(j, k + 1) {
                if (s1 >= j && s1 <= j + k) {
                    ++cnt;
                }
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256