akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {
  
  public static void main(String[] args) {
    solve(System.in, System.out);
  }
  
  private static class Node {
    
    Node(int value) {
      this.value = value;
    }
    
    int value;
    
    int maxDepth;
    
    Node parent = null;
    
    Set<Node> children = new HashSet<>();
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    
    // takahashi
    int u = sc.nextInt() - 1;
    // aoki
    int v = sc.nextInt() - 1;
    
    Map<Integer, Set<Integer>> tree = new HashMap<>();
    
    for (int i = 0; i < n - 1; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;

      Set<Integer> aNeighbors = tree.getOrDefault(a, new HashSet<>());
      aNeighbors.add(b);
      tree.put(a, aNeighbors);

      Set<Integer> bNeighbors = tree.getOrDefault(b, new HashSet<>());
      bNeighbors.add(a);
      tree.put(b, bNeighbors);
    }

    // construct tree
    Map<Integer, Node> nodes = new HashMap<>();
    Node aoki = construct(v, tree, nodes);
    Node taka = nodes.get(u);
    
    int turn = 0;
    
    // find distance between aoki and taka
    int distance = findTaka(aoki, taka, new HashSet<>());
    
    if (distance > 0) {
      int goParent = (distance - 1) / 2;
      turn += goParent;

      for (int i = 0; i < goParent; i++) {
        taka = taka.parent;
      }

      turn += taka.maxDepth - 1;

      turn += (distance - 2 * goParent) / 2;
    }
    
    os.println(turn);
  }
  
  private static Node construct(int value, Map<Integer, Set<Integer>> tree, Map<Integer, Node> visited) {
    if (visited.containsKey(value)) return visited.get(value);
    Node node = new Node(value);
    visited.put(value, node);
    
    int maxDepth = 0;
    
    for (int next : tree.get(value)) {
      Node child = construct(next, tree, visited);
      maxDepth = Math.max(child.maxDepth, maxDepth);
      child.parent = node;
      node.children.add(child);
    }
    node.maxDepth = maxDepth + 1;
    return node;
  }
  
  private static int findTaka(Node start, Node taka, Set<Node> visited) {
    if (start == taka) return 0;
    visited.add(start);
    for (Node child : start.children) {
      if (visited.contains(child)) continue;
      int find = findTaka(child, taka, visited) + 1;
      if (find > 0) return find;
    }
    return -1;
  }
  
}

Measured memory_bytes: 181500
int main(void){
  int n,a,b;
  int score[2];

  while(1){
    scanf("%d",&n);
    if(!n) break;
    score[0]=score[1]=0;
    while(n--){
      scanf("%d%d",&a,&b);
      if(a<b){
        score[1] += a+b;
      }
      else if(a>b){
        score[0] += a+b;
      }
      else{
        score[0] += a;
        score[1] += b;
      }
    }
    printf("%d %d\n",score[0],score[1]);
  }

  return 0;
}

Measured memory_bytes: 0
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
#define dbg(vec) for (size_t _ = 0; _ < vec.size(); ++_){std::cerr << #vec << "[" << _ << "] : " << vec[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;


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

  int64 n; cin >> n;
  cout << n * (n - 1) / 2 << '\n';


  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
 
class P
{
    static void Main()
    {
        var nx = Console.ReadLine().Split().Select(int.Parse).ToList();
        int n = nx[0];
        long x = nx[1];
        var a = Console.ReadLine().Split().Select(long.Parse).ToList();
        long[][] costMin = Enumerable.Repeat(0, n).Select(_ => new long[n]).ToArray();
        costMin[0] = a.ToArray();
        long min = a.Sum();
        for (int i = 1; i < n; i++)
        { 
            for (int j = 0; j < n; j++) costMin[i][(j + 1) % n] = Min(costMin[i - 1][(j + 1) % n], costMin[i - 1][j]);
            min = Min(min, costMin[i].Sum() + i * x);
        }
        Console.WriteLine(min);
    }
}


Measured memory_bytes: 45784
# -*- coding: utf-8 -*-
"""
黒板に N 個の正の整数 A1,…,AN が書かれています。
すぬけ君は，黒板に書かれている整数がすべて偶数であるとき，次の操作を行うことができます。

'黒板に書かれている整数すべてを，2で割ったものに置き換える。'
すぬけ君は最大で何回操作を行うことができるかを求めてください。
"""

N = int(input())
A = list(map(int, input().split()))
count = 0
all_even = True

while True:
    if all_even == False:#奇数があったらbreak
        break
    else:
        for i in range(N): #奇数になっていないか調べる
            if A[i] % 2 != 0:
                all_even = False
                break
        else:
            for i in range(N):#すべて偶数の時は2でわる
                A[i] /= 2
            count += 1

print(count)

Measured memory_bytes: 3064
chomp (my ($n, $y) = split / /, readline ARGV);

