akhauriyash/Code-Regression huggingface dataset:
N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
A = A[::-1]
#print("A:", A)

left = 0
right = N

while left + 1 < right:
  mid = (left + right) // 2
  Amid = A[mid]
  rest = M * V - M * P
  start = P if mid + 1 <= P else P - 1
  
  flag = 0
  for i in range(start, N):
    if mid == i:
      continue
    else:
      if A[i] > Amid + M:
        flag = 1
        break
      else:
        rest -= min(M, Amid + M - A[i])
        
  if rest > 0 or flag:
    right = mid
  else:
    left = mid
#print(left)

answer = 0
Aleft = A[left]
for i in range(N):
  if A[i] >= Aleft:
    answer += 1
    
print(answer)

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

const double EPS = 1e-9;

typedef struct Point {
	double x, y;
		
	Point operator - (const Point& a) const {
		return Point{x - a.x, y - a.y};
	}
	
	Point operator / (double d) const {
		return Point{x / d, y / d};
	}
	
	bool operator == (const Point& a) const {
		return fabs(x - a.x) < EPS && fabs(y - a.y) < EPS;
	}
} Vector;

double abs(Point a) {
	return sqrt(a.x * a.x + a.y * a.y);
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}

bool is_parrallel(Vector a, Vector b) {
	return fabs(cross(a, b)) < EPS;
}

Vector unit(Vector a) {
	return a / abs(a);
}

double D, px, py, vx, vy;
Point zero{0, 0}, p, v;

double calc() {
	double a = abs(p), b = 1.0 - a;
	
	Vector uz = unit(p - zero), vp = unit(v);
	
	if (uz == vp) return a + 2. * b;
	return a;
}

int main() {
	while (cin >> D, D > EPS) {
		cin >> px >> py >> vx >> vy;
		
		p = Point{px, py};
		v = Point{vx, vy};
		
		if (is_parrallel(v, p)) {
			double d = calc();
			if (d > D + EPS) cout << "impossible" << endl;
			else cout << setprecision(9) << setiosflags(ios::fixed) << d << endl;
		} else {
			cout << "impossible" << endl;
		}
	}
}

Measured memory_bytes: 1280
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        long N = sc.nextLong();
                        while (N!=0) {
                                int i;
                                for (i = 0; i < N; i++) {
                                        if (i*(i+1)/2>=N) {
                                                break;
                                        }
                                }
                                System.out.println(i);
                                N-=i;
                        }
                }
        }
}

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

int main() {
  int i,j;
  int K;
  int K_up,K_down;
  int num = 0; /* 必ず偶数 */
  int counter = 0;
  int ans;
  int k_ijou_counter = 0;
  int ok_counter = 0;
  cin >> num; /*2 ～　10^5個*/
  int problem[num];
  int problem_ookisa[num];
  
  /* 取り込み */
  /* 難易度は1～100000 */
  for(i=0; i<num; i++){
    cin >> problem[i];
  }
  
  /* 最大値と最小値の目星をつける */
  sort(problem, problem + num, greater<int>()); 
  
  ans = problem[(num/2)-1] - problem[num/2];
  
  /* Kの候補値で全探索 */
//  for(K=problem[((num)/2)+2]-1; K<problem[((num)/2)-2]+1; K++){
//    k_ijou_counter = 0;
//    for(j=0; j<num; j++){
//      if(problem[j] >= K) k_ijou_counter ++;/*難易度K以上の問題カウント*/
//    }
//    if(k_ijou_counter == (num/2)) ok_counter++; /* K以上の問題＝問題数の1\2ならOK */
//  }
  cout << ans << endl;
}

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

map<int, int> mp;

bool check(int n) {
    string s = to_string(n);
    for (auto p : mp) {
        int i = p.first - 1;
        if (i >= s.length()) return false;
        if (s[i] - '0' != p.second) return false;
    }
    return true;
}

