akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long

const int N = 100010;
const int moder = 1e9 + 7;

ll dp[2][N], pre[2][N], a[N], n, A, B;
std::map <ll, ll> Hash;

int main(){
	scanf("%lld%lld%lld", &n, &A, &B);
	for (int i = 1; i <= n; ++ i){
		scanf("%lld", &a[i]);
		Hash[- a[i]] = i;
	}
	dp[0][0] = dp[1][0] = pre[0][0] = pre[1][0] = 1;
	int now1 = 0, now2 = 0;
	for (int i = 2; i <= n; ++ i){
		auto u = Hash.lower_bound(B - a[i]);
		int sit = u == Hash.end() ? 0 : u -> second;
		if (sit == i - 1){
			-- sit;
		}
		dp[1][i - 1] = pre[0][sit];
		u = Hash.lower_bound(A - a[i]);
		sit = u == Hash.end() ? 0 : u -> second;
		if (sit == i - 1){
			-- sit;
		}
		dp[0][i - 1] = pre[1][sit];
		if (a[i] - a[i - 1] < A){
			for (int j = now1; j < i - 1; ++ j){
				dp[0][j] = pre[0][j] = 0;
			}
			now1 = i - 1;
		}
		if (a[i] - a[i - 1] < B){
			for (int j = now2; j < i - 1; ++ j){
				dp[1][j] = pre[1][j] = 0;
			}
			now2 = i - 1;
		}
		pre[1][i - 1] = (pre[1][i - 2] + dp[1][i - 1]) % moder;
		pre[0][i - 1] = (pre[0][i - 2] + dp[0][i - 1]) % moder;
	}
	ll ans = 0;
	for (int i = 0; i < n; ++ i){
		ans = (ans + dp[0][i] + dp[1][i]) % moder;
	}
	printf("%lld", ans);
	return 0;
}

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

int main(){
    ll n, k;
    cin>>n>>k;
    vector<int> h(n);
    rep(i,n){
        cin>>h[i];
    }
    sort(h.begin(), h.end());
    int nagasa;
    vector<int> ans(n-k+1);
    rep(i,n-k+1){
        nagasa= h[i+k-1]-h[i];
       ans[i]=nagasa;
    }
    sort(ans.begin(), ans.end());
    cout << ans.at(0) << endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
	
	public static void main(String[] args){
        Scanner sn = new Scanner(System.in);
		int K = 0;
        int X = 0;
        int zahyou_min = 0;
        int zahyou_max = 0;
        String ans ="" ;
        try{
            String str = sn.nextLine();
            String[] strlist = str.split(" ",0);
            K = Integer.parseInt(strlist[0]);
            X = Integer.parseInt(strlist[1]);
            sn.close();
            if(K<1 || K>100 || X <0 || X>100){
                return;
            }

            zahyou_min = X - (K-1);
            zahyou_max = X+(K-1);

            for(int i = 0; i<=2*K-2; i++){
                String tmp = String.valueOf(zahyou_min+i);
                ans = ans + (tmp+ " ");
            }
            
            System.out.println(ans);
        }catch(Exception e){
            //do nothing
            return;
        }
    }
}

Measured memory_bytes: 21204
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

int const maxn = 3005;

ll dp[3005][3005];

ll fw[3005][3005];

void upd(ll kind, ll i, ll add) {
	for (++i; i < maxn; i += -i & i) {
		fw[kind][i] += add;
		if (fw[kind][i] > mod) fw[kind][i] -= mod;
	}
}

ll get(ll kind, ll i) {
	ll ret = 0;
	for (++i; i > 0; i -= -i & i) {
		ret += fw[kind][i];
		if (ret > mod) ret -= mod;
	}
	return ret;
}

ll get(ll kind, ll i, ll j) {
	ll ret = get(kind, j) - get(kind, i - 1);
	ret %= mod; if (ret < 0) ret += mod;
	return ret;
}

ll p[maxn][maxn];

