akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI a(1<<n);
    REP(i,0,1<<n) cin >> a[i];
    sort(all(a));
    VI b(1<<n);
    {
        int cnt = 0;
        REP(i,1,1<<n) {
            if (a[i] != a[i-1]) ++cnt;
            b[i] = cnt; 
        }
    }
    VI cs(1<<n), m(1<<n);
    REP(i,0,1<<n) ++cs[b[i]];

    reverse(all(b));
    if (b[0] == b[1]) {
        cout << "No" << endl;
        return;
    }
    VI ne(1<<n);
    m[b[0]]++;
    REP(i,0,n) {
        int rem = 0;
        RREP(j,0,1<<n) {
            ne[j] = m[j];
            if (rem > 0) {
                int diff = min(cs[j] - ne[j], rem);
                rem -= diff;
                ne[j] += diff;
            }
            rem += m[j];
        }
        if (rem > 0) {
            cout << "No" << endl;
            return;
        }
        REP(j,0,1<<n) {
            m[j] = ne[j];
        } 
    }
    cout << "Yes" << endl;
}

int main() {
    solve();
    
    return 0;
}

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

using namespace std;

int main()
{
    unsigned long long int n,i,cnt=1,sum=0,j;
    cin>>n;
    vector<string> pal(n,"emp");
    for(i=0;i<n;i++)
    {
      cin>>pal[i];
      sort(pal[i].begin(),pal[i].end());
    }
    sort(pal.begin(),pal.end());
    //for(i=0;i<n;i++){cout<<pal[i]<<endl;}
    for(j=0;j<n-1;j++)
    {
     if(pal[j+1]!=pal[j])
     {  //cout<<"count from if "<<cnt<<"and j "<<j<<endl;
       sum+=(cnt*(cnt-1))/2;
       cnt=1;
     }
     else
     { cnt++;
      //cout<<cnt<<endl;
      }
    }
    sum+=(cnt*(cnt-1))/2;
    cout<<sum;
    return 0;
}


Measured memory_bytes: 7296
n, m = map(int, input().split())
ss = []
for i in range(m):
    k, *s = list(map(int, input().split()))
    s = set(s)
    ss.append(s)
p = list(map(int, input().split()))

ans = 0
for i in range(2 ** n):
    f = True
    for k in range(m):
        cnt = 0
        for j in range(n):
            if ((i >> j) & 1 and j+1 in ss[k]):
                cnt += 1
        if cnt % 2 != p[k]:
            f = False
    if f:
        ans += 1
print(ans)

