akhauriyash/Code-Regression huggingface dataset:
// atcoder/abc158/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

int di[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dj[] = {1, 0, 0, -1, 1, -1, -1, 1};
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli n, a, b;
  while (cin >> n >> a >> b) {
    lli x = n / (a + b);
    lli y = n % (a + b);
    cout << (x * a) + min(y, a) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl;
using namespace std;
int n;
int a[100005][3],memo[100005][3];
int dp(int i,int prev)
{
    if(memo[i][prev+1]!=-1)
    {
        return memo[i][prev+1];
    }
    if(i==n)
    {
        return 0;
    }
    int ret1=0,ret2=0,ret3=0;
    if(prev!=0)
    {
        ret1=a[i][0]+dp(i+1,0);
    }
    if(prev!=1)
    {
        ret2=a[i][1]+dp(i+1,1);
    }
    if(prev!=2)
    {
        ret3=a[i][2]+dp(i+1,2);
    }
    return memo[i][prev+1]=max(ret1,max(ret2,ret3));
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;++i)
    {
        scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
    }
    memset(memo,-1,sizeof memo);
    printf("%d",dp(0,-1));
    return 0;
}




Measured memory_bytes: 8832
import java.awt.Event;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.channels.FileChannel;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
 
public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
//		new TestA().doIt();
//		new TestB().doIt();
//		new TestC().doIt();
		new TestD().doIt();
	}
	class TestD{
		void doIt() {
			int N = sc.nextInt();
			int M = sc.nextInt();
			UnionFind uf = new UnionFind(N);
			for(int i = 0;i < M;i++) {
				int A = Integer.parseInt(sc.next()) - 1;
				int B = Integer.parseInt(sc.next()) - 1;
				uf.unionSet(A, B);
			}
			int MAX = 0;
			for(int i = 0;i < N;i++) {
				MAX = Math.max(MAX, uf.setSize[i]);
			}
			System.out.println(MAX);
		}
		class UnionFind{
			int[] p, rank, setSize;
			int numSets;
			
			public UnionFind(int N) {
				p = new int[numSets = N];
				rank = new int[N];
				setSize = new int[N];
				for(int i = 0;i < N;i++) {
					p[i] = i;
					setSize[i] = 1;
				}
			}
			
			int findSet(int i) {
				return p[i] == i ? i : (p[i] = findSet(p[i]));
			}
			
			boolean isSameSet(int i,int j) {
				return findSet(i) == findSet(j);
			}
			
			void unionSet(int i,int j) {
				if(isSameSet(i, j))return;
				numSets--;
				int x = findSet(i), y = findSet(j);
				if(rank[x] > rank[y]) {
					p[y] = x;
					setSize[x] += setSize[y];
				}else {
					p[x] = y;
					setSize[y] += setSize[x];
					if(rank[x] == rank[y])rank[y]++;
				}
			}
			
			int numDisjoinSets() {
				return numSets;
			}
			
			int sizeOfSet(int i) {
				return setSize[findSet(i)];
			}
		}
	}
}

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

