akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        final long bill = 2000000000;
        long pos[][] = new long [n][2];
        long neo_pos[][] = new long [n][2];
        long xMax = bill * -1, xMin = bill;
        long yMax = bill * -1, yMin = bill;

        for(int i = 0; i < n; i++){
            pos[i][0] = sc.nextInt();
            pos[i][1] = sc.nextInt();
            //xy座標から座標軸を45度回転させたx'y'座標に変換する
            //x'y'座標での正確な位置は√2で割らないといけないが整数計算で処理したいので行わない
            //通常マンハッタン距離は|xi - xj| +|yi - yj|で求められるが
            //x'y'座標でマンハッタン距離を求めると|x'i - x'j|と|y'i - y'j|の大きいほうがマンハッタン距離として計算できる
            neo_pos[i][0] = pos[i][0] + pos[i][1];
            neo_pos[i][1] = pos[i][0] * -1 + pos[i][1];
            if(xMax < neo_pos[i][0]){
                xMax = neo_pos[i][0];
            }
            if(xMin > neo_pos[i][0]){
                xMin = neo_pos[i][0];
            }
            if(yMax < neo_pos[i][1]){
                yMax = neo_pos[i][1];
            }
            if(yMin > neo_pos[i][1]){
                yMin = neo_pos[i][1];
            }
        }
        //xMax xMin yMax yMinを確認
        //System.out.println("xMax=" + xMax + " xMin=" + xMin);
        //System.out.println("yMax=" + yMax + " yMin=" + yMin);
        
        //正解を出力
        long dist_x = xMax - xMin;
        long dist_y = yMax - yMin;
        if(dist_x > dist_y){
            System.out.println(dist_x);
        }else{
            System.out.println(dist_y);
        }
    }
}


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

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N+1), S(N+2);
    for(int i=0; i<=N; i++){
        cin >> A[i];
        S[i+1] = S[i] + A[i];
    }

    int64_t ans = 0, now = 1;
    for(int i=0; i<=N; i++){
        ans += now;
        if(now < A[i]){
            cout << -1 << endl;
            return 0;
        }
        now -= A[i];
        int64_t s = S[N+1] - S[i+1];
        now = min(2*now, s);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4844
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size()) 
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
#define rep(i, n) for(int i=0;i<n;i++)

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x1f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-12;

string getstr(string sa, string sb, int A, int B) {
	if (A == 0 || B == 0) {
		string rv;
		for (int i = 1; i <= A; i++) rv += sa;
		for (int i = 1; i <= B; i++) rv += sb;
		return rv;
	}

	int c = B / A;
	string s1 = sa;
	string s2 = sa;
	for (int i = 1; i <= c; i++) s1 += sb;
	for (int i = 1; i <= c + 1; i++) s2 += sb;
	return getstr(s1, s2, A - B%A, B%A);
}
string getstr(string sa, string sb, string sc, int A, int B, int C) {
	if (A == 0) return getstr(sb, sc, B, C);
	if (B == 0) return getstr(sa, sc, A, C);
	if (C == 0) return getstr(sa, sb, A, B);

	string s1 = sa;
	string s2 = sa;
	string s3 = sa;
	int c1 = C / A, c2 = c1 + 1;
	if (A*c1 == C) {
		for (int i = 1; i <= c1; i++) {
			s1 += sc;
			s2 += sc;
		}
		int b1 = B / A, b2 = b1 + 1;
		for (int i = 1; i <= b1; i++) s1 += sb;
		for (int i = 1; i <= b2; i++) s2 += sb;
		return getstr(s1, s2, A - B%A, B%A);
	}
	else {
		for (int i = 1; i <= c1; i++) {
			s1 += sc;
			s2 += sc;
		}
		for (int i = 1; i <= c2; i++) s3 += sc;

		int x = A - C%A, y = C%A;
		int b1 = B / x, b2 = b1 + 1;
		for (int i = 1; i <= b1; i++) s1 += sb;
		for (int i = 1; i <= b2; i++) s2 += sb;
		return getstr(s1, s2, s3, x - B%x, B%x, y);
	}
}

int main() {
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	string ans = getstr(string("a"), string("b"), string("c"), A, B, C);
	return !printf("%s\n", ans.c_str());
}

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

const int N=1e5+100;
int mod=1e9+7;
typedef long long ll;
int a[N];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n,k;cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+1+n);
    int sum=0;
    for(int i=1;i<=k;i++)
        sum+=a[i];
    cout<<sum;
    return 0;
}



Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(((a + b) % 2 == 0) ? (a + b) / 2 : (a + b) / 2 + 1);

		sc.close();
	}

}




Measured memory_bytes: 23380
N = int(input())
from collections import Counter
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = Counter(A)
cb = Counter(B)
for i in range(1,N+1):
  if ca[i]+cb[i]>N:
    print('No')
    exit()
