akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int upto = lcm(n, m);
		int max = 0;
		int min = 0;
		long total = 0;
		for (int i = 0; i < upto; i++) {
		    if (i % m == 0) {
		        total += max - min;
           		max = 0;
        		min = Integer.MAX_VALUE;
		    }
		    max = Math.max(max, arr[i % n]);
		    min = Math.min(min, arr[i % n]);
		}
		total += max - min;
		System.out.println(total);
	}
	
	static int lcm(int x, int y) {
	    return x / gcd(x, y) * y;
	}
	
	static int gcd(int x, int y) {
	    if (x % y == 0) {
	        return y;
	    } else {
	        return gcd(y, x % y);
	    }
	}
}



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

int main() {
  int n;
  cin >> n;
  
  if (n == 1) cout << n << endl;
  else if (2 <= n && n < 4) cout << 2 << endl;
  else if (4 <= n && n < 8) cout << 4 << endl;
  else if (8 <= n && n < 16) cout << 8 << endl;
  else if (16 <= n && n < 32) cout << 16 << endl;
  else if (32 <= n && n < 64) cout << 32 << endl;
  else cout << 64 << endl;
}  

Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	static List<String> al=new ArrayList<>();
	
	static void permute(String str, int l, int r) 
    { 
        if (l == r) 
            al.add(str); 
        else
        { 
            for (int i = l; i <= r; i++) 
            { 
                str = swap(str,l,i); 
                permute(str, l+1, r); 
                str = swap(str,l,i); 
            } 
        } 
    } 
    public static String swap(String a, int i, int j) 
    { 
        char temp; 
        char[] charArray = a.toCharArray(); 
        temp = charArray[i] ; 
        charArray[i] = charArray[j]; 
        charArray[j] = temp; 
        return String.valueOf(charArray); 
    } 
    public static double distance(int a,int b,int x,int y){
    	return Math.sqrt(Math.pow(x-a,2)+Math.pow(y-b,2));
    }
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int tc=1;
		t:
		while(tc-->0){
			int n=Integer.parseInt(br.readLine());
			int[][] towns=new int[n][2];
			for(int i=0;i<n;i++){
				String[] s=br.readLine().split(" ");
				towns[i][0]=Integer.parseInt(s[0]);
				towns[i][1]=Integer.parseInt(s[1]);
			}
			StringBuilder sb=new StringBuilder();
			for(int i=0;i<n;i++){
				sb.append(i);
			}
			permute(sb.toString(),0,n-1);
			double[] tot=new double[al.size()];
			for(int i=0;i<al.size();i++){
				String a=al.get(i);
				for(int j=0;j<a.length()-1;j++){
					tot[i]+=distance(towns[Integer.parseInt(a.substring(j,j+1))][0],towns[Integer.parseInt(a.substring(j,j+1))][1],towns[Integer.parseInt(a.substring(j+1,j+2))][0],towns[Integer.parseInt(a.substring(j+1,j+2))][1]);
				}
			}
			double answer=0.0;
			for(int i=0;i<tot.length;i++){
				answer+=tot[i];
			}
			answer/=al.size();
			System.out.printf("%.10f\n",answer);
		}
	}
}

Measured memory_bytes: 62568
#include <cstdio>


