akhauriyash/Code-Regression huggingface dataset:
program align
  implicit none
  integer :: n, a(100000) = 0, b(100000) = 0, i, j
  integer(8) :: x = 0_8, y
  read(*,*) n
  do i = 1, n
    read(*,*) a(i)
  end do
  call quick_sort(a(1:n))
  do j = 1, 2
    b(1) = a((n+1)/2)
    do i = 1, n-1
      if (mod(i,2) == 0) then
        b(i+1) = a(i/2)
      else
        b(i+1) = a(n-i/2)
      end if
    end do
    y = 0_8
    do i = 1, n-1
      y = y+abs(b(i)-b(i+1))
    end do
    x = max(x,y)
    a(1:n) = a(n:1:-1)
  end do
  write(*,'(i0)') x
contains
  recursive subroutine quick_sort(a)
    integer, intent(inout) :: a(:)
    integer :: n, l, r, m
    integer :: p
    n = size(a)
    l = 1
    r = n
    m = (n+1)/2
    p = a(l)+a(m)+a(r)-max(a(l),a(m),a(r))-min(a(l),a(m),a(r))
    do
      do while (a(l) < p)
        l = l+1
      end do
      do while (a(r) > p)
        r = r-1
      end do
      if (l >= r) exit
      a(l) = xor(a(l),a(r))
      a(r) = xor(a(l),a(r))
      a(l) = xor(a(l),a(r))
      l = l+1
      r = r-1
    end do
    if (l-1 > 1) call quick_sort(a(1:l-1))
    if (n > r+1) call quick_sort(a(r+1:n))
  end
end program align

Measured memory_bytes: 1408
N,M = map(int,input().split())
S = []
for _ in range(M):
    INPUT = tuple(map(int,input().split()))
    S.append(INPUT[1:])
P = [int(i) for i in input().split()]

ans = 0
for i in range(2**N):
    # state[i]: スイッチiがon
    state = [False] * N
    for j in range(N):
        if 1 & (i >> j):
            state[j] = True
    
    # 全ての電球が点灯するか判定
    flag = True
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if state[s-1]:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = False
    
    if flag:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
long long a[200001];
int main()
{
	int n,flag=0;long long x;cin>>n;
	for(int i=0;i<n;++i)
	cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n-1;++i)
	{
		if(a[i]==a[i+1])
		{
			flag=1;cout<<"NO";break;
		}
	}if(flag==0) cout<<"YES";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    int A=(S[5]-'0')*1000+(S[6]-'0')*100+(S[8]-'0')*10+(S[9]-'0');
    cout<<(A<=430?"Heisei":"TBD")<<endl;
}

Measured memory_bytes: 256
#include<cstdio>

int main() {
  long X, Y; long sum = 0; int count = 1;
  scanf("%ld%ld", &X, &Y);
  sum = X;
  while (true) {
    sum = sum * 2;
    if (sum <= Y) {
      count += 1;
    }
    else {
      break;
    }
  }
  printf("%d\n", count);
}


Measured memory_bytes: 128
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    H = int(readline())

    cur = 1
    cnt = 1

    while 2 * cur <= H:
        cur *= 2
        cnt *= 2
        cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61856
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int H, W; cin >> H >> W;
	VS S(H);
	REP(i, H)cin >> S[i];

	int dp[110][110];
	REP(i, 110)REP(j, 110)dp[i][j] = INF;
	dp[0][0] = 0;
	if (S[0][0] == '#')dp[0][0] = 1;
	REP(i, H) {
		REP(j, W) {
			if (i == 0 && j == 0)continue;
			if (i == 0) {
				if (S[i][j - 1] != S[i][j])dp[i][j] = dp[i][j - 1] + 1;
				else dp[i][j] = dp[i][j - 1];
			}
			else if (j == 0) {
				if (S[i - 1][j] != S[i][j])dp[i][j] = dp[i - 1][j] + 1;
				else dp[i][j] = dp[i - 1][j];
			}
			else {
				dp[i][j] = min(dp[i - 1][j] + (S[i][j] != S[i - 1][j]), dp[i][j - 1] + (S[i][j] != S[i][j - 1]));
			}
		}
	}
	if (S[H - 1][W - 1] == '#')dp[H - 1][W - 1] += 1;




	cout << dp[H-1][W-1]/2 << endl;

	return 0;
}



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