Measured memory_bytes: 42224
#include<bits/stdc++.h>
using namespace std;
int N,M,a[105],i;
int res;
float sum;
int main(){
  cin>>N>>M;
  for(i=0;i<N;i++) {cin>>a[i];res+=a[i];}
  sum=(float)(res*(1.0))/(4*M);
  sort(a,a+N,greater<int>());
 // for(i=0;i<N;i++) cout<<a[i]<<" ";
  for(i=0;i<M;i++) if(a[i]<sum) {cout<<"No";return 0;}
  cout<<"Yes";
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for(int i=0; i < N; i++){
    cin >> A.at(i);
  }
  
  vector<int> B(N);
  B = A;		//AをBにコピー
  sort(B.begin(), B.end());
  
  int a1 = B.at(N-1);
  int a2 = B.at(N-2);
  
  for(int i = 0; i < N; i++){
    if(A.at(i) < a1){
      cout << a1 << endl;
    }else{
      cout << a2 << endl;
    }
  }
  
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn     cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;

int main()
{
    ll n,k,a,b;
    cin>>n>>k;
    map<ll,ll> x;
    rep(i,n) {
        cin>>a>>b;
        x[a]+=b;
    }
    for(auto q:x) {
        k-=q.second;
        if(k<=0)cout<<q.first<<endl,exit(0);
    }
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 100005
 
#define PI 3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007



int main()
{
	FAST;
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	for(ll i = 0; i < n; i ++){
		ll x , y;
		cin >> x >> y;
		x = abs(x);
		y = abs(y);
		if(x*x + y*y <= k*k){
			ans ++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3688
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
	public static void main(String[]args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int m = s.nextInt();
		long result=0;
		Long aux;
		long[]array1=new long[m];
		PriorityQueue<Long> array = new PriorityQueue<>(Collections.reverseOrder());
		
		for(int i =0;i<n;i++) {
			array.add(s.nextLong());		
		}
		for(int i=0;i<m;i++) {
			aux = array.poll();
			aux= (aux/2);
			array.add(aux);
		}
		int a=array.size();
		for(int i=0;i<a;i++) {

			
			result+= array.poll();
		}
		System.out.print("\n"+result);
		
			
		
	}
		
		
		
		
		
		
	}



Measured memory_bytes: 61240
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//Hang in there!

using namespace std;


int main() {
	vector<char>data(3);
	for (int i = 0; i < 3; i++) {
		cin >> data[i];
	}
	sort(data.begin(), data.end());
	if(data[0] == 'a' && data[1] == 'b' && data[2] == 'c') {
		cout << "Yes" << endl;
	}
	else {
	cout << "No" << endl;
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int map[100001];

int main( void )
{
	int t;
	cin >> t;
	while(t--) {
		int n, k;
		cin >> n >> k;
		--n;
		int prev, now;
		cin >> prev;
		for(int i=0; i < n; ++i) {
			cin >> now;
			map[i] = now - prev;
			prev = now;
		}
		sort(map, map+n);
		n = n - k + 1;
		long sum = 0;
		for(int i=0; i < n; ++i) sum += map[i];
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1252
N = int(input())
s = [int(input()) for _ in range(N)]
ans = sum(s)
if ans % 10 == 0:
    s.sort()
    for i in s:
        if i % 10 != 0:
            print(ans - i)
            exit()
    print(0)
else:
    print(ans)


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int n;
int x[20],y[20],p[20];
ll ans[20];
ll dist[20];
void dfs(int k,int cnt){
	if(k==n){
		ll sum=0;
		rep(i,0,n)sum+=dist[i]*p[i];
		ans[cnt]=min(ans[cnt],sum);
		return;
	}
	//素通り
	int temp[20];
	rep(i,0,n)temp[i]=dist[i];
	dfs(k+1,cnt);
	//x座標
	rep(i,0,n)dist[i]=min(temp[i],abs(x[i]-x[k]));
	dfs(k+1,cnt+1);
	//y座標
	rep(i,0,n)dist[i]=min(temp[i],abs(y[i]-y[k]));
	dfs(k+1,cnt+1);
}


int main(){
	scanf("%d",&n);
	rep(i,0,n)scanf("%d%d%d",x+i,y+i,p+i);
	rep(i,0,n)dist[i]=min(abs(x[i]),abs(y[i]));
	rep(i,0,n)ans[i]=INF;
	dfs(0,0);
	rep(i,0,n+1)printf("%lld\n",ans[i]);
}

Measured memory_bytes: 1732
#include<stdio.h>

int A[100000],n;


int partition(int p, int r);



  int main(){
    int i,a;

    scanf("%d",&n);
    
    for(i=0;i<n;i++)scanf("%d",&A[i]);

    a=partition(0,n-1);

    for(i=0;i<n;i++){
      
      if(i)printf(" ");
      
      if(i==a)printf("[");
      
      printf("%d",A[i]);
      
      if(i==a)printf("]");
    }
    printf("\n");

    return 0;
  }


int partition(int p, int r){
  int x,i,j,t;
  
  x=A[r];
  
  i=p-1;
  
  for(j=p;j<r;j++){
    
    if(A[j]<=x){
      
      i++;
      
      t=A[i];
      
      A[i]=A[j];
      
      A[j]=t;
      
    }
    
  }
  
    t=A[i+1];
    
    A[i+1]=A[r];
    
    A[r]=t;
    
    return i+1;
    
}



Measured memory_bytes: 2220
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
using namespace std;

typedef struct _node {
	int num;
	_node *prev;
	_node *next;
} NODE ;

NODE *top, *last;

NODE* initnode(void) {
	return (NODE*)malloc(sizeof(NODE));
}

void deletefirst(void) {
	top->next = (top->next)->next;
}

void deletelast(void) {
	if (top->next == last->next) {
		top->next = NULL;
		last->next = NULL;
	}
	else {
		NODE *ptr = (last->next)->prev;
		ptr->next = NULL;
		last->next = ptr;
	}
}

void insertnode(int x) {
	NODE *newnode = initnode();
	newnode->num = x;
	if (top->next == NULL) {
		newnode->next = NULL;
		last->next = newnode;
	}
	else {
		newnode->next = top->next;
		(top->next)->prev = newnode;
	}
	newnode->prev = NULL;
	top->next = newnode;
}

void deletenode(int x) {
	NODE *ptr = top;
	while (ptr->next != NULL) {
		if ((ptr->next)->num == x) {
			if (ptr == top) {
				deletefirst();
				break;
			} 
			else if ((ptr->next)->next == NULL){
				deletelast();
				break;
			}
			else {
				NODE *ptr2 = (ptr->next)->next;
				ptr->next = ptr2;
				ptr2->prev = ptr;
				break;
			}
		}
		ptr = ptr->next;
	}
}

int main(void) {
	int N, x;
	char sw[15];
	top = initnode();
	last = initnode();
	top->next = NULL;
	last->next = NULL;
	cin >> N;
	for (int i = 0; i < N; i++) {
		scanf("%s" ,sw);
		if (sw[0] == 'i') {
			scanf("%d", &x);
			insertnode(x);
		}
		else if (strlen(sw) == 6) {
			scanf("%d", &x);
			deletenode(x);
		}
		else if (sw[6] == 'F') {
			deletefirst();
		}
		else if (sw[6] == 'L') {
			deletelast();
		}
		else {
			cout << "Error" << endl;
		}
	}
	NODE *ptr = top;
	while ((ptr->next)->next != NULL) {
		cout << (ptr->next)->num << " ";
		ptr = ptr->next;
	}
	cout << (ptr->next)->num << endl;
	return 0;
}


Measured memory_bytes: 37608
#include <iostream>
#include <cstdio>
using namespace std;
string s1,t;
int ans;
int fzx_min(int x,int y) {
        return x<y ? x : y;
}
signed main()
{
        cin>>s1>>t;
        ans=2147483647;
        int len=s1.size()-t.size();
        for (int i=0; i<=len; i++) {
                int sum=0,len1=t.size();
                for (int j=i; j<i+len1; j++) if (s1[j]!=t[j-i]) sum++;
                ans=fzx_min(sum,ans);
        }
        cout<<ans<<"\n";
        return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int count(int x) {
    int ans = 0;
    while(x > 0) {
        if(x%2==0) {
            x /= 2;
            ans++;
        }
        else break;
    }
    return ans;
}
int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int mi = 1001001001;
    rep(i, n) {
        mi = min(mi, count(a[i]));
    }
    cout << mi;
}


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

int main()
{
    int n, k[10000] = {0};

    while( cin >> n )
    {
        if( n == 0 )
            break;
        bool j = false;
        int sum = 0;
        for( int i = 0; i < n; i++ )
        {
            cin >> k[i];
            if( k[i] == 0 )
                sum++;
            if( k[i] >= 2 )
                j = true;
        }
        if( j == true )
            cout << n - sum + 1 << endl;
        else
            cout << "NA" << endl;
    }
    return 0;
}



Measured memory_bytes: 3140
import random

random.seed(0)

def calc_point(point_list, interval, choice):
    point = 0

    for i, day in enumerate(interval):
        point -= c[i] * day

    point += point_list[choice - 1]

    return point

d = int(input())

c = list(map(int,input().split()))

s = []

for _ in range(d):
    temp = list(map(int,input().split()))

    s.append(temp)

choices = [(i % 26) + 1 for i in range(d)]

interval = [0] * 26
result = 0

for i in range(d):
    choice = choices[i]

    interval = [x + 1 for x in interval]

    interval[choice - 1] = 0

    result += calc_point(s[i], interval, choice)

for _ in range(10000):
    temp_choices = choices.copy()
    temp_result = 0

    temp_choices[random.randint(0, d - 1)] = random.randint(1, 26)
    temp_choices[random.randint(0, d - 1)] = random.randint(1, 26)
    temp_choices[random.randint(0, d - 1)] = random.randint(1, 26)

    interval = [0] * 26
    
    for i in range(d):
        choice = temp_choices[i]

        interval = [x + 1 for x in interval]

        interval[choice - 1] = 0

        temp_result += calc_point(s[i], interval, choice)

    if temp_result > result:
        choices = temp_choices
        result = temp_result

for choice in choices:
    print(choice)

Measured memory_bytes: 91756
ss = input()
lr = [1]
ans = [0] * len(ss)

for s in ss[1:]:
  if lr[-1] > 0:
    if s == "R":
      lr[-1] += 1
    else:
      lr.append(-1)
  else:
    if s == "L":
      lr[-1] -= 1
    else:
      lr.append(1)

i = 0
for num in lr:
  is_r = (num > 0)
  num = abs(num)
  half = num // 2
  if is_r:
    i += num
    ans[i-1] += num - half
    ans[i] += half
  else:
    ans[i-1] += half
    ans[i] += num - half
    i += num

print(" ".join([str(c) for c in ans]))



Measured memory_bytes: 11252
#include<bits/stdc++.h>
#define N 1001
using namespace std;
struct Node{int x,y;};
deque<Node>q;
int sx,sy,tx,ty,n,m,dis[N][N],dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
char str[N][N],vis[N][N];
int main(void){
	int i,dir,j;Node x,y;memset(dis,0x3f,sizeof dis);
	scanf("%d%d%d%d%d%d",&n,&m,&sx,&sy,&tx,&ty);
	for(i=1;i<=n;++i)scanf("%s",str[i]+1);
	q.push_back({sx,sy}),dis[sx][sy]=0;
	while(!q.empty()){
		x=q.front(),q.pop_front();
		if(vis[x.x][x.y])continue;vis[x.x][x.y]=1;
		for(dir=0;dir<4;++dir){
			y={x.x+dx[dir],x.y+dy[dir]};
			if(y.x&&y.x<=n&&y.y&&y.y<=m&&str[y.x][y.y]^'#'&&dis[y.x][y.y]>dis[x.x][x.y])dis[y.x][y.y]=dis[x.x][x.y],q.push_front(y);
		}
		for(i=-2;i<=2;++i){
			for(j=-2;j<=2;++j){
				y={x.x+i,x.y+j};
				if(y.x>=1&&y.x<=n&&y.y>=1&&y.y<=m&&str[y.x][y.y]^'#'&&dis[y.x][y.y]>dis[x.x][x.y]+1)dis[y.x][y.y]=dis[x.x][x.y]+1,q.push_back(y);
			}
		}
	}
	printf("%d\n",dis[tx][ty]^0x3f3f3f3f?dis[tx][ty]:-1);
}


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

main(){
  long num,gcd,i;
  
  scanf("%ld",&num);
  
  // 約数を探す
  gcd = (long)sqrt((long)num) + 1;
  while(num%gcd!=0){
    gcd--;
  }
  
  if(gcd!=1)
    printf("%ld",gcd+num/gcd-2);
  else
    printf("%ld",num-1);
  
}


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

int h, w, k;

int hashcount(vector<vector<char> > m) {
  int total = 0;
  rep(i, h) {
    rep(j, w) {
      if (m[i][j] == '#') total++;
    }
  }
  return total;
}

bool at_position(int num, int pos) {
  bool bit = num & (1 << pos);
  return bit;
}

int main() {
  cin >> h >> w >> k;

  vector<vector<char> > ma(h);

  rep(i, h) {
    rep(j, w) {
      char c;
      cin >> c;
      ma[i].push_back(c);
    }
  }

  int result = 0;

  for (int bh = 0; bh < (1 << h); bh++) {
    for (int bw = 0; bw < (1 << w); bw++) {
      vector<vector<char> > m(h);
      rep(hii, h) {
        rep(wii, w) { m[hii].push_back(ma[hii][wii]); }
      }

      rep(hi, h) {
        rep(wi, w) {
          if (at_position(bh, hi)) {
            m[hi] = vector<char>(w, '.');
          }
          if (at_position(bw, wi)) {
            rep(hii, h) { m[hii][wi] = '.'; }
          }
        }
      }
      if (hashcount(m) == k) result++;
    }
  }

  cout << result;

  return 0;
}

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

int binary_search(const vector<int> vec, const int key) {
	auto solve = [&] (int index) {
		if(vec[index] > key) return true;
		else return false;
	};
	int ok = vec.size();	// 解が存在する値
	int ng = -1;	// 解が存在しない値
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		if(solve(mid)) {
			ok = mid;
		} else {
			ng = mid;
		}
	}
	return ok;
}


int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) cin >> c[i];
	sort(all(a));
	sort(all(b));
	sort(all(c));
	ll ans = 0;
	
	ll sum = 0;
	vector<ll> wa(n);
	rep(i, n) {
		sum += lower_bound(all(a), b[i]) - a.begin();
		wa[i] = sum;
	}
	rep(i, n){
		int bc = lower_bound(all(b), c[i]) - b.begin();
		if(bc <= 0) continue;
		ans += wa[bc-1];
	}
	
	cout << ans << endl;
	return 0;
}

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

vector<int> P;

int root(int v){ //根を返す
    if(P[v] == v) return v;
    else return root(P[v]);
}

bool is_same_set(int a, int b){ // 同じならtrue
    return root(a) == root(b);
}

void unite(int a, int b){ // aの根をbの根にくっつける
    P[root(a)] = root(b);
}

int main(){
    int n; cin >> n;
    P.resize(n); //　Pは作りかけの森を想定する
    for(int i = 0; i < n; i++){
        P[i] = i;
    }
    vector<tuple<int, int, int>> vec; //<コスト,始点, 終点>を格納する配列
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            int a; cin >> a;
            if(a >= 0 && i < j){
                vec.push_back(make_tuple(a, i, j));
            }
        }
    }
    sort(vec.begin(), vec.end()); //コスト順にソート
    int ans = 0;
    for(auto v: vec){
        int cost = get<0>(v), str = get<1>(v), end = get<2>(v);
        if(is_same_set(str, end)) continue; //繋がっている
        //もし繋がっていなければ
        ans += cost; // コストを足す
        unite(str, end); //つなげてあげる
    }
    cout << ans << endl;
}


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

int a[500002];
int ans[500002];
int last[500002];
vector<pair<int, int> > v[500002];
int ft[500002];
void update(int i, int v){
    for(;i<=500000;i+=(i&-i)) ft[i] += v;
}
int query(int i){
    int ans = 0;
    for(;i>0;i-=(i&-i)) ans+=ft[i];
    return ans;
}
int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    for(int i=1;i<=q;i++){
        int l, r;
        scanf("%d%d", &l, &r);
        v[r].emplace_back(make_pair(l, i));
    }

    for(int i=1;i<=n;i++){
        if(last[a[i]] == 0) update(i, 1);
        else{
            update(last[a[i]], -1);
            update(i, 1);
        }
        for(int j=0;j<v[i].size();j++){
            int l = v[i][j].first, idx = v[i][j].second;
            ans[idx] = query(i) - query(l-1);
        }
        last[a[i]] = i;
    }


    for(int i=1;i<=q;i++) printf("%d\n", ans[i]);
}

Measured memory_bytes: 33236
N = int(input())
A = list(map(int, input().split()))
ans = 0
B = []
C = []
maA = max(A) + N -1
for k in range(N):
  if A[k] + k <= maA:
    B.append(A[k]+k)
  if -A[k] + k >0:
    C.append(-A[k]+k)
B.sort()
C.sort()

c = 0
b = 0
while b < len(B) and c < len(C):
  if B[b] == C[c]:
    s = 0
    t = 0
    j = float('inf')
    k = float('inf')
    for j in range(b, len(B)):
      if B[b] == B[j]:
        s += 1
      else:
        break
    for k in range(c, len(C)):
      if C[c] == C[k]:
        t +=1
      else:
        break
    ans += s*t
    b = j
    c = k
    continue
  elif B[b] > C[c]:
    c += 1
  else:
    b += 1
#print(B)
#print(C)
print(ans)

Measured memory_bytes: 32960
def main():
    S = [s for s in input()]
    T = [t for t in input()]
    L = len(S)
    M = len(T)
    flag = 0
    ans = []
    for i in range(L-M+1):
        P = list(S)
        tmp = list(S[i:i+M])
        cnt = 0
        num = tmp.count('?')
        for j in range(M):
            if tmp[j] != '?' and tmp[j] != T[j]:continue
            elif tmp[j] == T[j]:
                cnt += 1
        if cnt == M-num:
            flag = 1
            for k in range(M):
                P[i+k] = T[k]
            ans.append(P)
            
    if flag:
        pnt = []
        while ans:
            X = ans.pop()
            for i in range(L):
                if X[i] == '?':
                    X[i] = 'a'
            pnt.append(X)
        pnt.sort()
        print(''.join(pnt[0]))
    else:
        print('UNRESTORABLE')

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
N = int(input())
cuisine = []
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    ans -= b
    cuisine.append(a+b)
cuisine = sorted(cuisine, reverse=True)
for i in range(N):
    if i % 2 == 1:
        continue
    ans += cuisine[i]
print(ans)


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

bool check(int i)
{
  return (i == 4 || i == 6 || i == 9 || i == 11);
}

bool check2(int i)
{
  return (i == 2);
}

int main()
{
  int x, y;
  cin >> x >> y;
  if (check(x) && check(y))
    cout << "Yes" << endl;
  else if (check(x) || check(y))
    cout << "No" << endl;
  else if (check2(x) && check2(y))
    cout << "Yes" << endl;
  else if (check2(x) || check2(y))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
ch = []
for _ in range(M):
    b, c = map(int, input().split())
    ch.append([c, b])

A.sort()
ch.sort(reverse = True)


n = -1
result = 0
fin = 0
for c, b in ch:
    if fin == 1:
        break

    n += b

    if n >= N:
        for num in A[n-b+1:]:
            if c > num:
                result += c
            else:
                result += num
            fin += 1
        break

    if c < A[n]:
        for i, j in enumerate(A[n-b+1:]):
            if c < j:
                result += c*i + sum(A[n-b+i+1:])
                fin += 1
                break
    else:
        result += b * c


if not fin == 1:
    result += sum(A[n+1:])



print(result)


Measured memory_bytes: 24088
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
a=get_i
ans=0
cnt=1
flag=false
(N-1).times do|i|
  if a[i]==a[i+1]
      flag=true
      cnt+=1
  else
      if flag
          ans+=cnt/2
          cnt=1
          flag=false
      end
  end 
end

ans+=cnt/2
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n,w;
    cin>>n>>w;
    vector<ll>w1;
    vector<ll>v1;
    for(ll i=0;i<n;i++)
    {
        ll x;
        ll y;
        cin>>x>>y;
        w1.push_back(x);
        v1.push_back(y);
    }
    ll a[n+1][w+1];
      for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=w;j++)
        {
            if(i==0||j==0)
                a[i][j]=0;
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=w;j++)
        {
                if( j<w1[i-1])
                    a[i][j]=a[i-1][j];
                    else
                   {
                       a[i][j]=max(a[i-1][j-w1[i-1]]+v1[i-1],a[i-1][j]);
                       
                    }
        }
        
    }
    cout<<a[n][w];
   
    }


    



