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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll n,m;cin>>n>>m;
    ll res = min(n,m/2);
    n -= res;
    m -= res*2;
    if(n == 0){
        res += m/4;
    }
    out(res);
}

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

int N,M;
void solve()
{
	int res=0;
	vector<int>first,second;
	int temp;
	first.push_back(0);
	for(int i=0;i<N;i++)
	{
		scanf("%d",&temp);
		first.push_back(temp);
	}
	sort(first.begin(),first.end());
	for(int i=0;i<first.size();i++)
	{
		for(int j=i;j<first.size();j++)
		{
			if(first[i]+first[j]<=M)
			{
				second.push_back(first[i]+first[j]);
			}else{
				break;
			}
		}
	}
	sort(second.begin(),second.end());
	for(int i=0;i<second.size();i++)
	{
		int findV=M-second[i];
		int left=0,right=second.size()-1;
		int mid;
		int max_min=0;
		while(left<=right)
		{
			mid=(left+right)/2;
			if(findV<second[mid]){
				right=mid-1;
			}else{
				max_min=max(max_min,second[mid]);
				left=mid+1;
			}
		}
		res=max(res,max_min+second[i]);
	}
	printf("%d\n",res);
}

int main()
{
	while(true)
	{
		scanf("%d%d",&N,&M);
		if(N==0&&M==0)break;
		solve();
	}
	return 0;
}


Measured memory_bytes: 6744
import sys
x,n = map(int,input().split())

if n==0 :
    print(x)
    sys.exit()

p = list(map(int, input().split()))


for i in range(100) :
    i1=x-i
    i2=x+i
    
    if i1 not in p and i2 not in p :
        print(i1)
        sys.exit()
        
    
    if i1 not in p and i2 in p :
        print(i1)
        sys.exit()
    
    if i2 not in p and i1 in p :
        print(i2)
        sys.exit()
        
        
    

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int H,W;
char board[22][22];
int dist[22][22];
int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};

int ans=0;

int bfs(int sy,int sx,int gy,int gx){
  //bfs用距離情報初期化
  memset(dist,0,sizeof(dist));
  rep(i,H){
    rep(j,W)dist[i+1][j+1]=-1;
  }
  //bfs
  queue<pair<int,int>> que;
  que.push(make_pair(sy,sx));
  dist[sy][sx]=0;
  while(!que.empty()){
    //get remain info
    auto p=que.front();
    //delete from queue
    que.pop();
    rep(i,4){
      int y= p.first+dy[i],x=p.second+dx[i];
      if(dist[y][x]==-1 && board[y][x]=='.') {
      que.push(make_pair(y,x));
      dist[y][x]=dist[p.first][p.second]+1;
      }
    }
  }
  return dist[gy][gx];
}

