akhauriyash/Code-Regression huggingface dataset:
/*
    Author      : Dinesh Verra
    College     : ABV-IIITM
    Date        : 02/08/2020
    Source		: 
    Explanation : 
*/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision; 
using namespace std;
typedef long long ll;
// typedef unsigned long long ll;
#define cu continue
#define br break
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define inf INT_MAX
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define F first
#define S second
#define vll vector <ll>
#define vpll vector <pll>
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define all(v) v.begin(),v.end()
#define nl cout<<'\n'

template <typename A1>
void prn(A1&& arg)
{
	cout<<arg<<'\n';
}
template <typename A1, typename... A>
void prn(A1&& arg, A&&... args)
{
	cout<<arg<<' ';
	prn(args...);
}

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


	ll n,d,ans=0;
	cin>>n>>d;
	d*=d;
	ll x,y,tmp;
	for(ll i=0;i<n;i++)
	{
		cin>>x>>y;
		tmp=x*x+y*y;
		if(tmp<=d) ans++;
	}
	prn(ans);
}

Measured memory_bytes: 3636
import           Control.Applicative
import           Control.Monad
import           Data.List           (insert, intercalate)

print' :: [Int] -> IO ()
print' xs = putStrLn $ intercalate " " $ fmap show xs

step :: [Int] -> IO ()
step (x:xs) = f [x] xs
  where
    f as []     = print' as
    f as (b:bs) = print' (as ++ (b:bs)) >> f (insert b as) bs

main :: IO ()
main = do
    getLine
    xs <- fmap read . words <$> getLine :: IO [Int]
    step xs