ll go(ll kind, ll i, ll j) {
	ll ret = p[kind][j] - p[kind][i - 1];
	ret %= mod; if (ret < 0) ret += mod;
	return ret;
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	string s; cin >> s;
	for (ll x = 1; x <= n; x++) {
		dp[0][x] = 1;
		//upd(0, x, 1);
	}
	for (ll i = 0; i < n - 1; i++) {
		for (ll x = 1; x <= n; x++) {
			p[i][x] = p[i][x - 1] + dp[i][x];
			if (p[i][x] > mod) p[i][x] -= mod;
		}
		if (s[i] == '<') {
			for (ll x = 1; x <= n - i - 1; x++) {
				//upd(i + 1, x, get(i, 1, x));
				dp[i + 1][x] += go(i, 1, x);
				if (dp[i + 1][x] > mod) dp[i + 1][x] -= mod;
				/*for (ll j = 1; j <= x; j++) {
					(dp[i + 1][x] += dp[i][j]) %= mod;
				}*/
				// dp[i+1][x] += dp[i][1] + ... + dp[i][x]
			}
		} else {
			for (ll x = 1; x <= n - i - 1; x++) {
				//upd(i + 1, x, get(i, x + 1, n - i));
				dp[i + 1][x] += go(i, x + 1, n - i);
				if (dp[i + 1][x] > mod) dp[i + 1][x] -= mod;
				/*for (ll j = x + 1; j <= n - i; j++) {
					(dp[i + 1][x] += dp[i][j]) %= mod;
				}*/
				// dp[i+1][x] += dp[i][x + 1] + ... + dp[i][n - i]
			}
		}
	}

	cout << dp[n - 1][1] << endl;
	//cout << get(n - 1, 1, 1) << endl;

	return 0;
}

/*
5
2 6 15 5 10

4
2 6 15 5

*/

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll dist(ll x, ll y) {
	if (x > y) return 0x3f3f3f3f3f3f3f3fll;
	return y - x;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	ll x, y; cin >> x >> y;
	ll ans = 0x3f3f3f3f3f3f3f3fll;
	ans = min(ans, dist(x, y));
	ans = min(ans, dist(-x, -y) + 2);
	ans = min(ans, dist(-x, y) + 1);
	ans = min(ans, dist(x, -y) + 1);
	
	cout << ans << endl;
}


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

using namespace std;

string str;

bool check(char l, char r){
  if(l == ' ' || r == ' ') return true;
  if(l == 'R' || r == 'L') return false;
  return true;
}

bool solve(int turn){
  char pre = ' ';
  char step[2] = {' ', ' '};
  for(int i=0;i<str.size();i++){
    if(pre == str[i]) return false;
    step[turn] = str[i];
    if(!check(step[0], step[1])) return false;
    turn = 1 - turn;
    pre = str[i];
  }
  return true;
}

main(){
  int tc;
  cin >> tc;
  while(tc--){
    cin >> str;
    cout << (solve(0) || solve(1) ? "Yes" : "No") << endl;
  }
}

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

