akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <tuple>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#define int long long
using namespace std;

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

int calc(int i, int low) {
	int n = (a[i] + low + b[i] - 1) / b[i];
	return n * b[i] - a[i];
}

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i] >> b[i];

	int low = 0;
	for (i = n - 1; i >= 0; i--) {
		low = calc(i, low);
	}
	cout << low << endl;
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <sstream>
using namespace std;
struct P{double x,y;};

void output(double x,double y){
	printf("%.6lf %.6lf\n",x,y);
}
int main(){
	P a,b,r; string s;
	while(getline(cin,s)){
		while(~s.find(","))s[s.find(",")] = ' ';
		stringstream ss(s);
		ss >> a.x >> a.y >> b.x >> b.y >> r.x >> r.y;
		
		double x , y , X = a.x-b.x , Y = a.y-b.y;
		if(X == 0){
			output(2*a.x-r.x,r.y);
		}else if(Y == 0){
			output(r.x,2*a.y-r.y );
		}else{
			x = ( r.y -a.y + (Y/X)*a.x + (X/Y)*r.x ) / ( (X*X+Y*Y)/(X*Y) );
			y = (Y/X)*(x-a.x) + a.y;
			output(2*x-r.x,2*y-r.y);
		}
	}
}

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

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

  switch(N%10) {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
      cout << "hon" << endl;
    break;
  case 0:
  case 1:
  case 6:
  case 8:
      cout << "pon" << endl;
    break;
  case 3:
    cout << "bon" << endl;
  }
 
 
  return 0;
}


Measured memory_bytes: 3592
n, m = map(int, input().split())
sum = 0
arr = list(map(int, input().split()))
for a in arr:
    sum += a
count = 0
for a in arr:
    if a >= (sum / (4 * m)):
        count += 1
if count >= m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}
int main() {
  int n,l[200],i,x=0;
  scanf("%d",&n);
  for (i=0;i<2*n;i++) {
    scanf("%d",&l[i]);
  }
  qsort(l, 2*n, sizeof(int), comp);
  for (i=0;i<n;i++) {
    x+=l[2*i];
  }
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 128
// #include </Users/kmudda/Downloads/Karthik/stdc++.h>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <climits>
#define ll long long int
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define vvl vector< vl >
#define vvi vector< vi >
#define pb push_back
#define mp make_pair
#define max_int_value 2147483647
#define max_long_value 9223372036854775807
#define min_long_value -9223372036854775806
#define ii pair<ll,ll>
#define F first
#define S second
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)
 
#define CLR(v, d)     memset(v, d, sizeof(v))
 
