akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.math.BigInteger;

public class Main implements Runnable {
	
	//static int mod = 1000000007;
	
    public static void main(String[] args) {
    	new Thread(null, new Main(), "", 1024 * 1024 * 1024).start();
    }
    
    public void run() {
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        
        int n = sc.nextInt();
        int d = sc.nextInt();
        
        int k = 2*d + 1;
        
        int ans = n/k;
        
        if(n%k != 0){
        	ans += 1;
        }
        
        out.println(ans);
        
        out.flush();
    }

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}
	public int[] nextintArray(int n){
		int[] a = new int[n];
		for(int i=0;i<n;i++){
			a[i] = nextInt();
		}
		return a;
	}
	public long[] nextlongArray(int n){
		long[] a = new long[n];
		for(int i=0;i<n;i++){
			a[i] = nextLong();
		}
		return a;
	}
	public Integer[] nextIntegerArray(int n){
		Integer[] a = new Integer[n];
		for(int i=0;i<n;i++){
			a[i] = nextInt();
		}
		return a;
	}
	public int[][] nextintMatrix(int h, int w){
		int[][] mat = new int[h][w];
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				mat[i][j] = nextInt();
			}
		}
		return mat;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 24532
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const int INFI = 1000000000;
 const ll INFL = (1LL << 60);

 int main() {
   int x1, x2, x3, x4, x5; cin >> x1 >> x2 >> x3 >> x4 >> x5;
   if (x1 == 0) cout << 1 << endl;
   else if (x2 == 0) cout << 2 << endl;
   else if (x3 == 0) cout << 3 << endl;
   else if (x4 == 0) cout << 4 << endl;
   else cout << 5 << endl;
 }


Measured memory_bytes: 3624
N, M = gets.split.map(&:to_i)
As, Cs = [], []
M.times do
  a, b = gets.split.map(&:to_i)
  As << a
  Cs << gets.split.map(&:to_i)
end
INF = 10**10

ds = Cs.map{|cs| cs.inject(0){|s, n| s | (1 << (n - 1))}}
dp = Array.new(M + 1){Array.new(1 << N, INF)}
dp[0][0] = 0
M.times do |i|
  (1 << N).times do |j|
    dp[i + 1][j] = dp[i][j] if dp[i + 1][j] > dp[i][j]
    dp[i + 1][j | ds[i]] = dp[i][j] + As[i] if dp[i + 1][j | ds[i]] > dp[i][j] + As[i]
  end
end
ans = dp[M][(1 << N) - 1]
puts ans == INF ? -1 : ans

Measured memory_bytes: 34428
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

// rep(i, 100) { cout << i << endl; } => 0 1 2 ... 99
#define rep(i, n) for(int i = 0, i##_len = (n); i < (int)n; i++)

// std::sort(all(v));
#define all(x) (x).begin(), (x).end()

// long long int
using ll = long long;

// utility to cast return value of size function to int
#define SZ(x) ((int)(x).size())

// VS defines "_DEBUG" macro when debug configuration.
#if _DEBUG
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define dump(x)
#define debug(x)
#endif

