akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

long int n,m,used[100001]={0},a[100001]={0};

int cmp(const void* x, const void* y) {
	long int a = *(const long int*)x, b = *(const long int*)y;
	return a > b ? -1 : a < b;
}


void display_scores(void){
    long int i,j;
    printf("   |");
    for(i=1;i<=n;i++){
        printf("%7ld    ",i);
    };
    printf("\n---+");
    for(i=1;i<=n;i++){
        printf("-----------");
    };
    printf("\n");
    for(j=1;j<=n;j++){
        printf("%2ld |",j);
        for(i=1;i<j;i++){
            printf("        ");
        };
        for(i=1;i<=n;i++){
            if(i<=used[j])putchar('*');else putchar(' ');
            printf("%-10ld",a[i]+a[j]);
        };
        printf("\n");
    };
    return;
};

long int count_larger_combintion(long int x){
    long int low,high,mid,i,j,ans=0,prev_threshold;
    prev_threshold=n;
    for(i=1;i<=n;i++){
        low=1;
        high=prev_threshold;
        if(a[i]+a[1]<x){
            for(j=i;j<=n;j++) used[j]=0;
            return ans;
        };
        if(a[i]+a[high]>=x){
            used[i]=high;
            ans+=high;
            continue;
        };
        while(high-low>1){
            mid=(high+low)/2;
            if(a[i]+a[mid]>=x){
                low=mid;
            }else{
                high=mid;
            };
        };
        ans+=low;
        used[i]=low;
        prev_threshold=low;
    }
    return ans;
};


int main(void){
    long int i,xlow, xhigh, x,larger_num=0,threshold;
    long int sum[100001],ans=0;
    scanf("%ld %ld",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%ld",&a[i]);
    };
    qsort(&a[1],n,sizeof(a[1]),cmp);
    xlow=2*a[n];
    xhigh=2*a[1];
    while(larger_num!=m && xhigh-xlow>1){
        x=xlow+(xhigh-xlow)/2;
        larger_num=count_larger_combintion(x);
        if(larger_num>=m) xlow=x;
        if(larger_num<m) xhigh=x;
        //printf("x=%d, num=%d\n",x,larger_num);
        //display_scores();
    };
    threshold=xlow;
    //printf("result: threshold=%d\n",threshold);
    sum[1]=a[1];
    for(i=2;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
    };
    for(i=1;i<=n;i++){
        ans+=a[i]*used[i]+sum[used[i]];
    };
    ans-=(larger_num-m)*threshold;
    printf("%ld",ans);
    return 0;
};


Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N; cin >> N;
    ll a;
    unordered_map<ll, ll> A; REP(i, N) {
        cin >> a;
        A[a] = i+1;
    }

    REP (i, N-1) {
        cout << A[i+1] << ' ';
    }
    cout << A[N] << '\n';
    return 0;
}



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

int main()
{
int A,B,C,D;    
cin>>A>>B>>C>>D;
    
if (A+B==C+D){
 cout<<"Balanced"<<endl;   
}
else if(A+B>C+D){
 cout<<"Left"<<endl;   
}
else if(A+B<C+D){
 cout<<"Right"<<endl;   
}
}


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

