akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a = {}
ans = 0
for i in range(1,10):
    for j in range(1,10):
        a[i,j] = 0

for i in range(1,N+1):
    top = int(str(i)[0])
    low = int(str(i)[-1])
    if top == 0 or low == 0:
        continue
    a[top, low] += 1
    if top == low:
        ans += a[low,top] * 2 -1
    else:
        ans += a[low,top] * 2


print(ans)
    

        


Measured memory_bytes: 3064
import collections
N = int(input())
V = list(map(int, input().split()))

ans = 0
eve = V[0::2]
odd = V[1::2]
cntEve = collections.Counter(eve)
cntOdd = collections.Counter(odd)

if cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]:
    if len(cntEve) == 1 and len(cntOdd) > 1:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1]) - cntOdd.most_common()[1][1]
    elif len(cntEve) > 1 and len(cntOdd) == 1:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1]) - cntEve.most_common()[1][1]
    elif len(cntEve) == 1 and len(cntOdd) == 1:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1])
    else:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1]) - max(cntEve.most_common()[1][1],cntOdd.most_common()[1][1])
else:
    ans = N - int(cntEve.most_common()[0][1]) - int(cntOdd.most_common()[0][1])

print(ans)

Measured memory_bytes: 24620
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        while(true) {
            String str = stdIn.next();
            if(str.equals("-")) {
                break;
            }
            int m = stdIn.nextInt();
            for(int i = 0; i < m; i++) {
                int length = stdIn.nextInt();
                str = str.substring(length) + str.substring(0, length);
            }
            System.out.println(str);

        }
    }
}


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

int terms[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

signed main(){
  int i;
  cin >> i;
  cout << terms[i - 1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 1000000

/* Factorial modulo MOD */
LL fact[2*MAX];
char s[2*MAX];

void factorial() {
	fact[0] = 1;
	for(int i=1;i<2*MAX;i++) {
		fact[i] = (i * fact[i-1]) % MOD;
	}
}

/* Modulo exponentiation */
LL power(LL base, LL exp, LL ans) {
	if(!exp) return ans % MOD;
	if(exp&1) ans = (ans * base) % MOD;
	return power((base * base) % MOD, exp>>1, ans);
}

/* nCr modulo MOD */
LL nCr(LL n, LL r) {
	if(n < r) return 0;
	LL numerator = fact[n];
	LL denominator = (fact[n-r] * fact[r]) % MOD;
	return (numerator * power(denominator, MOD-2, 1)) % MOD;
}

int main() {

	int k, n, i;
	LL ans = 0;
	factorial();
	
	cin>>k;
	cin>>s;

	n = strlen(s);
	for(i = 0 ; i <=k ; i++) {

		LL lp = power(26, i, 1);

		LL rp = (power(25, k-i, 1) * nCr(k-i + n -1, n-1)) % MOD;
		ans = (ans + (lp * rp) % MOD) %MOD;
	}

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



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

using namespace std;

typedef long long ll;

int main(){
	int n, m;
	cin >> n >> m;
	int in[n];
	bool red[n];
	fill(in, in+n, 1);
	fill(red, red+n, false);
	red[0] = true;
	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		x--, y--;
		in[x]--;
		in[y]++;
		if(red[x])red[y] = true;
		if(!in[x])red[x] = false;
		//for(int i = 0; i < n; i++)cout << in[i] << ' ';cout << endl;
	}
	int ans = 0;
	for(int i = 0; i < n; i++)if(red[i])ans++;
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int n; cin>>n; ll arr[n]; for(int i=0;i<n;i++)cin>>arr[i];
    sort(arr,arr+n); int p=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                ll a=arr[i],b=arr[j],c=arr[k];
                if(a+b>c && a+c>b && b+c>a && a!=b && b!=c && a!=c)p++;
            }
        }
    } cout<<p;
 }


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll n, p, ans = 1, cnt;
    cin >> n >> p;
    for (ll i = 2; i * i <= p; ++i) {
        if (p % i) continue;
        cnt = 0;
        while (p % i == 0) {
            ++cnt;
            p /= i;
        }
        for (ll j = 0; j < cnt / n; ++j) ans *= i;
    }
    if (n == 1) ans *= p;
    cout << ans << endl;
    return 0;
}


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

