akhauriyash/Code-Regression huggingface dataset:
N = int(input())
P = list(map(int, input().split()))

cnt = 0
prev = 0

# 数列の各要素を「1,2,3,4,…,N」と比較し、異なっている箇所をカウントする
for i in range(N):
    if P[i] != i + 1:
        cnt += 1

# カウント結果が2箇所以内ならOK（1回のswapで昇順にできる）
if cnt <= 2:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
N=int(input())
A=list(map(int,input().split(" ")))
B=list(map(int,input().split(" ")))
C=list(map(int,input().split(" ")))

ans=0
for i in range(N):
    ans+=B[A[i]-1]
    if i<N-1:
        if A[i+1]==A[i]+1:
            ans+=C[A[i]-1]

print(ans)

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

int main(){
  int N;
  if(scanf("%d", &N) == EOF) exit(1);
  int A[N];
  for(int i = 0; i < N; i++){
    if(scanf("%d", &A[i]) == EOF) exit(1);
  }
  
  int s = 0;
  for(int i = 0; i < N; i++){
    s += A[i];
  }
  int sum = s / 2;
  
  for(int i = 0; i < (N-1)/2; i++){
    sum -= A[2*i];
  }
  //この時のsumの値*2が、N番目の山に降った雨量
  
  int ans2[N];
  ans2[N-1] = sum;
  ans2[0] = A[N-1] - ans2[N-1];
  for(int i = 1; i < N-1; i++){
    ans2[i] = A[i-1] - ans2[i-1];
  }
  
  for(int i = 0; i < N; i++){
    printf("%d ", ans2[i] * 2);
  }
  
  return 0;
}

Measured memory_bytes: 2048
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]v = new int[N];
    int[]c = new int[N];
    
    int ans = 0;
    for(int i=0; i<N; i++){
        v[i] = sc.nextInt();
}
    for(int i=0; i<N; i++){
        c[i] = sc.nextInt();
}
    for(int i=0; i<N; i++){
    if(v[i]>c[i]){
        ans += v[i]-c[i];
    }
}
    System.out.println(ans);
 }
}

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

int main() {
    int n;
    string S;
    cin >> n;
    cin >> S;
    int c=0;
    for(int i=0; i<n-1; i++) {
        if(S[i] != S[i+1]) c++;
    }
    cout << c+1 << endl;
    return 0;
}

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

int main() {
  long N,K;
  cin >> N >>K;
  vector<long> a(100001);
  //vector<int> b(N);
  for(int i=0;i<N;i++){
    long m,l;
    cin >> m>>l;
    a[m]+=l;
    }
    long c=0;
  for(int i=0;i<100001;i++){
    c +=a[i];
    if(c>=K){
        cout <<i<<endl ;
        return 0;
    }
  }

}


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

