akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
using namespace std;
int c[105],d[105];
int main()
{
	int n,m;
	cin>>n>>m;
	char a[105][105];
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	for(int i=0;i<n;i++)
		{
			int j;
			for( j=0;j<m;j++)
				if(a[i][j]=='#')
					break;
			if(j==m)
				c[i]=1;
		}
	for(int j=0;j<m;j++)
		{
			int i;
			for( i=0;i<n;i++)
				if(a[i][j]=='#')
					break;
			if(i==n)
			d[j]=1;
		}
	for(int i=0;i<n;i++)
		{
			if(c[i])
			continue;
			for(int j=0;j<m;j++)
			{
				if(d[j])
				continue;
				else 
				cout<<a[i][j];
			}
			cout<<endl;
		}
} 

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<cstring>
#define N 100010
#define int long long
using namespace std;
struct node{
	int nxt,to,w,f;
}road[N];
int head[N],cnt=1;
void add(int u,int v,int m,int w)
{
	road[++cnt]=(node){head[u],v,w,m};
	head[u]=cnt;
	road[++cnt]=(node){head[v],u,-w,0};
	head[v]=cnt;
}
int pre[N],bef[N],dis[N],flow[N];
bool in[N];
queue<int>q;
bool spfa(int s,int t)
{
	memset(dis,127,sizeof(dis));
	memset(flow,127,sizeof(flow));
	memset(in,0,sizeof(in));
	while(!q.empty())q.pop();
	q.push(s);
	dis[s]=0;
	in[s]=true;
	pre[t]=-1;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		in[u]=false;
		for(int i=head[u];i;i=road[i].nxt)
		{
			int v=road[i].to;
			if(road[i].f>0 && dis[v]>dis[u]+road[i].w)
			{
				dis[v]=dis[u]+road[i].w;
				pre[v]=u;
				bef[v]=i;
				flow[v]=min(flow[u],road[i].f);
				if(!in[v])
				{
					in[v]=true;
					q.push(v);
				}
			}
		}
	}
	return pre[t]!=-1;
}
void MCMF(int s,int t,int &maxf,int &minw)
{
	while(spfa(s,t))
	{
		int u=t;
		maxf+=flow[t];
		minw+=flow[t]*dis[t];
		while(u!=s)
		{
			road[bef[u]].f-=flow[t];
			road[bef[u]^1].f+=flow[t];
			u=pre[u];
		}
	}
}
signed main()
{
	int n;
	scanf("%d",&n);
	int s=2*n+5,t=s+1;
	int o1=2*n+1,o2=2*n+2,o3=2*n+3,o4=2*n+4;
	for(int i=1;i<=n;i++)
	{
		int x,y,w;
		scanf("%lld%lld%lld",&x,&y,&w);
		add(s,i,w,0);
		add(i,o1,w,x+y);
		add(i,o2,w,x-y);
		add(i,o3,w,-x+y);
		add(i,o4,w,-x-y);
	}
	
	for(int i=1;i<=n;i++)
	{
		int x,y,w;
		scanf("%lld%lld%lld",&x,&y,&w);
		add(i+n,t,w,0);
		add(o1,i+n,w,-x-y);
		add(o2,i+n,w,-x+y);
		add(o3,i+n,w,x-y);
		add(o4,i+n,w,x+y);
	}
	int ans=0,res=0;
	MCMF(s,t,res,ans);
	printf("%lld",-ans);
	return 0;
}

Measured memory_bytes: 6016
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}


int main()
{
  int N;
  cin>>N;
  int d[100];
  REP(i,N)
  {
    cin>>d[i];
  }
  ll ans=0;
  REP(i,N)
  {
    ans=ans+d[i];
  }
  ans=pow(ans,2);
  REP(i,N)
  {
    ans=ans-pow(d[i],2);
  }
  cout<<ans/2<<endl;

}


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