int main() {
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    int l[Q], r[Q];
    for (int i = 0; i < Q; i++) {
        cin >> l[i] >> r[i];
    }

    int numAC[N+1]; // num[i]はSのiから左の部分文字列に存在する"AC"の総数
    for (int i = 0; i <= N; i++) numAC[i] = 0;

    for (int i = 1; i < N; i++) {
        if (S[i-1] == 'A' && S[i] == 'C') numAC[i+1] = numAC[i] + 1;
        else numAC[i+1] = numAC[i];
    }

    for (int i = 0; i < Q; i++) {
        cout << numAC[r[i]] - numAC[l[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	long long A,B,C,X,Y;
	cin>>A>>B>>C>>X>>Y;
	
	long long ans = Inf;
	
	for(long long i=0;i<=1000000;i+=2){
		int x = X-i/2;
		int y = Y-i/2;
		long long a = i*C;
		
		a += A*max(x,0);
		a += B*max(y,0);
		ans = min(ans,a);
	}
	
	cout<<ans<<endl;
		
    return 0;
}


Measured memory_bytes: 256
N,M,X,Y = map(int,input().split())
xs = [int(i) for i in input().split()]
ys = [int(i) for i in input().split()]

xmax = max(xs)
ymin = min(ys)


zs = [i for i in range(X+1,Y+1)]
warflg = True
for z in zs:
    if xmax<z and z<=ymin:
        warflg = False

if warflg:
    print("War")
else:
    print("No War")



Measured memory_bytes: 3060
#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;
  rep(i,n){
    int h,m;
    scanf("%d:%d",&h,&m);
    double a=30*h+m/2.0;
    double b=6*m;
    if(a>b)swap(a,b);
    if(b-a<30 || a+360-b<30)cout<<"alert"<<endl;
    else if(b-a>=90 && a+360-b>=90)cout<<"safe"<<endl;
    else cout<<"warning"<<endl;
  }
}

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


int main(){
    int n, k, j;
    cin >> n >> k;
    double p = 0;
    for (int i=1; i<=n; i++){
        int sum=i;
        for (j=0;;j++){
            if (sum>=k) break;
            sum *= 2;
        }
        double q=1;
        for (int x=0; x<j; x++) q *= 0.5;
        p += q;
    }
    p /= n;
    printf("%.16f", p);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define print(i) std::cout << (i) << '\n'
inline long long ceildiv(long long a, long long  b) { return (a+b-1)/b; }
typedef pair<long long,long long> P;
const long long inf = 10e7;
//int |x|<=2*10**9     long |x|<= 9*10**18
typedef pair<int,string> PP;
#define ll long long
int memo[100005];
bool done[100005];
vector<int> edges[100005];
int dp(int x){
if (done[x])return memo[x];
int ret=0;done[x]=true;
for (int y:edges[x]){ret=max(ret,dp(y)+1); }
return memo[x]=ret;}
int main(){
int n,m ;cin>>n>>m;
rep(i,m){int a,s;cin>>a>>s;edges[--a].emplace_back(--s);}
int ans=0;
rep(j,n){ans=max(ans,dp(j));}
print(ans);
}

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

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

    int x;
    cin >> x;

    int rem = x%1000;
    rem = (1000 - rem)%1000;

    cout << rem << endl;
}



Measured memory_bytes: 3636
#include <stdio.h>

int main() {
    int a;
    scanf("%d",&a);
    int array[1000000];
    array[0]=a;
    int res = 0;
    int i = 0;
    while(res == 0){
        
        if (array[i]%2 == 0){
            array[i+1] = array[i]/2;
        }else{
            array[i+1] = 3*array[i]+1;
        }
        for(int t=0; t <= i-1 ;t++){
            if (array[i+1] == array[t]){
                res = 1;
            }
        }

        i++;
    }
    printf("%d\n", i+1);
  
    
    return 0;
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;


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

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans = 1e5;
    ans = min(abs(a+b-c-d),min(abs(a-b+c-d),abs(a-b-c+d)));
    cout << ans << endl;

}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long X=1000000000+7;

int main() {
  int n;
  long long k;
  cin>>n>>k;
  pair<int,int> ab[100009];
  rep(i,n)
    cin>>ab[i].first>>ab[i].second;
  sort(ab,ab+n);
  
  int ans,count=0;
  long long sum=0;
  while(sum<k && count<n){
    ans=ab[count].first;
    sum+=ab[count].second;
    count++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int count_do(const string& S) {
  string before, after;
  before += S[0];
  ll count = 1;
  for (ll i = 1; i < S.length();) {
    do {
      after += S[i];
      i++;
      if (i == S.length()) {
        if (before != after) count++;
        return count;
      }
    } while (before == after);
    count++;
    before = after;
    after.clear();
  }
  return count;
}

int main() {
  string S;
  cin >> S;
  ll ans1 = count_do(S);
  reverse(begin(S), end(S));
  ll ans2 = count_do(S);

  cout << max(ans1, ans2) << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
    while(true) {
        int n;
        cin >> n;
        if(!n) break;

        n = 1000-n;
        int cnt = 0;
        cnt += n/500;
        n %= 500;
        cnt += n/100;
        n %= 100;
        cnt += n/50;
        n %= 50;
        cnt += n/10;
        n %= 10;
        cnt += n/5;
        n %= 5;
        cnt += n;
        cout << cnt << endl;
    }
    return 0;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	string a,b,c;
	cin >> a >> b >> c;
	bool check = true;
	if(a[a.length()-1] != b[0]) check = false;
	if(b[b.length()-1] != c[0]) check = false;
	if(check) cout << "YES\n";
	else cout << "NO\n";	
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef unsigned long long ull;
const int IINF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

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

	bool b[20000];
	fill(b, b+20000, true);
	b[0] = b[1] = false;
	REP(i, 20000) {
		if(b[i]) {
			for(int j=i*2; j<20000; j += i)
				b[j] = false;
		}
	}
	vi prime;
	REP(i, 20000)
		if(b[i]) prime.pb(i);

	int n;
	while(cin >> n, n) {
		int f = 0, l = 0, sum = 0, cnt = 0;;
		while(true) {
			if(f == prime.size() || l == prime.size())
				break;
			if(sum == n)
				cnt++;
			if(sum <= n) {
				sum += prime[f];
				f++;
			}
			else if(sum > n) {
				sum -= prime[l];
				l++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1272
#include <stdio.h>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;
#define F first
#define S second
#define MP make_pair
const int N=5e5+10;
const ll INF=1LL<<60;
ll dis(pi a,pi b){
    ll x=a.F-b.F,y=a.S-b.S;
    return x*x+y*y;
}
int main(){
    int n,lim;
    ll ans=INF;
    pi a[N];
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d%d",&a[i].F,&a[i].S);
    sort(a,a+n);
    lim=min(10000,n);
    for(int i=0;i<lim;i++)for(int j=i+1;j<lim;j++)ans=min(ans,dis(a[i],a[j]));
    for(int i=lim;i<n;i++)for(int j=1;j<lim;j++)ans=min(ans,dis(a[i],a[i-j]));
    printf("%lld\n",ans);
}


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

using namespace std;
int f[100010];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0;i < n;i++)
    {
        int x;
        cin >> x;
        x++;
        f[x]++;
        f[x-1]++;
        f[x+1]++;
    }
    int ans = 0;
    for(int i = 0;i < 100010;i++)
    {
        ans = max(ans,f[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;

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

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

int main(){
	bool student[31]={},flag=false;
	int s;
	for(int i=1;i<29;i++){
		cin>>s;
		student[s]=true;
	}
	for(int i=1;i<31;i++){
		for(int j=1;j<31;j++){
			if(i!=j&&(student[i]==false&&student[j]==false)){
				cout<<min(i,j)<<endl<<max(i,j)<<endl;
				flag=true;
				break;
			}
		}
		if(flag==true)break;
	}
	return 0;
}

Measured memory_bytes: 1160
// a. 8 queens problem
#include<iostream>
 
using namespace std;
 
#define N 8
#define FREE -1
#define NOT_FREE 1
 
int row[N], col[N], dpos[2 * N - 1], dneg[2 * N - 1];
 
bool X[N][N];
 
void initialize() {
  for (int i = 0; i < N; i++) {
    row[i] = FREE;
    col[i] = FREE;
  }
  for (int i = 0; i < 2 * N - 1; i++) {
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}
 
void printBoard() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (X[i][j]) {
        if (row[i] != j) {
          return;
        }
      }
    }
  }
 
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cout << ((row[i] == j) ? "Q" : ".");
    }
    cout << endl;
  }
}
 
void recursive(int i) {
  if (i == N) {
    printBoard();
    return;
  }
 
  for (int j = 0; j < N; j++) {
    if (col[j] == NOT_FREE ||
        dpos[i + j] == NOT_FREE ||
        dneg[i - j + N - 1] == NOT_FREE) {
      continue;
    }
    row[i] = j; col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;
    recursive(i + 1);
    row[i] = j; col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
  }
}
 
int main(){
  initialize();
 
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      X[i][j] = false;
    }
  }
 
  int k; cin >> k;
  for (int i = 0; i < k; i++) {
    int r, c; cin >> r >> c;
    X[r][c] = true;
  }
 
  recursive(0);
 
  return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
vector<int> arr;
vector<long long> vaal;
long long functFrog(int n){
    if(vaal[n]!=-1) return vaal[n];
    if(n==0) return LONG_MAX;
    if(n==1){
        vaal[n] = abs(arr[n]-arr[n-1]);
        return vaal[n];
    } 
    if(n==2){
        vaal[n] =abs(arr[n]-arr[n-2]);
        return vaal[n];
    }
    if(n>2){
        vaal[n] =min(abs(functFrog(n-1)+abs(arr[n]-arr[n-1])),abs(functFrog(n-2)+abs(arr[n]-arr[n-2])));
        return vaal[n];
    }
}


long long memoSolution(int n){
    vaal[1] = abs(arr[1]-arr[0]);
    if(n>2) vaal[2] = abs(arr[2]-arr[0]);
    for(int i =3;i<n;i++){
        vaal[i] = min(abs(vaal[i-1]+abs(arr[i]-arr[i-1])),abs(vaal[i-2]+abs(arr[i]-arr[i-2])));
    }
    return vaal[n-1];
}

int main(){
    int n;
    cin >> n;
    arr = vector<int>(n);
    vaal = vector<long long>(n,0);
    for(int i=0;i<n;i++) cin >> arr[i];
    long long value = memoSolution(n);
    cout << value << "\n";
    return 0;
}

Measured memory_bytes: 1408
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

int64_t N, M, H[100010];
std::vector<int64_t> E[100010];

void solve()
{
    std::cin >> N >> M;
	for (int64_t i = 0; i < N; i++)
	{
		std::cin >> H[i];
	}
	for (int64_t i = 0; i < M; i++)
	{
		int64_t A, B;
		std::cin >> A >> B;
		A--;
		B--;
		E[A].push_back(B);
		E[B].push_back(A);
	}

	int64_t ans = 0;
	for (int64_t i = 0; i < N; i++)
	{
		bool ok = true;
		for (auto j : E[i])
		{
			if (H[i] <= H[j]) ok = false;
		}

		if (ok) ans++;
	}

	std::cout << ans << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 10196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}


typedef struct
{
    ll w,val;
} node;

ll n,k,mx;

vector<node>v;

ll dp[110][100010];

ll call(ll i,ll w,ll val)
{
    if(val<=0)return 0;

    if(i==n)
        return 1e18;


    if(~dp[i][val]==0)
    dp[i][val]=min(call(i+1,w,val),v[i].w+call(i+1,w,val-v[i].val));

    return dp[i][val];

}



int main()
{

    fastread();

    ll i,j,m,p,a,sum=0,t,b,c,d,cnt=0,q,l,r;


    string str;

    bool flag=true;

    cin>>n>>k;

    memset(dp,-1,sizeof(dp));



    for(i=0; i<n; i++)
    {
        cin>>a>>b;

        v.eb(node{a,b});

        sum+=b;
    }


    for(i=sum; i>=0; i--)
    {

        if(call(0,0,i)<=k)
        {
            cout<<i<<endl;

            return 0;
        }
    }





}


Measured memory_bytes: 89616
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long double solve(vector<long long>& X, vector<long long>& Y, string& dir) {
        int n = X.size();

        vector<long long> L;
        vector<long long> R;
        vector<long long> U;
        vector<long long> D;

        const long long INF = 1LL << 50;
        long long l = INF, r = -INF;
        long long b = INF, t = -INF;
        for(int i = 0; i < n; ++i) {
            if (dir[i] == 'L') {
                L.push_back(X[i]);
            } else if (dir[i] == 'R') {
                R.push_back(X[i]);
            } else if (dir[i] == 'U') {
                U.push_back(Y[i]);
            } else {
                D.push_back(Y[i]);
            }
            if (dir[i] == 'L' || dir[i] == 'R') {
                b = min(b, (long long)Y[i]);
                t = max(t, (long long)Y[i]);
            } else {
                l = min(l, (long long)X[i]);
                r = max(r, (long long)X[i]);
            }
        }

        sort(begin(L), end(L));
        sort(begin(R), end(R));
        sort(begin(U), end(U));
        sort(begin(D), end(D));


        auto calc = [&](long long T) {
            long long ll = l;
            long long rr = r;
            long long tt = t;
            long long bb = b;

            if (L.size() > 0) {
                ll = min(ll, L.front() - T);
                rr = max(rr, L.back() - T);
            }
            if (R.size() > 0) {
                ll = min(ll, R.front() + T);
                rr = max(rr, R.back() + T);
            }
            if (U.size() > 0) {
                bb = min(bb, U.front() + T);
                tt = max(tt, U.back() + T);
            }
            if (D.size() > 0) {
                bb = min(bb, D.front() - T);
                tt = max(tt, D.back() - T);
            }
            return (rr - ll) * (tt - bb);
        };
        long long res = 1LL << 62;
        long long N = 2e8 + 123456;
        for (int i = 0; i <= N; ++i ) {
            res = min(res, calc(i));
        }

        return res / 4.0;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    long long n;
    cin >> n;
    vector<long long> X(n);
    vector<long long> Y(n);
    string D;
    for(int i = 0; i < n; ++i) {
        long long x, y;
        char d;
        cin >> x >> y >> d;
        x *= 2;
        y *= 2;
        X[i] = x;
        Y[i] = y;
        D += d;
    }

    Solution sol;
    cout << sol.solve(X, Y, D) << "\n";


    return 0;
}

Measured memory_bytes: 3064
def main():
    n, m = map(int, input().split())
    w = [0] * n
    v = [0] * n
    for i in range(n):
        w[i], v[i] = list(map(int, input().split()))
    t = sum(v)
    l = [m + 1] * (t + 1)
    l[0] = 0
    for i in range(n):
        for j in range(t, v[i] - 1, -1):
            k = l[j - v[i]] + w[i]
            if k < l[j]:
                l[j] = k
    for i in range(t, 0, -1):
        if l[i] <= m:
            print(i)
            break
main()


Measured memory_bytes: 5108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VI A(N);
    REP(i,N) cin >> A[i];
    sort(A.begin(),A.end(),greater<int>());
    if(A[0] - A[N-1] >= 2){
        cout << "No" << endl;
        return 0;
    }else if(A[0] - A[N-1] == 1){
        int typeA = 0, typeB = 0;
        REP(i,N){
            if(A[i] == A[0]){
                typeB++;
            }else{
                typeA++;
            }
        }

        if(typeB == 1){
            cout << "No" << endl;
            return 0;
        }

        if(typeA + typeB / 2 >= A[0] && typeA+1 <= A[0]){
            cout << "Yes" << endl;
            return 0;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }else{
        if(A[0] == N-1){
            cout << "Yes" << endl;
            return 0;
        }else{
            if(N/2 >= A[0] && 1 <= A[0]){
                cout << "Yes" << endl;
                return 0;
            }else{
                cout << "No" << endl;
                return 0;
            }
        }
    }



}


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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define forr(i,a,b) for(ll i=(a);i<=(b);i++)
#define ford(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define size(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)



int main(void) {
    int N,i,j;
    cin >> N;
    int n[200900];
    int m[200900];
    for(i=0;i<N-1;++i){
       cin >> n[i];
      
    }
     for(i=0;i<N-1;++i){
     
       m[n[i]-1]++;
    }
    for (j=0;j<N;++j){
        
         cout << m[j] << "\n";
    

    }   
    
  return 0;
}

Measured memory_bytes: 5204
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 15;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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

	fread_unlocked(cn, 1, cm, stdin);
	int N = getint(), K = getint(), Q = getint();
	ll A[2002];
	int LR[2002];
	rep1(i, N) A[i] = ((ll)getint() << 16) + i;
	rep(i, N + 2) LR[i] = -1;

	priority_queue<int> q;
	priority_queue<int, vector<int>, greater<int>> q2[2002];
	int q3[2002];
	rep1(i, N) q3[i] = i;
	int kotae = 1e9;
	int saishou = 2e9;
	sort(A + 1, A + N + 1);
	const int m = (1 << 16) - 1;

	for (int i = N; i >= 1; i--) {
		int a = A[i] >> 16;
		int k = A[i] & m;

		int l = (LR[k - 1] == -1) ? k : LR[k - 1];
		int r = (LR[k + 1] == -1) ? k : LR[k + 1];
		LR[l] = r;
		LR[r] = l;

		if (k + k > l + r) swap(q3[l], q3[k + 1]);

		while (q2[q3[k + 1]].size()) {
			int tmp = q2[q3[k + 1]].top();
			q2[q3[l]].push(tmp);
			q2[q3[k + 1]].pop();
		}
		q2[q3[l]].push(a);
		while (q2[q3[l]].size() >= K) {
			int tmp = q2[q3[l]].top();
			q.push(tmp);
			q2[q3[l]].pop();
		}
		while (q.size() >= Q) {
			int tmp = q.top();
			chmin(saishou, tmp);
			q.pop();
		}
		chmin(kotae, saishou - a);
	}

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 10880
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

/*Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}
*/
void insert(int k){
  Node y = NIL;
  Node x = root;//根から探索start
  Node z;//挿入したいノードを格納
    
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){//挿入する場所を探索
  	y=x;
  	if(z->key<x->key) x=x->left;
  	else x=x->right;
  }
  
  z->parent=y;
  if(y==NIL) root=z;//最初の根を設定
  else if(z->key<y->key) y->left=z;//上の探索で見つけた親から左右どちらに入れるか判断
  else y->right=z;
}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      //Node t = treeSearch(root, x);
      //if ( t != NIL ) printf("yes\n");
      //else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      //treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 25120
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()

ll power(ll b,ll e,ll m)
{
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}  
bool isPowerOfTwo(ll x)
{
    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
} 

void solve()
{
  ll n,k;
  cin>>n>>k;
  ll v[n+1]={0};
  ll ans=0;
  while(k--)
  {
    ll x;
    cin>>x;
    while(x--)
    {
      ll a;
      cin>>a;
      v[a]=1;
    }
  }
  rep(i,1,n+1)
  {
    if(!v[i]) ans++;
  }
  cout<<ans;
}
int main()       
{
  fastio
  ll tt=1;
  while(tt--)
  {
    solve();
    cout<<"\n";
  }
  return 0;
}

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

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

    ld hd = ld(h);
    ld md = ld(m);

    ld hAngle = (hd * 30.f) + (md / 60.f * 30.f);
    ld mAngle = md * 6.f;
    ld angleDiff = abs(hAngle - mAngle);
    if(angleDiff > 180.f)
    {
        angleDiff = 360.f - angleDiff;
    }

    ld ad = ld(a);
    ld bd = ld(b);
    ld rad = angleDiff * M_PI / 180.f;
    ld sqrAns = (ad*ad) + (bd*bd) - (cos(rad) * (2 * ad * bd));
    ld ans = sqrt(sqrAns);

    cout << fixed << setprecision(20) << ans;

    return 0;
}


Measured memory_bytes: 4156
N,K=map(int,input().split())
List_First=[[int(i) for i in input().split()] for i in range(N)]
List_a=[i[0] for i in List_First]
List_b=[i[1] for i in List_First]
List_n=[i for i in range(N)]
new_List_n=sorted(List_n,key=lambda x:List_a[x])
new_List_a=[List_a[i] for i in new_List_n]
new_List_b=[List_b[i] for i in new_List_n]
S=0
m=-1
while S<K:
  m+=1
  S+=new_List_b[m]
print(new_List_a[m])
  
  

Measured memory_bytes: 29776
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int n;
  while(cin >> str){
    if(str=="-") break;
    cin >> n;
    for(int i=0,h;i<n;i++){
      cin >> h;
      string cat = str.substr(0,h);
      str.erase(0,h);
      str+=cat;
    }
    cout << str << endl;
  }
}



Measured memory_bytes: 3200
/**
    AUTHOR:JUNSH
    TIME:19/5/25
**/
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rev(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long ll;
inline int read(){
    int f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
const int inf=0x3f3f3f3f;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m,l,r;
    l=-1;r=inf;
    cin>>n>>m;
    while(m--){
        int ll,rr;
        cin>>ll>>rr;
        l=max(ll,l);
        r=min(rr,r);
    }
    if(r<l)cout<<"0"<<endl;
    else{
        cout<<min(n,r-l+1)<<endl;
    }
}


Measured memory_bytes: 256
# D
n, k = map(int, input().split())
v = list(map(int, input().split()))
q = []
ans = 0
for a in range(min(n, k) + 1):
    for b in range(min(n, k) - a + 1):
        # print(a, b)
        if a == 0:
            pass
        else:
            q.extend(v[:a])
        if b == 0:
            pass
        else:
            q.extend(v[-b:])
        q.sort()
        pick = k - (a + b)
        for i in range(min(pick, len(q))):
            # print(i, q)
            if q[0] < 0:
                q.reverse()
                q.pop()
                q.reverse()
            else:
                break
        s = sum(q)
        # print(q, pick, q[:pick], s)
        if ans < s:
            ans = s
        q.clear()
print(ans)


Measured memory_bytes: 3064
s = int(input())

for i in range(s):
  xs = map(int, input().split())
  xs = [x*x for x in xs]
  
  if xs[0]+xs[2] == xs[1] or xs[1]+xs[0] == xs[2] or xs[2]+xs[1]==xs[0]:
    print('YES')
  else:
    print('NO')


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

int N, K, H[200001];
vector<int> A;

int main(){
	scanf("%d%d", &N, &K);
	for(int i = 0; i < N; i++){
		int val;
		scanf("%d", &val);
		H[val]++;
	}
	for(int i = 1; i < 200001; i++)
		if(H[i] > 0) A.push_back(H[i]);
	int sum = 0;
	sort(A.begin(), A.end());
	if(A.size() > K) for(int i = 0; i < A.size() - K; i++) sum += A[i]; 
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 2168
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      m: usize,
      lrd: [(Usize1, Usize1, i64); m]
   }

   let mut to = vec![vec![]; n];
   for &(l, r, d) in lrd.iter() {
      to[l].push((r, d));
      to[r].push((l, -d));
   }

   let mut d = BTreeMap::<usize, i64>::new();
   for i in 0..n {
      if d.contains_key(&i) {
         continue;
      }
      if !dfs(i, 0i64, &mut d, &to) {
         println!("No");
         return;
      }
   }
   println!("Yes");
}

fn dfs(v: usize, now: i64, d: &mut BTreeMap<usize, i64>, to: &Vec<Vec<(usize, i64)>>) -> bool {
   d.insert(v, now);
   let mut b = true;
   for &(u, x) in to[v].iter() {
      if let Some(&v) = d.get(&u) {
         if v != now + x {
            b = false;
         }
      } else {
         b = dfs(u, now + x, d, to);
      }

      if !b {
         break;
      }
   }
   b
}


Measured memory_bytes: 33488
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
int main()
{
    ios;
    string s,k,l="";
    cin>>s>>k;
    for(int i=0;i<k.size()-1;i++)
    {
        l+=k[i];

    }
    if(s==l)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define fi first
#define se second
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
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;}
int const INF = 1001001001;

int N;

void dfs(string s, char c) {
    s.push_back(c);
    if(SZ(s) == N) {
        cout << s << endl;
    }
    else {
        char m = *max_element(all(s));
        m++;
        for(char let = 'a'; let <= m; let++) {
            dfs(s, let);
        }
    }
}


int main()
{
cin >> N;
dfs("", 'a');
return 0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
const int INF = 1 << 30;

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

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

    int dp[n+1][3];
    fill(dp[0], dp[n]+3, INF);
    dp[0][0] = dp[0][1] = dp[0][2] = 0;

    for (int i = 1; i <= n; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i-1];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i-1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i-1];
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << "\n";
    return 0;
}

Measured memory_bytes: 2560
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()
if A + B < 24:
    print(A + B)
else:
    print(A + B - 24)

Measured memory_bytes: 5784
import heapq

x, y, a, b, c = map(int, input().split())
pp = list(map(lambda x: (-int(x), 1), input().split()))
qq = list(map(lambda x: (-int(x), 2), input().split()))
rr = list(map(lambda x: (-int(x), 3), input().split()))

xx = pp + qq + rr
heapq.heapify(xx)
t = x + y
ans = 0
for _ in range(t):
    while len(xx) > 0:
        v = heapq.heappop(xx)
        if v[1] == 1 and x <= 0:
            continue
        if v[1] == 2 and y <= 0:
            continue
        break

    if v[1] == 1:
        x -= 1
    if v[1] == 2:
        y -= 1
    ans += v[0]

print(-ans)


Measured memory_bytes: 43296
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
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; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main()
{
    string S;
    cin >> S;
    int A,B,C,D;
    A = S[0] - '0';
    B = S[1] - '0';
    C = S[2] - '0';
    D = S[3] - '0';

    if(A + B + C + D == 7)
    {
        cout << A << '+'  << B << '+'  <<C  << '+'  <<D  << "=7" << endl;
        return 0;
    }
    if(A + B + C - D == 7)
    {
        cout << A << '+'  << B << '+'  <<C  << '-'  <<D  << "=7" << endl;
        return 0;
    }
    if(A + B - C + D == 7)
    {
        cout << A << '+'  << B << '-'  <<C  << '+'  <<D  << "=7" << endl;
        return 0;
    }
    if(A - B + C + D == 7)
    {
        cout << A << '-'  << B << '+'  <<C  << '+'  <<D  << "=7" << endl;
        return 0;
    }
    if(A - B - C + D == 7)
    {
        cout << A << '-'  << B << '-'  <<C  << '+'  <<D  << "=7" << endl;
        return 0;
    }
    if(A - B  + C - D == 7)
    {
        cout << A << '-'  << B << '+'  <<C  << '-'  <<D  << "=7" << endl;
        return 0;
    }
    if(A + B - C - D == 7)
    {
        cout << A << '+'  << B << '-'  <<C  << '-'  <<D  << "=7" << endl;
        return 0;
    }
    if(A - B - C - D == 7)
    {
        cout << A << '-'  << B << '-'  <<C  << '-'  <<D  << "=7" << endl;
        return 0;
    }

}

Measured memory_bytes: 256
n = int(input())
p = [int(i) for i in input().split()]
c = 0
for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1] or p[i] < p[i-1] == p[i+1] or p[i+1] < p[i] < p[i-1]:
        c += 1
