akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
struct node{int to,next;}e[N<<1];
int head[N],cnt,dep[N],vis[N],flag,n,m,b[2];
void add(int x,int y){e[cnt]=(node){y,head[x]};head[x]=cnt++;}
void dfs(int x)
{
	b[dep[x]&1]++;vis[x]=1;
	for(int i=head[x];i!=-1;i=e[i].next)
	{
		int to1=e[i].to;
		if(!vis[to1])dep[to1]=dep[x]+1,dfs(to1);
		else if(!((dep[x]-dep[to1])&1))flag=1;
	}
}
int main()
{
	scanf("%d%d",&n,&m);memset(head,-1,sizeof(head));
	for(int i=1,x,y;i<=m;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);dfs(1);
	if(flag)printf("%lld\n",(((long long)n*(n-1))>>1)-m);
	else printf("%lld\n",((long long)b[1]*b[0])-m);
}

Measured memory_bytes: 3584
data = {}
count = 0
max_num = 10**9
before = 0
while True:
    tmp = count**5
    data[count] = tmp
    data[-count] = -tmp
    count+=1
    if tmp - before > max_num:
        break
    before = tmp

x = int(input())
for k, v in data.items():
    for k2, v2 in data.items():
        if v - v2 == x:
            print(k, k2)
            exit()



Measured memory_bytes: 9200
<?php
fscanf(STDIN, "%s", $s);
// echo $s . "\n";
$arr = str_split($s);
$arr = array_map("intval", $arr);
// var_dump($arr);

$sum = 0;
foreach ($arr as $num) {
    $sum += $num;
}

if ($sum % 9 == 0) {
    echo "Yes\n";
} else {
    echo "No\n";
}

Measured memory_bytes: 34520
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin>>p.at(i);
    }
    int count=0;
    for(int i=1;i<n-1;i++){
        if(((p.at(i-1)<p.at(i))&&(p.at(i)<p.at(i+1)))^((p.at(i-1)>p.at(i))&&(p.at(i)>p.at(i+1)))){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 10

int main(void){
	int wScores[N];
	int kScores[N];
	int wBests,kBests;
	
	for (int i=0;i<N;i++) scanf("%d",&wScores[i]);
	for (int i=0;i<N;i++) scanf("%d",&kScores[i]);
	
	wBests=0; kBests=0;
	for (int i=0;i<3;i++){
		int max, p;
		max = 0;
		for (int j=0;j<N;j++){
			if (wScores[j] > max){
				max = wScores[j];
				p = j;
			}
		}
		wBests += max;
		wScores[p] = 0;
	}
	for (int i=0;i<3;i++){
		int max, p;
		max = 0;
		for (int j=0;j<N;j++){
			if (kScores[j] > max){
				max = kScores[j];
				p = j;
			}
		}
		kBests += max;
		kScores[p] = 0;
	}
	printf("%d %d\n",wBests, kBests);
	return 0;
}

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

using namespace std;

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

    vector<char> s;

    while(n>26){
        s.push_back((char)('a'+(n-1)%26));
        n=(n-1)/26;
        
    }

    s.push_back((char)('a'+n-1));

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

    for(auto i: s){
        cout << i;
    }

    cout << endl;

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) v.begin(), v.end()

using namespace std;

ll mod = 1e9+7;
inline ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

inline ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

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

inline ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return (dividend / divisor);
}

// 因数分解
inline 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;
}

inline bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

//階乗
inline ll factorialMethod(ll k){
    ll sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

inline ll vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
        
        
    }
    else { // 発見できなかったとき
        return 0;
    }
}

void recursive_comb(ll *indexes, ll s, ll rest, std::function<void(ll *)> f) {
    if (rest == 0) {
        f(indexes);
    } else {
        if (s < 0) return;
        recursive_comb(indexes, s - 1, rest, f);
        indexes[rest - 1] = s;
        recursive_comb(indexes, s - 1, rest - 1, f);
    }
}

void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

