akhauriyash/Code-Regression huggingface dataset:
# input n,m
n, m = map(int, input().split())

# input matrix
matrixA = []
for i in range(n):
    l = list(map(int, input().split()))
    matrixA.append(l)

# input vector
vectorb=[]
for _ in range(m):
    vectorb.append(int(input()))

# initialize C
C = [[0 for i in range(1)] for i in range(n)]

# calculate
for n_tmp in range(n):
    for m_tmp in range(m):
        C[n_tmp][0] += matrixA[n_tmp][m_tmp] * vectorb[m_tmp]

# output
for j in range(n):
    print(C[j][0])



Measured memory_bytes: 5980
def main():

  N, K = map(int, input().split())   
  A = [0] + list(map(int, input().split()))
  cur = 1
  visited = [-1] * (N + 1)
  visited[cur] = 0
  for i in range(1, K + 1):
    next_cur = A[cur]
    if next_cur == cur:
      print(next_cur)
      return
    elif visited[next_cur] != -1:
      mod = i - visited[next_cur]
      start = visited[next_cur]
      break
    else:
      visited[next_cur] = visited[cur] + 1
      cur = next_cur
  else:
    print(next_cur)
    return
  K = (K - start) % mod
  print(visited.index(K+start))
  
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 32332
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n,m;
ll a[10000],b[10000],c[10000];
ll ans;


void f(ll x,ll y,ll z){
  vector<ll> v;
  ll res=0;
  rep(i,n){
    v.push_back(x*a[i]+y*b[i]+z*c[i]);
  }

  sort(all(v));
  reverse(all(v));

  rep(i,m){
    res+=v[i];
  }

  ans = max(ans,res);
}