print(c)

Measured memory_bytes: 3064
#include<stdio.h>
int prime[1000000];
int count[1000000];
int main(){
	int n=0, i, k;
	for (i = 2; i < 1000000; i++){
		prime[i] = 1;
	}
	for (i = 2; i*i<1000000; i++){
		if (prime[i]){
			for (k = 2 * i; k < 1000000; k += i){
				prime[k] = 0;
			}
		}
	}

	for (i = 0; i <1000000 ; i++){
			count[i+1]=count[i]+prime[i];
	}

	while (1){
		if (scanf("%d", &n) == EOF){
			break;
		}
		
		printf("%d\n", count[n+1]);
	}
	return 0;
}

Measured memory_bytes: 8408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll Q,a,b;
bool check(ll c)
{
	//f[x]=-x^2+(a+c+1)*x 
	ll A=-1,B=(a+c+1);
	ll po=-B/(2ll*A);
	//cout<<po<<'\n';
	for(ll i=max(1ll,po-500);i<=min(c,po+500);i++)
	{
		if(i*(a+c-i+1)>=a*b)
			return false;
	}
	return true;
}
 
int main()
{	
	cin>>Q;
	while(Q--)
	{
		cin>>a>>b;
		if(a>b)
			swap(a,b);
		ll l=1,r=b,p;
		while(l<=r)
		{
			ll mid=l+r>>1;
			if(check(mid))
				l=mid+1,p=mid;
			else
				r=mid-1;
		}
		ll res=a-1+p;	
		cout<<res<<'\n';
	}	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sn = new Scanner(System.in);
        
        int k = sn.nextInt();
        int a = sn.nextInt();
        int b = sn.nextInt();
        
        for(int i = a; i <= b; i++) {
            if(i % k == 0) {
                System.out.print("OK");
                return;
            }
        }
        System.out.print("NG");
	}
}


