akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      long long n,c=0,i;
      cin>>n;
      long long a[n],b[n];
      for(i=0;i<n;i++)
      {
      cin>>a[i];
      b[i]=a[i];
      }
      sort(b,b+n);
      for(i=0;i<n;i++)
      {
      	if(a[i]==b[i])
      	c++;
      }
      if(c==n-2 || c==n)
      cout<<"YES"<<endl;
      else
      cout<<"NO"<<endl;
    }
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

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

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  sort(ALL(a));

  ll mi = a[0];
  ll ma = a[n-1];

  vector<pair<ll, ll>> ops;

  for (int i = 1; i < n - 1; i++) {
    if (a[i] >= 0) {
      ops.push_back({mi, a[i]});
      mi -= a[i];
    } else {
      ops.push_back({ma, a[i]});
      ma -= a[i];
    }
  }

  ops.push_back({ma, mi});
  ll ans = ma - mi;

  cout << ans << endl;
  for (auto& p : ops) {
    cout << p.first << " " << p.second << endl;
  }

  return 0;
}


Measured memory_bytes: 6092
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  if (K%2==0) cout << A-B << endl;
  else cout << B-A << endl;
}

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

int main()
{
    int n, s[100005], q, t[50005];
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> s[i];
    cin >> q;
    int count = 0;
    for(int i=0; i<q; i++)
    {
        cin >> t[i];
        if(*lower_bound(s, s+n, t[i])==t[i])
        {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3576
n, k = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = [0]

for a in A:
    B.append(B[-1] + a)

C = []

for i in range(n+1):
    for j in range(i, n+1):
        C.append(B[j] - B[i])

ans = 0
flag = False
D = []

for i in range(40, -1, -1):
    if flag:
        C = D
        flag = False
    D = []
    bit = 1 << i
    for c in C:
        if bit & c:
            D.append(c)
    if len(D) >= k:
        flag = True
        ans += bit
    
print(ans)

Measured memory_bytes: 65916
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int kaijou(int n){
    int ret = 1;
    for(int i=1; i < n + 1; ++i) {
        ret = ret * i;
    }
    return ret;
}

int calcOrder(int N, vector<int>& S){
    int order = 0;
    vector<bool> visited(N+1, false);

    for(int i = 1; i < N+1; ++i){
        int cnt = 0;
        for(int j = 1; j < S[i]; ++j){
            if(!visited[j]) ++cnt;
        }
        visited[S[i]] = true;
        order += kaijou(N - i) * cnt;
    }

    return order + 1;
}

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

    vector<int> P(N+1), Q(N+1);

    for(int i = 1; i < N+1; ++i){
        cin >> P[i];
    }

    for(int i = 1; i < N+1; ++i){
        cin >> Q[i];
    }

    cout << abs(calcOrder(N, P) - calcOrder(N, Q)) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

ll llabs(ll a, ll b){
  return(a < b ? b - a : a - b);
}

int main(){
  
  int n;
  ll a[111111], b[111111], amax, amin, bmax, bmin;
  
  cin >> n;
  for(int i = 0; i < n; i++){
    int x, y; cin >> x >> y;
    a[i] = x + y;
    b[i] = x - y;
  }
  
  amax = *max_element(a, a + n);
  amin = *min_element(a, a + n);
  bmax = *max_element(b, b + n);
  bmin = *min_element(b, b + n);

  ll aaa = 0, bbb = 0;
  for(int i = 0; i < n; i++){
    aaa = max(aaa, min(max(llabs(amax - a[i]), llabs(bmax - b[i])), max(llabs(amin - a[i]), llabs(bmin - b[i]))));
    bbb = max(bbb, min(max(llabs(amax - a[i]), llabs(bmin - b[i])), max(llabs(amin - a[i]), llabs(bmax - b[i]))));
  }
  cout << min(aaa, bbb) << endl;
}

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

#define int long long
#define pb push_back
#define F first
#define S second
#define MAX 10000000
#define MOD 1000000007
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef pair<int, int> PII;


signed main(){
  int n,k; cin>>n>>k;
    int arr[n];
 
    for (int i = 0; i < n; ++i)
    {
        cin>>arr[i];
    }
    int dp[k+1];
 
    for (int i = 0; i < arr[0]; ++i)
    {
        dp[i] = 0;
    }
 
    for (int i = arr[0]; i <= k; ++i)
    {
        dp[i] = 1;
        for (int j = 0; j < n && arr[j] <= i; ++j)
        {
            dp[i] = min(dp[i], dp[i-arr[j]]);
        }
        dp[i] = dp[i]^1;
    }
 
    if(dp[k])
        cout<<"First";
    else
        cout<<"Second";
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;

ll suff[500],n,p[500],dp[500][500];

ll rek(int l, int r) {
	if(dp[l][r]) return dp[l][r];
	if(r - l == 0) return dp[l][r] = 0;
	dp[l][r] = 1e15;
	for(int i = l; i < r; i++)
		dp[l][r] = min(dp[l][r], rek(l, i) + rek(i + 1, r) + suff[r] - suff[l - 1]);
	return dp[l][r];
}

int main() {
	
	scanf("%d ", &n);

	for(int i = 1; i <= n; i++) {
		scanf("%d", &p[i]);
		suff[i] += p[i];
		if(i) suff[i] += suff[i - 1];
	}
	
	printf("%lld\n", rek(1, n));
	
	/*for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			printf("%lld ", dp[i][j]);
		}
		printf("\n");
	}*/
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;
const int mod = 1e9+7;
int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int lcs(string a, string b) {
  int n = a.size(), m = b.size();
  int dp[2][m+1];
  for(int i = 0;i <= n;i++) {
    for(int j = 0;j <= m;j++) {
      if(i==0||j==0) dp[i%2][j] = 0;
      else {
        if(a[i-1] == b[j-1]) dp[i%2][j] = 1 + dp[1-i%2][j-1];
        else dp[i%2][j] = max(dp[i%2][j-1], dp[1-i%2][j]);
      }
    }
  }
  return dp[n%2][m];
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

bool equal(string s) {
  for(int i = 0,j = s.size()/2;j < s.size();i++,j++) {
    if(s[i] != s[j]) return false;
  }
  return true;
}

ll fact(int n) {
  ll ans = 1;
  fr(i,2,n+1) ans = (ans*i)%mod;
  return ans;
}

int main() {
  int k,s;
  cin>>k>>s;
  int n = 2550*2550;
  vector<int> left(n), right(n);
  frn(a,k+1) {
    frn(b,k+1) {
      left[a+b]++;
    }
  }
  frn(c,k+1) {
    if(s >= c) right[s-c]++;
  }
  int ans = 0;
  frn(i,left.size()) {
    ans += left[i]*right[i];
  }
  cout<<ans;
}



Measured memory_bytes: 51072
import java.util.*;

public class Main {
    static long[][] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for(int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        //dp on the answer for [l,r]
        dp = new long[N][N];
        for(int i = 0; i < N; i++) {
            dp[i][i] = a[i];
        }
        System.out.println(rec(0,N-1,a));
    }
    public static long rec(int l,int r, int[] a){
        if(dp[l][r] > 0) return dp[l][r];
        //l < r guaranteed
        long takeLeft = a[l] - rec(l+1,r,a);
        long takeRight = a[r] - rec(l,r-1,a);
        long ans = Math.max(takeLeft,takeRight);
        dp[l][r] = ans;
        return ans;
    }
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N, Q);
  vector< ll > a(N);
  REP(i, N) {
    cin >> a[i];
  }
  
  REP(qi, Q) {
    LCIN(x);

    ll sm = 0ll;
    int ub = 0;
    ll ans = 0ll;
    REP(lb, N) {
      while (ub < N) {
	if (sm + a[ub] > x) {
	  break;
	}
	sm += a[ub++];
      }
      ans += ub - lb;
      sm -= a[lb];
    }
    cout << ans << endl;
  }

  return 0;
}




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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    // - + - + ... にする場合
    ll cnt = 0;
    ll sum = 0;
    rep(i, N) {
        sum += a[i];
        if (i % 2) {
            if (sum <= 0) {
                cnt += abs(sum) + 1;
                sum = 1;
            }
        } else {
            if (sum >= 0) {
                cnt += abs(sum) + 1;
                sum = -1;
            }
        }
    }
    ll ans = cnt;

    // + - + - ... にする場合
    cnt = 0;
    sum = 0;
    rep(i, N) {
        sum += a[i];
        if (i % 2 == 0) {
            if (sum <= 0) {
                cnt += abs(sum) + 1;
                sum = 1;
            }
        } else {
            if (sum >= 0) {
                cnt += abs(sum) + 1;
                sum = -1;
            }
        }
    }
    chmin(ans, cnt);

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<string>
typedef long long ll;
#define  fi0(i,n)  for(int i=0;i<n;i++)
#define   pb()    push_back()
#define   mk()    make_pair()
#define   fst      first
#define   scnd    second
#define   fast    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define   endl     '\n';
using namespace std;
ll d(ll i)
{
}
void solve()
{
   int t;cin>>t;int k=1;while(t--){
   double t_r,r,b;
   cin>>t_r>>r>>b;
    double c_r,r_r;
   if(t_r<=r){
      r_r=0;
   }
   else{
      double d=t_r-r+1;
      r_r=d/(b/6);
   }
    b=300-b;
    if(b<=0){
      c_r=0;
    }
    else{
      c_r=(r)/(b/6);
    }
    cout<<setprecision(2)<<fixed<<c_r<<' '<<r_r<<endl;
}
}
void f()
{
    vector<string>xxx;
    cin.ignore();
    string s,test;
    getline(cin,s);
    reverse(s.begin(),s.end());
    for(int i=0; i<s.size(); i++)
    {
        if(i==s.size()-1)
        {
            test+=s[i];
            xxx.push_back(test);
            break;
        }
        if(s[i]!=' ')
        {
            test+=s[i];
        }
        else if(s[i]==' ')
        {
            xxx.push_back(test);
            test="";
        }
    }
    for(int i=0; i<xxx.size(); i++)
    {
        reverse(xxx[i].begin(),xxx[i].end());
        cout<<xxx[i]<<' ';
    }
}
void ff()
{
    int terget,run,ball;
    cin>>terget>>run>>ball;
    int r_run=terget-run+1;
    double over=50-(double)(ball)/6;
    double c_r_r=(double) run/over;
    double r_r_r=r_run/((double)(ball)/6);

    cout<<setprecision(2)<<fixed<<c_r_r<<' '<<r_r_r<<endl;
}
void mrge(int *arr,int low,int mid,int high){
    int i=low,k=low,j=mid+1,test[high];
    while(i<=mid&&j<=high){
      if(arr[i]<arr[j]){
        test[k++]=arr[i++];
      }
      else{
        test[k++]=arr[j++];
      }
    }
    while(i<=mid){
      test[k++]=arr[i++];
    }
    while(j<=high)test[k++]=arr[j++];
    for(int i=low;i<=high;i++)arr[i]=test[i];
}
void srt(int *arr,int low,int high){
  int mid;
   if(low<high){
  mid=(low+high)/2;
  srt(arr,low,mid);
  srt(arr,mid+1,high);
  mrge(arr,low,mid,high);
   }
   else return;
}
bool isprime(ll n){
  bool x=0;
  if(n==1)return x;
  for(int i=2;i*i<=n;i++){
    if(!(n%i))return x;
  }
  return !x;
}
vector<ll>save(){
      vector<ll>a;
      for(ll i=2;i<=100000;i++){
      if(isprime(i))a.push_back(i);
    }
    return a;
}
ll n=100007;
bool sa[100007];
void saive(){
    sa[2]=1;
    for(ll i=3;i<=n;i+=2){
            bool x=0;
        for(ll j=2;j*j<=i;j++){
            if(i%j==0){x=1;break;}
        }
        if(!x){sa[i]=1;}
    }
}
int main()
{
    fast;
    int n;cin>>n;
   vector<pair<int,int> >a(n);
   for(int i=0;i<n;i++)
   {
       cin>>a[i].first>>a[i].second;
   }
   int cnt=0,mx=0;bool flag=0;
   for(int i=0;i<n;i++)
   {
       if(a[i].first==a[i].second)
       {
           cnt++;
       }
       else {
        mx=max(cnt,mx);
        cnt=0;
       }
   }
   if(mx>=3||cnt>=3)cout<<"Yes\n";
   else cout<<"No\n";
}


Measured memory_bytes: 3644
#include <stdio.h>
int main(void){

int n=0,c=0,b=0,f=0,r=0,v=0,B=0,F=0,R=0;
int x[4][3][10]={0};
scanf("%d",&n);
for(c=1;c<=n;c++){
scanf("%d %d %d %d",&b,&f,&r,&v);
x[b-1][f-1][r-1]=x[b-1][f-1][r-1]+v;
}

for(B=0;B<4;B++){
	for(F=0;F<3;F++){
		for(R=0;R<10;R++){
		printf(" %d",x[B][F][R]);
		}
		printf("\n");
	}
	if(B<3){
	printf("####################\n");
}

}

return 0;
}

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

int main(){
    int x;
    cin>>x;
    while(1){
        int flg=0;
        for(int i=2;i<x;i++){
            if(x%i==0) flg=1;
        }
        if(flg==0) break;
        x+=1;
    }
    cout<<x<<endl;
}

Measured memory_bytes: 256
N = gets.to_i
H = gets.split.map(&:to_i)

dp = Array.new(N, 0)

1.upto(N-1) do |i|
  cost = []
  cost << dp[i - 1] + (H[i] - H[i-1]).abs
  cost << dp[i - 2] + (H[i] - H[i-2]).abs if i >= 2
  dp[i] = cost.min
end

puts dp[N-1]


Measured memory_bytes: 11396
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll k;
    string s;
    cin>>s>>k;
    string ans;
    for(ll i=0;i<k;i++){
        if(s[i]=='1'){
            ans="1";
        }else{
            ans=s[i];
            i=k+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}



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

#define MAX 2000001
#define VMAX 10000

int C[VMAX+1],n;

void countingSort(short *,short *,int);

int main(){
  unsigned short *A, *B;
  int i, j,k=0;
  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
    if(A[i]>k)k=A[i];
  }
  countingSort(A,B,k);

  for(i=1;i<=n;i++)if(i==1)printf("%d",B[i]); else printf(" %d",B[i]);
  printf("\n");
  return 0;
}

void countingSort(short A[],short B[],int k){
  int i,j;
  for(i=0;i<=k;i++)C[i]=0;
  for(j=1;j<=n;j++)C[A[j]]++;
  for(i=1;i<=k;i++)C[i]+=C[i-1];
  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
}



Measured memory_bytes: 9620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<list>
#include<sstream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	cout<<(a-1)*(b-1);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a == b) {
			System.out.println(a + b);
		}else {
			int res = Math.max(a, b) * 2 -1;
			System.out.println(res);
		}

	}

}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	int N, K;
	cin >> N >> K;
	
	ll m = 0; // 整数倍の数
	while ((m + 1)*K <= N) m++;

	if (K % 2 == 1) {
		cout << m * m * m << endl;
	}
	else {
		ll s = 0; //半整数の数
		while (K / 2 + K * s <= N)s++;
		cout << m * m * m + s * s * s << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        Map<Integer, List<Integer>> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            List<Integer> list = new ArrayList<>();
            if (map.containsKey(b[i])) {
                list = map.get(b[i]);
            }
            list.add(a[i]);
            map.put(b[i], list);
        }

        long sum = 0;
        for (Map.Entry<Integer, List<Integer>> e : map.entrySet()) {
            List<Integer> list = e.getValue();
            for (int i = 0; i < list.size(); i++) {
                sum += list.get(i);
            }
            if (sum > e.getKey()) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }

}


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

int main() {
	
	int h,a,n;
	
	cin>>h>>a;
	
	if(h%a==0)
	    n=h/a;
	else
	    n=(h/a) + 1;
	    
	cout<<n;
	
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

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

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

type restaurant struct {
	name  string
	point int
	id    int
}

type rs []restaurant

func (r rs) Len() int {
	return len(r)
}

func (r rs) Less(i, j int) bool {
	if r[i].name == r[j].name {
		return r[i].point > r[j].point
	}
	return r[i].name < r[j].name
}

func (r rs) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	a := make(rs, n)
	for i := range a {
		a[i].id = i + 1
		fmt.Fscan(read, &a[i].name, &a[i].point)
	}

	sort.Sort(a)
	for _, r := range a {
		fmt.Fprintln(write, r.id)
	}
}


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

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());

    ll ans = n;
    map<ll,bool> div;
    for(ll i=0;i<n;i++){
        if(div[a[i]]) ans--;
        else if(i != n-1){
            if(a[i] == a[i+1]) ans--;
        }
        for(ll j = 1;a[i] * j <= a[n-1];j++){
            if(a[i] * j > 1000000) continue;
            div[ a[i] * j ] = true;
        }
        // if(i == n-1) continue;
        // if(a[i] == a[i+1]) ans--;
    }

    if(ans < 0) cout<<0<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 66928
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    s_list = []
    for i in range(N):
        s = SI()
        s = sorted(s)
        s_list.append(''.join(s))

    s_list = sorted(s_list)
    dprint(s_list)

    cnt_list = []
    cnt = 0
    current = ''
    for s in s_list:
        if current != s:
            cnt_list.append(cnt+1)
            current = s
            cnt = 0
        else:
            cnt += 1
    cnt_list.append(cnt+1)
    dprint(cnt_list)


    ans = 0
    for cnt in cnt_list:
        ans += cnt*(cnt-1)//2

    print(ans)