int main(){
  cin>>n>>m;
  rep(i,n){
    cin>>a[i]>>b[i]>>c[i];
  }

  for(ll i=-1;i<2;i+=2){
    for(ll j=-1;j<2;j+=2){
      for(ll k=-1;k<2;k+=2){
        f(i,j,k);
      }
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	string s;
	cin >> s;
	ll n = s.size();

	ll l = 0, r = n;
	while(r - l > 1){
		ll m = (l + r) / 2;
		bool flg = false;
		rep(t, 2){
			ll mi = t, ma = m;
			if (mi % 2 != ma % 2) --ma;
			bool ok = true;
			rep(i, n){
				if(s[i] == '0'){
					--ma;
					--mi;
				}else if(s[i] == '1'){
					++ma;
					++mi;
				}else{
					++ma;
					--mi;
				}

				if (ma > m) ma -= 2;
				if (mi < 0) mi += 2;
				// if(m == 21 && ma - mi < 2) co({i, mi, ma});
				if (ma < mi){
					ok = false;
					break;
				}
			}
			flg |= ok;
		}

		if (flg) r = m;
		else
			l = m;
	}
	co(r);

	return 0;
}


Measured memory_bytes: 5344
fun main(args: Array<String>) {
    val (k, n) = readLine()!!.split(' ').map { it.toInt() }
    val a = readLine()!!.split(' ')

    var maxDist = 0
    var prev = 0
    repeat(n) {
        val aa = a[it].toInt()
        val dist = aa - prev
        prev = aa
        if (dist > maxDist) maxDist = dist
    }
    val finalDist = a[0].toInt() + k - a[n-1].toInt()
    if(finalDist > maxDist) maxDist = finalDist
    println(k - maxDist)
}


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

int main() {
    int D, G; cin >> D >> G;
    int p[D], c[D];
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }
    int ans = 10000;
    for (int bit = 0; bit < (1<<D); bit++) {
        int point = 0;
        int answered = 0;
        for (int i = 0; i < D; i++) {
            if (bit & (1<<i)) {
                answered += p[i];
                point += 100 * (i+1) * p[i];
                point += c[i];
            }
        }
        if (point < G) {
            for (int i = 0; i < D; i++) {
                int q = point;
                if (!(bit & (1<<i))) {
                    for (int j = 1; j <= p[i]; j++) {
                        q += 100 * (i+1);
                        if (q >= G) {
                            ans = min(ans, answered + j);
                        } 
                    }
                    q += c[i];
                    if (q >= G) {
                        ans = min(ans, answered + p[i]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

cnt = 0

def cn(n,N):
    global cnt
    
    if n == 0:
        return 0
    a = int("3"+n) 
    b = int("5"+n) 
    c = int("7"+n)
    if a <= N and "5" in n and "7" in n:
        cnt += 1
    if b <= N and "3" in n and "7" in n:
        cnt += 1
    if c <= N and "3" in n and "5" in n:
        cnt += 1
      
    if a > N:
        cn(0,N)
    else:
        cn(str(a),N)
    if b > N:
        cn(0,N)
    else:
        cn(str(b),N)
    if c > N:
        cn(0,N)
    else:
        cn(str(c),N)

cn("",N)
print(cnt)

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

int main(){

  int a,b,w;
  cin >> w >> a >> b;

  if (a + w < b) {
    cout << b-a-w << endl;
  } else if (a+w >= b && a <= b+w) {
    cout << 0 << endl;
  } else {
    cout << a-b-w << endl;
  }

}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int>p(N);
  for(int i=0;i<N;i++){
    cin >> p[i];
  }
  sort(p.begin(),p.end());
  int count=0;
  for(int i=0;i<K;i++){
    count+=p[i];
  }
  cout << count << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

long long bfs(int sx, int sy, std::vector<std::vector<char>> &grid,
              std::vector<std::vector<bool>> &is_visited) {
  int h = grid.size(), w = grid[0].size();

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

  std::queue<std::pair<int, int>> que;
  que.push(std::make_pair(sx, sy));

  is_visited[sy][sx] = true;

  long long cnt_w = 0, cnt_b = 0;

  while (!que.empty()) {
    int cur_x = que.front().first;
    int cur_y = que.front().second;

    if (grid[cur_y][cur_x] == '#') {
      cnt_b++;
    } else {
      cnt_w++;
    }
    que.pop();

    for (int i = 0; i < 4; i++) {
      int nx = cur_x + dx[i];
      int ny = cur_y + dy[i];
      if (nx < 0 || ny < 0 || nx >= w || ny >= h) {
        continue;
      }
      if (is_visited[ny][nx]) {
        continue;
      }
      if (grid[cur_y][cur_x] == grid[ny][nx]) {
        continue;
      }
      is_visited[ny][nx] = true;
      que.push(std::make_pair(nx, ny));
    }
  }
  return cnt_w * cnt_b;
}

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

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

  vector<vector<char>> g(h, vector<char>(w));

  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      g[i][j] = s[j];
    }
  }

  vector<vector<bool>> is_visited(h, vector<bool>(w, false));

  long long ans = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (is_visited[y][x]) {
        continue;
      }
      ans += bfs(x, y, g, is_visited);
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

void func(double a ,double b,double c,double d,double e,double f,double* x,double* y){
	double temp;
	*y=(c*d-a*f)/(b*d-a*e);
	temp=*y;
	*x=(c-b*temp)/a;
}

int main(void){
	double a,b,c,d,e,f,j,k;
	double *x=&j;
	double *y=&k;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF){
		//y=func(a,b,c,d,e,f);
		//x=(c-b*y)/a+0.00001;
		func(a,b,c,d,e,f,x,y);
		printf("%.3lf %.3lf\n",*x,*y);
	}
	return 0;
}

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

using namespace std;
using LLONG = long long;

int main()
{
    int N;
    cin >> N;
    vector<int> values(N);
    for (int i = 0; i < N; ++i) cin >> values[i];

    int count = 0;
    for (;;)
    {
        for (int &value : values)
        {
            if (value % 2 == 0)
            {
                value /= 2;
            }
            else
            {
                cout << count << endl;
                return 0;
            }
        }
        ++count;
    }

    return 0;
}

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

int main(){
    while(true){
      int n;
      cin >> n;
      if(n == 0){
        break;
      }
      int ans=-1;
      double mi=1e9;
      double ideal = 22.0;
      for(int i=0; i<n; i++){
        int p;
        double h, w;
        cin >> p >> h >> w;
        h /= 100;
        double bmi;
        bmi = w/(h*h);
        double riso;
        riso = abs(bmi-22.0);
        if(mi >= riso){
          mi = riso;
          ans = p;
        }
      }
      cout << ans << endl;
    }
  return 0;
}



Measured memory_bytes: 3204
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int a1[4];
	int l=1,k=0;
	string a;
	cin>>a;
	for(int i=0;i<4;i++)
	{
		a1[i]=a[i]-'0';
	}
	for(int i=0;i<4;i++)
	{
		if(a1[i]==a1[i+1])
		{
			l++;
		}
		else
		{
			l=1;
		}
		if(l>=3)
		{
			k=1;
		}
	}
	if(k==0)
	{
		cout<<"No"<<endl;
	}
	else
	{
		cout<<"Yes"<<endl;
	}
}

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

using namespace std;

#define fastio cin.tie(NULL);cout.tie(NULL);ios_base::sync_with_stdio(0);
#define debug(x) cout << x << endl;
#define endl '\n'
#define MAXN 1000005
#define INF 0x3f3f3f3f
#define LOG 20
#define pb push_back

typedef long long ll;
typedef pair <ll, ll> pii;
typedef vector <int> vi;
typedef vector <pii> vii;

int n, k;
int v[4];
int r, s, p;
string in;

char win(char c){
    if(c == 'r') return 'p';
    if(c == 's') return 'r';
    return 's';
}

int convert(char c){
    if(c == 'r') return 1;
    if(c == 's') return 2;
    return 3;
}

int32_t main(){
    fastio
    cin >> n >> k >> v[1] >> v[2] >> v[3] >> in;
    int sz = in.size();
    char last = ' ', c, next;
    string res = "";
    int out = 0;

    for(int i = 0; i < sz; i++){
        if(i - k >= 0){
            if(res[i - k] == win(in[i])) res += ' ';
            else {
                c = win(in[i]);
                res += c;
                out += v[convert(c)];
            }
        } else {
            c = win(in[i]);
            res += c;
            out += v[convert(c)];
        }
    }

    cout << out << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <random>
#include <array>
#include <chrono>
#include <cmath>
#include <memory>
#include <map>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

using llint=long long;

llint scoring(vector<llint> c,
            vector<vector<llint>> s,
            vector<llint> result,
            llint d=365){
    
    if(c.size()!=s[0].size()||s.size()!=result.size()){
  
        return -1;
    }else{
        llint score=0;
        REP(i,d){
            score+=s[i][result[i]-1];
            REP(j,26){
                if(j+1!=result[i]){
                    score-=c[j];
                }
            }
        }
         
        return score;
    }
 }

int main(){
    chrono::system_clock::time_point start, end;
    std::random_device rnd;     // 非決定的な乱数生成器を生成
    std::mt19937 mt(rnd());     //  メルセンヌ・ツイスタの32ビット版、引数は初期シード値
    start = chrono::system_clock::now();
    llint d;
    cin>>d;
    std::uniform_int_distribution<> rand26(1, 26),randd(0,d-1);        // [0, 99] 範囲の一様乱数
    
    llint anum=26;
    vector<llint> c(anum);
    
    REP(i,anum){
        cin>>c[i];
    }
    vector<vector<llint>> s(d,vector<llint>(anum));
    REP(i,d){
        REP(j,anum){
            cin>>s[i][j];
        }
    }
    vector<llint> result(d);

    REP(i,d){
        result[i]=rand26(mt);
    }
    double time;
    auto newresult=result;
    while(( time = static_cast<double>(chrono::duration_cast<chrono::microseconds>(
        ( chrono::system_clock::now()) - start).count()
        ))<1800000.){
        newresult=result;
        REP(i,20){
            newresult[randd(mt)]=rand26(mt);
        }
        if(scoring(c,s,newresult,d)>scoring(c,s,result,d)){
            result=newresult;
        }
        //cout<<"unko"<<endl;
    }
     
    REP(i,d){
        cout<<result[i]<<endl;
    }
}


Measured memory_bytes: 3484
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	S := getString()
	if strings.Contains(S, "A") && strings.Contains(S, "B") {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return n * powMod(n, p-1)
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 640
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define srch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    while(cin>>n)
    {
        x=n;
        s=0;
        while(x)
        {
            s+=x%10;
            x=x/10;
        }
        if(n%s==0) cout<<"Yes"<<en;
        else cout<<"No"<<en;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <limits>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
#define ll long long
#define rep(i_, start, end) for(ll i_=(ll)start; i_<(ll)end; i_++)
#define print(a) cout << a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");
 
string s, t;
int len_s, len_t;
int dp[3001][3001];
pair<int, int> last[3001][3001];
int main()
{
  cin >> s >> t;
  len_s = s.size();
  len_t = t.size();
  
  for(int i=0; i<len_s; i++){
    for(int j=0; j<len_t; j++){
      if (s[i] == t[j]){
        if (dp[i][j] + 1 > dp[i+1][j] && dp[i][j] + 1 > dp[i][j+1]){
          dp[i+1][j+1] = dp[i][j] + 1;
        }else if (dp[i+1][j] > dp[i][j+1]){
          dp[i+1][j+1] = dp[i+1][j];
        }else if (dp[i][j+1] >= dp[i+1][j]){
          dp[i+1][j+1] = dp[i][j+1];
        }
      }else{
        if (dp[i][j+1] < dp[i+1][j]){
          dp[i+1][j+1] = dp[i+1][j];
        }else{
          dp[i+1][j+1] = dp[i][j+1];
        }
      }
    }
  }
  
  string ans = "";
  int x = len_s;
  int y = len_t;
  int now = dp[len_s][len_t];
  while(1){
    if (now == 0){
      break;
    }else if(dp[x-1][y] == now){
      x--;
    }else if(dp[x][y-1] == now){
      y--;
    }else{
      ans = s[x-1] + ans;
      x--;
      y--;
      now--;
    }
  }
  print(ans);

  return 0;
}

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

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;

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+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int n,a[maxn],ans;
set<int> st;
map<int,int> mm;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    rep(n) cin >> a[i];
    sort(a,a+n);
    ans=n;
    rep(n) mm[a[i]]++;
    rep(n) for(int j=2*a[i]; j<=a[n-1]; j+=a[i]) st.insert(j);
    rep(n) if(mm[a[i]]>1) st.insert(a[i]);
    for(auto i: st) if(mm.count(i)) ans-=mm[i];
    print1(ans);
    return 0;
}


Measured memory_bytes: 61260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007
 
using graph = vector<vector<ll>>;

int main(){
    ll n;
    cin >> n;
    ll a[n];
    ll sum[n];
    //sum[0] = 0;
    rep(i,n){
        ll temp;
        cin >> temp;
        a[i] = temp;
    }
    sum[n-2] = a[n-1];
    for(int i = n-3; i >= 0; i--){
        sum[i] = (sum[i+1] + a[i+1]) % mod;
    }
    ll ans = 0;
    rep(i,n-1){
        ans += a[i] * sum[i] % mod;
        ans %= mod;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 6740
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,minn=100001;
  	cin>>n;
  string s;
  cin>>s;
  long long int west[n],east[n];
  memset(west,0,sizeof west);memset(east,0,sizeof east);
  if(s[0]=='W') west[0]=1; if(s[n-1]=='E') east[n-1]=1;
  
  for(long long int i=1;i<n;i++){
    west[i]=west[i-1];
    if(s[i]=='W') west[i]++;
   
  }
 
  for(long long int i=n-2;i>=0;i--){
    east[i]=east[i+1];
    if(s[i]=='E') east[i]++;
  }
  minn=min(west[n-2],east[1]);
  for(long long int i=1;i<=n-2;i++) minn=min(minn,west[i-1]+east[i+1]);
 
           
  
  
  cout<<minn;
}

Measured memory_bytes: 5380
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
nl = lambda: list(map(int, stdin.readline().split()))

n, K = na()
a = na()
ans = float('inf')
for i in range(2**(n-1)):
    colors = 1
    cost = 0
    tmp = a[0]
    for k in range(n-1):
        if tmp < a[k+1]:
            colors += 1
            tmp = a[k+1]
            continue
        if (i >> k) & 1:
            cost += tmp - a[k+1] + 1
            colors += 1
            tmp += 1
    if colors >= K:
        ans = min(ans, cost)
print(ans)


Measured memory_bytes: 42476
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

int main(){
	double n,m,x,y;
	cin >> m >> n >> x >> y;
	printf("%lf",m*n/2.000);
	if(x+x == m && y+y == n) cout << " " << 1;
	else cout << " " << 0;
}

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

using namespace std;

int main()

{
	
	string s;
	cin >> s;
	int n = s.size();
	bool checked[n] = {};
	int i, j, k;
	
	i = j = k = 0;
	
	while (j < n)
	{
		if (!checked[j])
		{
			k = 0;
			i = j;
			while (i < n)
			{
				if (s[i] == s[j])
				{
					checked[i] = 1;
					++k;
				}
				++i;
			}
			if (k != 2)
			{
				cout << "No";
				return 0;
			}
		}
		++j;
	}
	
	cout << "Yes";
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int s;
  cin >> s;
  if(0<s%100 && s%100<13){
    if(0<s/100 && s/100<13){
      cout << "AMBIGUOUS" << endl;
    }
    else{
      cout << "YYMM" << endl;
    }
  }
  else if(0<s/100 && s/100<13){
    cout << "MMYY" << endl;
  }
  else{
    cout << "NA" << endl;
  }
  return 0;
}

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

int g[200005];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,val;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> val;
    g[val - 1]++;
  }
  for (int i = 0; i < n; i++) cout << g[i] << '\n';
  return 0;
}

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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }


int ans = MOD;

void dfs(int f, int e){

}

int main() {
ll N, M;
cin >> N >> M;

if(N == 1 && M == 1) {
    print(1);
    return 0;
}

if(N == 1){
    print(M - 2);
    return 0;
}

if(M == 1){
    print(N - 2);
    return 0;
}

print((N - 2) * (M - 2));

}



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

int main(){
    string cad;
    cin>>cad;
    int cont=0, l=cad[0];
    for(int i=1; i<cad.length(); i++){
        if(cad[i]!=l){
            cont++;
            l=cad[i];
        }
    }
    printf("%d", cont);
return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;
#define N = 1000;
int main() {
    string str;
    getline(cin,str);
    
    for(int i=0;i<str.size();i++)
    {
        char c = str[i];
        
        if('a' <= c && c<= 'z'){
            cout<< (char)(c-'a'+ 'A');
        }else if('A' <= c && c<= 'Z'){
            cout<< (char)(c-'A'+ 'a');
        }else{
            cout<<c;
        }
    }
    cout<< endl;
    return 0;
}

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

int main(){
  long long int N,M,K=100;
  string S;
  
  cin>>N ;
  long long int cnt=0;
  while(K<N){
    cnt++;
    K*=1.01;
  }
  
  cout<<cnt<<endl;
  
   
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(void){
    int a, b, c, tmp = 0;
    cin >> a >> b >> c;
    
    if(b < a){
        tmp = a;
        a = b;
        b = tmp;
    }
    if(c < b){
        tmp = b;
        b = c;
        c = tmp;
    }
    if(b < a){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    cout << a << " " << b << " " << c << endl;
    return 0;
}



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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;


void solve(long long N){
	int a = N%10;
	if(a == 2 || a == 4 ||a == 5 ||a == 7 || a == 9) {
		cout << "hon" << endl;
	} else if (a == 0 || a == 1 || a == 6 || a == 8) {
		cout << "pon" << endl;
	} else {
		cout << "bon" << endl;
	}

}

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



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

int main() {
  std::string str1;
  std::string str2;
  std::string str3;
  int a;
  int b;
  
  cin >> str1 >> str2 >> a >> b >> str3;
  
  if (str3 == str1) {
    a = a - 1;
  }
  else{
    b = b - 1;
}
  cout << a << " " << b;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
    #define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
    #define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
constexpr int MAXN = 2e5 + 10;
LL nums[MAXN];
map<LL, vector<int>> table[32];





int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
#ifdef LOCAL
    freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    sort(nums, nums+n, greater<>());
    for (int i = 0; i < n; i++) {
        int j = 30;
        while (true) {
            if ((1LL<<j) & nums[i]) break;
            j--;
        }
        while (j >= 0) {
            if ((1LL<<j) & nums[i]) j--;
            else break;
        }
        j += 1;
        while (j < 32) {
            LL val = 1LL<<j;
            table[j][nums[i]%val].push_back(i);
            j++;
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (nums[i] == -1) continue;
        int j = 30;
        while (true) {
            if ((1LL<<j) & nums[i]) break;
            j--;
        }
        j++;
        LL rem = (1LL<<j) - nums[i];
        auto it = table[j].find(rem);
        if (it == table[j].end()) continue;
        while (!it->second.empty()) {
            int k = it->second.back();
            if (k == i && it->second.size() >= 2) {
                int sz = it->second.size();
                swap(it->second[sz-1], it->second[sz-2]);
                k = it->second[sz-1];
            }
            if (nums[k] == -1) {
                it->second.pop_back();
            } else {

                if (k == i) break;
                assert(nums[i] >= nums[k]);
                nums[k] = -1;
                nums[i] = -1;
                it->second.pop_back();
                cnt += 1;
                break;
            }
        }
    }
    cout << cnt << endl;





/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
    return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 134016
#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;
template<typename key>
using ordered_set = tree<key, null_type, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
#define F first
#define S second
#define T second.first
#define C second.second
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
#define all(v) v.begin(),v.end()
#define OO 0x3f3f3f3fLL
#define INF 0x3f3f3f3f3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout<<s,0
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll,pair<ll,ll>> piii;
const int N = 3e3+5, M= 5e5+5, mod = 998244353;
const double EPS = 1e-15;


int A[N], n, s;
ll mem[N][N];

ll solve(int idx, int sum){
    if(idx == n)return sum==s;
    if(sum>3000)
        return 0;

    ll& ret = mem[idx][sum];
    if(~ret)return ret;

    return ret = ((solve(idx+1, sum+A[idx])%mod) + 2*(solve(idx+1, sum)%mod))%mod;
}

int main(){
    FIO
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    cin>>n>>s;
    for(int i=0; i<n; i++)cin>>A[i];
    memset(mem, -1, sizeof mem);
    cout<<solve(0,0);

}


Measured memory_bytes: 74256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, u32, u64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);
parse_tuple!(A, B, C, D);
parse_tuple!(A, B, C, D, E);

// ===

fn main() {
    let n: i32 = read();
    if n == 1 {
        println!("Hello World");
    } else {
        let a: i32 = read();
        let b: i32 = read();
        println!("{}", a+b);
    }
}


Measured memory_bytes: 4352
N = int(input())
AB_number = 0
ab_cnt =0
a_cnt = 0
b_cnt = 0
for _ in range(N):
    s_i = input()
    AB_number += s_i.count("AB")
    if s_i[0] == "B" and s_i[-1] == "A":
        ab_cnt += 1
    elif s_i[-1] == "A":
        a_cnt += 1
    elif s_i[0] == "B":
        b_cnt += 1

if ab_cnt== 0:
    print(AB_number+min(a_cnt,b_cnt))
elif a_cnt != b_cnt:
    print(AB_number+(ab_cnt-1)+1+min(a_cnt,b_cnt))
elif a_cnt==0:
    print(AB_number+(ab_cnt-1)+min(a_cnt,b_cnt))
else:
    print(AB_number+(ab_cnt-1)+1+min(a_cnt,b_cnt))


Measured memory_bytes: 3064
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <numeric>
typedef long long int ll;
using namespace std;

int main(){
	string S;
	cin>>S;
	for(int i=0;i<(S.length()-1)/2;i++){
		if(S[i]==S[(S.length()-1)/2-i-1]){
		}else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	for(int i=(S.length()+3)/2-1;i<S.length();i++){
		if(S[i]==S[S.length()-i-1]){
		}else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN 1000005
#define INF 0x3f3f3f3f
#define MS(x, i) memset(x, i, sizeof x)
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define MOD 1000000007
#define NOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;


int a[MAXN];

inline ll read() {
    ll ret = 0, sgn = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-') sgn = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        ret = ret*10 + ch - '0';
        ch = getchar();
    }

    return ret*sgn;
}

int main()
{
    NOS

    string s;
    cin >> s;
    int n = s.length();
    int give = 0;
    int ret = 0;
    int jw = 0;

    for(int i = 1; i <= n; i++)
        a[i] = s[i - 1] - '0';

    for(int i = n; i >= 0; i--)
    {
        if(a[i] == 9 && jw == 1)
            a[i] = 0;
        else if(jw == 1)
        {
            a[i] += jw;
            jw = 0;
        }
        if(a[i] < 5)
            give += a[i];
        else if(a[i] == 5)
        {
            if(a[i - 1] >= 5)
            {
                jw++;
                ret += 5;
            }
            else
                give += 5;
        }
        else
        {
            jw++;
            ret += (10 - a[i]);
        }
    }

    cout << give + ret << endl;

}


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

vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; p++) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            num++;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    ll n;
    cin >> n;
    auto v = prime_factorize(n);
    int ans = 0;
    for (int i = 0; i < v.size(); i++) {
        ll d = v[i].first;
        for (int j = 0; j < v[i].second; j++) {
            if (n % d == 0) {
                n /= d;
                ans++;
            }
            d *= v[i].first;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> candle(n);
  for(int i = 0;i < n;i++)cin >> candle[i];
  int res = 0;
  res = INT_MAX;
  for(int i = 0;i <= n - k;i++){
    res = min(res,min(abs(candle[i]),abs(candle[i + k - 1])) + abs(candle[i + k - 1] - candle[i]));
    //res = min(res,abs(candle[i + k - 1] + abs(candle[i + k - 1] - candle[i])));
  }
  cout << res << endl;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, A: int, B: int, C: int, s: "List[int]"):
    v = [A, B, C]
    ans = []
    if sum(v) == 0:
        return None
    if sum(v) == 1:
        for l, r in s:
            if v[l] + v[r] == 0:
                return None
            if v[l] == 0:
                ans.append(l)
            else:
                ans.append(r)
            v[l], v[r] = v[r], v[l]
        return ans
    if sum(v) > 1:
        for i in range(N):
            l, r = s[i]
            if v[l] + v[r] == 0:
                return None
            if v[r] == 0 or v[l] > v[r] or (v[r] == v[l] and i != N - 1 and r in s[i + 1]):
                ans.append(r)
                v[l] -= 1
                v[r] += 1
            else:
                ans.append(l)
                v[l] += 1
                v[r] -= 1
        return ans


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    def s2i(s: str):
        return ord(s[0])-ord('A'), ord(s[1])-ord('A')

    def i2s(i: int):
        return chr(i + ord('A'))

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    s = [s2i(next(tokens)) for _ in range(N)]  # type: "List[int]"
    ans = solve(N, A, B, C, s)
    if ans == None:
        print(NO)
    else:
        print(YES)
        print("\n".join(list(map(i2s, ans))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 89724
#include<bits/stdc++.h>
using namespace std;
int n;
double a[105];
int main()
{
    cin>>n;
    double sum1=0,sum2=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum1+=a[i];
    }
    double m=sum1*1.0/n,ans=0;
    //cout<<m<<endl;
    m=round(m);
    for(int i=0;i<n;i++){
        ans+=(a[i]-m)*(a[i]-m);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    ll n,g;
    cin >> n >> g;
    vl w(n);
    vl v(n);
    rep(i,n) cin >> w[i] >> v[i];
    ll dp[n+1][g+1];
    rep(i,n+1) rep(j,g+1) dp[i][j]=0;
    for(ll i=n-1;i>=0;i--){
        for(ll j=0;j<=g;j++){
            if(j-w[i]>=0) dp[i][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
            else{
                dp[i][j]=dp[i+1][j];
            }
        }
    }
    cout << dp[0][g]<< endl;

    return 0;
}


Measured memory_bytes: 79104
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>


typedef long long LL;

using namespace std;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

int main(void) {
	int n;
	cin >> n;
	vector<int>a(n);
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int count = 1;
	for (int i = 0; i < n - 1; i++) {
		//連続してたら
		if (a[i] == a[i + 1]) {
			count++;
		}
		//不連続なら清算してリセット
		else {
			ans += count / 2;
			count = 1;
		}
		//最後まで見たら清算
		if (i == n - 2) {
			ans += count / 2;
		}
	}
	cout << ans;
	return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    int h[n];
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    vector<int> G[n];
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int ans = 0;
    bool flag = true;
    for(int i=0;i<n;i++){
        flag = true;
        for(int j=0;j<G[i].size();j++){
            if(h[i]<=h[G[i][j]]){
                flag=false;
            }
        }
        if(flag){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9152
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    char s[110],t[110];
    int n,ans=100,f[30]={},flag;
    scanf("%s",s);
    n=strlen(s);
    for(int i=0;i<n;i++){
        f[s[i]-'a']++;
        if(f[s[i]-'a']==n){
            printf("0\n");
            return 0;
        }
    }
    for(int i=0;i<30;i++){
        if(f[i]){
            for(int j=0;j<n;j++){
                t[j]=s[j];
            }
            for(int j=n-1;j>1;j--){
                flag=1;
                for(int k=0;k<j;k++){
                    if(t[k]==i+'a'||t[k+1]==i+'a'){
                        t[k]=i+'a';
                    }
                    else{
                        flag=0;
                    }
                }
                if(flag){
                    ans=min(ans,n-j);
                    break;
                }
            }
        }
    }
    printf("%d\n",ans);
}

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

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define IN1(x) ll x; cin >> x;

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <typename T>
vector<T> pows(int n) {
    vector<T> ret;
    T x = 1;
    while (ret.size() < n) {
        ret.push_back(x);
        x *= 10;
    }
    return ret;
}

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

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }

template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }
void YesNo(bool f) { cout << (f?"Yes":"No") << endl; }
void YESNO(bool f) { cout << (f?"YES":"NO") << endl; }

int main(void)
{
    cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	IN1(N);

	vector<ll> a(N); REP(i, N) cin >> a[i];
	sort(all(a));
	vector<ll> im(N);
	im[0] = a[0];
	FOR(i, 1, N) im[i] = im[i-1] + a[i];

	REP(i, N-1) {
		if (im[N-2-i] * 2 < a[N-1-i]) {
			out(1 + i);
			return 0;
		}
	}
	out(N);

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(c-(a-b),0)<<endl;
    return 0;
}


Measured memory_bytes: 256