int main()
{
	string s;
	cin >> s;
	vector<string> t{"dream","dreamer","erase","eraser"};
	reverse(s.begin(),s.end());
	for(int i = 0;i<4;i++)
	{
		reverse(t[i].begin(),t[i].end());
	}
	int now = 0;
	while(now!=s.size())
	{
		bool find = false;
		for(int i = 0;i<4;i++)
		{
			if(s.substr(now,t[i].size())==t[i])now+=t[i].size(),find=true;
		}
		if(find==false)
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


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

int t[110000];
int x[110000];
int y[110000];

int main()
{
  int N;
  cin >> N;
  
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  
  rep(i, N)
  {
    cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
  }
  
  bool is_can = true;
  rep(i, N)
  {
    int dt = t[i + 1] - t[i];
    int dist = abs(x[i + 1] - x[i]) + abs(y[i+1] - y[i]);
    if (dt < dist)
    {
      is_can = false;
    }
    
    if ((dt % 2) != (dist % 2))
    {
      is_can = false;
    }
  }
  
  if (is_can)
  {
    printf("Yes");
  }
  else
  {
    printf("No");
  }

  return 0;
}


Measured memory_bytes: 1408
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;

const int kx[8] = {-2, -2, -1, 1, -1, 1, 2, 2}, ky[8] = {1, -1, -2, -2, 2, 2, -1, 1}; //knight
const int dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dy8[8] = {0, 1, 0, -1, -1, 1, -1, 1}; //king
const int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

bool gridCheck(int x, int y,int n, int m) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

int main(){
        _
        int h,w; cin >> h >> w;
        string board[100];
        for(int i = 0; i<h; i++){
            cin >> board[i];
        }

        for(int i = 0; i<h; i++){
            for(int j = 0; j<w; j++){
                if(board[i][j]=='#')continue;

                    int cnt = 0;
                    for(int d = 0; d<8; d++){
                        int ni = i+dx8[d];
                        int nj = j+dy8[d];
                        if(gridCheck(ni, nj,h,w) and board[ni][nj]=='#'){
                            cnt++;
                        }
                    }
                board[i][j] = char(cnt+'0');
            }
        }

        for(int i = 0; i<h; i++)cout<<board[i]<<endl;


return 0;
}



Measured memory_bytes: 3664
#----------------------------------------------------------
P = 10**9 + 7
N = 100001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b or a<0 or b<0:
        return 0 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n=int(input())
x=list(map(int,input().split()))
s = [0] * n
for i in range(n):
    s[i] = x[i] + (s[i-1] if i>0 else 0)
ans=0

for i in range(n-1):
    t = (x[n-1]-x[n-2-i])%P
    t = (t * (fac[n-1]*inv[i+1])%P)%P
    ans=(ans+t)%P
for i in range(1, n-1):
    t = (s[n-2] - s[i-1] - s[n-2-i])%P
    p = (((fac[n-1] * inv[i])%P) * inv[i+1])%P
    ans = (ans + (t*p)%P)%P

print(ans%P)


Measured memory_bytes: 65728
N = int(input())
s = [(input()) for _ in range(N)] + ['0']
M = int(input())
t = [(input()) for _ in range(M)]
s.sort(reverse=True)
sc = 0
ans = 0
for i in range(N) :
    sc += 1
    if s[i] == s[i+1] :
        continue
    tc = t.count(s[i])
    ans = max(ans,sc-tc)
    sc = 0

print(ans)

Measured memory_bytes: 9204
#include <stdio.h>

int main()
{
  int i;
  int H, A[1000000];
  
  scanf("%d", &H);             // ??????????????????????????? H
  for(i = 1; i < H+1; i++)
    scanf("%d", &A[i]);        // ??????????????????????????? H???

  for(i = 1; i < H+1; i++)
    {
      printf("node %d: key = %d, ", i, A[i]);
      if(i != 1) printf("parent key = %d, ", A[i/2]);
      if(i*2 <= H) printf("left key = %d, ", A[i*2]);
      if(i*2+1 <= H) printf("right key = %d, ", A[i*2+1]);
      printf("\n");
    }
  return 0;
}

Measured memory_bytes: 608
n = int(input())
cnt = 0
d = {}
a_list = list(map(int,input().split()))
for i in a_list:
    d.setdefault(i,1)
    d[i] += 1
for i in d:
    if d[i]-1 >= i:
        cnt += abs(d[i]-1-i)
    else:
        cnt += d[i]-1
        
print(cnt)

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

int main(void){
int a,b,c;
int result=0;

cin >> a >> b >> c;

if(a > b){
 if(a > c){
  result = a*10+b+c;
 }else{
    result = c*10+a+b;
}
}else{
  if(b > c){
    result = b*10+a+c;
  }else{
    result = c* 10+a+b;
 }
}

cout << result  << endl;
return 0;
}


Measured memory_bytes: 256
import math
N,M = map(int,input().split())
n = max(N,M)
m = min(N,M)
if abs(N-M) > 1:
  print(0)
  exit()
 
ncnt = math.factorial(n) % 1000000007
 
if abs(N-M) == 0:
  mcnt = 2 * ncnt
else:
  mcnt = math.factorial(m)
print(ncnt*mcnt % 1000000007)

Measured memory_bytes: 10216
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  string N; cin >> N;
  int sum = 0,sum2 = 0;
  int len = N.length();
  for ( int i = 0; i < len; i++ ) {
    sum += N[i] - '0';
  }
  int ans = sum;
  int sum3;
  for ( int i = 0; i < len-1; i++ ) {
    sum2 += N[i]-'0';
    if ( N[i] == '0' ) continue;
    sum3 = sum2-1;
    sum3 += (len-i-1)*9;
    ans = max(ans,sum3);
  }

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


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

namespace AtTest.HCPCvirtual6
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nx = ReadInts();
            int n = nx[0];
            int x = nx[1];
            int[] ms = new int[n];
            int sum = 0;
            for(int i = 0; i < n; i++)
            {
                ms[i] = ReadInt();
                sum += ms[i];
            }
            x -= sum;
            Array.Sort(ms);
            WriteLine(n + x / ms[0]);
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<P> a(n);
  vector<P> b(n);
  rep(i, n) {
    cin >> a[i].fr;
    a[i].sc = i;
  }
  rep(i, n) {
    cin >> b[i].fr;
    b[i].sc = i;
  }

  sort(all(a));
  sort(all(b));

  // Check the sorted state. In each i, a[i] <= b[i] must be satisfied.
  rep(i, n) {
    if (a[i].fr > b[i].fr) {
      cout << "No" << endl;
      return 0;
    }
  }

  // Check if the i exists in which a[i+1] <= b[i].
  for (ll i = 0; i + 1 < n; ++i) {
    if (a[i+1].fr <= b[i].fr) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  // Check the count of cycles. We treat the cycles as the connected components.
  vector<ll> p(n); // p[i] .. The parent of i.
  rep(i, n) {
    p[a[i].sc] = b[i].sc;
  }
  // Count the length of a cycle whith include 0.
  ll x = 0;
  ll len = 0;
  do {
    x = p[x];
    ++len;
  } while (x != 0);

  if (len == n) { // Only 1 cycle exists, whose length is n.
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n,k,R,S,P;
    string t;
    ll point = 0;
    cin >> n >> k >> R >> S >> P >> t;
    vector<int> a(n);
    vector<int> pnt(3);
    pnt[0] = R;
    pnt[1] = S;
    pnt[2] = P;
   
    rep(i,n){
        if(t[i] == 'r'){
            point += P;
            a[i] = 2;
        }
        else if(t[i] == 's'){
            point += R;
            a[i] = 0;
        }
        else if(t[i] == 'p'){
            point += S;
            a[i] = 1;
    }
    }
    for(int i=0; i+k<n; i++){
        if(a[i] == a[i+k]){
            point -= pnt[a[i]];
            a[i+k] = -1;
        }
    }
    cout << point <<endl;
    }

Measured memory_bytes: 896
import java.util.*;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; ++i)
			a[i] = sc.nextInt();
		sc.close();
		Arrays.sort(a);
		int ans = a[n - 1] - a[0];
		System.out.println(ans);
	}

}


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

