akhauriyash/Code-Regression huggingface dataset:
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	ll dp[101][4][4][4] = { 0 };
	const ll mod = 1e9 + 7;
	ll N; cin >> N;

	rep(i, 4) dp[1][3][3][i] += 1;

	fori(n, 1, N) {
		rep(h, 4) rep(i, 4) rep(j, 4) rep(k, 4) {
			if (!((i == 0 && j == 1 && k == 2) ||
				(h == 0 && j == 1 && k == 2) ||
				(i == 1 && j == 0 && k == 2) ||
				(i == 0 && j == 2 && k == 1) ||
				(h == 0 && i == 1 && k == 2))) {
				dp[n + 1][i][j][k] = (dp[n][h][i][j] + dp[n + 1][i][j][k]) % mod;
			}
		}
	}

	ll sum = 0;
	rep(i, 4) rep(j, 4) rep(k, 4) sum = (sum + dp[N][i][j][k]) % mod;
	cout << sum << endl;
}

Measured memory_bytes: 256
S = str(input())

def rot(S):
    size = len(S)
    for i in range(size // 2):
        if S[i] != S[-(i + 1)]: return False
    return True

if not rot(S):
    print("No")
elif not rot(S[0 : len(S) // 2]):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 38384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
  int n;
  int *score;
  double ave, var, tmp;

  while(1){
    scanf("%d", &n);
    if(n == 0) break;
    score = malloc(sizeof(int)*n);
    ave = 0;
    var = 0;
    for(int i=0;i<n;i++){
      scanf("%d", (score+i));
      ave += score[i];
    }
    ave /= n;
    for(int i=0;i<n;i++){
      tmp = score[i] - ave;
      var += tmp * tmp;
    }
    var /= n;
    var = sqrt(var);
    printf("%.8f\n", var);
    free(score);
  }
  return 0;
}



Measured memory_bytes: 2048
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int main()
{
    int n, a, b;

    cin >> n >> a >> b;

    int ans = 0;
    REP(i, n){
        int t;
        cin >> t;
        if(t < a || t >= b){
            ans++;
        }
    }

    cout << ans << endl;
}

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

ll mod_pow(ll a,ll b){
    ll res=1;
    vector<ll> mm(60);
    mm[0]=a%mod;
    for(int i=1; i<=59; i++){
        mm[i]=mm[i-1]*mm[i-1]%mod;
    }
    for(int i=0; i<=59; i++){
        if(b>>i & 1)
            res=res*mm[i]%mod;
    }
    return res;
}

int main(){
    ll m,n;
    cin >> m >> n;
    cout << mod_pow(m,n) << endl;
    return 0;
}


Measured memory_bytes: 3108
S = gets.strip.to_i

x1=0
y1=0
x2=1
y2=1000000000
x3=S/1000000000+1
y3=1000000000-(S%1000000000)
if S%1000000000==0
    x3-=1
    y3=0
end
puts "#{x1} #{y1} #{x2} #{y2} #{x3} #{y3}"



Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);++i)
#define reps(i,n) for(int i = 1;i <= (n);++i)
using namespace std;
int main(){
  int m;
  cin >> m;
  cout << 48 - m << '\n';
  return 0;
}

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

int main() {
  long n,z,w,ans;
  cin >> n >> z >> w;
  vector<long> a(n);
  for(long i=0;i<n;i++) cin >> a[i];
  ans=labs(a[n-1]-w);
  if(n>1) ans=max(ans,labs(a[n-2]-a[n-1]));
  cout << ans << endl;
}

Measured memory_bytes: 3612
a,b = map(int,input().split())
if a <= 0 and b >= 0 or a >= 0 and b <= 0 or a == 0 or b == 0:
  print("Zero")
elif a > 0 and b > 0 or (a+b) % 2 == 1: 
  print("Positive")
else:
  print("Negative")

Measured memory_bytes: 3060
#define		_CRT_SECURE_NO_WARNINGS
#define		_USE_MATH_DEFINES

#include	<cstdio>
#include	<cmath>

using namespace std;

int main()
{
	int			n;
	double		S[1000];

	for (;;)
	{
		scanf("%d", &n);
		if (0 == n)		break;

		double sum = 0.;
		int	t;
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &t);
			S[i] = static_cast<double>(t);
			sum += S[i];
		}

		double	ave = sum / n;

		double	alpha2 = 0.;

		for (int i = 0; i < n; i++)
		{
			alpha2 += (S[i] - ave) * (S[i] - ave);
		}
		alpha2 = alpha2 / n;

		printf("%.8f\n", sqrt(alpha2));
	}

	return 0;
}

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

