akhauriyash/Code-Regression huggingface dataset:
#include<iomanip>
#include<vector>
#include<iostream>
#include<cmath>
using namespace std;

//vector<vector<int>> perm(vector<int> head, vector<int> rest);
double sq(double x);

int main(){
    long long N;
    double X, Y, d;
    double pair_ = 1.0;
    double d_total = 0.0;
    double ans;
    std::cin >> N;
    vector<vector<double>> matchi_list(N);

    for(long long i = 0; i < N; i++){
        std::cin >> X >>Y;
        matchi_list[i] = {X, Y}; 
    }

    for(long long i = 0; i < N; i++ ){
        for(long long j = i + 1; j < N; j ++){
            d = sqrtf(sq(matchi_list[i][0] - matchi_list[j][0]) + sq(matchi_list[i][1] - matchi_list[j][1]));
            d_total = d_total + d;
        }
    }

    ans = d_total * 2.0 / (double)N;
    // vector<int> v_in = {1,2,3,4,5,6,7,8,};
    // vector<vector<int>> v_out = perm({}, v_in);

    // for(int i = 0; i < v_out.size(); i++){
    //     for(int j = 0; j < v_out[0].size(); j++){
    //         std::cout << v_out[i][j] << " ";
    //     }
    //     std::cout << "\n";
    // }

    std::cout << setprecision(16) << ans;

}

// vector<vector<int>> perm(vector<int> head, vector<int> rest){
//     vector<vector<int>> v_out;
//     vector<vector<int>> v_temp;
//     int count = 0;
//     if(rest.size() == 0){
//         v_out.push_back(head);
//     }
//     vector<int> restx;
//     vector<int> headx;
//     std::vector<int>::iterator iter;
//     for(int i = 0; i < rest.size(); i++){
    
//         restx = rest;
//         headx = head;
//         iter = restx.begin();
//         for(int j = 0; j < count; j ++){
//             iter++;
//         }
//         headx.push_back(*iter);
//         restx.erase(iter);
//         restx.shrink_to_fit();
//         v_temp = perm(headx, restx);
//         v_out.insert(v_out.begin(), v_temp.begin(), v_temp.end()) ;
//         count++;
 
//         restx.clear();
//         headx.clear();

//     }

//     return v_out;
// }

double sq(double x){
     double ans;
     ans = x * x;
     return ans;
}

Measured memory_bytes: 3848
a, b, c = map(int, input().split())

max_ = max(a, b, c)
ans = 0
ans += (max_ - a) // 2
a += ((max_ - a) // 2) * 2

ans += (max_ - b) // 2
b += ((max_ - b) // 2) * 2

ans += (max_ - c) // 2
c += ((max_ - c) // 2) * 2

if [a, b, c].count(max(a, b, c)) == 3:
    print(ans)
elif [a, b, c].count(max(a, b, c)) == 2:
    print(ans + 2)
elif [a, b, c].count(max(a, b, c)) == 1:
    print(ans + 1)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }



int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
  
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for(int i = 0; i < n; i++)v[i] = i;
	for(int i = 0; i < (1 << n); i++){
		vector<int> now;
		for(int j = 0; j < n; j++){
			if(i & (1 << j))now.push_back(v[j]);
		}
		if((int)now.size() == k){
			cout << i << ':';
			for(auto j:now)cout << ' ' << j;
			cout << '\n';
		}
	}
	return 0;
}



Measured memory_bytes: 3160
let () =
  let a,b,c,d= Scanf.scanf "%d %d %d %d " (fun a b c d -> a,b,c,d) in
  Printf.printf "%s\n" 
    (if a+b>c+d then 
       "Left"
     else (
       if a+b=c+d then
         "Balanced"
       else
         "Right"
     )
    );


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int[] sum = new int[1000];
		sum[0] = 0;
		for(int i = 1; i < 1000; i++) {
			sum[i] = sum[i - 1] + i;
		}
		int ans = sum[b - a] - b;
		System.out.println(ans);
	}

}


Measured memory_bytes: 24020
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return true;}return false;}

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN3(n,a,b);
  if(a%2==b%2) OUT((b-a)/2);
  else OUT(min(a-1,n-b)+1+(b-a-1)/2);
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

struct Process{
	string name;
	int time;
	
	Process(string name = "", int time = 0) : name(name), time(time) {}
};

int main(){
	
	long long passtime = 0;
	int n, q;
	string s;
	int t;
	queue<Process> que;
	
	cin >> n >> q;
	
	for(int i = 0; i < n; i++){
		cin >> s;
		cin >> t;
		que.push(Process(s, t));
	}
	
	while(!que.empty()){
		Process np = que.front();
		que.pop();
		if(np.time <= q){
			passtime += np.time;
			cout << np.name << " " << passtime << endl;
		}
		else{
			passtime += q;
			np.time -= q;
			que.push(np);
		}
	}
	
	return 0;
}