my $m = [
  [    1,    1,    1],
  [10000, 5000, 1000],
  [    0,    0,    1],
];

for my $g (0..$n) {
  my $t = [$n, $y, $g];
  my $ans = cramer($m, $t) or next;
  if (pint($ans->[0]) && pint($ans->[1]) && pint($ans->[2])) {
    print "@$ans\n";
    exit;
  }
}
print "-1 -1 -1\n";

sub pint {
  my $n = shift;
  int($n) == $n && $n >= 0
}

sub cramer {
  my $x = shift; # coefficients matrix
  my $y = shift; # teacher signal array
  return unless @$x == @$y;
  my $det = det($x) or return;
  my @solution;
  for my $i (0 .. @$x - 1) {
    my $coe = [];
    for my $j (0 .. @{$x->[$i]} - 1) {
      $coe->[$j] ||= [];
      for my $k (0 .. @$y - 1) {
        $coe->[$j][$k] = $i != $k ? $x->[$j][$k] : $y->[$j];
      }
    }
    push @solution, det($coe) / $det;
  }
  \@solution;
}

sub det {
  my $x = shift;
  if (@$x > 2) {
    my $det = 0;
    for my $j (0 .. @{$x->[0]} - 1) {
      my $minor = sub_matrix(0, $j, $x);
      $det += det($minor, 1) * ((-1) ** $j) * $x->[0][$j];
    }
    return $det;
  }
  return ($x->[0][0] * $x->[1][1]) - ($x->[0][1] * $x->[1][0])
    if @$x == 2; # 2x2
  return $x->[0][0] if @$x == 1; # 1x1
}

sub sub_matrix {
  my $i_dim = shift;
  my $j_dim = shift;
  my $x = shift; # no matrix check for speed, must be square matrix
  my $minor = [];
  for my $i (0 .. @$x - 1) {
    next if $i == $i_dim;
    my $row = [];
    for my $j (0 .. @$x - 1) {
      push @$row, $x->[$i][$j] unless $j == $j_dim;
    }
    push @$minor, $row;
  }
  $minor;
}

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