// update max
template<class T>bool chmax(T & prov, const T & cur)
{
	if (cur > prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

// update min
template<class T>bool chmin(T & prov, const T & cur)
{
	if (cur < prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

int main()
{
	string S;
	cin >> S;
	int ans = 0;
	bool last_double = false;
	for(int i = 0, i_len = S.length(); i < i_len; i++)
	{
		ans++;
		if (i == i_len - 1)
		{
			continue;
		}
		else if(!last_double && S[i] == S[i + 1])
		{
			i++;
			last_double = true;
		}
		else
		{
			last_double = false;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int inf=1<<29;
const ll Maxn=1e6;
const double pi=3.1415926536;

int a[Maxn];

int JDZ(int x,int y){
	int sid;
	if(x>=y) sid=x-y;
	else sid=y-x;
	return sid;
}

int main(){
	int n;
	int sum=0;
	cin>>n;
	a[0]=0;
	a[n+1]=0;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n+1;i++){
		sum+=JDZ(a[i],a[i-1]);
	}
	int mid;
	for(int i=1;i<=n;i++){
		mid=sum-JDZ(a[i],a[i-1])-JDZ(a[i],a[i+1])+JDZ(a[i-1],a[i+1]);
		printf("%d\n",mid);
	}
	return 0;
}

Measured memory_bytes: 1664
import java.util.ArrayDeque;
import java.util.Iterator;
import java.util.Scanner;

public class Main {
	 public static void main(String[] args) {
		 ArrayDeque<Integer> list  = new ArrayDeque<>();
		 Scanner sc = new Scanner(System.in);
		 int n = sc.nextInt(); 
		 for(int i = 0; i < n; i++) {
			 int command = sc.nextInt();
			 switch(command) {
			 	case 0:
			 		if(sc.nextInt() == 0){
			 			list.addFirst(sc.nextInt());
			 		}else {
			 			list.addLast(sc.nextInt());
			 		}
			 		break;
			 		
			 	case 1:
					Iterator<Integer> ite = list.iterator();
					int p = sc.nextInt();
					for(int j = 0; j < p; j++) {
						ite.next();
					}
					System.out.println(ite.next());
					break;
					
			 	case 2:
			 		if(sc.nextInt() == 0){
			 			list.removeFirst();
			 		}else  
			 			list.removeLast();
			 		break;	
			 
			 }
		 }
	 }
}



Measured memory_bytes: 299460
//File Name: C.cpp
  //Author: long
  //Mail: 736726758@qq.com
  //Created Time: 2016年10月24日 星期一 20时05分28秒
                                   
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#define LL long long
using namespace std;
const int MAXN = 100000 + 10;
const int MOD = (int)1e9 + 7;
int a[MAXN],t[MAXN],h[MAXN];
LL solve(int n){
	memset(h,-1,sizeof(h));
	for(int i=1;i<=n;i++)
		if(t[i] > t[i-1]) h[i] = t[i];
	for(int i=n;i>0;i--){
		if(a[i] > a[i+1]){
			if(h[i] == -1) h[i] = a[i];
			else if(h[i] != a[i]) return 0;
			h[i] = a[i];
		}
	}
	for(int i=1;i<=n;i++)
		if(h[i] > t[i] || h[i] > a[i]) return 0;
	LL res = 1;
	for(int i=1;i<=n;i++){
		if(h[i] == -1){
			res = res * min(a[i],t[i]) % MOD;
		}
	}
	return res;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",t + i);
	for(int i=1;i<=n;i++) scanf("%d",a + i);
	printf("%d\n",(int)solve(n));
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 160;
int mo, n, k;
int f[N * 2][N][N], o;
#define add(x, y) ((x) = ((x) + (y)) % mo)
ll solve2() {
	f[0][0][0] = 1;
	for(int i = 1; i <= n; i++) {
		for(int x = 0; x < i; x++) {
			for(int y = 0; y < i; y++) if(f[i-1][x][y]) {
				for(int o = 0; o < 2; o++) {
					int _x = x, _y = y;
					if (i & 1) {
						_x = o ? x + 1 : 0;
						if (_x * 2 > k) continue;
					} else {
						_y = o ? y + 1 : 0;
						if (_y * 2 > k) continue;
					}
					add(f[i][_x][_y], f[i - 1][x][y]);
				}
			}
		}
	}
	ll ans = 0;
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= n; j++) add(ans, f[n][i][j]);
	}
	return ans;
}

ll solve1() {
	f[o][0][0] = 1;
	int h = (k - 1) / 2, mid = n / 2 - h, t = (n + 1) / 2 - mid;
	for(int i = 1; i <= h; i++) { //only even
		memset(f[1 - o], 0, sizeof f[1 - o]);
		for(int j = 0; j < i; j++) if (f[o][0][j])
			for(int oo = 0; oo < 2; oo++) {
				add(f[1 - o][0][oo ? j + 1 : 0], f[o][0][j]);
			}
		o = 1 - o;	
	}
	for(int i = 1; i <= mid + t; i++) { //both
		memset(f[1 - o], 0, sizeof f[1 - o]);
		for(int j = 0; j <= k + 1; j++) {
			for(int w = 0; w * 2 <= n; w++) if (f[o][j][w]) {
				for(int o1 = 0; o1 < 2; o1++) {
					for(int o2 = 0; o2 < (i > mid ? 1 : 2); o2++) {
						int _w = o2 ? w + 1 : 0;
						int _j = 0;
						if (o1 == 0) _j = 0;
						else {
							if (j) _j = j + 1;
							if (o2) _j = max(_j, _w + 1);
						}
						if (_j <= k + 1) {
							add(f[1 - o][_j][_w], f[o][j][w]);
						}
					}
				}
			}
		}
		o = 1 - o;
	}
	ll ans = 0;
	for(int i = 0; i <= k + 1; i++) {
		for(int j = 0; j <= n; j++) {
			add(ans, f[o][i][j]);
		}
	}
	return ans;
}

int main() {
	cin >> n >> k >> mo;
	if (k & 1) {
		cout << solve1() << endl;
	} else {
		cout << solve2() << endl;
	}
}

Measured memory_bytes: 14720
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] argst)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String str = br.readLine();
        
        while(str != null){
            String[] line = str.split("\\s");
            int H = Integer.parseInt(line[0]);
            int W = Integer.parseInt(line[1]);
            //System.out.println(H);
            //System.out.println(W);

            if(H !=0 && W != 0){
            String yoko = Wwrite(W);
            Hwrite(H,yoko);
            System.out.println("");
            str = br.readLine();
            }else{
                break;
            }
        }
    }

    public static String Wwrite(int W){
        StringBuilder buff = new StringBuilder();
        for(int i=0;i<W;i++){
            buff.append("#");
        }
        return buff.toString();
    }

    public static void Hwrite(int H,String yoko){
        for(int i=0;i<H;i++){
            System.out.println(yoko);
        }
    }
}

Measured memory_bytes: 25672
// URL: https://atcoder.jp/contests/abc134/tasks/abc134_b

import std.algorithm, std.container, std.math, std.range, std.typecons, std.string;

version(unittest) {} else
void main()
{
  int n, d; io.getV(n, d);
  io.put((n+d*2)/(d*2+1));
}

auto io = IO();

struct IO
{
  import std.algorithm, std.conv, std.format, std.meta, std.range, std.stdio, std.traits;

  dchar[] buf;
  auto sp = (new dchar[](0)).splitter;
  int precision = 10;
  string delimiter = " ";

  void nextLine()
  {
    stdin.readln(buf);
    sp = buf.splitter;
  }

  auto get(T)(ref T v)
  {
    if (sp.empty) nextLine();
    v = sp.front.to!T;
    sp.popFront();
  }

  auto getV(T...)(ref T v)
  {
    foreach (ref w; v) get(w);
  }

  auto getA(T)(size_t n, ref T v)
  if (hasAssignableElements!T)
  {
    v = new T(n);
    foreach (ref w; v) get(w);
  }

  auto getC(T...)(size_t n, ref T v)
  if (allSatisfy!(hasAssignableElements, T))
  {
    foreach (ref w; v)
      w = new typeof(w)(n);
    foreach (i; 0..n)
      foreach (ref w; v) get(w[i]);
  }

  auto getM(T)(size_t r, size_t c, ref T v)
  if (hasAssignableElements!T && hasAssignableElements!(ElementType!T))
  {
    v = new T(r);
    foreach (ref w; v) getA(c, w);
  }

  auto putA(T)(T v)
  {
    static if (isInputRange!T && hasLength!T && !isSomeString!T) {
      foreach (i, w; v) {
	putA(w);
	if (i < v.length - 1) write(delimiter);
      }
    } else if (isFloatingPoint!T) {
      writef(format("%%.%df", precision), v);
    } else {
      write(v);
    }
  }

  auto put(T...)(T v)
  {
    foreach (i, w; v) {
      putA(w);
      if (i < v.length - 1) write(delimiter);
    }
    writeln;
  }

  auto putB(S, T)(bool c, S t, T f)
  {
    if (c)
      put(t);
    else
      put(f);
  }

  auto dbg(T...)(T v)
  {
    stderr.writeln(v);
  }
}


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

long long func(long long n, long long x) {
  if (n == -1) return 0;
  return n/x + 1;
}

int main() {
  long long a, b, x;
  cin >> a >> b >> x;
  cout << func(b, x) - func(a-1, x) << endl;
}

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

int main() {
  int a,a1,a2,a3;
  a1 = a2 = a3 = 0;
  cin >> a;
  if (a >= 100){
    a1 = a / 100;
    a = abs(a - 100);
  }
  a2 = a / 10;
  a3 = a % 10;
  cout << a1+a2+a3 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
const int INF = 1e9;
const int MOD = 1e9+7;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    string S; cin >> S;
    vector<vi> sum(N+1, vi(10));
    REP(i, N)
    {
        REP(j, 10)
        {
            sum[i+1][j] += sum[i][j] + (j == S[i]-'0');
        }
    }

    set<int> p;

    for(int i = 1; i < N-1; i++)
    {
        REP(j, 10)
        {
            if(sum[i][j] == 0) continue;
            REP(k, 10)
            {
                if(sum[N][k] - sum[i+1][k] == 0) continue;
                p.insert(j * 100 + (S[i]-'0') * 10 + k);
            }
        }
    }
    cout << p.size() << endl;
}

Measured memory_bytes: 2432
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod=1000000007;
const char nl='\n';

const ll SZ = 200010;
ll parent[SZ], setSize[SZ];


void makeSet(ll n){
    parent[n]=n;
    setSize[n]=1;
}

ll findSet(ll n){
    if(n==parent[n])
        return n;
    return parent[n]=findSet(parent[n]);
}

void unionSets(ll a, ll b){
    a=findSet(a);
    b=findSet(b);
    if(a!=b){
        if(setSize[a]<setSize[b])
            swap(a,b);
        parent[b]=a;
        setSize[a]+=setSize[b];
    }
}

void solve(){
    ll i,j,k,l,m,n,u,v,x,y;
    cin>>n>>m;
    for(i=1;i<=n;i++) makeSet(i);
    for(i=0;i<m;i++){
        cin>>u>>v;
//        for(j=1;j<=n;j++) cout<<j<<" "<<setSize[j]<<nl;cout<<nl;
        unionSets(u,v);
    }

    ll ans=0;

    for(i=1;i<=n;i++){
//        cout<<i<<" "<<setSize[i]<<nl;
        ans=max(setSize[i],ans);
    }
    cout<<ans<<nl;
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int t = 1,i=1;
//    cin >> t;
	while (t--)
	{
//	    cout<<"Case #"<< i++ <<": ";
		solve();
	}
	return 0;
}



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

AB=0
B=0
for i in range(n):
    if s[i] =='a':
        if AB<a+b:
            AB+=1
            print('Yes')
        else:
            print('No')
    elif s[i] =='b':
        B+=1
        if AB<a+b and B<=b:
            AB+=1
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 9176
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <string>

using namespace std;

// stringをintに
// string a = "123";
// stoi(a)
//
// intをstringに
// int a = 123;
// to_string(a)
//
// charをintに
// char a = '1';
// (int)a - 48 // asciiコードを値にする

// 配列Aにcinする
//int main() {
//  int N;
//  cin >> N;
//  vector<int> A(N);
//  for (int i = 0; i < N; i++) {
//    cin >> A.at(i);
//  }
//  return 0;
//}

// 標準入出力
int main() {
	int K, X;
	cin >> K >> X;
  for (int i = (X - K + 1); i < X + K; i++) {
    cout << i << ' ';
  }
  cout << endl;
  return 0;
}

// 文字列を1文字ずつループ
//int main() {
//  string str;
//  cin >> str;
//  int sum = 0;
//  for(int i = 0; i < (int)str.size(); ++i){
//    char ch = str[i];
//
//    if (ch == '1') {
//      sum++;
//    }
//  }
//  cout << sum << endl;
//  return 0;
//}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int s[]=new int[a];
		int f[]=new int[a];
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			s[i]=scan.nextInt();
		}
		for(int i=0;i<a;i++) {
			f[i]=scan.nextInt();
		}
		for(int i=0;i<a;i++) {
			b[i]=s[i]-f[i];
		}
		Arrays.sort(b);
		int ans=0;
		for(int i=a-1;i>-1;i--) {
			if(b[i]<0) {
				break;
			}
			ans+=b[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 25300
import java.util.*;
public class Main {
    public static void main(String[] args) {
      Scanner s = new Scanner(System.in);
    	int n = s.nextInt();
    	char[] str = s.next().toCharArray();
    	for (int i =0; i < str.length; i++){
			int ans = (((n + str[i]) - 'A') % 26) + 'A';
			str[i] = (char) ans;
		}
    	System.out.println(new String(str));


    }
}



Measured memory_bytes: 22996
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
import numpy as np
ans=0
dp=np.zeros(t,np.int64)
# dp[i]:時間合計i以内に食べれる料理のおいしさ総和の最大
for i in range(n):
  a,b=ab[i]
  ans=max(ans,dp[-1]+b)
  dp[a:]=np.maximum(dp[a:],dp[:-a]+b)
print(ans)


Measured memory_bytes: 13132
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1e9 + 7;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> Ss(M);
    rep(i, M)
    {
        ll k;
        cin >> k;
        vector<ll> S(k);
        rep(j, k)
        {
            cin >> S[j];
            --S[j];
        }
        Ss[i] = S;
    }
    vector<ll> p(M);
    rep(i, M) cin >> p[i];

    // スイッチの状態を巡回
    ll ans = 0;
    std::vector<bool> onOff(N);
    for (uint16_t bits = 0; bits < (1 << N); ++bits)
    {
        rep(i, N) onOff[i] = (bits & (1 << i));
        //
        bool okay = true;
        rep(i, Ss.size())
        {
            auto& S = Ss[i];
            int count = 0;
            rep(j, S.size())
            {
                count += onOff[S[j]];
            }
            if (count % 2 != p[i])
            {
                okay = false;
                break;
            }
        }
        if (okay)
        {
            ++ans;
        }
    }
    cout << ans;

    //
    return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif /* __DEBUG__ */

int main(int argc, char **argv)
{
  ulli N, C;
  std::cin >> N >> C;
  
  std::vector<slli> x(N + 1, 0), y(N + 1, 0), v(N);
  N_TIMES(n, N) {
    std::cin >> x[n + 1] >> v[n];
    y[N - n] = C - x[n + 1];
  }
  
  std::vector<slli> S(N + 1, 0), T(N + 1, 0);
  N_TIMES(n, N) {
    S[n + 1] = S[n] + v[n];
    T[n + 1] = T[n] + v[(N - 1) - n];
  }
  
  std::vector<slli> f1(N + 1, 0), f2(N + 1, 0);
  N_TIMES(a, N + 1) {
    f1[a] = S[a] - 2 * x[a];
    f2[a] = S[a] - 1 * x[a];
  }
  
  std::vector<slli> g1(N + 1, 0), g2(N + 1, 0);
  N_TIMES(b, N + 1) {
    g1[b] = T[b] - 1 * y[b];
    g2[b] = T[b] - 2 * y[b];
  }
  
  std::vector<slli> g1_max(N + 1, 0), g2_max(N + 1, 0);
  g1_max[0] = g1[0];
  g2_max[0] = g2[0];
  for (ulli b = 1; b < N + 1; ++b) {
    g1_max[b] = std::max(g1[b], g1_max[b - 1]);
    g2_max[b] = std::max(g2[b], g2_max[b - 1]);
  }
  
  slli M = 0;
  N_TIMES(a, N + 1) {
    ulli b = N - a;
    M = std::max(M, f1[a] + g1_max[b]);
    M = std::max(M, f2[a] + g2_max[b]);
  }
  std::cout << M << std::endl;
  
  return 0;
}

Measured memory_bytes: 8960
N = gets.chomp.to_i
aArr = gets.chomp.split(' ').map(&:to_i)
# aArr.sort!

M = 10 ** 6

cnt = Array.new(M + 1, 0)
aArr.each do |a|
    if cnt[a] != 0 then
        cnt[a] += 1
        next
    else
        ma = a
        while ma <= M do
            cnt[ma] += 1
            ma += a
        end
    end
end

ans = 0

aArr.each do |a|
    # puts a.to_s + " : " + cnt[a].to_s
    ans += 1 if cnt[a] == 1
end

puts ans

Measured memory_bytes: 36940
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
AB = []
ABC = []
for i in A:
    for j in B:
        AB.append(i+j)
AB.sort(reverse = True)
for i in AB[:K+1]:
    for j in C:
        ABC.append(i+j)
ABC.sort(reverse = True)
for i in range(K):
    print(ABC[i])

Measured memory_bytes: 151816
N = int(input())

dp = [[0]*3 for i in range(N+1)]
A = [list(map(int, input().split())) for i in range(N)]

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

print(max(dp[N-1]))

Measured memory_bytes: 50380
#include <bits/stdc++.h>
#define MAXN 100100
using namespace std;
int a,b,c,n,va[MAXN],vb[MAXN],vc[MAXN],dpa[MAXN],dpb[MAXN],dpc[MAXN];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&a,&b,&c);
		va[i] = a;
		vb[i] = b;
		vc[i] = c;
		dpa[i] = max(va[i]+dpb[i-1],va[i]+dpc[i-1]);
		dpb[i] = max(vb[i]+dpa[i-1],vb[i]+dpc[i-1]);
		dpc[i] = max(vc[i]+dpa[i-1],vc[i]+dpb[i-1]); 
	}
	printf("%d",max(dpa[n-1],max(dpb[n-1],dpc[n-1])));
	return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int x = max({a, b, c});
    if(x%2 != (a+b+c)%2){
        x++;
    }
    int ans = (3*x - (a+b+c))/2;
    cout << ans << endl;

    return 0;
}   