#define ll long long
#define pb push_back
#define INF 1'000'000'007
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	string s1,s2;
	cin>>s1>>s2;
	ll m=s1.size(),n=s2.size();

	ll dp[m+1][n+1];
	rep(i,0,m+1){
		rep(j,0,n+1){
			if(i==0||j==0){
				dp[i][j]=0;
			}
			else if(s1[i-1]==s2[j-1]){
				dp[i][j]=1+dp[i-1][j-1];
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	ll i=m,j=n;
	string s="";
	while(i!=0&&j!=0){
		if(s1[i-1]==s2[j-1]){
			s+=s1[i-1];
			i--;
			j--;
		}
		else{
			if(dp[i-1][j]>dp[i][j-1]){
				i--;
			}
			else{
				j--;
			}
		}
	}
	reverse(s.begin(),s.end());
	cout<<s;

	
	
	
	return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N;
	cin >> N;
	vecl(A);
	vecl(B);
	fx(N) {
		vecpl(A);
	}
	fx(N) {
		vecpl(B);
	}

	if (A[N-1]!=B[0]) {
		ce(0)
		return 0;
	}

	ll ans = 1;
	fyg(N-1,1) {
		if (A[y-1]==A[y]&&B[y]==B[y+1]) {
			ans *= min(A[y],B[y]);
			ans %= MOD;
		}
	}
	fx(N-1) {
		if (A[x]!=A[x+1]) {
			if (x+2<N) {
				if (A[x+1]>B[x+2]&&B[x+1]!=A[x+1]) {
					ans = 0;
				}
			}
			else {
				if (B[x + 1] != A[x + 1]) {
					ans = 0;
				}
			}
		}
		if (B[x]!=B[x+1]) {
			if (x - 1 >= 0) {
				if (A[x - 1] < B[x] && B[x] != A[x]) {
					ans = 0;
				}
			}
			else {
				if (B[x] != A[x]) {
					ans = 0;
				}
			}
		}
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 2548
// D - String Equivalence
// DFS version
#include <bits/stdc++.h>
using namespace std;

int N;

void dfs(string pre){
	if(pre.size() >= N){ cout<< pre <<endl; return; }
	char mx = *max_element(pre.begin(), pre.end()) + 1;
	for(char c='a'; c<=mx; ++c) dfs(pre+c);
}

int main(){
	cin>>N;
	dfs("a");
}

Measured memory_bytes: 1536
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

//container util
//------------------------------------------
#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 SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
    string S;
    cin >> S;
    if(S[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }
    int c = 0;
    for(int i = 1; i < S.length(); i++) {
        if(S[i] != 'C' && !(S[i] >= 'a' && S[i] <= 'z')) {
            cout << "WA" << endl;
            return 0;
        }
        if(S[i] == 'C') {
            if(i >= 2 && i <= S.length() - 2)
                c++;
            else {
                cout << "WA" << endl;
                return 0;
            }
        }
    }
    if(c == 1) cout << "AC" << endl;
    else cout << "WA" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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 long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];

static const double pi = 3.141592653589793;
int main(){
   long long a;
   cin>>a;
   long long ret=1;
   vector<long long> vec(a);
   rep(i,a){
       cin>>vec.at(i);
   }
   sort(vec.begin(),vec.end());
   rep(i,a){
       if(ret>1000000007&&vec.at(i)>1000000007){
           ret=-1;
           break;
       }
    if(ret*vec.at(i)>1000000000000000000||ret<0){
            ret=-1;   
            break;
        }
   else{
         ret=ret*vec.at(i);
   }
   }
   cout<<ret<<endl;
}



Measured memory_bytes: 4000
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  double deg = 360 * abs((H / 12.0 + (M / (12.0 * 60.0))) - (M / 60.0));
  double rad = deg * M_PI / 180.0;
  double ans = sqrt(pow(A, 2.0) + pow(B, 2.0) - 2 * A * B * cos(rad));
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}

Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> b(n, 1e9);
    for (int i = 0; i < n-1; i++) cin >> b[i];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (!i) ans += b[i];
        else ans += min(b[i-1], b[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+1;
int n;
LL A[N],maks=2,mini=2;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&A[i]);
    }
    if(A[n]!=2){
        printf("-1\n");
        return 0;
    }
    for(int i=n-1;i>=1;i--){
        LL z=((LL)(maks+A[i+1]-(LL)1)/A[i])*A[i];
        maks=z;
        if(z==0){
            printf("-1");
            return 0;
        }
        if(mini%A[i]!=0){
            if(A[i]-(mini%A[i])<A[i+1]){
                mini+=(A[i]-((LL)mini%A[i]));
            }
            else
                mini=(LL)((LL)mini/A[i]+(LL)1)*A[i];
        }
        if(mini>maks){
            cout<<-1;
            return 0;
        }
     //   printf("Tajj %lld %lld\n",mini,maks);
    }
    maks+=((LL)A[1]-1);
    cout<<mini<<" "<<maks;
    return 0;
}


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

int main()
{
    // 入力
    string S,T;
    cin >> S >> T;
    
    // 判定
    // cout << S.length() << endl;
    // cout << T.substr(0,S.length()) << endl;
    // cout << T.length() << endl;
    // cout << T[S.length()] << endl;

    int ans = 0;
    if(S == T.substr(0,S.length())){
        if(T[S.length()] >= 'a' && T[S.length()] <= 'z'){
             cout << "Yes" << endl;
             return 0;
        }
    }

    // 出力
    cout << "No" << endl;
    
    // cin >> S;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#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, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
  
int main()
{
  int N, L;
  cin >> N >> L;

  vector<string> A(N);
  REP(i, N) cin >> A[i];

  sort(ALL(A));

  string B = "";

  REP(i,N){
    B = B + A.at(i);
  }
  
  cout << B << endl;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    ll N, K; cin>>N>>K;
    vec_int A(N), F(N);
    rep(i,N)cin>>A.at(i);
    rep(i,N)cin>>F.at(i);

    sort(A.begin(),A.end());
    sort(F.begin(),F.end());

    //よし、二分探索だ
    ll left = -1;
    ll right = pow(10,18); 

    while(right>left+1){
        ll comp = (left+right)/2;
//        cout<<right<<" "<<left<<" "<<comp<<endl;

        //compのスコアを達成できるかをチェックする
        ll used_K = 0;
        int flag = 0;
        rep(i,N){
            if(F.at(N-1-i)*A.at(i)>comp){
                used_K+=(F.at(N-1-i)*A.at(i)-comp)/F.at(N-1-i);
                if((F.at(N-1-i)*A.at(i)-comp)%F.at(N-1-i)!=0)used_K++;
            }
            if(used_K>K){
                flag=1;
                break;
            }
        }
        //flag=1の時にはスコアを達成できなかった
        if(flag==1){
            left = comp; 
        }else{
            right = comp;
        }
    }
    cout<<right<<endl;


    return 0;
}

Measured memory_bytes: 3328
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = tuple(map(int, input().split()))

    I = A.count(1)
    J = A.count(2)
    K = A.count(3)
    # for a in A:
    #     if a == 1:
    #         I += 1
    #     elif a == 2:
    #         J += 1
    #     else:
    #         K += 1

    dp = [[[0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)] 

    # def output(lst):
    #     for tmp in lst:
    #         print (tmp)

    for k in range(K + 1):
        for j in range(K + J + 1 - k):
            for i in range(N + 1 - k  - j):
                if i == j == k == 0:
                    continue
                tmp = N
                if i > 0:
                    tmp += i * dp[k][j][i - 1]
                if j > 0:
                    tmp += j * dp[k][j - 1][i + 1]
                if k > 0:
                    tmp += k * dp[k - 1][j + 1][i]
                dp[k][j][i] = tmp / (i + j + k)

    print (dp[K][J][I])

    # output(dp)

if __name__ == '__main__':
    main()

Measured memory_bytes: 505992
def main():
    input()
    t = list(map(int, input().split()))
    # if len(t) == 2:
    #     print(abs(t[0] - t[1]))
    #     exit()
    all = sum(t)
    left = t[0]
    right = all - t[0]
    ans = abs(left-right)
    for i in range(1, len(t)-1):
        left += t[i]
        if ans > abs(left-(all-left)):
            ans = abs(left-(all-left))
    print(ans)


if __name__ == '__main__':
    main()

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

#define ll long long int
#define mod 1000000007

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;


int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin>>s;
    if(s[0]=='7' || s[1]=='7' || s[2]=='7')cout<<"Yes\n";
    else cout<<"No\n";
    
}



Measured memory_bytes: 3652
n, d = map(int, input().split())
x = [list(map(int, input().split())) for item in range(n)]
cnt = 0
for i in range(len(x)):
    for j in range(i+1, len(x)):
        tmp = 0
        for k in range(d):
            tmp += (x[i][k] - x[j][k])**2
        if tmp ** 0.5 == int(tmp ** 0.5):
            cnt += 1
print(cnt)


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

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 100;

const ll inf = 1e18 + 100;

ll n, m;

vector<int> e[maxn];

bool vis[maxn];

ll od;

bool have[maxn], dob[maxn];

int color[maxn];

int sz[maxn];

int dfs(int v, int st){
    vis[v] = 1;
    int ret = 1;
    for (int i = 0; i < e[v].size(); i++)
        if (!vis[e[v][i]])
            color[e[v][i]] = color[v] ^ 1, ret += dfs(e[v][i], st);
        else
        if (color[e[v][i]] == color[v])
            dob[st] = 1;
    return ret;
}

int main()
{
    #ifdef ONPC
    ifstream cin("a.in");
    ofstream cout("a.out");
    #endif // ONPC
    ios::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        int v, u;
        cin >> v >> u;
        v--;
        u--;
        e[v].push_back(u);
        e[u].push_back(v);
    }
    for (int i = 0; i < n; i++)
    if (!vis[i]){
        sz[i] = dfs(i, i);
        have[i] = 1;
        if (sz[i] == 1)
            od++;
    }
    ll x = 0, y = 0;
    for (int i = 0; i < n; i++)
        if (sz[i] > 1)
            if (dob[i])
                y++;
            else
                x++;
    cout << od + od * (n - 1) * 2 - od * (od - 1) + 2 * x * x + 2 * x * y + y * y;
}


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

int arr[200000];

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

    for(int i=2;i<=n;i++)
    {
        arr[i]=1;
    }
    arr[1]=-1;


    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        if(arr[a]==0)
        {
            continue;
        }

        if(arr[a]<0)
        {
            arr[a]++;
            if(arr[b]<0)
                arr[b]--;
            else
                arr[b]=-1*(arr[b]+1);

        }

        if(arr[a]>0)
        {
            arr[a]--;
            if(arr[b]<0)
                arr[b]--;
            else
                arr[b]++;
        }

    }

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(arr[i]<0)
            cnt++;
    }
    cout<<cnt;
    return 0;
}


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