int main() {
    string s;
    cin >> s;
    
    if (s.size() == 1) {
        cout << s << endl;
        return 0;
    }
    int ans = s[0] - '0' - 1 + (s.size() - 1) * 9;
    bool all_nine = true;
    rep(i,s.size()) if (i > 0 && s[i] != '9') all_nine = false;
    if (all_nine) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
 
count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                count += 1
 
print(count)

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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  int i, j;
  int ans = 0;
  int ansmax = 0;
  vector<bool> kind(26, false);
  vector<bool> kind2(26, false);
  for(i = 1; i < n; i++)
  {
    for(j = 0; j < i; j++)
    {
      if(kind.at(s.at(j)-'a') == false)
      {
        kind.at(s.at(j)-'a') = true;
      }
    }
    for(j = i; j < n; j++)
    {
      if(kind2.at(s.at(j)-'a') == false)
      {
        kind2.at(s.at(j)-'a') = true;
      }
    }
    ans = 0;
    for(j = 0; j < 26; j++)
    {
      if(kind.at(j) == true && kind2.at(j) == true) ans++;
      kind.at(j) = false;
      kind2.at(j) = false;
    }
    if(ans > ansmax) ansmax = ans;
  }
  cout << ansmax << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std ;
 
int n ;
int w_size , s_size ;
string word ;
string s ;
 
int f( int p ){
     
    for( int k=1 ; k<w_size ; k++ ){
        if( word[k] == s[p%s_size] ) p++ ;
        else return 0 ;
    }
     
    return 1 ;
}
 
int main(){
     
    cin >> word ;
    cin >> n ;
     
    w_size = word.size() ;
     
    int ans=0 ;
    for( int i=0 ; i<n ; i++ ){
        cin >> s ;
        s_size = s.size() ;
        for( int j=0 ; j<s_size ; j++ ){
            if( word[0] == s[j] && f(j+1) ){
                ans++;
                break ;
            }
        }
    }
     
    cout << ans << endl ;
     
return 0 ;
}

Measured memory_bytes: 3124
import math
n,k = map(int,input().split())
prob = 0.0
for i in range(1,n+1):
  if i >= k:
    prob += 1/n
  else:
    omote_count = math.ceil(math.log2(k/i))
    prob += ((1/2)**omote_count ) * (1/n) 
  
print(prob)

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

int main() {
  int a, b;
  cin >> a >> b;

  if ((a+b)%3 == 0) cout << "Possible" << endl;
  else if (a%3 == 0) cout << "Possible" << endl;
  else if (b%3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

int retl(int K,int L){
    int tmp=0;
    while(pow(2,tmp) * L < K){
        tmp++;
    }
    return tmp;
}

struct A{
    string s;
    int p;
    int order;
};


int main(){
    int N,X;
  
    

    cin  >> N>>X;
    int L[N];
    int sum=0;
    int count=1;
    FOR(i,N){
        cin >>L[i];
        sum+=L[i];
        if(sum<=X){
            count++;
        }
    }
    int ans=count;
    

  
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int counter = 0;
      	int K = sc.nextInt();
        long[] a = new long[K];
      	a[0] = 7 % K;
      	
        
        for (int i = 1; i < K; i++) {
        	a[i] = (10 * a[i-1] + 7) % (long)K;
        }
		for (int i = 0; i < K; i++) {
        	if (a[i] == 0) {
            	counter = i + 1;
              	break;
            }
        }  
      	if (counter == 0) {counter = -1;}
      	System.out.println(counter);
	}	
}

Measured memory_bytes: 43456
//#include </Users/piyush/Desktop/nodejs/first-app/CP/bits/stdc++.h>
 #include <bits/stdc++.h>
typedef long long ll;
using namespace std;


#define print(x) for(auto iuiuiuiuiui:x){ cout<<iuiuiuiuiui<<" ";}br;

#define br cout<<"\n"
//const int INF=1e9+5;
const ll INF=1e18L+5;


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);


    ll n, total_w;
    cin>>n>>total_w;

    vector<ll> weight(n),value(n);


    ll w,v,maxi=INT_MIN;

    ll sum_value=0;

    for(ll i=0;i<n;i++){
        cin>>w>>v;
        weight[i]=w;
        value[i]=v;
        sum_value+=v;
    }

    vector<ll> item_value(sum_value+1,INF);

    item_value[0]=0;

    for(ll i=0;i<n;i++){
        w=weight[i];
        v=value[i];

        for(ll j=sum_value-v; j>=0;--j){
            item_value[j+v]=min(item_value[j+v],item_value[j]+w);
        }

    }

    ll ans=-INF;

    for(ll i=0;i<sum_value+1;i++){
        if(item_value[i]<=total_w){
            ans=max(ans,i);
        }
    }


    cout<<ans;






}

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

int main() {
  vector<int> x(5);
  int ans;
  for(int i=0; i<5; i++) {
    cin >> x[i];
    if(x[i]==0) ans=i+1;
  }
  cout << ans << endl;
}


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