int main(){
  int N;
  cin >> N;
  vector<int> z(N, 0);
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    // if(a > N/2+1){
    //   cout << 0 << endl;
    //   return 0;
    // }
    z[a]++;
  }

  int ans = 1;
  for(int i = 0; i < z.size(); i++){
    if(N % 2 == 0){
      if(i % 2 == 0){
        if(z[i] != 0){
          cout << 0 << endl;
          return 0;
        }
      }else{
        if(z[i] != 2){
          cout << 0 << endl;
          return 0;
        }
        ans *= 2;
        ans %= 1000000007;
      }
    }else{
      if(i % 2 == 1){
        if(z[i] != 0){
          cout << 0 << endl;
          return 0;
        }
      }else{
        if(i == 0){
          if(z[i] != 1){
            cout << 0 << endl;
            return 0;
          }
        }else{
          if(z[i] != 2){
            cout << 0 << endl;
            return 0;
          }
          ans *= 2;
          ans %= 1000000007;
        }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>

int max1(int a, int b){
    if(a<b){
        return b;
    }else{
        return a;
    }
}

int min1(int a, int b){
    if(a<b){
        return a;
    }else{
        return b;
    }
}

int main(){
    int n;
    int R[210000];
    int i;
    int maxv = -1100000000;
    int minv;

    scanf("%d", &n);

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

    minv = R[0];

    for(i=1; i<n; i++){
        maxv = max1(maxv, R[i]-minv);
        minv = min1(minv, R[i]);
    }

    printf("%d\n", maxv);

    return 0;
}


Measured memory_bytes: 2584
#include <stdio.h>

int main() {
	int w, h, n, ans;
	int x[100] = {0};
	int y[100] = {0};
	int a[100] = {0};
	int i, j, k;
	int square[10000] = {0};

	/* よみこみ */
	scanf("%d %d %d", &w, &h, &n);

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

	/* ぬりつぶす */
	for (i = 0; i < n; i++) {
		switch(a[i]) {
		case 1:
			for (j = 0; j < x[i]; j++) {
				for (k = 0; k < h; k++) {
					square[w * k + j] = 1;
				}
			}
			break;
		case 2:
			for (j = x[i]; j < w; j++) {
				for (k = 0; k < h; k++) {
					square[w * k + j] = 1;
				}
			}
			break;
		case 3:
			for (j = 0; j < y[i]; j++) {
				for (k = 0; k < w; k++) {
					square[w * j + k] = 1;
				}
			}
			break;
		case 4:
			for (j = y[i]; j < h; j++) {
				for (k = 0; k < w; k++) {
					square[w * j + k] = 1;
				}
			}
		}
	}

	/* のこった0を数える */
	for (i = 0; i < w * h; i++) {
		if (square[i] == 0) {
			ans++;
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import Data.List
main = do
  _<-getLine
  a <- map (read::String->Int) . words <$> getLine
  print $ sum $ zipWith (-) (step a []) a
  
step [] result = reverse result
step (x:xs) [] = step xs (x:[])
step (x:xs) (y:ys) = step xs ((max x y):y:ys)

Measured memory_bytes: 205468
#include <stdio.h>
#include <string.h>
  
int main(void){
  int i,trial,judge,tpoint=0,hpoint=0;
  char taro[110],hanako[110];
  
  scanf("%d",&trial);
  for(i=0;i<trial;i++){
    scanf("%s",taro);  scanf("%s",hanako);
    judge=strcmp(taro,hanako);
    if(judge>0)  tpoint+=3;
    else if(judge<0)  hpoint+=3;
    else {
      tpoint++;  hpoint++;
    }
  }
  printf("%d %d\n",tpoint,hpoint);
  
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    
    if(abs(a-b)<=d && abs(b-c)<=d)
    {
        cout << "Yes" << endl;
    }
    else if(abs(a-c)<=d)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

typedef long long ll;

#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
#define fi first
#define se second
const ll mod = 1000000007;
//              123456789

using namespace std;
 

///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int dp[51][2];
int N;
int P;
int A;
int num[2];
ll base;
ll ans;

ll com( ll n, ll r ){
	ll a = 1;
	for(int i = 1; i <= r; i++){
		a *= n-i+1;
		a /= i;
	}
	
	return a;	
}


int main(){
	
	cin>>N>>P;
	
	fill( num, num+2, 0 );
	
	REP(i, N){
		scanf("%d", &A);
		A %= 2;
		num[A]++;
	}
	
	base = 1;
	
	REP(i, num[0]) base *= (ll)2;
	
	ans = 0;
	
	if( P ){
		for( int i = 1; i <= num[1]; i+=2 ){
			ans += com(num[1], i);
		}
	}
	else{
		for( int i = 0; i <= num[1]; i+=2 ){
			ans += com(num[1], i);
		}
	}
	
	ans *= base;
	
	
	cout<<ans<<endl;
	
	return 0;

}

Measured memory_bytes: 256
#define ll long long
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[51],b[51];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    int c=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
        {
            c++;
            if(c>2)
            {
                cout<<"NO"<<endl;
                return 0;
            }
        }
    }
    cout<<"YES"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n, m, c;
  cin >> n >> m >> c;
  int a[n + 5][m + 5], b[m + 5];
  rep(i, m){
    cin >> b[i];
  }
  rep(i, n){
    rep(j, m){
      cin >> a[i][j];
    }
  }

  int ans = 0, nasu;
  rep(i, n){
    nasu = 0;
    rep(j, m){
      nasu += a[i][j] * b[j];
    }
    if(nasu + c > 0){
      ans ++;
    }
  }
  cout << ans << '\n';
  return 0;
}


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

int main(){
  long long a; char b, x, c, d;
  cin >> a >> b >> x >> c >> d;
  long long ans = a * (100 * (b - '0') + 10 * (c - '0') + (d - '0'))/100;
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>

using namespace std;
typedef long long ll;

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

int MOD = 1000000007;



int main(){
    std::ios_base::sync_with_stdio(false);

    std::vector<int> v(4, 0);

    REP(i,3){
        int a,b; cin >> a >> b; a--; b--;
        v[a]++; v[b]++;
    }

    int o = 0; int t = 0;

    REP(i,4){
        if(v[i] == 1) o++;
        if(v[i] == 2) t++;
    }

    if(o==2 && t==2){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


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

void SME(int a,int b);

int main(){
    int a,b;
    cin>>a>>b;
    SME(a,b);
    return 0;
}

void SME(int a,int b){
    if(a==b){
        cout<<"a == b"<<endl;
    }
    else if(a>b){
        cout<<"a > b"<<endl;
    }
    else if(a<b){
        cout<<"a < b"<<endl;
    }
}




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

#define ll long long int

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(),(v).end()

using namespace std;
///////////////////////////////////////////////////////

ll n,a,b;
ll h[100010];

bool check(ll k){
		
	// cout<<endl;
	// DEBUG(k);
	// cout<<endl;

	ll need = 0;
	FOR(i,1,n){

		if(a - (h[i]*1.0/k)<0){
			return true;
		}

		// if(k==51){
		// 	DEBUG(i);
		// }

		if(b - (h[i]*1.0/k) < 0){

			ll hi,lo,mid;
			hi = k;
			lo = 0;

		

			while(hi-lo>1){
				mid = lo + (hi-lo)/2;

				// DEBUG(mid);
				// DEBUG(hi);
				// DEBUG(lo);
				// cout<<endl;

				if(mid*a+(k-mid)*b - h[i]>=0){
					hi = mid;
				}
				else{
					lo = mid;
				}
			}

			// DEBUG(i);
			// DEBUG(lo);
			// DEBUG(hi);
			// cout<<endl;

			if(lo*a + (k-lo)*b - h[i]>=0){
				need+=lo;
			}
			else{
				need+=hi;
			}
		}
	}

	if(need<=k){
		return false;
	}
	return true;
}

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

	cin>>n>>a>>b;

	ll maxh = INT_MIN;
	FOR(i,1,n){
		cin>>h[i];
		maxh = max<ll>(maxh,h[i]);

	}

	ll hi,lo,mid;

	hi = maxh;
	lo = 1;

	while(hi-lo>1){

		mid = lo + (hi-lo)/2;


		if(check(mid)){
			lo = mid;
		}
		else{
			hi = mid;
		}

	}


	if(check(lo)){
		cout<<hi<<endl;
	}
	else{
		cout<<lo<<endl;
	}
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
typedef struct{
  char name[31];
  int page;
}BOOK;
main(){
  BOOK book[101],cp;
  int a=0,b,c,d,e;
  for(e=0;e<101;e++){
    book[e].page=0;
  }
  while(scanf("%s %d",&book[a].name,&book[a].page)!=EOF){
    a=a+1;
  }
  for(b=0;b<a;b++){
    for(c=a-1;c>0;c--){
      if(strcmp(book[c].name,book[c-1].name)<0){
	cp=book[c];
	book[c]=book[c-1];
	book[c-1]=cp;
      }
      else if(strcmp(book[c].name,book[c-1].name)==0){
	if(book[c].page<book[c-1].page){
	  cp=book[c];
	  book[c]=book[c-1];
	  book[c-1]=cp;
	}
      }
    }
  }
  for(d=0;d<a;d++){
    if(d!=0){
      if(strcmp(book[d].name,book[d-1].name)==0){
	printf(" %d",book[d].page);
      }
      else{
	printf("\n%s\n%d",book[d].name,book[d].page);
      }
    }
    else{
      printf("%s\n%d",book[d].name,book[d].page);
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 616
#include<iostream>
using namespace std;
int main(){
  double h,t,y;
  int k;
  while(cin>>h){
    t=h/9.8;
    y=4.9*t*t;
    for(k=0;5*k-5<y;k++);
    cout<<k<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
//しゃくとり法
int main(){
  ll N,M,K;
  cin>>N>>M>>K;
  vector<ll>A(N);
  vector<ll>B(M);
  for(ll i=0;i<N;i++)cin>>A[i];
  for(ll j=0;j<M;j++)cin>>B[j];
  
  //しゃくとり法開始
  //まずはBの総時間
  ll t=0;
  for(ll i=0;i<M;i++){
    t+=B[i];
  }
  
  ll j=M;
  ll ans=0;
  for(ll i=0;i<=N;i++){
    while(j>0&&t>K){
      j--;
      t-=B[j];
    }
    if(t>K)break;
    ans=max(ans,i+j);
    if(i==N)break;
    t+=A[i];
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  int n,b;
  string a;
  cin >> n;
  b = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == "Y") {
      cout << "Four" << endl;
      break;
    }
    else {
      b++;
    }
  }
  if (b == n) {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    vector <map<char,int> >  m(n);
    for(int i = 0 ; i < n ; i++){
        cin >> s[i];
        for(int j = 0 ; j < s[i].length() ; j++){
            m[i][s[i][j]]++;
        }
    }
    long cnt = 0;
    long tmp = 1;
    sort(m.begin(),m.end());
    for(int i = 0; i < n-1 ; i++){
        if(m[i] == m[i+1]){
            tmp++;
        }else{
            cnt += tmp * (tmp-1) /2;
            tmp = 1;
        }
    }
    cnt += tmp * (tmp-1) /2;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 51456
s = input()[::-1]
m = 13
mod = 10**9+7

r = [1]
for i in range(10**5):
    r.append(r[-1]*10 % m)

dp = [0]*m
dp[0] = 1
for i, c in enumerate(s):
    nxt = [0]*m
    if c == "?":
        for j in range(m):
            for k in range(10):
                nxt[(j+k*r[i])%m] += dp[j]
                nxt[(j+k*r[i])%m] %= mod
    else:
        n = int(c)
        for j in range(m):
            nxt[(j+n*r[i])%m] += dp[j]
            nxt[(j+n*r[i])%m] %= mod
    dp = nxt
print(dp[5])


Measured memory_bytes: 45936
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long LL;
const int N = 100010,mod = 1e9 + 7;
int f[N];
int a[N];
int n;

int qmi(int a,int k)
{
    int res = 1;
    while(k)
    {
        if(k&1) res = (LL)res * a %mod;
        a = (LL)a * a % mod;
        k>>=1;
    }
    return res;
}

void init(int n)
{
    for(int i=1;i<=n;i++) f[i] = qmi(i,mod-2),f[i] = (LL)f[i] + f[i-1] % mod;
}

int main()
{
    scanf("%d",&n);
    init(n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    
    LL ans = 0;
    for(int i=1;i<=n;i++) ans = (ans + (((LL)f[i] + f[n-i+1] - f[1]) % mod + mod) % mod * a[i] % mod)%mod;
    for(int i=1;i<=n;i++) ans = ans * i % mod;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4612
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int max(int x, int y)
{
    if (x >= y) return x;
    else return y;
}

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    int ans = max(a+b, max(a-b, a*b));
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

int qr(){int ret=0,f=1;char ch=getchar();while(!isdigit(ch))f=ch=='-'?-1:1,ch=getchar();while(isdigit(ch))ret=ret*10+ch-'0',ch=getchar();return ret*f;}
#define Rint register int
#define il inline

#define maxM 100005
struct job{
    int a,b;
}a[maxM];
bool cmp(job a,job b){
    if(a.b!=b.b)
        return a.b > b.b;
    else return a.a > b.a;
}
int safe[1000],vis[maxM];
int main(){
    Rint N,M;
    N = qr(),M = qr();
    for(Rint i = 1;i<=N;i++){
        a[i].a = qr(),a[i].b = qr();
    }
    sort(a+1,a+N+1,cmp);
    Rint day = 0;
    Rint ans = 0;
    for(int i = 1;i<=N;i++){
        for(int j = M-a[i].a;j>=0;){
            if(vis[j] == 0){
                vis[j] = 1,ans += a[i].b;
                break;
            }else{
                int j2 = j - vis[j];
                if(vis[j2] == 1)
                    vis[j]++;
                j-=vis[j];
            }             
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

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

	int ans = 0;
	if (a >= 13)	cout << b;
	if (a <= 12 && a >= 6)	cout << (b / 2);
	if(a<=5) cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  vector<int> scinence = {a,b,c,d};
  vector<int> sorcial = {e,f};
  sort(scinence.begin(), scinence.end());
  int ans = 0;
  for(int i = 3; i > 0;--i) ans += scinence.at(i);
  ans += max(e,f);
  cout << ans << endl;
}


Measured memory_bytes: 3152
def find_idx(s, c):
  idx_lst = []
  while c in s:
    idx = s.index(c)
    idx_lst += [idx]
    s = s[idx+1:]
  else:
    idx_lst += [len(s)]
  return idx_lst

s = input()
res = float('inf')
for i in range(97, 97 + 26):
  tmp = find_idx(s, chr(i))
  if tmp:
    res = min(res, max(tmp))
print(res)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
#define endl "\n"
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;
int power(int a, int b) {
    if(b==0) {
        return 1;
    } else {
        int ans = power(a,b/2);
        ans=(ans*ans)%mod;
        if(b%2==1) {
            ans=(ans*a)%mod;
        }
        return ans;
    }
}
int mul(int a, int b) {
    int ans = ((a%mod)*(b%mod))%mod;
    return ans;
}
int add(int a, int b) {
    int ans = ((a%mod)+(b%mod))%mod;
    return ans;
}
int Div(int a, int b) {
    int mulinv=power(b, mod-2);
    int ans = mul(a, mulinv);
    return ans;
}
int Sub(int a, int b) {
    int ans = (a-b+2*mod)%mod;
    ans =  ans%mod;
    return ans;
}
int32_t main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n<2) {
        cout<<0<<"\n";
        return 0;
    }
    // int ans = mul(2,Div(mul(n,n-1),2));
    // ans = mul(ans,power(10,n-2));
    // cout<<ans<<"\n";
    int ans = Sub(mul(2,power(9,n)), power(8,n));
    ans = Sub(power(10,n),ans);
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
#define A_MAX 1000000
#define A_MAX_HALF 500000
 
using namespace std;
 
int min_factor[A_MAX + 1];
int q[A_MAX + 1];
int a[A_MAX + 1];
vector<int> primes{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 };
int N;
 
// 入力読み込みは uzzy 氏のコードを真似した
const int cm = 1 << 25;
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() {
    fread(cn, 1, cm, stdin);
  
    for (int i = 2; i <= A_MAX_HALF; ++i) {
        if (!min_factor[i]) {
            min_factor[i] = i;
        }
        int min_factor_i = min_factor[i];
        for (int p : primes) {
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor_i) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }
 
    N = getint();
    for (int i = 0; i < N; ++i) {
        ++a[getint()];
    }
 
    int is_pairwise_coprime = 1;
    for (int n = A_MAX; n > 1; --n) {
        int an = a[n];
        if (an) {
            if (an > 1) {
                if (an == N) {
                    printf("not coprime\n");
                    return 0;
                }
                is_pairwise_coprime = 0;
            }
            a[min_factor[n]] += an;
            a[q[n]] += an;
        }
    }
    if (is_pairwise_coprime) {
        printf("pairwise coprime\n");
    } else {
        printf("setwise coprime\n");
    }
 
    return 0;
}

Measured memory_bytes: 21932
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

ll n,ans=0;
vector<ll> num;

int main(){
	cin>>n;
	num=vector<ll>(n);
	for(int i=0;i<n;i++) cin>>num[i];
	for(int i=0;i<n;i++){
		int tmp=num[i]/2;
		ans+=tmp;
		num[i]-=tmp*2;
		if(num[i]==1&&i+1!=n&&num[i+1]){
				num[i+1]--;
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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 ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
T = input()
mi = 10 ** 9
for i in range(len(S) - len(T)+1):
    a = S[i:i+len(T)]
    # print(a)
    tmp = 0
    for j in range(len(T)):
        if T[j] != a[j]:
            tmp += 1
    mi = min(mi, tmp)
print(mi)    

Measured memory_bytes: 10476
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 10e-8;

int main(){
	int len;
	while(~scanf("%d",&len)){
		if(len==0) break;
		int* a = new int[len];
		for(int i=0;i<len;i++){
			scanf("%d",a+i);
		}

		int n=32;
		int idx=0;
		while(n>0){
			n -= (n-1) % 5;
			printf("%d\n",n);
			n -= a[idx % len] >= n ? n : a[idx % len];
			printf("%d\n",n);
			idx++;
		}

		delete[] a;
	}
}

Measured memory_bytes: 3104
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100010
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,b[N],ans;
int main(){
	n=read();
	for(int i=1;i<n;i++){
		b[i]=read();
	}
	ans+=b[n-1];
	for(int i=n-1;i>1;i--){
		ans+=min(b[i],b[i-1]);
	}
	ans+=b[1];
	cout<<ans<<endl;
	return 0;
}


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

using ll = long long;
using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(false)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;

ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return (a == 0 || b == 0) ? 0 : (a / __gcd(a, b) * b); }

int main(int argc, const char* argv[]) {
	ll a;
	string s;
	cin >> a >> s;

	cout << ( a < 3200 ? "red" : s ) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int main()
{
    ios::sync_with_stdio(false);
    int n,cnt=0;
    cin>>n>>s;
    int k=-1;
    for(int i=0;s[i];i++)
    {
        if(s[i]=='R')
        {
            cnt++;
        }
    }
    int ans=cnt;
    for(int i=0;s[i];i++)
    {
        if(s[i]=='R'&&i+1<=cnt)
            ans--;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3868
<?php

fscanf(STDIN, "%d", $n);

$is_prime = true;
$min = PHP_INT_MAX;
for ($i = 2; $i <= sqrt($n); ++$i) {
    if ($n % $i === 0) {
        $is_prime = false;

        $min = min($min, $i + $n / $i - 2);
    }
}

if ($is_prime) {
    echo $n - 1;
    return;
} else {
    echo $min;
}




Measured memory_bytes: 4604
#include <stdio.h>
#include <stdint.h>

int getNumsInt32(int32_t *buf, int32_t num)
{
  int32_t i;

  for (i = 0; i < num; i++) {
    if (scanf("%d", &buf[i]) == EOF) {
      return -1;
    }
  }
  return 0;
}

int main()
{
  int32_t val[3];

  if (getNumsInt32((int32_t *)val, (int32_t)3) == -1) {
    return -1;
  }

  if (val[0] < val[1]) {
    if ((val[0] < val[2]) && (val[2] < val[1])) {
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }
  else {
    if ((val[0] > val[2]) && (val[2] > val[1])) {
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  } 

  return 0;
}

Measured memory_bytes: 128
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    H, W = iim()
    ha, hb = divmod(H, 2)

    if H == 1 or W == 1:
        print(1)
        return

    ans = ha * W
    if hb:
        ans += W // 2
        if W & 1:
            ans += 1
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
odd=[];eve=[]
for i in range(n):
    if i%2==1:
        eve.append(lis[i])
    else:
        odd.append(lis[i])
if n%2==0:
    eve=list(reversed(eve))
    for s in eve:
        print(s,end=" ")
    for t in odd:
        print(t,end=" ")
else:
    odd=list(reversed(odd))
    for s in odd:
        print(s,end=" ")
    for t in eve:
        print(t,end=" ")
    
        

        
        
    

    
    

Measured memory_bytes: 26412
#include<cctype>
#include<cstdio>
using namespace std;
inline int readint(){
	int x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)&&c!='-') c=getchar();
	if(c=='-'){
		f=1;
		c=getchar();
	}
	while(isdigit(c)){
		x=x*10+c-'0';
		c=getchar();
	}
	return f?-x:x;
}
const int maxn=5e5+5;
int n,m;
typedef long long ll;
const ll mod=998244353;
ll inv[maxn],cn[maxn],cm[maxn],pown[maxn],powm[maxn],fac[maxn];
int main(){
	#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	n=readint();
	m=readint();
	inv[1]=1;
	for(int i=2;i<=n||i<=m;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	cn[0]=1;
	for(int i=1;i<=n;i++) cn[i]=cn[i-1]*(n-i+1)%mod*inv[i]%mod;
	cm[0]=1;
	for(int i=1;i<=m;i++) cm[i]=cm[i-1]*(m-i+1)%mod*inv[i]%mod;
	pown[0]=1;
	for(int i=1;i<=m;i++) pown[i]=pown[i-1]*(n+1)%mod;
	powm[0]=1;
	for(int i=1;i<=n;i++) powm[i]=powm[i-1]*(m+1)%mod;
	fac[0]=1;
	for(int i=1;i<=n&&i<=m;i++) fac[i]=fac[i-1]*i%mod;
	ll ans=0;
	for(int i=0;i<=n&&i<=m;i++){
		ll res=cn[i]*cm[i]%mod*fac[i]%mod*pown[m-i]%mod*powm[n-i]%mod;
		if(i%2==0) ans=(ans+res)%mod;
		else ans=(ans+mod-res)%mod;
	}
	printf("%d\n",(int)ans);
	return 0;
}

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

template<class T>
vector<int> manacher(const vector<T>& s) {
	const int n = s.size();
	vector<int> res(n);
	int pos = 0, len = 0;
	while (pos < n) {
		while (pos - len >= 0 && pos + len < n && s[pos - len] == s[pos + len]) len++;
		res[pos] = len;
		int i;
		for (i = 1; pos - i >= 0 && pos + i < n && i + res[pos-i] < len; i++) res[pos+i] = res[pos-i];
		pos += i; len -= i;
	}
	return res;
}

vector<int> manacher(const string& s) {
	return manacher(vector<char>(s.begin(), s.end()));
}

int solve() {
	int N; cin >> N;
	string s, o;
	for (int i = 0; i < N; i++) {
		char c; cin >> c;
		s += c; s += '$';
		o += c;
	}
	s.pop_back();
	auto mn = manacher(s);
	for (int i = 2; i < N * 2; i += 2) {
		int p;
		for (p = i; mn[p] == p + 1; p += mn[p] - 1);
		if (p + mn[p] == N * 2 - 1) return i / 2 + 1;
	}
	return 0;
	assert(0);
}

int main() {
	cout << solve() << endl;
}


Measured memory_bytes: 15792
#include <iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<string>
using namespace std;

const double PI  =3.141592653589793238463;
#define pb push_back
#define pf push_front
#define sz(v)  ((int)(v).size());
#define all(v) ((v).begin()),((v).end())
typedef unsigned long long ull;
typedef long long ll;

typedef vector<int> vi;
typedef pair<int,int> pi;
//2 7 3 4 9

void printVec(vi v1)
{
    for(int i=0; i<v1.size(); i++)
        cout<<v1[i]<<" ";
    cout<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);

int n;cin>>n;
int k;cin>>k;
vector<int>vec(n,0);
for(int i=0;i<n;i++){
        cin>>vec[i];
}
sort(vec.begin(),vec.end());
ll total=0;
for(int i=0;i<k;i++){
total+=vec[i];
}
cout<<total;

    return 0;

}


Measured memory_bytes: 3672
use std::io;

fn read() -> Vec<i32> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().unwrap())
        .collect()
}

fn main() {
    loop {
        let NM = read();
        let N = NM[0] as usize;
        let mut M = NM[1];

        if N == 0 && M == 0 {
            break;
        }

        let mut DP_tuple = Vec::new();
        for i in 0..N {
            let DP = read();
            DP_tuple.push((DP[0], DP[1]));
        }
        DP_tuple.sort_by_key(|k| k.1);
        DP_tuple.reverse();

        for i in 0..DP_tuple.len() as usize {
            let DP = DP_tuple[i];
            let remain = M - DP.0;
            if remain >= 0 {
                DP_tuple[i].0 = 0;
                M = remain;
            } else {
                DP_tuple[i].0 = -remain;
                break;
            }
        }
        //println!("{:?}", DP_tuple);

        let ans = DP_tuple
            .iter()
            .fold(0, |acc, tuple| acc + tuple.0 * tuple.1);
        println!("{}", ans);
    }
}



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

int main() {
    ll ans=0, N;
    cin >> N;
    vector<ll> a(N), b(N);
    rep(i,N) cin >> a[i] >> b[i];
    sort(begin(a), end(a));
    sort(begin(b), end(b));
    if (N&1) {
        ll m = N/2;
        ans = b[m] - a[m] +1;
    } else {
        ll m2 = N/2;
        ll m1 = m2-1;
        ans = b[m1]+b[m2]-a[m1]-a[m2]+1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6392
s=list(input())
n=len(s)
if list(s[::-1])==list(s[:]) and list(s[(n-1)//2-1::-1])==list(s[:(n-1)//2]) and list(s[:(n+3)//2-2:-1])==list(s[(n+3)//2-1:]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9056
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

struct Interval {
    int a, b;
    Interval() {}
    Interval(int a, int b) {
	this->a = a;
	this->b = b;
    }
};

int memo2[100010];

vector<pair<int, int>> prs;

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

    rep(i, N) {
	int a, b;
	scanf("%d %d", &a, &b);
	prs.push_back(mp(a, b));
    }

    sort(all(prs));

    int ret2 = 0;
    rep(i, N) {
	memo2[prs[i].first]++;
	memo2[prs[i].second]--;
    }
    REP(i, 1, 100005) {
	memo2[i] += memo2[i - 1];
	ret2 = max(ret2, memo2[i]);
    }

    int ret = 0;
    priority_queue<int> q;
    rep(i, N) {
	while (!q.empty() && -q.top() <= prs[i].first) q.pop();
	int cnt = q.size();

	int low = i;
	int high = N;
	int mid = (high + low) / 2;
	int base = prs[i].second;
	while (high - low > 1) {
	    if (prs[mid].first < base) {
		low = mid;
	    } else {
		high = mid;
	    }
	    mid = (high + low) / 2;
	}

	ret = max(mid - i + cnt + 1, ret);

	q.push(-prs[i].second);
    }

    cout << ret << " " << ret2 << endl;

    return 0;
}

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

#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(ll i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl;
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
//#define endl "\n"
const int MAX = 3e5+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;

int n;
string a,b,ta,tb,s;
bool st;

int main(){
//	cout<<fixed<<setprecision(15);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
//    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    while(1){
    	if(st){
    		ta = '.'+a, tb = '.'+b;
			cout<<ta<<endl<<tb<<endl;
			cin>>s;
			if(s=="end")break;
			else if(s=="T"){a = ta, b = tb; continue;}
    		ta = '.'+a, tb = '#'+b;
			cout<<ta<<endl<<tb<<endl;
			cin>>s;
			if(s=="end")break;
			else if(s=="T"){a = ta, b = tb; continue;}
    		ta = '#'+a, tb = '.'+b;
			cout<<ta<<endl<<tb<<endl;
			cin>>s;
			if(s=="end")break;
			else if(s=="T"){a = ta, b = tb; continue;}
    		ta = '#'+a, tb = '#'+b;
			cout<<ta<<endl<<tb<<endl;
			cin>>s;
			if(s=="end")break;
			else if(s=="T"){a = ta, b = tb; continue;}
		}
		else {
			ta = a+'.', tb = b+'.';
			cout<<ta<<endl<<tb<<endl;
			cin>>s;
			if(s=="end")break;
			else if(s=="T"){a = ta, b = tb; continue;}
			ta = a+'.', tb = b+'#';
			cout<<ta<<endl<<tb<<endl;
			cin>>s;
			if(s=="end")break;
			else if(s=="T"){a = ta, b = tb; continue;}
			ta = a+'#', tb = b+'.';
			cout<<ta<<endl<<tb<<endl;
			cin>>s;
			if(s=="end")break;
			else if(s=="T"){a = ta, b = tb; continue;}
			ta = a+'#', tb = b+'#';
			cout<<ta<<endl<<tb<<endl;
			cin>>s;
			if(s=="end")break;
			else if(s=="T"){a = ta, b = tb; continue;}
			st = 1;
		}
	}
	return 0;
}

Measured memory_bytes: 724
#include<iostream>
using namespace std;
int main(){
  //std::sync_with_stdio(false); cin.tie(false); cout.tie(false);
  char input;
  cin>>input;
  if(input>='A' && input<='Z') cout<<'A'<<'\n';
    else cout<<'a'<<'\n';
  return 0;
}

Measured memory_bytes: 3512
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#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()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

struct UnionFind {
    vector<int> par;
    int n, cnt;
    UnionFind(const int& x = 0) {init(x);}
    void init(const int& x) {par.assign(cnt=n=x, -1);}
    inline int find(const int& x) {return par[x] < 0 ? x : par[x] = find(par[x]);}
    inline bool same(const int& x, const int& y) { return find(x) == find(y); }
    inline bool unite(int x, int y) {
        if ((x = find(x)) == (y = find(y))) {
            return false;
        }
        --cnt;
        if (par[x] > par[y]) {
            swap(x, y);
        }
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    inline int count() const {return cnt;}
    inline int count(int x) {return -par[find(x)];}
};

VI A;
VI B;
int N, M;

int _solve(int m) {
    UnionFind uf(N);
    REP(i, M) {
        if (i == m) {
            continue;
        }
        uf.unite(A[i], B[i]);
    }
    return uf.count();
    
}

void solve() {
    int ans = 0;
    REP(i, M) {
        if (_solve(i) != 1) {
            ans += 1;
        }
    }
    cout << ans << endl;
}

int main(int argc, char const* argv[])
{
    cin >> N >> M;
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a -= 1; b -= 1;
        A.PB(a); B.PB(b);
    }
    solve();

    return 0;
}


Measured memory_bytes: 256
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    deff_list = [0]
    for i in range(1,N):
        deff_list.append(As[i] - As[i-1])

    prev = 1000
    res = 1000
    for i in range(1, N):
        if deff_list[i] >= 0:
            res = (prev // As[i-1]) * As[i] + prev % As[i-1]
        
        prev = res
    
    print(res)



if __name__ == "__main__":
    resolve()


Measured memory_bytes: 8940
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC optimize("Ofast")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <random>
#include <cassert>
#include <complex>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef complex <LD> cld;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T1, typename T2>
T2 sum_mod(T1 x, T2 MOD) {
	if (x < 0)
		x += MOD;
	if (x >= MOD)
		x -= MOD;
	return x;
}

template <typename T1, typename T2>
T2 mul_mod(T1 x, T2 MOD) {
	if (x < 0)
		return (abs(x) % MOD == 0 ? 0 : MOD - abs(x) % MOD);
	return x % MOD;
}

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

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

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 gen_rand;

const int N = (int)2e5 + 7;
const int LOG = 20;
const int N_ = (int)8e2 + 7;
const int MAXN = (int)2e6 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)2e9 + 7;
const int CONST = 300;
const LL LINF = (i64)2e15;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1e-6;

/////////////////////////////////////////////////////////////////////

int wa[N];
bool sol[N];

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
	gen_rand.seed(0);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	gen_rand.seed(time(0));
#endif

	int n, m;
	cin >> n >> m;
	int ac = 0, pen = 0;
	for (int i = 0; i < m; i++) {
		int x; cin >> x;
		string s; cin >> s;
		if (s == "AC" && !sol[x])
			sol[x] = true, ac++, pen += wa[x];
		if (s == "WA" && !sol[x])
			wa[x]++;
	}
	cout << ac << ' ' << pen;
		
#ifdef _DEBUG 
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 768
def li():
    return list(map(int, input().split()))
def mi():
    return map(int, input().split())
def ii():
    return int(input())

N, A, B = mi()

div, mod = divmod(N, (A + B))

blue = div * A

if A >= mod:
    blue += mod
else:
    blue += A

print(blue)

Measured memory_bytes: 3064