#define int long long int

int32_t main() {
    
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    
    if(k <= a){
        cout << min(k, a) << endl;
    }
    
    else if(k <= a + b){
        cout << a << endl;
    }
    
    else{
        cout << 2*(a) + b - k << endl;
    }
    
 	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>

#define llint long long int

int main(void){

  int n,m;
  std::cin >> n >> m;

  llint p[m], y[m];
  for(int i=0; i<m; i++){
    std::cin >> p[i] >> y[i];
  }

  std::vector<llint> years[n];
  for(int i=0; i<m; i++){
    years[p[i]-1].push_back(y[i]);
  }

  for(int i=0; i<n; i++){
    if(years[i].size() > 1){
      std::sort(years[i].begin(), years[i].end());
    }
  }

  for(int i=0; i<m; i++){
    std::vector<llint> &v = years[p[i]-1];
    int number = (std::lower_bound(v.begin(), v.end(), y[i]) - v.begin()) + 1;
    std::printf("%06lld%06d\n", p[i], number);
  }


  return 0;
}








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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

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

    int N; cin >> N;
    vvi D(N, vi(2));
    REP(i, N)
    {
        REP(j, 2) cin >> D[i][j];
    }

    for(int i = 1; i < N-1; i++)
    {
        bool ok = true;
        for(int j = -1; j <= 1; j++)
        {
            if(D[i+j][0] != D[i+j][1]) ok = false;
        }
        if(ok)
        {
            Yes;
            return 0;
        }
    }
    No;
}

