akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

struct info{
    int ci;
    int pref;
    int year;
    string id="";
    info(int i, int p, int y){
        ci = i;
        pref = p;
        year = y;
    }
};

bool comp1(const info &a, const info &b){
    if(a.pref==b.pref){
        return a.year < b.year;
    }
    else
        return a.pref < b.pref;
}

bool comp2(const info &a, const info &b){
    return a.ci < b.ci;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<info> A;
    REP(i,m){
        int p, y;
        cin >> p >> y;
        string s;
        A.push_back(info(i, p, y));
    }
    sort(ALL(A), comp1);
    int order=0;
    int past=-1;
    for(int i=0; i<m; i++){
        if(A[i].pref==past)
            order+=1;
        else
            order = 1;

        string s1;
        REP(j,6-to_string(A[i].pref).size()) s1.append("0");
        s1.append(to_string(A[i].pref));

        string s2;
        REP(j,6-to_string(order).size()) s2.append("0");
        s2.append(to_string(order));
        A[i].id = s1 + s2;
        past = A[i].pref;
    }
    sort(ALL(A), comp2);

    for(auto x : A)
        cout << x.id<< endl;
    return 0;
}

Measured memory_bytes: 7152
import sys
def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = [0 for i in range(10**5+1)]
    sa = sum(a)
    for i in a:
        s[i] += 1
    q = int(input())
    for x in sys.stdin.readlines():
        b, c = map(int, x.split())
        s[c] += s[b]
        sa = sa + (c-b)*s[b]
        s[b] = 0
        print(sa)

main()

Measured memory_bytes: 21176
#!/usr/bin/env ruby
n = gets.chomp.to_i
s = gets.chomp

ans = 0
0.upto(9) do |i|
  first_i = s.chars.find_index(i.to_s)
  next if first_i.nil?
  0.upto(9) do |j|
    new_s = s[(first_i+1)..-1]
    first_j = new_s.chars.find_index(j.to_s)
    next if first_j.nil?
    0.upto(9) do |k|
      new_new_s = new_s[(first_j+1)..-1]
      first_k = new_new_s.chars.find_index(k.to_s)
      next if first_k.nil?
      ans += 1
    end
  end
end

puts ans


Measured memory_bytes: 21748
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int main(){
	char a[15];
	int n, m, i, j;
	while(~scanf("%s", a)){
		int b[20];
		int str = strlen(a);
		j = 0;
//		printf("%s %d\n", a, str);
		for(i = 0; i < str; i++){
			if(a[i] == '0')  b[j++] = 2;
			if(a[i] == '1')  b[j++] = 1;
			if(a[i] == 'B' && j != 0){
				j--;
				b[j] = 0;
		   }
		}
//		for(i = 0; i < j; i++) printf("%d*" , b[i]);
		if(j > 0)
		for(i = 0; i < j; i++){
			if(b[i] == 2)  printf("0");
			if(b[i] == 1)  printf("1");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>

using namespace std;

int d,g;
int p[11][2];
int minn = 1000;

int getCnt(int bonus)
{
    int ncnt = 0;
    int point = 0;
    for(int i=0; i<d; i++)
    {
        if(bonus & (1 << i)){
            ncnt += p[i][0];
            point += p[i][1];
            point += 100 * (i + 1) * p[i][0];
        }
    }

    if(point >= g) return ncnt;
    else{
        for(int i=d-1; i>=0; i--)
        {
            if(bonus & (1 << i)) continue;
            for(int j=0; j<p[i][0]; j++)
            {
                point += (i + 1) * 100;
                ncnt++;
                if(point >= g)
                {
                    return ncnt;
                }
            }
        }
    }
    return -1;
}

int main() {

    cin >> d; cin >> g;

    for(int i=0; i<d; i++)
    {
        cin >> p[i][0]; cin >> p[i][1];
    }

    for(int i=0; i<=pow(2, d); i++)
    {
        int cnt = getCnt(i);
        if(cnt > 0) minn = min(cnt, minn);
    }

    cout << minn << endl;

    return 0;
}

Measured memory_bytes: 512
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    int m;
    cin >> m;
    cout << (24 - m) + 24 << endl;

    return 0;
}



Measured memory_bytes: 632
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		int cnt = 0;
		Scanner sc = new Scanner(System.in);
		int input = 0;
		while((input = sc.nextInt()) != 0) {
			cnt++;
			System.out.println("Case " + cnt + ":" + " " + input);
		}
	}
}

Measured memory_bytes: 45320
s = input()
s_len = len(s)

