akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll h,w;cin>>h>>w;
    if(h>w)swap(h,w);
    if(h%3==0||w%3==0){
        cout<<0<<endl;
        return 0;
    }
    ll ans=INF;
    for(ll i=1;i<=w;i++){
        ll a=h*(i);
        ll b=(w-i)*(h/2);
        ll c;
        if(h%2==0)c=b;
        else c=(w-i)*(h/2+1);
        chmin(ans,mmax(a,mmax(b,c))-mmin(a,mmin(b,c)));
        //cout<<a<<" "<<b<<" "<<c<<endl;
    }
    for(ll i=1;i<=h;i++){
        ll a=w*(i);
        ll b=(h-i)*(w/2);
        ll c;
        if(w%2==0)c=b;
        else c=(h-i)*(w/2+1);
        chmin(ans,mmax(a,mmax(b,c))-mmin(a,mmin(b,c)));
        //cout<<a<<" "<<b<<" "<<c<<endl;
    }
    chmin(ans,h);
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------








































Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#define MAX_N 100001
#define MAX_V 100001
#define MP make_pair
using namespace std;
typedef pair<int, int> P;

int v_odd[MAX_N], v_even[MAX_N], exist_odd[MAX_V], exist_even[MAX_V];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N / 2; i++) cin >> v_odd[i] >> v_even[i];
    int mode_odd, second_odd = 0, mode_even, second_even = 0;
    for (int i = 0; i < MAX_V; i++) exist_odd[i] = 0;
    for (int i = 0; i < N / 2; i++) exist_odd[v_odd[i]]++;
    vector<P> count_freq;
    for (int i = 0; i < MAX_V; i++) {
        if (exist_odd[i] != 0) count_freq.push_back(MP(exist_odd[i], i));
    }
    sort(count_freq.begin(), count_freq.end());
    reverse(count_freq.begin(), count_freq.end());
    mode_odd = count_freq[0].second;
    if (count_freq.size() > 0) second_odd = count_freq[1].second;
    count_freq.clear();
    for (int i = 0; i < MAX_V; i++) exist_even[i] = 0;
    for (int i = 0; i < N / 2; i++) exist_even[v_even[i]]++;
    for (int i = 0; i < MAX_V; i++) {
        if (exist_even[i] != 0) count_freq.push_back(MP(exist_even[i], i));
    }
    sort(count_freq.begin(), count_freq.end());
    reverse(count_freq.begin(), count_freq.end());
    mode_even = count_freq[0].second;
    if (count_freq.size() > 0) second_even = count_freq[1].second;
    if (mode_odd != mode_even) cout << N - (exist_odd[mode_odd] + exist_even[mode_even]) << endl;
    else {
        int ans1, ans2;
        ans1 = N - exist_odd[mode_odd];
        if (second_even > 0) ans1 -= exist_even[second_even];
        ans2 = N - exist_even[mode_even];
        if (second_odd > 0) ans2 -= exist_odd[second_odd];
        cout << min(ans1, ans2) << endl;
    }
    return 0;
}

Measured memory_bytes: 2044
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double ans = 0;
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        if(i%2 == 1) ans++;
    }
    ans /= (double)n;
    cout << fixed << setprecision(12) << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();

    int sum = 0;
    for (int i = 0; i < m; i++) {
      sum += sc.nextInt();
    }
    if (sum > n) {
      System.out.println(-1);
    } else {
      System.out.println(n - sum);
    }
  }
}


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

ll GCD(ll a, ll b)
{
	if (b == 0) return a;
	else return GCD(b, a%b);
}

ll n, k;
vector<long long> a;

int main(int argc, char **argv)
{
	a.resize(10000000);
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}

	ll g{0};
	ll max{0};
	for (int i = 0; i < n; ++i)
	{
		g = GCD(g, a[i]);
	}
	max = *max_element(a.begin(), a.end());

	string ans;
	if (max >= k && k % g == 0)
		ans = "POSSIBLE";
	else
		ans = "IMPOSSIBLE";

	std::cout << ans << std::endl;
	
}


Measured memory_bytes: 78336
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin >> a[i];
  sort(a.begin(),a.end());
  int right = (int)a.size() -1,left;
  int cnt=0;
  for(left=0;left<right-1;left++){
    if(a[left]==a[left+1]){
      while(true){
        if(a[right]==a[right-1] || left+2==right){
          cnt+=2;
          right--;
          break;
        }
        right--;
      }
    }
  }
  if(right-2==--left && a[right]==a[right-1])cnt+=2;
  cout << n-cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;
    
