akhauriyash/Code-Regression huggingface dataset:
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b){if (b == 0) return a;return gcd(b, a % b);}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

bool check(vector<int> A){
    for(int i = 0; i < A.size(); i++){
        if(A[i] % 2 != 0) return false;
    }
    return true;
}

int main(){
    ll int N, ans=0;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) cin >> A[i];

    while(check(A)){
        for(int i = 0; i < N; ++i){
            A[i] /= 2;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static long H;
        static long W;
        static String[] map;
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var inp = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var A = new long[N + 2];
            A[0] = 0;
            A[N + 1] = 0;

            for (int i = 1; i <= N; i++)
            {
                A[i] = inp[i-1];
            }

            var sum = 0L;
            for (int i = 1; i <= N+1; i++)
            {
                sum += Abs(A[i] - A[i - 1]);
            }

            for (int i = 1; i <= N; i++)
            {
                Console.WriteLine(sum + Abs(A[i+1] - A[i-1]) - (Abs(A[i + 1] - A[i]) + Abs(A[i] - A[i-1])));
            }

            
        }


    }

}


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

typedef long double     lf;

using namespace std;

const lf EPS = 1e-9;

struct pt {
  lf x, y;
  pt( ) { }
  pt( lf x, lf y ) : x( x ), y ( y ) { }
};

inline lf x( pt P ) { return P.x; }
inline lf y( pt P ) { return P.y; }

istream& operator >> ( istream& in, pt& p ) {
  lf x,y; in >> x >> y;
  p = pt(x,y); return in;
}

ostream& operator << ( ostream& out, const pt& p ) {
  out << double(p.x) << " " << double(p.y);
  return out;
}

pt operator + ( const pt& A, const pt& B ) {
  return pt( x(A)+x(B), y(A)+y(B) );
}

pt operator - ( const pt& A, const pt& B ) {
  return pt( x(A)-x(B), y(A)-y(B) );
}


pt operator * ( const lf& B, const pt& A ) {
  return pt( x(A)*B, y(A)*B );
}

pt operator * ( const pt& A, const lf& B ) {
  return pt( x(A)*B, y(A)*B  );
}

inline lf dot( pt A, pt B ) {
  return x(A)*x(B) + y(A)*y(B);
}

inline lf norm( pt A ) {
  return x(A)*x(A) + y(A)*y(A);
}

inline lf abs( pt A ) {
  return sqrt( norm(A) );
}

inline lf dist ( pt A, pt B ) { return abs( B - A ); }

lf distToLine (pt p, pt A, pt B, pt &c) {
  lf u = dot( p-A , B-A ) / norm( B-A );
  c = A + u*( B-A );
  return dist( p , c );
}

pt refPoint(pt X, pt A, pt B) {
  pt aux; distToLine(X, A, B, aux);
  return X + lf(2.0)*(aux-X);
}

inline bool same ( lf a, lf b ) {
  return a+EPS > b && b+EPS > a;
}

inline lf cross( pt A, pt B ) {
  return x(A)*y(B) - y(A)*x(B);
}

///CHANGE
// 0  for collineal points ( angle = 0 )
// 1  for angle BAX counter clockwise
// -1 for angle BAX clockwise
inline int ccw (pt X, pt A, pt B) {
  lf c = cross( B-A, X-A );
  if( same( c, 0.0 ) ) { return 0; }
  if( c > EPS ) { return 1; }
  return -1;
}

///CHANGE
inline bool segContains ( pt X, pt A, pt B) {
  if ( !same ( 0, cross ( A-X, B-X ) ) ) return 0;
  return ( dot ( A-X, B-X ) < EPS );
}

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

inline bool parallel( pt A, pt B, pt C, pt D ) {
  return same ( 0, cross( B-A, D-C ) );
}

///NEW
inline bool ortho( pt A, pt B, pt C, pt D ) {
  return same ( 0, dot( B-A, D-C ) );
}

int n;

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

  cin >> n;
  for( int i = 0; i < n; ++i ) {
    pt A,B,C,D;
    cin >> A >> B >> C >> D;
    if( parallel( A, B, C, D ) ) {
      cout << "2\n";
    }
    else if( ortho( A, B, C, D ) ) {
      cout << "1\n";
    }
    else {
      cout << "0\n";
    }
  }
}

Measured memory_bytes: 3280
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e5+10;
typedef long long ll;
int a[N];
vector<int>q;
int main ()
{
    int n,c;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    cin>>c;
    a[i]=c*-1;
    }
    for(int i=1;i<=n;i++)
    {
        int pos=upper_bound(q.begin(),q.end(),a[i])-q.begin();
        if(pos==q.size())q.push_back(a[i]);
        else    q[pos]=a[i];
    }
    cout<<q.size()<<endl;
    return 0;
}

Measured memory_bytes: 4176
#include "bits/stdc++.h"
using namespace std;typedef long long lint;typedef vector<lint> liv;
//#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define linf 1152921504606846976
#define MAXN 100010
#define md 1000000007//998244353