print('Yes')
from collections import deque
lis = [deque() for _ in range(N+1)]
da = deque(list(range(1,N+1)))
db = deque(list(range(1,N+1)))
while len(da) and len(db):
  a = da.popleft()
  b = db.popleft()
  if a==b:
    if len(db):
      db.append(b)
      b = db.popleft()
    elif len(da):
      da.append(a)
      a = da.popleft()
    else:
      for i in range(1,N+1):
        for _ in range(len(lis[i])):
          c = lis[i].popleft()
          if c!=b:
            lis[b].append(c)
            lis[i].append(b)
            ca[a] -= 1
            cb[b] -= 1
            if ca[a]==0:
              break
        else:
          continue
        break
  if ca[a]>cb[b]:
    for _ in range(cb[b]):
      lis[a].append(b)
    ca[a] -= cb[b]
    cb[b] = 0
    da.appendleft(a)
  else:
    for _ in range(ca[a]):
      lis[a].append(b)
    cb[b] -= ca[a]
    ca[a] = 0
    if cb[b]>0:
      db.appendleft(b)
ans = []
for i in range(1,N+1):
  for _ in range(len(lis[i])):
    b = lis[i].popleft()
    ans.append(b)
print(*ans)


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

using namespace std;

const int MAXN = 5000;
int a[MAXN];
bool poss[MAXN + 1];

bool isNec(int pos, int n, int k)
{
    if (a[pos] >= k)
        return true;
    fill(poss, poss + k, false);
    poss[0] = true;
    for (int i = 0; i < n; i++)
    {
        if (i == pos)
            continue;
        for (int j = k - 1; j >= 0; j--)
        {
            if (poss[j] && j + a[i] <= k - 1)
                poss[j + a[i]] = true;
        }
    }
    for (int i = k - a[pos]; i < k; i++)
    {
        if (poss[i])
            return true;
    }
    return false;
}

int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = -1;
    for (int jump = n / 2 + 1; jump > 0; jump /= 2)
    {
        while (ans + jump < n && !isNec(ans + jump, n, k))
            ans += jump;
    }
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
module Main (main) where

import Data.Functor ((<$>))

main :: IO ()
main = do
  [a,b] <- map read . words <$> getLine :: IO [Int]
  case a `compare` b of
    LT -> putStrLn "a < b"
    GT -> putStrLn "a > b"
    EQ -> putStrLn "a == b"



Measured memory_bytes: 3568
n = int(input())
l = list(map(int, input().split()))
dic = {}
count = 0

for i in range(n):
  dic.setdefault(l[i],0)
  dic[l[i]] += 1

for x,y in dic.items():
  if x <= y:
    count += y - x
  else:
    count += y
print(count)


Measured memory_bytes: 17780
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

/*********** Constants ***********/
const auto INF = static_cast<ll>(1ll << 60);
const auto MOD = static_cast<ll>(1e9 + 7);
const auto NIL = nullptr;

/************* Utils *************/
struct Node {
    ll key;
    Node *parent, *left, *right;
};

void preOrder(Node **T) {
    if (*T == NIL) {
        return;
    }
    cout << " " << (*T)->key;
    preOrder(&(*T)->left);
    preOrder(&(*T)->right);
}

void inOrder(Node **T) {
    if (*T == NIL) {
        return;
    }
    inOrder(&(*T)->left);
    cout << " " << (*T)->key;
    inOrder(&(*T)->right);
}

void insert(Node **T, Node **z) {
    Node *y = NIL;
    Node *x = *T;
    while (x != NIL) {
        y = x;
        if ((*z)->key < x->key) {
            x = x->left;
        }
        else {
            x = x->right;
        }
    }
    (*z)->parent = y;
    if (y == NIL) {
        *T = *z;
    }
    else if ((*z)->key < y->key) {
        y->left = *z;
    }
    else {
        y->right = *z;
    }
}

/*********** Variables ***********/
Node *Tree;

/*********** Functions ***********/
bool init() {
    return true;
}

void solve() {
    ll N; cin >> N;
    string command;
    for (ll i = 0; i < N; i++) {
        cin >> command;
        if (command == "print") {
            inOrder(&Tree);
            cout << endl;
            preOrder(&Tree);
            cout << endl;
        }
        else {
            ll key; cin >> key;
            Node *node = new Node{key, NIL, NIL, NIL};
            insert(&Tree, &node);
        }
    }
}

void output() {
}

int main() {
    //init();
    solve();
    //output();
    return 0;
}


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

using namespace std;

map<int, long long> cc;

long long lucas(int n) {
  if (n == 0) {
    return 2;
  } else if (n == 1) {
    return 1;
  }
  auto it = cc.find(n);
  if (it == cc.end()) {
    long long ret = lucas(n-1) + lucas(n-2);
    cc[n] = ret;
    return ret;
  } else {
    return cc[n];
  }
}