Measured memory_bytes: 4116
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
int  h, w, x[50], y[50], c[50], d[50],p = 0,q = 0;long long int ans = (1 << 30), dis;
#define rep(i,n) for(int i =0;i < n;i++)
int main() {
	cin >> h >> w;
	rep(i, h) {
		cin >> x[i] >> y[i];
	}
	rep(i, w) {
		cin >> c[i] >> d[i];
	}
	rep(i, h) {
		ans = 114514810364364;
		rep(j, w) {
			dis = abs(x[i] - c[j]) + abs(y[i] - d[j]);
			if (dis < ans) {
				ans = dis;
				p = j + 1;
			}
		}
		cout << p << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
long long sin[100001];
int main(){
	while(1){
	memset(sin,0,sizeof(sin));
	int n,k;
	int i,j,max=0,x;
	cin>>n>>k;
		if(n==0&&k==0)break;
	for(i=0;i<n;i++){
		cin>>sin[i];
	}
	for(i=0;i<n-k+1;i++){
		x=0;
		for(j=0;j<k;j++){
			x+=sin[i+j];
		}
		if(max<x)max=x;
	}
	cout<<max<<endl;
	}
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {

	long long n;
	scanf("%lld", &n);

	long long sq = sqrt(n);

	while(sq >= 1) {
		if(n%sq == 0) {
			long long row = sq;
			long long col = n/sq;
			printf("%lld\n", row-1 + col-1);
			break;
		}
		sq--;
	}

    return 0;
}

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

flag=0
cnt=0
for i in range(N):
    if A[i][0]==A[i][1]:
        cnt+=1
    else:
        cnt=0
    if cnt==3:
        flag=1
if flag==1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62328
#include<stdio.h> 
int main(void){ 
    int a,b,r,ans,a1,b1;
    double c;
    
    while(scanf("%d %d",&a,&b)!=EOF){
        a1=a,b1=b; 
        
        while(1){
            r=a%b;
            
            if(r==0){
                ans=b;
                break;
            }
            else{
                a=b;
                b=r;
            } 
            
        } 
        
        c=(double)(a1)*(double)(b1)/(double)(ans);
        
        printf("%d %.0f\n",ans,c);
    }
    
    return 0; 
    
} 


Measured memory_bytes: 2028
n = int(input())
t = [0]
x = [0]
y = [0]
for _ in range(n):
    T, X, Y = map(int, input().split())
    t.append(T)
    x.append(X)
    y.append(Y)
    
can = True
for i in range(n):
    dt = t[i+1]-t[i]
    dist = abs(x[i+1]-x[i])+abs(y[i+1]-y[i])
    if dt < dist:
        can = False
    elif dist%2 != dt%2:
        can = False
        
print('Yes' if can else 'No')

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

struct Restaurant{
    ll id;
    string name;
    ll score;
    Restaurant(){}

    bool operator<(const Restaurant &another) const
    {
        if(name==another.name){
            // return score < another.score;
            return score > another.score;
        }else{
            return name < another.name;
        }
    }
};

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

    // input
    ll N;
    cin >> N;

    vector<Restaurant> A;    
    FOR(i, 0, N){
        auto r = Restaurant();
        r.id = i;
        cin >> r.name;
        cin >> r.score;
        A.push_back(r);
    }
    sort(ALL(A));

    for(auto r : A){
        p(r.id + 1);
    }

    return 0;
}

Measured memory_bytes: 256
n,d=map(int,input().split()) #2<=n<=10 souatari 10*9/2>kaisuu
x=[]
cnt=0
for _ in range(n):
  x+=[list(map(int,input().split()))]
dx=[]
for i in range(n):
  for j in range(n):
    if i == j:
      continue
    dx2=0
    for k in range(d):
      dx2 += (x[i][k]-x[j][k])**2
    dx +=[dx2**0.5]
for _ in dx:
	if _ == int(_):
  		cnt+=1 
print(cnt//2)

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

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

int main() {
    int x; cin >> x;
    int ans = 0;
    int cnt = 0;
    int tmp = x;
    cnt = tmp / 500;
    tmp %= 500;
    ans += cnt * 1000;
    cnt = tmp / 5;
    ans += cnt * 5;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int N;
  cin >> N;
  vector<int> b(N);
  cin >> b;
  if (b[0] != 1) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> tmp;
  for (int i = 0; i < N; i++) {
    debug(tmp);
    if (tmp.size() + 1 < b[i]) {
      cout << -1 << endl;
      return 0;
    } else {
      int idx = b[i] - 1;
      tmp.insert(tmp.begin() + idx, b[i]);
    }
  }
  for (int i = 0; i < N; i++) {
    cout << tmp[i] << endl;
  }
  return 0;
}

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

const int UNDEFINED = -1;
const int WIN = 0;
const int LOSE = 1;
int n;
int win[10], lose[10];
int result[10][10];
int ans;

int encode(int x, int y) {
    return x * n + y;
}
pair<int, int> decode(int z) {
    return  {z / n, z % n};
}

void dfs(int z) {
    int x, y;
    tie(x, y) = decode(z);
    if(x >= n or y >= n) {
        ans++;
        return;
    }
    if(win[x] > n / 2) return;
    if(lose[x] > n / 2) return;
    if(x == y) {
        dfs(encode(x, y) + 1);
        return;
    }
    if(result[x][y] != UNDEFINED) {
        dfs(encode(x, y) + 1);
        return;
    }
    // WIN
    if(win[x] < n / 2) {
        result[x][y] = WIN;
        result[y][x] = LOSE;
        win[x]++; lose[y]++;
        dfs(encode(x, y) + 1);
        result[x][y] = UNDEFINED;
        result[y][x] = UNDEFINED;
        win[x]--; lose[y]--;
    }
    // LOSE
    if(lose[x] < n / 2) {
        result[x][y] = LOSE;
        result[y][x] = WIN;
        lose[x]++; win[y]++;
        dfs(encode(x, y) + 1);
        result[x][y] = UNDEFINED;
        result[y][x] = UNDEFINED;
        lose[x]--; win[y]--;
    }
}

int main() {
    while(cin >> n and n > 0) {
        // init
        ans = 0;
        for(int i = 0; i < n; ++i) {
            win[i] = lose[i] = 0;
            for(int j = 0; j < n; ++j) {
                result[i][j] = UNDEFINED;
            }
        }
        // input
        int m; cin >> m;
        while(m--) {
            int x, y; cin >> x >> y;
            x--; y--;
            result[x][y] = WIN;
            result[y][x] = LOSE;
            win[x]++; lose[y]++;
        }
        dfs(0);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;


int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a <= c && c <= b ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a;i < b;i++)
#define rrep(i,a,b) for(int i = a;i >= b;i--)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << #x << ": " << x << endl;
typedef long long ll;
using namespace std;

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

   int a[5];
   rep(i,0,5){
      cin >> a[i];
   }
   int k;
   cin >> k;
   
   if(a[4] - a[0] <= k){
      cout << "Yay!" << endl;
   }else{
      cout << ":(" << endl;
   }

   return 0;
}

Measured memory_bytes: 256
#include<iostream>

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

int w,h;
int f[20][20];
int ans;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};

void rec(int n,int x, int y){

	if(n >= ans)return;

	rep(i,4){
		int mx = x + dx[i];
		int my = y + dy[i];

		if(f[my][mx] == 1)continue;
		if(0>mx || mx>=w)continue;
		if(0>my || my>=h)continue;

		while(1){
			if(f[my][mx] == 3){
				ans = n;
				return;
			}

			mx += dx[i], my += dy[i];
			if(0>mx || mx>=w)break;
			if(0>my || my>=h)break;

			if(f[my][mx] == 1){
				f[my][mx]=0;
				rec(n+1,mx-dx[i],my-dy[i]);
				f[my][mx]=1;
				break;
			}
		}
	}
}

int main(){

	int sx,sy;

	while(std::cin >> w >> h, (w||h)){

		rep(i,h){
			rep(j,w){
				std::cin >> f[i][j];
				if(f[i][j] == 2){
					sx = j, sy = i;
				}
			}
		}
		ans = 11;
		rec(1,sx,sy);
		if(ans > 10)ans = -1;
		std::cout << ans << std::endl;
	}
	return 0;
}

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

tmp = 0
for i in range(n-1):
    if abs(a_list[i] - a_list[i+1]) > tmp:
        tmp = abs(a_list[i] - a_list[i+1])
        max_index = i

if (a_list[0] + (k-a_list[-1])) > tmp:
    tmp = a_list[0] + (k-a_list[-1])
    max_index = n-1

if max_index != n-1:
    print(a_list[max_index] + (k-a_list[max_index+1]))
else:
    print(a_list[max_index]-a_list[0])




Measured memory_bytes: 26444
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

b = np.zeros(n, dtype='int')

cnt = 0
if n % 2 == 0:
    for i in range(n // 2):
        left_idx = n // 2 - 1 - i
        right_idx = n // 2 + i
        b[left_idx] = 2 * i + 1
        b[right_idx] = 2 * i + 2
    b = b[::-1]
else:
    for i in range(n // 2):
        left_idx = n // 2 - i
        right_idx = n // 2 + 1 + i
        b[left_idx] = 2 * i + 1
        b[right_idx] = 2 * i + 2
    b[0] = n
# print('b', b)

for i in a[[b - 1]]:
    print(i)


Measured memory_bytes: 34208
#include <stdio.h>
#define MAX_N 100
#define DE_MA 1000
#define DE_MI -1000
#define DE_TOTALMAX 10000000
int main() {
  int N;
  int box[MAX_N];

  scanf("%d", &N);
  int i;
  for (i = 0; i < N; i++) {
    scanf("%d", &box[i]);
  }

  int max = DE_MI;
  int min = DE_MA;
  
  /* max, min initialize */
  
  for (i = 0; i < N; i++) {
    max = (max < box[i]) ? box[i] : max;
    min = (min > box[i]) ? box[i] : min;
  }
//  printf("max: %d \n", max);
//  printf("min: %d \n", min);
    

  /* for文で , TOTAL BOXを作成する */
  int total_box[DE_MA - DE_MI + 1] ;
  int N_SEC = DE_MA - DE_MI + 1;
  int avenum;
  int total;
  int min_ID;
  int min_TOTAL = DE_TOTALMAX;
  for (avenum = min; avenum <= max ; avenum++) {
    total = 0;
    for (i = 0; i < N; i++) {
      total += (box[i] - avenum) * (box[i] - avenum);
    }
    //    total_box[avenum - min] = total;

    /* TOTAL の最小値計算も同時に行う */
    if (min_TOTAL > total) {
      min_TOTAL = total;
      min_ID = avenum;
    }
    
//    printf("avenum:%d\t total:%d\n",avenum ,total);
  }


  /* これで，このtotal_boxの最小値を考えればいい */

//  printf("\n-----------------------\n\n");
  printf("%d\n",min_TOTAL);

    
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MAX_V 10000
using namespace std;
int V;                //????????°
vector<int> G[MAX_V]; //??°???????????£??\???????????¨???
int match[MAX_V];     //??????????????°????????¢
bool used[MAX_V];     //DFS??§?????§??????????????????????????°

//u??¨v????????¶????????°?????????????????????
void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

//?¢?????????????DFS??§??¢???
bool dfs(int v){
  used[v] = true;
  for(int i=0; i<G[v].size(); i++){
    int u = G[v][i], w = match[u];
    if(w<0 || !used[w] && dfs(w)){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

//?????¨??°??????????????§??????????????°????±???????
int Bipartite_Matching(){
  int res=0;
  memset(match, -1, sizeof(match));
  for(int v=0; v<V; v++){
    if(match[v] < 0){
      memset(used,0,sizeof(used));
      if(dfs(v)) res++;
    }
  }
  return res;
}


int main(){
  int n,m,l;
  cin>>n>>m>>l;
  for(int i=0,a,b;i<l;i++)cin>>a>>b,add_edge(a,n+b);
  V=n+m;
  cout <<Bipartite_Matching()<<endl;
}

Measured memory_bytes: 3488
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x) {ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);

bool ok(vs &P,int r,int c,int s){
	int oR=0,oc=0,os=0;
	REP(lineno,P.size()){
		string line=P[lineno];
		int num_indent=0;
		REP(chno,line.size()){
			if(line[chno]=='.'){
				num_indent++;
			}else{
				break;
			}
		}
		if(num_indent!=oR*r+oc*c+os*s){
			return false;
		}
		REP(chno,line.size()){
			char c=line[chno];
			switch(c){
			case '(':
				oR++;break;
			case '{':
				oc++;break;
			case '[':
				os++;break;
			case ')':
				oR--;break;
			case '}':
				oc--;break;
			case ']':
				os--;break;
			}
		}
	}
	return true;
}

struct indent{
	int r,c,s;
	indent(int r,int c,int s):r(r),c(c),s(s){}
};

int main(){
	int p,q;
	while(cin>>p>>q,p|q){
		vs P(p);
		REP(i,p){
			cin>>P[i];
		}
		vs Q(q);
		REP(i,q){
			cin>>Q[i];
		}
		vector<indent> valid_indents;
		FOR(r,1,20+1){
			FOR(c,1,20+1){
				FOR(s,1,20+1){
					if(ok(P,r,c,s)){
						valid_indents.push_back(indent(r,c,s));
					}
				}
			}
		}
		int oR=0,oc=0,os=0;
		REP(i,q){
			string line=Q[i];
			set<int> valid_total_indents;
			REP(j,valid_indents.size()){
				int total_indent=0;
				total_indent+=oR*valid_indents[j].r;
				total_indent+=oc*valid_indents[j].c;
				total_indent+=os*valid_indents[j].s;
				valid_total_indents.insert(total_indent);
			}
			if(valid_total_indents.size()==1){
				cout<<(i==0?"":" ")<<*valid_total_indents.begin();
			}else{
				cout<<(i==0?"":" ")<<-1;
			}
			REP(k,line.size()){
				switch(line[k]){
				case '(':
					oR++;break;
				case '{':
					oc++;break;
				case '[':
					os++;break;
				case ')':
					oR--;break;
				case '}':
					oc--;break;
				case ']':
					os--;break;
				}
			}
		}
		cout<<endl;
	}
}

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

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

Measured memory_bytes: 3632
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
bs = [0] * (N + 1)
ws = [0] * (N + 1)
total = float("inf")
left_b = 0
right_w = 0
for i, s in enumerate(S):
    if s == "#":
        left_b += 1
    bs[i + 1] = left_b
for i in reversed(range(N)):
    if S[i] == ".":
        right_w += 1
    ws[i] = right_w

for i in range(N):
    total = min(total, ws[i+1] + bs[i])

print(total)


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

                            typedef long long ll;
                            typedef  double ld;
                            #define rep(i,a,n) for(ll i=(a); i<(n); i++)
                            #define per(i,a,n) for(ll i=(n-1); i>=(a); i--)
                            #define F first
                            #define S second
                            #define maxx(a,b) a=max(a,b)
                            #define minn(a,b) a=min(a,b)
                            #define db(x) cerr<<#x<<" = "<<x<<endl
                            #define N 1111111
                            #define mod 1000000007
                            #define rt return
                            #define inf 12345678908761

                            using namespace std;

                            ll a[3111][3111];

                            int main(){

                                ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

                                //freopen("Ulug'bek","r",stdin);
                                //freopen("Abdimanabov","w",stdout);

                                string q,w; cin>>q>>w;
                                q='1'+q;
                                w='2'+w;
                                int n=q.length();
                                int m=w.length();

                                rep(i,1,n)
                                rep(j,1,m)
                                {
                                    if(q[i]==w[j])maxx(a[i][j],a[i-1][j-1]+1);
                                    else
                                    a[i][j]=max(a[i-1][j],a[i][j-1]);
                                }

                                int x=n-1,y=m-1,ma=a[n-1][m-1];

                                string ans;


                                while(a[x][y]>0)
                                {
                                    if(x>0&&a[x-1][y]==a[x][y])x--;
                                    else
                                    if(y>0&&a[x][y-1]==a[x][y])y--;
                                    else
                                    if(x>0&&y>0&&a[x-1][y-1]==a[x][y]-1)
                                        ans+=q[x],x--,y--;
                                }

                                reverse(ans.begin(),ans.end());
                                cout<<ans;

                            rt 0;
                            }



















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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int H, W;
string S[60];
int x[3] = {-1, 0, 1};
int y[3] = {-1, 0, 1};

int get(int h, int w)
{
    int n = 0;
    REP(i, 3)
    {
        REP(j, 3)
        {
            if (i == 1 && j == 1)
                continue;
            int nh = x[i] + h, nw = y[j] + w;
            if (nh < 0 || nh >= H || nw < 0 || nw >= W)
                continue;
            if (S[nh][nw] == '#')
                n++;
        }
    }
    return n;
}

int main()
{

    cin >> H >> W;
    REP(i, H)
    {
        cin >> S[i];
    }

    REP(h, H)
    {
        REP(w, W)
        {
            if (S[h][w] == '.')
            {
                cout << get(h, w);
            }
            else
            {
                cout << S[h][w];
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
    string n;
    int c = 0;
    cin >> n;
    for(int i = 0; i < 3; i++){
        if(n[i] == '1'){
            c += 1;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;


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

    if (D == 25) {
        cout << "Christmas" << endl;
    }
    else if (D == 24) {
        cout << "Christmas Eve" << endl;
    }
    else if (D == 23) {
        cout << "Christmas Eve Eve" << endl;
    }
    else {
        cout << "Christmas Eve Eve Eve" << endl;
    }
}

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

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (1e10)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);}} premain;

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

#define S_MAX	(5*100100)

void makeM(int N, const string &t, unordered_map<string, int> &m) {
	REP(i, 1<<N) {
		string a, b;
		REP(j, N) {
			if (0 < (i & (1 << j))) {
				a += t[j];
			} else {
				b += t[j];
			}
		}
		m[a + "." + b] += 1;
	}
}

int main() {
	int N;
	string S;

	cin >> N;
	cin >> S;

	string T1 = S.substr(0,N);
	string T2 = S.substr(N);
	reverse(T2.begin(), T2.end());

	unordered_map<string, int> M1, M2;
	makeM(N, T1, M1);
	makeM(N, T2, M2);

	ll cnt = 0;
	for (auto &m : M1) {
		if (M2.count(m.first)) {
			cnt += (ll)m.second * M2[m.first];
		}
	}
	
	print(cnt);
	return 0;
}


Measured memory_bytes: 68468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    int N,M;cin >> N >> M;

    int ans = 0;

    if(N >= 2){
      ans += N * (N-1) / 2;
    }

    if(M >= 2){
      ans += M * (M-1) /2;
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = []
b = []
flag = False
def check(offset=[0, 0]):
    for i in range(m):
        for j in range(m):
            if a[i + offset[0]][j + offset[1]] != b[i][j]:
                return 1
    return 0

for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))

for i in range(n - m + 1):
    for j in range(n - m + 1):
        if check((i,j)) == 0:
            flag = True

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


Measured memory_bytes: 3064
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var s = new Array(N);
  var a=0;
  var b=0;
  var c=0;
  var ba=0;
  var ans=0;
  for(var i=0;i<N;i++){
    s[i]=input[i+1].split("");
    for(var j=0;j<s[i].length;j++){
      if(j==0&&s[i][j]=="B"){
        b++;
        c++;
      }
      if(j==s[i].length-1&&s[i][j]=="A"){
        a++;
        c++;
      }
      if(s[i][j]=="B"&&j>0){
        if(s[i][j-1]=="A"){
          ans++;
        }
      }
      if(c==2){
        ba++;
      }
    }
    c=0;
  }
  ans=ans+Math.min(a,b);
  if(b==ba&&a==ba&&ba!=0){
    ans--;
  }
  

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 23352
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 4e5 + 9, OO = 1e9 + 9;
ll a[N], b[N], z[N+N];
vector<ll> va, vb, vv;

void Z() {
	for(int it: vb)
		vv.push_back(it);
	vv.push_back(-1); // invalid number like $
	for(int it: va)
		vv.push_back(it);
	for (ll i = 1, l = 0, r = 0; i < (int)vv.size(); ++i) {
		if(i <= r)
			z[i] = min(r - i + 1, z[i - l]);
		while(i + z[i] < (int)vv.size() && vv[i + z[i]] == vv[z[i]])
			++z[i];
		if(i + z[i] - 1 > r) {
			r = i + z[i] - 1;
			l = i;
		}
	}
}

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 1; i < n + n; ++i) {
		if(i >= n)
			a[i] = a[i - n];
		va.push_back(a[i] ^ a[i - 1]);
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
		if(i)
			vb.push_back(b[i] ^ b[i - 1]);
	}
	Z();
	for (int i = n; i < n + n; ++i) {
		if(z[i] == n - 1)
			cout << i - n << ' ' << (a[i - n] ^ b[0]) << '\n';
	}
	return 0;
}


Measured memory_bytes: 30440
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define INF 0x3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n" 
#define pb push_back
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define print(v); for(auto x:v) cout<<x<<" "; cout<<endl;
typedef long long int ll;
int main()
{
    fast;
    ll n, m, x;
    cin >> n >> m >> x;
    long long arr[14][14]; long long cost[14];
    for(ll i = 1; i <= n; i++){
        cin >> cost[i];
        for(ll j = 1; j <= m; j++){
            cin >> arr[i][j];
        }
    }

    ll ans = 1e18;
    for(ll mask = 1; mask < (1 << n); mask++){
        // cout << mask << " " << endl;
        ll flag = 0;
        for(ll j = 1; j <= m; j++){
            ll sum = 0;
            for(ll i = 1; i <= n; i++){
                ll k = (mask & (1 << (i - 1)));
                if(k != 0){
                    sum = sum + arr[i][j];
                }
            }
            if(sum < x){
                flag = 1;
                break;
            }
            // cout << "sum: " << sum << endl;
        }
        if(flag == 0){
            ll val = 0;
            for(ll i = 1; i <= n; i++){
                ll k = (mask & (1 << (i - 1)));
                if(k != 0){
                    val += cost[i];
                }
            }
            ans = min(ans, val);
        }
    }
    if(ans == 1e18){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> ivec;
const ll N = 1e9+7;

int main(){
    int n; cin >> n;
    multiset<int> mst;
    rep(i,n){
        int d; cin >> d;
        mst.insert(d);
    }
    int min_n = 0,max_n = 0;
    auto itr = mst.begin();
    rep(i,(n/2)-1)itr++;
    min_n = *itr + 1;
    itr++;
    max_n = *itr;
    cout << max_n - min_n + 1 << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
  int n,ans=0;
  cin >> n;
  vector<int> a(n),b(n),c(n-1);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];
  rep(i,n) ans+=b[i];
  rep(i,n-1){
    if(a[i] + 1 == a[i+1]) ans+=c[a[i] - 1];
  }
  cout << ans << endl;
}








































//以下、ライブラリ
//ユークリッドの互除法

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
}



Measured memory_bytes: 256
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READV(M);
    if(N%2==1)
    {
        FORI(i,1,M+1)
        {
            cout<<i<<" "<<N-i<<endl;
        }
    }
    else
    {
        FORI(i,1,M+1)
        {
            if(i<=(M+1)/2)
            {
                cout<<i<<" "<<N-i+1<<endl;
            }
            else
            {
                cout<<i<<" "<<N-i<<endl;
            }
            
        }
    }
    

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3824
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, a, b = map(int, input().split())

ans = (n // (a + b)) * a + min((n % (a + b)), a)
print(ans)

Measured memory_bytes: 9364
#include <iostream>
using namespace std;
long long n;
long long ans=0;
void dfs(long long x,int a,int b,int c)
{
	if(x>n)
		return;
	if(a&&b&&c)ans++;
	dfs(x*10+3,a+1,b,c);
	dfs(x*10+5,a,b+1,c);
	dfs(x*10+7,a,b,c+1);
}
int main()
{
	cin>>n;
	dfs(0,0,0,0);
	cout<<ans<<endl;
	return 0;
}

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

inline void rd(int &x){
	x=0;char ch=0;int w=0;
	while(!isdigit(ch)) ch=getchar(),w|=ch=='-';
	while( isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	x=w?-x:x;
}
int n;
char s[N];
signed main(){
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;i++){
		if((s[i]=='p') and (s[n-i+1]!='q')) return puts("No"),0;
		if((s[i]=='b') and (s[n-i+1]!='d')) return puts("No"),0;
		if((s[i]=='q') and (s[n-i+1]!='p')) return puts("No"),0;
		if((s[i]=='d') and (s[n-i+1]!='b')) return puts("No"),0;
	} puts("Yes");
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int price_1000,price_500,need_amount;

	scanf("%d %d %d",&price_1000,&price_500,&need_amount);

	int ans = BIG_NUM;
	int num_1000,num_500 = 0,tmp_amount;

	while(true){

		tmp_amount = need_amount-num_500*500;
		if(tmp_amount <= 0){
			ans = min(ans,price_500*num_500);
			break;
		}

		if(tmp_amount%1000 == 0){

			num_1000 = tmp_amount/1000;

		}else{

			num_1000 = tmp_amount/1000+1;
		}

		ans = min(ans,price_1000*num_1000+price_500*num_500);

		num_500++;
	}

	printf("%d\n",ans);

	return 0;
}



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

int main() {
    int N, a, count, cmin = 201;
    cin >> N;
    for(int i = 1; i < N; i++) {
        cin >> a;
        count = 0;
        while(a % 2 == 0) {
            a /= 2;
            count++;
        }
        cmin = min(cmin, count);
    }

    cout << cmin << endl;
}

Measured memory_bytes: 256
#if __has_include("noamoa_atcoder_lib.h")
#include "noamoa_atcoder_lib.h"
#else
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) (x).begin(),(x).end()
namespace atcoder {
	using namespace std;
	using ll = long long;
	using llv = vector<ll>;
	using intv = vector<int>;
	using charv = vector<char>;
	using boolv = vector<bool>;
	using floatv = vector<float>;
	using doublev = vector<double>;
	using stringv = vector<string>;

	constexpr ll MOD7 = 1000000007;
	constexpr ll MOD9 = 1000000009;

	void reverse(string& s){
		reverse(all(s));
	}

	template<typename T>
	void init(vector<T>& v, T initVal = T()){
		for(auto& e : v){
			e = initVal;
		}
	}

	template<typename T>
	void sort(vector<T>& v){
		sort(all(v));
	}
	template<typename T>
	void sortInv(vector<T>& v){
		sort(all(v), greater<T>());
	}

	template<typename T>
	void reverse(vector<T>& v){
		reverse(all(v));
	}

	template<typename T>
	T sum(const vector<T>& v){
		T ret = 0;
		for(const auto& e : v) ret += e;
		return ret;
	}

	template<typename T>
	inline vector<T>& operator+=(vector<T>& v, const T& e){
		v.push_back(e);
		return v;
	}

	template<typename T1, typename T2>
	inline vector<T1>& operator+=(vector<T1>& v1, const vector<T2>& v2){
		for(const auto& e : v2) v1.push_back(e);
		return v1;
	}

	template<typename T>
	void in(vector<T>& v){
		for(auto& e : v) cin >> e;
	}

	template<typename T1, typename T2>
	void in(vector<T1>& v1, vector<T2>& v2){
		for(int i=0;i<v1.size();i++)
			cin >> v1[i] >> v2[i];
	}
	template<typename T1, typename T2, typename T3>
	void in(vector<T1>& v1, vector<T2>& v2, vector<T3>& v3){
		for(int i=0;i<v1.size();i++)
			cin >> v1[i] >> v2[i] >> v3[i];
	}
	template<typename T1, typename T2, typename T3, typename T4>
	void in(vector<T1>& v1, vector<T2>& v2, vector<T3>& v3, vector<T4>& v4){
		for(int i=0;i<v1.size();i++)
			cin >> v1[i] >> v2[i] >> v3[i] >> v4[i];
	}

	template<typename T>
	istream& operator>>(istream &stream, vector<T>& v){
		for(auto& e : v) stream >> e;
		return stream;
	}

	template<typename T>
	void out(const vector<T>& v){
		for(const auto& e : v) cout << e << ' ';
		cout << endl;
	}

	template<typename T>
	void outln(const vector<T>& v){
		for(const auto& e : v) cout << e << endl;
	}

	template<typename T>
	inline set<T>& operator+=(set<T>& v, const T& e){
		v.insert(e);
		return v;
	}

	template<typename T1, typename T2>
	inline set<T1>& operator+=(set<T1>& v1, const set<T2>& v2){
		for(const auto& e : v2) v1.insert(e);
		return v1;
	}

	constexpr ll modPow(ll x, ll n, ll m){ // O(logn)
		if(n == 0) return 1;
		else if(n % 2 == 0) return modPow((x * x) % m, n / 2, m);
		else return x * modPow(x, n - 1, m) % m;
	}
}
using namespace atcoder;
#endif

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

	llv nums(N);
	for(int i=0;i<N;i++){
		nums[A[i]-1]++;
	}
	ll sum = 0;
	for(int i=0;i<N;i++){
		sum += nums[i]*(nums[i]-1)/2;
	}

	for(int k=0;k<N;k++){
		ll n = nums[A[k]-1];
		cout << (sum - n + 1) << endl;
	}
}

Measured memory_bytes: 5760
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, COUT1, COUT2;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[i] = A[i];
	}
	sort(B.begin(), B.end());
	COUT1 = 0;
	COUT2 = 0;

	for (int k = 0; k < N - 1; k++) {
		if (A[k] != B[k]) {
			COUT1++;
		}
	}
	if (COUT1 < 3) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
ll dp[105][2]; 
// dp[a][b]:= 左から a bitまで見て 
// K以下が b=0:確定していない b=1確定している
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N)cin >> A[i];
    rep(i,105)dp[i][0] = dp[i][1] = -1;
    dp[50][0] = 0;
    for(int bit=49;bit>=0;bit--){ // bit bit 目を考える
        ll mask = (1LL<<bit);
        ll num = 0; // bit bit 目が立っている A[i] の個数
        rep(i,N)if(A[i]&mask)num++; // もしもbitが立っていたらnumを加算

        if(dp[bit+1][1]>=0)dp[bit][1] = dp[bit+1][1] + mask*max(num,N-num);
        //if(dp[bit+1][0]>=0){
            if(K&mask){
                // もしも K の bit bit 目が 1 だったならば
                // 1を選んだ場合
                dp[bit][0] = dp[bit+1][0] + mask*(N-num);
                // 0を選んだ場合
                chmax(dp[bit][1],dp[bit+1][0] + mask*num);
            }else{
                dp[bit][0] = dp[bit+1][0] + mask*num; 
            }
        //}
    }
    cout << max(dp[0][0],dp[0][1]) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

#define min(x,y) ( x < y ? x : y)

int main(void){
    int d,n;
    cin >> n >> d;
    double x[20][10];
    double dist;
    int res = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin >> x[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int k=i+1;k<n;k++){
            dist = 0.0;
            for(int j=0;j<d;j++){
                dist += pow((x[i][j] - x[k][j]),2.0);
            }
            dist = sqrt(dist);
            if(dist == ceil(dist))res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("\\s");
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a < b){
			System.out.println("a < b");
		}
		if(a > b){
			System.out.println("a > b");
		}
		if(a == b){
			System.out.println("a == b");
		}

	}

}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    vector<vector<int>> G(N);  // グラフ
    rep(i, M) {
        int tmpA, tmpB;
        cin >> tmpA >> tmpB;
        A.at(i) = tmpA - 1;
        B.at(i) = tmpB - 1;
        G.at(A.at(i)).push_back(B.at(i));
        G.at(B.at(i)).push_back(A.at(i));  // 無向グラフ
    }

    vector<int> seen(N, -1);  // 距離を記録する

    queue<int> que;
    que.emplace(0);  // sから探索する
    seen[0] = 0;
    while (que.size() != 0) {     // 幅優先探索
        int state = que.front();  // 現在の状態
        // cout << state << endl;
        que.pop();
        for (auto next : G[state]) {
            // cout << "next: " << next << endl;
            if (seen[next] == -1) {  // 未探索の時のみ行う
                seen[next] = state + 1;
                que.emplace(next);  //次の状態をqueueへ格納
            }
        }
    }

    bool ok = true;
    rep(i, N) {
        if (seen.at(i) == -1) ok = false;
    }

    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    for (int i = 1; i < N; i++) {
        cout << seen.at(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 11700
from itertools import product

n, a, b = map(int, input().split())

if a > b :
  print(0)
  exit()
elif n == 1:
  if a != b:
    print(0)
    exit()
  else:
    print(1)
    exit()
else:
  print((b-a) * (n-2) + 1)

Measured memory_bytes: 3060
// 二分探索木：挿入
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inoder(Node *u) {
    if (u == NIL) return;
    inoder(u->left);
    printf(" %d", u->key);
    inoder(u->right);
}

void preoder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preoder(u->left);
    preoder(u->right);
}

int main() {
    int n, i, x;
    string com;

    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        cin >> com;
        if(com == "insert") {
            scanf("%d", &x);
            insert(x);
        } else if (com == "print") {
            inoder(root);
            printf("\n");
            preoder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 26752
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int[] am = new int[32];
        int n,i,w,a,b,t;
        String st;
        String[] x;
        w = s.nextInt();
        n = s.nextInt();
        for(i=1;i<=w;i++)am[i]=i;
        for(i=1;i<=n;i++){
            st = s.next();
            x = st.split(",");
            a = Integer.parseInt(x[0]);
            b = Integer.parseInt(x[1]);
            t = am[a];
            am[a] = am[b];
            am[b] = t;
        }
        for(i=1;i<=w;i++)System.out.println(am[i]);
    }
}


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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const int INF = 100001;

vi a;

int main()
{
    int c;
    REP(i, 3)
    {
        cin >> c;
        a.push_back(c);
    }
    sort(ALL(a));
    cout << a[2] - a[0] << endl;
}

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

int main() {
  long H, W;
  cin >> H >> W;
  if (H%3 == 0 || W%3 == 0) {
    cout << 0 << endl;
    return 0;
  }
  long ans = min(H, W);
  for (int i=1; i<H; i++) {
    long Smax = max(i*((W+1)/2), (H-i)*W), Smin = min(i*(W/2), (H-i)*W);
    ans = min(ans, Smax-Smin);
  }
  for (int i=1; i<W; i++) {
    long Smax = max(i*((H+1)/2), (W-i)*H), Smin = min(i*(H/2), (W-i)*H);
    ans = min(ans, Smax-Smin);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384