template<typename T> T gcd(T a, T b){return (b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
template<typename T> T mod(T a, T b) {return (a<b ? a : a%b);}
template<typename T> T mod_neg(T a, T b) {return ((a%b)+b)%b;}
ll mulmod(ll a,ll b, ll m){ll q=(ll)(((ld)a*(ld)b)/(ld)m);ll r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
template<typename T> T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T> T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
template<typename T> T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T> T mod_inverse(T a, T n){T x,y;T d = extended_euclid(a, n, x, y);return (d>1?-1:mod_neg(x,n));}
 
using namespace std;
 
string IntToString (int a)
{
    ostringstream temp;
    temp<<a;
    return temp.str();
}
 
int StringToInt (string str)
{
    int xx;
    stringstream ss;
    ss << str;
    ss >> xx;
    return xx;
}
 
ll powerwithmodulus(ll base, ll exponent,ll modulus){
    ll result = 1; base%=modulus;
    while (exponent > 0)
    {
        if (exponent % 2 == 1) result = (result * base) % modulus;
        exponent = exponent >> 1;
        base = (base * base) % modulus;
    }
    return result;
}

/*  NCR using DP
for(int n = 0; n <= 1000; n++)
        for(int r = 0; r <= n; r++)
            if(r == 0 || n == r) ncr[n][r] = 1;
            else ncr[n][r] = (ncr[n-1][r-1] + ncr[n-1][r]) % mod;

*/

 
ll largestPowerOf2(ll n)
{
    return (ll)pow(2, floor(log(n) / log(2)));
}

inline bool cmp1(pair<ll,ll> &p1, pair<ll,ll> &p2) {
    if(p1.F == p2.F)
        return p1.S < p2.S;
    else
        return p1.F < p2.F;
}
 
//lower case std::transform(str.begin(), str.end(), str.begin(), ::tolower);
//Ascii A-65 Z-90 a-97 z-122 0-48 9-57

int cal(int pow, int val, int MOD){
   if(pow <= 0)
      return 1;
   int v = cal(pow/2, val, MOD);
   if(pow % 2 == 0)
      return (v*v) % MOD; 
   else
      return (((v*val) % MOD) * v) % MOD;
}

ll t,n,m,sum=0,coun=0,m1,m2,m3,i,j,k,sum1,sum2,p,q,r,p1,q1;
bool flag2;

int main() {

  fast_io;
  //freopen("inputf.in", "r", stdin);
  //freopen("outputf.in", "w", stdout);
  cin>>n>>m;
  if(abs(n-m) >= 2) {
    cout<<max(n,m) + (max(n,m) - 1)<<endl;
  } else {
    cout<<(n+m)<<endl;
  }
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

const long mod = 1_000_000_007;

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	long n = read.to!long;
	long x = read.to!long;
	
	long[] ss;
	foreach(i; 0 .. n) ss ~= read.to!long;
	
	ss.sort();
	
	print!1("ss:", ss);
	
	long[][] ans = new long[][](x + 1, n + 1);
	foreach(i; 0 .. n){
		foreach(k; 0 .. x + 1){
			long a;
			if(i == 0) a = k % ss[i], a %= mod;
			else a = ans[k][i - 1] * i + ans[k % ss[i]][i - 1], a %= mod;
			ans[k][i] = a % mod;
			print!1("k:", k, " i:", i, " ans:", ans);
		}
	}
	
	ans[x][n - 1].writeln;
	
}


/*

S[i] を小さい順に使うようにする。

順列に新しいsを追加するとき…、
先に、sよりも小さい数があれば、その追加は答えに影響しない。

S[i]を小さい順に使うので、考えるのは列の最初に追加することだけ考えればよい


i個目までを使ったとき、kを割った答えをans[k][i]とする

ans[k][i] = ans[k][i - 1] * i + ans[k % s[i]][i - 1]










*/


Measured memory_bytes: 210684
#include<cstdio>
using namespace std;
int A, B, C;
int X;
int solve(){
int result = 0;
for(int i = 0; i <= A; ++i){
for(int j = 0; j <= B; ++j){
for(int k = 0; k <= C; ++k){
int tmp = i * 500 + j * 100 + k * 50;
if(tmp == X) result++;
}
}
}
return result;
}
int main(){
scanf("%d%d%d%d", &A, &B, &C, &X);
int result = solve();
printf("%d\n", result);
return 0;
}

Measured memory_bytes: 888
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())

i = 0
while i<N:
  b = int(input())
  j=0
  while j<3:
    k=0
    while k<3:
      if A[j][k]==b:
        A[j][k]=0
      k+=1
    j+=1
  i+=1

flag = False
i = 0
while i<3:
  if A[i][0]+A[i][1]+A[i][2] == 0:
    flag = True
    break
  if A[0][i]+A[1][i]+A[2][i] == 0:
    flag = True
    break
  i += 1

if A[0][0]+A[1][1]+A[2][2] == 0:
  flag = True
if A[2][0]+A[1][1]+A[0][2] == 0:
  flag = True

if flag == True:
  print("Yes")
else:
    print("No")
    


Measured memory_bytes: 3064
n, m = gets.split.map{|e| e.to_i}
students = ([0] * n).map{gets.split.map{|e| e.to_i}}
points   = ([0] * m).map{gets.split.map{|e| e.to_i}}

students.each do |student|
  puts points.index(points.min_by{|point|
    (student[0] - point[0]).abs + (student[1] - point[1]).abs
  }) + 1
end

Measured memory_bytes: 1788
// luogu-judger-enable-o2
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 2e5+5;
int n, k, p;
char s[N];
bool bit[N];
int main()
{
    scanf("%d%d%s", &n, &k, s+1), s[n+1] = 'B';
    for(int i = 1; i <= n; ++i) bit[i] = s[i] != s[i+1];
    for(p = 1; p <= n&&k; --k)    
        if(s[1] == 'A') s[1] = 'B', bit[p] ^= 1;
        else if(bit[p] == 0) s[1] = 'A', ++p;
        else ++p;
    if(p <= n)
    {
        for(int i = p+1; i <= n+1; ++i) s[i-p+1] = ((s[i-p]-'A')^bit[i-1])+'A';
        for(int i = n-p+3; i <= n; ++i) s[i] = ((s[i-1]-'A')^1)+'A';
    }
    else for(int i = 1; i <= n; ++i) s[i+(n&1)] = 'A'+(i&1);
    if(k&&(n&1)) s[1] = ((s[1]-'A')^(k&1))+'A'; s[n+1] = 0;
    printf("%s\n", s+1);
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 10011 ;
ll dp[N][109], n, d, mod = 1e9+7, q, ans;
string s ;
int main ()
{
	ios::sync_with_stdio(false) ;
	cin.tie() ;
	cout.tie() ;
	cin >> s >> d ; 
	for(int i = 0 ; i < 10 ; i ++)
		dp[1][i%d] ++ ;
	for(int i = 2 ; i < N ; i ++){
		for(int j = 0 ; j < d ; j ++){
			for(int k = 0 ; k <= 9 ; k ++){
				ll now = (j-k+(1000000000*d))%d ;
				dp[i][j] = (dp[i][j] + dp[i-1][now]) % mod ;
			}
		}
	}
	for(int i = 0 ; i < s.size()-1 ; i ++){
		int k = s.size() - i - 1 ;
		for(int j = 0 ; j < s[i]-'0' ; j ++){
			ll now = ((1000000000*d)-j-q)%d ;
			ans = (ans + dp[k][now]) % mod ;
		}
		q = (q + s[i]-'0');
	}
	for(int j = 0 ; j <= s[s.size()-1]-'0' ; j ++){
		ll now = ((100*d)-j-q)%d ;
		if(now == 0)
			ans ++ ;
	}
	ans = (ans - 1 + mod) % mod ;
	ans %= mod ;
	cout << ans ;
}


Measured memory_bytes: 8832
import sys
from statistics import *
from collections import *
from operator import itemgetter
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m = na()
if n == 1 and m == 1:
    print(1)
elif n == 1 or m == 1:
    print(max(n, m) - 2)
else:
    print((n-2)*(m-2))

Measured memory_bytes: 5148
n = gets.to_i
as = gets.split.map &:to_i

as.map!.with_index(1){ |a, i|
	a - i
}

as.sort!

mid = nil

if as.size % 2 == 0 then
	mid = (as[as.size / 2 - 1] + as[as.size / 2]) / 2
else
	mid = as[as.size / 2]
end

puts as.map{ |x| (x-mid).abs}.inject(:+)


Measured memory_bytes: 17540
package main

import "fmt"

func main() {
	// Code for A - Happy Birthday!
	var A, B int
	fmt.Scanf("%d %d", &A, &B)

	if A <= 8 && B <= 8 {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}


Measured memory_bytes: 1832
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    ll a[X],b[Y],c[Z];
    for(ll i=0;i<X;i++){
        cin >> a[i];
    }
    for(ll i=0;i<Y;i++){
        cin >> b[i];
    }
    for(ll i=0;i<Z;i++){
        cin >> c[i];
    }
    vector<ll> e;
    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            e.push_back(a[i]+b[j]);
        }
    }
    sort(e.begin(),e.end(),greater<ll>());
    vector<ll> ans;
    int size = min((int)e.size(),3000);
    for(int i=0;i<size;i++){
        for(int j=0;j<Z;j++){
            ans.push_back(e[i]+c[j]);
        }
    }
    sort(ans.begin(),ans.end(),greater<ll>());
    for(int i=0;i<K;i++){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 43364
#include <stdio.h>
int main()
{

    int i,a,b,c,d,j,n,m,k,l,h,r;
    scanf("%d%d",&b,&c);
    i=b-c;
    if(i>0){
        printf("%d\n",i);
    } else{
        printf("0\n");
    }
    return 0;
}



Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String a = in.next();
        int an = 0;
         while(!a.equals("0")){
             int d = a.length();
             for(int i=0; i<d; i++){
                 an+=a.charAt(i)-'0';
         }
        System.out.println(an);
        an=0;
        a=in.next();                                                        
        }
    }
}

Measured memory_bytes: 26128
#define TST 0
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)
#define printM(a, n, m) F(i, 0, n){ FE(j, 0, m) cout << a[i][j] << (i==m?'\n':' ');}

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

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

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