int main() {
  int n;
  cin >> n;
  cout << lucas(n) << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
import numpy as np
#======================================================#
MOD=10**9+7
def main():
    n = II()
    aa = np.array(MII())
    ans = 0
    for i in range(60):
        cnt1 = int((aa&1).sum())
        ans += cnt1*(n-cnt1)*(2**i)
        aa >>= 1
    print(ans%MOD)

if __name__ == '__main__':
    main()

Measured memory_bytes: 48792
#include<bits/stdc++.h>
using namespace std;
#define tezi ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;

int a[12][12];
int c[12];

void solve(int ind, int n, int m, int x, int cur, int &ans, vector<int> &v){
    int flag = 0;
    for(int i = 0; i < m; ++i){
        if(v[i] < x){
            flag = 1;
            break;
        }
    }
    if(flag == 0){
        ans = min(ans, cur);
        return;
    }
    if(ind >= n) return;
    for(int i = 0; i < m; ++i){
        v[i] += a[ind][i];
    }
    solve(ind + 1, n, m, x, cur + c[ind], ans, v);
    for(int i = 0; i < m; ++i){
        v[i] -= a[ind][i];
    }
    solve(ind + 1, n, m, x, cur, ans, v);
}

int main(){
    tezi;
    int n, m, x, ans = INT_MAX;
    cin >> n >> m >> x;
    for(int i = 0; i < n; ++i){
        cin >> c[i];
        for(int j = 0; j < m; ++j){
            cin >> a[i][j];
        }
    }
    vector<int> v(m, 0);
    solve(0, n, m, x, 0, ans, v);
    if(ans != INT_MAX) cout << ans << "\n";
    else cout << "-1\n";
    return 0;
}


Measured memory_bytes: 3656
N, W = map(int, input().split())
items = sorted([list(map(int, input().split())) for i in range(N)])

# dp1[i][j] := 商品0 ~ i が対象
dp = [[0] * (W + 1) for i in range(N + 1)]

# dpテーブルを埋める
for i in range(N):
    wi, vi = items[i]
    for j in range(W + 1):
        if j + wi <= W:
            dp[i + 1][j + wi] = max(dp[i + 1][j + wi], dp[i][j] + vi)
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])


ans = 0
for i, (wi, vi) in enumerate(items):
    ans = max(ans, dp[i][W - 1] + vi)

print(ans)


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

ll N,nr, d_fost,d_curent;
ll a[10];

/**
5
3 2 4 3 5
*/

int main() {
    cin >> N;
    for (int i = 1; i <= 5; i++)
        cin >> a[i];
    for (int i = 1; i <= 5; i++) {
        d_curent = ceil( (double)N / a[i]);
        /// 2 3 2 2 1
        if (i == 1) {
            d_fost = d_curent, nr = d_curent;
            continue;
        }

        if (d_curent > d_fost) /** daca pot sa impart grupul in mai
        mult grupulete decat mi-au
        trebuit pentru statia i - 1, adica nr minim de
        pasi in plus necesari, atunci presupun ca toate grupulete
        s-au adunat pe pozitita i si vad daca pot sa-mi continui 
        drumul sau daca trebuie sa astept cele i + d_curent - 1 secunde.

            */
            nr = max(i + d_curent - 1, nr + 1);
        else
            nr++;

        d_fost = d_curent;
    }
    cout << nr << '\n';
    return 0;
}


Measured memory_bytes: 256
import itertools
# p, q, r
l = list(map(int, input().split()))
# 全てのルートの組み合わせ（順序は考慮しない）
routes = list(itertools.combinations(l, 2))
# 飛行時間最小のものを取得
print(min([route[0]+route[1] for route in routes]))


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

int main(){
  string T ;
  cin >> T ;
  int t = T.size();
for(int i=0;i<t;i++){
 if(T[i]=='?'){
   T[i]='D';
 }
}
  for(int i=0;i<t;i++){
    cout << T[i] ;
  }
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    

    int a,b;
    cin >> a >> b;
    cout << 6-a-b ;


    return 0;

}

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

#define X real()
#define Y imag()

using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
using ll  = long long;

using point = complex<double>;


void err(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);}

const int N = 1e5 + 50;
const double EPS = 1e-8;
const long long mod = 1e9 + 7;

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



int dp[N],h[N];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n ;
    cin >> n;
    for(int i = 0; i < n; ++i)
            cin >> h[i];
    // state : pos
    // trans : dp[pos] = min(dp[pos - 1] , dp[pos - 2] )
    // base  : dp[0] = 0 , dp[1] = abs(h[1]-h[0]);

    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int pos = 2; pos < n; ++pos)
            dp[pos] = min(dp[pos - 1] + abs(h[pos] - h[pos - 1])
                    , dp[pos - 2] + abs(h[pos] - h[pos - 2]));
    cout << dp[n - 1] << '\n';
    return 0;
}


Measured memory_bytes: 1024
local floor = math.floor
local min = math.min
local N = io.read("*n")

local function idiv(operand1, operand2)
	return floor(operand1 / operand2)
end

local function sumDigits(num)
	local sum = 0
	while num > 0 do
		sum = sum + num % 10
		num = idiv(num, 10)
	end
	return sum
end

local out = 100001
for A = 1, idiv(N, 2) do
	local B = N - A
	local sum = sumDigits(A) + sumDigits(B)
	out = min(out, sum)
end

