akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	map<string, int>A;
	int Q;
	cin >> Q;
	string key;
	int x;
	int a;
	rep(i, Q) {
		cin >> a;
		if (a == 0) {
			cin >> key >> x;
			A[key] = x;
		}
		else if (a == 1) {
			cin >> key;
			cout << A[key] << endl;
		}
	}
}




Measured memory_bytes: 27888
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	int a;
	scanf("%d",&a);
	printf("%.10f\n",(double)a*6.28318530717958623200);
	return 0;
}


Measured memory_bytes: 3824
// Har Har Mahadev
#include <bits/stdc++.h>
#define debug(x) cout << #x << " -> " << x << endl
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back

using namespace std;

void testcase(){
	int n,a[200005],k;
	cin >> n >> k;
	for(int i{0};i < n;i++){
		cin >> a[i];
	}
	int zer = 0;
	for(int i{0};i < k;i++){
		zer += (a[i] == 0);
	}
	for(int i = k;i < n;i++){
		zer -= (a[i-k] == 0);
		if(a[i] > a[i-k] && zer == 0){
			cout << "Yes\n";
		}
		else{
			cout << "No\n";
		}
		zer += (a[i] == 0);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 4396
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		ArrayList<Integer> array = new ArrayList<Integer>();

		for(int i=0;i<x;i++) {
			int tmp = sc.nextInt();
			array.add(tmp);
		}

		for(int i=x-1;i>=0;i--){
			System.out.print(array.get(i));
			if(i!=0) {
				System.out.print(" ");
			}
		}
		System.out.println();

		sc.close();
	}
}


Measured memory_bytes: 26228
package main

import (
        "fmt"
)

func solution(n, a, b int) int {
        out := 0
        for i := 1; i <= n; i++ {
                t := sumDigit(i)
                if t >= a && t <= b {
                        out += i
                }
        }
        return out
}

func sumDigit(n int) int {
        out := 0
        for n > 0 {
                out += n % 10
                n /= 10
        }
        return out
}

func main() {
        var n, a, b int
        fmt.Scan(&n, &a, &b)
        fmt.Println(solution(n, a, b))
}


Measured memory_bytes: 512
// Marcin Knapik
#include<bits/stdc++.h>
// #pragma GCC optimize("O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds; 
// #define ordered_set tree< int , null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)

typedef long double             ld;
typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;

#define boost                   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define REP(i, a, b)            for (int i = (a); i <= (b); i++)
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define TRAV(i, n)              for(auto&i:n)
#define beg(x)                  (*(x.begin()))
#define re(x)                   int x; cin >>x;   
#define f                       first
#define s                       second

template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1000000000000000000;
const ll N = 1e6+7;
const ll T = 1<<20;

ll n, m, k, q;

