akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <set>
using namespace std;

int heal[300000];

multiset<int> s;

int main()
{
    int n;scanf("%d",&n);
    int num=1;
    while (n--) num*=2;

    for (int i=1;i<=num;i++)
        scanf("%d",&heal[i]);

    for (int i=1;i<=num;i++)
        s.insert(-heal[i]);
    int tmp=1;
    heal[1]=-(*s.begin());
    s.erase(s.begin());

    for (int j=1;j<=num/2;j*=2)
    {
        int _tmp=tmp;
        for (int i=1;i<=_tmp;i++)
        {
            multiset<int>:: iterator it;
            it = s.upper_bound(-heal[i]);
            //printf("%d %d\n",heal[i],-*it);
            if (it!=s.end())
            {
                heal[++tmp]=-*it;
                s.erase(it);
            }
        }
        if (tmp!=j*2){
            printf("No\n");return 0;
        }
    }

    printf("Yes\n");

}


Measured memory_bytes: 13568
r, c = map(int, input().split())

sumOfCols = [0] * c

for i in range(r):
    cols = list(map(int, input().split()))
    s = sum(cols)
    sumOfCols = [p + q for p,q in zip(sumOfCols, cols)]
    print(' '.join(map(str, cols)), end=' ')
    print(s)


s = sum(sumOfCols)
print(' '.join(map(str, sumOfCols)), end=' ')
print(s)

Measured memory_bytes: 7796
import math
import sys
import os

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

N,K = LI()
P = LI()
C = LI()

P = list(map(lambda x:x-1,P))

res = -INF
used = [False] * N
ss = []

for i in range(N):
    # print('i',i)
    if used[i]:
        continue
    cur = i
    s = []
    while not used[cur]:
        used[cur] = True
        s.append(C[cur])
        cur = P[cur]
        # print(cur)
    ss.append(s)

# print(ss)

for vec in ss:
    M = len(vec)
    # 2周の累積和
    sum = [0]*(2*M + 1)
    for i in range(2*M):
        sum[i+1] = sum[i]+vec[i%M]
    
    # amari[r] := 連続するr個の最大値
    amari = [-INF]*M
    for i in range(M):
        for j in range(M):
            amari[j] = max(amari[j],sum[i+j] - sum[i])
    
    for r in range(M):
        if r>K:
            continue
        q = (K-r)//M
        if r==0 and q==0:
            continue
        if sum[M]>0:
            res = max(res, amari[r] + sum[M] * q)
        elif r > 0:
            res = max(res, amari[r])
print(res)




Measured memory_bytes: 75440
using System;
using System.Linq;

namespace ConsoleApp3
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var lines = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
            var averageA = lines.Sum() / n;
            var averageB = averageA + 1;

            var sumA = lines.Select(x =>
            {
                var dist = x - averageA;
                return dist * dist;
            })
            .Sum();

            var sumB = lines.Select(x =>
            {
                var dist = x - averageB;
                return dist * dist;
            })
            .Sum();

            Console.WriteLine(Math.Min(sumA, sumB));
        }
    }
}


