akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 10007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong F(llong x){
    switch (x%4)
    {
        case 0:
            return x;
        case 1:
            return 1;
        case 2:
            return x+1;
        case 3:
            return 0;
    }
}

int main(){
    llong A,B;
    cin >> A >> B;
    llong ans=F(A-1) ^ F(B);
    cout << ans << endl;

    
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 30;
const ll LINF = 1LL << 60;
const double eps = 1e-9;
const ll MOD = 1000000007LL;
template <typename T>
void chmin(T& a, T b) {
    a = min(a, b);
};
template <typename T>
void chmax(T& a, T b) {
    a = max(a, b);
};
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for(int i = 0; i < m; i++) {
        cin >> a[i];
    }
    sort(all(a));
    reverse(all(a));
    auto dp = make_v<int>(n + 10, 10);
    fill_v(dp, -INF);
    for(int i = 0; i < m; i++) {
        dp[0][i] = 0;
    }
    vector<int> c{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < m; j++) {
            for(int k = 0; k < m; k++) {
                if(i - c[a[j]] >= 0) {
                    chmax(dp[i][j], dp[i - c[a[j]]][k] + 1);
                }
            }
        }
    }
    int id = n;
    string s;
    while(1) {
        int ma = -1, k = 0;
        for(int i = 0; i < m; i++) {
            if(ma < dp[id][i]) {
                ma = dp[id][i];
                k = i;
            }
        }
        s.push_back('0' + a[k]);
        id -= c[a[k]];
        if(id == 0) {
            break;
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n,q,t,result=0;
        n=scan.nextInt();
        ArrayList<Integer> s=new ArrayList<Integer>();
        for(int i=0; i<n; i++)
            s.add(scan.nextInt());
        
        q=scan.nextInt();
        for(int i=0; i<q; i++){
            t=scan.nextInt();
            if(s.indexOf(t)!=-1)
                result++;     
        }
        
        System.out.println(result);
    }
}


Measured memory_bytes: 40164
#include<stdio.h>
 
int main(void)
{
    double a,b,c,d,e,f;
    double x,y;
 
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) !=EOF)
    {
        y=(d*c-a*f)/(d*b-a*e);
        x=(c-b*y)/a;
 
        printf("%.3lf %.3lf\n",x,y);
    }
 
    return 0;
}

Measured memory_bytes: 652
def binary_search(A, n, key):
    left = 0
    right = n
    while left < right:
        mid = int((left + right) / 2)
        if key == A[mid]:
            return True
        elif key > A[mid]:
            left = mid + 1
        elif key < A[mid]:
            right = mid
    return False

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

ans = 0
for t in T:
    if binary_search(S, n, t):
        ans += 1
print(ans)


Measured memory_bytes: 16708
#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 REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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 k;
  cin >> k;
  vector<ll> a;
  FORe(i, 1, 9) a.push_back(i);
  while (1) {
    if (k <= a.size()) {
      cout << a[k-1] << endl;
      return 0;
    }
    k -= a.size();
    vector<ll> old;
    swap(old, a);
    for (ll x : old) {
      FORe(i, -1, 1) {
        int d = x%10 + i;
        if (d < 0 || d > 9) continue;
        ll nx = x*10 + d;
        a.push_back(nx);
      }
    }
  }

  return 0;
}

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

int dp[3][101000];
int x[3][101000];
int n;

int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
		for(int j=0;j<3;++j) cin>>x[j][i];
	for(int i=1;i<=n;++i){
		for(int j=0;j<3;++j){
			for(int k=0;k<3;++k){
				if(k==j) continue;
				dp[j][i]=max(dp[j][i],dp[k][i-1]+x[j][i]);
			}
		}
	}
	int ans=0;
	for(int i=0;i<3;++i) ans=max(ans,dp[i][n]);
	cout<<ans<<"\n";
	return 0;
}

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