counter_list = []
for j in range(s_len):
    counter = 0

    for i in range(j, s_len):
        if s[i] == 'A' or s[i]=='T' or s[i]=='G' or s[i]=='C':
            counter += 1
        else:
            break
    counter_list.append(counter)
    
print(max(counter_list))

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

int main() {
    string s,t;
    cin >> s >> t;
    int x=s.size(), y=t.size(), res=-1;
    rep(i,x){
        if(s[i]==t[0] || s[i]=='?'){
            bool ok=true;
            for(int j=i; j<i+y; ++j){
                if((s[j]==t[j-i] || s[j]=='?') && x>=y+i){
                    continue;
                }else{
                    ok=false;
                    break;
                }
            }
            if(ok) res=i;
        }
    }
    if(res==-1){
        cout << "UNRESTORABLE" << "\n";
        return 0;
    }else{
        for(int i=res; i<res+y; ++i) s[i]=t[i-res];
        rep(i,x) if(s[i]=='?') s[i]='a';
        cout << s << "\n";
        return 0;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    
        var sc = new Scanner(System.in);
    
        int D = Integer.parseInt(sc.next());
        var c = new int[27];
        for(int i = 1; i <= 26; i++){
            c[i] = Integer.parseInt(sc.next());
        }
        var s = new int[D+1][27];
        for(int d = 1; d <= D; d++){
            for(int i = 1; i <= 26; i++){
                s[d][i] = Integer.parseInt(sc.next());
            }
        }
    
        var t = new int[D+1];
        for(int d = 1; d <= D; d++){
            t[d] = (d-1)%26+1;
        }
        long maxScore = Long.MIN_VALUE;
        var max = new int[D+1];
        for(int i = 0; i < 26; i++){
            long score = 0;
            var last = new int[27];
            for(int d = 1; d <= D; d++){
                score += s[d][t[d]];
                last[t[d]] = d;
                for(int j = 1; j <= 26; j++){
                    score -= c[j] * (d - last[j]);
                }
            }
            if(score > maxScore){
                maxScore = score;
                max = t.clone();
            }
            t[D]++;
            if(t[D] > 26) t[D] = 1;
        }
        
        var sb = new StringBuilder();
        for(int i = 1; i <= D; i++){
            sb.append(max[i]).append(System.lineSeparator());
        }
        System.out.print(sb);
    }
}

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

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

fn main() {
    let r:usize = read();
    let c:usize = read();
    let mat: Vec<Vec<usize>> = (0..r).map(|_| (0..c).map(|_| read()).collect()).collect();
    let mut colsum = vec![0; c];
    for i in 0..r {
        let mut rowsum:usize = 0;
        for j in 0..c {
            print!("{} ", mat[i][j]);
            colsum[j]  += mat[i][j];
            rowsum  += mat[i][j];
        }
        println!("{}",rowsum);
    }
    let s = colsum.clone().into_iter().map(|x| x.to_string()).collect::<Vec<String>>().join(" ");
    println!("{} {}",s, colsum.iter().sum::<usize>());
}


Measured memory_bytes: 5044
package main

import "fmt"

