akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
    ll w, h;
    cin >> w >> h;
    ll p, q;
    priority_queue<P,vector<P>,greater<P>> que;
    rep(i,w) {
        cin >> p;
        que.push(P(p,0));
    }
    rep(i,h) {
        cin >> q;
        que.push(P(q,1));
    }
    ll ans = 0;
    ll n = 0;
    p = w + 1; q = h + 1;
    while(!que.empty()){
        P a = que.top();
        que.pop();
        if(a.second == 0) {
            if(q > 0)  ans += a.first*q;
            else  ans += a.first;
            p--;
        } else {
            if(p > 0) ans += a.first*p;
            else ans += a.first;
            q--;
        }
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 6128
//58
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int N,K;cin>>N>>K,N|K;){
    int s[100];
    for(int i=0;i<K;i++){
      cin>>s[i];
    }
    bool fail=false;
    for(int i=0;i<N;i++){
      for(int j=0;j<K;j++){
	int b;
	cin>>b;
	s[j]-=b;
	if(s[j]<0){
	  fail=true;
	}
      }
    }
    cout<<((fail)?"No":"Yes")<<endl;
  }
  return 0;
}

Measured memory_bytes: 856
#include <iostream>
#include <string>
using namespace std;
int main() {
    
    string n;
    int sum = 0;
    
    cin>>n;
    
    for(int i = 0;i<n.size();i++){
        int a = n[i]-'0';
        sum = sum + a;
    }
    
    if(stoi(n)%sum==0){
         cout <<"Yes"<<endl;
    }else{
        cout <<"No"<< endl;
    }

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize ("Ofast")
#define int long long 
#define ld long double
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,l,r) for(int i=l;i<r;i++)
#define watch(x) cerr<<(#x)<<"= "<<(x)<<endl;
#define watcharr(a) cerr<<(#a)<<"("<<a.size()<<")= ";rep(i,a.size())cerr<<a[i]<<",";cerr<<'\n';
#define inf 2000000000000000000LL
#define mod 1000000007LL
#define mod1 998244353LL
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;

signed main() {
    FASTIO;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    //     freopen("stderr.txt", "w", stderr);
    // #endif

    int n,w;
    cin>>n>>w;
    vector<int> weight(n),value(n);
    int maxvalue=0;
    rep(i,n) 
        cin>>weight[i]>>value[i], maxvalue+=value[i];

    vector<vector<int>> dp(n+1,vector<int>(maxvalue+1,inf));
    dp[0][0]=0;
    int ans=0;
    loop(i,1,n+1){
        rep(j,maxvalue+1){
            if(j>=value[i-1]) dp[i][j]=min(dp[i-1][j],dp[i-1][j-value[i-1]]+weight[i-1]);
            else dp[i][j]=dp[i-1][j];
            if(dp[i][j]<=w) ans=max(ans,j);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 80256
local a, b, e = io.read("*n", "*n", "*n")
local r = e * 3
local c = r - a - b
local g, h, i = r - e - c, r - e - b, r - e - a
local d, f = r - a - g, r - c - i
print(a .." " .. b .. " " .. c)
print(d .." " .. e .. " " .. f)
print(g .." " .. h .. " " .. i)


Measured memory_bytes: 760
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    string s;
    cin>>s;
    int cnt=0;
    REP(i,s.size())if(s[i]=='1')cnt++;
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long a, b;
    cin >> a >> b;
    if(a % b == 0)
        cout << 0;
    else {
        if(a < b) {
            cout << min(abs(a - b), b - abs(a - b));
        } else {
            long long c = a / b;
            c++;
            cout << abs(a - (c * b));
        }
    }
}



Measured memory_bytes: 3660
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int n,a[N],b[N];
pair<long long,int> sum[N];
long long ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		sum[i]=make_pair(a[i]+b[i],i);
	}
	sort(sum+1,sum+1+n);
	for(int i=n,j=1;i>=1;i--,j++)
	{
		if(j%2==1)
			ans+=a[sum[i].second];
		else
			ans-=b[sum[i].second];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

typedef struct directed_edge {
  int32_t vertex;
  int32_t next;
} graph_edge;

typedef struct directedGraph {
  graph_edge *edge;
  int32_t *start;
  int32_t pointer;
  int32_t vertex_num;
  int32_t edge_max_size;
} graph;

graph* new_graph (const int vertex_num) {
  graph *g = (graph *) calloc (1, sizeof (graph));
  g->edge = (graph_edge *) calloc (1, sizeof (graph_edge));
  g->start = (int32_t *) calloc (vertex_num, sizeof (int32_t));
  g->pointer = 0;
  g->vertex_num = vertex_num;
  g->edge_max_size = 1;
  for (int32_t i = 0; i < vertex_num; ++i) {
    g->start[i] = -1;
  }
  return g;
}

void free_graph (graph *g) {
  free (g->edge);
  free (g->start);
  free (g);
  return;
}

void clear_graph (graph *g) {
  g->pointer = 0;
  for (int32_t i = 0; i < g->vertex_num; ++i) {
    g->start[i] = -1;
  }
}

void add_edge (graph *g, int32_t from, int32_t to) {
  if (g->pointer == g->edge_max_size) {
    g->edge_max_size *= 2;
    g->edge = (graph_edge *) realloc (g->edge, sizeof (graph_edge) * g->edge_max_size);
  }
  g->edge[g->pointer] = (graph_edge) {to, g->start[from]};
  g->start[from] = g->pointer++;
}

void BFS_graph (graph *g, int32_t src, int32_t *q) {
  uint8_t *used = (uint8_t *) calloc (g->vertex_num, sizeof (uint8_t));
  int32_t front = 0;
  int32_t last = 0;
  used[src] = 1;
  q[last++] = src;
  while (front < last) {
    const int32_t v = q[front++];
    for (int32_t p = g->start[v]; p != -1; p = g->edge[p].next) {
      const int32_t u = g->edge[p].vertex;
      if (!used[u]) {
	used[u] = 1;
	q[last++] = u;
      }
    }
  }
  free(used);
}

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))