Measured memory_bytes: 79104
n, k = map(int,input().split())
w = [int(input()) for _ in range(n)] 

def aa(m):
    g = c = 0 
    for i in w:
        g += i
        if g > m:
            c += 1
            g = i
            if c >= k:return 0
    return 1

l = max(w)
r = sum(w)

while l<r:
    m = (l+r)//2
    if aa(m):r = m
    else:l = m+1
print(r)
        


Measured memory_bytes: 9556
#include<stdio.h>

int main()
{
	int h, w, i, j;

	while (1){
		scanf("%d %d", &h, &w);

		if (h == 0 && w == 0) return 0;

		for (i = 1; i <= h; i++){
			for (j = 1; j <= w; j++)
				printf("#");
			printf("\n");
		}
		printf("\n");
	}
	return 0;

}

Measured memory_bytes: 572
#include <vector>
#include <algorithm>
#include <queue>

struct Edge {
	int src, dst;
	Edge(int src = 0, int dst = 0) : src(src), dst(dst) {}
};

template <typename Cost>
struct WeightedEdge : Edge {
	Cost cost;
	WeightedEdge(int src, int dst, Cost cost) : Edge(src, dst), cost(cost) {}
	bool operator < (const WeightedEdge<Cost> &rhs) const {
		return cost > rhs.cost;
	}
};