Measured memory_bytes: 28284
#include <iostream>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
    int q; cin >> q;
    rep(i,0,q) {
        string s; cin >> s;
        int cnt = 0;
        while(1) {
            // cout << s << endl;
            if(s.length() == 1) break;
            else {
                int ma = 0;
                repq(i,1,s.length()) {
                    string s1 = s.substr(0,i);
                    string s2 = s.substr(i,s.length() - i);
                    ma = max(ma, atoi(s1.c_str()) * atoi(s2.c_str()));
                }
                s = to_string(ma);
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3212
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<numeric>

#include <algorithm>
#include <functional>
using namespace std;

int main(){
  int n,a,b;
  vector<int>vec;
  cin >> n >> a >> b;

  vec.push_back((n*a));
  vec.push_back((b));

  std::sort(vec.begin(),vec.end());
  cout << vec[0];
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
bool prime[(int)1e6 + 7];
vector<int> primes;

int main() {
	int n, k;
	cin >> n >> k;
	int rsp[3];
	cin >> rsp[0] >> rsp[1] >> rsp[2];
	string s;
	cin >> s;
	ll score = 0;
	map<char, int> mrps;
	mrps['r'] = 0;
	mrps['s'] = 1;
	mrps['p'] = 2;

	map<int, char> mrps2;
	mrps[0] = 'r';
	mrps[1] = 's';
	mrps[2] = 'p';
	string ans = string(s.size(), '*');

	for (int i = 0; i < (int)s.size(); i++) {
		if (i - k >= 0) {
			if (s[i] != s[i - k] || ans[i-k] == s[i-k]) {
				score += rsp[(mrps[(s[i])] + 2)%3];
				ans[i] = mrps2[(mrps[(s[i])] + 2) % 3];
			}
			else  {
				ans[i] = s[i];
			}
		}
		else {
			score += rsp[(mrps[s[i]]+2)%3];
		}
	}
	cout << score;


}

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

using namespace std;

const bool debug = true;
#define dbg(...) if(debug) printf(__VA_ARGS__)
#define print(var) if (debug) cout << #var << " = " << var << endl

namespace {
    int n, m;
    void input() {
        cin >> n >> m;
    }

    void solve() {
        cout << max(0, n - m - 1) << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}




Measured memory_bytes: 3080
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;

int main() {
    int n; cin >> n;
    int ans = 1e5;
    rrep(i, 1, n) {
        int a, b; a = i; b = n - i;
        int cnt = 0;
        while (a) {
            cnt += a % 10;
            a /= 10;
        }
        while (b) {
            cnt += b % 10;
            b /= 10;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include<string.h>
using namespace std;
int main() {
  string A;
  cin>>A;
  long long int num[26],ans=0; 
memset(num,0,sizeof(long long int)*26);
  
long long  int l=A.size();
  for(int i=0;i<l;i++){
    num[A[i]-'a']++;
    }
    
    for(int i=0;i<26;i++){
      ans+=(num[i]*(num[i]+1))/2;
      }
   
   cout<<1+l*(l+1)/2-ans;
}

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

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int n,a;
    bool fg=false;
    cin>>n;
    while(n--)
    {
        cin>>a;
        if(!(a&1))
        {
            if(a%3==0 || a%5==0)continue;
            fg=true;
        }
    }
    if(!fg)cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)

bool debug=true;

/*    *************************************
	  * Written in New Computer           *
	  * The following code belongs to     *
	  * XiaoGeNintendo of HellHoleStudios *
	  *************************************
*/
template<typename T1,typename T2>ostream& operator<<(ostream& os,pair<T1,T2> ptt){
	os<<ptt.first<<","<<ptt.second;
	return os;
}
template<typename T>ostream& operator<<(ostream& os,vector<T> vt){
	os<<"{";
	for(int i=0;i<vt.size();i++){
		os<<vt[i]<<" ";
	}
	os<<"}";
	return os;
}

int n;

char toplace='a';
string s="";
vector<string> ans;

void dfs(int pos){
	if(pos==n){
		ans.push_back(s);
		return;
	}
	for(char i='a';i<=toplace;i++){
		s+=i;
		char tmp=toplace;
		toplace=max(char(i+1),toplace);
		
		dfs(pos+1);
		
		toplace=tmp;
		s.pop_back();
	}
}
int main(int argc,char* argv[]){
	qi;
	cin>>n;
	
	dfs(0);
	
	sort(ans.begin(),ans.end());
	
	for(string x:ans){
		cout<<x<<endl;
	}
	return 0;
}



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

int main()
{

        int N;
        cin >> N;

        int c[N];
        int s[N];
        int f[N];
        for (int i = 0; i < N -1; ++i) {
                cin >> c[i] >> s[i] >> f[i];
        }


        for (int i = 0; i < N-1; ++i) {

                int time = s[i] + c[i];

                for (int j = i + 1; j < N-1; ++j) {

                        if (time < s[j]) {

                                time += (s[j] - time);
                        }
                        else {

                                int t = time % f[j];
                                if (t != 0) {
                                        time += (f[j] - t);
                                }
                        }
                        time += c[j];
                }

                cout << time << endl;





        }

        cout << "0" << endl;










}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

vector <vector <int>> gr;

vector <int> bfs(int st) {
    vector <int> dst(sz(gr), 1e9);
    dst[st] = 0;
    deque <int> q = {st};
    while (!q.empty()) {
        int v = q.front();
        q.pop_f();
        for (int u : gr[v])
            if (dst[v] + 1 < dst[u]) {
                dst[u] = dst[v] + 1;
                q.pb(u);
            }
    }
    return dst;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, x, y;
    cin >> n >> x >> y, --x, --y;
    gr.resize(n);
    forn (i, 0, n - 1)
        gr[i].pb(i + 1), gr[i + 1].pb(i);
    gr[x].pb(y), gr[y].pb(x);
    vector <long long> ans(n);
    forn (i, 0, n) {
        auto dst = bfs(i);
        forn (j, i + 1, n)
            ans[dst[j]]++;
    }
    forn (i, 1, n)
        cout << ans[i] << "\n";
    return 0;
}

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

int main() {
	
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    
    long long n,m,k,count=0,ans=0,sum=0,l,r,i,j,x,y;
    long long a[5];
    for(i=0;i<5;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        count=i+1;
    }
    cout<<count<<"\n";
    
    
    
	return 0;
}

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

#define LL long long
double a, b, c, d, e, f, x, y, ans;
vector<double> u, v;

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    cin >> a >> b >> c >> d >> e >> f;

    for(int i = 0; i <= f; i++) 
        for(int j = 0; j <= f; j++)
            if(100 * i * a + 100 * j * b <= f) u.push_back(100 * i * a + 100 * j * b);

    for(int i = 0; i <= f; i++) 
        for(int j = 0; j <= f; j++)
            if(i * c + j * d <= f) v.push_back(i * c + j * d);

    for(double p : u) {
        for(double q : v) {
            if(p == 0 || q / p > e / 100) continue;
            if(p + q > f) continue;
            if(q / (p + q) >= ans) {
                ans = q / (p + q);
                x = p, y = q;
            }
        }
    }

    cout << x + y << " " << y;
}

Measured memory_bytes: 5364
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();

    int N = sc.nextInt();

    int[][] a = new int[2][N];

    for (int i = 0; i < N; i++) {
      a[0][i] = sc.nextInt();
    }

    for (int i = 0; i < N; i++) {
      a[1][i] = sc.nextInt();
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      int z = 0;
      for (int x = 0; x <= i; x++) {
        z += a[0][x];
      }
      for (int x = i; x < N; x++) {
        z += a[1][x];
      }
      ans = Math.max(ans, z);

    }

    System.out.println(ans);

  }

}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) {
      return buffer[ptr++];
    } else {
      return -1;
    }
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
      ptr++;
    }
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    int n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
}

Measured memory_bytes: 22740
#input
x = [0,0,0,0,0,0,0,0,0,0,0] #先頭は x_2000
r, D, x[0] = list(map(int, input().split()))
for i in range(1,11):
    x[i] = r * x[i-1] - D

#output
for i in range(1,11):
    print(x[i])

Measured memory_bytes: 3060
use proconio::input;

const MAX: usize = 100_001;

fn main() {
    input!(n: usize, v: [usize; n]);
    let mut a = vec![0; MAX];
    let mut b = vec![0; MAX];
    for i in 0..n {
        match i % 2 {
            0 => a[v[i]] += 1,
            1 => b[v[i]] += 1,
            _ => panic!(),
        }
    }
    let mut a: Vec<_> = a.iter().enumerate().map(|(i, &x)| (x, i)).collect();
    let mut b: Vec<_> = b.iter().enumerate().map(|(i, &x)| (x, i)).collect();
    a.sort_by_key(|&x| std::cmp::Reverse(x));
    b.sort_by_key(|&x| std::cmp::Reverse(x));
    println!(
        "{}",
        n - if a[0].1 != b[0].1 {
            a[0].0 + b[0].0
        } else {
            (a[0].0 + b[1].0).max(a[1].0 + b[0].0)
        }
    );
}


Measured memory_bytes: 8748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
ll MAX=100100;



int main(){
  	vector<ll> X(MAX, 0), Y(MAX, 0);
    string S;
    cin>>S;
    int Keta=S.size();
  	X[1]=S.at(0)-'0';
  	Y[1]=1+X[1];
    for(int i=1; i<Keta; i++){
        X[i+1] = X[i] * 3 + Y[i] * (S.at(i)-'0');
        X[i+1] %= MOD;
        Y[i+1] = Y[i] * 2 * (S.at(i)- '0') +  Y [i] * ('1' - S.at(i));
        Y[i+1] %= MOD;
    }
    ll Ans=Y[Keta]+X[Keta];
    Ans%=MOD;
    cout<<Ans<<endl;
    return 0;

}

Measured memory_bytes: 2048
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
//#define int ll

const int N = (1 << 18);
const int BUBEN = (1 << 10);
const int MX = 1e5 + 10;
int pref[BUBEN][MX], val[N], cost[N];
vector<int> path[BUBEN];
bool used[N];

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)  {
    cin >> val[i] >> cost[i];
  }
  for (int i = 1; i < min(n + 1, BUBEN); i++) {
    if (i == 1) {
      path[i] = {1};
    }
    else {
      path[i] = path[i / 2];
      path[i].pb(i);
    }
    for (int mask = 0; mask < (1 << SZ(path[i])); mask++) {
      int cur_cost = 0, cur_sum = 0;
      for (int j = 0; j < SZ(path[i]); j++) {
        if ((mask >> j) & 1) {
          cur_cost += cost[path[i][j]];
          cur_sum += val[path[i][j]];
        }
      }
      if (cur_cost <= 1e5) {
        pref[i][cur_cost] = max(pref[i][cur_cost], cur_sum); 
      }
    }
    for (int j = 1; j <= 1e5; j++) {
      pref[i][j] = max(pref[i][j], pref[i][j - 1]);
    }
    used[i] = true;
  }  
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int v, l;
    cin >> v >> l;
    if (used[v]) {
      cout << pref[v][l] << '\n';
    }
    else {
      vector<int> kek = {v};
      while (!used[v / 2]) {
        v /= 2;
        kek.pb(v);
      }
      v /= 2;
      int rez = 0;
      for (int mask = 0; mask < (1 << SZ(kek)); mask++) {
        int cur_cost = 0, cur_sum = 0;
        for (int j = 0; j < SZ(kek); j++) {
          if ((mask >> j) & 1) {
            cur_cost += cost[kek[j]];
            cur_sum += val[kek[j]];
          }
        }
        if (cur_cost <= l) {
          rez = max(rez, cur_sum + pref[v][l - cur_cost]);
        }
      }
      cout << rez << '\n';
    }
  }
} 