#define pb push_back
#define _vcppunko4(tuple) _getname4 tuple
#define _getname4(_1,_2,_3,_4,name,...) name
#define _getname3(_1,_2,_3,name,...) name
#define _trep2(tuple) _rep2 tuple
#define _trep3(tuple) _rep3 tuple
#define _trep4(tuple) _rep4 tuple
#define _rep1(n) for(lint i=0;i<n;++i)
#define _rep2(i,n) for(lint i=0;i<n;++i)
#define _rep3(i,a,b) for(lint i=a;i<b;++i)
#define _rep4(i,a,b,c) for(lint i=a;i<b;i+=c)
#define _trrep2(tuple) _rrep2 tuple
#define _trrep3(tuple) _rrep3 tuple
#define _trrep4(tuple) _rrep4 tuple
#define _rrep1(n) for(lint i=n-1;i>=0;i--)
#define _rrep2(i,n) for(lint i=n-1;i>=0;i--)
#define _rrep3(i,a,b) for(lint i=b-1;i>=a;i--)
#define _rrep4(i,a,b,c) for(lint i=a+(b-a-1)/c*c;i>=a;i-=c)
template<class T>
istream& operator>>(istream& is,vector<T>& vec);
template<class T,size_t size>
istream& operator>>(istream& is,array<T,size>& vec);
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p);
template<class T>
ostream& operator<<(ostream& os,vector<T>& vec);
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p);
template<class T>
istream& operator>>(istream& is,vector<T>& vec){ for(T& x: vec) is>>x;return is; }
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p){ is>>p.first;is>>p.second;return is; }
//template<class T>
//ostream& operator<<(ostream& os,vector<T>& vec){ os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; }
//template<class T>
//ostream& operator<<(ostream& os,deque<T>& deq){ os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; }
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p){ os<<p.first<<" "<<p.second;return os; }

inline void in(){}
template <class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){ cin>>head;in(move(tail)...); }
template <class T>
inline bool out(T t){ cout<<t<<'\n';return 0; }
inline bool out(){ cout<<'\n';return 0; }
template <class Head,class... Tail>
inline bool out(Head head,Tail... tail){ cout<<head<<' ';out(move(tail)...);return 0; }

#define rep(...) _vcppunko4((__VA_ARGS__,_trep4,_trep3,_trep2,_rep1))((__VA_ARGS__))
#define rrep(...) _vcppunko4((__VA_ARGS__,_trrep4,_trrep3,_trrep2,_trrep1))((__VA_ARGS__))
#define lin(...) lint __VA_ARGS__;in(__VA_ARGS__)
#define stin(...) string __VA_ARGS__;in(__VA_ARGS__)
#define vin(type,name,size) vector<type> name(size);in(name)

int main(){
	lin(a,b,c);
	cout<<((a==b&&b==c)?"Yes":"No");
}

//int main(int argc,char *argv[]){
//	string inp;
//	if(argc>1)inp=argv[1];
//	else return 0;
//
//	ifstream fin(inp);
//	lint in_n;fin>>in_n;
//	fin.close();
//
//	lint a,b;cin>>a>>b;
//
//	return a+b!=in_n;
//}

//sub-EOF


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

constexpr int mod = 1000000007;

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

    vector<int> color(3, 0);
    ll ans = 1;
    rep(i, n)
    {
        int a;
        cin >> a;
        int val = 0;
        bool add = true;
        rep(j, 3)
        {
            if (color[j] == a)
            {
                if (add)
                {
                    add = false;
                    ++color[j];
                }
                ++val;
            }
        }
        ans *= val;
        ans %= mod;
    }

    cout << ans << endl;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    bool flag;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }
    return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

int main() {
    int n, a;
    cin >> n >> a;
    vector<int> x(n + 1);
    int mx = a;
    REP1(i, n) {
        cin >> x[i];
        chmax(mx, x[i]);
    }
    vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(n + 1, vector<ll>(n * mx + 1)));
    REP(i, n + 1) {
        dp[i][0][0] = 1;
    }
    REP1(i, n) {
        REP1(j, n) {
            REP(k, n * mx + 1) {
                if (k < x[i]) {
                    dp[i][j][k] = dp[i - 1][j][k];
                } else {
                    dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
                }
            }
        }
    }

    ll ans = 0;
    REP1(i, n) {
        ans += dp[n][i][i * a];
    }
    cout << ans << endl;
}


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