bool solve(int A[], int size, int index, int remain) {
    bool a, b;
    if (remain == 0) {
        return true;
    } else if (size <= index || remain < 0) {
        return false;
    } else {
        a = solve(A, size, index + 1, remain);
        b = solve(A, size, index + 1, remain - A[index]);
    }
    return a || b;
}
int
main () {
    int n, q, A[2000], M[2000];

    scanf("%d", &n);
    for (int i=0; i<n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);

    for (int i=0; i<q; i++) {
        int m;
        scanf("%d", &m);
        if (solve(A, n, 0, m)) {
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }


    return 0;
}

Measured memory_bytes: 1016
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		char[] cstr = scanner.next().toCharArray();
		int count = 0;
		for(char c : cstr){
			if(c == '1'){
				count++;
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 21972
while True:
    r = input()
    if r == "0":
        break
    m = r.count("A")
    n = r.count("B")
    if r[0] == "A":
        m -= 1
    else:
        n -= 1
    if m > n:
        m += 1
    else:
        n += 1
    print(m,n)


Measured memory_bytes: 5552
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

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

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

int i,n,ans[N],sum[N];
vpii g[N];

void dfs(int v,int par)
{
    for(auto p:g[v])
    {
        int u=p.f,w=p.s;
        if(u!=par)
        {
            sum[u]+=sum[v]+w;
            sum[u]&=1;
            ans[u]=1-sum[u];
            dfs(u,v);
        }
    }
}

void solve()
{
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        int u,v,w;
        cin>>u>>v>>w;
        g[u].pb({v,w});
        g[v].pb({u,w});
    }
    ans[1]=1;
    dfs(1,0);
    for(i=1;i<=n;i++)
    {
        cout<<ans[i]<<endl;
    }
}

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

Measured memory_bytes: 15440
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<cstring>
#include<set>
#include<queue>
#include<map>
#include<math.h>

#define ll long long
#define dd double
#define scl(n)        scanf("%lld",&n)
#define scd(n)        scanf("%lf",&n)
#define scc(n)        scanf("%c",&n)
#define scs(n)        scanf("%s",&n)
#define ptl(n)        printf("%lld",n)
#define ptd(n)        printf("%f",n)
#define ptc(n)        printf("%c",n)
#define pts(n)        printf("%s",n)
#define nline         printf("\n")
#define pb            push_back
#define FOR(i,n)      for(ll i=0;i<n;i++)
#define FOR1(i,n)     for(ll i=1;i<=n;i++)
#define FORran(i,a,b) for(ll i=a;i<=b;i++)
#define pi            2*acos(0.0)
#define pii           pair<ll,ll>
#define uu            first
#define vv            second

using namespace std;

int main()
{
    ll d,t,s;
    scl(d);
    scl(t);
    scl(s);
    dd rt=(d*1.0)/s;
    if(rt<=t)
        printf("Yes");
    else
        printf("No");
    return 0;
}


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

const int MAX_=10000000;
bool is_prime[MAX_];

void sieve(){
	fill(is_prime,is_prime+MAX_,true);
	is_prime[0]=is_prime[1]=false;
	for(int i=2; i<MAX_; ++i){
		if(is_prime[i]){
			for(int j=i*2; j<MAX_; j+=i){
				is_prime[j]=false;
			}
		}
	}
}

int solve(int a,int d,int n){
	int count=0;
	int idx=a;
	while(count!=n){
		if(is_prime[idx]) ++count;
		idx+=d;
	}
	idx-=d;
	return idx;
}

int main(){
	sieve();
	int A,D,N;
	while(cin >> A >> D >> N&&!(A==0&&D==0&&N==0)){
		cout << solve(A,D,N) << endl;
	}
	return 0;
}

Measured memory_bytes: 10924
import sys
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

class Searchable_BIT():
    def __init__(self,N):
        self.N = N
        self.node = [0]*(self.N+1)
        self.cnt = 0

    def add(self,a): # 要素 x を追加
        x = a
        self.cnt += 1
        while x <= self.N:
            self.node[x] += 1
            x += x & -x

    def delete(self,x): # 要素 x を削除
        self.cnt -= 1
        while x <= self.N:
            self.node[x] -= 1
            x += x & -x

    def count(self,x): # x以下の要素数
        tmp = 0
        while x > 0:
            tmp += self.node[x]
            x -= x & -x
        return tmp

    def get_maxval(self):
        return self.get_lower_i(self.cnt)

    def get_lower_i(self,i): # i 番目に小さい要素を取得
        NG = -1
        OK = self.N
        while OK-NG > 1:
            mid = (OK+NG)//2
            #print(OK,NG,self.count(mid))
            if self.count(mid) >= i:
                OK = mid
            else:
                NG = mid
        return OK

N,K = inpl()
PP = inpl()

BIT = Searchable_BIT(N+1)
for i in range(1,K):
    BIT.add(PP[i]+1)

ans = [i for i in range(N-K+1)]

cnt = 1
for i in range(N-1):
    if PP[i] < PP[i+1]:
        cnt += 1
    else:
        cnt = 1
    if cnt >= K:
        ans[i-K+2] = -1

for i in range(N-K):
    L,R = PP[i]+1,PP[i+K]+1
    MIN,MAX = BIT.get_lower_i(1), BIT.get_maxval()
    if L <= MIN and MAX <= R:
        ans[i+1] = ans[i]
    BIT.delete(PP[i+1]+1)
    BIT.add(PP[i+K]+1)

print(len(set(ans)))


Measured memory_bytes: 89980
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
	char a[100], b[100];
	scanf("%s%s",a,b);
	int flag = 1;
	for (int i = 0; i < strlen(a); i++)
	{
		if (a[i] != b[strlen(b) - 1 - i])
			flag = 0;
	}
	if (flag)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a,b,c;

  scanf("%d %d %d",&a,&b,&c);

  if(a < b)
    {
      if(b < c)
	{
	  printf("Yes\n");
	}
      else
	{
	  printf("No\n");
	}
    }
  else
    printf("No\n");


  return 0;


}



Measured memory_bytes: 2124
from collections import defaultdict

R, G, B, N = map(int, input().split())
d = defaultdict(int)

for i in range((N//G)+1):
    for j in range((N//B)+1):
        d[i*G+j*B] += 1

ans = 0
for i in range((N//R)+1):
    ans += d[N-(R*i)]
print(ans)

Measured memory_bytes: 43100
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,H,W;
    cin >> N >> W >> H;
    vector<int> S_H(100050,0),S_W(100050,0);
    for(int i=0; i<N; i++){
        int x,y,w;
        cin >> x >> y >> w;
        S_H[max(0,y-w)]++;
        S_H[min(H+1,y+w)]--;
        S_W[max(0,x-w)]++;
        S_W[min(W+1,x+w)]--;
    }
    for(int i=0; i<H; i++){
        S_H[i+1] += S_H[i];
    }
    for(int i=0; i<W; i++){
        S_W[i+1] += S_W[i];
    }
    bool ok_H = true;
    for(int i=0; i<H; i++){
        if(S_H[i] <= 0) ok_H = false;
    }
    bool ok_W = true;
    for(int i=0; i<W; i++){
        if(S_W[i] <= 0) ok_W = false;
    }
    if(ok_H or ok_W){
        cout << "Yes" << enld;
    }else{
        cout << "No" << enld;
    }
    return 0;
}



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

typedef long long ll;
using namespace std;

bool print(int x) {
	cout << x << endl;
	cout.flush();
	string s;
	cin >> s;
	if(s[0] == 'V')
		exit(0);
	return s[0] == 'M';
}

int n;
int get(int l, int r){
	if(l <= r)
		return (l + r) >> 1;
	int len = n - 1 - l + 1 + r;
	return (l + len) % n;
}

int main() {
	ios::sync_with_stdio(false);
	//	srand(time(NULL));
	cin >> n;
	bool m = print(0);
	int p = 0, l = 1, r = n - 1;
	while(1){
		int nxt = get(l, r);
		bool cur = print(nxt);
		// arrab le p
		if(abs(p - nxt) % 2 == (cur == m)){
			if(p < nxt)
				r = nxt - 1;
			else l = nxt + 1;
		}
		// eb3ed
		else{
			if(p > nxt)
				r = nxt - 1;
			else l = nxt + 1;
		}
		m = cur;
		p = nxt;
	}
	return 0;
}

/*
MF.MFMF
 */


Measured memory_bytes: 852
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<map>
#include<deque>
#include<stack>
#include<algorithm>
#define N 105
using namespace std;
const int INF=0x7fffffff;
const double Pi=acos(-1);
int n,m;
char A[N][N];
bool Check_Row(int x)
{
	int i;
	bool OK=1;
	for(i=1;i<=m;i++)if(A[x][i]!='.')OK=0;
	return OK;
}
bool Check_Con(int y)
{
	int i;
	bool OK=1;
	for(i=1;i<=n;i++)if(A[i][y]!='.')OK=0;
	return OK;
}
void Remove_Row(int x)
{
	//cout<<"Remove_Row"<<x<<endl;
	int i,j;
	for(i=x+1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			A[i-1][j]=A[i][j];
		}
	}
	for(j=1;j<=m;j++)A[n][j]=' ';
	n--;
}
void Remove_Con(int y)
{
	//cout<<"Remove_Con"<<y<<endl;
	int i,j;
	for(j=y+1;j<=m;j++)
	{
		for(i=1;i<=n;i++)
		{
			A[i][j-1]=A[i][j];
		}
	}
	for(i=1;i<=n;i++)A[i][m]=' ';
	m--;
}
int main()
{
	int i,j;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			cin>>A[i][j];
		}
	}
	while(1)
	{
		bool OK=0;
		for(i=1;i<=n;i++)if(Check_Row(i)){Remove_Row(i);OK=1;continue;}
		if(OK==1)continue;
		OK=0;
		for(i=1;i<=m;i++)if(Check_Con(i)){Remove_Con(i);OK=1;continue;}
		if(OK==1)continue;
		break;
	}
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			cout<<A[i][j];
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

ll N,T;
ll t[200000];

int main(){
    cin>>N>>T;
    rep(i,N) cin>>t[i];

    ll ans=0;
    rep(i,N-1){
        ans+=min(T,t[i+1]-t[i]);
    }
    ans+=T;

    cout<<ans<<endl;
}

Measured memory_bytes: 5132
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n, m, pv[MAX];
vector<int> G[MAX];
bool used[MAX];

int main(){
    scanf("%d%d", &n, &m);
    rep(i, m){
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    memset(used, false, sizeof(used));
    queue<int> que;
    que.push(0);
    used[0] = true;
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(int nv: G[v])if(!used[nv]){
            que.push(nv);
            used[nv] = true;
            pv[nv] = v;
        }
    }
    puts("Yes");
    For(i, 1, n) printf("%d\n", pv[i] + 1);
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
ll A[202020];
ll S[202020];
vector<ll> V;

template<class V, int ME> class BIT {
public:
	V bit[1<<ME],val[1<<ME];
	V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	V add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
	V set(int e,V v) { add(e,v-val[e]);}
	int lower_bound(V val) {
		V tv=0; int i,ent=0;
		for(i=ME-1;i>=0;i--) if(tv+bit[ent+(1<<i)-1]<val) tv+=bit[ent+(1<<i)-1],ent+=(1<<i);
		return ent;
	}
};

BIT<int,20> bit;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	V.push_back(-1LL<<60);
	V.push_back(0);
	FOR(i,N) {
		cin>>A[i];
		A[i]-=K;
		S[i+1]=S[i]+A[i];
		V.push_back(S[i+1]);
	}
	sort(ALL(V));
	ll ret=0;
	int added=0;
	for(i=N-1;i>=0;i--) {
		x=lower_bound(ALL(V),S[i+1])-V.begin();
		added++;
		bit.add(x,1);
		y=lower_bound(ALL(V),S[i])-V.begin();
		ret += added-bit.total(y-1);
	}
	cout<<ret<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 9968
S = str(input())
flag = False
count = 0
tmp_str = ""
if S.count("C") == 1 and S[0] == "A":
  flag = True
  for i in range(1,len(S),1):
    if S[i] == "C":
      count = i
    else:
      tmp_str += S[i]

if (flag == True) and (count > 1) and (count < len(S)-1) and (tmp_str.islower() == True):
  print("AC")
else:
  print("WA")

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

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<vector<int>> abc(N, vector<int>(3));
    for (int i=0; i<N; i++)
        cin>>abc[i][0]>>abc[i][1]>>abc[i][2];
    vector<vector<int>> T(N, vector<int>(3));
    for (int i=0; i<3; i++)
        T[0][i] = abc[0][i];
    for (int i=1; i<N; i++)
        for (int j=0; j<3; j++)
            for (int k=0; k<3; k++)
                if (k != j)
                    T[i][k] = max(T[i][k], T[i-1][j]+abc[i][k]);
    cout<<*max_element(T[N-1].begin(), T[N-1].end())<<endl;
}


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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int x, y;
  cin >> x >> y;
  rep(i, x + 1) {
    int r = y - 2 * i;
    if (4 * (x - i) == r) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct UnionFind {
  const int n;
  V<> t; // root ? -sz : par
  UnionFind(int n) : n(n), t(n, -1) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, r; cin >> n >> r;
  UnionFind uf(n);
  for (int i = 0; i < n; ++i) {
    int p; cin >> p, --p;
    uf.unite(i, p);
  }
  set<int> se;
  for (int i = 0; i < n; ++i) se.insert(uf.find(i));
  V<> a;
  for (int e : se) a.push_back(uf.size(e));
  bitset<150001> bs;
  bs[0] = true;
  for (int e : a) {
    bs |= bs << e;
  }
  cout << (bs[min(r, n - r)] ? "Yes" : "No") << '\n';
}


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

int main()
{
    int N, cnt_ac = 0, cnt_wa = 0, cnt_tle = 0, cnt_re = 0;
    scanf("%d", &N);

    char str[N][5];

    for(int i = 0; i < N; i++)
    {
        scanf("%s", &str[i]);

        if(strcmp(str[i], "AC") == 0)cnt_ac++;
        if(strcmp(str[i], "WA") == 0)cnt_wa++;
        if(strcmp(str[i], "TLE") == 0)cnt_tle++;
        if(strcmp(str[i], "RE") == 0)cnt_re++;
    }

    printf("AC x %d\n", cnt_ac);
    printf("WA x %d\n", cnt_wa);
    printf("TLE x %d\n", cnt_tle);
    printf("RE x %d", cnt_re);

    return 0;
}

Measured memory_bytes: 4264
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); // number of 
#define ll long long                      //element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after sort  use as s.f();
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std; // assert(a[i]<n ) // if we want to check for special cond , used for debug                     
using namespace __gnu_pbds; // make less_equal in order to make a multiset pbds
#define INF (ll)1e18 
const ll Mod = (ll)1e9+7;
ll CaseN=1;
const ld PI = 22/7.0;


ll tst()
{
	ll ans=0;
	
	
return ans;	
}


void solve()
{
	
	// wr 
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll ans=0;
	// bring all r to frot
	ll c=0;
	for(ll i=0;i<n;i++)
	{
	if(s[i]=='R')
	{
	c++;	
	}	
	}
	// 0 - c-1; 
	ll cc=0;
	for(ll i=0;i<c;i++)
	{
	if(s[i]=='R')
	{
	cc++;	
	}	
	}
	
	ans = c-cc;
	cout<<ans<<endl;
	//cout<<"Case #"<<CaseN<<": ";
	CaseN++;
		// print your ans below;

  return ;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();	
	}
}




Measured memory_bytes: 3708
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
vector<char> V;
int main(){
    ll n;
    cin >> n;
    while(n!=0){
        ll temp=0;
        ll k=0;
        while(temp+pow(26,k+1)<n){
            k++;
            temp+=pow(26,k);
        }
        ll s=(n-temp-1)/pow(26,k)+1;
        char c='a'+s-1;
        //cerr<<c<<endl;
        V.push_back(c);
        n-=s*pow(26,k);
    }
    rep(i,V.size()){
        cout<<V[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 4112
#include <iostream>

using namespace std;

#define int long long

const int N = 2e5 + 10;

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);    
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    ans += (n - 1) / i;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3656
N = int(input())
h = list(map(int,input().split()))
ans = 0
i = 0
while sum(h)>0:
    while i < N and h[i] == 0:
        i += 1
    while i < N and h[i] > 0:
        h[i] -= 1
        i += 1
    ans += 1
    i = 0
print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int N;
    cin >> N;
    int n=N%10;
    if(n==3) cout << "bon" << endl;
    else if(n==0 || n==1 || n==6 || n==8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

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

using namespace std;

typedef long long ll;

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;
}

vector<int> A;

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

    A.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    bool ok = true;
    for (int i = 0; i < (int) A.size() - 1; i++) {
        if (A[i] == A[i + 1]) {
            ok = false;
            break;
        }
    }

    if (ok) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


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

int main(){
  
  int H, W;
  int sum = 0;
  cin >> H >> W;
  vector<vector<char>> grid(H, vector<char>(W, '.'));
  //配列に代入
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
    cin >>  grid.at(i).at(j); 
      
    }
  }
    
    //行成分の判別
  for(int i = 0; i < H; i ++){
    for(int j = 0, sum = 0; j < W; j++){
      
     //成分が「.」ならsumに＋１
      if(grid.at(i).at(j) == '.' ){
        sum += 1;
      }
      if(sum == W){
         for(int k = 0; k < W; k++){
           grid.at(i).at(k) = ' ';
           
        }
      }
    }
  }
  
  
	//列成分の判別
   for(int i = 0; i < W ; i++){
    for(int j = 0, sum = 0; j < H ; j++){
      
     //成分が「.」か空白ならsumに＋１
     if(grid.at(j).at(i) == '.'){
       sum += 1;
     }
      else if(grid.at(j).at(i) == ' '){
         sum += 1;
      }
      //列成分がすべて「.」なら空白を代入
      if(sum == H){
        for(int k = 0; k < H; k++){
         grid.at(k).at(i) = ' '; 
        }
      }
    }
  }
  
  //出力
 for(int i = 0;i < H ; i ++){
   for(int j = 0, sum =0; j < W; j++){
     //空白なら飛ばす
     if(grid.at(i).at(j) == ' '){
       sum += 1;
       if(j == W -1 && sum != W){
      cout << endl;
    }
     continue;
    }
      cout << grid.at(i).at(j);
     //最後の列になったら改行
       if(j == W -1 && sum != W){
      cout << endl;
    }
   }
 }
}

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

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

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

  function< int(vector<int> p,bool f) > rec =
  [&](vector<int> p,bool f){
    int res = 0;
    for(int i = 0; i < n-1; i++){
      if(i == 0){
        if(f == 0) res += p[i];
        else {
          if(p[i] >= p[i+1]){
            res += p[i] + p[i+1];
            p[i+1] = 0;
          }
          else {
            res += p[i] * 2;
            p[i+1] -= p[i];
          }
        }
      }
      else if(p[i] > 0){
        res += p[i] * 2;
        p[i+1] -= p[i];
      }
    }
    return res + max(0LL,p[n-1]);
  };

  int ans = 1 << 30;
  ans = min({ans,rec(p,0),rec(p,1)});
  reverse(p.begin(),p.end());
  ans = min({ans,rec(p,0),rec(p,1)});
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3308
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	int n, k;
	string s; cin >> n >> k >> s;
	s[k - 1] += 32;
	cout << s << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  for (int i = 0; i < H; i++) cin >> a.at(i);
  for (int y = 0; y < H; y++) {
    bool flag_y = false;
    for (int x = 0; x < W; x++) {
      if (a.at(y).at(x) == '#') {
        flag_y = true;
        cout << a.at(y).at(x);
        continue;
      }
      bool flag_x = false;
      for (int h = 0; h < H; h++) {
        if (a.at(h).at(x) == '#') flag_x = true;
      }
      for (int w = 0; w < W; w++) {
        if (a.at(y).at(w) == '#') flag_y = true;
      }
      if (flag_x && flag_y) cout << '.';
    }
    if (flag_y) cout << endl;
  }
}

Measured memory_bytes: 256
n,m=map(int,input().split())
fib=[1]
a=1
b=1
for i in range(n):
    fib.append(b)
    c=b
    b+=a
    a=c

total=1
cannot=0
s=-1
if m==0:
    total=fib[n]%(10**9+7)
else:
    for i in range(m):
        t=int(input())
        if t-s == 1:
            cannot+=1
            break
        else:
            total*=fib[t-s-2]
            total%=10**9+7
        s=t



    if n+1-t <= 1:
        cannot+=1
    else:
        total*=fib[n-t-1]
        total%=10**9+7

if cannot != 0:
    print(0)
else:
    print(total)

Measured memory_bytes: 460148
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}


int dp[100001][3];
int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    int n; cin >> n;
    for(int i = 0; i < n; ++i){
        int a, b, c; cin >> a >> b >> c;
        dp[i+1][0] = max(dp[i][1], dp[i][2]) + a;
        dp[i+1][1] = max(dp[i][0], dp[i][2]) + b;
        dp[i+1][2] = max(dp[i][0], dp[i][1]) + c;
    }
    cout << accumulate(dp[n], dp[n]+3, 3, [](int acc, int x) {return max(acc, x);}) << '\n';
    
    return 0;
}