Measured memory_bytes: 405428
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    if (s[0] != '1' || s[n - 1] != '0') {
        cout << -1 << "\n";
        return 0;
    }
    for (int i = 0; i < n - 1; ++i) {
        if (s[i] != s[n - 2 - i]) {
            cout << -1 << "\n";
            return 0;
        }
    }
    vector<pair<int, int>> edges;
    int curr = 0;
    int used = 1;
    edges.emplace_back(curr, used);
    for (int i = 1; i < n - 1; ++i) {
        if (s[i] == '1') {
            used++;
            edges.emplace_back(curr, used);
            curr = used;
        } else {
            used++;
            edges.emplace_back(curr, used);
        }
    }
    for (auto &p : edges) {
        cout << p.first + 1 << " " << p.second + 1 << endl;
    }
    return 0;
}

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

int main() {
  long long int N,ans = 0;
  cin >> N;
  for(int i = 0; i <= N; i++){
    if(i % 5 == 0 || i % 3 == 0){
      continue;
    }
    else{
      ans += i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
from collections import Counter

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

even = list(Counter(v[0::2]).items())
odd = list(Counter(v[1::2]).items())

even.append([0,0])
odd.append([0,0])
even.sort(key=lambda x: -x[1])
odd.sort(key=lambda x: -x[1])

if even[0][0] != odd[0][0]:
    print(n - even[0][1] - odd[0][1])
else:
    print(min(n-even[1][1]-odd[0][1], n-even[0][1]-odd[1][1]))


Measured memory_bytes: 62700
#include <bits/stdc++.h>
#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 pb push_back
#define fs first
#define sc second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define show(x) cout<< #x <<" "<<x<<endl
using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
D eps=1e-9,inf=1e10;
bool eq(D a,D b){return abs(a-b)<eps;}
int sig(D a){return eq(a,0)?0:(a>0?1:-1);}
D dot(P a,P b){return real(conj(a)*b);}
D cro(P a,P b){return imag(conj(a)*b);}
P perp(L l,P p){
	D t=dot(p-l.fs,l.fs-l.sc)/norm(l.fs-l.sc);
	return l.fs+t*(l.fs-l.sc);
}
int ccw(P a,P b,P c){
	if(sig(cro(b-a,c-a))==1) return 1;
	if(sig(cro(b-a,c-a))==-1) return -1;
	if(eq(abs(a-c)+abs(c-b),abs(a-b))) return 0;
	return 2;
}
bool iSP(L s,P p){
	return ccw(s.fs,s.sc,p)==0;
}
D dSP(L s,P p){
	P q=perp(s,p);
	return iSP(s,q)?abs(p-q):min(abs(p-s.fs),abs(p-s.sc));
}
int N,M;
vector<P> ps;
D mn[5001];
bool good(int i,int j){
	if(j==-1) return 1;
	if(eq(mn[i],mn[j])) return i<j;
	return mn[i]<mn[j];
}
bool good2(int i,int j,int n){
	if(j==-1) return 1;
	if(eq(abs(ps[i]-ps[n]),abs(ps[j]-ps[n]))) return i<j;
	return abs(ps[i]-ps[n])<abs(ps[j]-ps[n]);
}
int main(){
	cin>>N>>M;
	{
		int x,y;
		cin>>x>>y;
		ps.pb(P(x,y));
	}
	rep(i,N){
		int x,y;
		cin>>x>>y;
		ps.pb(P(x,y));
	}
	D ans=0;
	mn[0]=inf;
	rep(i,N) mn[i+1]=abs(ps[0]-ps[i+1]);
	rep(tt,M){
		int nx=-1;
		rep(i,N+1) if(good(i,nx)) nx=i;
		int x=-1;
		rep(i,N+1) if(mn[i]==inf) if(good2(i,x,nx)) x=i;
		ans+=abs(ps[x]-ps[nx]);
		mn[nx]=inf;
		rep(i,N+1) if(mn[i]!=inf){
			chmin(mn[i],dSP(L(ps[x],ps[nx]),ps[i]));
		}
	}
	printf("%.12f\n",ans);
}

Measured memory_bytes: 3456
#include<cstdio>

int main(){
    int x,y;
    for(int i = 0;; i++){
        scanf("%d %d",&x,&y);
        if(x == 0 && y == 0){
            break;
        }
        if(x > y){
            int z = x;
            x = y;
            y = z;
        }
        else{
            x = x;
            y = y;
        }
        printf("%d %d\n",x,y);
    }
    return 0;
}


Measured memory_bytes: 2596
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N;
vector<long long> A;

int main() {
    while (cin >> N) {
        A.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        long long sum = 0;
        map<long long, long long> ma;
        ma[sum]++;
        for (int i = 0; i < N; ++i) {
            sum += A[i];
            ma[sum]++;
        }
        
        long long res = 0;
        EACH(it, ma) {
            res += (it->second - 1) * it->second / 2;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 14336
import sys

input = sys.stdin.readline

def main():
    while True:
        m, f, r = map(int, input().split())
        if m==-1 and f==-1 and r==-1:
            sys.exit()
        elif m==-1 or f==-1:
            print("F")
        else:
            if m + f >= 80:
                print("A")
            elif 65 <= m + f <80:
                print("B")
            elif 50 <= m + f <65:
                print("C")
            elif 30 <= m + f <50:
                if r >= 50 :
                    print("C")
                else:
                    print("D")
            else:
                print("F")
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 5604
n, m = map(int, input().split())
xy = [tuple(map(int, input().split())) for _ in range(m)]

gray = [False] * n
gray[0] = True
ball = [1] * n

for x, y in xy:
    x -= 1; y -= 1
    ball[x] -= 1
    ball[y] += 1
    if gray[x]:
        gray[y] = True
    if not ball[x]:
        gray[x] = False

print(sum(gray))


Measured memory_bytes: 60632
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector < vector <int> > vvi;
const int HUGEI = 2147483647;  // (1 << 31) - 1
const ll HUGEL = 9223372036854775807;  // (1 << 63) - 1
const string ABC = "abcdefghijklmnopqrstuvwxyz";

const int MAX = 100000;

int n, m;
int xm[MAX], ym[MAX];
int dpn[MAX];
int cnt[MAX];

int main(void) {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> xm[i] >> ym[i];
    }

    for (int i = 0; i < n; i++) {
        dpn[i] = 0;
        cnt[i] = 1;
    }
    dpn[0] = 1;

    for (int i = 0; i < m; i++) {
        int x0 = xm[i] - 1;
        int y0 = ym[i] - 1;
        dpn[y0] = max(dpn[y0], dpn[x0]);
        cnt[y0]++;
        cnt[x0]--;
        if (cnt[x0] == 0) {
            dpn[x0] = 0;
        }
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        res += dpn[i];
    }
    cout << res << endl;
    return 0;
}


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

int main(){
    int N;
    scanf("%d",&N);
    int A[N+1];
    int B[N+1];
    int i,j;
    for(i=0;i<N;i++){
        B[i]=0;
    }
    A[0]=1;

    for(i=1;i<N;i++){
        scanf("%d",&A[i]);
            B[A[i]-1]+=1;

    }


    for(i=0;i<N;i++){
        printf("%d\n",B[i]);
    }
    return 0;
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n;
ll a[maxn];
vector<int> E[maxn];
void no() { puts("NO"); exit(0);}
ll dfs(int x, int fa)
{
	ll sum = 0, Max = 0;
	for(auto v : E[x])
		if(v != fa)
		{
			ll val = dfs(v, x);
			Max = max(Max, val);
			sum += val;
		}
	if(E[x].size() == 1) return a[x];
	ll cur = sum - a[x], lim;
	if(Max >= sum - Max) lim = sum - Max;
	else lim = sum / 2;
	if(cur < 0 || cur > lim) no();
	return a[x] - cur;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	if(n == 2)
	{
		if(a[1] == a[2]) puts("YES");
		else puts("NO");
		return 0;
	}
	for(int i = 1; i < n; ++i)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	int rt = 0;
	for(int i = 1; i <= n; ++i)
		if(E[i].size() > 1)
		{
			rt = i;
			break;
		}
	if(dfs(rt, 0)) no();
	puts("YES");
	return 0;
}

Measured memory_bytes: 16584
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());
    int M = Integer.parseInt(sc.next());

    int max = M / N;
    for (int i = max; i > 0; i--) {
      if (M % i == 0 && M / i >= N) {
        System.out.println(i);
        return;
      }
    }
    System.out.println(1);

  }
}

Measured memory_bytes: 22868
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;

int main()
{
    int count = 0;

    int h, w;
    cin >> h >> w;

    string str[60];
    for (int i = 0; i < h; i++)
    {
        cin >> str[i];
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (str[i].at(j) == '.')
            {
                for (int n = i - 1; n <= i + 1; n++)
                {
                    if (n < 0 || n >= h)
                    {
                        continue;
                    }
                    for (int m = j - 1; m <= j + 1; m++)
                    {
                        if (m < 0 || m >= w)
                        {
                            continue;
                        }
                        if (str[n].at(m) == '#')
                        {
                            count++;
                        }
                    }
                }

                str[i].at(j) = count + 48;
                //cout << "str[" << i << "].at(" << j << ")" << str[i].at(j) << endl;
                count = 0;
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        cout << str[i] << endl;
    }

    return 0;
}

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


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int C = sc.nextInt();
		Program program[] = new Program[N];
		Main main = new Main();
		for (int i=0;i<N;i++) {
			Program temp = main.new Program();
			temp.s= sc.nextInt();
			temp.t= sc.nextInt();
			temp.c= sc.nextInt();
			program[i] = temp;
		}
		Arrays.sort(program);
		int result[] = new int[1000000];
		int beforec =0;
		int beforeNext=0;
		for (int i=0;i<N;i++) {
			if (program[i].c!=beforec||beforeNext!=program[i].s) {
				result[program[i].s-1]++;
			}
			beforec = program[i].c;
			beforeNext= program[i].t;
			for (int j=program[i].s;j<program[i].t;j++) {
				result[j]++;
			}

		}
		int max =0;
		for (int i=0;i<=100000;i++) {
			if (result[i]>max) {
				max = result[i];
			}
		}
		System.out.println(max);
	}

	public class Program implements Comparable<Program>{
		int s;
		int t;
		int c;
		@Override
		public int compareTo(Program o) {
			if (this.c!=o.c)
				return this.c-o.c;
			return this.s-o.s;
		}

	}

}

Measured memory_bytes: 97612
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;


//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

int main() {
	ll A, B; cin >> A >> B;
	cout << A * B << endl;
}

Measured memory_bytes: 11024
from collections import deque
N, M = map(int, input().split())
table = []
for i in range(N):
    table.append([])
for i in range(M):
    Ai, Bi = map(int, input().split())
    table[Ai - 1].append(Bi - 1)
    table[Bi - 1].append(Ai - 1)

cost = [1000000] * N
queue = [0]
counter = 0
cost[0] = 0
answer = [-1] * N
answer[0] = 0
while counter < len(queue):
    current = queue[counter]
    counter += 1

    for n in table[current]:
        if cost[current] + 1 < cost[n]:
            cost[n] = cost[current] + 1
            answer[n] = current
            queue.append(n)
print('Yes')
for a in map(lambda x: x + 1, answer[1:]):
    print(a)



Measured memory_bytes: 36272
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> Pi;
typedef queue<Pi> QPi;
typedef pair<ll, ll> Pll;
typedef queue<Pll> QPll;
typedef vector<vi> Graph;
const int mod = 1000000007;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int n,a;
  cin >> n;
  vi ans(n,0);
  REP(i,n-1) {
    cin >> a;
    ans[a-1]++;
  }
  REP(i,n) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4004
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int d = sc.nextInt();
    int x[] = new int[11];
        x[0]= sc.nextInt();
    
    for(int i=0;i<10;i++){
        System.out.println(r*x[i]-d); 
        x[i+1]=r*x[i]-d;
    }
       
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  string s; cin >> s;
  reverse(all(s));
  int n = s.size();

  ll dp[n+1][13] = {0};
  dp[0][0] = 1;

  int mul = 1;
  rep(i, n){
    int c;
    if(s[i] == '?') c = -1;
    else c = s[i] - '0';

    rep(j, 10){
      if(c != -1 && j != c) continue;
      rep(k, 13){
        dp[i+1][(j*mul+k)%13] += dp[i][k];
        dp[i+1][(j*mul+k)%13] %= MOD;
      }
    }
    mul *= 10;
    mul %= 13;
  }
  std::cout << dp[n][5] << '\n';
}


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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    string S;
    int ans = 0, tmp = 0;
    cin >> S;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C')
            tmp++;
        else
            tmp = 0;
        ans = max(ans, tmp);
    }
    cout << ans;
}

