akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

vector< int > z_algorithm(const string &s) {
  vector< int > prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  rep(i,n){
    string tmp = s.substr(i);
    VI v = z_algorithm(tmp);

    FOR(j,1,v.size()){
      ans = max(ans,min<int>(v[j],j));
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

/*
cin.tie(0);
ios::sync_with_stdio(false);
*/
int main() {
	int n, i, j;
	cin >> n;
	vector<pii> x(n);
	for (i = 0; i < n; i++) {
		cin >> x[i].first >> x[i].second;
	}
	sort(x.begin(), x.end());
	ll ans;
	ans = x[n - 1].first;
	ans += x[n - 1].second;
	cout << ans << endl;
	


}

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

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

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

int main() {
  int a, b;
  cin >> a >> b;

  if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

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

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

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  if(n % 2){
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  for(ll i = 10; i <= n; i *= 5){
    ans += n / i;
  }

  cout << ans << endl;
  return 0;
}

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

int main() {
    string s;
    string zz(5000, 'z');
    vector<string> memo(5, zz);
    int K;
    cin>>s>>K;
    for(int i=0; i<s.length(); i++) {
        for(int j=i; j<s.length(); j++) {
            string tmp = s.substr(i,j-i+1);
            if(memo[4]<tmp) continue;
            for(int k=0; k<5; k++) {
                if(memo[k] == tmp) break;
                if(memo[k] > tmp) {
                    memo.insert(memo.begin()+k, tmp);
                    break;
                }
            }
        }
    }

    cout<<memo[K-1]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define optimize  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back

using namespace std;

int main()
{
    optimize;

   ll s=0;
   int n;

   cin>>n;

   int a[n];
   cin>>a[0];
   s = abs(0-a[0]);
   for(int i = 1;i<n;i++){
      cin>>a[i];

      s = s + abs(a[i-1]-a[i]);

   }

   s = s + abs(0-a[n-1]);
   ll ss = s;
   for(int i = 0;i<n;i++){
    ss  = s;
    if(i==0){
        ss = ss - abs(0-a[i]) - abs(a[i]-a[i+1]);
        ss = ss + abs(0 - a[i+1]);
        cout<<ss<<endl;

    }
    else if(i==n-1){
        ss = ss - abs(a[i-1]-a[i]) - abs(a[i]-0);
        ss = ss + abs(a[i-1]-0);
        cout<<ss<<endl;
    }
    else{
        ss = ss - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]);
        ss = ss+abs(a[i-1]-a[i+1]);
        cout<<ss<<endl;
    }
   }

}



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

int main() {
	ll n,k;
	cin>>n>>k;
	ll a[n],dp[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	dp[i]=pri;
		
	}
	dp[0]=0;
	for(ll i=0;i<n;i++){
	for(ll j=1;j<=k&&i+j<n;j++)  { dp[i+j]=min(dp[i+j],abs(a[i+j]-a[i])+dp[i]);}
		
	}
	
	cout<<dp[n-1]<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    A = cin.mapInt()
    ans = 0
    for i in range(N - 2):
        ans += min(A[i],A[i + 1])
    ans += A[0]
    ans += A[N - 2]
    print(ans)
    return

if __name__ == "__main__":
    main()


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

vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p=-1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u, v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i, q) {
    int p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i, n) {
    cout << ans[i] << endl;
  }
  return 0;
}


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

using namespace std;

map<string,int> mp;
set<string> s;
set<string> os;
int main()
{
    string str;
    int n,mx=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>str;
        s.insert(str);
        mp[str]++;
        if(mx<mp[str]){
            mx=mp[str];
            os.clear();
            os.insert(str);
        }
        else if(mp[str]==mx){
            os.insert(str);
        }
       /// sort(a+1,a+n+1); ///pt un sir a[1]..a[n]
        /// sort(a+1,a+n+1,greater<int>()); ///descr pt un sir a[1]..a[n]

           }
    for(auto x:os){
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 43904
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

ll MOD = 1e9+7;

inline ll MUL(ll a, ll b, const ll MD=MOD) {
	if (MD == 0) return -1;
	return (a * b) % MD;
}

inline ll ADD(ll a, ll b, const ll MD=MOD) {
	if (MD == 0) return -1;
	return (a + b) % MD;
}

inline ll SUB(ll a, ll b, const ll MD=MOD) {
	if (MD == 0) return -1;
	a %= MD;
	b %= MD;
	return ((a - b) % MD + MD) % MD;
}

inline ll powMod(ll a, ll p, const ll MD=MOD) {
	if (MD == 0) return -1;
	ll res = 1;
	for (; p; p >>= 1, a = MUL(a,a,MD)) {
		if (p & 1) res = MUL(res,a,MD);
	}
	return res;
}

ll eval(ll val) {
	if (val == 0) return 0;
	return 1LL + eval(val % __builtin_popcountll(val));
}

const int sz = 3e5+5;
pll curr[sz];

int main() {
	int N;
	sci(N);
	string s;
	cin >> s;
	int hit = 0;
	for (int i = 0; i < s.size(); ++i) {
		hit += s[i] == '1';
	}
	ll gede = 0;
	ll kecil = 0;
	for (int i = 0; i < s.size(); ++i) {
		pll tmp = {powMod(2, s.size()-1-i, hit+1), powMod(2, s.size()-1-i, hit-1)};
		if (s[i] == '1') {
			gede = ADD(gede, tmp.fi, hit+1);
			kecil = ADD(kecil, tmp.se, hit-1);
		}
	}
	for (int i = 0; i < s.size(); ++i) {
		ll tmp;
		if (s[i] == '0') {
			tmp = ADD(gede, powMod(2, s.size()-1-i, hit+1), hit+1);
		} else {
			tmp = SUB(kecil, powMod(2, s.size()-1-i, hit-1), hit-1);
		}
		if (tmp >= 0) {
			printf("%lld\n", 1+eval(tmp));
		} else {
			printf("0\n");
		}
	}
	return 0;
}

Measured memory_bytes: 3916
# Bibary Search Tree

import sys
sys.setrecursionlimit(2**20)  # 再帰回数上限の向上 かなり多くしないとREになる

root = None

class Node:
    def __init__(self,
                 parent=None,
                 left=None,
                 right=None):
        self.parent = parent
        self.left = left  # 左の子ノード
        self.right = right  # 右の子ノード

# 先行順巡回
def pre_parse(T: dict, u: int, pre_ls: list):
    # 深さ優先探索特有の即時終了条件
    if u == None:
        return
    pre_ls.append(u)
    pre_parse(T, T[u].left, pre_ls)  # より左の方から深さ優先探索
    pre_parse(T, T[u].right, pre_ls)

# 中間順巡回
def in_parse(T, u, in_ls):
    if u == None:
        return
    # 左→中→右の順に巡回
    in_parse(T, T[u].left, in_ls)
    in_ls.append(u)
    in_parse(T, T[u].right, in_ls)

# 挿入
def insert(T, z):
    global root
    T[z] = Node()
    y = None # xの親
    x = root # Tの根
    while (x is not None):
        y = x # xの親を設定
        if z < x:
            x = T[x].left # 左の子へ移動
        else:
            x = T[x].right # 右の子へ移動
    T[z].parent = y # zの親にyを設定
    if (y is None):
        root = z
    elif (z < y):
        T[y].left = z # yの左の子にする
    else:
        T[y].right = z # yの右の子にする


def find(T,  ROOT, k):
    x = ROOT # 訪問中のノード
    while T[x] is not None and x != k:
        if (k < x):
            T[x].left = x
        else:
            T[x].right = x
    return x

def print_result(T):
    pre_ls, in_ls = [], []
    in_parse(T, root, in_ls)
    pre_parse(T, root, pre_ls)
    print('', *in_ls)
    print('', *pre_ls)

N = int(input())
lst = [input().split() for i in range(N)]
T = {}
for i, c in enumerate(lst):
    if c[0] == 'insert':
        z = int(c[1])
        insert(T, z)
    elif c[0] == 'print':
        print_result(T)
    elif c[0] == 'find':
        is_find = find(T, root, z)
        if is_find is None:
            print('no')
        else:
            print('Yes')


Measured memory_bytes: 279876
def main():
    N = int(input())
    an = [0] + list(map(int, input().split()))

    res = [0] * (N + 1)

    for i in range(N, 0, -1):
        res[i] = (sum(res[2 * i::i]) % 2) ^ an[i]

    print(sum(res))
    print(*[i for i in range(N + 1) if res[i]])


if __name__ == '__main__':
    main()


Measured memory_bytes: 75612
#include "bits/stdc++.h"

using namespace std;

int n;
vector<string> s;

bool isvowel(char c)
{
  static const string vowel = "aiueo";
  for (int i = 0; i < 5; i++) {
    if (c == vowel[i]) return true;
  }
  return false;
}

string getname(string str)
{
  string res;
  res += str[0];
  for(int i = 1; i < str.size(); i++) {
    if(isvowel(str[i - 1])) {
      res += str[i];
    }
  }
  return res;
}

bool enough(int size)
{
  for(int i = 1; i < n; i++) {
    if (s[i].substr(0, min<int>(s[i].size(), size)) == s[i - 1].substr(0, min<int>(s[i - 1].size(), size))) return false;
  }
  return true;
}

static void solve()
{
  while(cin >> n && n) {
    s.resize(n);
    int start = 1, end = 50;
    int max_size = 0;
    for(int i = 0; i < n; i++) {
      cin >> s[i];
      s[i] = getname(s[i]);
      max_size = max<int>(max_size, s[i].size());
    }
    sort(s.begin(), s.end());
    while(start < end && start <= max_size) {
      int middle = (start + end) / 2;
      if (enough(middle)) {
        end = middle;
      }
      else {
        start = middle + 1;
      }
    }
    if(max_size < start) {
      cout << "-1\n";
    }
    else {
      cout << start << "\n";
    }
  }
}

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

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

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			//			 solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int numA = nextInt();
		int numB = nextInt();
		int numH = nextInt();

		out.println((numA + numB) * numH / 2);
	}

	private void solveB() {
		int numN = nextInt();

		out.println("");
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

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

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

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

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

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

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

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

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

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;

ll power(ll x, ll y){
    x %= MOD;
    ll ans = 1;
    while(y){
        if(y & 1)
            ans = (ans * x) % MOD;
        y >>= 1LL;
        x = (x * x) % MOD;
    }
    return ans;
}
ll ad(ll a, ll b){
    return((a % MOD + b % MOD) % MOD);
}
ll sub(ll a, ll b){
    return((a % MOD - b % MOD + MOD) % MOD);
}
ll mul(ll a, ll b){
    return(((a % MOD) * (b % MOD)) % MOD);
}
ll divi(ll a, ll b){
    return(mul(a, power(b, MOD - 2)) % MOD);
}

int main(){
	fast;
	ll n;
	cin >> n;
	cout << sub(ad(power(10, n), power(8, n)), ad(power(9, n), power(9, n)));
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>
#include <iomanip>
#include <set>

ll gcm(ll a, ll b)
{
	if (b>a) {ll c=a; a=b; b=c;}
	while (b>0)
	{
		ll r=a%b;
		a=b;
		b=r;
	}
	return a;
}
 
 
int main(int argc, char *argv[])
{
	int n;
	cin>>n;
	int Gall;
	

	bool pair=true;
	set<int> Prime;
	for (int i=0;i<n;i++)
	{
		int a;cin>>a;
		if (i==0) Gall=a; else Gall=gcm(Gall,a);
		if (pair)
		{
			for (int x=2;x*x<a;x++)
			{
				if (a%x==0)
				{
					while (a%x==0) a/=x;
					if (Prime.count(x)) pair=false; else Prime.insert(x);
				}
			}
			if (a>1)
			{
				if (Prime.count(a)) pair=false; else Prime.insert(a);
			}
		}
	}
	if (pair) cout<<"pairwise coprime"<<endl;
	else if (Gall==1) cout<<"setwise coprime"<<endl;
	else cout<<"not coprime"<<endl;

	return 0;
}


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

int main(){
  int n;
  while(cin >> n){
    int cnt = 0;
    for(int a = 0; a < 10; a++){
      for(int b = 0; b < 10; b++){
	for(int c = 0; c < 10; c++){
	  int d = n - (a + b + c);
	  if(d >= 0 && d <= 9) cnt++;
	}
      }
    }
    cout << cnt << endl;
  }
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int color, count = 0;
  if(S.at(0) == 'W') color = 0;
  else color = 1;
  for(char a: S) {
    if(a == 'W' && color == 1) {
      count++;
      color = 0;
    }
    else if(a == 'B' && color == 0) {
      count++;
      color = 1;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
     
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,w;
  cin >> n >> w;
  vector<int> vi(n);
  vector<long long> wi(n);
  for(int i = 0; i<n;i++){
    cin >> wi[i] >> vi[i];
  }
  long long dp[n+1][w+1];
  for(int i = 0; i<=n;i++){
    for(int j = 0; j<=w;j++){
      if(i==0 || j==0){
	dp[i][j] = 0;
      }else{
	if(j>=wi[i-1]){
	  dp[i][j] = max(dp[i-1][j],dp[i-1][j-wi[i-1]]+vi[i-1]);
	}else{
	  dp[i][j] = dp[i-1][j];
	}
      }
    }
  }
  cout << dp[n][w]<<'\n';
  return 0;
}


Measured memory_bytes: 82500
// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  // 1行目がinput[0], 2行目がinput[1], …に入る
  var inputs = input[1].split(" ");

  // argsは配列
  function avg(args) {
    var num = 0;
    for(var n of args) {
      num += Number(n);
    }
    return num / args.length;
  }
  var average = Math.round(avg(inputs));
  // console.log(average);

  var useStamina = 0;
  for(var point of inputs) {
    useStamina += Math.pow(average - point, 2);
  }
  console.log(useStamina);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main('2\n1 4');
// Main('7\n14 14 2 13 56 2 37');


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

int main() {
  int A,B;
  cin >> A >> B;
  int cost = B;
  if(A>=13){
    cout << B << endl;
  }
  if(A>=6 && A<=12){
    cout << B/2 << endl;
  }
  if(A<=5){
    cout << 0 << endl;
  }
}

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

typedef long long ll;
const int N = 1000006;
const ll MOD = 1000000007;

ll n,m,k;
int a[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	vector<int> ps,ng;
	int z = 0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a[i] = abs(x);
		if(x == 0){
			z++;
			continue;
		}
		if(x > 0) ps.push_back(x);
		else ng.push_back(x);
	}
	
	if(z + k > n){
		cout<<"0";
		return 0;
	}
	
	sort(a,a+n);
	sort(ps.begin(),ps.end());
	sort(ng.begin(),ng.end());
	reverse(ng.begin(),ng.end());
	
	ll ans = 1;
	
	if(k == (n-z) && ((int)ng.size()%2 == 1)){
		if(z){
			cout<<0;
			return 0;
		}
		for(int i=0;i<n;i++){
			ans *= a[i];
			ans %= MOD;
		}
		ans *= -1;
		ans += MOD;
		cout<<ans;
		return 0;
	}
	if(k%2 == 1 && (int)ps.size() == 0){
		if(z){
			cout<<0;
			return 0;
		}
		for(int i=0;i<k;i++){
			ans *= a[i];
			ans %= MOD;
		}
		ans *= -1;
		ans += MOD;
		cout<<ans;
		return 0;
	}
	
	if(k%2 == 1 && ps.size()){
		ans = ps[(int)ps.size()-1];
		ps.pop_back();
	}
	ans %= MOD;
	for(int i=0;i<k/2;i++){
		ll x = 1,y = 1;
		if((int)ps.size() > 1){
			int sz = (int)ps.size();
			x *= ps[sz-1];
			x *= ps[sz-2];
		}
		if((int)ng.size() > 1){
			int sz = (int)ng.size();
			y *= ng[sz-1];
			y *= ng[sz-2];
		}
		if(x >= y){
			x %= MOD;
			ans *= x;
			ans %= MOD;
			ps.pop_back();
			ps.pop_back();
		}else{
			y %= MOD;
			ans *= y;
			ans %= MOD;
			ng.pop_back();
			ng.pop_back();
		}
	}
	ans %= MOD;
	ans += MOD;
	ans %= MOD;
	cout<<ans;
	
	return 0;
}


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


void solve(long long N, std::vector<long long> A){
    unordered_set<long long> nums;
    for(auto a:A){
        if(nums.find(a) != nums.end())nums.erase(a);
        else nums.insert(a);
    }
    cout << nums.size() << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 5156
r,c=map(int,input().split())
meiro=[list(input()) for i in range(r)]
#迷路の白マスを数える作業
white=0
for i in range(r):
    for j in range(c):
        if meiro[i][j]==".":
            white+=1
#迷路の外を＃で囲む
for i in range(r):
    meiro[i].insert(c,"#")
    meiro[i].insert(0,"#")
meiro.insert(0,["#"]*(c+2))
meiro.append(["#"]*(c+2))
#print(meiro)囲えた
idou=[[0,1],[0,-1],[1,0],[-1,0]]
tesuu=[[-1]*(c+2) for i in range(r+2)]
from collections import deque
tesuu[1][1]=1
#print(tesuu)
quest=deque([[1,1]])#最初に見る場所
while len(quest)!=0:
    see=quest.popleft()
    for i in idou:
        if meiro[see[0]+i[0]][see[1]+i[1]]=="#":
            continue
        if tesuu[see[0]+i[0]][see[1]+i[1]]!=-1:
            continue
        quest.append([see[0]+i[0],see[1]+i[1]])
        tesuu[see[0]+i[0]][see[1]+i[1]]=tesuu[see[0]][see[1]]+1
#print(meiro)
#print(tesuu[r][c])
gy=r;gx=c
if tesuu[gy][gx]==-1:
    print(-1)
else:
    print(white-tesuu[gy][gx])

Measured memory_bytes: 40560
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
#define F first
#define S second
#define pb push_back 
#define mp make_pair
#define vi vector <int>
#define vb vector <bool>
#define vc vector <char>
#define vll vector <ll>
#define vs vector <string>
#define pll pair < ll , ll >
#define pld pair < ld , ld >
#define pii pair < int , int >
#define vpld vector < pld >
#define vpii vector < pii >
#define vpll vector < pll >
#define vvi vector < vector < int > >
#define vvll vector < vector < ll > >
#define vvld vector < vector < ld > >
#define vvb vector < vector < bool > >
#define vvpii vector < vector < pii > >
#define all(v) (v).begin() , (v).end()
#define allrev(v) (v).rbegin() , (v).rend()
#define dist(x1 , y1 , x2 , y2) sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1))
const int MOD = 1e9 + 7 ;
const int infi = INT_MAX ;
const ll infll = LLONG_MAX ;
const int dx4[] = {0 , -1 , 0 , 1} ;
const int dy4[] = {-1 , 0 , 1 , 0} ;
const int dx8[] = {-1 , -1 , -1 , 0 , 1 , 1 , 1 , 0} ;
const int dy8[] = {-1 , 0 , 1 , 1 , 1 , 0 , -1 , -1} ;
const ld PI = 3.1415926535897932384626 ;

///////////////////////////////////////////////////////////////////////////////////////

ll pow_mod(ll a , ll b , ll m) {
	ll ans = 1 ;
	while(b)
	{
		if (b&1) {
			ans = (ans*a) % m ;
		}
		b /= 2 ;
		a = (a*a) % m ;
	}
	return ans ;
}

bool isprime(ll num) {
    for (ll i = 2 ; i * i <= num ; ++i)
        if (num % i == 0) {
        	return false ;
		}
    return true;
}

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

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

///////////////////////////////////////////////////////////////////////////////////////

void solve (int test_case) {
	string s , t ;
	cin >> s >> t ;
	int n = s.size() ;
	int ans = 0 ;
	for (int i = 0 ; i < n ; ++i) {
		if (s[i] != t[i]) ++ ans ;
	}
	cout << ans << "\n" ;
}

int main() {
	ios_base :: sync_with_stdio (false) ;
	cin.tie(0) ;
	cout.tie(0) ;
	int tc = 1 ;
	//cin >> tc ;
	while (tc--) {
		solve (tc) ;
	}
	return 0 ;
}

Measured memory_bytes: 3884
n = int(input())
LR = [None] * n
for i in range(n):
    x, l = map(int, input().split())
    LR[i] = (x - l, x + l)
LR.sort(key=lambda lr: lr[1])
count = 1
cur = LR[0][1]
for l, r in LR[1:]:
    if cur <= l:
        count += 1
        cur = r
print(count)


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

int		main(void)
{
	int a, b, c;

	cin >> a >> b >> c;
	int x = max(a, max(b, c));
	int y = a + b + c - x;

	if (x == y)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


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

#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define ll long long

int main(void)
{
    char c;
    while((c=getchar())!=EOF)
    {
        if(isupper(c))
        {
            c = tolower(c);
        }
        else if(islower(c))
        {
            c = toupper(c);
        }
         putchar(c);
    }
    return 0;
}




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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
/* func */
int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
int32_t LCM(int32_t a, int32_t b){return a * b / GCD(a, b);}
int64_t LCM(int64_t a, int64_t b){return a * b / GCD(a, b);}
 
/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;
 
 
//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001
 
/*global*/
 
 
//for dfs, I prepare container(tree) at global
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1){
	for(int u: to[v]){
		if(u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}
 
//#define int int64_t
signed main()
{
	int n, q; cin >> n >> q;
	for(int i = 0, i_len = (int)n-1; i < i_len; ++i){
		int a, b;
		cin >> a >> b;
		--a;--b;
		to[a].emplace_back(b);
		to[b].emplace_back(a);		
	}
	ans.resize(n);
	for(int i = 0, i_len = (int)q; i < i_len; ++i){
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	dfs(0);
 
	for(int i = 0, i_len = (int)n; i < i_len; ++i){
		cout << ans[i] << "\n";
	}
 
}

Measured memory_bytes: 23552
#include <stdio.h>

int main()
{
	int N, Q;
	scanf("%d", &N);
	int A[100001] = {0};
	long long sum = 0;
	while (N--)
	{
		int a;
		scanf("%d", &a);
		A[a]++;
		sum += a;
	}
	scanf("%d", &Q);
	while (Q--)
	{
		int b, c;
		scanf("%d%d", &b, &c);
		sum += A[b] * (c - b);
		A[c] += A[b];
		A[b] = 0;
		printf("%ld\n", sum);
	}
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ff(i,a,b) for(int i = a; i < b; i++)
#define fb(i,a,b) for(int i = a; i > b; i--)
#define MOD 1000000007


ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}


void solve(){
	string n;
	cin>>n;
	ll ans=0;
	ff(i,0,n.length()){ ans+=(n[i]-'0'); ans%=9;}
	//cout<<ans;
	if(ans%9) cout<<"No";
	else cout<<"Yes";
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	//int t;
    //cin>>t;
	//while(t--)
		solve();
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define ll long long
#define _USE_MATH_DEFINES
# define M_PI           3.14159265358979323846
#include <math.h>
using namespace std;
int main()
{
    ll t;
    {
       long double n,a,b;
       cin>>n;
       a=2*M_PI*n;
       cout<<fixed<<setprecision(20)<<a<<endl;

    }

}



Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,x;
	cin>>a>>b>>x;
	if(a>x)
		cout<<"NO";
	else if(a+b>=x)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

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

int main() {
  string S;
  cin>>S;
  vector<char>a={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  for(int I=0;I<26;I++){
    bool A=true;
    for(int J=0;J<S.size();J++){
      if(S.at(J)==a.at(I)){
        A=false;
      }
    }
      
      if(A){
        cout<<a.at(I)<< endl;
        return 0;
      }
    
  }
  cout<<"None"<< endl;
}
      
    
    
  

Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N, T;
	int ans = INF32;
	cin >> N >> T;

	for (int i = 0; i < N; i++)
	{
		int cost, time;
		cin >> cost >> time;
		if (time <= T)
			ans = min(ans, cost);
	}
	if (ans == INF32)
	{
		cout << "TLE" << endl;
	}
	else
	{
		cout << ans << endl;
	}

	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	double EPS = 1.0e-05;

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int q = sc.nextInt();
			if(q == -1) break;
			double prev = (double) q / 2;
			for(int i = 0; ; i++){
				double res = prev - (prev * prev * prev - q) / (3 * prev * prev);
				if(Math.abs(res * res * res - q) < EPS * q){
					System.out.printf("%.6f\n",res);
					break;
				}
				prev = res;
			}
		}
		//System.out.printf("%.6f\n",EPS);
	}

	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 12000
MAX_N = 10 ** 5 + 10
N = int(input())
dp = [[0] * 3 for _ in range(MAX_N)]

arr = [0] * MAX_N
for i in range(N):
    arr[i] = list(map(int, input().split()))

for i in range(1, N+1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i][k] = max(dp[i][k], dp[i-1][j] + arr[i-1][k])

print(max(dp[N]))

Measured memory_bytes: 68716
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a % 2 == 1 && b % 2 == 1)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

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

class Solution {
public:
    void print(vector<int>& v) {
        for (int i = 0; i < v.size(); ++i) {
            cout << v[i];
            if (i + 1 != v.size()) {
                cout << " ";
            }
        }
        cout << endl;
    }

    void InsertionSort(vector<int>& v) {
        int key = 0;
        for (int i = 1, j = 0; i < v.size(); ++i) {
            key = v[i];

            print(v);

            j = i - 1;
            while (j >= 0 && v[j] > key) {
                v[j + 1] = v[j];
                j--;
            }
            v[j + 1] = key;
        }
        print(v);

    }
};

int main() {
    int n = 0;
    cin >> n;
    vector<int> inp = vector<int>(n ,0);

    for (int i = 0; i < n; ++i) {
        cin >> inp[i];
    }
    (new Solution)->InsertionSort(inp);
}



Measured memory_bytes: 3112
// Contest.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>

using namespace std;

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++)if (s[i] == ',')s[i] = ' ';
	cout << s;
	return 0;
}



Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
   SELECT SYSIN ASSIGN TO KEYBOARD ORGANIZATION LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD SYSIN.
   01 INDATA  PIC X(400000).
WORKING-STORAGE SECTION.
01 ln         PIC X(400).
01 maxlen     PIC 9(10) COMP.
01 cur        PIC 9(10) VALUE 1 COMP.
01 i          PIC 9(10) VALUE 1 COMP.
01 j          PIC 9(10) COMP.
01 len        PIC 9(10) COMP.
01 ans        PIC 9(10) VALUE ZERO.
01 zs         PIC Z(9)9.
01 N          PIC 9(10).
01 K          PIC 9(10).
01 h1.
   03 h11 OCCURS 100000 DEPENDING ON N.
      05 h    PIC S9(10).

PROCEDURE DIVISION.
  ACCEPT ln.
  UNSTRING ln DELIMITED BY SPACE INTO N K.
  OPEN INPUT SYSIN.
  READ SYSIN INTO INDATA.
  CLOSE SYSIN.
  MOVE N TO maxlen.
  PERFORM maxlen TIMES
    PERFORM VARYING j FROM cur BY 1 UNTIL INDATA(j:1) = SPACE
    END-PERFORM
    COMPUTE len = j - cur
    MOVE INDATA(cur:len) TO h(i)
    IF K <= h(i)
      ADD 1 TO ans
    END-IF
    COMPUTE cur = j + 1
    ADD 1 TO i
  END-PERFORM.
  MOVE ans TO zs.
  DISPLAY FUNCTION TRIM(zs).
  STOP RUN.


Measured memory_bytes: 5240
import java.util.*;
import java.io.*;
public class Main{
	static class node{
		int x,y,d;
		 node(int x1, int y1,int d1){x=x1;y=y1;d=d1;}
	}

public static long gcd(long a,long b){
	if(b==0){return a;}
	return gcd(b,a%b);
}

static int bfs(int[][] arr, int sx,int sy,int dx,int dy){
	int n=arr.length,m=arr[0].length;
	Queue<node> q=new LinkedList<>();
	boolean[][] b=new boolean[n][m];
	if(arr[sx][sy]!=0)q.add(new node(sx,sy,0));
	b[sx][sy]=true;
	while(!q.isEmpty()){
		node curr=q.poll();
		int x=curr.x,y=curr.y,d=curr.d;
		if(x==dx&&y==dy){return d;}
		if(y+1<m&&arr[x][y+1]!=0&&!b[x][y+1]){q.add(new node(x,y+1,d+1));b[x][y+1]=true;}
		if(y-1>=0&&arr[x][y-1]!=0&&!b[x][y-1]){q.add(new node(x,y-1,d+1));b[x][y-1]=true;}
		if(x+1<n&&arr[x+1][y]!=0&&!b[x+1][y]){q.add(new node(x+1,y,d+1));b[x+1][y]=true;}
		if(x-1>=0&&arr[x-1][y]!=0&&!b[x-1][y]){q.add(new node(x-1,y,d+1));b[x-1][y]=true;}
	}
	return -1;
}
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       int n=s.nextInt(),m=s.nextInt();
       s.nextLine();
       int[][] arr=new int[n][m];
       int[][][][] dp=new int[n][m][n][m];
       for(int i=0;i<n;i++){
       	String ss= s.nextLine();
       	for(int j=0;j<m;j++){
       		if(ss.charAt(j)=='.'){arr[i][j]=1;}
       	}
       }
       int res=0;
        for(int i=0;i<n;i++){
        	for(int j=0;j<m;j++){
        		for(int k=0;k<n;k++){
        			for(int l=0;l<m;l++){
        				if(dp[k][l][i][j]!=0){dp[i][j][k][l]=dp[k][l][i][j];continue;}
        				dp[i][j][k][l]=bfs(arr,i,j,k,l);
        				res=Math.max(res,dp[i][j][k][l]);
        			}
        		}
        	}
        }
                out.write(res+" ");
        
        out.flush();
  }
}


Measured memory_bytes: 276420
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			int x = scanner.nextInt();

			Set<Integer> costSet = new HashSet<>(m);
			for (int i = 0; i < m; i++) {
				int a = scanner.nextInt();
				costSet.add(a);
			}

			int costA = 0;
			for (int pos = x; pos > 0; pos--) {
				if (costSet.contains(pos)) {
					costA++;
				}
			}

			int costB = 0;
			for (int pos = x; pos < n; pos++) {
				if (costSet.contains(pos)) {
					costB++;
				}
			}

			System.out.println(Math.min(costA, costB));
		}
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 2e5 + 5;

ll n,a[N],f[N],sum[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum[i]=(i>1?sum[i-2]:0)+a[i];
	}
	for(int i=2;i<=n;i++){
		if(i&1) f[i]=max(f[i-2]+a[i],f[i-1]);
		else f[i]=max(f[i-2]+a[i],sum[i-1]);
	}
	cout<<f[n]<<'\n';
	return 0;
}

Measured memory_bytes: 8348
#include<iostream>
#include<string>
using namespace std;
int main(){
    int cnt = 0;
    string str;
    while(cin >> str){
        bool flg = 0;
        for(int i = 0; i < (str.size()+1)/2; i++){
            if(str[i] != str[str.size()-i-1]){
                flg = 1;
                break;
            }
        }
        if(!flg)cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
int N,Q;

int calc(int i,int n){
    int num = 0;
    if(n<10){
        return i;
    }else{
        int ten = 10;
        while(ten<= n){
            int temp = (n/ten) * (n%ten);
            if (num<temp)num=temp;
            ten *= 10;
        }
    }
    return calc(i+1,num);
}

int main(){

    cin >>Q ;
    for (int i=0;i<Q;i++){
        cin >> N;
        int ans = calc(0,N);
        cout << ans <<endl;
    }
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
using Tuple = tuple<int, int, int>;

int main() {
    int n; cin >> n;
    Graph g(n);
    rep(i, n-1) {
        int a; cin >> a;
        g[a-1].push_back(i+1);
    }

    rep(i, n) {
        cout << g[i].size() << endl;
    }

    return 0;

}

Measured memory_bytes: 14348
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 100
#define Pair pair<int,int>

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

int main(){
    ll n,a,b; cin >> n >> a >> b;
    ll x[n];
    ll dp[n];
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        dp[i] = min(dp[i-1]+(x[i]-x[i-1])*a, dp[i-1]+b);
    }
    cout << dp[n-1] << endl;
}


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

int main() {

    string s;

    cin >> s;

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

    if(s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(1) != s.at(2))cout << "Yes" << endl;
    else cout << "No" << endl;


}

Measured memory_bytes: 256
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Maybe

main :: IO ()
main = do
  [a,b] <- readInts
  print . showAnswer $ solve (a,b)

type Input  = (Int, Int)
type Output = Bool

solve :: Input -> Output
solve (a,b) = any odd $ map (\c -> a*b*c) [1..3]

showAnswer :: Output -> Answer
showAnswer = YesNo

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes" b
  show (YESNO b)    = bool "NO" "YES" b
  show (AB b)       = bool "B"  "A" b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

Measured memory_bytes: 380
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b;
    if(a==1){
        a=14;
    }
    if(b==1){
        b=14;
    }
    if(a<b){
        cout << "Bob" << endl;
    }else if(a>b){
        cout << "Alice" << endl;
    }else{
        cout << "Draw" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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


int main(){


    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }

    int ans = INF;

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

        int tmp1 = abs(a[i]) + abs(a[i+k-1]-a[i]);
        int tmp2 = abs(a[i+k-1]) + abs(a[i+k-1]-a[i]);
        int tmp3 = min(tmp1,tmp2);
        ans = min(ans,tmp3);

    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  int x, y, z;
  cin >> S;
  ;
}
void solve() {
  if (S == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (S == "Cloudy") {
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }

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

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

int main(void){
    string s1, s2;
    cin >> s1;
    cin >> s2;

    // implements
    if(s1[0]==s2[2] && s1[1]==s2[1] && s1[2]==s2[0]){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long n,q,t,i,a;
map<long,long>c;
int main(void){
  cin>>n;
  for(i=0;i<n;i++){
    cin>>t;
    c[t]++;
  }
  cin>>q;
  for(i=0;i<q;i++){
    cin>>t;
    a+=c[t]>0;
  }
  cout<<a<<endl;
  return 0;
}



Measured memory_bytes: 12464
N = int(input())
s = [input() for i in range(N)]
abc = sum([e.count("AB") for e in s]) # 各文字列のAB出現回数
bstart, aend = 0, 0
B_A = 0
for e in s:
    if e[0] == "B":
        bstart += 1
    if e[-1] == "A":
        aend += 1
    if e[0] == "B" and e[-1] == "A":
        B_A += 1
makedB_A = min(bstart-B_A, aend-B_A)
ans = 0

if bstart == 0 and aend == 0:
    ans = abc
elif bstart == aend:
    if makedB_A == 0:
        ans = abc + bstart - 1 
    else:
        ans = abc + bstart
else:
    ans = abc + min(bstart, aend)

    
print(ans)




Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define PB push_back
#define MP make_pair
#define S second
#define F first
//#define D cout<<"*\n";
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define mod 1000000007 
const double pi = 3.14159265358979323846; 

int dp[2][1000004];


int knapsack(int value[],int weight[],int n,int W)
{
	memset(dp,0,sizeof(dp));
	
   for(int i=1;i<=n;i++)
   {
   	  if(i&1)
   	  {
   	  	for(int j=0;j<=W;j++)
   	  	{
   	  		if(weight[i-1]>j)
   	  		dp[1][j]=dp[0][j];
   	  		else
   	  		{
   	  			dp[1][j]=max(dp[0][j],dp[0][j-weight[i-1]]+value[i-1]);
			}
    	 }
      }
      else
      {
      	for(int j=0;j<=W;j++)
   	  	{
   	  		if(weight[i-1]>j)
   	  		dp[0][j]=dp[1][j];
   	  		else
   	  		{
   	  			dp[0][j]=max(dp[1][j],dp[1][j-weight[i-1]]+value[i-1]);
			}
    	 }
	  }
   }
   
   if(n&1)
   return dp[1][W];
   return dp[0][W];
	
}

signed main()
{
    fast
    int t=1;
   // cin>>t;
    
    while(t--)
    {
      int n,W;
      cin>>n>>W;
      
      int value[n],weight[n];
      for(int i=0;i<n;i++)
      {
      	cin>>weight[i]>>value[i];
	  }
      cout<<knapsack(value,weight,n,W);
      
    }
	return 0;
}

	

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int n;
int res = 0;
struct node {
    int id;
    int dist;
    bool searched;
};

node v[10000];
vector<pair<int, int>> edge[10000];

int main() {
    cin >> n;
    REP(i, n) {
        int u, k;
        cin >> u >> k;
        v[u].id = u;
        v[u].dist = INF;
        v[u].searched = false;
        REP(j, k){
            int to, cost;
            cin >> to >> cost;
            edge[i].push_back(make_pair(to, cost));
        }
    }
    v[0].dist = 0;
    int prev = 0;
    REP(i, n){
        int minimum = INF;
        REP(j, n){
            if(!v[j].searched && minimum >= v[j].dist){
                prev = j;
                minimum = v[j].dist;
            }
        }
        while(!edge[prev].empty()){
            int s = edge[prev].size() - 1;
            int j = edge[prev][s].first;
            v[j].dist = min(v[j].dist, v[prev].dist + edge[prev][s].second);
            edge[prev].pop_back();
        }
        v[prev].searched = true;
    }
    REP(i, n) cout << i << " " << v[i].dist << endl;
    return 0;
}

Measured memory_bytes: 6192
#include<stdio.h>
void insertionSort(int a[],int n);
int main(void){
  int i,n;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  insertionSort(a,n);
  return 0;
}
void insertionSort(int a[],int n){
  int i,j,k,v;
  for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[n-1]);
  for(i=1;i<n;i++){
    v=a[i];
    j=i-1;
    while(j>=0&&a[j]>v){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
    for(k=0;k<n-1;k++){
      printf("%d ",a[k]);
    }
    printf("%d\n",a[n-1]);
  }
}

Measured memory_bytes: 1768