akhauriyash/Code-Regression huggingface dataset:
N = 12
Parent = [I for I in range(N+1)]
Rank = [0]*(N+1)
def FindParent(X):
    if Parent[X]==X:
        return X
    else:
        Parent[X] = FindParent(Parent[X])
        return Parent[X]

def CheckParent(X,Y):
    return FindParent(X)==FindParent(Y)

def UniteParent(X,Y):
    X = FindParent(X)
    Y = FindParent(Y)
    if X==Y:
        return 0
    if Rank[X]<Rank[Y]:
        Parent[X] = Y
    else:
        Parent[Y] = X
        if Rank[X]==Rank[Y]:
            Rank[X] += 1
            
for GA in [3,5,7,8,10,12]:
    UniteParent(1,GA)
for GB in [6,9,11]:
    UniteParent(4,GB)
X,Y = (int(T) for T in input().split())
print(['No','Yes'][CheckParent(X,Y)])

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

int main() {
    string S;
    cin >> S;

    char c;
    for(c = 'a'; c <= 'z'; c++) {
        int i;
        for(i = 0; i < S.size(); i++) {
            if(S[i] == c) {
                break;
            }
        }
        if(i == S.size()) {
            cout << c << endl;
            return 0;
        }
        if(c == 'z') {
            cout << "None" << endl;
            return 0;
        }
    }
}

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

ll fast(ll a, ll b)
{

    ll ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % m;
        a = (a * a) % m;
        b = b / 2;
    }
    return ans;
}

int main()
{
    ll n;
    cin >> n;
    vector<pair<ll, ll>> vec;
    for (int i = 0; i < n; i++)
    {
        ll a, b;
        cin >> b >> a;
        vec.push_back({a, b});
    }
    ll count = 0;
    ll sum = 0;
    sort(vec.begin(), vec.end());
    for (int i = 0; i < n; i++)
    {
        sum += vec[i].second;
        if (sum > vec[i].first)
        {
            count = 1;
           // cout << "yes" << i << " " << sum << "\n";
        }
    }
    if (count)
        cout << "No";
    else
        cout << "Yes";

    return 0;
}

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

int N,M;
map<string,int> s,t;

int main()
{
    cin>>N;
    for (int i = 0; i < N; i++)
    {
        string x;
        cin>>x;
        s[x]++;
    }

    cin>>M;
    for (int i = 0; i < M; i++)
    {
        string x;
        cin>>x;
        t[x]++;
    }

    int ans = 0;
    for (auto itr=s.begin(); itr!=s.end(); itr++)
    {
        ans = max(ans, s[itr->first] - t[itr->first]);
    }
    
    cout << ans << endl;
    return 0;
}


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

int main() {
    int N, M, C, ans = 0;
    cin >> N >> M >> C;
    vector<int> B(M);
    for(int i = 0; i < M;++i)
        cin >> B[i];
    for(int i = 0; i < N;++i){
        int sum = C;
        for(int j = 0; j < M; ++j) {
            int a;
            cin >> a;
            sum += a * B[j];
        }
        if(sum>0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::marker::*;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        ar: [(Usize1, Usize1); m],
    }
    let ar = ar;
    let res = solve(n, &ar);
    println!("{}", res);
}

fn solve(n: usize, ar: &[(usize, usize)]) -> usize {
    let mut uf = UnionFind::new(n);
    for a in ar {
        uf.unite(a.0, a.1);
    }

    let mut max = 0;
    for i in 0..n {
        max = std::cmp::max(max, uf.size(i));
    }
    max
}

struct UnionFind {
    ar: Vec<isize>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind { ar: vec![-1; n] }
    }

    fn root(&mut self, x: usize) -> usize {
        if self.ar[x] < 0 {
            return x;
        }
        let root = self.root(self.ar[x] as usize);
        self.ar[x] = root as isize;
        root
    }

    fn unite(&mut self, x: usize, y: usize) {
        let x = self.root(x);
        let y = self.root(y);
        if x != y {
            self.ar[x] += self.ar[y];
            self.ar[y] = x as isize;
        }
    }

    fn size(&mut self, x: usize) -> usize {
        let root = self.root(x);
        -self.ar[root] as usize
    }
}


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