int main(){
  int N,K,sum=0;
  cin>>N>>K;
  vector<int> kudamono(N);
  for(int i=0; i<N; i++){
    cin>>kudamono.at(i);
  }
  sort(kudamono.begin(),kudamono.end());
  for(int j=0; j<K; j++){
    sum+=kudamono.at(j);
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3588
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int health1 = sc.nextInt();
    int strength1 = sc.nextInt();
    int health2 = sc.nextInt();
    int strength2 = sc.nextInt();
    while (true) {
      health2 -= strength1;
      if ( health2 <= 0) break;
      health1 -= strength2;
      if (health1 <=0) break;
    }
    if (health1 > health2) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 35720
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define per(i,a,b) for (int i=(b)-1;i>=a;i--)
#define sz(a) (int) a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
//-----
const double eps = 1e-8;
const int inf = 0x7f7f7f7f;
const int N=1e5+5;
const int mod=1e9+7;
int a[N];
int main()
{
	int n;scanf("%d",&n);
	ll ans = 0;
	rep(i,0,n) scanf("%d",&a[i]);
	sort(a,a+n);
	if(n & 1) {
		int x = a[n/2-1],y = a[n/2],z = a[n/2+1];
		rep(i,0,n/2-1) {
			ans -= 2 * a[i];
		}
		rep(i,n/2+2,n) {
			ans += 2*a[i];
		}
		ans += max(2*z-x-y,z+y-2*x);
	}else {
		rep(i,0,n/2-1) {
			ans -= 2 * a[i];
		}
		rep(i,n/2+1,n) {
			ans += 2 * a[i];
		}
		ans -= a[n/2-1];
		ans += a[n/2];
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef vector<int> lnum;
const int base = 1000*1000*1000;
#define pb push_back
#define mp make_pair


const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const ll LINF = (ll)INF * INF;
int ans[200001];
int main()
{
	//memset(dpT , -1 , sizeof dpT);
	ios_base::sync_with_stdio(0);
	//freopen("input.txt" , "r"  , stdin);
	int n;
	cin >> n;
	int Ans = 0;
	for(int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		ans[x] = ans[x - 1] + 1;
		Ans = max(Ans , ans[x]);
	}
	cout << n - Ans << endl;



}




Measured memory_bytes: 1024
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}



const ll N=2e5+1;

ll fac[N],inv[N];


void fill(ll N,ll p){
  fac[0]=inv[0]=1;

  for(int i=1;i<N;i++){
    fac[i]=fac[i-1]*i%p;
    inv[i]=powM(fac[i],p-2,p);
  }
}

ll c(ll a,ll b,ll p){
if(a<b)return 0;

  return (fac[a]*inv[a-b]%p)*(inv[b])%p;
}

int main()
{ 

IOS;

fill(N,M);

ll n;cin>>n;
ll k;
cin>>k;

vl a(n);

FOR(i,n)cin>>a[i];

sort(all(a));

ll ans=0;

FOR(i,n){
ans=(ans-a[i]*c(n-i-1,k-1,M)%M)%M;
}
rev(a);

FOR(i,n){
ans=(ans+a[i]*c(n-i-1,k-1,M)%M)%M;
}

cout<<(ans+M)%M;

//end_routine();

return 0;
 
 }


Measured memory_bytes: 7208
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

int main() {
  std::size_t n, m;
  std::cin >> n >> m;

  std::vector<std::size_t> a(n);
  for (std::size_t i = 0; i < n; ++i) std::cin >> a[i];

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

  std::vector<std::size_t> b(m);
  std::vector<std::size_t> c(m);
  std::vector<std::size_t> ids(m);
  for (std::size_t i = 0; i < m; ++i) std::cin >> b[i] >> c[i];
  for (std::size_t i = 0; i < m; ++i) ids[i] = i;
  std::sort(ids.begin(), ids.end(),
            [&c](auto i, auto j) { return c[i] > c[j]; });

  std::size_t k = 0;
  for (std::size_t i = 0; i < m; ++i) {
    const auto id = ids[i];
    const auto bi = b[id];
    const auto ci = c[id];
    for (std::size_t j = 0; j < bi; ++j) {
      if (a[k] < ci) {
        a[k] = ci;
        ++k;
      } else {
        break;
      }
    }
  }

  const auto sum = std::accumulate(a.begin(), a.end(), 0ull);
  std::cout << sum << std::endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    vb ans(n, false);
    vi cnt(n, 1);
    ans[0] = true;
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        if (ans[x]) {
            if (cnt[x] == 1) ans[x] = false;
            ans[y] = true;
        }
        cnt[x]--;
        cnt[y]++;
    }
    cout << accumulate(ans.begin(), ans.end(), 0) << endl;
}

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

int main(void){
  int H, W, K;
  scanf("%d %d %d ", &H, &W, &K);
  char c[6][6]={'0'}, t[6][6]={'0'};
  for(int i=0;i<H;i++){
    scanf("%s", c[i]);
  }
  for(int i=0;i<6;i++){
    for(int j=0;j<6;j++){
      t[i][j]=c[i][j];
    }
  }

  int cnt=0, sh=0, bit=0;
  while(bit < pow(2, H+W)){
//    printf("%o ", bit);
    for(int i=0;i<H;i++){
      if(bit & (1<<i)){
        for(int j=0;j<W;j++){
          c[i][j]='R';
        }
      }
    }
    for(int j=0;j<W;j++){
      if(bit & (1<<(H+j))){
        for(int i=0;i<H;i++){
          c[i][j]='R';
        }
      }
    }

    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(c[i][j]=='#') sh++;
      }
    }

    if(sh == K) cnt++;
    for(int i=0;i<H;i++){
      //printf("%s\n", c[i]);
    }
//    printf("sh %d\n", sh);
    
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        c[i][j]=t[i][j];
      }
    }
    sh=0;
    bit++;
  }  

  printf("%d", cnt);
  return 0;
}

