akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

ll pow(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}


int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
 //    int t;
 //     cin >> t;

 //     while(t--){

 // }

     int n,m,k;
     cin >> n >> m >> k;
     vi c(n);
     vvi v(n,vi(m));
     fo(i,0,n){
     	cin >> c[i];
     	fo(j,0,m)cin >> v[i][j];
     }




     int x  =  (1 << n);
     int mi = 1e9;
     fo(i,1,x){
     	vi var(m);
     	int x = i;
     	vi pos;
     	int count = 0;
     	while(x > 0){
     		if(x&1)pos.pb(count);
     		x = x  >> 1;
     		count++;
     	}
     	int sum = 0;
     	// for(auto a : pos)cout << a << ' ';
     	// 	cout << endl;
     	for(auto a : pos){
     		sum += c[a];
     		fo(j,0,m)var[j] += v[a][j]; 
     	}
     	int flag = 0;
     	// if(sum == 120){
     	// 	fo(j,0,n){
     	// 		fo(p,0,m)cout << v[j][p] <<  ' ';
     	// 		cout << endl;
     	// 	}
     	// }
     	fo(j,0,m){
     		if(var[j] < k){
     			flag = 1;
     			break;
     		}
     	}
     	// cout << sum << endl;

     	if(flag == 0)
     		mi = min(sum,mi);


     }
     if(mi == (int)1e9)cout << -1  << endl;
     else cout << mi << endl;




return 0;
	
	}




