akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/dwacon5th-prelims/submissions/3656181
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

ll solve(int n, string &s, int k){
    int idx = 0;
    while(idx < n){
        if(s[idx] == 'D') break;
        ++idx;
    }
    if(idx == n) return 0;
    int j = min(idx+k, n);
    ll score = 0, cnt_c = 0, cnt_m = 0;
    for(int i = idx; i < j; ++i){
        if(s[i] == 'C'){
            score += cnt_m;
            ++cnt_c;
        }
        else if(s[i] == 'M'){
            ++cnt_m;
        }
    }
    ll res = score;
    for(int i = idx+1; i < n; ++i){
        if(s[i] == 'D'){
            int nj = min(i+k, n);
            for(int ii = j; ii < nj; ++ii){
                if(s[ii] == 'C'){
                    score += cnt_m;
                    ++cnt_c;
                }
                else if(s[ii] == 'M'){
                    ++cnt_m;
                }
            }
            res += score;
            j = nj;
        }
        else if(s[i] == 'C'){
            --cnt_c;
        }
        else if(s[i] == 'M'){
            score -= cnt_c;
            --cnt_m;
        }
    }
    return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, q;
    string s;
    cin >> n >> s >> q;
    rep(i,q){
        int k;
        cin >> k;
        cout << solve(n, s, k) << endl;
    }
	return 0;
}

Measured memory_bytes: 4240
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int n = nextInt();
    int m = nextInt();
    int[] a = new int[m];
    int sum = 0;
    for(int i=0;i<m;i++){
      a[i] = nextInt();
      sum += a[i];
    }

    if(sum>n){
      System.out.println("-1");
    }
    else{
      System.out.println(n-sum);
    }

    //System.out.println();

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 41320
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  while (n % 111 != 0) ++n;
  cout << n << endl;
  return 0;
}

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


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

int main(){
    int n, ans;
    int v[20];
    int c[20];

    cin >> n;

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

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

    for(int i = 0; i < n; i++){
        if(v[i] > c[i]){
            ans += v[i] - c[i];
        }
    }

    cout << ans << endl;
}

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

int main() {
  int N,M,S=0;
  cin>>N>>M;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    S+=A.at(i);
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  if(S%(4*M)==0){
  if(A.at(M-1)<S/(4*M)){
    cout<<"No"<<endl;
  }
  
    else{
      cout<<"Yes"<<endl;
    }
  }
  else{
    if(A.at(M-1)<S/(4*M)+1){
    cout<<"No"<<endl;
  }
  
    else{
      cout<<"Yes"<<endl;
    }
  }
}

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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int main()
{
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    int c1 = abs(A1 - A2);
    int c2 = abs(A2 - A3);
    int c3 = abs(A3 - A1);
    cout << c1 + c2 + c3 - max({c1, c2, c3}) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    int n, m = -1, k = 1000000010, t;
    bool d = false;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (m < a[i]) {
            m = a[i];
            d = false;
        }
        else if (m == a[i]) {
            d = true;
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (a[i] == m && !d) continue;
        int l = abs(m / 2 - a[i]);
        if (k > l) {
            k = l;
            t = a[i];
        }
    }
    cout << m << " " << t << endl;
    return 0;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))

t = True
x = -1

while t == True:
  x += 1
  for i in a:
    if i%2 == 0:
      continue
    else:
      t = False
  a = list(map(lambda x:x/2, a))  

      
print(x)

Measured memory_bytes: 9240
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int n;cin>>n;
    vector<long long> a(2*n);
    for(int i=0;i<2*n;++i)cin>>a[i];
    sort(a.begin(),a.end());
    long long res = 0;
    for(int i=0;i<n;++i)res+=a[2*i];
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

import sys
sys.setrecursionlimit(4100000)
rl = sys.stdin.readline

T = list(input())

for i in range(len(T)):
    if T[i] == '?':
        T[i] = 'D'
print(''.join(T))

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   string s;
   cin >> s;
   cout << count(s.begin(), s.end(), '1') << endl;

   return 0;
}

Measured memory_bytes: 764
import itertools

N = int(input())
L = list(map(int, input().split()))
L.sort()
#print(L)

C = [0] * (L[-1] + 1)
num_list = []
for key, group in itertools.groupby(L):
    C[key] = len(list(group))
    num_list.append(key)

C_sum = list(itertools.accumulate(C))