int main() {
  
  int n; cin >> n; int ans = 0; vector<int> vec(n);
  
  for (int i = 0; i < n; i++) cin >> vec[i];
  
  for (int i = 1; i < n - 1; i++) {
    if (vec[i - 1] < vec[i] && vec[i] < vec[i + 1]) ans++;
    if (vec[i + 1] < vec[i] && vec[i] < vec[i - 1]) ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
S = input()
N = len(S) - 1
ans = 0
for i in range(2**N):
    t = S[0]
    for j in range(N):
        if (i >> j) & 1 == 1:
            t += "+"
        t += S[j+1]
    ans += eval(t)
print(ans)

Measured memory_bytes: 3060
local function upper_bound(key,ary)
    local n=#ary
    if n==0 then
        return 1 
    end
    if key<ary[1] then
        return 1
    end
    if key>=ary[n] then
        return n+1
    end
    local min,max=1,n
    while 1<max-min do
        local mid=(min+max)//2
        if key>=ary[mid] then
            min=mid
        else
            max=mid
        end
    end
    return max
end

local function lower_bound(key,ary)
    local n=#ary
    if n==0 then
        return 1 
    end
    if key<=ary[1] then
        return 1
    end
    if key>ary[n] then
        return n+1
    end
    local min,max=1,n
    while 1<max-min do
        local mid=(min+max)//2
        if key>ary[mid] then
            min=mid
        else
            max=mid
        end
    end
    return max
end

----------

local n=io.read("n")
local l={}
for i=1,n do
    l[i]=io.read("n")
end
table.sort(l)

local comb=0
for i=1,n-2 do
    for j=i+1,n-1 do
        for k=j+1,n do
            if l[i]~=l[j] and l[j]~=l[k] and l[k]~=l[i] then
                if l[i]+l[j]>l[k] then
                    comb=comb+1
                end
            end
        end
    end    
end
print(comb)

Measured memory_bytes: 2752
n=int(input())
v=list(map(int,input().split()))
d_e={}
d_o={}
for i in range(n):
  if i%2==0:
    if v[i] in d_e:
      d_e[v[i]]+=1
    else:
      d_e[v[i]]=1
  else:
    if v[i] in d_o:
      d_o[v[i]]+=1
    else:
      d_o[v[i]]=1
d_o=sorted(d_o.items(),key=lambda x:x[1])
d_e=sorted(d_e.items(),key=lambda x:x[1])
if d_o[-1][0] != d_e[-1][0]:
    print(n-(d_o[-1][1]+d_e[-1][1]))
else:
  if (len(d_o)>=2) and(len(d_e)>=2):
    print(min(n-(d_o[-2][1]+d_e[-1][1]),n-(d_o[-1][1]+d_e[-2][1])))
  else:
    print(min(d_o[-1][1],d_e[-1][1]))

Measured memory_bytes: 17652
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




















 
int main(){
    ll n, ga, sa, ba, gb, sb, bb;
    cin >> n >> ga >> sa >> ba >> gb >> sb >> bb;
    vector<ll> dp(n + 1);
    for(ll i = 1; i <= n; i++){
        if(i >= ga) dp[i] = max(dp[i], dp[i - ga] + gb - ga);
        if(i >= sa) dp[i] = max(dp[i], dp[i - sa] + sb - sa);
        if(i >= ba) dp[i] = max(dp[i], dp[i - ba] + bb - ba);
    }
    ll m = dp[n] + n;
    vector<ll> dp2(m + 1);
    for(ll i = 1; i <= m; i++){
        if(i >= gb) dp2[i] = max(dp2[i], dp2[i - gb] + ga - gb);
        if(i >= sb) dp2[i] = max(dp2[i], dp2[i - sb] + sa - sb);
        if(i >= bb) dp2[i] = max(dp2[i], dp2[i - bb] + ba - bb);
    }
    cout << dp2[m] + m << endl;
}

Measured memory_bytes: 195584
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main = do
    n<-readLn::IO Int
    as<-replicateM n $ fst.fromJust.B.readInt <$> B.getLine ::IO[Int]
    print $ max (sol n as) (sol2 n as)
--
sol 2 [a,b] = abs(a-b)
sol n as = re (n-1) [a] [] u v
    where
        (a:u) = sort as
        v = reverse u

sol2 2 [a,b] = abs(a-b)
sol2 n as = re (n-1) [a] [] u v
    where
        (a:u) = sortBy (flip compare) as
        v = reverse u

re 0 lv rv _ _ = cal 0 (lv++reverse rv)
re 1 lv@(l:_) rv@(r:_) _ (a:_) = cal (max (abs(l-a)) (abs(r-a))) (lv++reverse rv)
re n [l] [] u (a:b:v) = re2 (n-2) [a,l] [b] u v
re n lv@(l:_) rv@(r:_) u (a:b:v)
    | (abs(l-a)+abs(r-b))>(abs(l-b)+abs(r-a)) = re2 (n-2) (a:lv) (b:rv) u v
    | otherwise = re2 (n-2) (b:lv) (a:rv) u v

re2 0 lv rv _ _ = cal 0 (lv++reverse rv)
re2 1 lv@(l:_) rv@(r:_) (a:_) _ = cal (max (abs(l-a)) (abs(r-a))) (lv++reverse rv)
re2 n lv@(l:_) rv@(r:_) (a:b:u) v
    | (abs(l-a)+abs(r-b))>(abs(l-b)+abs(r-a)) = re (n-2) (a:lv) (b:rv) u v
    | otherwise = re (n-2) (b:lv) (a:rv) u v

cal s [_] = s
cal s (a:b:v) = cal (s+abs(a-b)) (b:v)


Measured memory_bytes: 35196
a, b, c, d, e, f = map(int, input().split())

n = f//(100*a)
m = f//(100*b)
p = f//c
q = f//d

mx = 0
state = True
for k in range(p+1):
    for l in range(q+1):
        for i in range(n+1):
            for j in range(m+1):
                if i == 0 and j == 0:
                    continue
                s = 100*a*i+100*b*j
                t = c*k+d*l
                u = 100*t/s
                if s + t> f:
                    continue
                if u > e:
                    continue
                if mx < u:
                    state = False
                    mx = u
                    ans1, ans2 = s+t, t
                    if mx == e:
                        print(ans1, ans2)
                        exit()
if state:
    print(100*a, 0)
else:
    print(ans1, ans2)


Measured memory_bytes: 3064
#include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define int long long
#define double long double
#define INF INT_MAX
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, a;
vector<P> vec;
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a;
		vec.push_back({ a,0 });
	}
	rep(i, n) {
		cin >> a;
		vec.push_back({ a,1 });
	}
	sort(vec.begin(), vec.end());
	int ans = 1, p = 0, e = 0;
	rep(i, 2 * n) {
		if (vec[i].second == 0) {
			if (e > p)ans *= (e - p);
			p++;
		}
		else {
			if (p > e)ans *= (p - e);
			e++;
		}
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
#define ll long long
int n, i;
double s = 0, ans, x;
int main(){
	cin>>n;
	for(i = 1; i <= n; i++){
		cin>>x;
		s += 1.0000 / x;
	}
	cout<<(1/s)<<endl;
	return 0;
}

Measured memory_bytes: 256
def readln():
    import sys
    read = sys.stdin.readline
    return list(map(int, read().split()))


N, M = readln()
AB = [readln() for _ in range(M)]
A = [ab[0]-1 for ab in AB[::-1]]
B = [ab[1]-1 for ab in AB[::-1]]


class UnionFind:
    def __init__(self, N):
        self.N = N  # ノード数
        # 親ノードをしめす。負は自身が親ということ。
        self.parent = [-1] * N  # idxが各ノードに対応。

    def root(self, A):
        # print(A)
        # ノード番号を受け取って一番上の親ノードの番号を帰す
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.root(self.parent[A])  # 経由したノードすべての親を上書き
        return self.parent[A]

    def size(self, A):
        # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
        return -self.parent[self.root(A)]

    def concat(self, A, B):
        # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
        # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
        A = self.root(A)
        B = self.root(B)

        # すでにくっついている場合
        if (A == B):
            return False

        # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
        if (self.size(A) < self.size(B)):
            A, B = B, A

        # くっつける
        self.parent[A] += self.parent[B]  # sizeの更新
        self.parent[B] = A  # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる

        return True


ans = [N * (N - 1) // 2]
uni = UnionFind(N)
for a, b in zip(A, B):
    if uni.root(a) == uni.root(b):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uni.size(a) * uni.size(b))
        uni.concat(a, b)

for a in ans[-2::-1]:
    print(a)


Measured memory_bytes: 42088
n = int(input())
R = [0]*n
B = [0]*n
for i in range(n): R[i] = [int(j) for j in input().split()]
for i in range(n): B[i] = [int(j) for j in input().split()]
flag = [False]*n
R.sort(key=lambda x:x[1],reverse=True)
B.sort(key=lambda x:x[0])
ans = 0
for i in range(n):
    c,d = B[i]
    for j in range(n):
        if flag[j]: continue 
        a,b = R[j]
        if c > a and d > b:
            ans += 1
            flag[j] = True
            break
print(ans)

Measured memory_bytes: 3064
//#include<iostream>
#include<bits/stdc++.h>
using namespace std;
 int main(){
string s ;
cin>>s ;
map<string , int > ans ={

{ "SUN" , 7},
 {"MON" , 6},
 { "TUE" ,5},
 {"WED" , 4},
 {"THU" , 3},
 {"FRI" , 2},
{"SAT" , 1} ,


};
cout<< ans[s]<<endl;
return 0;



 }


Measured memory_bytes: 256
N, M = map(int, input().split())
LRD = [[int(i) for i in input().split()] for _ in range(M)]

class WeightedUnionFind() :
    def __init__(self, N) :
        self.parent = [-1] * N
        self.potential = [0] * N
        
    def root(self, x) :
        while self.parent[x] >= 0:
            x = self.parent[x]
        return x

    def unite(self, x, y, w) :
        rx = self.root(x)
        ry = self.root(y)
        
        if rx != ry :
            w = w + self.weight(x) - self.weight(y)
            if self.parent[rx] > self.parent[ry] :
                self.parent[rx] = ry
                self.potential[rx] = -w
            else :
                if self.parent[rx] == self.parent[ry] :
                    self.parent[rx] -= 1
                self.parent[ry] = rx
                self.potential[ry] = w
    
    def same(self, x, y) :
        return self.root(x) == self.root(y)
        
    def size(self, x) :
        return -self.parent[self.root(x)]
    
    def weight(self, x) :
        w = 0
        while self.parent[x] >= 0 :
            w += self.potential[x]
            x = self.parent[x]
        return w
        
    def diff(self, x, y) :
        return self.weight(y) - self.weight(x)
            
def solve() :
    WUF = WeightedUnionFind(N)
    for L, R, D in LRD :
        L, R = L - 1, R - 1
        if WUF.same(L, R) :
            if WUF.diff(L, R) != D :
                return 'No'
        else :
            WUF.unite(L, R, D)
    
    return 'Yes'
    
print(solve())

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

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

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

void Main()
{
    int n;cin>>n;
    VL a(n);
    LL small = INF_LL;
    int minus=0;
    REP(i,n){
        cin>>a[i];
        if(a[i]<0){
            minus++;
        }
        small = min(small,abs(a[i]));
    }

    LL result = 0;
    REP(i,n){
        result += abs(a[i]);
    }
    if(minus%2==1){
        result -= abs(small)*2;
    }

    cout<<result<<endl;


	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 1024
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	l := getNextInt(scanner)

	wf1 := makeInts(n, n)
	wf2 := makeInts(n, n)

	for y := 0; y < n; y++ {
		for x := 0; x < n; x++ {
			wf1[y][x] = math.MaxInt32
			wf2[y][x] = math.MaxInt32
		}
	}

	for i := 0; i < m; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		c := getNextInt(scanner)
		if c > l {
			continue
		}
		wf1[a][b] = c
		wf1[b][a] = c
	}

	for k := 0; k < n; k++ {
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				if i == j {
					continue
				}
				if wf1[i][j] > wf1[i][k]+wf1[j][k] {
					wf1[i][j] = wf1[i][k] + wf1[j][k]
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if wf1[i][j] <= l {
				wf2[i][j] = 1
			}
		}
	}

	for k := 0; k < n; k++ {
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				if i == j {
					continue
				}
				if wf2[i][j] > wf2[i][k]+wf2[j][k] {
					wf2[i][j] = wf2[i][k] + wf2[j][k]
				}
			}
		}
	}

	q := getNextInt(scanner)
	for i := 0; i < q; i++ {
		s := getNextInt(scanner) - 1
		t := getNextInt(scanner) - 1
		if wf2[s][t] == math.MaxInt32 {
			fmt.Fprintln(writer, -1)
			continue
		}
		fmt.Fprintln(writer, wf2[s][t]-1)
	}

	writer.Flush()
}