Measured memory_bytes: 6328
n,m = map(int,input().split())
li1 = [0 for _ in range(n)]
li2 = [0 for _ in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    a-=1
    b-=1
    if a==0:
        li1[b] = 1
    elif b==n-1:
        li2[a] = 1

ans = False
for i in range(1,n-1):
    if li1[i] and li2[i]:
        ans = True
        break

if ans:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 6320
inf = float('inf')

N, M = map(int,input().split())
A = []
C = []
for _ in range(M):
    a, b = map(int,input().split())
    A.append(a)
    c = list(map(int,input().split()))
    flag = 0
    for ci in c:
        flag |= 1 << (ci-1)
    C.append(flag)

dp = [[inf] * (1 << N) for _ in range(M+1)]
dp[0][0] = 0

for i in range(M):
    for S in range(1 << N):
        dp[i+1][S | C[i]] = min(dp[i+1][S | C[i]], dp[i][S] + A[i])
        dp[i+1][S] = min(dp[i+1][S], dp[i][S])

ans = dp[M][(1 << N) - 1]
if ans == inf:
    ans = -1
print(ans)

Measured memory_bytes: 138456
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m; cin >> n >> m;
  long ans = 0L;
  vector<pair<long, long>> drink;
  for(int i = 0; i < n; i++){
    long a;int b;
    cin >> a >> b;
    drink.push_back(make_pair(a,b));
  }
  sort(drink.begin(), drink.end());
  for(int i = 0; i < n; i++){
    if(m <= drink.at(i).second){
      ans += drink.at(i).first * m;
      break;
    }
    else{
      ans += drink.at(i).first * drink.at(i).second;
      m -= drink.at(i).second;
    }
  }
  cout << ans;
}

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

int main() {
	// your code goes here
	int n, k;
	cin >> n >> k;
	int h[n];
	int ans = 0;
	for(int i=0; i<n; i++)
	{
		cin >> h[i];
		if(h[i] >= k){ans++;}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>

inline int Min(const int a,const int b){return a<b?a:b;}
inline int Max(const int a,const int b){return a>b?a:b;}

int X,k,q,r[100005],t[100005],a[100005],Ans;

int main()
{
    scanf("%d%d",&X,&k);
    for(int i=1;i<=k;++i)scanf("%d",&r[i]);
    scanf("%d",&q);
    for(int i=1;i<=q;++i)scanf("%d%d",&t[i],&a[i]);
    int Minn=0,Maxn=X,t1=0,t2=1,f=-1,Now=0,p=0;
    while(t2<=q)
        if(t[t2]>r[t1+1]&&t1<k)
        {
            ++t1,Now=f*(r[t1]-r[t1-1]);
            Minn=Max(0,Min(X,Minn+Now));
            Maxn=Max(0,Min(X,Maxn+Now));
            p+=Now,f*=-1;
        }
        else
        {
            Ans=Max(Minn,Min(Maxn,a[t2]+p));
            Ans=Max(0,Min(X,Ans+f*(t[t2]-r[t1])));
            printf("%d\n",Ans),++t2;
        }
    return 0;
}


Measured memory_bytes: 2304
N = int(input())
T, A = list(map(int,input().split()))
hlist1 = list(map(int,input().split()))
kion_min = 10000000
titen = -10

for i in range(N):
  kion1 = abs(T-0.006*hlist1[i]-A)
  if kion1 < kion_min:
    kion_min = kion1
    titen = i+1

print(titen)

Measured memory_bytes: 38384
#include<iostream>
#include<cstring>

using namespace std;

int main(){
	int n;
	char alphabet[27];
	int alphabetnum[26];
	char buff[51];
	strncpy(alphabet, "abcdefghijklmnopqrstuvwxyz", 27);
	for(int i = 0; i < 26; i++){
		alphabetnum[i] = 100;
	}
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> buff;
		int buffnum[26] = {0};
		for(int j = 0; j < 50; j++){
			if(buff[j] == '\0'){
				break;
			}
			for(int k = 0; k < 26; k++){
				if(buff[j] == alphabet[k]){
					buffnum[k]++;
					break;
				}
			}
		}
		for(int j = 0; j < 26; j++){
			if(buffnum[j] < alphabetnum[j]){
				alphabetnum[j] = buffnum[j];
			}
		}
	}
	for(int i = 0; i < 26; i++){
		for(int j = 0; j < alphabetnum[i]; j++){
			cout << alphabet[i];
		}
	}
	cout << endl;
	return 0;
}

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

int main() {
  int n; cin >> n;
  auto f = [](int x) {
    int res = 0;
    while (x) {
      res += x % 10;
      x /= 10;
    }
    return res;
  };
  cout << (n % f(n) == 0 ? "Yes" : "No") << endl;
}

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

const long mod = 1000000007;
const long inv2 = 500000004;
int n;
vector<int> g[200000];
long sz[200000];

int rec(int from, int prev) {
  int sum = 1;
  for (int to : g[from]) {
    if (to == prev) continue;
    sum += rec(to, from);
  }
  sz[from] = sum;
  return sum;
}

long p[200001];
int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  p[0] = 1;
  for (int i = 0; i < n; ++i) {
    p[i + 1] = p[i] * inv2 % mod;
  }
  
  rec(0, -1);
  long sum = 0;
  for (int i = 1; i < n; ++i) {
    long a = (1 + mod - p[sz[i]]) % mod * (1 + mod - p[n - sz[i]]) % mod;
    sum = (sum + a) % mod;
  }
  sum = (sum + mod - n * inv2 % mod) % mod;
  sum = (sum + mod - p[n] + 1) % mod;
  cout << sum << endl;
}

