akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    uint64_t N, K;
    cin >> N >> K;
    vector<int> A(N + 1);
    for (uint64_t i = 1; i < N + 1; i++) {
        cin >> A[i];
    };

    vector<int> check(N + 1);
    int loop, loopst = 1, des = 1;
    for (uint64_t i = 1; i <= N + 1; i++) {
        if (check[des] == 0) {
            check[des] = i;
            des = A[des];
        } else {
            loop = i - check[des];
            loopst = check[des] - 1;
            break;
        }
    }
    K > loopst ? K = (K - loopst) % loop + loopst : K % loop;
    des = 1;
    for (uint64_t i = 0; i < K; i++) {
        des = A[des];
    }

    cout << des << endl;

    return 0;
}

Measured memory_bytes: 4852
#include <stdio.h>
int main(void)
{char ch[10000];
    int len,i;
    len=0; i=0;
    scanf("%s", ch);
    while(ch[i] != '\0'){
        if(ch[i]=='2'){
            len++;
        }
        i++;
    }
    printf("%d\n", len);
    return 0;
}


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

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  for (long &a : A) cin >> a;
  sort(A.begin(), A.end());

  long L = -2e18, R = 2e18;
  while (R - L > 1) {
    long M = (L + R) / 2, cnt = 0;
    for (int i = 0; i < N; i++) {
      int l = i, r = N;
      while (r - l > 1) {
        int m = (l + r) / 2;
        if (A.at(i) * A.at(m) <= M) (A.at(i) < 0) ? r = m : l = m;
        else (A.at(i) < 0) ? l = m : r = m;
      }
      cnt += (A.at(i) < 0) ? N - r : l - i;
    }
    (cnt < K) ? L = M : R = M;
  }
  cout << R << "\n";
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	string S;
	scan(N>>S);
	int rui[3][4001]={};
	int ch[4001];
	rep(i,N){
		if(S[i]=='R') ch[i]=0;
		else if(S[i]=='G') ch[i]=1;
		else ch[i]=2;
	}
	rep(i,N){
		rep(k,3) rui[k][i+1]=rui[k][i];
		rui[ch[i]][i+1]++;
	}
	ll ans=0;
	rep1(i,N-2){
		ans+=rui[(ch[i]+1)%3][i]*(rui[(ch[i]+2)%3][N]-rui[(ch[i]+2)%3][i+1]);
		ans+=rui[(ch[i]+2)%3][i]*(rui[(ch[i]+1)%3][N]-rui[(ch[i]+1)%3][i+1]);
		rep1(j,N){
			if(i-j<0||i+j>=N) break;
			if(ch[i-j]!=ch[i+j]&&ch[i-j]!=ch[i]&&ch[i+j]!=ch[i]) ans--;
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 3704
n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
sushi.sort(key=lambda x: x[1], reverse=True)
#print(sushi)
num = 0
kind = set()
changable = []
for i in range(k):
	num += sushi[i][1]
	if sushi[i][0] in kind:
		changable.append(sushi[i][1])
	else:
		kind.add(sushi[i][0])

num += len(kind)**2
#changable.reverse()
#print(changable)
ans = num

for i in range(k, n):
	if not changable:
		break

	if sushi[i][0] not in kind:
		num += sushi[i][1] + 2*len(kind)+1 - changable.pop()
		#print(num, kind)
		kind.add(sushi[i][0])
		ans = max(ans, num)


print(ans)

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

typedef long long ll;

int n;
int k;
ll x[100010];
ll y[100010];

ll MOD = 1e9 + 7;

ll mod(ll num)
{
	return (MOD + num) % MOD;
}

ll sum[4010][4010];

int main()
{
	cin >> n >> k;
	MOD = 2 * k;

	for(int i = 0;i < n;i++)
	{
		int a,b;
		char c;

		cin >> a >> b >> c;

		if(c == 'W') a += k;

		a++;
		b++;
		a = mod(a);
		b = mod(b);
		
		//左下の黒のマスの位置だけ分かればよい
		sum[a][b]++;
		sum[a + 2 * k][b]++;
		sum[a + 2 * k][b + 2 * k]++;
		sum[a][b + 2 * k]++;
	}

	for(int i = 1;i < 4010;i++)
	{
		for(int j = 0;j < 4010;j++)
		{
			sum[i][j] += sum[i - 1][j];
		}
	}
	for(int i = 1;i < 4010;i++)
	{
		for(int j = 0;j < 4010;j++)
		{
			sum[j][i] += sum[j][i - 1];
		}
	}

	int ans = 0;

	for(int i = 0;i <= 2 * k;i++)
	{
		for(int j = 0;j <= 2 * k;j++)
		{
			//斜めの黒いところを足す
			int value = sum[i + k][j + k] + sum[i][j] - sum[i][j + k] - sum[i + k][j];
			int value2 = sum[i + 2 * k][j + 2 *k] + sum[i + k][j+ k] - sum[i+ k][j + 2 *k] - sum[i + 2 *k][j+ k];
			ans = max(value + value2 , ans);
		}
	}

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


Measured memory_bytes: 127232
import itertools
import math


def main():
    N = int(input())
    coords = [list(map(int, input().split(' '))) for _ in range(N)]
    ans_squared = 10 ** 12
    # 2点を通る円で、全点覆える円の半径の最小値を求める
    for i, j in itertools.combinations(range(N), 2):
        x1, y1 = coords[i]
        x2, y2 = coords[j]
        d_squared = (x1 - x2)**2 + (y1 - y2)**2
        cover = True
        for n in range(N):
            x, y = coords[n]
            if (2 * x - (x1 + x2))**2 + (2 * y - (y1 + y2))**2 > d_squared:
                cover = False
                break
        if cover:
            ans_squared = min(ans_squared, d_squared / 4)
    if N == 2:
        print(math.sqrt(ans_squared))
        return
    # 3点を通る円で、全点覆える円の半径の最小値を求める
    for i, j, k in itertools.combinations(range(N), 3):
        x1, y1 = coords[i]
        x2, y2 = coords[j]
        x3, y3 = coords[k]
        dx12, dx23, dy12, dy23 = x1 - x2, x2 - x3, y1 - y2, y2 - y3
        if dx12 * dy23 == dy12 * dx23:
            # 3点が1直線上にのってると、3点を通る円が描けない
            continue
        v1, v2, v3 = x1 ** 2 + y1 ** 2, x2 ** 2 + y2 ** 2, x3 ** 2 + y3 ** 2
        scale = 2 * (dx12 * dy23 - dy12 * dx23)
        # 中心座標（のscale倍）
        scaled_cx = dy23 * v1 - (dy12 + dy23) * v2 + dy12 * v3
        scaled_cy = - dx23 * v1 + (dx12 + dx23) * v2 - dx12 * v3
        r_squared = (x1 - scaled_cx / scale)**2 + (y1 - scaled_cy / scale)**2
        cover = True
        for n in range(N):
            x, y = coords[n]
            if (scale * x - scaled_cx)**2 + (scale * y - scaled_cy)**2 \
                    > (scale * x1 - scaled_cx)**2 + (scale * y1 - scaled_cy)**2:
                cover = False
        if cover:
            ans_squared = min(ans_squared, r_squared)
    print(math.sqrt(ans_squared))


if __name__ == '__main__':
    main()

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll count = 0;
    vector<ll> A;
    A.resize(3);
    cin >> A[0] >> A[1] >> A[2];
    while(A[0] != A[1] || A[1] != A[2] || A[0] != A[2]) {
        sort(A.begin(), A.end());
        if(A[2] - A[0] == 1) {
            A[0]++; A[1]++;
        } else {
            A[0] += 2;
        }
        count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int x,y,z,h,g;
int main(){cin>>x>>y>>z;h=x-z;while(h-z>0){if(h-y-z<0)break;else h=h-y-z;g++;}cout<<g<<endl;return 0;}

Measured memory_bytes: 256
let () =
  let s = read_line () in
  let tbl = Hashtbl.create 26 in
  let sl = String.length s in
  let rec loop i =
    if i = sl then "yes"
    else
      if Hashtbl.mem tbl s.[i] then "no" else begin
          Hashtbl.replace tbl s.[i] true;
          loop (i+1)
        end in
  loop 0 |> print_endline



Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,x,c[20],a[20][20],maxa,flg=0,use[20],leastmoney=0x7ffffff;
void check();
bool ach();
void dfs(int x)
{
	if(x==n+1) 
	{
		check();
		return;
	}
	dfs(x+1);
	use[x]=1;
	dfs(x+1);
	use[x]=0;
}
void check()
{
 	if(!ach()) return;
 	int money=0;
	for(int i=1;i<=n;i++) if(use[i]) money+=c[i];
	leastmoney=min(money,leastmoney);
}
bool ach()
{
	int sum[20];
	for(int i=1;i<=m;i++) sum[i]=0;
	for(int i=1;i<=n;i++)
	{
		if(use[i]){
			for(int j=1;j<=m;j++) sum[j]+=a[i][j];
		}
	}
	for(int i=1;i<=m;i++) if(sum[i]<x) return false;
	return true;
}
int main()
{
//	freopen("1.txt","r",stdin);
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	dfs(1); 
	if(leastmoney==0x7ffffff) printf("-1");
	else cout<<leastmoney;
} 

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

int main(void){
    int n, cnt = 0;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    for (auto x : a){
        while (x%2 == 0){
            cnt++;
            x /= 2;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <string>

int main()
{
	std::string num;
	std::cin >> num;

	while (num != "0") {
		int sum = 0;
		for (std::string::iterator it = num.begin(); it < num.end(); it++) {
			sum += static_cast<int>(*it - '0');
		}
		std::cout << sum << "\n";
		std::cin >> num;
	}
    return 0;
}




Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int const SIZE=100009;

int main(){
	LL n;
	cin>>n;
	LL arr[SIZE];
	LL sum=0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	LL r=(2*sum)/(n*((n+1)));
	if((((2*sum)%(n*((n+1))))!=0)||(r<=0)){
		cout<<"NO";
		return 0;
	}
	for(int i=0;i<n;i++){
		int tn=(r-(arr[(i+1)%n]-arr[i%n]));
		if((tn%n!=0)||(tn<0)){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int x;
  cin >> x;
  cout << !x << endl;
}


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

int main() {
	int N, K;
	int x;
	cin >> N >> K;
	for (int i = 0; i < N; i++)
		cin >> x;
	if (!((N-1) % (K-1))) {
		cout << (N-1)/(K-1) << endl;
	} else {
		cout << (N-1)/(K-1)+1 << endl;
	}
}


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

int main() {
  
  int N;
  cin >> N;
  int sum = 0;
  int pro = 1;
  
  for (int i = 0; i < 9; i++) {
    pro *= 10;
    sum += (N % pro) / (pro / 10);
    if (N < (pro / 10)) {
      break;
    }
  }
  
  if ((N % sum) == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
from itertools import accumulate
import sys
input = sys.stdin.readline

H, W, K = map(int, input().split())
S = [list(map(int, input().rstrip())) for _ in range(H)]
cum = [list(accumulate(S[i])) for i in range(H)]
ans = float('inf')
for bit in range(1 << (H-1)):
    cnt = 0
    prev = -1
    for h in range(H-1):
        cnt += (bit >> h) & 1
    bit += 1 << (H-1)
    w = 0
    while w < W:
        s = 0
        cut = False
        for h in range(H):
            s += cum[h][w] - (cum[h][prev] if prev >= 0 else 0)
            if bit >> h & 1:
                if s > K:
                    cut = True
                    break
                s = 0
        if cut:
            if w-1 == prev:
                break
            cnt += 1
            prev = w-1
        else:
            w += 1
    else:
        ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 44508
#include<iostream>
using namespace std;
int main(){
	int h,w,n,a,x,y;
	cin>>w>>h>>n;
	int d[4]={0,w,0,h};
	for(int i=0;i<n;i++){
		cin>>x>>y>>a;a--;
		if(a==0)d[a]=max(d[a],x);
		if(a==2)d[a]=max(d[a],y);
		if(a==1)d[a]=min(d[a],x);
		if(a==3)d[a]=min(d[a],y);
	}
	cout<<max(0,(d[1]-d[0]))*max(0,(d[3]-d[2]))<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys


n = int(input())

pmax = 10 ** 9 + 7

if n == 1 or n== 0 :
    print('0')
    sys.exit()
    
elif n == 2:
    print('2')
    sys.exit()


x = 10 ** n % pmax
y = 9 ** n % pmax
z = 9 ** n % pmax
yz = 8 ** n % pmax

ans = (x - y - z + yz) % pmax


print(ans)

Measured memory_bytes: 10668
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<ull> vul;
#define For(i, n) for(ll i = 0; i < n; i++)
#define len(n) (ll)(n).size()
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define Sort(a) sort(a.begin(), a.end())

vector<ull> slimes;
ull pref_sizes[401];
ull dp[400][400];

int main() {
    FAST_IO;
    ll N;
    cin >> N;
    For(l, N) For(r, N) dp[l][r] = 1e15;
    For(i, N) {
        ull size;
        cin >> size;
        slimes.push_back(size);
        dp[i][i] = 0;
        if (i) pref_sizes[i] = pref_sizes[i - 1] + slimes[i];
        else pref_sizes[i] = slimes[i];
    }
    for(ll r = 0; r < N; r++) {
        for(ll l = r; l >= 0; l--) {
            for(ll m = l; m < r; m++) {
                dp[l][r] = min(dp[l][r], dp[l][m] + dp[m + 1][r] + (pref_sizes[r] - pref_sizes[l - 1]));
            }
        }
    }
    cout << dp[0][N - 1] << '\n';
    return 0;
}

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

int main(){
    int n, t, s = 0;
    cin >> n;
    t = n;
    while(t>0){
        s += t%10;
        t /= 10;
    }
    if(n%s == 0){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt( in.nextLine() );
        String s = in.nextLine();

        int count = 0;
        for( int i = 0 ; i < n - 2 ; i++ ){
            char c = s.charAt(i);
            if( c == 'A' && s.charAt( i + 1 ) == 'B' && s.charAt( i + 2 ) == 'C' ){
                count++;
            }
        }

        System.out.println( count );

    }

}


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
#define mod 1e9 + 7;

int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr); 
	cout.tie(nullptr); 
	cout.setf(ios::fixed); 
	cout.precision(20);

	ll n;
	string s;
	cin >> n >> s;
	vi v1(n),v2(n);
	ll a = 0, maxe = 0, maxw = 0;
	rep(i, n) {
		if (s[i] == 'E') {
			a++;
			v1[i] = a;
			//cout << i << " " << a << endl;
		}
		else v1[i] = a;
	}
	maxe = a;
	a = 0;
	repr(i, n) {
		if (s[i] == 'W') {
			a++;
			v2[i] = a;
			//cout << i << " " << a << endl;
		}
		else v2[i] = a;
	}
	maxw = a;
	//cout << maxe << " " << maxw << endl;
	ll ans = mod;
	rep(i,n) {
		ll ansx = (maxe - v1[i]) + (maxw - v2[i]);
		//cout << (maxe - v1[i]) << " " << (maxw - v2[i]) << endl;
		ans = min(ans, ansx);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2964
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int W, H;
char A[80][80];
int dd[5] = { 0, 1, 0, -1, 0 };
bool v[80][80], s[2][80][80];

bool isin(int y, int x) { return 0 <= y && y < H && 0 <= x && x < W; }

void dfs(int y, int x, int c) {
  if(v[y][x] || A[y][x] != '.') return;
  v[y][x] = true;
  s[c][y][x] = true;
  REP(i, 0, 4) if(isin(y + dd[i], x + dd[i + 1])) dfs(y + dd[i], x + dd[i + 1], c);
}

int main(void) {
  while(cin >> W >> H, W || H) {
    REP(i, 0, H) cin >> A[i];

    REP(i, 0, 2) REP(j, 0, H) REP(k, 0, W) s[i][j][k] = false;
    REP(i, 0, H) REP(j, 0, W) if(A[i][j] != '.') {
      REP(k, 0, 4) if(isin(i + dd[k], j + dd[k + 1])) {
        REP(l, 0, H) REP(m, 0, W) v[l][m] = false;
        dfs(i + dd[k], j + dd[k + 1], A[i][j] == 'W');
      }
    }

    int ans[2] = { 0, 0 };
    REP(i, 0, 2) REP(j, 0, H) REP(k, 0, W) if(s[i][j][k] && !s[1 - i][j][k]) ans[i]++;
    cout << ans[0] << " " << ans[1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3172
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S1 = readline().strip()
    S2 = readline().strip()
    
    if S1 == S2[::-1]:
        print('YES')
    else:
        print('NO')
    
    return


if __name__ == '__main__':
    main()


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

using namespace std;

#define reg register
#define ge getchar()
#define Re read()
#define FI "a.in"
#define FO "a.out"
#define MAXN 1000

inline int read() {
	int x = 0, t = 0, ch;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = ge;
	return t ? -x : x;
}

int n, m;
long long res;
char s[401][401];
bool Arrive[401][401];

inline void BFS(int x, int y) {
	if(Arrive[x][y]) return ;
	queue<int>X, Y;
	long long B = 0, W = 0;
	X.push(x), Y.push(y);
	Arrive[x][y] = 1;
	while(!X.empty()) {
		int x = X.front(); X.pop();
		int y = Y.front(); Y.pop();
		if(s[x][y] == '.') B++;
		else W++;
		for(int i = -1; i <= 1; i++)
			for(int j = -1; j <= 1; j++)
				if(abs(i) + abs(j) == 1) {
					int tx = x + i;
					int ty = y + j;
					if(tx < 0 || ty < 0 || tx == n || ty == m) continue;
					if(Arrive[tx][ty] || s[x][y] == s[tx][ty]) continue;
					X.push(tx); Y.push(ty);
					Arrive[tx][ty] = 1;
				}
	}
	res += B * W;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++)
		scanf("%s", s[i]);
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			BFS(i, j);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include <vector>
#include <list>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <climits>
#include <math.h>
using namespace std;

int main(){
      string str;
      cin >> str;
      int c=-1,r=0;
      for(int i=0;i<str.size();i++){
            if(str[i]=='C'){c=i;break;}
      }

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

      for(int i=c;i<str.size();i++){
            if(str[i]=='F'){r++;break;}
      }

      if(r>=1){cout << "Yes" << endl;}
      else{cout << "No" << endl;}

      return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;



int main(){
    int N,A,B;
    cin >> N >> A >> B;
    cout << min(A*N,B) << endl;

}


Measured memory_bytes: 256
while True:
    l = []
    x = list(input())
    if x[0] == '-':
        break
    else:
        n = int(input())
        for _ in range(n):
            l.append(int(input()))
        for i in l:
            j = x[:i]
            del x[:i]
            x.extend(j)
        print(''.join(x))


Measured memory_bytes: 5600
N = int(input())
A = list(map(int, input().split()))

if A.count(0) >= 1:
    print(0)
    exit(0)

L = 10**18
ans = A[0]
for i in range(1, N):
    ans *= A[i]
    if ans > L:
        print(-1)
        exit(0)
print(ans)


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

using namespace std;

const int MX=200011;

int n,p[MX],ip[MX];
int lg2[MX];
int mn[19][MX];
struct Q{
	int l,r,mn;
	Q(int _l=0,int _r=0,int _mn=0):l(_l),r(_r),mn(_mn){}
	inline bool operator<(const Q &x)const{return mn>x.mn;}
};

inline int q(int l,int r){
	int c=((r-l)>>1)+1;
	int L=lg2[c];
	return min(mn[L][l],mn[L][l+((c-(1<<L))<<1)]);
}

int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>p[i];
	for(int i=1;i<=n;i++)ip[p[i]]=i;
	lg2[1]=0;
	for(int i=2;i<=n;i++)lg2[i]=lg2[i>>1]+1;
	for(int i=1;i<=n;i++)mn[0][i]=p[i];
	for(int i=1;(1<<i)<=n;i++){
		for(int j=1;j+(1<<(i+1))-2<=n;j+=2)mn[i][j]=min(mn[i-1][j],mn[i-1][j+(1<<i)]);
		for(int j=2;j+(1<<(i+1))-2<=n;j+=2)mn[i][j]=min(mn[i-1][j],mn[i-1][j+(1<<i)]);
	}
	static priority_queue<Q>qi;
	qi.push(Q(1,n,q(1,n)));
	for(int i=1;i<=(n>>1);i++){
		Q r=qi.top();qi.pop();
		cout<<r.mn<<' ';
		int x=ip[r.mn],y=q(ip[r.mn]+1,r.r);
		cout<<y<<' ';
		y=ip[y];
		if(r.l<x)qi.push(Q(r.l,x-1,q(r.l,x-1)));
		if(x+1<y)qi.push(Q(x+1,y-1,q(x+1,y-1)));
		if(y<r.r)qi.push(Q(y+1,r.r,q(y+1,r.r)));
	}
	cout<<endl;
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    
    vector<int> vec(N,1);
    vector<int> copy(N,1);
    for (int i =0; i < N; i++) {
        int j;
        cin >> j;
        vec.at(i) = j;
        copy.at(i) = j;
    }
    sort(copy.begin(), copy.end(), std::greater<int>());
    
    int left = copy.at(N/2-1), right = copy.at(N/2);
    for (int h = 0; h < N; h++) {
        if (vec.at(h) >= left){
            cout << right << endl;
        }
        else {
            cout << left << endl;
        }
    }
}

Measured memory_bytes: 3712
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(N: int, K: int):
    # N-K+1 C i * K-1 C i - 1
    dp = [0]*(K+1)
    dp[1] = N - K  + 1
    for i in range(1, K):
        dp[i+1] = dp[i] * (N - K + 1 - i) * (K- i) // ((i+1)*i)
    for d in dp[1:]:
        print(d % MOD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


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

signed main(void)
{
	long long n, ans;
	long long a_cnt, c_cnt;
	cin >> n;
	vector<long long> a(n), b(n), c(n);

	rep(i, n) cin >> a.at(i);
	rep(i, n) cin >> b.at(i);
	rep(i, n) cin >> c.at(i);
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	a_cnt = 0;
	c_cnt = 0;
	ans = 0;
	rep(i, n)
	{
		auto Iter1 = lower_bound(a.begin(), a.end(), b[i]);
		a_cnt = Iter1 - a.begin();
		auto Iter2 = upper_bound(c.begin(), c.end(), b[i]);
		c_cnt = c.end() - Iter2;
		ans += a_cnt * c_cnt;
	}
	cout << ans << endl;
	return 0;
}


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

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' ';
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' ';
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 1e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e9 + 7;
const ll infll = 1e18 + 7;

int n, m, k;
int q = 1;
int ans, tmp, cnt, idx, mx, mn, sum;
int x, y, z;
int a[N], b[N];
string s, t;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//cin >> q;
while (q--){
    cin >> x >> y;
    if (x == y) cout << "Yes";
    else cout << "No";
}
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 256
#include<stdio.h>

int main (void) {
	long long int a, b, x, re;
	scanf(" %lld %lld %lld", &a, &b, &x);
	// t = a % x + a;
	if(a > b) {
		re = a;
		a = b;
		b = re;
	}

	re = b / x - a / x;
	if((a % x) == 0) re++;
	printf("%lld\n", re);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

const int MOD = 1000000007;
struct mint {
    int64 x;
    mint(const int64 x1=0) { x = x1%MOD; };

    mint& operator++(int n) { x+=1; return *this; };
    mint& operator--(int n) { x-=1; return *this; };
    mint& operator=(int64 n) { x=n%MOD; return *this; };
    mint& operator--() {x-=1; return *this; };
    mint& operator+=(const mint a) { if ( (x+=a.x) >= MOD) x-=MOD; return *this; }
    mint& operator-=(const mint a) { if ( (x+= MOD-a.x) >= MOD) x-= MOD; return *this; }
    mint& operator*=(const mint a) { (x*=a.x) %= MOD; return *this; }
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
    mint inv() const { return pow(MOD-2);}
    friend ostream& operator<<(ostream &os, const mint a) noexcept { return os << a.x; }
    constexpr bool operator == (const mint& r) const noexcept { return this->x == r.x; }
    constexpr bool operator != (const mint& r) const noexcept { return this->x != r.x; }
    mint pow(long long t) const {
        if (!t) return mint(1);
        mint a = pow(t>>1);
        a*=a;
        if(t&1) a*= *this;
        return a;
    }
};

struct combination {
    vector<mint> fact, ifact;

    // コンストラクタ
    combination(int n):fact(n+1),ifact(n+1) {
        fact[0] = mint(1);
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*mint(i);
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*mint(i);
    }

    mint nCr(int n, int r) {
        if (r < 0 || r > n) return 0;
        return fact[n]*ifact[r]*ifact[n-r];
    }
    mint nPr(int n, int r) {
        if (r < 0 || r > n) return 0;
        return fact[n]*ifact[n-r];
    }
    mint nHr(int n, int r) { return nCr(n+r-1, n-1); }
};

int main() {
    int64 n,k;
    cin >> n >> k;
    combination comb = combination(n);

    k = min(k, n);

    mint ans = 0;
    for (int64 i=0; i<=k; i++) {
        ans += comb.nCr(n,i) * comb.nCr(n-1,i);
    }

    cout << ans << endl;

}

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

int main(){
	string buf;
	int s = -1, e = -1;
	cin >> buf;
	for(int i = 0;i < buf.length();++i){
		if(i + 1 < buf.length() && buf[i] == buf[i + 1]){
			s = i; e = i + 1; break;
		}
		if(i + 2 < buf.length() && buf[i] == buf[i + 2]){
			s = i; e = i + 2; break;
		}
	}
	if(s != -1 && e != -1) cout << s + 1 << " " << e + 1 << endl;
	else cout << s << " " << e << endl;
	return 0;
}


Measured memory_bytes: 512
<>;
for(<>){
	($A,$B)=sort{$a-$b}glob;
	if($A==$B){
		print$A+$B-2,$/
	}else{
		$C=int(sqrt($A*$B));
		$C-=$C*$C==$A*$B;
		if($C*($C+1)>=$A*$B){
			print$C*2-2,$/
		}else{
			print$C*2-1,$/
		}
	}
}


Measured memory_bytes: 768
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int k=abs(c-a);
	int flag1=0,flag2=0;
	if(a-c>0)
		for(int i=0;i<k;i++)
		printf("L");
	else
		for(int i=0;i<k;i++)
		{
			printf("R");
			flag1=1;
		}
		
	int z=abs(d-b);
	if(b-d>0)
		for(int i=0;i<z;i++)
			printf("D");
	else
		for(int i=0;i<z;i++)
		{
			printf("U");
			flag2=1;
		}
		if(flag1)
		{
			for(int i=0;i<k;i++)
				printf("L");
		}
		else
		{
			for(int i=0;i<k;i++)
				printf("R");
		}
		if(flag2)
		{
			for(int i=0;i<z;i++)
				printf("D");
		}
		else
		{
		 	for(int i=0;i<z;i++)
				printf("U");
		} 
		
		int flag3=0,flag4=0,flag5=0,flag6=0;
		if(flag1)
		{
		 	for(int i=0;i<1;i++)
				printf("L");
		}
		else
		{
		 	for(int i=0;i<1;i++)
		 	{
		 		printf("R");
		 		flag3=1;
			 }
				
		}	
		if(b-d>0)
		for(int i=0;i<z+1;i++)
			printf("D");
		else
			for(int i=0;i<z+1;i++)
			{
				printf("U");
				flag4=1;
			}
		if(flag3)
		{
			for(int i=0;i<k+1;i++)
				printf("L");
		}
		else
			for(int i=0;i<k+1;i++)
			{
				printf("R");
				flag5=1;
			}
						
		if(flag4)
			printf("D");
		else
		{
			printf("U");
			flag6=1;
		}
		
		
		
		if(flag3)
			for(int i=0;i<1;i++)
				printf("L");
		else
			for(int i=0;i<1;i++)
				printf("R");
		if(flag4)
		{
			for(int i=0;i<z+1;i++)
			printf("D");
		}
		else
		for(int i=0;i<z+1;i++)
			printf("U");	
		if(flag5)
		{
			for(int i=0;i<k+1;i++)
				printf("L");
		}
		else
			for(int i=0;i<k+1;i++)
				printf("R");
		if(flag6)
		{
			printf("D\n");	
		}
		else
		printf("U\n");			 
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    ll count=0;
    rep(i,S.size()-1){
        if(S[i]!=S[i+1]){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 512
#include<stdio.h>

int main()

{  

    int n,k,i,j,a[1001],temp=0,ans=0;

    

    scanf("%d %d",&n,&k);

    

    for(i=0;i<n;i++)

    {

      scanf("%d",&a[i]);

    

    }

    

    for(i=0;i<n-1;i++)

    {

        for(j=i+1;j<n;j++)

        {

           if(a[i]>a[j])

           {

              temp=a[j];

              a[j]=a[i];

              a[i]=temp;

           }

        

        }

    

    }

    

    for(i=0;i<k;i++)

    {

      ans=ans+a[i];

    

    }

    

    printf("%d",ans);

    

    return 0;

}

Measured memory_bytes: 1740
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int W, H, x, y;
	cin >> W >> H >> x >> y;
	double ans = (double)W * H / 2;
	if (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y) {
		printf("%.10f 1\n", ans);
	}
	else {
		printf("%.10f 0\n", ans);
	}
}

Measured memory_bytes: 256
L, R = map(int, input().split())

minVal = 2018
for l in range(L, R):
    if l == L+2019:
        break
    for r in range(l+1, R+1):
        if r == l+2019:
            break
        if minVal >= (l*r) % 2019:
            minVal = (l*r) % 2019
print(minVal)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
int n;
ll a[100001];
ll dp[100001]={};

ll BinarySearch(ll b){
	int left=0,right=n;
	while(right-left>1){
		int mid=(right+left)/2;
		if(dp[mid]>=b)right=mid;
		if(dp[mid]<b)left=mid;
	}
	return right;
}

int main() {

	cin>>n;
	rep(i,n){
		cin>>a[i+1];
		dp[i+1]=INF;
	}
	rep(i,n){
		dp[BinarySearch(a[i+1])]=min(dp[BinarySearch(a[i+1])],a[i+1]);
	}
	rrep(i,n){
		if(dp[i+1]!=INF){
			cout<<i+1<<endl;
			return 0;
		}
	}

	return 0;
}



Measured memory_bytes: 4644
use proconio::input;
     
    fn main() {
        input! {
            s: String,
            t: String,
        }
     
        let s: Vec<char> = s.chars().collect();
        let t: Vec<char> = t.chars().collect();
        let len = s.len();
        let mut ans = 0;
        for i in 0 .. len {
            if s[i] != t[i] { ans += 1 };
        }
     
        println!("{}", ans);
    }

Measured memory_bytes: 4480
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
map<string,long long> ma;
int main(void)
{
    long long n;
    long long sum=0;
    string s;
    cin >> n;
    for(long long i=0;i<n;i++)
    {
        cin >> s;
        sort(s.begin(),s.end());
        ma[s]++;
    }
    for(auto &x:ma) {
        sum+=(x.second*(x.second-1)/2);
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 11136
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7


N = int(input())
S = str(input())


l,r = 0,0
stack = 0
for i in range(N):
    if S[i]==")":
        if stack > 0:
            stack -= 1
            r -= 1
        else:
            l += 1
    else:
        r += 1
        stack += 1

print("("*l+S+")"*r)


Measured memory_bytes: 6548
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int isPrime(int n){
    if(n==1){
        return 1;
    }
    for(int i=2;i<n;++i){
        if(n%i==0){
            return i;
        }
    }
    return n;
}
int fact(int n){
    int ans = 1;
    for(long long i = 1; i<= n; ++i){
        ans *= i;
    }
    return ans;
}


int main()
{
    unsigned long long a;
    string s;
    cin>>a>>s;
    s.erase(1,1);
    unsigned long long bb=stoi(s);
    unsigned long long c=a*bb;
    cout<<(unsigned long long)(c/100)<<endl;
    return 0;
}

Measured memory_bytes: 3588
import heapq
n,m=map(int,input().split())
A=[[0]*2for i in range(n)]
for i in range(n):
  A[i]=list(map(int,input().split()))
A=sorted(A)
ans=0
s=[]
j=0
for i in range(m+1):
  while j<n:
    if A[j][0]>i:
      break
    heapq.heappush(s,A[j][1]*(-1))
    j=j+1
  if len(s)==0:
    continue
  ans=ans-heapq.heappop(s)
print(ans)

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

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  int h,a;cin>>h>>a;
  cout<<(h-1)/a+1<<endl;
  return 0;
}


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

int main(){
    int n;
    cin>>n;
    int x=0;
    int val=n;
    while(val!=0){
        x+=val%10;
        val/=10;
    }
    
    cout<<(n%x==0 ? "Yes" : "No")<<endl;
    return 0;  
}

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

int main() {
  int a,b,c,d;
  cin>>a;
  b=a%60;
  a/=60;
  c=a%60;
  a/=60;
  d=a%60;
  cout<<d<<":"<<c<<":"<<b<<endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define int long long
main(){
	string s;
	int a,sum=0;
	cin>>s>>a;
	for(int i=0;i<s.size();i++){
		if(s[i]=='1')sum++;
		else break;
	}
	if(a<=sum)cout<<1<<endl;
	else cout<<s[sum]<<endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

use std::time::Instant;
fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums = HashMap::with_capacity(n + 1);
    for &a in &aa {
        *nums.entry(a).or_insert(0) += 1;
    }
    // let mut nums: HashMap<_, i32> = aa.iter()
    //     .fold(HashMap::with_capacity(n + 1), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    while !rems.is_empty() {
        while let Some(s_idx) = q.pop_front() {
            if !rems.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            // if let Some(destv) = dests.remove(&s_num) {
            //     for dest in destv {
            //         q.push_back(dest);
            //     }
            // }
            if let Some(destv) = dests.get_mut(&s_num) {
                for &dest in destv.iter() {
                    q.push_back(dest);
                }
                destv.clear();
            }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
    }
    println!("{}", ans);
    std::process::exit(0);
}


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

int a,b,c,d;

void convert_int(string s){
  a=s.at(0)-'0';
  b=s.at(1)-'0';
  c=s.at(2)-'0';
  d=s.at(3)-'0';
}

int op(bool x){
  if (x) return 1;
  else return -1;
}

char opc(bool x) {
  if (x) return '+';
  else return '-';
}

int main() {
  string s;
  cin>>s;
  convert_int(s);
  
  int tmp=0;
  bool flag=true;
  while (tmp<(1<<3) && flag) {
    bitset<3> s(tmp);
    int ans=a;
    ans+=op(s.test(0))*b;
    ans+=op(s.test(1))*c;
    ans+=op(s.test(2))*d;
    if (ans==7) {
      cout<<a<<opc(s.test(0))<<b<<opc(s.test(1))<<c<<opc(s.test(2))<<d<<"=7"<<endl;
      flag=false;
    }
    tmp++;
  }  
}

Measured memory_bytes: 256
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramA a = new ProgramA();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);

            //時間に換算して起きてる時間からk時間を除く
            Console.WriteLine(a*b);

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            //?はD、それ以外は普通に出す
            for (int i = 0;i < n;i++)
            {
            }
            

        }
    }

    class ProgramC
    {
        public void main()
        {

            int n = int.Parse(Console.ReadLine());
            string[] a = Console.ReadLine().Split(' ');

            //n=0のときは例外処理
            if(n == 0)
            {
                if (a[0] == "1")
                    Console.WriteLine("1");
                else
                    Console.WriteLine("-1");
                return;
            }
            //0のときは0以外はダメ
            if(a[0] != "0")
            {
                Console.WriteLine("-1");
                return;
            }
            long[] num = new long[n + 1];
            long[] leave = new long[n + 1];
            num[0] = 1;
            leave[n] = long.Parse(a[n]);
            //深さiを含む後ろの根の数を数えておく
            for (int i = n -1; i >= 0 ;i--)
                leave[i] = leave[i + 1] + long.Parse(a[i]);
            //前から根の数を決める（ただし、最大は後ろに考えるべき根の数に限られる）
            for(int i = 1;i <= n;i++)
            {
                num[i] = Math.Min(2 * (num[i - 1] - long.Parse(a[i - 1])), leave[i]);
                //あり得る数が葉になる数より大きければあり得ない(n-1まで）
                if(i < n && num[i] <= long.Parse(a[i]))
                {
                    Console.WriteLine("-1");
                    return;
                }
                //最後は頭からの条件で満たさないならアウト
                if (i == n && num[i] < long.Parse(a[i]))
                {
                    Console.WriteLine("-1");
                    return;
                }
            }
            
            //答え出力
            long ans = 0;
            for(int i = 0; i <= n;i++)
                ans += num[i];

            Console.WriteLine(ans);
        }
    }
}






Measured memory_bytes: 27540
#include <cstdio>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

ll as[500+10];
int N;
ll K;

ll bs[500+10];
bool isOK(ll x) {
  REP(i, N) {
    bs[i] = as[i] % x;
  }
  sort(bs, bs + N);
  ll cost = 0;
  ll cur = 0;
  for(int i1 = 0, i2 = N-1; i1 <= i2; ) {
    if(bs[i2] + cur < x) {
      cur += bs[i1];
      cost += bs[i1];
      ++i1;
    } else {
      cur -= x - bs[i2];
      --i2;
    }
  }
  // cerr << "> " << x << " " << cur << endl;
  assert(cur == 0);
  return cost <= K;
}

int main(void) {
  scanf("%d%lld", &N, &K);
  ll sum = 0;
  REP(i, N) {
    scanf("%lld", &as[i]);
    sum += as[i];
  }
  ll res = 1;
  for(ll i = 1; i*i <= sum; ++i) {
    if(sum % i != 0) {
      continue;
    }
    if(isOK(i)) {
      res = max(res, i);
    }
    if(isOK(sum / i)) {
      res = max(res, sum / i);
    }
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut k = vec![Vec::new(); m];
    for i in 0..m {
        let v = read_vec::<usize>();
        k[i] = v.into_iter().map(|x| x - 1).skip(1).collect::<Vec<_>>();
    }
    let p = read_vec::<usize>();

    let mut ans = 0;
    'outer: for i in 0..1u32 << n {
        let mut i = i;
        let mut on_off = vec![false; n];
        let mut pointer = 0;
        while i != 0 {
            on_off[pointer] = i % 2 == 1;
            pointer += 1;
            i /= 2;
        }
        for mi in 0..m {
            let mut on_count = 0;
            for &s in k[mi].iter() {
                if on_off[s] {
                    on_count += 1;
                }
            }
            if on_count % 2 != p[mi] {
                continue 'outer;
            }
        }
        ans += 1;
    }
    println!("{:?}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352