using namespace std ;

int main() {

  int a, b, c; 
  cin >> a >> b >> c ;
  for (int i = min(a, b); i >= 1; --i) {
    if (a%i == 0 && b%i == 0) {
      --c ;
    if (c==0) {
      cout << i << endl;
      return 0;
      }
    }
  }
}

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

using namespace std;

set<int>water;

int apx, apa;
int zhx, zahar;

int a, b, c, d, e, f;

void solve()
{
    int i, j, apa, zahar;
    int mx = f / 100;
    int apaax = 0;
    for(i = 0; i <= mx; i ++)
    {
        for(j = 0; j <= mx; j ++)
        {
            if(i * a + j * b <= mx)
            {
                water.insert((i * a + j * b) * 100);

                apaax = max(apaax, (i * a + j * b) * 100);
            }
        }
    }

    for(i = 0; i <= f; i ++)
    {
        for(j = 0; j <= f; j ++)
        {
            zahar = i * c + j * d;
            int needed = (zahar / e) * 100 + ((zahar % e) != 0) * 100;

            if(needed > apaax)
                continue;

            set<int>::iterator it = water.lower_bound(needed);

            if(it != water.end())
            {
                apa = (*it);

         //   if(apa == 100)
        //    printf("AVEM %d %d\n", apa, zahar);

                if(apa + zahar <= f)
                {
                    if(apx == 0 || zhx == 0)
                    {
                        apx = apa;
                        zhx = zahar;
                    }

                    if((100 * zahar) * (apx + zhx) > (100 * zhx) * (apa + zahar))
                    {
                        zhx = zahar;
                        apx = apa;
                    }
                }
            }
        }
    }
}

int main()
{
    scanf("%d%d", &a, &b);
    scanf("%d%d", &c, &d);
    scanf("%d%d", &e, &f);

    solve();

    if(zhx == 0)
    {
        apx = a * 100;
    }

    printf("%d %d\n", apx + zhx, zhx);

    return 0;
}


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