template <class Edge>
class Graph {
public:
	Graph(){}
	Graph(int n) : graph_(n) {}
	int size() const {
		return graph_.size();
	}
	void addEdge(const Edge &e){
		graph_[e.src].push_back(e);
	}
	std::vector<Edge>& operator [] (int i){
		return graph_[i];
	}
	const std::vector<Edge>& operator [] (int i) const {
		return graph_[i];
	}
private:
	std::vector<std::vector<Edge> > graph_;
};


template <typename Cost, Cost INF = 1e9>
class Dijkstra : Graph<WeightedEdge<Cost> >{
public:
	typedef WeightedEdge<Cost> EdgeType;
	typedef Graph<EdgeType> GraphType;
	using GraphType::size;
	using GraphType::addEdge;
	
	Dijkstra(){}
	Dijkstra(int n) : Graph<EdgeType>(n) {}
	void addEdge(int src, int dst, Cost cost){
		addEdge(EdgeType(src, dst, cost));
	}
	void solve(int s){
		int n = size();
		dist_.assign(size(), INF);
		prev_.assign(size(), -1);
		std::priority_queue<EdgeType> pq;
		dist_[s] = 0;
		pq.push(EdgeType(-1, s, 0));
		while (!pq.empty()){
			EdgeType c = pq.top(); pq.pop();
			if (dist_[c.dst] < c.cost) continue;
			prev_[c.dst] = c.src;
			for (int i = 0; i < (*this)[c.dst].size(); i++){
				EdgeType &e = (*this)[c.dst][i];
				if (dist_[e.dst] > c.cost + e.cost){
					dist_[e.dst] = c.cost + e.cost;
					pq.push(EdgeType(e.src, e.dst, c.cost + e.cost));
				}
			}
		}
	}
	Cost getDist(int t){
		return dist_[t];
	}
	std::vector<int> getPath(int t){
		std::vector<int> path;
		for (int v = t; v != -1; v = prev_[v]){
			path.push_back(v);
		}
		std::reverse(path.begin(), path.end());
		return path;
	}
private:
	std::vector<Cost> dist_;
	std::vector<int> prev_;
};