Measured memory_bytes: 256
INF = 1 << 28
def min(a,b); a < b ? a : b; end

N, M = gets.split.map(&:to_i)
K = M.times.map do 
  a,b = gets.split.map(&:to_i)
  keys = gets.split.map(&:to_i).inject(0){|s,i| s | (1 << (i - 1)) }  
  [a, keys]
end

dp = Array.new(1 << N, INF)
dp[0] = 0

K.each do |cost, keys|
  dp.each_index do |open|
    dp[open | keys] = min(dp[open] + cost, dp[open | keys])
  end
end
puts dp[-1] >= INF ? -1 : dp[-1]


Measured memory_bytes: 4092
using System;

namespace myApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            if (line.Length == 2) {
                Console.WriteLine(line);
            } else {
                char[] temp = line.ToCharArray();
                Array.Reverse(temp);
                Console.WriteLine(new string(temp));
            }
        }
    }
}


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

//各桁の和を計算する関数
int f(int n) {
  int sum=0;
  while(n>0){ //ｎが０になるまで処理
    sum += n%10;
    n /= 10;
    }
  return sum;
}

int main(){

  int  N;
  cin >> N;
  if(N % f(N) == 0 ) cout <<"Yes" ;
  else cout << "No";

}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
max_num = a[-1] + 1
cnt = [0] * (max_num)
a.sort()
ans = 0


