akhauriyash/Code-Regression huggingface dataset:
N  = int(input())
T, A = list(map(int, input().split()))
H = list(map(int, input().split()))

min_dif = 99999999999999999
min_pt = 0
for i, h in enumerate(H):
  dif = abs(A - (T - h*0.006))
  if dif < min_dif:
    min_pt=i+1
    min_dif = dif
    
print(min_pt)

Measured memory_bytes: 3064
MFR = input().split()
m = int(MFR[0])
f = int(MFR[1])
r = int(MFR[2])

while m!=-1 or f!=-1 or r!=-1:
    if m==-1 or f == -1:
        print("F")
    elif m+f>=80:
        print("A")
    elif m+f>=65:
        print("B")
    elif m+f>=50:
        print("C")
    elif m+f>=30:
        if r>=50:
            print("C")
        else:
            print("D")
    else:
        print("F")
    MFR = input().split()
    m = int(MFR[0])
    f = int(MFR[1])
    r = int(MFR[2])

Measured memory_bytes: 7688
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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 main() {
  int n;
  cin>>n;
  vl a(n);
  REP(i, n) cin>>a[i];
  sort(rall(a));
  priority_queue<pll> q;
  q.push(pll(a[1], a[0]));
  q.push(pll(a[1], a[0]));
  ll ans = a[0];
  FOR(i, 2, n) {
    pll p = q.top(); q.pop();
    ll x = p.first;
    ll y = p.second;
    ll z = a[i];
    ans += x;
    q.push(P(z,x));
    q.push(P(z,y));
  }
  cout << ans << endl;

  return 0;
}

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

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

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let mut cnt = 0;
    if s[0] == '1' { cnt += 1; }
    if s[1] == '1' { cnt += 1; }
    if s[2] == '1' { cnt += 1; }
    println!("{}", cnt);
}

Measured memory_bytes: 4352
N=10**9+7
x , y = map(int, input().split())
a=(2*x-y)//3
b=(2*y-x)//3

if 2*a+b!=x:
    print(0)
    exit()

n=a+b
r=a

def fac(n,r,N):
    ans=1
    for i in range(r):
        ans=ans*(n-i)%N
    return ans

def combi(n,r,N):
    if n<r or n<0 or r<0:
        ans = 0
        return ans
    r= min(r, n-r)
    ans = fac(n,r,N)*pow(fac(r,r,N),N-2,N)%N
    return ans