int main()
{
	int k, a, b;
	scanf("%d", &k);
	scanf("%d %d", &a, &b);
	
	for (int i = 0;; i++) {
		if (i > b) {
			printf("NG\n");
			break;
		}
		else if ((!(i % k)) && ((a <= i) && (i <= b))) {
			printf("OK\n");
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3692
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  vector<int> h,dp;
  cin>>n;
  h.assign(n,0);
  dp.assign(n+2,0);
  for(int i=0;i<n;i++){
     cin>>h[i];
  }
  dp[n-1]=0;
  dp[n-2]=abs(h[n-2]-h[n-1]);
  for(int i=n-3;i>=0;i--){
    dp[i]=min(dp[i+1]+abs(h[i]-h[i+1]),dp[i+2]+abs(h[i]-h[i+2]));
  }
  cout<<dp[0]<<endl;
  return 0;
}


Measured memory_bytes: 1024
# AOJ 0630: Microwave
# Python3 2018.7.2 bal4u

a, b, c, d, e = [int(input()) for i in range(5)]
if   a < 0 and b < 0: ans = c*(b-a)
elif a > 0 and b > 0: ans = e*(b-a)
else:                 ans = c*(-a)+d+e*b
print(ans)


Measured memory_bytes: 5604
a1,b1=map(int,input().split())
a2,b2=map(int,input().split())
a3,b3=map(int,input().split())
a4,b4=map(int,input().split())

if a1==1:
    d1=6000
if a1==2:
    d1=4000
if a1==3:
    d1=3000
if a1==4:
    d1=2000
    
c1=d1*b1

if a2==1:
    d2=6000
if a2==2:
    d2=4000
if a2==3:
    d2=3000
if a2==4:
    d2=2000
    
c2=d2*b2

if a3==1:
    d3=6000
if a3==2:
    d3=4000
if a3==3:
    d3=3000
if a3==4:
    d3=2000
    
c3=d3*b3

if a4==1:
    d4=6000
if a4==2:
    d4=4000
if a4==3:
    d4=3000
if a4==4:
    d4=2000
    
c4=d4*b4

print(c1)
print(c2)
print(c3)
print(c4)




Measured memory_bytes: 5600
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
    int n,k;cin>>n>>k;
    vector<int> h(n);
    rep(i,0,n-1)cin>>h[i];
    vector<int> dp(n, 1001001001);
    dp[0]=0;
    rep(i,0,n-2){
        rep(j,1,k){
            if(i+j>=n)break;
            
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n, l_i, r_i; cin >> n;
    int count = 0;
    for (int i=0;i<n;i++){
        cin >> l_i >> r_i;
        count += (r_i - l_i) + 1;
    }
    cout << count << endl; 
}

Measured memory_bytes: 256
def detect(n,c):
    if n%2 and c.pop(0) != 1:
        return False
    for i in range(1,n,2):
        if c[i] != 2:
            return False
    else:
        return True

N = int(input())

count = [0 for x in range(N)]
for x in map(int,input().split()):
    count[x] += 1

if detect(N,count):
    print((2**(N>>1)) % 1000000007)
else:
    print(0)

Measured memory_bytes: 11224
i = int(input())
nexti = 0
nextii = 0
ans = str()
nextans = str()


while i > 0:
  nexti = i // 26
  mod = i % 26
  if mod == 0:
    nextans = "z" + ans
    nextii = nexti-1
    nexti = nextii
  elif mod == 1:
    nextans = "a" + ans
  elif mod == 2:
    nextans = "b" + ans
  elif mod == 3:
    nextans = "c" + ans
  elif mod == 4:
    nextans = "d" + ans
  elif mod == 5:
    nextans = "e" + ans
  elif mod == 6:
    nextans = "f" + ans
  elif mod == 7:
    nextans = "g" + ans
  elif mod == 8:
    nextans = "h" + ans
  elif mod == 9:
    nextans = "i" + ans
  elif mod == 10:
    nextans = "j" + ans
  elif mod == 11:
    nextans = "k" + ans
  elif mod == 12:
    nextans = "l" + ans
  elif mod == 13:
    nextans = "m" + ans
  elif mod == 14:
    nextans = "n" + ans
  elif mod == 15:
    nextans = "o" + ans
  elif mod == 16:
    nextans = "p" + ans
  elif mod == 17:
    nextans = "q" + ans
  elif mod == 18:
    nextans = "r" + ans
  elif mod == 19:
    nextans = "s" + ans
  elif mod == 20:
    nextans = "t" + ans
  elif mod == 21:
    nextans = "u" + ans
  elif mod == 22:
    nextans = "v" + ans
  elif mod == 23:
    nextans = "w" + ans
  elif mod == 24:
    nextans = "x" + ans
  elif mod == 25:
    nextans = "y" + ans
  ans = nextans
  i = nexti
print(ans)


Measured memory_bytes: 9320
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef long long int64;

typedef double float64;
typedef long double float128;

const int kMaxN = 1e5+5, kInf = 0x3f3f3f3f;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vector<int> els(n);
    for (auto& itr : els) {
        cin >> itr;
    }

    sort(els.begin(), els.end(), [](auto& a, auto& b) { return a > b; });
    int ans[2] = {0, 0};
    for (int i = 0; i < n; i += 1) {
        ans[i & 1] += els[i];
    }

    cout << ans[0] - ans[1] << '\n';
    return 0;
}


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

vector<vector<ll>> f;
vector<vector<ll>> p;

ll n,output=-INF;

void dfs(ll time,bool OPEN,vector<bool> &open){//time:何番目の時間帯まで調べたか　OPEN:timeの時間帯に開いているか　
	if(time==10){
		bool all_close=true;//joisinoの店が全て閉まっていることは許されない
		for(ll i=0;i<10;i++){
			if(open[i]!=false){all_close=false;break;}
		}
		if(all_close){return;}


		ll answer=0;
		for(ll i=0;i<n;i++){//店iについて
			ll how_many_one=0;//共通の時刻は何個か
			for(ll j=0;j<10;j++){
				if(f[i][j] && open[j]){how_many_one++;}
			}
			answer+=p[i][how_many_one];
		}
		output=max(output,answer);

		return;
	}

	if(OPEN){open[time]=true;}
	else{open[time]=false;}

	dfs(time+1,true,open);
	dfs(time+1,false,open);

	return;
}

int main(){
	cin>>n;
	f.assign(n,vector<ll>(10,0));//n個の店について、10個の時間帯に対し、開いているか
	p.assign(n,vector<ll>(11,0));//n個の店について、joisinoと同じ時間帯の個数に対する、利益

	for(ll i=0;i<n;i++){
		for(ll j=0;j<10;j++){
			cin>>f[i][j];
		}
	}

	for(ll i=0;i<n;i++){
		for(ll j=0;j<=10;j++){
			cin>>p[i][j];
		}
	}

	vector<bool> open(10,false);
	dfs(0,true,open);
	dfs(0,false,open);


	cout<<output<<endl;

	return 0;
}

Measured memory_bytes: 256
h, w, a, b = map(int, input().split())

for i in range(b):
  for i in range(a):
    print(0,end="")
  for i in range(w-a):
    print(1,end="")
  print()
for i in range(h-b):
  for i in range(a):
    print(1,end="")
  for i in range(w-a):
    print(0,end="")
  print()

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 0; i <= n; i++)
#define REp(i,n) for(ll i = 1; i < n; i++)
#define REP(i,n) for(ll i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
  string s;
  cin >> s;
  int m = sz(s);
  int sum = 0;
  rep(i,m) {
    sum += s[i] - '0';
  }
  bool ok = true;
  rep(i,m) if(s[i] != '9') ok = false;
  if(ok) cout << 9*m << endl;
  else {
    cout << max(sum, 9*(m-1) + s[0]-'0'-1) << endl;
  }
}

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