#define printMatrix(mat,n,m){ \
    F(i, 0, n){               \
        F(j, 0, m){           \
            cout << mat[i][j] << space;\
        }\
        cout << endl;\
    }\
}

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n,m;
    cin >> n >> m;
    vvi s;
    int k;
    vi k_num;
    F(j, 0, m){
        cin >> k;
         k_num.pb(k);
         vi tmp;
        F(i, 0, k){
            int s_tmp;
            cin >> s_tmp;
            tmp.pb(s_tmp);
        }
        s.pb(tmp);
    }
    vi p;
    F(i, 0, m){
        int p_tmp;
        cin >> p_tmp;
        p.pb(p_tmp);
    }
    long ans = 0;
    for(int bit = 0; bit < (1<<n);bit ++){
            for(int j = 0; j < m;j++){
                int count = 0;
                // count number of switches in s
                for(int i = 0;i < k_num[j];i++){
                    if(bit & 1 << (s[j][i]-1)){
                        count++;
                     }
                }
                if(!(count % 2 == p[j])){
                // all switch do not light
                goto nextbit;
                }
            }
            // all swich turn on
            ans++;
nextbit:continue;
    }
#if TST==1
#endif
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define dump(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> S(M);
  vector<int> p(M);
  for(int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      int s;
      cin >> s;
      s--;
      S[i].push_back(s);
    }
  }
  for(int i = 0; i < M; i++) {
    cin >> p[i];
  }
  int ans = 0;
  //すべての場合について全探索
  for(int bit = 0; bit < (1 << N); bit++) {
    bool ok = true;

    for(int j = 0; j < M; j++) {
      int fire = 0;
      // Sに対応するスイッチがついてるかみてまわる
      for(int x : S[j]) {
        if(bit & (1 << x)) { fire++; }
      }
      if(fire % 2 != p[j]) {
        ok = false;
        break;
      }
    }
    if(ok) { ans++; }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
class DICE:
    def __init__(self, li = [1,2,3,4,5,6]):
        self.vals = li
        self.nextkeys = [1, 4, 3, 2] # 2 5 4 3 nsew
        self.nowkey = 0
        self.c_key = 5
        self.nowval = li[0]
        self.distvals = []
        tmp = self.nextkeys + [self.nowkey,self.c_key]
        for t in tmp:
            self.distvals.append(self.vals[t]) 
    def operate(self, s):
        pastkey = self.nowkey
        if s == 'N':
            self.nowkey = self.nextkeys[0]
            self.nextkeys[0] = self.c_key
            self.nextkeys[1] = pastkey
        elif s == 'S':
            self.nowkey = self.nextkeys[1]
            self.nextkeys[1] = self.c_key
            self.nextkeys[0] = pastkey
        elif s == 'E':
            self.nowkey = self.nextkeys[2]
            self.nextkeys[2] = self.c_key
            self.nextkeys[3] = pastkey
        elif s == 'W':
            self.nowkey = self.nextkeys[3]
            self.nextkeys[3] = self.c_key
            self.nextkeys[2] = pastkey
        self.nowval = self.vals[self.nowkey]
        self.c_key = abs(5 - self.nowkey)
        self.distvals = []
        tmp = self.nextkeys + [self.nowkey,self.c_key]
        for t in tmp:
            self.distvals.append(self.vals[t]) 

n = int(input())
flag = False
diceval = [[]] * n
for i in range(n):
    diceval[i] = list(map(int, input().split()))
s = 'NNNNWNNNNWNNNNWNNNN'+'NEEEENEEEENEEEENEEEE'+'ENWWWWNWWWWNWWWWNWWWWW'
for j in range(n - 1):
    if flag == True: break
    for k in range(j + 1, n):
        if flag == True: break
        diceA = DICE(li = diceval[j])
        diceB = DICE(li = diceval[k])
        for i in s:
            diceA.operate(i)
            if diceA.distvals == diceB.distvals:
                print('No')
                flag = True
                break
if flag == False:
    print('Yes')



Measured memory_bytes: 5612
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<double> a(n);
	double tmp;
	int min;
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		min = i;
		for (int j = i; j < n; j++)
		{
			if (a[j] < a[min])
			{
				min = j;
			}
		}
		if (min != i)
		{
			tmp = a[i];
			a[i] = a[min];
			a[min] = tmp;
			count++;
		}
	}
	for (int i = 0; i < n; i++)
	{
		cout << a[i];
		if (i == n - 1)
		{
			cout << endl;
		}
		else
		{
			cout << " ";
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 3284
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    long long int A, B, C, ans = 0; cin >> A >> B >> C;
    if (A < C) ans += A, C -= A;
    else ans += C, C = 0;
    if (B >= C) ans += B + C;
    else ans += 2 * B + 1;
    printf("%d\n", ans);
}


Measured memory_bytes: 3724
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 55;

int main() {
	ll n; cin >> n;
	string a, b, c; cin >> a >> b >> c;
	ll ans = 0;
	rep(i, 0, n) {
		if (a[i] == b[i] && b[i] == c[i]) {
		}
		else if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) {
			ans++;
		}
		else {
			ans += 2;
		}
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int MOD=1e9+7;
int n,m;
int a[maxn];
int dp[25][1<<17];
int max_state;
int f[maxn],invf[maxn]; 
inline int ksm(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(1ll*ans*x)%MOD; 
		x=(1ll*x*x)%MOD; y>>=1;
	}
	return ans; 
}
inline int C(int x,int y){
	if(x<y||y<0) return 0;
	return 1ll*f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) scanf("%d",&a[i]);
	f[0]=invf[0]=1;
	max_state=(1<<n);
	for(int i=1;i<=max_state;i++) f[i]=1ll*i*f[i-1]%MOD;
	invf[max_state]=ksm(f[max_state],MOD-2);
	for(int i=max_state-1;i>=1;i--) invf[i]=1ll*(i+1)*invf[i+1]%MOD;
	dp[m+1][0]=1;
	for(int i=m;i>=1;i--)
		for(int j=0;j<max_state;j++){
			dp[i][j]+=dp[i+1][j],dp[i][j]%=MOD;
			for(int k=0;k<n;k++){
				if((j>>k)&1)continue;
				dp[i][j+(1<<k)]+=1ll*dp[i+1][j]*C((1<<n)-j-a[i],(1<<k)-1)%MOD*f[1<<k]%MOD;
				dp[i][j+(1<<k)]%=MOD;
			}
		}
	ll ans=0;
	for(int i=0;i<max_state;i++){
		int cnt=0;
		for(int j=i;j;j-=j&-j) cnt++;
		if(cnt&1) ans+=MOD-1ll*dp[1][i]*f[max_state-i-1]%MOD;
		else ans+=1ll*dp[1][i]*f[max_state-i-1]%MOD;
	}
	printf("%lld\n",ans%MOD*max_state%MOD);
	return 0;
} 