ans = combi(n,r,N)
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
main()
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	if(A==5&&B==5&&C==7||A==5&&C==5&&B==7||B==5&&C==5&&A==7)
	{
		printf("YES\n");}
			 else printf("NO\n");
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    int k;
    string s;
    cin >> k >> s;

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


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define first fst
#define second scd
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int n;
  int c[500][3];
  cin>>n;
  rep(i,n-1) cin>>c[i][0]>>c[i][1]>>c[i][2];
  rep(i,n-1){
    int now=0;
    repi(j,i,n-1){
      if(now<c[j][1]) now=c[j][1];
      if(now%c[j][2]!=0) now+=c[j][2]-(now%c[j][2]);
      now+=c[j][0];
    }
    cout<<now<<endl;
  }
  cout<<0<<endl;
  

  return 0;
}




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

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int findSumDigits(int s) {
    int num = 0;
    int temp = 0;
    while (s) {
        temp = s % 10;
        num += temp;
        s = s / 10;
    }
    return num;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;

    for (int i = 9; i != 0; i--) {
        if (n % i == 0) {
            ans = n / i;
            if (ans >= 10) {
                cout << "No" << endl;
                return 0;
            } else {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;


    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define pi 2.0*acos(0.0)
#define INTM 1e18
#define mod 1000000007
#define FOR(i,j,n)    for(ll i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

int main(){
    ll d,n;
    cin>>d>>n;
    if(d==0){
        if(n != 100) cout<<1*n<<endl;
        else cout<<1*n+1<<endl;
    }
    else if(d==1){
        if(n != 100) cout<<100*n<<endl;
        else cout<<100*n+100<<endl;
    }
    else if(d==2){
        if(n != 100) cout<<10000*n<<endl;
        else cout<<10000*n+10000<<endl;
    }
}


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

int n,pos;
vector<int> pre,in,post;

void rec(int l,int r){
    if(l>=r)
        return;
    int root = pre[pos++];
    int m = distance(in.begin(),find(in.begin(),in.end(),root));
    rec(l,m);
    rec(m+1,r);
    post.push_back(root);
}

void solve(){
    pos = 0;
    rec(0,pre.size());
    for(int i=0;i<n;i++){
        if(i)
            cout<<" ";
        cout<<post[i];
    }
    cout<<endl;
}

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

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

Measured memory_bytes: 3152
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)

long long N, A[1 << 19], cnt[1 << 19], cl[1 << 19], ans[1 << 19], r[1 << 19];
vector<long long> E;

void init() {
	for (int i = 1; i <= N; i++) r[cnt[i]]++;
	for (int i = N; i >= 1; i--) r[i] += r[i + 1];

	for (int i = N; i >= 1; i--) {
		for (int j = r[i]; j >= 1; j--) E.push_back(j);
	}
}

long long solve(int pos) {
	vector<int> cntv(N + 1, 1);
	vector<int> cntk(N + 1, 0);

	int umaru = 0;
	for (int i = 0; i < E.size(); i++) {
		if (cntk[cntv[E[i]]] < pos) {
			cntk[cntv[E[i]]]++;
			if (cntk[cntv[E[i]]] == pos) umaru = max(umaru, cntv[E[i]]);
			cntv[E[i]] += 1;
		}
		else {
			cntv[E[i]] = umaru + 1;
			cntk[cntv[E[i]]]++;
			if (cntk[cntv[E[i]]] == pos) umaru = max(umaru, cntv[E[i]]);
			cntv[E[i]] += 1;
		}
	}

	for (int i = 1; i <= N; i++) {
		if (cntk[i] < pos) return i - 1;
	}
	return N;
}

int main() {
	scanf("%lld", &N);
	for (int i = 1; i <= N; i++) { scanf("%lld", &A[i]); cnt[A[i]]++; }
	init();

	int ret = 0; cl[0] = N;
	for (int i = 1; (i * i) <= N; i++) {
		long long sum = 0;
		for (int j = 1; j <= N; j++) { sum += min(cnt[j], 1LL * i); }
		cl[i] = sum / i; ret++;
		for (int k = cl[i] + 1; k <= cl[i - 1]; k++) ans[k] = i - 1;
	}

	for (int i = 1; i <= cl[ret]; i++) {
		ans[i] = solve(i);
	}
	for (int i = 1; i <= N; i++) printf("%lld\n", ans[i]);
	return 0;
}

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

int main(void)
{
    std::vector<int> a(5);
    for(int i = 0; i < 5 ;i++) {
        std::cin >> a[i];
        if (a[i] == 0) {
            std::cout << i + 1 << std::endl;
        }
    }
    return 0;

}

Measured memory_bytes: 3604
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll pow(ll a, ll b, ll m) {
	ll res = 1;
	for (a %= m; b; b >>= 1, (a *= a) %= m)
		if (b & 1) (res *= a) %= m;
	return res;
}
ll n, m, a, b, ans, f[200005];
ll inv(ll x) {
	return pow(x, mod - 2, mod);
}
ll C(ll n, ll k) {
	return f[n] * inv(f[n-k]) % mod * inv(f[k]) % mod;
}
ll calc(ll n, ll m) {
	return C(n + m, m);
}
int main() {
	cin >> n >> m >> a >> b; f[0] = 1;
	for (ll i = 1; i <= n + m - 2; ++i)
		f[i] = f[i-1] * i % mod;
	for (ll i = b + 1; i <= m; ++i) {
		(ans += calc(n - a - 1, i - 1) % mod * calc(a - 1, m - i)) %= mod;
	}
	ans = (ans % mod + mod) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int s[10000];
int n;

int linerSearch(int);

int main()
{
  int q, c=0, i;
  int t[500];

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

  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &t[i]);
  }

  for(i = 0; i < q; i++){
    if(1 == linerSearch(t[i])) c++;
  }

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

  return 0;
}

int linerSearch(int key)
{
  int i;
  
  i = 0;
  s[n] = key;
  while(s[i] != key) i++;
  if(i == n) return 0;
  else return 1;
}

Measured memory_bytes: 636
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt()*100;
        int b = sc.nextInt()*10;
        int c = sc.nextInt();
        int x = a+b+c;
        int z = x%4;
        System.out.println(z==0 ? "YES" : "NO");
    }
}

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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i=a;i>b;i--)
#define int long long

//constant--------------------------------------------------------------------------------------
const int inf = 100100100100000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//general_method--------------------------------------------------------------------------------
vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;}
int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;}
int digitlen(int i){int t = i;int count = 0;while(t){count += 1;t /= 10;}return count;}
int gcd(int m, int n){if((0== m)||(0 == n))return 0;while(m != n){if(m > n)m = m - n;else n = n - m;}return m;}
int lcm(int n, int m){return n*m/gcd(n,m);}

//io_method-------------------------------------------------------------------------------------
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}