int main(){
  int N,K,ans = 1;
  cin >> N >> K;
  
  for(int i = 0; i < N; i++){
    if(ans*2 < ans+K){
      ans *= 2;
    }
    else{
      ans += K;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a[100001];
int hsize=0;

void hpush(int x)
{
	int i=hsize;
	while(i>0)
	{
		int j=(i-1)/2;
		if(a[j]>=x) break;
		a[i]=a[j];
		i=j;
	}
	a[i]=x;
	hsize++;
}

void hpop()
{
	hsize--;
	int x=a[hsize];
	int i;
	for(i=0;2*i+1<hsize;)
	{
		int l=2*i+1;
		int r=2*i+2;
		if(r<hsize && a[l]<a[r]) l=r;
		if(x>a[l]) break;
		a[i]=a[l];
		i=l;
	}
	a[i]=x;
}

int main()
{
	int N,M;
	scanf("%d %d",&N,&M);
	long long int sum=0;
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%d",&x);
		hpush(x); 
	}
	for(int i=0;i<M;i++)
	{
		int x=a[0]/2;
		hpop();
		hpush(x);
	}
	for(int i=0;i<hsize;i++)
        sum+=a[i];
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X;
  cin >> N >> X;
  int gram = 0;
  int count = 0;
    
  vector<int>m(N);
  for (int i = 0; i < N; i++) {
    cin >> m.at(i);
    gram += m.at(i);
    count++;
  }
  sort(m.begin(), m.end());
  count += (X-gram)/m.at(0);
  cout << count << endl;
}
  



Measured memory_bytes: 3592
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll,ll> P;

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



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

long long floor_sum(long long n, long long m, long long a, long long b) {
    long long ans = 0;
    if (a >= m) {
        ans += (n - 1) * n * (a / m) / 2;
        a %= m;
    }
    if (b >= m) {
        ans += n * (b / m);
        b %= m;
    }

    long long y_max = (a * n + b) / m, x_max = (y_max * m - b);
    if (y_max == 0) return ans;
    ans += (n - (x_max + a - 1) / a) * y_max;
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
    return ans;
}

int main() {
	int t;
    cin >> t;
    rep(i, t) {
        ll n, m, a, b;
        cin >> n >> m >> a >> b;
        ll ans = floor_sum(n, m, a, b);
        cout << ans << endl;
    }
	return 0;
}


Measured memory_bytes: 3632
import math
N, K = map(int, input().split())

ans = 0
for r in range(1, min(K, N+1)):
    x = math.ceil( math.log2(K/r))
    ans += pow(0.5, x) / N
    # print(x, pow(0.5, x) / N)
if K <= N:
    ans += (N - K + 1) / N
print(ans)


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

using namespace std;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, C;
  cin >> n >> m >> C;
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int sum = C;
    for (int j = 0; j < m; j++) {
      int a;
      cin >> a;
      sum += a * b[j];
    }
    ans += (sum > 0);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
n,m = [int(i) for i in input().split()]
INIT = True
table = [INIT] * n
lis = []
for i in range(m):
  num = int(input())
  lis.append(num)

for i in lis[::-1]:
  if table[i-1]:
    print(i)
  table[i-1] = False

for i in range(n):
  if table[i]:
    print(i+1)



Measured memory_bytes: 12192
N, Q = map(int, input().split())
S = input()
l, r = [0] * Q, [0] * Q
cnt = [0] * len(S)
for i in range(Q):
    l[i], r[i] = map(int, input().split())
    l[i] -= 1
    r[i] -= 1
for i in range(1, len(S)):
    if(i == 0): pass
    cnt[i] = cnt[i - 1]
    if (S[i] == 'C' and S[i - 1] == 'A'):
        cnt[i] += 1
for i in range(Q):
    print(cnt[r[i]] - cnt[l[i]])


Measured memory_bytes: 54616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s;
    int z = 0;
    cin >> s;
    for (int i = 1; i < s.length(); i++) if (s[i] != s[i - 1]) z++;
    cout << z;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,p,ans=0;
	string s;
	cin>>n>>p>>s;
	vl sum(n);
	if(p==2||p==5){
		ll cnt=0;
		rrep(i,n){
			if((s[i]-'0')%p==0)cnt++;
			ans+=cnt;
		}
	}
	else{
		ll cnt=0,cur=1;
		map<ll,ll> mp;
		mp[0]++;
		rrep(i,n){
			cnt+=cur*(s[i]-'0');
			cnt%=p;
			mp[cnt]++;
			cur*=10;
			cur%=p;
		}
		for(auto x:mp){
			ans+=(x.sc*(x.sc-1))/2;
		}
	}
	puta(ans);
}


Measured memory_bytes: 2580
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
static const long long MOD_NUM = 1000000007LL;

static void A_task();

int main()
{
	A_task();
	fflush(stdout);
	return 0;
}

static void A_task()
{
	int N, M;
	get2int(N, M);
	
	if (N == M) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
}


Measured memory_bytes: 256
# F - Sugoroku
import sys
sys.setrecursionlimit(10 ** 9)

n,m = map(int,input().split())
s = input()

# r:sを後ろから見ていって、最小何手でゴールするかを求める。
INF = float('inf')
r = [INF for _ in range(n+1)]
r[n] = 0
idx = n
for i in range(n-1,-1,-1):
  while(idx-i > m or r[idx] == INF):
    idx -= 1
  if idx <= i:
    print(-1)
    exit()
  if s[i] == '0':
    r[i] = r[idx]+1
    p = r[i]
#print(r)

# rを先頭から見ていき、rの数字が変わる直前まで進むようにすれば
# 最短で辞書順最小なルートが求まる。
ans = []
c = 0
for i in range(n+1):
  if r[i] != INF and r[i] != p:
    p = r[i]
    ans.append(c)
    c = 1
  else:
    c += 1
print(*ans)

# mnr = [m for _ in range(n+1)]
# mnl = n+1
# def dfs(x,c):
#   global mnr,mnl
#   #print(x,c)
#   if x == n:
#     #print(r)
#     if len(r) < mnl or (len(r) == mnl and r < mnr):
#       mnr = r[:]
#       mnl = len(r)
#     return True
#   if c >= mnl or x > n or s[x] == '1':
#     return False
#   for i in range(m,0,-1):
#     r.append(i)
#     dfs(x+i,c+1)
#     r.pop()
# dfs(0,0)
# if mnl < n+1:
#   print(*mnr)
# else:
#   print(-1)

Measured memory_bytes: 90488
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    string s;
    cin >> s;

    if(s[0] == s[1] && s[1] == s[2]){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}   

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut wa_count = vec![0; n];
    let mut ac = vec![false; n];

    let mut ac_count = 0;
    let mut ans = 0;
    for i in 0..m {
        let v = read_vec::<String>();
        let p = i64::from_str_radix(&v[0], 10).unwrap() as usize - 1;
        let s = &v[1];
        if s == "AC" && !ac[p] {
            ans += wa_count[p];
            ac_count += 1;
            ac[p] = true;
        } else if s == "WA" {
            wa_count[p] += 1;
        }
    }
    println!("{} {}", ac_count, ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
        std::string s; cin>>s;
        std::vector<P> aro(0);

        char prev=s[0];
        ll cnt=0;
        for(char c: s){
                if(prev==c) cnt++;
                else{
                        aro.push_back({(prev=='<'), cnt});
                        cnt = 1;
                }
                prev = c;
        }
        aro.push_back({(prev=='<'), cnt});

        vector<ll> ans(s.size()+1);
        ll idx = 0;
        for(P p: aro){
                if(p.first){
                        for(ll i=0; i<=p.second; i++){
                                ans[idx+i] = max(ans[idx+i], i);
                        }
                }else{
                        for(ll i=0; i<=p.second; i++){
                                ans[idx+i] = max(ans[idx+i], p.second-i);
                        }
                }
                idx += p.second;
        }
        //for(ll i: ans) printf("%lld ", i);puts("");
        printf("%lld\n", accumulate(ans.begin(), ans.end(), 0LL));
        return 0;
}

Measured memory_bytes: 8820
h,w=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(h)]
m=[]

