akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
 
 


//c++ templte for help............................................................................................................................................

typedef long long ll;

template<typename... T>
void print1(T... t){
	((cout<<t<<" "),...);
}

template<typename... T>
void print2(T... t){
		vector<vector<ll>> ans={t...};
		for(ll i=0;i<(ll)ans.size();i++){
			if(i!=0) cout<<"\t\t";
			else cout<<"\t";
			for(ll j=0;j<(ll)ans[i].size();j++){
				cout<<ans[i][j]<<" ";
			}
			if(i!=(ll)ans.size()-1)
			cout<<endl;
		}
}	
#define deb(...) {cout<<" [ "#__VA_ARGS__<<" : "; print1(__VA_ARGS__); cout<<"]"<<endl; }
#define vdeb(...) {cout<<" [ "#__VA_ARGS__<<" : "; print2(__VA_ARGS__); cout<<"]"<<endl;}

// to return everything in string
#define ret(...) {stringstream returnn;returnn<<__VA_ARGS__;return returnn.str();}

stringstream retvec;
template<typename... T>
void returnvector(T... t){
		vector<vector<ll>> ans={t...};
		for(ll i=0;i<(ll)ans.size();i++){
			for(ll j=0;j<(ll)ans[i].size();j++){
				retvec<<ans[i][j];
				if(j!=(ll)ans[i].size()-1)
					retvec<<" ";
			}
			if(i!=(ll)ans.size()-1)
				retvec<<endl;
		}
}
#define vret(...) {returnvector(__VA_ARGS__);return retvec.str();}
	


//for loop
#define fo(i,n) for(int i=0;i<(ll)n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
 
 
//to print vector element 
template<typename T>
void printV(T vec){
	fo(i,vec.size()) cout<<vec[i]<<" "<<flush;
	cout<<endl;
	}
	
 
#define M ll(1e9+7)
const ll INF=ll(1e9+5);
 
//iterate map
template<typename T>
void itR(T map){
	 for(auto itr=map.begin();itr!=map.end();itr++){
				deb(itr->first,itr->second);
			}
	cout<<endl;
}

//c++ template for help...........................................................................................................................................

string solve(){
	ll n;
	cin>>n;
	
	ll ans=0;
	for(int i=1;i<n;i++){
		ans+=(n-1)/i;
	}
	ret(ans);
}

int main() {
	cout<<setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);

	//ll testCase;
	//cin>>testCase;
	//for(ll tt=0;tt<testCase;tt++){
		string ans1=solve();
		if(ans1!="")
			cout<<ans1<<endl;
	//}
	return 0;
}


Measured memory_bytes: 3656
def adja(i):
    if int(i) != i and i > 0:
        return int(i)+1
    elif int(i) != i and i < 0:
        return int(i)
    else:
        return int(i)
def mod(i):
   return i + 2 * adja(i/p)

N = int(input())
p = -2
ans=[]
while (True):
    r = mod(N)
    N = adja(N / p)
    ans.append(str(r))
    if N == 1 or N == 0 :
        if N == 1:
            ans.append(str(1))
        break
print("".join(ans[::-1]))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    int n,x;
    cin>>n;

    int c=0;

    for(int i=0,j=1; i<n; i++)
    {
        cin>>x;

        if(x==j)
        {
            c++;
            j++;
        }
    }
    if(c==0)
        cout<<-1<<endl;
    else
    cout<<n-c<<endl;









    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (long long i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int sum,tmp;

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

    while(true) {
	cin>>sum;
	if(sum==0) break;
	tmp=0;
	REP(i,9) {
		int x;
		cin>>x;
		tmp+=x;
	}
	cout<<sum-tmp<<endl;
    }

	return 0;
}



Measured memory_bytes: 3148
#include <stdio.h>
#include <limits.h>
#define N 500000

void Merge(int *,int ,int ,int );
void MergeSort(int *,int ,int );

int s[N];
long count;

int main(){
  int i,n,left=0,right;
  scanf("%d",&n);
  right=n;
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  MergeSort(s,left,right);
  for(i=0;i<n-1;i++) printf("%d ",s[i]);
  printf("%d\n%d\n",s[n-1],count);
  return 0;
}

void Merge(int *s,int left,int mid,int right){
  int i,n1,n2,k,j;
  n1=mid-left;
  n2=right-mid;
  
  int L[n1+1],R[n2+1];
  
  for(i=0;i<n1;i++){
    L[i]=s[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=s[mid+i];
  }
  L[n1]=INT_MAX;
  R[n2]=INT_MAX;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      s[k]=L[i];
      i++;
    }
    else{
      s[k]=R[j];
      j++;
    }
    count++;
  }
}