Measured memory_bytes: 1536
while True:
	a,op,b = input().split(" ")

	if op == "+":
		print(int(a)+int(b))
	elif op == "-":
		print(int(a)-int(b))
	elif op == "*":
		print(int(a)*int(b))
	elif op == "/":
		print(int(a)//int(b))
	elif op == "?":
		break



Measured memory_bytes: 5592
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    string ret = "AC";
    int c_cnt = 0;
    rep(i,n)
    {
        string si = s.substr(i,1);
        if(i==0)
        {
            if(si != "A")
            {
                ret = "WA";
                break;
            }            
        }
        else if(i>=2 && i<n-1)
        {
            if(si == "C")
                c_cnt++;
            else if(!islower(si.c_str()[0]))
            {
                ret = "WA";
                break;
            }
        }
        else
        {
            if(!islower(si.c_str()[0]))
            {
                ret = "WA";
                break;
            }
        }      
    }

    if(c_cnt != 1) ret = "WA";
    cout << ret << endl;
    return 0;
}

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

using namespace std;

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

#define pb push_back
#define mp make_pair

const int maxn=100005;
const ll INF=1e18;

template<class T>void byebye(T _rpl){cout<<_rpl<<endl;exit(0);}
int nextint(){int x;scanf("%d",&x);return x;}
ll nextll(){ll x;scanf("%lld",&x);return x;}
template<class T>T emax(T& t1,T t2){if(t1<t2)t1=t2;return t1;}
template<class T>T emin(T& t1,T t2){if(t1>t2)t1=t2;return t1;}