int main(){
   int N;
   cin >> N;
   vector<int> vec(N);
   for (int i = 0; i < N; i++){
       cin >> vec.at(i);
   }
   std::sort(vec.begin(), vec.end() );
   int sum = 0;
   for (int i = 0; i < N-1; i++){
       sum += vec.at(i);
   }
   if (vec.at(N-1) < sum){
       cout << "Yes" << endl;
   }
   else {
       cout << "No" << endl;
   }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <limits>
using namespace std;

//static const int MAX = 1000;
void selectionsort(int A[], int N){
    int count = 0;
    for (int i=0;i<N;i++){
        int mini = i;
        for (int j=i+1;j<N;j++){
            if (A[j] < A[mini]){
                mini = j;
            }
        }
        if (i != mini){
            swap(A[i], A[mini]);
            count++;
        }
    }
    cout << A[0];
    for (int i=1;i<N;i++) cout << " " << A[i];
    cout << endl;
    cout << count << endl;
}

int main(){
    int N;
    cin >> N;
    int A[100];
    for (int i=0;i<N;i++) cin >> A[i];
    selectionsort(A, N);
}



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

int main()
{
	int i, n, x, y;
	string s;

	cin >> s;

	n=s.length();
	x=0; y=0;

	if(s[0]=='1')
		y=1;
	else
		x=1;
	for(i=1; i<n; i+=1)
	{
		if(s[i]=='1')
		{
			if(x>0)
				x-=1;
			else
				y+=1;
		}
		else
		{
			if(y>0)
				y-=1;
			else
				x+=1;
		}
	}

	cout << n-x-y << endl;
}

Measured memory_bytes: 512
//#include "stdc++.h"
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
#define int long long int
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD = 1000000007;
const ll mod=1000000006;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
/*
 shuffle(x,x+n,rng) // shuffling elements of x in random order
 */

int32_t main()
{
    IOS;
    int a;
    cin>>a;
    string s;
    cin>>s;
    if(a>=3200)
        cout<<s<<endl;
    else
        cout<<"red"<<endl;
    return 0;
}







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

#define ll long long
int main()
{
    string s;
    cin>>s;
    int ans=15-s.length();
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='o')
            ans++;
    }
    if(ans>=8)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char n[] = new char[4];
        n = sc.next().toCharArray();
        sc.close();
        for (int i = 0; i < 3; ++i) {
            if (n[i] == '1') n[i] = '9';
            else if (n[i] == '9') n[i] = '1';
        }
        System.out.print(n);
    }
}

Measured memory_bytes: 21588
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())

ans = 'No'

# a1b1, a1b2, a1b3
# a2b1, a2b2, a2b3
# a3b1, a3b2, a3b3

for i in range(c11+1):
  a1 = i
  b1 = c11 - a1
  a2 = c21 - b1
  b2 = c12 - a1
  a3 = c31 - b1
  b3 = c13 - a1
  
  #print(a1, a2, a3, b1, b2, b3)
  
  if (a2+b2 == c22) and (a2+b3 == c23) and (a3+b2 == c32) and (a3+b3 == c33):
    ans = 'Yes'
    break
print(ans)
  

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {
  return b != 0 ? gcd(b, a % b) : a;
}
ll A,B,C,D,ans;
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