int main(){
  int player[200005];//心地よさ
  int n;
  long long ans = 0;
  cin >> n;
  rep(i, n){
    cin >> player[i];
  }
  sort(player, player+n);

  rep(i, n-1){
    ans += player[n-1-(i+1)/2];
  }


  cout << ans;
  return 0;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h> 
    //#define M_PI 3.14159265358979323846



using namespace std;

#define rep(i,a,b) for(int i=a;i<b;++i)
#define repb(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define vc vector<char>
#define vld vector<ld>
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
#define vvld vector<vector<ld> >
#define vpii vector<pii>
#define vpll vector<pll>
#define ld long double
#define ll long long
#define sz(a) (ll)a.size()
#define ssortA(arr)   stable_sort(arr.begin(),arr.end())
#define ssortB(arr)   stable_sort(arr.begin(),arr.end(),greater<pair<int,int> >());
#define pii pair<int,int>
#define pll pair<long long,long long>
#define ff first
#define ss second
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define endl "\n" 
#define PI acos(-1.0)
#define GCD(a,b) __gcd(a,b)
#define popcount(x) __builtin_popcountll(x)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fix(f,n) fixed<<setprecision(n)<<f<<endl
#define checkin(ds, a) (ds.find(a)!=ds.end()?1:0)
#define mem(arr)  memset(arr,0,sizeof(arr))
const int M=(int)1e9+7;
int main(){
    int c;cin>>c;cout<<(c^1)<<endl;
}

Measured memory_bytes: 3588
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

int s[100] = {};
int main() {
	char a[3][3];
	string ans = "";
	char unko;
	REP(i, 3)REP(j, 3) {
		cin >> unko;
		if (i == j)ans = ans + unko;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
int main(){
  std::string str;
  std::cin>>str;
  int i;
  i=str.size();
  if(str[0]=='k'&&str[1]=='e'&&str[2]=='y'&&str[3]=='e'&&str[4]=='n'&&str[5]=='c'&&str[6]=='e'){
    std::cout<<"YES"<<std::endl;
  }else if(str[0]=='k'&&str[1]=='e'&&str[2]=='y'&&str[3]=='e'&&str[4]=='n'&&str[5]=='c'&&str[i-1]=='e'){
    std::cout<<"YES"<<std::endl;
  }else if(str[0]=='k'&&str[1]=='e'&&str[2]=='y'&&str[3]=='e'&&str[4]=='n'&&str[i-2]=='c'&&str[i-1]=='e'){
    std::cout<<"YES"<<std::endl;
  }else if(str[0]=='k'&&str[1]=='e'&&str[2]=='y'&&str[3]=='e'&&str[i-3]=='n'&&str[i-2]=='c'&&str[i-1]=='e'){
    std::cout<<"YES"<<std::endl;
  }else if(str[0]=='k'&&str[1]=='e'&&str[2]=='y'&&str[i-4]=='e'&&str[i-3]=='n'&&str[i-2]=='c'&&str[i-1]=='e'){
    std::cout<<"YES"<<std::endl;
  }else if(str[0]=='k'&&str[1]=='e'&&str[i-5]=='y'&&str[i-4]=='e'&&str[i-3]=='n'&&str[i-2]=='c'&&str[i-1]=='e'){
    std::cout<<"YES"<<std::endl;
  }else if(str[0]=='k'&&str[i-6]=='e'&&str[i-5]=='y'&&str[i-4]=='e'&&str[i-3]=='n'&&str[i-2]=='c'&&str[i-1]=='e'){
    std::cout<<"YES"<<std::endl;
  }else if(str[i-7]=='k'&&str[i-6]=='e'&&str[i-5]=='y'&&str[i-4]=='e'&&str[i-3]=='n'&&str[i-2]=='c'&&str[i-1]=='e'){
    std::cout<<"YES"<<std::endl;
  }else std::cout<<"NO"<<std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
#include <algorithm>
#include<set>
#include<map>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_2 100000
#define d9_7 1000000007
int main(void){
  ll n;
  cin>>n;
  cout<<((n)*(n-1))/2<<endl;
  return 0;
}

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



int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a;
  cin>>a;
  int arr[a];
  for(int i=0;i<a;i++)
  cin>>arr[i];
  sort(arr,arr+a);
  int ctr=0;

  for(int i=a-1;i>=1;i--)
  {
    int l=0;int r=i-1;
    while(l<r)
    {
      if(arr[l]+arr[r]>arr[i])
      {
        ctr+=r-l;
        r--;
      }
      else
      l++;
    }
  }
  std::cout << ctr << '\n';
  return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
N, M = map(int, input().split())
dates = [[] for _ in range(10**5+1)]
for i in range(N):
    x,y = map(int, input().split())
    dates[x].append(y)

h = []
heapify(h)
ans = 0
for i in range(1,M+1):
    for b in dates[i]:
        heappush(h,-b)
    if len(h):
        ans -= heappop(h)
print(ans)

Measured memory_bytes: 72352
#include <stdio.h>
int main(void) 
{
    int i = 0, n, a, b, c;
    scanf("%d", &n);
    while (i < n) {
        scanf("%d %d %d", &a, &b, &c);
        if (a * a == b * b + c * c || b * b == a * a + c * c || c * c == a * a + b * b)
            printf("YES\n");
        else
            printf("NO\n");
        i++;
    }
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	int cnt = 0;
	for (int i = 1; i <= N; i++) {
		int a;
		cin >> a;
		if (i % 2 && a % 2) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pf pop_front
#define mp make_pair
using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++)
		cin>>h[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
object Main extends App {
  val in = io.StdIn.readLine.split(' ').map(_.toInt)

  val N = in(0)
  val M = in(1)
  val X = in(2)
  val Y = in(3)

  val xs = io.StdIn.readLine.split(' ').map(_.toInt)
  val ys = io.StdIn.readLine.split(' ').map(_.toInt)

  val boundX = (X +: xs).max
  val boundY = (Y +: ys).min

  val out = if (boundX < boundY) "No War" else "War"

  println(out)
}

Measured memory_bytes: 25536
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	n, m := readInt(), readInt()
	h := make([]int, n)
	for i := range h {
		h[i] = readInt()
	}

	arr := make([]int, n)
	for i := 0; i < m; i++ {
		a, b := readInt()-1, readInt()-1
		if h[a] == h[b] {
			arr[a] = -1
			arr[b] = -1
			continue
		}
		if h[a] > h[b] {
			arr[b] = -1
		} else {
			arr[a] = -1
		}
	}

	ans := 0
	for i := range arr {
		if arr[i] == 0 {
			ans++
		}
	}
	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 5844
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;

ll my_gcd(ll a, ll b){
	return (b==0) ? a : my_gcd(b, a%b);
}

ll my_lcm(ll a, ll b){
	return a*b / my_gcd(a,b);
}

ll factorial(ll a){
	ll ans = 1;
	for(ll i=a; i>0; i--){
		ans *= i;
	}
	return ans;
}

ll pow(ll a, ll b) {
	ll a_powered = 1;
	for (int i=0; i<b; i++) {
		a_powered *= a;
	}
	return a_powered;
}


int main(int argc, char *argv[]){
    int R,G,B,N;
    cin >> R >> G >> B >> N;

    if(R == 1 && G == 1 && B == 1){
        int ans = (N+2)*(N+1)/2;
        cout << ans << endl;
        return 0;
    }

    if(
        (R == 2 && G == 1 && B == 1) ||
        (R == 1 && G == 2 && B == 1) ||
        (R == 1 && G == 1 && B == 2)
    ){
        int ans = 0;
        for(int i=0; i <= N/2; i++){
            ans += N-2*i+1;
        }

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

    int ans=0;
    for(int r=0; r <= N/R; r++){
        for(int g=0; g <= (N-R*r)/G; g++){
            for(int b=0; b <= (N-R*r-G*g)/B; b++){
                int ball_num = R*r + G*g + B*b;
                if(ball_num == N){
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

template<class T> inline bool cmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool cmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll MAXN=1e5+5;
const ll MAXLG=__lg(MAXN)+2;

ll n,x;
ll a[MAXN];
/********** Main()  function **********/
int main()
{
  IOS();
  cin>>n>>x;
  REP(i,n)cin>>a[i];
  sort(a,a+n);
  ll i = 0;
  for(;i<n;i++){
    if(x<a[i])break;
    x -= a[i];
  }
  if(i==n&&x>0)i--;
  cout<<i<<endl;
	return 0;
}


Measured memory_bytes: 256
#!python3


iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = list(map(int, input()))
    K = int(input())
    size = len(N)

    if size < K:
        print(0)
        return

    dp = [[[0]*(size+1) for j in range(2)] for i in range(size+1)]

    dp[0][0][0] = 1
    for i in range(size):
        for less in range(2):
            for k in range(i+1):
                for x in range(10 if less else N[i] + 1):
                    #print((i, less, k), x, (i+1, int(less or x < N[i]), k + (1 if x else 0)))
                    dp[i+1][less or x < N[i]][k + (1 if x else 0)] += dp[i][less][k]
        #print(dp[i+1])

    print(dp[-1][0][K] + dp[-1][1][K])

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3428
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+5;
void allpos(int n){
	for(int i=1;i<n;i++){
		cout<<i<<" "<<i+1<<endl;
	}
}
void allneg(int n){
	for(int i=n;i>1;i--){
		cout<<i<<" "<<i-1<<endl;
	}
}
int a[N];
void solve(){
	int n;
	cin>>n;
	int mn = 1e9;
	int mx = -1e9;
	for(int i=1;i<=n;i++){
		int x; 
		cin>>x;
		a[i] = x; 
		mn = min(mn,x);
		mx = max(mx,x);
	}
	if(mn>=0){
		cout<<n-1<<endl;
		allpos(n);
		return; 
	}
	if(mx<=0){
		cout<<n-1<<endl;
		allneg(n);
		return ;
	}
	if(abs(mx)>=abs(mn)){
		cout<<n+n-1<<endl;
		int id = -1;
		for(int i = 1;i<=n;i++){
			if(a[i]==mx)id = i;
		}
		for(int i=1;i<=n;i++){
			cout<<id<<" "<<i<<endl;
		}
		allpos(n);
		return ;
	}
	else{
		cout<<n+n-1<<endl;
		int id = -1;
		for(int i = 1;i<=n;i++){
			if(a[i]==mn)id = i;
		}
		for(int i=1;i<=n;i++){
			cout<<id<<" "<<i<<endl;
		}
		allneg(n);
		return ;
	
		
	}
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3660
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,W = inpl() 
a = [inpl() for _ in range(n)]
a.sort(key = lambda x:x[1], reverse = True)
a.sort()
b = []
now = a[0][0]
li = []
for i in range(n):
    w,v = a[i]
    if now == w:
        li.append(v)
    else:
        now = w
        b.append(li)
        li = []
        li.append(v)
if li != []: b.append(li)
kind = now - a[0][0] + 1
f = a[0][0]
for i in range(len(b)):
    b[i] = b[i][::-1]

c = [[0] for _ in range(4)]
for i,l in enumerate(b):
    for x in l:
        c[i].append(c[i][-1] + x)
    c[i] = c[i]
# print(c)
ln = [len(x) for x in c]
res = 0
def chk(w,v):
    global res
    if w <= W:
        res = max(res, v)
x,y,z,w = ln
# print(ln)
for i in range(x):
    for j in range(y):
        for k in range(z):
            for l in range(w):
                ww = i*f+j*(f+1)+k*(f+2)+l*(f+3)
                v = c[0][i] + c[1][j] + c[2][k] + c[3][l]
                if ww <= W: res = max(res, v)
                # print(ww,v)
print(res)


Measured memory_bytes: 67816
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

####
def solve(N):
    N %= 10
    if N == 3:
        return 'bon'
    elif N in {0,1,6,8}:
        return 'pon'
    return 'hon'
print solve(rri())


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

int main() {
	int n;
	cin >> n;
	
	string s, t;
	cin >> s >> t;
	
	string ans = "";
	for(int i = 0; i<n; i++) {
		ans += s[i];
		ans += t[i];
	}
	
	cout << ans << endl;
	return 0;
}

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

void dfs(int i, int pre, vector<vector<int>> &rel,vector<bool> &checked){
    bool all_checked = true;
    for (int j : rel[i])
    {
        if(!checked[j]) all_checked = false;
    }
    if(all_checked) return;
    for (int j : rel[i])
    {
        if(j == pre) continue;
        if(!checked[j]){
            checked[j] = true;
            dfs(j,i,rel,checked);
        }
    }    
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> rel(n);
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin>> a >> b >> c;
        rel[a-1].push_back(b-1);
        rel[b-1].push_back(a-1);
    }
    int i = 0;
    int sum = 0;
    vector<bool> checked(n,false);
    bool all_checked = false;
    for (int i = 0; i < n; i++)
    {
        if(!checked[i]){
            checked[i] = true;
            dfs(i,-1,rel,checked);
            sum ++ ;
        }
    }
    cout << sum << endl; 
}

Measured memory_bytes: 14808
#include <cstdio>
#include <cstdlib>
using namespace std;

int top, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop() {
  --top;
  return S[top + 1];
}

int main() {
  int a, b;
  top = 0;
  char s[100];
  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '-') {
      a = pop();
      b = pop();
      push(b - a);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n", pop());
  return 0;
}

Measured memory_bytes: 2760
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = n/2;

		if(n % 2 == 0){
			System.out.println(ans);
		}else{
			System.out.println(ans+1);
		}

	}

	}

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

int main(){
    string a,b;
    cin >> a >> b;
    if(a.size() > b.size() || (a.size() == b.size() && a > b))cout << "GREATER";
    else if(a.size() == b.size() && a == b)cout << "EQUAL";
    else cout << "LESS";
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  while(1){
  int n,al[26]={},max=0,max2=0,b=0,maxal,maxal2,c=0;
  char a;
  cin>>n;
  if(n==0)break;
  for(int i=1;i<=n;i++){
    cin>>a;
    al[a-'A']++;
    if(al[a-'A']>max){
      if(i!=1&&a-'A'!=maxal){
        max2=max;
        maxal2=maxal;
      }
      max=al[a-'A'];
      maxal=(a-'A');
    }
    if(al[a-'A']>max2&&a-'A'!=maxal){
      max2=al[a-'A'];
      maxal2=(a-'A');
    }
    if(max>max2+n-i&&c==0)c=i;
  }
  for(int i=0;i<26;i++){
    if(i==maxal)continue;
    if(al[i]==max)b++;
  }
  a=maxal+'A';
  if(b!=0)cout<<"TIE"<<endl;
  else cout<<a<<" "<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

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

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

	int n, cntP = -1, cntQ = -1, cntT = 1;
	cin >> n;
	vector<int> P(n), Q(n), seq(n);

	for (int i = 0; i < n; i++)
		cin >> P[i];
	for (int i = 0; i < n; i++)
		cin >> Q[i];

	seq = P;
	sort(seq.begin(), seq.end());
	if (P == seq)
		cntP = 0;
	if (Q == seq)
		cntQ = 0;

	while (next_permutation(seq.begin(), seq.end())) {
		if (P == seq)
			cntP = cntT;
		if (Q == seq)
			cntQ = cntT;
		cntT++;
	}

	cout << abs(cntP - cntQ) << endl;
}


Measured memory_bytes: 3668
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  string S;
  cin >> S;
  vector<int64_t> A(N + 1, 0);
  int64_t count_black = 0;
  A[0] = 0;
  for (int64_t i = 1; i <= N; ++i) {
    if (S.c_str()[i - 1] == '#') {
      ++count_black;
    }
    A[i] = count_black;
  }
  int64_t result = INT64_MAX;
  for (int64_t black_start = 1; black_start <= N + 1; ++black_start) {
    const int64_t reverse_left = A[black_start - 1];
    const int64_t reverse_right = N - (black_start - 1) - (A[N] - A[black_start - 1]);
    const int64_t count = reverse_left + reverse_right;
    if (count < result) {
      result = count;
    }
  }
  cout << result << endl;
  return 0;
}


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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}
ll LCM(ll x, ll y){
	return x/GCD(x, y)*y;
}

int main() {
	int a; cin >> a;
	cout << a+a*a+a*a*a << endl;
	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

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

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>

int main(void) {
  int n, k, h[100000], c[100000], i, j, temp;
  scanf("%d %d", &n, &k);
  for(i=0;i<n;i++){
    scanf("%d", &h[i]);
    c[i]=1000000000;
  }
  c[0]=0;
  for(i=1;i<k;i++){
    c[i]=abs(h[i]-h[0]);
  }
  for(i=k;i<n;i++){
    for(j=1;j<=k;j++){
      temp=c[i-j]+abs(h[i]-h[i-j]);
      if(temp<c[i]){
        c[i]=temp;
      }
    }
  }
  printf("%d", c[n-1]);
}

Measured memory_bytes: 896
#if 0
2019.07.08

震惊，这题我竟然一遍过。
要求所有边被覆盖，对于这个条件，考虑用容斥处理，
对于每个边集 E ，钦定 E 不被覆盖后其他边随意的方案数为 f(E) ，
则 E 对答案的贡献为 f(E) * -1^|E| 。

钦定一些边不被覆盖相当于把树切成森林，每颗新的树独立。
考虑 DP ，设 f[u][i] 表示 u 的子树中，
去掉 u 在内的 i 个点的新树（这些点相互配对）的方案。
u -> v 转移时即 f[u][i + j] += f[u][i] * f[v][j] 。
特别地，对于 f[u][0] ，枚举 u 所在的新树大小 i ，f[u][0] -= f[u][i] * g[i] ，
其中 g[i] 表示大小为 i 的新树中随意配对的方案数，
为什么是 -= ？，因为要考虑容斥系数。
#endif
#include <cstdio>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;
inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 5005, mod = 1000000007;
lolong f[maxn][maxn], fu[maxn], g[maxn];
int size[maxn];
std::vector<int> G[maxn];

void dp(int u, int fa) {
	size[u] = 1;
	f[u][1] = 1;
	for(int v : G[u])
		if(v != fa) {
			dp(v, u);
			for(int i = 0; i <= size[u]; i ++) {
				fu[i] = f[u][i];
				f[u][i] = 0;
			}
			for(int i = 0; i <= size[u]; i ++)
				for(int j = 0; j <= size[v]; j ++)
					(f[u][i + j] += fu[i] * f[v][j]) %= mod;
			size[u] += size[v];
		}
	if(f[u][0]) puts("FUCK");
	for(int i = 1; i <= size[u]; i ++)
		(f[u][0] -= f[u][i] * g[i]) %= mod;
}

int main() {
	int n = input();
	for(int i = 1; i < n; i ++) {
		int u = input(), v = input();
		G[u].push_back(v);
		G[v].push_back(u);
	}
	g[0] = 1;
	for(int i = 2; i <= n; i ++)
		g[i] = g[i - 2] * (i - 1) % mod;
	dp(1, 0);
	printf("%lld\n", (mod - f[1][0]) % mod);
}


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

typedef long long ll;
#define mod 1000000007

int main()
{
    double d, t, s;
    cin >> d >> t >> s;

    double t2 = d / s;

    if(t2 <= t)
        cout << "Yes\n";
    
    else
        cout << "No\n";
}

Measured memory_bytes: 3732
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long tot = 0;
		long[] sum = new long[N + 1];
		for(int i=0;i<N;i++){
			sum[i + 1] = sum[i] + A[i];
		}
		
		tot = sum[N];
		long min = (long) 1e18;
		for(int i=0;i<=N;i++){
			long l = sum[i];
			long r = tot - l;
			min = Math.Min(min, Math.Abs(l - r));
		}
		
		Console.WriteLine(min);
		
		
		
	}
	int N;
	long[] A;
	public Sol(){
		N  = ri();
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 35072
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
	  #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
	   ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
		   # #  # # #                   # #      ###### #    # #    # #      #####
	  #    # #   #  #              #    # #      #    # #    # #    # #      #   #
	   ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LL i = 0; i < (n); i++)
#define FOR(in) for(LL i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 
 
LL concate(LL a, LL b)
{
	ostringstream os;
	os <<a <<b;
	istringstream is(os.str());
	LL c;
	is>> c;
	return c;
}
 
 
LL check(char c)
{
	return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';
}
LL mod = 1e9+7;
 
 
int main()
{
	//LL q,t;
	//cin>>t;
	//while(t--)
	//{
	   LL a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
		LL aa[1000];
		LL flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
		LL ma=0, mi=100000000;
		LL mid=0, temp=0, stop=0, start=0;
		double pi= 3.141592653589793;
		double d1=0.0, d2, d3, d4;
		VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
		VS vs, vs1, vs2, vs3, vs4;
		VP vp, vp1,vp2;
		char ch, ch1, ch2[1001];
		string str, str1, str2, str3, str4, str5;
		pair<LL, LL> pa;
		list<LL> li, li1;
		map<LL, LL> mp, mp1;
		set<LL> st;
		map<LL ,LL> :: iterator imll;
		VLL :: iterator ivll;
		set<LL> :: iterator isll;
		VP :: iterator ivp;
 
		
		cin>>str>>str1>>str2;
		putchar(toupper(str[0]));
		putchar(toupper(str1[0]));
		putchar(toupper(str2[0]));
		cout<<endl;

		
		
		
		
	exit()
 
 
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main{
	static Node root;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int i = 0; i < n; i++) {
			String com = scan.next();
			if(com.equals("insert")) {
				int k = scan.nextInt();
				insert(k);
			}else if(com.equals("find")){
				int k = scan.nextInt();
				Node t = find(k, root);
				if(t != null) {
					System.out.println("yes");
				}else {
					System.out.println("no");
				}
			}else if(com.equals("delete")){
				int k = scan.nextInt();
				treeDelete(find(k, root));
			}else {
				inorder(root);
				System.out.println();
				preoder(root);
				System.out.println();
			}
		}
		scan.close();
	}
	static class Node{
		int key;
		Node parent, left, right;
		Node(int key){
			this.key = key;
		}
	}
	static void insert(int k) {
		Node y = null;
		Node x = root;
		Node z = new Node(k);
		while(x != null) {
			y = x;
			if(k < x.key) {
				x = x.left;
			}else {
				x = x.right;
			}
		}
		z.parent = y;
		if(y == null) {
			root = z;
		}else {
			if(z.key < y.key) {
				y.left = z;
			}else {
				y.right = z;
			}
		}
	}
	static Node find(int k, Node x) {
		while(x != null && k != x.key) {
			if(k < x.key) x = x.left;
			else x = x.right;
		}
		return x;
	}
	static Node treeMinimum(Node x) {
		while(x.left != null) x = x.left;
		return x;
	}
	// 次節点の探索
	static Node getSuccessor(Node x) {
		if(x.right != null) return treeMinimum(x.right);
		Node y = x.parent;
		while(y != null && x == y.right) {
			x = y;
			y = y.parent;
		}
		return y;
	}
	static void treeDelete(Node z) {
		Node y;	// 削除する対象
		Node x;	// yの子
		// 削除する節点を決める
		if(z.left == null || z.right == null) {
			y = z;
		}else {
			y = getSuccessor(z);
		}
		// yの子を決める
		if(y.left != null) {
			x = y.left;
		}else {
			x = y.right;
		}
		if(x != null) {
			x.parent = y.parent;
		}
		if(y.parent == null) {
			root = x;
		}else {
			if(y == y.parent.left) {
				y.parent.left = x;
			}else {
				y.parent.right = x;
			}
		}
		if(y != z) {
			z.key = y.key;
		}
	}
	static void inorder(Node u) {
		if(u == null) return;
		inorder(u.left);
		System.out.print(" " + u.key);
		inorder(u.right);
	}
	static void preoder(Node u) {
		if(u == null) return;
		System.out.print(" " + u.key);
		preoder(u.left);
		preoder(u.right);
	}
}


Measured memory_bytes: 201888
import java.util.*;
import java.io.*;
public class Main {
	static Node head, tail, node;
	public static void main(String[] args) throws IOException {
		StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		head = new Node(0);
		tail = new Node(0);
		head.next = tail;
		tail.front = head;
		String command;
		int n, i, x;
		in.nextToken();
		n = (int)in.nval;
		// System.out.println("n = " + n);
		in.nextToken();
		for (i = 0; i < n; i++) {
			command = in.sval;
			// System.out.println("i = " + i + ", n = " + n + ", command = " + command);
			in.nextToken();
			if (command.length() > 6) {
				if (command.charAt(6) == 'F')
					deleteFirst();
				else
					deleteLast();
			} else {
				x = (int)in.nval;
				in.nextToken();
				if (command.charAt(0) == 'i')
					insertNum(x);
				else
					deleteNum(x);
			}
		}
		node = head.next;
		if (node.next != null) {
			System.out.print(node.value);
			node = node.next;
		}
		
		while (node.next != null) {
			System.out.print(" " + node.value);
			node = node.next;
		}
		System.out.println();
	}
	static void insertNum(int x) {
		node = new Node(x);
		node.next = head.next;
		node.next.front = node;
		node.front = head;
		head.next = node;
	}
	static void deleteNum(int x) {
		node = head.next;
		while (node.next != null) {
			if (node.value == x) {
				node.front.next = node.next;
				node.next.front = node.front;
				return;
			}
			node = node.next;
		}
	}
	static void deleteFirst() {
		node = head.next;
		node.next.front = head;
		head.next = node.next;
	}
	static void deleteLast() {
		node = tail.front;
		node.front.next = tail;
		tail.front = node.front;
	}
}

class Node {
	int value;
	Node front;
	Node next;
	Node() {
		value = 0;
		front = null;
		next = null;
	}
	Node(int x) {
		this();
		value = x;
	}
}


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

int main(){
  int H, W;
  string x;
  cin >> H >> W;
  
  for(int i=0 ; i<W+2 ; i++)
    cout << "#";
  cout << endl;
  
  for(int i=0 ; i<H ; i++){
    cin >> x;
    cout << "#" << x << "#" << endl;
  }
  
  for(int i=0 ; i<W+2 ; i++)
    cout << "#";
  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,x,y;
int main(){
	cin>>x>>y;
	if(y&1)printf("No\n");
	else{
		if(y>=2*x&&y<=4*x)printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 3652
from operator import itemgetter
from bisect import bisect_left, bisect_right
import heapq as hp
import sys
input = sys.stdin.readline

#import numpy as np
#import matplotlib.pyplot as plt

'''
def graph_ABC065D(N, max_xy):
    print(N)
    XY = []
    for _ in range(N):
        xi = np.random.randint(0, max_xy)
        yi = np.random.randint(0, max_xy)
        XY.append([xi, yi])
        print(xi, yi)
    return N, XY


def plot(N, XY, max_xy):
    X, Y = zip(*XY)
    plt.scatter(X, Y)
    plt.grid(b=True)
    plt.xlim((0, max_xy))
    plt.ylim((0, max_xy))
    plt.xticks(np.arange(0, max_xy, 1))
    plt.yticks(np.arange(0, max_xy, 1))
    plt.show()
'''

def main():
    N = int(input())
    XY = [list(map(int, input().split())) for _ in range(N)]

    Xs = []
    Ys = []
    for i, (x, y) in enumerate(XY):
        Xs.append((i, x))
        Ys.append((i, y))
    Xs.sort(key=itemgetter(1))
    Ys.sort(key=itemgetter(1))

    Ix, X = zip(*Xs)
    Iy, Y = zip(*Ys)
    # Ix, Iy are indexes of XY
    Rx = [None]*N
    Ry = [None]*N
    for i, (ix, iy) in enumerate(zip(Ix, Iy)):
        Rx[ix] = i
        Ry[iy] = i

    # take nearest 4s
    graph = [[] for _ in range(N)]
    for i, (x, y) in enumerate(XY):
        nexts = set()
        ix = Rx[i]
        if ix != 0:
            nexts.add(Ix[ix-1])
        if ix != N-1:
            nexts.add(Ix[ix+1])
        
        iy = Ry[i]
        if iy != 0:
            nexts.add(Iy[iy-1])
        if iy != N-1:
            nexts.add(Iy[iy+1])
        
        for n in nexts:
            d = min(abs(XY[n][0]-XY[i][0]), abs(XY[n][1]-XY[i][1]))
            graph[i].append((d, n))



    checked = [False for _ in range(N)]
    checked[0] = True 
    q = [] # しまっていく優先度付きキュー
    for d, n in graph[0]:
        hp.heappush(q, (d, n))
    ans = 0

    #print(graph)
    while q:
        nd, np = hp.heappop(q) # 一番距離が近いものを取ってくる
        #print(nd, np, q)
        if checked[np]: # 追加した後の残骸は見ない
            continue
        ans += nd
        #print(ans)
        checked[np] = True
        for d, p in graph[np]:
            if not checked[p]:
                hp.heappush(q, (d, p))

    print(ans)
            

if __name__ == "__main__":
    #print('input data')
    #N = 9
    #max_xy = 20
    #N, XY = graph_ABC065D(N, max_xy)
    #print('answer')
    #main(N, XY)
    #plot(N, XY, max_xy)

    main()


Measured memory_bytes: 124508
#include <bits/stdc++.h>]
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  if(A>=13){
  cout<<B<<endl;
  
  }
  else if(A>=6&&12>=A){
  cout<<B/2<<endl;
  }
  else{
  cout<<0<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
using namespace std;
using ll = long long;
void self_max(int &a,int b){
  a = max(a,b);
}

int main(){
  int ans = 10000000;
  int a,b,c; cin >> a >> b >> c;

  ans = min(a+b,ans);
  ans = min(ans,a+c);
  ans = min(ans,b+c);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
grid = []
for _ in range(h):
    grid.append(input())
dp = [[float("inf") for _ in range(w)] for _ in range(h)]
if grid[0][0] == ".":
    dp[0][0] = 0
else:
    dp[0][0] = 1
for j in range(1,w):
    if grid[0][j-1] == "." and grid[0][j] == "#":
        dp[0][j] = dp[0][j-1] +1
    else:
        dp[0][j] = dp[0][j-1]
for i in range(1,h):
    for j in range(w):
        if j == 0:
            if grid[i-1][j] == "." and grid[i][j] == "#":
                dp[i][j] = dp[i-1][j]+1
            else:
                dp[i][j] = dp[i-1][j]
        else:
            if grid[i-1][j] == "." and grid[i][j-1] == "." and grid[i][j] == "#":
                dp[i][j] = min(dp[i-1][j],dp[i][j-1])+1
            elif grid[i][j-1] == "." and grid[i][j] == "#":
                dp[i][j] = min(dp[i][j-1]+1,dp[i-1][j])
            elif grid[i-1][j] == "." and grid[i][j] == "#":
                dp[i][j] = min(dp[i][j-1],dp[i-1][j]+1)
            else:
                dp[i][j] = min(dp[i-1][j],dp[i][j-1])
print(dp[h-1][w-1])

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for(long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for(long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                                                            \
    (upper_bound((V).begin(), (V).end(), X) -                                  \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                                                               \
    {                                                                          \
        cerr << #v << ':';                                                     \
        for(auto xv : v) cerr << xv << ' ';                                    \
        cerr << endl;                                                          \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) {
    if(a > b) a = b;
    return a > b;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) {
    if(a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* liblary */

/* main */

signed main() {
    ll N;
    cin >> N;
    vector<string> S(N);
    vl P(N);
    vector<tuple<string, ll, ll>> v;
    FOR(i, 0, N) cin >> S[i] >> P[i];
    FOR(i, 0, N) P[i] *= -1;
    FOR(i, 0, N) v.push_back(make_tuple(S[i], P[i], i + 1));
    sort(ALL(v));
    for(auto t : v) cout << get<2>(t) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int c,gx,gy,map[20][20];
void check(int x,int y)
{
  if(map[x][y]==1 ||x>gx ||y>gy)
    return;
  if(x==gx && y==gy)
    {c++;return;}
  check(x+1,y);
  check(x,y+1);
}

int main()
{
  int n,x,y;
  for(;scanf("%d%d",&gx,&gy),gx;)
    {
      scanf("%d",&n);
      for(x=0;x<20;x++)
      for(y=0;y<20;y++)
	map[x][y]=0;
      for(c=0;n--;)
	{
	  scanf("%d %d",&x,&y);
	  map[x][y]=1;
	}
      check(1,1);
      printf("%d\n",c);
    }
  exit(0);
}

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

int main(){
  int asn=0;
  string t;
  cin >> t;
  int n = t.size();
  for(int i=0;i<n;i++){
    if(t.at(i) == '?') cout << 'D';
    else cout << t.at(i);
  }
  cout << endl;
    
}

Measured memory_bytes: 3756
# -*- coding: utf-8 -*-
# abc127/abc127_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    x = [0] * 11
    r, D, x[0] = i2nn()
    for i in range(10):
        x[i + 1] = r * x[i] - D
        print(x[i + 1])
    return

main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OUT(x) cout << x << endl;

ll mod =  1e9 + 7;

int main(){
    int N;
    cin >> N;
    ll power = 1;
    for(int i=1; i<=N; i++){
        power *= i;
        power %= mod;
    }
    OUT(power);
}


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

int lcs(string &x,string &y);

int main()
{
	int q;
	cin >> q;
	for (int i=0;i<q;++i)
	{
		string x,y;
		cin >> x >> y;
		cout << lcs(x,y) << endl;
	}
}

int lcs(string &x,string &y)
{
	const int maxlen=1000+24;
	vector<vector<int>> dp(maxlen,vector<int>(maxlen));

	int lenx=x.size();
	int leny=y.size();
	for (int i=0;i<=lenx;++i)
	{
		dp[i][0]=0;
	}
	for (int j=0;j<=leny;++j)
	{
		dp[0][j]=0;
	}

	for (int i=1;i<=lenx;++i)
	{
		for (int j=1;j<=leny;++j)
		{
			if (x[i-1]==y[j-1])
			{
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else
			{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}

	int maxdp=0;
	for (int j=1;j<=leny;++j)
	{
		maxdp=max(maxdp,dp[lenx][j]);
	}
	return maxdp;
}








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

using namespace std;


#define int long long
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)


using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;


signed main() {

    int num_query;
    scanf("%d", &num_query);

    int command, digit;

    bitset<64> B(0);

    for (int loop = 0; loop < num_query; loop++) {

        scanf("%d", &command);

        switch (command) {
            case 0:
                scanf("%d", &digit);
                printf("%d\n", B.test(digit));
                break;
            case 1:
                scanf("%d", &digit);
                B.set(digit);
                break;
            case 2:
                scanf("%d", &digit);
                B.reset(digit);
                break;
            case 3:
                scanf("%d", &digit);
                B.flip(digit);
                break;
            case 4:
                if (B.all()) {
                    printf("1\n");
                } else {
                    printf("0\n");
                }
                break;
            case 5:
                if (B.any()) {
                    printf("1\n");
                } else {
                    printf("0\n");
                }
                break;
            case 6:
                if (B.none()) {
                    printf("1\n");
                } else {
                    printf("0\n");
                }
                break;
            case 7:
                printf("%d\n", B.count());
                break;
            case 8:
                cout << B.to_ullong() << endl;
                break;
        }
    }

    return 0;
}


Measured memory_bytes: 3220