int cmp_int (const void *a, const void *b) {
  i32 d = *(i32 *)a - *(i32 *)b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  graph *g = new_graph (n);
  for (i32 i = 1; i < n; ++i) {
    i32 a, b;
    scanf ("%" SCNi32 "%" SCNi32, &a, &b);
    a--;
    b--;
    add_edge (g, a, b);
    add_edge (g, b, a);
  }
  i32 *c = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, c + i);
  }
  qsort (c, n, sizeof (i32), cmp_int);
  i32 *q = (i32 *) calloc (n, sizeof (i32));
  BFS_graph (g, 0, q);
  i32 *ans = (i32 *) calloc (n, sizeof (i32));
  i32 sum = 0;
  for (i32 i = n - 1; i >= 0; --i) {
    i32 v = q[i];
    ans[v] = c[n - 1 - i];
    if (i > 0) sum += c[n - 1 - i];
  }
  printf ("%" PRIi32 "\n", sum);
  for (i32 i = 0; i < n; ++i) {
    printf ("%" PRIi32, ans[i]);
    putchar (i == n - 1 ? '\n' : ' ');
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 508
from math import gcd
n = int(input())
plus = {}
minus = {}
mod = 10**9 + 7
gen = pow(10,19)
zero = 0 # 両方
for i in range(n):
    a,b = map(int,input().split())
    if a == b == 0:
        zero += 1
        continue
    if a < 0:a,b = -a,-b
    elif a == 0 and b < 0:b = -b
    g = gcd(a,b)
    a //= g
    b //= g
    key = a*gen + b
    if b > 0:
        if key not in plus.keys():plus[key] = 0
        plus[key] += 1
    else:
        if key not in minus.keys():minus[key] = 0
        minus[key] += 1
ans = pow(2,n-zero,mod)
for k,v in plus.items():
    a = k//gen
    b = k%gen
    opo = b*gen - a
    if opo in minus.keys():
        o = minus[opo]
        ans = ans*pow(2,v*(mod-2)%(mod-1),mod) + ans*pow(2,o*(mod-2)%(mod-1),mod) - ans*pow(2,(v+o)*(mod-2)%(mod-1),mod)
        ans %= mod
print((ans + zero - 1)%mod)


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

ll ans = 1000 * 8;
vector<int> l;

void rec(int A, int B, int C, int i, vector<int> use) {
    if (i == use.size()) {
        vector<int> ls(3);
        ll cost = 0;
        rep(i, use.size()) {
            if (use[i] != 3) {
                if (ls[use[i]]) cost += 10;
                ls[use[i]] += l[i];
            }
        }

        sort(ls.begin(), ls.end());
        if (ls[0] == 0) return;
        cost += abs(A - ls[2]);
        cost += abs(B - ls[1]);
        cost += abs(C - ls[0]);
        chmin(ans, cost);
        return;
    }

    rep(j, 4) {
        use[i] = j;
        rec(A, B, C, i + 1, use);
    }
}

int main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    l.resize(N);
    rep(i, N) cin >> l[i];
    vector<int> use(N, 0);
    rec(A, B, C, 0, use);

    cout << ans << endl;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::collections::HashSet;
use std::iter::FromIterator;

fn main() {
    let mut nm = String::new();
    stdin().read_line(&mut nm).unwrap();
    let nm: Vec<usize> = nm.trim().split_whitespace().flat_map(str::parse).collect();
    let (n, m) = (nm[0], nm[1]);

    let danger_zone: HashSet<usize> = HashSet::from_iter((0..m).map(|_|{
        let mut a = String::new();
        stdin().read_line(&mut a).unwrap();
        a.trim().parse().unwrap()
    }));

    let mut cmb = vec![0; n + 1];
    cmb[0] = 1;
    for i in 0..n {
        for j in i+1..i+3{
            if !danger_zone.contains(&j) && j <= n {
                cmb[j] = (cmb[j] + cmb[i]) % 1000000007;
            }
        }
    }
    println!("{}", cmb[n as usize]);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,a,b; cin>>n>>a>>b;
	int L = max(a,b)-min(a,b)+1;
	cout<<((L%2==0)?"Borys":"Alice")<<'\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int64)n;i++)
#define FORr(i,k,n)  for(int64 i=(int64)k;i>=n;i--)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define FOREACHr(it, l) for (auto it = l.rbegin(); it != l.rend(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddx[4] = {1,0,-1,0};
const int ddy[4] = {0,1,0,-1};
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}

int main(){
//	in_o();
	map<string, int64> mp;
	int n;
	cin>>n;
	int64 ans=0;
	FOR(i,0,n){
		string s;
		cin>>s;
		sort(s.begin(), s.end());
		ans+=mp[s];
		mp[s]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const LL MOD = 1e9 + 7;

const int N = 1e5 + 10;
LL a[N];
LL fact[N], invf[N];

LL modpow(LL a, LL n) {
  LL res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}

void pre() {
  fact[0] = invf[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % MOD;
    invf[i] = (invf[i - 1] * modpow(i, MOD - 2)) % MOD;
  }
}
LL choose(int n, int k) {
  if (n < k) return 0;
  return fact[n] * (invf[n - k] * invf[k] % MOD) % MOD;
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  pre();

  int n, k; cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);

  LL ans = 0;
  for (int i = 0; i < n; i++) {
    LL mn = choose(n - i - 1, k - 1);
    LL mx = choose(i, k - 1);
    LL ways = (mx - mn + MOD) % MOD;
    if (a[i] < 0) a[i] += MOD;
    ans += ways * a[i] % MOD;
  }
  ans %= MOD;
  cout << ans << endl;

  return 0;
}


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

for i in range(a+b+1):
    if 0<= i <a or a+1<= i <=a+b:
        if not s[i] in list(map(str,[j for j in range(10)])):
            print('No')
            break
    if i == a:
        if  s[i] != '-':
            print('No')
            break
else:
    print('Yes')

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

int main(void){
  
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    
    cin>>vec.at(i);
    
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int Alice=0,Bob=0;
  for(int i=0;i<N;i++){
    if(i%2==0){
      Alice+=vec.at(i);
    }
    else{
      Bob+=vec.at(i);
    }
  }
  cout<<Alice-Bob<<endl;
}

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

int main(){
  string str;
  cin >> str;

  string fist_str = str.substr(0,2);
  string second_str = str.substr(2,2);
  int fist = atoi(fist_str.c_str());
  int second = atoi(second_str.c_str());

  int counter = 0;

  if(fist <= 12 && fist >= 1)counter++;
  if(second <= 12 && second >= 1)counter += 2;

  if(counter == 1)cout << "MMYY" << endl;
  if(counter == 2)cout << "YYMM" << endl;
  if(counter == 3)cout << "AMBIGUOUS" << endl;
  if(counter == 0)cout << "NA" << endl;

}


Measured memory_bytes: 256
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sum := 0
	min := 10000000001
	isNegaOdd := false
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		if a < 0 {
			isNegaOdd = !isNegaOdd
			a = -a
		}
		sum += a
		if a < min {
			min = a
		}
	}
	if isNegaOdd {
		sum -= min * 2
	}
	fmt.Println(sum)
}


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