int main(){
    cin>>A>>B>>C>>D;
    ans=B-(A-1)-(B/C-(A-1)/C)-(B/D-(A-1)/D)+(B/lcm(C,D)-(A-1)/lcm(C,D));
    out(ans);

    
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; ++i)  cin >> s[i];
    vector<vector<int>> row(h), column(w);
    for(int i = 0; i < w; ++i)  column[i].emplace_back(-1);
    for(int i = 0; i < h; ++i){
        row[i].emplace_back(-1);
        for(int j = 0; j < w; ++j){
            if(s[i][j] == '.')  continue;
            row[i].emplace_back(j);
            column[j].emplace_back(i);
        }
        row[i].emplace_back(w);
    }
    for(int i = 0; i < w; ++i)  column[i].emplace_back(h);
    vector<vector<int>> score(h, vector<int>(w, 0));
    for(int i = 0; i < h; ++i){
        int sz = row[i].size();
        for(int j = 0; j + 1 < sz; ++j){
            int& l = row[i][j];
            int& r = row[i][j + 1];
            int len = r - l - 1;
            for(int k = l + 1; k < r; ++k){
                score[i][k] += len;
            }
        }
    }
    for(int i = 0; i < w; ++i){
        int sz = column[i].size();
        for(int j = 0; j + 1 < sz; ++j){
            int& l = column[i][j];
            int& r = column[i][j + 1];
            int len = r - l - 1;
            for(int k = l + 1; k < r; ++k){
                score[k][i] += len - 1;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            chmax(ans, score[i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 54400
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	final int MAX = Integer.MAX_VALUE;
	class Pair {
		int x, y;
		Pair() {}
		Pair(int y, int x) {
			this.y = y; this.x = x;
		}
	}
	
	char[][] map;
	int[][] d;
	int h,w;
	
	void run() {
		Scanner scan = new Scanner(System.in);
		h = scan.nextInt();
		w = scan.nextInt();
		int n = scan.nextInt();
		Pair p = new Pair();
		map = new char[h][w];
		d = new int[h][w];
		
		for (int i = 0; i < h; i++) {
			String str = scan.next();
			for (int j = 0; j < w; j++) {
				d[i][j] = MAX;
				map[i][j] = str.charAt(j);
				if (map[i][j] == 'S') {
					p.y = i;
					p.x = j;
				}
			}
		}
		
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			sum += solve(p, i);
			for (int j = 0; j < h; j++) {
				for (int k = 0; k < w; k++) {
					d[j][k] = MAX;
					if (map[j][k] == i + '0') {
						p.y = j; p.x = k;
					}
				}
			}
		}
		System.out.println(sum);
	}
	
	int solve(Pair p, int lebel) {
		Queue<Pair> que = new ArrayDeque<Pair>();
		int[] vi = { 0, 0, -1, 1};
		int[] vj = {-1, 1,  0, 0};
		que.add(p);
		
		d[p.y][p.x] = 0;
		
		while (!que.isEmpty()) {
			Pair pair = que.poll();
			if (map[pair.y][pair.x] == lebel + '0')
				return d[pair.y][pair.x];
			int y = 0, x = 0;
			for (int i = 0; i < 4; i++) {
				y = pair.y + vi[i];
				x = pair.x + vj[i];
				if (y >= 0 && y < h && x >= 0 && x < w && map[y][x] != 'X' && d[y][x] == MAX) {
					que.add(new Pair(y, x));
					d[y][x] = d[pair.y][pair.x] + 1;
				}
			}
		}
		return -1;
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define MOD pow(10,9)+7
#define LLINF pow(2,61)-1
#define INF pow(2,29)-1

int main() {
  int N, M; cin >> N >> M;
  bool to[N][N] = {};
  rep(i,M) {
    int s, t; cin >> s >> t; s--; t--;
    to[s][t] = true;
  }

  double num_from[N] = {}; rep(i,N) rep(j,N) num_from[i] += to[i][j];
  double exp[N] = {};
  for (int i=N-1; i>=0; i--) {
    if (i==N-1) continue;
    for (int j=N-1; j>i; j--) exp[i] += (exp[j]+1) * to[i][j];
    exp[i] /= num_from[i];
  }
  // rep(i,N) cout << exp[i] << " "; cout << endl;

  double result = exp[0];
  rep(i,N) {
    int num = -1, count = 0;
    for (int j=i+1; j<N; j++) {
      if (to[i][j]) {
        if (num==-1||exp[num]<exp[j]) num = j;
      }
    }
    if (num_from[i]<=1) continue;

    double tmp_exp[N] = {};
    for (int from=N-1; from>=0; from--) {
      if (from>i) { tmp_exp[from] = exp[from]; continue; }
      for (int j=N-1; j>from; j--) {
        if (from==i&&j==num) continue;
        tmp_exp[from] += (tmp_exp[j]+1) * to[from][j];
      }
      tmp_exp[from] /= ( from==i ? num_from[from]-1 : num_from[from] );
    }
    result = min(result, tmp_exp[0]);
    // cout << i << "->" << num << ":"; rep(i,N) cout << tmp_exp[i] << " "; cout << endl;
  }

    cout << fixed << setprecision(10) << result << endl;
  return 0;
}

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

signed main(){
    int n, ma,mb;
    cin >> n >> ma>>mb;
    int a,b,c;
    pair<int,int> p[n];
    for(int i=0;i<n;i++){
        cin >> a >> b >>c;
        p[i]= make_pair(c,mb*a-ma*b);
    }
    int n2 = n/2;
    int t[n+1][8001];
    for(int i=0;i<n+1;i++){
        for(int j=0;j<8001;j++)t[i][j]=0;
    }
  //  int s[4001]={};
    for(int i=0;i<n;i++){
        if(t[i][4000+p[i].second]==0)t[i+1][4000+p[i].second]=p[i].first;
        else t[i+1][4000+p[i].second]=min(p[i].first,t[i][4000+p[i].second]);
        for(int j=0;j<8001;j++){
            if(0<=j-p[i].second&& 8001>j-p[i].second&&(t[i][j-p[i].second]!=0&&j-p[i].second!=4000)){
                if(t[i][j]!=0)t[i+1][j]=min(t[i][j-p[i].second]+p[i].first,t[i][j]);
                else t[i+1][j]=t[i][j-p[i].second]+p[i].first;
            }else{
                if(j-p[i].second!=4000) t[i+1][j] = t[i][j];
            }
        }
    }
 //   for(int i=n2;i<n;i++){
   //     if(s[2000+p[i].second]==0)s[2000+p[i].second]=p[i].first;
    //    else s[2000+p[i].second]=min(p[i].first,s[2000+p[i].second]);
      //  for(int j=0;j<4001;j++){
   //         if(0<=j+p[i].second&& 4001>j+p[i].second&&(s[j]!=0&&j!=2000)){
 //               if(s[j+p[i].second]!=0)s[j+p[i].second]=min(s[j]+p[i].first,s[j+p[i].second]);
     //           else s[j+p[i].second]=s[j]+p[i].first;
   //         }
    //    }
   // }
if(t[n][4000]==0)cout << -1;
else cout << t[n][4000];

    

    return 0;
}

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

using namespace std;
int c[100001];
int n;
typedef long long ll;


bool solu(int s) {
    int counter = 0;
    for (int i = 0; i < n; ++i) {
        if (c[i] >= s)counter++;
    }
    if (counter >= s)return true;
    else return false;
}

int main() {
    string s;cin>>s;
    int freq[200]={0};
    freq[s[0]]++;
    freq[s[1]]++;
    freq[s[2]]++;
    if(freq['a']==1&&freq['b']==1&&freq['c']==1)cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int lim = 1e5;
    vector<int> numfact(lim+1, 0);
    for(int i=2; i<lim; i++){
        for(int j=i*2; j<=lim; j+=i){
            numfact[j]++;
        }
    }
    vector<int> ans(lim+1);
    for(int i=0; i<=lim; i++){
        ans[i] = (numfact[i]>2)? 1: 0;
        if(i>0) ans[i] += ans[i-1];
    }
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        cout << ans[a] << endl;
    }
    return 0;
}



Measured memory_bytes: 3632
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    else:
        for i in range(h):
            for j in range(w):
                if (i+j)%2 == 0:
                    print('#', end="")
                else:
                    print('.', end="")
            print()
        print()


Measured memory_bytes: 7000
N,A=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
for i in range(1,N):
    tmp=max(0,(a[i-1]+a[i])-A)
    if i==1:
        if a[1]<tmp:
            a[0]-=tmp-a[1]
            a[1]=0
            cnt+=tmp
            continue
    
    cnt+=tmp
    a[i]-=tmp
    
print(cnt)

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

int A[3][3];
int b[11];
int C[3][3];

int main(void) {
 
    for (int i=0;i<3;i++)
        for (int j=0;j<3;j++)
            C[i][j] = 0;

    for (int i=0;i<3;i++)
        for (int j=0;j<3;j++)
            cin >> A[i][j];

    int N;
    cin >> N;

    for (int i=0;i<N;i++)
        cin >> b[i];

    for (int i=0;i<3;i++)
        for (int j=0;j<3;j++)
            for (int k=0;k<N;k++)
                if (b[k] == A[i][j]) C[i][j] = 1;

    int ans = 0;

    ans += (C[0][0] & C[0][1] & C[0][2]);
    ans += (C[1][0] & C[1][1] & C[1][2]);
    ans += (C[2][0] & C[2][1] & C[2][2]);
    ans += (C[0][0] & C[1][0] & C[2][0]);
    ans += (C[0][1] & C[1][1] & C[2][1]);
    ans += (C[0][2] & C[1][2] & C[2][2]);
    ans += (C[0][0] & C[1][1] & C[2][2]);
    ans += (C[2][0] & C[1][1] & C[0][2]);

    if (ans > 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long[] a = new long[5];
		int n = in.nextInt();
		for(int i=0;i<n;i++) {
			String str = in.next();
			char c = str.charAt(0);
			if(c=='M') a[0]++;
			else if(c=='A') a[1]++;
			else if(c=='R') a[2]++;
			else if(c=='C') a[3]++;
			else if(c=='H') a[4]++;
		}
		long sum = 0;
		for(int i=0;i<=2;i++) {
			for(int j=i+1;j<=3;j++) {
				for(int k=j+1;k<=4;k++) {
					sum += a[i]*a[j]*a[k];
				}
			}
		}
		System.out.println(sum);
		in.close();
	}

}


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

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


int main(){
  int n,k,q; cin>>n>>k>>q;
 vector<int> vec(n);
  for(int i=0;i<n;i++)vec[i]=k-q;
  for(int i=0;i<q;i++){
   int a; cin>>a;
   vec[a-1]++;
  }
  for(int i=0;i<n;i++){

    if(vec[i]>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 1024
import java.util.Scanner

object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt
    val K = sc.nextInt
    
    var sunuke = List.fill(N)(0)
    
    for(i <-  1 to K){
    
        var d = sc.nextInt
        
        var list = List.fill(d)(sc.nextInt)
    
        list.foreach { v =>
            var okashi = sunuke(v - 1) + 1
            sunuke = sunuke.updated(v - 1, okashi)
        }
 
    }

    println( sunuke.count(_ == 0))
  }
}


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

struct SegmentTree {
    using T = int;
    static T op(const T& a, const T& b) { return a | b; }
    static constexpr T e() { return 0; }
    const int n;
    vector<T> t;
    SegmentTree(int _n) : n(_n), t(2 * n, e()) {}
    T& operator[](int i) { return t[i + n]; }
    T query(int l, int r) const {
        T resl = e(), resr = e();
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) resl = op(resl, t[l++]);
            if (r & 1) resr = op(t[--r], resr);
        }
        return op(resl, resr);
    }
    void update(int i, const T& a) {
        t[i += n] = a;
        while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
};

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    SegmentTree seg(n);
    for (int i = 0; i < n; i++) {
        seg.update(i, 1 << (s[i] - 'a'));
    }
    int q;
    cin >> q;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            seg.update(i, 1 << (c - 'a'));
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            int a = seg.query(l, r);
            cout << __builtin_popcount(a) << endl;
        }
    }
}

Measured memory_bytes: 4868
#include <bits/stdc++.h>
 
using namespace std;
int n;
vector<pair<int, int> > tasks;

int main(void){ 
  	cin >> n;
	for (int i = 0; i < n; i++) { 
	int a, b;
	cin >> a >> b;
    tasks.emplace_back(b, a); // 〆切 (, 所要時間)
    }
  
	sort(tasks.begin(), tasks.end()); 
	int sum = 0;
	bool isyes = true;
	for (auto v : tasks) {
		sum += v.second;
		if (sum > v.first) { 
        	isyes = false;
			break; 
        }
    }

 		cout << (isyes ? "Yes" : "No") << endl; 
 		return 0;
 }



Measured memory_bytes: 2420
#include<cstdio>
#include<algorithm>
using std::min;
#include<vector>
using std::vector;
#define reg register
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
	reg bool f=false;
	reg char ch=getchar();
	reg int res=0;
	while(ch<'0'||'9'<ch)f|=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')res=10*res+ch-'0',ch=getchar();
	return f?-res:res;
}