//main------------------------------------------------------------------------------------------


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

    
    string s = raw_input();
    string t = raw_input();

    map<char, char> mp;
    rep(i,0,s.size()){
        if(mp.find(t[i]) == mp.end()){
            mp[t[i]] = s[i];
        }else{
            if(mp[t[i]] != s[i]){
                print("No");
                return 0;
            }
        }
    }

    map<char, char> mp2;
    rep(i,0,s.size()){
        if(mp2.find(s[i]) == mp2.end()){
            mp2[s[i]] = t[i];
        }else{
            if(mp2[s[i]] != t[i]){
                print("No");
                return 0;
            }
        }
    }

    print("Yes");

}

Measured memory_bytes: 916
import numpy as np
n,*a=map(int,open(0).read().split())
mod=10**9+7
a=np.array(a)
ans=0
for i in range(60):
  c=len(a[a&1==1])
  a>>=1
  ans+=c*(n-c)*pow(2,i,mod)
  ans%=mod
print(ans)

Measured memory_bytes: 49952
from collections import defaultdict
def binsearch_int(func, min_x, max_x):
    """func(x) == Trueとなる最大のxを返す
    """
    if func(max_x):
        return max_x
    if not func(min_x):
        return None
    left,right=min_x,max_x
    while left+1<right:
        mid=(left+right)//2
        if func(mid):
            left=mid
        else:
            right=mid
    return left
N,M=list(map(int, input().strip().split()))
A=list(map(int, input().strip().split()))
AS=[0]*N
AS[0]=A[0]%M
modG=defaultdict(list)
ct=0
for i in range(1,N):
    AS[i]=(AS[i-1]+A[i])%M
for i,a in enumerate(AS):
    if a==0:ct+=1
    modG[a].append(i)
for i in range(N):
    ans=binsearch_int(lambda x: modG[AS[i]][x]+1<=i,0,len(modG[AS[i]])-1)
    if ans is None:
        continue
    ct+=(ans+1)
print(ct)

Measured memory_bytes: 24356
#include<bits/stdc++.h>
using  namespace  std;
int  main()
{
    string   a;
    cin>>a;
    if(int(a.find('C'))!=-1 and int(a.rfind('F'))!=-1 and a.find('C')<a.rfind('F'))
        cout<<"Yes";
    else 
	    cout<<"No";
    return  0;
}

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

int main(){
  int A , B ; 
  cin >> A >> B ; 
  string S ;
  cin >> S ; 
  int cnt = 0 ; 
  if(S.at(A) == '-' && S.size() == A+B+1 ){
    for(int i = 0 ; i < S.size() ; i++){
      if(S.at(i) == '-') cnt++ ; 
    }
    
    if(cnt == 1){
      cout << "Yes" << endl ; 
      return 0 ; 
    }
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 3600
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b := intScanner(), intScanner()
	if a == b {
		fmt.Println("Draw")
	} else if a == 1 {
		fmt.Println("Alice")
	} else if b == 1 {
		fmt.Println("Bob")
	} else if a > b {
		fmt.Println("Alice")
	} else {
		fmt.Println("Bob")
	}
}


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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int t1=c-b;
  int t2=a-d;
  while(t1>0 && t2>0){
      c=t1;
      t1=c-b;
      if(t1<=0)
        break;
      a=t2;
      t2=a-d;
      if(t2<=0)
        break;
  }
  if(t1<=0)
    cout<<"Yes\n";
  else if(t2<=0)
    cout<<"No\n";
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	static int time;

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s[] = br.readLine().split(" ");

		Arrays.sort(s);
		System.out.println(s[0] + " " + s[1] + " " + s[2]);
	}
}