for y in range(h):
  for x in range(w):
    if x<w-1 and l[y][x]%2:
      l[y][x]-=1
      l[y][x+1]+=1
      m.extend([[y+1,x+1,y+1,x+2]])

for x in range(w):
  for y in range(h):
    if y<h-1 and l[y][x]%2:
      l[y][x]-=1
      l[y+1][x]+=1
      m.extend([[y+1,x+1,y+2,x+1]])

print(len(m))
for i in m:
  print(*i,sep=" ")

Measured memory_bytes: 72668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define ALLRANGE(x) x.begin(), x.end()

using namespace std;

int main(){
  string n;
  cin >> n;
  cout << (count(ALLRANGE(n), '9')!=0 ? "Yes": "No") << endl; 
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;

int main(){
    long long int n,d,ans=0;
    cin>>n>>d;
    vector<pair<long long int,long long int>>a(1000000);
    for(long long int i=0;i<n;i++){
        cin>>a[i].first>>a[i].second;
        if(a[i].first*a[i].first+a[i].second*a[i].second<=d*d){
            ans++;
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 18804
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int d=b-a;
  int n=d-1;
  
  long long ans;
  ans = (n+1)*n/2 - a;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import bisect
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

ans=0
A.sort()
B.sort()
C.sort()

for i in range(len(B)):
    ans+=bisect.bisect_left(A,B[i])*(len(C)-bisect.bisect_right(C,B[i]))
print(ans)

Measured memory_bytes: 22516
#include <iostream>
#include <stdio.h>
using namespace std;


int main(void){
        int n=0;
        while(1) {
                cin>>n;
                if(n==0) return 0;
                int a[n+1][n+1];
                int s;
                for(int i=0; i<n; i++) {
                        s=0;
                        for(int j=0; j<n; j++) {
                                a[i][j]=0;
                                cin>>a[i][j];
                                s+=a[i][j];
                        }
                        a[i][n]=s;
                }

                for(int j=0; j<n+1; j++) {
                        s=0;
                        for(int i=0; i<n; i++) {
                                s+=a[i][j];
                        }
                        a[n][j]=s;
                }

                for(int i=0; i<n+1; i++) {
                        for(int j=0; j<n+1; j++) {
                                printf("%5d",a[i][j]);
                        }
                        printf("\n");

                }
        }

        return 0;

}



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

int main() {
    int m, f, r, sum;
    while (true) {
        cin >> m >> f >> r;
        sum = m + f;
        if (m == -1 && f == -1 && r == -1) break;
        else if (m == -1 || f == -1) cout << 'F' << endl;
        else if (sum >= 80) cout << 'A' << endl;
        else if (sum >= 65 && sum < 80) cout << 'B' << endl;
        else if (sum >= 50 && sum < 65) cout << 'C' << endl;
        else if (sum >= 30 && sum < 50 && r >= 50) cout << 'C' << endl;
        else if (sum >= 30 && sum < 50 && r < 50) cout << 'D' << endl;
        else if (sum < 30) cout << 'F' << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3004
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
   int n;
   cin>>n;
   map<string,int> mp;
   for(int i=0;i<n;i++){
	   string s;
	   cin>>s;
	   mp[s]++;
   }
   cout<<"AC"<<" "<<'x'<<" "<<mp["AC"]<<"\n";
   cout<<"WA"<<" "<<'x'<<" "<<mp["WA"]<<"\n";
   cout<<"TLE"<<" "<<'x'<<" "<<mp["TLE"]<<"\n";
   cout<<"RE"<<" "<<'x'<<" "<<mp["RE"]<<"\n";
   
}

Measured memory_bytes: 3620
/*
 *created by Kraken on 28-03-2020 at 17:05
 */
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String s = sc.next();
		if (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5))
			System.out.println("Yes");
		else
			System.out.println("No");
	}

	static class FastReader {

		BufferedReader br;

		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    ll ans = 0;
    rep(i,n){
        ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-10;
int INF=1e9;
int MOD=1000000007;
int main(){
	int m;
	cin>>m;
	while(m--){
		int n,init,type,year,comm;
		double rate;
		cin>>init>>year>>n;
		int ans=0;
		while(n--){
			cin>>type>>rate>>comm;
			int now=init;
			if(type){
				REP(i,year){
					now=now*rate+now-comm;
				}
			}else{
				int sum=0;
				REP(i,year){
					sum+=now*rate;
					now-=comm;
				}
				now+=sum;
			}
			ans=max(ans,now);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1232
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.nextLong()
    println(solve(s, 0L))
}

fun solve(s: Long, sum: Long): Long {
    var res = sum + s
    var p = 10L
    while (p <= s) {
        res += solve(s % p, sum + s / p)
        p *= 10
    }
    return res
}


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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

void solve()
{
    int n;
    cin>>n;

    vll v(n);
    forn(i,n){
        cin>>v[i];
    }

    vector<ll> dp(n,1ll<<60);
    dp[0]=0;

    for(int i=0;i<n;i++){
        if(i+1<n){
            dp[i+1]=min(dp[i+1],abs(v[i+1]-v[i])+dp[i]);
        }
        if(i+2<n){
            dp[i+2]=min(dp[i+2],abs(v[i+2]-v[i])+dp[i]);
        }
    }

    cout<<dp[n-1]<<endl;
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 1792
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[202020];

int main(){
    
    // 1. 入力情報.
    int N;
    LL K;
    scanf("%d %lld", &N, &K);
    rep(i, N) scanf("%lld", &a[i]);
    
    // 2. sort.
    sort(a, a + N);
    
    // 3. 丸太の分割.
    // -> 二分探索で確認してみる.
    auto f = [](LL aMax, LL k, int n) -> bool {
        // ex.
        // 18 を 2回分割すると, 長さ 6 の 丸太 が 3つ.
        // -> 18 ÷ (長さ 6) = 3 だが, 分割回数は, 2回 なので 注意.
        LL ok = 0;
        rep(i, n){
            ok += a[i] / aMax;
            if(a[i] % aMax == 0) ok--;
        }
        return (ok <= k);
    };
    
    // LL l = 1, h = a[N - 1], m;
    LL l = 0, h = a[N - 1], m; // handmade13, handmade14 で, WAのため, ロジック修正.
    while(l + 1 < h){
        m = (h + l) >> 1;
        if(f(m, K, N)) h = m;
        else           l = m;
        // printf("h=%lld l=%lld m=%lld\n", h, l, m);
    }
    
    // 4. 出力.
    printf("%lld\n", h);
    return 0;
    
}

Measured memory_bytes: 5276
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        char[] S = Console.ReadLine().ToCharArray();

        S = S.Select(o => (char)(o + N)).Select(o => o >= 91 ? (char)(o - 26):o).ToArray();
        Console.WriteLine(S);
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

int main(){
	string S;
	cin >> S;
	int N = S.size();
	vector<int> A(N + 1, -1);

	if (S[0] == '<') {
		A[0] = 0;
	}
	if (S[N - 1] == '>') {
		A[N] = 0;
	}
	for (int i = 1;i < N;i++) {
		if (S[i - 1] == '>' && S[i] == '<') {
			A[i] = 0;
		}
	}

	for (int i = 0;i < N;i++) {
		if (S[i] == '<') {
			if (A[i] != -1) {
				A[i + 1] = A[i] + 1;
			}
		}
	}

	for (int i = N - 1;i >= 0;i--) {
		if (S[i] == '>') {
			if (A[i + 1] != -1 && A[i] < A[i + 1] + 1) {
				A[i] = A[i + 1] + 1;
			}
		}
	}

	ll ans = 0;
	for (int i = 0;i <= N;i++) {
		ans += (ll)A[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 2820
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;

int main(){
  ll s,i=2; cin>>s;
  set<ll>c;
  while(1){
   c.insert(s);
    if(s%2==0) s/=2; 
   else s=3*s+1;
  if(c.count(s)){
  cout<<i<<endl;
    break;
  }
  i++;
  }
}

Measured memory_bytes: 256
n,m,q = map(int,input().split())
bi = [[0 for i in range(n+1)] for j in range(n+1)]
for i in range(m):
    l,r = map(int,input().split())
    bi[l][r] += 1
ans = [[0 for i in range(n+1)] for j in range(n+1)]
for i in range(1,n+1):
    cou = 0
    for j in range(1,n+1):
        cou += bi[i][j]
        ans[i][j] = ans[i-1][j] + cou

for i in range(q):
    p , q  =map(int,input().split())
    print(ans[q][q]-ans[q][p-1]-ans[p-1][q]+ans[p-1][p-1])

Measured memory_bytes: 15572
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
    int N;
    cin >> N;
    int l[N];
    for(int i = 0; i < N; i++) cin >> l[i];

    sort(l, l + N);

    ll ans = 0;
    for(int i = 0; i < N - 2; i++){
        for(int j = i + 1; j < N - 1; j++){
            int len = l[i] + l[j];
            int p = lower_bound(l, l + N, len) - l;
            ans += p - j - 1;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
string s;
vvi dp;

int main(){
	cin>>s>>m;
	n=s.size();
	dp=vvi(n+2,vi(n+2));
	for(int d=0;d<n;d++) for(int l=0;l<n;l++) if(l+d<n){
		int r=l+d;
		if(s[l]==s[r]) dp[l+1][r+1]=dp[l+2][r]+(l==r?1:2);
		dp[l+1][r+1]=max({dp[l+1][r+1],dp[l+2][r+1],dp[l+1][r]});
	}
	for(int i=0;i<m;i++){
		vvi DP(n+2,vi(n+2));
		for(int d=0;d<n;d++) for(int l=0;l<n;l++) if(l+d<n){
			int r=l+d;
			bool B=s[l]==s[r];
			DP[l+1][r+1]=(B?DP[l+2][r]:dp[l+2][r])+(l==r?1:2);
			DP[l+1][r+1]=max({DP[l+1][r+1],DP[l+2][r+1],DP[l+1][r]});
		}
		dp=DP;
	}
	cout<<dp[1][n]<<endl;
}

Measured memory_bytes: 1104
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>

int main() {
  int n;

  while(std::cin >> n) {
    if(n == 0) break;
    std::vector<int> score(n);
    int sum = 0;
    for(int i = 0; i < n; ++i) {
      std::cin >> score[i];
      sum += score[i];
    }
    double average = double(sum) / double(n);
    double alpha = 0;
    for(int i = 0; i < n; ++i) {
      alpha += (score[i] - average) * (score[i] - average);
    }
    alpha = sqrt(alpha / n);
    printf("%.4f\n", alpha);
  }

  return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
int w,h,n,i,j,k,yy,ans,a[300005],b[300005],xia,shang,head,tail,zhan[300005];
struct nyh{
	int x,y;
}o[300005];
bool cmp(nyh u,nyh v){
	return u.x<v.x||u.x==v.x&&u.y<v.y;
}
int maxx(int u,int v){
	return u>v?u:v;
}
int minn(int u,int v){
	return u<v?u:v;
}
void gb(int u,int v){
	int mid=((u+v)>>1);
	if(u==v)
		return;
	gb(u,mid);
	gb(mid+1,v);
	for(i=mid,xia=0,shang=h;i>=u;i--){
		a[i]=xia;
		b[i]=shang;
		if(o[i].y>=yy) shang=minn(shang,o[i].y);
		if(o[i].y<=yy) xia=maxx(xia,o[i].y);
	}
	for(i=mid+1,xia=0,shang=h;i<=v;i++){
		a[i]=xia;
		b[i]=shang;
		if(o[i].y>=yy) shang=minn(shang,o[i].y);
		if(o[i].y<=yy) xia=maxx(xia,o[i].y);
	}
	head=1;tail=0;
	for(i=mid,j=mid;i>=u;i--){
        while(j<=v&&a[j]<=a[i]){
            while(head<=tail&&b[zhan[tail]]+o[zhan[tail]].x<=b[j]+o[j].x)
            	tail--;
            tail++;
            zhan[tail]=j;
            j++;
        }
        while(head<tail&&b[i]+o[zhan[head]].x<=b[zhan[head+1]]+o[zhan[head+1]].x)
        	head++;
    	ans=maxx(ans,(o[zhan[head]].x-o[i].x+min(b[i],b[zhan[head]])-a[i])<<1);
    }
    head=1;tail=0;
	for(i=mid,j=mid;i<=v;i++){
        while(j>=u&&a[j]<=a[i]){
            while(head<=tail&&b[zhan[tail]]-o[zhan[tail]].x<=b[j]-o[j].x)
            	tail--;
            tail++;
            zhan[tail]=j;
            j--;
        }
        while(head<tail&&b[i]-o[zhan[head]].x<=b[zhan[head+1]]-o[zhan[head+1]].x)
        	head++;
    	ans=maxx(ans,(o[i].x-o[zhan[head]].x+min(b[i],b[zhan[head]])-a[i])<<1);
    }
}
void work(){
	sort(o+1,o+n+1,cmp);
	yy=(h>>1);
	o[0].x=0;
	o[0].y=yy;
	o[n+1].x=w;
	o[n+1].y=yy;
	gb(0,n+1);
}
int main(){
	w=read();h=read();n=read();
	for(i=1;i<=n;i++){
		o[i].x=read();
		o[i].y=read();
	}
	ans=max(w,h)*2+2;
	work();
	swap(w,h);
	for(i=1;i<=n;i++)
		swap(o[i].x,o[i].y);
	work();
	pus(ans,2);
	return 0;
}

Measured memory_bytes: 6144
#include <cstdio>

using namespace std;

int main(){
	char b[10],a[3][3];
	while(~scanf("%9s",b)){
		char r=0;
		for(int i=0;i<9;i++)
			a[i%3][i/3]=b[i];
		for(int i=0,j,f;i<3;i++){
			if(a[i][0]=='s')continue;
			for(j=0,f=1;j<3;j++)
				if(a[i][0]!=a[i][j])f=0;
			if(f)r=a[i][0];
		}
		for(int i=0,j,f;i<3;i++){
			if(a[0][i]=='s')continue;
			for(j=0,f=1;j<3;j++)
				if(a[0][i]!=a[j][i])f=0;
			if(f)r=a[0][i];
		}
		if(a[0][0]!='s'&&a[0][0]==a[1][1]&&a[0][0]==a[2][2])r=a[0][0];
		if(a[2][0]!='s'&&a[2][0]==a[1][1]&&a[2][0]==a[0][2])r=a[2][0];
		printf("%c\n", r?r:'d');
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

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

const int M = 400;
bool visited[M][M];
vs s;
ll h, w;
ll cw = 0;
ll cb = 0;
void dfs(ll x, ll y){
    if(s[x][y] == '#'){
        cb++;
    }else{
        cw++;
    }
    visited[x][y] = 1;
    rep(i, 4){
        ll nx = x+dx[i];
        ll ny = y+dy[i];
        if(nx >= 0 && nx < h && ny >= 0 && ny < w && !visited[nx][ny] && s[nx][ny] != s[x][y]){
            dfs(nx, ny);
        }
    }
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cin >> h >> w;
    rep(i, h){
        string tmp;
        cin >> tmp;
        s.push_back(tmp);
    }
    ll ans = 0;
    rep(i, h)rep(j, w){
        if(!visited[i][j] && s[i][j] == '#'){
            cw = 0;
            cb = 0;
            dfs(i, j);
            ans += cw*cb;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15616
// https://atcoder.jp/contests/abc158/tasks/abc158_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, A, B;
  cin >> N >> A >> B;

  ll res = 0;
  ll abDiv = N / (A + B);
  ll abMod = N % (A + B);
  res += abDiv * A;
  res += min(abMod, A);

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

int main () 
{
    int High, Width;
    
    while (1)
    {
        std::cin >> High >> Width;
        
        if (High == 0 && Width == 0) break;
        
        for (int i = 0; i < High; i++) 
        {
            for (int j = 0; j < Width; j++) 
            {
                if (i == 0 || i == High - 1)
                {
                    std::cout << "#";
                }
                else if (j == 0 || j == Width - 1)
                {
                    std::cout << "#";
                }
                else 
                {
                    std::cout << ".";
                }
            }
            
            std::cout << std::endl;
        }
        
        std::cout << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

typedef pair<int,int> Point;

int diff_x[8] = {-1,0,1,-1,1,-1,0,1},diff_y[8] = {-1,-1,-1,0,0,1,1,1};
set<Point> SET;

int main(){

	int N;
	double R;

	scanf("%d %lf",&N,&R);

	double tmp_x,tmp_y;
	for(int i = 0; i < N; i++){
		scanf("%lf %lf",&tmp_x,&tmp_y);
		SET.insert(Point((int)(tmp_x/R),(int)(tmp_y/R)));
	}

	int ans = 0;

	while(SET.size() != 0){
		set<Point>::iterator it = SET.begin();
		Point point = *it;
		SET.erase(it);
		ans++;
		for(int i = 0; i < 8; i++){
			Point tmp = Point(point.first + diff_x[i],point.second + diff_y[i]);
			it = SET.find(tmp);
			if(it != SET.end())SET.erase(it);
		}
	}

	printf("%d\n",ans);
}

Measured memory_bytes: 11712
import java.util.*

fun main(args: Array<String>) {
	val scanner = Scanner(System.`in`)
	var ans = 0
	var min = Int.MIN_VALUE
	for (i in 0 until scanner.nextInt()) {
		val height = scanner.nextInt()
		if (min <= height) {
			min = height
			ans++
		}
	}
	println(ans)
	scanner.close()
}

Measured memory_bytes: 29604
#include<bits/stdc++.h>
using namespace std;
 
const int M = 1e9 + 7;
int h, w, dp[1000][1000];
char g[1000][1000];
 
int ans (int i, int j) {
    if (dp[i][j] != -1) return dp[i][j];
    int ret = 0;
    if (i + 1 < h) ret = (ret + ans(i+1,j)) %M;
    if (j + 1 < w) ret = (ret + ans(i,j+1)) %M;
    return dp[i][j] = ret;
}
 
int main ()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> h >> w;
    memset(dp, -1, sizeof(dp));
    dp[h-1][w-1] = 1;
    for (int i=0; i<h; ++i)
        for (int j=0; j<w; ++j) {
            cin >> g[i][j];
            if (g[i][j] == '#')
                dp[i][j] = 0;
        }
    cout << ans(0, 0) << endl;
    return 0;
}

Measured memory_bytes: 5376
n = int(input())
s = []
t = []
for i in range(n):
  a,b = map(str,input().split())
  s.append(a)
  t.append(int(b))
x = str(input())
w = False
ans = 0
for j in range(n):
  if w:
    ans+=t[j]
  if s[j] == x:
    w = True
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
  cin>>n;
  string s;
  cin>>s;int ans=n;
  int i=0;
  while(i<n)
  {int c=0;
  while(s[i]==s[i+1])
  {i++;c++;}
   ans=ans-(c);i++; }
  cout<<ans;
}

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

int main(){
	while(true){
		string str;
		getline(cin, str);
		
		if(str[0] == '0') break;
		
		int ans = 0;
		for(int i=str.size() -1; i>=0; i--){
			ans += str[i] - '0';
		}
		cout << ans << "\n";
	}
	cout << flush;
	
	return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<int64_t> s;
  for(int i=2;i<1000000;i++){
    int C=1;
    for(int x:s){
      if(x*x>i){
        break;
      }
      if(i%x==0){
        C=0;
        break;
      }
    }
    if(C){
      s.push_back(i);
    }
  }
  int L=s.size();
  vector<int> q(L);
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  int A=p[0],Z=1;
  for(int i=0;i<N;i++){
    A=gcd(A,p[i]);
    if(p[i]==1||Z==0){
      continue;
    }
    int64_t D=p[i];
    for(int j=0;j<L;j++){
      if(D%s[j]==0){
        if(q[j]){
          Z=0;
          break;
        }
        q[j]++;
        while(D%s[j]==0){
          D/=s[j];
        }
      }
      if(D==1){
        break;
      }
      if(s[j]*s[j]>D){
        int b=lower_bound(s.begin(),s.end(),D)-s.begin();
        if(q[b]){
          Z=0;
          break;
        }
        q[b]++;
        break;
      }
    }
  }
  if(Z){
    cout<<"pairwise coprime"<<endl;
  }
  else if(A==1){
    cout<<"setwise coprime"<<endl;
  }
  else{
    cout<<"not coprime"<<endl;
  }
}



Measured memory_bytes: 8004
N = int(input())
B = list(map(int, input().split()))

ans=0
for i in range(N):
    if i==0:
        ans+=B[i]
    elif i==N-1:
        ans+=B[i-1]
    else:
        ans+=min(B[i-1], B[i])
        
print(ans)

Measured memory_bytes: 3064
//By Tushar Gautam
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
int t,n,m,k,x,y,w;
set<int> v[LIM];
ll ans=0;
int val[LIM];
signed main(){
	fastio;
	cin>>n;
	int deg[n]={0};
	forn(i,n-1){
		cin>>x>>y; --x,--y;
		v[x].insert(y);
		v[y].insert(x);
		deg[x]++;
		deg[y]++;
	}
	set<p32> cur;
	forn(i,n) cur.insert(mp(deg[i],i));
	int c[n];
	forn(i,n) cin>>c[i];
	sort(c,c+n);
	int done=0;
	while(done<n){
		auto tp=*cur.begin();
		cur.erase(tp);
		val[tp.se]=c[done++];
		forstl(it,v[tp.se]){
			ans+=val[tp.se];
			cur.erase(mp(deg[it],it));
			--deg[it];
			v[it].erase(tp.se);
			cur.insert(mp(deg[it],it));
		}
	}
	cout<<ans<<ln;
	forn(i,n) cout<<val[i]<<" ";
	cout<<ln;
	return 0;
}

Measured memory_bytes: 6528