Measured memory_bytes: 3616
num = list(map(int, input().split()))
x1 = num[0]
y1 = num[1]
x2 = num[2]
y2 = num[3]

x3 = x2 + y1 - y2
y3 = y2 - x1 + x2
x4 = x3 + x1 - x2
y4 = y3 + y1 - y2

print(x3, y3, x4, y4)

Measured memory_bytes: 3060
#include <iostream>
#include <map>

int main(){
	int n;
	while(std::cin >> n, n){
		std::map<long long int, int> stars;
		int max_num = 0, max_time = 0;
		for(int i=0;i<n;i++){
			int snum;
			std::cin >> snum;
			stars[snum]++;
			if(max_time < stars[snum])
				max_num = snum, max_time = stars[snum];
		}
		if(max_time > n / 2)
			std::cout << max_num << std::endl;
		else
			std::cout << "NO COLOR" << std::endl;
	}
}

Measured memory_bytes: 1940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            out.println(a <= b ? a : a - 1);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

Measured memory_bytes: 22228
import sys
sys.setrecursionlimit(10002)

H, N = [int(i) for i in input().split()]
locate_put = [set(), {0, 1}, {1, 2}, {2, 3}, {0, 1, 2, 3}]
not_jama = [{0, 1, 2, 3} for _ in range(H)]
known_fn = {}