func makeInts(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}


Measured memory_bytes: 4864
import math
A, B, N, M = map(int, input().split())
a = (N * 60 + M) / 2
b = M * 6
c = abs(a - b)
c = math.radians(min(c, 360 - c))
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(c)))


Measured memory_bytes: 9560
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		boolean[] x=new boolean[n+1];
		Arrays.fill(x,false);
		int[] y=new int[n+1];
		int sum=0,num=0;
		for(int i=0;i<m;i++) {
			int a=sc.nextInt();
			String s=sc.next();
			if(s.equals("AC")) {
				x[a]=true;
			}else {
				if(!x[a])
					y[a]++;
			}
		}
		for(int i=0;i<n+1;i++) {
			if(x[i])
				num+=y[i];
			if(x[i])
				sum++;
		}
		System.out.print(sum+" "+num);
	}
} 

Measured memory_bytes: 64348
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

t = I()
for _ in range(t):
    n = I()
    klr = [LI() for _ in range(n)]
    ans = 0
    L = []
    R = []
    for k,l,r in klr:
        if l >= r:
            L.append([k, l-r])
        else:
            R.append([n-k, r-l])
        ans += min(l, r)
    L.sort()
    R.sort()
    hl = []
    hr = []
    for k, x in L:
        heappush(hl, x)
        if len(hl) > k:
            heappop(hl)
    for k, x in R:
        heappush(hr, x)
        if len(hr) > k:
            heappop(hr)
    ans += sum(hl) + sum(hr)
    print(ans)

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