ans = 0
for idx, a in enumerate(num_list):
    for b in num_list[idx:]:
        m = max(b - a + 1, L[0], b)
        M = min(b + a - 1, L[-1])
        val = 0
        if a == b and m == b:
            val = (C[a] * (C[a] - 1) * (C[a] - 2) // 6) + (C[a] * (C[a] - 1) // 2) * (C_sum[M] - C_sum[m])
        elif a == b and m > b:
            val = (C[a] * (C[a] - 1) * (C[a] - 2) // 6) + (C[a] * (C[a] - 1) // 2) *(C_sum[M] - C_sum[m] + C[m])
        elif a < b and m == b:
            val = C[a] * (C[b] * (C[b] - 1) // 2 + C[b] * (C_sum[M] - C_sum[m]))
        elif a < b and m > b:
            val = C[a] * (C[b] * (C_sum[M] - C_sum[m] + C[m]))

        #print('a={}, b={} --> {}<=c<={}, so +{}'.format(a, b, m, M, val))
        ans += val
print(ans)

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

int main()
{
	std::set<long> s;
	long n, m;

	cin >> n;

	for (long i = 0; i < n; i++) {
		long t;
		cin >> t;
		s.insert(t);
	}

	cin >> m;

	for (long i = 0; i < m; i++) {
		long t;
		cin >> t;
		if (s.find(t) != s.end())
			s.erase(t);
	}

	for (std::set<long>::iterator itr = s.begin(); itr != s.end(); itr++)
		cout << *itr << endl;

	return 0;
}


Measured memory_bytes: 12468
#![allow(unused)]

use proconio::{input, fastout};
use proconio::marker::{Chars, Usize1};

#[fastout]
fn main() {
    input! {
        n: usize,
    }

    let mut f = vec![1; n + 1];
    for i in 2..=n {
        for j in 1..=(n / i) {
            f[i * j] += 1;
        }
    }

    let mut ans = 0;
    for i in 1..=n {
        ans += i * f[i];
    }
    println!("{}", ans);
}



Measured memory_bytes: 80172
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    string a, b, c; cin >> a >> b >> c;
    string ans;
    ans += a[0]; ans += b[0]; ans += c[0];
    cout << ans << endl;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,k; string s; cin>>n>>k>>s;
	vector<int>one(1,0),zero(1,0);
	if(s.front()=='0')one.emplace_back(0);
	for(int i=0;i<s.size();){
		int cnt=0; char c=s.at(i);
		while(i<s.size()&&s.at(i)==c)++i,++cnt;
		if(c=='1')one.emplace_back(cnt);
		else zero.emplace_back(cnt);
	}
	for(int i=1;i<one.size();++i)one.at(i)+=one.at(i-1);
	for(int i=1;i<zero.size();++i)zero.at(i)+=zero.at(i-1);
	if(s.back()=='0')one.emplace_back(one.back());
	int ans=0;
	for(int i=min(k,(int)zero.size()-1),base=i;i<zero.size();++i){
		ans=max(ans,one.at(i+1)-one.at(i-base)+zero.at(i)-zero.at(i-base));
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    string s;
    cin >> s;
    bool f = s[0] == s[1] && s[1] == s[2];
    bool g = s[1] == s[2] && s[2] == s[3];
    cout << (f || g ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;


int main() {
	string s;
	cin >> s;
	if (s[6]>'4'||s[5]>'0') {
		cout << "TBD" << endl;
	}
	else {
		cout << "Heisei" << endl;
	}
}


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

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end() 
#define mod 1000000007
#define maxx 200006
#define ll long long 
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long > 
#define listi vector< int> 
#define pii   pair<int , int> 
#define pll pair<long long , long long > 
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

// end of #define 

// define globals ...


//write function from here ...



int Main(){

 
 int n;
 int ans=0;
 cin>>n;
 for(int i=1;i<=n;i++){

  ll a;
  cin>>a;
  if(i%2==1 && a%2==1){
    ans++;

  } 
 }

 cout<<ans;










return 0;

}

















int main(){
 quick;



 Main();

 return 0;


}

Measured memory_bytes: 3564
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll N, W;
vector<pair<ll, ll>> v;
ll dp[101][100001];
ll solve(int i, ll w)
{
    if (i == 0)
    {
        if (w - v[i].first < 0)
        {
            return 0L;
        }
        else
        {
            return v[i].second;
        }
    }
    if (dp[i][w] != -1)
        return dp[i][w];

    ll take = 0, donttake = 0;
    if (w - v[i].first >= 0)
    {
        take = v[i].second + solve(i - 1, w - v[i].first);
    }
    donttake = solve(i - 1, w);
    return dp[i][w] = max(take, donttake);
}
int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> N >> W;
    v.resize(N, make_pair(0, 0));
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < N; i++)
    {
        cin >> v[i].first >> v[i].second;
    }
    cout << solve(N - 1, W) << endl;
}

Measured memory_bytes: 79232
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  string s;
  cin>>s;
  int l=s.length();
  ll a[l],b[l];
  a[0]=3; b[0]=2;
  rep(i,l-1){
    if(s[i+1]=='1'){
      a[i+1]=(3*a[i])%modbig;
      b[i+1]=(2*b[i])%modbig;
    }else{
      a[i+1]=(3*a[i]-2*b[i]+2*modbig)%modbig;
      b[i+1]=b[i]%modbig;
    }
  }
  cout<<a[l-1];
}


Measured memory_bytes: 2048
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    bool b = (lread() % 500) <= lread();
    writeln(b ? "Yes" : "No");
}


Measured memory_bytes: 256
/********************************************************
  **░██████╗██╗░░░░░░█████╗░██╗░░░██╗██╗░█████╗░░██████╗░**
  **██╔════╝██║░░░░░██╔══██╗██║░░░██║██║██╔══██╗██╔════╝░**
  **╚█████╗░██║░░░░░███████║╚██╗░██╔╝██║██║░░╚═╝██║░░██╗░**
  **░╚═══██╗██║░░░░░██╔══██║░╚████╔╝░██║██║░░██╗██║░░╚██╗**
  **██████╔╝███████╗██║░░██║░░╚██╔╝░░██║╚█████╔╝╚██████╔╝**
  **╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░╚════╝░░╚═════╝░**
  *********************************************************/

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


#define ll                          long long
#define ld                          long double

#define forn(i,n)                   for(int i=0;i<n;++i)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend();
#define isSubstring(s1,s2)          s1.find(s2) != std::string::npos
	
#define pb                          push_back
#define pf                          push_front
#define mp                          make_pair
#define fr                          first
#define sc                          second

#define vpi                         vector<pair<int,int>>
#define vi                          vector<int>
#define sz(a)                       (int)a.size()

#define   endl                       "\n"
#define     nl                       cout<<"\n";
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define MN                           INT_MIN
#define MX                           INT_MAX

bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);}