int SelectionSort(int A[], int N) {
	int minj;
	int sw = 0;
	for (int i = 0;i < N;i++) {
		minj = i;
		for (int j = i;j < N;j++)
			if (A[j] < A[minj])
				minj = j;
		if (A[minj] < A[i]) {
			swap(A[i], A[minj]);
			sw++;
		}
	}
	return sw;
}
void trace(int A[], int N) {
	int i;
	for (i = 0;i < N;i++) {
		if (i > 0) cout << " ";/*隣接する要素の間に1つの空白を出力*/
		cout <<A[i];
	}
	cout << endl;
}
int main() {
	int N,sw;
	cin >> N;
	int A[100];
	for (int i = 0;i < N;i++)cin >> A[i];
	sw = SelectionSort(A, N);
	trace(A, N);
	cout << sw << endl;



}


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

int main()
{
    int n,i,j,count=0;
    cin>>n;
    int arr[n];
    for(i=0;i<n;i++)
     cin>>arr[i];
     for(i=0;i<n;i++)
     {
         for(j=i+1;j<n;j++)
          {
              if(j!=i)
              {
                  count+=arr[i]*arr[j];
              }
          }
     }
     cout<<count;
     return 0;
}

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

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

    int n, m;
    cin >> n >> m;

    int sum = 0;
    while(m--) {
        int a;
        cin >> a;
        sum += a;
    }

    int ans = n >= sum ? n - sum : -1;
    cout << ans << '\n';
    return 0;
}


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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;

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