const int MAXN=600+5;
const int MAXM=(MAXN*(MAXN-1))>>1;

int n,m;
int u[MAXM],v[MAXM];
double P[MAXN];
double E[MAXN][MAXN];
vector<int> V[MAXN];

int main(void){
    reg int i,j,k,size;
	reg double ans;
	n=read(),m=read();
	for(i=1;i<=m;++i){
		u[i]=read(),v[i]=read();
		V[u[i]].push_back(v[i]);
	}
	for(i=n-1;i>=1;--i){
		P[i]=1;
		size=V[i].size();
		for(j=0;j<size;++j)
			P[i]+=P[V[i][j]]/size;
	}
	for(i=1;i<=n-1;++i){
		if(V[i].size()==1u)
			continue;
		E[i][i]=1;
		for(j=i-1;j>=1;--j){
			size=V[j].size();
			for(k=0;k<size;++k)
				E[j][i]+=E[V[j][k]][i]/size;
		}
	}
	ans=P[1];
	for(i=1;i<=m;++i){
		if(V[u[i]].size()==1)
			continue;
		double newf=(P[u[i]]*V[u[i]].size()-P[v[i]]-1)/(V[u[i]].size()-1);
		ans=min((double)ans,P[1]+E[1][u[i]]*(newf-P[u[i]]));
	}
	printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
  ll x,k,d;
  cin >> x >> k >> d;
  x = abs(x);
  k -= abs(x/d);
  x = x%d;
  if(k<=0){
    cout << abs(x-k*d) << endl;
  }
  else{
    if(k%2==0) cout << x << endl;
    else cout << abs(x-d) << endl;
  }
  return 0;
}

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