#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;

int main()
{
	int n, m, r;
	scanf("%d %d %d", &n, &m, &r);
	
	Dijkstra<int, INF> dijkstra(n);
	
	for (int i = 0; i < m; i++){
		int s, t, d;
		scanf("%d %d %d", &s, &t, &d);
		dijkstra.addEdge(s, t, d);
	}
	
	dijkstra.solve(r);
	for (int i = 0; i < n; i++){
		int c = dijkstra.getDist(i);
		if (c == INF) puts("INF");
		else printf("%d\n", c);
	}
}

Measured memory_bytes: 14680
import sys
from collections import deque

input = sys.stdin.readline


def dfs(N):
    alphabet = "abcdefghij"
    stack = deque(["a"])
    while stack:
        s = stack.pop()
        if len(s) == N:
            print(s)
            continue
        suffixes = []
        for al in alphabet:
            suffixes.append(al)
            if al not in s:
                break
        for suffix in reversed(suffixes):
            stack.append("".join((s, suffix)))


def main():
    N = int(input())

    dfs(N)


if __name__ == "__main__":
    main()


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

namespace ITP1_5_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<int[]>();
            string input;
            while ((input = Console.ReadLine()) != "0 0")
                list.Add(input.Split(' ').Select(x => Convert.ToInt32(x)).ToArray());
            foreach (var l in list)
            {
                for (int height = 0; height < l[0]; height++)
                {
                    bool patis;
                    if (height % 2 == 0) patis = true;
                    else patis = false;
                    for(int width = 0; width < l[1]; width++)
                    {
                        if (patis) Console.Write("#");
                        else Console.Write(".");
                        patis = !patis;
                    }
                    Console.WriteLine();
                }                   
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  int ans = 0;
  int a[5];
  for(int i = A ; i <= B; i++){
    int n = i;
    for(int j = 0; j < 5; j++){
      a[j] = n % 10;
      n /= 10;
    }
    if(a[0]  == a[4] && a[1] == a[3]){
      ans ++;
    }
  }
  cout << ans << endl;
  
  
  
  return 0;
}

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

