akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(int i = 0;i < n;++i)
#define rep1(i, n) for(int i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define chmin

#define lset(h, n) memset(h, n, sizeof(h));
    

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    string n,m;
    cin >> n >> m;
    int ans = 0;
    rep(i,3){
        if(n[i]==m[i]) ans++;
    }
    pri(ans);



    
    return 0;
}



Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from itertools import accumulate #list(accumulate(A))

Q = ii()
lr = li2(Q)
from collections import deque
que = deque()

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

prime = [0]*(10**5+1)
flag = [0]*(10**5+1)
prime[2] = 1

for i in range(3, 10**5+1, 2):
    if is_prime(i):
        prime[i] = 1

for i in range(3, 10**5+1, 2):
    if prime[i] and prime[(i+1)//2]:
        flag[i] = 1

ans = list(accumulate(flag))

for i in range(Q):
    print(ans[lr[i][1]]-ans[lr[i][0]-1])

Measured memory_bytes: 33584
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
using namespace std;
typedef long long ll;

const int MAX_N = 1000;
string str;
ll res = 0;

ll s2i(string s) {
	stringstream ss(s);
	ll i;
	ss >> i;
	return i;
}

bool is_number(char c) {return '0' <= c && c <= '9';}

int c2i(char c) {return c - '0';}

int sum[MAX_N];

void solve() {
	int loc = 0;
	for (int i = str.size()-1; i >= 0; i--) {
		if (is_number(str[i])) {
			sum[loc] += c2i(str[i]);
			loc++;
		} else {
			loc = 0;
		}
	}
}

int main(int argc, const char *argv[]) {
	memset(sum, 0, sizeof sum);
	while (cin>>str) {
		solve();
	}
	// advance
	for (int i = 0; i < MAX_N-1; i++) {
		if (sum[i] > 9) {
			sum[i+1] += sum[i] / 10;
			sum[i] %= 10;
		}
	}
	// print
	bool flag = false;
	for (int i = MAX_N-1 ; i >= 0; i--) {
		if (sum[i] == 0 && !flag) continue;

		cout<<sum[i];
		flag = true;
	}
	cout<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void AGC019B()
{
	string A;
	cin >> A;
	size_t n = A.size();
	ll ct = 1;
	vi cts(26);
	for (size_t i = 0; i < n; ++i)
	{
		int m = A[i] - 'a';
		ct += i - cts[m];
		++cts[m];
	}
	cout << ct << endl;
}



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

Measured memory_bytes: 640
import math
ABHM = list(map(int, input().split()))

radHM = math.pi * 2
mCorrection = ABHM[3] / 60
if ((ABHM[2] + mCorrection) * 5 > ABHM[3]):
    radHM *= ((ABHM[2] + mCorrection) * 5 - ABHM[3]) / 60
else:
    radHM *= (ABHM[3] - (ABHM[2] + mCorrection) * 5) / 60

print(math.sqrt(ABHM[0] * ABHM[0] + ABHM[1] * ABHM[1] - 2 * ABHM[0] * ABHM[1] * math.cos(radHM)))

Measured memory_bytes: 62300
a = gets.to_i
b = gets.split().map(&:to_i)
min = 1000000
max = -1000000
sum = 0
for i in b do
  sum += i
  if i > max
    max = i
  end
  if min > i
    min = i
  end
end

puts "#{min} #{max} #{sum}" 


Measured memory_bytes: 8900
/**
*    author:  Dooloper
*    created: 29.08.2020 21:08:21
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
   long long x;
public:
   mint(long long x=0) : x((x%mod+mod)%mod) {}
   mint operator-() const {
     return mint(-x);
   }
   mint& operator+=(const mint& a) {
       if ((x += a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator-=(const mint& a) {
       if ((x += mod-a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator*=(const  mint& a) {
       (x *= a.x) %= mod;
       return *this;
   }
   mint operator+(const mint& a) const {
       mint res(*this);
       return res+=a;
   }
   mint operator-(const mint& a) const {
       mint res(*this);
       return res-=a;
   }
   mint operator*(const mint& a) const {
       mint res(*this);
       return res*=a;
   }
   mint pow(ll t) const {
       if (!t) return 1;
       mint a = pow(t>>1);
       a *= a;
       return a;
   }
   // for prime mod
   mint inv() const {
       return pow(mod-2);
   }
   mint& operator/=(const mint& a) {
       return (*this) *= a.inv();
   }
   mint operator/(const mint& a) const {
       mint res(*this);
       return res/=a;
   }

   friend ostream& operator<<(ostream& os, const mint& m){
       os << m.x;
       return os;
   }
};
#pragma endregion

struct UnionFind{
  vector<int> d;
  UnionFind(){}
  UnionFind(int mx):d(mx,-1){}
  int root(int x){
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y){
    x = root(x);y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y]; d[y] = x;
    return true;
  }
  bool same(int x, int y){return root(x) == root(y);}
  int size(int x){return -d[root(x)];}
  int operator[](int x){return root(x);}
  int operator()(int x){return size(x);}
};

int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  UnionFind t(n);
  rep(i,m){
    int a, b;
    scanf("%d%d",&a,&b);
    a--;b--;
    t.unite(a,b);
  }
  int ans = 1;
  rep(i,n) ans = max(ans,t(i));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
const int MAXN = 55;
ll binom[MAXN][MAXN], pre[MAXN][MAXN];
int main() {
	for (int i = 0; i < MAXN; ++i) {
		for (int j = 0; j <= i; ++j)
			if (!j || j == i) binom[i][j] = 1;
			else binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j];
		pre[i][1] = binom[i][1];
		for (int j = 2; j < MAXN; ++j) pre[i][j] = pre[i][j - 1] + binom[i][j];
	}
	int n, k, S, T;
	scanf("%d%d%d%d", &n, &k, &S, &T);
	vector<int> A(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	if ((T & S) != S) {
		printf("0\n");
		return 0;
	}
	vector<int> bits;
	for (int j = 0; j < 18; ++j) {
		if ((T & (1 << j)) && !(S & (1 << j))) bits.push_back(j);
	}
	int s = bits.size();
	vector<int> B;
	for (int i = 0; i < n; ++i) {
		if (~T & A[i]) continue;
		if ((S & A[i]) != S) continue;
		int b = 0;
		for (int j = 0; j < s; ++j) {
			if (A[i] & (1 << bits[j])) b |= 1 << j;
		}
		B.push_back(b);
	}
	int req = (1 << s);
	ll ans = 0;
	vector<int> cnt(req);
	for (int b = 0; b < req; ++b) {
		for (int x : B) {
			cnt[x & b]++;
		}
		ll t = 0;
		for (int x : B) {
			t += pre[cnt[x & b]][k];
			cnt[x & b] = 0;
		}
		if (__builtin_popcount(b) & 1) ans -= t;
		else ans += t;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 4296
import java.util.Scanner;

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

	long N = scan.nextLong();
	long[] route_ = new long[5];
	for(int i = 0; i < 5; i++){
	    route_[i] = scan.nextLong();
	}

	long min = Math.min(
			    Math.min(
				     Math.min(route_[0],route_[1]),
				     Math.min(route_[2],route_[3])),
			    route_[4]);

	long count = (long)5;
	if(N % min != (long)0){
	    count += N / min;
	}else{
	    count += (N / min - 1);
	}

	System.out.println(count);
    }
}


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

using namespace std;
int main() {
    int N;
    int a[100];
    int alice = 0;
    int bob = 0;

    cin >> N;
    for (int i = 0; i < N; i++) cin >> a[i];
    sort(a, a+N);
    reverse(a, a+N);

    for (int i = 0; i < N; i++) {
        if (i%2) {
            bob += a[i];
        } else {
            alice += a[i];
        }
    }
    cout << alice - bob << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

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

int main(void){
  string s;
  cin>>s;
  for(int i = s.size() - 1 ; i >= 0 ; i --){
    cout<<s[i];
  }
  cout<<endl;

}

Measured memory_bytes: 1176
#include <stdio.h>
#include <ctype.h>
#include <string.h>
//prototype
int main(void);

int main(void){

  int i;
  int str_count;
  char str[1200];

  fgets(str,sizeof(str), stdin); 

  str_count = strlen(str) + 1;

  for (i = 0; i < str_count; i++) {
    if (isupper(str[i]) != 0) {
    //Upper case
      str[i] = tolower(str[i]);
    } else {
    //Lower case
      str[i] = toupper(str[i]);
    }
  }

  //disp the string
  printf("%s", str);

  return 0;
}



Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010;
int n,ans,mn,p[MAXN];
int main () {
	scanf("%d",&n);
	mn=n+1;
	for (int i=1;i<=n;i++) {
		scanf("%d",&p[i]);
		mn=min(mn,p[i]);
		if (p[i]==mn) {ans++;}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
int count=0;
int m;
int G[11111];
int A[1000000];
void insertionsort(int A[],int n,int g)
{
	int i,j;
	int v;
	for(i=g;i<n;i++)
	{
	v=A[i];
	 j=i-g;	
		while(j>=0 && A[j]>v)
		{
			A[j+g] =A[j];
			j=j-g;
			count++;
		}
		A[j+g]=v;
	}
}

void shellsort(int A[],int n)
{
	int i;
	G[0]=1;
	for(i=1;;i++)
	{
		G[i]=3*G[i-1]+1;
		if(G[i]>n)
		{
			break;
		}
	
	}
		m=i;
	
	for(i=m-1;i>=0;i--)
	{
		insertionsort(A,n,G[i]);
	}
}

int main(void)
{
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
	}
	
	shellsort(A,n);
	printf("%d\n",m);
	for(i=m-1;i>=0;i--)
	{
		printf("%d",G[i]);
		printf(" ");
	}
	printf("\n");
	printf("%d\n",count);
	for(int i=0;i<n;i++)
	{
		printf("%d\n",A[i]);
	}
	return 0;
}


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

using int64 = int64_t;

int main() {
  int64 x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<vector<int64>> a(3);
  a[0].resize(x);
  a[1].resize(y);
  a[2].resize(z);
  for (int64 i = 0; i < x; ++i)
    cin >> a[0][i];
  for (int64 i = 0; i < y; ++i)
    cin >> a[1][i];
  for (int64 i = 0; i < z; ++i)
    cin >> a[2][i];

  if (a[0].size() < a[1].size())
    swap(a[0], a[1]);
  if (a[1].size() < a[2].size())
    swap(a[1], a[2]);
  if (a[0].size() < a[1].size())
    swap(a[0], a[1]);

  vector<int64> aa;
  for (int64 t : a[0])
    for (int64 u : a[1])
      aa.push_back(t + u);
  auto& bb = a[2];

  sort(aa.begin(), aa.end(), greater<int64>());
  sort(bb.begin(), bb.end(), greater<int64>());
  if (aa.size() > k) aa.resize(k);
  if (bb.size() > k) bb.resize(k);

  vector<int64> c;
  for (int64 t : aa)
    for (int64 u : bb)
      c.push_back(t + u);
  sort(c.begin(), c.end(), greater<int64>());
  for (int64 i = 0; i < k; ++i)
    cout << c[i] << "\n";

  return 0;
}


Measured memory_bytes: 43368
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
if 0 in A:
  print(0)
  exit()
for ai in A:
  pro *= ai
  if pro > 10**18:
    print(-1)
    exit()
print(pro)
    

Measured memory_bytes: 86424
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
   int n,m;
   cin >> n >> m;
   int WA[100010],numAC=0,numWA=0;
   bool AC[100010];
   rep(i,1,n+1){
   	 WA[i]=0;
   	 AC[i]=false;
   }
   while(m--){
   	int p;
   	string s;
   	cin >> p >> s;
    if(AC[p]) continue;
    if(s=="AC"){
    	AC[p]=true;
    	numAC++;
    	numWA += WA[p];
    }else if(s=="WA"){
        WA[p]++;
    }
   }cout << numAC << " " << numWA << "\n";
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(snip_i, n) cin >> a.at(snip_i);
	sort(ALL(a));
	vector<int> b(n);
	rep(snip_i, n) cin >> b.at(snip_i);
	sort(ALL(b));
	vector<int> c(n);
	rep(snip_i, n) cin >> c.at(snip_i);
	sort(ALL(c));
	ll ans = 0;
	rep(i, n){
		int nb = b.at(i);
		int nc = upper_bound(c.begin(), c.end(), nb) - c.begin();
		nc = n - nc;
		int na = lower_bound(a.begin(), a.end(), nb) - a.begin();
		ans += (ll)nc * na;
		// cerr << nc << " " << na << " " << ans << endl;
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main(){
   string s,t,u;
   int a,b;
   cin >> s >> t;
   cin >> a >> b;
   cin >> u;

  
  if(s == u) a -= 1;
  else b -= 1;

  cout << a << " " << b;
    return 0;
}



Measured memory_bytes: 256
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict
import bisect

N, P = [int(x) for x in input().split()]


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


t = prime_decomposition(P)
c = collections.Counter(t)

ret = 1
for k,v in c.items():
    v2 = v
    while v2 >= N:
        ret *= k
        v2 -= N

print(ret)






Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

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


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

bool board[105][105];

int main() {
  int a, b;
  cin >> a >> b;
  bool base = false;
  if (a > b) {
    swap(a, b);
    base = true;
  }
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      board[i][j] = base;
    }
  }
  int acount = 1;
  int bcount = 0;
  int i, j;
  while (acount < a) {
    for (i = 1; i < 100; i += 2) {
      for (j = 0; j <= i; j++) {
        int k = i - j;
        board[j][k] = !board[j][k];
        if (j > 0) acount++;
        bcount++;
        if (acount >= a) break;
      }
      if (acount >= a) break;
    }
  }
  while (bcount > b) {
    for (int k = 1; k <= i; k++) {
      int l = i - k + 1;
      if (k > j) l -= 2;
      board[k][l] = !board[k][l];
      bcount--;
      if (bcount <= b) break;
    }
  }
  while (bcount < b) {
    for (int i = 99; i >= 0; i -= 2) {
      for (int j = 99; j >= 0; j -= 2) {
        board[i][j] = !board[i][j];
        bcount++;
        if (bcount >= b) break;
      }
      if (bcount >= b) break;
    }
  }
  cout << "100 100\n";
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      cout << (board[i][j] ? '#' : '.');
    }
    cout << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1e9 + 7

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

    int n;

    cin >> n;

    int mx = 0,mn = INT_MAX,id,cnt = 0;

    vector<int> a(n);

    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
        if(a[i]>mx){ mx = a[i]; cnt = 1; }
        else if(a[i]==mx) cnt++;
    }

    for(int i = 0;i < n;i++)
    {
        if(a[i]==mx and cnt==1) continue;
        if(max(mx-a[i],a[i])<mn){ id = a[i]; mn = max(mx-a[i],a[i]); }
    }

    cout << mx << ' ' << id;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>

using namespace std;

void solve()
{
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
	{
		cout << "vowel" << endl;
	}
	else
	{
		cout << "consonant" << endl;
	}
}

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

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
l_sum = 0
r_sum = a.inject(:+)
min = -1

(n-1).times do |i|
    l_sum += a[i]
    r_sum -= a[i]
    x = (l_sum - r_sum).abs
    min = x if(min == -1 || min > x)
end

puts min

Measured memory_bytes: 16132
atoe =[int(input()),int(input()),int(input()),int(input()),int(input())]

maxNum = 5
wrap = 0
atoe = sorted(atoe, key=lambda x: -10 if x%10==0 else -(x%10))
for i in range(0, maxNum-1):
    if atoe[i] % 10 == 0:
        step = atoe[i]
    else:
        step = (atoe[i] // 10 + 1) * 10
    #print(atoe[i], step)
    wrap += step

wrap += atoe[maxNum-1]
print(wrap)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(void) {
    string S;
    cin >> S;
    if(S.at(1) == S.at(0)) {
        if(S.at(2) != S.at(0) && S.at(3) == S.at(2)) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if(S.at(2) == S.at(0)) {
            if(S.at(3) == S.at(1)) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else if(S.at(2) == S.at(1)) {
            if(S.at(3) == S.at(0)) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }

    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int c=0;
    cin>>s>>t;
    for(int i=0;i<3;i++){
        if(s[i]==t[i])
            c++;
    }
    cout<<c<<endl;
    return 0;
}


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

const double EPS = 1e-9;

bool inside(double r, double cx, double cy, double x, double y){
    return hypot(x-cx, y-cy) <= r + EPS;
}

vector<double> circle(double x1, double y1, double x2, double y2, double x3, double y3){
    double a = x1 - x2;
    double b = y1 - y2;
    double c = x2 - x3;
    double d = y2 - y3;
    double q = 2*(a*d - b*c);
    if(abs(q) < EPS) return {};
    double D1 = x1*x1 + y1*y1;
    double D2 = x2*x2 + y2*y2;
    double D3 = x3*x3 + y3*y3;
    double v1 = D1 - D2;
    double v2 = D2 - D3;
    double cx = (d*v1 - b*v2)/q;
    double cy = (-c*v1 + a*v2)/q;
    double r = hypot(cx-x1, cy-y1);
    return {cx, cy, r};
}

int main(){
    int N;
    cin >> N;
    vector<double> X(N), Y(N);
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i];
    vector<vector<double>> cand;
    for(int i=0; i<N; i++) for(int j=0; j<i; j++){
        double cx = (X[i]+X[j])/2;
        double cy = (Y[i]+Y[j])/2;
        double r = hypot(cx-X[i], cy-Y[i]);
        cand.push_back({cx, cy, r});
    }
    for(int i=0; i<N; i++) for(int j=0; j<i; j++) for(int k=0; k<j; k++){
        auto ret = circle(X[i], Y[i], X[j], Y[j], X[k], Y[k]);
        if(ret.size()) cand.push_back(ret);
    }
    double ans = 1e9;
    for(auto& v : cand){
        double cx = v[0], cy = v[1], r = v[2];
        bool ok = true;
        for(int i=0; i<N; i++) if(!inside(r, cx, cy, X[i], Y[i])) ok = false;
        if(ok) ans = min(ans, r);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 1468
#include<stdio.h>
int main(void)
{
	int s;
	int count=2;
	int i,j,k;

	scanf("%d",&s);
/*
	if(s==1){
		count=4;
	}else if(s==2){
		count=4;
		s=1;
	}
	

	for(i=0;s!=1;i++){
		count++;
		if(s%2==0){
			s=s/2;
			printf("%d\n",s);
		}else{
			s=3*s+1;
            printf("%d\n",s);
  		}
	}*/

	switch(s){
		case 1:
			count=4;
			break;
		case 2:
			count=4;
			break;
		default:
			for(i=0;s!=1;i++){
		        count++;
		        if(s%2==0){
			       s=s/2;
			    }else{
			       s=3*s+1;
		        }
			}
	}


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

	return 0;
}

Measured memory_bytes: 128
#! /usr/bin/env python3

import sys
from collections import deque
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


# adjacent_2
def adjacent_2(h, w, H, W):
    ret = []
    for (dh, dw) in [(0, 1), (1, 0)]:
        h_ = h + dh
        w_ = w + dw
        if (0 <= h_) & (h_ < H) & (0 <= w_) & (w_ < W):
            ret.append((h_, w_))
    return ret


def adjacent_2_(h, w, H, W):
    ret = []
    for (dh, dw) in [(0, -1), (-1, 0)]:
        h_ = h + dh
        w_ = w + dw
        if (0 <= h_) & (h_ < H) & (0 <= w_) & (w_ < W):
            ret.append((h_, w_))
    return ret


H, W = map(int, readline().split())
M = [list(readline().decode().rstrip()) for _ in range(H)]

que = deque([(0, 0)])
while len(que) != 0:
    acc = que.popleft()

    ret = adjacent_2(*acc, H, W)
    cnt = adjacent_2_(*acc, H, W)
    ret = [pos for pos in ret if M[pos[0]][pos[1]] == '#']
    cnt = [pos for pos in cnt if M[pos[0]][pos[1]] == '#']

    if (len(cnt) > 1):
        print("Impossible")
        sys.exit()
    if acc == (H - 1, W - 1):
        break

    if (len(ret) != 1) or (len(cnt) > 1):
        print("Impossible")
        sys.exit()
    que.append(*ret)

print("Possible")


Measured memory_bytes: 9540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N; cin >> N;
    string s = "MARCH";
    ll c[5] = {0};
    rep (i, N) {
        string t; cin >> t;
        rep (j, 5) {
            if (t[0] == s[j]) c[j]++;
        }
    }

    ll ans = 0;
    rep (i, 5) {
        REP (j, i + 1, 5) {
            REP(k, j + 1, 5) {
                ans += c[i] * c[j] * c[k];
            }
        }
    }
    COUT(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<lint> A(N);
  REP(i, N) cin >> A[i];
  map<lint, lint> ma;
  REP(i, N) {
    ma[-A[i]]++;
  }
  int ans = 0;
  for(auto itr=ma.begin(); itr!=ma.end(); itr++) {
    lint a = -(itr->first);
    lint b = 1;
    while(b <= a) b *= 2;
    b -= a;
    if(ma.find(-b) != ma.end()) {
      if(a != b) {
        while(ma[-a] >= 1 && ma[-b] >= 1) {
          ma[-a]--;
          ma[-b]--;
          ans++;
        }
      } else {
        while(ma[-a] >= 2) {
          ma[-a] -= 2;
          ans++;
        }
      }
      
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 14464
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;


public class my
{
	public static void Main()
	{
		var n = my.GetInt();
		var A = my.GetIntArray(n);
		
		var cnt = my.MergeSort(A, 0, n);
		
		my.WriteArray(A);
		Console.WriteLine(cnt);
	}
	
	private static int MergeSort(int[] A, int left, int right)
	{
		int cnt = 0;
		
		if(left +1 < right) {
			int mid = (left + right) / 2;
			
			cnt += my.MergeSort(A, left, mid);
			cnt += my.MergeSort(A, mid, right);
			cnt += my.Merge(A, left, mid, right);
		}
		
		return cnt;
	}
	
	private static int Merge(int[] A, int left, int mid, int right)
	{
		var n1 = mid - left;
		var n2 = right - mid;
		
		var L = new int[n1 + 1];
		Array.Copy(A, left, L, 0, n1);
		//var L = A.Skip(left).Take(n1+1).ToArray();
		var R = new int[n2 + 1];	// for sentinel
		Array.Copy(A, mid, R, 0, n2);
		L[n1] = int.MaxValue;	// Sentinel
		R[n2] = int.MaxValue;
		
		int i = 0, j=0;
		
		int cnt = 0;
		for(int k = left; k < right; k++) {
			if(L[i] <= R[j]) {
				A[k] = L[i++];
			} else {
				A[k] = R[j++];
			}
			cnt++;
		}
		
		return cnt;
	}

	
	private static int CountChar(string s, char c)
	{
		return s.Length - s.Replace(c.ToString(), "").Length;
	}

	private static int[] GetIntArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
	}
		
	private static int[] GetIntArray(int n)
	{
		var A = new int[n];
		var s = Console.ReadLine().Split(' ');
		
		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}
	
	private static void WriteArray(int[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static void WriteArray(long[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static int GetInt()
	{
		return int.Parse(Console.ReadLine());
	}
	
	private static long GetLong()
	{
		return long.Parse(Console.ReadLine());
	}
}

Measured memory_bytes: 61092
H, W = map(int, input().split())
S = [input() for _ in range(H)]
for i in range(H):
    for j in range(W):
        count = 0
        if S[i][j] != "#":
            for k in [-1,0,1]:
                for l in [-1,0,1]:
                    if 0<=i+k<=H-1 and 0<=j+l<=W-1:
                        if S[i+k][j+l] == "#":
                            count += 1
            S[i] = S[i].replace(".",str(count),1)
for i in range(H):
    print(S[i])


Measured memory_bytes: 3064
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int digitSum(int n,int digit=8) {
	// digit > 2
	int x = 1;
	FOR(i,0,digit){
		x *= 10;
	}
	int sum = 0;
	FOR(i, 0, digit) {
		sum += n / x;
		n %= x;
		x /= 10;
	}
	sum += n;
	return sum;
}

int main()
{
	int n, l, r;
	int nPeople = 0;
	cin >> n;
	FOR(i, 0, n) {
		cin >> l >> r;
		nPeople += r - l + 1;
	}
	cout << nPeople << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <cstdlib>
int x[120];
int y[120];
int h[120];
int main()
{
    int n;
    int h_ = 0;
    scanf("%d", &n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d%d", &x[i], &y[i], &h[i]);
        h_ = std::max(h_, h[i]);
    }

    for(int l=h_;;l++)
    {
        for(int i=0;i<=100;i++)
        {
            for(int j=0;j<=100;j++)
            {
                int done = 1;
                for(int k=0;k<n;k++)
                {
                    if(std::max(l-abs(i-x[k])-abs(j-y[k]), 0) != h[k])
                    {
                        done = 0;
                        break;
                    }
                }
                if(done)
                {
                    printf("%d %d %d\n", i, j, l);
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int N, M;
  cin >> N >> M;
  vi A(N);
  rep(i,N) cin >> A[i];

  vi sum(N);
  sum[0] = A[0] % M;
  rep(i,N-1) sum[i+1] = (sum[i] + A[i+1]) % M;
  map<int, int> G;
  ++G[0];
  rep(i,N) ++G[sum[i]];

  ll ans = 0;
  for (auto p : G) {
    int &v = p.second;
    ans += (ll)v*(v-1)/2;
  }

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


Measured memory_bytes: 3968
//RGB Boxes

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    int R,G,B,N,Ans=0;cin>>R>>G>>B>>N;
    for(int i=0;i*R<=N;i++){
        for(int j=0;(j*G+i*R)<=N;j++){
            if(N>=i*R+j*G&&(N-i*R-j*G)%B==0)Ans++;
        }
    }
    cout << Ans << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

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

const int mod = 1e9 + 7;


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

	int n,k;
	cin >> n >> k;

	int cnt=0;
	vi h(n);
	rep(i, n){
		cin >> h[i];
		if(h[i] >= k){
			cnt++;
		}
	}

	

	cout << cnt << endl;;
    return 0;
}




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

#define int long long

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

int I, O, T, J, L, S, Z;

signed main() {
    cin >> I >> O >> T >> J >> L >> S >> Z;
    int ans = I / 2 * 2 + O + J / 2 * 2 + L / 2 * 2;
    int odd = I % 2 + J % 2 + L % 2;
    if (odd == 3) {
        ans += 3;
    } else if (odd == 2 && I != 0 && J != 0 && L != 0) {
        ans += 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import math

N = int(input())

n = math.floor(N **(1/2))
list =[]
count = 0
for a in range(1,n+1):
    if N % a  != 0:
        pass
    else:
        b = int(N/a)
        #print(a,b)
        m = max(len(str(a)),len(str(b)) )
        #list.append(m)
        count += 1
        if count == 1:
            mintmp = m

        if  mintmp > m:
            mintmp = m

#print(min(list))
print(mintmp)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, h, m;
  const double PI = acos(-1);
  cin >> a >> b >> h >> m;
  double th = double(60*h+m)*(PI/360);
  double tm = double(m)*(PI/30);
  double rad = abs(th-tm);
  double ans = a*a+b*b-2*a*b*cos(rad);
  ans = sqrt(ans);
  cout << fixed << setprecision(20) << ans;
}


Measured memory_bytes: 4144
def main():
    A, B, C = map(int, input().split())
    ans = 0
    seen = set()
    while True:
        if A % 2 != 0 or B % 2 != 0 or C % 2 != 0:
            break
        if (A, B, C) in seen:
            print(-1)
            return
        seen.add((A, B, C))
        x = A//2
        y = B//2
        z = C//2
        A = y + z
        B = z + x
        C = x + y
        ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll a[500005],t[2000005],ind[500005],le[500005],ri[500005],res[500005];
bool comp(ll i,ll j){
	if(le[i]==le[j])
		return ri[i]<ri[j];
	return le[i]<le[j];
}
void update(ll v,ll tl,ll tr,ll pos){
	if(tl==tr){
		t[v]=1;
		return;
	}
	ll tm=(tl+tr)/2;
	if(pos<=tm)
		update(2*v,tl,tm,pos);
	else
		update(2*v+1,tm+1,tr,pos);
	t[v]=t[2*v]+t[2*v+1];
}
ll sum(ll v,ll tl,ll tr,ll l,ll r){
	if(l>r)
		return 0;
	if(l==tl&&r==tr)
		return t[v];
	ll tm=(tl+tr)/2;
	return sum(2*v,tl,tm,l,min(r,tm))+sum(2*v+1,tm+1,tr,max(l,tm+1),r);
}
void solve(){
	ll n,q;
	cin>>n>>q;
	vector<vector<ll>> v(n+1);
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		v[a[i]].push_back(i);
	}
	for(ll i=1;i<=n;i++)
		if(!v[i].empty())
			reverse(v[i].begin(),v[i].end());
	for(ll i=1;i<=q;i++){
		cin>>le[i]>>ri[i];
		ind[i]=i;
	}
	for(ll i=1;i<=n;i++)
		if(!v[i].empty())
			update(1,1,n,v[i].back());
	sort(ind+1,ind+q+1,comp);
	ll j=1;
	for(ll i=1;i<=n;i++){
		while(j<=q&&le[ind[j]]==i){
			res[ind[j]]=sum(1,1,n,le[ind[j]],ri[ind[j]]);
			j++;
		}
		v[a[i]].pop_back();
		if(!v[a[i]].empty())
			update(1,1,n,v[a[i]].back());
	}
	for(ll i=1;i<=q;i++)
		cout<<res[i]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 45068
from collections import deque

O = input()
E = input()

OQ = deque(O)
EQ = deque(E)
P = ''
for i in range(1, len(O) + len(E) + 1):
    if i % 2 == 1:
        P += OQ.popleft()
    else:
        P += EQ.popleft()
print(P)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);
ll tens[100005];
const ll mod = 1000000007;

int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s;
  cin >> s;
  tens[0]=1;
	for(ll i=1;i<100004;i++){
		tens[i]=(tens[i-1]*10)%13;
	}
	ll tmp;
  ll n = s.length();
  ll dp[n][13];
  memset(dp,0,sizeof(dp));
  if(s[0] == '?'){
     
    for (ll i = 0; i < 10; ++i)
    {
     tmp=(i*tens[n-1])%13;
      dp[0][tmp] += 1;
    }
   }
  else{
  	tmp=((s[0]-'0')*tens[n-1])%13;
    dp[0][tmp] = 1;
}
 
 
  for (ll i = 1; i < n ; ++i)
  {
    ll t = ((s[i]-'0')*tens[n-i-1])%13;
    if(s[i] == '?')
    {
      for (ll j = 0; j < 10; ++j)
      {
        t = (j*tens[n-i-1])%13;
        for (ll k = 0; k < 13; ++k)
        {
          dp[i][(k+t)%13] += dp[i-1][k];
          dp[i][(k+t)%13] %= mod;
          //if((k+t)%13==5) cout<<"this"<<j<<" "<<endl;
        }
      }
    }
    else
    {
      
      for (ll j = 0; j < 13; ++j)
      {
        dp[i][(j+t)%13] += dp[i-1][j];
        dp[i][(j+t)%13] %= mod;
      }
    }
   
    
  }
  
  cout << dp[n-1][5] << endl;
  return 0;
}

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

int main() {
  long long H, W; cin >> H >> W;
  if (H == 1 || W == 1) cout << 1 << endl;
  else if (H % 2 == 1 && W % 2 == 1) {
    cout << (H * W + 1) / 2 << endl;
  }
  else cout << H * W / 2 << endl;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<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);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// テーブルを作る前処理
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }

};

int main() {
    int N,K,L;
    cin >> N >> K >> L;

    UnionFind uf1(N);
    REP(i,K){
        int p,q;
        cin >> p >> q;
        uf1.merge(p-1,q-1);
    }
    

    UnionFind uf2(N);
    REP(i,L){
        int r,s;
        cin >> r >> s;
        uf2.merge(r-1,s-1);        
    }

    map<pair<ll, ll>, ll> rnum;
    REP(i,N) rnum[{uf1.root(i), uf2.root(i)}]++;
    REP(i,N) {
        cout << rnum[{uf1.root(i), uf2.root(i)}];
        if (i != N-1) cout << ' ';
    }
    cout << endl;

    return 0;
}


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

int main() {
  ll N, D;
  int ans = 0;
  cin >> N >> D;

  vector<ll> X(N), Y(N);

  for(int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
  }
  for(int i = 0; i < N; i++) {
    if(X[i] * X[i] + Y[i] * Y[i] <= D * D) ans++;
  }

  cout << ans;
  return 0;

}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ld,ld> id;

#define FOR(i, a, b) for(int i=(a); i<=(b); i++)
#define ROF(i, a, b) for(int i=(a); i>=(b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define FILL(x, n, v) fill(x, x+n, v);
#define ALL(x) x.begin(), x.end()
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define f first
#define s second
#define ins insert
#define e emplace
#define eb emplace_back
#define ef emplace_front
#define p push
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ft front
#define bk back
#define pp pop
#define ppb pop_back
#define ppf pop_front

#define db cout<<"YEET\n";
#define ct(x) cout<<x<<'\n';

const ll MOD = 1e9+7; //998244353
const ll MAXN = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

int main(){
    FAST
    ll h, w, n;
    cin >> h >> w >> n;
    vector<tuple<ll, ll, ll> > border;
    FOR(i,1,n){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        if ((a==0 || a==h || b==0 || b==w) && (c==0 || c==h || d==0 || d==w)){
            border.eb(a,b,i);
            border.eb(c,d,i);
        }
    }
    ll sz = (ll)border.size()-1;

    vector<tuple<ll, ll, ll> > top, right, bottom, left;
    FOR(i,0,sz){
        ll x, y, num;
        tie(x,y,num) = border[i];
        if (x==0) top.eb(x,y,num);
        else if (x==h) bottom.eb(x,y,num);
        else if (y==0) left.eb(x,y,num);
        else right.eb(x,y,num);
    }
    sort(ALL(top));
    sort(ALL(bottom), greater<tuple<ll, ll, ll> >());
    sort(ALL(right));
    sort(ALL(left), greater<tuple<ll, ll, ll> >());

    bool check[MAXN], imposs=0;
    MEM(check, false);
    stack<ll> ans;

    sz = (ll)top.size()-1;
    FOR(i,0,sz){
        ll num = get<2>(top[i]);
        if (!check[num]){
            ans.p(num);
            check[num]=1;
        } else {
            if (ans.empty() || ans.top() != num) imposs=1;
            else ans.pp();
        }
    }

    sz = (ll)right.size()-1;
    FOR(i,0,sz){
        ll num = get<2>(right[i]);
        if (!check[num]){
            ans.p(num);
            check[num]=1;
        } else {
            if (ans.empty() || ans.top() != num) imposs=1;
            else ans.pp();
        }
    }

    sz = (ll)bottom.size()-1;
    FOR(i,0,sz){
        ll num = get<2>(bottom[i]);
        if (!check[num]){
            ans.p(num);
            check[num]=1;
        } else {
            if (ans.empty() || ans.top() != num) imposs=1;
            else ans.pp();
        }
    }
    
    sz = (ll)left.size()-1;
    FOR(i,0,sz){
        ll num = get<2>(left[i]);
        if (!check[num]){
            ans.p(num);
            check[num]=1;
        } else {
            if (ans.empty() || ans.top() != num) imposs=1;
            else ans.pp();
        }
    }
    
    if (!ans.empty()) imposs=1;

    if (imposs) cout << "NO";
    else cout << "YES";
}

Measured memory_bytes: 16492
Q=[]
A=->*x{Q<<[?+,*x]*" "}
C=->*x{Q<<[?<,*x]*" "}
C[2,0,403]
0.upto(30){|i|A[403+i,403+i,404+i]}
2.times{|x|s=67+128*x
31.downto(0){|i|A[403+i,s+33,61]
C[x,61,s+i]
C[s+i,403,61]
i.times{A[61,61,61]}
A[61,s+33,s+33]}}
30.times{|i|30.times{|j|A[67+i,195+j,61]
C[61,403,61]
A[2+i+j,61,2+i+j]}}
57.downto(0){|i|2.times{A[2+i,3+i,2+i]}}
puts Q.size,Q

Measured memory_bytes: 14864
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N,K;
    cin >> N >> K;
    ll P[5010], C[5010];
    rep(i,0,N){
        cin >> P[i];
        P[i]--;
    }
    rep(i,0,N) cin >> C[i];
    ll ans = -INF;
    rep(i,0,N){
        ll score = 0;
        vector<ll> scores;
        ll cnt = 0, cur = i;
        while(true){
            cnt++;
            cur = P[cur];
            score += C[cur];
            scores.push_back(C[cur]);
            if(cur == i) break;
        }
        ll shou = K / cnt;
        ll amari = K % cnt;
        if(score > 0){
            if(shou == 0){
                ll res = -INF, cur = 0;
                ll v = min(K,cnt);
                rep(j,0,v){
                    cur += scores[j];
                    res = max(res, cur);
                }
                ans = max(ans, res);
            }else{
                ll alt1 = score * shou;
                ll res = 0, cur = 0;
                rep(j,0,amari){
                    cur += scores[j];
                    res = max(res, cur);
                }
                alt1 += res;
                ans = max(ans, alt1);

                ll alt2 = score * (shou - 1);
                if(shou == 1){
                    res = -INF;
                }else{
                    res = 0;
                }
                cur = 0;
                rep(j,0,cnt){
                    cur += scores[j];
                    res = max(res, cur);
                }
                alt2 += res;
                ans = max(ans, alt2);
            }

        }else{
            ll res = -INF, cur = 0;
            ll v = min(K, cnt);
            rep(j,0,v){
                cur += scores[j];
                res = max(res, cur);
            }
            ans = max(ans, res);
        }
    }
    print(ans);
    

}

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

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	llong n;
	llong a,b;
	cin>>n>>a>>b;
	
	llong hoge=n/(a+b);
	llong hogee=n%(a+b);
	
	llong ans=0;
	ans+=a*hoge;
	ans+=min(hogee,a);
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256