int main(){
  cin >> H >> W;

  //盤面初期化と白カウント
  memset(board,'#',sizeof(board));
  rep(i,H){
    rep(j,W) {
      cin >> board[i+1][j+1];
    }
  }

reps(i,H){
  reps(j,W){
    if(board[i][j]=='.'){
      for(int k=i;k<=H;k++){
        reps(l,W){
          if(board[k][l]=='.'){
            int cur=bfs(i,j,k,l);
            ans= max(ans,cur);
            //cout << cur << ' ';
          }
        }
      }
    }
  }
}

cout << ans << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;


int main(){
    int N;
    cin >> N;
    ll A[100001]={};
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    ll ans=0;
    for(int i=0; i<N; i++){
        ans += A[i]/2;
        A[i]%=2;
        
        if(A[i]==1 && i<N-1 && A[i+1]>0){
            ans++;
            A[i+1]--;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <map>
#include <cmath>
#include <bitset>
#include <string>
#include <queue>

using namespace std;

#define int long long

bool func(int i, int j, int k, string s) {
    return (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]);
}

signed main() {
    int n; cin >> n;
    string s; cin >> s;
    map <char, int> mp;
    for(int i = 0; i < n; i++) mp[s[i]]++;

    int sum = mp['R'] * mp['G'] * mp['B'];

    int cnt = 0;
    for(int i = 0; i < n - 2; i++) {
        for(int j = i + 1; j < n - 1; j++) {
            int k = j + j - i;
            if(k < n && func(i, j, j + (j - i), s)) cnt++;
        }
    }

    int ans = sum - cnt;

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


Measured memory_bytes: 3624
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,a) for(int i = 0; i < (a); i++)
using namespace std;

int main(){
	int n;
	cin >> n;
	if(n <= 999)cout << "ABC" << endl;
	else cout << "ABD" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int lot[10],save[100][2]={0},tag=0,a,b;
    bool f = true;
    for(int i=0; i<10; i++) cin >>lot[i];
    a = lot[0];
    b = 0;
    for(int i=1; i<10; i++){
      if(a<lot[i] && b>lot[i]) a = lot[i];
      else if(a>lot[i] && b<lot[i]) b = lot[i];
      else if(a<lot[i] && b<lot[i]){
	save[tag][0] = a;
	save[tag][1] = i;
	a = lot[i];
	tag++;
      }
      else if(a>lot[i] && b>lot[i]){
	if(tag == 0){
	  f = false;
	  break;
	}
	else{
	  a = save[tag-1][0];
	  i = save[tag-1][1];
	  b = lot[i];
	  tag--;
	}
      }
    }
    if(f) cout <<"YES"<<endl;
    else cout <<"NO"<<endl;
  }
  return 0;
}

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

int main(){
    string S;
    cin >> S;
    int ans=0;
    
    for(int i=0; i<6; i++) if(S.at(i)=='1') ans++;
    
    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

ll dp[int(1e5) + 10][3];

int main() {
	faster;

	ll n;
	cin >> n;

	vector<ll> a(n), b(n), c(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	for (int i = 1; i <= n; i++) {
		dp[i][0] = a[i - 1] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b[i - 1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c[i - 1] + max(dp[i - 1][0], dp[i - 1][1]);
	}

	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;

	return 0;
}

Measured memory_bytes: 7920
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  string s;
  cin>>s;
  rep(i,3)
    cout<<s.at(i);
  cout<<endl;
}

Measured memory_bytes: 3628
n = int(input())

A = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

L = []

total = 0
keta = 1

while True:
    total += 26**keta
    if n <= total:
        break
    keta += 1

n -= (total-26**keta)
n -= 1

while n > 0:
    L.append(n%26)
    n //= 26

M = [0]*keta

for i in range(min(keta, len(L))):
    M[-(i+1)] = L[i]



ans = ""
for m in M:
    ans += A[m]

print(ans)


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

#define ll long long
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define see(x) cout<<(#x)<<" -> "<<(x)<<"\n"
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define fr(i,a,b) for(int i=a;i<b;i++)
#define fr1(i,b,a) for(int i=b;i>=a;i--)

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
long double infd=1.0/0.0;
const double pi=2*acos(0.0);
const int MOD=1e9+7;

int main(){
    nimble;
    int tt=1;//cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        string s,t;
        cin>>s>>t;
        string x="";
        for(int i=0;i<n;i++){
            cout<<s[i]<<t[i];
        }
    }
    return 0;
}



Measured memory_bytes: 256
ans = []
loop do
    n = gets.to_i
    break if n == 0
    a = (1..n).map do |i|
        name, w, l, d = gets.chomp.split
        [name, [w.to_i*3 + d.to_i, -i]]
    end
    a.sort_by!(&:last).reverse!
    ans << a.map{|name, (point, _)| "#{name},#{point}"}.join("\n")
end
puts ans.join("\n\n")

Measured memory_bytes: 8788
c, s, f = [0] * 505, [0] * 505, [0] * 505
n = input()
for _ in xrange(1, n):
    tc, ts, tf = map(int, raw_input().split())
    c[_], s[_], f[_] = tc, ts, tf
for i in xrange(1, n):
    t = s[i]
    t += c[i]
    for j in xrange(i + 1, n):
        if t >= s[j]:
            t += (f[j] - (t % f[j])) % f[j]
        else:
            t = s[j]
        t += c[j]
    print t
print 0


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000007LL
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(i=a;i<=b;i++)

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

ll mypow(ll a, ll b) { if(b == 0) return 1; ll temp=mypow(a,b/2); temp=(temp*temp)%INF; if(b%2 == 1) temp=(a*temp)%INF; return temp; }
int mygcd(int a, int b) { if(b==0) return a; return mygcd(b,a%b); }
int cntBits(ll a) { int ret=0; while(a>0) { ret++; a/=2; } return ret; }
int arr[100010][3];
int main()
{
	ios::sync_with_stdio(0);
	int tt=1,tcase; 
	//cin >> tt;
	rep(tcase,1,tt)
	{
		int n; cin >> n;
		int i,j,k;
		rep(i,0,n-1) rep(j,0,2) cin >> arr[i][j];
		rep(i,1,n-1)
		{
			rep(j,0,2)
			{
				int val=0;
				rep(k,0,2)
				{
					if(j!=k) val=max(val,arr[i-1][k]);
				}
				arr[i][j]+=val;
			}
		}
		cout << max(arr[n-1][0],max(arr[n-1][1],arr[n-1][2])) << "\n";
	}
	return 0;
}


Measured memory_bytes: 1408
//
// Created by Knight_F on 2019-08-18.
//

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct Edge{
    int to,nxt;
}edg[(int)4e5+10];
int head[(int)2e5+10],num;
int sum[(int)2e5+10];
void add(int a,int b){
    edg[++num].to=b;
    edg[num].nxt=head[a];
    head[a]=num;
}
void dfs(int root,int up){
    int t=head[root];
    while(t!=0){
        if(edg[t].to!=up){
           sum[edg[t].to]+=sum[root];
           dfs(edg[t].to,root);
        }
        t=edg[t].nxt;
    }
}
int main(){
    ios::sync_with_stdio(false);
    int n,q; cin>>n>>q;
    for(int i=1;i<n;i++){
        int ai,bi; cin>>ai>>bi;
        add(ai,bi); add(bi,ai);
    }
    for(int i=1;i<=q;i++){
        int pi,xi; cin>>pi>>xi;
        sum[pi]+=xi;
    }
    dfs(1,0);
    for(int i=1;i<=n;i++) cout<<sum[i]<<' ';
    return 0;
}

Measured memory_bytes: 16512
#include<stdio.h>

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

	int temp;
	if(a > b){
		temp = a;
		a = b;
		b = temp;
	}
	if(a > c){
		temp = a;
		a = c;
		c = temp;
	}
	if(b > c){
		temp = b;
		b = c;
		c = temp;
	}
		printf("%d %d %d\n", a, b, c);

	return 0;
}



Measured memory_bytes: 2056
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
int n,k,cnt0,cnt2;
ll ans=0;
int main() {
	read(n),read(k);
	cnt0=n/k,cnt2=cnt0+(n%k>=k/2);
	if(k&1)
		cnt2=0;
	ans=1ll*cnt0*cnt0*cnt0+1ll*cnt2*cnt2*cnt2;
//	cout<<cnt0<<" "<<cnt2<<endl;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int s; cin>>s;
    //集合を作る
    set<int> st;
    int x=s; //初期値
    //countで重複を調べる
    while(st.count(x)==0){
        st.insert(x);
        if(x%2==0) x/=2;
        else x=x*3+1;
    }
    //集合のサイズに1足したものを出力する
    cout<<(st.size()+1)<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
int main()
{
	int n;
	cin >> n;
	vector <int> A(n + 1);
	vector <int> B(n);
	for (int i = 0; i < n + 1; i++)  cin >> A[i];
	for (int i = 0; i < n; i++)  cin >> B[i];

	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (A[i] < B[i]) {
			sum += A[i];
			B[i] -= A[i];
			
			if (A[i + 1] >= B[i]) {
				sum += B[i];
				A[i + 1] -= B[i];
			}
			else {
				sum += A[i + 1];
				A[i + 1] = 0;
			}
		}
		else {
			sum += B[i];
		}
	}
	cout << sum << endl;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,m;
	cin >> n >> m;
	vector<vector<int>> ta(n,vector<int>(m));
	for(int i=0;i<n;i++){
		string str;
		cin >> str;
		for(int j=0;j<m;j++){
			if(str[j]=='#') ta[i][j]=1;
		}
	}
	
	vector<vector<int>> dp(n+1,vector<int>(m+1,1<<29));
	for(int i=0;i<=n;i++) dp[i][0]=1<<29;
	for(int i=0;i<=m;i++) dp[0][i]=1<<29;
	
	if(ta[0][0]) dp[1][1]=1;
	else dp[1][1]=0;
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(i==1 && j==1) continue;
			if(ta[i-1][j-1]==0){
				dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
			}else{
				dp[i][j]=1+min(dp[i-1][j],dp[i][j-1]);
				if(i>1 && ta[i-2][j-1]==1) dp[i][j]=min(dp[i][j],dp[i-1][j]);
				if(j>1 && ta[i-1][j-2]==1) dp[i][j]=min(dp[i][j],dp[i][j-1]);
			}
		}
	}
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			//cout << dp[i][j] << " ";
		}
		//cout << "\n";
	}
	cout << dp[n][m] << "\n";
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

