akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;

const int MAX_N=110,MAX_H=1e5+10;

int N,M;
int H[MAX_N],MP[MAX_N],T[MAX_N],D[MAX_N];

void solve(){
    vector<int> dp0(MAX_H,INF),dp1(MAX_H,INF);
    dp0[0]=dp1[0]=0;
    for (int i=0;i<MAX_H;++i){
        for (int j=0;j<M;++j){
            if (!T[j]){
                int nxt=min(MAX_H-1,i+D[j]);
                dp0[nxt]=min(dp0[nxt],dp0[i]+MP[j]);
            } else {
                int nxt=min(MAX_H-1,i+D[j]);
                dp1[nxt]=min(dp1[nxt],dp1[i]+MP[j]);
            }
        }
    }
    for (int i=MAX_H-2;i>=0;--i){
        dp0[i]=min(dp0[i],dp0[i+1]);
        dp1[i]=min(dp1[i],dp1[i+1]);
    }
    int ans=INF;
    for (int i=0;i<MAX_H;++i){
        int sum=dp1[i];
        for (int j=0;j<N;++j){
            sum+=dp0[max(0,H[j]-i)];
            if (ans<sum) break;
        }
        ans=min(ans,sum);
    }
    cout << ans << '\n';
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N,N){
        for (int i=0;i<N;++i) cin >> H[i];
        cin >> M;
        for (int i=0;i<M;++i){
            string S,Tar; cin >> S >> MP[i] >> Tar >> D[i];
            T[i]=(Tar=="All");
        }
        solve();
    }
}


Measured memory_bytes: 3628
n = int(input())
p =list(map(int,input().split()))
ans = 0

if p[-1] == n:
    a = p[-2]
    b = p[-1]
    
    p[-2] = b
    p[-1] = a
    
    ans += 1

for i in range(n-1):
    if i == p[i]-1:
        a = p[i]
        b = p[i+1]
        
        p[i] = b
        p[i+1] = a
        
        ans += 1
        
print(ans)

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

using namespace std;

int main(void) {
	int N;
	string A, B, C;
	cin >> N;
	cin >> A >> B >> C;
	int result = 0;
	for(int i = 0; i < N; ++i) {
		if(A[i] == B[i] && B[i] == C[i]) {
			continue;
		}
		if(A[i] != B[i] && B[i] != C[i] && C[i] != A[i]) {
			result += 2;
			continue;
		}
		++result;
	}
	cout << result << '\n';
	return 0;
}



Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.range;

alias Point = Tuple!(int, "x", int, "y", int, "p");

int N;
Point[100] RS, BS;
int[][200] GS;

void main()
{
    N = readln.chomp.to!int;
    foreach (i; 0..N) {
        auto ab = readln.split.to!(int[]);
        RS[i] = Point(ab[0], ab[1], 0);
    }
    foreach (i; 0..N) {
        auto cd = readln.split.to!(int[]);
        BS[i] = Point(cd[0], cd[1], 0);
    }

    foreach (int i, r; RS[0..N]) {
        foreach (int j, b; BS[0..N]) {
            if (r.x < b.x && r.y < b.y) {
                GS[i] ~= 100+j;
                GS[100+j] ~= i;
            }
        }
    }

    int res;
    int[200] match = -1;
    foreach (i; 0..200) {
        if (match[i] < 0) {
            bool[200] used;
            bool search(int p) {
                used[p] = true;
                foreach (g; GS[p]) {
                    auto s = match[g];
                    if (s < 0 || !used[s] && search(s)) {
                        match[p] = g;
                        match[g] = p;
                        return true;
                    }
                }
                return false;
            }
            if (search(i)) ++res;
        }
    }
    writeln(res);
}

Measured memory_bytes: 380
#include <iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string>
#include <map>
using namespace std;

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

	map<string, int> mp;
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		mp[s]++;
	}
	
	int mx = 0;
	for (auto p : mp) mx = max(mx, p.second);
	for (auto p : mp) {
		if (p.second != mx)continue;
		cout << p.first << endl;
	}

	return 0;
}

Measured memory_bytes: 25216
n = int(input())
x = input().split()

min = 2**20

for p in range(100):
    min_i = 0
    if p in x:
        continue
    for i in x:
        min_i = min_i + (int(i) - p)**2
    if min_i <= min:
        min = min_i
print(min)

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