typedef long long ll;

int main(){
   int N;
   cin>>N;
   vector<ll> A(N);
   for(int i=0; i<N; i++) cin>>A[i];
   ll ans = 0;

   sort(A.begin(),A.end());
   for(int i=0; i<N-1; i++){
       ans += A[N-1-((i+1)/2)];
   } 

   cout<<ans<<endl;

}

Measured memory_bytes: 4744
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

void trace (vector<int> const & a) {
    int n = a.size();
    for(int i=0; i<n; ++i) {
        if(i) cout << " ";
        cout << a[i];
    }
    cout << endl;
}

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

    int n; cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];
    int bblcnt = 0;

    bool flg = true;
    while(flg) {
        flg = false;
        for(int i=n-1; i>0; --i) {
            if(a[i-1] > a[i]) swap(a[i-1], a[i]), ++bblcnt, flg = true;
        }
    }
    trace(a);
    cout << bblcnt << endl;
    


    return 0;
}



Measured memory_bytes: 3176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0); }
 
int main() {
  ull n;
  vector<ull> v;
  vector<ull> c;
  cin >> n;

  each(i, n) {
    ull tmp;
    cin>> tmp;
    v.push(tmp);
  }
  each(i, n) {
    ull tmp;
    cin >> tmp;
    c.push(tmp);
  }

  vector<ull> xy;
  each(i, n) {
    if (v[i] >= c[i])
      xy.push(v[i] - c[i]);
  }

  if (xy.size() > 0) {
    cout << sum_value(xy) << endl;
  } else {
    cout << 0 << endl;
  }
 
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.stream.IntStream;

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer st;

    private static int readInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }

    public static void main(String[] args) throws IOException {
        int n = readInt();
        int m = readInt();
        UnionFind graph1 = new UnionFind(n);

        int usedEdges = 0;
        for (int i = 0; i < m; i++) {
            if (graph1.union(readInt(), readInt())) {
                usedEdges++;
                n--;
            }
        }

        System.out.println(n - 1);
    }

    static class UnionFind {
        final int[] parent;
        final int[] rank;

        UnionFind(int n) {
            parent = IntStream.range(0, n + 1).toArray();
            rank = new int[n + 1];
        }

        public int find(int p) {
            while (p != parent[p]) {
                parent[p] = parent[parent[p]];    // path compression by halving
                p = parent[p];
            }
            return p;
        }

        public boolean union(int p, int q) {
            int rootP = find(p);
            int rootQ = find(q);
            if (rootP == rootQ) return false;

            if (rank[rootP] < rank[rootQ]) parent[rootP] = rootQ;
            else if (rank[rootP] > rank[rootQ]) parent[rootQ] = rootP;
            else {
                parent[rootQ] = rootP;
                rank[rootP]++;
            }
            return true;
        }
    }
}



Measured memory_bytes: 55084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
ll h, w, dp[1001][1001];
char grid[1001][1001];
int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    dp[0][0] = 1;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> grid[i][j];
        }
    }
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (grid[i][j] != '.') continue;
            if (grid[i + 1][j] == '.') dp[i + 1][j] = (dp[i][j] + dp[i + 1][j]) % MOD;
            if (grid[i][j + 1] == '.') dp[i][j + 1] = (dp[i][j] + dp[i][j + 1]) % MOD;
        }
    }
    cout << dp[h - 1][w - 1] % MOD;
    return 0;
}

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