for i in a:
    cnt[i] += 1

a = set(a)

for k in a:
    for l in range(k * 2, (max_num), k):
        cnt[l] += 1

for m in a:
    if cnt[m] == 1:
        ans += 1
    


print(ans)


Measured memory_bytes: 128528
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void LANCER_SHARK() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

int frq[50];
int main(){
	LANCER_SHARK();
	double n, a, res = 0;
	string str;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a >> str;
		if (str == "JPY") res += a;
		else res += (a*380000.0);
	}
	cout << res;
	cout << endl;
	return 0;
}


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

using namespace std;

#define mod 1000000007
#define sz(c)  (int) c.size()
#define all(c) c.begin(), c.end()
#define tr(container,it) for(__typeof(container.begin()) it = container.begin();it != container.end(); it++)
#define present(s,x) s.find(x) != s.end()
#define cpresent(c,x) find(all(c),x) != c.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,a,b) for(int i=a; i<b;i++)
#define ini(n) scanf("%d",&n)
#define opn printf("\n")

 
#define TRACE
 
#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
 
#else
 
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)    
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif 

typedef pair<int,int> pi;
typedef vector<pi> vp;
typedef vector<vp> vvp;
typedef vector<int> vi;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector< vi > vvi;
typedef priority_queue<int> pq;
typedef priority_queue<int, vi , greater<int> >minpq;
typedef priority_queue<pi,vp,greater<pi> > mpq;