void MergeSort(int *s,int left,int right){
  long mid;
  if(left+1<right){
    mid=(left+right)/2;
    MergeSort(s,left,mid);
    MergeSort(s,mid,right);
    Merge(s,left,mid,right);
  }
}

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

using i64 = int64_t;

int main(){
    int d, g;
    cin >> d >> g;
    vector<pair<int, int>> v;
    for(int i=0;i<d;++i){
        int p, c;
        cin >> p >> c;
        v.emplace_back(p, c);
    }
    int ans = 1000;
    for(int i=0;i<(1<<d);++i){
        int point = 0, num = 0;
        for(int j=0;j<d;++j){
            if((i>>j)&1){
                point += v[j].second + v[j].first*100*(j+1);
                num += v[j].first;
            }
        }
        for(int j=d-1;j>=0;--j){
            if(point >= g)break;
            if((i>>j)&1)continue;
            for(int k=0;k<v[j].first;++k){
                point += (j+1)*100;
                num++;
                if(point >= g)break;
                if(k == v[j].first-1)point += v[j].second;
            }
        }
        ans = min(ans, num);
    }

    cout << ans << endl;

    return 0;
}

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

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

    char s1, s2, s3, s4;
    s1 = s[0];
    s2 = s[1];
    s3 = s[2];
    s4 = s[3];

    if (s1 == s2)
    {
        if ((s3 == s4) & (s2 != s3))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else if (s1 == s3)
    {
        if ((s2 == s4) & (s2 != s3))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else if (s1 == s4)
    {
        if ((s2 == s3) & (s1 != s3))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define INF 10000000
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
using namespace std;
int main()
{
	long long n, m;
	cin >> n >> m;
	if (n == m)
	{
		cout << 2 << endl;
		return 0;
	}
	long long n1 = 0, n2 = n, m1 = 0, m2 = m;
	int cnt1 = 0;
	while (1)
	{
		long long tmp = min(n1 + n2, m2);
		m2 -= tmp;
		m1 += tmp;
		long long r = (n1 + n2) - tmp;
		m1 -= r;
		if (m1 <= 0 && m2 <= 0)
			break;
		cnt1++;
		long long sum = m1 + m2;
		if (n1 > 0)
		{
			n1--;
			sum--;
		}
		n2 -= sum / 2;
		if (sum % 2 != 0 && n2 > 0)
		{
			n1++;
			n2--;
		}
		if (n1 <= 0 && n2 <= 0)
			break;
		cnt1++;
	}
	int cnt2 = 0;
	n1 = 0;
	n2 = m;
	m1 = 0;
	m2 = n;
	while (1)
	{
		long long sum = m1 + m2;
		if (n1 > 0)
		{
			n1--;
			sum--;
		}
		n2 -= sum / 2;
		if (sum % 2 != 0 && n2 > 0)
		{
			n1++;
			n2--;
		}
		//cout << n1 << " " << n2 << " " << m1 << " " << m2 << endl;;
		if (n1 <= 0 && n2 <= 0)
			break;
		cnt2++;
		long long tmp = min(n1 + n2, m2);
		m2 -= tmp;
		m1 += tmp;
		long long r = (n1 + n2) - tmp;
		m1 -= r;
		//cout << n1 << " " << n2 << " " << m1 << " " << m2 << endl;
		if (m1 <= 0 && m2 <= 0)
			break;
		cnt2++;
	}
	//cout << cnt1 << " " << cnt2 << endl;
	int ans = min(cnt1, cnt2);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>

int main(){
	int a[3], i, j, min = 0, tmp = 0;

	scanf("%d %d %d", &a[0], &a[1], &a[2]);

	for (i = 0; i<3; i++){
		min = a[i];
		for (j = i + 1; j<3; j++){
			if (a[i]>a[j]){
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	printf("%d %d %d\n", a[0], a[1], a[2]);


	return 0;
}

Measured memory_bytes: 2664
def get_binaly_arr(num,digit):
    return list(bin(num)[2:].zfill(digit))

def get_droped_mat(mat,binaly_arr,direction):
    if direction == "H":# 行をdrop!
        return [mat[i] for i in range(len(mat)) if binaly_arr[i] != "0" ]
    elif direction == "W": # 列をdrop!
        return [[arr[i] for i in range(len(arr)) if binaly_arr[i] != "0" ] for arr in mat]
    else :
        print("INVALID DIRECTION!")

def count_black(mat):
    return sum([sum([1 for item in arr if item == "#"]) for arr in mat])
    
if __name__ == "__main__":
    H,W,K = list(map(int,input().split()))
    c = []
    for i in range(0,H):
        c.append(list(input()))

    H_pattern_num = 2 ** H
    W_pattern_num = 2 ** W
    count = 0
    ite_num = 0
    for i in range(0,H_pattern_num):
        for j in range(0,W_pattern_num):
            # バイナリ配列を生成
            H_binaly_arr = get_binaly_arr(i,H)
            W_binaly_arr = get_binaly_arr(j,W)

            mat_temp = c.copy()
            mat_temp = get_droped_mat(c,H_binaly_arr,direction="H")
            mat_temp = get_droped_mat(mat_temp,W_binaly_arr,direction="W")
            if K == count_black(mat_temp):
                count += 1
    print(count)

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

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

	double ans = 0.0;
	for(int i=1; i<=n; i++){
		double p = 1.0/n;
		int x = i;

		while(0<x && x<k){
			x *= 2;
			p *= 0.5;
		}
		ans += p;
	}

	cout << fixed << setprecision(15) << ans << endl;
}

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

int main() {
    int n,m,l;
    cin >> n >> m >> l;
    int array1[n][m];
    int array2[m][l];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> array1[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            cin >> array2[i][j];
        }
    }
    long array3[n][l];
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            array3[i][j]=0;
            for(int k=0;k<m;k++){
                array3[i][j]+=array1[i][k]*array2[k][j];
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j==0) cout << array3[i][j];
            else cout << " " << array3[i][j];
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3224
#include<stdio.h>

int main(void){
    double x, y;
    int d, r, j, k;
    double f;
    
    scanf("%lf %lf", &x, &y);
    j = x;
    k = y;
    d = x / y;
    r = j % k;
    f = x / y;
    
    printf("%d %d %lf\n", d, r, f);
    return 0;
}


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  ll K;
  cin>>K;
  vector<ll> A(K);
  for(int i(0);i<K;i++){
    cin>>A[i];
  }
  if(A[K-1] != 2){
    cout << -1 << endl;
    return 0;
  }
  ll nowl(2),nowh(2);
  for(int i(K-1);i>=1;i--){
    ll l = nowl,h = nowh+(A[i]-1);
    ll next1(-1),next2(-1);
    ll li = (l+A[i-1]-1)/A[i-1];
    ll hi = h/A[i-1];
    if(li > hi){
      cout << -1 << endl;
      return 0;
    }
    next1 = li*A[i-1];
    next2 = hi*A[i-1];


    nowl = next1;
    nowh = next2;
  }
  cout << nowl << " " << nowh+A[0]-1 << endl;
  return 0;
}



Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

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);
		}
	}
	return res;
}

ll n,m;

int main(){
	cin >> n >> m;
	vector<ll> vl = divisor(m);
	sort(ALL(vl));
	ll ans = -1;
	rep(i,vl.size()){
		ll num = m / vl[i];
		// cout << "!" << num << endl;
		if(num >= n)ans = vl[i];
		else break;
	}
	cout << ans << endl;
}


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

int bubbleSort(int, int*);
int main(){
  int n; cin >> n;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];

  int sorted = bubbleSort(n, a);
  for(int i=0; i<n-1; i++) cout << a[i] << " ";
  cout << a[n-1];
  cout << endl << sorted << endl;

  return 0;
}