int main(){
  int N,ans=0,cnt=0;
  cin >> N;
  long long H[N];
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  for(int j=1;j<N;j++){
    if(H[j]<=H[j-1]){
      cnt++;
    }
    else{
      ans=max(ans,cnt);
      cnt=0;
    }
    if(j==N-1){
      ans=max(ans,cnt);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define N 100

int main(){

  int n,A[N],i,j,k,count=0,flag,temp;

  scanf("%d",&n);

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

    for(j=n-1;j>=1;j--){
      if(A[j]<A[j-1]){
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;
	flag=1;
	count++;
      }

    }
    
  }

  for(k=0;k<n;k++){
    if(k)printf(" ");
    printf("%d",A[k]);
    
  }

  printf("\n");

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

  return 0;
}



Measured memory_bytes: 2144
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,m;
	string s;
	cin >> n >> m >> s;
	m-=1;
	for(int i = 0; i < n; i++)
		if(i == m)
			cout << char(s[i] + 32);
		else 
			cout << s[i];
}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] cin = Console.ReadLine().Split();
        int a = int.Parse(cin[0]);
        int b = int.Parse(cin[1]);
        int[] p = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

        int x = 0;
        int y = 0;
        int z = 0;
        for (int i = 0; i < n; i++)
        {
            if (p[i] <= a) x++;
            else if (p[i] <= b) y++;
            else z++;
        }

        Console.WriteLine(Math.Min(x, Math.Min(y, z)));
    }
}

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