Measured memory_bytes: 8516
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

void solve(int n, int m, int q)
{
    string to36 = "0123456789";
    for (auto c = 'A'; c <= 'Z'; c++)
    {
        to36 += c;
    }
    map<int, vector<int>> candid; //候補
    rep(i, m)
    {
        rep(j, n)
        {
            candid[i].push_back(j);
        }
    }
    string button = "";
    rep(i, n) button += "0";
    string light = "";
    rep(i, m) light += "0";
    rep(tmp, q)
    {

        string op, res;
        cin >> op >> res;
        vector<int> on_button;
        map<int, bool> on_light;
        rep(i, n)
        {
            if ((button[i] == '0') ^ (op[i] == '0')) //ボタンが前押されていなくて、今操作された　or ボタンが前押されていて、今操作されていないなら（ほんまか？）
            {
                on_button.push_back(i);
            }
        }
        rep(i, m)
        {
            if (res[i] == '1')
            {
                on_light[i] = true;
            }
        }
        rep(i, m)
        {
            if (on_light[i])
            {
                vector<int> update;
                set_intersection(ALL(on_button), ALL(candid[i]), inserter(update, end(update)));
                candid[i] = update;
            }
            else
            {
                vector<int> update;
                set_difference(ALL(candid[i]), ALL(on_button), inserter(update, end(update)));
                candid[i] = update;
            }
        }
        for (auto &&l : on_light)
        {
        }
        rep(i, n)
        {
            if (op[i] == '1')
            {
                if (button[i] == '1')
                {
                    button[i] = '0';
                }
                else
                {
                    button[i] = '1';
                }
            }
        }
        //  cerr << button << endl;
        light = res;
    }
    rep(i, m)
    {
        if (candid[i].size() == 1)
        {

            cout << to36[candid[i][0]];
        }
        else
        {
            cout << '?';
        }
    }
    cout << endl;
}