Measured memory_bytes: 2176
# input
N = int(input())
A = list(map(int, input().split()))

full_root = [0] + A + [0]
full_place = [abs(full_root[i] - full_root[i + 1]) for i in range(N + 1)]
full_res = sum(full_place)
# check
for ind in range(1, N + 1):
    res = full_res - sum(full_place[ind - 1:ind + 1]) + abs(full_root[ind - 1] - full_root[ind + 1])

    print(res)

Measured memory_bytes: 20540
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		String s1 = sc.next();
		String s2 = sc.next();
		
		// 計算
		long result = 0L;
		long MOD = 1000000007L;
		boolean flg = false;
		for(int i = 0; i < n; i++){
		    if(s1.charAt(i) == s2.charAt(i)){
		        if(i == 0){
		            result = 3;
		        }else if(flg){
		            result *= 2;
		            result %= MOD;
		        }
		        flg = true;
		    }else{
		        if(i == 0){
		            result = 6;
		        }else if(flg){
		            result *= 2;
		            result %= MOD;
		        }else{
		            result *= 3;
		            result %= MOD;
		        }
		        i++;
		        flg = false;
		    }
		}
		
		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 23764
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{

public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		List<Integer> firstList  = new ArrayList<>();
		List<Integer> secondList  = new ArrayList<>();
		for(int i = 0;i < 6;i++){
			
			firstList.add(Integer.parseInt(sc.next()));
		}
		for(int i = 0;i < 6;i++){
			
			secondList.add(Integer.parseInt(sc.next()));
		}
		
		
		Dice dice1 = new Main().new Dice(firstList);
		Dice dice2 = new Main().new Dice(secondList);
		
		System.out.println(dice1.isIdenticalTo(dice2));
		
		sc.close();
		

	}
	
	
	class Dice{
		
		private int one;
		private int two;
		private int three;
		private int four;
		private int five;
		private int six;
		
		Dice(List<Integer> arg){
			
			if(arg == null || arg.size() != 6){
				throw new IllegalArgumentException();
			}
			
			this.one  = arg.get(0);
			this.two  = arg.get(1);
			this.three= arg.get(2);
			this.four = arg.get(3);
			this.five = arg.get(4);
			this.six  = arg.get(5);
			
		}
		
		
		Dice roll(String direction){
			int tmp;
			switch(direction){
			
			case "N":
				
				tmp = this.five;
				this.five = this.one;
				this.one  = this.two;
				this.two  = this.six;
				this.six  = tmp;
				break;
				
			case "S":
				tmp = this.five;
				this.five = this.six;
				this.six  = this.two;
				this.two  = this.one;
				this.one  = tmp;
				break;
			case "W":
				tmp = this.one;
				this.one = this.three;
				this.three  = this.six;
				this.six  = this.four;
				this.four  = tmp;
				break;
				
			case "E":
				tmp = this.one;
				this.one = this.four;
				this.four  = this.six;
				this.six  = this.three;
				this.three  = tmp;
				break;
			}
			
			return this;
		}
		
		
		int showTop(){
			return this.one;
		}
		
		int showFront(){
			return this.two;
		}
		
		int showRight(){
			return this.three;
		}
		
		int showLeft(){
			return this.four;
		}
		
		int showBack(){
			return this.five;
		}
		
		int showDown(){
			return this.six;
		}

		public String isIdenticalTo(Dice dice) {
			
			for(int i = 0; i <4 ;i++){
				
				for(int j = 0; j<4 ;j++){
				
					dice.roll("E");
					if(this.one == dice.one &&
					this.two == dice.two    &&
					this.three==dice.three  &&
					this.four ==dice.four   &&
					this.five ==dice.five   &&
					this.six  ==dice.six    
					){
						return "Yes";
					}
					
				}
				
				dice.roll("N");
				
			}
			
			dice.roll("E");
			
			for(int i = 0; i <4 ;i++){
				
				for(int j = 0; j<4 ;j++){
				
					dice.roll("E");
					if(this.one == dice.one &&
					this.two == dice.two    &&
					this.three==dice.three  &&
					this.four ==dice.four   &&
					this.five ==dice.five   &&
					this.six  ==dice.six    
					){
						return "Yes";
					}
					
				}
				
				dice.roll("N");
				
			}
			
			return "No";
		}
		
	}

}



Measured memory_bytes: 26212
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)


int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	 #endif

    FAST
	//PRECISE



ll x,k,d;
cin>>x>>k>>d;
x=abs(x);
ll ans=0;

	ll y=x/d;
	if(y<=k){
	ll z1=y*d;	
	x-=y*d;
	k-=y;
	ll a1=x;
	ll a2=abs(x-d);
	if(k%2==0)ans=a1;
	else ans=a2;}
	else{
		ans=x-k*d;
	}