#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_9 1000000000
#define INF (numeric_limits<int>::max()/2)
#define int long long
    
typedef long long ll;
typedef pair<int,int> Pair;
double rate = 380000.0;
double ans=0;

signed main(){
    int N;
    cin>>N;
    REP(i,N){
        double x; string u;
        cin>>x>>u;
        if (u == "BTC") ans+=x*rate;
        else ans+=x;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
const int maxn = 1e5 + 100; 
const int maxm = 1 << 15 + 10; 
const int inf = 0x3f3f3f3f; 

int n, ans, state; 
int v[maxn], cnt[20], f[maxm]; 

int dp(int s) {
	if (!s) return 0; 
	if (f[s] < inf) return f[s]; 
	for (int i = 0; i <= 15; ++i) {
		if (!(s & (1 << i))) continue; 
		for (int j = 0; j <= 15; ++j) {
			if (i == j || !(s & (1 << j))) continue; 
			int x = i ^ j; 
			int y = s ^ (1 << i) ^ (1 << j) ^ (1 << x); 
			if (s & (1 << x)) f[s] = min(f[s], dp(y) + 2); 
			else f[s] = min(f[s], dp(y) + 1); 
		}
	}
	return f[s]; 
}

int main() {
	scanf("%d", &n); 
	for (int i = 1; i < n; ++i) {
		int x, y, z; 
		scanf("%d%d%d", &x, &y, &z); 
		x += 1, y += 1; 
		v[x] ^= z; v[y] ^= z; 
	}
	for (int i = 1; i <= n; ++i) cnt[v[i]]++; 
	for (int i = 1; i <= 15; ++i) {
		ans += (cnt[i] >> 1); 
		state += (cnt[i] & 1) * (1 << i); 
	}
	memset(f, 0x3f, sizeof(f)); 
	printf("%d\n", ans + dp(state)); 
	return 0; 
}

Measured memory_bytes: 131712
#include"bits/stdc++.h"
using namespace std;
int arr[112345];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&arr[i]);
    }
    int ans = 1;
    int inc = 1;
    int dec = 1;
    for(int i = 1; i < n; i++)
    {
       if(inc && dec)
       {
           if(arr[i] > arr[i-1]) dec = 0;
           else if(arr[i] < arr[i-1]) inc = 0;
       }
       else if(inc)
       {
           if(arr[i] < arr[i-1])
           {
               ans++;
               dec = 1;
           }
       }
       else
       {
           if(arr[i] > arr[i-1])
           {
               ans++;
               inc = 1;
           }
       }

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


}


Measured memory_bytes: 640
#include <stdio.h>
#include <ctype.h>

#define N 20;

static
char d[ 20 ][ 20 ];
static
int w, h;

static
int dfs (
  int x,
  int y
  )
{
  int res;

  if ( x < 0 || x >= w
    || y < 0 || y >= h )    return ( 0 );
  if ( d[ x ][ y ] != '.' ) return ( 0 );

  d[ x ][ y ] = '#';
  res   = 1;
  res  += dfs ( x - 1, y );
  res  += dfs ( x + 1, y );
  res  += dfs ( x, y - 1 );
  res  += dfs ( x, y + 1 );

  return ( res );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int sx = 0, sy = 0;
    int x, y;

    scanf ( " %d %d", &w, &h );
    if ( !( w | h ) ) break ;

    for ( y = 0; y < h; ++y )
    for ( x = 0; x < w; ++x )
    {
      int ch = ' ';

      while ( isspace ( ch ) )  ch = getchar ( );
      if ( ch == '@' )
      {
        sx = x; sy = y;
        d[ x ][ y ] = '.';
      }
      else
      {
        d[ x ][ y ] = ch;
      }
    }

    printf ( "%d\n", dfs ( sx, sy ) );
  }

  return ( 0 );
}

Measured memory_bytes: 0
def examA():
    N = I()
    ans = (N-1)//2
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()

"""

"""