int main() {
	int b, r, g, c, s, t;
	
	while(1){
		cin >> b >> r >> g >> c >> s >> t;
		if(!b && !r && !g && !c && !s && !t)
			break;
		
		int total = t - s - r * 3 - b * 5;
		cout << 100 + (b + r) * 15 + b * 5 * 13 + r * 3 * 13 + g * 7 + c * 2 - total * 3 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int N;
	cin >> N;
	vector<string> W(N);
	rep(i, N) {
		cin >> W[i];
		if (i >= 1) {
			if (W[i][0] != W[i - 1][W[i - 1].size() - 1]) {
				cout << "No" << endl;
				return 0;
			}
		}
		rep(j, i) {
			if (W[j] == W[i]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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



int main(){
	int n;
	cin  >> n;
	vector<vector<pair<int,int> > > data(n);
	
	for(int i=0;i<n;++i){
		int m;
		cin >> m;
		vector<pair<int,int> > vm(m);
		for(int j=0;j<m;++j){
			cin >> vm[j].first >> vm[j].second;
			vm[j].first--;
		}
		data[i] = vm;
	}
	
	int res = 0;
	for(int i=0;i<pow(2,n);++i){
		bitset<15> bs(i);
		bool f = true;
		for(int j=0;j<n;++j){
			//cout << "--"<<j <<endl;
			if(bs[j]){
				for(int k=0;k<data[j].size();++k){
//					cout <<k<< "--"<<endl;
					int target = data[j][k].first;
					int tf = data[j][k].second;
//					cout << target <<" "<< bs[target] << " " << tf<<" "<<(bs[target] != tf)  <<endl;
					if(bs[target] != tf){
						f = false;
						break;
					}
				}
			}
		}
		//cout << bs << " " << f <<endl;
		if(f){
			res = max(res,(int)bs.count());
			//cout << bs <<" "<<bs.count()<<  endl;
		}
		
	}
	
	cout << res <<endl;
	
	return 0;
}


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

int main() {

    while(1){

        int n;

        cin >> n;

        if(n==0) break;

        for(int i=0;i<n;i++) {

            int x1, x2, i1, i2, j1, j2, k1, k2;

            cin >> x1 >> i1 >> j1 >> k1 >> x2 >> i2 >> j2 >> k2;

            int ax,ai,aj,ak;

            ax = x1*x2 - i1*i2 - j1*j2 - k1*k2;
            ai = x1*i2 + i1*x2 + j1*k2 - k1*j2;
            aj = x1*j2 - i1*k2 + j1*x2 + k1*i2;
            ak = x1*k2 + i1*j2 - j1*i2 + k1*x2;

            cout << ax << " " << ai << " " << aj << " " << ak << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
//datatypes
	#define int long long
	#define vi vector<int>
	#define si set<int>
	#define vii vector<ii>
	#define ii pair<int,int>
	#define mii map<int,int>
	#define M 1000000007
	#define pi 3.141592653589793
	#define in(x) int x; cin>>x;
	#define sz(x) (int)x.size()
	#define fr first
	#define sc second
	#define pb push_back
	#define mkp make_pair
	#define inputFile \
	    freopen("input.txt", "r", stdin); 
	#define outputFile \
	    freopen("output.txt", "w", stdout)
	#define rep(i,a,b) for(int i=a; i<b; i++)
	#define trav(a) for(auto &x:a)
	#define test cout<<"hello\n";
	#define all(x) (x).begin(),(x).end()
	#define mem0(x) memset(x, 0, sizeof(x))
	#define mem1(x) memset(x, -1, sizeof(x))
	#define sa(x) std::sort(all(x))
	#define sd(x) std::sort(all(x),greater<int>())
int a[100005];
vi dp;
int getto(int d)
{
	if(dp[d]!=-1)
		return dp[d];
	else return dp[d] = min(getto(d-2) + abs(a[d]-a[d-2]), getto(d-1) + abs(a[d]-a[d-1]));
}
signed solve()
{
	int n;
	cin>>n;
	dp.resize(n);
	
	for(int i=0; i<n; ++i){
		cin>>a[i];
		dp[i]=-1;
	}
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	cout<<getto(n-1);
	return 0;
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--) solve();
	//cout << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=998244353;
const long double PI=3.14159265358979;
const ll MAX=0;

ll DP[600020];

int main() {
  ll N,X,M;
  cin>>N>>X>>M;ll A[M];//ll sum[M];
  rep(i,M){
    A[i]=0;//Sum[i]=0;
  }
  ll p=1,ans=0;
  while(p<=N){
    if(A[X]!=0){
      break;
    }
    A[X]=p;ans+=X;
    X=X*X;X%=M;p++;
  }
  ll d=p-A[X];ll dsum=0;
  rep(i,d){
    dsum+=X;X*=X;X%=M;
  }
  N-=p;N++;ans+=N/d*dsum;ll m=N%d;
  rep(i,m){
    ans+=X;X*=X;X%=M;
  }
  cout<<ans;
  
  
}



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

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

    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j + i <= N; j++)
        {
            int a = i, b = j, c = N - i - j;
            if (a * 10000 + b * 5000 + c * 1000 == Y)
            {
                cout << a << ' ' << b << ' ' << c << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}


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

int main() {
  ll h, w;
  cin >> h >> w;
  if (h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }
  ll d = ((h + 1) / 2) * ((w + 1) / 2);
  ll c = (h / 2) * (w / 2);
  cout << d + c << endl;
  return 0;
}

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

public class Main{
	static int max = 10000000;
	static boolean[] isPrime = new boolean[max];
	public static void main(String[] args) {
		aryPrime();
		int[] cnt = new int[max];
		int k = 0;
		for(int i = 0; i < max; i++) {
			if(isPrime[i]) {
				k++;
			}
			cnt[i] = k;
		}
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			System.out.println(cnt[n]);
		}
		sc.close();
	}
	static void aryPrime(){
        int l = isPrime.length;
        Arrays.fill(isPrime, true);
        isPrime[0] = false;
        isPrime[1] = false;
        for(int i = 2; i <= (int)Math.sqrt(l); i++) {
            if(isPrime[i]) {
                for(int j = i * 2; j < l; j += i) {
                    isPrime[j] = false;
                }
            }
        }
    }
}


Measured memory_bytes: 75156
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        
        int M = Integer.MIN_VALUE;
        int m = Integer.MAX_VALUE;
        long sum = 0;
        
        for(int i=0; i<a; i++) {
            int p = sc.nextInt();
            M = Math.max(M, p);
            m = Math.min(m, p);
            sum += p;
        }
        
        System.out.printf("%d %d %d\n", m, M, sum);
    }
}



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

public class Main {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int h = scan.nextInt();
        int w = scan.nextInt();
        List<String> list = new ArrayList<String>();
        for(int i = 0; i < h; i++){
            String nextWord = scan.next();
            list.add(nextWord);
        }

        for(int i = 0; i < h; i++){
            System.out.println(list.get(i) + "\n" + list.get(i));
        }
    }
}

Measured memory_bytes: 22484
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        double tmp = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            tmp += (double)1/A[i];
        }
        System.out.print(1/tmp);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

Measured memory_bytes: 23508
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
	int min = 100000;

	int n, x;
	cin >> n >> x;

	int wei = x;
	for (int i = 0; i < n; i++) {
		int m;
		cin >> m;
		if (m < min) min = m;
		wei -= m;
	}
	cout << n + wei / min << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using cd = complex<ld>;

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

  int nv, ne;
  cin >> nv >> ne;
  vector<int> real(nv, 1);
  vector<int> red(nv, 0);
  red[0] = 1;
  while (ne-- > 0) {
    int u, v;
    cin >> v >> u;
    --u;
    --v;
    red[u] |= red[v];
    real[u]++;
    real[v]--;
    if (real[v] == 0) {
      red[v] = 0;
    }
  }
  cout << count(red.begin(), red.end(), 1);
  return 0;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;

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

    vector<int> hPl(H, 0);
    vector<int> wPl(W, 0);
    set<pii> st;

    for (int i = 0; i < M; i++)
    {
        int h, w;
        cin >> h >> w;
        h--; w--;

        hPl[h]++;
        wPl[w]++;
        st.insert({h,w});
    }
    

    int hmax = *max_element(hPl.begin(), hPl.end());
    int wmax = *max_element(wPl.begin(), wPl.end());

    vector<int> hmaxId, wmaxId;

    for (int i = 0; i < H; i++)
    {
        if(hPl[i] == hmax){
            hmaxId.push_back(i);
        }
    }

    for (int i = 0; i < W; i++)
    {
        if(wPl[i] == wmax){
            wmaxId.push_back(i);
        }
    }
    
    bool bombOverlap = true;

    int ans =  hmax + wmax;
    for (auto hid : hmaxId)
    {
        for (auto wid : wmaxId)
        {
            if(st.find({hid,wid}) == st.end()){
                bombOverlap = false;
                cout << ans << endl;
                return 0;
            }
        }
    }

    ans -= 1;

    cout << ans << endl;

    return 0;
}


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

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORTASC(c) sort((c).begin(), (c).end())
#define SORTDESC(c, t) sort((c).begin(), (c).end(), std::greater<t>());
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

const double PI = acos(-1.0);

using ll = long long;
using namespace std;

int main()
{
    string a[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;

    cin >> s;

    REP(i, 7){
        if (a[i] == s){
            cout << 7-i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace Template
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = inputs[0], d = inputs[1];

            var monitoringRange = 1 + d * 2;
            var answer = Math.Ceiling((double)n / monitoringRange);

            // 解答の出力
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13268
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    n = ni()
    a = na()

    cur = 1
    cnt = 0
    is_ok = False
    for aa in a:
        if aa == cur:
            is_ok = True
            cur += 1
        else:
            cnt += 1
    if is_ok:
        print(cnt)
    else:
        print(-1)
if __name__ == '__main__':
    main()

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

int main() {
  int n, num = 0;
  double sum = 0;
  cin >> n;
  vector<int> x(n), y(n), r(n);
  vector<double> l(n * n);
  for(int i = 0; i < n; i++)
    cin >> x.at(i) >> y.at(i);
  for(int i = 0; i < n; i++) {
    r.at(i) = i;
    for(int j = 0; j < n; j++) {
      if(i < j)
        l.at(i * n + j) = sqrt((x.at(i) - x.at(j)) * (x.at(i) - x.at(j)) +
                               (y.at(i) - y.at(j)) * (y.at(i) - y.at(j)));
      else if(i > j)
        l.at(i * n + j) = l.at(j * n + i);
    }
  }
  do {
    for(int i = 0; i < n - 1; i++)
      sum += l.at(r.at(i) * n + r.at(i + 1));
    num++;
  } while(next_permutation(r.begin(), r.end()));
  cout << setprecision(10) << sum / num << endl;
}

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

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<unsigned long long int>;

int main(void) {
    Int n;
    cin >> n;
    cout << 48 - n << endl;
    return 0;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int k;
  cin>>k;
  int a = k/2;
  cout<<(a*(k-a))<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,k;
    cin>>n>>k;
    if(k==1)
    {
        cout<<0;
        return 0;
    }
    int ans=n-k;
    cout<<ans;

} 



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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

int main(void){
  int hun=1,num=0;
  string a,b;
  cin>>a>>b;
  for(int i=b.size()-1;i>=0;i--){
    num+=(b.at(i)-'0')*hun;
    hun*=10;
  }
  for(int i=a.size()-1;i>=0;i--){
    num+=(a.at(i)-'0')*hun;
    hun*=10;
  }
  int square = sqrt(num);
  if(square*square==num)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;


return 0;}


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

namespace AtCoder.Abc171
{
    public class ModularCombinationFixedK
    {
        int k;
        long mod;
        long[] combination;

        public ModularCombinationFixedK(int maxN, int k, long mod)
        {
            combination = new long[maxN + 1];
            this.k = k;
            this.mod = mod;

            combination[k] = 1;
            for (int i = k; i < maxN; i++)
                combination[i + 1] = combination[i] * (i + 1) % mod * Inverse(i - k + 1) % mod;
        }

        public ModularCombinationFixedK(int n, long mod) : this(n, n, mod) { }

        public long Get(int n)
        {
            return combination[n];
        }

        long Inverse(long a)
        {
            long i = mod, v = 0, d = 1;
            while (a > 0)
            {
                long t = i / a, x = a;
                a = i % x;
                i = x;
                x = d;
                d = v - t * x;
                v = x;
            }
            v %= mod;
            if (v < 0) v = (v + mod) % mod;
            return v;
        }
    }

    class F
    {
        static readonly long mod = 1000000007;

        public static void Main()
        {
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            int n = k + s.Length;

            var comb = new ModularCombinationFixedK(n - 1, s.Length - 1, mod);
            long ans = 0;

            var pow26 = new long[k + 1];
            pow26[0] = 1;
            for (int i = 1; i <= k; i++)
                pow26[i] = (pow26[i - 1] * 26) % mod;

            long pow25 = 1;
            for (int i = 0; i <= k; i++)
            {
                ans = (ans + (comb.Get(s.Length - 1 + i) * pow25) % mod * pow26[k - i]) % mod;
                pow25 = pow25 * 25 % mod;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 47272
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


void f(int n){
  int a[100][100]={};
  rep(i,n){
    rep(j,5){
      cin>>a[n-1-i][j];
    }
  }
  ll ans = 0;
  bool flag = true;



  while(flag){
    
    flag = false;
    rep(i,n){
      rep(j,3){
        if(a[i][j]==0) continue;
        int b = a[i][j];
        int c = 0;
        FOR(k,j,6){
          if(b==a[i][k]) c++;
          else break;
        }
        if(c>=3){
          ans += c*b;
        
          while(b==a[i][j]){
            a[i][j]=0;
            j++;
            flag = true;
          
          }
        }
      }
    }
    rep(i,5){
      rep(j,n){
        if(a[j][i]==0){
          int k = j;
          while(a[k][i]==0&&k<n) k++;
          a[j][i] = a[k][i];
          a[k][i] = 0;
        }
      }
    }
  }

  cout<<ans<<endl;

}

int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0) break;
    f(n);
  }
}


Measured memory_bytes: 3104
#include <stdio.h>

int main(void) {
	int H, W;
	int h, w;

	while (1) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0) break;
		for (h = 1; h <= H; h++) {
			for (w = 1;w<=W; w++) {
				if (h==1 || h==H|| w == 1 || w == W) {
				printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, Q;
  string S;
  cin >> N >> S >> Q;
  vector<set<int>> se(26);
  for(int i = 0; i < N; i++){
    se.at(S.at(i) - 'a').insert(i);
  }

  vll ans(0);
  while(Q--){
    ll query;
    cin >> query;
    if(query == 1){
      ll ii;
      char cc;
      cin >> ii >> cc;
      ii--;
      if(S.at(ii) != cc){
        se.at(S.at(ii) - 'a').erase(ii);
        se.at(cc - 'a').insert(ii);
        S.at(ii) = cc;
      }
    }
    else{
      ll left, right;
      cin >> left >> right;
      left--; right--;
      int res = 0;
      for(int i = 0; i < 26; i++){
        auto ite = se.at(i).lower_bound(left);
        if(ite != se.at(i).end() && *ite <= right) res++;
      }
      cout << res << endl;
    }
  }
}

Measured memory_bytes: 24220
import sys
def input():
	return sys.stdin.readline()[:-1]

MOD = 998244353
class Rsum():
	def __init__(self, size):
		#the number of nodes is 2n-1
		self.n = 1
		while self.n < size:
			self.n *= 2
		self.node = [0] * (2*self.n-1)

	def Access(self, x):
		return self.node[x+self.n-1]

	def Add(self, x, val):
		x += self.n-1
		self.node[x] += val
		while x > 0:
			x = (x-1)//2
			self.node[x] = self.node[2*x+1] + self.node[2*x+2]
		return

	#[l, r)
	def Get(self, l, r):
		L, R = l+self.n, r+self.n
		s = 0
		while L<R:
			if R & 1:
				R -= 1
				s += self.node[R-1]
			if L & 1:
				s += self.node[L-1]
				L += 1
			L >>= 1
			R >>= 1
		return s

n = int(input())
d = []
for i in range(n):
	x, yy = map(int, input().split())
	d.append((x, yy, i))
y = [-1 for _ in range(n)]
d.sort(key=lambda x: x[1])
for i, x in enumerate(d):
	y[x[2]] = i

d.sort()
lus = [-1 for _ in range(n)]
lds = [-1 for _ in range(n)]
rus = [-1 for _ in range(n)]
rds = [-1 for _ in range(n)]

st = Rsum(n)
for i in range(n):
	pnt = y[d[i][2]]
	g = st.Get(pnt, n)
	lus[i] = g
	lds[i] = i - g
	st.Add(pnt, 1)

st = Rsum(n)
for i in range(n-1, -1, -1):
	pnt = y[d[i][2]]
	g = st.Get(pnt, n)
	rus[i] = g
	rds[i] = n-1-i - g
	st.Add(pnt, 1)

pws = [1]
for _ in range(n-1):
	pws.append((pws[-1] * 2) % MOD)

ans = (n * pws[n-1]) % MOD
for lu, ld, ru, rd in zip(lus, lds, rus, rds):
	ans += ((pws[lu]-1) * (pws[rd]-1))
	ans += ((pws[ld]-1) * (pws[ru]-1))
	ans += ((pws[lu]-1) * (pws[ld]-1) * (pws[ru]-1))
	ans += ((pws[lu]-1) * (pws[ld]-1) * (pws[rd]-1))
	ans += ((pws[lu]-1) * (pws[rd]-1) * (pws[ru]-1))
	ans += ((pws[ld]-1) * (pws[rd]-1) * (pws[ru]-1))
	ans += ((pws[lu]-1) * (pws[ld]-1) * (pws[ru]-1) * (pws[rd]-1))
	ans %= MOD
print(ans)

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S,T="CODEFESTIVAL2016"; cin >> S;
    int ans=0;
    for (int i=0;i<S.size();++i)
        if (S[i]!=T[i]) ++ans;
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define mod 998244353
using namespace std;

typedef unsigned long long ll;

ll comb[3 * 100005];
ll invcomb[3 * 100005];

ll pow_(ll x, ll n) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) ret = x * ret % mod;
        x = x * x % mod;
        n /= 2;
    }
    return ret;
}

int main() {
    ll N, A, B, K, n_A, n_B, count = 0, c_A, c_B;
    cin >> N >> A >> B >> K;
    comb[0] = 1; invcomb[0] = 1;
    for (int i = 0; i < N; i++) {
        comb[i + 1] = (i + 1) * comb[i] % mod;
        invcomb[i + 1] = invcomb[i] * pow_(i + 1, mod - 2) % mod;  
    }
    for (n_A = 0; n_A <= N; n_A++) {
        n_B = (K - A * n_A) / B;
        if (n_B <= N && A * n_A + B * n_B == K) {
            c_A = (((comb[N] * invcomb[n_A]) % mod) * invcomb[N - n_A]) % mod;
            c_B = (((comb[N] * invcomb[n_B]) % mod) * invcomb[N - n_B]) % mod;
            count += (c_A * c_B) % 998244353;
        }
    }
    cout << count % 998244353 << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = long long ;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    ll count = n/10;
    ll res = 0;
    if(n%2==1){
        cout << 0 << endl;
        return 0;
    }
    ll tmp = 10;
    res += n/10;
    n/=10;
    while(n!=0){
        res += n/5;
        n/=5;
    }
    cout << res << endl;
}

Measured memory_bytes: 384
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //int n = 4;
            //string[] numbers = { "2", "4", "6", "12" };

            int n = int.Parse(Console.ReadLine());
            string[] numbers = Console.ReadLine().Split(' ');

            int minConvert = 100;
            for (var i = 0; i < n; i++)
            {
                int curConvert = RepeatMod2(int.Parse(numbers[i]), 0);
                if (minConvert > curConvert) { minConvert = curConvert; }
            }
            if (minConvert == 100) { minConvert = 0; }

            Console.WriteLine(minConvert);
        }

        static int RepeatMod2(int argInt, int ConverCnt)
        {
            if (argInt == 0)
                return ConverCnt;

            if (argInt % 2 == 0)
            {
                argInt = argInt / 2;
                ConverCnt++;
                return RepeatMod2(argInt, ConverCnt);
            }
            else
            {
                return ConverCnt;
            }
        }
    }

}


Measured memory_bytes: 13140
N = int(input())
h = list(map(int, input().split()))
count = 0

if min(h) > 0:
    tmp = min(h)
    h = list(map(lambda x: x - tmp, h))
    count += tmp

while True:
    star = -1
    end = -1
    frag = False
    min_num = -1
    if min(h) == max(h):
        break

    for i in range(N):
        if h[i] > 0 and not frag:
            star = i
            frag = True
        if h[i] == 0 and frag:
            end = i
            break
    if end == -1:
        end = len(h)

    min_num = min(h[star:end])
    count += min_num
    for j in range(min_num):
        for i in range(star, end):
            h[i] -= 1

print(count)


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

int main() {

    long long int dp[34] = {0};

    dp[0] = 1;

    for(int i=0;i<31;i++){
        dp[i+1] += dp[i];
        dp[i+2] += dp[i];
        dp[i+3] += dp[i];
    }

    for(int i=0;i<31;i++){
        dp[i] = dp[i]/10;
    }

    while(1){

        int n;

        cin >> n;

        if(n==0) break;

        int ans = dp[n]%365==0 ? dp[n]/365 : dp[n]/365+1;
        
        if(ans==0) ans = 1;

        cout << ans << endl;

    }


    return 0;
}

Measured memory_bytes: 2992
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#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 Q;

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

  rep( q, Q ) {
    ll A, B;
    std::cin >> A >> B;

    if( A == B ) {
      std::cout << (A-1)*2 << endl;

      continue;
    }

    if( A > B )
      std::swap( A, B );

    ll ng = A, ok = 2*B;

    auto C = [&]( ll x ) {
      return (x+1)/2*(x/2+1) >= A*B;
    };

    while( ok-ng > 1 ) {
      ll mid = (ng+ok)>>1;

      (C(mid) ? ok : ng) = mid;
    }

    std::cout << ng-1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <limits.h>

int main(void) {
    long n, m, i, min = LONG_MIN, max = LONG_MAX;
    scanf("%ld%ld", &n, &m);
    long l[m], r[m];
    for ( i = 1; i <= m; i++ ) {
        scanf("%ld%ld", &l[i], &r[i]);
        if ( l[i] > min ) {
            min = l[i];
        }
        if ( r[i] < max ) {
            max = r[i];
        }
    }
    if ( max > min ) {
        printf("%ld\n", max - min + 1);
    }
    else if ( max == min ) {
        printf("1\n");
    }
    else {
        printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;cin>>N;
    int a[N];
    int sum=0;
    for(int i=0;i<N;i++){
        cin>>a[i];
        sum+=a[i];
    }
    
    int ans=0,ave=round(double(sum)/N);
    for(int i=0;i<N;i++){
        ans+=pow(a[i]-ave,2);
    }
    
    cout<<ans<<endl;
}


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

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

	vector<int> s(100000, 0);
	int64_t sum = 0;

	vector<int>a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		s[a[i]]++;
		sum += a[i];
	}

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

	for (int i = 0; i < q; i++)
	{

		s[c[i]] += s[b[i]];
		sum += (c[i] - b[i]) * s[b[i]];
		s[b[i]] = 0;

		cout << sum << endl;
	}

	return 0;
}


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

n = int(input())
a = [None]*n #x-y
b = [None]*n #x+y
for i in range(n):
    x, y = map(int, input().split())
    a[i] = x-y
    b[i] = x+y

print(max(max(a)-min(a), max(b)-min(b)))


Measured memory_bytes: 24704
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define endl "\n"
const long long mod=1e9+7;
const double pi=acos(-1);
const long long inf=1000000000000000005LL;

int n,k,arr[100100];
ll dp[110][100010];
bool hah[110][100010];
ll hitung(ll x,ll y){
	if(x==n)
		if(y==0)
			return 1;
		else
			return 0;
	if(hah[x][y])
		return dp[x][y];
	for(int i=0;i<=arr[x];i++)
		if(y>=i){
			dp[x][y]=dp[x][y]+hitung(x+1,y-i);
			dp[x][y]=dp[x][y]%mod;
		}
	hah[x][y]=true;
	return dp[x][y];
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>arr[i];
	for(int i=0;i<n;i++)
		dp[i][0]=1;
	for(int i=n-1;i>=0;i--){
		for(int j=1;j<=k;j++){
			if(i==n-1){
				if(j<=arr[i]){
					dp[i][j]=dp[i][j-1]+1;
				}else{
					dp[i][j]=dp[i][j-1];
				}
			}else{
				int h=j,l=max(0,j-arr[i]);
				dp[i][j]=dp[i][j-1]+((l==0)?dp[i+1][h]:dp[i+1][h]-dp[i+1][l-1]+mod);
				dp[i][j]=dp[i][j]%mod;
			}
		}
	}
	cout<<(dp[0][k]-dp[0][k-1]+mod)%mod<<endl;
}

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,c;
  cin>>n>>c;
  auto d=make_v<Int>(c,c);
  for(Int i=0;i<c;i++)
    for(Int j=0;j<c;j++)
      cin>>d[i][j];
  auto a=make_v<Int>(n,n);
  for(Int i=0;i<n;i++)
    for(Int j=0;j<n;j++)
      cin>>a[i][j];

  vector<vector<Int> > G(3);
  for(Int i=0;i<n;i++)
    for(Int j=0;j<n;j++)
      G[(i+j)%3].emplace_back(a[i][j]-1);

  auto dp=make_v<Int>(3,c);
  fill_v(dp,0);
  for(Int k=0;k<3;k++){
    for(Int i=0;i<c;i++){
      for(Int v:G[k]) dp[k][i]+=d[v][i];
    }
  }

  
  
  const Int INF = 1e15;
  Int ans=INF;
  for(Int i=0;i<c;i++){
    for(Int j=0;j<c;j++){
      for(Int k=0;k<c;k++){
	if(i==j||j==k||i==k) continue;
	Int res=dp[0][i]+dp[1][j]+dp[2][k];
	chmin(ans,res);
      }
    }
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4588
#include <iostream>
#include <algorithm>
using namespace std;
int N;
int high;
int low;
int COU;
int KU[4]={0};
int JKK(int a,int b);
int main(){
	while (1){
		COU=0;
		cin>>N;
		if (N==0) break;
		if (N%1111==0){
			cout<<"NA"<<endl;
			continue;
		}
		while(N!=6174){
			COU++;
			KU[0]=JKK(10,N);
			KU[1]=JKK(100,N);
			KU[2]=JKK(1000,N);
			KU[3]=N/1000;
			sort(KU,KU+4);
			high=KU[3]*1000+KU[2]*100+KU[1]*10+KU[0];
			low=KU[3]+KU[2]*10+KU[1]*100+KU[0]*1000;
			N=high-low;
		}
		cout<<COU<<endl;
		N=0;
		COU=0;
		
	}
	return 0;
}
int JKK(int a,int b){
	int r;
	r=b%a;
	if(a==100) r/=10;
	else if(a==1000) r/=100;
	return r;
}
	
	


Measured memory_bytes: 3160
//write for s26

#include<bits/stdc++.h>
using namespace std;
int main() {
	int h1,m1,h2,m2,k,t1,t2;
	cin>>h1>>m1>>h2>>m2>>k;
	t1=h1*60+m1;t2=h2*60+m2;
	if(t2-k<=0) {
		cout<<0<<endl;
		return 0;
	}
	int ram=t2-k;
	cout<<abs(ram-t1)<<endl;
	return 0;
}

Measured memory_bytes: 3636
X, N = map(int, input().split())
P = list(map(int, input().split()))
result = X
if N == 0:
    print(X)
    import sys
    sys.exit()

arr = [i for i in range(max(P)+2) if i not in P]
diff = [abs(i - X) for i in arr]

print(arr[diff.index(min(diff))])

Measured memory_bytes: 9204
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
def main():
	A = input()
	A_list = list(A)
	B = input()
	B_list = list(B)
	B_com = B_list + B_list
	l1 = len(A)
	l2 = len(A * 2)

	i = 0
	num = []
	for c in B_list:
		if A_list[0] == c:
			num.append(i)
			i += 1
		else:
			i += 1

	if len(num) == 0:
		print('No')
	else:
		for j in num:
			check = 0
			for k in range(l1):
				if A_list[k] == B_com[j + k]:
					check += 0
				else:
					check += 1
			if check == 0:
				print('Yes')
				break
			else:
				check = -1
		if check == -1:
			print('No')

 
if __name__ == '__main__':
	main()

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
vector<int> G[4];
int main() {
	for (int i = 0; i < 3; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int odd = 0;
	for (int i = 0; i < 4; i++) {
		if (G[i].size() % 2) odd++;
	}
	if (odd == 0 || odd == 2) cout << "YES" << endl;
	else cout << "NO" << endl;

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d; cin >> a >> b >> c >> d;
  int e = a+b-c-d;
  if(e>0)cout << "Left" << endl;
  else if(e<0)cout << "Right" << endl;
  else cout << "Balanced" << endl;
}

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

import sys
INT_MIN = sys.maxsize * -1
match = [-100,2,5,5,4,5,6,3,7,6]
CHOICES = []
for i in A:
    if (i == 6) and (9 in A):
        continue
    if (i == 3) and (5 in A):
        continue
    if (i == 2) and (3 in A or 5 in A):
        continue
    CHOICES.append([i, match[i]])
CHOICES.sort(reverse=True)

ans = [0]
#print(CHOICES)
for i in range(1,N+1):
    ans.append(INT_MIN)
    for c in CHOICES:
        #if  i - c[1] == 0:
        #    ans[i] = max(ans[i], int(str(c[0])))
        #elif i - c[1] >= 0 and ans[i - c[1]] != INT_MIN:
        #    ans[i] = max(ans[i], int(str(c[0]) + str(ans[i - c[1]])))

        if i - c[1] >= 0 and ans[i - c[1]] != INT_MIN:
            ans[i] = max(ans[i], c[0] + ans[i - c[1]] * 10)

print(ans[N])




Measured memory_bytes: 14820
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
ll to_int(string s){
  ll ans = 0,i;
  for(i=0;i<s.size();i++){
    if(s[i] == '.') continue;
    ans = ans*10+s[i]-'0';
  }
  return ans;
}
int main(){
  cin.tie(nullptr);ios::sync_with_stdio(false);
  ll N,a,i,j,k,l,two,five;string s;cin >> N;
  ll m[19][19];memset(m,0,sizeof(m));
  for(i=0;i<N;i++){
    cin >> s;
    if(s.find('.') == -1) two = five = 9;
    else two = five = 10-s.size()+s.find('.');
    a = to_int(s);
    while(a%2 == 0){
      two++;a /= 2;
    }
    while(a%5 == 0){
      five++;a /= 5;
    }
    two = min(two,18LL);
    five = min(five,18LL); 
    m[two][five]++;
  }
  ll ans = 0;
  for(i=0;i<19;i++){
    for(j=0;j<19;j++){
      for(k=0;k<19;k++){
        for(l=0;l<19;l++){
          if(i+k>=18 && j+l>=18){
            if(i==k && j==l) ans += m[i][j]*(m[k][l]-1);
            else ans += m[i][j]*m[k][l];
          }
        }
      }
    }
  }
  cout << ans/2 << "\n";
}

Measured memory_bytes: 3652
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b, c, d = rm()
if abs(a-c) <= d or abs(a-b) <= d and abs(b-c) <= d:
  print('Yes')
else:
  print('No')
















Measured memory_bytes: 27020