int read(){
	int f=1,ret=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ret=ret*10+(c-'0');c=getchar();}
	return ret*f;
}

void write(int x){
	if(x<0){putchar('-');write(-x);return;}
	if(x<10){putchar(x+48);return;}
	write(x/10);
	putchar(x%10+48);
}

ll n,a,b,c,dd;
map<ll,ll> ans;

ll pre(ll x,ll y){
	return x/y*y;
}

ll nxt(ll x,ll y){
	if(x%y==0)return x;
	return x/y*y+y;
}

ll d[]={2,3,5};
ll cost[3];

ll dfs(ll x){
	if(x==0)return 0ll;
	if(x==1)return dd; 
	if(ans.count(x))return ans[x];
	ll res=INF;
	for(int i=0;i<3;++i){
		ll p=pre(x,d[i]);
		ll N=nxt(x,d[i]);
		res=min(res,ll(x-p)*dd+dfs(p/d[i])+cost[i]);
		res=min(res,ll(N-x)*dd+dfs(N/d[i])+cost[i]);
	}
	if(INF/dd>=x)res=min(res,dd*x);
	return ans[x]=res;
}

int main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n>>cost[0]>>cost[1]>>cost[2]>>dd;
		ans.clear();
		cout<<dfs(n)<<endl;
	//	for(map<ll,ll>::iterator it=ans.begin();it!=ans.end();++it)cerr<<it->first<<' '<<it->second<<endl;
	}
	return 0;
}



Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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;}
/*
void chmin(ll a, ll b){if (a>b){a = b; return true;}return false;}
void chmax(ll a, ll b){if (a<b){a = b; return true;}return false;}
*/