int main()
{
    int n, m, q;
    while (cin >> n >> m >> q, n)
    {
        solve(n, m, q);
    }
    return 0;
}


Measured memory_bytes: 3444
from collections import deque
INF = 10**18
h,w = map(int,input().split())
li = [list(input()) for i in range(h)]


def bfs(sy,sx):
    #頂点をINFで初期化
    d = [[INF]*w for i in range(h)]
    
    #移動４方向のベクトル
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]

    #スタート位置とゴール位置を探す
    """
    for i in range(h):
        for j in range(w):
            if li[i][j]  == "s":
                sx = i
                sy = j
            if li[i][j] == "g":
                gx = i
                gy = j
    """
    if li[sy][sx] == "#":
        return 0
    #スタート地点をキューにいれ、頂点を０にする
    que = deque([])
    que.append((sy,sx))
    d[sy][sx] = 0
    
    #キューが空になるまでループ（行ける要素がなくなるまで）
    while que:
        # キューの先頭を取り出す
        p = que.popleft()
        # 取り出してきた状態がゴールなら探索をやめる
        """
        if p[0] == gx and p[1] == gy:
            break
        """
        # 移動4方向をループ
        for i in range(4):
            nx = p[1] + dx[i]
            ny = p[0] + dy[i]

            #壁との判定とすでに訪れたかどうかをチェック
            if 0<=nx and nx < w and 0 <= ny and ny < h:
                if li[ny][nx] != "#" and d[ny][nx] == INF:
                    #移動できる点なのでキューについか
                    que.append((ny,nx))
                    #前の点+1で移動できる
                    d[ny][nx] = d[p[0]][p[1]] + 1
    dmax = 0
    for i in range(h):
        for j in range(w):
            if d[i][j] == INF:
                continue
            dmax = max(dmax,d[i][j])
    return dmax
ans = 0
for i in range(h):
    for j in range(w):
        c = bfs(i,j)
        ans = max(ans,c)
print(ans)

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

#define DIGIT 100

int getDivCount(int x_val) {
    int cnt = 0;
    while (x_val % 100 == 0) {
        x_val /= 100;
        ++cnt;
    }
    
    return cnt;
}

int main(void) {
    int d, n, num, val;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> d >> n;
    num = val = 0;
    while(num < n) {
        ++val;
        if (getDivCount(val) == d) {
            ++num;
        }
    }
    
    cout << val << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-9
#define MOD	1000000007
#define int	long long
#define sz(x) (int)x.size()
#define all(a) (a).begin(),(a).end()
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;


#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]" << " ";
	err(++it, args...);
}