int n,m;
int main(){
	//ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin>>n>>m;
	ll a[1002][3];
	rep(i,n){
		rep(j,3){
			cin>>a[i][j];
		}
	}
	ll ans  = -1e18;	
	for(int i=0; i < 8 ; i++){
		vector<ll>w;
		for(int k = 0 ; k<n; k++){
			int mask1 = 1&i ? -1 : 1;
			int mask2 = 2&i ? -1 : 1;
			int mask3 = 4&i ? -1 : 1;
			w.pb({mask1*a[k][0] + mask2*a[k][1] + mask3*a[k][2]});
			
 		}
		sort(all(w),greater<ll>());
		ll tmp=0;
		for(int x=0; x<m; x++){
			tmp += w[x];
		}
		ans = max(ans,tmp);
	}
	cout<<ans;
}


	

	



Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, c;
    cin >> a >> b >> c;

    if (c - a - b >= 0) {
        if (4 * a * b < (c - a - b) * (c - a - b)) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }

    return 0;
}



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

int main(){
int n;cin>>n;
vector<int> num(n);
for(auto&& itr : num)cin>>itr;
cout<<*max_element(num.begin(),num.end())-*min_element(num.begin(),num.end())<<endl;

return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <sstream>
#include <functional>
#include <algorithm>
using namespace std;

#define mem(a,n) memset(a,n,sizeof(a))
#define memc(a,b) memcpy(a,b,sizeof(b))
#define rep(i,a,n) for(int i=a;i<n;i++) ///[a,n)
#define dec(i,n,a) for(int i=n;i>=a;i--)///[n,a]
#define pb push_back
#define fi first
#define se second
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
typedef unsigned long long ull;
const double PI=acos(-1.0);
const double E=2.718281828459045;
const double eps=1e-3;
const int INF=0x3f3f3f3f;
const int MOD=258280327;
const int N=1e6+5;
const ll maxn=1e6+5;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};
ll cal(ll x)
{
    int ans=0;
    while(x)
    {
        ans+=x%10;
        x/=10;
    }
    return ans;
}
int main()
{
    ll n;
    IO;
    while(cin>>n)
    {
        int tmp=cal(n);
        //int ans=(n-1)*9;
        int cnt=0,a[20];
        int minx=INF;
        while(n)
        {
            a[cnt++]=n%10;
            n/=10;
            minx=min(a[cnt-1],minx);
        }
        int ans=(cnt-1)*9;
        ans+=(a[cnt-1]-1);
        //if(minx<=a[cnt-1])
        //ans+=a[cnt-1]-1;
        //else ans
        ans=max(ans,tmp);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+5,M=4005,mod=1e9+7;
int n,f[M][M],a[N],b[N];
LL fac[M*2],inv[M*2],ans;
LL C(int x,int y) {return fac[y]*inv[x]%mod*inv[y-x];}
LL qpow(LL x,LL y) {LL ret=1; while(y) {if(y&1) ret=ret*x%mod; x=x*x%mod,y>>=1;} return ret;}
int main()
{
	fac[0]=inv[0]=1;
	for(int i=1;i<2*M;++i) fac[i]=fac[i-1]*i%mod;
	inv[2*M-1]=qpow(fac[2*M-1],mod-2);
	for(int i=2*M-2;i>=1;--i) inv[i]=inv[i+1]*(i+1)%mod;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",&a[i],&b[i]);
		f[2001-a[i]][2001-b[i]]+=1;
	}
	for(int i=1;i<=4001;++i)
		for(int j=1;j<=4001;++j)
			(f[i][j]+=f[i-1][j]+f[i][j-1])%=mod;
	for(int i=1;i<=n;++i)
		(ans+=f[a[i]+2001][b[i]+2001]-C(a[i]+a[i],a[i]+b[i]+a[i]+b[i]))%=mod;
	ans=ans*qpow(2,mod-2)%mod;
	printf("%lld",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 64512
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;


int main() {
    ll N; cin>>N;
    vel A(N); rep0(i,N){cin>>A[i];}
    ll Max=0;
    priority_queue<ll> s;
    rep0(i,N){
        s.push(A[i]);
    }
    rep0(i,N){
        if(A[i]==s.top()){
            s.pop();
            cout<<s.top()<<endl;;
            s.push(A[i]);
        }
        else{cout<<s.top()<<endl;}
    }
}


Measured memory_bytes: 4848