Measured memory_bytes: 3652
(defparameter *hash-memo* (make-hash-table :test #'equal))

(defmacro dp (&body func)
  `(let* ((f (quote func))
          (num (gethash f *hash-memo*)))
     (if num
         num
         (setf (gethash f *hash-memo*) ,func))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(let* ((n (read))
       (a (loop repeat n collect (read))))
  (princ (if (every (lambda (x) (or (oddp x) (or (zerop (mod x 3)) (zerop (mod x 5))))) a) "APPROVED" "DENIED")))


Measured memory_bytes: 7396
#include <iostream>
#include <string>
#define rp(i,n) for(long long i=0;i<n;i++)

using namespace std;
using ll = long long;

int main(void)
{
    double a,b,s,t;
    int ans;
    cin>>a>>b;
    s=max(a/0.08,10*b);
    t=min((a+1)/0.08,10*(b+1));
    if(s-(int)s==0)
    {
         ans =s;
    }else
    {
        ans = (int)(s+1);
    }
    if(ans>=t)
    {
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import itertools
# n = int(input())
# lis = [x for x in range(n)] # 0からn-1までのリスト
# permutations_lis = itertools.permutations(lis)# 全ての場合のリストを生成
# # 以下出力
# for one_case in permutations_lis:
#     for num in one_case:
#         print(num, end=" ")
#     print("")

def main():
    # 入力
    n = int(input())

    pls = []
    for i in range(n):
        x, y = map(int, input().split())
        pls.append((x, y))

    # ｎ番目をスタート地点とする
    lis = [x for x in range(n)]
    permutations_lis = itertools.permutations(lis)

    num = 0
    sum = 0
    for plist in permutations_lis:
        num += 1
        now = pls[plist[0]]
        ls = plist[1:]
        for i in ls:
            x_diff_2 = (pls[i][0] - now[0])**2
            y_diff_2 = (pls[i][1] - now[1])**2
            zz = x_diff_2 + y_diff_2
            # print(zz)
            sum += pow(x_diff_2 + y_diff_2, 0.5)
            # print(sum)
            now = pls[i]

    print(sum/num)


main()


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
int main() {

	size_t con[3]{ 5,5,7 }, b[3]{0,0,0};

	for (auto& v : b) {
		std::cin >> v;
	}
	std::sort(std::begin(b), std::end(b));
	if (std::equal(std::begin(b), std::end(b), con)) {
		std::cout << "YES";
	}
	else {
		std::cout << "NO";
	}
	std::cout<< "\n";

	return 0;
}

Measured memory_bytes: 256
import sys
from itertools import accumulate
readline = sys.stdin.readline

S = [1 if s == 'A' else 2 for s in readline().strip()]
T = [1 if s == 'A' else 2 for s in readline().strip()]
AS = [0] + list(accumulate(S))
AT = [0] + list(accumulate(T))
Q = int(readline())
Ans = [None]*Q 

for qu in range(Q):
    a, b, c, d = map(int, readline().split())
    if (AS[b]-AS[a-1])%3 != (AT[d]-AT[c-1])%3:
        Ans[qu] = 'NO'    
    else:
        Ans[qu] = 'YES'

print('\n'.join(map(str, Ans)))

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

int main() {
  int H, W;
  cin >> H >> W;

  int i,j;
  vector<vector<char>> a(H, vector<char>(W));
  for (i = 0; i < H; i++){
    for (j = 0; j < W; j++){
      cin >> a.at(i).at(j);
    }
  }

  //行のチェック
  vector<bool> h_flag(H, true);
  for (i = 0; i < H; i++){
    for (j = 0; j < W; j++){
      if (a.at(i).at(j) == '#') {
        h_flag.at(i) = false;
        break;
      }
    }
  }

  //列のチェック
  vector<bool> w_flag(W, true);
  for (i = 0; i < W; i++){
    for (j = 0; j < H; j++){
      if (a.at(j).at(i) == '#'){
        w_flag.at(i) = false;
        break;
      }
    }
  }

  //チェックした行と列を除いて出力する
  for (i = 0; i < H; i++){
    for (j = 0; j < W; j++){
      if (!h_flag.at(i) && !w_flag.at(j)){
        cout << a.at(i).at(j);
      }
    }
    if (!h_flag.at(i)) {
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h = gi();
    int n = gi();
    int s = 0;
    for (int i = 0; i < n; i++)
        s += gi();
    printf(s >= h ? "Yes\n" : "No\n");

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    if a[i] <= b[i]:
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0
        ans += min(a[i + 1], b[i])
        a[i + 1] = max(a[i + 1] - b[i], 0)
    else:
        ans += b[i]
print(ans)

Measured memory_bytes: 18624
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main(){
	int x1[] = {0, -1, 0, 1, 0};
	int y1[] = {-1, 0, 0, 0, 1};
	int x2[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
	int y2[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
	int x3[] = {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0};
	int y3[] = {-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2};
	int l[] = {5, 9, 13};
	int *xs[] = {x1, x2, x3};
	int *ys[] = {y1, y2, y3};
	char c;
	int m[100][100];
	rep(i, 100) rep(j, 100) m[i][j] = 0;
	for (int x, y, s; cin >> x >> c >> y >> c >> s; ) {
		rep(i, l[s - 1]) {
			m[y + ys[s - 1][i] + 20][x + xs[s - 1][i] + 20]++;
		}
	}
	int minc = 0, cnt = 0;
	rep(i, 10) rep(j, 10) {
		minc = max(minc, m[i + 20][j + 20]);
		if (m[i + 20][j + 20] == 0) cnt++;
	}
	cout << cnt << endl << minc << endl;
	
	return 0;
}

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

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: BufRead> {
  reader: R,
  iter: std::vec::IntoIter<String>
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader, iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut scanner = Scanner::new(cin);
  scanner.new_line();
  let s = scanner.iter.collect::<Vec<String>>().join(" ");
  let s: String = s.chars().map(|c| {
    if c.is_uppercase() {
      c.to_lowercase().to_string()
    }
    else {
      c.to_uppercase().to_string()
    }
  })
  .collect();
  println!("{}", s);
}



Measured memory_bytes: 5052
#include<stdio.h>

int main(){
	int a;
	int b; 
	int c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	if (a<b){
		if (b < c){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
		
			
	}
	else{
		printf("No\n");
	}


	return 0;
}

Measured memory_bytes: 1008
using System;

class program
{
    static void Main()
    {
        int a, b;
        string temp;
        string[] temp_array;

        temp = Console.ReadLine();
        temp_array = temp.Split(' ');

        a = int.Parse(temp_array[0]);
        b = int.Parse(temp_array[1]);

        if((a*b)%2 == 0)
        {
            Console.WriteLine("Even");
        }
        else
        {
            Console.WriteLine("Odd");
        }
    }
}



Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    if((a==b && a!=c) ||(a==c && a!=b) || (b==c && a!=b)) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
n = int(input())
s = input()
d = 0
ans = ''
for i in range(len(s)):
    if ord('Z') < ord(s[i]) + n:
        d = ord(s[i])+n-26
    else:
        d = ord(s[i])+n
    ans = ans + chr(d)

print(ans)



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

using namespace std;

int main()
{
  //freopen("in.txt", "r", stdin);
  int a, b, c, d;
  while (scanf("%d%d%d%d", &a, &b, &c, &d) != EOF) {
    int l = max(a, c), r = min(b, d);
    int ans = r - l;
    if (ans < 0) ans = 0;
    printf("%d\n", ans);
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<pair<string, int>, int>> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first.first >> v[i].first.second;
    v[i].first.second *= -1;
    v[i].second = i + 1;
  }
  sort(begin(v), end(v));
  for (auto e : v) cout << e.second << endl;
}


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

middle = N % K
answer = middle
while True:
  if abs(answer-K) > N:
    answer = N
    break
  if abs(answer - K) < answer:
    answer = abs(answer-K)
  else:
    break
    
print(str(answer))

Measured memory_bytes: 3060
N=int(input())

t,x,y=0,0,0
F=True
for _ in range(N):
    s,a,b=t,x,y
    t,x,y=map(int,input().split())

    m=abs(x-a)+abs(y-b)
    if not(m<=t-s and (t-s-m)%2==0):
        F=False

if F:
    print("Yes")
else:
    print("No")
        


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

int main() {

	string s; cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '+') ans++;
		else ans--;
	}
	cout << ans << endl;
	return 0;
}

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


void solve(long long N){

    vector<ll> sum_yaku(N+1,1);
    sum_yaku[0] = 0;
    sum_yaku[1] = 1;
    for (size_t i = 2; i <= N; i++)
    {
        for (size_t j = 1; i*j<=N; j++)
        {
            sum_yaku[i*j]++;
        }
    }

    for (auto &&i : sum_yaku)   
    {
//        cout << i << " ";
    }
    //cout << endl;
    

    ll ans = 0;
    for (size_t i = 0; i <= N; i++)
    {
        ans += i*sum_yaku[i];
    }
    
    cout << ans << endl;

}

signed main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 81428
#include<iostream>
#include<vector>
#include<string>
using namespace std;



int main(){

    long long n;
    cin>>n;
    if(n%2){
        cout<<0<<endl;
        return 0;
    }
    n = n/2;
    long long res = 0;
    while(n){
        res+= n/5;
        n= n/5;
    }
    cout<<res<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> cards(N);
  for (int i=0; i<N; i++) {
    cin >> cards.at(i); }
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  
   int A=0, B=0;
  for (int i=0; 2*i < N; i++) {
    A += cards.at(2*i); }
  for (int i=0; 2*i+1 < N; i++) {
    B += cards.at(2*i+1); }
  
  cout << A - B << endl;
  
  
}


Measured memory_bytes: 256
import sys
n,x = map(int, input().split())
a = list(map(int, input().split()))
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

if len(a)==1:
  print(abs(x-a[0]))
  sys.exit()

g = gcd(abs(x-a[0]), abs(x-a[1]))
for i in range(2,n):
  g = gcd(g, abs(x-a[i]))
print(g)

Measured memory_bytes: 14252
# C
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


N = int(input())
s = []
for i in range(N):
    tmp = list(input())
    tmp = sorted(tmp)
    tmp = ','.join(tmp)
    s.append(tmp)
c = collections.Counter(s)
ans_list = c.values()
ans_list = [i for i in ans_list if i >= 2]
ans = 0
if len(ans_list) != 0:
    for i in ans_list:
        ans += cmb(i, 2)
    print(ans)
else:
    print(ans)

Measured memory_bytes: 72280
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define mp make_pair

void print(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cout<<a[i]<<' ';
    cout<<endl;
}

void get(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cin>>a[i];
}

const ll p = 998244353;

int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    s = s%p;
    if (s<0) s+=p; 
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}


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

    ll n, w;
    cin>>n>>w;
    vector<ll> weight(n);
    vector<ll> value(n);
    for (int i = 0; i<n; i++) cin>>weight[i]>>value[i];
    
    vector<ll> dp(1e5 + 1, 1e10);
    dp[0] = 0;
    for (int i = 0; i<n; i++)
    {
        for (int j = 1e5; j>=value[i]; j--) dp[j] = min(dp[j], dp[j-value[i]] + weight[i]);
    }
    
    int res = 0;
    for (int i = 0; i<=1e5; i++) if (dp[i]<=w) res = max(res, i);
    cout<<res;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C;
    int D = 0;
    
    cin >> A;
    cin >> B;
    cin >> C;
    
    D = A;
    A = B;
    B = D;
    
    D = A;
    A = C;
    C = D;
    
    cout << A << " " << B << " " << C;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, k;
long long s[600000], ans, *f = s, *b = s, *t = s, u;
int main(){
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++){
		scanf("%lld", b);
		t = b++;
		while(f != t) *b++ = *t + *f++;
	}
	for(u = 1LL<<40, f = s; u; u /= 2){
		sort(f, b);
		t = lower_bound(f, b, u);
		if(b-t >= k){
			ans += u;
			f = t;
		}
		while(t != b) *t++ ^= u;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 4352
import java.lang.StringBuilder
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (0 until n).map { sc.next().toLong() }
    println(problem066c(n, a))
}

fun problem066c(n: Int, a: List<Long>): String {
    val b = LinkedList<Long>()
    for (i in 0 until n) {
        if (n % 2 == 0) {
            if (i % 2 != 0) {
                b.add(0, a[i])
            } else {
                b.add(a[i])
            }
        } else {
            if (i % 2 != 0) {
                b.add(a[i])
            } else {
                b.add(0, a[i])
            }
        }
    }
    val sb = StringBuilder()
    b.forEach {
        sb.append("$it ")
    }
    return sb.toString()
}

Measured memory_bytes: 90516
#133d
import math
N = int(input()) #3≤N≤10^5 -1
A_list = list(map(int, input().split()))
ans_list=[]
#円形に N 個の山が連なっており、時計回りに山 1, 山 2, …, 山 N と呼ばれます。Nは奇数です。
#これらの山の間に N個のダムがあり、ダム 1, ダム 2, …, ダム N と呼ばれます。
#ダム i (1≤i≤N) は山 i と山 i+1 の間にあります (山 N+1 は山 1のことを指します)。
#山 i(1≤i≤N) に 2x リットルの雨が降ると、ダム i−1 とダム i にそれぞれ x リットルずつ水が溜まります
#(ダム 0 はダム Nのことを指します)。

#ある日、各山に非負の偶数リットルの雨が降りました。
#その結果、ダム i(1≤i≤N) には合計で Aiリットルの水が溜まりました。
#各山に降った雨の量を求めてください。この問題の制約下では解が一意に定まることが証明できます。

#ex
#3
#  2  2   4
#---------------
#4  0   4   (4)

#5
#  3   8   7   5   5
#2   4  12   2   8   (2)

#連立方程式を立てて、整理すると一番左端の回答は以下になる
first_ans = sum(A_list[0::2]) - sum(A_list[1::2])
ans_list.append(first_ans)
#それ以外は下記の式で求まるので回す。
for i in range(0,N-1):
    ans_list.append(2*A_list[i] - ans_list[i])
    
print(' '.join(map(str, ans_list)))

Measured memory_bytes: 19272
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main(){
    ll cnt = 0, n, m;
    cin >> n >> m;

    // 外側(上下)
    if(m == 1 && n - 2 > 0) cnt += n - 2;

    // 外側(左右)
    if(n == 1 && m - 2 > 0) cnt += m - 2;

    if(n == 1 && m == 1) cnt = 1;

    if(n - 2 <= 0) n = 2;
    if(m - 2 <= 0) m = 2;

    // 内側
    cnt += (n - 2) * (m - 2);

    cout << cnt << endl;
}

Measured memory_bytes: 256
<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) list($a[]) = ints();
$cnt = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($a[$i] % 2 && ($a[$i + 1] ?? 0) !== 0) ++$a[$i + 1];
    $cnt += intdiv($a[$i], 2);
}
echo $cnt;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 21104
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,Q;
int S[2<<17];
vector<int>G[2<<17];
void dfs(int u,int p,int s)
{
	S[u]+=s;
	for(int v:G[u])if(v!=p)dfs(v,u,S[u]);
}
main()
{
	cin>>N>>Q;
	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);
	}
	for(int i=0;i<Q;i++)
	{
		int p,x;cin>>p>>x;
		S[p-1]+=x;
	}
	dfs(0,-1,0);
	for(int i=0;i<N;i++)cout<<S[i]<<endl;
}


Measured memory_bytes: 24960
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heapify, heappop, heappush 
def main():
    N, M = map(int, readline().split())
    A = [-int(i) for i in readline().split()]
    heapify(A)
    for _ in range(M):
        v = -heappop(A)
        heappush(A, -(v//2))
    print(-sum(A))
if __name__ == '__main__':
    main()

Measured memory_bytes: 12660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  ll h,w;
  cin>>h>>w;
  if(h%3==0 || w%3==0){
    cout<<0<<endl;
  }
  /*else if(h==2 && w==2){
    cout<<1<<endl;
  }
  else if(h==2 || w==2){
    cout<<2<<endl;
  }*/
  else{
    ll ans=min(h,w);
    ll x,y,z;
    x=(h/3)*w;
    y=(h-h/3)*(w/2);
    z=(h-h/3)*(w-w/2);
    ans=min(ans,max(x,max(y,z))-min(x,min(y,z)));
    
    x=(h/3+1)*w;
    y=(h-h/3-1)*(w/2);
    z=(h-h/3-1)*(w-w/2);
    ans=min(ans,max(x,max(y,z))-min(x,min(y,z)));
    
    x=(w/3)*h;
    y=(w-w/3)*(h/2);
    z=(w-w/3)*(h-h/2);
    ans=min(ans,max(x,max(y,z))-min(x,min(y,z)));
    
    x=(w/3+1)*h;
    y=(w-w/3-1)*(h/2);
    z=(w-w/3-1)*(h-h/2);
    ans=min(ans,max(x,max(y,z))-min(x,min(y,z)));
    
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;
int n,k;
ll a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    vector<ll>fu;
    vector<ll>zh;
    int zero=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
            fu.pb(a[i]);
        else if(a[i]>0)
            zh.pb(a[i]);
        else
            zero++;
    }
    int sheng=n-zero;
    if(k>sheng)
    {
        cout<<0<<'\n';
        return 0;
    }
    if(n==k)
    {
        ll ans=1;
        for(int i=1;i<=n;i++)
        {
            ans*=a[i];
            ans%=mod;
            ans=(ans+mod)%mod;
        }
        cout<<ans<<'\n';
        return 0;
    }
    ll ans=1;
    int lenz=zh.size();
    int lenf=fu.size();
    if(lenf>0)
    sort(fu.begin(),fu.end());
    if(lenz>0)
    sort(zh.begin(),zh.end(),greater<ll>());

    if(k%2)
    {
        if(lenz>0)
        {
            ans=zh[0];
            int l=0,r=1;
            int cnt=0;
            while(cnt<k-1)
            {
                ll temp1=0;
                if(l+1<=lenf-1)
                {
                    temp1=fu[l]*fu[l+1];
                }
                ll temp2=0;
                if(r+1<=lenz-1)
                {
                    temp2=zh[r]*zh[r+1];
                }
                if(temp1>temp2)
                {
                    ans*=temp1%mod;
                    ans%=mod;
                    l+=2;
                }
                else
                {
                    ans*=temp2%mod;
                    ans%=mod;
                    r+=2;
                }
                cnt+=2;

            }
            cout<<ans<<'\n';
        }
        else
        {
            if(zero)
                cout<<0<<'\n';
            else
            {
                sort(fu.begin(),fu.end(),greater<ll>());
                for(int i=0;i<k;i++)
                {
                    ans*=fu[i];
                    ans%=mod;
                    ans=(ans+mod)%mod;
                }
                cout<<(ans+mod)%mod<<'\n';
            }
        }
    }
    else
    {

            int l=0,r=0;
            int cnt=0;
            while(cnt<k)
            {
                ll temp1=0;
                if(l+1<=lenf-1)
                {
                    temp1=fu[l]*fu[l+1];
                }
                ll temp2=0;
                if(r+1<=lenz-1)
                {
                    temp2=zh[r]*zh[r+1];
                }
                if(temp1>temp2)
                {
                    ans*=temp1%mod;
                    ans%=mod;
                    l+=2;
                }
                else
                {
                    ans*=temp2%mod;
                    ans%=mod;
                    r+=2;
                }
                cnt+=2;

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







}


Measured memory_bytes: 6656
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		long mon = 100_000;
		while(n != 0){
			mon *= 1.05;
			n--;
			if(mon % 1000 != 0){
				mon += 1000;
				mon -= mon % 1000;
			}
		}
		System.out.printf("%d\n", mon);
	}
}

Measured memory_bytes: 25832
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	char s[105];
	long long a;
	int b;
	scanf("%s%lld",s,&a);
	if(a>100)b=100;
	else b=a;
	for(int i=0;i<b;i++){
		if(s[i]!='1'){
			cout<<s[i]-'0';
			return 0;
		}
	}
	cout<<1;
	return 0;
}

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

int main() {
  ll l, r; cin >> l >> r;
  ll ans = 2019;
  for (ll i=l; i<r; i++) {
    for (ll j=i+1; j<=r; j++) {
      ans = min(ans, (i*j) % 2019);
      if (ans == 0) {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> v(n, 1);
    vector<bool> r(n, false);
    r[0] = true;
    REP(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a]--; v[b]++;
        if(r[a]){
            if(v[a] == 0){
                r[a] = false;
            }
            r[b] = true;
        }
    }
    int ans = 0;
    for(auto i : r) if(i) ans++;
    cout << ans << endl;
    return 0;
}


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

int N;

int L[13];

int main(void)
{
    cin >> N;

    for(int i=0;i<N;i++)cin >> L[i];

    int max=0;
    int point;

    for(int i=0;i<N;i++)
    {
        if(L[i]>max)
        {
            max=L[i];

            point=i;
        }
    }

    int cnt=0;

    for(int i=0;i<N;i++)
    {
        if(i==point)
        {
            continue;
        }

        cnt+=L[i];
    }

    if(cnt>L[point])cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
	int n; cin >> n;
	vector<vector<int>> v(n,vector<int>(3));
	vector<vector<int>> dp(n,vector<int>(3));
	for ( int i = 0 ; i<n ; i++) {
		cin >> v[i][0] >> v[i][1] >> v[i][2];
	}
	for ( int i = 0 ; i<n ; i++) {
		for ( int j = 0 ; j<3; j++) {
			if ( i==0 ) { // En la primera iteracion no hay restricciones
				dp[i][j] = v[i][j];
			} else {
				for ( int k = 0 ; k < 3 ; k++) {
					if ( j == k) continue;
					// Se exploran las tres posiciones anteriores
					// execpto la elegida anteriormente que es j
					dp[i][j] = max (dp[i][j],dp[i-1][k] + v[i][j]);
				}
			}
		}
	}
	int ans = dp[n-1][0];
	ans = max (dp[n-1][1],ans);
	ans = max (dp[n-1][2],ans);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13972
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<(*i)<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;






int main() {
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=0;
    while(a>=b){
        ans++;
        b*=2;
    }
    while(b>=c){
        ans++;
        c*=2;
    }
    Yn(ans<=k);
}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;

  ll sum = 0;
  for(int i=1;i<=n;i++){
    if(i%3!=0 && i%5!=0){
      sum += i;
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18
#define PI 3.1415926535

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
  vector<int> p(3);
  rep(i,3) cin >> p[i];
  sort(p.begin(),p.end());
  int s = p[2] * 2 - p[0] - p[1];
  int ans = 0;
  if(s % 2 == 0) ans = s/2;
  else{
    s += 1;
    ans = s/2 + 1;
  }
  cout << ans << endl;
}
   

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int T[100010];
int main()
{
	int n,c,k,ans=0;
	cin>>n>>c>>k;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&T[i]);
	}
	sort(T+1,T+1+n);
	T[n+1]=(int)1e9+10;
	int i=1;
	while(i<=n)
	{
		if(i==n)
		{
			ans++;break;	
		}
		int l=i,r=n,j;
		while(l<r)
		{
			j=(l+r)>>1;
			if(T[j]-T[i]<=k&&j-i+1<=c)
			{
				l=j+1;
			}
			else r=j;
		}
		if(l==n)
		{
			if(T[n]-T[i]<=k&&n-i+1<=c)
			{	ans++;
				break;	}
		}
		//j=l-1;
		//i=j+1;
		i=l;
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector> 
using namespace std;
const long long inf=(1ll<<60);
long long n,ans;
struct node{
	long long x,y;
	node(long long u,long long v)
	{
		x=u,y=v;
	}
};
vector <node> c[4];
inline bool cmp1(node x,node y)
{
	return x.x+x.y > y.x+y.y;
}
inline bool cmp2(node x,node y)
{
	return -x.x+x.y > -y.x+y.y;
}
inline bool cmp3(node x,node y)
{
	return -x.x-x.y > -y.x-y.y;
}
inline bool cmp4(node x,node y)
{
	return x.x-x.y > y.x-y.y;
}
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	n=read();
	long long u,v;
	for(long long i=1;i<=n;++i)
	{
		long long x=read(),y=read();
		c[0].push_back(node(x,y));
		c[1].push_back(node(x,y));
		c[2].push_back(node(x,y));
		c[3].push_back(node(x,y));
	}
	sort(c[0].begin(),c[0].end(),cmp1);
	sort(c[1].begin(),c[1].end(),cmp2);
	sort(c[2].begin(),c[2].end(),cmp3);
	sort(c[3].begin(),c[3].end(),cmp4);
	for(long long i=0;i<n;++i)
	{
		long long x=c[0][i].x,y=c[0][i].y;
		for(long long j=0;j<4;++j)
		{
			u=c[j][0].x,v=c[j][0].y;
			ans=max(ans,abs(x-u)+abs(y-v));
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 15876
N, L = map(int, input().split())
W = []
V = []
for _ in range(N):
    w, v = map(int, input().split())
    W.append(w)
    V.append(v)

VMAX = 10**5 + 100
ans = 0
dp = [[float('inf')] * (VMAX+1) for _ in range(N+1)]
dp[0][0] = 0
for n in range(N):
    for v in range(VMAX):
        if dp[n][v] != float('inf'):
            dp[n+1][v] = min(dp[n+1][v], dp[n][v])
            dp[n+1][v+V[n]] = min(dp[n+1][v+V[n]], dp[n][v] + W[n])

            if dp[n+1][v+V[n]] <= L:
                ans = max(ans, v+V[n])
# print(*dp, sep='\n')
print(ans)


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

int main(){
  int m, k;
  cin >> m >> k;
  if (k >= (1 << m)) cout << -1 << endl;
  else if (m == 1 && k == 1) cout << -1 << endl;
  else if (m == 1 && k == 0) cout << "0 0 1 1" << endl;
  else{
    int ans[1<<(m+1)];
    ans[0] = k;
    ans[1<<m] = k;
    int add = 0;
    for (int i=0; i<(1<<m)-1; i++){
      if (i==k) add = 1;
      ans[i+1] = i + add;
      ans[(1<<(m+1))-i-1] = i + add;
    }

    for (int i=0; i<(1<<(m+1)); i++){
      cout << ans[i];
      if (i != (1<<(m+1))-1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}

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


int main(){
    int a,b,c;
    cin>>a>>b>>c;
    
    cout<< (b-a == c-b ? "YES" : "NO" ) <<endl; 
    
    return 0;
}

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

int main(){
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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;
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll K, A ,B; cin >> K >> A >> B;
    ll cnt=0, sum=1;
    ll i=0;

    if(B-A<=2) sum+=K;
    else{
        while(i<K){
            if(sum>=A and i+2<=K) sum += (B-A), i+=2;
            else sum++, i++;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(N: Int, K: Int, h: LongArray){
    h.sort()
    val ans = (0..N - K).map{ h[it+K-1] - h[it] }.min()
    println(ans)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val K = sc.next().toInt()
    val h = LongArray(N)
    for (i in 0 until N ) {
        h[i] = sc.next().toLong()
    }
    solve(N, K, h)
}



Measured memory_bytes: 41868
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s == "abc"||s == "acb"|| s == "bac"|| s == "bca"|| s == "cab"|| s == "cba"){
        cout << "Yes" << endl;
    } else {
        cout << "No" <<  endl;
    }
    return 0;
}

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

using namespace std ;

typedef long long LL ;


#define mkp make_pair
#define pll pair<LL, LL>

const LL B1 = 237ll ;
const LL B2 = 637ll ;
const int N = 300010 ;
const LL P1 = 998244353 ;
const LL P2 = 1004535809 ;

int n ;
LL ans ;
char s[N] ;
LL I1, I2 ;
LL S[N], T[N] ;
map <pll, LL> buc ;

LL expow(LL a, LL b, LL p){
    LL ret = 1 ;
    while (b){
        if (b & 1)
            (ret *= a) %= p ;
        (a *= a) %= p ; b >>= 1 ;
    }
    return ret ;
}
int main(){
    cin >> n >> (s + 1) ;
    I1 = expow(B1, P1 - 2, P1) ;
    I2 = expow(B2, P2 - 2, P2) ;
    for (int i = n ; i >= 1 ; -- i){
        if (s[i] == '-'){
            S[i] = (S[i + 1] - B1 + P1) % P1 ;
            T[i] = (T[i + 1] - B2 + P2) % P2 ;
        }
        if (s[i] == '+'){
            S[i] = (S[i + 1] + B1) % P1 ;
            T[i] = (T[i + 1] + B2) % P2 ;
        }
        if (s[i] == '<'){
            S[i] = (S[i + 1] * I1) % P1 ;
            T[i] = (T[i + 1] * I2) % P2 ;
        }
        if (s[i] == '>'){
            S[i] = (S[i + 1] * B1) % P1 ;
            T[i] = (T[i + 1] * B2) % P2 ;
        }
        //cout << S[i] << " " << T[i] << endl ;
    }
    LL gs = 1, gt = 1 ;
    for (int i = n ; i >= 1 ; -- i){
        LL x, y ;
        x = expow(gs, P1 - 2, P1) * (-S[i + 1] + P1) % P1 ;
        y = expow(gt, P2 - 2, P2) * (-T[i + 1] + P2) % P2 ;
        if (x < 0) x += P1 ; if (y < 0) y += P2 ; ++ buc[mkp(x, y)] ;
        //cout << x << " " << y << endl ;
        if (s[i] == '<') (gs *= I1) %= P1, (gt *= I2) %= P2 ;
        if (s[i] == '>') (gs *= B1) %= P1, (gt *= B2) %= P2 ;
        x = expow(gs, P1 - 2, P1) * (-S[i] + S[1]) % P1 ;
        y = expow(gt, P2 - 2, P2) * (-T[i] + T[1]) % P2 ;
        if (x < 0) x += P1 ; if (y < 0) y += P2 ; ans += buc[mkp(x, y)] ;
    }
    cout << ans << endl ; return 0 ;
}


Measured memory_bytes: 35968
#include<bits/stdc++.h>
using namespace std;
int n,m,d;
double ans;
int main(){
	scanf("%d%d%d",&n,&m,&d);
	if (d==0) ans=(m-1)*1.0/n;
	else ans=(n-d)*2.0*(m-1)/n/n;
	printf("%.8lf\n",ans);
	return 0;
}
			


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Order ord = new Order();
		try (Scanner sc = new Scanner(System.in)) {
			int q = sc.nextInt();
			for(int i = 0; i < q; i++) {
				int order_number = sc.nextInt();
				if(order_number == 0) {
					ord.push(1, sc.nextInt());
				}else if(order_number == 1) {
					ord.randomAccess(sc.nextInt());
				}else if(order_number == 2) {
					ord.pop(1);
				}
//				System.out.println(ord.getArray());
			}
		}
	}
}

class Order{
	ArrayList<Integer> array = new ArrayList<Integer>();
	public void makeList(int a){
		array.add(a);
	}
	public void push(int d, int x){
		if(d == 0) {
			array.add(0, x);
		}else if(d == 1) {
			array.add(x);
		}
	}
	public void randomAccess(int p) {
		System.out.println(array.get(p));
	}
	public void pop(int d) {
		if(d == 0) {
			array.remove(0);
		}else if(d == 1) {
			array.remove(array.size() - 1);
		}

	}
	public ArrayList<Integer> getArray() {
		return array;
	}
}



Measured memory_bytes: 141760
#include<stdio.h>
int flg[1000000];
int main(void)
{
	int n;
	int i,j;
	int cnt;
	
	while(scanf("%d",&n)!=EOF){
		cnt=0;
		for(i=2;i<=n;i++){
			flg[i]=0;
		}
		for(i=2;i*i<=n;i++){
			if(flg[i]==0){
				for(j=2;i*j<=n;j++){
					flg[i*j]=1;
				}
			}
		}
		for(i=2;i<=n;i++){
			if(flg[i]==0){
				cnt++;
			}
		}	
	printf("%d\n",cnt);
	}
	return 0;
}
	

Measured memory_bytes: 4496
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

int main(){
	string str;
	cin >> str;
	for (int i = str.length() - 1; i >= 0; --i) {
		cout << str[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1172
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



#include<bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }

const int mx = 1e5+123;
int h[mx], dp[mx], n, k;

int solve ( int i )
{
    if ( i == n ) return 0;

    if ( dp[i] != -1 ) return dp[i];

    int ret = inf;

    for ( int j = 1; j <= k; j++ ) {
        if ( i+j <= n ) ret = min ( ret, abs ( h[i] - h[i+j] ) + solve ( i+j ) );
    }

    return dp[i] = ret;
}

int main()
{
    optimize();

    cin >> n >> k;
    for ( int i = 1; i <= n; i++ ) cin >> h[i];

    mem ( dp, -1 );
    cout << solve ( 1 ) << endl;

    return 0;
}


















Measured memory_bytes: 12192
#include <algorithm>
#include <cstdio>

using namespace std ;

const int N=1e5+10 ;

int A[N] , B[N] ;
int n ;

int main ()
{
	int i , res=0 ;
	scanf("%d",&n);
	for ( i=1 ; i<n ; i++ ) scanf("%d",B+i);
	A[1]=B[1],A[n]=B[n-1];
	for ( i=2 ; i<n ; i++ ) A[i]=min(B[i-1],B[i]);
	for ( i=1 ; i<=n ; i++ ) res+=A[i];
	printf("%d\n",res);
	return 0 ;
}


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

using namespace std;

int main(void)
{
    int N; cin >>N;
    vector<int> d(N);
    for(int i = 0; i < N; i++) cin >> d.at(i);

    int sum = 0;

    for(int i = 0; i < N-1; i++)
    {
        for(int j = i + 1; j < N;j++)
        {
            sum += d.at(i) * d.at(j);
        }
    }

    cout << sum << endl;
}

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

const int N = 5010;

char s[N * 2]; int n;

inline void FUCK(char t) {
    for (int i = 1; i <= n; i++) putchar(t);
    exit(0);
}

int tmp[N * 2]; char res[N];

int main() {
    int k; scanf("%d%d%s", &n, &k, s + 1); char t = 127;
    for (int i = 1; i <= n; i++) t = min(t, s[i]);
    for (int i = n + 1; i <= n * 2; i++) s[i] = s[n * 2 - i + 1];
    for (int i = 1; i <= n; i++) res[i] = 127;
    if (k == 1) {
        for (int i = 1; i <= n + 1; i++) {
            bool flag = false;
            for (int j = 1; j <= n; j++) if (s[i + j - 1] != res[j]) {
                if (s[i + j - 1] < res[j]) flag = true;
                break; 
            } 
            if (flag) for (int j = 1; j <= n; j++) res[j] = s[i + j - 1];
        }
        for (int i = 1; i <= n; i++) putchar(res[i]); 
        return 0;
    }
    if (k >= 20) FUCK(t);
    int mx = 0;
    for (int i = 1; i <= n * 2; i++) if (s[i] == t) 
        tmp[i] = tmp[i - 1] + 1, mx = max(mx, tmp[i]);
    if ((mx << (k - 1)) >= n) FUCK(t);
    int all = mx << k - 1, len = n - mx;
    for (int i = 1; i <= all; i++) putchar(t);
    
    for (int i = 1; i <= n * 2; i++) if (tmp[i] == mx && i - mx - len + 1 >= 1) {
        int st = i - mx + 1; bool flag = false;
        for (int j = 1; j <= len; j++) if (s[st - j] != res[j]) {
            if (s[st - j] < res[j]) flag = true;
            break; 
        } 
        if (flag) for (int j = 1; j <= len; j++) res[j] = s[st - j];
    }
    for (int i = 1; i <= n - all; i++) putchar(res[i]);
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().strip().split()))
count = 0
for i in range(n):
    mini = i
    for j in range(i, n):
        if a[j] < a[mini]:
            mini = j
    if i != mini:
        count += 1
        a[i], a[mini] = a[mini], a[i]
print(' '.join(map(str, a)))
print(count)

Measured memory_bytes: 6724
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	sort(ALL(a));
	ll x=a[n-1],y=0;
	ll diff=INF*INF;
	REP(i,n-1) {
		if(x%2) {
			if(diff>abs(a[i]-(x/2+1))) {
				diff=abs(a[i]-(x/2+1));
				y=a[i];
			}
		} else {
			if(diff>min(abs(a[i]-(x/2+1)),abs(a[i]-x/2))) {
				diff=min(abs(a[i]-(x/2+1)),abs(a[i]-x/2));
				y=a[i];
			}
		}
	}
	cout<<x<<" "<<y<<endl;
}


Measured memory_bytes: 1024