solve()

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

int main(){
  int n,m;
  int p[100000];
  long long int train[100000][3],cnt[100000] = {};
  cin >> n >> m;
  for(int i = 0;i < m;i++){
    cin >> p[i];
    p[i]--;
  }
  for(int i = 0;i < n - 1;i++){
    cin >> train[i][0] >> train[i][1] >> train[i][2];
  }
  int city = p[0];
  for(int i = 1;i < m;i++){
    for(int j = min(city,p[i]);j < max(city,p[i]);j++){
      cnt[j]++;
    }
    city = p[i];
  }
  long long int res = 0;
  for(int i = 0;i < n - 1;i++){
    if(train[i][0] * cnt[i] <= train[i][1] * cnt[i] + train[i][2]){
      res += train[i][0] * cnt[i];
    }
    else {
      res += train[i][1] * cnt[i] + train[i][2];
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 6620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int N, M; cin >> N >> M;
  vi arr(M);
  rep(i,M) cin >> arr[i];

  if (M == 1) {
    cout << arr[0] << endl;
    if (arr[0] == 1) {
      cout << 1 << endl;
      cout << arr[0] << endl;
    } else {
      cout << 2 << endl;
      cout << 1 << ' ' << arr[0]-1 << endl;
    }
    return 0;
  }

  vi odd;
  rep(i,M) if (arr[i]%2) odd.push_back(i);

  if (odd.size() > 2) {
    cout << "Impossible" << endl;
    return 0;
  }

  if (odd.size() != 0) swap(arr[0], arr[odd[0]]);
  if (odd.size() == 2) swap(arr[M-1], arr[odd[1]]);

  rep(i,M-1) cout << arr[i] << ' ';
  cout << arr[M-1] << endl;

  ++arr[0]; --arr[M-1];
  if (arr[M-1] == 0) {
    arr.pop_back();
    --M;
  }

  cout << M << endl;

  rep(i,M-1) cout << arr[i] << ' ';
  cout << arr[M-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;

typedef long long ll;
typedef pair<ll, ll> Pa;

/*2種類の連続した文字列を圧縮する*/
vector<int> strcompress(string S, int N){
    int count = 1;
    char c = S[0];
    vector<int> vec; 
	rep(i, N-1){
		if(c == S[i+1]){
			count++;
		}else{
			vec.push_back(count);
			count = 1;
			c = S[i+1];
		}
	}
	vec.push_back(count);
    return vec;
}

int main() {
    string s;
    cin >> s;
    vector<int> str = strcompress(s, s.size());
    int idx = 0;
    if(s[0] == '>') idx = 1;
    ll ans = 0;
    rep(i, str.size()-1){
        if(i%2 != idx) continue;
        if(str[i] < str[i+1]) str[i]--;
        else str[i+1]--;
    }
    rep(i, str.size()){
        ans += (ll)str[i]*((ll)str[i]+1)/2;
    }
    cout << ans;
}


Measured memory_bytes: 2560
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;

int main()
{
    fastio;
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
         string s;
         cin>>s;
         ll x=s.size()-1;
         if(s[x]=='s')
         {
             s+="es";
         }
         else
         {
             s+="s";
         }

         cout<<s<<endl;
    }

}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a>b){
        a+=b;
        b=a-b;
        a-=b;
    }
    for(int i=0;i<b;i++){
        cout<<a;
    }
}


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

#define ll long long

int main()
{
    int n,m,d,re=0;

    cin>>n>>m;

    vector<int>v[100005];

    priority_queue<int>pq;



    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;

        v[a].push_back(b);
    }

    for(int i=1;i<=m;i++)
    {
        for(auto it : v[i])pq.push(it);

        if(!pq.empty())
        {
            re+=pq.top();
            pq.pop();
        }
    }

    cout<<re<<endl;


    return 0;
}