cout<<ans;


return 0;
 }
 

Measured memory_bytes: 3648
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()

li = sorted(map(int, input().split()))
i = 0
while True:
    if X - i not in li:
        print(X - i)
        exit()

    if X + i not in li:
        print(X + i)
        exit()

    i += 1


Measured memory_bytes: 61960
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair 
#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 debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
#define all(x) (x).begin(),(x).end()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using ii = pair<int, int>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using pil = pair<int,ll>;
using vvi = vector<vi>;
using vpi = vector<ii>;

const int N = 100100;
ll mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x),b(y),c(z);
    rep(i,0,x-1){
        cin>>a[i];
    }
    rep(i,0,y-1){
        cin>>b[i];
    }
    rep(i,0,z-1){
        cin>>c[i];
    }
    sort(c.rbegin(),c.rend());
    priority_queue<pll> q;

    rep(i,0,x-1){
        rep(j,0,y-1){
            q.push(mp(a[i]+b[j]+c[0],0));
        }
    }
    rep(i,0,k-1){
        auto fr = q.top();
        q.pop();
        cout<< fr.F << nl;
        int se = fr.S;
        if(se == z - 1){
            continue;
        }
        q.push(mp(fr.F - c[se] + c[se+1], se + 1));
    }
    return 0;
}


Measured memory_bytes: 19764
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <climits>
#include <iomanip>
 
using namespace std;

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
 
	int n;
	cin >> n;

	vector<int> seconds(n);
	vector<int> max_speeds(n);

	for (int i = 0; i < (int) seconds.size(); ++i) {
		cin >> seconds[i];
		if (i != 0)
			seconds[i] += seconds[i - 1];
	}

	for (int i = 0; i < (int) max_speeds.size(); ++i) {
		cin >> max_speeds[i];
	}

	int max_time = seconds[n - 1];

	const int INF = 1e9;
	vector<vector<double>> dp(max_time + 1);//dp[i][j] - distance at the end of i second, if we have speed j;

	for (int i = 0; i <= max_time; ++i) {
		dp[i].resize(101, -INF);
	}
	
	dp[0][0] = 0;

	for (int i = 1; i <= max_time; ++i) {
		int max_speed = max_speeds[0];
		for (int j = 1; j < (int) seconds.size(); ++j) {
			if (i > seconds[j - 1] && i <= seconds[j])
				max_speed = max_speeds[j];
		}
		for (int j = 0; j <= max_speed; ++j) {
			if (j != 0 && dp[i - 1][j - 1] != -INF) 
				dp[i][j] = max(dp[i - 1][j - 1] + (double)(j + (j - 1)) / 2, dp[i][j]);
			
			if (j != max_speed && dp[i - 1][j + 1] != -INF)
				dp[i][j] = max(dp[i - 1][j + 1] + (double)(j + j + 1) / 2, dp[i][j]);
			
			if (dp[i - 1][j] != -INF)
				dp[i][j] = max(dp[i - 1][j] + j, dp[i][j]);

			if (dp[i - 1][j] != -INF && j != max_speed) 
				dp[i][j] = max(dp[i - 1][j] + (j + j + 0.5f) / 2, dp[i][j]);

			if (dp[i - 1][j] != -INF && j != 0) 
				dp[i][j] = max(dp[i - 1][j] + (j + j - 0.5f) / 2, dp[i][j]);
		}
	}

	cout << setprecision(15) << fixed << (double)dp[max_time][0] << endl;

	return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   f(i,1,50000+1){
      double v = i;
      v = v*1.08;
      int val = v;
      if(val == n){
         cout << i << '\n';
         return 0;
      }
   }
   cout << ":(\n";
   return 0;
} 

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


long long dp[1001];