Measured memory_bytes: 23168
import java.util.Scanner;
 
public class Main {
 public static void main (String[ ] args) {
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  String s = sc.next();
  char[] ch = s.toCharArray();
  int x = 0;
 
  int m = 0;
  for (int i = 0; i < n; i++) {
   if (ch[i] == 'I') {
    x++;
    m = Math.max(m, x);
   } else if (ch[i] == 'D') {
    x--;
   }
 }
 
 
  System.out.println(m);
 
 }
}

Measured memory_bytes: 9808
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (int i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (int i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int X;
    cin >> X;
    X -= 400;
    cout << max(1, 8 - X / 200) << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    string s;
    cin >> s;
    string t = s.substr(5, 2);
    if(t == "01" || t == "02" || t == "03" || t == "04")
        cout << "Heisei" << endl;
    else
        cout << "TBD";
    return 0;
}

Measured memory_bytes: 256
k=input()

list_a=k.split()

n=list_a[0]

m=list_a[1]

t=input()

list_b=t.split()

h=len(list_b)

list_s=[int(s) for s in list_b]

if int(m)==int(h) and sum(list_s) <= int(n):
  print(int(n)-sum(list_s))
elif int(m)==int(h) and sum(list_s) > int(n):
  print("-1")


Measured memory_bytes: 9836
from collections import deque
n, m = map(int, input().split())
connect = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    connect[a].append(b)
    connect[b].append(a)
 
color = [-1]*n
color[0] = 0
explored = {0}
next = deque([0])
exploring =deque()
Yes = True
 
while next:
    now = next.popleft()
    exploring.extend(connect[now])
    while exploring:
        a = exploring.popleft()
        if color[a] == -1:
            color[a]=(color[now]+1)%2
        elif color[a] == (color[now]+1)%2:
            pass
        else:
            Yes = False
        if a not in explored:
            next.append(a)
        explored.add(a)
 
 
 
if Yes:
    s=sum(color)
    print(s*(n-s)-m)
else:
    print(n*(n-1)//2-m)

Measured memory_bytes: 32852
#include<bits/stdc++.h>
using namespace std;
int n,a,c;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){scanf("%d",&a);if(a&1)c^=1;}
	if(c==1)puts("NO");else puts("YES");
	return 0;
}

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);

using namespace std;
ll mod = 1e9 + 7;



ll fact[1000001]; ll inv[1000001];
ll primes[100007];
ll arr[1000007];
ll modPower(ll b, ll p) {
	if (p == 0)
		return 1;

	ll halfpow = modPower(b, p / 2);
	ll toReturn = (halfpow * halfpow) % mod;
	if (p % 2)
		toReturn = (toReturn * b) % mod;

	return toReturn;
}

ll fastPower(ll b, ll p) {
	if (p == 0)
		return 1;
	ll ans = fastPower(b, p / 2);
	ans = (ans * ans);
	if (p % 2 != 0)
		ans = (ans * b);
	return ans;
}
ll GcdRecursive(ll a, ll b) {
	if (b == 0) return a;
	return GcdRecursive(b, a % b);
}
ll modLCM(ll a, ll b) {
	ll val = GcdRecursive(a, b);
	ll tmp = ((a % mod) * (b % mod)) % mod;
	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
	return finalVal;

}
ll LCM(ll a, ll b) {
	return (a * b) / GcdRecursive(a, b);
}
void move1step(ll& a, ll& b, ll q) { // a and b by reference
	ll c = a - q * b;
	a = b;
	b = c;
}
ll GcdIterative(ll a, ll b) {
	while (b) move1step(a, b, a / b);
	return a;
}

void pre(ll n) {

	fact[0] = 1;
	inv[0] = 1;

	for (ll i = 1; i <= n; i++) {
		fact[i] = (i * fact[i - 1]) % mod;
		inv[i] = modPower(fact[i], mod - 2);
		arr[i] = modPower(i, mod - 2);
	}
}

ll npr(ll n, ll r) {
	return ((fact[n] * inv[n - r]) % mod);
}

ll ncr(ll n, ll r) {
	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
}

void sieve(ll val) {
	memset(primes, 1, sizeof primes);
	primes[0] = primes[1] = false;
	for (int i = 2; i <= val; i++) {
		if (primes[i]) {
			for (int j = i * i; j <= val; j += i) {
				primes[j] = 0;
			}
		}
	}

}




int main()
{
	MohamedMotaz;
	pre(10000);
	ll x, y; cin >> x >> y;
	ll ans = 0;
	ans += (x - 1) * x * 0.5;
	ans += (y - 1) * y * 0.5;
	cout << ans;
}





















Measured memory_bytes: 4480
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val (n, d) = (0 until 2).map { sc.nextInt() }
    val check = d * 2 + 1
    var res1 = n / check
    if (n % check > 0) {
        res1++
    }
    println(res1)
}