int32_t main()
{
	int n;
	string s;
	cin >> n >> s;
	if(n&1){
		cout << "No\n";
		return 0;
	}
	bool ok = true;
	for(int i =0;i<n/2;i++)
	{
		if(s[i] != s[i+n/2])
			ok = false;
	}
	cout << (ok ? "Yes\n" : "No\n");
}
	

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
int a, b, c; 
int main()
{
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << ' ' << b << ' ' << c << endl; 
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int bubbleSort(int *A, int N)
{
	int flag, i, j, t, count = 0;

	flag = 1;
	while (flag) {
		flag = 0;
		for (j = N - 1; j > 0; j--) {
			if (A[j] < A[j - 1]) {
				t = A[j];
				A[j] = A[j - 1];
				A[j - 1] = t;
				count++;
				flag = 1;
			}
		}
	}

	return count;
}

int main(void)
{
	int N, A[100], i, c;

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	c = bubbleSort(A, N);
	printf("%d", A[0]);
	for (i = 1; i < N; i++) {
		printf(" %d", A[i]);
	}
	printf("\n%d\n", c);

	return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N;cin>>N;
    int A;cin>>A;
    int B;cin>>B;
    int a;
    int b;
    int c;
    int d;
    int e;
    int output=0;
    for(int i=1;i<=N;i++){
        a=0;b=0;c=0;d=0;e=0;
        a=i%10;
        b=(i/10)%10;
        c=(i/100)%10;
        d=(i/1000)%10;
        e=(i/10000)%10;
        if(a+b+c+d+e>=A&&a+b+c+d+e<=B){
            output=output+i;
        }
    }
    
    


    cout<<output<<endl;
    return 0;
    
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
  for(int i=0; i<s.size(); i++) {
    for(int j=0; j<26; j++) {
      if(s.at(i) == a.at(j)) {
        cout << a.at((j+n)%26);
        continue;
      }
    }
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T = int>T in() { T x; cin >> x; return x; }
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(),(obj).end()

using arll3 = array<long long, 3>;
bool comp0(const arll3&arg1, const arll3&arg2) { return +arg1[0] + arg1[1] + arg1[2] > +arg2[0] + arg2[1] + arg2[2]; }
bool comp1(const arll3&arg1, const arll3&arg2) { return +arg1[0] + arg1[1] - arg1[2] > +arg2[0] + arg2[1] - arg2[2]; }
bool comp2(const arll3&arg1, const arll3&arg2) { return +arg1[0] - arg1[1] + arg1[2] > +arg2[0] - arg2[1] + arg2[2]; }
bool comp3(const arll3&arg1, const arll3&arg2) { return +arg1[0] - arg1[1] - arg1[2] > +arg2[0] - arg2[1] - arg2[2]; }
bool comp4(const arll3&arg1, const arll3&arg2) { return -arg1[0] + arg1[1] + arg1[2] > -arg2[0] + arg2[1] + arg2[2]; }
bool comp5(const arll3&arg1, const arll3&arg2) { return -arg1[0] + arg1[1] - arg1[2] > -arg2[0] + arg2[1] - arg2[2]; }
bool comp6(const arll3&arg1, const arll3&arg2) { return -arg1[0] - arg1[1] + arg1[2] > -arg2[0] - arg2[1] + arg2[2]; }
bool comp7(const arll3&arg1, const arll3&arg2) { return -arg1[0] - arg1[1] - arg1[2] > -arg2[0] - arg2[1] - arg2[2]; }
int main()
{
	const int n = in(), m = in();
	vector<arll3>xyz(n);
	REP(i, n)cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
	long long ans = 0;
	for (auto c : { comp0, comp1, comp2, comp3, comp4, comp5, comp6, comp7 })
	{
		sort(ALL(xyz), c);
		long long sum[3] = { 0,0,0 };
		REP(i, m)REP(j, 3)sum[j] += xyz[i][j];
		const long long ans_tmp = abs(sum[0]) + abs(sum[1]) + abs(sum[2]);
		if (ans < ans_tmp)ans = ans_tmp;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static Stack<Double>stack = new Stack<Double>();
    static String[] input;
    public static void main(String[] args) {
        while(read()){
            solve();
        }

    }

    static boolean read(){
        if(!sc.hasNext())return false;
        input = sc.nextLine().split(" ");
        return true;
    }

    static void solve(){
        for(int i = 0; i < input.length; i++){
            String item = input[i];
            double a = 0, b = 0;
            if(item.equals("+")){
                b = stack.pop();
                a = stack.pop();
                stack.push(a+b);
            }else if(item.equals("-")){
                b = stack.pop();
                a = stack.pop();
                stack.push(a-b);
            }else if(item.equals("*")){
                b = stack.pop();
                a = stack.pop();
                stack.push(a*b);
            }else if(item.equals("/")){
                b = stack.pop();
                a = stack.pop();
                stack.push(a/b);
            }else{
                stack.push(Double.parseDouble(item));
            }
        }
        System.out.printf("%.6f\n", stack.pop());
    }

}

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

public class Main {
	public static long N;
	public static long[] A;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextLong();
		A = new long[(int) N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
		}
		Arrays.sort(A);

		long score = A[(int) N - 1];
		long idx = N - 2;
		boolean second = false;
		for (int i = 2; i < N; i++) {
			score += A[(int) idx];
			if (second)
				idx--;
			second = !second;
		}
		System.out.println(score);
	}
}


Measured memory_bytes: 61268
N,_,W = map(int, input().split())
A = [int(i) for i in input().split()]

if N == 1:
    ans = abs(A[0] - W)
else:
    # 1枚残す場合
    ans = abs(A[-1] - A[-2])
    # 0枚残す場合
    ans = max(ans, abs(A[-1] - W))

print(ans)

Measured memory_bytes: 3188
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 29996224275833
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
// int mI(int a, int m)  {return power(a, m - 2, m);}
// vector<vector<int>> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1},{1,1},{1,-1},{-1,1},{-1,-1}};

string s;
int n ;
int k;
int dp[101][28][28];
int fun(int i,int last,int fi){
    //db3(i, last, fi);
    if(i>=n)
        return 0;
    if(i==n-1){
        if(s[i]-'a'==last)
            return k;
        else if(s[i]-'a'==fi)
            return k - 1;
        else
            return 0;
    }
    if(dp[i][last][fi]!=-1)
        return dp[i][last][fi];
    int ans = 1e15;
    fo(j, 26)
    {
        if (j != last)
        {
            if (i == 0)
                fi = j;
            if (s[i] - 'a' == j)
                ans = min(ans, fun(i + 1, j, fi));
            else
                ans = min(ans, k + fun(i + 1, j, fi));
        }
    }
    return dp[i][last][first]=ans;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s;
    cin >> k;
    n = s.size();
    memset(dp, -1, sizeof(dp));
    int g = 0;
    foo(i,1,n){
        if(s[i]!=s[i-1]){
            //db1(i);
            g = 1;
        }
    }
    if(g==0){
        //deb(n);
        cout << (n*k)/2;
    }
    else
        cout << fun(0, 27, 0);

}
    


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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define int long long

signed main(){

  int n,mm,sum=0;
  cin >> n >> mm;
  vector<int> xx(n),yy(n),zz(n);
  vector<int> v(n);
  rep(i,n){
    cin >> xx[i] >> yy[i] >> zz[i];
  }
  rep(m,8){
    int xs = (m & 0x0004)/4;
    int ys = (m & 0x0002)/2;
    int zs = (m & 0x0001)/1;
    rep(i,n){
        v[i] = (long long)(xx[i]*pow(-1,xs)+yy[i]*pow(-1,ys)+zz[i]*pow(-1,zs));
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    long long summ=0;
    rep(i,mm){
        summ+=v[i];
    }
    if (sum<summ)sum=summ;
  }
  cout << sum << endl;


  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
inline int getint() {
    int r = 0; char c = getchar(); bool b = true;
    while (c < '0' || c > '9') { if (c == '-') b = false; c = getchar(); }
    while (c >= '0' && c <= '9') { r = (r<<1)+(r<<3) + c - '0'; c = getchar(); }
    return b ? r : -r;
}
int n, a[200005];
int main() {
    n = getint();
    for (int i = 0; i < n; ++i)
        a[i] = getint() - i;
    nth_element(a, a + (n / 2), a + n);
    LL b = a[n / 2];
    LL ans = 0ll;
    for (int i = 0; i < n; ++i)
        ans += abs(b - LL(a[i]));
    printf("%lld", ans);
}

Measured memory_bytes: 896
# arr=input().strip().split(' ')
def aa():
    x,n=[int(i) for i in input().strip().split(' ')]
    if n==0:
        print(x)
        return 
    arr=[int(i) for i in input().strip().split(' ')]
    # neg,pos=[],[]
    # for i in arr:
    # 	if x-i >0 :
    # 		pos.append(x-i)
    # 	else:
    # 		neg.append(i-x)
    # pos=sorted(pos)
    # neg=sorted(neg)
    
    diff=[]
    for i in arr:

        diff.append(x-i)
    i=-1
    j=0
    while i in diff:
        i=i-1
    while j in diff:
        j=j+1
    if abs(i)<abs(j):
        print(x-i)
    else:
        print(x-j)
    # print(x+)
aa()

Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s1,s2;
  cin>>s1>>s2;
  for(int i=0;i<s1.size();i++) {
    if(s1[i] != s2[i]) {
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
}


Measured memory_bytes: 3580
import java.io.InputStream
import java.io.BufferedReader

fun main(args: Array<String>) {
  val inputStream = System.`in`
  val allText = inputStream.bufferedReader()
                           .use(BufferedReader::readText)
  allText.trim().split('\n')
         .map { s->
            s.split(' ').map{ Integer.parseInt(it) }.sum().toString().length
         }
  .forEach{ println(it) }
}


Measured memory_bytes: 31924
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main() {
    int N , M;
    cin >> N >> M;
    vector<int> A(N);
    int total = 0;
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        total += A.at(i);
    }
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (total <= A.at(i) * 4 * M) {
            cnt++;
        }
    }
    if (cnt >= M) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k;

int main(){
  ll ans=0;
  cin >> k >> n;
  vi a(n),b(n);
  REP(i,n) cin>>a[i];
  sort(a.begin(), a.end());
  ll a0=a[0];
  REP(i,n){
    a[i]-=a0;
  }
  REP(i,n-1){
    b[i]=a[i+1]-a[i];
  }
  b[n-1]=k-a[n-1];

  REP(i,n){
    ans=max(ans,b[i]);
  }

  cout<<(k-ans)<<endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

struct edge {
    int from, to, diff, score;
    edge(int f, int t, int d, int s) : from(f), to(t), diff(d), score(s) {}
};

int N, M, Q;
vector<edge> es;

int dfs(vector<int> &A) {
    int ret = 0;

    if (A.size() == N) {
        for (auto e : es) {
            if (A[e.to] - A[e.from] == e.diff) {
                ret += e.score;
            }
        }
        return ret;
    }

    int prev = A.empty() ? 1 : A.back();
    for (int i = prev; i <= M; ++i) {
        A.emplace_back(i);
        chmax(ret, dfs(A));
        A.pop_back();
    }

    return ret;
}
int main() {
    cin >> N >> M >> Q;
    rep(i, Q) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        --a;
        --b;
        es.emplace_back(a, b, c, d);
    }
    vector<int> A;
    cout << dfs(A) << endl;
}

Measured memory_bytes: 3492
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()

using ll = long long;

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

    int a;
    bool ans = true;
    rep(i, n) { 
        cin >> a;

        if(a % 2 == 0) {
            if(a % 3 == 0 || a % 5 == 0) {
            }
            else {
                ans = false;
            }
        }
    }

    if(ans) {
        cout << "APPROVED" << endl;
    }
    else {
        cout << "DENIED" << endl;
    }
    
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
bool compare(const pii& v1, const pii& v2){
	return v1.s < v2.s;
}
lli solve(){
	lli n, w;
	cin>>n>>w;
	vector<pii> S(n);
	lli sum = 0;
	loop(i, 0, n){
		cin>>S[i].f>>S[i].s;
		sum += S[i].s;
	}
	vector<vll> dp(n+1, vll (sum+1, 1e15));
	loop(i, 0, n+1)
		dp[i][0] = 0;
	sort(S.begin(), S.end(), compare);
	lli ans = 0;
	loop(i, 1, n+1){
		loop(j, 1, sum+1){
			if(j < S[i-1].s)
				dp[i][j] = dp[i-1][j];
			else{
				lli temp = dp[i-1][j];
				if(temp == 0)	
					temp = 1e15;
				dp[i][j] = min(	temp, dp[i-1][j-S[i-1].s] + S[i-1].f);
			}
			if(w >= dp[i][j] && dp[i][j] != 0)
				ans = max(ans, j);
		}
	}
	cout<<ans<<"\n";
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

i32 k,t, tmp, dif, past, length;
maxheap<i32> a;
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    cin >> k >> t;
    rep(i,t) {
        cin >> tmp;
        a.push(tmp);
    }

    past = a.top(); a.pop();
    while(a.size()) {
        i32 dif = abs(past-a.top());
        length += min(past, a.top())*2;
        a.pop();
        past = dif;
    }
    cout << max(k - length - 1, (i32)0) << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <cassert>
#include <cfloat>
#include <climits>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ull;

int main() {
	ull H, W, N;
	cin >> H >> W >> N;
	ull res[10];
	for (int i = 0; i < 10; i++) {
		res[i] = 0;
	}

	res[0] = (H - (ull)2)*(W - (ull)2);
	ull a, b;
	map<ull, int> mp;
	int t;
	for (int i = 0; i < N; i++) {
		cin >> a>> b;
		for (ull x = -1; x <= 1; x++) {
			for (ull y = -1; y <= 1; y++) {
				if (a + x > 1 && a + x < H) {
					if (b + y > 1 && b + y < W) {
						t = mp[(a + x) * (ull)1000000007 + (b + y)];
						res[t]--;
						res[t + 1]++;
						mp[(a + x) * (ull)1000000007 + (b + y)] = t + 1;
					}
				}
			}

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

Measured memory_bytes: 56448
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {

  string a,b;
  cin>>a>>b;
  if(a>b)cout<<">\n";
  else if (a==b)cout<<"=\n";
  else cout<<"<\n";


  return 0;
}


Measured memory_bytes: 256
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s: Vec<char> = s.trim().chars().collect();
    let mut ans = 0;
    for i in 1..s.len() {
        if s[i] != s[i - 1] {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

using ld = double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;

ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); }
ld dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }

using C = pair<ld, P>;
#define rad first
#define pnt second

C smallest_enclosing_disc(vector<P> ps){
    auto c3 = [](const P &a, const P &b, const P &c){
        ld A = norm(b - c);
        ld B = norm(c - a);
        ld C = norm(a - b);
        ld S = abs(cross(b - a, c - a));
        P p = (A*(B+C-A)*a + B*(C+A-B)*b + C*(A+B-C)*c) / (4*S*S);
        ld r = abs(p - a);
        return make_pair(r, p);
    };

    auto c2 = [](const P &a, const P &b){
        P c = (a + b) / (ld)2;
        ld r = abs(a - c);
        return make_pair(r, c);
    };

    auto in_circle = [](const P &a, const C &c){
        return norm(a - c.pnt) <= c.rad*c.rad + eps;
    };

    int n = ps.size();
    random_shuffle(ps.begin(), ps.end());
    C c = c2(ps[0], ps[1]);
    for(int i = 2; i < n; ++i){
        if(!in_circle(ps[i], c)){
            c = c2(ps[0], ps[i]);
            for(int j = 1; j < i; ++j){
                if(!in_circle(ps[j], c)){
                    c = c2(ps[j], ps[i]);
                    for(int k = 0; k < j; ++k){
                        if(!in_circle(ps[k], c)){
                            c = c3(ps[i], ps[j], ps[k]);
                        }
                    }
                }
            }
        }
    }
    return c;
}

// http://www.spoj.com/problems/QCJ4/
// http://www.spoj.com/status/ns=18116289

// int main(){
//     srand(time(0));
//     int n;
//     cin >> n;
//     vector<P> ps(n);
//     for(int i = 0; i < n; ++i){
//         ld x,y;
//         cin >> x >> y;
//         ps[i] = P(x,y);
//     }

//     printf("%.2lf\n", (double)smallest_enclosing_disc(ps).rad*2);
// }


int n,m;
ld r[111], mb[111];

bool used[111];

bool chk(int s){
    vector<int> b;
    rep(i,n)if(!used[i]) b.emplace_back(r[i]);
    vector<ld> a;
    for(int i = s; i < m; ++i) a.emplace_back(mb[i]);
    sort(all(a));
    sort(all(b));
    int last = -1;
    rep(i,a.size()){
        bool found = false;
        for(int j = last+1; j < (int)b.size(); ++j){
            if(a[i] < b[j] + eps){
                found = true;
                last = j;
                break;
            }
        }
        if(!found)return false;
    }
    return true;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(10)<<fixed;
    cin >> n ;
    G g(n);
    rep(i,n){
      ld x,y;
      cin >> x >> y;
      g[i] = P(x,y);
    }
    ld ans = smallest_enclosing_disc(g).rad;
    cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll N, M; cin >> N >> M;
    vvll v(N);
    rep(i, M) {
        ll a, b; cin >> a >> b; a--, b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    queue<pair<ll, ll>> que; // node number, distance
    que.push({0, 0});
    vector<bool> visited(N, false);
    vll distances(N, inf);
    distances[0] = 0;
    visited[0] = true;
    vll ans(N);
    while (que.size()) {
        auto _ = que.front(); que.pop();
        ll node = _.first, distance = _.second;
        visited[node] = true;
        for (auto nnode : v[node]) {
            if (visited[nnode]) continue;

            if (distances[nnode] > distance + 1) {
                distances[nnode] = distance + 1;
                ans[nnode] = node + 1;
                que.push({nnode, distance + 1});
            }
        }
    }

    cout << "Yes" << endl;
    reprr(i, 1, N) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 14432
// Example program
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;


int main()
{
 int x;
 int n=1;
 

 while ( cin >> x && x!=0 )
 {
 	cout << "Case " << n << ": " << x << endl;
 	n++;
 }
}

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

bool answer(string &s){
  if(s=="") return true;
  
  int l=s.size();
  if(s.at(l-1)=='m'&&s.at(l-2)=='a'&&s.at(l-3)=='e'&&s.at(l-4)=='r'&&s.at(l-5)=='d') return answer(s.erase(l-5));
  if(s.at(l-1)=='e'&&s.at(l-2)=='s'&&s.at(l-3)=='a'&&s.at(l-4)=='r'&&s.at(l-5)=='e') return answer(s.erase(l-5));
  if(s.at(l-1)=='r'&&s.at(l-2)=='e'&&s.at(l-3)=='s'&&s.at(l-4)=='a'&&s.at(l-5)=='r'&&s.at(l-6)=='e') return answer(s.erase(l-6));
  if(s.at(l-1)=='r'&&s.at(l-2)=='e'&&s.at(l-3)=='m'&&s.at(l-4)=='a'&&s.at(l-5)=='e'&&s.at(l-6)=='r'&&s.at(l-7)=='d') return answer(s.erase(l-7));
  return false;
}

int main() {
  string s;
  cin >> s;
  if(answer(s)) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

#define ll long long
#define scan(x) scanf("%lld",&x)
#define pb push_back
#define mp make_pair

using namespace std;

ll value[21],cost[21];


int main()
{
    ll i,j,k,x,l,m,n;
    cin >> n;
    for(i=0;i<n;i++)
        cin >> value[i];

    ll ans=0;
    for(i=0;i<n;i++)
    {
        cin >> x;
        if(x< value[i])
            ans+= value[i]-x;
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <queue>

int n;
static const int nmax = 20005;
static const int INFTY = (1<<21);
static const int WHITE = 0; // Not visited
static const int GRAY = 1;  // Visited
static const int BLACK = 2; // In MST
using pair = std::pair<int, int>;
std::array<std::vector<pair>, nmax> adjlist;
std::array<int, nmax> d;
std::array<int, nmax> color;

void dijklstra(int s)
{
  color.fill(WHITE);
  d.fill(INFTY);


  auto priority = [](pair x, pair y){return x.second > y.second;};
  std::priority_queue<
    pair,
    std::vector<pair>,
    decltype(priority)
    > pq(priority);

  pq.push(std::make_pair(s, 0));
  color[s] = GRAY;
  d[s] = 0;

  while (!pq.empty())
    {
      auto u = pq.top();
      pq.pop();
      //std::cout << u.first << ' ' << u.second << std::endl;
      if (d[u.first] < u.second)
        continue;

      color[u.first] = BLACK;
      d[u.first] = u.second;

      for (int i=0; i<adjlist[u.first].size(); ++i)
        {
          auto v = adjlist[u.first][i];
          if ( (color[v.first] != BLACK) && ((d[u.first] + v.second) < d[v.first]))
            {
              d[v.first] = d[u.first] + v.second;
              color[v.first] = GRAY;
              pq.push(std::make_pair(v.first, d[v.first]));
            }
        }
    }


}

void print_distance(int v)
{
  dijklstra(v);

  for (int i=0; i<n; ++i)
    {
      std::cout << i << " " << d[i] << std::endl;
    }
}

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

  for (int i=0; i<n; ++i)
    {
      int u, k;
      std::cin >> u >> k;
      for (int j=0; j<k; ++j)
        {
          int v, c;
          std::cin >> v >> c;
          adjlist[u].push_back(std::make_pair(v, c));
        }
    }

  print_distance(0);
}



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

const int DIM = 2005;

char mat[DIM][DIM];
int psm1[DIM][DIM], hor[DIM][DIM];
int psm2[DIM][DIM], ver[DIM][DIM];

int main(void)
{
    int n, m, q;
    cin >> n >> m >> q;
    
    for (int i = 1; i <= n; ++i) {
        cin >> (mat[i] + 1);
        
        for (int j = 1; j <= m; ++j) {
            psm1[i][j] = psm1[i - 1][j] + psm1[i][j - 1] - psm1[i - 1][j - 1] + (mat[i][j] == '1');
            psm2[i][j] = psm2[i - 1][j] + psm2[i][j - 1] - psm2[i - 1][j - 1] + (mat[i][j] == '1') * ((mat[i - 1][j] == '1') + (mat[i][j - 1] == '1'));
            
            ver[i][j] = ver[i - 1][j] + (mat[i][j] == '1' and mat[i - 1][j] == '1');
            hor[i][j] = hor[i][j - 1] + (mat[i][j] == '1' and mat[i][j - 1] == '1');
        }
    }
    
    for (int i = 1; i <= q; ++i) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        
        int v1 = psm1[x2][y2] - psm1[x1 - 1][y2] - psm1[x2][y1 - 1] + psm1[x1 - 1][y1 - 1],
            v2 = psm2[x2][y2] - psm2[x1][y2] - psm2[x2][y1] + psm2[x1][y1],
            v3 = hor[x1][y2] - hor[x1][y1], v4 = ver[x2][y1] - ver[x1][y1];
        
        cout << v1 - v2 - v3 - v4 << "\n";
    }
    
    return 0;
}

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

int main() {
  string a, b;
  cin >> a >> b;
  if ((a=="H"&&b=="H")||(a=="D"&&b=="D")) {
    cout << "H" << endl;
  } else {
    cout << "D" << endl;
  }
  return 0;
}

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

#define INF 1e9
using namespace std;
using ll = long long;

int main() {

    ll N; cin >> N;

    map<string, ll> s;

    for (int i = 0; i < N; ++i) {
        string str;
        cin >> str;

        sort(str.begin(), str.end());

        if (s.count(str) == 1) {
            s[str] += 1;
        } else {
            s[str] = 1;
        }
    }

    ll ans = 0;

    for (auto item : s) {
        ans += (item.second * (item.second - 1)) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 11136
# -*- coding: utf-8 -*-
# abc132/abc132_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    d = i2nn()
    d.sort()
    before_half = d[int(N / 2 - 1)]
    after_half = d[int(N / 2)]
    print(after_half - before_half)
    return

main()


Measured memory_bytes: 14900