print(out)


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 20;
const int P = 1e9 + 7;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, ans, t, l[MAXN], r[MAXN], a[MAXN], b[MAXN], s[MAXN];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
void updans(int pos, int val) {
	val = 1ll * val * pos % P;
	update(s[pos], val);
	if (pos != 1) updans(pos / 2, val);
}
void getans(int pos, int val) {
	val = 1ll * val * pos % P;
	if (pos != 1) {
		update(ans, 1ll * pos / 2 * val % P * s[pos ^ 1] % P);
		getans(pos / 2, val);
	}
}
void work(int pos, int depth) {
	if (depth == n) {
		l[pos] = r[pos] = b[pos] = pos;
		return;
	}
	work(pos * 2, depth + 1);
	work(pos * 2 + 1, depth + 1);
	l[pos] = l[pos * 2], r[pos] = r[pos * 2 + 1];
	for (int i = l[pos * 2]; i <= r[pos * 2]; i++)
		updans(a[i], 1ll * b[i] * pos % P);
	for (int i = l[pos * 2 + 1]; i <= r[pos * 2 + 1]; i++)
		getans(a[i], b[i]);
	for (int i = l[pos * 2]; i <= r[pos * 2]; i++)
		updans(a[i], P - 1ll * b[i] * pos % P);
	for (int i = l[pos]; i <= r[pos]; i++)
		b[i] = 1ll * b[i] * pos % P;
}
int main() {
	read(n), t = 1 << (n - 1);
	for (int i = t; i < t * 2; i++)
		read(a[i]), a[i] += t - 1;
	work(1, 1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7752
#include<stdio.h>
int main()
{
	double x[4],y[4],m1,m2;
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<4;j++)
			scanf("%lf%lf",&x[j],&y[j]);
		m1=(y[1]-y[0])/(x[1]-x[0]);
		m2=(y[3]-y[2])/(x[3]-x[2]);
		printf("%s\n",m1==m2?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 620
import java.util.Scanner;

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

		int n = sc.nextInt();

		String s = sc.next();
		char[] c = s.toCharArray();

		int count = 1;

		for(int i=0; i<n-1; i++){
			if(!(c[i]==c[i+1])){
				count++;
			}
		}

		System.out.println(count);
	}
}


Measured memory_bytes: 26836
n = int(input())
v_data = list(map(int,input().split()))
c_data = list(map(int,input().split()))
res = 0

for i in range(n):
  if v_data[i] - c_data[i] > 0:
    res += v_data[i] - c_data[i]
print(res)

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

int main(){
  int r, g, b;
  cin >> r >> g >> b;
  
  int product = r * 100 + g * 10 + b;
  
  if(product % 4 == 0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
  
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void dijkstra(int s,int cost[][],int d[],boolean used[],int V){
		for(int i = 0;i < V;i++){
			d[i] = Integer.MAX_VALUE;
			used[i] = false;
		}
		d[s] = 0;
		while(true){
			int v = -1;
			for(int u = 0;u < V;u++){
				if(!used[u] && (v == -1 || d[u] < d[v]))v = u;
			}
			if(v == -1)break;
			used[v] = true;
			for(int u = 0;u < V;u++){
				if(d[v] != Integer.MAX_VALUE && cost[v][u] != Integer.MAX_VALUE){
					if(d[u] > d[v] + cost[v][u]){
						d[u] = d[v] + cost[v][u];
					}
				}
			}
		}
	}
	void doIt() { 
		while(true){
			int n = sc.nextInt();
			if(n == 0)break;
			int V = 10;
			int cost[][] = new int [V][V];
			int d[] = new int[V];
			boolean used[] = new boolean[V];
			for(int i = 0;i < V;i++){
				for(int j = 0;j < V;j++){
					cost[i][j] = Integer.MAX_VALUE;
				}
			}
			for(int i = 0;i < n;i++){
				int b = sc.nextInt();
				int c = sc.nextInt();
				cost[b][c] = sc.nextInt();
				cost[c][b] = cost[b][c];
			}
			int costall = Integer.MAX_VALUE;
			int ans = 0;
			for(int i = 0;i < V;i++){
				int cnt = 0;
				dijkstra(i,cost,d,used,V);
				for(int j = 0;j < V;j++){
					if(d[j] != Integer.MAX_VALUE){
						cnt = cnt + d[j];
					}
				}
				if(cnt != 0){
					if(costall > cnt){
						costall = cnt;
						ans = i;
					}
				}
			}
			System.out.println(ans+" "+costall);
		}
     }
    public static void main(String[] args) {
    	// TODO Auto-generated method stub
    	new Main().doIt();
    }
}

Measured memory_bytes: 19688
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
const int INF = 100000000;

int main(){
    string s;
    cin >> s;
    if(s == "SUN"){
        cout << 7 << endl;
    }else if(s == "MON"){
        cout << 6 << endl;
    }else if(s == "TUE"){
        cout << 5 << endl;
    }else if(s == "WED"){
        cout << 4 << endl;
    }else if(s == "THU"){
        cout << 3 << endl;
    }else if(s == "FRI"){
        cout << 2 << endl;
    }else if(s == "SAT"){
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{	string x;
	cin >> x;
	int f=0;
	for (int i = 0; i < x.length(); i++)
	{
		if ((i + 1) % 2 == 0)
		{
			if (x[i] == 'R')
				f = 1;
		}
		else
		{	
			if (x[i] == 'L')
				f = 1;
		}
	}
	if (f)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{int a,b,c,k,sum=0,co=1,i=1;
    cin>>a>>b>>c>>k;
 while(co<=k && i<=a)
  {co++;
  sum++;
  i++;
  }i=1;
  while(co<=k && i<=b)
    {co++;
    i++;}
    i=1;
  while(co<=k && i<=c)
  {
      co++;
      i++;
      sum--;
  }
  cout<<sum;
return 0;}

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

const int N = 505;
const int mod = 1000000007;
using LL = long long;
int head[N], tot, n, m, k, idx, bcc, dfn[N], low[N];
bool vis[N];
struct edge { int to, nxt; } e[N << 1];
void link(int x, int y) {
	e[++tot] = (edge) { y, head[x] }, head[x] = tot;
	e[++tot] = (edge) { x, head[y] }, head[y] = tot;
}
void reduce(int &x) { x += x >> 31 & mod; }
int pow(int x, int y, int ans = 1) {
	for (; y; y >>= 1, x = (LL) x * x % mod)
		if (y & 1) ans = (LL) ans * x % mod;
	return ans;
}
std::stack<std::pair<int, int>> stack;
std::vector<std::pair<int, int>> edges[N];
void tarjan(int x, int f = 0) {
	dfn[x] = low[x] = ++idx;
	for (int i = head[x]; i; i = e[i].nxt)
		if (e[i].to != f) {
			int y = e[i].to;
			if (!dfn[y]) {
				stack.push({x, y});
				tarjan(y, x), low[x] = std::min(low[x], low[y]);
				if (dfn[x] <= low[y]) {
					++bcc; std::pair<int, int> _e;
					do {
						_e = stack.top(); stack.pop();
						edges[bcc].push_back(_e);
					} while (_e != std::make_pair(x, y));
				}
			} else if (dfn[y] < dfn[x]) {
				stack.push({x, y});
				low[x] = std::min(low[x], dfn[y]);
			}
		}
}
int calc0(int n) {
	int ans = 0;
	for (int i = 0; i < n; ++i)
		reduce(ans += pow(k, std::__gcd(i, n)) - mod);
	return pow(n, mod - 2, ans);
}
int calc1(int n) { // C(n + k - 1, k - 1)
	int ans = 1;
	for (int i = 2; i < k; ++i) ans = (LL) ans * i % mod;
	ans = pow(ans, mod - 2);
	for (int i = 1; i < k; ++i)
		ans = (LL) ans * (n + i) % mod;
	return ans;
}
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m >> k;
	for (int i = 0, x, y; i < m; ++i) std::cin >> x >> y, link(x, y);
	for (int i = 1; i <= n; ++i) if (!dfn[i]) tarjan(i);
	int ans = 1;
	for (int i = 1; i <= bcc; ++i) {
		int e_num = edges[i].size(), v_num = 0;
		std::memset(vis, 0, sizeof vis);
		for (auto p : edges[i])
			vis[p.first] = vis[p.second] = 1;
		for (int j = 1; j <= n; ++j) v_num += vis[j];
		ans = (LL) ans * (v_num >= e_num ? calc0(e_num) : calc1(e_num)) % mod;
	}
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define aint(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


class UnionFind
{
public:
  UnionFind(int n)//0~n-1までitemを初期化
  {
    parent=vector<int>(n,-1);//親なら-size
    weight=vector<int>(n,0);
  }
  int root(int a)
  {
    if(parent[a]<0)return a;
    int r=root(parent[a]);
    weight[a]+=weight[parent[a]];
    return parent[a]=r;
  }
  int size(int a)
  {
    return -parent[root(a)];
  }
  bool connect(int a,int b,int cost)
  {
    int A=root(a);
    int B=root(b);
    cost+=weight[a];
    cost-=weight[b];
    if(A==B && cost!=0)return false;
    if(A==B)return true;
    if(size(A)>=size(B))
    {
      swap(A,B);
    }
    else
    {
      cost=-cost;
    }
    weight[A]=cost;
    parent[B]+=parent[A];
    parent[A]=B;
    return true;
  }
  void print()
  {
    rep(i,weight.size())cout<<weight[i]<<" ";
    cout<<endl;
  }
  vector<int> parent;
  vector<int> weight;

};


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  UnionFind uni(n+1);
  bool ok=1;
  rep(i,m)
  {
    int l,r,d;
    cin>>l>>r>>d;
    //uni.print();
    if(uni.root(l)==uni.root(r))
    {
      int diff= uni.weight[r]-uni.weight[l];
      if(diff!=d)
      {
        ok=0;
        break;
      }
    }
    else
    {
      uni.connect(l,r,d);
    }
  }
  cout<<(ok?"Yes":"No")<<endl;
  return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;ll k;cin>>n>>k;
    vll a(n),f(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>f[i];
    sort(all(a));
    sort(all(f));reverse(all(f));
    ll l=(ll)-1,r=1e12,m,sum;
    while(r-l>1){
        m=(l+r)/2;
        sum=(ll)0;
        rep(i,n)sum+=max((ll)0,a[i]-m/f[i]);
        if(sum<=k)r=m;
        else l=m;
    }
    cout<<r<<endl;
}

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

using namespace std;
typedef long long lint;

int n, m, i, x, a[15][15], j, rez;
int q[15];

void bk(int k, int cr, int sum)
{
    if(k == 1) return;
    if(sum >= q[k]) return;
    if(sum + a[cr][1] < q[k])
        q[k] = sum + a[cr][1];
    int i = 0;
    for(i = 0; i <= 9; i ++)
    {
        if(i == 1 || i == cr) continue;
        bk(k, i, sum + a[cr][i]);
    }
}

int main()
{
    //freopen("f.in", "r", stdin);
    //freopen("f.out", "w", stdout);

    scanf("%d%d", &n, &m);

    for(i = 0; i <= 9; i ++)
    {
        for(j = 0; j <= 9; j ++)
        {
            scanf("%d", &a[i][j]);
        }
    }

    for(i = 0; i <= 9; i ++)
    {
        if(i == 1) continue;
        q[i] = a[i][1];
        bk(i,i,0);
    }
    for(i = 1; i <= n; i ++)
    {
        for(j = 1; j <= m; j ++)
        {
            scanf("%d", &x);
            if(x != -1 && x != 1)
                rez += q[x];
        }
    }
    printf("%d", rez);

    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
a=[int(input()) for i in range(M)]
c=[0]*(N+1)
c[0]=1
MOD=7+10**9
j=0
for i in range(1,N+1):
    if j<M and i==a[j]:
        j+=1
    elif i==1:
        c[i]=1
    else:
        c[i]=(c[i-1]+c[i-2])%MOD
print(c[-1]%MOD)

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

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

    int N, M;
    cin >> N >> M;
    priority_queue<int> q;
    for (int i = 0, Ai; i < N; i++) {
        cin >> Ai;
        q.push(Ai);
    }

    while (M > 0) {
        int top = q.top();
        q.pop();
        top >>= 1;
        q.push(top);
        M--;
    }

    long long sum = 0;
    while (!q.empty()) {
        sum += q.top();
        q.pop();
    }
    cout << sum << '\n';

    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>

int main(){
        int N,L[100],sum=0;
        std::cin>>N;
        for(int i=0; i<N; i++)
                std::cin>>L[i];
        std::sort(L,L+N);
        for(int i=0; i<N-1; i++) {
                sum+=L[i];
        }
        if(sum>L[N-1]) std::cout<<"Yes";
        else std::cout<<"No";
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;

int main(){
  int n,m;
  cin >> n>> m;
  vector<P> ans;
  //偶奇場合分け
  if(n%2) {//奇数
    for(int l=1,r=n-1;l < r;l++,r--){
      ans.emplace_back(l,r);
    }
  }else{//偶数
    bool flag = false;
    for(int l = 1,r=n-1;l<r;l++,r--){
      if(!flag && r-l <= n/2){
        --r;
        flag = true;
      }
      ans.emplace_back(l,r);
    }
  }
  rep(i,m){
    printf("%d %d\n",ans[i].first, ans[i].second);
  }
  return 0;
} 

Measured memory_bytes: 4092
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

bool used[10];
double x[11], y[11];
double ans = 0;
double res = 0;
int n;

void dfs(int pos, int j) {
    if(pos == n) {
        ans += res;
      //cout << res << endl;
    }
    rep(i, n) {
        if(!used[i]) {
            if(pos != 0) res += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
            used[i] = true;
            dfs(pos + 1, i);
              if(pos != 0) res -= sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
            used[i] = false;
        }
    }
}

void solve() {
	cin >> n;
    rep(i, n) {
        cin >> x[i] >> y[i];
    }
    x[10] = 0; y[10] = 0;
    memset(used, 0, sizeof(used));
    dfs(0, -1);
    int t = 1;
    rep(i, n) {
        t *= (i + 1);
    }
  //cout << t << endl;
    cout << ans / (double)t << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class AXXFESTIVAL {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] arr = in.next().toCharArray();
            for (int i = 0; i < arr.length - 8; i++) {
                out.print(arr[i]);
            }
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public void close() {
        }

    }
}



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

int main() {
  // ここにプログラムを追記
  int a;//現在のレーティング
  int b;//次のレーティング
  cin >> a >> b;
  //b = (a + P)/2 ⇨
  cout << 2*b - a << endl;
}

Measured memory_bytes: 256
import os
import sys

import numpy as np


def solve(inp):
    r, c, k = inp[:3]
    items = np.zeros((r + 1, c + 1), dtype=np.int64)
    rrr = inp[3::3]
    ccc = inp[4::3]
    vvv = inp[5::3]
    for r_, c_, v in zip(rrr, ccc, vvv):
        items[r_, c_] = v

    dp = np.zeros((r + 1, c + 1, 4), dtype=np.int64)

    for i in range(1, r + 1):
        for j in range(1, c + 1):
            v = items[i, j]
            dp[i, j] = np.maximum(dp[i, j - 1], dp[i - 1, j, 3])
            if v > 0:
                dp[i, j, 1:] = np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v)

    return dp[-1, -1, -1]


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(ans)


Measured memory_bytes: 387180
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
ll dp[200005]={0};
ll ans,n;
ll a[200005]={0};
int main()
{
	ll i,j,x,y;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i];
	a[0]=a[1];
	for(i=2;i<=n;i++)
	{
	
		x=abs(a[i]-a[i-1]);
		y=abs(a[i]-a[i-2]);
		dp[i]=min((dp[i-1]+x),(dp[i-2]+y));
	}
	cout<<dp[n];
	return 0;
}



Measured memory_bytes: 5136
//#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
map<int,int> M;
int main()
{
    speed
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        int a;
        cin>>a;
        if(M[a])
        {
            cout<<"NO";
            return 0;
        }
        M[a]++;
    }
    cout<<"YES";

    return 0;
}


Measured memory_bytes: 9600
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int ans = 0;
        for(Character c:arr){
            if(c=='+')ans++;
            else ans--;
        }
        System.out.println(ans);
    }
}


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

int main() {
	int a,b;
	cin>>a>>b;
	if(a>=b)rep(i,a)cout<<b;
	else rep(i,b)cout<<a;
	
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
	int i, j, h, w, g;
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0) {
			break;
		}
		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
}

Measured memory_bytes: 3044
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxd = 55;
int a[maxd],t,n;
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) if(a[i]!=i) t++;
	if(t>2) printf("NO");
	else printf("YES");
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int vx[] = {1, 0, -1, 0};
int vy[] = {0, 1, 0, -1};