int32_t main(){
	int n, k;
	cin >> n >> k;
	int a[n+1];
	int sumi = 0;
	for(int i = 1; i <= n; i++){
		a[i] = k + i - 1;
		sumi += a[i];
	}
	
	int temp = 1e9;
	for(int i = 1; i <= n; i++){
		if(abs(a[i]) < abs(temp))
			temp = a[i];
	}
	cout<< sumi - temp;
	
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=110;
int n,K,s;
vector<pair<int,int> > ans;
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(K);
	s=(n-1)*(n-2)/2;
	if (K>s) printf("-1\n");
	else {
		for (int i=2;i<=n;i++)
		for (int j=i+1;j<=n;j++) {
			if (s==K) {
				printf("%d\n",n-1+ans.size());
				for (int k=2;k<=n;k++)
					printf("1 %d\n",k);
				for (int k=0;k<ans.size();k++)
					printf("%d %d\n",ans[k].first,ans[k].second);
				return 0;
			}
			s--;
			ans.push_back(make_pair(i,j));
		}
		printf("%d\n",n-1+ans.size());
				for (int k=2;k<=n;k++)
					printf("1 %d\n",k);
				for (int k=0;k<ans.size();k++)
					printf("%d %d\n",ans[k].first,ans[k].second);
				return 0;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i)
#define mod 1e9 + 7
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	　　　　　 　 _... ..._
	　　　　　 , ´⌒ ⌒ヽ
	　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
	　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
	　　　　　　△ﾑ,8ﾑﾌつ
	　　　　　/(ﾝ_/＿ヽ＼
	　　　　 ～～i_ﾌ_ﾌ～´
	*/
	int n, m;
	int a;
	int ans = 0;
	cin >> n >> m;
	priority_queue<int>L;
	rep0(i, n - 1) {
		cin >> a;
		L.push(a);
	}
	rep0(j, m - 1) {
		ans += L.top();
		L.pop();
	}
	cout << ans << endl;
	return 0;
}
 

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

using ll = long long;

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

    unordered_map<int, int> mp;
    ll ans = 0;

    for(int i = 0; i < n; i++) {
        int cur = i-a[i];
        ans += mp[cur];
        mp[i+a[i]]++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 19436
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N;

	cin >> N;

	int tmp = N / 2;

	if (N % 2 != 0) {
		tmp++;
	}

	cout << (double)tmp / N << endl;

	return 0;
}

Measured memory_bytes: 256
S = input()
S = list(S)

ans = 1
pre = S[0]
c = 1
while 1:
    if c == len(S):
        break
    if c == len(S)-1:
        if S[c] == pre:
            break
        else:
            ans += 1
            break

    if S[c] == pre:
        pre = S[c]+S[c+1]
        ans += 1
        c += 2
    else:
        pre = S[c]
        ans += 1
        c += 1

print(ans)


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

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

  cin >> m;
  vector<string> t(m);
  rep (i, m) cin >> t[i];

  vector<bool> ut(m);
  bool opened = false;

  rep (i, m) {
    bool solved = false;

    rep (j, n) {
      if (t[i] == u[j]) {
        if (opened) {
          cout << "Closed by " << t[i] << endl;
          opened = false;
          solved = true;
        }
        else {
          cout << "Opened by " << t[i] << endl;
          opened = true;
          solved = true;
        }
        break;
      }
    }

    if (!solved) cout << "Unknown " << t[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3200
def show(nums):
    for i in range(len(nums)):
        if i != len(nums)-1:
            print(nums[i],end=' ')
        else:
            print(nums[i])

N = int(input())
A = list(map(int,input().split()))

count = 0
flag = 1

for i in range(N):
    while flag:
        flag = 0
        for j in range(N-1,i,-1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                count += 1
                flag = 1

show(A)
print(count)



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

class DandA {
    static void Main(string[] args) {
        int r = ReadLineInt();
        Console.WriteLine(r * r);
    }

    static string[] ary = new string[] {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}

    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
}

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

int main() {
  string S ; 
  cin >> S ; 
  for(int i = 0 ; i < S.size() ; i++){
    if (S.at(i) == '1'){
      cout << 9  ; 
    }
    else if(S.at(i) == '9'){
      cout << 1 ;
    }
    
  }
  cout << endl ; 
}

Measured memory_bytes: 3608
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;

int main(){
    int A , B , C ; cin >> A >> B >> C ;
    cout << ( A + B + C ) - max( {  A, B, C }) << endl ;
    return 0 ;
}


Measured memory_bytes: 3604
#include <stdio.h>
int main(void) {
    int price,money,change;
    while (1) {
        scanf("%d %d\n",&price,&money);
        if (price==0&&money==0) break;
        change=money-price;
        printf("%d %d %d\n",(change%500)/100,(change%1000)/500,change/1000);
    }
    return 0;
}

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

int main(){
while(1){
	int a[6]={500,100,50,10,5,1};
	int n,ans=0;
	scanf("%d",&n);
	if(n==0)break;
	n=1000-n;
	for(int i=0;i<6;i++){
		ans+=n/a[i];
		n%=a[i];
	}
	printf("%d\n",ans);
}
}

Measured memory_bytes: 1168
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N, M = MAP()
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(N-M+1):
	for j in range(N-M+1):  #左上のますが(i, j)
		tmp_lis = []
		for k in range(M):
			tmp_lis.append(A[i+k][j:j+M])
		if tmp_lis == B:
			print("Yes")
			exit()
else:
	print("No")

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

int dp[50000];
int coins[51];
int n;

int greedy(int k) {
    int c = 0;
    for(int i=n-1; i>=0; --i) {
        c += k/coins[i];
        k %= coins[i];
    }
    return c;
}

int main() {
    int tc=1;
    while(cin>>n, n) {
        for(int i=0; i<n; ++i) cin>>coins[i];
        if(coins[0] != 1) {
            cout<<"Case #"<<tc++<<": Cannot pay some amount"<<endl;
            continue;
        }

        memset(dp, 0x3f, sizeof(dp));
        dp[0] = 0;
        for(int i=0; i<n; ++i) {
            for(int j=0; j<50000-coins[i]; ++j) {
                dp[j+coins[i]] = min(dp[j]+1,dp[j+coins[i]]);
            }
        }

        for(int i=0; i<50000; ++i) {
            if(dp[i] < greedy(i)) {
                cout<<"Case #"<<tc++<<": Cannot use greedy algorithm"<<endl;
                goto NEXT;
            }
        }

        cout<<"Case #"<<tc++<<": OK"<<endl;
    NEXT:;
    }
}

Measured memory_bytes: 1060
import heapq
n, m = map(int, input().split())
M = [[] for _ in range(m + 1)]
q = []
for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        M[m - a] += [b]
for day in range(m + 1):
    for value in M[day]:
        if len(q) <= day:
            heapq.heappush(q, value)
        else:
            heapq.heappushpop(q, value)
print(sum(q))

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

int memo[50001];
int solveCoinChange( int n, int m, int* c )
{
    if( memo[n] )
        return memo[n];

    int min = 10000000;
    for( int i = 0; i < m; i++ )
    {
        if( n - c[i] > 0 )
            memo[n] = solveCoinChange( n - c[i], m, c ) + 1;
        if( memo[n] < min )
            min = memo[n];
    }
    return memo[n] = min;
}

int main()
{
    int n, m, c[20];

    cin >> n >> m;

    for( int i = 0; i < m; i++ )
    {    
        cin >> c[i];
        memo[c[i]] = 1;
    }
    cout << solveCoinChange( n, m, c ) << endl;

    return 0;
}



Measured memory_bytes: 7212
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin>>p[i];

  vector<double> expo(n);
  for(int i=0;i<n;i++){
    expo[i] = (double)(1+p[i])/2; //(1+p[i])*p[i]/2/p[i];
  }

  vector<double> sum(n+1);
  sum[0] = 0;
  for(int i=1;i<=n;i++){
    sum[i] = sum[i-1]+expo[i-1];
  }
  double s,max=0;
  for(int i=0;i<=n-k;i++){
    s = sum[i+k]-sum[i];
    if(s > max) max = s;
  }
  /*
  int cnt = 0;
  double sum=0,max=0;
  int right = 0;
  for(int left=0;left<n;left++){
    while(right-left+1 != k){
      sum += expo[right++];
    }
    if(sum > max) max = sum;
    sum -= expo[left++];
  }
  */

  printf("%.7lf\n",max);
//  cout << max << endl;
}


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

A.sort()
A.append(0)
temp = A[0]
num = 0
ans = 0
for i in range(N+1):
    if A[i] == temp:
        num += 1
    elif num < temp:
        ans += num
        num = 1
        temp = A[i]
    else:
        ans += num-temp
        num = 1
        temp = A[i]
        
print(ans)

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

int main() {

    int n, m;
    while (cin >> n >> m and (n or m)) {

        int h[1501], w[1501];
        vector<int> hh(1500001, 0), ww(1500001, 0);

        rep(i, n) cin >> h[i];
        rep(i, m) cin >> w[i];

        rep(i, n) {
            int s=0;
            for (int j=i; j<n; ++j) {
                s += h[j];
                hh[s]++;
            }
        }

        rep(i, m) {
            int s=0;
            for (int j=i; j<m; ++j) {
                s += w[j];
                ww[s]++;
            }
        }

        int ans=0;
        rep(i, 1500001) {
            ans += hh[i] * ww[i];
        }

        cout << ans << endl;

    }

    return 0;
}

Measured memory_bytes: 14496
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final int m = scanner.nextInt();
        final int x = scanner.nextInt();

        final int[][] books = new int[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            books[i][0] = scanner.nextInt();
            for (int j = 1; j <= m; j++) {
                books[i][j] = scanner.nextInt();
            }
        }

        int min = Integer.MAX_VALUE;
        for (int bit = 1; bit < 1 << n; bit++) {
            final int[] sum = new int[m + 1];
            int price = 0;
            for (int i = 1; i <= n; i++) {
                if ((bit & 1 << (i - 1)) > 0) {
                    for (int j = 1; j <= m; j++) {
                        sum[j] += books[i][j];
                    }
                    price += books[i][0];
                }
            }

            final boolean allMatch = Arrays.stream(sum, 1, m + 1).allMatch(v -> v >= x);
            if (allMatch) {
                min = Math.min(min, price);
            }
        }

        System.out.println(min < Integer.MAX_VALUE ? min : -1);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

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


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N, M; cin >> N >> M;
  vector<vector<int>> s(M);
  vector<int> ks(M);
  vector<int> p(M);
  rep(i, M) {
    cin >> ks[i];
    s[i].resize(ks[i]);
    rep(j, ks[i]) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  rep(i, M) cin >> p[i];

  int ans = 0;
  REP(S, 0, (1 << N)) {
    bool ok = 1;
    rep(i, M) {
      int count = 0;
      rep(j, ks[i]) {
        count += (S >> s[i][j]) & 1;
      }
      bool light_is_on = count % 2 == p[i];
      ok = ok && light_is_on;
    }
    ans += ok;
  }
  cout << ans << endl;
}


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

int main()
{
    int n, k, i;
    char str[100];
    scanf("%d", &n);
    scanf("%d", &k);
    scanf("%s", str);

    str[k - 1] = str[k - 1] + 32;

    printf("%s\n", str);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

//for debugging 
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14 
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int modi = 1e9+7;
void solve(){
	int n;
	cin >> n;
	pair<int,int> coords[n];
	vi xy,x_y;
	for(int i =0;i<n;i++){
		int x,y;
		cin >> x >> y;
		coords[i] = {x,y};
		xy.pb(x+y);
		x_y.pb(x-y);
	}
	int ans = 0;
	sort(xy.begin(),xy.end());
	sort(x_y.begin(),x_y.end());

	ans = max(xy[n-1]-xy[0],x_y[n-1] - x_y[0]);

	// pii a  = dfs(0,coords[0]);
	// pii b=  dfs(a.se, coords[a.se]);
	// sort(ru.begin(),ru.end());
	cout << ans << endl; 

}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 6760
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



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

  int N, K, C;
  string S;
  cin >> N >> K >> C >> S;
  int mae = -1 * MOD, cou = 0;
  int A[K], B[K];
  rep(i,N){
    if(S[i] == 'x') continue;
    if(i - mae > C){
      mae = i;
      A[cou] = i;
      cou++;
    }
    if(cou == K) break;
  }
  cou--;
  mae = MOD;
  for(int i=N-1;i>=0;i--){
    if(S[i] == 'x') continue;
    if(mae - i > C){
      mae = i;
      B[cou] = i;
      cou--;
    }
    if(cou == -1) break;
  }
  rep(i,K){
    if(A[i] == B[i]){
      cout << A[i]+1 << endl;
    }
  }
  
}

Measured memory_bytes: 5012
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    ll count = 0;

    for(int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        while(A % 2 == 0) {
            count++;
            A /= 2;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
'''
        2 A1 = M_1 + M_2
        2 A2 = M_2 + M_3
        2 A3 = M_3 + M_4
        2 A4 = M_4 + M_5
        2 A5 = M_5 + M_1
A1 + A2 + A3 = M_1 + M_2 + M_3

M_1 = (A1 + A2 + A3) - (M_2 + M_3 + M_4 + M_5)
M_2 = (A1 + A2 + A3) - (M_3 + M_4 + M_5 + M_6)
M_3 = (A1 + A2 + A3) - (M_4 + M_5 + M_6 + M_7)
'''

n    = int(input())
ai   = list(map(int, input().split()))
aix2 = list(map(lambda x: x * 2, ai))

sum_a = sum(ai)

def ring_get(xs, s, e, mod):
    ys = []
    i  = s % mod

    while i != (e % mod):
        ys.append(xs[i])
        i = (i + 2) % mod

    return ys

beforeM = sum_a - sum(ring_get(aix2, 1, 1 + (n - 1), n))

print(beforeM)

for i in range(1, n):
    print(aix2[i - 1] - beforeM)
    beforeM = aix2[i - 1] - beforeM


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

int compare(const void *a,const void *b){
	return *(int*)a - *(int*)b;
}

int main(void){
	int n;
	int i;
	int num[1000];
	int sa[1000];
	while(scanf("%d",&n)){
		if(n == 0){
			break;
		}
		for(i = 0;i < n;i++){
			scanf("%d",&num[i]);
		}
		qsort(num,n,sizeof(int),compare);
		for(i = 0;i < n - 1;i++){
			sa[i] = num[i + 1] - num[i];
		}
		qsort(sa,n - 1,sizeof(int),compare);
		printf("%d\n",sa[0]);
		for(i = 0;i < 1000;i++){
			num[i] = 0;
			sa[i] = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 656
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    string n;
    cin>>n;
    for(int i=0;i<n.size();i++)
    {
        if(n[i]=='1')
            n[i]='9';
        else if(n[i]=='9')
            n[i]='1';
    }
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256