for _ in range(N):
    xi, yi = [int(i) for i in input().split()]
    not_jama[yi].remove(xi)


def get_fn(h, way_put):
    if known_fn.get((h, way_put)):
        return known_fn[(h, way_put)]
    if h == 0:
        return 0
    best_count = 0
    for way, place_put in enumerate(locate_put):
        place_can_put = not_jama[h] - locate_put[way_put] & not_jama[h - 1]
        if place_put.issubset(place_can_put):
            count = get_fn(h - 1, way)
            count += 0 if way == 0 else 1 if way != 4 else 2
            best_count = count if count > best_count else best_count
    known_fn[(h, way_put)] = best_count
    return best_count


print(get_fn(H - 1, 0))



Measured memory_bytes: 25896
#include<stdio.h>
int main(){
  long long n,a,b,c,d;
  scanf("%lld %lld %lld",&n,&a,&b);
  c=a*(n-1)+b;
  d=a+(n-1)*b;
  if(n==1&&a-b||b<a)printf("0\n");
  else printf("%lld\n",d-c+1);  
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		
		String w = scan.nextLine();
		
		char c = w.charAt(0);
		int cc = 0;
		
		for(int i = 0 ; i < w.length() ; i++){
			
			if(c == w.charAt(i)){
				cc++;
			}
			String a = c + "";
			if(i == w.length() - 1){
				w = w.replaceAll(a , "");
				
				if(cc % 2 != 0){
					System.out.println("No");
					break;
				}
				
				if(w.length() != 0){
					c = w.charAt(0);
					cc = 1;
					i = 0;
				} else if(w.length() == 0){
					System.out.println("Yes");
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 9428
s = list(input())
k = int(input())
first = s[0]
last = s[-1]
first_num = 0
last_num = 0
now_num = 0
now = s[0]
ans = 0
for i in s:
  if i == first:
    first_num += 1
  else:
    break
for i in reversed(s):
  if i != last:
    break
  last_num += 1
for i in s:
  if i == now:
    now_num += 1
  else:
    ans += now_num // 2
    now_num = 1
    now = i
ans += now_num // 2
ans *= k
if first == last:
  if first_num % 2 and last_num % 2:
    ans += k - 1
  if len(set(s)) == 1:
    ans = (first_num * k) // 2 
print(ans)

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

int main() {
  int h,w,x,y;
  cin>>h>>w>>x>>y;
  double ans;
  ans=1.00*h*w/2;
  cout<<ans<<' ';
  if(2*x==h&&2*y==w)cout<<1<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	int h, w, i, j, k, ok = false;
	cin >> h >> w >> k;
	for (i = 0; !ok && i <= w; i++) {
		for (j = 0; !ok && j <= h; j++) {
			if (i * (h - j) + j * (w - i) == k)
				ok = true;
		}
	}
	if (ok)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

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

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

int main(){

  while(true){
    int n, m, q; cin>> n>> m>> q;
    if(n==0 && m==0 && q==0) break;

    bool a[m][n];
    rep(i, m)rep(j, n) a[i][j]=true;
    string ps=string(n, '0'),
           pb=string(m, '0');
    rep(_, q){
      string s, b; cin>> s>> b;
      vector<int> changed_switches, unchanged_switches;
      rep(i, n){
        if(s[i]=='1') changed_switches.push_back(i);
        else unchanged_switches.push_back(i);
      }
      vector<int> changed_bulbs, unchanged_bulbs;
      rep(i, m){
        if(pb[i]!=b[i]) changed_bulbs.push_back(i);
        else unchanged_bulbs.push_back(i);
      }
      for(int i: changed_bulbs){
        for(int j: unchanged_switches){
          a[i][j]=false;
        }
      }
      for(int i: unchanged_bulbs){
        for(int j: changed_switches){
          a[i][j]=false;
        }
      }
      ps=s; pb=b;
    }

    rep(i, m){
      int k=-1, cnt=0;
      rep(j, n){
        if(a[i][j]){
          cnt++;
          k=j;
        }
      }
      if(cnt>1){
        cout<< "?";
      }else{
        if(0<=k && k<10) cout<< k;
        else cout<< (char)('A'+(k-10));
      }
    }cout<< endl;
  }

  return 0;
}


Measured memory_bytes: 3208
from collections import Counter
N=int(input()) #1行目のNを取得する
S=[input() for i in range(N)] #複数行の数値の入力を取得

most_common_list=Counter(S).most_common()

common_s=[]

for i in range(len(most_common_list)):
    if most_common_list[i][1]==most_common_list[0][1]:
        common_s.append(most_common_list[i][0])
    else:
        break

for s in sorted(common_s):
    print(s)

Measured memory_bytes: 45040
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

signed main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    int x = (a + d - 1) / d;
    int y = (c + b - 1) / b;
    if(x >= y){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void)
{
	int x, y;
	
	
	for ( x = 1; x <= 9; x++){
		for ( y = 1; y <= 9; y++){
			printf("%dx%d=%d\n", x, y, x * y);
		}
	}
	
	return (0);
}

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

int main() {
    int n, k; cin >> n >> k;
    double ans = 0;
    for (int i = 1; i <= n; i++) {
        double p = 1;
        int x = i;
        while (x < k) {
            x *= 2;
            p /= 2;
        }
        ans += p;
    }
    cout << fixed << setprecision(12) << ans / n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int w;
    int h;
    int x;
    int y;
    int r;
    
    scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);

    printf("%s\n", x >= r && x <= w - r && y >= r && y <= h - r ? "Yes" : "No");
    
    
    return 0;
}


Measured memory_bytes: 2112
n,t=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(n)]
ab.sort()
dp=[(6007)*[0]for _ in range(n+1)]
dp[0][0]=0
ans=0
for i in range(n):
  for j in range(6007):
    dp[i+1][j]=max(dp[i+1][j],dp[i][j])
    if j<t:dp[i+1][j+ab[i][0]]=max(dp[i][j]+ab[i][1],dp[i][j+ab[i][0]])
    ans=max(ans,dp[i+1][j])
print(ans)


Measured memory_bytes: 216520
#include "bits/stdc++.h"
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long


int32_t main() {
	Fast_IO
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for (auto &i : a)
		cin >> i;
	vector<bool> dp(k + 1, false);
	dp[0] = 0;
	// for (auto c : a) {
	// 	dp[c] = 1;
	// }
	for (int i = 1; i <= k; i++) {
		bool canwin = false;
		for (auto &c : a) {
			if (i - c >= 0) {
				if (dp[i - c] == 0)
					canwin = true;
			}
		}
		if (canwin)
			dp[i] = true;
	}
	if (dp[k]) {
		cout << "First\n";
	}
	else {
		cout << "Second\n";
	}
}

Measured memory_bytes: 3672
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		for (int i = 1; i < 100000; i++) {
			if (n < i * i) {
				System.out.println((i - 1) * (i - 1));
				return;
			}
		}
	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    ll h = n;
    ll l = -1;
    while(h - l > 1)
    {
        ll mid = (h+l) >> 1;
        ll score = a[mid];
        ll stock = m*v;
        score += m;
        stock -= m;
        ll cnt = 0;
        bool flag = true;
        priority_queue<ll> que;
        for(int i = 0; i < n; i++)
        {
            if(i == mid) continue;
            if(a[i] < score)
            {
                ll del = min(score-a[i], m);
                stock -= del;
                que.push(m-del);
            }
            else if(a[i] > score)
            {
                cnt++;
                if(cnt == p)
                {
                    flag = false;
                    break;
                }
                else
                {
                    stock -= m;
                }
            }
        }
       
        if(!flag)
        {
            l = mid;
        }
        else
        {
            ll num = p-1-cnt;
            while(num > 0)
            {
                if(que.empty()) break;
                ll sc = que.top();
                que.pop();
                stock -= sc;
                num--;
            }
            if(stock <= 0) h = mid;
            else l = mid;
        }
    }
    cout << n-h << endl;
}



Measured memory_bytes: 2896
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int A, B, C, D;

  cin >> A >> B >> C >> D;

  int takahashi, aoki;
  if (C % B == 0)
    takahashi = C / B;
  else
    takahashi = C / B + 1;
  if (A % D == 0)
    aoki = A / D;
  else
    aoki = A / D + 1;

  if (takahashi <= aoki) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pll = pair<ll, ll>;
using pss = pair<string, string>;
using pdd = pair<ld, ld>;
using graph = vector<vector<int>>;

const ll MOD = 1000000007;
const ld EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ex[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ey[8] = {0, 1, 1, 1, 0, -1, -1, -1};

template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }

ll intabs(ll a)
{
    if (a >= 0)
        return a;
    else
        return -a;
}

ll intpow(ll a, ll b, ll p = LLONG_MAX)
{
    ll ret = 1;
    while (b != 0)
    {
        if ((b & 1) == 1)
            ret *= a;
        a *= a;
        if (a >= p)
            a %= p;
        if (ret >= p)
            ret %= p;
        b = b >> 1;
    }
    return ret;
}

int digit(ll a, ll b = 10)
{
    int ret = 0;
    while (a != 0)
    {
        a /= b;
        ret++;
    }
    return ret;
}

ll gcd(ll x, ll y)
{
    while (y != 0)
    {
        ll cnt = x % y;
        x = y;
        y = cnt;
    }
    return x;
}

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

class UnionFind
{
    vector<int> par, sz;

public:
    UnionFind(int n) : par(n), sz(n)
    {
        for (int i = 0; i < n; i++)
        {
            par[i] = i;
            sz[i] = 1;
        }
    }
    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
        sz[ry] += sz[rx];
    }
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    int size(int x)
    {
        return sz[root(x)];
    }
};

vector<bool> seen;
void dfs(const graph &g, int v)
{
    seen[v] = true;
    for (auto i : g[v])
    {
        if (seen[i])
            continue;
        dfs(g, i);
    }
}

int main()
{
    int i, j, k, cnt;
    int n;
    cin >> n;
    int d[10][10];
    for (i = 0; i < 10; i++)
        for (j = 0; j < 10; j++)
            d[i][j] = 0;
    for (i = 1; i <= n; i++)
    {
        d[i % 10][(i / intpow(10, digit(i) - 1)) % 10]++;
    }
    ll ans = 0;
    for (i = 1; i <= 9; i++)
    {
        for (j = 1; j <= 9; j++)
        {
            ans += d[i][j] * d[j][i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
using namespace std;



int main(){
  int a, b; cin >> a >> b;
  int ans = 0;
  FOR(i, a, b+1){
    if(i/10000 == i%10){
      if(i%10000/1000 == i%100/10){
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
            
        Scanner sc = new Scanner(System.in);		                                        
           
        int n = sc.nextInt();
        
        long[] a = new long[n];
        
        for(int i = 0;i < n;i++){
            a[i] = sc.nextLong();
        }
                   
        long sum = 0;
        long cost = 0;
        long ans = Long.MAX_VALUE;
        // +-+-
        for (int i = 0; i < n; i++) {
            sum += a[i];
            if (i % 2 == 0) {
                if (sum <= 0) {
                    cost += -sum + 1;
                    sum = 1;
                }
            } else {
                if (sum >= 0) {
                    cost += sum + 1;
                    sum = -1;
                }
            }
        }
        ans = Math.min(ans, cost);
        sum = 0;
        cost = 0;
        // -+-+
        for (int i = 0; i < n; i++) {
            sum += a[i];
            if (i % 2 == 0) {
                if (sum >= 0) {
                    cost += sum + 1;
                    sum = -1;
                }
            } else {
                if (sum <= 0) {
                    cost += -sum + 1;
                    sum = 1;
                }
            }
        }
        ans = Math.min(ans, cost);
        System.out.println(ans);           
                      
    }    
    
}

Measured memory_bytes: 61168
/*
 * parasol 
 */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <time.h>
using namespace std;
#define ll long long
const ll maxn = 2e5+5;
const ll mod = 1e9+7;
const double eps = 1e-9;
const double pi = acos(-1.0);
const ll inf = (1ll)<<60;
 
ll a[maxn];
ll n;
 
int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> n;
    ll sum = 0;
    for(ll i = 1; i <= n; i++){
        scanf("%lld", &a[i]);
        a[i] -= i; 
    }    
    sort(a+1, a+1+n);
    ll ans = 0; 
    ll x = a[(1+n)/2];
    
    for(ll i = 1; i <= n; i++){
        ans += abs(a[i]-x);
    }
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 1792
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for _ in range(N + 1)]
# dp[i][j](j=0,1,...,W)の値が求まっている状態で、dp[i+1][j]を更新することを考える
for i in range(N):
	for j in range(W + 1):
		# 品物(w[i],v[i])を選ぶとき、j-w[i]>=0に限って、価値v[i]が加算される
		if j - w[i] >= 0:
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i])
		# 品物(w[i],v[i])を選ばないとき、何も加算しない
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])

Measured memory_bytes: 122516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vvec<int> g(N);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vec<int> d(N,0);
    vec<int> pre(N,-1);
    queue<int> Q;
    Q.push(0);
    while(!Q.empty()){
        int cur = Q.front(); Q.pop();
        for(auto& to:g[cur]) if(pre[to]==-1){
            pre[to] = cur;
            Q.push(to);
        }
    }
    cout << "Yes\n";
    for(int i=1;i<N;i++) cout << pre[i]+1 << "\n";
}

Measured memory_bytes: 10632
N_ID, M_gate = map(int, input().split())
mini = float('inf')
MAX = 0

for i in range(M_gate):
    L, R = map(int, input().split())
    MAX = max(MAX, L)
    mini = min(mini, R)

answer = max(0, mini - MAX + 1)
print(answer)

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

typedef unsigned long long ull;
typedef long long ll;

ll mini(ll a, ll b){
  if(a<b) return a;
  else return b;
}

int main(){ 
  ll K, N;
  cin >> K >> N;
  vector<ll> A(N);
  vector<ll> D(N);
  for(int i=0; i<N; i++) cin >> A[i];
  ll sum=0;
  for(int i=0; i<N-1; i++){
    D[i]=A[i+1]-A[i];
    sum+=D[i];
  }
  D[N-1]=A[0]-A[N-1]+K;
  sum+=D[N-1];
  ll dist=-1;
  for(int i=0; i<N; i++){
    ll temp=sum-D[i];
    if(dist==-1) dist=temp;
    else dist=mini(dist, temp);
  }
  cout <<dist <<endl;
}


Measured memory_bytes: 3328
import java.util.Scanner;
public class Main{
	

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);			
		int x=sc.nextInt();
		
		int [][]  wl = new int [x][3];
		int [] rs = new int [x];
		int i,j,c=1;
		
		for(i=0;i<x*(x-1)/2;i++){
			int vsa =sc.nextInt();
			int vsb =sc.nextInt();
			int wla =sc.nextInt();
			int wlb =sc.nextInt();
		
			if(wla>wlb) wl[vsa-1][1]=wl[vsa-1][1]+3;
			else if(wla<wlb) wl[vsb-1][1]=wl[vsb-1][1]+3;
			else if(wla==wlb){
				wl[vsa-1][1]++;
				wl[vsb-1][1]++;
			} 
		}
		
		for(i=0;i<x;i++){
			wl[i][2]=1;
			for(j=0;j<x;j++){
				if(wl[j][1]>wl[i][1]) wl[i][2]++;
			}
		}
		
		for(i=0;i<x;i++){
			System.out.printf("%d\n",wl[i][2]);
		}
		
		sc.close();
		System.exit(0);
	}
}