intmax_t min(intmax_t a, intmax_t b)
{
    if (a > b) 
        return b;
    else
        return a;
}

int main(void)
{
    intmax_t N, B[100];
    intmax_t A[100], ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < (N - 1); i++) {
        scanf("%jd", &B[i]);
    }

    A[0] = B[0];
    for (size_t i = 1; i < (N - 1); i++) {
        A[i] = min(B[i - 1], B[i]);
    }
    A[N - 1] = B[N - 2];

    for (size_t i = 0; i < N; i++) {
        ans += A[i];
    }

    printf("%jd\n", ans);

    return 0;
}


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

int main(){
    int a,b;
    string s;
    cin >> a >> b >> s;
    bool flag = true;
    for (int i = 0; i < a+b+1; i++){
        if (i == a){
            flag = (s[i] == '-');
        }else{
            flag = (s[i] != '-');
        }

        if (!flag){
            break;
        }
    }
    cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	int h, a;
	cin >> h >> a;
	int ans = (h + a - 1) / a;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<map>
using namespace std;
int main(){
    int i,j,C[3][3];
    for(i=0;i<3;i++){
        for(j=0;j<3;j++)
            cin>>C[i][j];
    }
    if(C[1][0]-C[0][0]!=C[1][1]-C[0][1] || C[1][1]-C[0][1]!=C[1][2]-C[0][2]){
        cout<<"No"<<endl;
        return 0;
    }else if(C[2][0]-C[1][0]!=C[2][1]-C[1][1] || C[2][1]-C[1][1]!=C[2][2]-C[1][2]){
        cout<<"No"<<endl;
        return 0;
    }else if(C[0][1]-C[0][0]!=C[1][1]-C[1][0]|| C[1][1]-C[1][0]!=C[2][1]-C[2][0]){
        cout<<"No"<<endl;
        return 0;
    }else if(C[0][2]-C[0][1]!=C[1][2]-C[1][1]|| C[1][2]-C[1][1]!=C[2][2]-C[2][1]){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 500001
#define NIL 2000000001
void maxHeapify(int);
void buildMaxHeap();
int heap[N],n;
main(){
  int i;
  for(i=0;i<N;i++){
    heap[i]=NIL;
  }
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&heap[i]);
  }
  buildMaxHeap();
  for(i=1;i<=n;i++){
    printf(" %d",heap[i]);
  }   
  printf("\n");
  return 0;
}
 
 
void maxHeapify(int i){
  int l,r,largest,a;
    l = 2*i;
  
    r = 2*i+1;
   
  if(l<=n && heap[l] > heap[i]) largest = l;
  else largest = i;
   
  if(r<=n && heap[r] > heap[largest])  largest = r;
   
  if(largest!=i){
    a=heap[largest];
    heap[largest]=heap[i];
    heap[i]=a;
    maxHeapify(largest);
  }
}
void buildMaxHeap(){
  int i;
  for(i=n/2;i>=1;i--){
    maxHeapify(i); 
  }
}

Measured memory_bytes: 2552
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import java.util.Map;
import java.util.Collection;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DCandyDistribution solver = new DCandyDistribution();
        solver.solve(1, in, out);
        out.close();
    }

    static class DCandyDistribution {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            Map<Integer, Integer> values = new HashMap<>();
            values.put(0, 1);
            int sum = 0;
            for (int i = 0; i < n; i++) {
                sum += in.nextInt();
                sum %= m;
                values.merge(sum, 1, (v1, v2) -> v1 + v2);
            }
            out.println(values.values().stream().mapToLong(i -> (i - 1L) * i / 2).sum());
        }

    }
}



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

