akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
par = [-1] * n  # 親だった場合は-(その集合のサイズ)


# xがどのグループに属しているか調べる
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return find(par[x])


# 自分のいるグループの数
def size(x):
    return -par[find(x)]


# xとyの属する集合を併合
def unite(x, y):
    # 根を探す
    x, y = find(x), find(y)

    # 根が一緒
    if x == y:
        return

    # 大きい方に小さい方をくっつける
    if size(x) < size(y):
        x, y = y, x

    # xのサイズを更新
    par[x] += par[y]
    # yの親をxにする
    par[y] = x


# 同じ集合に属するか判定
def same(x, y):
    return find(x) == find(y)


bridges = [list(map(int, input().split())) for _ in range(m)]
bridges.reverse()
huben = n * (n - 1) // 2
ans = []
for i in range(m):
    ans.append(huben)
    a, b = bridges[i]
    a, b = a - 1, b - 1
    if same(a, b):
        continue
    else:
        huben -= size(a) * size(b)
        unite(a, b)
ans = ans[::-1]
for i in range(m):
    print(ans[i])


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

void printv(vector<ll> v) {
  for (ll i : v)
    cout << i << endl;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n + 10);
  rep(i, n) cin >> a[i + 1];
  vector<ll> checked(n + 10, -1);
  ll now = 1;
  ll cntm = 0;
  ll cntloop;
  ll cnts;
  while (true) {
    if (checked[now] >= 0) {
      cntloop = cntm - checked[now];
      cnts = checked[now];
      break;
    }
    checked[now] = cntm;
    now = a[now];
    cntm++;
  }
  ll loopn = 0;
  if ((k - cnts) >= 0) {
    loopn = (k - cnts) % cntloop + cnts;
  } else {
    loopn = k;
  }
  now = 1;
  rep(i, loopn) { now = a[now]; }
  cout << now << endl;
}


Measured memory_bytes: 6360
#include <stdio.h>
#include <stdlib.h>

#define DEFAULT_STACK_SIZE 16
#define FREE_STACK(s) \
  do {\
    free(s->p);\
    free(s);\
  } while (0)
#define SENTINEL -1
#define IS_SENTINEL(e) (e.h == SENTINEL)

typedef struct { int h, w, **c; } rectangle_t;
typedef struct { int c, h; } element_t; // column and height
typedef struct { element_t *p; int i, size; } stack_t;

static stack_t *new_stack(int size) {
  stack_t *s = (stack_t *) malloc(sizeof(stack_t));

  s->i = 0;
  s->size = size;
  s->p = (element_t *) malloc(sizeof(element_t) * s->size);
  return s;
}

static void push_stack(stack_t *s, element_t e) {
  if (s->i == s->size) {
    s->size *= 2;
    s->p = (element_t *) realloc(s->p, sizeof(element_t) * s->size);
  }
  s->p[s->i++] = e;
}

static element_t peek_stack(stack_t *s) {
  element_t e = { SENTINEL, SENTINEL };
  return s->i == 0 ? e : s->p[s->i - 1];
}

static element_t pop_stack(stack_t *s) {
  element_t e = { SENTINEL, SENTINEL };
  return s->i == 0 ? e : s->p[--s->i];
}

static void height_histgramify(rectangle_t r) {
  int i, j;

  for (i = 0; i < r.h; ++i) {
    for (j = 0; j < r.w; ++j) {
      if (i == 0 || r.c[i][j]) {
        r.c[i][j] = !r.c[i][j];
      } else {
        r.c[i][j] = r.c[i-1][j] + !r.c[i][j];
      }
    }
  }
}

static int max_area(int max, int pos, element_t e) {
  int area = (pos - e.c) * e.h;
  return area > max ? area : max;
}

static int largest_rectangle(rectangle_t r) {
  int i, j, c, h, max;
  stack_t *s;
  element_t e;

  for (i = max = 0; i < r.h; ++i) {
    for (j = 0, s = new_stack(DEFAULT_STACK_SIZE); j <= r.w; ++j) {
      c = j;
      h = j == r.w ? SENTINEL : r.c[i][j];
      for (e = peek_stack(s); e.h > h; e = peek_stack(s)) {
        max = max_area(max, j, pop_stack(s));
        c = e.c;
      }
      if (e.h == h && h > 0) continue;
      e.c = c;
      e.h = h;
      push_stack(s, e);
    }
    FREE_STACK(s);
  }
  return max;
}

int main(int argc, char **argv) {
  rectangle_t r;
  int i, j;

  scanf("%d %d", &r.h, &r.w);
  r.c = (int **) malloc(sizeof(int *) * r.h);
  for (i = 0; i < r.h; ++i) {
    r.c[i] = (int *) malloc(sizeof(int) * r.w);
    for (j = 0; j < r.w; ++j) scanf("%d", &r.c[i][j]);
  }
  height_histgramify(r);
  printf("%d\n", largest_rectangle(r));
  for (i = 0; i < r.h; ++i) free(r.c[i]);
  free(r.c);
}


Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,a,b) for(int i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
typedef long double ld;
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; }