int main()
{
	int n, k;
	int v[50];

	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> v[i];
	}

	int ans = 0;
	for(int l=0;l<=min(n,k);l++){
		for(int r=0;r<=k-l;r++){
			vector<int> take;
			for(int i=0;i<l;i++){
				take.push_back(v[i]);
			}
			for(int i=n-r;i<n;i++){
				if(i <= l)
					continue;
				take.push_back(v[i]);
			}
			sort(take.begin(), take.end());
			// for(int i=0;i<take.size();i++){
			// 	cout << take[i] << " ";
			// }cout << endl;
			int pop = k - l - r;
			for(int i=0;i<pop;i++){
				if(take.size() > 0 && take[0] < 0)
					take.erase(take.begin());
				else
					break;
			}
			int sum = 0;
			for(int i=0;i<take.size();i++){
				sum+=take[i];
			}
			//cout << l << " " << r << " " << sum << endl;
			if(ans < sum){
				ans = sum;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){

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

    string s ;
    cin >> s ;
    int last = s[0]-'0' ;
    int ans = 0 ;
    for(int i = 1; i < s.size(); i++){

        int x = s[i]-'0' ;
        if(x == last){

            x = 1-x ;
            ans++ ;

        }
        last = x ;

    }
    last = s[0]-'0' ;
    last = 1 - last ;
    int ans2 = 1 ;
    for(int i = 1; i < s.size(); i++){

        int x = s[i]-'0' ;
        if(x == last){

            x = 1-x ;
            ans2++ ;

        }
        last = x ;

    }
    cout << min(ans, ans2) ;

}


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

int main() {
    int a[3] = {0};
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
    }
    sort(a, a + 3);
    cout << a[0] + a[1] << endl;

    return 0;
}


Measured memory_bytes: 256
n, nc = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(nc)]
grid = [list(map(int, input().split())) for _ in range(n)]
dic = [{}, {}, {}]
for i in range(n):
    for j in range(n):
        if grid[i][j] not in dic[(i+j) % 3]:
            dic[(i+j) % 3][grid[i][j]] = 1
        else:
            dic[(i+j) % 3][grid[i][j]] += 1
minscore = 10 ** 10
def score(color, count):
    ret = 0
    for col, cnt in count.items():
        ret += d[col-1][color-1] * cnt
    return ret
for c0 in range(nc):
    for c1 in range(nc):
        for c2 in range(nc):
            if c0 != c1 and c1 != c2 and c2 != c0:
                minscore = min(minscore, score(c0,dic[0]) + score(c1,dic[1]) + score(c2,dic[2]))
print(minscore)