int main() {
    int n, m;
    cin >> n >> m;
    int ans = -1;
    bool ok = true;
    for (int i = 0; i < m; i++) {
        int s, c;
        cin >> s >> c;
        if (mp.find(s) != mp.end() && mp[s] != c) {
            ok = false;
            break;
        }
        mp[s] = c;
    }
    if (!ok) {
        cout << -1;
        return 0;
    }
    int limit = 0, start = 0;
    if (n == 1) {
        limit = 9;
    }
    else if (n == 2) {
        start = 10;
        limit = 99;
    }
    else {
        start = 100;
        limit = 999;
    }
    for (int i = start; i <= limit; i++) {
        if (check(i)) {
            ans = i;
            break;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
n,k = gets.split.map(&:to_i)
pt = gets.split.map(&:to_i)
t = gets.chomp #s=>0, p=>1, r=>2

ans = [0]*n
n.times do |i|
  m = t[i] == "s" ? 0 : (t[i] == "p" ? 1 : 2)
  if i >= k && t[i-k] == t[i] && ans[i-k] > 0
    #nothing
  else
    ans[i] = pt[m]
  end
end
p ans.inject(:+)

Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
int a[8];
int dp[10000];
int rec(int idx, int n)
{
    if(idx>=n)
    {
        return 0;         
    }
    if(dp[idx]!=-1)
    {
        return dp[idx];
    }
    
    return dp[idx]=max(rec(idx+1,n), rec(idx+2,n)+a[idx]);
    
    
}





int main()
{
    long long a,b,c; cin>>a>>b>>c;
    if(a>c)
    {
        a=a-c;
        cout<<a<<" "<<b; return 0;
    }
    else
    {
        b-=(c-a);
        if(b<0){b=0;}
        cout<<0<<" "<<b; return 0;
    }
}


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



int main(){
	int a,b;
	string f="Yes";
	cin>>a>>b;
	
	if(a%500>b){
		f="No";
	}
	
	cout<<f<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

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

    ll r = 0;
    int p[20];
    for (int k = 0; k < 20; k++) {
        p[k] = -1;
    }
    int s = -1;
    for (int i = 0; i < n; i++) {
        int t = s;
        for (int k = 0; k < 20; k++) {
            if (a[i] & 1 << k) {
                t = max(t, p[k]);
                s = max(s, p[k]);
                p[k] = i;
            }
        }
        r += i - t;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	//a=0 ,b=1, c=2
	int num[3]={0};
	for(int i=0; i<3; i++){
		scanf("%d",&num[i]);
	}
	int tmp=0;
	for(int i=num[0]; i<=num[1]; i++){
		if(num[2]%i==0){
			tmp++;
		}
	}
	printf("%d\n",tmp);
	return 0;
}


Measured memory_bytes: 2756
//**************************
//*** writer  :  Alan Hu **
//************************

//傅思程你敢抄我程序？？？
//傅思程你敢抄我程序？？？
//傅思程你敢抄我程序？？？

#include<bits/stdc++.h>

using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

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

int gcd(int x,int y)
{
	if (x%y==0) return y;
	else return gcd(y,x%y);
}
 
int n,x;
vi v,cnt;
 
int main()
{
	cin>>n>>x;
	rept(i,0,n)
	{
		int y;
		cin>>y;
		v.pb(y);
	}
	v.pb(x);
	sort(v.begin(),v.end());
	rept(i,0,v.size()-1) cnt.pb(v[i+1]-v[i]);
	int ans=cnt[0];
	rept(i,1,cnt.size()) ans=gcd(max(ans,cnt[i]),min(ans,cnt[i]));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <map>

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long N; cin >> N;
    vector<long long> A(N);
    map<long long, long long> map;
    rep (i, 0, N) {
        cin >> A[i];
        map[A[i]]++;
    }

    if (A.size() % 2 == 0) {
        for (int i = 1; i < A.size(); i += 2) {
            if (map[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    else {
        for (int i = 0; i < A.size(); i += 2) {
            if (i == 0) {
                if (map[i] != 1) {
                    cout << 0 << endl;
                    return 0;
                }
            }
            else if (map[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
        }
    }

    long long ans = 1;
    for (auto mp : map) {
        ans *= mp.second;
        ans %= MOD;
    }
    cout << ans % MOD << endl;
}

Measured memory_bytes: 4992
N=int(input())
suits=["S","H","C","D"]
cards=[]
for _ in range(N):
    s,n=input().split()
    if s=="S":
        cards.append(int(n))   
    elif s=="H":
        cards.append(13+int(n))   
    elif s=="C":
        cards.append(26+int(n))
    else:
        cards.append(39+int(n))

for i in range(1,53):
    if i not in cards:
        print(suits[(i-1)//13],(i-1)%13+1)



Measured memory_bytes: 5604
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint A, B, C;

map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);	
	cin >> A >> B >> C;
	if (A == B && B == C && A%2 == 0) {
		cout << -1 << endl;
	}
	else {
		lint cnt = 0;
		while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
			cnt++;
			lint tmp = A, tmp2 = B;
			A = B / 2 + C / 2;
			B = tmp / 2 + C / 2;
			C = tmp / 2 + tmp2 / 2;
		}
		cout << cnt << endl;
	}
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1005];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	double sum=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sum/=m*4;
	int abs=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]>=sum)abs++;
		if(abs==m)
		break;
	}
	if(abs==m)
	printf("Yes\n");
	else 
	printf("No\n");
	return 0;
}

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

const int MAXN = 3e5+10;

int bit[MAXN];
int par[MAXN];
int parent(int i) {
  return par[i] < 0 ? i: (par[i]=parent(par[i]));
}

bool merge(int a, int b) {
  int x = parent(a);
  int y = parent(b);
  if (x==y) {
    if (bit[x]) return false;
    else return bit[x] = 1;
  }
  if (bit[x] && bit[y]) return false;
  bit[x]+=bit[y];
  par[y] = x;
  return 1;
}

int gc=0;
map<pair<int,int>, int> m;
int gid(int r, int c) {
  auto p = make_pair(r,c);
  if (m.count(p)) {
    return m[p];
  }
  else {
    return  m[p] = gc++;
  }
}

int n, h, w;

int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  cin >> n >> h >> w;
  memset(par, -1,sizeof par);
  vector<vector<int>> v;
  for(int i=0;i<n;i++) {
    int r, c, w;
    cin >> r >> c >> w;
    v.push_back({w,r,c});
  }
  sort(v.rbegin(), v.rend());
  ll ans = 0;
  for(auto p: v) {
    if (merge(gid(p[1],0), gid(p[2],1))){
      ans+=p[0];
      //cerr << "ADDING " << p[1] << " " << p[2] << " " << p[0] <<endl;
    }
    //else //cerr << "NOT ADDING " << p[1] << " " << p[2] << " " << p[0] <<endl;
  }
  cout << ans <<endl;
}



Measured memory_bytes: 20784
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

struct jie
{
    int x,y,k;
};
int n,m,us[805][805],a[805][805],dx[4]={-1,1,0,0},dy[4]={0,0,-1,1},ans=1000000007;
char mp[805][805];
queue<jie> q;
void bfs(int x1,int y1,int k)
{
    jie p;
    p.x=x1,p.y=y1,p.k=0;
    ans=min(ans,(m-y1+k-1)/k+1);
    ans=min(ans,(n-x1+k-1)/k+1);
    ans=min(ans,(x1-1+k-1)/k+1);
    ans=min(ans,(y1-1+k-1)/k+1);
    us[x1][y1]=1;
    q.push(p);
    while(!q.empty())
    {
        jie pp=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            int nx=pp.x+dx[i];
            int ny=pp.y+dy[i];
            int t=pp.k+1;
            if(nx<=n&&ny<=m&&nx>=1&&ny>=1&&us[nx][ny]==0&&mp[nx][ny]=='.')
            {
                us[nx][ny]=1;
                ans=min(ans,(m-ny+k-1)/k+1);
                ans=min(ans,(n-nx+k-1)/k+1);
                ans=min(ans,(nx-1+k-1)/k+1);
                ans=min(ans,(ny-1+k-1)/k+1);
                if(t<k)
                {
                    p.x=nx;
                    p.y=ny;
                    p.k=t;
                    q.push(p);
                }
            }
        }
    }
}
int main()
{
    int i,j,k;
    scanf("%d %d %d",&n,&m,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%s",mp[i]+1);
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(mp[i][j]=='S')
            {
                bfs(i,j,k);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;


int main()
{

   short a,b,c;

    while(cin>>a>>b>>c)
    {

      short n1,n2,n3;
      n1=a+b;
      n2=a+c;
      n3=b+c;

      if(n1<n2)
      {
          if(n1<n3)
          {
              cout<<n1<<endl;

          }
            else
                cout<<n3<<endl;
      }

      else
      {
          if(n2<n3)
          {
              cout<<n2<<endl;
          }
          else
            cout<<n3<<endl;
      }

    }








    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;

using Graph = vector<vector<char>>;

int main() {
  ll x; 
  cin >> x;
  ll ans = 100;
  ll count =0;
  while(x>ans){
    ans = (ll) (ans*1.01);
    count++;
  }

  cout << count << endl;
}

Measured memory_bytes: 3636
import itertools
import bisect

tfs = ['3', '5', '7']
lst = list()
for i in range(3, 10):
    lst += itertools.product(tfs, repeat=i)
lst = sorted([int(''.join(z)) for z in filter(lambda x: all([(y in x) for y in tfs]), lst)])
n = int(input())
print(bisect.bisect(lst, n))

Measured memory_bytes: 47580
#include <bits/stdc++.h>
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define sort(a) sort((a).begin(),(a).end())
#define rev(a) reverse((a).begin(),(a).end())
using db = double;
using namespace std;
typedef long long ll;



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

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

int main() {
    
    ll n; cin >> n;
    map<ll, ll>mp;
    for (ll i = 0; i < n; i++) {
        ll a; cin >> a;
        mp[a]++;
    }
    ll ans = 0;
    for (auto u : mp) {
        if (u.first <= u.second) {
            ans += u.second  - u.first;
        }
        else if (u.second < u.first) {
            ans += u.second;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9560
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    string S, t1, t2;
    long long n, i, c1=0, c2=0;

    cin >> S;

    n = S.size();

    for(i=0; i<n; i++){
        if(i%2==0){
            t1 += '0';
            t2 += '1';
        }
        else{
            t1 += '1';
            t2 += '0';
        }

        if(S[i]!=t1[i]){
            c1++;
        }
        if(S[i]!=t2[i]){
            c2++;
        }
    }

    cout << min(c1, c2) << endl;

    return 0;
}

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

int main() {
  int n, sa = 0, sb = 0, m;
  cin >> n;
  vector<int> v(n);
  rep(i, n) {
    cin >> v[i];
    sb += v[i];
  }
  m = sb;
  rep(i, n-1) {
    sa += v[i];
    sb -= v[i];
    m = min(m, abs(sa-sb));
  }
  cout << m << endl;
}


Measured memory_bytes: 3592
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=100005;

int dp[3005][3005][2];

int n;
int a[3005];

int solve(int i,int j,int k)
{
    if(j<i)
        return dp[i][j][k]=0;
    if(i==j)
    {
        if(k)
            return dp[i][j][k]= -a[j];
        else
            return dp[i][j][k]= a[j];
    }
    if(dp[i][j][k]!=-1)
        return dp[i][j][k];
    dp[i][j][k]=0;
    if(!k)
    {
        dp[i][j][k]=max(a[i]+solve(i+1,j,!k),a[j]+solve(i,j-1,!k));
    }
    else
    {
        dp[i][j][k]=min(-a[i]+solve(i+1,j,!k),-a[j]+solve(i,j-1,!k));
    }
    return dp[i][j][k];
}



void solve()
{
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cout<<solve(0,n-1,0)<<endl;
    
    
    
    
    
    
}


int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}






Measured memory_bytes: 141568
N = gets.to_i
h = Hash.new { |k, v| k[v] = 0 }
N.times { h[gets.chomp] += 1 }
M = gets.to_i
M.times { h[gets.chomp] -= 1 }
item = h.sort_by { |k, v| -v }.detect { |k, v| v >= 0 }
p item.nil? ? 0 : item[1]

Measured memory_bytes: 1788
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

const int maxn = 5000;

int main() {
  int n;
  int right_cost, left_cost;
  scanf("%d %d %d", &n, &right_cost, &left_cost);
  vector<int> perm(n), invperm(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &perm[i]), --perm[i];
    invperm[perm[i]] = i;
  }

  vector<lint> prev_dp(n + 1);
  vector<lint> dp(n + 1, 0LL);
  for (int v = n - 1; v >= 0; --v) {
    swap(dp, prev_dp);

    int my_pos = invperm[v];
    int bigger_before = 0;
    for (int i = 0; i < my_pos; ++i)
      if (perm[i] > v)
        ++bigger_before;

    for (int i = 0; i <= n; ++i) {
      lint &res = dp[i];

      if (my_pos < i) {
        res = prev_dp[i];
      } else if (bigger_before == 0) {
        res = prev_dp[my_pos + 1];
      } else {
        res = min((lint)bigger_before * right_cost + prev_dp[my_pos + 1],
                  left_cost + prev_dp[i]);
      }

      if (0 <= i && i < my_pos && perm[i] > v)
        --bigger_before;
    }
  }

  printf("%lld\n", dp[0]);

  return 0;
}


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

using namespace std;

int main() {
    int a, b, c, d, e, k;
    vector<int> point(5);
    for (int i = 0; i < 5; ++i) {
        cin >> point[i];
    }
    cin >> k;

    bool check = true;
    for (int i = 0; i < point.size(); ++i) {
        for (int j = i; j < point.size() - 1; ++j) {
            if (point[j + 1] - point[i] > k) {
                check = false;
                break;
            }
        }
    }

    if (check) {
        cout << "Yay!\n";
    } else {
        cout << ":(\n";
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fr(i, a, b) for (ll i = a; i < b; i++)

int main() {
    ios::sync_with_stdio(false);
    #ifdef CODE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int x;
    cin >> x;
    if (x >= 30) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		    Scanner sc = new Scanner(System.in);
		    int n = sc.nextInt();
		    int[] b = new int[n-1];
		    int ans =0;
		    for(int i=0;i<n-1;i++) {
		    	b[i] = sc.nextInt();
		    	if(i==0) {
		    		ans += 2*b[i];
		    	}else{
		    		if(b[i]>b[i-1]){
		    			ans += b[i];
		    		}else {
		    			ans -= b[i-1];
		    			ans += 2*b[i];
		    		}
		    	}
		    }
		    System.out.println(ans);

		    sc.close();
	}
}


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

int main(void){
    int n;
    char c[36][3],d[36][3];
    cin>>n;
    int i,j;
    for(i=0;i<n;i++){
        cin>>c[i];
        for(j=0;j<3;j++)d[i][j]=c[i][j];
    }
    char swap[3];
    for(i=0;i<n;i++){
        for(j=n-1;j>i;j--){
            if(c[j-1][1]>c[j][1]){
                swap[0]=c[j][0];
                c[j][0]=c[j-1][0];
                c[j-1][0]=swap[0];
                
                swap[1]=c[j][1];
                c[j][1]=c[j-1][1];
                c[j-1][1]=swap[1];
            }
        }
    }
    
    for(i=0;i<n-1;i++){
        cout<<c[i]<<" ";
    }
    cout<<c[n-1]<<endl;
    cout<<"Stable"<<endl;
    
    char min;
    for(i=0;i<n-1;i++){
        min=i;
        for(j=i;j<n;j++){
            if(d[min][1]>d[j][1]){
                min=j;
            }
        }
        if(min!=i){
            swap[0]=d[min][0];
            d[min][0]=d[i][0];
            d[i][0]=swap[0];
                
            swap[1]=d[min][1];
            d[min][1]=d[i][1];
            d[i][1]=swap[1];
        }
    }
    
    bool isstable=1;
    for(i=0;i<n;i++){
        if(c[i][0]!=d[i][0]){
            isstable=0;
        }
    }
    for(i=0;i<n-1;i++){
        cout<<d[i]<<" ";
    }
    cout<<d[n-1]<<endl;
    if(isstable)cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int n;
char str[100100];
bool wlf[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	scanf("%s",str);
	for(int i=0;i<4;i++){
		wlf[0]=i&1;
		wlf[1]=(i>>1)&1;
		for(int j=2;j<n;j++){
			wlf[j]=wlf[j-1]^wlf[j-2]^(str[j-1]=='x');
		}
		bool flg=true;
		for(int i=0;i<n;i++){
			int le=(i-1+n)%n;
			int ri=(i+1+n)%n;
			if(wlf[ri]!=wlf[i]^wlf[le]^(str[i]=='x'))
			{
				flg=false;
				break;
			}
		}
		if(flg){
			for(int i=0;i<n;i++){
				if(wlf[i])
					cout<<'W';
				else
					cout<<'S';
			}
			cout<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n;
  cin>>n;
  int f[100][10];
  rep(i,n)rep(j,10)cin>>f[i][j];
  int p[100][11];
  rep(i,n)rep(j,11)cin>>p[i][j];
  ll ans=(ll)-INF*INF;
  int bit;
  loop(bit,1,1<<10){
    ll sum=0;
    rep(i,n){
      int c=0;
      rep(j,10)if(f[i][j] && (bit&(1<<j)))c++;
      sum+=p[i][c];
    } 
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
}


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

int main(){
  long long n,T;
  cin >> n >> T;
  vector<long long> t(n);
  long long ans = 0;
  
  for(auto i=0;i<n;i++){
    cin >> t.at(i);
  }
  vector<long long> endtime(n+1);
  endtime.at(0) = 0;
  for(auto i=0;i<n;i++){
    //long long dt = t.at(i+1)-t.at(i);
    if(endtime.at(i)>t.at(i)){
      endtime.at(i+1) = t.at(i) + T;
      ans += (endtime.at(i+1)-endtime.at(i));
    }
    else{
      ans +=T;
      endtime.at(i+1) = t.at(i) + T;
    }
  }
  cout << ans<< endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, g;
  cin >> n >> g;
  rep(i, n - 1) {
    ll a;
    cin >> a;
    g = __gcd(g, a);
  }
  ll ans = 0;
  while(g % 2 == 0) {
    ans++;
    g /= 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

	int n = scan.nextInt();
	int k = scan.nextInt();
	int[] x = new int[n];
	for(int i = 0; i < n; i++){
	    x[i] = scan.nextInt();
	}

	int sum = 0;
	for(int i = 0; i < n; i++){
	    sum += Math.min(Math.abs(x[i]), Math.abs(x[i]-k))*2;
	}

	System.out.println(sum);
    }
}



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

int main(){
    int N;
    cin>>N;
    for(int i=1;i<=9;i++){
        if((N/i)<=9&&i*(N/i)==N){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);  
    int A,B,C;
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    sort(v.begin(),v.end());
    cout << 10*v[2]+v[1] + v[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#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, a;
    cin >> n >> a;
    vector<int64_t> x(n);
    vector<int64_t> y(n);
    vector<pair<int64_t, int64_t>> p(n);
    for (int i = 0; i < n; i++) {
        cin >> x.at(i) >> y.at(i);
        p.at(i) = make_pair(x.at(i), y.at(i));
    }

    sort(begin(x), end(x));
    sort(begin(y), end(y));
    int64_t ans = INT64_MAX;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = 0; k < n; k++) {
                for (int l = k + 1; l < n; l++) {
                    int64_t x_min = x.at(i);
                    int64_t x_max = x.at(j);
                    int64_t y_min = y.at(k);
                    int64_t y_max = y.at(l);
                    int cnt = 0;
                    for (int m = 0; m < n; m++) {
                        int64_t cur_x = p.at(m).first;
                        int64_t cur_y = p.at(m).second;
                        if (x_min <= cur_x && cur_x <= x_max && y_min <= cur_y && cur_y <= y_max) {
                            cnt++;
                        }
                    }
                    if (cnt >= a) {
                        int64_t area = (x_max - x_min) * (y_max - y_min);
                        chmin(ans, area);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
    char station[53]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int num,i,place,a[101];
    char string[101];
    while (scanf("%d",&num)!=EOF&&num!=0) {
        for (i=0; i<num; i++) scanf("%d",&a[i]);
        scanf(" %s",string);
        for (i=0; i<strlen(string); i++) {
            if (islower(string[i])) {
                place=string[i]-'a'-a[i%num];
            } else {
                place=string[i]-'A'+26-a[i%num];
            }
            if (place<0) place+=52;
            printf("%c",station[place]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 576
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
	int L, i, j, k, l, A, B, C, D, tmp;
	char c;
	scanf("%d", &L);
	char *S = (char *)malloc(sizeof(char) * (L + 1));
	char *T = (char *)malloc(sizeof(char) * (L + 1));
	char *strtmp;
	scanf("%s", S);
	scanf("%s", T);
	for(A = 0; S[A] != '\0'; A++){}
	for(B = 0; T[B] != '\0'; B++){}
	C = (2 * L) / A + 2;
	D = (2 * L) / B + 2;
	char *Srep = (char *)malloc(sizeof(char) * (A * C + 1));
	char *Trep = (char *)malloc(sizeof(char) * (B * D + 1));
	for(i = 0; i < A * C; i++){
		Srep[i] = S[i % A];
	}
	for(i = 0; i < B * D; i++){
		Trep[i] = T[i % B];
	}
	Srep[A * C] = '\0';
	Trep[B * D] = '\0';
//	printf("Srep:%s\n", Srep);
//	printf("Trep:%s\n", Trep);
	if(strcmp(Srep, Trep) > 0){
		strtmp = S;
		S = T;
		T = strtmp;
		tmp = A;
		A = B;
		B = tmp;
	}
	for(l = 0; B * l <= L; l++){
		if((L - B * l) % A == 0){
			k = (L - B * l) / A;
			break;
		}
	}
	for(i = 0; i < k; i++){
		for(j = 0; j < A; j++){
			printf("%c", S[j]);
		}
	}
	for(i = 0; i < l; i++){
		for(j = 0; j < B; j++){
			printf("%c", T[j]);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2304
def warshall_floyd(n, dists):
    prev = [t.copy() for t in dists]

    for k in range(n):
        current = [[0] * n for _ in range(n)]
        prev_k = prev[k]
        for i in range(n):
            prev_i, current_i = prev[i], current[i]
            prev_i_k = prev_i[k]
            for j in range(n):
                current_i[j] = min(prev_i[j], prev_i_k + prev_k[j])
        prev = current

    return prev


def solve(n, links, total_d, odd_vertices):
    if not odd_vertices:
        return total_d

    d_table = warshall_floyd(n, links)
    d_table = [[d for oj, d in enumerate(d_table[oi]) if oj in odd_vertices] for ni, oi in enumerate(odd_vertices)]
    ndt = len(d_table)
    bit_dict = {1 << i: i for i in range(ndt)}

    def minimum_pair(remains):
        if not remains:
            return 0
        b = remains & -remains
        remains ^= b
        i = bit_dict[b]
        return min(minimum_pair(remains ^ (1 << j)) + d_table[i][j] for j in range(ndt) if remains & (1 << j))

    return total_d + minimum_pair((1 << ndt) - 1)


v, e = map(int, input().split())

dists = [[float('inf')] * v for _ in range(v)]
for i in range(v):
    dists[i][i] = 0
odd_vertices = [0] * v
total_d = 0

for _ in range(e):
    s, t, d = map(int, input().split())
    dists[s][t] = min(dists[s][t], d)
    dists[t][s] = min(dists[t][s], d)
    odd_vertices[s] ^= 1
    odd_vertices[t] ^= 1
    total_d += d

print(solve(v, dists, total_d, [i for i, v in enumerate(odd_vertices) if v]))

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

using namespace std;

long long UNIT = 1000000007;

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

    vector<bool> broken(N+1, false);
    vector<long long> C(N+1, 0);
    for(int i = 0;i < M; i++) {
        int tmp;
        cin >> tmp;

        broken[tmp] = true;
    }

    
    C[1] = !broken[1] ? 1 :0;
    if(!broken[2] && !broken[1]) {
        C[2] = 2;
    } else if(broken[2]) {
        C[2] = 0;
    } else {
        C[2] = 1;
    }
    for(int i = 3; i <= N; i++) {
        if (broken[i]) C[i] = 0;
        else C[i] = (C[i-1] + C[i-2]) % UNIT;
    }

    cout << C[N] << endl;

    // long long count = 1;
    // for(int i = 2;i <= N; i+=2) {
    //     bool c1 = broken[i-1];
    //     bool c2 = broken[i-2];
    //     if(c1&&c2) {
    //         cout << 0 <<endl;
    //         return 0;
    //     } else if ((!c1)&&(!c2)) {
    //         count *= 2;
    //         count %= UNIT;
    //     } 
    // }

    // cout << count  << endl;


}

Measured memory_bytes: 1024
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <limits.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, N, X, x[100000], a[100000], r;
	cin >> N >> X;
	for (i; i < N; i++) {
		cin >> x[i];	a[i] = llabs(X-x[i]);
	}

	ans = a[0];
	for (i = 1; i < N; i++) {
		if (ans < a[i]) {
			int temp;
			temp = ans;
			ans = a[i];
			a[i] = temp;
		}

		r = ans%a[i];
		while (r != 0) {
			ans = a[i];
			a[i] = r;
			r = ans%a[i];
		}
		ans = a[i];
	}

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

Measured memory_bytes: 1792
#include "bits/stdc++.h"

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;



void solve() {
	int n, a;
	cin >> n >> a;


	cout << ((n % 500 <= a )? "Yes" : "No") << endl;
}


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

	solve(); 
	return 0;
}

Measured memory_bytes: 256
n=int(input())
s=list(input())
t=['a']*(len(s))
list=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for i in range(len(s)):
    c=list.index(s[i])+n if list.index(s[i])+n <= 25 else list.index(s[i])+n-26
    t[i]=list[int(c)]
print(*t,sep='')

Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
string s,t;
int dp[3001][3001];
int LCS(int i,int j){
    if(dp[i][j]!=-1) return dp[i][j];
    if(s[i]=='\0' || t[j]=='\0') return 0;
    if(s[i]==t[j])
        return dp[i][j]=1+LCS(i+1,j+1);
    return dp[i][j]=max(LCS(i+1,j),LCS(i,j+1));
}
string r;
void printLCS(int i,int j){
    if(s[i]=='\0' || t[j]=='\0') {
        cout<<r<<'\n';
        return;
    }
    if(s[i]==t[j]){
        r+=s[i];
        printLCS(i+1,j+1);
    } else{
        if(dp[i+1][j]>dp[i][j+1]) printLCS(i+1,j);
        else printLCS(i,j+1);
    }
}
int main(){
    memset(dp,-1,sizeof(dp));
    cin >> s >> t;
    LCS(0,0);
    printLCS(0,0);
    // while(1);
    return 0;
}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
typedef long long ll;
const int maxn = 100005;
const int maxm = 105;
const int mod = 998244353;
const int inf = 1e9 + 7;
//head
typedef pair<int, int> pii;
int n, v[maxn];
map<int, int> cnt1, cnt2;
int main() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> v[i];
        if(i & 1) cnt1[v[i]]++;
        else cnt2[v[i]]++;
    }
    vector<pii> v1, v2;
    for(auto p : cnt1) {
        v1.pb({p.se, p.fi});
    }
    for(auto p : cnt2) {
        v2.pb({p.se, p.fi});
    }
    sort(all(v1)), sort(all(v2));
    vector<pii> ans1, ans2;
    ans1.pb(v1.back()), ans2.pb(v2.back());
    for(int i = sz(v1)-2; i >= 0; --i) {
        if(v1[i].se != ans1[0].se) {
            ans1.pb(v1[i]);
            break;
        }
    }
    for(int i = sz(v2)-2; i >= 0; --i) {
        if(v2[i].se != ans2[0].se) {
            ans2.pb(v2[i]);
            break;
        }
    }
    int ans = inf;
    bool same = true;
    for(auto p : ans1) {
        for(auto p2 : ans2) {
            if(p.se != p2.se) {
                ans = min(ans, n - p.fi - p2.fi);
                same = false;
            }
        }
    }
    if(same) ans = min(ans, n - max(ans1[0].fi, ans2[0].fi));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6520
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    string S; cin >> S;
    if(S == "SUN") Out(7);
    else if(S == "MON") Out(6);
    else if(S == "TUE") Out(5);
    else if(S == "WED") Out(4);
    else if(S == "THU") Out(3);
    else if(S == "FRI") Out(2);
    else if(S == "SAT") Out(1);

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <bitset>
using namespace std;
const int INF = 1147483647;

bitset<10005> all[15];
int r, c;

//int count(){
//	int out = 0;
//	for (int i = 0; i < all.size(); ++i){
//		for (int j = 0; j < r; ++j){
//			if (((1 << j)&all[i]) == 0){
//				++out;
//			}
//		}
//	}
//	return out;
//}
//
//void show(){
//	for (int i = 0; i < r; ++i){
//		for (int j = 0; j < c; ++j){
//			if (all[j] & (1 << i)){
//				cout << 1 << ' ';
//			}
//			else{
//				cout << 0 << ' ';
//			}
//		}
//		cout << endl;
//	}
//	cout << count() << endl;
//}
//
//
//void dfs(map<vector<int>,int> &stu){
//	show();
//	for (int i = 0; i < r; ++i){
//		for (int j = 0; j < all.size(); ++j){
//			if (all[j] & (1 << i)){
//				all[j] = all[j] & (~(1 << i));
//			//	cout << ((1 << i)) << endl;
//			//	cout << (~(1 << i)) << endl;
//			}
//			else{
//				all[j] = all[j] | (1 << i);
//			}
//		}
//
//		if (stu.count(all) == 0){
//			int t = count();
//			stu[all] = t;
//			out = max(t, out);
//			dfs(stu);
//		}
//
//		for (int j = 0; j < all.size(); ++j){
//			int cache = all[j];
//			if (all[j] & (1 << i)){
//				all[j] = all[j] & (~(1 << i));
//			}
//			else{
//				all[j] = all[j] | (1 << i);
//			}
//		}
//	}
//	for (int i = 0; i < all.size(); ++i){
//		int tmp = 0;
//		for (int j = 0; j < r; ++j){
//			tmp = tmp | (1 << j);
//		}
//		int cache = all[i];
//		all[i] = ~all[i] & tmp;
//		if (stu.count(all) == 0){
//			int t = count();
//			stu[all] = t;
//			out = max(t, out);
//			dfs(stu);
//		}
//		all[i] = cache;
//	}
//}
//
//void solve(){
//	out = -1;
//	map<vector<int>, int> stu;
//	dfs(stu);
//	cout << out << endl;
//}
//

int count(){
	int out = 0;
	for (int j = 0; j < c; ++j){
		int tmp = 0;
		for (int i = 0; i < r; ++i){
			if (all[i][j] == 0)
				++tmp;
		}
		out += max(tmp, r - tmp);
	}
	return out;
}
void show(){
	for (int i = 0; i < r; ++i){
		for (int j = 0; j < c; ++j){
			cout << all[i][j] << ' ';
		}
		cout << endl;
	}
	cout << count() << endl;
}
void solve(){
	int out = -1;
	for (int i = 0; i < (1 << r); ++i){
		for (int j = 0; j < r; ++j){
			if (i&(1 << j)){
				all[j].flip();
			}
		}
		//show();
		out = max(out, count());

		for (int j = 0; j < r; ++j){
			if (i&(1 << j)){
				all[j].flip();
			}
		}
	}
	cout << out << endl;
}
int main(){
//	freopen("p_2.1.11.txt", "r", stdin);
//	freopen("a.out", "w",stdout);
	while (true){
		scanf("%d %d", &r, &c); 
		if (r == 0 && c == 0)
			break;

		int tmp;
		for (int i = 0; i < r; ++i){
			for (int j = 0; j < c; ++j){
				scanf("%d", &tmp);
				all[i][j] = tmp;
			}
		}

		solve();
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i = 0; i < n; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int a = 0, b = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 == 0){
      a += vec.at(i);
    }else{
      b += vec.at(i);
    }
  }
  cout << a - b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    long long int n,x,ans=0;
    scanf("%lld%lld", &n,&x);
    long long int a[n],sum[n-1];
    for(long long int i=0; i<n; i++) scanf("%lld", &a[i]);

    if(a[0]>x)
    {
        ans=ans+(a[0]-x);
        a[0]=x;
    }
    for(long long int i=0; i<n-1; i++)
    {
        if(a[i]+a[i+1]>x)
        {
            ans+=a[i]+a[i+1]-x;
            a[i+1]=x-a[i];
        }
    }
    printf("%lld", ans);
    return 0;
}

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

int main(){
	int prime[100005],n,pri[100005],nn=0;
	cin>>n;
	memset(prime,0,sizeof(prime));
	prime[0]=1;
	prime[1]=1;
	for(int i=2;i<=100003;i++){
		if(!prime[i]){
			nn++;
			pri[nn]=i;
			for(int j=i+i;j<=100003;j+=i){
				prime[j]=1;
			}
		}
	}
	for(int i=1;i<=n;i++){
		int l,r;
		cin>>l>>r;
		int ll=1,rr=nn,sl;
		while(ll+1<rr){
			int mid=(ll+rr)/2;
			if(pri[mid]<=l){
				ll=mid;
			}else{
				rr=mid;
			}
		}
		sl=ll;
		ll=1;
		rr=nn;
		while(ll+1<rr){
			int mid=(ll+rr)/2;
			if(pri[mid]>=r){
				rr=mid;
			}else{
				ll=mid;
			}
		}
		//cout<<sl<<" "<<rr<<endl;
		sl=max(1,sl-3);
		rr=min(nn,rr+3);
		int s=0;
		for(int j=sl;j<=rr;j++){
			if(pri[j]>=l&&pri[j]<=r){
				//cout<<pri[j]<<" ";
				if(!prime[(pri[j]+1)/2]){
					s++;
				}
			}
		}
		cout<<s<<endl;
	}	
}



Measured memory_bytes: 4020
#include <stdio.h>

int main(void){
    // Your code here!
    char num[2][101];
    int cnt[2] = {},cntindex=0,index=0;
    char ch;
    
    while((ch = getchar()) != EOF){
        if(ch == '\n'){
            cntindex=1;
            index=0;
            continue;
        }
        
        num[cntindex][index++]=ch;
        cnt[cntindex]++;
    }
    
    if(cnt[0] > cnt[1]){
        printf("GREATER\n");
    }
    else if(cnt[0] < cnt[1]){
        printf("LESS\n");
    }
    else{
        int i;
        for(i = 0; i < cnt[0]; i++){
            if(num[0][i] > num[1][i]){
                printf("GREATER\n");
                break;
            }
            else if(num[0][i] < num[1][i]){
                printf("LESS\n");
                break;
            }
        }
        
        if(i == cnt[0]){
            printf("EQUAL\n");
        }
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int num,m,current;
    cin >> num >> m;
    queue<int> caution;
    for(int i =0;i<m;i++){
        cin >> current;
        caution.push(current);
    }

    long ans = 1;
    long how[100010]={};
    how[0]=1;
    how[1]=1;
    how[2]=2;
    for(int i=3;i<100005;i++){
        how[i]=(how[i-1]+how[i-2])%1000000007;
    }
    current = -1;

    while(caution.size()!=0){
        if(caution.front()-current==0){
        }else if(caution.front()-current==1){
            ans *= 0;
        }else{
            ans *= how[caution.front()-current-2];
        }
        current = caution.front();
        caution.pop();
        ans %= 1000000007;
    }

    ans *= how[num-current-1];

    
    ans %= 1000000007;


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

Measured memory_bytes: 1408