int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll func(ll n){
  n /= 2;
  ll ans = 0;
  while(n){
    ans += n/5;
    n /= 5;
  }
  return ans;
}
int main(){
  ll n; cin >> n;
  if(n%2==1){
    cout << 0 << endl;
    return 0;
  }
  cout << func(n) << endl;
  return 0;
}


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

int main() {
	int x, i, j;

	for (i = 0; i < 10000; i++) {
		for (j = 0; j < 1; j++) {
			cin >> x;
			if (x != 0) {
				cout << "Case" << " " << i + 1  << ":" << " " << x << endl;
			}
			else {
				i = 10000;
			}
		}
	}
	return 0;
}

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

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

#define frep(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) frep(i, 0, (n))
#define rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define all(i, x) for(typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MAX = 100010;
const int INF = 1e9;
const int MOD = 1000000007;
const string END = "\n";

void solve(){
	ll n; cin >> n;
	ll a[n];
	ll cnt1 = 0, cnt2 = 0;
	rep(i, n){
		cin >> a[i];
		if(a[i] % 4 == 0){
			cnt1 += 2;
		}else if(a[i] % 2 == 0){
			cnt2 += 1;
		}
	}
	if(cnt1 + 1 >= n){
		cout << "Yes" << END;
	}else{
		if(cnt1 + cnt2 >= n){
			cout << "Yes" << END;
		}else{
			cout << "No" << END;
		}
	}
}

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


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	input := nextString()
	remSumArray := make([]int, 2019)
	remSumArray[0] = 1
	var num int
	digit := 1
	for i := len(input) - 1; i >= 0; i-- {
		num += int(input[i]-48) * digit
		digit *= 10
		digit %= 2019
		remSumArray[num%2019]++
	}
	var result int
	for _, num := range remSumArray {
		result += num * (num - 1) / 2
	}
	fmt.Println(result)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

int main()
{
    int n, li, ans = 0;
    cin >> n;
    vector<int> l;
    for(int i = 0; i < n; i++){
        cin >> li;
        l.push_back(li);
    }
    sort(l.begin(), l.end());

    for(int m1 = n - 1; m1 >= 2; m1--){
        for(int m2 = m1 - 1; m2 >= 1; m2--){
            ans += distance(upper_bound(l.begin(), l.begin() + m2, l[m1] - l[m2]), l.begin() + m2);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mx = 1123, mod = 1e9 + 7;
int dp[mx][mx];
int main() {
  int H, W;
  cin >> H >> W;
  dp[0][0] = 1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (c == '.') {
        if (j) dp[i][j] += dp[i][j-1];
        if (i) dp[i][j] += dp[i-1][j];
        dp[i][j] %= mod;
      }
    }
  }
  cout << dp[H-1][W-1] << endl;
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  
  for(int i = 0; i < k; i++){
    if(i % 2){
      b /= 2;
      a += b;
    }
    else{
      a /= 2;
      b += a;
    }
  }
  
  cout << a << " " << b << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>

int main()
{
  int a,b,d,r;
  double f;
  scanf("%d %d",&a,&b);

  d = a / b;
  r = a % b;
  f = (double)a / b;
    

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


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

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PN() putchar('\n')
#define PRINTARR(a,b) for(int i=0;(a+i)!=(b);i++){cout << *(a+i) << " ";}PN();
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define MT make_tuple

typedef pair<int, int> PII;
typedef tuple<int, int, int> T3I;
typedef long long LL;
typedef unsigned long long ULL;

void RI() {}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d", &head);
    RI(tail...);
}
void RLL() {}
template<typename... T>
void RLL( LL& head, T&... tail ) {
    scanf("%lld", &head);
    RLL(tail...);
}
void print() {putchar('\n');}
template<typename T, typename... U>
void print(T head, U... tail) {
    cout << head << " ";
    print(tail...);
}

const int MOD = 1000000007;
#define MAX_N 100005
int cnt[MAX_N];

int main()
{
    int n;
    RI(n);
    REP(i, n) {
        int a;
        RI(a);
        REP(j, a, a+3) {
            cnt[j]++;
        }
    }
    int ans = 0;
    REP(i, MAX_N) {
        ans = max(ans, cnt[i]);
    }
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    int res = Inf;
    cin >> s;
    vector<int> alp(26, 0);
    rep (i, s.size()) alp[s[i] - 'a']++; 
    rep (i, 26) {
        if (alp[i] == 0) continue;
        char x = 'a' + i;
        string t = s;
        bool same = false;
        int tmp = 0;
        while (!same) {
            bool all = true;
            rep (i, t.size()) if (t[i] != x) all = false;
            if (all) {
                same = true;
                break;
            }
            string u;
            FOR (i, 1, t.size()) {
                if (t[i] == x || t[i - 1] == x) u += x;
                else u += t[i];
            }
            t = u;
            tmp++;
        }
        res = min(res, tmp);
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<cstdio>
using namespace std;
map<long long ,long long>mp;
const long long md=1e9+7;
long long n;
long long solve(long long x)
{
	if(mp[x])return mp[x];
	else return mp[x]=(solve(x/2)+solve((x-1)/2)+solve((x-2)/2))%md; 
}
int main()
{
	mp[0]=1LL;
	mp[1]=2LL;
	scanf("%lld",&n);
	printf("%lld",solve(n));
	return 0;
}

Measured memory_bytes: 256
def cal_cost(X, P):
    cost = 0
    for x in X:
        cost += (x - P) ** 2
    return cost


def main(N, X):
    return min(cal_cost(X, p) for p in range(max(X) + 1))


if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    ans = main(N, X)
    print(ans)


Measured memory_bytes: 2940
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        long[] A = new long[N];

        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
        }
        Arrays.sort(A);

        System.out.println(A[N-1] - A[0]);
        }
}

Measured memory_bytes: 21588
using System;

namespace abc160A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string A = S.Substring(2, 1);
            string B = S.Substring(3, 1);
            string C = S.Substring(4, 1);
            string D = S.Substring(5, 1);
            if (A == B && C == D)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


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

using namespace std;

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template<class T>
void print(vector<T>& V, bool spaced = true) {
    string space;
    spaced ? space = " " : space = "";
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << space;
    }cout<< '\n';
}