int main()
{
  int h, w;
  char s[50][50];
  int ret = 1;

  cin >> h >> w;
  for (int i = 0; i < h; i++){
    cin >> s[i];
  }

  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (s[i][j] == '#'){
        int c = 0;
        for (int k = 0; k < 4; k++){
          int nx = j + vx[k];
          int ny = i + vy[k];
          if (!(nx < 0 || ny < 0 || nx >= w || ny >= h)){
            if(s[ny][nx] == '#') c++;
          }
        }
        if (c == 0) ret = 0;
      }
    }
  }

  if (ret == 0) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	
	int x = 800*n;
	int y = 200*(n/15);
	
	printf("%d\n", x-y);
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define MOD 998244353
#define VALMAX 1000000

using namespace std;

long long F[VALMAX+5],W[VALMAX+5];

int put(int a, int b)
{
    int rez=1;
    for(int i=0; (1<<i)<=b; i++)
    {
        if((1<<i)&b)
            rez=(1LL*rez*a)%MOD;
        a=(1LL*a*a)%MOD;
    }
    return rez;
}

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

    for(int i=1; i<=VALMAX; i++)
    {
        W[i]+=put(i,MOD-2);
        for(int j=i+i; j<=VALMAX; j+=i)
            W[j]=(W[j]-W[i]+MOD)%MOD;
    }

    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin>>x;
        F[x]++;
    }

    long long rez=0;
    for(int i=1; i<=VALMAX; i++)
    {
        long long sum=0;
        for(int j=i; j<=VALMAX; j+=i)
            sum=(sum+1LL*F[j]*j)%MOD;
        for(int j=i; j<=VALMAX; j+=i)
        {
            rez=(rez+1LL*(1LL*(1LL*W[i]*j%MOD)*j%MOD)*((1LL*F[j]*(F[j]-1))/2%MOD))%MOD;
            sum=(sum-(1LL*F[j]*j%MOD)+MOD)%MOD;
            rez=(rez+1LL*(1LL*W[i]*sum%MOD)*(1LL*j*F[j]%MOD))%MOD;
        }
    }
    cout<<rez<<"\n";
    return 0;
}


