akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline void LB(vector<T>& v, T& a) { return *lower_bound(ALL(v),a); }
template <typename T> inline void LBP(vector<T>& v, T& a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline void UB(vector<T>& v, T& a) { return *upper_bound(ALL(v),a); }
template <typename T> inline void UBP(vector<T>& v, T& a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; }
template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N;
  cin >> N;
  vector<int> A(N);
  cin >> A;
  vector<int> B = A;
  SORT(B); REV(B);
  REP(i,N) {
    if (A[i] == B[0]) {
      cout << B[1] << endl;
    } else {
      cout << B[0] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 4736
import java.util.Scanner;

class Solver {

    private final int A;
    private final int B;
    private final int AB;
    private final int X;
    private final int Y;

    Solver(Scanner in){
        A = in.nextInt();
        B = in.nextInt();
        AB = in.nextInt();
        X = in.nextInt();
        Y = in.nextInt();
    }

    void solve() {
        if (A + B <= AB * 2) {
            System.out.println(A * X + B * Y);
            return;
        }
        int max = Math.max(X, Y);
        int min = Math.min(X, Y);
        int temp = A * X + B * Y;
        for (int i = min; i <= max; i++) {
            temp = Math.min(i * 2 * AB + A * Math.max(X - i, 0) + B * Math.max(Y - i, 0), temp);
        }
        System.out.println(temp);
    }
}

class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        new Solver(in).solve();

        in.close();
    }
}

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

#define ll long long

int main(){
	ll int n;
	cin>>n;
	int k = n%10;
	
	if(k==2 || k==4||k== 5||k== 7||k== 9){ cout<<"hon"<<endl;}
	else if(k==3){ cout<<"bon"<<endl;}
	else cout<<"pon"<<endl;
	
return 0;	
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
using ll = long long;
constexpr ll pow(const ll a, const ll b, const ll mod) { return b == 0 ? 1LL : b % 2 == 1 ? pow(a, b - 1, mod) * a % mod : pow(a * a % mod, b / 2, mod); }
constexpr ll inverse(const ll a, const ll mod) { return pow(a, mod - 2, mod); }
constexpr ll MOD0 = 1000000007LL, MOD1 = 1000000009LL, MOD2 = 1000000021;
constexpr ll X = 121234243;
constexpr ll XINV0 = inverse(X, MOD0), XINV1 = inverse(X, MOD1), XINV2 = inverse(X, MOD2);
constexpr int L = 250000;
using P = std::tuple<ll, ll, ll>;
P power[L+1] = {P{1, 1, 1}}, invpower[L+1] = {P{1, 1, 1}};
auto plus = [](const P& p1, const P& p2) { return P{(std::get<0>(p1) + std::get<0>(p2)) % MOD0, (std::get<1>(p1) + std::get<1>(p2)) % MOD1, (std::get<2>(p1) + std::get<2>(p2)) % MOD2}; };
auto minus = [](const P& p1, const P& p2) { return P{(std::get<0>(p1) + MOD0 - std::get<0>(p2)) % MOD0, (std::get<1>(p1) + MOD1 - std::get<1>(p2)) % MOD1, (std::get<2>(p1) + MOD2 - std::get<2>(p2)) % MOD2}; };
auto rshift = [](const P& p) { return P{std::get<0>(p) * X % MOD0, std::get<1>(p) * X % MOD1, std::get<2>(p) * X % MOD2}; };
auto lshift = [](const P& p) { return P{std::get<0>(p) * XINV0 % MOD0, std::get<1>(p) * XINV1 % MOD1, std::get<2>(p) * XINV2 % MOD2}; };
auto mul = [](const P& p1, const P& p2) { return P{std::get<0>(p1) * std::get<0>(p2) % MOD0, std::get<1>(p1) * std::get<1>(p2) % MOD1, std::get<2>(p1) * std::get<2>(p2) % MOD2}; };
int main()
{
    for (int i = 1; i <= L; i++) { power[i] = rshift(power[i - 1]), invpower[i] = lshift(invpower[i - 1]); }
    auto invp = [](const int i) { return i >= 0 ? invpower[i] : power[-i]; };
    int N;
    std::string S;
    std::cin >> N >> S;
    std::vector<int> deg(N + 1, 0);
    std::vector<P> value(N + 1, P{0, 0, 0});
    for (int i = N - 1; i >= 0; i--) {
        if (S[i] == '-') {
            deg[i] = deg[i + 1], value[i] = minus(value[i + 1], P{1, 1, 1});
        } else if (S[i] == '+') {
            deg[i] = deg[i + 1], value[i] = plus(value[i + 1], P{1, 1, 1});
        } else if (S[i] == '>') {
            deg[i] = deg[i + 1] + 1, value[i] = rshift(value[i + 1]);
        } else {
            deg[i] = deg[i + 1] - 1, value[i] = lshift(value[i + 1]);
        }
    }
    const P answer = value[0];
    for (int i = 0; i <= N; i++) { value[i] = mul(minus(value[i], answer), invp(deg[i])); }
    std::map<P, ll> mp;
    ll ans = 0;
    for (int i = 0; i <= N; i++) {
        const P obj = plus(value[i], mul(invp(deg[i]), answer));
        if (mp.find(obj) != mp.end()) { ans += mp[obj]; }
        mp[value[i]]++;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 38532
<?php
list($H,$W)=sscanf(trim(fgets(STDIN)),"%d %d");
if($H == 1){
    echo 1;
    exit;
}
if($W == 1){
    echo 1;
    exit;
}

$p1 = ceil($W / 2);
$p2 = floor($W / 2); //きりすて
$calc = 0;
$calc = $p1 * ceil($H/2);
$calc += $p2 * floor($H/2);
echo (int)$calc;

Measured memory_bytes: 4856
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int X, Y;
	cin >> X >> Y;

	string str = "No";
	if(Y % 2 == 1) {
		cout << str << "\n";
		return 0;
	}

	for(int l2Cnt=0; l2Cnt <= X; l2Cnt++) {
		int l4Cnt = X - l2Cnt;

		int legTotal = (l2Cnt*2) + (l4Cnt*4);
		// cout << "legTotal:" << legTotal << "\n";
		if(legTotal == Y) {
			str = "Yes";
			break;
		}
	}

	cout << str << "\n";
	return 0;
}

Measured memory_bytes: 3624
s=list(input())
s1=[]
s2=[]

for i in range(len(s)):
    if i%2==0:
        s1.append('0')
        s2.append('1')
    else:
        s1.append('1')
        s2.append('0')
    
count1=0
count2=0
for i in range(len(s)):
    if s[i]!=s1[i]:
        count1+=1
    if s[i]!=s2[i]:
        count2+=1
        
print(min(count1,count2))

Measured memory_bytes: 5512
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


def f(x):
    if x == 0:
        return 0
    return f(x % pop_count(x)) + 1


def solve():
    N = Scanner.int()
    S = Scanner.string()
    pc = sum([s == '1' for s in S])
    ans = [0 for _ in range(N)]
    for b in range(2):
        npc = pc
        if b == 0:
            npc += 1
        else:
            npc -= 1
        if npc <= 0:
            continue
        r0 = 0
        for i in range(N):
            r0 = ((r0 * 2) + int(S[i])) % npc
        k = 1
        for i in reversed(range(N)):
            if int(S[i]) == b:
                r = r0
                if b == 0:
                    r = (r + k) % npc
                else:
                    r = (r - k + npc) % npc
                ans[i] = f(r) + 1
            k = (k * 2) % npc
    print(*ans, sep='\n')


def main():
    sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 15704
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        n: usize,
    };
    
    println!("{}", (n + 1) / 2);
}


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

int D[35][35];
int F[505][505];

map<int,int> cnt[3];

int main(){
  int N, C;
  cin >> N >> C;
  rep(i,C){
    rep(j,C){
      cin >> D[i+1][j+1];
    }
  }
  rep(i,N){
    rep(j,N){
      cin >> F[i][j];
      int m = ((i+1) + (j+1))%3;
      cnt[m][F[i][j]]++;
    }
  }

  int sum = 1000000000;
  
  REP(i,1,C+1){
    REP(j,1,C+1){
      REP(k,1,C+1){
        if(i==j || j==k || i==k) continue;
        vector<int> v;
        v.push_back(i);
        v.push_back(j);
        v.push_back(k);
        
        int tmp = 0;
        rep(l,3){
          FOR(it,cnt[l]){
            int p = it->first, c = it->second;
            tmp += D[p][v[l]] * c;
          }
        }

        sum = min(sum, tmp);
        
      }
    }
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <math.h>

char prime[999999];

int main(void)
{
	int i;
	int n;
	
	for (i = 2; i < 999999; i++){
		prime[i] = 1;
	}
	for (i = 2; i < (int)sqrt(999999); i++){
		if (prime[i] == 0) continue;
		else {
			int j;
			for (j = i * 2; j < 999999; j += i){
				prime[j] = 0;
			}
		}
	}
	
	while (scanf("%d", &n) != EOF){
		for (i = n - 1; prime[i] == 0; i--);
		printf("%d ", i);
		for (i = n + 1; prime[i] == 0; i++);
		printf("%d\n", i);
	}
	
	return 0;
}

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

using namespace std;


void solve() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for (auto& x: a) {
        cin >> x;
        sum += x;
    }
    int cnt = 0;
    for (int x: a) if (x*4*m >= sum) cnt++;
    cout << (cnt>=m ? "Yes": "No");
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


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

lli n, a, b, c, d;
string s;

int main(void){
	cin >> n >> a >> b >> c >> d >> s;
	a--;
	b--;
	c--;
	d--;
	s+='.';
	if(c > d){
		bool f = false;
		for(int i = b; i <= d; i++){
			if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') f = true;
		}
		if(!f){
			cout << "No" << endl;
			return 0;
		}
	}
	bool ans = true;
	for(int i = a; i < c; i++){
		if(s[i] == '#' && s[i+1] == '#') ans = false;
	}
	for(int i = b; i < d; i++){
		if(s[i] == '#' && s[i+1] == '#') ans = false;
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=200010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
vector<int>G[100010];
int main(){
	int n,m;cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;cin>>a>>b;a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	bool v[100010]={false};
	int L=0;int R=G[0][0];
	v[L]=true;v[R]=true;
	deque<int> q;
	q.push_front(L);q.push_back(R);
	int lo=2;
	while(1){
		bool f=true;
		int l=L;int r=R;
		for(int i=0;i<G[l].size();i++){
			int e=G[l][i];
			if(v[e])continue;
			lo++;
			q.push_front(e);
			v[e]=true;
			L=e;
			f=false;
			break;
		}
		for(int i=0;i<G[r].size();i++){
			int e=G[r][i];
			if(v[e])continue;
			lo++;
			q.push_back(e);
			v[e]=true;
			R=e;
			f=false;
			break;
		}
		if(f)break;
	}
	cout<<lo<<endl;
	for(int i=0;i<q.size();i++){
		cout<<q[i]+1;
		if(i!=q.size()-1){
			cout<<" ";
		}
	}
	cout<<endl;
    return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define fast_io ios::sync_with_stdio(false);cin.tie(NULL);
#define input freopen("Test.txt","r",stdin)
#define output freopen("Output.txt","w",stdout);
#define what_is(x) cout<<#x<<" is "<<x<<endl;
#define F(i,a,b) for(int i = a; i < b; i++)
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define inf 1000000000
const double pi = 3.141592653589793238460;
#define debug false
#define MAXN 100010
#define mod 1000000007

vector<int> adj[100010];
int dist1[100010],dist2[100010];

void dfs(int node,int par,int dist[])
{
	dist[node] = dist[par]+1;
	for(auto i:adj[node])
	{
		if(i!=par)
			dfs(i,node,dist);
	}
}



void solve()
{
	int n; cin>>n;
	int a,b;
	cin>>a>>b;
	for(int i=0;i<n-1;i++)
	{
		int u,v;
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dist1[0] = -1;
	dist2[0] = -1;
	dfs(a,0,dist1);
	dfs(b,0,dist2);
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		if(dist1[i]<dist2[i])
		{
			ans = max(ans,dist2[i]-1);
		}
	}
	cout<<ans<<"\n";
}

int main()
{
     // input; // output; // if(debug){watch_is();}
    fast_io;
    solve();   
    return 0;
}

Measured memory_bytes: 10368
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
from copy import deepcopy

N = int(input())
oary = input().split()


def bubble_sort(ary):
    for i in range(N):

        for j in range(N - 1, i, -1):
            if int(ary[j][1:]) < int(ary[j - 1][1:]):
                ary[j], ary[j - 1] = ary[j - 1], ary[j]


def selection_sort(ary):

    for i in range(0, N):
        minj = i

        for j in range(i, N):
            if int(ary[j][1:]) < int(ary[minj][1:]):
                minj = j

        ary[i], ary[minj] = ary[minj], ary[i]


def naive_check(oary, nary):
    for i in range(1, N - 1):
        for j in range(i + 1, N):
            for a in range(1, N - 1):
                for b in range(a + 1, N):

                    if int(oary[i][1:]) == int(nary[j][1:]):
                        if oary[i] == nary[b]:
                            if oary[j] == nary[a]:
                                return False

    return True


def is_stable(oary, nary):

    if naive_check(oary, nary):
        print('Stable')
    else:
        print('Not stable')


bary = deepcopy(oary)
bubble_sort(bary)
print(' '.join(bary))
print('Stable')
# is_stable(oary, bary)

sary = deepcopy(oary)
selection_sort(sary)
print(' '.join(sary))
if bary == sary:
    print('Stable')
else:
    print('Not stable')
# is_stable(oary, sary)



Measured memory_bytes: 6344
/**
 *    author:  RM07
 *    created: August 15, 2020 6:08 PM
 *    motto: Knowledge is Power, Strive for Excellence
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed main(){
    int n,k;
    cin >> n >> k;
    int *P = new int[n+1];
    int *C = new int[n+1];
    int S[n+1] = {0};
    for(int i = 1 ; i <= n ; i++) {
        cin >> P[i];
    } 
    for(int i = 1; i <= n ; i++) {
        cin >> C[i];
    }
    int ans = INT_MIN;
    for(int start = 1; start <= n; start++) {
        int cnt = 0;
        int curr = start;
        int mx = INT_MIN;
        int sum = 0;
        while(true){
            cnt++;
            curr = P[curr];
            sum += C[curr];
            S[cnt] = sum;
            mx = max(mx, sum);
            if(curr == start) {
                break;
            }
        }
        for(int x = 1; x <= cnt && x <= k ;x++) {
            ans = max(ans, S[x]);
            if(sum > 0) {
                ans = max(ans, S[x] + sum * ((k - x) / cnt));
            }
        }

    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3716
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
z = [x + y for x, y in xy]
w = [x - y for x, y in xy]
z.sort()
w.sort()

ans = max(z[-1] - z[0], w[-1] - w[0])
print(ans)

Measured memory_bytes: 62100
#include <iostream>
#include <cmath>

using namespace std;

int main(void){
  int L,R,d;
  cin >> L >> R >> d;
  int count = 0;
  for(int n=L;n<=R;n++){
    if(n%d == 0){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <cstdio>


int main(){
	int a,b,ans;

	ans=0;
	scanf("%d %d",&a,&b);
	if(a>b){
		ans+=a;
		a--;
	}else{
		ans+=b;
		b--;
	}

	if(a>b){
		ans+=a;
		a--;
	}else{
		ans+=b;
		b--;
	}

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

	return 0;
}


Measured memory_bytes: 128
import copy
N = int(input())
p = list(map(int,input().split()))
a = sorted(p)
if a==p:
  print("YES")
  exit()
for i in range(N):
  for j in range(i,N):
    b = copy.deepcopy(p)
    l = b[i]
    b[i] = b[j]
    b[j] = l
    if a==b:
      print("YES")
      exit()
print("NO")

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

template< typename Monoid >
struct SegmentTree {
    using F = function< Monoid(Monoid, Monoid) >;

    int sz;
    vector< Monoid > seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x) {
        seg[k + sz] = x;
    }

    void build() {
        for(int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x) {
        k += sz;
        seg[k] = x;
        while(k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) L = f(L, seg[a++]);
            if(b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const {
        return seg[k + sz];
    }
};

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

	ll MOD = 998244353;

	ll n;
	cin >> n;

	vector<pll> v(n);
	rep(i, n) cin >> v[i].first >> v[i].second;

	sort(v.begin(), v.end());

	SegmentTree<ll> f(n, [](ll a, ll b){ return max(a, b);}, 0ll);
	for(int i = n-1; i >= 0; i--){
		f.update(i, i);
		ll x = v[i].first;
		ll d = v[i].second;

		auto it = upper_bound(v.begin(), v.end(), (pll){x + d, -1ll});
		it--;
		ll r = it - v.begin();

		ll val = f.query(i, r+1);
		f.update(i, val);
	}

	vector<ll> dp(n+1, 0);
	dp[n] = 1;
	for(int i = n-1; i >= 0; i--){
		ll r = f.query(i, i+1);
		dp[i] += dp[r+1];
		dp[i] %= MOD;

		dp[i] += dp[i+1];
		dp[i] %= MOD;
	}

	cout << dp[0] << endl;
}


Measured memory_bytes: 11844
n=int(input())
h=list(map(int,input().split()))
r=0
l=0
ans=0
cnt=0
while r<n and l<n:
  if r==l:
    r+=1
  else:
    if h[r-1]>=h[r]:
      cnt+=1
      r+=1
      ans=max(ans,cnt)
    else:
      l+=1
      cnt=0

print(ans)      

Measured memory_bytes: 14224
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	int n;
	cin >> n;

	vector<int> coordinates(n + 2);
	int total_distance = 0;
	int pos = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> coordinates[i];
		total_distance += abs(coordinates[i] - pos);
		pos = coordinates[i];
	}	

	total_distance += abs(pos);

	for (int i = 1; i <= n; ++i) {
		int curr = total_distance;
		curr -= abs(coordinates[i] - coordinates[i - 1]);
		curr -= abs(coordinates[i] - coordinates[i + 1]);
		curr += abs(coordinates[i - 1] - coordinates[i + 1]);
		cout << curr << "\n";
	}

	return 0;

}

Measured memory_bytes: 1664
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if w>=v:
  print("NO")
else:
  d=0
  if b>a:
    d=b-a
  else:
    d=a-b
  if d/(v-w)<=t:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 9192
#include <stdio.h>
int main(void){
  int a,b;
  while(scanf("%d %d",&a,&b)!=EOF){
    int s = a + b;
    int j;
    for(j=0;s>0;j++)s/=10;
    printf("%d\n",j);
  }
  return 0;
}
 

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	int n;
	cin >> n;

	vector<int> t(n);
	vector<int> x(n);
	vector<int> y(n);
	rep (i, 0, n)
		cin >> t[i] >> x[i] >> y[i];

	int old_t, old_x, old_y;
	old_t = old_x = old_y = 0;
	bool judge = true;
	rep (i, 0, n) {
		int tmp_t = t[i] - old_t;
		int tmp_d = abs(x[i] - old_x) + abs(y[i] - old_y);
		if (tmp_t < tmp_d
				|| tmp_t % 2 != tmp_d % 2) {
			judge = false;
			break;
		}
		old_t = t[i];
		old_x = x[i];
		old_y = y[i];
	}

	cout << ((judge) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 1408
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	numL = []
	for i in range(N):
		A, B = getlist()
		numL.append([A, B])
	KK = K

	Kbit = []
	while True:
		Kbit.append(K % 2)
		K = int(K // 2)
		if K == 0:
			break

	Kbit = Kbit[::-1]
	M = len(Kbit)
	Ksum = [0] * M
	if Kbit[0] == 1:
		Ksum[0] = 2 ** (M - 1)
	for i in range(1, M):
		if Kbit[i] == 1:
			Ksum[i] = Ksum[i - 1] + 2 ** (M - 1 - i)
		else:
			Ksum[i] = Ksum[i - 1]

	# print(Kbit)
	# print(Ksum)

	ans = 0
	for i in range(1, M - 1):
		if Kbit[i] == 1:
			var = Ksum[i - 1] + 2 ** (M - 1 - i) - 1
			cnt = 0
			for j in range(N):
				A = numL[j][0]
				B = numL[j][1]
				if var | A == var:
					cnt += B

			ans = max(ans , cnt)

	cnt = 0
	for i in range(N):
		A = numL[i][0]
		B = numL[i][1]
		if (2 ** (M - 1) - 1) | A == (2 ** (M - 1) - 1):
			cnt += B
	ans = max(ans, cnt)
	cnt = 0
	for i in range(N):
		A = numL[i][0]
		B = numL[i][1]
		if KK | A == KK:
			cnt += B
	ans = max(ans, cnt)

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 22380
n = int(input())
h = list(map(int, input().split()))

h.reverse()

for i in range(n-1):
    if h[i] >= h[i+1]:
        pass

    elif h[i] == h[i+1] - 1:
        h[i+1] -= 1

    else:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 20748
#include<bits/stdc++.h>
using namespace std;
#define int long
signed main(){
  int n,r=0;
  cin>>n;
  vector<int> v;
  while(n){
    v.push_back(n%10);
    n/=10;
  }
  n=v.size();
  for(int i=0;i<v.size()-1;++i){
    if(v[i]==9)continue;
    v[i]=9,--v[i+1];
  }
  for(auto i:v)r+=i;
  cout<<r;
}

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


int main()
{
  int n,c,i,j;
  cin>>n;
  cin>>c;
  vector<int>w(n+1);
  vector<long int>v(n+1);
  
  vector<vector<long int>> kp(n+1, vector<long int>(c+1));
  kp[0]=vector<long int>(c+1,0);
  for(i=1;i<n+1;i++)
  kp[i][0]=0;
  
  w[0]=0;
  v[0]=0;
  for(i=1;i<n+1;i++)
  {
      cin>>w[i];
      cin>>v[i];
  }
  
  for(i=1;i<n+1;i++)
  {
      for(j=1;j<c+1;j++)
      {
          if(w[i]>j)
          kp[i][j]=kp[i-1][j];
          else
          {
              kp[i][j]=max(kp[i-1][j],kp[i-1][j-w[i]]+v[i]);
          }
      }
  }
  cout<<kp[n][c];
  
}


Measured memory_bytes: 80256
input()
hl=map(int, input().split())

prev = 0
cnt = 0
max_cnt = 0
for i in hl:
  if prev == 0:
    prev = i
    continue
  if i <= prev:
    cnt += 1
    if cnt > max_cnt:
      max_cnt = cnt
  else:
    cnt = 0
  prev = i
print(max_cnt)

Measured memory_bytes: 64112
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int K;
  cin >> K;
  int kotae = 0;
  int a;
  for (int i=0; i < N; i++){
    cin >> a;
    if (a >= K){
      kotae++;
    }
  }
  cout << kotae;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
#include<iterator>
#include<queue>
#include<functional>
using namespace std;

const int MAX_V = 1000;
const int INF = INT_MAX / 2;
typedef pair<int, int> P;

struct edge { int to, cap, cost, rev; };

int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prev_v[MAX_V];
int prev_e[MAX_V];

void add_edge(int s, int t, int cap, int cost) {
    edge forward_edge = { t, cap, cost, G[t].size() };
    G[s].push_back(forward_edge);
    edge backward_edge = { s, 0, -cost, G[s].size() - 1 };
    G[t].push_back(backward_edge);
}

int minimum_cost_flow(int s, int t, int f){
    int res = 0;
    fill(h, h+V, 0);

    while(f>0){
        priority_queue< P, vector<P>, greater<P> > que;
        fill(dist, dist+V, INF);
        dist[s] = 0;
        que.push(P(0, s));
        while(!que.empty()){
            P p = que.top();
            que.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            for (int i=0;i<G[v].size();i++){
                edge &e = G[v][i];
                if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] -h[e.to]){
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prev_v[e.to] = v;
                    prev_e[e.to] = i;
                    que.push(P(dist[e.to], e.to));
                }
            }
        }
        if (dist[t] == INF) return -1;

        for (int v=0;v<V;v++){
            h[v] += dist[v];
        }
        int d = f;
        for (int v=t;v!=s;v=prev_v[v]){
            d = min(d, G[prev_v[v]][prev_e[v]].cap);
        }
        f -= d;
        res += d * h[t];
        for (int v=t;v!=s;v=prev_v[v]){
            edge &e = G[prev_v[v]][prev_e[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

int main(){
    int E, F;
    cin >> V >> E >> F;
    int u, v, c, d;
    for (int i=0;i<E;i++){
        cin >> u >> v >> c >> d;
        add_edge(u, v, c, d);
    }
    cout << minimum_cost_flow(0, V-1, F) << endl;
}


Measured memory_bytes: 3208
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N, K = LI()
    A = LI()

    P = sorted([ai for ai in A if ai > 0])
    Pm = sorted([-ai for ai in A if ai > 0])
    M = sorted([ai for ai in A if ai < 0])
    Mp = sorted([- ai for ai in A if ai < 0])
    zero = [ai for ai in A if ai == 0]

    zero_len = len(P) * len(zero) + len(M) * len(zero) + len(zero) * (len(zero) - 1) // 2

    if K <= len(P) * len(M):
        left = - 10 ** 18 - 1
        right = 0
        ans = right
        while right - left != 1:
            tmp = 0
            mid = (left + right) // 2
            for mi in M:
                tmp += bisect_right(Pm, - mid // mi)

            if tmp >= K:
                ans = min(ans, mid)
                right = mid
            else:
                left = mid
        print(ans)
    elif K <= len(P) * len(M) + zero_len:
        print(0)
    else:
        diff = len(P) * len(M) + zero_len
        left = 0
        right = 10 ** 18 + 1
        ans = right
        while right - left != 1:
            tmp = 0
            mid = (left + right) // 2
            for pi in P:
                tmp += bisect_right(P, mid // pi)
                tmp -= 1 if mid // pi >= pi else 0
            for mpi in Mp:
                tmp += bisect_right(Mp, mid // mpi)
                tmp -= 1 if mid // mpi >= mpi else 0
            tmp //= 2
            if tmp + diff >= K:
                ans = min(ans, mid)
                right = mid
            else:
                left = mid
        print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;

int main()
{
    #ifdef HOME
    freopen("input.txt", "rt", stdin);
    #endif // HOME
    string s;
    cin >> s;
    if (s[0] == '9' || s[1] == '9')
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    n *= 2;
    string s;
    cin >> s;
    s = "W" + s + "W";
    VI a(n + 1);
    REP(i,n+1){
        a[i] = (s[i] != s[i + 1]);
    }
    VL c(n);
    REP(i,n){
        if (a[i]){
            c[i] = 1;
        }else{
            c[i] = -1;
            a[i+1] ^= 1;
        }
    }
    ll ans = 1, x = 0;
    REP(i,n){
        if (c[i] == -1){
            ans = (ans * x) % mod;
        }
        x += c[i];
    }
    if (x != 0) ans = 0;
    FOR(x,1,n/2) ans = (ans * x) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2884
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define tcase int _; cin >> _; while(_--)
const int MAX = 1e6;

string s,t;
int ans;

void solve() {
	cin >> s >> t;
	ans = t.size();
	for(int i=0; i<=s.size()-t.size(); i++) {
		int cnt=0;
		for(int j=0; j<t.size(); j++) {
			if(s[i+j] != t[j]) cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans;
}

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

 	solve();

  	return 0;
}



Measured memory_bytes: 3612
def DFS(v):
    global rst
    if v<=N:
        L.append(v)
        DFS(v+1)
        L.pop()
        DFS(v+1)
    else:
        cost=[0]*M
        for i in L:
            for j in range(M):
                cost[j]+=CA[i-1][j+1]

        for i in range(M):
            if cost[i]<X:
                break
        else:
            out=0
            for j in L:
                out+=CA[j-1][0]
            rst=min(rst,out)

N,M,X=map(int,input().split())
CA=[list(map(int,input().split())) for _ in range(N)]
rst=10**9
L=[]

DFS(1)
if rst==10**9:
    print(-1)
else:
    print(rst)

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

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N;
    io.read(N);
    vector<char> S(N);
    for(int i = 0; i < N; i++){
        io.read(S[i]);
    }
    set<char> st;
    for(int i = 0; i < N; i++){
        st.insert(S[i]);
    }
    if(st.size() == 3) cout << "Three";
    else cout << "Four";
    return 0;
}

Measured memory_bytes: 256
use std::f64;

fn norm(x: (f64, f64)) -> f64 {
    (x.0.powi(2) + x.1.powi(2)).sqrt()
}

fn print_tuple(t: (f64, f64)) {
    println!("{} {}", t.0, t.1);
}

fn koch_curve(p1: (f64, f64), p2: (f64, f64), depth: i32) {
    if depth == 0 {
        return;
    }

    let l = ((p2.0 - p1.0) / 3.0, (p2.1 - p1.1) / 3.0);
    let s = (p1.0 + l.0, p1.1 + l.1);
    let t = (p2.0 - l.0, p2.1 - l.1);
    let c = 1.0 / (2.0 * (3.0_f64).sqrt());
    let u = (
        (p1.0 + p2.0) / 2.0 - c * (p2.1 - p1.1),
        (p1.1 + p2.1) / 2.0 + c * (p2.0 - p1.0),
    );

    koch_curve(p1, s, depth - 1);
    print_tuple(s);
    koch_curve(s, u, depth - 1);
    print_tuple(u);
    koch_curve(u, t, depth - 1);
    print_tuple(t);
    koch_curve(t, p2, depth - 1);
}

fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    let n = line.trim().parse::<i32>().unwrap();

    println!("0 0");
    koch_curve((0.0, 0.0), (100.0, 0.0), n);
    println!("100 0");
}



Measured memory_bytes: 5052
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

// Levenshtein Distance
int levenshtein(string a, string b) {
  int n = a.size(), m = b.size();
  int d[n+1][m+1];
  REP(i, n+1) d[i][0] = i;
  REP(i, m+1) d[0][i] = i;
  for (int i=1; i<=n; ++i) {
    for (int j=1; j<=m; ++j) {
      d[i][j] = min(min(d[i-1][j] + 1,  // a deletion
                        d[i][j-1] + 1), // an insertion
                    d[i-1][j-1] + (a[i-1] != b[j-1])); // a substituion
      if (i>=2 && j>=2 && a[i-2]==b[j-1] && a[i-1]==b[j-2])
        d[i][j] = min(d[i][j], d[i-2][j-2]+1);
      //printf("(%d,%d):%d:%d ",i,j,d[i][j],a[i-1]!=b[j-1]);
    }
    //cout << endl;
  }
  return d[n][m];
}

bool judge(string a, string b, int d) {
  REP(i, a.size()-1) {
    string tmp = a;
    swap(tmp[i], tmp[i+1]);
    //cout << tmp << " " << b << " " << levenshtein(tmp, b) << endl;
    if (levenshtein(tmp, b) <= d-1) return 1;
  }
  REP(i, b.size()-1) {
    string tmp = b;
    swap(tmp[i], tmp[i+1]);
    //cout << tmp << " " << a << " " << levenshtein(tmp, a) << endl;
    if (levenshtein(tmp, a) <= d-1) return 1;
  }
  
  return 0;
}



int main() {
  int n;
  while(cin>>n,n) {
    int d;
    cin >> d;
    string name[n];
    REP(i, n) {
      cin >> name[i];
    }
    set<pair<string, string> > se;
    sort(name, name+n);
    REP(i, n) {
      REP(j, i) {
        //cout << name[j] <<"," <<name[i]<< " :  " << levenshtein(name[j], name[i]) << endl;
        int l = levenshtein(name[j], name[i]);
        if (l <= d || d == 2 && l <= 3 && judge(name[j], name[i], d))
          se.insert(make_pair(name[j], name[i]));
      }
    }
    FOR(it, se) {
      cout << it->first << "," << it->second << endl;
    }
    cout << se.size() << endl;
  }
}

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

#define MOD 1000000007
#define MAX 100005
#define ll long long
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define ss(x) scanf("%s",x)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vpii vector<pii >
#define vll vector<ll>
#define clr(x) memset(x,0,sizeof(x))

#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

using namespace std;

ll power(ll a,ll b,ll m){
	ll x=1%m; a%=m;
	while(b){
		if((1&b)) x = x * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return x;
}

int main(){
	int n,a,b;
	sd(n);sd(a);sd(b);

	int diff = b-a-1;

	if(diff&1) printf("Alice");
	else printf("Borys");
}

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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int n, m;
int x[100000], y[100000];

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

    cin >> n >> m;
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    int X = 0, Y = 0;
    rep(i, n) {
        X += x[i] * (i - n + 1 + i);
        X %= MOD;
    }
    rep(i, m) {
        Y += y[i] * (i - m + 1 + i);
        Y %= MOD;
    }
    cout << X * Y % MOD << endl;
    return 0;
}

Measured memory_bytes: 1792
n=int(input())
x = [0]*n
y = [0]*n
for i in range(n):
    x[i], y[i] = map(int, input().split())
    
l=0
for i in range(n):
    for j in range(n):
        if(i!=j):
            l+=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5

print(l/n)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
typedef long long ll;

int n;
double d;
double x, y;
double t;
int ans;

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	cin >> n >> d;
	for (int i = 1; i <= n; i++)
	{
		cin >> x >> y;
		t = double(sqrt(x*x + y*y));
		if (t <= d) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3860
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;


vector<vector<int>> arr;
int N, M, X, c, a, len;
vector<int> oks;



void func(int i, vector<int>& und, int sum) {

	int ok = 0;
	for (auto&& u : und) {
		if (u >= X) ok++;
	}
	if (ok == M) {
		oks.emplace_back(sum);
		return;
	}
	if (i == len && ok <= M) return;

	func(i + 1, und, sum); //i冊目は買わない

	vector<int> temp(und.size());
	transform(und.begin(), und.end(), arr[i].begin() + 1, temp.begin(), plus<int>());
	sum += arr[i][0];
	func(i + 1, temp, sum); //i冊目を買う

}




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


	for (size_t i = 0; i < N; ++i) {
		vector<int> temp;
		cin >> c;
		temp.emplace_back(c);
		for (size_t j = 0; j < M; j++)
		{
			cin >> a;
			temp.emplace_back(a);
		}
		arr.emplace_back(temp);
	}

	len = arr.size();
	vector<int> und(M);

	func(0, und, 0);

	if (oks.size()) {
		cout << *min_element(oks.begin(), oks.end()) << endl;
	}
	else
	{
		printf("-1\n");
	}
}


Measured memory_bytes: 3620
/*map,set,priority_queue,stack,queue*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define el "\n"
#define pb push_back
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
typedef vector<int> vi;
const int inf = (1e18)+7;
const int neginf = -1*((int)1e18 ) + 7 ;
const int mod = (int)1e9 + 7;
const int N = 500007;
/*int arr[N];
vector<int> adj[N];

void dfs(int x,int par)
{
    arr[x]+=par;
    arr[par] = 0;
    for(auto child:adj[x])
    {
        if(child==par)
            continue;
        dfs(child,x);
    }
}
*/

int32_t main() 
{
fastio
  
    int n;
    cin>>n;
    int arr[n];
    fo(i,n)
        cin>>arr[i];
    
    int sum = 0;
    for(int i=0;i<n;++i)
    {
        for(int j=i+1;j<n;++j)
        {
            sum+= arr[i]*arr[j];
        }
    }
    cout<<sum<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD=1000000007;
ll INF=20000;

int main(){
    int H, N;
    cin>>H>>N;
    vector<int> A(N), B(N);
  	int AMax, BMax;
    for(int i=0; i<N; i++){
        cin>>A[i]>>B[i];
      	AMax=max(AMax, A[i]);
      	BMax=max(BMax, B[i]);
    }
    vector<vector<ll>> dp(N+1, vector<ll>(INF));
  	for(int i=0; i<INF; i++){
      	dp[0][i]=MOD;
    }
  	dp[0][0]=0;
    for(int i=0; i<N; i++){
        for(int j=0; j<=INF; j++){
            if(j<A[i]){
                dp[i+1][j]=dp[i][j];
            }
            else{
              	dp[i+1][j]=min(dp[i][j], dp[i+1][j-A[i]]+B[i]);              
            }
        }
    }
  	/*for(int i=0; i<27; i++){
      	cout<<dp[2][i]<<endl;
    }*/
  	ll Ans=MOD;
  	for(int i=H; i<H+10000; i++){
      	if(dp[N][i]<MOD){
          	Ans=min(Ans, dp[N][i]);
        }
      
    }
  	cout<<Ans<<endl;
}



Measured memory_bytes: 160640
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi s(n),t(n);
	rep(i,n)cin>>s[i];
	rep(i,n)cin>>t[i];

	int out=0;
	rep(i,29){
		vi a=s,b=t;
		ll q=1<<(i+1);
		rep(i,n)a[i]%=q,b[i]%=q;
		q>>=1;
		sort(all(b));
		int co=0;
		rep(j,n){
			co+=lower_bound(all(b),2*q-a[j])-lower_bound(all(b),q-a[j]);
			co+=lower_bound(all(b),4*q-a[j])-lower_bound(all(b),3*q-a[j]);
		}
		if(co%2)out|=q;
	}
	cout<<out<<endl;
}










Measured memory_bytes: 3432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll ANS;
const ll MAX=2000005;
const ll MOD=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(ll i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(ll i,ll j){
    if(i<j) return 0;
    if(i<0||j<0) return 0;
    return fac[i]*(finv[j]*finv[i-j]%MOD)%MOD;
}
int main(void){
    ll r1,r2,c1,c2;
    cin>>r1>>c1>>r2>>c2;
    COMinit();
    for(ll i=1;i<=r2+1;i++){
        ANS=(ANS+COM(i+c2,i))%MOD;
    }
    for(int i=1;i<=r1;i++){
        ANS=(ANS+COM(i+c1-1,i))%MOD;
    }
    for(int i=1;i<=r1;i++){
        ANS=(ANS-COM(i+c2,i))%MOD;
    }
    for(int i=1;i<=r2+1;i++){
        ANS=(ANS-COM(i+c1-1,i))%MOD;
    }
    if(ANS<0) ANS+=MOD;
    cout<<ANS<<endl;
    
}


Measured memory_bytes: 50508