int main() {
    int n, m;
    cin >> n >> m;
    string a[50], b[50];
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    bool f = true;
    
    if (n == m) {
        rep(x, n) {
            rep(y, n) {
                if (a[y][x] != b[y][x]) {
                    f = false;
                }
            }
        }
        
        if (f) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    else {
        rep(ax, n - m) {
            rep(ay, n - m) {
                f = true;
                
                rep(bx, m) {
                    rep(by, m) {
                        if (a[ay + by][ax + bx] != b[by][bx]) {
                            f = false;
                        }
                    }
                }
                
                if (f) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    
    cout << "No" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

signed main(void)
{
  int r, c, n;
  cin >> r >> c >> n;
  vector<PII> v;
  REP(i, n) {
    int x[2], y[2];
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    if((x[0] == 0 || x[0] == r || y[0] == 0 || y[0] == c) && (x[1] == 0 || x[1] == r || y[1] == 0 || y[1] == c)) REP(j, 2) {
      if(x[j] == 0 || y[j] == c) v.PB(MP(x[j]+y[j], i));
      else v.PB(MP(2*r+2*c-x[j]-y[j], i));
    }
  }
  sort(ALL(v));
  stack<int> st;
  REP(i, v.size()) {
    if(st.empty() || st.top() != v[i].second) st.push(v[i].second);
    else st.pop();
  }

  if(st.empty()) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 2548
n = int(input())
s = input()
can = []
for cut in range(n):
  p = []
  for i in range(cut+1):
    now = s[i]
    if now in p:
      pass
    else:
      p.append(now)
  pp = []
  for i in range(cut+1,n):
    now = s[i]
    if now in p:
      if now in pp:
        pass
      else:
        pp.append(now)
    else:
      pass
  can.append(len(pp))
print(max(can))

Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 200000000000;
struct edge {int to,cost;};
typedef std::pair<int,int> P;

    int N;
    int A[100010];
    int X,Y,Z;
    int ans=0;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){
        cin>>A[i];
        if(A[i]%4==0)X++;
        else if(A[i]%2==0)Y++;
        else Z++;
    }

    if(Z+(Y%2)-1<=X)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
    	ll val=(int)((double)i*(double)1.08);
    	//cout<<val<<endl;
    	if(val==n)
    	{
    		cout<<i<<endl;
    		return 0;
    	}
    }
    cout<<":("<<endl;
    return 0;
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<int>> dat(11, vector<int>(11));
    rep(i, 10)
    {
        rep(j, 10)
        {
            cin >> dat[i][j];
        }
    }
    rep(k, 10)
    {
        rep(i, 10)
        {
            rep(j, 10)
            {
                dat[i][j] = min(dat[i][j], dat[i][k] + dat[k][j]);
            }
        }
    }
    int ans = 0;
    rep(i, h)
    {
        rep(j, w)
        {
            int a;
            cin >> a;
            if (a == -1)
                continue;
            ans += dat[a][1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
#define ljc 998244353
using namespace std;
#define gc getchar
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
ll A,B,n,dp[2][5050],P[5050];
inline void chkmin(ll &a,const ll &b){if (a>b) a=b;}
signed main(){
	n=read(),A=read(),B=read();
	for (int i=1;i<=n;i++) P[i]=read();
	bool cur=0;
	memset(dp[cur],0x3f,sizeof dp[cur]);
	ll inf=dp[0][0];
	dp[0][0]=0;
	for (int i=1;i<=n;i++){
		cur^=1;
		memset(dp[cur],0x3f,sizeof dp[cur]);
		for (int j=0;j<=n;j++){
			chkmin(dp[cur][j],dp[cur^1][j]+A*(P[i]>j)+B*(P[i]<j));
			if (P[i]>j) chkmin(dp[cur][P[i]],dp[cur^1][j]);
		}
	}
	ll _=inf;
	for (int i=0;i<=n;i++) chkmin(_,dp[cur][i]);
	cout<<_;
	return 0;
}



Measured memory_bytes: 3708
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e15;
using namespace std;
typedef long long ll;
int main() {
  ll n;
  string s;
  cin >> n >> s;
  REP(i, s.length()) {
    s[i] = 'A' + (s[i] - 'A' + n) % 26;
    cout << s[i];
  }
  return 0;
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7
n = int(input())

a_sum = 0
sq_sum = 0
for a in map(int, input().split()):
  a_sum = (a_sum + a) % mod
  sq_sum = (sq_sum + a * a) % mod
res = (a_sum * a_sum - sq_sum) % mod
print(-(mod // 2) % mod * res % mod)

Measured memory_bytes: 25144
/*
https://www.luogu.org/problem/AT2168
Author: Yu-343
*/

#include <cstdio>

int main (void) {
	int h, w;
	scanf ("%d %d", &h, &w);
    int cnt = 0;
	for (int i = 1; i <= h; ++i) {
		getchar ();
		for (int j = 1; j <= w; ++j) {
			char ch = getchar ();
			if (ch == '#') ++cnt;
		}
	}
	puts ((cnt == h + w - 1) ? "Possible" : "Impossible");
	return 0;
}

Measured memory_bytes: 128
#include <cstring>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;

long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

const int M = 998244353;

int main() {
    int n; cin >> n;
    pair<int, int> p[n]; for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
    sort(p, p+n, [](pair<int, int> &x, pair<int, int> &y) {
            return x.second < y.second;
        });
    for (int i = 0; i < n; i++) p[i].second = i+1;
    sort(p, p+n);
    int L[n+2], R[n+2];
    memset(L, 0, sizeof(L));
    memset(R, 0, sizeof(R));
    for (int i = 0; i < n; i++)
        for (int j = p[i].second; j <= n; j += j&-j) R[j]++;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        int a, b = 0, c, d = 0, y = p[i].second;
        for (int j = y; j > 0; j -= j&-j) b += L[j], d += R[j];
        d--;
        a = i - b; c = n-i-1-d;
        ans += modexp(2, n, M) - (modexp(2, a, M) + modexp(2, d, M) - 1) * (modexp(2, b, M) + modexp(2, c, M) - 1) % M;
        ans %= M;
        for (int j = y; j <= n; j += j&-j) L[j]++, R[j]--;
    }
    cout << (ans % M + M) % M << endl;
}


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

using ll=long long; 

void solve(){
	string s;
	cin>>s;
	int a=stoi(s.substr(0,2));
	int b=stoi(s.substr(2,2));
	if((a>12 || a<1) && (b>12 || b<1)){
		cout<<"NA"<<endl;
	}
	else if(a<=12 &&a>=1 && b<=12 && b>=1){
		cout<<"AMBIGUOUS"<<endl;
	}
	else if(a<=12 && a>=1){
		cout<<"MMYY"<<endl;
	}
	else{
		cout<<"YYMM"<<endl;
	}
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct mint{
	ll x;
	mint(ll x=0):x((x%mod+mod)%mod){}
	friend ostream &operator<<(ostream& os,const mint& a){
		return os<<a.x;
	}
	friend istream &operator>>(istream& is,mint& a){
		ll t;
		is>>t;
		a=mint(t);
		return (is);
	}
	mint& operator+=(const mint a){
		if((x+=a.x)>=mod) x-=mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x+=mod-a.x)>=mod)x-=mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x*=a.x)%=mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if (!t) return 1;
		mint a=pow(t>>1);
		a*=a;
		if(t&1) a*=*this;
		return a;
	}
	// for prime mod
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this)*=a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
};

struct combination{
  vector<mint> fact,ifact;
  combination(int n):fact(n+1),ifact(n+1){
	assert(n<mod);
	fact[0]=1;
	for(int i=1;i<=n;i++) fact[i]=fact[i-1]*i;
	ifact[n]=fact[n].inv();
	for(int i=n;i>=1;i--) ifact[i-1]=ifact[i]*i;
  }
  mint operator()(int n,int k){
	if (k<0 || k>n) return 0;
	return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	mint ans=0;
	FOR(i,k,n+2){
		mint cnt1=i*(i-1)/2;
		mint cnt2=i*(2*n-i+1)/2;
		ans+=cnt2-cnt1+1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define NIL -1
#define MAX 1000

static const int N = 100000;

int main()
{
    int n;
    cin >> n;
    
    int h[n], c[n];
    rep(i, n) cin >> h[i];

    c[0] = 0;
    c[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; ++i){
        c[i] = min(c[i-2] + abs(h[i] - h[i-2]), c[i-1] + abs(h[i] - h[i-1]));
    }

    cout << c[n-1] << endl;

    return 0;
}

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

class AtCoder {
  public static void Main() {
    var inputs = Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToList();
    var H = inputs[0];
    var N = inputs[1];
    var A = Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray();
    Console.WriteLine(A.Sum() >= H ? "Yes" : "No");
  }
}

Measured memory_bytes: 20192
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin >> a;
  int ans=0;
  if(a[0]=='1'){
    ans++;
  }
  if(a[1]=='1'){
    ans++;
  }
    if(a[2]=='1'){
      ans++;
    }
    cout << ans << endl;
  }


Measured memory_bytes: 256
using System;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] a = { int.Parse(input[0]), int.Parse(input[1]), int.Parse(input[2]) };
            Array.Sort(a);
            Console.WriteLine(a[0] + " " + a[1] + " " + a[2]);
        }
    }
}

Measured memory_bytes: 9156
#include <iostream>
using namespace	std;
int main(){
  int n,m,p;
  while(cin >> n >> m >> p && n){
    int	x[100];
    int a=0,d,ans;//all,dividend,answer;                                        
    for(int i=0;i<n;i++){
      cin >> x[i];
      a+=x[i];
    }   
    d=a*100*(100-p)/100;
    if(x[m-1]==0)
      ans = 0;
    else
      ans=d/x[m-1];
    cout << ans << endl;
  }
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

bool vis[60], g[60][60];
vector<int> G[60];
int a[60], b[60];

void dfs(int u)
{
    if(vis[u])
        return;
    vis[u] = true;

    for(auto i: G[u]){
        if(g[u][i])
            dfs(i);
    }
}

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


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

        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
        G[a[i]].Pb(b[i]);
        G[b[i]].Pb(a[i]);
    }

    int ans = 0;
    for(int i = 0; i < m; i++){
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;

        mem(vis, false);
        int cnt = 0;
        for(int j = 1; j <= n; j++)
            if(!vis[j])
                cnt++, dfs(j);

        g[a[i]][b[i]] = g[b[i]][a[i]] = true;

        if(cnt > 1)
            ans++;
    }

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


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

int main() {
	
	int n,i;
	cin>>n;
	int arr[n],dp[n];
	for(i=0;i<n;i++)
	cin>>arr[i];
	dp[0]=0;
	
	for(i=1;i<n;i++)
	{
	    if(i!=1)
    	    dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	    else
    	    dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
	}
	cout<<dp[n-1]<<endl;
	
	return 0;
}

Measured memory_bytes: 4380
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
typedef long long ll;
int n,k,a[N];
ll ans;
int main()
{
    scanf("%d%d",&k,&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),k-=a[i];
    if(k<=0) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 640
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> P;
typedef pair<ll,pair<ll,ll>> p;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
static const int MAX_SIZE = 1 << 17; //segment tree のサイズ。この実装では2べきにする必要がある。 2^17 ≒ 1.3 * 10^5

int C[30];

int main(){
    int N;
    ll A,B,C,D,mi,pl;
    cin>>N>>A>>B>>C>>D;
    A-=B;
    N--;
    for(int i=0;i<=N;i++){
        pl=D*(N-i)+(-C)*i;
        mi=C*(N-i)+(-D)*i;
        //cout<<i<<" "<<mi<<" "<<pl<<endl;
        if(A>=mi && A<=pl){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}



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

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

int main(void) {
    int n, a;
    double ans = 0.0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    REP(i, n) {
        cin >> a;
        ans += 1.0 / (double) a;
    }

    cout << fixed << setprecision(10) << 1.0 / ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
   public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
     int num1 = scan.nextInt();
     int num2 = scan.nextInt();
     int answer;
     
     if( num1 >= 10 || num2 >= 10 )
       answer = -1;
     else 
       answer = num1 * num2;
     
     System.out.println(answer);
   }
}

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

signed main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int t, ans = 0;
  t = min(a, k);
  ans += t; k -= t;
  t = min(b, k);
  k -= t;
  t = min(c, k);
  ans += -t; k -= t;
  cout << ans << endl;
}


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

typedef int32_t i32;
typedef int64_t i64;

#define MIN(a,b) ((a)<(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

#define POS(i, j) (((i) & 1) * (k + 2) + MIN((j), k + 1))

void run (void) {
  i32 n, k;
  scanf ("%" SCNi32 "%" SCNi32, &n, &k);
  i64 *dp = ALLOC (2 * (k + 1 + 1), i64);
  dp[POS(0, k)] = 1;
  const i32 mod = 1000000007;
  for (i32 i = 1; i <= n; ++i) {
    i32 a;
    scanf ("%" SCNi32, &a);
    for (i32 j = k; j >= 0; --j) {
      dp[POS(i, j)] = (dp[POS(i - 1, j)] + dp[POS(i, j + 1)] + mod - dp[POS(i - 1, j + a + 1)]) % mod;
    }
  }
  printf ("%" PRIi64 "\n", dp[POS(n, 0)]);
}

int main (void) {
  run();
  return 0;
}


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

#define PB          push_back
#define PF          push_front
#define MP          make_pair
#define FI          first
#define SE          second
#define SIZE( A )   int( ( A ).size( ) )
#define ALL( A )    ( A ).begin( ), ( A ).end( )
#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )

using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lf;
typedef pair< int, int >    pii;
typedef pair< ll, ll >      pll;
typedef vector< bool >      vb;
typedef vector< lf >        vd;
typedef vector< ll >        vll;
typedef vector< int >       vi;
typedef vector< pii >       vpii;

const int MAXN = int( 1e5 )+10;
const int MOD  = int( 1e9 )+7;
const int oo   = INT_MAX;

int a, b, c, d;

int main( ) {

  #ifdef LOCAL
    freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
  #else
    //freopen( ".in", "r", stdin );
    //freopen( ".out", "w", stdout );
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );
  #endif

  while( cin >> a >> b >> c >> d ) {
    int mn = max( a, c );
    int mx = min( b, d );
    cout << max( 0, mx-mn ) << '\n';
  }

  return 0;
}

Measured memory_bytes: 256
#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 = 0,M = 0;
  cin >> N >> M;
  map <ll,ll> mp;
  rep(i,2*M){
    ll a = 0;
    cin >> a;
    mp[a]++;
  }
  for(ll i = 1; i <= N; i++){
    cout << mp[i] << endl;
  }
}

Measured memory_bytes: 3608
S=io.read()
t={}
for i=1,#S-2 do
  t[i]=tonumber(string.sub(S,i,i+2))-753
    if t[i]<0 then 
      t[i]=-t[i]
    end
end
min=t[1]
for i=2,#S-2 do 
  if min>t[i] then
    min=t[i]
  end
end
print(min)

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

int main() {
	int K, S; cin >> K >> S;
	int cnt1 = 0,cnt2=0,cnt3=0;
	for (int i = 0; i <= K; i++)
	{
		for (int j = i; j <= K; j++)
		{
			for (int k = j; k <= K; k++)
			{
				if (i + j + k == S && i == j && j == k)cnt1++;
				else if (i + j + k == S && i != j && j != k && i != k)cnt3++;
				else if (i + j + k == S)cnt2++;
			}
		}
	}
	cout << cnt1 + cnt2 * 3+cnt3*6 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }


int main() {
 int n;
  cin>>n;
  vin w(n);
  rep(i,n) cin>>w[i];
  //////
  int sum=0;
  rep(i,n) sum+=w[i];
  int ans=inf;
  rep(i,n){
   int cnt=0; 
    rep(j,i+1){
      cnt+=w[j];
    }
  //  cout<<cnt<<endl;
    cnt=abs(2*cnt-sum);
    
    ans=min(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353
#define ft first
#define se second
#define pp pair<ll,ll>
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

ll a[100010];

bool check_product(long long a,long long b,long long c)
{
	double prod=a;
	prod*=b;
	if (prod>2*c)
		return true;
	return a*b>c;
}

void solve(){
	ll n;cin>>n;
	ll ans = 1;
	ll x = 1ll;
	f(i,18) x = x*10;
	int f = 1;
	int z = 0;
	f(i,n){
		cin>>a[i];
		if(a[i] == 0) z=1;
	}
	if(z){
		cout<<"0"<<endl;
		return;
	}
	sort(a,a+n);
	f(i,n){
		if(check_product(ans, a[i], x)){
			f=0;
			break;
		}
		ans = ans * a[i];
	}
	ll y = ans - x;
	if(f==0 || y > 0){
		cout<<"-1"<<endl;
		return;
	}
	cout<<ans<<endl;
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 4428
#include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int main(){
	int digit[10][7] = {{0,1,1,1,1,1,1}, {0,0,0,0,1,1,0}, {1,0,1,1,0,1,1}, {1,0,0,1,1,1,1},
	{1,1,0,0,1,1,0}, {1,1,0,1,1,0,1}, {1,1,1,1,1,0,1}, {0,1,0,0,1,1,1}, {1,1,1,1,1,1,1}, {1,1,0,1,1,1,1}};
	int n, a;
	while(cin >> n) {
		if(n==-1) break;
		int x[7] = {0,0,0,0,0,0,0};
		rep(i,n) {
			cin >> a;
			rep(j,7) {
				int y = digit[a][j]^x[j];
				cout << y;
			}
			cout << endl;
			rep(j,7) x[j] = digit[a][j];
		}
	}
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

const double PI = acos(-1);

int main(void) {
  int N, M;
  cin >> N >> M;
  REP(i, M) {
    int v;
    cin >> v;
    N -= v;
  }
  printf("%d\n", N >= 0 ? N : -1);
  return 0;
}


Measured memory_bytes: 3256
/*
    B - Digital Gifts
    https://atcoder.jp/contests/abc119/tasks/abc119_b
*/
#include <bits/stdc++.h>
using namespace std;

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

    int n;
    cin >> n;
    double sum = 0.0;
    for (int i = 0; i < n; i++) {
        string val, kind;
        cin >> val >> kind;

        if (kind == "JPY") {
            sum += stod(val);
        } else {
            sum += stod(val) * 380000.0;
        }
    }

    cout << fixed;
    cout << setprecision(10) << sum << endl;
}

Measured memory_bytes: 256
r = 0
while r == 0:
        i = map(str,raw_input().split())
        i[0] = int(i[0])
        i[2] = int(i[2])
        if i[1] == "+":
                print i[0]+i[2]
        elif i[1] == "-":
                print i[0]-i[2]
        elif i[1] == "*":
                print i[0]*i[2]
        elif i[1] == "/":
                print i[0]/i[2]
        elif i[1] == "?":
                break
        else:
                print "error"

Measured memory_bytes: 4244
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int c[3][3];
    int i,j;
    for(i = 0;i < 3;++i){
        for(j = 0;j < 3;++j){
            cin >> c[i][j];
        }
    }
    int temp;
    temp = c[0][1]-c[0][0];
    if(temp != c[1][1] -c[1][0]){
        cout << "No" << endl;
        return 0;
    }
    if(temp != c[2][1] -c[2][0]){
        cout << "No" << endl;
        return 0;
    }
    temp = c[0][2]-c[0][1];
    if(temp != c[1][2] -c[1][1]){
        cout << "No" << endl;
        return 0;
    }
    if(temp != c[2][2] -c[2][1]){
        cout << "No" << endl;
        return 0;
    }
    temp = c[0][0]-c[1][0];
    if(temp != c[0][1] -c[1][1]){
        cout << "No" << endl;
        return 0;
    }
    if(temp != c[0][2] -c[1][2]){
        cout << "No" << endl;
        return 0;
    }
    temp = c[1][0]-c[2][0];
    if(temp != c[1][1] -c[2][1]){
        cout << "No" << endl;
        return 0;
    }
    if(temp != c[1][2] -c[2][2]){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

int cnt = 0;
string s;

int main(){
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        cnt += (s[i] == '+') ? 1 : -1;
    }
    cout << cnt;
}


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    ll N, A, B; cin >> N >> A >> B;
    ll H[N]; rep(i, N) cin >> H[i];
    int ng = -1, ok = pow(10, 9);
    int m = (ng+ok)/2;
    while(abs(ng-ok) > 1){
        ll cnt = 0;
        ll mB = m*B;
        ll dif_AB = A-B;
        rep(i, N){
            //各魔物の残りHPはH[i]-m*B
            //(H[i]-m*B) / (A-B) or +1回の爆発を必要とする
            ll rem_hp = max(0ll, H[i]-mB);
            if(rem_hp % dif_AB == 0) cnt += rem_hp / dif_AB;
            else cnt += rem_hp / dif_AB + 1;
        }
        if(cnt > m) ng = m;
        else ok = m;
        m = (ng+ok)/2;

    }
    cout << ok << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 1024
#include<stdio.h>
#define L 100
#define WT 0
#define GR 1
#define BK 2

int n,M[L][L];
int cr[L],d[L],f[L],tl;


void DFSv(int);
void DFS(void);


int main(){
  int u,v,k,i,j;

  scanf("%d",&n);
  for(i = 0;i<n;i++){
    for(j = 0;j<n;j++)M[i][j] = 0;
  }

  for(i = 0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j =0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }

  }

  DFS();

  return 0;
}

void DFS(){
  int a;

  for(a =0;a<n;a++) cr[a] = WT;
  tl = 0;
  for(a= 0;a<n;a++){
    if(cr[a]==WT)DFSv(a);
  }
  for(a =0;a<n;a++){
    printf("%d %d %d\n",a+1,d[a],f[a]);
  }
}


void DFSv(int b){
  int a;
  cr[b] = GR;
  d[b] = ++tl;
  for(a = 0;a<n;a++){
    if(M[b][a]==0) continue;
    if(cr[a]== WT){
      DFSv(a);
    }


  }
  cr[b] = BK;
  f[b] = ++tl;
}




Measured memory_bytes: 2032
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a+n, greater<ll>());
    ll f = 0, s = 0;
    bool ok = true;
    vector<ll> c(n, 0);
    for(ll i = 0; i < n-1; i++){
        bool ok = true;
        //cout << i << endl;
        if(a[i]==a[i+1] && c[i]==0 && f==0){
            f = a[i];
            c[i] = 1; c[i+1] = 1;
        }
        if(a[i]==a[i+1] && c[i]==0 && f!=0){
            s = a[i];
            c[i] = 1; c[i+1] = 1;
        }
        if(s!=0)
            break;
    }
    cout << f*s << endl;
    return 0;
}


Measured memory_bytes: 1792
import Data.Ord

main = interact $ put . sol . get

get = fmap read . words

put GT = "Alice"
put LT = "Bob"
put EQ = "Draw"

sol :: [Int] -> Ordering
sol [1,1] = EQ
sol [1,_] = GT
sol [_,1] = LT
sol [a,b] = compare a b


Measured memory_bytes: 508
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll M, d[212345], c[212345];

int main() {

	scanf("%lld", &M);
	rep(i, M) scanf("%lld%lld", &d[i], &c[i]);

	pair<ll, ll> counts[10];
	rep(n, 10) {
		int t = n;
		int b = 1, a = 1;
		do {
			b++;
			a++;
			t += n;
			if (t > 9) {
				t = t % 10 + 1;
				a++;
			}
		} while (t != n);
		if (n) counts[n] = { b, a - 1 };
		else counts[n] = { 2, 1 };
	}

	ll ans = 0;
	rep(i, M) {
		if (c[i] % (counts[d[i]].first - 1)) {
			ans += counts[d[i]].second * (c[i] / (counts[d[i]].first - 1));
			c[i] %= counts[d[i]].first - 1;
		}
		else {
			ans += counts[d[i]].second * (c[i] / (counts[d[i]].first - 1) - 1);
			c[i] = counts[d[i]].first - 1;

		}
	}

	vector<ll> last;
	rep(i, M) {
		rep(t, c[i]) last.push_back(d[i]);
	}

	int t = 0;
	for (auto l : last) {
		t += l;
		ans++;
		if (t > 9) {
			t = t % 10 + 1;
			ans++;
		}
	}

	printf("%lld\n", ans - 1);

	return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.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; }

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n, a, b;
	cin >> n >> a >> b;

	ll ans = 0;
	for(int i = 1; i <= n; i++){
		int sum = 0;
		int n = i;
		while(n != 0){
			sum += (n % 10);
			n /= 10;
		}
		if(sum >= a && sum <= b){
			ans += i;
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main() {
    int64_t n;
    cin >> n;
    vector<int64_t> a(n);
    for(int i = 0;i < n;i++) {
        cin >> a.at(i);
    }
    int64_t g = euclidean_gcd(a.at(0),a.at(1));
    for(int i = 2;i < n;i++) {
      g = euclidean_gcd(g,a.at(i));
    }
    cout << g << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#define N 200000

int main(){
  int i, j, n, max, min, A[N];
  scanf("%d", &n);
  for(i = 0; i < n; i++){
  scanf("%d", &A[i]);
  }

  min = A[0];
  max = A[1] - A[0];
  for(i = 1; i < n; i++){
    if(max < A[i] - min) max = A[i] - min;
    if(min > A[i]) min = A[i];
  }
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int GCD(int x,int y){
  if(x<y){
    swap(x,y);
  }
  while(x%y!=0){
    int temp=x;
    x=y;
    y=temp%y;
  }
  return y;
}

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

int main() {
  int n;
  cin>>n;
  ll x[n],y[n];
  ll maxs[4],mins[4];
  for(int i=0;i<4;i++){
    maxs[i]=-1e18;
    mins[i]=1e18;
  }
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
    maxs[0]=max(maxs[0],x[i]+y[i]);
    maxs[1]=max(maxs[1],x[i]-y[i]);
    maxs[2]=max(maxs[2],-x[i]+y[i]);
    maxs[3]=max(maxs[3],-x[i]-y[i]);
    mins[0]=min(mins[0],x[i]+y[i]);
    mins[1]=min(mins[1],x[i]-y[i]);
    mins[2]=min(mins[2],-x[i]+y[i]);
    mins[3]=min(mins[3],-x[i]-y[i]);
  }
  ll ans=maxs[0]-mins[0];
  for(int i=1;i<=3;i++){
    ans=max(ans,maxs[i]-mins[i]);
  }
  cout<<ans<<endl;
  return 0;
}

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

bool check(stack<char>&st){
	stack<bool> s;
	int len=st.size();
	if(st.empty()) return true;
	for(int i=0 ; i<len;++i){
		if(st.top()==')'){
			s.push(true);
			st.pop();
		} else if(st.top()==']'){
			s.push(false);
			st.pop();
		} else if(st.top()=='('){
			if(s.empty()) return false;
			if(s.top()==false) return false;
			s.pop();
			st.pop();
		} else if(st.top()=='['){
			if(s.empty()) return false;
			if(s.top()==true) return false;
			s.pop();
			st.pop();
		}
	}
	if (!s.empty()) return false;
	return true;
}

int main(){
	string s;
	stack<char> st;
	while(1){
		getline(cin , s);
		if (s==".") break;
		for(int i=0;i<s.length();++i){
			if(s[i]=='(') st.push('(');
			if(s[i]=='[') st.push('[');
			if(s[i]==')') st.push(')');
			if(s[i]==']') st.push(']');
			if(s[i]=='.') break;
		}
		if(check(st)){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
			for(int i=0;!st.empty();++i){
				st.pop();
			}
		}
		s.erase();
	}
	return 0; 
}

Measured memory_bytes: 1180
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(string S){
    vector<bool> used(26, false);
    char a;
    if (S.size() == 26) {
        int n = S.size();
        a = S.back();
        for (int i = 0; i < n; i++) {
            if (S.back() < a) {
                char c = S.back();
                S.pop_back();
                for (int i = c-'a'; i <= 'z'-'a'; i++) {
                    if (used[i]) {
                        S.push_back('a'+i);
                        std::cout << S << std::endl;
                        return;
                    }
                }
            } else if (S.back() >= a) {
                a = S.back();
                used[a - 'a'] = true;
                S.pop_back();
            }
        }
        std::cout << -1 << std::endl;
        return;
    } else {
        for (auto c : S) {
            used[c - 'a'] = true;
        }
        for (int i = 0; i < 26; i++) {
            if (!used[i]) {
                S.push_back('a' + i);
                std::cout << S << std::endl;
                return;
            }
        }
    }

}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    string S;
    cin >> S;
    solve(S);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


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

#define pb push_back
#define fr first
#define sc second
typedef pair<int,int> pii;
typedef vector<int> vi;
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
  int n;
  int a,b,c;
  cin>> n;
  for(int i=0;i<n;i++){
    cin>> a>> b>> c;
    if(c*c == a*a+b*b || b*b == c*c+a*a || a*a == b*b+c*c){
      cout<< "YES"<< endl;
    }else{
      cout<< "NO"<< endl;
    }
  }
} 

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  long long int a=1,in;
  cin>>in;
  rep(i,30){
    a*=3;
    if(a>=in){
      cout<<i+1<<endl;
      return 0;
    }

  }


}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Integer>[] list = new List[m];
        int[] pArr = new int[m];


        for (int i = 0; i < m; i++) {
            list[i] = new ArrayList<Integer>();
            int k = sc.nextInt();
            for (int j = 0; j < k; j++) {
                list[i].add(sc.nextInt());
            }
        }
        for (int i = 0; i < m; i++) {
            pArr[i] = sc.nextInt();
        }


        int count = 0;
        String format = "%0" + n + "d";
//        debug(format);
        for (int i = 0; i < Math.pow(2, n); i++) {
            String bin = String.format(format, Integer.parseInt(Integer.toBinaryString(i)));
//            debug(bin);
            boolean isValid = true;
            for (int j = 0; j < m; j++) {
                int sum = 0;
//                debug(list[j]);
                for (int k : list[j]) {
                    sum += bin.charAt(k - 1) == '1' ? 1 : 0;
                }
                if (sum % 2 != pArr[j]) isValid = false;
            }
            if (isValid) count++;
        }
        System.out.println(count);


//        System.out.println(sum / (n * Math.pow(2, indexMax)));
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


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

int main()
{
  string s;
  vector<bool> a(26, false);
  bool flag = false;

  cin >> s;
  for (int i = 0; i < s.size(); i++)
  {
    if (a[s[i] - 'a'])
      flag = true;
    else
      a[s[i] - 'a'] = true;
  }
  cout << (flag ? "no" : "yes") << endl;
}

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long b[n + 1], c[n + 1];
  b[0] = c[0] = 0;
  for (int i = 0; i < n; i++) {
    b[i + 1] = b[i] + a[i];
    c[i + 1] = c[i] + max(0, a[i]);
  }
  long long res = 0;
  for (int i = 0; i < n - k + 1; i++) {
    res = max(res, c[i] - c[0] + c[n] - c[i + k]);
    res = max(res, c[i] - c[0] + c[n] - c[i + k] + b[i + k] - b[i]);
  }
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 2176
using namespace std;
using ll=long long;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == c || a + c == b || c + b == a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
    return 0;
}



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

using namespace  std;
#define int long long 
#define N 666666
int sum[N];
vector<int> v;
map<int,int> mp;
signed main(){
	string str;
	cin>>str;
	int add=0;
	mp[0]=1;
	int ans=0;
	int t=1;
	for(int i=str.size()-1;i>=0;i--){
		add=add+(str[i]-'0')*t;
	//	cout<<add%2019<<" ";
		add%=2019;
		ans+=mp[add];
		mp[add]++;
		t*=10;t%=2019;
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 3752
#include<stdio.h>
int Y[]={0,1,0,-1,-1,1};
int X[]={1,0,-1,0,-1,1};
int main(){
  int n,m,t,r,a,b,x[5010],y[5010],i,j,ny,nx;
  while(scanf("%d %d",&n,&m),n){
    int d[300][300]={t=0};
    while(m--){
      scanf("%d %d",&a,&b);
      d[b+100][a+100]=40;
    }
    scanf("%d %d",&x[0],&y[0]);
    d[y[0]+=100][x[0]+=100]=n+1;
    for(r=1;r-t;t++){
      for(i=0;i<6;i++){
	ny=y[t]+Y[i];
	nx=x[t]+X[i];
	if(d[ny][nx]+1>=d[y[t]][x[t]])continue;
	d[y[r]=ny][x[r]=nx]=d[y[t]][x[t]]-1;
	r++;
      }
    }
    printf("%d\n",r);
  }
  return 0;
}

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

int main()
{
    int m, n;
    const int size = 7400000;
    bool a[size];

    while( cin >> m >> n )
    {
        if( m + n == 0 )
            break;
        
        for( int i = 0; i < size; i++ )
            a[i] = 0;

        if( m > n )
            cout << m + n << endl;
        else if( m == n )
            cout << m + n + 1 << endl;
        else
        {
            for( int i = m; i < size; i++ )
            {
                if( n == 0 )
                {
                    for( int j = i; j < size; j++ )
                        if( a[j] == false )
                        {
                            cout << j << endl;
                            break;
                        }
                    break;
                }
                if( a[i] == false )
                {
                    a[i] = true;
                    n--;
                    for( int j = i; j < size; j += i )
                        a[j] = true;
                }
            }
        }
    }
    return 0;
}


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

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

int main(){
  int N;
  cin >> N;
  vector<int> h(N);
  for(int i = 0; i < N; i++){
  	int a;
    cin >> a;
    h.at(i) = a;
  }
  const long long INF = 1LL << 60;
  long long dp[100010];
  for(int i = 0; i < 100010; i++){
  	dp[i] = INF;
  }
  dp[0] = 0;
  for(int i = 0; i < N; i++){
    chmin(dp[i], dp[i-1]+ abs(h[i]-h[i-1]));
    chmin(dp[i], dp[i-2]+ abs(h[i]-h[i-2]));
  }
  
  cout << dp[N-1] << endl;
  
}

Measured memory_bytes: 1408
ds = [31,29,31,30,31,30,31,31,30,31,30,31]
s=["Wednesday",
   "Thursday",
   "Friday",
   "Saturday",
   "Sunday",
   "Monday",
   "Tuesday"
  ]
loop do
  m,d = gets.split.map &:to_i
  break if m == 0 && d == 0
  puts s[((0...m-1).inject(0){|s,i| s += ds[i]} + d)%7]
end

Measured memory_bytes: 6100