int main(){
	int n;
	cin >> n;
	
	int minR = 1000000000;
	int ans = -1000000000;
	
	for(int i=0; i<n; i++){
		int r;
		cin >> r;
		if(i!=0)ans = max(ans, r - minR);
		minR = min(minR, r);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int H, W, N;
  cin >> H >> W;
  cin >> N;
  int nof_color[N+1];
  for(int i = 1; i < N+1; ++i) {
    cin >> nof_color[i];
  }
  int oneline[H*W];
  int index = 0;
  for(int i = 1; i < N+1; ++i) {
    for(int j = 0; j < nof_color[i]; ++j) {
      oneline[index] = i;
      ++index;
    }
  }
  int g[H][W];
  index = 0;
  for(int h = 0; h < H; ++h) {
    for(int tmp_w = 0; tmp_w < W; ++tmp_w) {
      int w = tmp_w;
      if(h%2) w = W - 1 - tmp_w;
      g[h][w] = oneline[W*h + tmp_w];
      g[h][w] = oneline[index];
      ++index;
    }
  }
  for(int h = 0; h < H; ++h) {
    for(int w = 0; w < W; ++w) {
      if(w==W-1) COUTB(g[h][w]);
      else COUTS(g[h][w]);
    }
  }
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 512
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

ll f(ll x) { return x * (x + 1) / 2; }

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

    ll ans = 0;
    rep(i, n) ans += f(n - i);

    rep(i, n - 1) {
        ll u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);

        ll t = u * (n + 1 - v);
        ans -= t;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>
int main(){
	int h,n;
	int a[100005];
	int i=0;
	int sum=0;
	scanf("%d%d",&h,&n); 
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	if(sum>=h)printf("Yes");
	else printf("No");
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String[] A = sc.next().split("");
		String[] B = sc.next().split("");
		String[] C = sc.next().split("");
		if (A[A.length - 1].equals(B[0]) && B[B.length - 1].equals(C[0]))
			System.out.println("YES");
		else
			System.out.println("NO");
		sc.close();
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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


int main(void) {
	ll X, Y, i, j, k, cnt = 0;
	scanf("%lld %lld", &X, &Y);
	while (X <= Y) {
		X *= 2;
		cnt++;
	}

	printf("%d", cnt);




	return 0;
}

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

vector<int> binary(int i, int n, int N){
    int x = 1;
    rep(j,N){
        x *= n;
    }
    vector<int> vec(N);
    rep(j,N){
        x /= n;
        vec[j] = i / x;
        i -= x * vec[j];
    }
    return vec;
}

int main(){
    int N;
    cin >> N;
    vector<vector<pair<int,int> > > vec(N, vector<pair<int,int> > (0));
    rep(i,N){
        int cnt;
        cin >> cnt;
        rep(j,cnt){
            pair<int,int> p;
            cin >> p.first;
            cin >> p.second;
            p.first--;
            vec[i].push_back(p);
        }
    }
    int num = 1;
    rep(i,N){
        num *= 2;
    }
    int ans = 0;
    rep(i,num){
        vector<int> honest_list = binary(i,2,N);
        bool honest = true;
        rep(j,N){
            if (honest_list[j] == 1){
                rep(k,vec[j].size()){
                    if (vec[j][k].second == 1){
                        if (honest_list[vec[j][k].first] == 0) honest = false;
                    }
                    else if (vec[j][k].second == 0){
                        if (honest_list[vec[j][k].first] == 1) honest = false;
                    }
                }
            }
        }
        if (honest){
            int ans_sub = 0;
            rep(j,N){
                ans_sub += honest_list[j];
            }
            ans = max(ans, ans_sub);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int cnt[15][15];
int get_begin(int num) {
    int res = 0;
    while (num) {
        res = num % 10;
        num /= 10;
    }
    return res;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    for (int i = 1; i <= n; ++i)
        ++cnt[get_begin(i)][i % 10];
    int res = 0;
    for (int i = 1; i < 10; ++i)
        for (int j = 1; j < 10; ++j)
            res += cnt[i][j] * cnt[j][i];
    cout << res << '\n';
    return 0;
}

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

int main() {
  int n, a, b, c, d;
  cin >>n; //1000a+100b+10c+d
  a = n/1000;
  b = (n-1000*a)/100;
  c = (n-1000*a-100*b)/10;
  d = (n-1000*a-100*b-10*c);
    
  if (a==b) {
    if (b==c) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else if (b==c){
    if (c==d) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 10000007;



int main(void) {
  int n,l;
  cin >> n >> l;
  int ans = 1000000;
  rep2(i,1,n+1){
    if(abs(ans)>abs(l+i-1)){
      ans = l+i-1;
    } 
  }
  //cout << ans << endl;
  cout << n*l+(n*(n+1))/2-n-ans << endl;
}


Measured memory_bytes: 256
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)

var n int
var g [][]int

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,100)}
  n = input.NextInt()
  g = make([][]int,n)
  for i:=0;i<n-1;i++ {
    a,b := input.NextInts()
    g[a-1] = append(g[a-1],b-1)
    g[b-1] = append(g[b-1],a-1)
  }
  x,c := center()
  y := sub(c)
  if len(c) == 1 {
    x++
    for _,u := range g[c[0]] { y = min64(y,sub([]int{c[0],u})) }
  }
  fmt.Println(x,y)
}

func max(x,y int) int {
  if x > y { return x }
  return y
}
func min(x,y int) int {
  if x < y { return x }
  return y
}
func min64(x,y int64) int64 {
  if x < y { return x }
  return y
}

func dfs(u,p int) int {
  d := 0
  for _,v := range g[u] {
    if v == p { continue }
    d = max(d,dfs(v,u)+1)
  }
  return d
}
func center() (int,[]int) {
  m := n+1
  x := make(map[int][]int)
  for i:=0;i<n;i++ {
    d := dfs(i,-1)
    if _,ok := x[d];!ok { x[d] = []int{} }
    x[d] = append(x[d],i)
    m = min(m,d)
  }
  return m,x[m]
}
func sub(c []int) int64 {
  var cat func(int,int,int)
  a := make([]int,n)
  b := make([]int,n)
  cat = func(u,p,d int) {
    a[u] = d
    k := 0
    for _,v := range g[u] {
      if v == p { continue }
      k++
      cat(v,u,d+1)
    }
    b[u] = k
  }
  if len(c) == 1 {
    cat(c[0],-1,0)
  } else {
    cat(c[0],c[1],0)
    cat(c[1],c[0],0)
  }
  m := map[int]int{}
  for i:=0;i<n;i++ { m[a[i]] = max(m[a[i]],b[i]) }
  ret := int64(len(c))
  for _,v := range m {
    if v < 2 { continue }
    ret *= int64(v)
  }
  return ret
}

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int {
  n,_ := strconv.Atoi(i.NextLine())
  return n
}
func(i *Input) NextInts() (int,int) {
  s := strings.Fields(i.NextLine())
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define maxe(a,b,c) max(a,max(b,c))
#define eb emplace_back
#define em emplace
#define print(x) cout<<x<<endl;
#define fill(a,val) memset(a,val,sizeof(a))
#define in(k) int k;cin>>k
#define edl cout<<"\n"
#define ll  long long
#define ld  long double
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const ll mod=1e9+7;
signed main()
{
    //cout<<fixed<<setprecision(20);
    fastio;
    in(n);in(k);
    int a[n+1];
    fr(i,1,n)
    cin>>a[i];
    int d[n+1][k+1];
    d[0][0]=1;
    fr(i,1,k) d[0][i]=0;
    fr(i,1,n)
    {
        int sum[k+1];sum[0]=d[i-1][0];
        fr(j,1,k)
        sum[j]=(sum[j-1]+d[i-1][j])%mod;
        fr(j,0,k)
        {
            int overflow=j-a[i]-1;
            if(overflow>=0)
            d[i][j]=(sum[j]-sum[overflow]+mod)%mod;
            else
            d[i][j]=sum[j];
        }
    }
    print(d[n][k]);
    printclock;
    return 0;
}

Measured memory_bytes: 40064
f = raw_input().split(" ")
stack = []
for i in f:
	if i.isdigit():
		stack.append(int(i))
	else:
		y = stack.pop()
		x = stack.pop()
		if i == "+":
			stack.append(x+y)
		if i == "-":
			stack.append(x-y)
		if i == "*":
			stack.append(x*y)
print stack.pop()

Measured memory_bytes: 4212
import java.util.*; 
 
class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
       
        String s=sc.next();
 
    
 	if(s.equals("SUN")){
    		System.out.println(7);
    	}else if(s.equals("MON")){
     		System.out.println(6);
   	 }else if(s.equals("TUE")){
   			 System.out.println(5);
    }else if(s.equals("WED")){
  System.out.println(4);
    }else if(s.equals("THU")){
		System.out.println(3);
    }else if(s.equals("FRI")){
      System.out.println(2);
    }else{
    System.out.println(1);
    }
      
    }
}

Measured memory_bytes: 20560
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return b.second > a.second;
    }
    return a.first < b.first;
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    int n;
    while (cin >> n)
    {
        if (n == 0)
            break;

        vector<int> v;
        for (int i = 0; i < n; ++i)
        {
            int a;
            cin >> a;
            v.push_back(a);
        }
        bool update = true;
        int cnt = 0;
        while (update)
        {

            update = false;

            map<int, int> mp;
            for (int i = 0; i < n; ++i)
            {
                mp[v[i]]++;
            }

            for (int i = 0; i < n; ++i)
            {
                if (v[i] != mp[v[i]])
                    update = true;
                v[i] = mp[v[i]];
            }
            cnt++;
        }
        cout << cnt - 1 << endl;
        for (int i = 0; i < n; ++i)
        {
            if (i)
                cout << " ";
            cout << v[i];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
import itertools
import sys
import numpy as np
import collections

c1=list(map(int, input().split()))
c2=list(map(int, input().split()))
c3=list(map(int, input().split()))

ans=[]
cr1,cr2,cr3 = zip(c1,c2,c3)
for c in [c1,c2,c3]:
    for i,cr in enumerate([cr1,cr2,cr3]):
        a=sum(c)+sum(cr)-c[i]*3
        ans.append(a)
print('Yes' if len(set(ans))==1 else 'No')



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

int main() {
    string s;
    cin >> s;
    int64_t k;
    cin >> k;

    string s_d = s + s;
    char s_begin = s[0];
    char s_end;
    char s_d_end;

    int count = 0;
    int count_first = 0;
    int count_second = 0;
    for(int i = 0; i < s_d.length() - 1; i++) {
        if(i == s.length() - 1) {
            count_first = count;
            count = 0;
            s_end = s_d[i];
        }
        if(s_d[i] == s_d[i + 1]) {
            count++;
            s_d[i + 1] = '*';
        }
    }
    count_second = count;
    s_d_end = *s_d.rbegin();

    int64_t ans;
    if(s_begin != s_end || s_begin != s_d_end) {
        if(k % 2 == 0) {
            ans = (count_first + count_second) * (k / 2);
        } else {
            ans = (count_first + count_second) * (k / 2) + count_first;
        }
    } else {
        ans = count_first + count_second * (k - 1);
    }

    // cout << s_d << endl;
    // cout << count_first << endl;
    // cout << count_second << endl;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>

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

template <typename M, typename L>
struct SegmentTree {
  int n;
  vector<M> dat;
  vector<L> laz;
  M em;
  L el;
  function<M(M, M)> multiply;
  function<L(L, L)> composite;
  function<M(L, M)> apply;
  SegmentTree(int n0, M em, L el, function<M(M, M)> mul, function<L(L, L)> com,
              function<M(L, M)> app)
      : em(em), el(el), multiply(mul), composite(com), apply(app) {
    n = 1;
    while (n < n0) {
      n *= 2;
    }
    dat.resize(n * 2 - 1, em);
    laz.resize(n * 2 - 1, el);
  }
  void _update(int i, L f) {
    dat[i] = apply(f, dat[i]);
    laz[i] = composite(f, laz[i]);
  }
  void update(int ql, int qr, L f) { update(ql, qr, f, 0, 0, n); }
  void update(int ql, int qr, L f, int i, int il, int ir) {
    if (qr <= il or ir <= ql) return;
    if (ql <= il and ir <= qr) {
      _update(i, f);
    } else {
      auto m = (il + ir) / 2, lch = i * 2 + 1, rch = i * 2 + 2;
      _update(lch, laz[i]);
      _update(rch, laz[i]);
      laz[i] = el;
      update(ql, qr, f, lch, il, m);
      update(ql, qr, f, rch, m, ir);
      dat[i] = multiply(dat[lch], dat[rch]);
    }
  }
  M query(int ql, int qr) { return query(ql, qr, 0, 0, n); }
  M query(int ql, int qr, int i, int il, int ir) {
    if (ql <= il and ir <= qr) {
      return dat[i];
    } else if (qr <= il or ir <= ql) {
      return em;
    } else {
      auto m = (il + ir) / 2;
      // f(l + r) = f(l) + f(r)
      return apply(laz[i], multiply(query(ql, qr, i * 2 + 1, il, m),
                                    query(ql, qr, i * 2 + 2, m, ir)));
    }
  }
  void tour() {
    cout << endl << "BEGIN";
    queue<pair<int, bool>> q;
    q.emplace(0, true);
    while (q.size() > 0) {
      int i;
      bool f;
      tie(i, f) = q.front();
      q.pop();
      if (f) cout << endl;
      cout << dat[i].val << " ";
      if (i * 2 + 1 < (int)dat.size()) {
        q.emplace(i * 2 + 1, f);
        q.emplace(i * 2 + 2, false);
      }
    }
    cout << endl << "END" << endl;
  }
};

int main() {
  // DSL_2_F

  int n, q;
  cin >> n >> q;
  using M = int;
  using L = int;
  const L el = -1;
  SegmentTree<M, L> seg(n, numeric_limits<int>::max(), el,
                        [&](M a, M b) -> M { return min(a, b); },
                        [&](L f, L g) -> L { return f == el ? g : f; },
                        [&](L f, M a) -> M { return f == el ? a : f; });
  rep(i, n) { seg.update(i, i + 1, (1LL << 32) - 1); }
  while (q--) {
    int t;
    cin >> t;
    if (t == 0) {
      int s, t, x;
      cin >> s >> t >> x;
      seg.update(s, t + 1, x);
    } else {
      int s, t;
      cin >> s >> t;
      cout << seg.query(s, t + 1) << endl;
    }
  }

  return 0;
}

// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4017266#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4017276#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4017280#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4017282#1



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

using namespace std;


int main() {
	int N, r;
	cin >> N >> r;
	if(N >= 10) {
		cout << r << endl;
	}
	
	else {
		cout << r + (100*(10 - N)) << endl;
	}
		
	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int cnt[10][10];
int main() {
	int n; cin >> n;
	for(int a = 1; a <= n; ++a) {
		int tmp = a;
		while(tmp >= 10) {
			tmp /= 10;
		}
		cnt[tmp][a % 10]++;
	}
	int ans = 0;
	for(int i = 1; i <= 9; ++i) {
		for(int j = 1; j <= 9; ++j) {
			ans += cnt[i][j] * cnt[j][i];
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

mo=1000
ch=0
tu=0
b=sorted(a)
if a==b:
  ka=mo//a[0]
  mo=mo-ka*a[0]
  mo=mo+ka*a[-1]
  
else:
  
  for i in range(1,n):
    if a[i-1]<a[i]:
      ch+=1
    if a[i-1]>a[i] and ch>0:
      y=min(a[tu:i])
      ka=mo//y
      mo=mo-ka*y
      mo=mo+a[i-1]*ka
      tu=i
      ch=0
    if i==n-1:
      if a[i-1]<a[i]:
        y=a[i-1]
        ka=mo//y
        mo=mo-ka*y
        mo=mo+a[i]*ka
  
    
print(mo)

Measured memory_bytes: 9040
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim n As Integer = NextInt()
        Dim x As Integer = NextInt()
        Dim a(n - 1) As Integer
        For i As Integer = 0 To UBound(a)
            a(i) = NextInt()
        Next
        Array.Sort(a)

        Dim ans As Integer = 0
        For i As Integer = 0 To UBound(a)
            If x < a(i) Or (i = n - 1 And x <> a(i)) Then Exit For
            ans += 1
            x -= a(i)
        Next

        WriteLine(ans)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function
End Module


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

string s;

int main()
{
    cin >> s;
    int a = int(s[0] - '0') * 10 + int(s[1] - '0');
    int b = int(s[2] - '0') * 10 + int(s[3] - '0');
    if (1 <= a && a <= 12)
        if (1 <= b && b <= 12)
            printf("AMBIGUOUS\n");
        else printf("MMYY\n");
    else if (1 <= b && b <= 12)
            printf("YYMM\n");
         else printf("NA\n");
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> l(n);
  rep(i,n) cin >> l[i];
  ll ans = 0;

  sort(l.begin(), l.end());

  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      for (int k = j+1; k < n; k++) {
        if (l[i]!=l[j] && l[i]!=l[k] && l[j]!=l[k] && l[i]+l[j] > l[k]) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
from itertools import product

n = int(input())

ans = 0
for i in range(1, 10):
    for pat in product("357", repeat=i):
        num = "".join(pat)
        st = set(num)
        if int(num) <= n and st == {"3", "5", "7"}:
            ans += 1

print(ans)


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

const int N = 100 + 5;

int n, m, a[N];
double tot;

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> a[i], tot += a[i];
    tot = tot / 4 / m; int cnt = 0;
    for (int i = 1; i <= n; ++i) if (a[i] >= tot) ++cnt;
    if (cnt >= m) puts("Yes"); else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long

using namespace std;

typedef pair<int, int> td;

int cost[100000][3];
int op[100000][3];

int main(){
    #ifdef ZERBRA
        freopen("code.inp", "r", stdin);
        //freopen("code.out", "w", stdout);
    #endif // ONLINE_JUDGE
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        scanf("%d%d%d", &cost[i][0], &cost[i][1], &cost[i][2]);
    op[0][0] = cost[0][0];
    op[0][1] = cost[0][1];
    op[0][2] = cost[0][2];
    for (int i = 1; i < n; ++i)
        for (int j = 0; j < 3; ++j)
            for (int h = 0; h < 3; ++h)
                if (j != h) op[i][h] = max(op[i][h], op[i-1][j] + cost[i][h]);
    printf("%d", max(op[n-1][0], max(op[n-1][1], op[n-1][2])));
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int n,m,tmp,ans,ichi;
	ans =0;
	ichi=0;
	cin >> n >> m;
	int x[200001]={};
	int y[200001]={};
	for(int i=0;i<n;i++){
		cin >> tmp;
		y[tmp%m]+=1;
		x[tmp]+=1;
	}
	if(m%2==1){
		ans += y[0]/2;
		for(int i=1;i<=(m/2);i++){
			ans+=min(y[i],y[m-i]);
			if(y[i]>y[m-i]){
				for(int j=0;j<(n/m+1);j++){
					if(x[i+m*j]>=2){
						ichi+=x[i+m*j]/2;
					}
				}
				if(2*ichi>=(y[i]-y[m-i])){
					ans += (y[i]-y[m-i])/2;
				}else{
					ans +=ichi;
				}
				ichi=0;
			}else if(y[i]<y[m-i]){
				for(int j=0;j<(n/m+1);j++){
					if(x[m-i+m*j]>=2){
						ichi+=x[m-i+m*j]/2;
					}
				}
				if(2*ichi>=(y[m-i]-y[i])){
					ans += (y[m-i]-y[i])/2;
				}else{
					ans +=ichi;
				}
				ichi=0;
			}
		}
	}else{
		ans += y[0]/2;
		ans += y[m/2]/2;
		for(int i=1;i<=(m/2-1);i++){
			ans+=min(y[i],y[m-i]);
			if(y[i]>y[m-i]){
				for(int j=0;j<(n/m+1);j++){
					if(x[i+m*j]>=2){
						ichi+=x[i+m*j]/2;
					}
				}
				if(2*ichi>=(y[i]-y[m-i])){
					ans += (y[i]-y[m-i])/2;
				}else{
					ans +=ichi;
				}
				ichi=0;
			}else if(y[i]<y[m-i]){
				for(int j=0;j<(n/m+1);j++){
					if(x[m-i+m*j]>=2){
						ichi+=x[m-i+m*j]/2;
					}
				}
				if(2*ichi>=(y[m-i]-y[i])){
					ans += (y[m-i]-y[i])/2;
				}else{
					ans +=ichi;
				}
				ichi=0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792