Measured memory_bytes: 24220
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int>T(3);
  for(int i=0;i<3;i++){
    cin>>T.at(i);
  }
  sort(T.begin(),T.end());
  if(T.at(2)==T.at(1)+T.at(0)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

int main(){
	using ll=long long;
	int N;
	cin >> N;
	vector<ll> A(N);
	for(int i=0; i<N; i++){
		cin >> A.at(i);
	}

	vector<vector<ll>> c(60,vector<ll>(2,0));
	for(int i=0; i<N; i++){
		ll tmp=A.at(i);
		bitset<60> bit(tmp);
		for(int j=0; j<60; j++){
			if(bit.test(j)){
				c.at(j).at(1)++;
			}
			else{
				c.at(j).at(0)++;
			}
		}
	}

	ll tmp;
	ll ans=0;
	ll mod=1000000007;
	for(int j=0; j<60; j++){
		tmp = c.at(j).at(0)*c.at(j).at(1)%mod;
		for(int k=0; k<j; k++){
			tmp = tmp*2%mod;
		}
		ans += tmp; 
		ans %= mod;
	}

	cout << ans << endl;

}


Measured memory_bytes: 5580
S = input()

heads = int(S[:2])
tails = int(S[2:])


def is_month(n):
    return n >= 1 and n <= 12


if is_month(heads) and (not is_month(tails)):
    print("MMYY")
elif (not is_month(heads)) and (not is_month(tails)):
    print("NA")
elif (not is_month(heads)) and is_month(tails):
    print("YYMM")
else:
    print("AMBIGUOUS")


Measured memory_bytes: 9120
n=int(input())
t,a=[int(i) for i in input().split()]

h=[int(i) for i in input().split()]

min=1000000
ans=0
for i in range(n):
    temp=t-0.006*h[i]
    if min>abs(a-temp):
        min=abs(a-temp)
        ans=i+1
        
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
  string x;
  cin >> x;
  int scnt = 0;
  int cnt = 0;
  for(int i = 0; i < x.size(); ++i) {
    if(x[i] == 'S') ++scnt;
    else if(scnt > 0) {
      --scnt;
      cnt += 2;
    }
  }

  cout << x.size() - cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[200005],b[200005];
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,m;
    scanf("%d",&n);
    int i;
    for (i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    scanf("%d",&m);
    for (i=0;i<m;i++)
    {
        scanf("%d",&b[i]);
    }
    sort(b,b+m);
    int j=0;
    for (i=0;i<n;i++)
    {
        if (j==m) break;
        if (a[i]==b[j])
        {
            j++;
        }
    }
    if (j==m)
    {
        puts("YES");
    }
    else
    {
        puts("NO");
    }
    return 0;
}


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

#define repi(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(v) begin(v), end(v)

using ll = long long;

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll result = numeric_limits<ll>::min();
  result = max(result, a * c);
  result = max(result, a * d);
  result = max(result, b * c);
  result = max(result, b * d);

  cout << result << '\n';

  return 0;
}


Measured memory_bytes: 3612
n, m, c = map(int, input().split())
b = list(map(int, input().split()))

a = []
for i in range(n):
	temp = list(map(int, input().split()))
	a.append(temp)

count = 0
for item in a:
	total = 0
	for i in range(m):
		total += (b[i] * item[i])
	total += c
	if total > 0:
		count += 1

print(count)

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

using namespace std;

typedef long long int lli;

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

    int n, a, myxor = 0;

    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a;
        myxor ^= a ^ a ^ a;
    }

    cout << ((myxor==0) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 * @Author: yujirotakahashi
 * @Date:   2020-05-17T20:23:33+09:00
 * @Last modified by:   yujirotakahashi
 * @Last modified time: 2020-05-17T21:18:19+09:00
 */

#include<bits/stdc++.h>
using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
//const ll INF = (1LL << 60);
//const double pi=acos(-1.0);
using ll = long long;
using PAIR = pair<int, int>;
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/**************************************/

/******** User-defined Function *******/


/**************************************/

/********** Main()  function **********/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  double a,b,h,m; cin >> a >> b >> h >> m;

  double arg1,arg2;
  arg1 = (360/12) * h + 30*(m/60);
  arg2 = (360/60) * m;

  double arg = min(abs(arg1-arg2),360-abs(arg1-arg2));

  double tmp = (M_PI/180) * arg;
  double ans = sqrt(a*a+b*b - 2*a*b*cos(tmp));

  Dcout(ans);

  return 0;
}
/********  Main() Ends Here *************/


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

money = 1000
stock = 0
for i in range(N-1):
  for j in range(i+1, N):
    if A[i] > A[j]:
      money += stock * A[i]
      stock = 0
      break

    if A[i] < A[j]:
      stock += money // A[i]
      money -= A[i] * (money // A[i])
      break

money += stock * A[-1]
print(money)


Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	float d,t,s;
	cin>>d>>t>>s;
	float ans = d/s;
	if(ans<=t){
		cout<<"Yes"<<'\n';
	}
	else{
		cout<<"No"<<'\n';
	}
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    string s;
    string a="CODEFESTIVAL2016";

    cin >>s;
    int x=0;
    rep(i,s.size())
    {
        if(s[i]!=a[i]) ++x;
    }
    cout << x << endl;
    return 0;
}


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

using namespace std;

long long dp[100005], a[100005], b[100005], t, kq, n, w, ans;

