akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int,input().split()))

step = 0
while True:
    flag = False
    for i in range(N):
        if A[i] % 2 == 0:
            A[i] = A[i] / 2
        else:
            flag = True
            break
    if flag:
        break
    step += 1
print(step)

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

int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  int d = a-b;

  if(c-d < 0){
    cout << 0 << endl;
  } else {
    cout << c-d << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <stack>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <functional>
//#include <unordered_set>
#define INF 2147483647
#define MAXN  100005
#define PII pair<int, int>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int pre[MAXN], rnk[MAXN];
int F(int x)
{
	if (x != pre[x])
	{
		int p = pre[x];
		pre[x] = F(pre[x]);
		rnk[x] += rnk[p];
	}
	return pre[x];
}

int main()
{
	//ios::sync_with_stdio(false);
	//cin.tie(0);
#ifdef local_debug
	ifstream inputs("input.txt");
	cin.rdbuf(inputs.rdbuf());
	freopen("input.txt", "r", stdin);
#endif
	int n,m;
	int l, r, d;
	while (cin >> n >> m) {
		for (int i = 0; i < MAXN; i++)
		{
			pre[i] = i;
			rnk[i] = 0;
		}
		int f = 0;
		for (int i = 0; i < m; i++)
		{
			cin >> l >> r >> d;
			int lx = F(l);
			int rx = F(r);
			if (lx != rx)
			{
				pre[rx] = lx;
				rnk[rx] = rnk[l] - rnk[r] + d;
			}
			else if (rnk[r]-rnk[l] != d)
			{
				f = 1;
			}
 		}
		string ss[] = { "Yes","No" };
		cout << ss[f] << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) throws Exception {
		MyScanner sc = new MyScanner();
		int n = sc.nextInt();
		int m = sc.nextInt();
		long sum = 0;
		for(int i = 0; i < m; i++)
			sum += sc.nextInt();
		
		if(sum > n)
			System.out.println("-1");
		else
			System.out.println((n - sum));
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

Measured memory_bytes: 33896
import sys
readline = sys.stdin.readline


def main():
    X, Y = map(int, readline().rstrip().split())
    for i in range(X + 1):
        j = X - i
        if 2 * i + 4 * j == Y or 2 * j + 4 * i == Y:
            print('Yes')
            return
    
    print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9184
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var N = ReadInt();
            var B = ReadSplitInt();
            var A = new int[B.Count + 1];

            A[0] = B[0];
            A[A.Length - 1] = B.Last();

            for (int i = 1; i < B.Count; i++)
            {
                A[i] = Min(B[i], B[i - 1]);
            }

            if (B.Count == 1)
            {
                Println(B[0] * 2);
                return;
            }

            Println(A.Sum());
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



Measured memory_bytes: 13396
(defvar N (read))
(defvar P (read))
(defvar e 0)
(defvar o 1)

(dotimes (x N)
  (if (evenp (read))
      (setf e (* 2 e)
            o (* 2 o))
      (setf e (+ e o)
            o e)))

(if (zerop P) (princ o) (princ e))

Measured memory_bytes: 3688
import itertools
N, M, Q = map( int, input().split() )

point_list = []
for i in range( Q ):
  a, b, c, d = map( int, input().split() )
  point_list.append( [ a, b, c, d ] )

all_lists = itertools.combinations_with_replacement(range( 1, M + 1 ), N)

max_point = 0
for t in all_lists:
  point = 0
  for p in point_list:
    a, b, c, d = p
    if t[ b - 1 ] - t[ a - 1 ] == c:
      point += d
  max_point = max( max_point, point )
print( max_point )


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

int main() {
  string s;
  cin >> s;
  int r = 0;
  int max = 0;
  
  rep(i, 3){
    if(s.at(i) == 'R'){
      r++;
      if(max < r){
        max = r;
      }
    }
    else{
      r = 0;
    }
  }
  
  cout << max << endl;

}

Measured memory_bytes: 3620
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long h = long.Parse(Console.ReadLine());
        long ans =0;
        long count = 1;
        while (h > 0)
        {
            h = h/2;
            ans += count ;
            count *= 2;
        }
        Console.WriteLine(ans);
    }  
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;


bool solve(){
	int n;
	cin>> n;
	if(!n) return false;
	
	vector<vector<int> > vvi(n);
	for(int i=0;i<n;i++){
		int n2;
		cin>> n2;
		for(int j=0;j<n2;j++){
			int in;
			cin>> in;
			vvi[i].push_back(in);
		}
	}
	vector<int> out;
	int m;
	cin>> m;
	for(int i=0;i<m;i++){
		int in;
		cin>> in;
		out.push_back(in);
	}
	
	int ans = 0;
	for(int i=0;i<n;i++){
		bool flag = true;
		for(int j=0;j<out.size();j++){
			if(find(vvi[i].begin(), vvi[i].end(), out[j]) == vvi[i].end()) flag = false;
		}
		if(flag){
			if(ans){
				cout<< -1<< endl;
				return true;
			}else{
				ans = i+1;
			}
		}
	}
	if(ans){
		cout<< ans<< endl;
	}else{
		cout<< -1<< endl;
	}
	return true;
	
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	while(solve());

	return 0;
}

 

Measured memory_bytes: 1272
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    long long int n;
    cin >> n;
    string res;
    while (n > 0) {
        n--;
        res.push_back('a' + n % 26);
        n /= 26;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}


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

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

  int X;
  //問題数の取得
  string Y;
  //結果の取得
  
  vector<bool> atcoder(N);
  for (int i=0;i<N;i++) atcoder.at(i) = false;
  //解いた問題を管理
  
  
  vector<int> WA(N);
  //問題ごとのWAを管理
  
  for(int i=0;i<M;i++){
    cin >> X;
    cin >> Y;
    if (atcoder.at(X-1) == false){
      if (Y == "AC"){
        atcoder.at(X-1) = true;
      } else if (Y == "WA"){
        WA.at(X-1)++;
      }
    }
  }
  
  int A=0;
  //正解数をカウント
  int W=0;
  //不正解数をカウント
  
  for(int i=0;i<N;i++){
    if (atcoder.at(i) == true){
      A++;
      W += WA.at(i);
    }
  }
  
  
  
  cout << A << " " << W << endl;
  
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<string> s(3);
    for(int i=0;i<3;i++){
        cin>>s[i];
    }
    string ans = s[0].substr(0,1)+s[1].substr(1,1)+s[2].substr(2,1);
    cout<<ans<<endl;
}

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

#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <iostream>

using namespace std;

int run()
{
    string s;
    cin >> s;
    vector<bool> flag(26, false);
    for(int i = 0; i < s.size(); i ++) flag[s[i]-'a'] = true;
    if(26 != s.size()) {
        string ans = s;
        for(int i = 0; i < 26; i ++) {
            if(!flag[i]) {
                ans += (i + 'a');
                break;
            }
        }
        cout << ans << endl;
        return 0;
    }
    int i = 0;
    for(i = s.size() - 1; i > 0; i --) {
        if(s[i-1] < s[i]) break;
    }
    if(0 == i) cout << -1 << endl;
    else {
        string ans = s.substr(0, i - 1);
        for(int j = s.size() - 1; j >= i; j --) {
            if(s[j] > s[i-1]) {
                ans += s[j];
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

int main(int argc, char * argv[])
{
    run();
    return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
    #ifdef magUNbos
    freopen("in" ,"r" ,stdin);
    freopen("out","w",stdout);
    #endif // magUNbos
    ll x,y;
    cin>>x>>y;
    ll ans = abs(abs(x) - abs(y));
    if( (x >= 0 && y < 0) || ( x < 0 && y > 0) ){
        ans++;
    }
    else if(x > y){
        ans += 2;
    }
    if(x > 0 && y == 0)
        ans--;


    cout<<ans<<endl;
}


Measured memory_bytes: 256
#define		_CRT_SECURE_NO_WARNINGS
#define		_USE_MATH_DEFINES
#include <cstdio>
#include <cmath>

int main()
{
	double	r;
	double	c, a;

	scanf("%lf", &r);

	c = 2 * r * M_PI;
	a = r * r * M_PI;

	printf("%.6f %.6f\n", a, c);

	return 0;
}

Measured memory_bytes: 2716
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b,c;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    char N[1];
    scanf("%s",N);
    if((int)N[0]<96){
        printf("A");
        return 0;
    }else{
        printf("a");
    }
        
}



Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

typedef long long lli;
const int MAX_N = 101;
const int M = 100000007;
const double eps = 1e-9;
int N;
double P[MAX_N], W[MAX_N];
int G[MAX_N];
bool vis[MAX_N];
vector<vector<int> > Grp;
int comb[101][101];

bool equals(double a, double b) {
  return fabs(a-b) < eps;
}

void dfs(int p, vector<int> &v) {
  v.push_back(p);
  vis[p] = true;
  if(vis[G[p]]) return;
  dfs(G[p],v);
}

void makeComb() {
  comb[0][0] = 1;
  for(int i = 1; i <= 100; ++i) {
    comb[i][0] = 1;
    for(int j = 1; j < i; ++j) {
      comb[i][j] = (comb[i-1][j-1] + comb[i-1][j])%M;
    }
    comb[i][i] = 1;
  }
}

void make() {
  fill(vis, vis+N, false);
  Grp.clear();
  for(int i = 0; i < N; ++i) {
    if(vis[i]) continue;
    vector<int> v;
    dfs(i, v);
    Grp.push_back(v);
  }
}

pair<double, int> calc(int g) {
  vector<int> &v = Grp[g];
  double minCost = -1;
  int cnt = 0;
  for(int i = 0; i < v.size(); ++i) {
    double cost = 1.0/P[v[i]];
    int p = G[v[i]];
    while(p != v[i]) {
      cost += 1.0/W[p];
      p = G[p];
    }
    if(equals(minCost, cost)) {
      ++cnt;
    } else if(minCost == -1 || cost < minCost) {
      cnt = 1;
      minCost = cost;
    }
  }
  return make_pair(minCost, cnt);
}

void solve() {
  make();
  int c = 1;
  int u = N;
  for(int i = 0; i < Grp.size(); ++i) {
    c = (lli)c*comb[u][Grp[i].size()]%M;
    u -= Grp[i].size();
  }
  double time = 0;
  for(int i = 0; i < Grp.size(); ++i) {
    pair<double, int> p = calc(i);
    time += p.first;
    c = (lli)c*p.second%M;
  }
  printf("%.12f %d\n", time, c);
}

int main() {
  makeComb();
  while(cin >> N && N) {
    for(int i = 0; i < N; ++i) {
      int p;
      cin >> P[i] >> p >> W[i];
      G[p] = i;
    }
    solve();
  }
  return 0;
}

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

const int maxn = 200005;

int n, k, c, d, pos;
int l[maxn], r[maxn];
char s[maxn];

signed main () {
	scanf("%d %d %d", &n, &k, &c);
	scanf("%s", &s);
	d = 1, pos = 0;
	while (d <= k && pos < n) {
		while (s[pos] == 'x' && pos < n) 
			++pos;
		l[d] = pos;
		pos += c + 1, ++d;
	}
	d = k, pos = n - 1;
	while (d && pos >= 0) {
		while (s[pos] == 'x' && pos >= 0)
			--pos;
		r[d] = pos;
		pos -= c + 1, --d;
	}
	for (int i = 1; i <= k; ++i) {
		if (l[i] == r[i])
			printf("%d\n", l[i] + 1);
	}
}


Measured memory_bytes: 5512
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define ll long long

#ifndef ONLINE_JUDGE
#define debug(format, ...) fprintf(stderr, \
    "%s:%d: " format "\n", __func__, __LINE__,##__VA_ARGS__)
#else
#define debug(format, ...)
#define NDEBUG
#endif

char s[200005];

int f[200005][5];

bool diff(int x, int y, int l)
{
    while (l) {
        if (s[x] != s[y]) return true;
        x--; y--; l--;
    }
    return false;
}

int main()
{
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= min(2, i); j++) {
            f[i][j] = -1000000000;
            for (int k = 1; k <= max(min(2, i-j), 1); k++) {
                if (i-j == 0 || j != k || diff(i, i-j, k)) {
                    f[i][j] = max(f[i][j], f[i-j][k] + 1);
                }
            }
            //debug("f[%d][%d] = %d\n", i, j, f[i][j]);
        }
    }
    printf("%d", max(f[n][1], f[n][2]));
    return 0;
}


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

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

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

ll n,w,dp[100006][103];
ll wt[103],v[103];

ll solve(ll n, ll w)
{
	if(dp[w][n] != -1)
		return dp[w][n];

	if(n < 1 || w < 1)
		return 0;

	if(w < wt[n])
		dp[w][n] =  solve(n-1,w);
	else
		dp[w][n] = max(v[n] + solve(n-1,w - wt[n]) , solve(n-1,w));

	return dp[w][n];
}


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

	ll i,j;
	cin >> n >> w;
	memset(dp,-1,sizeof(dp));

	for(i=1;i<n+1;i++)
		cin >> wt[i] >> v[i];

	cout << solve(n,w) << endl;
}

Measured memory_bytes: 80768
using System;
class Program{
  static void Main(string[] args){
    string[] tmp = Console.ReadLine().Split(' ');
    int h = int.Parse(tmp[0]);
    int w = int.Parse(tmp[1]);
    tmp = Console.ReadLine().Split(' ');
    h -= int.Parse(tmp[0]);
    w -= int.Parse(tmp[1]);
    Console.WriteLine(h*w);
  }
}

Measured memory_bytes: 11092
using System;
using System.Collections;
public class Kuku{
    public static void Main(){
        string[] d = Console.ReadLine().Split(' ');
        int d0 = int.Parse(d[0]);
        int d1 = int.Parse(d[1]);
        int ans = -1;
        if(d0<10 && d1<10){
            ans = d0*d1;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int x;
	cin >> x;

	int a = x / 500;
	x -= 500 * a;
	int b = x/5;
	cout << a*1000 + b*5 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
    int a,b;
    cin >> a >> b;
    if (a >= 13) {
        cout << b << "\n";
    } else if (a >= 6 && a <= 12) {
        cout << b/2 << "\n";
    } else {
        cout << 0 << "\n";
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
 public static void main(String[] args){
  Scanner stdIn = new Scanner(System.in);
   final double pi = 3.141;
   int R = stdIn.nextInt();
   double Enshu = 2 * pi * R;
   
   System.out.println(Enshu);
 }
}

Measured memory_bytes: 35824
#include <iostream>

using namespace std;

int main() {
    int H = 1;
    int W = 1;

    cin >> H;
    cin >> W;

    while (H != 0 || W != 0) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << '#';
            }
            cout << '\n';
        }
        cout << '\n';
        cin >> H;
        cin >> W;
    }
    return 0;
}



Measured memory_bytes: 3068
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <complex>
using namespace std;

int main()
{
    long n,k;
    
    cin  >> n;
    cin >> k;
    vector<long> x(n);

    long count = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> x[i];
        count += 2 * min(abs(k -x[i] ), abs(x[i] ));
    }





    cout << count;
    
    return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e10;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 100;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y;
    ll c = 1;
    cin >> x >> y;
    ll b = 2;
    while(b*x <= y){
        c++;
        b *= 2;
    }
    PRINT(c);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int MAXN = 1e5 + 5, MAXM = 3e5 + 5, BOUND = 1e7, MOD = 1073741824, INF = 0x3f3f3f3f, base = 10000;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-9;
#define mid l + ((r-l)>>1)
#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define lc(x) ch[x][0]
#define pii pair<int,int>
#define vi vector<int>
#define RR register int
#define rc(x) ch[x][1]
#define rep(i,a,b) for(RR i=(a);i<=(b);++i)
#define random(a,b) ((a)+rand()%((b)-(a)+1))

int n;
int a[MAXN];
ll sum;
int gcd(int a, int b) {
	return !b ? a : gcd(b, a%b);
}
int qpow(int a, int b) {
	int ans = 1;
	for (; b; b >>= 1, a *= a)if (b & 1)ans *= a;
	return ans;
}
ll f[MAXN][2];
int main() {
	cin >> n;
	rep(i, 1, n)cin >> a[i];
	memset(f, 0xcf, sizeof(f));
	f[0][0] = 0;
	rep(i, 1, n) {
		f[i][0] = max(f[i - 1][0] + a[i], f[i - 1][1] - a[i]);
		f[i][1] = max(f[i - 1][0] - a[i], f[i - 1][1] + a[i]);
	}
	cout << f[n][0] << '\n';
	return 0;
}

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

#define INF 0x3f3f3f3f3f3f3f3fLL

int n, k;

vector<long long>v;

long long memo[101010];

long long solve(int pos){
	
	if(pos == 1) return 0;
	if(memo[pos] != -1) return memo[pos];
	
	long long here = INF;
	
	for(int i = pos - 1; i >= max(1 , pos - k) ; i --)
		here = min(here, solve(i) + abs(v[pos] - v[i]));
	
	return memo[pos] = here;
}


int main(){
	
	memset(memo,-1,sizeof memo);
	
	cin>>n>>k;
	
	v.resize(n + 1);
	v[0] = 0;
	
	for(int i = 1 ; i <= n ; i ++)
		cin>>v[i];
	
	cout<<solve(n)<<"\n";
	
	return 0;
}

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

using namespace std;
int main(){
    int X, N, a;
    cin >> X >> N;
    vector<int> nums(101);

    for(int i=0; i<N; i++){
        cin >> a;
        nums[a] = true;
    }
    int minDiff = 110;
    int res = 110;
    for(int i=0; i<=101; i++){
        if(!nums[i]){
            if( abs(i - X) <= minDiff ){
                if (abs(i-X) == minDiff){
                    res = min(res, i);
                }else{
                    res = i;
                }
                minDiff = abs(i - X);
            }
        }
    }

    cout << res << endl;

}

Measured memory_bytes: 3612
from random import randrange, random
from bisect import bisect
from math import exp
from time import perf_counter as timer
def simulated_annealing(C, S, duration=1.8):
    
    D = len(S)
    K = len(C)

    helper = lambda i,j: (j-i-1)*(j-i)//2
    
    class State:
        def __init__(self,d2c,c2d):
            self.c2d = c2d
            self.d2c = d2c
            self.score = self._score()

        @classmethod
        def random(cls):
            d2c = [randrange(K) for _ in range(D)]
            c2d = [[-1] for _ in range(K)]
            for d,c in enumerate(d2c):
                c2d[c].append(d)
            for c in range(K):
                c2d[c].append(D)
            return State(d2c,c2d)

        def _score(self):
            s = 0
            for d,c in enumerate(self.d2c):
                s += S[d][c]

            for c,ds in enumerate(self.c2d):
                k = C[c]
                for a,b in zip(ds,ds[1:]):
                    s -= k*helper(a,b)
            return s

        def random_move(self):
            d = randrange(D)
            c = self.d2c[d]
            nc = randrange(K-1)
            if nc >= c:
                nc += 1

            delta = S[d][nc] - S[d][c]

            cd = self.c2d[c]
            i = bisect(cd,d)-1
            delta += C[c]*(helper(d,cd[i+1]) + helper(cd[i-1],d))
            delta -= C[c]*helper(cd[i-1],cd[i+1])

            cd = self.c2d[nc]
            i = bisect(cd,d)
            delta += C[nc]*helper(cd[i-1],cd[i])
            delta -= C[nc]*(helper(d,cd[i]) + helper(cd[i-1],d))

            return (d,nc),delta

        def make_move(self, move, delta):
            '''
            move = (d,nc)
            '''
            d,nc = move
            c = self.d2c[d]
            self.d2c[d] = nc

            i = bisect(self.c2d[c], d)-1
            self.c2d[c].pop(i)

            i = bisect(self.c2d[nc],d)
            self.c2d[nc].insert(i, d)
            self.score += delta

    ALPHA = 10

    state = State.random()

    START = timer()
    deadline = START + duration
    now = START
    while now < deadline:
        temp = ALPHA*(deadline-now)/duration
        
        move, delta = state.random_move()
        if delta >= 0 or exp(delta/temp) > random():
            state.make_move(move, delta)
        now = timer()
    return (v+1 for v in state.d2c)

if __name__ == '__main__':
    D = int(input())
    C = tuple(map(int,input().split()))
    S = tuple(tuple(map(int,input().split())) for _ in range(D))
    print(*simulated_annealing(C,S), sep='\n')

Measured memory_bytes: 98444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int Binary_Search(ll first,ll last,vector<ll>v,ll search_value)
{
    int pos=-1;
    while(first<=last)
    {
        ll mid=first+((last-first)/2);
        if(v[mid]==search_value)
        {
            pos=mid;
            break;
        }
        else if(search_value>v[mid])
        {
            first=mid+1;
        }
        else
        {
            last=mid-1;
        }
    }
    return pos;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    {
        return a;
    }
    else
    {
        return gcd(b,a%b);
    }
}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}