string A;

int main(){
  cin >> A;
  int jisu = A.size();
  
  int res = 1;
  while(true){
    if(res > jisu) break;
  	cout << A[res - 1];
    res += 2;
  }
  cout << endl;
}

Measured memory_bytes: 512
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] strAry = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			if (i == strAry.length - 1) System.out.println(strAry[0]);
			else System.out.print(strAry[strAry.length - i - 1] + " ");
		}
	}
}

Measured memory_bytes: 24264
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<int,P> PP;

vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main()
{
	
	string s;
	cin >> s;
	if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad" << endl;
	else cout << "Good" << endl;
	return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

const int MAX_N = 1e6+5;
int prime[MAX_N];
bool is_prime[MAX_N];

int seive(int n) {
  rep(i, 0, MAX_N) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;

  int p = 0;

  rep(i, 2, n+1) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2*i; j <= n; j += i) is_prime[j] = false;
    }
  }

  return p;
};

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

  int n;
  while (cin >> n) {
    cout << seive(n) << endl;
  }

  return 0;
};



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


ll N,K,M;

int main() {
    cin >> N >> M >> K;
    if(N-K>=0){
        cout << N-K << " " << M << endl;
    }else if(N+M-K>=0){
        cout << 0 << " " << N+M-K << endl;
    }else{
        cout << 0 << " " << 0 <<  endl;
    }
}


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

using namespace std;

void solve()
{
    int n;
    cin >> n;
    if ('A' <= n && n <= 'Z')
    {
        cout << 1 << endl;
    }
    else if ('a' <= n && n <= 'z')
    {
        cout << 2 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}

int main()
{
    solve();
    return 0;
}



Measured memory_bytes: 3104
#include <stdio.h>
#include <math.h>

int main()
{
	int i, n;
    double xa, ya, ra, xb, yb, rb;
    double d;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb);
        d = sqrt(pow(xa-xb, 2)+pow(ya-yb, 2));
        if(d > ra + rb) printf("0\n");
        else if(d < ra - rb) printf("2\n");
        else if(d < rb - ra) printf("-2\n");
        else printf("1\n");
    }
    return 0;
}

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

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

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    if s[s.len() - 1] == 's' {
        println!("{}es", s.into_iter().collect::<String>());
    } else {
        println!("{}s", s.into_iter().collect::<String>());
    }
}