template<class T>
void printendl(vector<T>& V) {
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << '\n';
    }
}

template<class T>
T gcd(T a, T b) {
    T r;
    while (b != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

template <class T>
T lcm (T a, T b) {
    return a / gcd(a, b) * b;
}

template<class T>
T Max(T a, T b) {
    return (a < b) ? b : a;
}

template<class T>
T Min(T a, T b) {
    return (a < b) ? a : b;
}

//str

bool isPalindrome(string str){
    
    int length = str.length();
 
    for (int i = 0; i < (length / 2); i++)
        if (str[i] != str[length - 1 - i])
            return false;
 
    return true;    
}

void reverseStr(string& str) 
{ 
    int n = str.length(); 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
}
 

//Read through the messages at the end when you're done

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int L; cin>> L;
    double a = (L+0.0)/3, b = (L+0.0)/3, c = (L+0.0)/3;
    cout << fixed << setprecision(12) << a*b*c << '\n';
    

    
    

    return 0;
}

    //Use long long da5eel rabbak!
    //Dont use endl;
    //DONT SUBMIT IZA UR NOT SURE WALLAHI BTENDAM
    //Dear Amine, just because it worked for the test cases doesnt necessarily mean it is correct.
    //Dear Amine, try it on ur own test cases iza ur not SURE
    //In case u didnt use long long, CHECK FOR POTENTIAL OVERFLOWS
    //DONT FORGET TO MOD EVERYTHING IZA U NEED TO MOD



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

using namespace std;

int main() {

  vector<string> str(3);

  for(int64_t i=0;i<3;i++)
    cin >> str[i];

  cout << "A" << str[1][0] << "C" << endl;

  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  ll n,a,b; cin>>n>>a>>b;
  ll ans=n/(a+b)*a;
  if(n%(a+b)<=a)
  ans+=n%(a+b);
  else
  ans+=a;
  cout<<ans<<endl;

  return 0;
}


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

int main(){
  string S; cin >> S;
  S.push_back('B');
  
  int ans = 0, tmp=0;
  for(int i=0; i<S.length(); i++){
    if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
      tmp++;
    } else {
      ans = max(ans,tmp);
      tmp = 0;
    }
  }
  cout << ans << endl;
}


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	int n;
	cin >> n;
	vi a;
	map<int, int> count;
	rep(i,n){
		int t;
		cin >> t;
		a.eb(t);
		count[t]++;
	}

	SORT(a);
	vector<bool> furui(a[a.size() - 1] + 1, true);
	int prev = -1;
	for(auto [key, value] : count){
		if(furui[key]){
			for(int j=2; key*j<=a[a.size()-1]; ++j){
				furui[key*j] = false;
			}
		}
	}
	rep(i,a.size()){
		if(prev == a[i]){
			furui[a[i]] = false;
		}
		prev = a[i];
	}

	int ans = 0;
	for(auto [key, value] : count){
		if(furui[key]){
			ans += value;
		}
	}

	cout << ans << endl;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 17344
N=int(input())
min=10*N
for A in range(1,N):
  B=N-A
  sum=0
  while A>0:
    sum+=A%10
    A=A//10
  while B>0:
    sum+=B%10
    B=B//10
  if min>sum:
    min=sum
print(min)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int N,M;
ll L[101010],R[101010],C[101010];
vector<pair<ll,int>> V;
set<pair<ll,int>> st;
ll d[101010];
const ll INF=1e15;