int main(){
    int a,b; cin >> a >> b;
    if(a%3==0 || b%3==0 ||(a+b)%3==0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 3636
N = int(input())
S = input()

ans = S[1:].count("E")

calc = ans

for i in range(1,N) :
    if S[i] == "E" :
        calc -= 1
    if S[i-1] == "W" :
        calc += 1
    
    ans = min(ans,calc)

print(ans)


Measured memory_bytes: 3676
#include<iostream>
using namespace std;
int main(){
	int x,y,n;
	while(cin>>x>>y){
		if(x==0&&y==0){
			break;
			}
	if(x>y){
		n=x;
		x=y;
		y=n;
		}
	cout<<x<<" "<<y<<endl;
	}
return 0;

	}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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;}

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

void check(int x,int y,vc<pair<pi,bool>> &v){
    rep(k,SZ(v)){
        if(x==v[k].fi.fi && y==v[k].fi.se){
            v[k].se=true;
        }
    }
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    while(true){
        int N; cin >> N;
        if(N==0) break;
        vc<pair<pi,bool>> v;
        rep(i,N){
            int a,b; cin >> a >> b;
            v.eb(make_pair(a,b),false);
        }
        int nx=10,ny=10;
        check(nx,ny,v);
        int M; cin >> M;
        rep(i,M){
            char d; int l; cin >> d >> l;
            if(d=='N'){
                rep(j,l){
                    nx+=dx[0]; ny+=dy[0];
                    check(nx,ny,v);
                }
            } else if(d=='E'){
                rep(j,l){
                    nx+=dx[1]; ny+=dy[1];
                    check(nx,ny,v);
                }
            } else if(d=='S'){
                rep(j,l){
                    nx+=dx[2]; ny+=dy[2];
                    check(nx,ny,v);
                }
            } else {
                rep(j,l){
                    nx+=dx[3]; ny+=dy[3];
                    check(nx,ny,v);
                }
            }
        }
        bool can=true;
        rep(i,N){
            if(!v[i].se){
                can=false;
            }
        }
        if(can) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 3152
W, H, N = list(map(int, input().split()))
xya = [list(map(int, input().split())) for _ in range(N)]

Result =[[1 for _ in range(H)] for _ in range(W)]

for x,y,a in xya:
  #print(x,y,a)
  if a == 1:
    for i in range(x):
      for j in range(H):
        Result[i][j] = 0
  elif a == 2:
    for i in range(x, W):
      for j in range(H):
        Result[i][j] = 0
  elif a == 3:
    for i in range(W):
      for j in range(y):
        Result[i][j] = 0
  elif a == 4:
    for i in range(W):
      for j in range(y, H):
        Result[i][j] = 0
#print(Result)

Result = [flatten for inner in Result for flatten in inner]
print(sum(Result))

Measured memory_bytes: 3188
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const A = parseInt(arg[0].split(" ")[0]);
    const B = parseInt(arg[0].split(" ")[1]);
    
    if(A >= 13) {
        console.log(B);
    } else if(13 > A && A >= 6) {
        console.log(B / 2);
    } else {
        console.log(0);
    }
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
  size_t N, M;
  int C;

  std::cin >> N >> M >> C;

  std::vector<int> B(M);

  for (size_t i=0; i<M; i++)
    std::cin >> B[i];

  size_t ans = 0;

  for (size_t i=0; i<N; i++) {
    auto calc = C;
    for (size_t j=0; j<M; j++) {
      int a;
      std::cin >> a;
      calc += a * B[j];
    }
    if (calc > 0) ans++;
  }

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

  return 0;
}


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

const int N = 5e5 + 25, MOD = 998244353;
int n, k, ans;
int F[N], Fdiv[N];

int _sum (int a, int b) {
	int c = a + b;
	if (MOD <= c)
		c -= MOD;
	return c;
}

int _sub (int a, int b) {
	int c = a - b;
	if (c < 0)
		c += MOD;
	return c;
}

int _mul (int a, int b) {
	return 1LL * a * b % MOD;
}

int _pow (int a, int b) {
	int res = 1;
	for (; b; b >>= 1) {
		if (b & 1)
			res = _mul(res, a);
		a = _mul(a, a);
	}
	return res;
}

int _choose (int a, int b) {
	if (b < a || min(a, b) < 0)
		return 0;

	return _mul(F[b], _mul(Fdiv[a], Fdiv[b - a]));
}

void preProcess() {
	F[0] = 1;
	Fdiv[0] = 1;
	for (int i = 1; i < N; i++) {
		F[i] = _mul(F[i - 1], i);
		Fdiv[i] = _pow(F[i], MOD - 2);
	}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	preProcess();
	cin >> n >> k;
	if (k < n) {
		cout << 0 << "\n";
		return 0;
	}

	for (int B = 0; B + B < k && n <= k - B; B++) {
		int R = k - B;
		int T = R - n + 1;
		// cout << R << " " << R + B << " " << T << " " <<  B + T << " " << R + B << "\n";

		if (B < T) {
			// cout << "ADD1 --> " << _choose(R, R + B) << "\n";
			ans = _sum(ans, _choose(R, R + B));
		}
		else {
			// cout << "ADD2 --> " << _choose(R, R + B) << " - " << _choose(B + T, R + B) << "\n";
			ans = _sum(ans, _sub(_choose(R, R + B), _choose(B - T, R + B)));
		}
	}
	if (k % 2 == 0 && n * 2 <= k) {
		int R = k / 2;
		int B = k / 2;
		B--;
		int T = R - n + 1;

		if (B < T) {
			// cout << "ADD1 --> " << _choose(R, R + B) << "\n";
			ans = _sum(ans, _choose(R, R + B));
		}
		else {
			// cout << "ADD2 --> " << _choose(R, R + B) << " - " << _choose(B + T, R + B) << "\n";
			ans = _sum(ans, _sub(_choose(R, R + B), _choose(B - T, R + B)));
		}
	}

	cout << ans << "\n";
	return 0;	
}

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

string map[12];
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
void check(int i,int j)
{
  map[i][j]='0';
  for(int a=0;a<4;a++)
    {
      int x=i+dx[a];
      int y=j+dy[a];
      if(x>=0 &&x<12&&y>=0&&y<12)
	if(map[x][y]=='1')
	  check(x,y);
    }
}


int main()
{
  for(;cin>>map[0];)
    {
      for(int i=1;i<12;i++)
	cin>>map[i];      
      int count=0;
      for(int i=0;i<12;i++)
	for(int j=0;j<12;j++)
	  if(map[i][j]=='1')
	    {
	      count++;
	      check(i,j);
	    }
      cout<<count<<endl;
    }
}

Measured memory_bytes: 1188
import java.util.Scanner;

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

        String[] a = scanner.nextLine().split(" ");
        int N = Integer.parseInt(a[0]);
        int K = Integer.parseInt(a[1]);
        a = scanner.nextLine().split(" ");

        int[] array = new int[N];
        int plusStart = -1;
        int minusStart = -1;

        for (int i = 0; i < N; ++i) {
            int it = Integer.parseInt(a[i]);
            if (plusStart < 0 && it >= 0) {
                plusStart = i;
                if (it == 0) {
                    minusStart = plusStart;
                } else if (i > 0) {
                    minusStart = plusStart - 1;
                }
            }
            array[i] = it;
        }
        if (plusStart < 0) {
            minusStart = N - 1;
        }

        if (minusStart == plusStart && K == 1) {
            System.out.println(0);
            return;
        }

        int min = Integer.MAX_VALUE;

        if (plusStart >= 0) {
            int start = 1;

            if (plusStart + K - 1 <= N - 1) {
                min = array[plusStart + K - 1];
            } else {
                //plusStart + K - 1 > N - 1
                //plusStart + K - N > 0
                start = plusStart + K - N;
            }
            for (int i = start; i < K; ++i) {
                if (plusStart - i < 0) {
                    break;
                }
                int w = array[plusStart - i] * -2 + array[plusStart - i + K - 1];
                if (w < min) {
                    min = w;
                }
            }
        }

        if (minusStart >= 0) {
            int start = 1;

            if (minusStart >= K - 1) {
                int w = array[minusStart - (K - 1)] * -1;
                if (w < min) {
                    min = w;
                }
            } else {
                // minusStart < K - 1
                // K - 1 - minusStart > 0
                start = K - 1 - minusStart;
            }

            for (int i = start; i < K; ++i) {
                if (minusStart + i >= N) {
                    break;
                }
                int w = array[minusStart + i] * 2 + array[minusStart - (K - 1 - i)] * -1;
                if (w < min) {
                    min = w;
                }
            }
        }
        System.out.println(min);
    }
}

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