Measured memory_bytes: 3568
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = ii()
    dp = [0] * (S + 1)

    dp[0] = 1
    # 1 <= i <= Sの範囲を探索
    for i in range(1, S + 1):
        # 0 <= j <= i - 3の範囲で、
        # 間仕切りを置くことができる個数の合計を集計
        if i > 2:
            dp[i] = sum(dp[0:i - 2])
            dp[i] %= MOD
    print(dp[-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 9872
#include<bits/stdc++.h>
using namespace std;
 
using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;


int main(){
    int t=1;
    //cin>>t;
    while(t--){
        ll n;
        int m;
        cin>>n>>m;
        int a[n];
        ll sum=0;
        for(int i=0;i<m;i++){
            cin>>a[i];
            sum+=a[i];
        }
        if(sum>n)
            cout<<"-1";
        else
            cout<<abs(n-sum);
    }
    return 0;
}
    

Measured memory_bytes: 3604
#include<stdio.h>
int main(void)
{
	int l,a,b,c,d;
	scanf("%d %d %d %d %d", &l, &a, &b, &c, &d);
	while(a>0||b>0)
	{
		if(a>0)
		a-=c;
		if(b>0)
		b-=d;
		l--;
	}
	printf("%d\n", l);
	
	return 0;
}


Measured memory_bytes: 2112
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  priority_queue<ll, vector<ll>, greater<ll>> q;
  ll res = 0;
  REP(i, N) {
    ll s;
    cin >> s;
    res += s;
    if (s % 10 != 0) {
      q.emplace(s);
    }
  }
  if (q.empty()) {
    cout << 0 << endl;
  } else {
    while (res % 10 == 0 && !q.empty()) {
      res -= q.top();
      q.pop();
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 3652
s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
S = s.split(", ")
k = int(input())
print(S[k-1])

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


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


void swap(int *x, int *y)
{
  int tmp = *x;
  *x = *y;
  *y = tmp;
}


void reverse_array(int array[], int size)
{
  int i=0;

  while (i < size/2){
    swap(&array[i], &array[size-i-1]);
    i++;
  }
}


int main()
{
  int n, k, i, l[50], ans=0;

  scanf("%d %d", &n, &k);
  for (i=0; i<n; i++) scanf("%d", &l[i]);
  qsort(l, n, sizeof(int), comp);
  reverse_array(l, n);
  for (i=0; i<k; i++) ans += l[i];
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10**9 + 7

A = [[1]*(M+1) for i in range(N+1)]
for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            A[i+1][j+1] = (A[i+1][j] + A[i][j+1])%mod
        else:
            A[i+1][j+1] = (A[i+1][j] + A[i][j+1] - A[i][j])%mod
print(A[N][M])



Measured memory_bytes: 73436
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int A, B, L, L1, L2, L3, L4, L5, c;
  c =0;
  cin >> A >> B;
 while(A<=B){
   L1 = A%10;
   L2 = A/10%10;
   L4 = A/1000%10;
   L5 = A/10000;
   if(L1==L5 && L2==L4) c++;
     A++;
     
   }
  cout << c << endl;
  
   
}
   


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

int diff(int a, int b){
    if(a>b){
        return a-b;
    }
    return b-a;
}

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

int  main(){
    int n;
  	scanf("%d", &n);
    int* a = (int*)malloc(sizeof(int)*n);
  	int* t=a;
  	for(int i=0;i<n;i++){
    	scanf("%d", t++);
    }
    int* dp = (int*)malloc(sizeof(int)*n);
    dp[n-1]=0;
    dp[n-2]=diff(a[n-2], a[n-1]);
    for(int i=n-3;i>=0;i--){
        dp[i]=min(diff(a[i], a[i+1])+dp[i+1], diff(a[i], a[i+2])+dp[i+2]);
    }
    printf("%d", dp[0]);
    return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

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

Measured memory_bytes: 256
#include<stdio.h>
using namespace std;

int main() {
    int H, W;
    while(1) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0) break;
        
        for (int i = 0; i < H; i++) {
            if (i % 2 == 0) {
                for (int j = 0; j < W; j++) {
                    if (j%2 == 0) {
                        printf("#");
                    } else {
                        printf(".");
                    }
                }
                printf("\n");
            } else {
                for (int j = 0; j < W; j++) {
                    if (j%2 == 1) {
                        printf("#");
                    } else {
                        printf(".");
                    }
                }
                printf("\n");
            }
            
        }
        printf("\n");
    }
}


Measured memory_bytes: 2580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;

#define P pair<int, int>
#define MAX 246912

int main()
{	
	int n;
	bool p[MAX];
	fill(begin(p), end(p), 1);
	p[0] = p[1] = 0;
	for (int i = 2; i < sqrt(MAX) + 1; i++) {
		if (p[i]) {
			for (int j = i * 2; j < MAX; j += i)
				p[j] = 0;
		}
	}
	while (cin >> n, n) {
		int cnt = 0;
		for (int i = n+1; i <= 2*n; i++) {
			if (p[i]) cnt++;
		}
		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1400
#include <cstdint>
#include <iostream>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

} // namespace null_null

#include <vector>
#include <math.h>
#include <algorithm>

namespace null_null {

void main_() {
  usize N;
  std::cin>>N;
  std::vector<i32>L(N);
  for(usize i=0;i<N;i++){
    std::cin>>L[i];
  }

  std::sort(L.begin(),L.end());

  i32 ans=0;
  for(usize i=0;i<N;i++){
    for(usize j=0;j<i;j++){
      i32 l=std::abs(L[i]-L[j]);
      i32 sub = upper_bound(L.begin(),L.end(),l)-L.begin();
      ans+=std::max((i32)0,(i32)j-sub);
    }
  }

  std::cout<<ans<<std::endl;
}

} // namespace null_null

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  null_null::main_();
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#define PI 100
int main()
{
    int a[PI];
    int i,k;
    int n;
    scanf("%d",&n);
    for( i=0;i<n;i++)
     scanf("%d",&a[i]);
     for(i=0;i<n-1;i++)
        printf("%d ",a[i]);
    printf("%d\n",a[n-1]);
    for(i=1;i<n;i++)
    {
        int key=a[i];
        int j=i-1;
        while(j>=0&&a[j]>key)
           {
               a[j+1]=a[j];
               j--;
               a[j+1]=key;
           }
        for(k=0;k<n-1;k++)
            printf("%d ",a[k]);
        printf("%d\n",a[n-1]);
    }

}



Measured memory_bytes: 2088
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String o = sc.next();
		String e = sc.next();
		for(int i = 0; i < o.length(); i++) {
			System.out.print(o.charAt(i));
			if(i < e.length()) System.out.print(e.charAt(i));
		}
		System.out.println();
	}
}

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

int comp_func(const void *a, const void *b)    //昇順ソート用比較関数
{
  return *(int*)a - *(int*)b;
}

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

  int score = 0;
  qsort(s, N, sizeof(int), comp_func);
  for(int i = 0; i < N; i++){
    score += s[i];
  }
  if(score % 10 != 0){
    printf("%d\n", score);
  }else{
    int i;
    for(i = 0; i < N; i++){
      if(s[i] % 10 != 0){
        score -= s[i];
        printf("%d\n", score);
        return 0;
      }
    }
    if(i >= N - 1) printf("%d\n", 0);
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
using namespace std;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n,a,b;cin>>n>>a>>b;
    cout <<min(a,b)<<" "<<max(a+b-n,0)<<endl;
    
    return 0;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll dp[2005],n;
int32_t main(){
CODE_START;
cin>>n;
dp[3]=1;
for(ll i=4;i<=n;i++)
{
    for(ll j=i-3;j>=3;j--)
    {
        dp[i]+=dp[j];
    }
    dp[i]++;
    dp[i]%=mod;
}
cout<<dp[n]<<endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

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

  ll ans = 100000000000001;
  for (ll i = 1; i < 10000001; i++) {
    if (n % i == 0) {
      ll j = n / i;
      ll tmp_ans = i - 1 + j - 1;
      ans = min(ans, tmp_ans);
    }
  }

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int now = 0;
    bool check;
    string s, tmp; cin >> s;
    reverse(s.begin(), s.end());
    vector<string> v(4);
    v[0] = "dream", v[1] = "dreamer", v[2] = "erase", v[3] = "eraser";
    rep(i, 0, 4) reverse(v[i].begin(), v[i].end());
    while(1){
        check = false;
        rep(i, 0, 4){
            if (i == 0 || i == 2) tmp = s.substr(now, 5);
            else if (i == 1) tmp = s.substr(now, 7);
            else tmp = s.substr(now, 6);
            if (tmp == v[i]) check = true, now += tmp.size();
            if (check) break;
        }
        if (!check) break;
        if (now == s.size()) break;
    }
    if (check) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <climits>
#include <algorithm>
using namespace std;

const int MAX_N = 1010;
const int INF = INT_MAX;
int dp[MAX_N][MAX_N];

int main(void) {
    string s1, s2; cin >> s1 >> s2;
    fill_n((int *)dp, MAX_N*MAX_N, INF);

    for (int i = 0; i <= s1.size(); i++) {
        dp[0][i] = i;
    }
    for (int i = 0; i <= s2.size(); i++) {
        dp[i][0] = i;
    }

    for (int i = 1; i <= s2.size(); i++) {
        for (int j = 1; j <= s1.size(); j++) {
            if (s2[i-1] == s1[j-1]) {
                dp[i][j] = dp[i-1][j-1];
            } else {
                dp[i][j] = min(min(dp[i-1][j-1], dp[i-1][j]), dp[i][j-1]) + 1;
            }
        }
    }

    cout << dp[s2.size()][s1.size()] << endl;

    // for (int i = 0; i <= s2.size(); i++) {
    //     for (int j = 0; j <= s1.size(); j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    return 0;
}

Measured memory_bytes: 7172
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long sum = 1;
		for(int i=1;i<=N;i++) {
			sum = (sum*i)%1000000007;
		}

		System.out.println(sum);
		/*if(sum<1000000007) {
			System.out.println(sum);
		}else {
			System.out.println(sum%1000000007);
		}*/




	}
	public static int sample(int N,int M,char[][] arrayA,char[][] arrayB,int k) {
		int res=0;
		for(int i=0;i<N-M+1;i++) {
			for(int j=0;j<M;j++) {
				for(int l=0;l<M;l++) {
					if(arrayA[j+k][l+i]!=arrayB[j][l]) {
						res = 1;
						break;
					}
				}
			}
			if(res == 0) {
				return 0;
			}
			res = 0;
		}
		return 1;
	}

}


Measured memory_bytes: 23764
import statistics


def stddev(values):
    """ calculate standard deviation

    >>> s = stddev([70, 80, 100, 90, 20])
    >>> print('{:.5f}'.format(s))
    27.85678
    >>> s = stddev([80, 80, 80])
    >>> print('{:.5f}'.format(s))
    0.00000
    """
    return statistics.pstdev(values)


def run():
    while True:
        c = int(input())  # flake8: noqa
        if c == 0:
            break
        values = [int(i) for i in input().split()]
        print(stddev(values))


if __name__ == '__main__':
    run()


Measured memory_bytes: 7100
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> E;
const LL MOD = 1000000007LL;
LL f(LL b, LL n) {
	LL ret = 0;
	while (n) {
		ret += n%b;
		n /= b;
	}
	return ret;
}
int main() {
	LL n, s;
	cin >> n >> s;
	if (n == s) {
		cout << (n + 1) << endl;
		return 0;
	}
	if (n < s) {
		cout << -1 << endl;
		return 0;
	}
	for (LL i = 2; i*i <= n; i++) {
		if (f(i, n) == s) {
			cout << i << endl;
			return 0;
		}
	}
	LL ans = 1LL << 60;
	for (LL i = 1; i*i <= n; i++) {
		if ((n - s) % i) continue;
		LL b = (n - s) / i + 1;
		if (f(b, n) == s) ans = min(ans, b);
	}
	if (ans == 1LL << 60) ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int i,j,n;
   cin>>n;
   int a[n+3];
   for(i=0;i<n;i++)
    cin>>a[i];
   sort(a,a+n);
   n=n/2;
   cout<<a[n]-a[n-1]<<endl;
    return 0;
}



Measured memory_bytes: 640
class Problem
  attr_accessor :a, :b, :n, :m, :h, :w, :x, :y, :s ,:t

  def initialize
    @n,@m = gets.to_s.split.map{ |v| v.to_i }
    @a = Array.new(n){ gets.chomp }
    @b = Array.new(m){ gets.chomp }
  end

  def solve
    0.upto(n-m) do |y|
      0.upto(n-m) do |x|
        return true if match(y,x)
      end
    end
    false
  end

  def match(oy,ox)
    m.times do |y|
      m.times do |x|
        return false if b[y][x] != a[oy+y][ox+x]
      end
    end
    true
  end

  def show(ans)
    puts ans ? "Yes" : "No"
  end
end

Problem.new.instance_eval do
  show(solve)
end


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  string s,t; cin>>s>>t;
  
  if(n>m) swap(n,m), swap(s,t);
  ll g=gcd(n,m);
  bool ok=true;
  if(s[0]!=t[0]) ok=false;
  if(g!=1){
    ll spanm=m/g, spann=n/g;
    ll cnt=0;
    while(cnt*spanm<m){
      if(s[cnt*spann]!=t[cnt*spanm]) ok=false;
      cnt++;
    }
  }
  if(!ok){
    cout<<-1<<endl;
    return 0;
  }
  ll l=lcm(n,m);
  
  cout<<l<<endl;
  
}

Measured memory_bytes: 640
s = input()

op = ['+','-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            e = s[0] + op[i] + s[1] + op[j] + s[2] + op[k] + s[3]
            if eval(e) == 7:
                print(e + '=7')
                exit()


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

int main(){
    string weather[3];
    weather[0]="Sunny";
    weather[1]="Cloudy";
    weather[2]="Rainy";
    string S;
    cin >> S;
    int j;
    for(int i=0; i<3; i++){
        if(S==weather[i]){
            j= (i+1)%3;
            break;
        }
    }

    cout << weather[j] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans ="yes";
        char[] test = s.toCharArray();
        outLoop:for(int i=0;i<s.length();i++){
            for(int j=0;j<s.length();j++){
                if(i!=j&&test[i]==test[j]){
                    ans = "no";
                    break outLoop;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n;
vector<int> et[100000];
int parent[100000];
int sz[100000];

int dfs(int v, int p) {
	parent[v] = p;
	sz[v] = 1;
	for (int i = 0; i < et[v].size(); i++) {
		if (et[v][i] == p) continue;
		sz[v] += dfs(et[v][i], v);
	}
	return sz[v];
}

void reverse(vector<int> &a) {
	int l = 0, r = a.size() - 1;
	while (l < r) {
		swap(a[l], a[r]);
		l++;
		r--;
	}
}

int getCut() {
	vector<int> path;
	int v = n - 1;
	
	while (true) {
		path.push_back(v);
		v = parent[v];
		if (v == 0) break;
	}
	path.push_back(v);
	
	reverse(path);
	
	int length = path.size() - 1;
	return path[length / 2 + 1];
}

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		et[a].push_back(b);
		et[b].push_back(a);
	}
	dfs(0, -1);
	int v = getCut();
	
	if (sz[v] >= n - sz[v]) { cout << "Snuke" << endl; }
	else { cout << "Fennec" << endl; }
	return 0;
}

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

int N;
int a[1000000];

int main()
{       
        cin >> N;
        for(int i=0;i<3*N;++i){
                cin >> a[i];
        }       
        
        sort(a,a+3*N,greater<int>());
        
        long long ans=0;
        
        for(int i=0;i<2*N;++i){
                if(i%2==1){
                        ans += a[i];
                }       
        }       
        cout << ans << endl;
}       

Measured memory_bytes: 1408
#include <stdio.h>
#include <stack>
#include <vector>

static const int MAX = 100000;
static const int NIL = -1;

static int n;
static std::vector<int> G[MAX];
static int color[MAX];

static void dfs(int r, int c)
{
    std::stack<int> s;
    s.push(r);
    color[r] = c;

    while (!s.empty()) {
        int u = s.top();
        s.pop();
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i];
            if (color[v] == NIL) {
                color[v] = c;
                s.push(v);
            }
        }
    }
}

static void assignColor()
{
    int id = 1;
    for (int i = 0; i < n; i++) {
        color[i] = NIL;
    }
    for (int i = 0; i < n; i++) {
        if (color[i] == NIL)
            dfs(i, id++);
    }
}

int main()
{
    int m, q;

    scanf("%d %d", &n, &m);

    for (int i = 0; i < m; i++) {
        int s, t;
        scanf("%d %d", &s, &t);
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    scanf("%d", &q);

    for (int i = 0; i < q; i++) {
        int s, t;
        scanf("%d %d", &s, &t);
        if (color[s] == color[t]) {
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }

    return 0;
}


Measured memory_bytes: 8512
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<utility>


using namespace std;

struct Enemy
{
public:
    long pos;
    long HP;
};

bool cmp( Enemy& E1, Enemy& E2 ){
    return E1.pos < E2.pos;
}

int main(){
    int N;
    long D, A;
    cin >> N >> D >> A;

    long X,H;

    vector<Enemy> Elist(N);
    queue<pair<int, long>> Bombs; 

    for(int i=0;i<N;++i){
        cin >> X >> H;
        Elist[i].pos = X;
        Elist[i].HP = H;
    }

    sort( Elist.begin(), Elist.end(), cmp);

    long numBomb;
    long tempNum;
    numBomb = 0;

    long damage;
    damage = 0;
        
    // for(auto e : Elist){
    //     printf("%d %d\n", e.pos, e.HP);
    // }
    
    int inow;
    inow = 0;
    int id;
    id = 0;
    Enemy Enow;

    while(true){

        while( !Bombs.empty() && Bombs.front().first < inow ){
            damage -= Bombs.front().second * A;
            Bombs.pop();
        }
        
        Enow = Elist[inow];
        
        tempNum = Enow.HP > damage ? (Enow.HP - damage - 1) / A + 1 : 0;
        numBomb += tempNum;
        damage += tempNum * A; 

        
        while(  id < N && Elist[id].pos <= Enow.pos + 2 * D ) ++id;
       
        if(tempNum>0) Bombs.push( make_pair( id-1, tempNum ) );

        ++inow;
        if( inow == N ) break;
    }

    printf("%ld\n", numBomb );
    
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long

using namespace std;

int main() {
    fast_io;

    int a, b;
    cin >> a >> b;

    for (int p = b * 10; p < (b + 1) * 10; p++) {
        if (p * 8 / 100 == a) {
            cout << p << endl;
            return 0;
        }
    }
    
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


    public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		while(true){//?????????????????????????????§??\?????????????????°???????????????
			int tyuukan = scan.nextInt();//???????????????????????°
			int kimatu = scan.nextInt();//???????????????????????°
			int tuishi = scan.nextInt();//???????¨?????????°

			if(tyuukan == -1 && kimatu == -1 && tuishi == -1)//??\????????¨???-1??????????????????
				break;
			else if(tyuukan == -1 || kimatu == -1)//??????????????????????????????????¬????????????´???????????????F???
					System.out.println("F");
			else if(tyuukan + kimatu >= 80)//????????¨?????????????¨???????80?????\????????´???????????????A???
				System.out.println("A");
			else if(tyuukan + kimatu >= 65)//????????¨?????????????¨???????65~79????????´???????????????B???
				System.out.println("B");
			else if(tyuukan + kimatu >= 50)//????????¨?????????????¨???????50~64????????´???????????????C???
				System.out.println("C");
			else if(tyuukan + kimatu >= 30)//????????¨?????????????¨???????30~49????????´???????????????D???
				if(tuishi >= 50)//?????????D??????????????????????????????????????????????????°???50?????\????????´???????????????C???
					System.out.println("C");
				else
					System.out.println("D");
			else//????????¨?????????????¨???????30??????????????´???????????????D???
				System.out.println("F");
		}
		scan.close();
	}
}

Measured memory_bytes: 26180
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
    

num = int(input()) 
ans = num2alpha(num)
print(ans.lower())  

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
int N;
ll A[100005];
ll Lgcd[100005];
ll Rgcd[100005];
const int inf=1e9+7;
int ans=0;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}
ll gcd(ll a, ll b)
{
  if(b>a) swap(a,b);
  if(b==0) return a;
  return gcd(b,a%b);
}
int main(void)
{
  cin >> N;
  Fill(Lgcd,inf);
  Fill(Rgcd,inf);
  for (int i = 1; i <= N; ++i)
    {
      cin >> A[i];
    }
  sort(A,A+N);
  ll ans=A[1];
  for(int i=2;i<=N;i++)
    {
      ans=gcd(ans,A[i]);
    }
  for (int i = 1; i <= N; ++i)
    {
      if(i==1) Lgcd[i]=A[i];
      else Lgcd[i]=gcd(A[i],Lgcd[i-1]);
    }
  for (int i = N; i >= 0; i--)
    {
      if(i==N) Rgcd[i]=A[i];
      else Rgcd[i]=gcd(A[i],Rgcd[i+1]);
    }
  for (int i = 1; i <= N; ++i)
    {
      if(i==1) ans=max(ans,Rgcd[i+1]);
      else if(i==N) ans=max(ans,Lgcd[i-1]);
      else
	{
	  ll tmp=gcd(Lgcd[i-1],Rgcd[i+1]);
	  ans=max(ans,tmp);
	}
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        int n = in.nextInt();
        int m = in.nextInt();

        int[] h = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            h[i] = in.nextInt();
        }

        List<Set<Integer>> obs = new ArrayList<>();
        for (int i = 0; i <= n; i++) {
            obs.add(new HashSet<>());
        }

        for (int i = 0; i < m; i++) {
            int a = in.nextInt();
            int b = in.nextInt();

            obs.get(a).add(b);
            obs.get(b).add(a);
        }

        int answer = 0;
        for (int i = 1; i <= n; i++) {
            boolean good = true;
            for (int o : obs.get(i)) {
                if (h[i] <= h[o]) {
                    good = false;
                    break;
                }
            }

            if (good) {
                answer++;
            }
        }

        out.println(answer);
    }
}


Measured memory_bytes: 79176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) (a).begin(),(a).end()
#define debug(x) cerr<<(#x)<<": "<<(x)<<endl

int n;
vector<int> a;

void show(map<int,int> mp, int size){
    rep1(i,size){
        cout << char('a'+mp[i]);
    }
    cout << endl;
}

int check(int m){
    // cout << char('a'+m-1) << "まで" << endl;
    map<int,int> mp;
    rep1(i,n-1){
        if(a[i-1] < a[i]) continue;
        if(m == 1) return false;
        int pos = a[i];
        mp.erase(mp.upper_bound(pos), mp.end());
        while(true){
            if(mp[pos] < m - 1){
                mp[pos]++;
                break;
            }
            mp.erase(--mp.end());
            pos--;
            if(pos==0) return false;
        }
        // show(mp,size);
    }
    return true;
}

int main(void){
    cin >> n;
    a.resize(n);
    rep(i,n) scanf("%d", &a[i]);
    int l = 0, r = n;
    while(l+1 < r){
        int m = (l+r)/2;
        if(check(m)){
            r = m;
        }else{
            l = m;
        }
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18l+7;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	ll w[n];
	ll v[n];
	int W;
	cin>>W;
	for(int i=0;i<n;i++)cin>>w[i]>>v[i];
	ll sum=0;
	for(int i=0;i<n;i++)sum+=v[i];
	int ans=0;
	ll dp[n+1][sum+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=sum;j++)
		dp[i][j]=INF;
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=sum;j++){
			if(i==0 || j==0)
			dp[i][j]=INF;
			else
			if(j-v[i-1]>0)
			dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i-1]]+w[i-1]);
			else
			if(j-v[i-1]==0 || i-1==0)
			dp[i][j]=min(dp[i-1][j],w[i-1]);
			else
			dp[i][j]=dp[i-1][j];
		}
		for(int j=0;j<=sum;j++){
			if(dp[i][j]<=W)
			ans=max(ans,j);
		}
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 82444
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            Array.Sort(line);
            int a = int.Parse(line[0]);
            int b = int.Parse(line[1]);
            int c = int.Parse(line[2]);
            int d = 3;
            if (a == b)
            {
                d--;
            }
            if (b == c)
            {
                d--;
            }
            Console.WriteLine(d);
        }
    }
}


Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