Measured memory_bytes: 31396
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int x = Integer.parseInt(line[0]);
        int y = Integer.parseInt(line[1]);

        do{
            if(x > y){
                int tmp = x;
                x = y;
                y = tmp % y;
            }else if(x < y){
                int tmp = y;
                y = x;
                x = tmp;
            }else{
                break;
            }
        }while(x % y != 0);

        System.out.println(y);
    }
}

Measured memory_bytes: 24316
w = gets.chomp
i = 0
loop do
    x = gets.chomp.split
    if x[0] == "END_OF_TEXT"
        break
    end
    x.each do |j|
        k = j.downcase
        if k == w
            i += 1
        end
    #y = x.downcase.scan(/\A#{w}\Z/).size
    end
#    y = x.downcase.scan(/\A#{w}\Z/).size
    #i += y
end
puts "#{i}"

Measured memory_bytes: 8652
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl


signed main(void){
    int N,K;
    int A[114514];
    cin >> N >> K;
    REP(i,N){
        cin >> A[i];
    }
    int Ans=0;
    
    for(int j=40;j>=-1;j--){
        if(j!=-1&& !(K&(1LL<<j)))continue;
        int num=0;
        
        for(int i=40;i>=0;i--){
            
            int R=1LL<<i;
            int calc=0;
            REP(k,N){if(A[k]&R)calc++;}
            
            if(i<j){
                num+=R*max(calc,N-calc);
            }
            
            if(i==j){
                num+=R*calc;
            }
            
            if(i>j){
                if(K&R){
                    num+=R*(N-calc);
                }else{
                    num+=R*calc;
                }
            }
            
        }
        Ans=max(Ans,num);
        //cout << j <<" "<< num << endl;
    }
    cout << Ans << endl;
    return 0;
}



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

int n, a[300010];
long long sl[300010], sr[300010];