Measured memory_bytes: 3656
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct stu
{
    int x,y;
};
stu vp[90005];
int k[90005];
int main()
{
    int h,w,d,num;
    scanf("%d %d %d",&h,&w,&d);
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            scanf("%d",&num);
            vp[num].x=i;
            vp[num].y=j;
        }
    }
    for(int i=d+1;i<=h*w;i++)
    {
        k[i]=k[i-d]+abs(vp[i].x-vp[i-d].x)+abs(vp[i].y-vp[i-d].y);
    }
     int q;
     scanf("%d",&q);
     for(int i=0;i<q;i++)
     {
         int x,y;
         scanf("%d %d",&x,&y);
         printf("%d",abs(k[y]-k[x]));

         if(i!=q-1)
            printf("\n");
     }

}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

int main(){
   int s,w;
   cin>>s>>w;
   (s<=w)? cout<<"unsafe":cout<<"safe"<<endl;
return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    string S; cin >> S;
    REP(i, S.length()-1)
    {
        if(S[i] == S[i+1])
        {
            cout << "Bad" << endl;
            return;
        }
    }
    cout << "Good" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    let a = nextIntArray()
    let b = nextIntArray()
    let ans = 0
    for(let i = 0; i<a.length-1; i++){
        if(a[i] >= b[i]){
            ans += b[i]
        } else if(a[i+1] + a[i] >= b[i]) {
            ans += b[i]
            a[i+1] = a[i+1]-b[i]+a[i]
        } else {
            ans += a[i] + a[i+1]
            a[i+1] = 0
        }
    }
    console.log(ans)
}
Main()



Measured memory_bytes: 50896
import sys
from collections import deque
input = sys.stdin.readline

def main():
    h, w, k = map(int, input().split())
    sx, sy, gx, gy = map(int, input().split())

    c = [input() for i in range(h)]

    not_yet = deque([(sx-1, sy-1)])
    dist = [[-1]*w for i in range(h)]
    dist[sx-1][sy-1] = 0
    already = [[False]*w for i in range(h)]
    already[sx-1][sy-1] = True

    while not_yet:
        x, y = not_yet.popleft()
        d = dist[x][y]

        for i in range(x+1, x+k+1):
            if i >= h or c[i][y] == "@":
                break
            if already[i][y] and dist[i][y] < d + 1:
                break
            if already[i][y] and dist[i][y] == d + 1:
                continue
            dist[i][y] = d + 1
            already[i][y] = True
            not_yet.append((i, y))

        for i in range(x-1, x-k-1, -1):
            if i < 0 or c[i][y] == "@":
                break
            if already[i][y] and dist[i][y] < d + 1:
                break
            if already[i][y] and dist[i][y] == d + 1:
                continue
            dist[i][y] = d + 1
            already[i][y] = True
            not_yet.append((i, y))
        
        for i in range(y+1, y+k+1):
            if i >= w or c[x][i] == "@":
                break
            if already[x][i] and dist[x][i] < d + 1:
                break
            if already[x][i] and dist[x][i] == d + 1:
                continue
            dist[x][i] = d + 1
            already[x][i] = True
            not_yet.append((x, i))

        for i in range(y-1, y-k-1, -1):
            if i < 0 or c[x][i] == "@":
                break
            if already[x][i] and dist[x][i] < d + 1:
                break
            if already[x][i] and dist[x][i] == d + 1:
                continue
            dist[x][i] = d + 1
            already[x][i] = True
            not_yet.append((x, i))

    ans = dist[gx-1][gy-1]
    print(ans)

    