using namespace std;

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

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

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

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n,m;
map<string,ll> ma;

int main(){
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        ma[s]++;
    }
    cin >> m;
    rep(i,m){
        string s;
        cin >> s;
        ma[s]--;
    }
    ll ans = 0;
    for(auto it = ma.begin();it != ma.end();it++){
        ans = max(ans,it->second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char c;
int main()
{
	cin>>c;
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
	{
		cout<<"vowel";
	}
	else
	{
		cout<<"consonant";
	}
	return 0;
}

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



int main(){
    
    int n;
    cin>>n;
    
    for(int i=n;i>3;i=i-4){
        if(i%7==0||i%4==0){
            cout<<"Yes";
            return 0;
        }
    }
    
    cout<<"No";

    return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li n, k;
    cin >> n >> k;
    li num = 0;
    if (k % 2 == 1) {
        num = (n / k) * (n / k) * (n / k);
    } else {
        li tmp = n / (k / 2);
        tmp -= n / k;
        num = tmp * tmp * tmp + (n / k) * (n / k) * (n / k);
    }
    cout << num << endl;

    return 0;
}

Measured memory_bytes: 256
N,Q = map(int, input().split())
SS = input()
lrq = []
for i in range(N-1):
  if SS[i] == "A" and SS[i+1] == "C":
    lrq.append(1)
  else:
    lrq.append(0)
lrq.append(0)
lr = []
lr.append(0)
for i in range(N):
  lr.append(lr[i]+lrq[i])
for _ in range(Q):
  l,r = map(int, input().split())
  l -= 1
  r -= 1
  ans = lr[r+1]-lr[l]
  if lrq[r] == 1:
    ans -= 1
  print(ans)


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

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) begin(a),end(a)

signed main()
{
    int n, m;
    while (cin >> n >> m, n) {
        string s; cin >> s;

        int ans = 0;

        rep(i, m) {
            if (i + 2 < m) {
                if (s[i] != 'I') continue;

                int lvl = 0;

                if (s[i+1] == 'O' && s[i+2] == 'I') {
                    lvl += 1;
                    i += 3;

                    while (i + 1 < m && s[i] == 'O' && s[i+1] == 'I') {
                        lvl += 1;
                        i += 2;
                    }

                    ans += max(lvl - n + 1, 0);

                    i--;
                }
            }
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 3884
#include<iostream>
using namespace std;
bool isprime[1000005];
int prime[1000005];
void sieve() {
	for (int i = 0; i <= 1000000; i++) isprime[i] = true;
	isprime[0] = isprime[1] = false;
	prime[0] = prime[1] = 0;
	for (int i = 2; i <= 1000000; i++) {
		if (isprime[i]) {
			prime[i] = prime[i - 1] + 1;
			for (int j = 2 * i; j <= 1000000; j += i) isprime[j] = false;
		}
		else prime[i] = prime[i - 1];
	}
}
int main() {
	sieve();
	int n;
	while (cin >> n) {
		cout << prime[n] << endl;
	}
}

Measured memory_bytes: 6044
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */


int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  size_t n, m;
  cin >> n >> m;
  vector<vector<size_t>> adj(n);
  for(size_t i = 0, u, v; i < m; ++i)
  {
    cin >> u >> v;
    --u; --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  vector<bool> tag(n, false);
  vector<size_t> out;
  out.reserve(n);
  out.push_back(0);
  tag[0] = true;

  for(size_t k = 0; k < 2; ++k)
  {
    reverse(begin(out), end(out));
    while(true)
    {
      const auto u = out.back();
      bool fail = true;
      for(const auto v: adj[u])
        if(!tag[v])
        {
          fail = false;
          out.push_back(v);
          tag[v] = true;
          break;
        }
      if(fail) break;
    }
  }

  cout << out.size() << '\n';
  for(size_t i = 0; i < out.size(); ++i)
    cout << out[i] + 1 << " \n"[i + 1 == out.size()];

  return EXIT_SUCCESS;
}



Measured memory_bytes: 7168
SixNum = [i for i in range(0,100001)]
for i in range(1,7):
        for j in range(1,100001):
                SixNum[j] = min(SixNum[j],j//(6**i) + SixNum[j%(6**i)])

NineNum = [i for i in range(0,100001)]
for i in range(1,6):
        for j in range(1,100001):
                NineNum[j] = min(NineNum[j],j//(9**i) + NineNum[j%(9**i)])

N = int(input())
ans = 100001
for i in range(0,N+1):
        ans = min(ans,SixNum[i]+NineNum[N-i])
print(ans)

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

int main(){
  int n;
  cin >> n;
  char s[n];
  for (int i=0;i<n;i++){
    cin >> s[i];
  }
  int count=0;
  for (int i=0;i<n;i++){
    if (s[i]=='Y'){
      count++;
    }
  }
  if(count==0){
    cout << "Three" << endl;
  }
  else{
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
package main;

import (
	"strconv"
	"bufio"
	"os"
	"fmt"
)

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	x := sc.NextInt()
	a := sc.NextIntArray()

	k := a[0] - x
	if k > 0 {
		a[0] = x
	} else {
		k = 0
	}
	for i := 0; i < N - 1; i++ {
		tmp := a[i] + a[i + 1] - x
		if tmp > 0 {
			a[i + 1] -= tmp
			k += tmp
		}
	}

	fmt.Println(k)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,m,c,b[50],x,cnt=0;
int main()
{
  cin>>n>>m>>c;
  for(int i=1;i<=m;i++) cin>>b[i];
  for(int i=1;i<=n;i++)
  {
    int ans=0;
    for(int j=1;j<=m;j++) cin>>x,ans+=b[j]*x;
    if(ans+c>0) cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll A[200010];

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

  rep( i, N ) {
    std::cin >> A[i];
  }

  ll prv = 0;
  ll ans = 0;

  rep( i, N ) {
    if( prv > A[i] ) {
      ans += prv-A[i];
    } else {
      prv = A[i];
    }
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5188
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for ( int i=1; i<=int(n); i++ )  
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;
typedef pair<int, int> pii;
typedef long double LD;
const int INF = 0x3f3f3f3f;

template <class T>  
inline bool RD(T &ret) {  
        char c; int sgn;  
        if (c = getchar(), c == EOF) return 0;  
        while (c != '-' && (c<'0' || c>'9')) c = getchar();  
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');  
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');  
        ret *= sgn;  
        return 1;  
}  
template <class T>  
inline void PT(T x) {  
        if (x < 0) putchar('-') ,x = -x;  
        if (x > 9) PT(x / 10);  
        putchar(x % 10 + '0');  
}  

const int N = 5e6 + 10;
char str[N];

int main() {
	int K;
	scanf("%s%d", str + 1, &K);
	int n = strlen(str + 1);
	for(int i = 1; i <= n; i ++) {
		if(str[i] == 'a') continue;
		int nd = 26 - (str[i] - 'a');
		if(K >= nd) str[i] = 'a', K -= nd;
	}
	str[n] = (str[n] - 'a' + K) % 26 + 'a'; 
	printf("%s\n", str + 1);
}


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

using namespace std;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<set<int>> graph(n + 1);
    for (int i = 0; i < m; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        graph[x].insert(y);
        graph[y].insert(x);
    }
    set<int> seen;
    int answer = 0;
    vector<int> parent(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        /* printf("seen is = {"); */
        /* for (int x : seen) { */
        /*     printf("%d ", x); */
        /* } */
        /* printf("}\n"); */
        if (seen.count(i) != 0) {
            continue;
        }
        int size = 0;
        vector<int> q = {i};
        int index = 0;
        /* printf("searching for component at %d\n", i); */
        while (index < (int)q.size()) {
            int node = q[index];
            index++;
            if (seen.count(node) != 0) {
                continue;
            }
            seen.insert(node);
            size++;
            for (int child: graph[node]) {
                if (seen.count(child) == 0) {
                    q.push_back(child);
                    parent[child] = node;
                }
            }
        }
        answer = max(answer, size);
        /* printf("size is = %d\n", size); */
    }
    printf("%d\n", answer);
}


Measured memory_bytes: 42452
#include <stdio.h>
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	int n;
	scanf("%d",&n);
	int m=1e6,s=0;
	for(int i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		s+=t;
		if(t%2)m=min(m,t);
	}
	printf("%d\n",(s-s%2*m)/2);
}


Measured memory_bytes: 2100
#include <iostream>
#include <string>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
static int const max_size = 100;

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

	int A[3][101];
	rep(i, 0, 2 + 1) {
		rep(j, 0, N + 1) {
			if (i == 0 || j == 0) {
				A[i][j] = 0;
				continue;
			}
			cin >> A[i][j];
		}
	}

	int maxValue = 0;
	rep(i, 1, N + 1) {
		int sum = 0;
		rep(j, 1, i + 1) {
			sum += A[1][j];
		}
		rep(j, i, N + 1) {
			sum += A[2][j];
		}
		if (maxValue < sum) {
			maxValue = sum;
		}
	}
	cout << maxValue << endl;

	return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i,n) for(int i=0;i<(n);i++) 
#define rep1(i,n) for(int i=1;i<(n);i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

int main(int argc, const char *argv[]){
    int n,m;
    cin >> n >> m;
    vector<ll> a(n),b(m),c(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i] >> c[i];
    vector<pair<ll,ll>> d;
    rep(i,n) d.push_back(pair<ll,ll>(a[i],1));
    rep(i,m) d.push_back(pair<ll,ll>(c[i],b[i]));
    sort(d.begin(),d.end(),greater<pair<ll,ll>>());
    ll cnt=n;
    ll sum = 0;
    rep(i,n+m){
        if(d[i].second <= cnt){
            sum += d[i].first*d[i].second;
            cnt -= d[i].second;
        }else{
            sum += d[i].first*cnt;
            co(sum);
            return 0;
        }
    }
}

Measured memory_bytes: 8816
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,K;
  cin >> N >> K;
  vector<int> x(N);
  rep(i,N)
  {
    cin >> x[i];
  }
  int sum = 0;
  rep(i,N)
  {
    sum += 2*min(x[i],K-x[i]);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
        if(x+r<=W && x-r>=0 && y+r<=H && y-r>=0) {
printf("Yes\n");
}
    else {
printf("No\n");
}       
return 0;    
}


Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

#define rep(i, n) for(long int i = 0; i < n; i++)

int main(){
    long int a, b, q;
    cin >> a >> b >> q;
    long int s[a];
    rep(i, a) cin >> s[i];
    long int t[b];
    rep(i, b) cin >> t[i];
    sort(s, s + a);
    sort(t, t + b);
    long int x1[q];
    rep(i, q) cin >> x1[i];
    rep(i, q) {
        long int x = x1[i];
        long int idx1 = lower_bound(s, s + a, x) - s;
        long int idx3 = lower_bound(t, t + b, x) - t;
        long int ans;
        ans = 10000000000000000;
        if (idx1 < a && idx3 < b){
            ans = min(ans, max(s[idx1] - x, t[idx3] - x));
        }
        if (idx1 > 0 && idx3 > 0){
            ans = min(ans, max(x - s[idx1-1], x - t[idx3-1]));
        }
        if (idx1 < a && idx3 > 0){
            ans = min(ans, min(s[idx1] - x, x - t[idx3-1]) * 2 + max(s[idx1] - x, x - t[idx3-1]));
        }
        if(idx1 > 0 && idx3 < b){
            ans = min(ans, min(x - s[idx1-1], t[idx3] - x) * 2 + max(x - s[idx1-1], t[idx3] - x)); 
        }
        cout << ans << endl;
    } 
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/
int main()
{
  string a, b;
  cin >> a >> b;
  cout << b << a << endl;
    return 0;
}

Measured memory_bytes: 256
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll n;
cin>>n;
ll ans=-1;
for(ll i=1;i<=n;i++)
{
    double tt=((double)i*(1.08));
    ll x=tt;
    //cout<<x<<endl;
    if(x==n)
    {
        ans=i;
    }
}
if(ans==-1)
{
    cout<<":("<<endl;
}else
{
    cout<<ans<<endl;
}
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void)
{
	double r,p,s,e;
	p=M_PI;
	scanf("%lf",&r);
	s=p*r*r;
	e=2*p*r;
	printf("%lf %lf",s,e);
	return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
using i64 = long long;
using namespace std;

string g[10];
int main() {
  int H, W, K;
  cin >> H >> W >> K;
  for (int i = 0; i < H; i++) 
    cin >> g[i]; 
  int best = H * W;
  for (int s = 0; s < (1 << (H - 1)); s++) {
    auto check = [&](int x) {
      return (s & (1 << x)) > 0;
    };
    vector<int> cuts;
    for (int i = 0; i < H - 1; i++)
      if (check(i)) 
        cuts.push_back(i);
    cuts.push_back(H - 1);
    array< vector<int>, 2> occur = {
      vector<int>(cuts.size(), 0),
      vector<int>(cuts.size(), 0)
    };
    vector<int> vcuts;
    bool possible = true;
    for (int col = 0; col < W; col++) {
      bool ok;
      int repeat = 2;
      while (repeat--) {
        ok = true;
        for (int cut = 0, row = 0; cut < cuts.size() && row < H; row++) {
          if (cuts[cut] < row) {
            cut++;
          }
          int color = g[row][col] == '1';
          if (color == 1 && occur[color][cut] + 1 > K)
            { ok = false; break; }
          occur[color][cut] += 1;
        }
        if (ok) { break; }
        if (!ok && repeat == 1) {
          vcuts.push_back(col);
          fill(occur[0].begin(), occur[0].end(), 0);
          fill(occur[1].begin(), occur[1].end(), 0);
        }
      }
      if (!ok) { possible = false; break; }

    }
    if (!possible)
      continue;

    best = min(best, (int) cuts.size() + (int) vcuts.size() - 1);
  }
  cout << best << endl;
}

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

int main() {
  int m1,m2,d1,d2;

  cin >> m1 >> d1 >> m2 >> d2;

  if(m1 != m2) {
    cout << 1 << endl;
    return 0;
  }
  else {
    cout << 0 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long int a,b,c,d=0,e2=0,e1=0,b1=0;
 scanf("%lld%lld%lld",&a,&b,&c);
 d=b+c;
 if(b==0)
 printf("0");
 else
{
 e1=a%d;
 e2=a/d;
 if(e1<=b)
 b1=b*e2+e1;
 else
    b1=b*e2+b;

     printf("%lld",b1);
}

}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

// 標準入力からデータを読み込む準備

Scanner sc = new Scanner(System.in);

// 2つの文字の固まりをそれぞれ整数値と想定して読み込む

int a = sc.nextInt();

int b = sc.nextInt();

int area = a*b/* ここを変えて面積を求めよう */;

int length = 2*a+2*b/* ここを変えて周囲の長さを求めよう */;

System.out.println(area + " " + length); 

}

}

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

int main() {
    int W,H,N;
    cin >> W >> H >> N;
    int total = 0;
    int ans = 0;
    while(total < N){
        ans++;
        if(W >= H ){
            total += W;
            H--;
        }else{
            total += H;
            W--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
hs = list(map(int, input().split()))

min = 99999
ans = 99999

for i in range(n):
    tmp = t - hs[i] * 0.006
    d = abs(a-tmp)
    if d < min:
        ans = i
        min = d

print(ans+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  int sum = 0;
  cin >> A >> B;
  for(int i = 0; i <= B - A;){  
    string s = to_string(A);
    if((s.at(0) == s.at(4)) && (s.at(1) == s.at(3))){
      sum ++;
    }
    A++;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3668
#include "bits/stdc++.h"
#include <random>
#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, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<pll> a(n);
  REP(i, n) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(ALL(a));
  vl sum(n + 1);
  REP(i, n) sum[i + 1] = sum[i] + a[i].first;

  int l = -1, r = n - 1;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    auto c = upper_bound(ALL(a), pll(a[mid].first,INF)) - a.begin();
    if (mid >= n - p) {
      r = mid;
      continue;
    }
    if (a[n - p].first > a[mid].first + m) {
      l = mid;
      continue;
    }
    if (c + p - 1 >= v) {
      r = mid;
      continue;
    }
    map<ll, ll> q;
    q.emplace(v - (c + p - 1), m);
    for (int i = c; i <= n - p; ++i) {
      ll rem = m + a[mid].first - a[i].first;

      vector<pll> v;
      while (!q.empty()) {
        auto p = *prev(q.end(), 1);
        q.erase(p.first);
        if (p.first == 0)
          continue;
        if (p.second > rem) {
          q[p.first - 1] += rem;
          q[p.first] += p.second - rem;
          break;
        }
        else {

          v.emplace_back(p.first - 1, p.second);
          rem -= p.second;
        }
      }
      for (auto&& b : v)
        q[b.first] += b.second;
    }
    if (!q.empty() && (*q.begin()).first== 0)q.erase(q.begin());

    if (q.empty()) {
      r = mid;
    }
    else {
      l = mid;
    }
  }
  cout << n - r << endl;
}


Measured memory_bytes: 2560
N=int(input())
a=list(map(int, input().split()))
l = [0]*(10**5+1)
for i in a:
    l[i] += 1
res = 0
for i in range(1, 10**5):
    res = max(res, l[i-1]+l[i]+l[i+1])
print(res)

Measured memory_bytes: 13964
#include <complex>
#include <cstdio>
#include <cmath>
using namespace std;

// _ÀWð^Æ·é
typedef complex<double> P;

//XYÀW
#define X real()
#define Y imag()

// ¼üp1,p2Æüªp3,p4Ìð·»è
// (n < 0)<=>ð· , (n == 0)<=>¼üã, (n > 0)<=>ð·µÄ¢È¢  
double isIntersect(P p1, P p2, P p3, P p4){  
    return ( (p1.X-p2.X)*(p3.Y-p1.Y) + (p1.Y-p2.Y)*(p1.X-p3.X)) * ((p1.X-p2.X)*(p4.Y-p1.Y) + (p1.Y-p2.Y)*(p1.X-p4.X));  
}

int main(){
	double xa, xb, xc, xd, ya, yb, yc, yd;

	while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF ){
		P a( xa , ya );
		P b( xb , yb );
		P c( xc , yc );
		P d( xd , yd );
		
		if( isIntersect(a,c,b,d) > 0.0 || isIntersect(b,d,a,c) > 0.0 ){
			printf("NO\n");
		}else{
			printf("YES\n");
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> state;
const int INF = 1 << 29;
const double EPS = 1e-10;

int H, W;
int memo[12][500][500];
int dx[] = {1, 0, -1, 0, 0};
int dy[] = {0, 1, 0, -1, 0};
char field[22][22];

int h(int x, int y){
  return y * W + x;
}

int main(){
  int sx, sy, gx, gy;
  string order;
  while(cin >> H >> W && (H || W)){
    rep(i, H) rep(j, W){
      cin >> field[i][j];
      if(field[i][j] == 'A'){
	field[i][j] = '.';
	sy = i;
	sx = j;
      }
      if(field[i][j] == 'B'){
	field[i][j] = '.';
	gy = i;
	gx = j;
      }
    }
    cin >> order;
    bool f = false;
    queue<state> que;
    memset(memo, -1, sizeof(memo));
    que.push(state(0, P(h(sx, sy), h(gx, gy))));
    memo[0][h(sx, sy)][h(gx, gy)] = 0;
    while(!que.empty()){
      int ngx, ngy;
      state st = que.front();que.pop();
      int turn = st.first;
      sx = st.second.first % W;
      sy = st.second.first / W;
      gx = st.second.second % W;
      gy = st.second.second / W;
      //      cout << turn << " " << sx << " "<< sy << endl;
      if(sx == gx && sy == gy){
	cout << memo[turn][h(sx,sy)][h(gx,gy)] << " " << sy << " " << gx << endl;
	f = true;
	break;
      }
 
      ngx = gx, ngy = gy;
      if(order[turn] == '8') ngx = gx, ngy = gy - 1;
      if(order[turn] == '6') ngx = gx + 1, ngy = gy;
      if(order[turn] == '4') ngx = gx - 1, ngy = gy;
      if(order[turn] == '2') ngx = gx, ngy = gy + 1;
      if(0 > ngx || ngx >= W || 0 > ngy || ngy >= H){
	ngx = gx;
	ngy = gy;
      }
      rep(i, 5){
	int nturn = (turn + 1) % (int)order.size();
	int nsy = sy + dy[i];
	int nsx = sx + dx[i];
	if(0<=nsx && nsx<W && 0<=nsy && nsy<H && field[nsy][nsx] == '.'){
	  if(memo[nturn][h(nsx,nsy)][h(ngx, ngy)] == -1){
	    memo[nturn][h(nsx,nsy)][h(ngx,ngy)]=memo[turn][h(sx,sy)][h(gx,gy)]+1;
	    que.push(state(nturn, P(h(nsx, nsy), h(ngx, ngy))));
	  }
	}
      } 
    } 
    if(!f) cout << "impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
s=list(map(int,input().split()))
t=list(map(int,input().split()))
if s[0]==1:
  print(0)
else:
  b=0
  for i in range(s[0]):
    a=0
    for j in range(s[0]):
      if t[i]>t[j]:
        a=a+1
    b=b+a*s[1]*(s[1]-1)//2
    b=b%1000000007
  b=b%1000000007
  for v in range(s[0]-1):
    a=0
    for w in range(v+1,s[0]):
      if t[v]>t[w]:
        a=a+1
    b=b+a*s[1]
    b=b%1000000007
  b=b%1000000007
  print(int(b))

Measured memory_bytes: 3188
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr()
	H1 := list[0]
	M1 := list[1]
	H2 := list[2]
	M2 := list[3]
	K := list[4]

	a := H1*60 + M1
	b := H2*60 + M2

	if b-a-K >= 0 {
		fmt.Printf("%d", b-a-K)
	} else {
		fmt.Printf("%d", 0)
	}
	fmt.Printf("\n")
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 1760
#include<bits/stdc++.h>
using namespace std;
const int N=60,MOD=1e9+7;
typedef long long ll;
struct Matrix{
	int f[N][N];
	Matrix(){memset(f,0,sizeof(f));}
};
int n;
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch&15),ch=getchar();
	return x*f;
}
Matrix operator*(Matrix a,Matrix b)
{
	Matrix s;
	for (register int i=1;i<=n;++i)
	  for (register int j=1;j<=n;++j)
	    for (register int k=1;k<=n;++k)
	      s.f[i][j]=(s.f[i][j]+1ll*a.f[i][k]*b.f[k][j])%MOD;
	return s;
}
Matrix Power(Matrix a,ll x)
{
	Matrix s;
	for (register int i=1;i<=n;++i) s.f[i][i]=1;
	while (x)
	{
		if (x&1) s=s*a;
		x>>=1;
		a=a*a;
	}
	return s;
}
int main()
{
	ll K;scanf("%d%lld",&n,&K);
	Matrix a;
	for (register int i=1;i<=n;++i)
	  for (register int j=1;j<=n;++j)
	    a.f[i][j]=read();
	Matrix s=Power(a,K);
	int ans=0;
	for (register int i=1;i<=n;++i)
	  for (register int j=1;j<=n;++j)
	    ans=(1ll*ans+s.f[i][j])%MOD;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384