#define int long long

using namespace std;

int n,k;
int a[505];

bool check(int x){
    vector<int> v;
    for(int i=0;i<n;i++) {
        int t = a[i]%x;
        if(t) v.push_back(t);
    }
    sort(v.begin(),v.end());
    int now = 0,s = 0;
    for(int l = 0,r = v.size()-1;l<=r;){
        if(now>=0) now-=v[l],s+=v[l],l++;
        else now+=x-v[r],r--;

    }
    return !now&&s<=k;
}

int32_t main() {

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

    cin>>n>>k;
    int sum = 0;
    for(int i=0;i<n;i++) cin>>a[i],sum+=a[i];
    int ans = 0;
    for(int i=1;i<=sqrt(sum);i++){
        if(sum%i==0&&check(sum/i)) ans = max(ans,sum/i);
        else if(sum%i==0&&check(i)) ans = max(ans,i);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template <class T> void out(const T &val) { cout << val << endl; }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
const int maxn = 2e5 + 5;
int a[maxn];

int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        #if __cplusplus >= 201103L
        auto start = steady_clock::now();
        #endif
    #endif
    int n = read();
    ll sum = 0;
    rep(i, 1, n) {
        sf(a[i]);
        sum += a[i];
    }
    ll h = 0;
    ll ans = LLONG_MAX;
    rep(i, 1, n) {
        h += a[i];
        ll t = sum - h;
        ans = min(ans, abs(h - t));
    }
    out(ans);
    #ifdef LOCAL
        #if __cplusplus >= 201103L
        auto end = steady_clock::now();
        duration<double> time_span = duration_cast<duration<double>>(end - start);;
        printf("Total time: %.6fs\n", time_span.count());
        #endif
    #endif
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<utility>
#include<cstring>

using namespace std;

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

int main(){
  int T;
  scanf("%d",&T);
  while(T--){
    int N;
    scanf("%d",&N);
    vector<pair<int,int> > v[16];
    while(N--){
      char buf[2049];
      scanf("%s",buf);
      int l=strlen(buf);
      for(int i=0;i<l;i+=2){
	char n[3]={};
	n[0]=buf[i];
	n[1]=buf[i+1];
	int b=strtol(n,nullptr,16);
	for(int j=0;j<16;j++){
	  if(b>>j&1){
	    v[j].push_back((i==0)?make_pair(0,1):make_pair(i/gcd(i,l),l/gcd(i,l)));
	  }
	}
      }
    }
    int den=1;
    for(auto e:v){
      for(auto f:e){
	den=den*f.second/gcd(den,f.second);
	if(den>1024)goto fail;
      }
    }
    {
      int syn[1024]={};
      for(int i=0;i<16;i++){
	for(auto e:v[i]){
	  syn[e.first*den/e.second]|=1<<i;
	}
      }
      for(int i=0;i<den;i++){
	printf("%02X",syn[i]);
      }
      puts("");
      continue;
    }
  fail:
    puts("Too complex.");
  }
}

Measured memory_bytes: 1116