if __name__ == "__main__":
    main()



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

using namespace std;
int plas(int N){
	if(N<0)	return N*-1;
	return N;
}

int main(){
	int N,M;
	int a[200002];
	int b[200002];
	cin >> N >> M;
	for(int i=1;i<M+1;i++){
		cin >> a[i] >> b[i];
	}
	bool Flag[200002]={};
	for(int i=0;i<M+1;i++){
		if(b[i]==N){
			Flag[a[i]]=1;
		}
	}
	string ans="IMPOSSIBLE";
	for(int i=0;i<M+1;i++){
		if(a[i]==1 && Flag[b[i]]==1){
			ans = "POSSIBLE";
		}
	}
	cout << ans;
	return 0;
}


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

int main(){
  int x,y,s;
  int nx,ny;

  while(1){
    int MAX=0;
    cin >> x >> y >> s;
    if(!x && !y && !s)break;

    for(double i=1;i<s/2+1;++i){
      double j=s-i+0.99999999999999;
      double k=i+0.99999999999999;
      nx=k*100/(100+x);
      ny=j*100/(100+x);
      if((nx*(100+x)/100+ny*(100+x)/100)!=s)continue;
      // cout << "nx "<< nx <<"ny " << ny <<endl;
      // cout << "nx "<< nx*(100+y)/100 <<"ny " << ny*(100+y)/100 <<((int)nx*(100+y)/100+(int)ny*(100+y)/100) <<endl;
      MAX=max(MAX,(nx*(100+y)/100+ny*(100+y)/100));
    }
    cout << MAX <<endl;
  }
}

Measured memory_bytes: 3052
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
// #include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int maxn = 2e5;
LL d[maxn], v[maxn], w[maxn];

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	LL n, W;
	cin >> n >> W;
	for(int i = 0; i < n; ++i){
		cin >> w[i] >> v[i];
	}
	for(int i = 0; i < n; ++i){
		for(int j = W; j >= 0; --j){
			if(w[i] <= j){
				d[j] = max(d[j], d[j - w[i]] + v[i]);
			}
		}
	}
	cout << d[W] << endl;
	return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>

#define max(a,b)	(a>b?a:b)