Measured memory_bytes: 5492
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int a,b;
    scanf("%d%d", &a, &b);

    if(b%a==0) {
        printf("-1\n"); return 0;
    }
    int i;
    for(i=1; i<a; i++) {
        ll tmp=(ll)b*i;
        ll tmp2 = tmp%a;
        if(tmp2==0) continue;
        ll tmp3 = a-tmp2;
        ll val = i + tmp3;
        if(val > (tmp+tmp3)/a) {
            printf("%lld\n", tmp+tmp3);
            return 0;
        }
    }
    printf("-1\n"); return 0;

    return 0;
}




Measured memory_bytes: 2764
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int d[1000];
int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i += 2)printf("%c", s[i]); printf("\n");
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	int a, b, m;
	cin >> a >> b >> m;
	vector<int> price_of_refrigerator(a);
	vector<int> price_of_microwave(b);
	for (int i = 0; i < a; i++) cin >> price_of_refrigerator[i];
	for (int i = 0; i < b; i++) cin >> price_of_microwave[i];

	int ans = *min_element(price_of_refrigerator.begin(), price_of_refrigerator.end())
		+ *min_element(price_of_microwave.begin(), price_of_microwave.end());
	for (int i = 0; i < m; i++) {
		int x, y, c;
		cin >> x >> y >> c;
		int price = price_of_refrigerator[x - 1] + price_of_microwave[y - 1] - c;
		ans = min(ans, price);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 12;
const ll inf = 1e9+7;


int main() {
  fastio;
 /* freopen("input.txt", "r", stdin);
  freopen("op1.txt", "w", stdout);*/
  ll k,ind=0;
  cin>>k;
  f(i,1,2e6){
    ind=(ind*10+7)%k;
    if(!ind){cout<<i<<endl;return 0;}
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e6+1)
//#define INF (1LL<<59)

vector<pii> vec;
int dp[101][100001];
int dfs(int ind,int w){
	if(w<0)return -INF;
	if(ind<=0)return 0;
	if(dp[ind][w]!=-1)return dp[ind][w];
	return dp[ind][w] = max(dfs(ind-1,w-vec[ind-1].second)+vec[ind-1].first,dfs(ind-1,w));
}


int main(){
	int n,l;
	cin>>n>>l;
	vec.resize(n);
	
	rep(i,n){
		int a,b;
		cin>>a>>b;
		vec[i] = pii(a,b);
	}
	memset(dp,-1,sizeof(dp));
	cout<<dfs(n,l)<<endl;
}

Measured memory_bytes: 42528
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;
int ans = 1e9;
bool ok = false;
int h, w;
vector<string> s(50);
vector<vector<int>>c(50,vector<int>(50,1e9));
int vx[4]={0,1,0,-1};
int vy[4]={1,0,-1,0};
void dfs(int i, int j, int cost)
{
    //cout<<i<<" "<<j<<endl;
    c[i][j]=min(c[i][j],cost);
    if (cost+1 <= ans&&ans!=h-1+w-1)
    {
        rep(k,4){
            if(0<=i+vx[k]&&i+vx[k]<h&&0<=j+vy[k]&&j+vy[k]<w){
                if(s[i+vx[k]][j+vy[k]]=='.'&&c[i+vx[k]][j+vy[k]]>cost+1){
                    dfs(i+vx[k],j+vy[k],cost+1);
                }
            }
        }
    }
    if (i == h - 1 && j == w - 1)
    {
        ok = true;
        ans = min(ans, cost);
    }
}
int main()
{

    cin >> h >> w;

    rep(i, h) cin >> s[i];
    int black = 0,white=0;
    
    rep(i, h) rep(j, w) if (s[i][j] == '#') black++; else white++;

    dfs(0, 0, 0);
   // cout<<ans<<endl;
    if (ok)
    {
        cout << max(white-2 - (ans -1),0) << endl;
    }
    else
    {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 512
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 1E+05;

ll N, M;

ll modFac(ll n);

ll f[MAX_N + 1];

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

    cin >> N >> M;

    ll ans = 0;
    modFac(max(N, M));
    if (N == M) {
        ans = (((f[N] * f[M]) % MOD) * 2) % MOD;
    } else if (N == M + 1 || M == N + 1) {
        ans = (f[N] * f[M]) % MOD;
    } else {
        ans = 0;
    }

    cout << ans << "\n";

    return 0;
}

ll modFac(ll n)
{
    ll ans = 1;
    for (int i = 1; i <= n; i++) {
        ans = (ans * i) % MOD;
        f[i] = ans;
    }
    return ans;
}

Measured memory_bytes: 4436
#include <bits/stdc++.h>
#define rep(i,n) for (ll 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
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
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 = 1e9;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
  ll X; cin >> X;
  int ans = 0,x = 0;
  while(x<X){
    ans++;
    x+=ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n, m, k = map(int, input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % PRIME

PRIME = 998244353
N = 2 * 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % PRIME )
    inverse.append( ( -inverse[PRIME % i] * (PRIME//i) ) % PRIME )
    g2.append( (g2[-1] * inverse[-1]) % PRIME )

ans = 0
for i in range(k + 1):
  ans += cmb(n - 1, i, PRIME) * pow(m - 1, n - i - 1, PRIME) * m
  ans %= PRIME

print(ans)

Measured memory_bytes: 33312
def getInv(N):#Qはmod
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv

Q = 10**9+7
N, A, B, C = map( int, input().split())
modinv = getInv( max(2*N-1, 100))
a = A*modinv[A+B]%Q
b = B*modinv[A+B]%Q
Powa = [1]*(N+1)
Powb = [1]*(N+1)
for i in range(N):
    Powa[i+1] = (Powa[i]*a)%Q
    Powb[i+1] = (Powb[i]*b)%Q
t = 100*modinv[100-C]%Q
ans = 0
nowc = 1
ans = Powa[N]*N + Powb[N]*N
ans %= Q
for k in range(N+1, N*2):
    nowc *= (k-1)*modinv[k-N]
    nowc %= Q
    ans += nowc*( Powa[N]*Powb[k-N] + Powb[N]*Powa[k-N])%Q*k%Q
    ans %= Q
print(ans*t%Q)

Measured memory_bytes: 18804
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = sum(B)

for i in range(N-1):
    if A[i+1]-A[i] == 1:
        ans += C[A[i]-1]
        
print(ans)

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

using namespace std;
typedef long long ll;

const int M = 1e9 + 7, N = 200'010;
ll a[N];

int main() {
    int n;
    scanf("%d", &n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        sum += a[i];
    }
    sum %= M;
    ll res = 0;
    for (int i = 0; i < n; i++) {
        sum -= a[i];
        if (sum < 0) sum += M;
        res = (res + a[i] * sum) % M;
    }
    printf("%lld\n", res);
}


Measured memory_bytes: 5296
/*
	"We all make choices in life, but in the end our choices make us."
*/
#include <bits/stdc++.h>
#define endl '\n'
#define FIO ios_base::sync_with_stdio(0); cin.tie(NULL)
#define pb push_back
#define pii pair<int,int>
#define ll long long int 
#define ui unsigned int
#define pll pair<ll,ll> 
#define mp make_pair
#define f first
#define s second
#define all(x) (x).begin(),(x).end() 
#define SORT(v) sort(all(v))
#define SORTD(v) sort(all(v),greater<int>())
#define SET(a,b) for(ui i=0;i<size(a);++i){a[i]=b;} 
#define test() int t; cin>>t ; while(t--)
#define FOR(i,a,b) for(int i=a;i<b;++i)  
#define cerr if(0)cerr
#define watch(x) cerr<<#x<<" is "<<x<<endl;
#define print(x) cout<<x<<endl
#define printv(v) for(auto i : v){cout<<i<<" ";}cout<<endl;
const ll MOD=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


//_________________________________________________________________________________

using namespace std;


int main()
{
	FIO;
	
	int a,p;
  cin>>a>>p;
  
  cout<<(a*3+p)/2;

	return 0;

}
	
	





Measured memory_bytes: 256
MOD = 10**6+3
n = MOD + 10

fac = [1] + [0] * n
for i in range(1, n+1):
    fac[i] = fac[i-1] * i % MOD

q = int(input())

def f(x, d, n):
    if d == 0:
        return pow(x, n, MOD)
    p = (x * pow(d, MOD-2, MOD)) % MOD
    if p + n - 1 >= MOD:
        return 0
    q = fac[(p + n - 1) % MOD]
    r = fac[p - 1]
    s = pow(d, n, MOD)
    return (q*pow(r, MOD-2, MOD)*s) % MOD

for i in range(q):
    x, d, n = [int(item) for item in input().split()]
    print(f(x, d, n))

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

int main(void){
    int n,i;
    cin >> n;

    vector<int>  a(n+1);
    for(i=1; i<=n; i++){
        cin >> a.at(i);
    }


    if(n % 2 == 0  && n > 2){
        for(i=n; i>=2; i-=2){
            cout << a.at(i) << " ";
        }
        for(i=1; i<n-1; i+=2){
            cout << a.at(i) << " ";
        }
        cout << a.at(n-1) << endl;
    }else if(n % 2 == 1 && n > 1){
        for(i=n; i>=1; i-=2){
            cout << a.at(i) << " ";
        }
        for(i=2; i<n-1; i+=2){
            cout << a.at(i) << " ";
        }
        cout << a.at(n-1) << endl;
    }



    if(n == 1){
        cout << a.at(1) << endl;
    }

    if(n == 2){
        cout << a.at(2) << " " <<a.at(1) << endl;
    }


    return 0;
}

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

using namespace std;

#ifdef Lin1043
    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)
    #define massert(...) assert(...)
#else
    #define DEBUG(...)
    #define massert(...)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

struct iopener
{
    iopener()
    {
#ifdef Lin1043
        // freopen("./in" , "r" , stdin);
#endif
    }
} iop;

typedef long long LL;

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}

const int N = 2000 + 5;

int n , A[N];

int main()
{
    read(n);
    rep(i , 0 , n * 2 - 1) read(A[i]);
    sort(A , A + n * 2);
    int Ans = 0;
    rep(i , 0 , n * 2 - 1) if(i % 2 == 0)
        Ans += A[i];
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n,l; cin>>n>>l;
	ll total=0;
	vl vec(n);
	rep(i,1,n+1){
		total+=l+i-1;
		vec[i-1]=l+i-1;
	}
	ll ans=MOD;
	rep(i,0,n){
		ll a=total-vec[i];
		ll b=abs(total-a);
		chmin(ans,b);
	}
	if(total<0) cout<<total+ans;
	else cout<<total-ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include<stdbool.h>
#include<stdlib.h>

int sheep = 0;

int wolf = 0;

char str[200];

int main(void) {

	fgets(str, sizeof(str), stdin);

	sscanf(str, "%d %d", &sheep, &wolf);

	if (sheep > wolf) {

		printf("%s\n","safe");

	}
	else
	{
		printf("%s\n", "unsafe");
	}



	return false;



}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int graph [300][300];

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

	int N; cin >> N;
	F0R(i, N) F0R(j, N) cin >> graph[i][j];
	
	bool fail = false;
	F0R(k, N) F0R(i, N) F0R(j, N) 
		fail |= graph[i][j] > graph[i][k] + graph[k][j];

	
	if (fail) {
		print(-1);
	} else {
		ll total = 0;
		F0R(i, N) F0R(j, N) {
			fail = false;
			F0R(k, N) if (k != i && k != j) fail |= graph[i][k] + graph[k][j] == graph[i][j];
			if (!fail) total += graph[i][j];
		}
		print(total / 2);
	}
}

Measured memory_bytes: 640
/*
                            Author: Ankit Kaul
*******Code Belongs to Respective Author Only*************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
/*freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
        {   if(n % 2 ==1)
            result=(result * x)%M;
            x=(x*x)%M;
            n=n/2;
        }
    return result%M;
}
bool isPrime(int n)
    {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
    }
int inv(int a,int m)
{   return power(a,m-2);
}   
int lcm(int a,int b)
{   return a*b/(gcd(a,b));
}
signed main()
{   jaldi
    int a,b,c;
    cin>>a>>b>>c;
    a=abs(a);
    int x=a/c;
    if(x==0)
    {   if(b%2==0)
        cout<<a<<endl;
        else
        cout<<abs(a-c)<<endl;      
    }
    else
    {   if(b<=x)
        cout<<abs(a-b*c);
        else
        {   b-=x;
            a=abs(a-c*x);
            if(b%2==0)
            cout<<a<<endl;
            else
            cout<<abs(a-c)<<endl;
        }
    }
}



Measured memory_bytes: 3632
import java.util.Scanner;

//Search
public class Main {

	static int c;
	static int[] a;

	static int comp(int k, int x){
		c++;
		return a[k]-x;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			a = new int[n];
			for(int i=0;i<n;i++)a[i]=sc.nextInt();
			int x = sc.nextInt();
			c = 0;
			int l = 0;
			int r = n-1;
			int k = (l+r)/2;
			while(l<=r){
				int com = comp(k, x);
				if(r<=l)break;
				if(com<0)l=k+1;
				else if(com>0)r=k-1;
				else break;
				k=(l+r)/2;
			}
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 26172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll a[100005];
ll ans;
ll gcd(ll i,ll j){
	if(j==0){
		return i; 
	}else{
		return gcd(j,i%j);
	}
}
int main(void){
	ll n,m; cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	if(a[n-1]<m){
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
	ans=gcd(a[0],a[1]);
	for(int i=2;i<n;i++){
		ans=gcd(ans,a[i]);
	}
	if(m%ans==0){
		cout<<"POSSIBLE"<<endl;
	}else{
		cout<<"IMPOSSIBLE"<<endl;
	}
	
}


Measured memory_bytes: 1024
#include <stdio.h>

#define X 600

int main(void)
{
	int y;
	int d;
	int s = 0;
	int i;
	
	while (scanf("%d", &d) != EOF){
		for (i = 0; i < X; i += d){
			s += d * i * i;
		}
		printf("%d\n", s);
		s = 0;
	}
	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
n = int(input())

v = list(map(int, input().split()))
c = list(map(int, input().split()))

kati = []
for i in range(n):
    kati.append(v[i]-c[i])

count = 0

for k in kati:
    if k>0: count += k

print(count)




Measured memory_bytes: 3060