int main(){
    ll n, k;
    cin >> n >> k;
    
    vector<ll> a(n);
    rep(i, k){
        ll d;
        cin >> d;
        rep(j, d){
            ll x;
            cin >> x;
            a[x-1] = 1;
        }
    }
    
    ll ans = 0;
    rep(i, n){
        if(a[i] == 0){
            ans ++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3660
#include<cstdio>
#include<vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
long long a[100010][3];
long long dp[100010][3];

int main(){
    int n;
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            scanf("%lld",&a[i][j]);
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k)continue;
                chmax(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }
    long long res=0;
    for(int j=0;j<3;j++){chmax(res,dp[n][j]);}
    printf("%lld\n",res);
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define vi vector<ll>
#define all(v) v.begin(), v.end()

bool pre[10];

bool check(ll num) {
	while(num > 0) {
		if (pre[num % 10]) {
			return false;
		}
		num /= 10;
	}
	return true;
}

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

	ll ele = 0, n = 0, k = 0;
	cin >> n >> k;
	rep(i, k) {
		cin >> ele;
		pre[ele] = true;
	}	

	while(!check(n)) {
		n++;
	}
	cout << n << endl;
	//cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;

#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())

ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

template <class TH>
void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; }
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a)
{
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V)
{
  os << "[";
  for (auto vv : V)
    os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P)
{
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/

main()
{
  int n, i, j;
  cin >> n;
  vector<double> a(n);
  for(i = 0; i < n; i++)
  cin >> a[i];
  vector<vector<double>> dp(n + 1, vector<double>(n + 1));
  dp[0][0] = 1.0;
  for(i = 1; i <= n; i++)
  for(j = 0; j <= i; j++)
  dp[i][j] = dp[i - 1][j] * (1.0 - a[i - 1]) + (j >= 1 ? dp[i - 1][j - 1] * a[i - 1]: 0);
  double ans = 0.0;
  for(i = n + 1 >> 1; i <= n; i++)
  ans += dp[n][i];
  printf("%.9f", ans);
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define per(i,a,b) for(ll i=(b)-1;i>=(a);i--)
ll k,a,b;
int main() {
    ios_base::sync_with_stdio(0);
    cin>>k>>a>>b;
    cout<<(b/k-(a-1)/k>0?"OK":"NG")<<"\n";
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define i_love_u_Phuong ios_base::sync_with_stdio(0); cin.tie(0);

using ll = long long;
using namespace std;
using ld = long double;
int n,m;
map<string,int> mp;
vector<string> a;

void enter()
{
    cin >> n;
    for(int i=0; i<n; ++i)
    {
        string s;
        cin >> s;
        if (mp[s]==0) a.push_back(s);
        mp[s]++;
    }
    cin >> m;
    for(int i=0; i<m; ++i)
    {
        string s;
        cin >> s;
        if (mp[s]!=0) mp[s]--;
    }
    int ans=0;
    for(int i=0; i<a.size(); ++i)
        ans=max(ans,mp[a[i]]);
    cout << ans;
}

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    i_love_u_Phuong;
    enter();
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,x,m,l[10],r[10],s[10];
int pp[6],ans[6],mx;
void dfs(int p){
  if(p==n){
    for(int i=0;i<m;i++){
      int sm=0;
      for(int j=l[i];j<=r[i];j++)sm+=pp[j];
      if(sm!=s[i])return;
    }
    int sss=0;
    for(int i=0;i<n;i++)sss+=pp[i];
    if(mx<sss){mx=sss;for(int i=0;i<n;i++)ans[i]=pp[i];}
    return;
  }
  for(int i=0;i<=x;i++)
    pp[p]=i,dfs(p+1);
}

int main(){
  cin>>n>>x>>m;
  for(int i=0;i<m;i++){
    cin>>l[i]>>r[i]>>s[i];
    l[i]--,r[i]--;
  }
  mx=-1;
  dfs(0);
  if(mx==-1)cout<<-1;
  else for(int i=0;i<n;i++){
      if(i)cout<<" ";
      cout<<ans[i];
    }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;

int main() {string w;
cin >> w;
long N = w.size();
map<char, int> mp;
rep(i, N){
    mp[w.at(i)]++;
}
string ans = "Yes";
for(char x = 'a'; x <= 'z'; x++){
    if(mp[x] % 2 == 1) ans ="No";
}



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



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  int l[n];
  rep(i,n)cin >> l[i];
  int ans = 0;
  rep(i,n)rep(j,i)rep(k,j){
    if((l[i]!=l[j])&&(l[j]!=l[k])&&(l[k]!=l[i])){
      int sum = l[i]+l[j]+l[k];
      if(((sum-l[i])>l[i])&&((sum-l[j])>l[j])&&((sum-l[k])>l[k]))ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  string s;
  cin >> s;
  
  vector<char> ch(s.size());
  for(int i=0; i<s.size(); i++){
    ch[i] = s[i];
  }
  sort(ch.begin(),ch.end());
  
  vector<int> tf(26);
  for(int i=0; i<26; i++){
    tf[i] = 0;
  }
    
  for(int i=0; i<s.size(); i++){
    tf[ch[i]-'a'] = 1;
  }
  
  int count = 0;
  
  for(int i=0; i<26; i++){
    if(tf[i] == 1){
      count++;
    }
  }
  
  char c = 0;
  if(count == 26){
    cout << "None" << endl;
  }
  else{
    for(int i=0; i<26; i++){
     if(tf[i] == 0){
       c = 97 + i;
      cout << c << endl;
      break;
     }
    }
  }
  return 0;
}


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

int main(){

	list<int> height;
	int h;

	for(int i=0;i<10;++i){
		cin>>h;
		height.push_back(h);
	}

	height.sort();

	list<int>::iterator it=height.end();
	
	--it;
	for(int i=0;i<3;++i){
		cout<<*it<<"\n";
		--it;
	}

    return 0;
}

Measured memory_bytes: 1192
#include<cstdio>

struct node{
    int parent;
    int left;
    int right;
    int sibling;
    int degree;
    int depth;
    int height;
};

node tree[25];

void setdepth(int depth,int id){
    tree[id].depth = depth;
    if(tree[id].left >= 0)
        setdepth(depth + 1,tree[id].left);
    if(tree[id].right >= 0)
        setdepth(depth + 1,tree[id].right);
}

int setheight(int id){
    if(id == -1)
        return -1;
    if(tree[id].left == -1 && tree[id].right == -1){
        tree[id].height = 0;
        return 1;
    }

    int a = setheight(tree[id].left);int b = setheight(tree[id].right);
    tree[id].height =  a >= b ? a : b;
    return tree[id].height + 1;
}

int main(void){
    int n;
    scanf("%d",&n);

    for(int i = 0;i < n;i++){
        tree[i].sibling = -1;
        tree[i].degree = 0;
        tree[i].parent = -1;
    }
    for(int i = 0;i < n;i++){
        int id,left,right;
        scanf("%d%d%d",&id,&left,&right);
        tree[id].left = left;
        tree[id].right = right;
        if(left >= 0){
            tree[left].parent = id;
            tree[id].degree++;
        }
        if(right >= 0){
            tree[right].parent = id;
            tree[id].degree++;
        }
        if(left >= 0 && right >= 0){
            tree[left].sibling = right;tree[right].sibling = left;
        }
    }
    int root;
    for(int i = 0;i < n;i++)
        if(tree[i].parent == -1){
            root =  i;
            break;
        }

    setdepth(0,root);

    setheight(root);

    for(int i = 0;i < n;i++){
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,tree[i].parent,tree[i].sibling,tree[i].degree,tree[i].depth,tree[i].height);

        if(tree[i].parent == -1)
            printf("root");
        else if(tree[i].left >= 0 || tree[i].right >= 0)
            printf("internal node");
        else
            printf("leaf");
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 2724
import math
import numpy as np
n=int(input())
a=list(map(int, input().split()))

flag=False
ans="APPROVED"

for i in range(0,n):
    if a[i]%2==0:
        if a[i]%3!=0 and a[i]%5!=0:
            ans="DENIED"
            flag=True
            break
    if flag:
        break
print(ans)


Measured memory_bytes: 12488
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;


int d[200010];
int t[200010];


signed main(){
  int n,m;
  bool flag=true;
  cin>>n;
  rep(i,n){
    cin>>d[i];
  }

  sort(d,d+n);
  cin>>m;
  rep(i,m){
    cin>>t[i];
  }
  sort(t,t+m);

  for(int i=0;i<m;i++){
    int temp=t[i];
    int num=upper_bound(t,t+m,temp)-lower_bound(t,t+m,temp);
    int num2=upper_bound(d,d+n,temp)-lower_bound(d,d+n,temp);
    if(num>num2)flag=false;
    i+=num-1;
  }
  if(flag)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;



}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == '1') {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n, x, m = map(int, input().split())

a = x
li = [a]
exists = dict()
i = 1
for i in range(2, n + 1):
    a = a * a % m
    if a in exists:
        break
    li.append(a)
    exists[a] = i

ans = sum(li)
if i != n:
    loop, left = divmod(n - i + 1, i - exists[a])
    ans += loop * sum(li[exists[a]-1:]) + sum(li[exists[a]-1:exists[a]-1+left])
print(ans)


Measured memory_bytes: 15608
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i< (int)(n); i++)
#define rep2(i,x,n) for(int i = (int)x; i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int a, b, c, x, y;
	ll ans = 0;
	cin >> a >> b >> c;
	int dc = c*2;
	cin >> x >> y;
	if(dc <= a + b){
		if(x > y){
			ans += dc*y;
			if(dc <= a){
				ans += dc*(x-y);
			}else{
				ans += a*(x-y);
			}
		}else{
			ans += dc*x;
			if(dc <= b){
				ans += dc*(y-x);
			}else{
				ans += b*(y-x);
			}
		}
	}else{
		ans += a * x + b * y;
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    for(int i=0;i<k;i++){
        if(a==max(a,max(b,c))) a=a*2;
        if(b==max(a,max(b,c))) b=b*2;
        if(c==max(a,max(b,c))) c=c*2;
    }
    cout << a+b+c << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <utility>
using namespace std;
int a[20];
map<pair<long long, long long>, long long> m[18][18];
long long go(int l, int r, long long fl, long long fr) {
	if (l >= r) return 0;
	if (m[l][r].count(make_pair(fl, fr))) {
		return m[l][r][make_pair(fl, fr)];
	}
	long long &res = m[l][r][make_pair(fl, fr)];
	if (l + 1 == r) {
		return res = (fl + fr) * a[l];
	}
	res = 1ll << 61;
	for (int i = l; i < r; i++) {
		long long t = (fl + fr) * a[i] + go(l, i, fl, fl + fr) + go(i + 1, r, fl + fr, fr);
		if (res > t) res = t;
	}
	return res;
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	long long ans = 0;
	ans += a[0] + a[n-1];
	for (int i = 0; i < n; i++) {
		a[i] = a[i+1];
	}
	ans += go(0, n - 2, 1, 1);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 16640
import java.util.*;

public class Main {
    static class Pair{
        public int x;
        public int y;
        public Pair(int x,int y) {
            this.x=x;
            this.y=y;
        }
        @Override
        public boolean equals(Object obj) {
            if(obj instanceof Pair) {
                Pair other = (Pair) obj;
                return other.x==this.x && other.y==this.y;
            }
            return false;
        }//同値の定義
        @Override
        public int hashCode() {
            return Objects.hash(this.x,this.y);
        }//これ書かないと正しく動作しない（要　勉強）
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        int N = Integer.parseInt(sc.next());
        // HashMap<ArrayList<Integer>, Integer> map = new HashMap<ArrayList<Integer>, Integer>();
        HashMap<Pair, Integer> map = new HashMap<Pair, Integer>();
        for (int i=0;i<N;i++) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            for (int j=-1;j<=1;j++) {
                for (int k=-1;k<=1;k++) {
                    if (a+j<2 || a+j>H-1) continue;
                    if (b+k<2 || b+k>W-1) continue;
                    // ArrayList<Integer> add = new ArrayList<Integer>();
                    // add.add(a+j);
                    // add.add(b+k);
                    Pair add = new Pair(a+j, b+k);
                    if (map.containsKey(add)) {
                        map.put(add, map.get(add)+1);
                    } else {
                        map.put(add, 1);
                    }
                }
            }
        }
        ArrayList<Integer> val = new ArrayList<Integer>(map.values());
        long[] ans = new long[10];
        long sum = 0L;
        for (int i=0;i<val.size();i++) {
            sum++;
            ans[val.get(i)]++;
        }
        ans[0]=(long)(H-2)*(W-2)-sum;
        for (int i=0;i<10;i++) {
            System.out.println(ans[i]);
        }
        // System.out.println(map);
    }
}

Measured memory_bytes: 167964
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int l;
l knapsack(l wt[],l v[],l W,l n)
{
    l dp[n+1][W+1];
    for(l i=0;i<=n;i++)
    {

        for(l w=0;w<=W;w++)
        {
             if(i==0||w==0)
                dp[i][w]=0;
    else if(wt[i-1]<=w)
    {
         dp[i][w] = max(v[i-1]+dp[i-1][w-wt[i-1]],dp[i-1][w]);
    }
    else
        dp[i][w] = dp[i-1][w];

        }
    }
    return dp[n][W];
}
int main()
{
    l n,W;
    cin>>n>>W;
    l v[n],w[n];
    for(l i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
   cout<<knapsack(w,v,W,n)<<"\n";

    return 0;
}


Measured memory_bytes: 82408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    int cnt=0;
    for(int i=0;i<a.size();i++)
	{
        if(a[i]=='C')
		{cnt=1;}
        if(a[i]=='F'&&cnt==1)
		{
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

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


int main() {
    map<string, int> data;
    int N, M;
    string line;

    cin >> N;
    for (int n=0; n<N; n++) {
        cin >> line;
        data[line]++;
    } 

    cin >> M;
    for (int m=0; m<M; m++) {
        cin >> line;
        data[line]--;
    } 

    int result = 0;

    for (auto itr = data.begin(); itr !=data.end(); ++itr) {
        if (result < itr->second) result = itr->second;
    }


    cout << result << endl;

}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))

minus = 0
zero = 0

for i in range(n):
    if A[i] < 0:
        minus += 1
    elif A[i] == 0:
        zero += 1

A2 = [abs(i) for i in A]
if minus %2 == 0 or zero >= 1:
    print(sum(A2))
else:
    print(sum(A2)-2*min(A2))

Measured memory_bytes: 90536
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    cout << n*(n+1)/2 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)

namespace {
	struct input_returnner {
		int N; input_returnner(int N_ = 0) :N(N_) {}
		template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
		template<typename T> operator T() const { T res; cin >> res; return res; }
		template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
		template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
		template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
		template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
		template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
		template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
	};
	template<typename T> input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(int N) { return std::move(input_returnner(N)); }
}

void solve();
/// ---template---

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

signed main(void) {
	SETUP;
	solve();
	return 0;
}

#define int ll
void solve() {
	int N = in();
	vector<int> P(N);
	REP(i, N) cin >> P[i];
	vector<int> resa(N), resb(N);
	resa[P[0] - 1] = resb[P[0] - 1] = 0;

	FOR(i, 1, P.size()) {
		int cur = P[i] - 1;
		int old = P[i - 1] - 1;
		if (P[i] - P[i - 1] > 0) {
			resa[cur] = (cur - old) * 20001 + resa[old];
			resb[cur] = -(cur - old) * 20001 + resb[old] + 1;
		}
		else {
			resa[cur] = (cur - old) * 20001 + resa[old] + 1;
			resb[cur] = -(cur - old) * 20001 + resb[old];
		}
	}
	int mina = resa[0];
	int minb = resb.back();
	for (auto &a : resa) {
		cout << a - mina + 1 << " ";
		a = a - mina + 1;
	}
	cout << endl;
	for (auto &a : resb) {
		cout << a - minb + 1 << " ";
		a = a - minb + 1;
	}
	cout << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<long long> a(3*n);
	for(int i = 0;i < 3*n;i++) cin >> a[i];
	sort(a.begin(),a.end());
	long long sum=0;
	for(int i = 0;i < n;i++) sum+=a[3*n-(i+1)*2];
	cout << sum << endl;
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Atcoder_with_csharp
{
    using cl = Console;

    class Program
    {
        static void Main(string[] args)
        {
            var ap = new ArgsProcess();
            var arg = ap.ArgsInt;
            var sum = arg.Sum();

            var str = (sum >= 22) ? "bust" : "win";

            cl.WriteLine(str);
        }
    }


    public class ArgsProcess
    {
        // 引数格納
        public string[] Args { get; set; }

        // 引数格納(int)
        public int[] ArgsInt
        {
            get { return GetArgsAsArrayOfInteger(); }
        }

        public ArgsProcess(string args)
        {
            initialize(args);
        }

        public ArgsProcess()
        {
            // 入力してから
            var args = Console.ReadLine();
            initialize(args);
        }

        private void initialize(string args)
        {
            // スペース区切り
            var s = args.Split(' ').ToList();
            s.RemoveAll(x => x == "");

            this.Args = s.ToArray();
        }

        private int[] GetArgsAsArrayOfInteger()
        {
            int[] ret = Array.Empty<int>();
            try
            {
                // intにparse
                ret = this.Args.ToList().ConvertAll(x => int.Parse(x)).ToArray();
            }
            catch
            {
                Console.WriteLine("This args is not integer.");
            }
            return ret;
        }

    }
}

Measured memory_bytes: 13268
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    N, M = parseMap(split(readline()))
    x = zeros(Int, N)
    y = zeros(Int, N)
    flg = 0
    for ii = 1:M
        s, c = parseMap(split(readline()))
        if x[s] != 0 && x[s] != c
            println(-1)
            return
        else
            x[s] = c
            y[s] = 1
        end
    end
    if sum(x) == 0 && N != 1 && y[1] == 1
        println(-1)
        return
    end
    if x[1] == 0 && N != 1
        x[1] = 1
    end
    for ii = 1:N
        print(x[ii])
    end

end

main()


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll start = 1;
ll n;
vector<vector<pair<ll, ll>>> G;
vector<ll> dist;
void dijkstra() {
    priority_queue<pi, vector<pi>, greater<pi>> pq;
    dist = vector<ll>(n+1,INF);
    dist[start] = 0;
    pq.push(pi(0, start));

    while(!pq.empty()) {
        ll d = pq.top().first, v = pq.top().second;
        pq.pop();

        if(v == n) break;
        if(dist[v] < d) continue;

        for(int i = 0; i < (int)G[v].size(); ++i) {
            pi e = G[v][i];

            if(d + e.second < dist[e.first]) {
                dist[e.first] = d + e.second;
                pq.push(pi(dist[e.first], e.first));
            }
        }
    }
}

int main() {
    ll m, i, j, k;
    cin >> n >> m;
    vector<pair<pair<ll, ll>, ll>> v(m);
    for(i = 0; i < m; i++) {
        cin >> v[i].first.second >> v[i].second >> v[i].first.first;
    }
    sort(v.begin(), v.end());
    G = vector<vector<pair<ll,ll>>> (n+1);
    dist.resize(n+1);
    set<pair<ll,ll>> st;
    for(i=0;i<m;i++){
        if(st.find({v[i].first.second, v[i].second})!=st.end())continue;
        G[v[i].first.second].push_back({v[i].second, v[i].first.first});
        st.insert({v[i].first.second,v[i].second});
    }
    
    for(i=2;i<=n;i++){
        G[i].push_back({i-1,0});
    }
    dijkstra();
    if(dist[n]==INF){
        cout << -1 << endl;
        return 0;
    }
    cout << dist[n] << endl;
    return 0;
}

Measured memory_bytes: 20096
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,d,ac,ad,bc,bd;
	cin>>a>>b>>c>>d;
	ac=a*c;
	ad=a*d;
	bc=b*c;
	bd=b*d;
	cout<<max(ac,max(ad,max(bc,bd)));
	return 0;
} 

Measured memory_bytes: 3620
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())
rarr = []
garr=[]
barr=[]

for i in range(n):
    if s[i]=="R":
        rarr.append(i)
    elif s[i]=="G":
        garr.append(i)
    else:
        barr.append(i)

#組み合わせ全通り
ans=len(rarr)*len(barr)*len(garr)

#[0, 2, 5, 11, 12, 16, 17, 18, 23, 27, 31] 11
#[4, 7, 8, 13, 20, 21, 25, 29, 35] 9
#[1, 3, 6, 9, 10, 14, 15, 19, 22, 24, 26, 28, 30, 32, 33, 34, 36, 37, 38] 19
if len(rarr)>len(garr):
    rarr,garr=garr,rarr
if len(barr)>len(garr):
    barr,garr=garr,barr

garr=Counter(garr)

for r in rarr:
    for b in barr:
        #GRB
        if r-b >0 and garr[r + r-b]:
            ans-=1
        #GBR
        elif b-r >0 and garr[b + b-r]:
            ans-=1
        #RGB BGR
        if r-b >0 and (r-b)%2==0 and garr[b+((r-b)//2)]:
            ans-=1

        elif b-r >0 and (b-r)%2==0 and garr[r+((b-r)//2)]:
            ans-=1
        #RBG
        if r-b>0 and garr[b-(r-b)]:
            ans-=1
        elif b-r>0 and garr[r-(b-r)]:
            ans-=1

print(ans)


Measured memory_bytes: 10724
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int a, b, h;
	cin >> a >> b >> h;
	print((a + b)*h / 2);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


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


// input
int N, Q;
vector<int> c, l, r;


void input() {
    cin >> N >> Q;
    c = vector<int>(N);
    l = r = vector<int>(Q);
    rep(i, N) cin >> c[i];
    rep(i, Q) cin >> l[i] >> r[i];
}


struct BIT {
    int n;
    vector<ll> dat;

    BIT(int n_) {
        n = n_;
        dat = vector<ll>(n + 1, 0);
    }

    void add(int i, int x) {
        i++;
        while (i <= n) {
            dat[i] += x;
            i += i & -i;
        }
    }

    ll sum(int i) {
        if (i == 0) return 0;
        return dat[i] + sum(i - (i & -i));
    }
};


vector<P> create_arrow_list() {
    vector<P> ret;
    vector<int> w(N, -1);
    rep(i, N) {
        int v = c[i] - 1;
        if (w[v] != -1) ret.push_back(make_pair(w[v], i));
        w[v] = i;
    }
    sort(ret.rbegin(), ret.rend());
    return ret;
}


vector<T> create_query_list() {
    vector<T> ret;
    rep(i, Q) ret.push_back(make_tuple(l[i] - 1, r[i] - 1, i));
    sort(ret.rbegin(), ret.rend());
    return ret;
}


int main() {
    input();
    vector<P> arrow_list = create_arrow_list();
    int an = arrow_list.size();
    vector<T> query_list = create_query_list();
    vector<int> ans(Q);
    BIT bit = BIT(N);
    int i = 0;
    int j = 0;
    int x, y, v;
    while (i != an || j != Q) {
        if (i == an) {
            tie(x, y, v) = query_list[j];
            ans[v] = y - x + 1 - bit.sum(y + 1);
            j++;
        } else if (j == Q) {
            bit.add(arrow_list[i].second, 1);
            i++;
        } else if (get<0>(query_list[j]) <= arrow_list[i].first) {
            bit.add(arrow_list[i].second, 1);
            i++;
        } else {
            tie(x, y, v) = query_list[j];
            ans[v] = y - x + 1 - bit.sum(y + 1);
            j++;
        }
    }
    rep(i, Q) cout << ans[i] << endl;
}


Measured memory_bytes: 25824
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

class UnionFind {
private:
	unsigned size_; 
	std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	//unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	unsigned root(unsigned x)
	{
		while(par[x] != x)
		{
			par[x] = par[par[x]];
			x = par[x];
		}
		return x;
	}
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	
	cin >> N;

	int maxm = 0;
	int prev = 0;
	cin >> prev;
	int cnt = 0;

	rep(i, N-1)
	{
		int tmp = 0;
		cin >> tmp;

		if (tmp <= prev)
		{
			cnt++;
		}
		else 
		{
			maxm = max(maxm, cnt);
			cnt = 0;
		}
		prev = tmp;
		
	}

	maxm = max(maxm, cnt);
	cout << maxm << endl;

	
	return 0;
}


Measured memory_bytes: 256
// 2020-07-18 11:45:19
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll n, k;
  cin >> n >> k;
  if(n >= k) {
    n -= (n / k) * k;
  }
  cout << min(n, abs(n - k)) << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

int main(){
  int N, now = 0, count = 0;
  vector<int> a;

  cin >> N;
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    x--;
    a.push_back(x);
  }

  while(1){
    if(now == 1){
      cout << count << endl;
      break;
    }
    if(N <= count){
      cout << "-1" << endl;
      break;
    }
    count++;
    now = a[now];
  }

	return 0;
}


Measured memory_bytes: 892
using System;
 using System.Linq;
 
 class Program {
     public static void Main(string[] args) {
         var n = Console.ReadLine();
         var l = Console.ReadLine().Split(' ')
             .Select(int.Parse).ToList();
         l.Sort();
         l.Reverse();
         var total = l.Where((a, i) => i % 2 == 1).Sum();
         Console.WriteLine(total);
     }
 }

Measured memory_bytes: 13268
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

ll h,w,n,ans=0;

int main(){
	cin>>h>>w>>n;
	int sx,sy;
	cin>>sx>>sy;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		int cx=abs(sx-x),cy=abs(sy-y);
		ans+=cx+cy;
		if((sx-x)*(sy-y)>0) ans-=min(cx,cy);
		sx=x;
		sy=y;
	}
	cout<<ans<<endl;
}

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


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


fa = set([x for x, y in factorization(a)]+[1])
fb = set([x for x, y in factorization(b)]+[1])
ans = 0
for x in fa:
    if x in fb:
        ans += 1
print(ans)

Measured memory_bytes: 3188
function Main(s){
	s|=0;
	var st=String(s);
	var a=0;
	var ans="Yes";
	for(var i=0;i<st.length;i=(i+1)|0){
		a+=st[i]|0;
	}
	if(s%a){ans="No";}
	
	console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define size(a) int((a).size())
#define present(c, x) (c.find(x) != c.end()) 
#define printVerdict(verdict) cout << (verdict ? "YES": "NO") << '\n'
#define printDecimal(d) printf("%.9f\n", d)
#define inrange(val, start, end) (val >= start && val <= end)
#define var(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const ll inf = 0x3f3f3f3f;
const ll mod = 998244353;
 
template <class T1, class T2, class T3> 
void printTuple(tuple<T1, T2, T3> t) { cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n'; }
template <class T1, class T2>
void printPair(pair<T1, T2> p) { cout << p.first << " " << p.second << '\n'; }
template <class T>
void printArray(vector<T> arr) { for (int i = 0; i<size(arr); i++) {cout << arr[i] << " ";} cout << '\n'; } 

struct segTree {
	int sz;
	ll baseValue = 0; 
	vector<ll> tree;
	void init(ll n) {
		sz = 1;
		while (sz < n) sz *= 2;
		tree.assign(2*sz, baseValue);
	}
	
	ll query(ll a, ll b) {
		return (a + b)%mod;
	}
	
	void set(int idx, ll val) {set(idx, val, 0, 0, sz);}
	void set(int idx, ll val, int curr, int left, int right) {
		if (right - left == 1) tree[curr] = val;
		else {
			int mid = left + (right - left)/2;
			if (idx < mid) set(idx, val, curr*2+1, left, mid);
			else set(idx, val, curr*2 + 2, mid, right);
			tree[curr] = query(tree[curr*2 + 1], tree[curr*2 + 2]);
		}
	}
	
	ll evaluate(int left, int right) {return evaluate(left, right, 0, 0, sz);}
	ll evaluate(int left, int right, int curr, int curr_left, int curr_right) {
		if (curr_left >= right || left >= curr_right) return baseValue;
		if (curr_left >= left && curr_right <= right) return tree[curr];
		int mid = curr_left + (curr_right - curr_left)/2;
		ll s1 = evaluate(left, right, curr*2+1, curr_left, mid), s2 = evaluate(left, right, curr*2+2, mid, curr_right);
		return query(s1, s2);
	}
};

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	segTree tree;
	int n,k; cin >> n >> k;
	tree.init(n+2);
	vector<pair<int, int>> seg;
	for (int i= 0; i<k; i++) {
		int u,v; cin >> u >> v;
		seg.push_back(make_pair(u, v));
	}
	vector<ll> dp(n+1, 0);
	dp[1] = 1;
	tree.set(1, dp[1]);
	for (int i = 2; i<=n; i++) {
		for (pair<int, int> p : seg) {
			if (i - p.first <= 0) continue;
			dp[i] += tree.evaluate(i - p.second, i-p.first+1);
			dp[i] %= mod;
		}
		tree.set(i, dp[i]);
	}
	cout << dp[n] << '\n';
}


Measured memory_bytes: 9000
N = int(input())
a = list(map(int, input().split()))

one, two, three = 0, 0, 0
for ai in a:
    if ai == 1: one += 1
    if ai == 2: two += 1
    if ai == 3: three += 1

u = N + 1
dp = [[[-1]* u for _ in range(u)] for _ in range(u)]
dp[0][0][0] = 0

def rec(i, j, k):
    if dp[i][j][k] >= 0:
        return dp[i][j][k]
    res = N
    if i > 0: res += rec(i-1, j, k) * i
    if j > 0: res += rec(i+1, j-1, k) * j
    if k > 0: res += rec(i, j+1, k-1) * k
    res /= (i + j + k)
    dp[i][j][k] = res
    return res

print(rec(one, two, three))

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

using namespace std;
typedef long long int ll;

int main() {
  int a,b;
  cin>>a>>b;
  if(a+b==15)
    cout<<'+'<<endl;
  else if(a*b==15)
    cout<<'*'<<endl;
  else
    cout<<'x'<<endl;


  
  return 0;
}



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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int cnt5 = 0;
    int cnt7 = 0;
    if(A == 5)
        cnt5++;
    if(A == 7)
        cnt7++;
    if(B == 5)
        cnt5++;
    if(B == 7)
        cnt7++;
    if(C == 5)
        cnt5++;
    if(C == 7)
        cnt7++;
    
    if(cnt5 == 2 && cnt7 == 1)
        cout << "YES";
    else
        cout << "NO";
}

Measured memory_bytes: 256