int a, b;

void solve() {
  cin >> a >> b;

  if (a == b) {
    cout<< 0 << endl;
  } else {
    int c = a + b;
    if (c % 2 == 0) {
      cout << c / 2 << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
  }
}

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

  // cout << fixed << setprecision(10);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
long long a[1005],b[1005];
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;++i) scanf("%lld%lld",&a[i],&b[i]);
	for(int i=1;i<n;++i) {
		long long bs=1;
		if(a[i+1]<a[i]) bs=a[i]/a[i+1];
		if(b[i+1]<b[i]) bs=max(bs,b[i]/b[i+1]);
		if(a[i+1]*bs<a[i]||b[i+1]*bs<b[i]) ++bs;a[i+1]*=bs;b[i+1]*=bs;
	}
	printf("%lld\n",a[n]+b[n]);
	return 0;
}

Measured memory_bytes: 128
n, k = map(int, input().split())
l = list(map(int, input().split()))
for i in range(n - 1):
    for j in range(i + 1, n):
        if l[i] < l[j]:
            buf = l[i]
            l[i] = l[j]
            l[j] = buf
ans = 0
for i in range(k):
    ans += l[i]
print(ans)

Measured memory_bytes: 3060
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int b[101010], a[101010];

int main(){
    cin >> n;
    REP(i, n - 1){
        cin >> b[i];
    }
    REP(i, n){
        a[i] = HINF<int>();
    }
    REP(i, n - 1){
        a[i] = min(a[i], b[i]);
        a[i + 1] = min(a[i + 1], b[i]);
    }
    int ans = 0;
    REP(i, n)ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  int N,K;
  int count;
  int result;
  
  cin >> N >> K;
  while(count < N){
    int x;         // input
    int y=count+1; // 1,2,3..

    cin >> x;
    if(x*2 < abs(x-K)*2){
      result += x*2;
    }else{
      result += abs(x-K)*2;
    }
    count++;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
from collections import deque
n, q = map(int, input().split())
d = []
for i in range(n):
    d.append(deque())
for i in range(q):
    x, *y = map(int, input().split())
    if x == 0:
        d[y[0]].append(y[1])
    elif x == 1 and d[y[0]]:
        print(d[y[0]][0])
    elif x == 2 and d[y[0]]:
        d[y[0]].popleft()



Measured memory_bytes: 14536
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a;
long long b;
long long r;
cin>>a>>b>>r;
if(a<=b)cout<<a<<endl;
else {
	if((b+r)>=a)cout<<b<<endl;
	else{
      long long count =(a/(b+r))*b;
      long long k = a%(b+r);
      if(k<=b)cout<<(count+k)<<endl;
      else cout<<(count+b)<<endl;	  
	}
}
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]

K = 10**6+1
num = [0] * K
l = [False] * K
for i in range(N):
    num[A[i]]+=1
    l[A[i]] = True

for i in range(1, K):
    if num[i]>0:
        if num[i]>1:
            l[i] = False
        j = 2
        while i*j < K:
            l[i*j] = False
            j += 1

ans = 0
for i in range(N):
    if l[A[i]]:
        ans += 1

print(ans)


Measured memory_bytes: 104408
program tr
  implicit none
  integer ::i,j,n
  integer,allocatable ::p(:)

  read(*,*) n
  allocate(p(n))
  read(*,*) p
  j=0
  do i=2,n-1
     if((p(i).lt.max(p(i-1),p(i+1))).and.(p(i).gt.min(p(i-1),p(i+1))))then
        j=j+1
     endif
  enddo

  write(*,'(i0)') j
end program tr

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
 int n,i,o=0,t=0;
float j;
 scanf("%d",&n);
if(n==0)
 printf("0");
else
{for(i=1;i<=n;i++)
{ t++;
  if(i%2!=0)
   o++;
}}
j=(float)o/t;
printf("%f",j);
return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
typedef long long int lli;
const int maxn=1e5+1;
const int mod=1e9+7;

int main() {
  lli power[maxn];
  for (int i=0; i<maxn; i++) {
    power[i]=1;
  }
  for (int i=2; i<maxn; i++) {
    power[i]=(power[i-1]*i)%mod;
  }
  int N;
  cin >> N;
  cout << power[N] << endl;
  return 0;
}


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

using namespace std;

int a, b, c, x, y, ans;

int main() {
    cin >> a >> b >> c >> x >> y;
    if (2 * c < a + b) {
	int mn = min(x, y);
	ans += 2 * mn * c;
	x -= mn;
	y -= mn;
    }
    return cout << ans + min(a, 2 * c) * x + min(b, 2 * c) * y, 0;
}

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

int main() {
  vector<string> S(3);
  cin >> S.at(0) >> S.at(1) >> S.at(2);
  int i=0, j=0;
  while(1){
    if(S.at(i).size()==0){
      cout << char('A'+i) << endl;
      break;
      }
    j=i;
    i=S.at(i).at(0)-'a';
    S.at(j).erase(0,1);
  }
}

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

int main(){
  int N;
  int tmp;
  scanf("%d",&N);
  char buf[N*2];
  char buf1[N*2];
  scanf("%s",buf);
  if(N%2!=0){
    printf("No\n");
    return 0;
  }else{
    int c=0;
      while(c!=N/2){
        buf1[c]=buf[c];
        c++;
      }
      tmp=c;
      int i=0;
      while(tmp!=i){
        if(buf1[i]!=buf[c]){
          printf("No\n");
          return 0;
        }
        i++;
        c++;
        }
        printf("Yes\n");
        return 0;
      }


  return 0;

}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string s, t = "CODEFESTIVAL2016";
  cin >> s;
  int ret = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != t[i]) ++ret;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool mp[105][105];
