akhauriyash/Code-Regression huggingface dataset:
#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 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

signed main(void)
{
  double a, b[100], ma = -INF, mi = INF;
  int cnt = 0;
  while(cin >> a) {
    b[cnt] = a;
    cnt++;
    //cout << ma-mi << endl;
  }
  REP(i, cnt) {
    //cout << i << " ";
    ma = max(ma, b[i]);
    mi = min(mi, b[i]);
  }
  cout << fixed << setprecision(5) << ma-mi << endl;
  return 0;
}

Measured memory_bytes: 3232
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int px = 0;
		int py = 0;
		int pt = 0;
		for (int i = 0; i < n; i++) {
			int t = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			int d = Math.abs(x - px) + Math.abs(y - py);
			if (d > t - pt || (t - pt - d) % 2 != 0) {
				System.out.println("No");
				return;
			}
			px = x;
			py = y;
			pt = t;
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 88448
#include <stdio.h>
int main(void){
    long int a,b,k;
    
    scanf("%ld%ld%ld",&a,&b,&k);
    a-=k;
    if(a<=0){
        b+=a; a=0;
    }
    if(b<0)
        b=0;
    printf("%ld %ld\n",a,b);
    return 0;
}

Measured memory_bytes: 128
package main
import "fmt"
func main() {
  var n int
  fmt.Scan(&n)
  w := make([]int,n)
  d := 10000000
  s1,s2 := 0,0
  for i:=0;i<n;i++ {
    fmt.Scan(&w[i])
    s2 += w[i]
  }
  for i:=0;i<n;i++ {
    s1,s2 = s1+w[i],s2-w[i]
    t := abs(s2-s1)
    if d > t { d = t }
  }
  fmt.Println(d)
}
func abs(n int) int {
  if n < 0 { return -n }
  return n
}

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

int field[50][50];
int w, h;

void dfs(int x, int y) {
  if(x < 0 || h <= x || y < 0 || w <= y || field[x][y] == 0) return; 
  field[x][y] = 0;
  for(int i = -1; i <= 1; i++) {
    for(int j = -1; j <= 1; j++) {
      if(i == 0 && j == 0) continue;
      dfs(x+i, y+j);
    }
  }
}

int main() {

  while(cin >> w >> h, w+h) {
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
	cin >> field[i][j];
      }
    }

    int ans = 0;
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
	if(field[i][j] == 1) {
	  ans++;
	  dfs(i,j);
	}
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1272
import java.util.*;
import java.io.*;
import static java.lang.System.in;

public class Main {
    static int n,m;
    static long mod = 1000000000+7;
    // static ArrayList<Integer>[] graph,tree;
    public static void main(String[] args)throws IOException {
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        Scanner sc = new Scanner(System.in);
        //String[] buf = reader.readLine().split(" ");
        n = sc.nextInt();
        int maxn = 200000+5;
        ArrayList<Integer>[] rec = new ArrayList[maxn+1];
        for(int i=0;i<=maxn;i++) rec[i] = new ArrayList<>();
        int[] idx = new int[maxn+1];
        int[] c = new int[n];
        for(int i=0;i<n;i++){
            c[i] = sc.nextInt();
            rec[c[i]].add(i);
        }
        long[] dp = new long[n];
        dp[0] = 1;
        idx[c[0]]++;
        for(int i=1;i<n;i++){
            int cur = c[i];
            if(idx[cur]==0){
                dp[i] = dp[i-1];
            }else{
                int former = rec[cur].get(idx[cur]-1);
                if(former==i-1){
                    dp[i] = dp[i-1];
                } else{
                    if(former==0) dp[i] = (dp[i-1]+1)%mod;
                    else{
                        dp[i] = (dp[i-1]+dp[former])%mod;
                    }
                }
            }
            idx[cur]++;
        }
        System.out.println(dp[n-1]);
    }
}

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

int main() {
  ios::sync_with_stdio(0);
	cin.tie(0); 
  cout.tie(0);
  int n;
  cin>>n;
  vector<vector<int>> grid(n, vector<int>(3));
  
  for(int i=0; i<n; i++){
      cin>>grid[i][0]>>grid[i][1]>>grid[i][2];
  }
  
  for(int i=1; i<n; i++){
      grid[i][0] += max(grid[i-1][1], grid[i-1][2]);
      grid[i][1] += max(grid[i-1][0], grid[i-1][2]);
      grid[i][2] += max(grid[i-1][1], grid[i-1][0]);
  }
  int maxm = -1;
  for(int i=0; i<3; i++) maxm = max(grid[n-1][i], maxm);
    cout<<maxm<<endl;
  return 0;
}


Measured memory_bytes: 5760
import heapq
n=int(input())
A=[int(i) for i in input().split()]
AL=A[:n]
AR=[0]*n
for i in range(2*n,3*n):
  AR[i-2*n]-=A[i]
ALS,ARS=[0]*(n+1),[0]*(n+1)
ALS[0],ARS[0]=sum(AL),sum(AR)
heapq.heapify(AL)
heapq.heapify(AR)
for i in range(n):
  l,r=A[n+i],-A[2*n-i-1]
  heapq.heappush(AL,l)
  ALS[i+1]=ALS[i]+l-heapq.heappop(AL)
  heapq.heappush(AR,r)
  ARS[i+1]=ARS[i]+r-heapq.heappop(AR)
ans=-float("inf")
for i in range(n+1):
  ans=max(ans,ALS[i]+ARS[n-i])
print(ans)

Measured memory_bytes: 37212
#define mod 1000000007
#define PI 3.14159265358979323846
#define inf 100000000000000000
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
#define _ <<" "<<
#define forn(i, n) for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;

map< ii ,int > mp;
vector<int >v[5005];
signed main() {
    SPEED;
  //	freopen("test.txt","r",stdin);
    int n;cin>>n;

    cout<<pow(n,3);



}	
 
 

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a[111], res;

void rec(int l, int r) {
	if (r<l) return;
	if (l==r) {
		res += a[l];
		a[l] = 0;
		return;
	}
	int lst = l;
	reps(i,l,r+1) if (a[i]==0) rec(lst,i-1), lst = i+1;
	if (lst==l) {
		reps(i,l,r+1) a[i]--;
		res++;
		rec(l,r);
	} else rec(lst,r);
}

signed main() {
	cin >> n;
	reps(i,1,n+1) cin >> a[i];
	rec(1,n);
	cout << res << endl;
}

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

int main() {
  lint N, M, K;
  cin >> N >> M >> K;

  vector<lint> A(N);
  for(auto& elem : A) cin >> elem;
  partial_sum(A.begin(), A.end(), A.begin());
  A.insert(A.begin(), 0LL);

  vector<lint> B(M);
  for(auto& elem : B) cin >> elem;
  partial_sum(B.begin(), B.end(), B.begin());
  B.insert(B.begin(), 0LL);

  lint ans = -1e18;
  for(lint i=0; i<=N; i++) {
    lint sum = A[i];
    if(sum > K) continue;
    lint r = K - sum;
    auto j = upper_bound(B.begin(), B.end(), r) - B.begin();
    ans = max(ans, i + j - 1);
  } 

  cout << ans << endl;
}

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

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

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

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

    string S; cin >> S;
    if(S[0] == 'S'){
        if(S[1] == 'U') cout << 7 << endl;
        else cout << 1 << endl;
    } else if(S[0] == 'M') cout << 6 << endl;
    else if(S[0] == 'T'){
        if(S[1] == 'U') cout << 5 << endl;
        else cout << 3 << endl;
    } else if(S[0]=='W') cout << 4 << endl;
    else cout << 2 << endl;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int tr=0,tw=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            tr++;
        }
        else{
            tw++;
        }   
    }
    int ans=tw;
    int r=0,w=0;
    for(int i=n-1;i>-1;i--){
        if(s[i]=='R'){
            r++;
        }
        else{
            w++;
        }
        // cout<<r<<" "<<w<<endl;
        if(r>tw-w){
            break;
        }
        ans=min(ans,r+tw-r-w);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
//#include <ext/numeric>


using namespace std;
//using namespace __gnu_cxx;

//const int MAXN = (int)1e5 + 5;

int solve(int x) {
    while (x >= 10) {
        x /= 10;
    }
    return x;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n;
    cin >> n;
    map<pair<int, int>, int> mp;
    long long ans = 0;
    long long neg = 0;
    for (int i = 1; i <= n; ++i) {
        mp[{solve(i), i % 10}]++;
        ans += mp[{i % 10, solve(i)}];
        neg += i % 10 == solve(i);
    }

    cout << ans * 2 - neg << '\n';

    return 0;
}

Measured memory_bytes: 3668
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

// int main(){
//   ll n,a;
//   cin >> n >> a;
//   ll x[n];
//   REP(i,n){
//     cin >> x[i];
//   }
//   ll ans = 0;
//   REP(i,1<<n){
//     ll sum = 0;
//     ll cnt = 0;
//     REP(j,n){
//       if((i>>j)&1){
//         sum+=x[j];
//         cnt++;
//       }
//     }
//     if(sum==a*cnt){
//       ans++;
//     }
//   }
//   cout << ans-1 << endl;
//   return 0;
// }

// int main(){
//   ll n,a;
//   cin >> n >> a;
//   ll x[n+1];
//   x[0] = 0;
//   REP(i,n){
//     cin >> x[i+1];
//   }
//   ll cnt[n+1][n+1][50*50+1];
//   //x[i]まででj個使い、和がkとなる組合せ
//   REP(i,n+1){
//     REP(j,n+1){
//       REP(k,50*50+1){
//         if(i==0&&j==0&&k==0){
//           cnt[i][j][k]=1;
//         }else if(i>=1&&k<x[i]){
//           cnt[i][j][k]=cnt[i-1][j][k];
//         }else if(i>=1&&j>=1&&k>=x[i]){
//           cnt[i][j][k]=cnt[i-1][j][k]+cnt[i-1][j-1][k-x[i]];
//         }else{
//           cnt[i][j][k]=0;
//         }
//       }
//     }
//   }
//   ll ans = 0;
//   for(ll i=1; i<=n; i++){
//     ans += cnt[n][i][a*i];
//   }
//   cout << ans << endl;
// }

int main(){
  ll n,a;
  cin >> n >> a;
  ll x[n+1];
  REP(i,n){
    cin >> x[i+1];
    x[i+1]-=a;
  }
  ll cnt[n+1][50*50*2+1];
  //x[i]までのうちjになる組合せ
  REP(i,n+1){
    REP(j,50*50*2+1){
      if(i==0&&j==50*50){
        cnt[i][j]=1;
      }else if(i>=1&&j-x[i]>=0&&j-x[i]<=2*50*50){
        cnt[i][j]=cnt[i-1][j-x[i]]+cnt[i-1][j];
      }else if(i>=1){
        cnt[i][j]=cnt[i-1][j];
      }else{
        cnt[i][j]=0;
      }
    }
  }
  cout << cnt[n][50*50]-1 << endl;
}


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

int main() {
  string a;
  cin >> a;
  
  if (a.at(0) == a.at(1) && a.at(0) == a.at(2)) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }

  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差

ld mysqrtl(ld x)
{
  ld a = sqrt((double)x); // 近似値
  do {
    a = (a + x/a) / 2.0L;
  } while (fabsl(x - a*a) > eps);
  return a;
}

int	main(void)
{
  	long long int	a;
  	long long int	b;
  	long long int	c;
  	int	num;
  
  	num = scanf("%lld %lld %lld", &a, &b, &c);
  	if (num != 3)
      	return (0);
      	
    if (a < b)
    {
      	if (0 < mysqrtl(c) - mysqrtl(a) - mysqrtl(b))
        {
          	printf("Yes");
        }
      	else
        {
      	    printf("No");
        }
    }
    else
    {
        if (0 < mysqrtl(c) - mysqrtl(b) - mysqrtl(a))
        {
          	printf("Yes");
        }
      	else
        {
      	    printf("No");
        }
    }
  	return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, K;
    cin >> N >> K;
    vi x(N);
    cin >> x;
    auto f = [](int l, int r) {
        if (l * r > 0) {
            return max(abs(l), abs(r));
        } else {
            return abs(l - r) + min(abs(l), abs(r));
        }
    };
    int ans = INF;
    REP(i, N - K + 1) {
        int l = x[i], r = x[i + K - 1];
        chmin(ans, f(l, r));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int d[100100];

signed main(){
    int n;
    cin >> n;
    rep(i, 0, n){
        int a, b;
        cin >> a >> b;
        d[a] ++;
        d[b + 1]--;
    }
    rep(i, 1, 100010){
        d[i] += d[i - 1];
    }
    int ans = 0;
    rep(i, 0, 100010){
        // cout << d[i] << " ";
        if(d[i] >= i - 1){
            ans = i - 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3868
#include <iostream>

int main(int argc, char *argv[]) {
  int a, b, c, d;
  std::cin >> a >> b >> c >> d;
  int i = 0;
  while (a > 0 && c > 0) {
    if (i % 2 == 0)
      c -= b;
    else
      a -= d;
    ++i;
  }
  if (a > 0)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}


Measured memory_bytes: 3100
def d_christmas(N, X):
    # レベルnのときのパティの総数をp_nと書くと、 p_{n+1} = p_n + 1 + p_n, p_0 = 1
    # レベルnのときのバーガーの層数をa_nと書くと、 a_{n+1} = 1 + a_n + 1 + a_n + 1, a_0 = 1
    a, p = [1], [1]
    for _ in range(N):
        a.append(a[-1] * 2 + 3)
        p.append(p[-1] * 2 + 1)

    def f(n, x):
        # レベルnバーガーの下からn層食べたとき、食べたパティの数
        if n == 0:
            return 0 if x <= 0 else 1  # パティが1枚だけのバーガーを食べる
        elif x <= 1 + a[n - 1]:
            return f(n - 1, x - 1)
        else:
            return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1])

    return f(N, X)

N, X = [int(i) for i in input().split()]
print(d_christmas(N, X))

Measured memory_bytes: 3064
def main():
    N = int(input())
        
    A = 1
    countA = 0
    for i in range(N):
        A = (A*10)%(10**9 + 7)
        
    B = 1
    countB = 0
    for i in range(N):
        B = (B*9)%(10**9 + 7)
        
    C = 1
    countC = 0
    for i in range(N):
        C = (C*8)%(10**9 + 7)
        
    ans = (A - 2*B + C)%(10**9 + 7)
        
    print(ans)
    
if __name__ == '__main__':
    main()

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

int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int N,K,X,Y;
  cin>>N>>K>>X>>Y;
  cout<<(N-K>=0?K*X+(N-K)*Y:N*X)<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**6)

def score(Ans):
    t = 0
    for ai,bi,ci,di in zip(A,B,C,D):
        if Ans[bi]-Ans[ai]==ci:
            t += di
    return t

def dfs(Ans):
    if len(Ans)==n:
        return score(Ans)
    ans = 0
    prev_last = Ans[-1] if len(Ans)>0 else 0
    for v in range(prev_last, m):
        Ans.append(v)
        ans = max(ans, dfs(Ans))
        Ans.pop()
    return ans

n, m, q = map(int, readline().split())
A,B,C,D = [0]*q, [0]*q, [0]*q, [0]*q
for i in range(q):
    a,b,C[i],D[i] = map(int, readline().split())
    A[i] = a-1
    B[i] = b-1

print(dfs([]))

Measured memory_bytes: 9256
num = int(input())

import math

def find_factors (n): 
    limit = int(math.sqrt(n)+1)
    count = 0
    list=[]
    for i in range (1,limit):
        if n % i ==0:
            list.append(i)
            list.append (int(n/i))
            count = len(list)
    return count

if num >105:
    ccount = 1
    temp = 107
    while temp <= num:
        if find_factors(temp)==8:
            ccount +=1
        temp+=2
    print (ccount)
elif num ==105:
    print ("1")
elif num < 105:
    print ("0")
        


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  while(true){
    rep(i, n){
      if(a[i] % 2 == 0) a[i] /= 2;
      else{
        cout << ans << endl;
        return 0;
      }
    }
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	long long l[n+1];

	l[0]=2;
	l[1]=1;

	for(int i=2;i<=n;i++)
		l[i]=l[i-1]+l[i-2];

	cout << l[n] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<queue>

const int MAX = 1001001001;

int main() {

	int N, M, X;
	std::cin >> N >> M >> X;
	std::vector<int> C(N);
	std::vector<std::vector<int>> A(N, std::vector<int> (M));
	for (int i = 0; i < N; i++) {
		std::cin >> C[i];
		for (int j = 0; j < M; j++) {
			std::cin >> A[i][j];
		}
	}

	int answer = MAX;
	for (int i = 0; i < 1 << N; i++) {
		int cost = 0;
		std::vector<int> skill(M);
		for (int j = 0; j < N; j++) {
			if (i >> j & 1) {
				cost += C[j];
				for (int k = 0; k < M; k++) skill[k] += A[j][k];
			}
		}
		int count_error = 0;
		for (int j = 0; j < M; j++) {
			if (skill[j] < X) count_error = 1;
		}
		if (count_error == 0) answer = std::min(cost, answer);
	}

	if (answer == MAX) std::cout << -1 << std::endl;
	else std::cout << answer << std::endl;
	return 0;
}

Measured memory_bytes: 3604
from copy import deepcopy, copy
class dice:
    men = [0] * 7
    def __init__(self, li = [0] * 6):
        self.men = [0] + li
    def move0(self, a, b, c, d):
        self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a]
    def move(self, h):
        if h == "A":
            pass
        elif h == "N":
            self.move0(1, 2, 6, 5)
        elif h == "S":
            self.move0(1, 5, 6, 2)
        elif h == "W":
            self.move0(1, 3, 6, 4)
        elif h == "E":
            self.move0(1, 4, 6, 3)
        elif h == "O":
            self.men[1], self.men[6], self.men[2], self.men[5] = self.men[6], self.men[1], self.men[5], self.men[2]
        elif h == "L":
            self.move0(2, 3, 5, 4)
        elif h == "R":
            self.move0(2, 4, 5, 3)
        elif h == "B":
            self.men[3], self.men[4], self.men[2], self.men[5] = self.men[4], self.men[3], self.men[5], self.men[2]
        else:
            print("笆ｲ繧ｨ繝ｩ繝ｼ")
    def move2(self, a, b):
        if self.men[1] != a:
            for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
                if self.men[i] == a:
                    self.move(s)
                    break
        if self.men[2] != b:
            if b == self.men[3]:
                self.move("L")
            elif b == self.men[4]:
                self.move("R")
            else:
                self.move("B")
saikoro1 = dice(list(map(int, input().split())))
saikoro2 = dice(list(map(int, input().split())))
ans = []
saikoro3 = deepcopy(saikoro2)
for i in range(6):
    ans.append(saikoro3.men[:])
    saikoro3.move("L")
    ans.append(saikoro3.men[:])
    saikoro3.move("L")
    ans.append(saikoro3.men[:])
    saikoro3.move("L")
    ans.append(saikoro3.men[:])
    saikoro3 = deepcopy(saikoro2)
    saikoro3.move("SWENOOO"[i])
print("Yes" if saikoro1.men in ans else "No")



Measured memory_bytes: 6356
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn solve() -> usize {
    let n: usize = read();
    let a: usize = read();
    let b: usize = read();

    let mut ans: usize = 0;
    for i in 1..n + 1 {
        let numstr: String = i.to_string();
        let mut cnt: usize = 0;
        for j in numstr.chars() {
            let strnum: usize = j as usize - 48;
            cnt += strnum;
        }

        if cnt >= a && cnt <= b {
            ans += i;
        }
    }

    ans
}

fn main() {
    println!("{}", solve());
}


Measured memory_bytes: 4352
import Control.Monad (replicateM,guard)
import Data.List (groupBy)

main = do
    [h,w] <- fmap read . words <$> getLine
    xs <- replicateM h getLine
    let nns (x,y) = do
        dx <- [-1,0,1]
        dy <- [-1,0,1]
        let x'=x+dx
        let y'=y+dy
        guard $ not $ x==x' && y==y'
        guard $ 1<=x' && x'<=w
        guard $ 1<=y' && y'<=h
        return (x',y')
    let ys = [ ((x,y), if xs.>(x,y)=='#'
                            then "#"
                            else show . countBomb $ (xs.>) <$> nns (x,y)) | y <- [1..h], x <- [1..w] ]
    mapM_ putStrLn $ concatMap snd <$> groupBy (\((_,y1),_) ((_,y2),_) -> y1==y2) ys

countBomb = length . (filter ('#'==))
xs .> (x,y) = (xs !! (y-1)) !! (x-1)

Measured memory_bytes: 1148
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1e8;


int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a != c){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

char s[101];
bool isPal(int ii, int jj)
{
  for (int i = ii, j = jj; i < j; i++, j--)
    if (s[i] != s[j])
      return false;
  return true;
}

int main()
{
  while (scanf(" %s", s) != EOF)
  {
    bool ans = true; int n = strlen(s);
    ans = isPal(0, n - 1) && isPal(0, (n - 1) / 2 - 1) && isPal((n + 3) / 2 - 1, n - 1);
    printf("%s\n", ans ? "Yes" : "No");
  }
  return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<functional>
#include<iterator>
#include<iostream>
#include "bits/stdc++.h"
#define IO ios_base::sync_with_stdio(false);cin.tie(0);
#define mem(a,val) memset(a,val,sizeof(a))
#define pb push_back
using namespace std;

void solu (){

}

int main(void){
    string temp;
	while(cin>>temp){int n=0;
	    for(int i=0;i<temp.length();i++){
	        n+=temp[i]-48;
	    }
        if(n%9==0)
            cout<<"Yes\n";
            else
                cout<<"No\n";
            temp.clear();
	}


	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
#define min3(a,b,c) min(a,min(b,c))
#define nl cout<<"\n";
#define all(v) v.begin(),v.end()
#define F first
#define S second
typedef long long ll;
typedef vector<long long> vl;
typedef vector<pair<long,long>> vp;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
ll gcd(ll a,ll b);
ll binpow(ll a,ll b);
void solve()
{
    string x,y;
    cin>>x>>y;
    ll c=0;
    rep(i,0,x.length())
   if(x[i]!=y[i]) c++;
    cout<<c;
}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
	 	solve();
	}
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
ll binpow(ll a, ll b) {
   ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> a(N);
    rep(i, N) cin >> a[i];

    reverse(a.begin(), a.end());

    int max = 0;
    int ans = 0;
    priority_queue<int> q;
    rep(i, a.size()) {
        if (q.empty()) {
            q.push(a[i]);
            continue;
        }

        int d = q.top() - a[i];
        q.push(a[i]);
        if (d > max) {
            max = d;
            ans = 1;
        } else if (d == max) {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll solve(ll N){
    ll ans = 0;
    return ans;
}

int main(){
    ll A,B; cin >> A >> B;
    print(lcm(A,B));
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,ans,a[2020][2020],b[2020][2020];
char c[2020][2020];
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>c[i][j];
		}
	}
	for(int i=0;i<n;i++)
	{
		int cnt=0;
		for(int j=0;j<m;j++)
		{
			if(c[i][j]=='.')
			{
				cnt++;
			}
			else
			{
				cnt=0;
			}
			a[i][j]=cnt;
		}
	}
	for(int j=0;j<m;j++)
	{
		int cnt=0;
		for(int i=0;i<n;i++)
		{
			if(c[i][j]=='.')
			{
				cnt++;
			}
			else
			{
				cnt=0;
			}
			b[i][j]=cnt;
		}
	}
	for(int i=n-1;i>=0;i--)
	{
		for(int j=m-1;j>=0;j--)
		{
			if(j<m-1 && a[i][j])
			{
				a[i][j]=max(a[i][j],a[i][j+1]);
			}
			if(i<n-1 && b[i][j])
			{
				b[i][j]=max(b[i][j],b[i+1][j]);
			}
			ans=max(ans,a[i][j]+b[i][j]-1);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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


using namespace std;

#define pb push_back
const int maxi=1e6;
int a[maxi];
string s;
int n;
vector<int> v[maxi];
int k;
int solve(int x)
{
   return (x+k-2)/(k-1);
}
int main()
{
   cin>>n>>k;

   int poz=0;
   for (int i=1;i<=n;i++)
   {
       scanf("%d",&a[i]);
       if (a[i]==1) poz=i;
   }

  int  ans=100000000;

   for (int j=1;j<=min(k,poz);j++){
       ans=min(ans,solve(poz-j)+ 1 + solve(n-poz-(k-j)));
   }

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


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

#define what_is(x)    cerr<<#x<<" is "<<x<<"\n";
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int solve(){
    cin>>str;
    n=sz(str);
    rep(i,0,n-1){
        if(i%2==0){
            if(str[i]=='R'||str[i]=='U'||str[i]=='D') ;
            else{
                cout<<"No";
                return 0;
            }
        }
        else{
            if(str[i]=='L'||str[i]=='U'||str[i]=='D') ;
            else{
                cout<<"No";
                return 0;
            }
        }
    }
    cout<<"Yes";
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
// And Then the GOD Entered..   
#include<bits/stdc++.h>
 using namespace std;
 
typedef long long int ll;
#define endl "\n"
#define fi first
#define sec second 
#define pb push_back
#define test cout<<"debuged\n";
#define INF ll(1e18)
#define MOD 1000000007
#define debug(x) cout<<x<<"\n";
#define pll pair<ll,ll>
#define mp make_pair
#define Minato_Namikaze ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define MAX 200015

ll n;
ll vis[305][305][305];
double dp[305][305][305];

double solve(ll x, ll y, ll z)
{
    if(x + y + z == 0)
        return 0;
    double ans = 0;
    if(vis[x][y][z] != -1)
        return dp[x][y][z];
    vis[x][y][z] = 1;
    ans = double(double(n) / double(x + y + z));
    if(x - 1 >= 0)
        ans += double(double(x) / double(x + y + z)) * (solve(x - 1, y, z));
    if(y - 1 >= 0)
        ans += double(double(y) / double(x + y + z)) * (solve(x + 1, y - 1, z));
    if(z - 1 >= 0)
        ans += double(double(z) / double(x + y + z)) * (solve(x , y + 1, z - 1));
    return dp[x][y][z] = ans;
}

int main()
{
    Minato_Namikaze
    cin >> n;
    memset(vis, -1, sizeof vis);
    ll x = 0, y = 0, z = 0;
    for(ll i = 0; i < n; ++i)
    {
        ll u;
        cin >> u;
        if(u == 1)
            x++;
        else if(u == 2)
            y++;
        else
            z++;
    }    
    cout << fixed << setprecision(10);
    cout << solve(x, y, z) << endl;
    
}

Measured memory_bytes: 441600
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b; cin>>a>>b;
	if(b<a)a--;
	cout<<a<<endl;
	
	return 0;
}

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

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

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

int m, a, b;

vector<int> primes;

#define MAX 50001
bool ps[MAX];

void erat()
{
	fill(ps, ps+MAX, true);
	ps[0] = ps[1] = false;
	REP(i, 2, MAX) {
		if (ps[i]) primes.push_back(i);
		for (int j = 2*i; j < MAX; j += i)
			ps[j] = false;
	}
}

int main(void)
{
	erat();
	while (cin >> m >> a >> b, m|a|b) {
		int ans = 0;
		pii ansp;
		rep(i, primes.size()) {
			int p = primes[i];
			REP(j, i, primes.size()) {
				int q = primes[j];
				if (p*q > m) break;
				if (!(a*q <= p*b)) continue;
				if (!(p <= q)) continue;
				if (ans < p*q) {
					ans = p*q;
					ansp = pii(p, q);
				}
			}
		}
		printf("%d %d\n", ansp.first, ansp.second);
	}
	return 0;
}

Measured memory_bytes: 1300
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
ans += A[0]
if n > 2:
#     print((n+1) // 2, A[1:(n+1) // 2])
    ans += sum(A[1:(n+1) // 2]) * 2
    if n % 2 == 1:
        ans -= A[(n+1) // 2 - 1]
print(ans)

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

int main()
{
  string b[3];
  while (cin >> b[0], b[0] != "0"){
    int f = 0;
    cin >> b[1] >> b[2];
    for (int i = 0; i < 3; i++){
      if (b[i] == "bbb"){
        f = 1;
        break;
      }
      else if (b[i] == "www"){
        f = 2;
        break;
      }
      else {
        string str = "";
        str += b[0][i];
        str += b[1][i];
        str += b[2][i];
        if (str == "bbb"){
          f = 1;
          break;
        }
        if (str == "www"){
          f = 2;
          break;
        }
      }
    }
    if (f == 0){
      string str = "";
      str += b[0][0];
      str += b[1][1];
      str += b[2][2];
      if (str == "bbb") f = 1;
      else if (str == "www") f = 2;
      str = "";
      str += b[0][2];
      str += b[1][1];
      str += b[2][0];
      if (str == "bbb") f = 1;
      else if (str == "www") f = 2;
    }

    if (f == 0) cout << "NA\n";
    else if (f == 1) cout << "b\n";
    else if (f == 2) cout << "w\n";
  }
}

Measured memory_bytes: 3012
import itertools

N = int(input())
table = [input() for _ in range(N)]

count = 0

for b in range(N):
    symmetric = True
    new_table = []
    for i in range(N):
        string = table[i][b:] + table[i][:b]
        new_table.append(string)
    
    for i in range(N-1):
        string1 = new_table[i][i+1:]
        string2 = ''.join([s[i] for s in new_table[i+1:]])
        if string1 != string2:
            symmetric = False
            break
    
    if symmetric:
        count += N

print(count)

Measured memory_bytes: 3308
#include<bits/stdc++.h>
using namespace std;
int n,t,ans,maxn,maxn1,ans1;
int a[100010];
int main(){
    cin>>n>>t;
    for (int i=1;i<=n;i++)
		cin>>a[i];
    for (int i=n;i>0;i--)
	{
		maxn=max(a[i],maxn);
		ans=max(maxn-a[i],ans);
	}
    for (int i=n;i>0;i--)
	{
		maxn1=max(a[i],maxn1);
		if(maxn1-a[i]==ans)
			ans1++;
	}
    cout<<ans1<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>


int search(int A[], int n, int key){
	int i = 0;
	A[n]= key;
	while(A[i] != key)i++;
	return i != n;
}

int main(){
	int i, n, A[10000+1], q, key, sum = 0;
	
	scanf("%d",&n);
	for(i = 0; i < n; i++)scanf("%d",&A[i]);
	
	scanf("%d", &q);
	for(i = 0; i < q; i++){
	scanf("%d",&key);
		if(search(A, n, key))sum++;
	}
	printf("%d\n",sum);
	
	return 0;
	
}




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

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

    vector<int> a(n + 2);
    for (int i = 0; i < n; i++) cin >> a[i];

    sort(a.rbegin(), a.rend());

    long long ans = 1;
    int cnt = 0;
    for (int i = 1; i < a.size(); i++) {
        if (a[i] == a[i - 1]) {
            ans *= a[i];
            ++cnt, ++i;
        }
        if (cnt == 2) break;
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long MOD = 998244353;

bool checkPalindrome(string s, int n) {
    int i = 0, j = n - 1;
    while (i < j) {
        if (s[i] != s[j]) return false;
        i++, j--;
    }
    return true;
}

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

    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> count(200005, 0);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        count[v[i]]++;
    }

    for (int i = 0; i < 200005; i++) {
        ans += (ll)count[i] * (ll)(count[i] - 1) / 2;
    }

    for (int i = 0; i < n; i++) {
        ans -= count[v[i]] - 1;
        cout << ans << "\n";
        ans += count[v[i]] - 1;
    }

    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <cmath>
#define R register
using namespace std;
int n,k,p[100005];
long long ans=1e14+1,ans2,dx;
inline int ri(){
	char c=getchar();int x=0,w=1;
	while(!isdigit(c)){if(c=='-')w=-1;c=getchar();}
	while( isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*w;
}
int main(){
	n=ri(); k=ri();
	for(R int i=1;i<=n;i++){ 
		p[i]=ri(); 
		if(p[i-1]<=0&&p[i]>0)dx=i-1;
	}
	if(p[n]<=0){ cout<<abs(p[n-k+1]); return 0; }
	
	for(R int k1=0;k1<=dx;k1++){//k1向左几步 
		int k2=k-k1;//k2向右 
		if(k2>n-dx)continue;
		else{
			if(k1!=0)ans2+=abs(p[dx-k1+1]);
			if(k2!=0){ ans2*=2; ans2+=p[dx+k2]; }
		}
		ans=min(ans,ans2); ans2=0;
	}
	for(R int k1=0;k1<=n-dx;k1++){//k1向右几步
		int k2=k-k1;//k2向左
		if(k2>dx)continue;
		else{
			if(k1!=0)ans2+=p[dx+k1];
			if(k2!=0){ ans2*=2; ans2+=abs(p[dx-k2+1]); }
		} 
		ans=min(ans,ans2);ans2=0;
	} 
	printf("%lld\n",ans);
	return 0;
}

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

int grow(int a ,int r, int d){
  int growr =r;
  int growd =d;
  return a*growr-growd;}

int main() {
    int r, d,x;
    cin >> r >> d>>x;
    
    for(int i=0;i<10;i++){
      cout<<grow(x,r,d)<<endl;
      x=grow(x,r,d);}
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

int main() {

	int N,M;
	map<string,int> s, t;

	scanf("%d", &N);

	rep(i, N) {
		char str[16];
		scanf("%s", str);
		s[string(str)]++;
	}
	scanf("%d", &M);

	rep(i, M) {
		char str[16];
		scanf("%s", str);
		t[string(str)]++;
	}

	int a = 0;

	for (auto ss : s) a = max(a,ss.second - t[ss.first]);

	printf("%d", a);

	return 0;
}


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

int n,num[100010],tot[100010],ok[100010],dp[100010];

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<n;i++){
		int a,b,c;
		cin>>a>>b>>c;
		num[a]^=c;num[b]^=c;
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(num[i]==0) cnt++;
		else tot[num[i]]++;
	}
	vector<int> v;
	for(int i=1;i<=15;i++){
		cnt+=tot[i]/2;
		if(tot[i]%2==1){
			v.push_back(i);
		}
	}
	if(v.empty()){
		cout<<n-cnt<<endl;
		return 0;
	}
	int len=v.size();
	for(int i=0;i<(1<<len);i++){
		int sum=0;
		for(int j=1;j<=len;j++) if(i&(1<<(j-1))){
			sum^=v[j-1];
		}
		if(sum==0) ok[i]=1;
	}
	for(int i=0;i<(1<<len)-1;i++){
		int mask=((1<<len)-1)^i;
		for(int j=mask;j>0;j=(j-1)&mask) if(ok[j]){
			dp[i|j]=max(dp[i|j],dp[i]+1);
		}
	}
	cout<<n-cnt-dp[(1<<len)-1]<<endl;
	return 0;
} 

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n;
int a[10010];

void solve() {
    cin >> n;
    REP(i,n-1) {
        cin >> a[i+1];
    }
    a[0] = inf;
    a[n] = inf;
    int ans = 0;
    REP(i,n) {
        ans += min(a[i],a[i+1]);
    }
    cout << ans << endl;
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

Measured memory_bytes: 256
N, T = map(int, input().split())
t = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
	if t[i] + T <= t[i + 1]:
		ans += T
	else:
		ans += t[i + 1] - t[i]
ans += T
print(ans)


Measured memory_bytes: 26708
using System.Linq;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	public K() { WriteLine(Solve() ? "YES" : "NO"); }
	bool Solve()
	{
		var I = ReadLine().Split().Select(int.Parse).ToArray();
		int N = I[0], A = I[1], B = I[2], C = I[3], D = I[4];
		long d = B - A, n = N - 1, s = C + D, l = n * C - d, r = n * D - d;
		for (var k = 0; k <= N; k++)
		{
			var t = s * k;
			if (l <= t && t <= r) return true;
		}
		return false;
	}
}


Measured memory_bytes: 13268
n = gets.to_i
array_p = gets.split(" ").map!{|i | i.to_i}

swap = 0

array_p.each_with_index do |num, index|
    unless num == (index + 1)
    swap = swap + 1

    if swap == 3
      break
    end
  end
end

swap != 3 ? result = "YES" : result = "NO"

puts result


Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	static int[][] memo;

	public static int hoge(int current, int n, String last) {
		return 0;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int x,y,z,k,i1,i2,i3;
		long temp;
		long[] a,b,c,ans;
		String str;
		String[] s;
		str = bf.readLine();
		s = str.split(" ");
		x = Integer.parseInt(s[0]);
		a = new long[x];
		y = Integer.parseInt(s[1]);
		b = new long[y];
		z = Integer.parseInt(s[2]);
		c = new long[z];
		k = Integer.parseInt(s[3]);
		ans = new long[k];
		str = bf.readLine();
		s = str.split(" ");
		for(i1 = 0;i1 < x;++i1) {
			a[i1] = Long.parseLong(s[i1]);
		}
		str = bf.readLine();
		s = str.split(" ");
		for(i1 = 0;i1 < y;++i1) {
			b[i1] = Long.parseLong(s[i1]);
		}
		str = bf.readLine();
		s = str.split(" ");
		for(i1 = 0;i1 < z;++i1) {
			c[i1] = Long.parseLong(s[i1]);
		}
		Arrays.sort(a);
		Arrays.sort(b);
		Arrays.sort(c);
		for(i1 = x-1;i1 >= 0;--i1) {
			if(a[i1] + b[y-1] + c[z-1] <= ans[0]) {
				break;
			}
			for(i2 = y-1;i2 >= 0;--i2) {
				if(a[i1] + b[i2] + c[z-1] <= ans[0]) {
					break;
				}
				for(i3 = z-1;i3 >= 0;--i3) {
					temp = a[i1] + b[i2] + c[i3];
					if(temp <= ans[0]) {
						break;
					} else {
						ans[0] = temp;
						Arrays.sort(ans);
					}
				}
			}
		}
		for(i1 = k-1;i1 >= 0;--i1) {
			System.out.println(ans[i1]);
		}
	}
}

Measured memory_bytes: 156212
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define endl '\n'

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	
	
	//ll t; cin>>t; while(t--)
	{
		
		string s,t;
		cin>>s>>t;
		ll cnt=0;
		for(int i=0;i<s.length();i++)
		{
			if(s[i]!=t[i])
			{
				cnt++;
			}
		}
		cout<<cnt;
		
	}
}

Measured memory_bytes: 3784
import statistics
import math

N = int(input())
a = []
b = []
for i in range(N):
    A, B = map(int,input().split())
    a.append(A)
    b.append(B)

if N%2 == 1:
    ans = statistics.median(b) - statistics.median(a) + 1
else:
    ans = (statistics.median(b) - statistics.median(a))*2 + 1
print(int(ans))

Measured memory_bytes: 28828
#include<bits/stdc++.h>
using namespace std;
int n;
double a[50];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
		if(i==n-2)
			cout<<(double)(a[n-2]+a[n-1])/2<<endl;
		else
			a[i+1]=(a[i]+a[i+1])/2;
	return 0;
}

Measured memory_bytes: 256
n = str(input())

ans = n[-1]

if ans == "1" or ans == "0" or ans == "6" or ans == "8":
    print("pon")
elif ans == "2" or ans == "4" or ans == "5" or ans == "7" or ans == "9":
    print("hon")
else:
    print("bon")

Measured memory_bytes: 9048