const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  ll n; cin >>n;
  ll m = (n+1) / 2;
  ll ans = 1;
  vector<ll> a(m, 0);
  for (int i=0; i<n; i++){
    ll buf; cin >>buf;
    if (n%2 == buf%2){
      ans = 0; break;
    }
    a.at(buf/2)++;
  }
  for (int i=0; i<m; i++){
    if (i == 0){
      if (n%2 == 1){
        if (a.at(0) != 1){
          ans = 0; break;
        }
        continue;
      }
    }
    if (a.at(i) != 2){
      ans = 0; break;
    }
    ans = ans * a.at(i) % MOD;
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 640
N = int(input())
A = []
ex = [0]*N
light = 0
c = 0
for i in range(N) :
    A.append(int(input()))

while light != 1 :
    if ex[light] == 1 :
        print('-1')
        exit()
    ex[light] = 1
    light = A[light]-1
    c += 1
    

print(c)

Measured memory_bytes: 7852
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int A=1000005;
int main(){IOS;
	int n;
	cin>>n;
	vector<int>a(n);
	vector<int>b(1000005,0);
	bool pairwise=true;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[a[i]]++;}
		for(int i=2;i<A;i++){
			int cnt=0;
			for(int j=i;j<A;j+=i){
				  cnt+=b[j];}
				  if(cnt>1)
				  pairwise=false;}
				  bool setwise=true;
				  int g=0;
				  for(int i=0;i<n;i++){
					   g=__gcd(a[i],g);}
					  if(g!=1)
					  setwise=false;
					  if(pairwise)
					  cout<<"pairwise coprime"<<endl;
					  else if(setwise)
					  cout<<"setwise coprime"<<endl;
					  else cout<<"not coprime"<<endl;}
					  