int main()
{
	int a,b,i,j,x=0,y=0;
	cin>>a>>b;
	a--,b--;
	for(i=0;i<50;i++)
		for(j=0;j<100;j++)
			mp[i][j]=1;
	while(a)
	{
		mp[x][y]=0;
		a--;
		y+=2;
		if(y>=100)
		{
			x+=2;
			y=0;
		}
	}
	x=99,y=0;
	while(b)
	{
		mp[x][y]=1;
		b--;
		y+=2;
		if(y>=100)
		{
			x-=2;
			y=0;
		}
	}
	puts("100 100");
	for(i=0;i<100;i++)
	{
		for(j=0;j<100;j++)
		{
			if(mp[i][j])cout<<"#";
			else cout<<".";
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>

void make_table(std::vector<std::vector<char> > &table) {
    int i;
    int j;
    table[1].push_back(46); 
    table[1].push_back(44); 
    table[1].push_back(33); 
    table[1].push_back(63); 
    table[1].push_back(32); 
    for (i = 2; i <= 7; i++) {
        for (j = 0; j <= 2; j++) {
            table[i].push_back(97 + 3 * (i - 2) + j); 
        }
    }
    table[7].push_back(115);
    for (i = 8; i <= 9; i++) {
        for (j = 0; j <= 2; j++) {
            table[i].push_back(116 + 3 * (i - 8) + j); 
        }
    }
    table[9].push_back(122);
}

int main(void) {
    int n;
    std::string s;
    const char* c;
    char now_num;
    int now_count;
    std::vector<std::vector<char> >  table(10, std::vector<char>());
    make_table(table);

    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> s;
        c = s.c_str();
        now_count = 0;
        now_num = c[0];
        //std::cout << "SSIZE = " << s.size() << std::endl;
        for (int j = 0; j < s.size(); j++) {
            if (c[j] == now_num) {
                now_count++;
            } else {
                if (c[j] == '0') {
                    //std::cout << "C = " << c[j] << std::endl;
                    //std::cout << "NUM = " << now_num << std::endl;
                    //std::cout << "COUNT = " << now_count << std::endl;
                    int amari = now_count % table[(int)now_num - 48].size() - 1;
                    if (amari == -1) {
                        amari += table[(int)now_num - 48].size();
                    }
                    std::cout << table[(int)now_num - 48][amari];
                }
                if (j != s.size() - 1) {
                    now_num = c[j];
                }
                now_count = 1;
            }
        }
        std::cout << std::endl;
    }

    return EXIT_SUCCESS;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define S(x) (int) x.size()
#define LB lower_bound
#define UB upper_bound
#define fp(x, y) fixed<<setprecision(y)<<x
#define M 100005
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884
using namespace std;

void solve()
{
	int x;
	float y;
	cin>>x>>y;
	string s = to_string(y);
	int a, b, c;
	a = s[0]-'0';
	b = s[2]-'0';
	c = s[3]-'0';
	int ans = (x*a*100 + x*b*10 + x*c)/100;
	cout<<ans<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3840
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int c[10];
  rep(i,6){
    cin>>c[i];
  }
  if(c[0]+c[1]*5+c[2]*10+c[3]*50+c[4]*100+c[5]*500>=1000){
    cout<<1<<'\n';
  }
  else{
    cout<<0<<'\n';
  }
  return(0);
}


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

struct Node {
  vector<int> to;
  vector<int> e;
};

void dfs(int K, vector<Node> &G, int n, int k, vector<int> &E) {
  auto &g = G[n];
  for (int i = 0; i < g.e.size(); i++) {
    if (E[g.e[i]] == -1) {
      E[g.e[i]] = k;
      k = (k + 1) % K;
      dfs(K, G, g.to[i], k, E);
    }
  }
}

int main(void) {
  int N;
  cin >> N;
  vector<Node> G(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].to.push_back(b);
    G[a].e.push_back(i);
    G[b].to.push_back(a);
    G[b].e.push_back(i);
  }

  int K = 0;
  for (auto &n : G) {
    K = max(K, (int)n.e.size());
  }

  vector<int> E(N - 1, -1);
  dfs(K, G, 0, 0, E);

  cout << K << endl;
  for (auto c : E) {
    cout << c + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 12032
/*  -*- coding: utf-8 -*-
 *
 * 2898.cc: Prime Number
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10000000;
const int MAX_P = MAX_N + 2;

/* typedef */

/* global variables */

bool primes[MAX_P + 1];

/* subroutines */

void gen_primes(int maxp) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  for (int p = 2; p * p <= maxp; p++)
    if (primes[p])
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
}

/* main */

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

  gen_primes(n + 2);

  int cnt = 0;
  for (int p = 1; p <= n; p++)
    if (primes[p] && primes[p + 2]) cnt++, cnt++;
  printf("%d\n", cnt);
  return 0;
}



Measured memory_bytes: 12996
#include<iostream>
#include<vector>
#include<queue>
// #include<unordered_map>
int main(){
    int R,C,K;
    std::cin>>R>>C>>K;
    std::vector<std::vector<unsigned long long> > mat(R,std::vector<unsigned long long>(C,0));
    std::vector<std::vector<bool> > flags(R,std::vector<bool>(C,1));
    std::vector<std::vector<std::vector<unsigned long long> > > dp(R,std::vector< std::vector<unsigned long long> >(C,std::vector<unsigned long long>(4,0)));
    for(int i=0;i<K;++i){
        int r,c,v;
        std::cin>>r>>c>>v;
        mat[r-1][c-1]=v;
    }
    std::queue<std::pair<int,int> > searchQ;
    searchQ.push(std::pair<int,int>(0,0));
    flags[0][0]=0;
    // dp[0][0][1]=mat[0][0];
    while (!searchQ.empty()){
        std::pair<int,int> index=searchQ.front();
        int y=index.first,x=index.second;
        searchQ.pop();
        if(index.second+1 < C){
            for(int i=0;i<4;++i){
                if(dp[y][x+1][i]<dp[y][x][i]){
                    dp[y][x+1][i]=dp[y][x][i];
                }
            }
            if(mat[y][x]>0){
                for(int i=0;i<3;++i){
                    unsigned long long buf=(dp[y][x][i]+mat[y][x]);
                    if(dp[y][x+1][i+1]<buf){
                        dp[y][x+1][i+1]=buf;
                    }
                }
            }
            if(flags[y][x+1]==1){
                searchQ.push(std::pair<int,int>(y,x+1));
                flags[y][x+1]=0;
            }
        }
        if(index.first+1<R){
            unsigned long long max=0;
            for(int i=0;i<4;++i){
                unsigned long long buf=dp[y][x][i];
                if(mat[y][x]>0 && i<3){
                    buf+=mat[y][x];
                }
                if(max<buf){
                    max=buf;
                }
            }
            dp[y+1][x][0]=max;
            if(flags[y+1][x]==1){
                searchQ.push(std::pair<int,int>(y+1,x));
                flags[y+1][x]=0;
            }
        }
    }
    unsigned long long ans=0;
    for(int i=0;i<4;++i){
        unsigned long long buf=dp[R-1][C-1][i];
        if(mat[R-1][C-1] && i<3){
            buf+=mat[R-1][C-1];
        }
        if(ans<buf){
            ans=buf;
        }
    }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 708124
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int min(int a, int b)
{
	return a > b ? b : a;
}
int main()
{
	int a[200];
	int n;
	int sum = 0;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	int num[200];
	num[0] = a[0];
	for (int i = 1; i < n; ++i) {
		num[i] = a[i] + num[i - 1];
		// cout << num[i] << endl;
	}
	int dp[200];
	memset(dp, 0x3f3f3f, sizeof(dp));
	int mina = 0x3f3f3f;
	for (int i = 0; i < n; ++i) {
		mina = min(mina, abs(sum - num[i] - num[i]));
	}
	printf("%d\n", mina);
	return 0;
}


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

using namespace std;

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

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

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

string S;

int dp[5050][5050];

int f(int a, int b) {
    if (a >= S.size() || b >= S.size()) return 0;
    if( dp[a][b] != -1 ) return dp[a][b];
    if (S[a] == S[b]) return dp[a][b] = f(a + 1, b + 1) + 1;
    return 0;
}

void solve(long long N, std::string S) {
    ::S = S;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            ans = max(ans, min(f(i, j), abs(j - i)));
        }
    }
    cout << ans << endl;
}

int main() {
    memset(dp, -1, sizeof(dp));
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 100096
#include <stdio.h>
int main(){
double n;
while(scanf("%lf",&n)!=EOF){
if(n<=48){
printf("light fly\n");
}else if(n<=51){
printf("fly\n");
}else if(n<=54){
printf("bantam\n");
}else if(n<=57){
printf("feather\n");
}else if(n<=60){
printf("light\n");
}else if(n<=64){
printf("light welter\n");
}else if(n<=69){
printf("welter\n");
}else if(n<=75){
printf("light middle\n");
}else if(n<=81){
printf("middle\n");
}else if(n<=91){
printf("light heavy\n");
}else{
printf("heavy\n");
}}
return 0;
}

Measured memory_bytes: 608
l, r = map(int, input().split())
mod = []
ans = 0

if r-l<673:
  if l%673 < r%673:
    for i in range(l%2019, r%2019):
      for j in range(i+1, r%2019+1):
        mod.append((i*j)%2019)
    ans = min(mod)
print(ans)

Measured memory_bytes: 6808
#import sys
#input = sys.stdin.readline

n = int(input())
abc = []
for i in range(n):
    abc.append([int(i) for i in input().split()])
dp = [[float("inf") for i in range(3)] for i in range(n)]

dp[0] = abc[0]
for i in range(n-1):
    dp[i+1][0] = abc[i+1][0] + max(dp[i][1], dp[i][2])
    dp[i+1][1] = abc[i+1][1] + max(dp[i][0], dp[i][2])
    dp[i+1][2] = abc[i+1][2] + max(dp[i][0], dp[i][1])
    
print(max(dp[-1]))


Measured memory_bytes: 86232
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
Def inf=1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n,m,c,out=0;
vvi w;
void f(int x,int y,int r){
    w[x][y]=0;
    rep(i,4){
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx<0||ny<0||nx>=n||ny>=m)continue;
        if(w[nx][ny]==r)f(nx,ny,r);
    }
}
void F(vvi in,int a){
    if(a==5){
        w=in;
        int co=0;
        if(c==in[0][0])f(0,0,in[0][0]);
        rep(i,n)rep(j,m)co+=!w[i][j];
        out=max(out,co);
    }else{
        rep(q,6){
            w=in;
            f(0,0,in[0][0]);
            rep(i,n)rep(j,m)if(w[i][j]==0)w[i][j]=q+1;
            F(w,a+1);
        }
    }
}
signed main(){
    while(cin>>n>>m>>c,n){
        vvi in(n,vi(m));
        rep(i,n)rep(j,m)cin>>in[i][j];
        out=0;
        F(in,0);
        cout<<out<<endl;
    }
}



Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>
#include<algorithm>
#include<queue>
#include<set>
#include<math.h>
#include<random>


#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}

struct SegmentTree {
private:
	int n;
	vector<long long int> node;
	int TANNI;

	long long int Func(long long int a, long long int b) {
		return min(a,b);
	}

public:
	//元配列ｖをセグメント木で表現する。
	SegmentTree(vector<long long int> v, long long int tanni) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪→これをｎとおく。
		//セグメント木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1;
		while (n < sz)n *= 2;

		TANNI = tanni;
		node.resize(2 * n - 1, TANNI);

		//最下段に値を入れた後に、下の段から順番に値を入れる。
		//値を入れるには、自分の子の２値を参照すればよい。
		for (int i = 0; i < sz; i++)node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--)node[i] = Func(node[2 * i + 1], node[2 * i + 2]);
	}

	void update(long long int x, long long int val) {
		//最下段のノードにアクセスする。
		x += (n - 1);

		//最下段のノードを更新したら、あとは親に上って更新していく。
		node[x] = val;

		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = Func(node[2 * x + 1], node[2 * x + 2]);
		}
	}

	long long int getVal(int x) {
		x += (n - 1);
		return node[x];
	}

	long long int getAns(int a, int b, int k = 0, int l = 0, int r = -1) {
		//最初に呼び出された時の区間は[0,n)
		if (r < 0)r = n;

		//要求区間と対象区間が交わらない→単位元を返す。
		if (r <= a || b <= l) return TANNI;

		//要求区間が対象区間を完全に被覆する→対象区間を答えの計算に使う。
		if (a <= l && r <= b) return node[k];

		//要求区間が対象区間の一部を被覆→子をよびだす。
		//左の子をvl、右の子をvrとしている。
		//新しい対象区間は現在の対象区間を半分に割ったもの。
		int vl = getAns(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = getAns(a, b, 2 * k + 2, (l + r) / 2, r);
		return Func(vl, vr);


	}



};