int main() {
	cin >> n;
	for (int i = 1; i <= 3 * n; i++)cin >> a[i];

	priority_queue<int, vector<int>, greater<int>>q;
	long long s = 0;
	for (int i = 1; i <= 2 * n; i++) {
		q.push(a[i]);
		s += a[i];
		if (q.size() > n) {
			s -= q.top(); q.pop();
		}
		sl[i] = s;
	}

	priority_queue<int>que;
	s = 0;
	for (int i = 3 * n; i >= n; i--) {
		que.push(a[i]);
		s += a[i];
		if (que.size() > n){
			s -= que.top(); que.pop();
		}
		sr[i] = s;
	}

	long long res = -1e15;
	for (int i = n; i <= 2 * n; i++)res = max(res, sl[i] - sr[i + 1]);
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 5624
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var array = cin.ReadIntArray(N);
            int resultInt = 0;
            int beforeInt = 0;
            int baseIndex = 0;

            Array.Sort(array);
            do
            {
                for (int i = 0; i < N; i++)
                {
                    if (baseIndex == i) { continue; }
                    beforeInt = array[baseIndex] - array[i];
                    beforeInt = Math.Abs(beforeInt);
                    if (resultInt == 0 || beforeInt > resultInt)
                    {
                        resultInt = beforeInt;
                    }
                }
                baseIndex++;
            }
            while (baseIndex < N);
            Console.WriteLine(resultInt);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
typedef vector<int>V;
int main(void){
	int n;
	int box[100000];
	int i;
	int MAX;
	int sum;
	V v;
	cin>>n;
	MAX=-1;
	for(i=0;i<n;i++){
		cin>>box[i];
		MAX=max(MAX,box[i]);
	}
	for(i=1;i<=MAX;i++){
		if(MAX%i==0){
			v.push_back(i);
		}
	}
	sort(v.begin(),v.end());
	// for(auto it:v){
		// cout<<it<<endl;
	// }
	sum=0;
	for(i=0;i<n;i++){
		auto it1=lower_bound(v.begin(),v.end(),box[i]);
		//auto it2=upper_bound(v.begin(),v.end(),box[i]);
		//cout<<*it1<<endl;
		// cout<<*it2<<endl;
		sum+=*it1-box[i];
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3536
S = input()
K = int(input())

a = S[0]
c = 0
g = []

for i in range(len(S)):
    if a == S[i]:
        c += 1
    else:
        g.append(c)
        a = S[i]
        c = 1

g.append(c)

if len(g) == 1:
    c = len(S) * K / 2
elif S[0] == S[-1]:
    c = int(g[0] / 2)
    c += int(g[-1] / 2)
    c += int((g[0]+g[-1]) / 2) * (K-1)

    for i in range(1, len(g) - 1):
        c += int(g[i] / 2) * K
else:
    c = 0
    for i in g:
        c += int(i / 2) * K


print(int(c))



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll A,B,C,K;
    cin >> A >> B >> C >> K;

    ll result = 0;
    if(A <= K){
        result += A;
    }
    else{
        result += K;
        cout << result;
        return 0;
    }
    K -= A;
    K -= B;

    // cout << K;

    if(K <= 0){
        cout << result;
        return 0;
    }
    else{
        // cout << K;
        result -= K;
        cout << result;
        return 0;
    }

}

Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

int const TREE_SIZE = 1 << 25;
int const INT_MAX = 1 << 29;
long long int seg_tree[TREE_SIZE];

void add(int a, long long int w){
	
	// a?????????????´????w??¨?????? O(log N)
	
	a += TREE_SIZE / 2;
	
	seg_tree[a] = w;
	
	for(int x = a / 2; x > 0; x /= 2){
		seg_tree[x] = max(seg_tree[2 * x], seg_tree[2 * x + 1]);
	}
}

long long int max_query(int a, int b, int index, int l, int r){
	
	// ?????? [a, b) ???????´?????????§???????????? O(log N)
	// ???????????? max_query(a, b, 1, 0, TREE_SIZE / 2) ?????????????????¶
	
	if(r <= a || b <= l){
		return -100000000000000000;
	}
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	
	return max(max_query(a, b, index * 2, l, (l + r) / 2), max_query(a, b, index * 2 + 1, (l + r) / 2, r));
}

typedef pair<long long int, long long int> P;

vector<P> v1, v2;

int main(){
	
	int N;
	long long int D;
	
	cin >> N >> D;
	
	int middle = N / 2;
	
	P p_zero;
	p_zero.first = 0;
	p_zero.second = 0;
	
	v1.push_back(p_zero);
	v2.push_back(p_zero);
	
	for(int i = 0; i < middle; i++){
		long long int num1, num2;
		cin >> num1 >> num2;
		int v_size = v1.size();
		for(int j = 0; j < v_size; j++){
			P p = v1[j];
			p.first += num1;
			p.second += num2;
			v1.push_back(p);
			p.first -= num1 * 2;
			p.second -= num2 * 2;
			v1.push_back(p);
		}
	}
	
	for(int i = middle; i < N; i++){
		long long int num1, num2;
		cin >> num1 >> num2;
		int v_size = v2.size();
		for(int j = 0; j < v_size; j++){
			P p = v2[j];
			p.first += num1;
			p.second += num2;
			v2.push_back(p);
			p.first -= num1 * 2;
			p.second -= num2 * 2;
			v2.push_back(p);
		}
	}
	
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	
	long long int ans = 0;
	
	for(int i = 0; i < TREE_SIZE; i++){
		seg_tree[i] = -100000000000000000;
	}
	
	for(int i = 0; i < v2.size(); i++){
		add(i + 1, v2[i].second);
	}
	/*
	for(int i = 0; i < v1.size(); i++){
		cout << v1[i].first << " ";
	}
	cout << endl;
	for(int i = 0; i < v2.size(); i++){
		cout << v2[i].first << " ";
	}
	cout << endl;
	*/
	
	int index_start = 0;
	int index_end = 0;
	
	for(int i = 0; i < v1.size(); i++){
		for(index_end ; index_end < v2.size(); index_end++){
			if(v2[index_end].first > v1[i].first + D){
				break;
			}
		}
		for(index_start; index_start < v2.size(); index_start++){
			if(v2[index_start].first >= v1[i].first - D){
				break;
			}
		}
		//cout << index_start << " " << index_end << endl;
		long long int ref = max_query(index_start + 1, index_end + 1, 1, 0, TREE_SIZE / 2);
		/*
		if(index_start != index_end){
			cout << index_start << " " << ref - v1[i].second << endl;
		}
		*/
		//cout << ref << endl;
		if(ans < ref - v1[i].second){
			//cout << index_start << " " << index_end << endl;
			ans = ref - v1[i].second;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 713340
#include <iostream>
#include <queue>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    priority_queue<pair<int, int>> q;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        q.push({a[i], i});
    }
    for (int i = 0; i < m; i++) {
        auto x = q.top();
        q.pop();
        a[x.second] /= 2;
        q.push({x.first / 2, x.second});
    }
    int64_t ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1784
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;
int n,a[105],b[3],cnt;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
				{
					b[0]=a[i];b[1]=a[j];b[2]=a[k];
					sort(b,b+3);
					if(b[0]+b[1]>b[2])cnt++;
				}
			}
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner s = new Scanner(System.in);
        String str = s.next();
        if( Character.isUpperCase( str.charAt( 0 ) ) ) {
    System.out.println( "A" );
}
else {
    System.out.println( "a" );
}
       // System.out.println("XXXXXXXX");
    }
}


Measured memory_bytes: 35624
#include <iostream>
#include <cstring>

using namespace std;

char s[101];
int c, f;
int main()
{
    cin>>s;
    for(int i=0;i<strlen(s);i++){
        if(s[i]=='C') c=i+1;
        else if(s[i]=='F' && c) f=i+1;
    }
    if(c&&f)
        cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
marks = {i+1:-1 for i in range(n)}
roots = {i+1:[] for i in range(n)}

for i in range(m):
    a,b = map(int,input().split())
    roots[a].append(b)
    roots[b].append(a)

searchs = [{'root':roots[1], 'mark':1}]
while searchs != []:
    next_search = []
    for search in searchs:
        for root in search['root']:
            if marks[root] == -1:
                marks[root] = search['mark']
            else:
                continue
            next_search.append({'root':roots[root], 'mark':root})
    searchs = next_search[:]

marks[1] = 'Yes'
for v in marks.values():
    print(v)
    

Measured memory_bytes: 130896
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp34 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            if (N <= 999) {
                //if (N <= 9) {
                //    Console.WriteLine("ABC" + "00" + N);
                //} else if (N <= 99) {
                //    Console.WriteLine("ABC" + "0" + N);
                //} else {
                //    Console.WriteLine("ABC" + "" + N);
                //}
                Console.WriteLine("ABC");
            } else {
                //if (N - 999 <= 9) {
                //    Console.WriteLine("ABD" + "00" + (N - 999));
                //} else if (N - 999 <= 99) {
                //    Console.WriteLine("ABD" + "0" + (N - 999));
                //} else {
                //    Console.WriteLine("ABD" + "" + (N - 999));
                //}
                Console.WriteLine("ABD");
            }

        }

    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

int main() {
  std::vector<int> heights;
  for (auto i =0; i < 10; i++) {
    int h;
    std::cin >> h;
    heights.push_back(h);
  }
  std::sort(heights.begin(), heights.end(), std::greater<int>());
  for (auto i =0; i < 3; i++) {
    std::cout << heights[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 3088
import sys
readline = sys.stdin.buffer.readline

n = int(readline())

alphabets = [chr(ord('a') + x) for x in range(26)]

def dfs(s,i):
    if len(s)==n:
        print("".join(s))
    else:
        t = min(len(set(s))+1,len(s)+1)
        for i in range(t):
            dfs(s+[alphabets[i]],i)

dfs([],0)

Measured memory_bytes: 4340
#include<stdio.h>
int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a+b==c||a+c==b||b+c==a){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
import sys
readline = sys.stdin.buffer.readline

if __name__ == "__main__":
    A = [[0] * 3 for _ in range(3)]
    for i in range(3):
        tmp = list(map(int, input().split()))
        for j in range(3):
            A[i][j] = tmp[j]
    
    N = int(input())
    b = [0] * N
    for i in range(N):
        b[i] = int(input())

    check = [[0]*3 for _ in range(3)]
    for v in b:
        for i in range(3):
            for j in range(3):
                if A[i][j] == v:
                    check[i][j] = 1
    ok = False
    for i in range(3):
        cnt = 0
        for j in range(3):
            if check[i][j] == 1:
                cnt += 1
        if cnt == 3:
            ok = True

    for j in range(3):
        cnt = 0
        for i in range(3):
            if check[i][j] == 1:
                cnt += 1
        if cnt == 3:
            ok = True
    
    cnt = 0
    for i in range(3):
        if check[i][i] == 1:
            cnt += 1;
    if cnt == 3:
        ok = True
    
    cnt = 0
    for i in range(3):
        if check[i][2-i] == 1:
            cnt += 1;
    if cnt == 3:
        ok = True
    
    if ok == True:
        print("Yes")
    else:
        print("No")


    




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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

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

class Graph{
    public:
    using PL = pair<ll, ll>;
    const ll INF = 1e15;

    ll size;
    // has dist, to
    vector<vector<PL> > g;
    vector<ll> dist;

    Graph(ll n){
        size = n;
        g = vector<vector<PL> >(size);
        dist = vector<ll>(size);
    }

    void add_edge(ll x, ll y, ll w){
        g[x].push_back(make_pair(w, y));
    }

    void dijkstra(ll s){
        priority_queue<PL, vector<PL>, greater<PL> > PQ;
        fill(dist.begin(), dist.end(), INF);
        dist[s] = 0;
        PQ.push(make_pair(0, s));

        while(!PQ.empty()){
            PL p = PQ.top(); PQ.pop();
            ll v = p.second;
            if(dist[v] < p.first) continue;
            for(PL np: g[v]){
                ll d = np.first;
                ll u = np.second;
                if(dist[u] > dist[v] + d){
                    dist[u] = dist[v] + d;
                    PQ.push(make_pair(dist[u], u));
                }
            }
        }
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n, m, s, t; cin >> n >> m >> s >> t;
    Graph ga(n);
    Graph gb(n);
    for(int i=0;i<m;i++){
        ll u, v, a, b; cin >> u >> v >> a >> b;
        ga.add_edge(u - 1, v - 1, a);
        ga.add_edge(v - 1, u - 1, a);
        gb.add_edge(u - 1, v - 1, b);
        gb.add_edge(v - 1, u - 1, b);
    }
    ga.dijkstra(s - 1);
    gb.dijkstra(t - 1);

    vector<ll> cost;

    for(int i=0;i<n;i++){
        cost.push_back(ga.dist[i] + gb.dist[i]);
    }

    vector<ll> ans;
    ll cash = 1e15;
    ll cmin = 1e16;

    reverse(cost.begin(), cost.end());

    for(int i=0;i<n;i++){
        cmin = min(cmin, cost[i]);
        ans.push_back(cash - cmin);
    }

    reverse(ans.begin(), ans.end());

    for(ll a: ans) cout << a << endl;
}

Measured memory_bytes: 20732
import sys
sys.stdin.readline

N, K = [int(x) for x in input().split()]
arr = [0] * (10**5+1)
for _ in range(N):
    a, b = [int(x) for x in input().split()]
    arr[a] += b

remain = K
for i in range(1, 10**5+1):
    if arr[i] != 0:
        remain -= arr[i]
    if remain <= 0:
        print(i)
        exit()

Measured memory_bytes: 5848
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

class BProblemSet {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll n;
	    in>>n;
	    map<ll,ll> d;
	    rep(i,n){
	        ll tmp;
	        in>>tmp;
	        d[tmp]++;

	    }
	    ll m;
	    in>>m;
	    map<ll,ll> t;
	    rep(i,m){
	        ll tmp;
	        in>>tmp;
	        t[tmp]++;
	    }
        bool ans=true;
	    for(const auto &i: t){

	        if(i.second>d[i.first]) ans=false;
	    }
	    if(ans) out<<"YES"<<endl;
	    else out<<"NO"<<endl;


	}
};


int main() {
	BProblemSet solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  vc a(4);
  rep(i, 4) cin >> a[i];
  vl b(4);
  rep(i, 4) b[i] = a[i] - '0';
  rep(i, 1 << 3) {
    vl op(3, -1);
    rep(j, 3) if(i >> j & 1) op[j] = 1;
    ll sum = b[0];
    rep(j, 3) sum += b[j + 1] * op[j];
    if(sum != 7) continue;
    cout << b[0];
    rep(j, 3) cout << (op[j] == 1 ? '+' : '-') << b[j + 1];
    cout << "=7" << endl;
    return 0;
  }
}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    cin >> n;

    int m = n / 2;
    if (m + m == n) m--;
    cout << m << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int a, b, h; cin>>a>>b>>h;
    int ans = (h/2)*(a+b);
    cout<<ans;
    return 0;
}






Measured memory_bytes: 256
mod = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())

def inv(x):
  m = mod
  u = 1
  v = 0
  while(m):
    t = x // m
    x -= t * m
    x, m = m, x
    u -= t * v
    u, v = v, u
  u %= mod
  if u < 0:
    u += mod
  return u

fac = [1]
for i in range(1, r2 + c2 + 3):
  fac.append(fac[i - 1] * i % mod)

def paths(r, c):
  return fac[r + c + 2] * inv(fac[r + 1] * fac[c + 1]) % mod

f = paths(r2, c2) - paths(r2, c1 - 1) - paths(r1 - 1, c2) + paths(r1 - 1, c1 - 1)
f %= mod
if f < 0:
   f += mod
print(f)

Measured memory_bytes: 82220
#include <stdio.h>

int search(int A[], int n, int key) {
	int i = 0;
	A[n] = key;
	while (A[i] != key) i++;
	return i != n;
}


int main()
{
	int n, i, A[100001], q, key, sum=0;
	scanf("%d", &n);

	for (i = 0; i < n; i++) scanf("%d", &A[i]);

	scanf("%d", &q);
	for (i = 0; i < q; i++){
		scanf("%d", &key);
		if (search(A, n, key)) sum++;
	}
	printf("%d\n", sum);

	return 0;
}

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

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

int main() {
    cin >> n;

    for (int i = 0 ; i < n ; ++i) {
        cin >> s;
        if (s == "AC")  a++;
        if (s == "WA")  b++;
        if (s == "TLE") c++; 
        if (s == "RE")  d++;
    }

    cout << "AC"  << " x " << a << endl; 
    cout << "WA"  << " x " << b << endl; 
    cout << "TLE" << " x " << c << endl;
    cout << "RE"  << " x " << d << endl;
    return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;

int n;
int p[20];

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

	int ans = 0;
	for (int i = 1; i < n-1; i++)
		if ((p[i - 1] < p[i] and p[i] < p[i + 1]) or (p[i - 1] > p[i] and p[i] > p[i + 1]))
			ans++;

	cout << ans << endl;
	return 0;
}


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

int main(){
	string S;
	int K, i;
	cin >> K >> S;
	
	if(K<S.size()){
		for(i=0; i<K; i++){
			cout << S[i];
		}cout << "..." << endl;
	}
	else	cout << S;
	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	int p = arr[0];
	int c = 1;
	for(int i=1;i<n;i++)
	{
		if(arr[i] >= p)
		{
			c++;
			p = arr[i];
		}
	}
	cout<<c<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>

using namespace std;

int main()
{
	int A, B;
	cin >> A; cin >> B;
	int ans = A + B;

	if (ans < A - B)
		ans = A - B;

	if (ans < A*B)
		ans = A*B;

	cout << ans << endl;
	return 0;
}

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

using namespace std;

const int N = 200000 + 77;
int n , a[N] , T[N] , Fen[N];
long long Suff[N] , Pref[N] , A = 1e18;
bool WTF;
vector < int > V;
inline bool Greater(int x , int tx , int y , int ty){
   int Mn = min(tx , ty);
   tx -= Mn , ty -= Mn;
   if(tx > ty + 31)
      return 1;
   if(tx + 31 < ty)
      return 0;
   return x * 1ll * (1ll << tx) > y * 1ll * (1ll << ty);
}
inline int Add(int x , int y){
   for(;x < N;x += x & - x)
      Fen[x] += y;
}
inline int AddRange(int le , int ri){
   Add(le , 1);
   Add(ri + 1 , - 1);
}
inline int Get(int x){
   int res = 0;
   for(;x;x -= x & - x)
      res += Fen[x];
   return res;
}
inline void Do(int id){
   int x = V.back();
   V.pop_back();
   if(WTF)
      AddRange(x , id - 1) , AddRange(x , id - 1);
   else
      AddRange(id + 1 , x) , AddRange(id + 1 , x);
   if(WTF)
      Pref[id] += id - x + id - x;
   else
      Suff[id] += x - id + x - id;
   if(WTF == 0){
      while(! V.empty()){
         if(Greater(a[x] , Get(x) + 2 , a[x + 1] , Get(x + 1)))
            x = V.back() , V.pop_back();
         else {
            break ;
         }
      }
      V.push_back(x);
      return ;
   }
   while(! V.empty()){
      if(Greater(a[x] , Get(x) + 2 , a[x - 1] , Get(x - 1)))
         x = V.back() , V.pop_back();
      else {
         break ;
      }
   }
   V.push_back(x);
}
int main(){
   ios::sync_with_stdio(0);cin.tie(0);
   cin >> n;
   for(int i = 1;i <= n;++ i)
      cin >> a[i];
   V.push_back(n);
   for(int i = n - 1;i > 0;-- i){
      Suff[i] = Suff[i + 1];
      while(Greater(a[i] , 0 , a[i + 1] , Get(i + 1)))
         Do(i);
      if(Greater(a[i + 1] , Get(i + 1) , a[i] , 2))
         V.push_back(i);
   }
   V.clear();
   memset(Fen , 0 , sizeof(Fen));
   memset(T , 0 , sizeof(T));
   for(int i = 1;i <= n;++ i)
      a[i] *= 2;
   WTF = 1;
   V.push_back(1);
   for(int i = 2;i <= n;++ i){
      Pref[i] = Pref[i - 1];
      while(Greater(a[i] , 0 , a[i - 1] , Get(i - 1)))
         Do(i);
      if(Greater(a[i - 1] , Get(i - 1) , a[i] , 2))
         V.push_back(i);
   }
   /*
   V.clear();
   for(int i = 1;i <= n;++ i)
      cout << Pref[i] << ' ' ;
   cout << '\n';
   for(int i = 1;i <= n;++ i)
      cout << Suff[i] << ' ';
   */
   A = min(Suff[1] , Pref[n] + n);
   for(int i = 1;i <= n;++ i)
      A = min(A , Pref[i] + Suff[i + 1] + i);
   cout << A;
   return 0;
}


Measured memory_bytes: 5760
program lunlun_number
  implicit none
  integer :: k, l = 9, i, j, m, n = 9
  integer(8), allocatable :: a(:,:)
  read(*,*) k
  if (k < 10) then
    write(*,'(i0)') k
    stop
  end if
  allocate(a(2,k))
  a = 0_8
  a(1,1:9) = (/1_8, 2_8, 3_8, 4_8, 5_8, 6_8, 7_8, 8_8, 9_8 /)
  do
    do i = 1, 9
      m = 0
      do j = 1, l
        if (mod(a(1,j),10_8) /= 0_8) then
          m = m+1
          a(2,m) = a(1,j)*10_8+mod(a(1,j),10_8)-1_8
          n = n+1
          if (n == k) then
            write(*,'(i0)') a(2,m)
            stop
          end if
        end if
        m = m+1
        a(2,m) = a(1,j)*10_8+mod(a(1,j),10_8)
        n = n+1
        if (n == k) then
          write(*,'(i0)') a(2,m)
          stop
        end if
        if (mod(a(1,j),10_8) /= 9_8) then
          m = m+1
          a(2,m) = a(1,j)*10_8+mod(a(1,j),10_8)+1_8
          n = n+1
          if (n == k) then
            write(*,'(i0)') a(2,m)
            stop
          end if
        end if
      end do
      a(1,1:m) = a(2,1:m)
      l = m
    end do
  end do
end program lunlun_number

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

int main(){
	// sengen
	int x,y;
	int count =0;
	// nyuryoku
	cin >> x >> y;
	// keisan
	if(x == 1){
		count += 300000;
	}else if(x == 2){
		count += 200000;
	}else if(x == 3){
		count += 100000;
	}
	if(y == 1){
		count += 300000;
	}else if(y == 2){
		count += 200000;
	}else if(y == 3){
		count += 100000;
	}
	if(x == 1 && y == 1){
		count += 400000;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define endl '\n'

using namespace std;

main()
{
  fast;
  ll n,k;
  cin>>n>>k;
  cout<<min(n%k,k-n%k)<<endl;
}

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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

int main(void){
  
  ll A,B,N;
  cin >> A >> B >> N;
  
  ll max=0;
  
  if((B-1)<N){
    cout << ((A*(B-1))/B) - A*((B-1)/B);
  }else{
    cout << ((A*N)/B) - A*(N/B);
  }
  return 0;
}


Measured memory_bytes: 3584