vi tab = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	cin >> n >> m;
	if(min(n, m) == 1){
		cout << 1 << '\n';
		exit(0);
	}
 
	if(n&1 and m&1){
		cout << n * m / 2 + 1 << '\n';
	}
	else{
		cout << n * m / 2 << '\n';
	}
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
	ll a;
	cin>>a;
	string s;
	cin>>s;
	if(a>=3200){
		cout << s << endl;
	}
	else{
		cout << "red" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
while true
  m,f,r = gets.chomp.split(" ").map &:to_i

  break    if m == -1 and f == -1 and r == -1
  puts "A" if 80 <= m+f and -1 < m*f
  puts "B" if 65 <= m+f and m+f < 80 and -1 < m*f
  puts "C" if 50 <= m+f and m+f < 65 and -1 < m*f
  puts "C" if 30 <= m+f and m+f < 50 and 50 <= r and -1 < m*f
  puts "D" if 30 <= m+f and m+f < 50 and r < 50  and -1 < m*f
  puts "F" if m+f < 30 or m == -1 or f == -1

end
  

Measured memory_bytes: 8660
#include <bits/stdc++.h>
using namespace std;
//useful 
#define rep(i,n) for(int i = 0; i < (n); i++)
int long long gcd(int long long a, int long long b){
    return b?gcd(b,a%b):a;
} //最大公約数
int long long lcm(int long long a, int long long b){
    return a/gcd(a,b)*b;
} //最小公倍数
int long long GetDigit(int long long num){
    int long long digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
} //桁数
int long long GetDigitN(int long long num, int long long N){
    int long long digit=0;
    while(num!=0){
        num /= N;
        digit++;
    }
    return digit;
} //十進数でnumの際のN進数における桁数
int long long divisorcount(int long long n){
	int long long ans = 1;
	vector<int> x(n + 1);
	int long long num = n; // 素因数分解する変数num 
	for (int long long i = 2; i <= n; i++) {
		while (num%i == 0) { // 素数で割り切れなくなるまで割っていく
			x.at(i)++; //割った個数を配列に足す
			num /= i;
		}
	}
	for (int i = 2; i <= n; i++){	
		ans *= x.at(i) + 1; //それぞれを+1して掛けていく
	}
    return ans;
} //約数カウント

int main(){
    int A;
    cin >> A;
    if(A >= 30){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]

if m==1:
    for i in a:
        if b[0] in i:
            print('Yes')
            exit()
        else:
            print('No')
            exit()

for i in range(n-m+1):
    cnt=0
    while cnt<n-m+1:
        l=[]
        for j in range(m):
        #bと同じ長さの部分配列を作る
            l+=[a[j+cnt][i:i+m]]

        if l==b:
            print('Yes')
            exit()
        cnt+=1
print('No')

Measured memory_bytes: 3064
s=input()
t=input()

num_t=len(t)
num=[]
for i in range(len(s)-num_t+1):
    temp_s=s[i:i+num_t]
    trial=True
    for x,y in zip(temp_s,t):
        if x!='?' and x!=y:
            trial=False
            break

    if trial:
        num+=[i]


if num==[]:
    print('UNRESTORABLE')
    exit()

ans='z'*50
for j in num:
    temp=''
    for i in range(len(s)):
        if j==i:
            temp+=t

        elif i<j or j+num_t<=i:
            if s[i]=='?':
                temp+='a'
            else:
                temp+=s[i]
    if temp<ans:
        ans=temp

print(ans)


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

int main() {
    int N,M;cin >> N >> M;
    int k;
    vector<vector<int>> s(M);
    for (int i = 0;i < M;i++){
        cin >> k;
        for (int j = 0;j < k;j++){
            int a;cin >> a;a--;
            s[i].push_back(a);
        }
    }
    vector<int> p(M);
    for (int i = 0;i < M;i++){
        cin >> p[i];
    }
    ll ans = 0;
    for(int bit = 0;bit < (1 << N);bit++) {
        int flag = 0;
        for (int i = 0; i < M; i++) {
            int count = 0;
            for (auto j :s[i]) {
                if ((bit & (1 << j))) count++;
            }
            if ((count % 2) != p[i]) flag = 1;
        }
        if (flag == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a[3],b[2],r=0;
	int i;
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	if(a[0]<a[1]&&a[0]<a[2]){
		r+=a[0];
	}else if(a[0]>a[1]&&a[2]>a[1]){
		r+=a[1];
	}else{
		r+=a[2];
	}
	for(i=0;i<2;i++){
		scanf("%d",&b[i]);
	}
	if(b[0]>b[1]){
		r+=b[1];
	}else{
		r+=b[0];
	}
	printf("%d\n",r-50);
	return 0;
}

Measured memory_bytes: 592
import java.util.*;

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

        int s = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());

        if(w >= s){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
    }
}

Measured memory_bytes: 26976
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

//Ford-Fulkerson法、蟻本そのまま
//最大流(=最小カット)を求めるアルゴリズム
//隣接リスト表現での実装
//計算量は最大流量Fとして、O(F|E|)だが、実際はもっと高速
//Dinic法はさらに高速らしい

//辺を表す構造体（行き先、容量、逆辺）
struct edge{ll to, cap, rev;};

vector<vector<edge>> G(203, vector<edge>(0));;//$1には最大頂点数+3を入れよう！
bool used[203];

//辺を追加する！
//fromからtoへ向かう容量capの辺
void add_edge(ll from, ll to, ll cap){
    G[from].emplace_back(edge{to,cap,(ll)G[to].size()});
    G[to].emplace_back(edge{from,0,(ll)G[from].size()-1});
}

//増加パスをdfsで探す！
ll dfs(ll v, ll t, ll f){
    if(v==t)return f;
    used[v]=1;
    for(ll i=0;i<G[v].size();i++){
        edge &e=G[v][i];
        if(!used[e.to]&&e.cap>0){
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

//sからdへの最大流を求める
ll max_flow(ll s,ll t){
    ll flow=0;
    for(;;){
        memset(used,0,sizeof(used));
        ll f=dfs(s,t,INF);
        if(f==0)return flow;
        flow+=f;
    }
}



int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1,0);
    vector<ll> B(N+1,0);
    vector<ll> C(N+1,0);
    vector<ll> D(N+1,0);
    for(ll i=1;i<=N;i++)cin>>A[i]>>B[i];
    for(ll i=1;i<=N;i++)cin>>C[i]>>D[i];

    //辺の追加
    for(ll i=1;i<=N;i++)
        for(ll j=1;j<=N;j++)
            if(A[i]<C[j]&&B[i]<D[j])add_edge(i,j+N,1);
    
    for(ll i=1;i<=N;i++)add_edge(0,i,1);
    for(ll i=N+1;i<=2*N;i++)add_edge(i,2*N+1,1);

    print(max_flow(0,2*N+1))

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){


char number[1001]={0};
int i,sum=0;



while(1){
      sum=0;
      scanf("%s",&number);
      if(number[0]== '0' ) break;


      for(i=0;number[i]!= '\0';i++){
              sum=sum+(number[i]-'0');
      }
      printf("%d\n",sum);

}
return 0;

}

Measured memory_bytes: 536
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn readc() -> char {
    let s: String = read();
    return s.chars().nth(0).unwrap();
}

fn read_vec<T: FromStr>(n: usize) -> Vec<T> {
    return (0..n).map(|_| read()).collect();
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut ai: Vec<u64> = read_vec(n);

    ai.sort();
    ai.reverse();

    let cnt: u64 = ai.clone().into_iter().sum();
    let target = ai[m-1];
    let cond = cnt as f64 / (4.0 * m as f64);

    // println!("{} {} {}", cnt, target, cond);

    if (target as f64) < cond {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
local unpack = table.unpack or unpack
local insert = table.insert or insert
local max = math.max
----
local N, M = read.nn()
local adj_mat = array(2, nil)
local rev_adj_mat = array(2, nil)
for i=1,M do
    local x, y = read.nn()
    adj_mat[x][y] = true
    rev_adj_mat[y][x] = true
end
local function indeg_zero(n)
    for k, v in pairs(rev_adj_mat[n]) do
        if v then
            return false
        end
    end
    return true
end

local toposorted = {}
local function make_queue()
    local q = {}
    local front = 1
    local back = #q + 1
    local function push(v)
        q[back] = v
        back = back + 1
    end
    local function pop()
        local r = q[front]
        front = front + 1
        return r
    end
    local function empty()
        return back - front == 0
    end
    return push, pop, empty
end
local push, pop, empty = make_queue()
for n=1,N do
    if indeg_zero(n) then
        push(n)
    end
end

local lp_from = array(1, 0)
local ans = 0
while not empty() do
    local n = pop()
    insert(toposorted, n)
    for m in pairs(adj_mat[n]) do
        rev_adj_mat[m][n] = nil
        if indeg_zero(m) then
            push(m)
            --lp_from[m] = max(lp_from[m], lp_from[n] + 1)
            lp_from[m] = lp_from[n] + 1
            ans = max(ans, lp_from[m])
        end
    end
end
print(ans)

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

int main(void) {
    int H,W;
    bool ans;
    int one,two,four;
    int tone=0,ttwo=0,tfour=0;
    string s;
    vector<int> ch(26, 0);
    cin >> H >> W;
    for (int i=0; i<H; i++) {
        cin >> s;
        for (int j=0; j<s.size(); j++) ch[(int)(s[j] - 'a')]++;
    }
    if (H % 2 == 0 && W % 2 == 0) {
        one = 0;
        two = 0;
        four = (H * W) / 4;
    } else if (H % 2 != 0 && W % 2 == 0) {
        one = 0;
        two = W / 2;
        four = ((H - 1) * W) / 4;
    } else if (H % 2 == 0 && W % 2 != 0) {
        one = 0;
        two = H / 2;
        four = (H * (W - 1)) / 4;
    } else {
        one = 1;
        two = (H + W - 2) / 2;
        four = ((H-1) * (W-1)) / 4;
    }
    for (int i=0; i<26; i++) {
        tfour += ch[i] / 4;
        ch[i] = ch[i] % 4;
        ttwo += ch[i] / 2;
        ch[i] = ch[i] % 2;
        tone += ch[i];
    }
    if (tfour < four) ans = false;
    else {
        ttwo += (tfour - four) * 2;
        ans = (ttwo == two && tone == one);
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int total = 0;
    for (int i = 1; i <= n; i++){
        string s = to_string(i);
        int sum = 0;
        for (auto si:s){
            int j = si - '0';
            sum += j;
        }
        if (a <= sum && sum <= b) total += i;
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        long sum = 0;
        for (int i = 0; i < N; i++) {
            int A = sc.nextInt();
            map.put(A,map.getOrDefault(A,0)+1);
            sum += A;
        }
        StringBuilder ans = new StringBuilder();
        int Q = sc.nextInt();
        for (int i = 0; i < Q; i++) {
            int B = sc.nextInt();
            int C = sc.nextInt();
            if (!map.containsKey(B)) {
                ans.append(sum).append('\n');
                continue;
            }
            int cnt = map.get(B);
            sum -= (long)cnt*B;
            sum += (long)cnt*C;
            map.put(C,map.getOrDefault(C,0)+cnt);
            map.put(B,0);
            ans.append(sum).append('\n');
        }

        System.out.print(ans);
    }
}



Measured memory_bytes: 66220
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  int L[n];
  rep(i,n) cin >> L[i];
  sort(L,L+n);
  // for(int i = 0; i < n; i++) printf("%d\n", L[i]);
  long long array[2000+1] = {0};
  for(int i = 0; i < n; i++){
    array[L[i]]++;
    // printf("%d %d\n",L[i] ,array[L[i]]);
  }
  for(int i = 1; i <=2000; i++){
    array[i] = array[i] + array[i-1];
    // printf("%d",array[i] );
  }

  long long cnt = 0;
  int a,b;
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
        a = L[i];
        b = L[j];
        cnt += array[a+b-1] - array[b-a];
        if(b-a < a && a < a+b) cnt--;
        if(b-a < b && b < a+b) cnt--;
    }
  }
  printf("%lld\n", cnt/3);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 100000000;

int main(){
	int N, M;
	cin >> N >> M;
	int a[M], b[M], c[M], d[N][N];
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			d[i][j] = INF;
		}
		d[i][i] = 0;
	}
	for(int i=0; i<M; i++){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
		d[a[i]][b[i]] = c[i];
		d[b[i]][a[i]] = c[i];
	}
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			for(int k=0; k<N; k++){
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
	int ans = 0;
	for(int i=0; i<M; i++){
		bool flag = true;
		for(int j=0; j<N; j++){
			for(int k=0; k<N; k++){
				if(c[i] + d[j][a[i]] + d[b[i]][k] == d[j][k] || c[i] + d[j][b[i]] + d[a[i]][k] == d[j][k]){
					flag = false;
				}
			}
		}
		if(flag) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define all(a) (a.begin(), a.end())

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

void solve() {
	string s;
	cin >> s;
	int n = (int)s.length();
	int ans = 1e9;
	for (int i = 0; i < n-2; ++i) {
		char t[4];
		t[0] = s[i], t[1] = s[i+1], t[2] = s[i+2], t[3] = '\0';
		int m = atoi(t);
		ans = min(ans,abs(m-753));
	}

	cout << ans << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

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

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

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

using namespace std;
typedef long long ll;

int main(){
	vector<int>n(3);
	for(int i = 0; i < 3; i++){
		cin >> n[i];
	}

	sort(n.begin(), n.end(),greater<int>());

	int ans = n[0] * 10 + n[1] + n[2];

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <random>
#include <map>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)
#define YN(f) f?cout<<"YES"<<endl:cout<<"NO"<<endl;
#define yn(f) f?cout<<"Yes"<<endl:cout<<"No"<<endl;

int a,b,c;

signed main(){
	cin>>a>>b>>c;
	cout<<a*b/2<<endl;
	return 0;
}

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

int main(){
  int n,m,input;
  vector<int> a;
  float sum=0;
  cin >> n >> m;
  while (cin >> input){
    sum += input;
    a.push_back(input);
  }
  
  sort(a.begin(),a.end(),greater<int>());
  int count = 0;
  for(int i=0;i<m;i++){
    if((sum/(4*m))<=a[i]){
    	count++;
    }else{
    	break;
    }
      if(count==m){
    cout<<"Yes";
    return 0;
  }
  }



  cout << "No";
  return 0;
}

Measured memory_bytes: 256
N, K = list(map(int, input().split()))

count = 0
for i in range(K, N+2):
    # count += sum(range(N+1-i,N+1))-sum(range(i))+1
    # i*(2*N+1-i)/2-i*(i-1)/2 +1
    count += (N+1-i)*i+1

# print(count)
print(count % (10**9+7))

Measured memory_bytes: 9136
s = input()
# s = 'igyojknviataivnkjoygizigyojknviaaaivnkjoygi'
n= len(s)

tmp1 =s[:int((n-1)/2)]
tmp2 =s[int((n+3)/2)-1:]


flg = True

for i in range(0, int(len(tmp1)/2)):
    if tmp1[i] != tmp1[len(tmp1)-1-i]:
        flg = False

for i in range(0, int(len(tmp2)/2)):
    if tmp2[i] != tmp2[len(tmp2)-1-i]:
        flg = False

if s != s[::-1]:
    flg = False

if flg == True:
    print("Yes")
else:
    print("No")




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

int main() {
  int K,N;
  cin >> K >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  int s=K+a[0]-a[N-1];
  for(int i=0;i<N-1;i++){
    int t=a[i+1]-a[i];
    s=max(s,t);
  }
  cout << K-s << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define N 1116

int n,m,h[N],c[N],ans;
queue<int> a[N];

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();m=read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			a[i].push(read());
	ans=0x3fffffff;
	for (int i=1;i<=m;i++){
		for (int j=1;j<=n;j++)
			while (h[a[j].front()]) a[j].pop();
		fill(c+1,c+m+1,0);
		for (int j=1;j<=n;j++)
			c[a[j].front()]++;
		int t=1;
		for (int j=1;j<=m;j++)
			if (c[j]>c[t]) t=j;
		h[t]=1;ans=min(ans,c[t]);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
	int N, K;
	int rA, rB;
	int result = 1;

	cin >> N >> K;

	if (N >= 1 && N <= 10 && K >= 1 && K <= 10) {
		for (int i = 0; i < N; i++) {
			rA = result * 2;
			rB = result + K;
			if (rA >= rB) {
				result = rB;
			} else {
				result = rA;
			}
		}
		cout << result << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <iostream>


int main(void)
{
    int n = 0;
    std::cin >> n;

    std::vector<int> S(n);
    for (int i = 0; i < n; i++) {
        std::cin >> S[i];
    }

    int q = 0;
    std::cin >> q;

    std::vector<int> T(n);
    for (int i = 0; i < q; i++) {
        std::cin >> T[i];
    }


    int C = 0;

    for (int i = 0; i < q; i++) {
        for (int j = 0; j < n; j++) {
            if (T[i] == S[j]) {
                C++;
                break;
            }
        }
    }

    std::cout << C << "\n";

    return 0;
}


Measured memory_bytes: 3184
from sys import stdin
input = stdin.readline

def BFS(K,edges,N):
  roots=[ [] for i in range(N)]
  for a,b,c in edges:
    roots[a-1]+=[(b-1,c)]
    roots[b-1]+=[(a-1,c)]
  dist=[-1]*N
  stack=[]
  stack.append(K)
  dist[K]=0
  while stack:
    label=stack.pop(-1)
    for i,c in roots[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        stack+=[i]
  return dist
 

edges=[]
N = int(input())
K = 1
for i in range(N-1):
  edges += [list(map(int,input().split()))]
distance = BFS(K-1,edges,N)
for i in range(N):
  print(distance[i] % 2)



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

ll n, m, ans;

int main() {
    cin >> n >> m;
    // Scc
    if (n >= m / 2) ans = m / 2;
    else ans = n + (m - n * 2) / 4;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    A = LI()
    F = LI()

    A.sort()
    F.sort(reverse=True)

    # 時間tで感触できるか
    def can_complete(t):
        return sum([max(i-t//j, 0) for i, j in zip(A, F)]) <= K

    # for j in range(20):
    #     print(can_complete(j))

    ng = -1
    ok = max(A)*max(F)
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        if can_complete(m):
            ok = m
        else:
            ng = m
    print(ok)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 138032
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
long long M = 1e9+7;
long long power(long long a, long long p)
    {
        if(p==0) return 1;
        long long ans= power(a,p/2);
        ans =(ans * ans) % M;
        if(p%2) ans = (ans*a) % M;
        return ans;
    }

    bool isPrime(long long n)
    {
        if (n <= 1)
            return false;
        for (long long i = 2; i < n; i++)
            if (n % i == 0)
                return false;
        return true;
    }
    long long SieveOfEratosthenes(long long n, long long a)
    {
        bool prime[n+1];
        memset(prime, true, sizeof(prime));
        for (long long p=2; p*p<=n; p++)
        {
            if (prime[p] == true)
            {
                for (long long i=p*p; i<=n; i += p)
                    prime[i] = false;
            }
        }
        for (long long p=2; p<=n; p++)
           if (prime[p])
           {
               if(a%p==0)
               {
                   return (a-p);
               }
           }
    }
    long long nCr(int n, int r)
    {
        if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
        long long ans = 1;
        int i;
        for(i = 1; i <= r; i++) {
            ans *= n - r + i;
            ans /= i;
        }
        return ans;
    }
int main()
{
    IOS;
    long long a,b,c,d,e,h,k,l,n,t,f,m,f1=0,flag=0,flag1=0,co=0,co1=0,co2=0,arr1[100001]={0},sum=0,sum1=0,ma=0,ma1=0,mi=1000000000000000001;
    long long g,co3=0,co4=0,co5=0,co6=0,co7=0,co8=0,mul=1,sum2=0,sum3=0,mu=1,mu1=1;
    long long a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,b6,c1;
    double pi=2 * acos (0.0);
    string str,str1,str2,str3,str4,str5,str6;
    char ch,ch1;
    //vector<long long>v; //vector<long long> v(n+1);
    //vector<long long>v1;
    // vector<string>vs;
    // vector<string>vs1;
    vector<char>vc;
    //map<long long,long long>mp;
    map<char,int>mp1;
    //set<long long>s;
    set<long long>s1;
    queue<long long> q;
    //stack<long long> stk;
    //vector< pair<long long,long long> >v3;
    //map<long long,long long>::iterator it;
    //map<string,string>::iterator it;
    // vector<pair<char, pair<int,int> > > v3;
    //vector< pair<char,int > > v1;
    int x[]={1,1,1,0,0,-1,-1,-1};
    int y[]={0,1,-1,1,-1,1,-1,0};
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[111111],k,mx,g;
int gcd(int a,int b)
{
	if (!b) return a;
	return gcd(b,a%b);
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		mx=max(mx,a[i]);
	}
	if (n==1 && mx!=k)
	{
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
	else if (n==1 && mx==k)
	{
		cout<<"POSSIBLE"<<endl;
		return 0;
	}
	if (mx<k)
	{
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
	g=gcd(a[1],a[2]);
	for (int i=3;i<=n;i++)
	{
		g=gcd(a[i],g);
	}
	if (k%g) cout<<"IMPOSSIBLE"<<endl;
	else cout<<"POSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long  ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
//�ő����
int ans;
int n,m;
int a[111111];
int cnt[111111];
signed main(){
    cin>>n>>m;
    priority_queue<int> q;
    rep(i,n){
        cin>>a[i];
        q.push(a[i]);
    }
    rep(i,m){
        int b=q.top();q.pop();
        b/=2;
        q.push(b);
    }
    while(q.size()){
        ans+=q.top();q.pop();
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 1912
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#include <set>
#include <climits>
#define lli long long int
#define ll long long
#define mod 1000000007
#define pii pair<int,int>
#define mp make_pair
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;


int main(){
        int n, a, b;
        cin >> n >> a >> b;
        if(n * a > b){
          cout << b;
        }
        else{
        
        cout << n * a;
        }
        return 0;
}


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

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

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

    int A,B; cin >> A >> B;

    if(A >= 13) cout << B << endl;
    else if(A >= 6) cout << B/2 << endl;
    else cout << 0 << endl;

    return 0;

}

Measured memory_bytes: 256
import sys

a_list = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b_list = [int(input()) for _ in range(n)]
bingo_list = [[0,0,0] for _ in range(3)]

for b in b_list:
    for i,row in enumerate(a_list):
        for j,n in enumerate(row):
            if n == b:
                bingo_list[i][j] = 1

for row in bingo_list:
    if sum(row) == 3:
        print('Yes')
        sys.exit()

for i in range(3):
    num = bingo_list[0][i] + bingo_list[1][i] + bingo_list[2][i]
    if num >= 3:
        print('Yes')
        sys.exit()

if bingo_list[0][0] + bingo_list[1][1] + bingo_list[2][2] >= 3:
    print('Yes')
    sys.exit()

if bingo_list[0][2] + bingo_list[1][1] + bingo_list[2][0] >= 3:
    print('Yes')
    sys.exit()

print('No')

Measured memory_bytes: 3064
N,M=map(x->parse(Int,x),split(readline()))
c=zeros(Int,N)
a=b=0
for s=readlines()
  p,s=split(s)
  p=parse(Int,p)
  if s=="AC"
    if c[p]>=0
      a+=1
      b+=c[p]
      c[p]=-1
    end
  else
    if c[p]>=0
      c[p]+=1
    end
  end
end
println("$a $b")

Measured memory_bytes: 169260
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K, num=0;
  cin >> N>>K;

  for(int i=0; i<N; i++){
    int x;
    cin>>x;
    num += min(x*2,abs(K-x)*2);
  }
  cout << num << endl;
}

Measured memory_bytes: 256
import math
from collections import defaultdict
import itertools
def trial_division(n):
    a = [1]
    for i in range(2,int(math.sqrt(n)) + 1):
        while n % i == 0:
            n //= i
            a.append(i)
    a.append(n)
    return a

N = int(input())
d = defaultdict(int)
for i in range(2,N+1):
    for k in trial_division(i):
        if k != 1:
            d[k] += 1
check = []
for v in d.values():
    if v != 1:
        check.append(v)
M = len(check)
tmp = 1
ans = 0

for i in check:
    if i >= 74:
        ans += 1

for i in range(M):
    for k in range(i+1,M):
        for a in range(1,check[i]+1):
            for b in range(1,check[k]+1):
                if (a+1)*(b+1) == 75:
                    ans += 1

for i in range(M):
    for k in range(i+1,M):
        for l in range(k+1,M):
            for a in range(1,check[i]+1):
                for b in range(1,check[k]+1):
                    for c in range(1,check[l]+1):
                        if (a+1)*(b+1)*(c+1) == 75:
                            ans += 1

print(ans)

Measured memory_bytes: 44268
N =int(input())
A1 = a = list(map(int, input().split()))
A2 = a = list(map(int, input().split()))

f_a1 = [0 for i in range(len(A1))]
f_a2 = [0 for i in range(len(A2))]
F = [0 for i in range(len(A1))]
for i in range(len(A1)):
    f_a1[i] = sum(A1[:i+1])
    f_a2[i] = sum(A2[i:])
    F[i] = f_a1[i] + f_a2[i]

print(max(F))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}



int main(){
    // Failed to predict input format
    ll N,M,X;
    cin >> N >> M >> X;
    vector<ll> C(N);
    vector<vector<ll>> A(N, vector<ll>(M));
    for (long long i = 0; i < N; i++) {
        cin >> C[i];
        for (long long j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    ll n = N;
    ll res=INT_MAX;
    for (ll bit = 0; bit < (1<<n); bit++) {
        V v;
        for (ll i = 0; i < n; i++) {
            if(bit & (1<<i)) {
                v.push_back(i);
            }
        }

        vector<ll> a(M);
        ll mi=0;
        for (ll i = 0; i < v.size(); i++) {
            ll idx=v[i];
            mi+=C[idx];
            for (long long j = 0; j < M; j++) {
                a[j]+=A[idx][j];
            }
        }

        bool f=true;
        for (long long j = 0; j < M; j++) {
            if(a[j]<X){
                f=false;
                break;
            }
        }
        if(f==true){
            chmin(res, mi);
        }

    }
    if(res==INT_MAX){
        cout << -1 << endl;
    }else{
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int L,N;
  cin >> N >> L;
  string s[200];
  for(int i = 0; i < N; i++)
    cin >> s[i];

  sort(s,s+N);
  for(int i = 0; i < N; i++)
    cout << s[i];
  cout << endl;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 n;
    cin >> n;

    i64 ans = 0;
    for (i64 i = 1; i <= n; i++) {
        i64 j = n / i;
        ans += i * j * (j + 1) / 2;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a.at(i);
	sort(a.begin(),a.end());
	vector<ll> b(n),c(n);
	if(n % 2 == 0){
		int k = 2;
		b.at(0) = -1;
		for(int i = 1; i < n - 1; i++){
			b.at(i) = k;
			k *= -1;
		}
		b.at(n - 1) = 1;
		k = -2;
		c.at(0) = 1;
		for(int i = 1; i < n - 1; i++){
			c.at(i) = k;
			k *= -1;
		}
		c.at(n - 1) = -1;
	}
	else{
		int k = 2;
		b.at(0) = -1;
		for(int i = 1; i < n - 1; i++){
			b.at(i) = k;
			k *= -1;
		}
		b.at(n - 1) = -1;
		k = -2;
		c.at(0) = 1;
		for(int i = 1; i < n - 1; i++){
			c.at(i) = k;
			k *= -1;
		}
		c.at(n - 1) = 1;
	}
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	ll ans1 = 0, ans2 = 0;
	rep(i,n){
		ans1 += a.at(i) * b.at(i);
		ans2 += a.at(i) * c.at(i);
	}
	cout << max(ans1, ans2) << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  int H, W;
  char a[110][110];
  bool w[110], h[110];

  cin >> H >> W;
  for(int y = 0; y < H; y++){
    for(int x = 0; x < W; x++){
      cin >> a[y][x];
    }
  }

  for(int y = 0; y < H; y++){
    bool flag = false;
    for(int x = 0; x < W; x++){
      if(a[y][x] == '#') flag = true;
    }
    h[y] = flag;
  }

  for(int x = 0; x < W; x++){
    bool flag = false;
    for(int y = 0; y < H; y++){
      if(a[y][x] == '#') flag = true;
    }
    w[x] = flag;
  }


  for(int y = 0; y < H; y++){
    if(h[y]){
      for(int x = 0; x < W; x++){
        if(h[y] && w[x]) cout << a[y][x];
      }
      cout << endl;
    }
  }

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    static int[] A;
    static final int SENTINEL = Integer.MAX_VALUE;
    static int count = 0;
    static int[] L = new int[500000];
    static int[] R = new int[500000];

    static void merge(int l, int m, int r){
        int n1 = m - l, n2 = r - m;


        for (int i = 0; i < n1; i++)
            L[i] = A[l + i];
        for (int i = 0; i < n2; i++)
            R[i] = A[m + i];

        L[n1] = SENTINEL;
        R[n2] = SENTINEL;

        int i = 0, j = 0;

        for (int k = l; k < r; k++) {
            count++;
            if (L[i] <= R[j]) A[k] = L[i++];
            else A[k] = R[j++];
        }
    }

    static void mergeSort(int l, int r){
        if (l + 1 < r){
            int m = (l+r)/2;
            mergeSort(l,m);
            mergeSort(m,r);
            merge(l,m,r);
        }
    }


    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());

        A = new int[n];

        String[] nums = br.readLine().trim().split("\\s+");
        for (int i = 0; i < n; i++)
            A[i] = Integer.parseInt(nums[i]);

        mergeSort(0,n);

        StringBuilder s = new StringBuilder().append(A[0]);
        for (int i = 1; i < n; i++)
            s.append(" ").append(A[i]);

        System.out.println(s);
        System.out.println(count);
    }
}



Measured memory_bytes: 162708
def f
  n = gets.chomp.to_i
  a = gets.chomp.split.map(&:to_i)
  bubblesort(a, n)
end

def bubblesort(a, n)
  flag = 1
  exchange_counts = 0
  while flag == 1
    flag = 0
    for i in 1..n-1
      j = n-i
      if a[j] < a[j-1]
        a[j-1], a[j] = a[j], a[j-1]
        flag = 1
        exchange_counts += 1
      end
    end
  end
  puts a.join(" ")
  puts exchange_counts
end

f


Measured memory_bytes: 6876
class Union_find():

    def __init__(self, num):
        self.num = num
        self.par = list(range(num))
        self.rank = [0]*num

    def find(self, x):
        px = self.par[x]
        if px == x:
            return x
        else:
            rx = self.find(px)
            self.par[x] = rx
            return rx

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] > self.rank[y]:
                self.par[y] = x
            else:
                self.par[x] = y
                if self.rank[x] == self.rank[y]:
                    self.rank[y] = self.rank[y] + 1
        return self

    def same(self, x, y):
        return self.find(x) == self.find(y)

class Group_map():
    #dx, dyは原点対象となる要素を省く
    def __init__(self, H, W, dx, dy, Mat):
        self.H = H
        self.W = W
        self.dx = dx
        self.dy = dy
        self.Mat = Mat
        self.group = Union_find(H*W)

    def to_num(self, i, j):
        return i*(self.W) + j

    def grouping(self):
        for i in range(self.H):
            for j in range(self.W):
                for k in range(len(self.dx)):
                    (ni, nj) = (i + self.dx[k], j + self.dy[k])
                    if ni in range(self.H) and nj in range(self.W) and self.Mat[i][j] == self.Mat[ni][nj]:
                        self.group.union(self.to_num(i, j), self.to_num(ni, nj))
        return self

    def num_group(self, k):
        self.grouping()
        l = set()
        for i in range(self.H):
            for j in range(self.W):
                if self.Mat[i][j] == k:
                    l.add(self.group.find(self.to_num(i, j)))
        return len(l)

    def same(self, x, y):
        return self.group.same(self.to_num(x[0], x[1]), self.to_num(y[0], y[1]))

(w, h) = map(int, input().split(" "))
while w != 0 and h != 0:
    Map = []
    for i in range(h):
        Map.append(list(map(int, input().split(" "))))
    g = Group_map(h, w, [1, 1, 1, 0], [-1, 0, 1, 1], Map)
    print(g.num_group(1))
    (w, h) = map(int, input().split(" "))
    


Measured memory_bytes: 5848