const int MAXN = 50;
int n , m , dep , cnt , dfn[ MAXN + 5 ] , low[ MAXN + 5 ];
vector< int > Graph[ MAXN + 5 ];

void Tarjan( int u , int fa ) {
	dfn[ u ] = low[ u ] = ++ dep;
	for( int i = 0 ; i < Graph[ u ].size( ) ; i ++ ) {
		int v = Graph[ u ][ i ];
		if( !dfn[ v ] ) {
			Tarjan( v , u );
			low[ u ] = min( low[ u ] , low[ v ] );
			if( low[ v ] > dfn[ u ] ) cnt ++;
		}
		else if( v != fa )
			low[ u ] = min( low[ u ] , dfn[ v ] );
	}
}

int main( ) {
	scanf("%d %d",&n,&m);
	for( int i = 1 , u , v ; i <= m ; i ++ ) {
		scanf("%d %d",&u,&v);
		Graph[ u ].push_back( v );
		Graph[ v ].push_back( u );
	}
	for( int i = 1 ; i <= n ; i ++ )
		if( !dfn[ i ] ) Tarjan( i , 0 );
	printf("%d\n", cnt );
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include <stdio.h>
#include <iostream>

using namespace std;

const int NUM[4] = { 1,9,7,4 };


int main() {
	int iNum[4] = { 0 };
	bool bNum[4] = { false };
	int total = 0;

	for (int j = 0; j < 4; j++) {
		scanf("%d", &iNum[j]);

		if((0 <= iNum[j]) && (iNum[j] <= 9)){
			for (int i = 0; i < 4; i++) {
				if (iNum[j] == NUM[i]) {
					if (bNum[i] == false) {
						bNum[i] = true;
						total++;
					}
					
				}
			}
		}
	}

	if (total == 4) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}

	return 0;
}

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