int main() {
    cin >> n >> w;
    t = 0;
    for (int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
        t += b[i];
    }
    for (int i = 0; i <= t; i++)
        dp[i] = 1e18;
    dp[0] = 0;
    t = 0;
    for (int i = 1; i <= n; i++){
        for (int j = t; j >= 0; j--)
            dp[j + b[i]] = min(dp[j + b[i]], dp[j] + a[i]);
        t += b[i];
    }
    for (int i = 0; i <= t; i++){
        if (dp[i] <= w)
            ans = max(ans, (long long)i);
    }
    cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <queue>
using namespace std;
char mp[50][50];
bool lck[50][50];
int h,w;
struct dta{
  int x;
  int y;
  int pt;
};

int main(){
  cin>>h>>w;
  int bl = 0;
  
  for(int i = 0; h > i; i++){
    for(int j = 0; w > j; j++){
      cin>>mp[i][j];
      if(mp[i][j] == '#')bl++;
    }
  }


  queue<dta> a;
  a.push({0,0,1});
  lck[0][0] = true;
  int ans = h*w+1;
  while(!a.empty()){
    if(a.front().x == h-1 && a.front().y == w-1){
      ans = min(ans,h*w-(bl+a.front().pt));
      a.pop();
      continue;
    }
    //cout << a.size() << " " <<  a.front().x << " " << a.front().y << " " << a.front().pt << endl;
    if((a.front().x != 0) && (!lck[a.front().x-1][a.front().y]) && (mp[a.front().x-1][a.front().y] == '.'))a.push({a.front().x-1,a.front().y,a.front().pt+1}),lck[a.front().x-1][a.front().y] = true;
    if((a.front().x!=h-1) && (!lck[a.front().x+1][a.front().y]) && (mp[a.front().x+1][a.front().y] == '.'))a.push({a.front().x+1,a.front().y,a.front().pt+1}),lck[a.front().x+1][a.front().y] = true;
    if((a.front().y != 0) && (!lck[a.front().x][a.front().y-1]) && (mp[a.front().x][a.front().y-1] == '.'))a.push({a.front().x,a.front().y-1,a.front().pt+1}),lck[a.front().x][a.front().y-1] = true;
    if((a.front().y!=w-1) && (!lck[a.front().x][a.front().y+1]) && (mp[a.front().x][a.front().y+1] == '.'))a.push({a.front().x,a.front().y+1,a.front().pt+1}),lck[a.front().x][a.front().y+1] = true;
    a.pop();
  }
  if(ans == h*w+1){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }

}

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

int n;
long long ans = 0, l;
string s;

struct STrie
{
    STrie *bit[2];

    STrie() { bit[0] = bit[1] = nullptr; }
} *rt = new STrie();

void add(string &s)
{
    STrie *cur = rt;
    for (char &c : s)
    {
        int b = c - '0';
        if (cur->bit[b] == nullptr)
            cur->bit[b] = new STrie();
        cur = cur->bit[b];
    }
}

void DFS(STrie *cur, int dep)
{
    int cnt = (cur->bit[0] == nullptr) + (cur->bit[1] == nullptr);
    if (cnt == 1)
        ans ^= (1LL << (__builtin_ctzll(l - dep)));
    if (cur->bit[0] != nullptr)
        DFS(cur->bit[0], dep + 1);
    if (cur->bit[1] != nullptr)
        DFS(cur->bit[1], dep + 1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> l;
    while (n--)
    {
        cin >> s;
        add(s);
    }
    DFS(rt, 0);
    cout << (ans ? "Alice" : "Bob");
}


Measured memory_bytes: 5840
#include <stdio.h>

int main( void ) {
	double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;

	for ( ; scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &xa1, &ya1, &xa2, &ya2, &xb1, &yb1, &xb2, &yb2 ) == 8; puts( xa1 > xb2 || ya1 > yb2 || xa2 < xb1 || ya2 < yb1 ? "NO" : "YES" ) ) ;

	return 0;
}

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

int main()
{
	int A,B;
	cin >> A >>B;
	int coast;
	if(A<6&&A>=0){
		coast = 0;
	}
	if(A>=6&&A<=12){
		coast = B/2;
	}	 
	if(A>12){
		coast = B;
	} 
	cout << coast << endl;
	return 0;
} 

Measured memory_bytes: 256
(a,b,c,d)=gets.split.map(&:to_i)

divc = b/c - (a-1)/c
divd = b/d - (a-1)/d
cd = c.lcm(d)
divcd = b/cd - (a-1)/cd

r = (b-a+1) - (divc+divd-divcd)
p r;

Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main()
{
	int a, b, c, d;
	
	cin >> a >> b >> c >> d;
	
	if (a + b > c + d) {
		cout << "Left" << endl;
	}
	else if (a + b < c + d) {
		cout << "Right" << endl;
	}
	else {
		cout << "Balanced" << endl;
	}
	
	return (0);
}

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

int vis[101];

int main()
{
	int N, K;
	cin >> N >> K;
	
	for(int i=1; i<=K; i++)
	{
		int d1, v;
		cin >> d1;                   //1
		for(int j=1; j<=d1; j++)
		{    
			cin >> v;
			vis[v] = 1;
		}
	}
	
	int ans = 0;
	for(int i=1; i<=N; i++)
	{
		if(vis[i]==0) ans++;
	}
	
	cout << ans;
	return 0;
}
 

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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
 int N;
 cin >> N;
 for (int i = 1; i <= 9; i++) {
   for (int j = 1; j <= 9; j++) {
     if(i * j == N) {
       cout << "Yes" << endl;
       return 0;
     }
   }
 }
 cout << "No" << endl;
 return 0;
}


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