Measured memory_bytes: 15872
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
using namespace std;
long long a,b,c,x,y;
int main(){
	cin>>a>>b>>c;
	if(a+b>=c){
		cout<<"No";
		return 0;
	}
	x=4*a*b;
	y=(c-a-b)*(c-a-b);
	if(x<y)	cout<<"Yes";
	else cout<<"No";
 	return 0;
}

Measured memory_bytes: 256
/*C - Typical Stairs*/
#include <bits/stdc++.h>
using namespace std;

using Long = long long;
const Long MOD = 1000000007ll;

set <Long> nums;
vector <Long> memo(100005, -1ll);
int tam;

Long ways(Long pos);
int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int steps;

	cin >> tam >> steps;

	Long s;
	for (int i = 0; i < steps; ++i)
	{
		cin >> s;
		nums.insert(s);
	}

	cout << ways(0ll);

	return 0;
}

Long ways(Long pos){

	if(pos == tam)
		return 1ll;

	if(pos > tam)
		return 0ll;


	if(memo[pos] != -1ll)
		return memo[pos];

	Long ans = 0ll;

	if(nums.count(pos + 1) == 0){
		ans += ways(pos + 1);
		ans %= MOD;
	}

	if(nums.count(pos + 2) == 0){
		ans += ways(pos + 2); 
		ans %= MOD;
	}

	ans %= MOD;

	memo[pos] = ans;

	return ans;
}