int main(){
  cin>>N>>M;
  V.resize(M);
  rep(i,M){
    cin>>L[i]>>R[i]>>C[i]; L[i]--,R[i]--;
    V[i]={L[i],i};
  }
  sort(V.begin(),V.end());
  V.push_back({1e9,0});
  rep(i,N) d[i]=INF;
  d[0]=0;
  int ind=0;
  rep(i,N){
    while(st.size()){
      auto it=st.begin();
      if(it->second<=i){
        st.erase(it);
      }else{
        d[i]=min(d[i],it->first);
        break;
      }
    }
    if(d[i]==INF){
      cout<<-1<<endl;
      return 0;
    }
    while(V[ind].first==i){
      int j=V[ind++].second;
      if(d[R[j]]>d[i]+C[j]){
        d[R[j]]=d[i]+C[j];
        st.insert({d[R[j]],R[j]});
      }
    }
  }
  cout<<d[N-1]<<endl;
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

int main(){
	string s;
	cin>>s;
	if(s[0]=='S'){
		cout<<"Cloudy"<<endl;
	}else if(s[0]=='C'){
		cout<<"Rainy"<<endl;
	}else{
		cout<<"Sunny"<<endl;
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int n;
	cin >> n;

	printf("%d:", n);
	int t = n;
	for (int i = 2; i <= (int)sqrt(n); i += (i == 2 ? 1 : 2))
	{
		while (t%i == 0)
		{
			printf(" %d", i);
			t /= i;
		}
	}
	if (t != 1)
	{
		printf(" %d", t);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 3256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

namespace {

}

int main()
{
	int H = 0, W = 0;

	cin >> H >> W;

	std::vector<std::string> line(H);
	for (auto& elem : line){
		cin >> elem;
	}

	//vector<vector<bool>> table(H,vector<bool>(W));

	for (int j = 0; j < H; ++j){ // 行
		string line2;
		bool isBomb = false;
		for (int i = 0; i < W; ++i){// 横
			if (line[j][i] == '#'){
				line2 += '#';
			}
			else {
				int count = 0;
				for (int k = 0; k < 3; ++k){// 行
					int curRow = j - 1 + k;
					if ((curRow) >= 0 && (curRow) < H){
						for (int m = 0; m < 3; ++m){// 横
							int curCol = i - 1 + m;
							if ((curCol) >= 0 && (curCol) < W){
								if (line[curRow][curCol] == '#'){
									++count;
								}
							}
						}
					}
				}
				line2 += '0' + count;
			}
		}
		cout << line2 << std::endl;
	}


	return 0;
}

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

using namespace std;

int check(int x) {
    string s;
    cout << x << endl;
  	fflush(stdout);
    cin >> s;
    if(s[0] == 'M') return 1;
    else if(s[0] == 'F') return 2;
    else if(s[0] == 'V') exit(0);
}

int main() {
    string s;
    int n, l, r, val_l;
    cin >> n;
    l = 0;
    r = n - 1;
    val_l = check(r);
    val_l = check(l);
    while(l + 1 != r) {
        int mid = (r + l) / 2;
        int tmp = check(mid);
        if(mid % 2 == 0) {
            if(tmp == val_l) l = mid;
            else r = mid;
        }
        else{
            if(tmp == val_l) r = mid;
            else l = mid;
        }
    }
    val_l = check(l); cout.flush();
    if(!val_l) return 0;
    else {
        cout << r << '\n'; cout.flush();
    }
 
    return 0;
}

Measured memory_bytes: 852
#include <stdio.h>
#include <string.h>

char s[110];
int len;
int cc;

int main(void)
{
	scanf("%s", s);
	
	len = strlen(s);
	
	for(int i = 0 ; i < len / 2 ; i++)
	{
		if(s[i] != s[len - i - 1])
			cc++;
	}
	
	printf("%d", cc);
	return 0;
}

Measured memory_bytes: 128
S = list(input())

ans = 0
if(S[0]==S[1])and(S[1]==S[2]):
  if(S[0]=='R'):
    print(3)
  else:
    print(0)
elif(S[0]==S[1])and(S[0]=='R'):
  print(2)
elif(S[1]==S[2])and(S[1]=='R'):
  print(2)
else:
  print(1)

Measured memory_bytes: 9128
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) range(i,0,b)
#define rangei(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) rangei(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
    template<class...T>
    ostream & operator << (ostream &os, tuple<T...> const &t){
        _ot<0>(os, t); return os;
    }
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#define endl '\n'
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,l+n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max();

// RMQ
template<class T>
struct SegmentTree {
    int n;
    vector<T> dat;
    SegmentTree(int n_ = 0) : n(n_){
        for(n = 1; n < n_; n <<= 1);
        dat.resize(n*2, inf);
    }
    T query(int v, int w, int l, int r){
        if(r <= l || w == 0) return inf;
        if(r - l == w) return dat[v]; // assert(l == 0 && r == w);
        return min(query(v*2, w/2, l, min(r, w/2)),
                   query(v*2+1, w/2, max(0, l-w/2), r-w/2));
    }
    void update(int i, T x){
        dat[i+=n] = x;
        for(; i!=1; i/=2) dat[i/2] = min(dat[i], dat[i^1]);
    }
    T query(int l, int r){ return query(1,n,l,r); }
    size_t size() const { return n; }
};

int main(){
    fastios();
    int n, q;
    while(cin >> n >> q){
        SegmentTree<int> st(n);
        rep(i,q){
            char c;
            int x, y;
            cin >> c >> x >> y;
            if(c == '0'){
                st.update(x,y);
            } else {
                cout << st.query(x,y+1) << endl;
            }
        }
    }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

    for(int x=1;x<=3500;x++){
        for(int y=1;y<=3500;y++){

            int s=n*x*y;
            int t=4*x*y-x*n-y*n;
            if(t<=0||s%t)continue;
            cout<<x<<" "<<y<<" "<<s/t<<endl;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

#define MAX_N 200000
#define MAX_A 1000000

bool dp[MAX_A + 1]; // when any divisor of `n` which is less than `n` does'nt
                    // exist in `A`, `dp[i] = true`

int main( int argc, char **argv )
{
    // handling inputs
    int N; // number of array
    cin >> N;

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

    int a_max = A.at( N - 1 );
    vector<bool> dp( A.at( N - 1 ) + 1, true );
    vector<bool> check( A.at( N - 1 ) + 1, false );

    for ( auto a : A )
    {
        if ( check[a] )
        {
            dp[a] = false;
            continue;
        }
        if ( dp[a] )
            for ( int b = 2 * a; b <= a_max; b += a ) dp[b] = false;
        check[a] = true;
    }

    int ans = 0;
    for ( auto a : A )
        if ( dp[a] ) ans++;

    cout << ans << endl;

    return 0;
}


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

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

int main()
{
    int n;
    scanf("%d", &n);

    int constraint[n][n - 1];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n - 1; j++)
            scanf("%d", &constraint[i][j]), constraint[i][j]--;

    int pos[n] = {0};
    int g[2][n];
    memset(g, -1, sizeof(g));
    for (int i = 0; i < n; i++) {
        g[0][i] = constraint[i][pos[i]];
    }

    /*
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++)
                printf("%d%c", g[i][j], j == n - 1 ? '\n' : ' ');
        }
        printf("\n");
    */
    int ans = 0;
    while (true) {
        bool has = false;
        int cur = ans & 1;
        int nxt = cur ^ 1;
        // printf("cur %d nxt %d\n", cur, nxt);
        for (int i = 0; i < n; i++) {
            int &target = g[cur][i];
            if (g[cur][i] >= 0 && i == g[cur][target]) {
                has = true;
                g[nxt][i] = pos[i] + 1 < n - 1 ? constraint[i][pos[i] + 1] : -1;
                pos[i]++;
            } else {
                g[nxt][i] = g[cur][i];
            }
        }

        if (has == false)
            break;

        /*
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++)
                printf("%d%c", g[i][j], j == n - 1 ? '\n' : ' ');
        }
        printf("\n");
        getchar();
        */

        ans++;
    }

    for (int i = 0; i < n; i++)
        if (pos[i] < n - 1)
            ans = 0;

    printf("%d\n", ans == 0 ? -1 : ans);

    return 0;
}


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

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789


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

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

int N;
int A[112345];
int cnt[3];
bool flag = 0;

int main(){
	
	cin>>N;
	
	fill( cnt, cnt+3, 0 );
	
	REP( i, N ){
		scanf("%d", A+i);
		if( A[i] % 4 == 0 ) cnt[2]++;
		else if( A[i] % 2 == 0 ) cnt[1]++;
		else{
			cnt[0]++;
		}
	}
	
	if( cnt[0] <= cnt[2] ) flag = 1;
	else if( cnt[0] - cnt[2] == 1 && !cnt[1] ){
		flag = 1;
	}
	
	if( flag ) puts("Yes");
	else{	 puts("No");}
	
	return 0;

}

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

int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  
  int n = (c + b - 1)/b;
  int m = (a + d - 1)/d;
  
  if(n <= m) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

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

#define M 187
#define P 16

int mark[M][M];

int dp[M][M][P][M]; //y1 y2 x1 
int cut[M][M][M];

int H, W;

int main() {

	cin >> H >> W;
	for (int i = 0; i < H; i++)
	{
		string S;
		cin >> S;
		for (int j = 0; j < W; j++)
		{
			//if ((rand()) % 2 == 0) mark[i][j] = 0;
			if (S[j] == '.') mark[i][j] = 0;
			else mark[i][j] = 1;
		}
	}

	for (int w = 1; w <= W; w++)
	{
		for (int y1 = 0; y1 + w <= H; y1++)
		{
			int y2 = y1 + w;

			for (int x1 = 0; x1 < W; x1++)
			{
				dp[y1][x1][0][y2] = x1;
				
				if (w <= 2) {
					int flag = 0;
					for (int x2 = x1; x2 < W; x2++)
					{
						for (int y = y1; y < y2; y++)
						{
							flag |= (1 << mark[y][x2]);
						}
						if (flag == 3) break;
						else dp[y1][x1][0][y2] = x2 + 1;
					}
				}
				else {
					dp[y1][x1][0][y2] = min(dp[y1 + 1][x1][0][y2], dp[y1][x1][0][y2 - 1]);
				}
			}
		}
	}




	for (int p = 1; p < P; p++)
	{
		for (int h = 1; h <= H; h++)
		{
			for (int y1 = 0; y1 + h <= H; y1++)
			{
				int y2 = y1 + h;
				for (int x1 = 0; x1 < W; x1++)
				{
					//yoko
					int ans = dp[y1][x1][p - 1][y2];
					if (ans != W) ans = dp[y1][ans][p - 1][y2];

					if (h >= 2 && dp[y1][x1][p][y2 - 1] > ans) {
						int tmin = min(dp[y1][x1][p][y2 - 1], dp[y1 + 1][x1][p][y2]);

						//tate
						for (int y3 = y1 + 1; y3 < y2 && ans < tmin; y3++)
						{
							if (ans > dp[y1][x1][p - 1][y3]) break;
							while (y3 < y2 - 1 && dp[y1][x1][p - 1][y3] == dp[y1][x1][p - 1][y3 + 1]) {
								y3++;
							}

							if (ans < dp[y3][x1][p - 1][y2]) ans = max(ans, min(dp[y1][x1][p - 1][y3], dp[y3][x1][p - 1][y2]));
						}
					}

					dp[y1][x1][p][y2] = ans;

					//cout << y1 << " " << y2 << " " << x1 << " " << p << " " << ans << endl;
				}
			}
		}
	}

	int ret = P;
	for (int i = 0; i < P; i++)
	{
		if (dp[0][0][i][H] == W) {
			ret = i;
			break;
		}
	}

	cout << ret << endl;
	cin >> H;
}



Measured memory_bytes: 406016
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;

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

	vector<int> data1(a), data2(a);
	for (int i = 0; i < a; i++) {
		cin >> data1[i], --data1[i];
	}

	for (int i = 0; i < a; i++) {
		cin >> data2[i], --data2[i];
	}

	map<vector<int>, int> ord;
	int cnt = 0;

	vector<int> v(a);

	for (int i = 0; i < a; i++) {
		v[i] = i;
	}

	do{
		ord[v] = cnt++;
	}while(next_permutation(v.begin(), v.end()));

	cout << abs(ord[data1] - ord[data2]) << endl;



	return 0;
}

Measured memory_bytes: 5248
#!/usr/bin/env python3
import numpy as np
import math

n = int(input())
x = list(map(int, input().split()))

p1 = math.floor(np.mean(x))
p2 = math.ceil(np.mean(x))
ans1 = 0 
ans2 = 0 
for i in x:
    ans1 += (i-p1)**2
    ans2 += (i-p2)**2

print(min(ans1, ans2))


Measured memory_bytes: 14512
#include<iostream>
#include<map>
using namespace std;
typedef long long LL;
const int N = 200010;
LL a[N];
LL x[N];
LL sum[N];
map<LL,int> m;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
		x[i]=(sum[i]-i+k)%k;
	}
	LL ans=0;
	m[0]=1;
	for(int i=1;i<=min(n,k-1);i++){
		ans+=m[x[i]];
		m[x[i]]++;
	}
	for(int i=k;i<=n;i++){
		m[x[i-k]]--;
		ans+=m[x[i]];
		m[x[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 17408
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<string, int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

long long int a[210000], b[210000], v[210000];

int main(){
	
	int N;
	cin >> N;
	
	long long int rem = 0, ans = 0;
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
		rem ^= a[i];
	}
	for(int i = 0; i < N; i++){
		cin >> b[i];
		rem ^= b[i];
	}
	
	for(int dig = 1; dig < 30; dig++){
		for(int i = 0; i < N; i++){
			v[i] = a[i] % (1 << dig);
		}
		sort(v, v + N);
		long long int cnt = 0;
		for(int i = 0; i < N; i++){
			long long int num = (1 << dig) - b[i] % (1 << dig);
			cnt += distance(lower_bound(v, v + N, num), v + N);
		}
		cnt %= 2;
		ans += cnt * (1 << dig);
	}
	
	if(N % 2 == 1){
		cout << (ans ^ rem) << endl;
	}else{
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5120
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  int N;
  ll Y;

  cin>>N>>Y;

  for(int i=0;i<=N;i++){
    for(int j=0;j<=N-i;j++){
      if(10000*i+5000*j+(N-i-j)*1000==Y){
        cout<<i<<" "<<j<<" "<<N-i-j<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<" "<<-1<<" "<<-1<<endl;

}


Measured memory_bytes: 256
import math
import os
import sys
# from fractions import gcd
input = sys.stdin.readline

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル


def cmb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


def main():
    X, Y = list(map(int, input().split()))
    N = (2 * Y - X) / 3
    M = (2 * X - Y) / 3

    if not (N.is_integer() and M.is_integer()):
        print(0)
        return

    N = int(N)
    M = int(M)

    for i in range(2, M + N + 1):
        g1.append((g1[-1] * i) % MOD)
        inverse.append((-inverse[MOD % i] * (MOD//i)) % MOD)
        g2.append((g2[-1] * inverse[-1]) % MOD)

    print(cmb(N+M, M, MOD))


if __name__ == '__main__':
    main()


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

int main(){
    string o,e;
    cin>>o>>e;

    string password;

    for(int i=0; i<o.size(); i++){
        password.push_back(o[i]);
        
        if(e.size()==i){
            continue;
        }

        password.push_back(e[i]);
    }

    cout<<password<<endl;
}

Measured memory_bytes: 256
/* basic header */
#include <bits/stdc++.h>
/* define */
#define ll long long
#define pb emplace_back
#define mp make_pair
#define eps 1e-8
#define lson (curpos<<1)
#define rson (curpos<<1|1)
/* namespace */
using namespace std;
/* header end */

int main() {
    int a[4];
    cin >> a[1] >> a[2] >> a[3];
    sort(a + 1, a + 1 + 3);
    if (a[1] == a[2] && a[2] != a[3] || a[1] != a[2] && a[2] == a[3]) puts("Yes"); else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

int field[1000][1000];

int main()
{
	int h, w;
	int a, b;

	scanf("%d %d %d %d", &h, &w, &a, &b);

	for (int i = 0; i < b; i++)
		for (int j = 0; j < a; j++)
			field[i][j] = 1;

	for (int i = b; i < h; i++)
		for (int j = a; j < w; j++)
			field[i][j] = 1;

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
			printf("%d", field[i][j]);
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	string s = "No";
	vector<vector<long long>> a(3, vector<long long>(3));
	vector<vector<bool>> flag(3, vector<bool>(3, false));
	long long n;

	for (long long i = 0; i < 3; i++)
		for (long long j = 0; j < 3; j++)
			cin >> a[i][j];

	cin >> n;

	vector<long long> b(n);

	for (long long i = 0; i < n; i++)
		cin >> b[i];

	for (long long k = 0; k < n; k++)
		for (long long i = 0; i < 3; i++)
			for (long long j = 0; j < 3; j++) {
				if (b[k] == a[i][j])
					flag[i][j] = true;
			}

	if (flag[0][0] && flag[1][1] && flag[2][2])
	{
		s = "Yes";
	}
	else if (flag[0][2] && flag[1][1] && flag[2][0])
	{
		s = "Yes";
	}
	else
	{

		for (long long i = 0; i < 3; i++)
		{
			if (flag[i][0] && flag[i][1] && flag[i][2])
			{
					s = "Yes";
					break;
			}
			else if (flag[0][i] && flag[1][i] && flag[2][i])
			{
					s = "Yes";
					break;
			}
		}
	}

	cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

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






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

  int n,p;
	string s;
	cin>>n>>p>>s;
	 int ans=0;
	if(p==2 || p==5){
		for(int i=0; i<n; ++i)
			if((s[i]-'0')%p==0)
				ans+=i+1;
		cout<<ans<<"\n"; return 0;
	} 
	
		map<int,int> mp;
		mp[0]++;
		int t=0,p2=1;
		for(int i=n-1;i>=0; --i){
			t=(t+(s[i]-'0')*p2)%p;
			ans+=mp[t];
			mp[t]++;
			p2=p2*10%p;
		}
	
	cout<<ans;




  
}



Measured memory_bytes: 1044
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
// Not for Rating """"""""""I'm in Love with Experience :)""""""""""""""""""
void solve()
{
    string str;cin>>str;
    ll N=str.length();
    ll p=0,a=753,mn=1000;
    for(ll i=0;i<N-2;++i)
    {
        p=100*(str[i]-'0')+ 10*(str[i+1]-'0') + (str[i+2]-'0');
        //cout<<p<<'\n';
        mn=min(mn,abs(p-753));
    }
    cout<<mn;
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int T=1;while(T--){solve();}return 0;
}/*Solved By:- RITIK AGARWAL*/

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	
	static BufferedReader reader;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		
		String[] NKs = readLine().split(" ");
		int N = Integer.parseInt(NKs[0]);
		int K = Integer.parseInt(NKs[1]);
		
		int[] S = readLine().chars().toArray();
		int c_0 = "0".charAt(0);
		int c_1 = "1".charAt(0);
		boolean now = false;
		ArrayList<Integer> cnt_0_1 = new ArrayList<>();
		int tmp = 0;
		for(int i=0;i<N;i++) {
			if(now) {
				if(S[i]==c_0) {cnt_0_1.add(tmp);tmp=1;now=false;}
				else{tmp++;}
			}else {
				if(S[i]==c_0) {tmp++;}
				else{cnt_0_1.add(tmp);tmp=1;now=true;}
			}
		}
		cnt_0_1.add(tmp);
		
		int max_pt = 0;
		int pt=0;
		for(int i=0;i<K*2;i++) {
			if(i<cnt_0_1.size()) {
				pt+=cnt_0_1.get(i);
			}
		}
		max_pt = pt;
		for(int sp=2;sp+K*2-1<=cnt_0_1.size();sp+=2) {
			pt-=cnt_0_1.get(sp-2);
			if(sp-3>=0) {pt-=cnt_0_1.get(sp-3);}
			if(sp+K*2-2<cnt_0_1.size()) {pt+=cnt_0_1.get(sp+K*2-2);}
			if(sp+K*2-1<cnt_0_1.size()) {pt+=cnt_0_1.get(sp+K*2-1);}
			if(pt>max_pt) {max_pt = pt;}
		}
		
		System.out.println(max_pt);
	}

	private static String readLine(){
		try{
			return reader.readLine();
		}catch(Exception e){
			return e.getMessage();
		}
	}
}

Measured memory_bytes: 28756
from itertools import groupby
from operator import mul
from functools import reduce

N, M = map(int, input().split())
mod = 10 ** 9 + 7


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def main():
    p = [len(list(j)) for i, j in groupby(prime_factorize(M))]
    answer = 1
    for i in p:
        answer *= cmb(i + N - 1, N - 1)
        answer %= mod

    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	S := sc.nextStr()
	if S[0] == S[1] && S[1] == S[2] {
		fmt.Fprintln(wtr, "No")
	} else {
		fmt.Fprintln(wtr, "Yes")
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
using ll = long long;
int main(void){
    ll n,k;
    cin >> n >> k;
    string str;
    cin >> str;

    ll cnt = 0;
    ll i = 0;
    if(str[0]=='1') cnt--;
    while(i<n && cnt<k){
        if(str[i]=='1'&&str[i+1]=='0') cnt++;
        i++;
    }
    ll ans = i;
    ll back_i=0;
    str = str + "0";
    while(i<n){
        while(!(str[i]=='1'&&str[i+1]=='0')&&i<n-1) i++;
        while(!(str[back_i]=='0'&&str[back_i+1]=='1')&&back_i<n) back_i++;
        back_i++;
        i++;
        //cout << "back_i : " << back_i << "  i : " << i << endl;
        ans = max(ans, i-back_i);

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

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

int n, c;
int a[31], b[31];
int dp[31][1 << 16];

void solve(){
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < (1 << 16); j++){
      if(dp[i][j] == -1) continue;

      int nj = (j | a[i]);

      for(int k = 0; k < c; k++){
        int cal = (nj & b[k]);
        int pop = __builtin_popcount(cal);
        dp[i + 1][nj - cal] = max(dp[i + 1][nj - cal], dp[i][j] + pop);
      }
    }
  }

  int ans = 0;
  for(int i = 0; i < (1 << 16); i++){
    ans = max(ans, dp[n][i]);
  }
  cout << ans << endl;
}

int main(){
  while(cin >> n >> c, n){
    for(int i = 0; i < n; i++){
      a[i] = 0;
      for(int j = 0; j < 16; j++){
        int x;
        cin >> x;
        a[i] = (a[i] << 1) + x;
      }
    }

    for(int i = 0; i < c; i++){
      b[i] = 0;
      for(int j = 0; j < 16; j++){
        int x;
        cin >> x;
        b[i] = (b[i] << 1) + x;
      }
    }

    solve();
  }
}

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

int main() {
    int A,B,C,D,E,F;
    cin>>A>>B>>C>>D>>E>>F;

    float max=0.0;
    int max_water=0;
    int max_sugar=0;

    for(int a=0; a*100*A<=F; a++) {
        for(int b=0; a*100*A+b*100*B<=F; b++) {
            int water=a*100*A+b*100*B;
            for(int c=0; c*C<=E*water/100 ;c++) {
                for(int d=0; c*C+d*D<=E*water/100; d++) {
                    int sugar=c*C+d*D;
                    if((water+sugar)==0) continue;
                    float nodo=(float)sugar/((float)water+(float)sugar);
                    if(water+sugar<=F && max<nodo) {
                        max=nodo;
                        max_water=water;
                        max_sugar=sugar;
                    }
                }

            }
        }
    }
    if(max==0.0) max_water=100*A;
    cout<<max_water+max_sugar<<' '<<max_sugar<<endl;

    return 0;
}

Measured memory_bytes: 384