Measured memory_bytes: 11092
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

int x[200010], d[200010];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> x[i]; d[i] = x[i]; }
	sort(d, d + n);
	int p,l;
	p = d[(n-1) / 2 + 1];
	l = d[(n-1) / 2];

	for (int i = 0; i < n; i++) {
		if (x[i] <= d[(n-1) / 2])cout << p << endl;
		else if(x[i] >= d[((n-1) / 2)+1])cout << l << endl;
	}


	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,h,w;
  cin>>n>>h>>w;
  int cnt=0;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    if(a>=h&&b>=w)cnt++;
  }
  cout<<cnt<<endl;
  return(0);
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    string s;
    scan(s);

    auto ok = s[0] == 'A' && s[2 .. $ - 1].count!"a == 'C'" == 1;

    foreach (ch ; s) {
        if (ch == 'A' || ch == 'C') continue;
        ok &= ('a' <= ch && ch <= 'z');
    }

    writeln(ok ? "AC" : "WA");
}



















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	int a, b; cin >> a >> b;
	int ans = 0;
	rep(i, 50) {
		int c = (a - 1) / (1LL << (i + 1)) * (1LL << i);
		int a_ = (a - 1) % (1LL << (i + 1));
		c += max(0LL, a_ - (1LL << i) + 1);
		int d = b / (1LL << (i + 1)) * (1LL << i);
		int b_ = b % (1LL << (i + 1));
		d += max(0LL, b_ - (1LL << i) + 1);
		if ((d - c) % 2)ans += 1LL << i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int n,a;
set<int> st;
signed main(){
	cin>>n;
	int ans=0;
	rep(i,n){
		cin>>a;
		if(a>=3200)ans++;
		else st.insert(a/400);
	}
	cout<<max(1,(signed)st.size())<<" "<<st.size()+ans<<endl;
	return 0;
}

Measured memory_bytes: 256
route_num, limit = map(int, input().split(' '))

costs = []
spends = []
for i in range(route_num):
    cost, spend = map(int, input().split(' '))
    costs.append(cost)
    spends.append(spend)

max_cost = 2000
for cost, spend in zip(costs, spends):
    if spend <= limit and cost < max_cost:
        max_cost = cost

if max_cost == 2000:
    print("TLE")
else:
    print(max_cost)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int main(){
  int n,a,i,sum=0,diff=10001,ans=0;
  cin >> n;
  vector<int> m(n);
  for(i=0;i<n;i++){
    cin >> a;
    sum += a;
    m.at(i) = a*n;
  }
  for(i=0;i<n;i++){
    if(abs(m.at(i)-sum)<diff){
      diff = abs(m.at(i)-sum);
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	int height,width,tmp;
	scanf("%d %d",&height,&width);

	int** table = new int*[height+1];
	table[0] = new int[width+1];
	for(int i=0; i < width+1; i++)table[0][i] = 0;

	int max_r = 0;

	for(int i=1; i <= height; i++){
		table[i] = new int[width+1];
		table[i][0] = 0;
		for(int k=1; k <= width; k++){
			scanf("%d",&tmp);
			//table[i][k] = 1-tmp;
			if(tmp != 1){
				table[i][k] = min(table[i-1][k-1],min(table[i][k-1],table[i-1][k]))+1;
				max_r = max(max_r,table[i][k]);
			}else{
				table[i][k] = 0;
			}

		}
	}

	printf("%d\n",max_r*max_r);

    return 0;
}

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

using namespace std;

static int pos = 0;
static vector<int> pre;
static vector<int> in;
static vector<int> post;

static void recursive(int left, int right)
{
    if (left >= right)
        return;

    int index = pre[pos++];
    int m = (int)distance(in.begin(), find(in.begin(), in.end(), index));
    recursive(left, m);
    recursive(m + 1, right);
    post.push_back(index);
}

static void solve()
{
    recursive(0, (int)pre.size());

    for (int i = 0; i < post.size(); i++) {
        if (i > 0)
            cout << " ";
        cout << post[i];
    }
    cout << endl;
}

int main()
{
    int n, k;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> k;
        pre.push_back(k);
    }

    for (int i = 0; i < n; i++) {
        cin >> k;
        in.push_back(k);
    }

    solve();
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  // vector<P> v(n);
  vector<pair<double,double>> v(n);
  rep(i, 0, n) {
    int x, l;
    cin >> x >> l;
    // v[i] = make_pair(x - l + 1, x + l - 1);
    v[i] = make_pair(x - l + 0.1, x + l - 0.1);
  }
  sort(v.begin(), v.end());

  int ans = 0;
  // P now = v[0];
  pair<double, double> now = v[0];
  rep(i, 1, n) {
    if (v[i].first <= now.second) {
      ans++;
      if (v[i].second < now.second) {
        now = v[i];
      }
    } else {
      now = v[i];
    }
  }

  cout << n - ans << endl;
}


Measured memory_bytes: 4764
#include<bits/stdc++.h>
#define N 200005
#define M 2000
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N

using namespace std;

void solve(){
    
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin>>t;
	if(t%10==3){
	    cout<<"bon";
	    return 0;
	}
	t = t%10;
	if(t==0||t==1||t==6||t==8){
	    cout<<"pon";
	    return 0;
	}
	cout<<"hon";
	
}


Measured memory_bytes: 3596
read x n
read s
m=200
for k in `seq 0 101`;do
 y=$k
 for t in $s;do
  if [ $k -eq $t ];then
   y=$m
  fi
 done
 if [ $[(x-m)**2] -gt $[(x-y)**2] ];then
  m=$y
 fi
done
echo $m

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

int main() {
    long long int N, K, P = 1000000000 + 7, ans = 0;
    cin >> N >> K;
    long long int s = K * (K - 1) / 2, g = (2 * N - K + 1) * K / 2;
    for (long long int i = K; i < N + 2; i++) {
        ans += g - s + 1;
        ans %= P;
        s += i;
        g += N - i;

        if (ans < 0) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3632