Measured memory_bytes: 5760
n = int(input())
a = list(map(int,input().split()))
s = sum(a[1:])
ans = 0
mod = 10**9+7
for i in range(n):
  if i != 0:
    s -= a[i]
  ans += (a[i]*s)%mod
  ans %= mod
print(ans)

Measured memory_bytes: 31680
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }
 
typedef long long ll;
int const inf = 1<<29;
 
int N;
vector<vector<pair<int, int64_t>>> g;
vector<int64_t> dist;
 
void dfs(int curr, int par) {
  for (auto e: g[curr]) {
    int dest; int64_t cost; tie(dest, cost) = e;
    if (dest == par) continue;
    dist[dest] = dist[curr] + cost;
    dfs(dest, curr);
  }
}
 
int main() {
  cin >> N; g.resize(N);
  dist.resize(N);
  rep(i, N - 1) {
    int a, b, c; cin >> a >> b >> c;
    a--, b--;
    g[a].emplace_back(b, c);
    g[b].emplace_back(a, c);
  }
  int Q, K; cin >> Q >> K;
  K--;
  dfs(K, -1);
  rep(_, Q) {
    int x, y; cin >> x >> y;
    x--, y--;
    cout << dist[x] + dist[y] << "\n";
  }
}

Measured memory_bytes: 14336
#include<iostream>
#include<algorithm>
typedef long long lint;
using namespace std;