Measured memory_bytes: 5632
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

ll d,s,t;

void solve(){
    cin >> d >> t >> s;
    if(d<=s*t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
typedef pair<ll,ll> P;

#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 REP(i,n) rep(i,0,n)
#define RREP(i,n) rrep(i,n,0)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

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

  ll x;
  cin >> x;
  ll i = 0;
  while (1) {
    ll sum = i * (i + 1) / 2;
    if (sum >= x) {
      cout << i << endl;
      return 0;
    }
    i++;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,y,a,b,c,i=-1;
	cin>>n>>y;
	y=y/1000;
	FOR(i,0,n+1){
		FOR(j,0,n+1){
			b=y-10*j-i;
			if(b%5==0 && b>=0){
				b=b/5;
				a=j;
				c=i;
				if(a+b+c==n){
					printf("%d %d %d\n",a,b,c);
					return 0;
				}
			}
		}
	}
	printf("-1 -1 -1\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long sum = a + b;
        long mod = n % sum;
        long div = n / sum;
        System.out.println(div * a + Math.min(mod, a));
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
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 loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#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 prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;



int main() {
    int nums[100009];
    string s;
    
    cin >> s;
    
    mem(nums,0);
    rep(i,s.size()) {
        if ( s[i]=='1') nums[i] = 1;
    }
    
    int now = nums[0], lsize = 1, rsize = s.size()-1, maxk=s.size();
    rep(i,s.size()-1) {
        if ( now != nums[i+1]) {
            maxk = min( maxk, max(lsize,rsize));
        }
        now = nums[i+1];
        lsize++; rsize--;
    }
    cout << maxk << endl;
    
}


Measured memory_bytes: 832
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = 100005;
double T;
inline double f(double x) {
	return T - 0.006 * x;
}
inline double ab(double x) {
	return x > 0 ? x : -x;
}
int main()
{
	double n, a, ans, val;
	int id = 1;
	cin >> n >> T >> a;
	cin >> val;
	ans = f(val);
	n--;
	for (int i = 2; i <= n + 1; i++) {
		cin >> val;
		if (ab(f(val) - a) < ab(ans - a)) {
			ans = f(val);
			id = i;
		}
	}
	cout << id;
	return 0;
}

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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int ll
//#define endl '\n'

int32_t main()
{
    IOS
    int n;
    cin>>n;
    cout<<3*n*n<<endl;
}



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

int main(void){
  string s,t;
  cin>>s>>t;
  int A,B;
  cin>>A>>B;
  string u;
  cin>>u;
  if(s==u) A--;
  else if(t==u) B--;
  cout<<A<<" "<<B<<endl;
  return 0;
}


Measured memory_bytes: 256
n,*l=map(int,open(0).read().split())
a=b=c=0;l+=[0,1]
while a<n:
	while l[a]<=l[a+1]:a+=1
	while l[b]>=l[b+1]:b+=1
	a=b=max(a,b)+1
	c+=1
print(c)

Measured memory_bytes: 14052
YEN = 0
NUM = 1

N, M = list(map(int, input().split()))
shop = list([])
for i in range(N):
    a, b = list(map(int, input().split()))
    shop.append([a, b])
shop.sort()

require = M
price = 0
minidx = 0
while(require > 0):
#    print("require = {}, price = {}".format(require, price))
#    print("idx = {}, num = {}, price = {}".format(minidx, shop[minidx][NUM], shop[minidx][YEN]))
    if(require >= shop[minidx][NUM]):
        price = price + shop[minidx][YEN] * shop[minidx][NUM]
        require = require - shop[minidx][NUM]
        minidx = minidx + 1
    else:
#        print("buy = {}, price = {}".format(require, A[minidx]))
        price = price + shop[minidx][YEN] * require
        require = 0

print(price)


Measured memory_bytes: 20456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*Problem A: Greatest Common Divisor
Please find the greatest common divisor of two natural numbers. 
A clue is: The Euclid's algorithm is a way to resolve this task.

Input
The input file consists of several lines with pairs of two natural numbers in each line. 
The numbers do not exceed 100000.
The number of pairs (datasets) is less than 50.

Output
Your program has to print the greatest common divisor for each pair of input numbers. 
Print each result on a new line.*/
public class Main{
	
	public static void main(String[] args){
		InputStreamReader inputStreamReader = new InputStreamReader(System.in);
		BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
		StringBuilder stringBuilder = new StringBuilder();

		try{
			String dataSet;
			while((dataSet = bufferedReader.readLine()) != null){
				if(dataSet.length()==0) break;
				String[] dataList = dataSet.split(" ");
				int x = Integer.parseInt(dataList[0]);
				int y = Integer.parseInt(dataList[1]);
				if(x>y){
					stringBuilder.append(gcd(x, y) + "\n");	
				}else
				stringBuilder.append(gcd(y, x) + "\n");
			}
			System.out.print(stringBuilder);
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	static int gcd(int x, int y){
		if(y==0){
			return x;
		}else{
			return gcd(y, x%y);
		}
	}
}

Measured memory_bytes: 24160
def kanashisa(a, n, b)
  s = 0
  a.zip((1..n)){|a, n|
    s += (a - n - b).abs
  }
  s
end

def stepsize(s)
  s /= 4
  s = 1 if s == 0
  s
end

n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i);

a0 = kanashisa(a, n, a[0])
a1 = kanashisa(a, n, a[0] + 1)
s, pos, bef, now = a1 < a0 ? [stepsize(a0 / n), a[0] + 1, a0, a1] : [-stepsize(a0 / n), a[0], a1, a0]

begin
  begin
    pos += s
    bef, now = [now, kanashisa(a, n, pos)]
  end while(bef > now)
  break if s == 1 || s == -1
  s = s > 0 ? -stepsize(s) : stepsize(-s)
end while(true)

puts bef


Measured memory_bytes: 55004
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n;
  set<string> se;
  for(int i=0; i<n; i++) {
    cin >> s;
    se.insert(s);
  }
  cout << se.size() << endl;
}

Measured memory_bytes: 19248
import Control.Monad
import Data.List
import qualified Data.ByteString.Lazy.Char8 as B

main = do
  input <- B.getContents
  let [a,b] = map readInt . B.words $ input
  print (solve a b)

readInt :: B.ByteString -> Int
readInt s = case B.readInt s of Just (n,_) -> n

solve :: Int -> Int -> Int
solve a b =
  length [(i,i) |i<-[1..12], (i,i)<=(a,b)]

Measured memory_bytes: 380
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(((a * b) % 2) == 1 ) {
			System.out.println("Odd");
		}else {
			System.out.println("Even");
		}

	}
}


Measured memory_bytes: 20688
N, K = map(int, input().split(" "))
if K % 2 == 1:
    print ((int(N/K))**3)

else:
    tmp = (int(N/K))**3
    e=0
    t = K
    while t % 2 == 0:
        t /= 2
        e += 1
    
    m = K / 2
    cnt = 0
    for i in range(2 ** (e-1), N+1, 2 ** e):
        if i % m == 0:
            cnt += 1
    n = int((N+1) / 2)

    print ((int(N/K))**3 + (int(cnt))**3)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,A;
cin>>N>>A;
int a1=1;
int a2=0;
int a=N-A;
if(a%(A-1)==0){
cout<<a1+a/(A-1)<<endl;}
else
cout<<a1+a/(A-1)+1<<endl;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define forf(i,a,b) for(i=a;i<b;i++)
#define forr(i,a,b) for(i=a;i>b;i--)
#define mp make_pair
#define f first
#define s second
#define pb(x) push_back(x)
typedef  long long  int ll;
typedef std::vector<ll> vi;

#define input(vec,a,b) for(ll i =a;i<b;i++) cin>>vec[i]
#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" " ;cout<<endl;
#define all(a) a.begin(),a.end()
using namespace std;


void solve(){
        ll i,j,n,k;
        cin>>n>>k;
        ll h[n],c[n];
        for(i=0;i<n;i++)
        cin>>h[i];
        c[0]=0;
        c[1]=abs(h[0]-h[1]);
        for(i=2;i<n;i++)
        {
                 ll mi=c[i-1]+abs(h[i]-h[i-1]);
                 for(j=2;j<=k&&j<=i;j++)
                 mi=min(mi,c[i-j]+abs(h[i]-h[i-j]));
                 c[i]=mi;
        }
        cout<<c[n-1];
}

int main()
{
      IO;
      ll t=1;
      //cin>>t;


      while(t--)
      {

          solve();
      }
    return 0;
}

Measured memory_bytes: 5060
#include<cstdio>
#include<cstring>

const int N=100005;

int n,m,te,h[N],nxt[N<<1],to[N<<1],w[N<<1],f[N],cnt[3],e,ok;
long long ans;

void link(int a,int b,int c)
{
	nxt[++te]=h[a];
	h[a]=te;
	to[te]=b;
	w[te]=c;
}

void dfs(int u)
{
	cnt[f[u]]++;
	for(int i=h[u],v;i;i=nxt[i])
	{
		++e;
		v=to[i];
		if(-1==f[v])
		{
			f[v]=(f[u]+w[i])%3;
			dfs(v);
		}
		else if((f[u]+w[i])%3!=f[v])
			ok=0;
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		link(a,b,1),link(b,a,2);
	}
	memset(f,-1,sizeof(f));
	for(int i=1; i<=n; i++)
		if(-1==f[i])
		{
			ok=1;
			cnt[0]=cnt[1]=cnt[2]=0;
			e=0;
			f[i]=0;
			dfs(i);
			e/=2;
			if(!ok)
				ans+=1ll*(cnt[0]+cnt[1]+cnt[2])*(cnt[0]+cnt[1]+cnt[2]);
			else if(cnt[0]&&cnt[1]&&cnt[2])
				ans+=1ll*cnt[0]*cnt[1]+1ll*cnt[1]*cnt[2]+1ll*cnt[2]*cnt[0];
			else
				ans+=e;
		}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 6528
n = int(input())
d = {}
for _ in range(n):
  s = input()
  if s in d: d[s] += 1
  else: d[s] = 1
m = int(input())
for _ in range(m):
  t = input()
  if t in d: d[t] -= 1
  else: d[t] = -1
    
print(max(0, max(d.values())))

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    ll D, G;
    cin >> D >> G;
    ll p[11], c[11];
    rep(i, D) cin >> p[i] >> c[i];
    ll ans = 1e8;
    rep(b, 1<<D) {
        bitset<10> bit(b);
        ll score = 0, use = 0;
        rep(i, D) {
            if (bit[i] == 1) {
                score += p[i] * 100 * (i+1) + c[i];
                use += p[i];
            }
        }
        if (score < G) {
            for (int i=D-1; i>=0; --i) {
                if (bit[i] == 1) continue;
                ll less = G - score;
                if (less <= 100*(i+1)*p[i]) {
                    use += less / (100*(i+1)) + bool(less%(100*(i+1)));
                    score = G;
                    break;
                }
            }
        }
        if (score >= G) ans = min(ans, use);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

H,W,K=map(int,input().split())
c=[list(map(int,list(input().replace('.','0').replace('#','1')))) for _ in range(H)]
ans=0
for i in range(2**H):
    for k in range(2**W):
        d=[c[i][:] for i in range(H)]
        for j in range(H):
            if (i>>j)&1:
                d[j]=[0]*W
        for l in range(W):
            if (k>>l)&1:
                for m in range(H):
                    d[m][l]=0
        cnt=0
        for j in range(H):
            cnt+=sum(d[j])
        ans+=cnt==K
print(ans)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == s[i + 1])
        {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
long long int seg1[800005], seg2[800005], ss;
long long int min(long long int a, long long int b)
{
	if (a < b)
		return a;
	else
		return b;
}
long long int get1(long long int x, long long int k, long long int left, long long int right)
{
	if (2 * k + 2 < 2 * ss - 1)
	{
		seg1[2 * k + 1] = min(seg1[2 * k + 1], seg1[k]);
		seg1[2 * k + 2] = min(seg1[2 * k + 2], seg1[k]);
	}
	if (x < left || right <= x)
		return ss;
	if (left == x && x + 1 == right)
		return seg1[k];
	return min(get1(x, 2 * k + 1, left, (left + right) / 2), get1(x, 2 * k + 2, (left + right) / 2, right));
}
void set1(long long int l, long long int r, long long int v, long long int k, long long int left, long long int right)
{
	if (r < left || right <= l)
		return;
	if (l <= left && right <= r + 1)
	{
		seg1[k] = min(seg1[k], v);
		return;
	}
	set1(l, r, v, 2 * k + 1, left, (left + right) / 2);
	set1(l, r, v, 2 * k + 2, (left + right) / 2, right);
	return;
}
long long int get2(long long int x, long long int k, long long int left, long long int right)
{
	if (2 * k + 2 < 2 * ss - 1)
	{
		seg2[2 * k + 1] = min(seg2[2 * k + 1], seg2[k]);
		seg2[2 * k + 2] = min(seg2[2 * k + 2], seg2[k]);
	}
	if (x < left || right <= x)
		return ss;
	if (left == x && x + 1 == right)
		return seg2[k];
	return min(get2(x, 2 * k + 1, left, (left + right) / 2), get2(x, 2 * k + 2, (left + right) / 2, right));
}
void set2(long long int l, long long int r, long long int v, long long int k, long long int left, long long int right)
{
	if (r < left || right <= l)
		return;
	if (l <= left && right <= r + 1)
	{
		seg2[k] = min(seg2[k], v);
		return;
	}
	set2(l, r, v, 2 * k + 1, left, (left + right) / 2);
	set2(l, r, v, 2 * k + 2, (left + right) / 2, right);
	return;
}
int main()
{
	long long int n, q;
	scanf("%lld %lld", &n, &q);
	ss = 1;
	while (ss < n)
		ss *= 2;
	long long int i, j;
	long long int ans = (n - 2) * (n - 2);
	for (i = 0; i < 2 * ss - 1; i++)
		seg1[i] = seg2[i] = n - 1;
	long long int a, x;
	for (i = 0; i < q; i++)
	{
		scanf("%lld %lld", &a, &x);
		if (a == 1)
		{
			j = get1(x - 1, 0, 0, ss);
			ans -= j - 1;
			set2(0, j, x - 1, 0, 0, ss);
		}
		else
		{
			j = get2(x - 1, 0, 0, ss);
			ans -= j - 1;
			set1(0, j, x - 1, 0, 0, ss);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9900
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  cin >> N;
  int A,B;
  cin >> A >> B;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin >> P.at(i);
  }
  int ans=0;
  int first=0,second=0,third=0;
  for(int i=0;i<N;i++){
    if (P.at(i)<=A) {first++;}
    if(P.at(i)>=A+1 && P.at(i) <= B){second++;}
    if(P.at(i)>=B+1){third++;}
  }
  ans=min(first,min(second,third));
  cout << ans << endl;
  return 0;
}

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

int main () {
    int n, q;
    std::cin >> n >> q;
    std::string s;
    std::cin >> s;
    std::vector<int> l(q);
    std::vector<int> r(q);

    for (int i = 0; i < q;i++) {
        std::cin >> l[i];
        std::cin >> r[i];
    }
    std::vector<std::pair<int, int> > p;

    std::vector<int> inc(n);
    int cns = 0;
    for (int i = 1; i < n; i++)
    {
        if(s[i - 1] == 'A' && s[i] == 'C') {
            cns++;
        }
        inc[i] = cns;
    }

        for (int i = 0; i < q; i++)
        {
            int ans = inc[r[i] - 1] - inc[l[i] - 1];
            std::cout << ans << "\n";
        }


}

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

int main () {
	long N;
	long temp, first=0, second=0;
	vector<long> fidxs;
	cin >> N;
	for (int i=0; i<N; ++i) {
		cin >> temp;
		if (temp > first) {
			second = first;
			first = temp;
			fidxs.clear();
			fidxs.push_back(i);
		} else if (temp == first) {
			second = temp;
			fidxs.push_back(i);
		} else if (temp > second) {
			second = temp;
		}
	}

	long idx = 0;
	for (int i=0; i<N; ++i) {
		if (i == fidxs[idx]) {
			cout << second << endl;
			++idx;
		} else {
			cout << first << endl;
		}
	}
}


Measured memory_bytes: 3312