int main()
{
	
	int x, y, z;
	cin >> x >> y >> z;

	cout << z << " " << x << " " << y << endl;

	return 0;





}



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

void swap(int& a, int& b){
	int h = a;
	a = b;
	b = h;
}

int BubbleSort(vector<int>& A){
	int count = 0;
	for(int i = 0;i<A.size();i++){
		for(int j = A.size()-1; j>i; j--){
			if(A[j] < A[j-1]){
				count++;
				swap(A[j], A[j-1]);
			}
		}
	}
	return count;
}
int SelectionSort(vector<int>& A){
	int count = 0;
	for(int i = 0; i< A.size(); i++){
		int mini = i;
		for(int j = i; j < A.size(); j++){
			if(A[j] < A[mini]){
				mini = j;
			}
		}
		if(i != mini){
			count++;
			swap(A[i], A[mini]);
		}
	}
	return count;
}

int main(){
	int n,h;
	vector<int> v;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> h;
		v.push_back(h);
	}
	int c = SelectionSort(v);
	cout << v[0];
	for(int i=1;i<n;i++){
		cout << " " << v[i];
	}
	cout << endl << c << endl;
	return 0;
}

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

bool palcheck(string s)
{
	for(int i=0;i<s.length();i++)
	{
		if(s[i]!=s[s.length()-1-i])
		{
			return false;
		}
	}
	return true;
}