int N;
int A[100010];

lint solve(int n)
{
	lint ret=0;
	lint tmp=0,sum=0;
	for(int i=0;i<N;i++)
	{
		tmp=sum+A[i];
		if(n%2==0)
		{
			if(i%2==0)
			{
				if(tmp<=0)
				{
					tmp=1;
					ret+=abs(tmp-sum-A[i]);
				}
			}
			else
			{
				if(tmp>=0)
				{
					tmp=-1;
					ret+=abs(tmp-sum-A[i]);
				}
			}
		}
		else
		{
			if(i%2==0)
			{
				if(tmp>=0)
				{
					tmp=-1;
					ret+=abs(tmp-sum-A[i]);
				}
			}
			else
			{
				if(tmp<=0)
				{
					tmp=1;
					ret+=abs(tmp-sum-A[i]);
				}
			}
		}
		sum=tmp;
	}
	return ret;
}

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


Measured memory_bytes: 640
//started 17 minute late
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
#define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
#define inf 3e15
    
const int N=505;
const int M=1e9+7;
int a[N];
int n,k,sum=0;
bool chk(int x)
{
	int reqd = 0;
	vector<int> v;
	for(int i = 0; i < n; i++)
	{
		int cur = a[i] % x;
		v.push_back(cur);
	}
	sort(v.begin(), v.end());
	int l = 0, r = v.size() - 1;
	int rem = 0;
	while(l <= r)
	{
		if(rem <= 0)
		{
			rem += v[l];
			reqd += v[l];
			l++;
		}
		else
		{
			rem -= (x - v[r]);
			reqd += (x - v[r]);
			r--;
		}
	}
	if(reqd<=2 * k)
		return 1;
	return 0;
}

void solve()
{
	
	cin>>n>>k;
	f(i,0,n-1) cin>>a[i],sum+=a[i];
	std::vector<int> v;
	for(int i=1;i*i<=sum;i++)
	{
		if(sum%i==0){
		v.pb(i);
		v.pb(sum/i);
		}
	}
	sort(all(v));
	reverse(all(v));
	for(auto X:v)
	{
		if(chk(X))
		{
			cout<<X;
			return;
		}
	}
}
signed main()  
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}



Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<map>
#include<vector>
#include<algorithm>
#define INF 20000000
using namespace std;
typedef complex<double> P;
map<int,P>data;
double gr[1200][1200];


int prev[1200];
double d[1200];
int used[1200];
void dijkstra(int s){
	fill(d,d+1200,INF);
	fill(used,used+1200,false);
	fill(prev,prev+1200,-1);
	d[s]=0;
	while(true){
		int v=-1;
		for(int u=0;u<1200;u++){
			if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
		}
		if(v==-1)break;
		used[v]=true;
		
		for(int u=0;u<1200;u++){
			if(d[u]>d[v]+gr[v][u]){
				d[u]=d[v]+gr[v][u];
				prev[u]=v;
			}
		}
	}
}
vector<int>get_path(int t){
	vector<int>path;
	for(;t!=-1;t=prev[t])path.push_back(t);
	reverse(path.begin(),path.end());
	return path;
}
int main(){
	int n;
		while(cin>>n &&n){
		fill((double*)gr,(double*)gr+1200*1200,INF);
		for(int i=0;i<n;i++){
			int b,x,y;
			cin>>b>>x>>y;
			data[b].real()=x;
			data[b].imag()=y;
		}
		for(map<int,P>::iterator itr=data.begin();itr!=data.end();itr++){
			for(map<int,P>::iterator it=data.begin();it!=data.end();it++){
				if(abs(itr->second-it->second)<=50 &&abs(itr->second-it->second)>0){
					gr[itr->first][it->first]=abs(itr->second-it->second);
				}
			}
		}
	
		int m;
		cin>>m;
		for(int i=0;i<m;i++){
			int a,b;
			cin>>a>>b;
			dijkstra(a);
			if(d[b]==INF){
				cout<<"NA"<<endl;
				continue;
			}
			else{
		
				vector<int>ans;
				ans=get_path(b);
				for(int i=0;i<ans.size();i++){
					if(i)cout<<" ";
					cout<<ans[i];
				}
				cout<<endl;
			}
		}
	}
}

Measured memory_bytes: 12504