func main() {
	var n, m, x int
	fmt.Scan(&n, &m, &x)

	var a, l, h int
	for i := 0; i < m; i++ {
		fmt.Scan(&a)

		if a < x {
			l++
		} else {
			h++
		}
	}
	fmt.Println(min(l, h))
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys


def solve(S: str):

    l = [0] * 2019
    ps = 0
    d = 1
    for i in range(1, len(S) + 1):
        ps += int(S[-i]) * d
        l[ ps % 2019 ] += 1
        d = d * 10 % 2019

    ans = 0
    for i in l:
        ans += i * (i - 1) // 2
    
    ans += l[0]
    
    print(ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

int main(){
  string A, B;
  cin >> A >> B;
  int LA = A.size();
  int LB = B.size();
  int temp=0;
  if(LA>LB) cout << "GREATER" << endl;
  else if(LA<LB) cout << "LESS" << endl;
  else{
    for(int i=0; i<LA; i++){
      if(A.at(i)>B.at(i)){
        cout << "GREATER" << endl;
        break;
      }
      else if(A.at(i)<B.at(i)){
        cout << "LESS" << endl;
        break;
      }
      else{
        temp++;
      }
    }
    if(temp==LA) cout << "EQUAL" << endl;
  } 
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    const double PI = acos(-1);
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double minAngle = 2.0 * PI * m / 60.0;
    double hourAngle = 2.0 * PI * (h + m / 60.0) / 12.0;
    double diff = fabs(minAngle - hourAngle);
    if (diff > PI) diff = 2 * PI - diff;
    cout << setprecision(20) << sqrt(a*a + b*b - 2*a*b*cos(diff)) << endl;
    return 0;
}

Measured memory_bytes: 4240
using System;
 
class Program {
    private static int Main() {
        var input = Console.ReadLine();
        var values = input.Split( ' ' );
 
        int a = int.Parse( values[ 0 ] );
        int b = int.Parse( values[ 1 ] );
         
        string mark;
        if( a < b ) {
            mark = "<";
        } else if( a > b ) {
            mark = ">";
        } else {
            mark = "==";
        }
 
        var output = string.Format( "a {0} b", mark );
        Console.WriteLine( output );
 
        return 0;
    }
}

Measured memory_bytes: 5388
n,a,b = map(int,input().split())

mod = 10**9+7

ans = 1
r = 2
m = n
while(True):
    if(m%2 == 1):
        ans *= r
        ans %= mod
    r = r**2
    r %= mod
    m = m//2
    if(m == 0):
        break

a = max(a,n-a)
b = max(b,n-b)
base = []
rbase = [0,1]
c = min(a,b)
d = max(a,b)

bas = 1
for i in range(n,c,-1):
    bas *= i
    bas %= mod
    base.append(bas)

#0からn-cまでの逆元
rbase = [0,1]
for i in range(2,n-c+1):
    q = mod//i
    r = mod % i
    rbase.append(-q * rbase[r] % mod)
rbases = []
rbas = 1
for i in range(1,n-c+1):
    rbas *= rbase[i]
    rbas %= mod
    rbases.append(rbas)

a_ = base[n-c-1]*rbases[n-c-1]%mod
if(d == n):
    b_ = 1
else:
    b_ = base[n-d-1]*rbases[n-d-1]%mod
print((ans - a_ - b_ - 1)%mod)


Measured memory_bytes: 32584
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

template<typename T> void fastin(T &num) {
  bool negative = false;
  T c;
  num = 0;
  c = getchar_unlocked();
  if (c == '-') {
    negative = true;
    c = getchar_unlocked();
  }
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
  if (negative) num *= -1;
}
/*
string pad(const int& num) {
  string t = to_string(num);
  string pad = "";
  if (t.size() < 6) {
    int diff = 6 - (int) t.size();
    for (int i = 0; i < diff; ++i) {
      pad += '0';
    }
  }
  return pad + t;
}
*/
struct task{
  int year, id;
};

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

  int n, m; fastin(n); fastin(m);
  vector<task> v[101010];
  for (int i = 0; i < m; ++i) {
    int p, y; fastin(p); fastin(y);
    v[p].push_back({y, i + 1});
  }

  vector<int> ans1(m + 1), ans2(m + 1);

  for (int i = 1; i <= n; ++i) {
    if (v[i].empty()) continue;
    sort(v[i].begin(), v[i].end(), [](const task &x, const task &y){
      return x.year < y.year;
    });
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < (int)v[i].size(); ++j) {
      ans1[v[i][j].id] = i;
      ans2[v[i][j].id] = j + 1;
      //ans[v[i][j].id] = pad(i) + pad(j + 1);
    }
  }

  for (int i = 1; i <= m; ++i) {
    //printf("%s\n", ans[i].c_str());
    cout << setfill('0') << right << setw(6) << ans1[i] << setfill('0') << right << setw(6) << ans2[i] << '\n';
  }

  return 0;
}

Measured memory_bytes: 7808
/*  In the name of ALLAH */

#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define int long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif



int32_t main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
  
    int a;
    cin>>a;
    int res = a*a + a+ a*a*a;
    cout<<res<<endl;
 

 
    
 
    return 0;
}


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

int main(){
int i, j, n, m, k[30], o, a[30], l;
cin >> n >> m;
  
for(i=0; i<m; i++)
  a[i]=0;
  
for(i=0; i<n; i++){
  cin >> k[i];
  for(j=0; j<k[i]; j++){
    cin >> o;
    a[o-1]++;
  }
}

  l=0;
for(i=0; i<m; i++)
  if(a[i] == n)
    l++;

  cout <<l;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    int ans = pow(3, n);
    int cnt = 1;
    rep(i, n) {
        int a;
        cin >> a;
        if(a % 2 == 0) {
            cnt *= 2;
        }
    }
    ans -= cnt;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int N = 0, S = 0, E = 0, W = 0;

    int L; cin >> L;
    string s; cin >> s;
    for(int i=0; i<L; i++) {
        if('A' <= s[i] and s[i] <= 'M') N++;
        if('N' <= s[i] and s[i] <= 'Z') S++;
        if('a' <= s[i] and s[i] <= 'm') E++;
        if('n' <= s[i] and s[i] <= 'z') W++;
    }

    int m1 = min(N, S), m2 = min(E, W);
    N -= m1, S -= m1;
    E -= m2, W -= m2;

    string ans = "";
    for(int i=0; i<N; i++) ans += 'A';
    for(int i=0; i<S; i++) ans += 'N';
    for(int i=0; i<E; i++) ans += 'a';
    for(int i=0; i<W; i++) ans += 'n';
    cout << ans.size() << endl << ans << endl;
    return 0;
}



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