int main() {
	int K, A, B;
	cin >> K >> A >> B;

	for (int i = A; i <= B; ++i) {
		if (i % K == 0) {
			cout << "OK" << endl;
			return 0;
        }
    }

	cout << "NG" << endl;
	return 0;
}

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

long long N,Q,a[100009],p[100009],q[100009];vector<long long>C;

int main(){
	cin>>N>>Q;
	if(Q==0){
		for(int i=1;i<=N;i++)cout<<"1"<<endl;
		return 0;
	}
	for(int i=1;i<=Q;i++) cin>>a[i];
	long long maxn=(1LL<<60);
	for(int i=Q;i>=1;i--){if(maxn>a[i]){maxn=a[i];C.push_back(maxn);}}
	reverse(C.begin(),C.end());
	p[C.size()-1]=1;
	
	for(int i=C.size()-1;i>=0;i--){
		long long cx=C[i];
		while(true){
			long long pos1=upper_bound(C.begin(),C.end(),cx)-C.begin();pos1--;
			if(pos1>=0 && C[pos1]==cx) pos1--;
			if(pos1<0) break;
			//cout<<i<<" "<<p[i]<<" "<<cx<<" "<<pos1<<" "<<C[pos1]<<endl;
			long long I=cx/C[pos1];
			p[pos1]+=I*p[i];
			cx-=I*C[pos1];
		}
		q[N]+=(cx/N)*p[i];
		q[cx%N]+=p[i];
	}
	for(int i=N;i>=1;i--) q[i]+=q[i+1];
	for(int i=1;i<=N;i++) cout<<q[i]<<endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  for(int i=1; i<10; i++){
    for(int j=i; j<10; j++){
      if(i*j==N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define bk back()
#define pb push_back

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(x,a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

// FILE I/O
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
    // cin.exceptions(cin.failbit);
    // throws exception when do smth illegal
    // ex. try to read letter into int
    if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int dp[105][105];

bool solve(int p, int legs) {
    if (p == 0) return legs == 0;

    if (dp[p][legs] != -1) return (bool)dp[p][legs];

    bool res = solve(p-1,legs-2);
    res |= solve(p-1,legs-4);
    return dp[p][legs] = res;
}

int32_t main() {

    setIO();

    memset(dp,-1,sizeof dp);

    int a,b; cin >> a >> b;

    FOR(i,0,a+1) {
        FOR(j,0,a+1) {
            if (i+j == a && 4*i+2*j == b) {
                cout << "Yes"; exit(false);
            }
        }
    }

    cout << "No";
}


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

int	main(void)
{
	int n;
	long long sum = 0;
	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		if (i % 3 != 0 && i % 5)
			sum += i;
	}

	cout << sum << endl;
	return (0);
}

Measured memory_bytes: 3596
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 300;
double dp[N + 5][N + 5][N + 5];
int arr[5];
int n;

double calc(int x,int y,int z) {
	if(x + y + z == 0) return 0;
	double &res = dp[x][y][z];
	if(res > -0.5) return res;
	double tot = x + y + z;
	res = 0;
	if(x > 0) res += (1.0 * x / tot) * (1.0 + calc(x - 1,y,z));
	if(y > 0) res += (1.0 * y / tot) * (1.0 + calc(x + 1,y - 1,z));
	if(z > 0) res += (1.0 * z / tot) * (1.0 + calc(x,y + 1,z - 1));
	res += 1.0 * (n - tot) / tot;
	return res;
}

void hora(int tc) {
	cin>>n;
	for(int i = 0;i < n;i++) {
		int x;
		cin>>x;
		arr[x]++;
	}
	memset(dp,-1,sizeof dp);
	cout<<calc(arr[1], arr[2], arr[3])<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}



Measured memory_bytes: 222080
N,Y=map(int,input().split())

S=Y//1000-N
count=0
for x in range(N+1):
    if (S-9*x)%4==0 and (S-9*x)//4>=0 and N-x-(S-9*x)//4>=0:
        y=(S-9*x)//4
        z=N-y-x
        count=1
        break
if count==1:
    print(str(x)+' '+str(y)+' '+str(z))
else:
    print(str(-1)+' '+str(-1)+' '+str(-1))


Measured memory_bytes: 3064
#ifdef loc
    #include "codes/loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;

typedef long long ll;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define sz(a) int(a.size())
const int N = 200005;

int a[N], b[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    rep(i, 1, n + 1) {
        cin >> a[i];
    }
    rep(i, n + 1, 1) {
        int x = 0;
        for(int j = i + i; j <= n; j += i) {
            x += b[j];
        }
        x %= 2;
        if(x != a[i]) {
            b[i] = 1;
        }
    }
    int res = 0;
    rep(i, 1, n + 1) {
        res += b[i];
    }
    cout << res << endl;
    rep(i, 1, n + 1) {
        if(b[i]) {
            cout << i << ' ';
        }
    }
    if(res > 0) {
        cout << endl;
    }
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  for (int i=0;i<=100;i++) {
    if((a*i)%b == c){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;

}


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

int main(){
	string s;
	cin>>s;
	int a=0;
	for(int i=0;i<s.size();i++){
		if(a==0&&s[i]=='C')a=1;
		if(a==1&&s[i]=='F'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int *ufp, *ufr;
int UF_find(int);
void UF_union(int, int);
int main(void)
{
  int i, n, q, com, x, y;
  scanf("%d %d", &n, &q);
  ufp = (int*)malloc(sizeof(int) * n);
  ufr = (int*)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++){
    ufp[i] = i;
    ufr[i] = 0;
  }
  for (i = 0; i < q; i++) {
    scanf("%d %d %d", &com , &x, &y);
    if (!com) UF_union(UF_find(x), UF_find(y));
    else if (UF_find(x) == UF_find(y)) printf("1\n");
    else printf("0\n");
  }
  free(ufp);
  free(ufr);
}
int UF_find(int a)
{
  if (ufp[a] == a) return a;
  else {
    ufp[a] = UF_find(ufp[a]);
    return ufp[a];
  }
}
void UF_union(int a, int b)
{
  if (ufr[a] < ufr[b]) ufp[a] = b;
  else {
    ufp[b] = a;
    if (ufr[a] == ufr[b]) ufr[a]++;
  }
}


Measured memory_bytes: 2104
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
  int n;
  cin >> n;
  ll a[n], b[n];
  REP(i, n){
    cin >> a[i];
  }
  REP(i, n) cin >> b[i];
  ll d1 = 0, d2 = 0;
  REP(i, n){
    if(a[i] > b[i]) d1 += a[i]-b[i];
    else d2 += b[i]-a[i];
  }
  if(2*d1 > d2) cout << "No" << endl;
  if(2*d1 < d2){
    ll d3 = 0;
    REP(i, n){
    if(a[i] < b[i]) d3 += 2*((b[i]-a[i])/2);
  }
  if(2*d1 <= d3) cout << "Yes" << endl;
  else cout << "No" << endl;
  }
  if(2*d1 == d2){
    bool f = true;
    REP(i, n){
      if(a[i] < b[i] && (b[i]-a[i])%2 == 1) f = false;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 384
h, w = map(int, input().split())
S = [[1 if i=="#" else 0 for i in input()] for _ in range(h)]
dy = (1, 0, -1, 0)
dx = (0, 1, 0, -1)
seen = [[False]*w for _ in range(h)]

def dfs(y, x):
  white = 0
  black = 0
  stack = [(y, x)]
  seen[y][x] = True
  while stack:
    s, t = stack.pop()
    if S[s][t]:
      black += 1
    else:
      white += 1
    for di, dj in zip(dy, dx):
      ny, nx = s+di, t+dj
      if 0 <= ny < h and 0 <= nx < w:
        if seen[ny][nx]:
          continue
        if S[s][t] ^ S[ny][nx]:
          seen[ny][nx] = True
          stack.append((ny, nx))
  return black, white

ans = 0
for i in range(h):
  for j in range(w):
    if not seen[i][j]:
      black, white = dfs(i, j)
      ans += black * white
print(ans)

Measured memory_bytes: 13212
#include<iostream>
#include<stdio.h>

using namespace std;

int main(void)

{
    int a, N, i, f = 0;
    scanf("%d", &N);
    for(i = 1; i < 10; i++){
        if(N%i == 0){
            a = N/i;
            if(a < 10){
                f = 1;
            }
        }
    }
    if(f == 1){
        printf("Yes\n");
    }
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n; 
int arr[105];
int main() {
	int k, x;
	cin >> k >> x;
	// 3 7

	int l = x - (k - 1);
	int r = x + (k - 1);

	for (int i = l; l <= r; l++) {
		cout << l << " ";
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  vector<int> count(26);
  for(int i = 0;i < 26;i++)count[i] = 0;
  for(int i = 0;i < s.size();i++){
    count[s[i] - 'a']++;
  }
  for(int i = 0;i < 26;i++){
    if(count[i] == 0){
      cout << (char)('a' + i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

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

p = 0
m = 0
cnt = 0
for i in range(N-1):
    if(A[i] < A[i+1]):
        p = 1
    elif(A[i] == A[i+1]):
        continue
    else:
        m = 1
    if(p == m == 1):
        cnt += 1
        p = 0
        m = 0
print(cnt+1)

Measured memory_bytes: 14252
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

def f(x1,y1,x2,y2,t):
    l = abs(x1-x2)+abs(y1-y2)
    if l <= t:
        if l%2 == t%2:
            return True
    return False

if __name__ == "__main__":
    n = I()
    t = [0]
    x = [0]
    y = [0]
    for i in range(n):
        a,b,c = I2()
        t.append(a)
        x.append(b)
        y.append(c)
    for i in range(n):
        #print(x[i],y[i],x[i+1],y[i+1],t[i+1]-t[i])
        if not f(x[i],y[i],x[i+1],y[i+1],t[i+1]-t[i]):
            print("No")
            exit()
    print("Yes")

Measured memory_bytes: 17564
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;

        var dp = new int[N + 1];
        for (int i = 0; i <= N; i++)
        {
            dp[i] = i;
        }

        int j = 9;
        while (j <= N)
        {
            for (int i = j; i <= N; i++)
            {
                chmin(ref dp[i], dp[i - j] + 1);
            }
            j *= 9;
        }
        j = 6;
        while (j <= N)
        {
            for (int i = j; i <= N; i++)
            {
                chmin(ref dp[i], dp[i - j] + 1);
            }
            j *= 6;
        }

        WriteLine(dp[N]);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13252
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define INF (long)1e9
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	vector<int> vec(150, 0);
	for(int i = 0; i < s.size(); i++)
	{
		vec[(int)s[i]]++;
	}
	for(int i = 0; i < vec.size(); i++)
	{
		if(vec[i] >= 2)
		{
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
	return 0;
}



Measured memory_bytes: 256
# AOJ 1052: Old Bridges
# Python3 2018.7.7 bal4u

while True:
	n = int(input())
	if n == 0: break
	tbl = [list(map(int, input().split())) for i in range(n)]
	tbl.sort(key=lambda x:(x[1],x[0]))
	s, f = 0, True
	for v, w in tbl:
		s += v
		if s > w:
			f = False
			break
	print("Yes" if f else "No")



Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,b;
    cin>>n;
    vector<int> a(100010);
    rep(i,n){
        cin>>b;
        if(b!=0) a[b-1]++;
        a[b]++;
        a[b+1]++;
    }
    sort(all(a));
    reverse(all(a));
    cout<<a[0];
}

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

low=1
high=2*max(A)
X=max(A)
while low<=high:
  mid=(low+high)//2
  cnt = 0
  for i in range(N):
      if A[i]%mid==0:
          cnt += A[i]//mid-1
      else:
          cnt += A[i]//mid
  if K<cnt:
    low=mid+1
  else:
    X=min(X,mid)
    high=mid-1
print(X)

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

int N,M,ans,a;
int K[35],A[35][35];
map<int,int> MA;
int main(){
	cin >> N >> M;
	for(int i=0;i<N;i++){
		cin >> K[i];
		for(int j=0;j<K[i];j++){
			cin >> a;
			MA[a]+=1;
		}
	}

	for(int i=1;i<=M;i++){
		if(MA[i]==N) ans++;
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 256
/*                             //
         frostbyte02
//                             */
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define LLFOR(i,a,b) for (ll i=a; i<=b; i++)
#define FORD(i,a,b) for (int i=a; i>=b; i--)
#define fi first
#define se second
#define pb push_back
#define fastio {ios_base::sync_with_stdio(false); cin.tie(0);}
#define sqr(x) (x)*(x)
#define sqrmod(x) (((x)%MOD)*((x)%MOD))%MOD

using namespace std;
const int MOD = 1e9+7;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

int main()                                
{
        fastio
        int n; cin >> n;
        int h[n+1];
        int res = 0;
        FOR(i,1,n)
        {
                cin >> h[i];
                bool ok = true;
                FOR(j,1,i)
                {
                        if (h[j]>h[i])
                        {
                                ok = false;
                                break;
                        }
                }
                if (ok) res++;
        }
        cout << res;
        return 0;  
}


Measured memory_bytes: 256