int bubbleSort(int n, int* a){
  int count=0;
  for(int i=n-1; i>=0; i--){
    for(int j=0; j<i; j++){
      if(a[j]>a[j+1]){
        int p = a[j];
        a[j] = a[j+1];
        a[j+1] = p;
        count++;
      }
    }
  }
  return count;
}



Measured memory_bytes: 3120
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();

		Set<Integer> set = new HashSet<>();

		set.add(a);
		set.add(b);
		set.add(c);

		System.out.println(set.size());

	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
int main()
{
    string s;
    int q, t, f;
    char c;
    int add = 0;
    cin >> s >> q;
    deque<char> dq(s.size());
    for(int i = 0; i < s.size(); i++) dq[i] = s[i];
    for(int i = 0; i < q; i++){
        cin >> t;
        if(t == 1){
            add = (add ? 0 : 1);
        }
        if(t == 2){
            cin >> f >> c;
            if((add == 0 && f == 1) || (add == 1 && f == 2))
                    dq.push_front(c);
            else
                    dq.push_back(c);
        }
    }
    if(add == 1) reverse(dq.begin(), dq.end());
    for(int i = 0; i < dq.size(); i++){
        printf("%c", dq[i]);
    }
    cout << endl;
    return 0;
}

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

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

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


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

int main(){
  int a,b;
  cin>>a>>b;
  for(int i=1;i<4;i++){
    if(i!=a&&i!=b){
      cout<<i<<endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, d; cin >> n >> d;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		if (1LL * x * x + 1LL * y * y <= 1LL * d * d) ++cnt;
	}
	cout << cnt << "\n";
}

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	for ( int n; cin >> n, n; )
	{
		int res = 0;
		for ( int a = 0; a * a <= n; a++ )
		{
			for ( int b = a; b * b <= n; b++ )
			{
				for ( int c = b; c * c <= n; c++ )
				{
					for ( int d = c; d * d <= n; d++ )
					{
						res += a * a + b * b + c * c + d * d == n;
					}
				}
			}
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1192
#include<iostream>

#define N 101

int n;
int a[N];
int g[N][N];

using namespace std;
int main() {

    cin>>n;
    for(int i = 0; i < n; i++) cin>>a[i]>>a[i+1];
    

    int i = 1, j = 1, k = 1, min, b;
    while(1) {
        if(i == 1 && j == n+1) break;
        if(i == j) g[i][j] = 0;
        
        if(i != j) {
            min = (1<<21);
            for(int x = i; x < j; x++) {
                b = g[i][x] + g[x+1][j] + a[i-1] * a[x] * a[j];
                if(min > b) min = b;
            }
        
            g[i][j] = min;
        }
        
        i++;
        j++;
        if(j > n) {
            i = 1;
            j = ++k;
        }
    }

    cout<<g[1][n]<<endl;

    return 0;
}



Measured memory_bytes: 3128
import java.io.*;

public class Main{
               public static void main(String args[]) throws IOException{
               
               int x = 0;
               int h = 0;
               int m = 0;
               int s = 0;

               InputStreamReader isr = new InputStreamReader(System.in);
               BufferedReader br = new BufferedReader(isr);
               String buf = br.readLine();
                 
               x = Integer.parseInt(buf);
               
               h = x / 3600;
               m = (x - h * 3600) / 60;
               s = x - h * 3600 - m * 60;  

               System.out.println(h +":"+ m +":"+ s);

            }
     }

Measured memory_bytes: 24456
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

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

#define         rep(i,n)       for ( i=0 ; i<n ; ++i )
#define         rep1(i,n)      for ( i=1 ; i<=n ; ++i )
#define         sajo(str)      sort(str.begin(),str.end())
#define         rev(str)       reverse(str.begin(),str.end())
#define         usajo(str)     sort(str.rbegin(),str.rend())
#define         input(a)       for(auto &it : a) cin>>it
#define         pi             2*acos(0.0)
#define         nel            printf("\n")
#define         longmx         92233720368547758
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"YES"<<"\n"
#define         no             cout<<"NO"<<"\n"
#define         vcl            vector<ll>
#define         vpl            vector<pair<ll,ll>>
#define         pb             push_back
#define         mkp(x,y)       make_pair(x,y)
#define         ff             first
#define         sc             second
#define         spc            ' '
#define         nn             '\n'
#define         ikarus_101     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef         long long int  lli;
typedef         long long      ll;

int main(){ikarus_101

    unsigned long long int tc,n,m,a,b,c,d,x,y,i,j,l,r,k,ans,sum,tot,cnt,mx,mn,idx,tmp;

    cin>>n;
    unsigned long long int aa[n];
    ans = 1;
    rep(i,n) cin>>aa[i];
    sort(aa,aa+n);
    rep(i,n)
    {
        ans*=aa[i];
        if(ans <= 0)
        {
            cout<<'0'<<nn;
            return 0;
        }

        k = 1000000000000000000/ans;
        if(i+1<n && aa[i+1]>k)
        {
            cout<<-1<<nn;
            return 0;
        }

    }
    cout<<ans<<nn;
    return 0;
}


Measured memory_bytes: 4400
//45
#include<iostream>
#include<cmath>

#define S(X) ((X)*(X))

using namespace std;

int main(){
  int px[1001],py[1001],bn[1001],ni[1001];
  for(int n;cin>>n,n;){
    for(int i=0;i<n;i++){
      cin>>bn[i]>>px[i]>>py[i];
      ni[bn[i]]=i;
    }
    int m;
    cin>>m;
    while(m--){
      int s,g;
      cin>>s>>g;
      int p[1001];
      double d[1001];
      fill(p,p+1001,-1);
      fill(d,d+1001,1<<29);
      bool u[1001]={};
      d[ni[g]]=0;
      for(;;){
	int x,md=1<<29;
	for(int j=0;j<n;j++){
	  if(!u[j]&&md>d[j]){
	    x=j;
	    md=d[j];
	  }
	}
	if(md==1<<29)break;
	u[x]=true;
	for(int i=0;i<n;i++){
	  double ds=sqrt(S(px[x]-px[i])+S(py[x]-py[i]));
	  if(ds<=50&&d[x]+ds<d[i]){
	    d[i]=d[x]+ds;
	    p[i]=x;
	  }
	}
      }
      if(d[ni[s]]==1<<29){
	cout<<"NA"<<endl;
      }else{
	int i=ni[s];
	while(i!=-1){
	  cout<<((i==ni[s])?"":" ")<<bn[i];
	  i=p[i];
	}
	cout<<endl;
      }
    }
  }
  return 0;
}

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

using namespace std;
typedef long long int lli;

#define all(arr) arr.begin(),arr.end()
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define MOD 1000000007

template <typename T>
void input(vector<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.push_back(temp);
}

template <typename T>
void output(vector<T> arr) {
  for(auto x:arr) cout<<x<<" ";
  cout<<endl;
}


template <typename T>
void input_set(set<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.insert(temp);
}

lli mul(lli a, lli b) {
  return (a%MOD*b%MOD)%MOD;
}

lli power(lli num,lli base) {
  lli ans = 1;
  while(base>0) {
    if(base&1)
      ans = mul(ans, num);

    num = mul(num, num);
    base >>= 1;
  }

  return ans;
}

void solve() {
  int n, x;
  cin >> x >> n;
  vector<int> arr;
  input(arr, n);
  sort(all(arr));
  int t1 = x;
  while(true) {
    int ind = lower_bound(all(arr), t1) - arr.begin();
    if(ind<0 or ind==n or arr[ind]!=t1)
      break;
    --t1;
  }

  int t2 = x;
  while(true) {
    int ind = lower_bound(all(arr), t2) - arr.begin();
    if(ind<0 or ind==n or arr[ind]!=t2)
      break;
    ++t2;
  }

  int mi = min(abs(x-t1), abs(x-t2));
  if(mi==abs(x-t1))
    cout << t1 << endl;
  else
    cout << t2 << endl;
}

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

  lli testcases=1;
  while(testcases--) {
    solve();
  }
}



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

using namespace std;

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

	double sum = 0, d;
	for (int i = 0; i < n; i++) {
		cin >> d;
		sum += 1.0 / d;
	}

	printf("%.10f\n", 1.0 / sum);

	return 0;
}


Measured memory_bytes: 256
import copy
N,W = map(int,input().split())
w = []
v = []
for i in range(N):
    a,b = map(int,input().split())
    w.append(a)
    v.append(b)
dp = [0] * (W+1)
tmp_dp = [0] * (W+1)
for i in range(N):
    tmp_dp = copy.copy(dp)
    for j in range(W):
        if dp[j] != 0:
            if j + w[i] <= W:
                if dp[j + w[i]] < tmp_dp[j] + v[i]:
                    dp[j + w[i]] = tmp_dp[j] + v[i]
    if dp[w[i]] < v[i]:
        dp[w[i]] = v[i]
print(max(dp))

Measured memory_bytes: 153724
#include<iostream>
#include<vector>

using namespace std;

int main(){
  vector<int> table(1000001,0);
  table[0]=table[1]=1;
  
  for(int i=4;i<1000001;i+=2)
    table[i]=1;
  for(int i=3;i<1000001;i+=2){
    if(table[i]==0)
      for(int j=i+i;j<1000001;j+=i)
	table[j]=1;
  }
  
  int a,b,n;
  while(scanf("%d%d%d",&a,&b,&n),n+a+b){
    while(n){
      if(a>1000000){
	printf("error\n");
	break;
      }
      if(table[a]==0) n--;
      a+=b;
    }
    printf("%d\n",a-b);
  }
  
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
	char s[101];
	scanf("%s",s);
	int i=0;
	while (s[i]!=0){
		i++;
	}
	printf("%c%d%c\n",s[0],i-2,s[i-1]);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main(){
    int A,B,K; cin >> A >> B >> K;

    if(K >= (B-A+2)/2){
        for(int i=A;i<=B;i++){
            cout << i << endl;
        }
        return 0;
    }

    for(int i=A;i<A+K;i++){
        cout << i << endl;
    }
    for(int i=B-K+1;i<=B;i++){
        cout << i << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int numOfCards = s.nextInt();
		int numOverlap = 0;
		Set<Integer> cards = new HashSet<Integer>();
		for(int i = 0; i< numOfCards; i++){
			int tmp = s.nextInt();
			if(!cards.contains(tmp)){
				cards.add(tmp);
			}else{
				numOverlap++;
			}
		}
		if(numOverlap % 2 == 0){
			System.out.println(numOfCards - numOverlap);
		}else{
			System.out.println(numOfCards - numOverlap-1);
		}
	}

}


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

typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

// cout<<fixed<<setprecision(10);
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(){
    int h, a; cin >> h >> a;
    int ans = 0;
    while(true){
        ans++;
        h = h-a;
        if(h<=0){
            break;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<algorithm>

using namespace std;

int main() {
	int i;
	string S;
	int count = 0;
	cin >> S;

	for (i = 0; i < S.size()/2; ++i) {
		if (S[i] != S[S.size() - i-1]) {
			++count;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a)      cout<<a<<" "
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll minize(ll& a,ll b){return a=(a>b?b:a);}
inline ll maxize(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5],dp[3],dpc[4];

ll Solves(){
	
	ll n,m,k,cnt=1,ans=0,x,y,q,c=0,sum=0,v,t;
	// PROCESS IN HERE
	sc2(n,m); string s;
	sc(s);
	vector<pll> vec;
	fu(i,1,le(s)){
		if(i==le(s) or s[i]!=s[i-1]){
			vec.pb(mp(s[i-1]-'0',cnt));
			cnt=1;
		}		
		else cnt++;
	}
	
	queue<pll> qu;
	cnt=0;
	fuv(i,vec){
		while(sz(qu) and dpc[0]==m and vec[i].fi==0){
			dp[qu.front().fi]-=qu.front().se;
			dpc[qu.front().fi]--;
			qu.pop();
		}
		dp[vec[i].fi]+=vec[i].se;
		dpc[vec[i].fi]++;
		maxize(ans,dp[0]+dp[1]);
		qu.push(vec[i]);
	}
	pr(ans);
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 2880
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int X;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> X;

	int K = 1;
	while (K * X % 360 != 0) K++;
	cout << K << endl;
}







Measured memory_bytes: 3624
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

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

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, N);
    vector<i64> a(N);
    read(a);

    i64 ans = 0;
    rep(i, 1, N) {
        if (a[i - 1] <= a[i]) continue;
        ans += a[i - 1] - a[i];
        a[i] = a[i - 1];
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 4760
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  int a,b;
  cin >> a >> b;
  
  if(a == 1) a = 14;
  if(b == 1) b = 14;
  
  if(a > b)  cout << "Alice" << endl;
  if(a < b)  cout << "Bob" << endl;
  if(a == b) cout << "Draw" << endl;
  
  return 0;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
	string s;
	cin >> s;
	reverse(s.begin(), s.end());

	for (int i = 0; i < 4; i++) reverse(divide[i].begin(), divide[i].end());

	bool can = true;
	for (int i = 0; i < s.size();) {
		bool can2 = false;
		for (int j = 0; j < 4; j++) {
			if (s.substr(i, divide[j].size()) == divide[j]) {
				can2 = true;
				i += divide[j].size();
			}
		}
		if (!can2) {
			can = false;
			break;
		}
	}
	if (can) cout << "YES" << endl;
	else cout << "NO" << endl; 
} 

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#define N 400011
#define MAX 1000000007
#define int long long
using namespace std;
struct point{
	int x,y,z;
}ee[N];
struct node{
	int no,data;
	bool operator<(const node &other)const{
		return data>other.data;
	}
}temp;
priority_queue<node> pq;
struct apple{
	int v,nxt,q;
}edge[N*4];
int indexx[N],tot,n,m,vist[N],dist[N],dis[2][N],sum[2][N],ans,que[N];
int S,T,Ans,d[N];
void addedge(int x,int y,int z){
	edge[++tot].v=y;
	edge[tot].q=z;
	edge[tot].nxt=indexx[x];
	indexx[x]=tot;
}
void dij(int st){
	memset(dist,0x3f,sizeof(dist));
	memset(vist,0,sizeof(vist));
	temp.no=st;
	temp.data=0;
	dist[st]=0;
	pq.push(temp);
	while(!pq.empty()){
		temp=pq.top();pq.pop();
		int x=temp.no;
		if(vist[x]) continue;
		vist[x]=1;
		int t=indexx[x],vv,qq;
		while(t){
			vv=edge[t].v;
			qq=edge[t].q;
			if(dist[vv]>dist[x]+qq){
				dist[vv]=dist[x]+qq;
				temp.no=vv,temp.data=dist[vv];
				pq.push(temp);
			}
			t=edge[t].nxt;
		}
	}
}
void bfs(int st,int k){
	int head=0,tail=0;
	que[++tail]=st;
	sum[k][st]=1; 
	while(head<tail){
		int x=que[++head];
		int t=indexx[x],vv;
		while(t){
			vv=edge[t].v;
			d[vv]--;
			sum[k][vv]=(sum[k][vv]+sum[k][x])%MAX;
			if(!d[vv]){
				que[++tail]=vv;
			}
			t=edge[t].nxt;
		}
	}
}
signed main(){
	int x,y,z;
	scanf("%lld%lld",&n,&m);
	scanf("%lld%lld",&S,&T);
	for(int i=1;i<=m;i++){
		scanf("%lld%lld%lld",&x,&y,&z);
		ee[i].x=x;
		ee[i].y=y;
		ee[i].z=z;
		addedge(x,y,z);
		addedge(y,x,z);
	}
	dij(S);Ans=dist[T];
	for(int i=1;i<=n;i++) dis[0][i]=dist[i];
	memset(indexx,0,sizeof(indexx));tot=0;
	for(int i=1;i<=m;i++){
		if(dist[ee[i].x]>dist[ee[i].y]) swap(ee[i].x,ee[i].y);
		if(dist[ee[i].x]+ee[i].z==dist[ee[i].y]){
			addedge(ee[i].x,ee[i].y,1);
			d[ee[i].y]++;
		}
	}
	bfs(S,0);
	memset(d,0,sizeof(d));
	memset(indexx,0,sizeof(indexx));tot=0;
	for(int i=1;i<=m;i++){
		addedge(ee[i].x,ee[i].y,ee[i].z);
		addedge(ee[i].y,ee[i].x,ee[i].z);
	}
	dij(T);
	for(int i=1;i<=n;i++) dis[1][i]=dist[i];
	memset(indexx,0,sizeof(indexx));tot=0;
	for(int i=1;i<=m;i++){
		if(dist[ee[i].x]>dist[ee[i].y]) swap(ee[i].x,ee[i].y);
		if(dist[ee[i].x]+ee[i].z==dist[ee[i].y]){
			addedge(ee[i].x,ee[i].y,1);
			d[ee[i].y]++;
		}
	}
	bfs(T,1);
	ans=sum[0][T]*sum[0][T]%MAX;
	for(int i=1;i<=m;i++){
		x=ee[i].x,y=ee[i].y,z=ee[i].z;
		if(dis[0][x]>dis[0][y]) swap(x,y);
		if(dis[0][x]+dis[1][y]+z==Ans){
			int t=sum[0][x]*sum[1][y]%MAX;
			if(abs(dis[0][x]-dis[1][y])<z){
				ans=(ans-t*t%MAX+MAX)%MAX;
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(dis[0][i]==dis[1][i] && dis[0][i]+dis[1][i]==Ans){
			int t=sum[0][i]*sum[1][i]%MAX;
			ans=(ans-t*t%MAX)%MAX;
		}
	}
	ans=(ans%MAX+MAX)%MAX;
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 35416
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll A, B, ans, p, q;
priority_queue<ll> L;
priority_queue<ll,vector<ll>,greater<ll>> R;
ll topL(){return p=L.top()+A;}
ll topR(){return q=R.top()+B;}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    rep(i,N){
        int l,r; cin>>l>>r;
        int len = r-l;
        B+=len;
        L.push(r-A); R.push(r-B);
        while(topL()>topR()){
            ans+=p-q;
            L.pop(); R.pop();
            L.push(q-A); R.push(p-B);
        }
        A-=len;
    }
    cout1(ans);
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

template<typename T>
struct BIT{
    int N;
    vector<T> dat;
    BIT(int n) : N(n), dat(n+1,0){ }
    void add(int i, T num){
        for(int x = i+1; x <= N; x += (x & -x)) dat[x] += num;
    }
    T sum(int i){
        T ret = 0;
        for(int x = i+1; x > 0; x -= (x & -x)) ret += dat[x];
        return ret;
    }
    T sum(int i, int j){
        return sum(j) - sum(i-1);
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    char s[n]; cin >> s;
    vector<BIT<int>> bits(30, BIT<int>(n+1));
    rep(i,n){
        int c = s[i] - 'a';
        bits[c].add(i, 1);
    }
    int q; cin >> q;
    rep(i,q){
        int t; cin >> t;
        if(t == 1){
            int x; char c;
            cin >> x >> c;
            x--;
            bits[s[x]-'a'].add(x, -1);
            bits[c-'a'].add(x, 1);
            s[x] = c;
        }else{
            int l,r; cin >> l >> r;
            l--; r--;
            int ans = 0;
            rep(i,26){
                if(bits[i].sum(l,r) > 0) ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 61440
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxi=500005;
ll bit[26][maxi];

void update(ll val,ll idx,ll p)
{
    for(ll i=idx;i<maxi;i+=(i&-i))
        bit[p][i]+=val;
}
ll getsum(ll idx,ll p)
{
    ll ans=0;
    for(ll i=idx;i>0;i-=(i&-i))
        ans+=bit[p][i];
    return ans;
}
int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        ll idx=(ll)(s[i]-'a');
        update(1,i+1,idx);
    }
    ll q;
    cin>>q;
    while(q--)
    {
        ll a;
        cin>>a;
        if(a==1)
        {
            ll pos;
            char ch;
            cin>>pos>>ch;
            ll id=(ll)(s[pos-1]-'a');
            ll id1=(ll)(ch-'a');
            update(-1,pos,id);
            update(1,pos,id1);
            s[pos-1]=ch;
        }
        else
        {
            ll l,r;
            cin>>l>>r;
            ll cnt=0;
            for(int i=0;i<26;i++)
            {
                if(getsum(r,i)-getsum(l-1,i) > 0)
                    cnt++;
            }
            cout<<cnt<<"\n";
        }
    }
}


Measured memory_bytes: 102532
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

    int q;
    cin >> q;

    int rev = 0;

    queue<char> fr, en;

    rep(i, q) {
        int t;
        cin >> t;
        if (t == 1) {
            rev++;
        }
        else {
            int f;
            char c;
            cin >> f >> c;
            f--;
            f += rev;
            f %= 2;
            if (f == 0) {
                fr.push(c);
            }
            else {
                en.push(c);
            }
        }
    }

    if (rev % 2) {
        reverse(all(s));
        
        for (int i = 0, v = fr.size(); i < v; i++) {
            char c = fr.front();
            fr.pop();
            s += c;
        }
        for (int i = 0, v = en.size(); i < v; i++) {
            char c = en.front();
            en.pop();
            string cs{c};
            s.insert(0, cs);
        }
    }
    else {
        for (int i = 0, v = fr.size(); i < v; i++) {
            char c = fr.front();
            fr.pop();
            string cs{c};
            s.insert(0, cs);
        }
        for (int i = 0, v = en.size(); i < v; i++) {
            char c = en.front();
            en.pop();
            s += c;
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std ;
void solve() {
	int n, K;
	cin >> n >> K;
	int arr[n];
	for (int i = 0; i < n; ++i)
		cin >> arr[i];
	int dp[n];
	dp[n - 1] = 0;
	for (int i = n - 2; i >= 0; --i) {
		dp[i] = INT_MAX;
		for (int j = 1; j <= K && i + j < n; j++) {
			dp[i] = min(dp[i], dp[i + j] + abs(arr[i] - arr[i + j]));
		}

	}
	cout << dp[0];
}

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


Measured memory_bytes: 4376
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#define inf 1000000007
#define rep(i,n) for(long i=0;i<n;i++)

typedef long long ll;
using namespace std;


using ll = long long int;
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M) %M;
}


//モジュラ逆元
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}



int main(){
    
    
    long n,a,b;
    cin >> n >> a >> b;
    long ans=RepeatSquaring(2, n, inf)-1;
    
    //nCa
    //分子
    long x1=1;
    for (long i=0;i<a;i++){
        x1*=(n-i);
        x1%=inf;
    }
    //分母
    long y1=1;
    for(long i=1;i<=a;i++){
        y1*=i;
        y1%=inf;
    }
    long nCa=x1*modinv(y1,inf)%inf;
    
    //nCb
    //分子
    long x2=1;
    for (long i=0;i<b;i++){
        x2*=(n-i);
        x2%=inf;
    }
    //分母
    long y2=1;
    for(long i=1;i<=b;i++){
        y2*=i;
        y2%=inf;
    }
    long nCb=x2*modinv(y2,inf)%inf;
    
    ans-=nCa;
    ans+=inf;
    ans%=inf;
    ans-=nCb;
    ans+=inf;
    ans%=inf;
    cout << ans << endl;
  
}




Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, m = map(int,input().split())
c = [0] + list(map(int,input().split()))

dp = [[0] + [n+1 for _ in range(n)] for _ in range(m+1)]
for i in range(1,m+1):
    for j in range(1,n+1):
        if j >=c[i]:
            dp[i][j] = min(dp[i-1][j],dp[i][j-c[i]]+1)
        else:
            dp[i][j] = dp[i-1][j]

print (dp[m][n])


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

using namespace std;
int m,n=3,f[100005][5],a[100005][5];

int lonnhat(int i,int k)
{
    int kq=0;
    for (int j=1;j<=n;j++)
        if (j!=k)
        kq=max(kq,f[i][j]);
    return kq;
}
int main()
{
    int kq=0;
    cin>>m;
    for (int i=0;i<=m;i++)
    for (int j=1;j<=n;j++)
        if (i==0)
            f[i][j]=0;
            else
        cin>>a[i][j];
    for (int i=1;i<=m;i++)
    for (int j=1;j<=n;j++)
        f[i][j]=lonnhat(i-1,j)+a[i][j];
    for (int j=1;j<=n;j++)
        kq=max(kq,f[m][j]);
    cout<<kq;
}


Measured memory_bytes: 4096
#include <stdio.h>

int main(void){
	int n,cnt=0,x[100];
	char str[100];

	for( ; ; ){
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%d",&n);
		if(n==0){
			cnt--;
			if(cnt<0)
				return 0;
			printf("%d\n",x[cnt]);
		}
		else
			x[cnt++]=n;
	}
}

Measured memory_bytes: 612