akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define NODE_NUM 100000
struct node_t {
	int key;
	struct node_t *next;
};
typedef struct node_t Node;

Node *insert_value(Node *node, int value) {
	Node *p;

	p = malloc(sizeof(Node));
	p->key = value;
	p->next = node;
	return p;
}

int find_value(Node *node, int value) {
	Node *p;

	for (p = node; p != NULL; p = p->next) {
		if (p->key == value)
			return 1;
	}
	return 0;
}

int get_key(char str[15]) {
	static int code['T'+1] = {['A']=1, ['C']=2, ['G']=3, ['T']=4};
	int i, s = 0, p = 1;

	for (i = 0; str[i] != '\0'; i++) {
		s += p * code[(int)str[i]];
		p *= 5;
	}
	return s;
}

int main(void) {
	Node *nodes[NODE_NUM] = {0};
	int num_cmd, key, index;
	char cmd[15], str[15];

	scanf("%d ", &num_cmd);
	while (num_cmd--) {
		scanf("%s %s", cmd, str);
		key = get_key(str);
		index = key % NODE_NUM;
		if (cmd[0] == 'i') {
			nodes[index] = insert_value(nodes[index], key);
		} else {
			if (find_value(nodes[index], key)) {
				puts("yes");
			} else {
				puts("no");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 19204
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n;
  cin>>n;
  int ly = 0;
  int rx = 1e9;
  int largest = 0;
  vector<tuple<int,int>> vt;
  for(int i:irange(0,n)) {
    int l,r;
    cin>>l>>r;
    ly = max(ly, l);
    rx = min(rx, r);
    largest = max(largest, r-l);
    vt.emplace_back(l,r);
  }
  boost::sort(vt);
  boost::reverse(vt);
  int ry = 1e9;
  int res = 0;
  for (int i:irange(0,n)) {
    int lx,r;
    tie(lx,r) = vt[i];
    if (i > 0) {
      int c1 = max(rx-lx+1, 0);
      int c2 = max(ry-ly+1, 0);
      res = max(res, c1+c2);
    } else {
      int c1 = max(rx-ly+1, 0);
      int c2 = largest+1;
      res = max(res, c1+c2);
    }
    ry = min(ry, r);
  }
  cout<<res<<endl;
  return 0;
}


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

const int kn = 2e5 + 5, N = 1e5+5;

#define x first
#define y second

#define ff(i,n) for(int i=1;i<=n;i++)

int n, m, s, t;
vector<int> G[N];

int dis[3][N];

priority_queue< pair< pair<int,int>, int>, vector<pair< pair<int,int>, int> >, greater< pair< pair<int,int>, int> > > pq; //dis, remainder, vertex

int main() {
	scanf("%d %d", &n, &m);
	ff(i,m)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		G[u].push_back(v);
	}
	ff(i,n) dis[0][i] = dis[1][i] = dis[2][i] = 3*m + 1;
	scanf("%d %d", &s, &t);
	dis[0][s] = 0;
	pq.push({{0,0},s});
	while(pq.size())
	{
		int dist = pq.top().x.x, rem = pq.top().x.y, u = pq.top().y;
		//cout << dist <<" "<<rem <<" "<<u << endl;
		pq.pop();
		if(dist == 3*m || dist != dis[rem][u]) continue;
		int nxt = (rem+1)%3;
		for(int p : G[u])
		{
			if(dis[nxt][p] > dist + 1*(not nxt))
			{
				dis[nxt][p] = dist + 1*(not nxt);
				pq.push({{dist+1*(not nxt),nxt},p});
			}
		}
	}
	if(dis[0][t] == 3*m+1) printf("-1");
	else printf("%d",dis[0][t]);
}
//hahahahahahahahahhahahahahahaahahahahhahahahahahahah


Measured memory_bytes: 6912
# include"stdio.h"
int main(){
    int n;
    scanf("%d",&n);
    char s[n];
    int f[n];
    scanf("%s",s);

    for(int i=0;i<n;i++)
        f[i]=0;
    int max=0;
    for(int i=0;i<n;i++){
        if(s[i]=='I')f[i]++;
        else  f[i]--;
        if(i!=n-1) f[i+1]=f[i];
        if(max<f[i]) max=f[i];
    }
    printf("%d\n",max);
}


Measured memory_bytes: 128
S  = [inp for inp in input()]
dic = {}
for s in S:
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
ans = float('inf')
N = len(S)
for alphabet in dic.keys():
    tempN = N
    copyS = S.copy()
    count = 0
    while True:
        if copyS.count(alphabet) == tempN:
            break
        count += 1
        for i in range(tempN-1):
            copyS[i] = copyS[i] if copyS[i] == alphabet else copyS[i+1]
        copyS.pop(-1)
        tempN -= 1
    if count < ans:
        ans = count
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int Abs(int x){
  return x > 0 ? x : -x ;
}
  

int main (void){
  int n;
  int a[100002];
  int i;
  int budget_MAX = 0;
  int budget;
  
  scanf("%d",&n);
  a[0] = 0;
  a[n+1] = 0;
  for(i=1; i<=n+1; i++){
    scanf("%d",&a[i]);
    
    budget_MAX += Abs(a[i] - a[i-1]);
  }
  
  for(i=1; i<=n; i++){
    //printf("(a[n-1],a[n],a[n+1]) = (%d,%d,%d)\n",a[i-1],a[i],a[i+1]);
    if( (a[i-1] <= a[i] && a[i] <= a[i+1]) ||
        (a[i-1] >= a[i] && a[i] >= a[i+1]) ){
          budget = budget_MAX;
        }
    else if( Abs(a[i-1] - a[i]) < Abs(a[i] -a[i+1]) ){
          budget = budget_MAX - Abs(a[i-1] - a[i]) * 2;
    }
    else{
          budget = budget_MAX - Abs(a[i] - a[i+1]) * 2;
    }
   printf("%d\n",budget);                                
  }
  
  return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <ll, ll> pll;
const ll M=1e9+7;
ll inf=1e18;
int main()
{
    fast;
    int n,k;
    cin>>n>>k;
    vector <int> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    int dp[k+1]={0};
    for(int i=0;i<=k;i++){
        for(int j=0;j<v.size();j++){
            if(i>=v[j] && !dp[i-v[j]])
                dp[i]=1;
        }
    }
    if(dp[k])
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;
}


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

int main() {
    int x;
    cin >> x;
    if (x >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3552
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if op == "?":
        break
    
    if op == "+":
        print("%d" % (a+b))
    if op == "-":
        print("%d" % (a-b))
    if op == "*":
        print("%d" % (a*b))
    if op == "/":
        print("%d" % (a/b))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
using namespace std;

signed main(){
    int b;
    cin>>b;
    while(b){
        int x,y=0;
        Rep(i,1,100000){
            int t=i*(i+1)/2;
            if(b>=t&&(b-t)%i==0&&y<i){
                x=(b-t)/i+1;
                y=i;
            }
        }
        cout<<x<<" "<<y<<endl;
        cin>>b;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int a, b;
    vector<int> ans;
    string str;
    int count=0;

    while(1)
    {
        cin >> a >> str >> b;
        if(str == "?")
            break;
        else if(str == "+")
            ans.push_back(a+b);
        else if(str == "-")
            ans.push_back(a-b);
        else if(str == "*")
            ans.push_back(a*b);
        else if(str == "/")
            ans.push_back(a/b);
        count++;
    }
    for(int i = 0; i < count; i++)
        cout << ans[i] << endl;
    return 0;
} 

Measured memory_bytes: 1232
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()

typedef unsigned long long ll;

int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

int main(){ 
int N; cin >> N;
vector<pair<ll, ll>> c(N);//配列の宣言
for(int i = 0; i < N ; i++){
  ll a,b;
  cin >> a >> b;
  c[i] = make_pair(a,b);//配列型のpairに代入
}
ll count = 0;
for(int i = N - 1; i >=0; i--){
    if(c[i].first % c[i].second != 0){
        count += c[i].second - (c[i].first % c[i].second);
    }
    if(i != 0){
        c[i-1].first += count; 
    }
}
cout << count << endl;
}





Measured memory_bytes: 1792
package main

import (
  "fmt"
  "strconv"
)

func stoi(s string) int {
  d, _ := strconv.Atoi(s)
  return d
}

func main() {
  var s string 
  fmt.Scan(&s)
  a, b := stoi(s[:2]), stoi(s[2:])
  bl1 := a >= 1 && a <= 12
  bl2 := b >= 1 && b <= 12
  var res string 
  if bl1 {
    if bl2 {
      res = "AMBIGUOUS"
    } else {
      res = "MMYY"
    } 
  } else {
    if bl2 {
      res = "YYMM"
    } else {
      res = "NA"
    }
  }
  fmt.Println(res)
}


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


def solve(N: int, s: "List[int]"):
    s.sort()
    x = sum(s)
    si = [i for i in s if(i%10 != 0)]
    if(x%10 == 0):
        idx = 0
        while(x%10 == 0 and idx < len(si)):
            x -= si[idx]
            idx += 1

            
    if(x%10 == 0):
        print(0)
    else:
        print(x)
        
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17

int d(ll x){
    int ans=0;
    while(x){
        x/=10;
        ans++;
    }
    return ans;
}
int main(){
    ll n;cin>>n;
    ll num[10][10];
    memset(num,0,sizeof(num));
    for(int i=1;i<=n;i++){
        if(i<=9){num[i][i]++;continue;}
        int high=i/(pow(10,d(i)-1));
        int low=i%10;
        if(!high||!low)continue;
        num[high][low]++;
    }
    ll res=0;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            res+=num[i][j]*num[j][i];
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define ck(a,b) (0<=(a)&&(a)<(b))

using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int ans=-1;
		int maxs=0;
		string s[51];
		REP(i,0,n) {
			string tmps;
			cin>>tmps;
			s[i]+=tmps[0];
			REP(j,1,(int)tmps.size()){
				char c=tmps[j-1];
				if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
					s[i]+=tmps[j];
				}
			}
			maxs=max(maxs,(int)s[i].size());
		}
		REP(k,1,maxs+1){
			set<string> ss;
			REP(i,0,n){
				string ryaku;
				if((int)s[i].size()<k) ryaku=s[i];
				else ryaku=s[i].substr(0,k);
				if(ss.find(ryaku)==ss.end()){
					ss.insert(ryaku);
				}else	break;
			}
			if((int)ss.size()==n) {
				ans=k;
				break;
			}
		}
		p(ans);
	}
	return 0;
}

Measured memory_bytes: 3172
const lines = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
const line1st = lines[0].split(' ');
const N = +line1st[0];
const M = +line1st[1];
const H = lines[1].split(' ').map(v => +v);
const A = [];
const B = [];
for (let i = 2; i < 2 + M; i++) {
    const line = lines[i].split(' ');
    A.push(+line[0]);
    B.push(+line[1]);
}

// console.log(`N=${N} M=${M}`);
// console.log(H);
// console.log(A);
// console.log(B);

const badTowers = {};

for (let i = 0; i < M; i++) {
    const a = A[i] - 1;
    const b = B[i] - 1;
    const ha = H[a];
    const hb = H[b];
    // console.log(`i=${i} H[${a}]=${ha} H[${b}]=${hb}`)
    if (ha < hb) {
        badTowers[A[i]] = true;
        // console.log(`${A[i]} = bad`);
    } else if (ha > hb) {
        // console.log(`${B[i]} = bad`);
        badTowers[B[i]] = true;
    } else {
        badTowers[A[i]] = true;
        badTowers[B[i]] = true;
    }
}

let good = 0;
for (let i = 1; i <= N; i++) {
    if (!badTowers[i]) {
        good ++;
    }
}

// console.log(badTowers);
console.log(good);


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

int i = 0, j = 0, ans = 0, tmp = 0,a,b;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n ,m;
	cin >> n >> m;
	ans = 0;
	vector<int> s;
	vector<int> g;
	int sc = 0, gc = 0;
	int i = 0, j = 0, ans = 0, tmp = 0;
	for (i; i < m; ++i) {
		cin >> a >> b;
		if (a == 1) {
			s.push_back(b);
			sc++;
		}
		else if (b == n) {
			g.push_back(a);
			gc++;
		}
	}
	sort(s.begin(), s.end());
	sort(g.begin(), g.end());
	i = 0;
	j = 0;
	while (1) {
		if (i > sc - 1 || j > gc - 1) {
			break;
		}
		if ( s[i] == g[j]) {
			ans = 1;
			break;
		}
		if (s[i] < g[j]) {
			i++;
		}
		else {
			j++;
		}
	}



	if (ans == 0) {
		printf("IMPOSSIBLE\n");
	}
	else {
		printf("POSSIBLE\n");
	}
	cin >> a;
	return 0;
}

Measured memory_bytes: 1276
import java.util.*;
import java.util.ArrayList;

public class Main{
    public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        String[] strN = sc.next().split("");
        int len = strN.length;
        int N = Integer.parseInt(String.join("",strN));
        int n = 0;
        for (int i=0;i<len;i++) n += Integer.parseInt(strN[i]);
        //System.out.println(N);
        if(N%n==0)System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 22996
import java.util.*;

class Main{

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

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            w = sc.nextInt(); h = sc.nextInt();
            if(w==0 && h==0) break;

            int[][][][] dp = new int[w+2][h+2][2][2];
                 
            dp[1][1][1][1] = 1;
            dp[1][1][1][0] = 1;
            for(int x=1; x<=w; x++){
                for(int y=1; y<=h; y++){
                    for(int turn = 0; turn<2; turn++){
                        for(int before=0; before<2; before++){
                            for(int i=0; i<2; i++){
                                int nx = x + dx[i], ny = y + dy[i];
                                if(nx<1 || nx>w || ny<1 || ny>h) continue;
                                if(turn==1 && before!=i) continue;
                                int nturn = 0;
                                if(before!=-1 && before!=i) nturn = 1;
                                dp[nx][ny][nturn][i] += dp[x][y][turn][before];
                                dp[nx][ny][nturn][i] %= 100000;
                            }
                        }
                    }
                }
            }

            int ans = dp[w][h][0][0] + dp[w][h][0][1] + dp[w][h][1][0] + dp[w][h][1][1];
            System.out.println(ans%100000);
        }
    }

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

Measured memory_bytes: 23192
import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def bfs(sy, sx):
    dist = [[-INF] * W for _ in range(H)]
    dist[sy][sx] = 0
    que = deque([(sy, sx)])
    popleft = que.popleft; append = que.append
    while que:
        y, x = popleft()
        cur = dist[y][x]
        for dy, dx in zip([0, 1, 0, -1], [1, 0, -1, 0]):            
            ny = y + dy
            nx = x + dx
            if 0 <= ny < H and 0 <= nx < W and \
                    grid[ny][nx] != '#' and dist[ny][nx] == -INF:
                dist[ny][nx] = cur + 1
                append((ny, nx))
    ret = max(max(x for x in di)for di in dist)
    return ret

INF = 10 ** 3
H, W = lr()
grid = [sr() for _ in range(H)]
answer = max(max(bfs(i, j) if grid[i][j] == '.' else 0 for j in range(W)) for i in range(H))
print(answer)
# 22

Measured memory_bytes: 45916
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, t=0;
  cin >> N;
  vector<int> A(N);
  REP(i,N) cin >> A[i];
  int no_1=0, no_2=0;
  REP(i,N) {
    if(A[i]>no_1) {
      no_2 = no_1;
      no_1=A[i];
    }
    else if(no_2 < A[i] && A[i] <= no_1){
      no_2 = A[i];
    }
  }
  REP(i,N) {
    if(no_1 != A[i]) cout << no_1 << endl;
    else  cout << no_2 << endl;
  }
}

Measured memory_bytes: 2432
def solve(n, xs):
	ys = sorted(xs, reverse=True)
	m1, m2 = ys[0], ys[1]
	for x in xs:
		if x == m1:
			yield m2
		else:
			yield m1


def main():
	n = int(input())
	xs = [int(input()) for _ in range(n)]
	for a in solve(n, xs):
		print(a)


if __name__ == "__main__":
	main()

Measured memory_bytes: 14112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

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

int main(){
	vector<int> a(5);
	rep(i, 5) cin >> a[i];
	
	int ans = 0;
	int mx_loss = 0;
	for(int i = 0; i < 5; ++i){
		int time = (a[i] + 9) / 10 * 10;
		ans += time;
		mx_loss = max(mx_loss, time - a[i]);
	}
	
	cout << ans - mx_loss << endl;
	
	return 0;
}



Measured memory_bytes: 256
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)

    from collections import Counter
    from collections import deque

    #dxy = [[0,1],[0,-1],[1,0],[-1,0]]
    #dxy = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]]
    #mod = 1000000007

    n = int(input())
    F = [input().split() for _ in range(n)]
    P = [list(map(int, input().split())) for _ in range(n)]
    ans = -10**10
    for i in range(1, 1033):
        a = list(str(format(i, '010b')))
        total = 0
        for j in range(n):
            cnt = 0
            for k in range(10):
                if F[j][k]=='1' and a[k]=='1':
                    cnt += 1
            total += P[j][cnt]
        if total>ans:
            ans = total
    print(ans)




if __name__ == '__main__':
    main()

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

int chofuku(vector<int> Bin){
  sort(Bin.begin(),Bin.end());
  int n = Bin.size();
  int ans = 0;
  for(int i=1;i<n;i++){
    if(Bin[i] == Bin[i-1] && Bin[i] > 0)ans++;
  }
  // cout << " " << ans << endl;
  return ans;
}

int main(){
  
  int N,A,B,C;
  cin >>N>>A>>B>>C;
  vector<int> l(N);
  for(int i=0;i<N;i++) cin >>l[i];
  
  int ans = 1000000000;
  
  int max_i = pow(4,N);
  for(int i=0;i<max_i;i++){
    vector<int> Bin(N);
    vector<int> Ans(4,0);
    int gousei = 0;
    for(int j=0;j<N;j++){
      Bin[j] = (i>>(2*j))&3;
      Ans[Bin[j]] += l[j];
    }
    // for(int i=0;i<3;i++) cout << Bin[i] << " ";
    gousei = chofuku(Bin);
    int ans1 = abs(Ans[1] - A);
    int ans2 = abs(Ans[2] - B);
    int ans3 = abs(Ans[3] - C);
    int temp = ans1 + ans2 + ans3 + gousei*10;
    if(Ans[1]*Ans[2]*Ans[3] > 0) ans = min(temp,ans);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N,M; cin >> N >> M;
    vector<int> H;
    vector<vector<int> > G(N);
    REP(i,N){
        int h; cin >> h; //h--;
        H.push_back(h);
    }
    REP(i,M){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int ans = 0;
    REP(i,N){
        if(G[i].size() == 0){
            //cout << i << endl;
            ans++;
        }
        else{
            bool flag = true;
            REP(k,G[i].size()){
                if(H[i] <= H[G[i][k]]){
                    flag = false; break;
                }
            }
            if(flag == true){
                //cout << i << endl;
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 8728
void main() {
	auto ip = readAs!(long[]), A = ip[0], B = ip[1], N = ip[2];
	long res;
	
	//res.writeln;

	auto m = min(B-1, N);
	writeln((floor(A*m/B.to!real) + A*floor(m / B.to!real).to!long));
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-10
//#define p 2173412051LL
//#define sz 2

using namespace std;

char s[ 200010 ];
ll f[ 2 ][ 2019 ];

int main() {
	int n;
	ll ans = 0;
	scanf( "%s", s + 1 );
	n = strlen( s + 1 );
	for( int i = 1; i < n; ++i ) {
		memset( f[ 1 ], 0, sizeof( f[ 1 ] ) );
		f[ 0 ][ s[ i ] - '0' ] += 1;
		for( int j = 0; j < 2019; ++j )
			f[ 1 ][ ( j * 10 + s[ i + 1 ] - '0' ) % 2019 ] += f[ 0 ][ j ];
		for( int j = 0; j < 2019; ++j )
			f[ 0 ][ j ] = f[ 1 ][ j ];
		ans += f[ 0 ][ 0 ];
	}
	printf( "%lld", ans );
	return 0;
}

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

int main(){
    int W, a, b;
    cin >> W >> a >> b;
    if(a<b){
        if (a+W >= b)
            cout << 0 << endl;
        else
            cout << (b-a-W) << endl;
    } else if (a>b){
        if(b+W >= a)
            cout << 0 << endl;
        else
            cout << (a-b-W) << endl;
    } else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    int main(){
        int a,b,c,d,e,f,g,h,i;
            cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
        int N;
            cin>>N;
        vector<int>x(N);
        for(int i=0;i<N;i++){
            cin>>x.at(i);
        }
        for(int j=0;j<N;j++){
            if(a==x.at(j)){
                a=0;
            }
            if(b==x.at(j)){
                b=0;
            }
            if(c==x.at(j)){
                c=0;
            }
            if(d==x.at(j)){
                d=0;
            }
            if(e==x.at(j)){
                e=0;
            }
            if(f==x.at(j)){
                f=0;
            }
            if(g==x.at(j)){
                g=0;
            }
            if(h==x.at(j)){
                h=0;
            }
            if(i==x.at(j)){
                i=0;
            }
        }
        if(a==0&&b==0&&c==0){
            cout<<"Yes";
        }else if(d==0&&e==0&&f==0){
            cout<<"Yes";
        }else if(g==0&&h==0&&i==0){
            cout<<"Yes";
        }else if(a==0&&d==0&&g==0){
            cout<<"Yes";
        }else if(b==0&&e==0&&h==0){
            cout<<"Yes";
        }else if(c==0&&f==0&&i==0){
            cout<<"Yes";
        }else if(a==0&&e==0&&i==0){
            cout<<"Yes";
        }else if(c==0&&e==0&&g==0){
            cout<<"Yes";
        }else{
            cout<<"No";
        }
        //cout<<a<<b<<c<<d<<e<<f<<g<<h<<i;
    return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(m);
  rep(i,m) cin>>a[i];

  int ans = max(a[0]-1, n - a.back());
  rep(i,m-1){
    ans = max(ans, (a[i+1] - a[i])/2);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3152
n = int(input())

s = [""] * n
t = [""] * n

cnt = 0
flg = 0

for i in range(n):
    s[i] = input()
    t[i] = sorted(s[i])

t = sorted(t)

for i in range(n - 1):
    if t[i] == t[i + 1]:
        flg += 1
        cnt += flg
    else:
        flg = 0

print(cnt)


Measured memory_bytes: 32688
import java.util.Scanner;

public class Main {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int a;
        int b;
        String op;
        while(true){
            a = sc.nextInt();
            op = sc.next();
            b = sc.nextInt();
            
            switch (op) {
                case "+":
                    System.out.println(a+b);
                    break;

                case "-":
                    System.out.println(a-b);
                    break;

                case "*":
                    System.out.println(a*b);
                    break;

                case "/":
                    System.out.println(a/b);
                    break;

                case "?":
                    sc.close();
                    return;
            }
        }
    }
}


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

static const int N = 100;

int main()
{
    int n, p[N + 1], m[N + 1][N + 1];
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> p[i - 1] >> p[i];
    }

    for (int i = 1; i <= n; i++)
    {
        m[i][i] = 0;
    }

    for (int l = 2; l <= n ; l++)
    {
        for (int i = 1; i <= n - l + 1; i++)
        {
            int j = i + l -1;
            m[i][j] = (1 << 21);
            for (int k = i; k <= j - 1; k++)
            {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }

    cout << m[1][n] << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int N;
    while (cin >> N, N)
    {
        vector<P> p(N + 1);
        vector<int> rsum(N + 1, 0), wsum(N + 1, 0);
        for (int i = 1; i <= N; i++)
        {
            int r, w;
            cin >> r >> w;
            p[i] = P(r, w);
        }
        sort(p.begin(), p.end());
        for (int i = 1; i <= N; i++)
        {
            rsum[i] = rsum[i - 1] + p[i].first;
            wsum[i] = wsum[i - 1] + p[i].second;
        }
        if (2 * p[N].first > rsum[N])
        {
            // dp[i][j] := i 冊目まででwrite に T 使えるか
            int wmax = p[N].first;
            vector<vector<bool>> dp(N + 1, vector<bool>(wmax + 1, false));
            dp[0][0] = true;
            for (int i = 1; i < N; i++)
            {
                int w = p[i].second;
                for (int j = 0; j <= wmax; j++)
                {
                    dp[i][j] = dp[i - 1][j];
                    if (j >= w)
                    {
                        dp[i][j] = dp[i][j] | dp[i - 1][j - w];
                    }
                }
            }
            int ma = -1;
            for (int j = 0; j <= wmax - rsum[N - 1]; j++)
            {
                if (dp[N - 1][j])
                    ma = max(ma, j);
            }
            cout << 2 * wmax + (wsum[N] - ma) << endl;
        }
        else
        {
            cout << rsum[N] + wsum[N] << endl;
        }
    }
}



Measured memory_bytes: 3264
#[allow(dead_code)]
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    
    let a = readlvec!(i32);
    let f = |a: &Vec<_>| {
        let ma = a.iter().cloned().max().unwrap();
        let res = a.iter().cloned().map(
            |x|
            if (ma-x)%2 == 0 {
                (ma-x)/2
            } else {
                1_000_000
            }).sum();
        res
    };
    let mut ans: i32 = f(&a);
    let mut a: Vec<_> = a.into_iter().map(|x| x+1).collect();
    for i in 0..a.len() {
        a[i] -= 1;
        ans = min(ans, f(&a)+1);
        a[i] += 1;
    }
    printfln!("{}", ans);
}


Measured memory_bytes: 4352
n = str(input())[::-1]
n = n + "0"
l = len(n)
ans = 0
flg = 0
check = 0

for i in range(l):
    check = int(n[i])
    check += flg
    if check == 5:
        if int(n[i + 1]) >= 5:
            ans += 5
            flg = 1
        else:
            ans += 5
            flg = 0
    elif check > 5:
        ans += 10 - check
        flg = 1
    else:
        ans += check
        flg = 0
print(ans + flg)



Measured memory_bytes: 5492
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        Console.WriteLine(a + b >= 10 ? "error" : (a + b).ToString());
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main()
{
	chutiyaap;
	int x;cin>>x;
	int fi=x/500;
	fi*=1000;
	int rem=x%500;
	int f=rem/5;
	f*=5;
	cout<<f+fi;


}

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

void solve(){

	ll x,y ;
	cin>>x>>y ;

	if(x==y|| x%y==0)
	{
		cout<<-1 ;
	}
	else{
		cout<<x; 
	}

}


int main(){



		int y ;

		y=1 ;
		//cin>>y ;

		while(y--){
 
			solve() ;

		}

}

Measured memory_bytes: 3640
#include <iostream>

int main() {
  unsigned long long N, M;
  std::cin >> N >> M;
  if (N * 2 >= M) {
    std::cout << M / 2 << std::endl;
  } else {
    std::cout << N + (M - N * 2) / 4 << std::endl;
  }
  return 0;
}

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

int main() {
  ll a, b, n, tmp, tmp1, tmp2, ans;
  cin >> a >> b >> n;
  tmp = n / b * b - 1;
  tmp1 = floor(a * tmp / b) - a * floor(tmp / b);
  tmp2 = floor(a * n / b) - a * floor(n / b);
  ans = tmp1 >= tmp2 ? tmp1 : tmp2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>


int main(){

  int a,b;
  scanf("%d %d",&a,&b);


  if( a < b ){
    printf("a < b\n");
  }
  if( a > b ){
    printf("a > b\n");
  }
  if(a == b){
    printf("a == b\n");
  }

}



// C++
/*
#include <iostream>
using namespace std;


int main(){

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

  if( a < b ){
    cout << "a < b" << endl;;
  }
  if( a > b ){
    cout << "a > b" << endl;;  
  }
  if(a == b){
    cout << "a == b" << endl;;
  }

}
*/

Measured memory_bytes: 1012
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;

int main()
{
    string S;
    ll K;
    cin >> S >> K;

    int num = 0;
    for (int i = 0; i < min((ll)S.size(), K); i++) {
        num = S[i] - '0';
        if (num > 1) break;
    }

    cout << num << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = [int(x) for x in input().strip().split()]
    b = []
    for i in range(1, n+1):
        b.append(i)

    a, b = zip(*sorted(zip(a, b)))
    print(*b)


if __name__ == "__main__":
    main()


Measured memory_bytes: 25880
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
// int main(){
//     int a,b;
//     cin>>a>>b;
//     if((a*b)%2==0) cout<<"Even"<<endl;
//     else cout<<"Odd"<<endl;
// }
int main(){
    int a,b;
    cin>>a>>b;
    int N;
    int k=0;
    int b1=b;
    while (b1)
    {
        b1/=10;
        k++;
    }
    N=(int)(b+pow(10,k)*a);
    if(abs(sqrt(N)-(int)sqrt(N))<=10e-9||abs(sqrt(N)-floor(sqrt(N)))<=10e-9) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

int main(){
	fast;
	string s;
	cin >> s;
	if(s[s.size() - 1] == 's'){
		s.push_back('e');
		s.push_back('s');
	}
	else s.push_back('s');
	cout << s;
	return 0;
}


Measured memory_bytes: 3648
/*
    NO 
        TIME 
            TO 
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <complex>
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
// define x, y as real(), imag()


template<class T>
istream& operator>> (istream& is, complex<T>& p) {
  T value;
  is >> value;
  p.real(value);
  is >> value;
  p.imag(value);
  return is;
}
#define M_PI 3.14159265358979323846
typedef long long int lli;
lli mod=1e9+9ll;
#define OS //single input use oeis
lli INF=9223372036854775807;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,z,k,x,m,d,y,q,b,c;
const double pi=3.14159265358979323846;
lli me(lli a,lli b)
{
    // cout<<mod<<"\n";
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}

int main()
{
 #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif
 IO;
 OS;
 cin>>x;
 lli p=100;
 lli cc=0;
 for(int j=1;j<=1000000;j++)
 {
    lli in=p/100;
    p+=in;
    cc++;
    if(p>=x)
        break;
 }
 cout<<cc;

}

Measured memory_bytes: 3652
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	string s,t;
	cin >> s >> t;
	
	for(int i=0;i<s.size()-1;i++){
		for(int j=i+1;j<s.size();j++){
			if(s[i]>s[j]){
				char temp=s[i];
				s[i]=s[j];
				s[j]=temp;
			}
		}
	}
	
	for(int i=0;i<t.size()-1;i++){
		for(int j=i+1;j<t.size();j++){
			if(t[i]<t[j]){
				char temp=t[i];
				t[i]=t[j];
				t[j]=temp;
			}
		}
	}
	
	if(s<t)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

using namespace std;

int main() {
    int N;
    cin >> N;
    long long int ans = 0;
    for(int i = 1; i <= N; i++) {
        if(i % 3 == 0) {
            continue;
        }
        if(i % 5 == 0) {
            continue;
        }
        ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K, x, a;
  a = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x > K / 2.0)
      a += (K - x) * 2;
    else
      a += x * 2;
  }
  cout << a << endl;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()
# def xor_wa(N):
#     for i in range(0, N+1):

if A % 2 == 0 and B % 2 != 0:
    dist = B - A
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
if A % 2 == 0 and B % 2 == 0:
    dist = B - 1 - A
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
    ans = ans ^ B
if A % 2 != 0 and B % 2 != 0:
    dist = B - (A + 1)
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
    ans = ans ^ A
if A % 2 != 0 and B % 2 == 0:
    dist = B - 1 - (A + 1)
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
    ans = ans ^ A ^ B


print(ans)





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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

int main(){
    int n,k;
    cin >> n >> k;
    vc d(k);
    rp(i,k){
        cin >> d[i];
    }
    while(1){
        S s=to_string(n);
        bool ok=true;
        rp(i,s.size()){
            bool same=false;
            rp(j,k){
                if(s.at(i)==d.at(j)){
                    same=true;
                }
            }
            if(same){
                ok=false;
                break;
            }
        }
        if(ok){
            cout << n << endl;
            return 0;
        }
        n++;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m, c; cin >> n >> m >> c;
    vector<long long> b(m);
    for (int i = 0; i < m; i++) cin >> b[i];
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        long long tmp = 0;
        for (int j = 0; j < m; j++) {
            long long a; cin >> a;
            tmp += a * b[j];
        }
        if (tmp + c > 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=1e5+5;

int main(){
	string s,t;cin>>s>>t;
	int a,b;cin>>a>>b;
	string u;cin>>u;
	if(u==s)a--;
	else b--;
	cout<<a<<' '<<b;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll Comb(ll n, ll k){
  ll f[105][105];
  rep(i,105) f[0][i] = f[i][0] = 1;
  REP(i,1,105){
    REP(j,1,105){
      f[i][j] = f[i-1][j] + f[i][j-1];
      if(i+j==n && j==k) return f[i][j];
    }
  }
  return 1;
}


int main(){
  int N, A, B;
  cin >> N >> A >> B;
  vector<ll> v(N);
  rep(i,N){
    cin >> v[i];
  }
  sort(ALLOF(v));
  reverse(ALLOF(v));

  ll mx = -1;
  ll mxn = 1;
  
  ll sum = 0;
  rep(i,N){
    sum += v[i];
    if(A<=i+1 && i+1<=B){
      if(mx*(i+1) < sum*mxn){
        mx = sum;
        mxn = i+1;
      }
    }
  }

  printf("%.15lf\n", mx/(double)mxn);

  ll cnt1 = 0, cnt2 = 0;
  rep(i,N){
    if(v[i] == v[mxn-1]){
      cnt1++;
      if(i < mxn){
        cnt2++;
      }
    }
  }

  sum = 0;
  rep(i,A-1){
    sum += v[i];
  }
  
  ll ret = 0;
  REP(i,A,B+1){
    sum += v[i-1];
    if(sum*mxn != mx*i) break;
    ll cnt = 0;
    rep(j,i){
      if(v[i-1] == v[j]) cnt++;
    }
    ret += Comb(cnt1,cnt);
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int x=1;
	while(x*(x+1)/2<=n) x++;
	int s=x*(x+1)/2-n;
	for(int i=1;i<=x;i++){
		if(i==s) continue;
		cout<<i<<endl;
	}
}


Measured memory_bytes: 256
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

record = [False] * 2001
for item in s:
    for i in range(2000 - item, 0, -1):
        if record[i]:
            record[i + item] = True
    record[item] = True

for m in t:
    if record[m]:
        print('yes')
    else:
        print('no')

Measured memory_bytes: 7728
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int main(){
    int n;
    cin >> n;
    REP(i, n){
    	string s1, s2;
    	cin >> s1 >> s2;
    	int len1 = s1.length(), len2 = s2.length();
    	if (len1 > 80 || len2 > 80) {
    		cout << "overflow" << endl;
    	} else {
    		int num1[100] = {0}, num2[100] = {0}, ans[100] = {0};
    		REP(j, len1){
    			num1[j] = s1[len1-1-j] - '0';
    		}
    		REP(j, len2){
    			num2[j] = s2[len2-1-j] - '0';
    		}
    		int ll = len1 > len2 ? len1 : len2;
    		REP(j, ll){
    			ans[j] += num1[j] + num2[j];
    			if (ans[j]/10 > 0) {
    				ans[j+1]++;
    				ans[j] -= 10;
    			}
    		}
    		if (ans[80] > 0){
    			cout << "overflow" << endl;
    		} else {
    			if (ans[ll] > 0) cout << ans[ll];
    			REP(j, ll){
    				cout << ans[ll-1-j];
    			}
    			cout << endl;
    		}
    	}
    }
}


Measured memory_bytes: 2964