Measured memory_bytes: 35764
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define mod 1000000007
//#define N 500055
//#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,x,y,z,xz,num[40],f[41][1<<18],P,ans;
inline void add(int &x,int k){
	x+=k;x-=(x>=mod)?mod:0;x+=(x<0)?mod:0;
}
signed main(){
	n=read();x=read();y=read();z=read();xz=x+y+z;
	num[0]=1;F(i,1,20) num[i]=num[i-1]*2;
	f[0][0]=1;P=num[x-1]+num[x+y-1]+num[x+y+z-1];ans=1;
	F(i,0,n-1){
		ans=1LL*ans*10%mod;
		F(j,0,num[xz]-1){
			F(k,1,10){
				int t=(num[xz]-1)&((j<<k)|(num[k-1]));
				if ((t&P)==P) continue;
				add(f[i+1][t],f[i][j]);
			}
		}
	}
	F(i,0,num[xz]-1){
		add(ans,-f[n][i]);
	}
	wrn(ans);
	return 0;
}

Measured memory_bytes: 40192
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int d; cin>>d;
  ll g; cin>>g;
  vector<P> p(d);
  rep(i,d) cin>>p[i].fs>>p[i].sc;

  int ans=INF;
  for(int bit=0;bit<(1<<10);bit++){
    ll sum=0;
    int c=0;
    rep(i,d){
      int k=1<<i;
      if((k&bit)!=0){
        sum+=p[i].fs*(i+1)*100+p[i].sc;
        c+=p[i].fs;
      }
    }
    if(sum>=g) ans=min(ans,c);
    else{
      for(int i=d-1;i>=0;i--){
        int k=1<<i;
        if((k&bit)==0){
          for(int j=1;j<p[i].fs;j++){
          sum+=(i+1)*100;
          c++;
          if(sum>=g){
            ans=min(ans,c);
            break;
          }
        }
        }
      }
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256