int main()
{
    ll arr[10005]={0};
    ll n;
    cin>>n;
    for(int i=1;i<=105;i++)
    {
        for(int j=1;j<=105;j++)
        {
            for(int k=1;k<=105;k++)
            {
                ll ans=(i*i)+(j*j)+(k*k)+(i*j)+(i*k)+(j*k);
                if(ans<10005)
                {
                    arr[ans]+=1;
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        cout<<arr[i]<<endl;
    }
    return 0;
}



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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    create_mod_tables(300000);
    int64_t ans = power_mod(2, N) - 1;
    for(int c : {A, B}){
        int64_t res = fact_inv[c];
        for(int i=0; i<c; i++) mul(res, N-i);
        add(ans, MOD-res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7296
package main

import (
	"fmt"
)

func main() {
	var w, h, x, y float64
	fmt.Scan(&w, &h, &x, &y)

	if x == w/2 && y == h/2 {
		fmt.Println(w*h/2, 1)
	} else {
		fmt.Println(w*h/2, 0)
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

bool prime( int n )
{
	if ( n < 2 )
	{
		return false;
	}

	for ( int i = 2; i <= sqrt( n ); i++ )
	{
		if ( !( n % i ) )
		{
			return false;
		}
	}

	return true;
}

int main()
{
	int n;

	while (	cin >> n )
	{
		for ( int i = n - 1; 0 <= n; i-- )
		{
			if ( prime( i ) )
			{
				cout << i << ' ';
				break;
			}
		}

		for ( int i = n + 1; ; i++ )
		{
			if ( prime( i ) )
			{
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int,input().split()))

s = []
ap = a[0]
count = 0
for i in range(n):
    if ap == a[i]:
        count += 1
    else:
        if count > 1:
            s.append(count)
        ap = a[i]
        count = 1
if count > 1:
    s.append(count)

ans = 0
for x in s:
    ans += x//2
print(ans)

Measured memory_bytes: 3188
#include <iostream>

using namespace std;


int main(){

	int n, A, B, C;
	bool ans;

	cin >> n;

	while (n--){
		ans = true;
		B = 0;
		C = 0;

		for (int i = 0; i < 10; i++){
			cin >> A;

			if (A > B){
				B = A;
			}
			else if(A > C){
				C = A;
			}
			else{
				ans = false;
			}
		}

		cout << (ans ? "YES" : "NO") << endl;

	}


	return 0;
}

Measured memory_bytes: 1152
N, M = [int(n) for n in input().split()]

H = [int(n) for n in input().split()]

A = []
B = []

p = {}
for m in range(M):
    a, b = [int(n) for n in input().split()]
    A.append(a)
    B.append(b)

    if H[a-1] >= H[b-1]:
        if b in p:
            p[b].append(a)
        else:
            p[b] = [a]
    if H[a-1] <= H[b-1]:
        if a in p:
            p[a].append(b)
        else:
            p[a] = [b]

s = 0
for i in range(N):
    if i + 1 not in p:
        s += 1

print(s)


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

int main() {
    string S;

    cin >> S;

    int ans = 700;

    if (S[0] == 'o'){
        ans += 100;
    }
    if (S[1] == 'o'){
        ans += 100;
    }
    if (S[2] == 'o'){
        ans += 100;
    }

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

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

adj = [0]*n # adjacent list

for i in range(n):
    tmp = list(map( int, input().split() ) )
    adj[tmp[0]-1] = list(map(lambda x : x - 1, tmp[2:]))

c = ['w']*n # color of each vertex
d = [0]*n # discovery time for each vertex
f = [0]*n  # finish time for each vertex
time = 0

def DFS_visit(u):
    global time
    time += 1
    d[u] = time
    c[u] = 'g'
    for v in adj[u]:
        if c[v] == 'w':
            DFS_visit(v)
    c[u] = 'b'
    time += 1
    f[u] = time
    
for u in range(n):
    if c[u] == 'w':
        DFS_visit(u)
        
        
for u in range(n):
    print(f"{u+1} {d[u]} {f[u]}")


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

int main() {
  int a = 0;
  string s;
  cin >> a >> s;
  if(a >= 3200){
    cout << s;
  }
  else{
    cout << "red";
  }
}

Measured memory_bytes: 3616
N, K = map(int, input().split())

answer_list = [0]*N

for _ in range(K):
  d = int(input())
  A = list(map(int, input().split()))
  
  for i in range(len(A)):
    answer_list[(A[i]-1)] += 1
    
print(answer_list.count(0))

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

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

  int tmp = max(a, max(b, c));
  while (k>0) tmp*=2, k--;

  cout<<tmp+a+b+c-max(a, max(b, c))<<endl;
}


Measured memory_bytes: 256
// author <Maksud alam Rony>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define it iterator
#define pb push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define fill(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
#define pi acos(-1)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) (v).erase(unique(all(v)),(v).end())
#define endl "\n"
string digit="0123456789";
string small="abcdefghijklmnopqrstuvwxyz";
string capital="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};

int main(){
   int n;
   cin>>n;
   map<ll, ll>mp;
   int arr[n];
   ll sum =0;
   for(int i=0; i<n; i++){
       cin>>arr[i];
       mp[arr[i]]++;
       sum += arr[i];
   }
   int q;
   cin>>q;
   while(q--){
     int a,b;
     cin>>a>>b;
     sum -=mp[a]*a;
     sum +=mp[a]*b;
     cout<<sum<<endl;
     mp[b]+=mp[a];
     mp[a]=0;
   }

}



Measured memory_bytes: 9964
#include<iostream>
int main(){
int a[10000],l=0,t,c=3;
while(std::cin>>a[l++]);
for(int i=0;i<l-1;i++){
for(int j=i+1;j<l;j++){
if(a[i]<a[j]){
t=a[i];a[i]=a[j];a[j]=t;
}
}
}
while(c--)std::cout<<a[2-c]<<std::endl;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define line cout<<endl;
#define space cout<<" ";
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int ll;

using namespace std;

const int N = 1e9+7;





int main()
{
    char a;
    cin>>a;

    if(a>=65&&a<=90)
    {
        cout<<"A";
    }
    else
        cout<<"a";
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define getchar getchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int getint() {
	char C;
	while (!isdigit(C = getchar()));
	int x = C - '0';
	while (isdigit(C = getchar())) x = x * 10 + C - '0';
	return x;
}

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


	int N, Q;
	N = getint();
	Q = getint();
	char S[1000000];
	fread(S, 1, N + 4 * Q, stdin);
	int L = 0;
	int R = N;
	char *t = S + N + 4 * Q - 3;
	char *d = S + N + 4 * Q - 1;

	for (int i = Q - 1; i >= 0; i--) {
		if (*d == 'R') {
			if (R > 0 && *(S + R - 1) == *t) R--;
			if (L > 0 && *(S + L - 1) == *t) L--;
		}
		else {
			if (R < N && *(S + R) == *t) R++;
			if (L < N && *(S + L) == *t) L++;
		}
		t -= 4;
		d -= 4;
	}

	co(R - L);

	Would you please return 0;
}

Measured memory_bytes: 1280
import java.util.*

var _map = mutableMapOf<Int, MutableMap<Int, Int>>()

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    var total = 0
    val K = sc.nextInt()
    for(i in 1..K) {
        val _i = gck(i)
        for(j in 1..K) {
            val _j = gck(j)
            val ij = _i.filterKeys { key -> _j.containsKey(key) }
            for (k in 1..K) {
                val _k = gck(k)
                val ijk = ij.filterKeys { key -> _k.containsKey(key) }
                total += ijk.keys.max()!!
            }
        }
    }
    println(total)
}

fun gck(K:Int): MutableMap<Int, Int> {
    if (_map.containsKey(K)) {
        return _map.get(K)!!
    }
    var map = mutableMapOf<Int, Int>()
    for(i in 1..K) {
        if (K % i == 0) {
            map.put(i, K/i)
        }
    }
    _map.put(K, map)
    return map
}


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

int main() {
  int A,B,C; cin >> A >> B >> C;
  if (A <= C && B >= C) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 100005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n,ar[N][3],dp[N][3];
ll findans(ll i,ll flg){
	if(i==n+1){
		return 0;
	}
	if(dp[i][flg]!=-1){
		return dp[i][flg];
	}

	ll j,an=0;
	for(j=0;j<3;j++){
		if(j!=flg){
			an=max(an,findans(i+1,j)+ar[i][j]);
		}
	}
	return dp[i][flg]=an;
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll i,j,k,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i][0]>>ar[i][1]>>ar[i][2];
	}
	memset(dp,-1,sizeof(dp));
	ll an=findans(1,-1);
	cout<<an;
	return 0;
}

Measured memory_bytes: 9984
import java.util.*;
public class Main {

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    boolean allZero = true;
    Map<Integer, Integer> map = new HashMap<>();
    for (int i = 0; i < N; i++) {
      int a = sc.nextInt();
      map.put(a, map.getOrDefault(a, 0)+1);
      if (a != 0) {
        allZero = false;
      }
    }
    if (allZero) {
      System.out.println("Yes");
      return;
    }
    
    if (N%3 != 0 || (map.size() != 2 && map.size() != 3)) {
      System.out.println("No");
      return;
    }
    if (map.size() == 2) {
      System.out.println(map.getOrDefault(0, -1) == N/3 ? "Yes" : "No");
    } else {
      Set<Integer> count = new HashSet<>();
      for (int c : map.values()) {
        count.add(c);
      }
      if (count.size() != 1) {
        System.out.println("No");
        return;
      }
      Iterator<Integer> itr = map.keySet().iterator();
      int x = itr.next();
      int y = itr.next();
      int z = itr.next();
      
      System.out.println((x^y) == z ? "Yes" : "No");
    }
  }
}

Measured memory_bytes: 58480
N = int(input())
A = list(map(int, input().split()))

tmp = []

for idx, e in enumerate(A):
    tmp.append(e - (idx + 1))

tmp.sort()

b = tmp[len(tmp) // 2]

res = 0
for idx, e in enumerate(A):
    res += abs(e - (idx + 1) - b)

print(res)


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

#ifdef LOCAL
 #include <bits/debugger.hpp>
 // #define __int64 __int64_t
#else 
 #define debug(a...) //
#endif

#define __int64 long long int

int main()
{
 ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
 int n;
 cin >> n;
 vector<__int64> a(n + 1);
 for(int i = 1; i <= n; i++) cin >> a[i];
 __int64 all_xor = 0;
 for(int i = 1; i <= n; i += 2) all_xor ^= (a[i] ^ a[i + 1]);
 for(int i = 1; i <= n; i++) cout << (all_xor ^ a[i]) << ' ';
 cout << '\n';
 return 0;
}


Measured memory_bytes: 4716
n = int(input())
a = [ int(i)-1 for i in input().split() ]
b = [ int(i) for i in input().split() ]
c = [ int(i) for i in input().split() ]
ans = 0
for i in range(n):
    ans += b[a[i]]
    if i != n-1 and a[i+1] == a[i] + 1:
        ans += c[a[i]]
print(ans)


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

using namespace std;

int main(){
    string s, s1, s0;
    int cont0 = 0, cont1 = 0;

    cin >> s;

    for(int i = 0; i < s.length(); i++){
        if(i == 0){
            s1 = '1';
            s0 = '0';
        }else{
            if(s1[i-1] == '1') s1 = s1 + '0';
            else s1 = s1 + '1';

            if(s0[i-1] == '1') s0 = s0 + '0';
            else s0 = s0 + '1';
        }
    }

    for(int i = 0; i < s.length(); i++){
        if(s[i] != s1[i])   cont1++;
        
        if(s[i] != s0[i])   cont0++;
    }

    cout << min(cont1, cont0) << endl ;

    return 0;

}

Measured memory_bytes: 1016
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] numArr = sc.next().toCharArray();
        int length = numArr.length;
        int[] arr = new int[length];
        for (int i = 0; i < length; i++) {
            arr[i] = numArr[i] - '0';
        }
        long[][][][][][] dp = new long[length + 1][10][10][10][10][2];
        dp[0][0][0][0][0][1] = 1;
        long[][] counts = new long[length + 1][2];
        for (int i = 1; i <= length; i++) {
            for (int a = 0; a < 10; a++) {
                for (int b = 0; b < 10; b++) {
                    for (int c = 0; c < 10; c++) {
                        for (int d = 0; d < 10; d++) {
                            for (int e = 0; e < 10; e++) {
                                dp[i][b][c][d][e][0] += dp[i - 1][a][b][c][d][0];
                                if (e < arr[i - 1]) {
                                    dp[i][b][c][d][e][0] += dp[i - 1][a][b][c][d][1];
                                } else if (e == arr[i - 1]) {
                                    dp[i][b][c][d][e][1] += dp[i - 1][a][b][c][d][1];
                                }
                            }
                        }
                    }
                }
            }
            for (int e = 0; e < 10; e++) {
                counts[i][0] += counts[i - 1][0];
                if (e < arr[i - 1]) {
                    counts[i][0] += counts[i - 1][1];
                } else if (e == arr[i- 1]) {
                    counts[i][1] += counts[i - 1][1];
                }
            }
            for (int j = 0; j < 10; j++) {
                counts[i][0] += dp[i][5][1][j][3][0];
                counts[i][1] += dp[i][5][1][j][3][1];
                dp[i][5][1][j][3][0] = 0;
                dp[i][5][1][j][3][1] = 0;
            }
        }
        System.out.println(counts[length][0] + counts[length][1]);
    }
}



Measured memory_bytes: 35464
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>

#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{

    int n, m, q, a[100], b[100], c[100], d[100];
    vector<int> res;
    int line[] = {0,1,1,1,1,1,1,1,1,1,1};
    int r = 0;
 
    
    cin >> n >> m >> q;
    
    for(int i = 0; i < q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    
        for(int x1 = 1; x1 <= m; x1++)
        {
            for(int x2 = x1; x2 <= m; x2++)
            {
                for(int x3 = x2; x3 <= m; x3++)
                {
                    for(int x4 = x3; x4 <= m; x4++)
                    {
                        for(int x5 = x4; x5 <= m; x5++)
                        {
                            for(int x6 = x5; x6 <= m; x6++)
                            {
                                for(int x7 = x6; x7 <= m; x7++)
                                {
                                    for(int x8 = x7; x8 <= m; x8++)
                                    {
                                        for(int x9 = x8; x9 <= m; x9++)
                                        {
                                            for(int x10 = x9; x10 <= m; x10++)
                                            {
                                                line[1] = x1;
                                                line[2] = x2;
                                                line[3] = x3;
                                                line[4] = x4;
                                                line[5] = x5;
                                                line[6] = x6;
                                                line[7] = x7;
                                                line[8] = x8;
                                                line[9] = x9;
                                                line[10] = x10;
                                                
                                                res.push_back(0);
                                                
                                                for(int i = 0; i < q; i++)
                                                {
                                                    if(line[b[i]] - line[a[i]] == c[i])
                                                    {
                                                        res[r] += d[i];
                                                    }
                                                }
                                                r++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    
    sort(res.begin(), res.end(), greater<int>());
    
    cout << res[0];
    
}

Measured memory_bytes: 3860