int main(){
	int m;
	int a[7],b[7];
	while(cin>>m&&m){
		memset(dp,0,sizeof(dp));
		for(int i=0;i<m;i++){
			cin>>a[i]>>b[i];
		}
		dp[0]=1;
		for(int i=0;i<m;i++){
			for(int j=1000;j>=0;j--){
				for(int k=1;k<=b[i];k++){
					if(1000<j+k*a[i])break;
					dp[j+k*a[i]]+=dp[j];
				}
			}
		}
		int g;
		cin>>g;
		for(int i=0;i<g;i++){
			int n;
			cin>>n;
			cout<<dp[n]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int n,m;
    cin>>n>>m;
    vector<vector<int>> g(n);
    for(int i=0;i<m;i++) {
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=0;i<n;i++) {
        cout<<g[i].size()<<endl;
    }
    return 0;
}


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

typedef long long LL;
typedef unsigned long long ULL;

const int PI = 3.141592653589793;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;

int main(){

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

        int a, b, c, d; cin >> a >> b >> c  >> d;

        int y = c / b + (c % b > 0);
        int n = a / d + (a % d > 0);
        if (y <= n) {
                cout << "Yes\n";
        }
        else cout << "No\n";

        return 0;
}



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

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj(n, vector<int>(n, 0));
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        adj[a-1][b-1] = 1;
        adj[b-1][a-1] = 1;
    }
    vector<int> check(n, 0);
    queue<int> q;
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i; j < n; j++){
            if(adj[i][j] == 0) continue;
            adj[i][j] = 0;
            adj[j][i] = 0;
            q.push(0);
            while(!q.empty()){
                int node = q.front();
                q.pop();
                if(check[node] == 1) continue;
                check[node] = 1;
                for(int k = 0; k < n; k++){
                    if(adj[node][k] == 1) q.push(k);
                }
            }
            int sum = 0;
            for(int k = 0; k < n; k++){
                sum += check[k];
                check[k] = 0;
            }
            if(sum < n) ans++;
            adj[i][j] = 1;
            adj[j][i] = 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
'use strict'

const main = input => {
	const args = input.trim().split(' ')
	if (args[0] === 'H' && args[1] === 'H') console.log('H')
	else if (args[0] === 'H' && args[1] === 'D') console.log('D')
	else if (args[0] === 'D' && args[1] === 'H') console.log('D')
	else console.log('H')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21956
#include <bits/stdc++.h>
#include <atcoder/all>
#define MOD (int)(998244353)
using namespace std;
using namespace atcoder;

// as + bt = GCD(a,b) a,b:const s,t:var(any)
// return GCD(a,b)
long long extGCD(long long a, long long b, long long& s, long long& t) {
  s = 1, t = 0;
  long long u = 0, v = 1;
  while (b) {
    long long tmp = a / b;
    a -= b * tmp;
    s -= u * tmp;
    t -= v * tmp;
    swap(s, u);
    swap(t, v);
    swap(a, b);
  }
  return a;
}
// (mod)x+ay=1, calculate y -> a^-1 (mod m) (a,m : coprime)
long long calcinv(long long a, long long m) {
  long long s, t;
  extGCD(a, m, s, t);
  return (s + m) % m;
}

using P = pair<int, int>;
int n;
vector<vector<long long>> memo;
priority_queue<P, vector<P>, greater<P>> pq;

int main() {
  cin >> n;
  {
    map<int, int> mp;
    for (int i = 0; i < 2 * n; ++i) {
      int x;
      cin >> x;
      ++mp[x];
    }
    for (auto [_, p] : mp) {
      vector<long long> v(1, 1);
      long long now = 1, cnt = 1;
      for (long long i = p; i > 1;) {
        (now *= i--) %= MOD;
        (now *= i--) %= MOD;
        (now *= calcinv(2 * cnt++, MOD)) %= MOD;
        v.push_back(now);
      }
      pq.push(P(v.size(), memo.size()));
      memo.push_back(v);
    }
  }
  while (pq.size() > 1) {
    P l = pq.top(), r;
    pq.pop();
    r = pq.top();
    pq.pop();
    memo[l.second] = convolution(memo[l.second], memo[r.second]);
    pq.push(P(memo[l.second].size(), l.second));
  }
  int id = pq.top().second;
  vector<long long> oddf(2, 1);
  for (int i = 3; i <= 2 * n; i += 2) {
    long long now = oddf.back() * i % MOD;
    oddf.push_back(now);
  }
  long long res = 0, len = memo[id].size();
  for (int i = 0; i < len; ++i) {
    long long now = memo[id][i] * oddf[n - i] % MOD;
    if (i & 1)
      (res += MOD - now) %= MOD;
    else
      (res += now) %= MOD;
  }
  cout << res << endl;
  return 0;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;


signed main() {
    int N, M;
    cin >> N >> M;
    if (N == M)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int i, a,b, c, n;
  cin >> a >> b >> c;
  n = 0;
  for(i=a;i<=b;i++) 
  {
    if (c%i==0)
    n++;   
  } 
   cout << n << endl;
   
   return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int N,M,K,X;
   cin>>N>>M;
   int cnt=0;
   map<int,int> A;
   rep(i,N){
       cin>>K;
       rep(j,K){
           cin>>X;
           A[X]++;
       }
   }
   for (auto p:A){
       
       auto v=p.second;
       if(v==N){
           cnt++;
       }
   }
   cout<<cnt<<endl;
}

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

int main(void){
  string ref1 = "";
  string ref2 = "";
  string a;
  cin >> a;

  for (int i = 0;i < a.length(); i++){
    if (i %2 ==0){
      ref1 = "1" + ref1;
      ref2 = "0" + ref2;
    }
    else{
      ref2 = "1" + ref2;
      ref1 = "0" + ref1;
      // ref2 = ref2 + pow(10, i);
    }
  }

  int count1 = 0;
  int count2 = 0;

  for (int i = 0; i < ref1.length(); i++){
    if(ref1[i] != a[i]){
      count1 = count1 + 1;
    }  
  }  

  for (int i = 0; i < ref2.length(); i++){
    if(ref2[i] != a[i]){
      count2 = count2 + 1;
    }  
  }

  if (count1 < count2){
    cout << count1 << endl;
  }
  else{
    cout << count2 << endl;
  }
}


Measured memory_bytes: 912
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
//#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)

int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
const int maxn = 1000 + 10;
vi adj[maxn];
int d[maxn], par[maxn];
int32_t main(){
	IOS;
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		string s;
		cin >> s;
		for(int j=0; j<n; j++){
			if(s[j] == '1')
				adj[i].push_back(j);
		}
	}
	int ans = 1000;
	bool ok = true;
	int best = 0;
	for(int i=0; i<n; i++){
		memset(d, 63, sizeof d);
		d[i] = 0;
		queue<int> q;
		q.push(i);
		while(q.size()){
			int v = q.front();
			q.pop();
			for(auto u : adj[v])
				if(d[u] > d[v] + 1){
					d[u] = d[v] + 1;
					par[u] = v;
					best = max(best, d[u]);
					q.push(u);
				}
		}
		for(int v=0; v<n; v++){
			for(auto u : adj[v]){
				if(u != par[v] && v != par[u])
					ans = min(ans, d[u] + d[v] + 1);
				if((d[u] - d[v]) % 2 == 0)
					ok = false;
			}
		}	
	}
	if(!ok)
		cout << -1 << endl;
	else{
		cout << best + 1 << endl;
	}
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define mp make_pair
#define rep(a,b,c) for(int a=1;a<=b;a+=c)
#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)

const double PI=acos(-1);
const double EPS=1e-12;
const int MOD=1e9+7;
const int INF=1<<30;


using namespace std;


int main(){
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int a,b;
	b=38;
	a=b*b-b+1;
	cout<<a<<" "<<b<<endl;
	int st[1005],end[1005],pos[1005],cnt[1005];
	st[1]=2;
	end[1]=b;
	repp(i,2,b,1){
		st[i]=st[i-1]+b-1;
		end[i]=end[i-1]+b-1;
		pos[i]=st[i];
		cnt[i]=i;
	}
	rep(i,b,1){
		if(i==1){
			rep(j,b,1){
				cout<<i<<" ";
				repp(k,st[j],end[j],1){
					cout<<k;
					if(k!=end[j])cout<<" ";
					else cout<<endl;
				}
			}
		}
		else{
			rep(j,b-1,1){
				cout<<i<<" ";
				repp(k,2,b,1){
					int temp=(pos[k]+j-1);
					if(temp>end[k])temp=(temp%(end[k]+1))+st[k];
					cout<<temp;
					if(k!=b)cout<<" ";
					else cout<<endl;
				}
			}
			repp(j,2,b,1){
				pos[j]+=cnt[j];
				if(pos[j]>end[j])pos[j]=(pos[j]%(end[j]+1))+st[j];
			}
		}
	}
	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1 << 30
#define LLINF LLONG_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}
ll power(ll x,ll n){ll a=1;REP(i,n)a*=x;return a;}

int K,T;

int main()
{
  cin >> K >> T;
  vector<int> a(T,0);
  REP(i,T) cin >> a[i];
  int ans = 0, last = -1;
  while(K>0)
  {
    int m = 0, mi = -1;
    REP(i,T)
    {
      if(i==last) continue;
      if(a[i] > m)
      {
        mi = i;
        m = a[i];
      }
    }
    if(m == 0)
    {
      ans = a[last];
      break;
    }
    a[mi]--;
    last = mi;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//const int N = 51;
//ll dp[N][N*N+N][N];
//void _(){
//    int n,a;
//    cin >> n >> a;
//    vi arr(n);
//    cin >> arr;
//    dp[0][0][0] = 1;
//    for(int i = 0; i < n; ++i)
//        for(int sum = 0; sum < N*N; ++sum){
//            for(int cnt = 0; cnt <= i; ++cnt){
//                dp[i+1][sum+arr[i]][cnt+1] += dp[i][sum][cnt];
//                dp[i+1][sum][cnt] += dp[i][sum][cnt];
//            }
//        }
//    ll ans = 0;
//    for(int sum = 0; sum < N*N; ++sum)
//        for(int cnt = 0; cnt < N; ++cnt)
//            if(cnt*a == sum)
//                ans += dp[n][sum][cnt];
//    print(ans-1);
//
//
//}
//
//
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define all(v) (v).begin(), (v).end()
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<int> vi;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
T1 void print(T x, string end = "\n"){
    cout << x << end;
}
const int N = 51;
ll dp[N][N*N+N][N];
void _(){
    int n,a;
    cin >> n >> a;
    vi arr(n);
    cin >> arr;
    dp[0][0][0] = 1;
    for(int i = 0; i < n; ++i)
        for(int sum = 0; sum < N*N; ++sum){
            for(int cnt = 0; cnt <= i; ++cnt){
                dp[i+1][sum+arr[i]][cnt+1] += dp[i][sum][cnt];
                dp[i+1][sum][cnt] += dp[i][sum][cnt];
            }
        }
    ll ans = 0;
    for(int sum = 0; sum < N*N; ++sum)
        for(int cnt = 0; cnt < N; ++cnt)
            if(cnt*a == sum)
                ans += dp[n][sum][cnt];
    print(ans-1);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        _();
}


Measured memory_bytes: 53120
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;

typedef long double ld;

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
	ll k,n;
	cin>>k>>n;
	
	ll arr[n];
	
	for(ll i=0;i<n;i++)cin>>arr[i];

	
	ll ans = 1e18;
	
	for(ll i=0;i<n;i++)
	{
		ll val = arr[n-1]-arr[i];
		if(i!=0){
			val += k-arr[n-1];
			val += arr[i-1];
		}
		ans = min(ans,val);
		//cout<<val<<" ";
		val = arr[i]-arr[0];
		if(i!=n-1)
		{
			val += arr[0];
			val += k-arr[i+1];
		}
		//cout<<val<<endl;
		ans = min(ans,val);
	}
	
	cout<<ans;
		
	
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
int main()
{
    char in[10];
    while (~scanf("%s", in+1)) {
        bool flg = false;
        REP(i,2,4) if(in[i]==in[i-1]) flg=true;
        puts(flg ? "Bad" : "Good");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> kati(N);
    vector<int> cost(N);
    for(int i=0; i<N; i++){
        cin >> kati.at(i);
    }
    for(int i=0; i<N; i++){
        cin >> cost.at(i);
    }

    int sum=0;
    for(int i=0; i<N; i++){
        if(kati.at(i) - cost.at(i) >=0){
            sum += kati.at(i) - cost.at(i);
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

vector<int> factors(int n){
    vector<int> ret;
    for(int i = 1; i*i <= n; i ++) if(n % i == 0) ret.push_back(i), ret.push_back(n/i);
    return ret;
}

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    
    auto v = factors(a[0]), w = factors(a[1]);
    v.insert(v.end(), w.begin(), w.end());
    Sort(v); Unique(v);
    
    int ans = 1;
    for(const auto &e : v){
        int k = 0;
        For(i, n) if(a[i] % e != 0) k ++;
        if(k <= 1) ans = e;
    }
    
    Cout(ans);
}

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

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef long long ll;

#define maxn 200000

int a[maxn],b[maxn],c[maxn],d[maxn];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n; cin >> n;
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];

  int ans = 0;

  rep(k,29){ // k bit目
    ll tmp = 0; // k bit目が1の数
    ll t = 1ll << k;
    rep(i,n){
      c[i] = a[i] & (2 * t - 1);
      d[i] = b[i] & (2 * t - 1);
    }
    sort(d, d + n);
    rep(i,n){ // a_i
      tmp += lower_bound(d,d+n,2*t-c[i]) - lower_bound(d,d+n,t-c[i]);
      tmp += lower_bound(d,d+n,4*t-c[i]) - lower_bound(d,d+n,3*t-c[i]);
    }
    if(tmp & 1) ans += t;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll a,b;
  cin>>a>>b;
  vvc t(100,vc(100));
  rep(i,100){
    rep(j,100){
      if(i<50){
        t[i][j]='#';
      }
      else t[i][j]='.';
    }
  }
  a--;
  b--;
  for(int i=0;i<50;i+=2){
    for(int j=0;j<100;j+=2){
      if(a>0){
        t[i][j]='.';
        a--;
      }
    }
  }
  for(int i=99;i>=50;i-=2){
    for(int j=0;j<100;j+=2){
      if(b>0){
        t[i][j]='#';
        b--;
      }
    }
  }
  cout<<100<<" "<<100<<endl;
  rep(i,100){
    rep(j,100){
      cout<<t[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[200000];
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];

  int mx=a[n-1],ans=-1e9;
  for(int i=n-2;i>=0;i--){
    if(mx-a[i]>ans)ans=mx-a[i];     
    if(mx<a[i])mx=a[i];
    }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 1940