int X, Y, S;

void solve(){
    vector<int> vec(S+1, -1);
    
    for(int i=0; i<=S; i++){
        int a = i*(100+X)/100;
        if(a > S)
            break;
        vec[a] = i;
    }
    int ans = 0;
    for(int i=1; i<S; i++){
        int a = vec[i]*(100+Y)/100;
        int b = vec[S-i]*(100+Y)/100;
        
        ans = max(ans, a+b);
    }
    cout << ans << endl;
}

int main(){
    while(cin >> X >> Y >> S, X|Y|S){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3104
from collections import Counter
N=int(input());dp=[1]*(10**7);C=Counter(sorted(list(map(int,input().split()))));ans = 0
for a,b in C.items():
    if b != 1:dp[a] = 0
    elif dp[a]:ans += 1
    for j in range(a,10**6+1,a):dp[j] = 0
print(ans)

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

int main(){
  const int MAXI = 10001;
  int N, T, E;
  int x[100];
  cin >> N >> T >> E;
  for(int i=0; i < N; i++){
    cin >> x[i];
  }
  for(int i=0; i < N; i++){
    int time;
    for(time=0; time < MAXI; time+=x[i]){
      if(abs(time-T) <= E){
	cout << i+1 << endl;
	return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 1164
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)

s = readChar()
q = readInt()
qa = []
booh = 0
for i in range(q):
	x = input()
	if x=="1":
		qa.append([1,0,0])
	else:
		x = x.split()
		qa.append([int(x[0]),int(x[1]),x[2]])

def t1(s):
	return s[::-1]

def t2(f,c,s):
	if f==1:
		return c+s
	else:
		return s+c

fi=""
la=""
for a in qa:
	if a[0]==1:
		booh = (booh+1)%2
	else:
		if (a[1]+booh)%2==1:
			fi=a[2]+fi
		else:
			la+=a[2]

s = fi+s+la
if booh==1:
	s = t1(s)

print(s)

Measured memory_bytes: 25924
h, w = gets.chomp.split.map(&:to_i)

c = []
10.times do
  c << gets.chomp.split.map(&:to_i)
end


def min(a,b)
  a < b ? a : b
end


10.times do |k|
  10.times do |i|
    10.times do |j|
      c[i][j] = min(c[i][j], c[i][k] + c[k][j])
    end
  end
end


ans = 0
h.times do
  row = gets.chomp.split.map(&:to_i)

  row.each do |val|
    next if val == -1
    ans += c[val][1]
  end
end

puts ans

Measured memory_bytes: 2428
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort(x.begin(),x.end())
#define mp make_pair
#define pb push_back
using namespace std;

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

while(1){
rep(i,0,n){
if(v[i]%2==0){
v[i]/=2;
}else {
goto AWAY;
}
}
ans++;
}
AWAY:;
cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define int long long 
typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int N;
int len;

int pow26(int x){
	int res=1;
	FOR(i,1,x) res*=26;
	return res;
}
main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	len = 1;
	while (N > pow26(len)){
		N-=pow26(len);
		len++;
	}
	//db(len), db(N);
	FOR(i,1,len){
		char c= 'a';
		int x = (N + pow26(len-i) - 1)/pow26(len-i);
		N-=(x-1)*pow26(len-i);
		//db(x);
		c+=x-1;
		cout<<c;
	}
}


Measured memory_bytes: 3560
#include <stdio.h>
#include <string.h>
int main() {
  char X[15] = "2019/04/30";
  char S[15];
  scanf("%s",S);
  if (strcmp(X,S)>=0) {
    printf("%s\n", "Heisei");
  }else{
    printf("%s\n","TBD");
  }
  return 0;
}


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

int main(){
	int res=1005;
	string s,t;
	cin>>s>>t;
	for(int i=0;i<=s.length()-t.length();i++){
		int index=0,count=0;
		for(int j=i;j<i+t.length();j++){
			if(s[j]!=t[index]){
				count++;
			}
			index++;
		}
		res=min(res,count);
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

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

int main() {
	int n, f;
	cin >> n;
	f = n / 15;
	cout << n * 800 - f * 200 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define __gnu_pbds::gp_hash_table unordered_map;
#define int long long int
#define pb push_back

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

int n;
cin>>n;
vector<int> v(n+1);

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

int j=1,count=0;
for(int i=1;i<=n;i++)
{
     if(v[i]==j)
     {
          j++;
     }
     else
     {
          count++;
     }
}
if(count==n)
{
     cout<<-1;
}
else
{
     cout<<count;
}


}

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50

int main()
{
    int n;
    cin >> n;
    vll data;
    ll sum = 0;
    for(int i = 0; i < n; ++i)
    {
        int l;
        cin >> l;
        sum += l;
        data.pb(sum);
    }
    ll ans = infll;
    for(int i = 0; i < n-1; ++i)
    {
        ans = min(ans, abs((sum-data[i]) - data[i]));
    }

    cout << ans << endl;

}

Measured memory_bytes: 2420
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cstring>
#include<vector>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<functional>
#define io ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
#define ll long long
#define P pair<int,int>
#define lc rt*2
#define rc rt*2+1
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;

using namespace std;

double dp[6][4][3];
int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		cout << 'x';
	return 0;
 }

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

using namespace std;

#define ll long long
#define ld long double
#define ff first
#define ss second
#define rsz resize
#define ins insert 
#define mp make_pair
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define ft front() 
#define bk back()
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define deb(x) cout<<#x<<" "<<x<<'\n';
#define rep(i,a,b) for (int i = (a); i < (b); ++i)

const ll mod = 1e9+7; // 998244353;
const ll inf = 1e18; 
const ld pie = acos((ld)-1);

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};



int main(){
    
	int n;
	scanf("%d",&n);
	vector<int> a(n);
	int sum=0;
	for(int i=0;i<n;++i){
		scanf("%d",&a[i]);
		sum+=a[i]-1;
	}

	printf("%d\n",sum);


	return 0;

	/*STUFF TO LOOK:	
		1. Check the constraints
		2. Corner cases(n==0||n==1)
		3. Variables in loops
		4. Make sure two ints aren’t multiplied to get a long long
		5. Don't use scanf or printf while using ios_base
		6. using the local variable of the same name when global variable was required to be used
	*/
}


Measured memory_bytes: 3748
#include <stdio.h>

int main()
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (a + b < c + d) {
        printf("Right\n");
    } else {
        if (a + b == c + d) {
            printf("Balanced\n");
        } else {
            printf("Left\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
# 幅優先探索, BFS

from collections import deque

n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]

neighbor = [[] for _ in range(n)]
for edge in edges:
    neighbor[edge[0]-1].append(edge[1]-1)  # 1- → 0-index
    neighbor[edge[1]-1].append(edge[0]-1)

queue = deque()
queue.append(0)

back = [-1] * n  # visitしたかどうかを兼ねる
back[0] = 0
while len(queue) > 0:
    vertex = queue.popleft()
    for nei in neighbor[vertex]:
        if back[nei] == -1:
            back[nei] = vertex
            queue.append(nei)
        
print('Yes')
for i in back[1:]:
    print(i+1)  # 0- → 1-index


Measured memory_bytes: 70964
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
bool isPrime(int x){
int i;
if(x < 2)return 0;
else if(x == 2) return 1;
if(x%2 == 0) return 0;
for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
return 1;
}
int main(){
    int x;
    cin >> x;
    while(1){
        if(isPrime(x)) break;
        else x++;
    }
    cout << x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n;
    string s;
    cin >> n >> s;
    ll m = s.length();
    for(ll i = 0;i < m;i++){
        s[i] = (char)('A' + (((s[i]-'A')+n)%26));
    }
    cout << s << endl;
}

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

signed main() {
  string s;
  cin >> s;
  int cont = 0;
  int n = 15 - s.size();
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'o') {
      cont++;
    }
  }

  if (cont + n >= 8) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// 5/29
// 2-5-5 わーシャルフロイド
// 類題
#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>;
const int INF = 1e9;

// 二頂点間の距離を格納する隣接行列
vector<vector<int>> dist;

void warshall_floyed(int N) {
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

int main() {
    int H, W;
    cin >> H >> W;

    dist.assign(10, vector<int>(10, INF));
    rep(i, 10) {
        rep(j, 10) {
            int c;
            cin >> c;
            dist[i][j] = c;
        }
    }

    warshall_floyed(10);

    int ans = 0;

    // map<int, int> mp;
    rep(i, H) {
        rep(j, W) {
            int a;
            cin >> a;

            if (a != -1) {
                // mp[a]++;
                ans += dist[a][1];
            }
        }
    }

    // for (auto p : mp) {
    //     ans += dist[p.first][1] * p.second;
    // }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s; int d; cin >> s >> d;
    int n = s.length();
    VI k(n);
    FOR(i, 0, n)k[i] = s[i] - '0';

    auto dp = vec<ll>(2, 2, d);
    dp[0][0][0] = 1;
    FOR(i, 0, n){
        FOR(small, 0, 2)FOR(m, 0, d)dp[(i + 1) & 1][small][m] = 0;
        FOR(small, 0, 2)eFOR(x, 0, (small ? 9 : k[i]))FOR(m, 0, d) {
            (dp[(i + 1) & 1][small | (x < k[i])][(m + x) % d] += dp[i & 1][small][m]) %= mod;
        }
    }

    cout << (dp[n & 1][0][0] + dp[n & 1][1][0] - 1 + mod) % mod << "\n";
}


Measured memory_bytes: 384
def gcd(x,y):
	if x < y:
		x,y = y,x
	while y > 0:
		r = x % y
		x = y
		y = r
	return x

def lcm(x,y):
	return x * y // gcd(x,y)

N=int(input())
T=[0]*N
for i in range(N):
	T[i] = int(input())

ans=1
for i in range(N):
	ans=lcm(ans,T[i])

print(int(ans))

Measured memory_bytes: 3316
use proconio::input;

fn main() {
  input! {
    a: i64,
    b: i64,
    c: i64,
    d: i64,
  }
  let tak = (a + d - 1) / d; let aoki = (b + c - 1) / b;
  if tak >= aoki {
    println!("Yes");
  } else {
    println!("No");
  }
} 

Measured memory_bytes: 2128
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = sys.stdin.readline

def main():
    n = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    c1 = sum(As)

    for i in range(n):
        #モンスターを全滅させることができない場合
        if As[i]- Bs[i] > 0:
            As[i] -= Bs[i]
            Bs[i] = 0
        else:
            Bs[i] -= As[i]
            As[i] = 0

            if As[i+1] - Bs[i] > 0:
                As[i+1] -= Bs[i]
                Bs[i] = 0
            else:
                Bs[i] -= As[i]
                As[i+1] = 0
                
    c2 = sum(As)
    
    print(c1-c2)
        
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 20660
#include <cstdio>
#include <queue>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
const int MAXN = 100005;
int A[MAXN], B[MAXN];
int main(){
    int n;
    cin >> n;
    for(int i = 0; i <= n; i++) cin >> A[i];
    for(int i = 0; i < n; i++) cin >> B[i];
    int flag = 0; long long ans = 0;
    for(int i = n - 1; i >= 0; i--){
        ans += min(A[i + 1], B[i]);
        if(B[i] > A[i + 1]){
            B[i] -= A[i + 1];
            int m = min(B[i], A[i]);
            ans += m;
            A[i] -= m;
        }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
  int x,i=1,ans=0,temp,j;
  scanf("%d",&x);
  while(1)
    {
      temp = i;
      if(i*i > x)
	{
	  break;
	}
      for(j=0;j<10;j++)
	{
	  temp *= i;
	  if(temp <= x && ans < temp)
	    {
	      ans = temp;
	    }
	  else if(temp > x)
	    {
	      break;
	    }
	}
      i++;
    }
  printf("%d\n",ans);
  return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

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

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


    return 0;

}


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

using namespace std;

typedef long long ll;

struct union_find{
    vector<ll> par;
    vector<ll> chs;
    union_find(int N){
        par.resize(N);
        chs.resize(N);
        for(int i=0;i<N;i++) par[i] = i;
        for(int i=0;i<N;i++) chs[i] = 1;
    }
    ll root(ll x){
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(ll x,ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
        chs[ry] += chs[rx];
    }
    bool same(ll x,ll y){
        return root(x) == root(y);
    }
    ll size(ll x){
        return chs[root(x)];
    }
};

int main(){
    ll N,M;
    cin >> N >> M;
    union_find uf(N);
    ll a,b,c;
    for(int i=0;i<M;i++){
        cin >> a >> b >> c;
        uf.unite(a-1,b-1);
    }
    ll count = 0;
    for(int i=0;i<N;i++){
        if(uf.root(i)==i) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
#include<string.h>

typedef struct{
    char name[10];
    int score;
    int order;
    int number;
}rest;

int main(void){
    int n = 0;
    int i, j;
    rest rest[100];

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        rest[i].order = 1;
        rest[i].number = i + 1;
        scanf("%s %d", rest[i].name, &rest[i].score);
        for(j = 0; j < i; j++){
            if(strcmp(rest[j].name, rest[i].name) > 0){
                rest[j].order++;
            }else if(strcmp(rest[j].name, rest[i].name) == 0){
                if(rest[j].score > rest[i].score){
                    rest[i].order++;
                }else{
                    rest[j].order++;
                }
            }else{
                rest[i].order++;
            }
        }
    }
    
    for(i = 0; i < n; i++) 
        for(j = 0; j < n; j++)
            if(rest[j].order == i + 1)
                printf("%d\n", rest[j].number);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n,l,an,ans;
int main() {
	an=1e9;
	scanf("%d %d",&n,&l);
	for(int i=1; i<=n; i++) {
		ans+=l+i-1;
		if(abs(an)>abs(l+i-1))an=l+i-1;
	}
	ans-=an;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
N, M = list(map(int,input().split()))

b = [0]*(N+2)
b[0] = 1

for i in range(M):
    b[int(input())] = -1

for i in range(N):
    if b[i] != -1:
        if b[i+1] != -1:
            b[i+1] += b[i]
        if b[i+2] != -1:
            b[i+2] += b[i]

print(b[N]%1000000007)

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

n, q = map(int, input().split())
s = input()
memo = [0] * n
cnt = 0

for i in range(1, n):
    if s[i - 1] == 'A' and s[i] == 'C':
        cnt += 1
    memo[i] = cnt

for i in range(q):
    l, r = map(int, input().split())
    print(memo[r - 1] - memo[l - 1])


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

using namespace std;

#define MOD 1000000007
typedef long long int ll;

ll modi(ll a,ll n){
	if(n==0)
		return 1;
	else{
	    if(n%2==0){	      
         	ll temp=modi(a,n/2);	              
		    return (temp*temp)%MOD;		
        }
        else{
              return(a*modi(a,n-1))%MOD;	
        }
    }
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);
        
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll ans=0;
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			if(a[i]>a[j]){
				if(i<j){
					ll add=((k*(k+1))%MOD*modi(2,1000000005))%MOD;
					ans=(ans+add)%MOD;
				}
				else{
					ll add=((k*(k-1))%MOD*modi(2,1000000005))%MOD;
					ans=(ans+add)%MOD;
				}
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a,b;char op;cin>>a>>op>>b;
  op=='+' ? cout<<a+b<<endl : cout<<a-b<<endl;
}


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

string s, t;
int dp[3001][3001];

int solve(int i, int j){
	if(i == s.size() || j == t.size())	return 0;
	if(dp[i][j] != -1) return dp[i][j];

	dp[i][j] = max(solve(i+1, j), solve(i, j+1));

	if(s[i] == t[j])
		dp[i][j] = max(dp[i][j], solve(i+1, j+1) + 1);

	return dp[i][j];
}

void Tsolve(int i, int j){
	if(i == s.size() || j == t.size()){
		cout<<'\n';
		return;
	}

	if(s[i] == t[j]){
		int a = solve(i+1, j+1) + 1;
		cout<<s[i];
		Tsolve(i+1, j+1);
	}
	else{
		int b = solve(i+1, j);
		int c = solve(i, j+1);

		if(b>c)
			Tsolve(i+1, j);
		else
			Tsolve(i, j+1);
	}
	return;
}

int main(){
	cin>>s>>t;
	memset(dp, -1, sizeof dp);
	int ans = solve(0, 0);
	Tsolve(0,0);
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    ll n, count = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        if(i < 10) count++;
        if(99 < i && i < 1000) count++;
        if(9999 < i && i < 100000) count++;
    }
    print(count);
}


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

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] X = new int[M];
            for (int i = 0; i < M; i++) {
                X[i] = in.nextInt();
            }
            Arrays.sort(X);

            int[] diff = new int[M - 1];
            for (int i = 0; i < diff.length; i++) {
                diff[i] = X[i + 1] - X[i];
            }
            Arrays.sort(diff);

            int count = 0;
            for (int i = 0; i < diff.length - (N - 1); i++) {
                count += diff[i];
            }

            System.out.println(count);
        }
    }
}


Measured memory_bytes: 50296
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
check1=0
check2=0
for i in range(X,N+1):
  if i in A:
    check1+=1
for i in range(X,-1,-1):
  if i in A:
    check2+=1
print(min(check1,check2))


Measured memory_bytes: 3060
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 1000 + 5;
const int M = 201;
const int Q = 2e5 + 5;
const int OO = 2e9;
const int mod = 998244353;

int a,b,c,k,ans,m;

void init() {
}

int main() {

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

    cin >> a >> b >> c >> k;

    m = min(a,k);
    k -= m, ans += m;
    m = min(b,k);
    k -= m;
    m = min(c,k);
    k -= m, ans -= m;

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    ll x,y;
    cin >> x >> y;
    ll res = 0;
    if(x*y<0){
        res = abs(abs(x)-abs(y))+1;
    }else if(x!=0&&y!=0){
        if(x>y){
            res = x-y+2;
        }else{
            res = y-x;
        }
    }else{
        if((x>0&&y==0)||(x==0&&y<0)){
            res = abs(x)+abs(y)+1;
        }else{
            res = abs(x)+abs(y);
        }
    }
    
    put(res);
    return 0;
}


Measured memory_bytes: 256
int main(){
 
  int n,p[101],m[101][101];
  int i,j,k,l,s;
 
  scanf("%d",&n);
 
  for(i=1;i<=n;i++) scanf("%d%d",&p[i-1],&p[i]);
 
  for(i=1;i<=n;i++) m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=1000000;
      for(k=i;k<=j-1;k++){
    s=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
 
    if(m[i][j]>s) m[i][j]=s;
    else m[i][j] = m[i][j];
      }
    }
  }
  printf("%d\n",m[1][n]);
 
  return 0;
}

Measured memory_bytes: 636
#include "bits/stdc++.h"
using namespace std;

#define OUT(x)  cerr << #x << " = " << x << endl;
#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define piii    pair<int, pair<int, int>>

int main() {
        string s;
        cin >> s;
        string t = s;
        reverse(all(t));
        if (s == t) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
}



Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

distance = [b - a, c - a, d - a, e - a, c - b, d - b, e - b, d - c, e - c, e - d]
for i in range(10):
  if k < distance[i]:
    print(":(")
    exit()
print("Yay!")

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

class Dmondai {
    static void Main()
    {
        var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = line[0];
        var M = line[1];
        var A= Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).OrderBy(x=>x).ToArray();
        var cost = new int[] { 2,5,5,4,5,6,3,7,6};
        var dp = new int[N+1];
        dp[0] = 0;
        for (int i = 1; i <= N; ++i) dp[i] = int.MinValue;
        for (int i=0;i<=N;++i)
        {
            if (i != 0 && dp[i] == int.MinValue) continue;
            for (int j=0;j<M;++j)
            {
                if (N < i + cost[A[j] - 1]) continue;
                dp[i+cost[A[j] - 1]] = dp[i]+1;
            }
        }
        var ans = string.Empty;
        var index = N;
        while (0<index)
        {
            for (int j=M-1;-1<j;--j)
            {
                if (index - cost[A[j] - 1] < 0) continue;
                if (dp[index - cost[A[j] - 1]] == dp[index] -1) {
                    ans += A[j];
                    index -= cost[A[j] - 1];
                    break;
                }
            }
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 25172