Measured memory_bytes: 2144
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int ans = 1;
        for (int i = 0; i < 3; i++) {
            ans *= a;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
n,k = map(int,input().split())
a = list(map(int,input().split()))
c = 0
mod = (int)(1e9+7)
num = [0 for _ in range(2001)]
for v in a:
  num[v]+=1
for i in range(1,2001):
  num[i]+=num[i-1]
s = set(a)
for v in s:
  c += (num[v]-num[v-1])*num[v - 1]
nn = k-1
if (nn%2==0):
  mul = int((nn//2)*(nn-1))
  mul+=nn
else:
  mul = (nn//2 +1)*nn
now = mul*c
now%=mod
total = 0
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]>a[j]:
      total+=1
total*=k
total%mod
final = total+now
print(final%mod)

Measured memory_bytes: 3188
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool pallindrome(string s)
{
    string t(s.rbegin(),s.rend());
    return s==t;
}
int main()
{
   string s;
   cin>>s;
   int n=s.size();
   bool f=true,b=true;
   if(pallindrome(s)&&pallindrome(s.substr(0,(n-1)/2))&&pallindrome(s.substr((n+1)/2)))
   cout<<"Yes\n";
   else
   cout<<"No\n";
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

long long  mod = 1000000007;


int a[100010];

int main(){
	int n;
	cin >> n;
	int ans =0;
	rep(i,n){
		int b;
		cin >> b;	
		if(b>n){
			ans++;
		}else{
			a[b]++;
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]>=i){
			ans += a[i]-i;
		}else{
			ans += a[i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

void solve(){
    int n; cin >> n;
    int dp[n+1];
    int h[n+1];
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for(int i = 3; i <= n; i++){
        int h1 = dp[i-1] + abs(h[i]-h[i-1]);
        int h2 = dp[i-2] + abs(h[i]-h[i-2]);
        dp[i] = min(h1, h2);
    }
    // for(int i = 1; i <= n; i++)cout << dp[i] << " ";
    // cout << endl;
    cout << dp[n] << endl;
}

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

Measured memory_bytes: 1024
/**
 * Created by hiramekun at 19:56 on 2019-12-29.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll a, b, k;
    cin >> a >> b >> k;
    ll aminus = min(a, k);
    ll bminus = min(b, k - aminus);
    cout << a - aminus << ' ' << b - bminus << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
"""
全探索
"""
n = int(input())
ans = 0
for num in range(1,n+1) :
    count = 0
    for i in range(1,num+1) :
        if num%i == 0 :
            count += 1
    if count == 8 and num%2 :
        ans += 1
print(ans)


Measured memory_bytes: 8996
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0){
				return;
			}
			long[][] score = new long[2][n];
			for(int i = 0;i < m;i++){
				int s = sc.nextInt();
				int k = sc.nextInt();
				int[] c = new int[k];	
				for(int j = 0;j < k;j++){
					c[j] = sc.nextInt()-1;
					score[0][c[j]] += s;
				}
				if(k == 1) {
					score[1][c[0]] += s;
				}
			}
			long max = 0;
			int maxIndex = 0;
			long max2 = 0;
			int maxIndex2 = 0;
			for(int i = 0;i < n;i++){
				if(score[0][i] >= max){
					max = score[0][i];
					maxIndex = i;
				}
			}
			for(int i = 0;i < n;i++){
				if(i == maxIndex){
					continue;
				}
				if(score[0][i] >= max2){
					max2 = score[0][i];
					maxIndex2 = i;
				}
			}
			long min = Long.MAX_VALUE;
			int minIndex = 0;
			long min2 = Long.MAX_VALUE;
			int minIndex2 = 0;
			for(int i = 0;i < n;i++){
				if(score[1][i] <= min){
					min = score[1][i];
					minIndex = i;
				}
			}
			for(int i = 0;i < n;i++){
				if(i == minIndex){
					continue;
				}
				if(score[1][i] <= min2){
					min2= score[1][i];
					minIndex2 = i;
				}
			}
			long ans = 0;
			if(minIndex == maxIndex){
				ans = max2 - min+1;
				ans = Math.max(ans,max - min2+1);	
				System.out.println(ans);
				continue;
			}
			ans = max - min +1;
			System.out.println(ans);
		}
	}
}



Measured memory_bytes: 163332
#include <bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)

using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;
	vi a(n);
	rep(i, 0, n) cin >> a[i];

	vi dp(200000, INT_MAX);
	dp[0] = 0;
	dp[1] = abs(a[0] - a[1]);

	rep(i, 2, min(n, k)) {
		rep(j, 0, i) {
			dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
		}
	}
	
	rep(i, k, n) {
		
		rep(j, 1, k + 1) {
			dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
		}
	}
	cout << dp[n - 1] << endl;
}

int main() {
	int t = 1;
	//cin >> t;
	while(t--)
		solve();

	return 0;
}


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

long long knapsack(vector<int> w, vector<int> v, int W){
    int n=w.size();
    vector<vector<long long>> vec(n+1, vector<long long>(W+1));
    for(int i=0; i<=n; i++){
        for(int j=0; j<=W; j++){
            if(i==0 || j==0) vec[i][j]=0;
            else if(j<w[i-1]) vec[i][j]=vec[i-1][j];
            else {
                vec[i][j] = max(v[i-1]+vec[i-1][j-w[i-1]], vec[i-1][j]);
            }
        }
    }
    return vec[n][W];
}

int main(){
  int n,W;
  cin>>n>>W;
  vector<int> w(n),v(n) ;
  for(int i=0; i<n; i++) cin>>w[i]>>v[i];
  cout<<knapsack(w, v, W);
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n;
	string s;
	cin >> n >> s;
	s.erase(unique(s.begin(), s.end()), s.end());
	cout << s.length();
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#define LEN 300
#define TRUE 1
#define FALSE -1

int solve(int, int);
int n, A[LEN];
int flag;

int main()
{
  int q, M;
  int i, j, k;

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

  scanf("%d", &q);
  for(i=0; i<q; i++)
    {
      scanf("%d", &M);
      flag=FALSE;

      solve(-1, M);
      if(flag==TRUE)printf("yes\n");
      else printf("no\n");
    }


  return 0;
}

int solve(int i, int m)
{
  if(i>n)return FALSE;
  else if(m<0)return FALSE;
  else if(m==0 || m-A[i+1]==0)
    {
      flag=TRUE;
      return TRUE;
    }
  else
    {
      //not use A[i]
      solve(i+1, m);
      //use A[i]
      solve(i+1, m-A[i]);
    }
}

Measured memory_bytes: 376
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200002
int main()
{
    int n,ans=0;
    bool solve = 0;
    char s[MAXN];
    scanf("%d%s",&n,s);
    int cnt = n;
    for(int i=0;i<n;i++)
    {   
        if(s[i]=='W')
        {
            while(s[cnt] != 'R')
            {
                cnt--;
                if(cnt<=i)
                {
                    solve=1;
					break;               	
				}
            }
            if(solve == 1)
            {
            	break;
			}
            ans++;
            swap(s[i],s[cnt]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3848
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
typedef long long ll;

using namespace std;

int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c>>d>>e>>k;
  if ((e - a) <= k) cout << "Yay!";
  else cout << ":(";
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int A;
  int p;
  int x;
  int y;
  int z;
  scanf("%d",&A);
  scanf("%d",&p);
  x=p/2;
  y=p%2;
  z=(A*3+y)/2;
  printf("%d",x+z);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,n;
cin>>a;
n=a%10;
if(n==2 || n==4 || n==5 || n==7 || n==9)
cout<<"hon"<<endl;
else if(n==0 || n==1 || n==6 || n==8)
cout<<"pon"<<endl;
else
    cout<<"bon"<<endl;
return 0;

}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll K,S;
    //string S;
    cin >> K>>S;

    ll ans = 0;

    REP(i,K+1){
        REP(j,K+1){
            ll tmp = S - i - j;
            if(tmp>=0&&tmp<=K){
                ans++;
            }
        }
    }

    cout << ans << endl;

}


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

int main() {
  string w;
  cin >> w;
  if (w.size() %2 == 1) {
    cout << "No" << endl;
  }
  else {
    sort (w.begin(), w.end());
    int n = w.size()/2;
    int cnt = 0;
    
    for (int i=0; i<n; i++) {
      if (w.at(2*i) == w.at(2*i+1)) {
      }
      else {
        cnt++;
      }
    }
    
    if (cnt == 0){
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <random>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <iterator>
#include <climits>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
#define INF 2001001001
#define MOD 1000000007

int N,A,B,C,D;
string S;

int main()
{
  //ios_base::sync_with_stdio(0);cin.tie(0);
  //freopen (".in","r",stdin);
  //freopen (".out","w",stdout);
  cin>>N>>A>>B>>C>>D; A--; B--; C--; D--;
  cin>>S;
  int cur=0;
  bool space=false;
  for (int i=0;i<N;i++){
    if (i+1==N || S[i]!=S[i+1]){
      if (S[i]=='#' && cur>=2 && ((i>=A && i<=C) || (i>=B && i<=D))){
	cout<<"No"<<endl;
	return 0;
      }
      if (S[i]=='.' && cur>=3 && i-1>=B && i-1<=D)
        space=true;
      cur=0;
    }
    cur++;
  }
  if (C<D || C<B || space)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    // read in integers 
    ll a, b;
    cin >> a >> b; 

    ll lcm = a;

    while(true){
        if (lcm % b == 0){
            cout << lcm << endl;
            return 0;
        }
        lcm = lcm + a;
        // cout << lcm << endl;
    }
}

Measured memory_bytes: 256
//============================================================================
// Name        : HelloWorld.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
typedef long long ll;
using namespace std;
string A,B,C;
int main() {
	cin>>A>>B>>C;

	cout<<"A"<<B[0]<<"C"<<endl;
	return 0;
}


Measured memory_bytes: 256
H, W, M = map(int, input().split())
r = [0]*(W+1)
c = [0]*(H+1)
rc = {}
for i in range(M):
    h, w = map(int, input().split())
    rc[(h, w)] = True
    r[w] += 1
    c[h] += 1

rm = max(r)
cm = max(c)

ri = {i for i, v in enumerate(r) if v == rm}
ci = {i for i, v in enumerate(c) if v == cm}

cnt = sum([w in ri and h in ci for h, w in rc])
print(rm+cm-(len(ri)*len(ci) == cnt))


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

struct UF{
	vector<int> p;
	UF() {}
	UF(int n) : p(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return false;
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
	int size(int a){ return -p[find(a)]; }
};

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	UF uf(n);
	rep(i, m){
		int x, y, z;
		cin >>x >>y >>z;
		uf.unite(x-1, y-1);
	}
	int ans = 0;
	rep(i, n) ans += uf.root(i);
	cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long P = sc.nextLong();

        long ans = gcd(P, N);
        if(N==1){
            ans = P;
        }
        System.out.println(ans);
    }

    private static long gcd(long p, long n) {
        long gcd = 1;

        long m = p;
        int count = 0;

        for (long i = 2; (i * i) <= p; i++) {
            count = 0;
            while (m % i == 0) {
                count++;
                m /= i;
            }
            if (count >= n) {
                gcd *= (long) Math.pow(i, count / n);
            }
        }
        return gcd;
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

#define MOD 1000000007
using namespace std;

int n, m;
string s;

int main() {
	cin >> n >> m;
  if(m==1){cout<<0<<endl;return 0;}
	cout << n - m<<endl;
}

Measured memory_bytes: 256