int main(){
int N,L;
  cin>>N>>L;
 vector<string>S(N);
  for(int i=0; i<N; i++){
   cin>>S[i]; }
  
  sort(S.begin(), S.end());
  
  for(int i=0; i<N; i++){
   cout<<S[i];
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <numeric>
#include <set>

#define MOD 1000000007
#define INF 2000000000
#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define FOR(YY, yy) for(long long yy = 0; yy < YY; ++yy)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;
typedef vector<pair<int, pair<int, int> > > vpip;
typedef vector<bool> vb;
typedef priority_queue<int> pqi;

int main(int argc, char **argv)
{
    ios::sync_with_stdio(); cin.tie(0);
    int N; cin >> N;

    cout << (int)pow(N, 3) << endl;

    return 0;
}

//cikisir



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

#define MAX_N 100

typedef long long ll;

// int N = 4;
// int A[MAX_N] = {1, 4, 6, 3};
int N;
int A[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A, A + N);
    printf("%d\n", abs(A[N - 1] - A[0]));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define ull unsigned ll
#define pll pair<ll, ll>
#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout);
#define M 1000000007
#define N 200000
#define INF 101111111111111
using namespace std;
main(){
    FAST;
    ll a, b;
    scanf("%lld %lld", &a, &b);
    if(a > 9 || b > 9) printf("-1\n");
    else printf("%lld\n", a*b);
}

Measured memory_bytes: 256
s = input()

a = s[0]
b = s[1]
c = s[2]
d = s[3]

if(a == b and b == c and c == d): 
 print('No')
elif(a == b and c == d): 
 print('Yes')
elif(a == c and d == b): 
 print('Yes')
elif(a == d and c == b): 
 print('Yes')
else:
 print('No')




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

typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPM(i,n) for(ll i=(n-1); 0=<i; i--)
#define VI vector<int>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());

int main(void){
    int N,M;
    int flag = 0;
    //標準入力
    cin >> N >> M;

    vector<double> score(N);
    REP(i,N)
    {
        cin >> score.at(i); 
        //cout << score.at(i) << endl;
    }

    ll sum = accumulate(score.begin(), score.end(),0LL);

    //debug
    // cout << fixed;
    // cout << "border:" << setprecision(2) << (double)sum/(4*M) << endl;

    REP(i,N)
    {
        if( score.at(i) < (double)sum/(4*M) )score.at(i) = 0;
    }

    V_SORT_D(score)

    //debug
    // REP(i,N)
    // {
    //     cout << "i:" << i << " " << score.at(i) << endl;
    // }

    REP(i,M)
    {
        if(score.at(i) == 0)
        {
            flag = 1;
            break;
        }
    }

    if(flag == 1)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
<?php
list($x, $y) = ints();
$s = ['1' => 300000, '2' => 200000, '3' => 100000];
$b = 400000;
echo $x === 1 && $y === 1 ? $s[$x] + $s[$y] + $b : ($s[$x] ?? 0) + ($s[$y] ?? 0);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16080
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000001
#define LINF 1000000000000000001

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

int a,b;
int main(){
	cin >> a>>b;
	cout << (a+b)/2 + ((a+b)%2 != 0) << endl;
	
	return 0;
}

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

int main() {
  int n, d, x;
  cin >> n >> d >> x;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  
  x += n;
  for(int i = 0; i < n; i++) {
    for (int j = 1; j <= 100; j++) {
      if (j * a[i] +1 <= d) {
        x++;
      }
      else {
        break;
      }
    }
  }
  
  cout << x << endl;
}

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



int main(){
int N;
  cin >> N;
int min=100000;
  int a,b;
  for(int i=1;i<=N/2;i++){
    
   a=i;
   b=N-i;
    int x=0,y=0;
    while(a>0){
    x+=a%10;
      a/=10;
    }
    while(b>0){
     y+=b%10;
      b/=10;
    }
    
  if(x+y<min)min=x+y;
  }
cout << min << endl;

}

Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;

int sumofdigits(int n){
    int sum =0;
    while(n>0){
        sum += n%10;
        n /=10;
    }
    return sum;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,ans=INF;
    cin>>n;
    for(int i=1;i<n;i++){
        ans=min(ans,sumofdigits(i)+sumofdigits(n-i));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back

using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

const int inf=1000000007;
struct Seg{
	int mn[1<<18],lz[1<<18],s;
	void Init(int n){
		s=1;
		while(s<n)s*=2;
		fill(mn,mn+s*2,0);
		fill(lz,lz+s*2,0);
	}
	int NodeMin(int i){
		return mn[i]+lz[i];
	}
	void Propagate(int i){
		lz[i*2]+=lz[i];
		lz[i*2+1]+=lz[i];
		mn[i]+=lz[i];
		lz[i]=0;
	}
	void Add(int b,int e,int l,int r,int i,int v){
		if(e<=l||r<=b)
			return;
		if(b<=l&&r<=e){
			lz[i]+=v;
			return;
		}
		Propagate(i);
		Add(b,e,l,(l+r)/2,i*2,v);
		Add(b,e,(l+r)/2,r,i*2+1,v);
		mn[i]=min(NodeMin(i*2),NodeMin(i*2+1));
	}
	void Add(int b,int e,int v){
		Add(b,e,0,s,1,v);
	}
	int Get(int b,int e,int l,int r,int i){
		if(e<=l||r<=b)
			return inf;
		if(b<=l&&r<=e)
			return NodeMin(i);
		Propagate(i);
		return min(Get(b,e,l,(l+r)/2,i*2),Get(b,e,(l+r)/2,r,i*2+1));
	}
	int Get(int b,int e){
		return Get(b,e,0,s,1);
	}
} seg;

const int Nmax=334893;
struct Pos{
	int x,y;
} ps[Nmax];
int n,m,k;

struct Query{
	int y,b,e,v;
	bool operator<(const Query& rhs)const{
		return y<rhs.y;
	}
} qs[Nmax];


pii GetRange(int y){
	int b=abs(y);
	int e=(n-1)+(m-1)-abs(y-((m-1)-(n-1)))+1;
	return pii(b,e);
}

bool Solve(int s){
	REP(i,k){
		qs[i*2]=Query{ps[i].y-s,max(0,ps[i].x-s),min(n+m,ps[i].x+s+1),1};
		qs[i*2+1]=Query{ps[i].y+s+1,max(0,ps[i].x-s),min(n+m,ps[i].x+s+1),-1};
	}
	qs[k*2]=Query{inf,0,0,0};
	sort(qs,qs+2*k+1);
	//for even
	{
		auto modify=[](int& v){
			if(v&1)v++;
		};
		seg.Init(n+m);
		int lastY=-(n-1);
		modify(lastY);
		REP(i,2*k+1){
			Query q=qs[i];
			modify(q.y);
			modify(q.b);
			modify(q.e);
			if(lastY<q.y){
				pii u=GetRange(lastY),b=GetRange(q.y-1);
				if(lastY<=0&&0<=q.y-1)
					u.first=0;
				if(lastY<=(m-1)-(n-1)&&(m-1)-(n-1)<=q.y-1)
					u.second=(m-1)+(n-1)+1;
				modify(u.first);
				modify(u.second);
				modify(b.first);
				modify(b.second);
				if(seg.Get(min(u.first,b.first)/2,max(u.second,b.second)/2)==0)
					return true;
			}
			seg.Add(q.b/2,q.e/2,q.v);
			lastY=q.y;
		}
	}
	//for odd
	{
		auto modify=[](int& v){
			if(!(v&1))v++;
		};
		seg.Init(n+m);
		int lastY=-(n-1);
		modify(lastY);
		REP(i,2*k+1){
			Query q=qs[i];
			modify(q.y);
			modify(q.b);
			modify(q.e);
			if(lastY<q.y){
				pii u=GetRange(lastY),b=GetRange(q.y-1);
				if(lastY<=0&&0<=q.y-1)
					u.first=0;
				if(lastY<=(m-1)-(n-1)&&(m-1)-(n-1)<=q.y-1)
					u.second=(m-1)+(n-1)+1;
				modify(u.first);
				modify(u.second);
				modify(b.first);
				modify(b.second);
				if(seg.Get(min(u.first,b.first)/2,max(u.second,b.second)/2)==0)
					return true;
			}
			seg.Add(q.b/2,q.e/2,q.v);
			lastY=q.y;
		}
	}
	return false;
}

int main(){
	n=read(),m=read(),k=read();
	REP(i,k){
		int x=read(),y=read();
		ps[i]=Pos{x+y,y-x};
	}
	int l=-1,r=n+m;
	while(r-l>1){
		int mid=(r+l)/2;
		if(Solve(mid))
			l=mid;
		else
			r=mid;
	}
	cout<<r<<endl;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }

int n;

int main()
{
  int c = 0;
  cin >> n;
  forn(i,n) {
    int p; cin >> p;
    if (p != i+1) c++;
  }

  if (c <= 2)
    cout << "YES\n";
  else
    cout << "NO\n";

  return 0;
}


Measured memory_bytes: 256
dice = list(map(int,input().split()))
x = list(input())

def move(x):
    if x == "N":
        dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]

    elif x == "W":
        dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]

    elif x == "E":
        dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]

    elif x == "S":
        dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]

for i in range(len(x)):
    move(x[i])
print(dice[0])


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

#define rep(i,n)  for(int i = 0; i < (n); i++)
using vi = vector<int>;
using ll = long long;
const int inf = 1<<30;

int main(){
  int e;
  while(cin >> e, e){
    int m = inf;
    rep(z,101) rep(y,1001){
      int x = e - z*z*z - y*y;
      if(0 <= x){
	m = min(m, x+y+z);
      }
    }
    cout << m << endl;
  }
}


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int N;
	int ans = 0;

	cin >> N;

	int h,hl;
	int cnt = 0;
	cin >> hl;
	for (int ni = 1; ni < N; ni++){
		cin >> h;
		if (h <= hl) cnt++;
		else{
			if (cnt > ans) ans = cnt;
			cnt = 0;
		}
		hl = h;
	}
	if (cnt > ans) ans = cnt;

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


	return 0;
}



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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> s(M);
  vector<int> p(M);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int tmp;
      cin >> tmp;
      tmp--;
      s[i].push_back(tmp);
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 0; i < (1 << N); i++) {
    bool flag = true;
    for (int j = 0; j < M; j++) {
      int sum = 0;
      for (auto e : s[j]) {
        if (i & (1 << e)) sum++;
      }
      if (sum % 2 != p[j]) {
        flag = false;
        break;
      }
    }
    ans += (flag ? 1 : 0);
  }

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

Measured memory_bytes: 256
fun main(args:Array<String>?): Unit {
    val n = readLine()!!.trim().toInt()
    if (n == 1){
        println("! 1")
        return
    }
    val maxi = (2 .. n).maxBy{i ->
        println("? 1 $i")
        readLine()!!.trim().toInt()
    }!!
    val distance = (1 .. n).map{i ->
        println("? $maxi $i")
        readLine()!!.trim().toInt()
    }.withIndex().sortedBy(IndexedValue<Int>::value).map{it.index + 1}
    println("! ${distance.joinToString(" ")}")
}


Measured memory_bytes: 47440
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static long MOD = 1000000007;
	public static void main(String[] args) {
		int i,j,k;
		Scanner sc = new Scanner(in);
		long n = parseLong(sc.next());
		sc.close();
		long cnt = 0;
		if(n%2==0) {
			long l = 10;
			long tmp=0;
			while((tmp=n/l)>0) {
				cnt+=tmp;
				l*=5;
			}
		}
		out.println(cnt);
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
 
using P = pair<int,int>;
using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////

void solve(){
  ini(N); out(N*N*N);
}

Measured memory_bytes: 256