using namespace std;
#define ll long long
#define ld long double
#define eb emplace_back
#define mod 1000000007
#define pii pair<int, int>

int n, m;
vector<bool> visited;
vector< vector<int> > adj;

void dfs(int v){
    visited[v] = true;
    for(auto &x: adj[v]){
        if(!visited[x]) dfs(x);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    adj.resize(n+1);
    visited.assign(n+1, false);
    while(m--){
        int x, y;
        cin >> x >> y;
        adj[x].eb(y);
        adj[y].eb(x);
    }

    int cnt = -1;
    for(int i=1; i<=n; i++){
        if(!visited[i]){
            cnt++;
            dfs(i);
        }
    }
    cout << cnt;
}


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

void setmax(uint8_t& a, int b) {
	if (b > a) {
		a = b;
	}
}

const int MAXX = 190;
const int MAXY = 190;
const int MAXN = 20;
int X, Y;
char A[MAXX][MAXY];
uint8_t dp[MAXX][MAXX][MAXY], ndp[MAXX][MAXX][MAXY];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> X >> Y;
	for (int x = 0; x < X; x++) {
		cin >> A[x];
	}

	for (int xlo = X-1; xlo >= 0; xlo--) {
		for (int xhi = xlo; xhi < X; xhi++) {
			for (int ylo = Y-1; ylo >= 0; ylo--) {
				if (xlo == xhi || (A[xhi][ylo] == A[xhi-1][ylo] && dp[xlo][xhi-1][ylo] > ylo)) {
					if (ylo < Y-1 && A[xhi][ylo] == A[xhi][ylo+1]) {
						dp[xlo][xhi][ylo] = dp[xlo][xhi][ylo+1];
					} else {
						dp[xlo][xhi][ylo] = ylo+1;
					}
				} else {
					dp[xlo][xhi][ylo] = ylo;
				}
			}
		}
	}

	int ans = 0;
	while (dp[0][X-1][0] < Y) {
		for (int xlo = 0; xlo < X; xlo++) {
			for (int xhi = xlo; xhi < X; xhi++) {
				for (int ylo = 0; ylo < Y; ylo++) {
					// append right
					if (dp[xlo][xhi][ylo] == Y) {
						ndp[xlo][xhi][ylo] = Y;
					} else {
						ndp[xlo][xhi][ylo] = dp[xlo][xhi][dp[xlo][xhi][ylo]];
					}

					// append down
					// find last position such that dp(mid) <= dp(mid+1)
					int mi = xlo-1, ma = xhi-1;
					while (ma - mi > 1) {
						int md = (mi + ma) / 2;
						setmax(ndp[xlo][xhi][ylo], min(dp[xlo][md][ylo], dp[md+1][xhi][ylo]));
						if (dp[xlo][md][ylo] <= dp[md+1][xhi][ylo]) {
							ma = md;
						} else {
							mi = md;
						}
					}
					for (int i = ma; i <= ma+1 && i <= xhi-1; i++) {
						setmax(ndp[xlo][xhi][ylo], min(dp[xlo][i][ylo], dp[i+1][xhi][ylo]));
					}
				}
			}
		}
		memcpy(dp, ndp, sizeof(dp));
		ans++;
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main()
{
	int n; string s; cin >> n >> s; int count = 0;
	for (int i = 0; i < n - 2; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
#define x first
#define y second
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std;

typedef pair<int, int> pii;

int n, a, b, c, d, e, ans;

int main() {
	INIT
	int A[5];
	for (int i = 0; i < 5 ; ++i) {
		cin >> A[i];
		ans += A[i];
	}
	vector<int> B;
	for (int i = 0; i < 5 ; ++i) {
		d = A[i] % 10;
		if (d) {
			B.pb(d);
		}
	}
	
	sort(B.begin(), B.end());
	for (int i = 1; i < B.size(); ++i) {
		d = 10 - B[i];
		ans += d;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
s =input()
n = len(s)
ans  = 0
cnt = 0
pre = s[0]
for i in range(n):
    if s[i] == "A":
        if pre =="B":cnt =1
        else:cnt+=1
    elif s[i] =="C":
        if pre == "B":
            ans += cnt
        else:cnt = 0
    elif s[i] == "B":
        if pre == "B":cnt = 0
    pre = s[i]
print(ans)


Measured memory_bytes: 3500
N, M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
minimum_votes = sum(A) * (1 / (4 * M))

eligible_products = [a for a in A if a >= minimum_votes]

if len(eligible_products) >= M:
    print("Yes")
else:
    print("No")

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}
#define PI 3.14159265358979323846
int main(){


    int a, b;
    cin >> a >> b;
    int h, m;
    cin >> h >> m;
    double h_deg = 30 * h + 0.5 * m;
    double m_deg = 6 * m;

    double deg;
    if(h_deg > m_deg) {
        deg = min(h_deg-m_deg, m_deg + (360-h_deg));
    }
    else {
        deg = min(m_deg-h_deg, h_deg + (360-m_deg));
    }
    printf("%.12lf",sqrt(a*a + b*b - 2*a*b*cos(PI/180*deg)));

    return 0;
}

Measured memory_bytes: 4160
//https://codeforces.com/contest/1335/problem/

#include <bits/stdc++.h>
#define ll long long int
#define pll pair<ll, ll>
#define pii pair<int, int>

using namespace std;
const int N = 2e5 + 5;
int arr[N];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int x;
        cin >> x;
        arr[x]++;
    }
    for (int i = 1; i <= n; i++)
    {
        cout<<arr[i]<<'\n';
    }
    return 0;
}

Measured memory_bytes: 4384
/*
	"We know what we are, but know not what we may be."
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

/*
	"You never know how strong you are until being strong is the only choice you have."
*/

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
	
/*
	"With self-discipline most anything is possible."
*/
	
	long long n, k; cin >> n >> k;
	
	vector<double> a(n);
	for(auto &i : a) cin >> i;
	
	double sum = 0, cur = 0;
	for(long long i = 0; i < n; i++){
		sum += a[i];
		if(i - k >= 0) sum -= a[i - k];
		cur = max(sum, cur);
	}
	
	cout << fixed << setprecision(10) << (cur + double(k)) / 2;
	return 0;
}

/*
	"Reach for it. Push yourself as far as you can."
*/

Measured memory_bytes: 1792
def gcd(x,y):
    if y>x:
        a=y
        y=x
        x=a
    a=1
    while a*y:
        a=x%y
        x=y
        y=a
    return x
a=int(input())
b=[int(i) for i in input().split()]
c=b[0]
for i in range(a-1):
    c=gcd(c,b[i+1])
print(c)


Measured memory_bytes: 14252
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main() {
	double r, w, c, r2;
	while (1) {
		cin >> r >> w >> c >> r2;
		if (r + w + c + r2 == 0) break;
		if (r / w >= c) cout << 0 << endl;
		else {
			double a = c*w;
			cout << ceil((a - r)/r2) << endl;
		}
	}
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define un(x)           x.erase(unique(all(x)), x.end())
#define xx              first
#define yy              second
#define pb              push_back
#define all(v)          v.begin(),v.end()

#define D(x)            cerr << #x " = " << x << '\n'
#define DBG             cerr << "Hi!" << '\n'

#define CLR(a)          memset(a,0,sizeof(a))
#define SET(a)          memset(a,-1,sizeof(a))

// inline int setBit(int n,int pos) { return n = n | (1 << pos); }
// inline int resetBit(int n,int pos) { return n = n & ~(1 << pos); }
// inline bool checkBit(int n,int pos) { return (bool)(n & (1 << pos)); }

// int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
// int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// unsigned int num = rng();
// shuffle(V.begin(), V.end(), rng);

/******************************************************************************************/

//const int MAX = 500010;
//const int INF = 0x3f3f3f3f;
//const int MOD = 1000000007;


//inline int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
//inline int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; }
//inline int mul(int a, int b) { return (a * 1LL * b) % MOD; }


int ara[1000010];

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

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

	int mx = 0;
	for(int i=1;i<n;i++) mx = max(mx, ara[i + 1] - ara[i]);
	mx = max(mx, ara[1] + k - ara[n]);
	cout << k - mx << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>

int main(void){
    int A,B,M;
    std::cin >> A >> B >> M;
    int a[A], b[B], mina=-1, minb=-1;
    int m[M][3], sum[M], minsum = -1;

    for(int i=0; i<A; i++){
        std::cin >> a[i];
        if(mina<0 || a[i] < mina) mina = a[i];
    }
    for(int i=0; i<B; i++){
        std::cin >> b[i];
        if(minb<0 || b[i] < minb) minb = b[i];
    }
    for(int i=0; i<M; i++){
        std::cin >> m[i][0] >> m[i][1] >> m[i][2];
        sum[i] = a[m[i][0]-1] + b[m[i][1]-1] - m[i][2];
        if(minsum < 0 || sum[i] < minsum) minsum = sum[i];

        //std::cout << i << "=" << sum[i] << std::endl;
    }

    if(mina + minb < minsum) minsum = mina+minb;

    std::cout << minsum << std::endl;
    
    return 0;
}

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

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

	int a;
	string s;

	cin >> a;
	cin >> s;

	if(a<3200)
	{
		s = "red";
	}

	cout << s << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;

const long long mod = 1e9 + 7ll ;

const int MAX = 2e5 + 5 ;

int n ;

int add(int x , int y)
{
	if(x >= mod)
		x -= mod ;
	if(y >= mod)
		y -= mod ;
	int z = x+y ;
	if(z >= mod)
		z -= mod ;
	return z ;
}

int arr[MAX] ;
string s ;

int main()
{
	//ios_base::sync_with_stdio(0) ;
	//cin.tie(0) ;
	cin>>n ;
	cin>>s ;
	for(int i = 0 ; i < n*2 ; ++i)
	{
		if(s[i] == 'W')
			arr[i] = 0 ;
		else
			arr[i] = 1 ;
	}
	long long ans = 1ll ;
	long long moves = 0 ;
	if(arr[0] == 0)
		return cout<<0<<"\n" , 0 ;
	for(int i = 0 ; i < n*2 ; ++i)
	{
		if((arr[i] + moves) % 2 != 0)
			moves++ ;
		else
		{
			ans = (ans * moves) % mod ;
			ans %= mod ;
			moves-- ;
		}
		if(moves > n || moves < 0)
			return cout<<0<<"\n" , 0 ;
	}
	if(moves != 0)
		return cout<<0<<"\n" , 0 ;
	long long fact = 1ll ;
	for(int i = 2 ; i <= n ; ++i)
	{
		fact = (fact * i) % mod ;
		fact %= mod ;
	}
	ans = (ans * fact) % mod ;
	ans %= mod ;
	return cout<<ans<<"\n" , 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
 
typedef long long ll;
typedef long double ld;
 
#define X first
#define Y second
#define pb push_back
#define all(x) x.begin(), x.end()
#define deb(x) cerr << #x << " " << x << '\n';
 
// #define int ll
 
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
 
using namespace std;
 
void pudge(){ 
    int a, b, c, k, ans;
    cin >> a >> b >> c >> k;
    ans = min(a, k);
    k = max(0, k - a);
    k = max(0, k - b);
    ans -= min(c, k);
    cout << ans << '\n';
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    // int q; cin >> q; while(q--)
    pudge();
 
    return 0;
}



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

vector<int> perfect_squares;
int points[10][10];

bool is_perfect_square(int n){
	return binary_search(perfect_squares.begin(), perfect_squares.end(), n);
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, d;
	cin >> n >> d;
	
	for (int i = 0; i <= 10000; i++){
		perfect_squares.push_back(i * i);
	}
	
	for (int i = 0; i < n; i++){
		for (int j = 0; j < d; j++){
			cin >> points[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++){
		for (int j = i + 1; j < n; j++){
			int dist = 0;
			for (int k = 0; k < d; k++){
				dist += (points[i][k] - points[j][k]) * (points[i][k] - points[j][k]);
			}
			//cerr << dist << endl;
			if (is_perfect_square(dist)){
				++ans;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <string>
#include <iostream>

using namespace std;

typedef long long    ll;
typedef long double  ld;

#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)

#define endl '\n'
#define INF  0x7f7f7f7f7f7f7f7f
#define INFi 0x7f7f7f7f


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

ll solve(string S, string T) {
  ll res = 0;
  rep(i, S.size())
    if (S[i]!=T[i])
      res++;
  return res;
}

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

  string S, T;
  cin >> S >> T;

  auto ans = solve(S, T);
  cout << ans << endl;

  return 0;
}


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

int main() {
    int k;
    cin >> k;
    int odd = (k+1)/2;
    int even = k/2;
    cout << odd*even << endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    h, w = map(int, input().split())
    maiz = []
    count =[]
    for i in range(h):
        a = input()
        maiz.append(a)
        count.append([0]*w)

    for i in range(h):
        for j in range(w):
            if maiz[i][j] == "#":
                count[i][j] = "#"
                if i > 0 and maiz[i-1][j] == ".":
                    count [i-1][j] +=1
                if i < h -1  and maiz[i+1][j] == ".":
                    count [i+1][j] +=1
                if j > 0 and maiz[i][j-1] == ".":
                    count [i][j-1] +=1
                if j < w -1  and maiz[i][j+1] == ".":
                    count [i][j+1] +=1
                if i > 0 and j > 0 and maiz[i-1][j-1] == ".":
                    count [i-1][j-1] +=1
                if i < h -1 and j < w-1  and maiz[i+1][j+1] == ".":
                    count [i+1][j+1] +=1
                if i > 0 and j < w-1 and maiz[i-1][j+1] == ".":
                    count [i-1][j+1] +=1
                if i < h -1 and j >0  and maiz[i+1][j-1] == ".":
                    count [i+1][j-1] +=1


    for i in count:
        ans = ""
        for j in i :
            ans += str(j)
        print(ans)






Measured memory_bytes: 9252
N,M,X,Y = [int(x) for x in input().split()]
x = [X]+[int(x) for x in input().split()]
y = [Y]+[int(x) for x in input().split()]
x.sort()
y.sort()
if(x[-1]<y[0]):
  print('No War')
else:
  print('War')
  

Measured memory_bytes: 3060
s = input()
g = 0
p = 0
ans = 0
for si in s:
    if p + 1 <= g: # パーを出せる
        p += 1
        if si == 'g': # 相手がグーの時は勝ち
            ans += 1
    else: # パーを出せない
        g += 1
        if si == 'p': # 相手がパーの時は負け
            ans -= 1
print(ans)


Measured memory_bytes: 3316
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskD   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        String S = in.next();
        String T = in.next();
        String ans = "Yes";
        UnionFind uf = new UnionFind(S.length());
        HashMap<Character, Integer> hm = new HashMap<>();
        for(int i = 0; i < S.length(); i++){
            char st = S.charAt(i);
            if(!hm.containsKey(st)) hm.put(st, i);
            else uf.union(hm.get(st), i);
        }
        HashMap<Character, Integer> hm2 = new HashMap<>();
        for(int i = 0; i < T.length(); i++){
            char st = T.charAt(i);
            if(!hm2.containsKey(st)) hm2.put(st, i);
            if(uf.find(i) != hm2.get(st)) ans = "No";
        }
        out.println(ans);

    }

class UnionFind   {
int[] par;
int[] size;
int g;

UnionFind(int youso) {
            this.g = youso;
            this.par = new int[youso];
            this.size = new int[youso];
            for(int i=0; i<=g-1; i++){
                par[i] = i;
            }
            for(int i=0; i<=g-1; i++){
                size[i] = 1;
            }
        }

int find(int node) {
            if(par[node]==node){
                return node;
            }
            return par[node] = find(par[node]);
        }

void union(int node1, int node2) {
            int root1 = find(node1);
            int root2 = find(node2);
            if(root1 == root2){
                return;
            }
            g--;
            if(size[root1] < size[root2]){
                int temp = root1;
                root1 = root2;
                root2 = temp;
            }
            size[root1] += size[root2];
            par[root2] = root1;
        }

}

}
}



Measured memory_bytes: 29264
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define intl long long
void fastio()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}
int main()
{
	intl n;
	cin>>n;
	intl a[n+1];
	for(intl i=0;i<n;i++)
	{
		cin>>a[i];
	}
	intl dp[n+1];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0])+dp[0];
	for(intl i=2;i<n;i++)
	{
		dp[i]=min(((abs(a[i-1]-a[i]))+dp[i-1]),((abs(a[i-2]-a[i])+dp[i-2])));
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;
 
int main() {
  int a, b, c, x, y;
 
  cin >> a >> b >> c >> x >> y;
 
  int min_price = x * a + b * y;
  rep(a_num, x + 1) {
    int min_c_num = max((x - a_num) * 2, 0);
 
    int price_with_b = a_num * a + max((y - min_c_num / 2), 0) * b + min_c_num * c;
    int price_without_b = a_num * a + max(min_c_num, y * 2) * c;
 
    int price = min(price_with_b, price_without_b);
    if(price == 110000000) {
 
    }
 
    min_price = min(min_price, price);
  }
 
  cout << min_price << endl;
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N)  cin >> A.at(i);

  vector<int> L(N+1);
  vector<int> R(N+1);
  L.at(0)=0;
  R.at(N)=0;
  REP(i,1,N+1)  L.at(i)=gcd(L.at(i-1),A.at(i-1));
  for(int i=N-1;i>=0;i--) R.at(i)=gcd(R.at(i+1),A.at(i));
  debug_vec(L);
  debug_vec(R);

  int ans=0;
  rep(i,N)  chmax(ans,gcd(L.at(i),R.at(i+1)));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4476
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int n, a[100005];
ll ans, sum[100005];
#define getsum(l, r) ((l) <= (r) ? sum[r] - sum[(l) - 1] : 0)

int main(){
	getint(n);
	for(register int i = 1; i <= n; i++) getint(a[i]);
	sort(a + 1, a + n + 1);
	for(register int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
	if(n & 1){
		ans = max((getsum(n / 2 + 2, n) - getsum(1, n / 2 - 1)) * 2 - a[n / 2 + 1] - a[n / 2],
		          (getsum(n / 2 + 3, n) - getsum(1, n / 2)) * 2 + a[n / 2 + 1] + a[n / 2 + 2]);
	}
	else ans = (getsum(n / 2 + 2, n) - getsum(1, n / 2 - 1)) * 2 + a[n / 2 + 1] - a[n / 2];
	return printf("%lld\n", ans), 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n;
	while(cin>>n){
		int ans=0;
		ans=1+n*(n+1)/2;
		o(ans);
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<int> v(n), c(n);
  for (auto &x: v) cin >> x;
  for (auto &x: c) cin >> x;

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

  cout << ans << endl;

  return 0;
}


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

int main(){
  int k;
  cin >> k;
  int cnt = 0;
  queue<string> que;
  for(int i=1; i<=9; i++) que.push(to_string(i));
  string current;
  while(cnt<k){
    current = que.front();
    que.pop();
    int lastNum = current.back()-'0';
    if(lastNum != 0 && lastNum != 9){
      rep(i, 3) que.push(current+to_string(lastNum-1+i));
    }else if(lastNum == 0){
      rep(i, 2) que.push(current+to_string(lastNum+i));
    }else{
      rep(i, 2) que.push(current+to_string(lastNum-1+i));
    }
    cnt++;
  }
  cout << current << endl;
  return 0;
}
    
    

Measured memory_bytes: 10752
n = int(input())
a = list(map(int, input().split()))
a.append(0)
a.insert(0, 0)
inter = []

for i in range(n+1):
    inter.append(abs(a[i]-a[i+1]))

SUM = sum(inter)

for j in range(n):
    diff = inter[j]+inter[j+1]-abs(a[j]-a[j+2])
    ans = SUM-diff
    print(ans)

Measured memory_bytes: 57452
n=int(input())
x=0
ans=[]
for i in range(1,n+1):
  if i%3==0:ans.append(str(i))
  else:
    x=i
    while x:
      if x%10==3:
        ans.append(str(i))
        break
      x//=10
print(" "+" ".join(ans))


Measured memory_bytes: 5928
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;

int n,w,inf=-1,wei[105],val[105],dp[105][10005];

int func(){
	for(int i=0;i<n;i++){
		for(int j=0;j<=w;j++){
			if(j<wei[i]) dp[i+1][j]=dp[i][j];
			else dp[i+1][j]=max(dp[i][j],dp[i][j-wei[i]]+val[i]);
		}
	}
	return dp[n][w];
}

int main(){
	cin>>n>>w;
	for(int i=0;i<n;i++){
		cin>>val[i]>>wei[i];
	}
	cout<<func()<<endl;
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) {
    u += m;
  }
  return u;
}

ll calc(ll n, ll r) {
  ll num = 1;
  for (ll i = 1; i <= r; i++) {
    num = num * (n - i + 1) % MOD;
    num = num * modinv(i, MOD) % MOD;
  }
  return num % MOD;
}

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

int main() {
  ll n, a, b;
  scanf("%lld %lld %lld", &n, &a, &b);

  ll ans = fastpow(2, n, MOD);
  ans -= 1;

  ans = (ans - calc(n, a) + MOD) % MOD;
  ans = (ans - calc(n, b) + MOD) % MOD;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  double av;
  int x[200000]={},m[200000]={},min,n,idx,a,b;
  cin>>n;
  for(int i=0;i<n;i++){cin>>x[i];m[i]=x[i];}
  sort(m,m+n);
  a=m[n/2];
  b=m[n/2-1];
  av=(a+b)/2;
  for(int i=0;i<n;i++)
    if(av>=x[i])cout<<a<<endl;
    else cout<<b<<endl;
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int N, K;
	cin >> N >> K;

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		if (n >= K) cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-15
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    long double a, b, c;
    cin >> a >> b >> c;
    (sqrt(a)+sqrt(b)+EPS < sqrt(c)) ? Yes() : No();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll N;
    cin >>N;
    vector<ll> P(N);

    rep(i,N){
        cin>>P[i];
    }
    ll ans = 0;
    ll min = INF;
    rep(i,N){
        if(P[i]<min){
            ans++;
            min = P[i];
        }
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 4832