int main()
{
	string s;
	getline(cin,s);
	string s1 = s;
	string s2 = "";
	string s3 = "";
	for(int i =0;i<(s.length()-1)/2;i++)
	{
		s2 += s[i];
	}
	for(int i =((s.length()+3)/2)-1;i<s.length();i++)
	{
		s3 += s[i];
	}
	if(palcheck(s1)&&palcheck(s2)&&palcheck(s3))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    int sum = 0;
    for(int i = 0; i < n; i++){
        int l, r; cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, q;
  cin >> n >> m >> q;
  vector<int> a(q), c(m);
  for (auto&& e : a) {
    cin >> e;
    --e;
    ++c[e];
  }
  reverse(begin(a), end(a));
  set<int> se;
  vector<int> v;
  for (int e : a) {
    if (se.count(e)) {
      continue;
    }
    se.insert(e);
    v.push_back(e);
  }
  for (int i = 0; i < m; ++i) {
    if (se.count(i)) {
      continue;
    }
    se.insert(i);
    v.push_back(i);
  }
  while (v.size() >= 2 and v[v.size() - 2] < v.back()) {
    v.pop_back();
  }
  v.pop_back();
  if (any_of(begin(v), end(v), [&](int e) { return c[e] < n; })) {
    cout << "No\n";
    exit(0);
  }
  int k = v.size();
  map<int, int> mp;
  for (int i = 0; i < k; ++i) {
    mp[v[i]] = i;
  }
  vector<int> t(k);
  for (int e : a) {
    if (not mp.count(e)) {
      continue;
    }
    int i = mp[e];
    if (t[i] == n) {
      continue;
    }
    if (i == 0 or t[i - 1] > t[i]) {
      ++t[i];
    }
  }
  if (all_of(begin(t), end(t), [&](int e) { return e == n; })) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


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

int main() {
  int n, m;
  long x;
  cin >> n >> m >> x;
  long c[n], a[n][m];
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  
  long min = -1;
  
  // 全探索（2^n 通り. 最大 2^12=4096 通り）
  // 12桁の2進数
  int b = 0b0;
  while (b++ < pow(2, n)) {
    long total_price = 0;
    vector<long> skills(m);
    bool satisfied = true;
    for (int i = 0; i < n; i++) {
      total_price += ((b >> i) & 1)*c[i];
      for (int j = 0; j < m; j++) {
        skills[j] += ((b >> i) & 1)*a[i][j];
      }
    }
    for (int j = 0; j < m; j++) {
      if (skills[j] < x) {
        satisfied = false;
        break;
      }
    }
    if (satisfied && (total_price < min || min == -1)) min = total_price;
  }
  
  cout << min;
  
  return 0;
}

Measured memory_bytes: 4104
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int dp[100001];
main()
{
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++) cin>>arr[i];
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
	    int q=1000000000000000000;
	    for(int j=1;j<=k;j++)
	    {
	        if(i-j>=0)
	        {
	            q=min(q,dp[i-j]+abs(arr[i]-arr[i-j]));
	        }
	    }
	    dp[i]=q;
	}
	cout<<dp[n-1];
}

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

using namespace std;

int main(){
    char exa;
    int time = 1;
	bool ha = false;
    while (exa = getchar()){
		time ++;
		if (time > 101)	break;
		if (exa == 'C')	ha = true;
    	if (exa == 'F' && ha == true){
    		printf ("Yes");
    		return 0;
		}
	}
	printf ("No");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		int tot = 0, mn = 500000;
		for(int i = 1; i <= n; i++){
			tot = tot + (l + i -1);
			if( Math.abs(mn) > Math.abs(l+i-1) )
				mn = l+i-1;
		}

		tot = tot - mn;
		System.out.println(tot);
	}
}

Measured memory_bytes: 21844