Measured memory_bytes: 42908
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <fstream>

using namespace std;

int main(void)
{
	int n, m;

	cin >> n >> m;

	cout << (n - 1)*(m - 1) << endl;

	return 0;
}

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

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


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

vector<int> A[21][21];

int kose(int n)
{
if(n==1){return 2;}
else if(n==2){return 2;}
else if(n%2==1){return kose(n-1);}
else{return kose(n/2)+1;}			
}



void graf(int n)
{
if(n==1){A[1][2].push_back(0); return;}
else if(n==2){A[1][2].push_back(0); A[1][2].push_back(1); return;}	
else if(n%2==1){ graf(n-1); A[1][kose(n)].push_back(n-1);   }	
else{
graf(n/2);
for(int i=1;i<=20;i++)
{
for(int j=1;j<=20;j++)
{
for(int k=0;k<A[i][j].size();k++){A[i][j][k]*=2;}	
}
		
			
}

A[kose(n)-1][kose(n)].push_back(0); A[kose(n)-1][kose(n)].push_back(1);

}	

	
	

}


int main()
{ int n,sum=0; scanf("%d",&n);
graf(n);
for(int i=1;i<=20;i++)
{
for(int j=1;j<=20;j++)
{
	sum+= A[i][j].size();
	//printf("%d %d %d\n",i,j,A[i][j].size());
}
		
			
}
printf("%d %d\n",kose(n),sum);

for(int i=1;i<=20;i++)
{
for(int j=1;j<21;j++)
{
for(int k=0;k<A[i][j].size();k++){printf("%d %d %d\n",i,j,A[i][j][k]);}	
}
		
			
}
//printf("%d",n);
	

return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int A = int.Parse(str[0]);
		int B = int.Parse(str[1]);
		int Q = int.Parse(str[2]);
		long[]S = new long[A];
		long[]T = new long[B];
		long[]X = new long[Q];
		long[]X2 = new long[Q];
		var dic = new Dictionary<long,long>();
		for(var i=0;i<A;i++){
			S[i] = long.Parse(Console.ReadLine());
		}
		for(var i=0;i<B;i++){
			T[i] = long.Parse(Console.ReadLine());
		}
		for(var i=0;i<Q;i++){
			X[i] = long.Parse(Console.ReadLine());
			X2[i] = X[i];
		}
		Array.Sort(X2,(x,y)=>x.CompareTo(y));
		int s = -1;
		int t = -1;
		int a1 = 0;
		int b1 = 0;
		for(var i=0;i<Q;i++){
			long ans = 0;
			while(a1<A && S[a1]<X2[i]){
				a1++;
			}
			long s1 = -999999999999;
			long s2 = 999999999999;
			if(a1>0){
				s1 = S[a1-1];
			}
			if(a1<A){
				s2 = S[a1];
			}
			while(b1<B && T[b1]<X2[i]){
				b1++;
			}
			long t1 = -999999999999;
			long t2 = 999999999999;
			if(b1>0){
				t1 = T[b1-1];
			}
			if(b1<B){
				t2 = T[b1];
			}
			ans = s2 - t1 + Math.Min(X2[i]-t1,s2-X2[i]);
			ans = Math.Min(ans,t2 - s1 + Math.Min(X2[i]-s1,t2-X2[i]));
			ans = Math.Min(ans,X2[i]-Math.Min(s1,t1));
			ans = Math.Min(ans,Math.Max(s2,t2)-X2[i]);
			dic[X2[i]] = ans;
		}
		for(var i=0;i<Q;i++){
			Console.WriteLine(dic[X[i]]);
		}
	}
}

Measured memory_bytes: 27344