int main(){
	int A,B;
	int ans=0;
	
	scanf("%d %d",&A,&B);
	
	ans+=max(A,B);
	A>B?A--:B--;
	ans+=max(A,B);
	
	printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long ret = 0;
  long long minv = 9e18;
  for (int i = 0; i < n; i++){
    cin >> a[i];
    minv = min(minv, a[i]);
  }
  for (int i = 0; i < n; i++) {
    long long tmp = (a[i] - minv) / (n + 1);
    ret += tmp;
    a[i] -= tmp * (n + 1);
  }
  for (int i = 0; i < n; i++) a[i] += ret;
  minv += ret;
  long long d = minv - (n - 1);
  if (d > 0) {
    for (int i = 0; i < n; i++) a[i] -= d;
    ret += d * n;
    minv -= d;
  }
  int maxv = 0;
  int maxi;
  for (int i = 0; i < n; i++) {
    if (maxv < a[i]) {
      maxv = a[i];
      maxi = i;
    }
  }
  while (maxv >= n) {
    for (int i = 0; i < n; i++) a[i]++;
    ret++;
    a[maxi] -= (n + 1);
    maxv = 0;
    for (int i = 0; i < n; i++) {
      if (maxv < a[i]) {
        maxv = a[i];
        maxi = i;
      }
    }
  }
  cout << ret << '\n';
  return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(1,n-1):
  if (p[i] > p[i-1]) and (p[i] < p[i+1]): cnt += 1
  if (p[i] < p[i-1]) and (p[i] > p[i+1]): cnt += 1
print(cnt)

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

const ll MOD = 1e9+7;
const int MAX = 1e5+7;

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

	int n, k; cin >> n >> k;
	vector<ll> v(n); FOR(i, n) cin >> v[i];

	sort(all(v));

	ll ans = 1;

	if(v[n-1] <= 0 && (k%2)){
		FOR(i, k){
			ans = ans * v[n-i-1] % MOD;
			if(ans < 0) ans += MOD;
		}
	}else{
		int l = 0, r = n-1;
		if(k%2){
			ans = ans * v[r] % MOD;
			if(ans < 0) ans += MOD;
			r--;
			k--; 
		}
		ll a1, a2;
		while(k > 0){
			a1 = v[l] * v[l+1];
			a2 = v[r] * v[r-1];

			if(a1 > a2){
				a1 %= MOD;
				ans = ans * a1 % MOD;
				l+=2;
			}else{
				a2 %= MOD;
				ans = ans * a2 % MOD;
				r-=2;
			}

			k-=2;
		}
	}

	if(ans < 0) ans += MOD;
	
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 4736
n, m = map(int, input().split())
ll = 0
rr = n
for _ in range(m):
    l, r = map(int, input().split())
    ll = max(ll, l)
    rr = min(rr, r)

if ll <= rr:
    print(rr-ll+1)
else:
    print(0)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int t[] = new int[N + 1];
        int x[] = new int[N + 1];
        int y[] = new int[N + 1];
        boolean ans = true;
        int time = 0;
        t[0] = 0;
        x[0] = 0;
        y[0] = 0;
        for (int i = 1; N + 1 > i; i++) {
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        for (int j = 1; N + 1 > j; j++) {
            time = Math.abs(t[j] - t[j - 1]);
            if (time < Math.abs(x[j] - x[j - 1]) + Math.abs(y[j] - y[j - 1])) {
                ans = false;
                break;
            }
            if (time == x[j] + y[j]) {
                continue;
            } else if (time % 2 == 0 && (Math.abs(x[j] - x[j - 1]) + Math.abs(y[j] - y[j - 1])) % 2 == 0) {
                continue;
            } else if (time % 2 != 0 && (Math.abs(x[j] - x[j - 1]) + Math.abs(y[j] - y[j - 1])) % 2 != 0) {
                continue;
            } else {
                ans = false;
                break;
            }
        }
        if (ans == true) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 94664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, a, b; cin >> k >> a >> b;
    bool ok = false;
    rep (i, a, b + 1) if (i % k == 0) ok = true;
    cout << (ok ? "OK\n" : "NG\n");
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);


int main(){

	IOS

	ll n,k;
	cin>>n>>k;
	map<ll,ll> mp;
	while(k--){
		ll d;
		cin>>d;
		ll tmp;
		fo(i,d){
			cin>>tmp;
			mp[tmp]++;
		}


	}
	ll cnt=0;
	FOR(i,1,n){
		if(!mp.count(i)) cnt++;
	}
	
	cout<<cnt<<endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> arr1(N), arr2(N);
    int x, y;
    for (int i = 0; i < N; i++) {
        cin >> x >> y;
        arr1[i] = x + y;
        arr2[i] = x - y;
    }
    sort(arr1.begin(), arr1.end());
    sort(arr2.begin(), arr2.end());
    cout << max(arr1[N - 1] - arr1[0], arr2[N - 1] - arr2[0]) << endl;
}

Measured memory_bytes: 4848
import sys
def main():
    input = sys.stdin.readline
    H,W=map(int, input().split())
    A=[list(input().rstrip()) for _ in range(H)]
    from itertools import chain
    from collections import Counter
    C=Counter(chain.from_iterable(A))
    t4=[(v//4)*4 for v in C.values()]
    t2=[(v//2)*2 for v in C.values()]
    if sum(t4) >= (H-(H&1))*(W-(W&1)):
        if sum(t2) >= H*W-(H&W&1):
            print('Yes')
            return
    print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38896
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;
typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef map<int, int> M;
typedef pair<int, int> P;

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

    string s;
    cin >> s;
    LL sum = 0;
    for (int i = 0; i < (1 << (s.size() - 1)); ++i)
    {
        LL n = 0;
        for (int j = 0; j < s.size();  ++j)
        {
            n += s[j] - '0';
            if (j == (s.size()-1)) {
                sum += n;
            } else if (i & (1 << j)) {
                sum += n;
                n = 0;
            } else {
                n *= 10;
            }
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int K;
    cin >> K;

    int64_t ans = 0;
    for(int a=1; a<=K; a++) {
        for(int b=1; b<=K; b++) {
            for(int c=1; c<=K; c++) {
                ans += gcd(a, gcd(b, c));
            }
        }
    }

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


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

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

    int n=0;
    cin >> n;

    int *order = new int[n];

    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        order[a-1] = i+1;
    }

    
    for(int i=0; i<n; i++){
        cout << order[i];
        if(i+1!=n)
            cout << " ";
    }
    cout << endl;

    delete[] order;

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    if((s[0]==s.back()&&s.size()%2==0)||(s[0]!=s.back()&&s.size()%2)) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 89;
	ll M; scanf("%lld", &M); 
	while (kkt) {
		ll sum = 0;
		vector<ll> t(4); for (int i = 0; i < 4; i++) scanf("%lld", &t[i]);
		sum += t[0] * 10 + t[1] * 50 + t[2] * 100 + t[3] * 500;
		sum -= M;
		vector<ll> res(4);
		res[3] = sum / 500;
		sum %= 500;
		res[2] = sum / 100;
		sum %= 100;
		res[1] = sum / 50;
		sum %= 50;
		res[0] = sum / 10;
		if (t[0] - res[0] > 0) {
			cout << "10 " << t[0] - res[0] << "\n";
		}
		if (t[1] - res[1] > 0) {
			cout << "50 " << t[1] - res[1] << "\n";
		}
		if (t[2] - res[2] > 0) {
			cout << "100 " << t[2] - res[2] << "\n";
		}
		if (t[3] - res[3] > 0) {
			cout << "500 " << t[3] - res[3] << "\n";
		}
	    scanf("%lld",&M); if(M==0) break;
		puts("");
	}
	return 0;

}


Measured memory_bytes: 3148
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int n = input<int>();
    vector<pair<int, int>> segs;

    int longest = 0;
    for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        segs.emplace_back(l, -r);

        longest = max(longest, r - l + 1);
    }

    sort(ALL(segs));

    vector<pair<int, int>> res;
    for (auto& elem: segs) {
        elem.second = -elem.second;

        while (not res.empty() and elem.second <= res.back().second)
            res.pop_back();

        res.push_back(elem);
    }

    int64_t ans = 0;
    ans = max(0, -res.back().first + res[0].second + 1) + longest;
    for (int spl = 1; spl < SZ(res); ++spl) {
        int64_t x = max(0, -res[spl - 1].first + res[0].second + 1) +
            max(0, -res[SZ(res) - 1].first + res[spl].second + 1);

        ans = max(ans, x);
    }

    cout << ans << "\n";
    

    return 0;
}


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


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


void solve() {
	int n; cin >> n;
	int o = (n + 1) / 2;
	double p = (float)o / n;
	cout << setprecision(10) << p << endl;
}

int main() {


	solve();


	return 0;
}

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

using namespace std;

int main(){
	int a[5];
	for(int i = 0; i < 5; i++){
		cin >> a[i];	
	}
	int f;
	cin >> f;
	if(a[4] - a[0] > f){
		puts(":(");
		return 0;
	}
	puts("Yay!");
}

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

template<class T,class U> void chmax(T& a, U b) {if(a<b)a=b;}
template<class T,class U> void chmin(T& a ,U b) {if(b<a)a=b;}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    vvi dp(101010, vi(3, 0));

    int n,k,r,s,p;
    cin >> n>>k>>r>>s>>p;
    string t;
    cin >> t;

    auto winp = [&](char me, char enemy) {
        if (me == 'r' and enemy == 's') return r;
        if (me == 's' and enemy == 'p') return s;
        if (me == 'p' and enemy == 'r') return p;
        return 0;
    };

    vector<int> used(101010);
    
    rep(i, k) {
        dp[i][0] = winp('r', t[i]);
        dp[i][1] = winp('s', t[i]);
        dp[i][2] = winp('p', t[i]);
        for (int j = i + k; j < n; j += k) {
            dp[j][0] = max(dp[j - k][1], dp[j - k][2]) + winp('r', t[j]);
            dp[j][1] = max(dp[j - k][0], dp[j - k][2]) + winp('s', t[j]);
            dp[j][2] = max(dp[j - k][0], dp[j - k][1]) + winp('p', t[j]);
        }
    }

    ll ans = 0;
    rep(i, k) {
        int j = n - 1 - i;
        ans += *max_element(all(dp[j]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6400