int main(void)
{
    string S, T;
    cin >> S >> T;
    
    int count = 0;
    for (int i = 0; i < 3; i++) {
        if (S[i] == T[i])
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    int n,k,j;
    cin>>n;
    int h[n];
    int i,c=0;
    for(i=0;i<n;i++)
    {
        cin>>h[i];
    }
    k=h[n-1];
    h[n-1]=0;
    for(i=n-2;i>=0;i--)
    {


        if(k<=h[i])
        {
            k=h[i];
            h[i]=h[i+1]+1;

        }
        else
        {
            k=h[i];
            h[i]=0;
        }
    }

    for(i=0;i<n;i++)
    {
        if(c<h[i])
        {
            c=h[i];
        }
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int dp[3001][3001];
string lcs(string one,string two){
  for(int i=1;i<=one.size();i++){
	for(int j=1;j<=two.size();j++){
	  if(one[i-1]==two[j-1])
		dp[i][j]=dp[i-1][j-1]+1;
        else
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}
  }
  int i=one.size();
  int j=two.size();
  string ans="";
  while(i>0 && j>0){
	if(one[i-1]==two[j-1]){
      ans+=one[i-1];
      i--;
      j--;
	}
	else
    if(dp[i-1][j]>dp[i][j-1])
    i--;
	else
	j--;
  }
  reverse(ans.begin(),ans.end());
  return ans;
}
string one,two;
int main(){
cin>>one>>two;
cout<<lcs(one,two)<<endl;
return 0;
}


Measured memory_bytes: 35456
use proconio::input;
use std::cmp::min;

fn main() {
    input! {
        mut x: i64,
        mut k: i64,
        d: i64,
    }

    let mut x = x.abs();
    let straight = min(k, x / d);
    k -= straight;
    x -= straight * d;
    let ans = if k % 2 == 0 { x } else { d - x };

    println!("{}", ans);
}


Measured memory_bytes: 2136
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

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

string s;
int n;

void realsolve() {
  int k;
  cin >> k;
  ll ret = 0;
  ll d = 0;
  ll m = 0;
  ll c = 0;
  ll dm = 0;
  ll mc = 0;
  for(int i = 0; i < n; i++) {
    if(i >= k) {
      if(s[i-k] == 'D') {
        dm -= m;
        d--;
      }
      else if(s[i-k] == 'M') {
        mc -= c;
        m--;
      }
      else if(s[i-k] == 'C') {
        c--;
      }
    }
    if(s[i] == 'D') {
      d++;
    }
    else if(s[i] == 'M') {
      dm += d;
      m++;
    }
    else if(s[i] == 'C') {
      ret += dm;
      mc += m;
    }
  }
  cout << ret << "\n";
}

void solve() {
  cin >> n >> s;
  int qq;
  cin >> qq;
  while(qq--) realsolve();
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


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

int main(){

    int n,k,x,y;
    scanf("%d", &n);
    scanf("%d", &k);
    scanf("%d", &x);
    scanf("%d", &y);
    if(n <= k){
        printf("%d", n * x);
    }else{
        printf("%d", k * x + y * (n - k));
    }
    
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;

	if (N == M) {
		cout << "Yes" << endl;
	}

	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    d = collections.Counter(list(map(int, input().rstrip('\n').split())))
    m = int(input().rstrip('\n'))
    t = collections.Counter(list(map(int, input().rstrip('\n').split())))
    for k, v in t.items():
        if k not in d:
            print("NO")
            exit()
        else:
            if v > d[k]:
                print("NO")
                exit()
    print("YES")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 125904
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n, k; cin >> n >> k;
    int ans = 0;
    vector<bool> ok(n, true);
    rep(i,k) {
        int d; cin >> d;
        rep(j,d) {
            int a; cin >> a;
            a--;
            ok[a] = false;
        }
    }
    rep(i,n) {
        if (ok[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String x = sc.next();
        String y = sc.next();

        int tmp = 0;
        int max = 0;

        for (int i = 0; i < x.length() - y.length() + 1; i++) {
            for (int j = 0; j < y.length(); j++) {
                if (x.charAt(j + i) == y.charAt(j)) {
                    tmp++;
                    if (tmp > max) {
                        max = tmp;
                    }
                }
            }
            tmp = 0;
        }

            System.out.println(y.length() - max);



        sc.close();

        }

    }



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

int main(void){
  int n;
  string s,s1,s2;
  
  cin >> n;

  if(n % 2 == 1){ 
    cout << "No" << endl;
    return 0;
  }

  cin >> s;

  s1 = s.substr(0,n/2);
  s2 = s.substr(n/2,n/2);

  if(s1 == s2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int d = sc.nextInt();

		if(c==d){
			System.out.println("a == b");
		}else if(c<d){
			System.out.println("a < b");
		}else{
			System.out.println("a > b");
		}

	}
}


Measured memory_bytes: 26312
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>

#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
    double N, X;
    int T;
    cin >> N >> X >> T;

    printf("%d\n", (int)(ceil(N/X) * T) );

    return 0;
}


Measured memory_bytes: 3788
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		while (sc.hasNext() == true) {
			String[] ps = sc.nextLine().split(" ");
			
			double[] points = new double[8];
			for (int i = 0; i < points.length; i++) {
				points[i] = Double.parseDouble(ps[i]);
			}
			
			double a, b, c, d, e, f;
			a = points[3] - points[1];
			b = points[2] - points[0];
			c = points[5] - points[3];
			d = points[4] - points[2];
			e = points[1] - points[5];
			f = points[0] - points[4];
			
			double g, h, i;
			g = -(a * points[0]) + b * points[1];
			h = -(c * points[2]) + d * points[3];
			i = -(e * points[4]) + f * points[5];
			
			double j, k, l, m, n, o;
			j = -(a * points[4]) + b * points[5];
			k = -(c * points[0]) + d * points[1];
			l = -(e * points[2]) + f * points[3];
			m = -(a * points[6]) + b * points[7];
			n = -(c * points[6]) + d * points[7];
			o = -(e * points[6]) + f * points[7];
			
			if ((((j > g) && (m > g)) || ((j < g) && (m < g)))
					&& (((k > h) && (n > h)) || ((k < h) && (n < h)))
					&& (((l > i) && (o > i)) || ((l < i) && (o < i)))) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 26736
#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
int sx,sy,tx,ty;
struct threeElements{
int _1st,_2nd,_3rd;
};
vector<vector<int>>adj(10);
ll n;
bool check(string s,string t)
{
    int n1=s.length(),n2=t.length(),j=0;
    for(int i=0;i<n1;i++)
    {
        if(s[i]==t[j])
            j++;
        if(j==n2)
            return 1;
    }
    return 0;
}
int main()
{
   // freopen ("jumping.in","r",stdin);
   _IOS();
   //18:52
    int i=1;
    int a,b,c;
    cin>>a>>b>>c;
    set<int>s;
    while(!s.count((a*i)%b))
        s.insert((a*i)%b),i++;
    if(s.count(c))
        cout<<"YES";
    else
        cout<<"NO";


}


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

vector<vector<int>> to;
vector<int>ans;

void dfs(int v, int p = -1){
  rep(i, to[v].size()){
    int u = to[v][i];
    if(u==p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main() {
  int n, q;;
  cin >> n >> q;
  to.resize(n);
  rep(i,n-1){
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q){
    int p, x;
    cin >> p >> x;
    --p;
    ans[p]+=x;
  }
  dfs(0);
  rep(i,n) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 23552
from decimal import *

n, a, b = map(int, input().split())

if abs(Decimal(a)-Decimal(b)) % Decimal(2) == 0:
    ans = (abs(Decimal(a)-Decimal(b))/Decimal(2))
else:
    if Decimal(n)-Decimal(b)>= Decimal(a)-Decimal(1):
        ans = (Decimal(a)-Decimal(1)) + Decimal(1) + (Decimal(b)-Decimal(a)-Decimal(1))/Decimal(2)
    else:
        ans = (Decimal(n)-Decimal(b)) + Decimal(1) + (Decimal(b)-Decimal(a)-1)/Decimal(2)

print(ans)


Measured memory_bytes: 5588
#include <iostream>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    cout << (a[0] + a[1]) << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main(){
    int a[5];
    int ans;
    for(int i=0; i<5; i++)
        cin >> a[i];
    for(int i=0; i<5; i++)
        if(a[i]==0)
            ans = i;
    cout<<ans+1;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>

using namespace std;
typedef long double ld;
typedef vector<ld> vd;

const ld EPS = 10e-10;

ld solve();
bool search(const ld t, const ld r, vd& s);

int main(void) {
	
	while(true){
		ld ans = solve();
		if( ans < 0.0 ) { break; }
		cout << fixed << setprecision(5) << ans << endl;
	}

	return 0;
}


bool search( const ld t, const ld r, vd& s ) {

	for( int i = -20; i < 20; i++ ) {

		ld d[2]={(ld)i,(ld)i+1.0};

		for(int j = 0; j < 2; j++)
			if(d[j]>=-r+EPS&&d[j]+EPS<=r)
				if(sqrt(r*r-d[j]*d[j])+t>r+s[i+20]+EPS) 
					return false;
	
	}

	return true;
}

ld solve() {

	//????????¢?´¢
	ld r, low=0.0, high=21.0, mid;
	int n, m;
	vd v(40,0.0);
	
	cin >> m >> n;
	r = (ld)m;
	
	if( m == 0 && n == 0 ) { return -1.0; }

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

		int xl, xr;
		ld h;
		cin >> xl >> xr >> h;

		for( int j = xl+20; j < xr+20; j++ )
			if( v[j] < h ) 
				v[j] = h;
	}
	

	//low???????????????????????????
	for( int i = 0; i < 1000; i++ ) {
		mid = (high+low)/2.0;
		if( search(mid,r,v) )
			low = mid;
		else 
			high = mid;
	}

	return mid;
}

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

int n;
double x[100],y[100];

double distance(double p){
  double sum=0;
  for(int i=0;i<n;i++){
    double w=abs(x[i]-y[i]);
    sum += pow(w,p);
  }
  return pow(sum,1.0/p);
}

int main(){
  cout<<fixed<<setprecision(12);

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  for(int i=0;i<n;i++){
    cin>>y[i];
  }
  
  cout<< distance(1) <<endl;
  cout<< distance(2) <<endl;
  cout<< distance(3) <<endl;

  double mx=0;
  for(int i=0;i<n;i++){
    mx=max(mx, abs(x[i]-y[i]) );
  }
  cout<< mx <<endl;
  
  return 0;
}


Measured memory_bytes: 3432
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
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 main(){

    int x,l=20190430,y,m,d;
    string S;
    cin>>S;

    y=stoi(S.substr(0,4));
    m=stoi(S.substr(5,2));
    d=stoi(S.substr(8));
    x=y*10000+m*100+d;
    if(x<=l){
        cout<<"Heisei"<<endl;
    }else{
        cout<<"TBD"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

int min(int a, int b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

int avd_i(int a, int b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

int main() {
	
	int N, A;

	cin >> N >> A;


	cout << N*N - A << endl;

	return 0;
}

Measured memory_bytes: 764
//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0

#define putb push_back
#define f first
#define s second

//logx(a^n)=loga(a^n)/logx(a)
//logx(a*b)=logx(a)+logx(b)
//logx(y)=log(y)/log(x)

#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define putf push_front
#define gainb pop_back

#define gainf pop_front
#define len(x) (ll)x.size()

// 1/b%mod=b^(m-2)%mod
// (a>>x)&1==0

typedef double db;
typedef long long ll;

const ll ary=1e5+5;
const ll mod=1e9+7;
const ll inf=1e18;

using namespace std;
using namespace __gnu_pbds;
ll n,ans,e[ary];
vector< pair<ll,ll> > g[ary];
void dfs(ll v=1,ll c=0,ll p=0){
	ll col=1;
	for(int i=0;i<len(g[v]);i++){
		ll to=g[v][i].f;
		if(to==p){
			continue;
		}
		if(col==c){
			col++;
		}
		ans=max(ans,col);
		e[g[v][i].s]=col;
		dfs(to,col,v);
		col++;
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<n;i++){
		ll a,b;
		cin>>a>>b;
		g[a].putb({b,i});
		g[b].putb({a,i});
	}
	dfs();
	cout<<ans<<"\n";
	for(int i=1;i<n;i++){
		cout<<e[i]<<"\n";
	}
}

Measured memory_bytes: 10752
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    sx, sy, tx ,ty  = map(int, input().split())
    dx = tx - sx
    dy = ty - sy

    p1 = 'R' * dx + 'U' * dy
    p2 = 'L' * dx + 'D' * dy
    p3 = 'D' + 'R' * (dx + 1) + 'U' * (dy + 1) + 'L'
    p4 = 'U' + 'L' * (dx + 1) + 'D' * (dy + 1) + 'R'
    print(p1 + p2 + p3 + p4)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    ll n;
    cin >> n;
    VL a(n);
    REP(i,n) scanf("%lld", &a[i]);
    ll sum = 0;
    REP(i,n) sum += a[i];
    ll x = n*(n+1)/2;
    bool f = true;
    if (sum % x != 0) f = false;
    ll p = sum / x;
    VL ans(n);
    REP(i,n){
        ll d = a[i] + p - a[(i+1)%n];
        if (d % n != 0 || d < 0) f = false;
        ans[(i+1)%n] = d / n;
    }
    ll po = 0;
    REP(i,n) po += ans[i];
    if (po != p) f = false;
    ll b = ans[0];
    FORR(i,n-1,1) b += (n+1-i) * ans[i];
    if (a[0] != b) f = false;

    cout << (f ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
A = list(map(int, input().split()))
# a+i と i-aのとりうる値の個数をカウントするが
# 一致するとしても[0, n)の範囲だけなのでDの大きさはnで十分
D = [0]*n
for i, a in enumerate(A):
    if 1+i+a < n:
        D[i+a] += 1
ans = 0
# i-aに対応するD[i-a]を加えるだけで答えが求まる
for i, a in enumerate(A):
    if 1+i-a >= 0:
        ans += D[i-a]
print(ans)

Measured memory_bytes: 92760
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    a, b, k = list(map(int, readline().split()))
    if a == b:
        print(a)
    else:
        ans = set()
        for i in range(a, min(a + k, b)):
            ans.add(i)
        for i in range(b, max(b - k, a), - 1):
            ans.add(i)
        print(*sorted(list(ans)))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38512
import itertools

n,m = map(int, input().split())
path = [[False]*n for _ in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    path[a][b]=True
    path[b][a]=True
ans = 0

for i in itertools.permutations(range(n),n):
    if i[0]==0:
        for j in range(n):
            if j==n-1:
                ans += 1
                break
            if not path[i[j]][i[j+1]]:
                break

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
int main() {

	int t;
	int i,j,n;

	cin>>n;

	int ac=0, wa=0, tle=0, re=0;
	while (n--) {
		string s;
		cin>>s;
		if (s[0]=='A') ac++;
		if (s[0]=='W') wa++;
		if (s[0]=='T') tle++;
		if (s[0]=='R') re++;
	}
	printf("AC x %d\n", ac);
	printf("WA x %d\n", wa);
	printf("TLE x %d\n", tle);
	printf("RE x %d\n", re);

	return 0;
}

Measured memory_bytes: 3724
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

N, K = map(int, input().split())
MOD = 10 ** 9 + 7

# 階乗、Combinationコンビネーション(numpyを使う)


def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


U = 10**6
fact, fact_inv = make_fact(N * 2 + 10, MOD)
fact, fact_inv = fact.tolist(), fact_inv.tolist()


def mod_comb_k(n, k, mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod


ans = 0
for i in range(N):
    if K < i:
        continue

    if N - 1 <= K:
        ans = mod_comb_k(N + N - 1, N - 1, MOD)
        break

    if i == 0:
        ans += 1
        continue

    a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD))
    a %= MOD
    ans += a
    ans %= MOD

    '''
    a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1])
    a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \
        int(fact_inv[N-i-1]) % MOD
    ans = (a + ans) % MOD
    '''

print(ans)


Measured memory_bytes: 56144
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<random>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 1e9;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
#define VMAX 500+10
    int N,K,ans=0;
    int A[1001];
int main(){
    cin>>N;
    REP(i,N){
        int a,b;
        cin>>a>>b;
        ans+=b-a+1;
    }
    cout<<ans;
}


Measured memory_bytes: 256
n = int(input())
s = input()
dict = {}
for i,j in zip(range(0, n), s):
    dict[i] = j

for i in range(0, n - 1):
    if dict[i] == dict[i+1]:
        del dict[i]
        n -= 1
    else:
        continue
print(len(dict))


Measured memory_bytes: 15396
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for s in S.split():
        a = 0
        for c in s:
            if c == 'A':
                a += 1
            else:
                ans += a
    return ans

def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


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

using namespace std;
using ll=long long;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cll ll t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pii pair<int,int>
#define vint vector<int>

ll mod=1e9+7;

int main(){
    faster;

    int n;
    cin>>n;

    int a[10][10]={};

    for(int i=1;i<=n;i++){
        int last=i%10;
        int tmp=i;
        int first;
        while(tmp!=0){
            first=tmp%10;
            tmp/=10;
        }
//        cout<<first<<" "<<last<<'\n';
        a[first][last]++;
    }
    ll final=0;
//    cout<<a[1][1]<<endl;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            final+=a[i][j]*a[j][i];
        }
    }

    cout<<final<<endl;
}

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

namespace debug
{
    public static partial class Program
    {
        public static void Main()
        {
            var n = Console.ReadLine().ToLong();
            var ais = Console.ReadLine().ToLongArray().ToList();

            for (var i = 0; i < n; i++)
            {
                ais[i] -= i + 1;
            }

            ais.Sort();
            var b = ais[(int)(n / 2)];

            Console.WriteLine(ais.Sum(x => Math.Abs(x - b)));
        }
    }

    public static partial class Program
    {
        //テンプレここから
        private static long Gcd(long aaa, long bbb) => bbb == 0 ? aaa : Gcd(bbb, aaa % bbb);
        private static long Lcm(long aaa, long bbb) => aaa * bbb / Gcd(aaa, bbb);
        private static long ToLong(this double ddd) => (long) ddd;
        private static long ToLong(this string str) => long.Parse(str);
        private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
        private static long[] ToLongArray(this string str, char opr = ' ') => str.Split(opr).ToLong();
        private static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb));
        private static long Sign(this long iii) => Math.Sign(iii);
        private static bool IsEven(this long iii) => iii % 2 == 0;
        private static bool IsEven(this int iii) => iii % 2 == 0;

        private static readonly int[] Dx =
        {
            0, -1, 0, 1
        };

        private static readonly int[] Dy =
        {
            -1, 0, 1, 0
        };

        public const int Mod = 1000000007;
        public const string UpperAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const string LowerAlphabet = "abcdefghijklmnopqrstuvwxyz";
        private static long ToLong(this char ccc) => ccc.ToString().ToLong();
        private static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
        private static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);

        private static string JoinToStr(this IEnumerable<long> array, string sep = "") =>
            array.Select(xxx => xxx.ToString()).Join(sep);

        public static string JoinToStr(this IEnumerable<int> array, string sep = "") =>
            array.Select(xxx => xxx.ToString()).Join(sep);

        //テンプレここまで
    }
}


Measured memory_bytes: 33796
#include<stdio.h>

int main(void){
int A, B;
scanf("%d %d", &A,&B);
int ka = A+B;
int gen = A-B;
int zyo = A*B;
if(ka >= gen && ka >= zyo){
printf("%d\n", ka);
}
else if(gen >= zyo){
printf("%d\n", gen);
}
else{
printf("%d\n", zyo);
}
  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<string> s(n);
	for (auto &v : s) {
		cin >> v;
	}

	int ans = 0;
	for (auto str : s) {
		for (int i = 1; i < str.size(); i++) {
			ans += (str[i - 1] == 'A' && str[i] == 'B');
		}
	}

	vector<int> rightA(n);
	vector<int> leftB(n);
	vector<int> ba(n);
	for (int i = 0; i < n; i++) {
		int r = s[i].size() - 1;
		int l = 0;

		rightA[i] += (s[i][r] == 'A');
		leftB[i] += (s[i][l] == 'B');
		ba[i] += (s[i][l] == 'B' && s[i][r] == 'A');
	}

	int sumRightA = accumulate(begin(rightA), end(rightA), 0, [](int acc, int v) { return acc + v; });
	int sumLeftB = accumulate(begin(leftB), end(leftB), 0, [](int acc, int v) { return acc + v; });
	int score = min(sumRightA, sumLeftB);
	ans += score;

	// 2
	// BA
	// BA
	int sumBa = accumulate(begin(ba), end(ba), 0, [](int acc, int v) { return acc + v; });
	if (sumRightA != 0 && score == sumRightA && score == sumLeftB && score == sumBa) {
		ans--;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 896
import sys

k = int(input())
a = list(map(int, input().split()))[::-1]

m, M = 2, 2

for i in range(k):
	if m % a[i] != 0:
		m += a[i] - (m % a[i])

	M = M - (M % a[i]) + a[i] - 1

	if m > M:
		print(-1)
		sys.exit()

print(m, M)

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

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  int i = 0;
  while(A*i-i+1 < B){
    i += 1;
  }

  cout << i << endl;

}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, x int
	fmt.Scanf("%d%d", &N, &x)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &a[i])
	}
	sort.Ints(a)
	ans := 0
	b := 0
	for i := 0; i < N; i++ {
		b += a[i]
		if b > x {
			break
		}
		ans++
	}
	if ans == N && b != x {
		ans--
	}
	fmt.Printf("%d\n", ans)
}


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

using namespace std;

#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-8;
const double pi=acos(-1.0);
const int K=1e6+7;
const int mod=1e9+7;

LL a,b,c,ans;
int main(void)
{
    cin>>a>>b>>c;
    for(int i=1;i<=200&&!ans;i++)
    if((i*a)%b==c)
        ans=1;
    if(ans)
        cout<<"YES\n";
    else
        cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,p;
  ll a[1000010]={0};
  char s[LIMIT2];
  
  scanf("%s",s);
  n = strlen(s);
  for(i=0;i<n;i++){
    if(s[i]=='<') a[i+1] = max(a[i+1],a[i]+1);
  }
  for(i=n-1;i>=0;i--){
    if(s[i]=='>') a[i] = max(a[i],a[i+1]+1);
  }
  for(i=0;i<=n;i++) result+=a[i];
  printf("%lld",result);
  return 0;
}



Measured memory_bytes: 8448
def main():
    S = list(map(int,input()))
    length = len(S)

    if length%2 == 0:
        array1 = [0,1]*int(length/2)
        array2 = [1,0]*int(length/2)
    else:
        array1 = [0,1]*int((length-1)/2)+[0]
        array2 = [1,0]*int((length-1)/2)+[1]

    count1 = 0
    count2 = 0
    for i in range(length):
        if S[i] != array1[i]:
            count1 += 1
        if S[i] != array2[i]:
            count2 += 1
    print(min(count1,count2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6160
/* C++14(GCC5.4.1) */
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main(void){
    // N,Mの入力
    ll n,m;
    cin >> n >> m;

    // Aを受け取る
    vector<ll> A(n);
    for(int i=0; i<n; i++){
        cin >> A[i];
    }

    // Aを昇順にsort
    sort(A.begin(), A.end());

    // B,Cを受け取る
    vector<pair<ll,ll>> BC(m);
    for(int i=0; i<m; i++){
        cin >> BC[i].second >> BC[i].first;
    }
    // (C,B)をCの降順にsort(Aの各要素を見るのを一回のみにできる)
    for(int i=0; i<m; i++) BC[i].first *= -1;
    sort(BC.begin(), BC.end());
    for(int i=0; i<m; i++) BC[i].first *= -1;

    // Aの値を更新していく
    ll sweep=0; // Aの各要素を一回ずつ見る
    for(int i=0; i<m; i++){
        int counter=0;
        while(counter<BC[i].second && A[sweep]<BC[i].first){
            A[sweep] = BC[i].first;
            sweep++;
            counter++;
        }
    }

    // 総和の算出
    ll ans=0;
    for(int i=0; i<n; i++){
        ans += A[i];
    }

    cout << ans;

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i=0; i<N; i++) cin>>d.at(i);

    int sum = 0;
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            if (i!=j) sum += d.at(i)*d.at(j);
        }    
    }

    cout << sum/2 << endl;
}

Measured memory_bytes: 256
import copy
from collections import defaultdict

N = int(input())
tmp = copy.copy(N)
d = defaultdict(int)
if N == 1:
    print(0)
    exit()
for i in range(2, int(N ** 0.5) + 3):
    while N % i == 0:
        N //= i
        d[i] += 1
if N > 1:
    d[N] += 1
ans = 0
for i in d.values():
    tmp = 1
    while i - tmp >= 0:
        i -= tmp
        tmp += 1
        ans += 1
print(ans)


Measured memory_bytes: 9884
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

const int INF=1e18;

signed 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];
    }
    int sumV=accumulate(v.begin(),v.end(),0LL);

    vector<vector<int> > dp(N+1,vector<int>(sumV+1,INF));
    dp[0][0]=0;

    for(int i=0;i<N;i++){
        for(int j=0;j<=sumV;j++){
            chmin(dp[i+1][j],dp[i][j]);
            if(j+v[i]<=sumV){
                chmin(dp[i+1][j+v[i]],dp[i][j]+w[i]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<=sumV;i++){
        if(dp[N][i]<=W){
            ans=i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 80256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int N, K, t;

	cin >> N >> K;
	vector<int> Dk(K, 0);
	vector<bool> bucket(110, false);

	rep(i, K)
	{
		cin >> Dk.at(i);
		rep(j, Dk.at(i))
		{
			cin >> t;
			if (bucket.at(t-1) == false) bucket.at(t-1) = true;
		}
	}

	int cnt = 0;
	rep(i, N)
	{
		if (!bucket.at(i)) ++cnt;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3604
n,m = map(int,input().split())
INF = 10 ** 9
cur = [INF] * (2**n)
cur[0] = 0
for i in range(m):
  a,b = map(int,input().split())
  c = 0
  for j in map(int,input().split()):
    c += 2**(j-1)
  pre,cur = cur,[INF]*(2**n)
  for j in range(2**n):
    cur[j] = min(pre[j],cur[j])
    jc = j|c
    cur[jc] = min(pre[j]+a,cur[jc])
if cur[-1] == INF:
  print(-1)
else:
  print(cur[-1])

Measured memory_bytes: 48728
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    vector<int> ab(2);
    rep(i,2) cin >> ab[i];
    rep(i,3){
        bool ok = false;
        rep(j,2){
            if(i+1 == ab[j]){
                ok = true;
            }
        }
        if(!ok){
            cout << i+1 << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 256