akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n;
  ll d;
  cin >> n >> d;
  int ans = 0;
  REP(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x * x + y * y <= d * d) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3648
n=int(input())
a=list(map(int,input().split()))

flag=0
b=[]
c=[]
for i in range(n-1):
    if a[i]<a[i+1]:
        if flag>0:
            pass
        else:
            flag=1
            b.append(a[i])
    else:
        if flag<=0:
            pass
        else:
            flag=-1
            c.append(a[i])
    #print(a[i])
    
if flag==1:
    c.append(a[n-1])
    
            
if c==[]:
    print(1000)
else:
    money=1000
    kabu=0
    for i in range(len(b)):
        kabu=money//b[i]
        money=money-kabu*b[i]+kabu*c[i]
        kabu=0
    print(money)
    
#print(b,c)


Measured memory_bytes: 61952
#include <bits/stdc++.h>
    
using namespace std;
int n, o;
int main( ) {
    cin>>n;
    o=n%10;
    if (o==2 or o==4 or o==5 or o==7 or o==9){
        cout<<"hon";
    }
    else if(o==0 or o==1 or o==6 or o==8){
        cout<<"pon";
    }
    else{
        cout<<"bon";
    }
    return 0;
}

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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a == max(a, max(b, c))) {
        cout << a * pow(2, k) + b + c << endl;
    } else if (b == max(a, max(b, c))) {
        cout << b * pow(2, k) + a + c << endl;
    } else {
        cout << c * pow(2, k) + b + a << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>

int main() {
    
    int a,b;
    
    std::cin >> a >> b;
    if(a < b) std::cout << "a < b" << "\n";
    if(a > b) std::cout << "a > b" << "\n";
    if(a == b) std::cout << "a == b" << "\n";
    
    return 0;
}



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

int main(){
  long long A, B;
  cin >> A >> B;
   
  if((A + B) % 2 == 0) {
    long long K = (A + B) / 2;
    cout << K << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
//i64 mod = 1000000007;
i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;

int main(int argc, char **argv) {
    int n;
    cin >> n;
    unordered_map<int, int> as;
    for (int i=0; i<n; ++i) {
        int a;
        cin >> a;
        if (as.find(a) != as.end()) {
            as[a] = 0;
        }
        else
            as.insert(make_pair(a, 1));
    }

    if (as.find(1) != as.end()) {
        cout << as[1] << endl;
        return 0;
    }

    i64 ans{0};
    for (auto kv : as) {
        for (int j=2; j*j <= kv.first; ++j) {
            if (kv.first%j != 0) continue;
            if (as.find(j) != as.end() ||
                as.find(kv.first/j) != as.end()) {
                kv.second=0;
                break;
            }
        }
        ans+=kv.second;
    }

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


Measured memory_bytes: 11396
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a;
ll b[100001] = { 0 };

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

	for (ll i = 0; i <n; i++) {
		ll tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

	for (ll i = 0; i < n; i++) {
		b[a[i]]++;
		if (a[i] != 0) {
			b[a[i] - 1]++;
		}
		b[a[i]+1]++;
	}
	for (ll i = 0; i < 100000; i++) {
		ll tmp = b[i];
		ans = max(tmp, ans);
	}

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


Measured memory_bytes: 1908
s = "x" + input()
n = len(s)

a = s[1:]
l = s[1:(n-1)//2 + 1]
r = s[(n+3)//2:]

if a == a[::-1] and l == l[::-1] and r == r[::-1]:
    ans = "Yes"
else:
    ans = "No"

print(ans)


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

using namespace std;

int N, X;
const int maxSize = 100001;
int x[maxSize];
int main()
{
cin >> N >> X;
int temp;
for(int i=0; i<N; i++)
{
    cin >> temp;
    x[i] = abs(temp-X);
}

if(N==1)
    cout << x[0];
else
{
    int ans = __gcd(x[0], x[1]);
    for(int i=2; i<N; i++)
        ans = __gcd(ans, x[i]);
    cout << ans;
}
//find gcd
return 0;
}



Measured memory_bytes: 640
#include <iostream>  
using namespace std;  
  
// Important header files   
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
#include <iostream>  
using namespace __gnu_pbds;  
using namespace std;  
  
// Declaring ordered_set 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update>  
    ordered_set; 
#define rep(i,n) for(li i=0;i<n;i++)
#define li long long int
#define ll long long int
#define pb push_back
#define all(v) sort(v.begin(),v.end())
const int N = 40043;
const ll mod = 1e9 + 7;
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f first
#define s2 second
const ll INF=(1LL<<60)-1;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};

int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    return (a*b)/gcd(a,b);
}
 
ll power(ll a,ll b,ll mo)
{
    ll ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return ans;
}
 
li xx,yy,dd;
void equation(li a,li b)
{
    if(b==0)
    {
        xx=1;
        yy=0;
        dd=a;
    }
    else
    {
        equation(b,a%b);
        li temp=xx;
        xx=yy;
        yy=temp-(a/b)*yy;
    }
}
li inverse(li a,li m)
{
    equation(a,m);
    return(xx%m+m)%m;
}
bool compare(const pair<li,li> &i, pair<li,li> &j)
{
    if(i.f==j.f)
    return i.s2 > j.s2;
    else
    return i.f<j.f;
    
}

void solve()
{
    int n,l,r,k;
    cin>>n;
    int ans=0;
  	for(int i=1;i<=n;i++)
  	{
  	    int valid=i;
  		ans=0;
		for(int j=1;j*j<=valid;j++)
			{
				for(int k=1;k*k<=valid;k++)
					{
						int f=i-(j*j+k*k+j*k);
						
						double z=1.0*(-(j+k)+sqrt((j+k)*(j+k)+4*f))/2.0;
					
						if(z>0 && z<=n && z-(int)z==0)
						ans++;
					}
			}	
				cout<<ans<<endl;
	}
	
    
    
}
signed main()
{
    FAST_IO;
    li t;
    t=1;
  
    while(t--)
    {
        solve();
        cout<<endl;
        
    }
    
}

Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int ans = h * w;
    ans -= a * w;
    ans -= b * h;
    ans += a * b;
    cout << ans << endl;
}

Measured memory_bytes: 256
#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 reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
vector<vector<int>> vec(2010, vector<int>(2010, 0));

char rev(char c) {
  switch(c) {
    case 'R':
      return 'L';
    case 'L':
      return 'R';
    case 'U':
      return 'D';
    case 'D':
      return 'U';
  }
  return 'U';
}

int main()
{
  int sx, sy, tx, ty;
  int cx, cy;
  cin >> sx >> sy >> tx >> ty;
  cx = sx;
  cy = sy;
  string tmp = "";
  string ans = "";
  while(cy < ty) {
    tmp += 'U';
    cy++;
  }
  while(cx < tx) {
    tmp += 'R';
    cx++;
  }
  ans += tmp;
  rep(i, (int)tmp.size()) ans += rev(tmp.at(i));
  tmp = "L";
  cx = sx - 1, cy = sy-1;
  while(cy < ty) {
    tmp += 'U';
    cy++;    
  }
  while(cx < tx) {
    tmp += 'R';
    cx++;
  }
  tmp += 'D';
  ans += tmp;
  rep(i, (int)tmp.size()) ans += rev(tmp.at(i));
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 19436
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

int main() {
    long long W, H, x, y;
    cin >> W >> H >> x >> y;
    double res = W * H / 2.0;
    cout << fixed << setprecision(10) << res << " ";

    if (x*2 == W && y * 2 == H) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll,ll> mp;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        mp[a[i]]++;
    }
    ll sum = 0;
    for(auto i:mp){
        if(i.second >= 2) sum += i.second*(i.second-1)/2;
    }

    for (int i = 0; i < n; ++i) {
        ll ans = 0,ans2 = 0;
        ll tmp,tmp2;
        tmp = mp[a[i]]-1;
        if(tmp >= 2) ans += tmp*(tmp-1)/2;
        tmp2 = mp[a[i]];
        if(tmp2 >= 2) ans2 -= tmp2*(tmp2-1)/2;
        cout << sum+ans+ans2 << endl;
    }
    return 0;
}

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

vector<vector<int>> C(3, vector<int>(3, 0));

int main(void){
    
    for(int i = 0; i < 3; ++i) for(int j = 0; j < 3; ++j) scanf("%d", &C[i][j]);
    
    vector<int> a(3, 0), b(3, 0);
    for(int a1 = 0; a1 <= 100; ++a1){
        for(int a2 = 0; a2 <= 100; ++a2){
            for(int a3 = 0; a3 <= 100; ++a3){
                a[0] = a1;
                a[1] = a2;
                a[2] = a3;
                b[0] = C[0][0] - a1;
                b[1] = C[0][1] - a1;
                b[2] = C[0][2] - a1;
                int cnt = 0;
                for(int i = 0; i < 3; ++i){
                    for(int j = 0; j < 3; ++j){
                        if(C[i][j] == a[i] + b[j]) ++cnt;
                    }
                }
                if(cnt == 9) { printf("Yes\n"); return 0; }
            }
        }
    }
    printf("No\n");
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
up = dn = False
ans = 1
p = A[0]
for a in A:
    if p < a:
        up = True
    elif p > a:
        dn = True
    if up and dn:
        ans += 1
        up = dn = False
    p = a
print(ans)

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

int n, sum = 0, scnt = 0;
vector<int> memo[100005];

void solve();

int main() {
  cin >> n;
  while(sum < n) sum += ++scnt;
  if(sum != n)
    cout << "No" << endl;
  else
    solve();
  return 0;
}

void solve() {
  int nlast = 2, now = 1, cnt = 0;
  cout << "Yes" << endl;
  while(1) {
    while(now < nlast) {
      memo[now].push_back(cnt + 1);
      memo[nlast].push_back(cnt + 1);
      ++now;
      ++cnt;
    }
    ++nlast;
    now = 1;
    if(cnt == n) break;
  }
  cout << scnt + 1 << endl;
  for(int i = 1; i <= scnt + 1; ++i) {
    cout << memo[i].size();
    for(int j = 0; j < memo[i].size(); ++j)
      cout << " " << memo[i][j];
    cout << endl;
  }
}

Measured memory_bytes: 4608
n,d = map(int,input().split())
su = 0
for i in range(n):
  x,y = map(int,input().split())
  #print("i=",i,"x,y=",x,y)
  if d**2 >= x**2 +y**2:
    su +=1
  else:
    continue
print(su)

Measured memory_bytes: 9184
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>

using namespace std;
typedef long long ll;


int main() {
	ll a, b, x;
	cin >> a >> b >> x;
	if (a == 0) cout << b / x + 1 << endl;
	else cout << b / x - (a - 1) / x << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int in(){int x; scanf("%d",&x); return x;}
//static const int MAX = 10000;


int main(){
  int A = in(), B = in(), ans;
  ans = max(A+B, A-B);
  ans = max(ans, A*B);

  cout << ans << endl;
}


Measured memory_bytes: 256
N, A, B, C, D = [int(c) for c in input().split()]
S = input()

reachable = {B-1}
unreachable = set()
for i, c in enumerate(S):
    if c=='.' and (i-2 in reachable or i-1 in reachable):
        reachable.add(i)


for x in range(A, C):
    if x>=2 and S[x-1]=='#' and S[x-2]=='#':
        print('No')
        exit()

    unreachable.add(x)    
    if S[x-1]=='.' and ((x-2 in reachable and x-2 not in unreachable) or
                        (x-3 in reachable and x-3 not in unreachable) or
                        (x-1 in reachable and S[x-2]=='.' and S[x]=='.')
    ):
        unreachable.discard(x-1)
    if S[x-2]=='.' and ((x-3 in reachable and x-3 not in unreachable) or
                        (x-4 in reachable and x-4 not in unreachable)):
        unreachable.discard(x-2)
        
out = 'Yes' if D-1 in reachable and D-1 not in unreachable else 'No'
print(out)

# ##..#..
# #######
# S##.#..
# .#.##..
# #######
# .#..##.
# .#..#.#


 # #.S#.#...#.#...
 # .U.#.#...#.#...
 # ..##.#...#.#...
 # ###############
 # ...###...#.#...
 # ###############
 # ...#.##..#.#...
 # ...#.#.#.#.#...
 # ...#.#..##.#...
 # ###############
 # ...#.#...###...
 # ###############
 # ...#.#...#.##..
 # ...#.#...#.#.#.
 # ...#.#...#.#G.#




Measured memory_bytes: 26204
n,a,b,c,d=map(int,input().split())
# 合計で個区間ができる。
nn=n
n-=1
for i in range(nn):
  cnt=0
  while n>=0:
    l=a-n*d-cnt
    r=a-n*c+cnt
    if l<=b<=r:
      print('YES')
      exit()
    r=a+n*d+cnt
    l=a+n*c-cnt
    if l<=b<=r:
      print('YES')
      exit()
    n-=2
    cnt+=d-c
print('NO')


Measured memory_bytes: 65756
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int a, b, c;
  cin >> a >> b >> c;
  
  if (a == b && b == c) {
    cout << (a % 2 == 0 ? -1 : 0) << '\n';
    return 0;
  }
  int ans = 0;
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    int na = (b + c) / 2;
    int nb = (a + c) / 2;
    int nc = (a + b) / 2;
    swap(a, na);
    swap(b, nb);
    swap(c, nc);
    ans++;
  }
  cout << ans << '\n';




  
  return 0;
}

Measured memory_bytes: 256
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define inf INT_MAX/3
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
#define sz size()
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
map<int,int>mp;
set<int> s;

int main()
{

    string s;
    cin>>s;
    int a[3];
    a[2]=s[0]-'0';
    a[1]=s[1]-'0';
    int min=1000;
    for(int i=2; i<s.length(); i++)
    {
        a[0]=s[i]-'0';
        int score=a[2]*100+a[1]*10+a[0];
        if(abs(score-753)<min)min=abs(score-753);
        a[2]=a[1];
        a[1]=a[0];
    }
    cout<<min<<endl;
    return 0;
}


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

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

using namespace std;

vector<pair<char,int>> run_length_encoding(const string& s){
	vector<pair<char,int>> res;
	int n=s.length(),pre=0;
	rep(i,n) if(i==n-1 || s[i]!=s[i+1]) res.emplace_back(s[i],i-pre+1), pre=i+1;
	return res;
}

int main(){
	int n,k,r,s,p;
	string t; cin>>n>>k>>r>>s>>p>>t;

	int ans=0;
	rep(i,k){
		string h;
		for(int j=i;j<n;j+=k) h+=t[j];

		for(auto q:run_length_encoding(h)){
			if     (q.first=='r') ans+=(q.second+1)/2*p;
			else if(q.first=='s') ans+=(q.second+1)/2*r;
			else                  ans+=(q.second+1)/2*s;
		}
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 1724
N,M = map(int, input().split())
A = []
for i in range(N):
    A.append(input())
B = []
for i in range(M):
    B.append(input())

for i in range(N-M+1):
    for j in range(N-M+1):
        tmp = [A[i+k][j:j+M] for k in range(M)]
        if tmp == B:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
def c_all_green(D, G, Problems):
    ans = float('inf')
    for binary in range(1 << D):
        total_score = 0
        solved_problem = 0
        
        # 「全問正解する配点」の決定(1つも全問正解しない場合も含む)
        for k, (p, c) in enumerate(Problems):
            if binary & (1 << k) != 0:
                total_score += 100 * p * (k + 1) + c
                solved_problem += p

        # この時点で目標スコアを達成したなら、「中途半端に解く配点」
        # (解説に倣った呼び方)を考える必要はない
        if G <= total_score:
            ans = min(ans, solved_problem)
            continue

        # 「中途半端に解く配点」を決定
        for k, (p, c) in enumerate(reversed(Problems), 1):  # 高配点の順に見る
            if binary & (1 << (D-k)) != 0:
                continue  # 注目した配点はすでに全問正解した配点だった
            for _ in range(p):
                if G <= total_score:
                    break
                total_score += 100*(D-k+1)
                solved_problem += 1

        ans = min(ans, solved_problem)
    return ans

D, G = [int(i) for i in input().split()]
Problems = [[int(i) for i in input().split()] for j in range(D)]
print(c_all_green(D, G, Problems))

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

using namespace std;
using LL = long long;
using VI = vector<int>;
using PI = pair<int, int>;

struct Dice {
	Dice() { d = new int[6]; }
	~Dice() { delete[] d; }

	void get() {
		for (int i = 0; i < 6; i++) {
			cin >> d[i];
		}
	}
	void roll(char c) {
		int t = d[0];
		int tmp = d[1];
		switch (c) {
		case 'N':
			d[0] = d[1]; d[1] = d[5]; d[5] = d[4]; d[4] = t;
			break;
		case 'S':
			d[0] = d[4]; d[4] = d[5]; d[5] = d[1]; d[1] = t;
			break;
		case 'W':
			d[0] = d[2]; d[2] = d[5]; d[5] = d[3]; d[3] = t;
			break;
		case 'E':
			d[0] = d[3]; d[3] = d[5]; d[5] = d[2]; d[2] = t;
			break;
		case 'r':
			d[1] = d[2]; d[2] = d[4]; d[4] = d[3]; d[3] = tmp;
			break;
		default:
			break;
		}
	}
	int top() { return d[0]; }
	int right() { return d[2]; }
	int front() { return d[1]; }
	int left() { return d[3]; }
	void open(int a[]) { a = d; }
	Dice & operator=(Dice & obj) { this->d = obj.d; }
	bool operator==(Dice & obj) {
		for (int i = 0; i < 6; i++) {
			if (this->d[i] != obj.d[i]) { return false; }
		}
		return true;
	}
	int* d;
};

int main() {
	Dice d, d0;
	d.get(); d0.get();

	for (auto & e : "WWWNNNN") {
		for (int i = 0; i < 4; i++) {
			if (d == d0) { 
				cout << "Yes" << endl;
				return 0;
			}
			d.roll('r');
		}
		d.roll(e);
	}
	cout << "No" << endl;
	return 0;
}



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

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

fn main() {
    let n = read();
    let mut a: Vec<i32> = (0..n).map(|_| read()).collect();
    a.insert(n, 0);
    a.insert(0, 0);
    let sum = {
        let mut res = 0;
        for x in a[..].windows(2) {
            let (p, q) = (x[0], x[1]);
            res += (p - q).abs();
        }
        res
    };
    for x in a[..].windows(3) {
        let (p, q, r) = (x[0], x[1], x[2]);
        println!("{}", sum - (p - q).abs() - (q - r).abs() + (p - r).abs());
    }
}


Measured memory_bytes: 5244
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+1;
const int mod = 998244353;
struct event{
	int ind,val;
};
bool cmp(event a,event b){
	if(a.ind==b.ind) return(a.val>b.val);
	return(a.ind<b.ind);
}
vector<event> arr;
int mn[upperlimit];
int mx[upperlimit];
int main() {
//	freopen(".in","r",stdin);freopen(".out","w",stdout);
	event temp;
	int n,a,b,pos=0,neg=0;
	sd(n);
	for(int i = 1; i <= n; i++){
		sd(a);sd(b);
		temp.ind=a;temp.val=1;
		arr.pb(temp);
		temp.ind=b;temp.val=-1;
		arr.pb(temp);
	}
	sort(arr.begin(),arr.end(),cmp);
	for(int i = 0; i < arr.size(); i++){
		if(arr[i].val==1){
			pos++;mn[pos]=arr[i].ind;
		}
		else{
			neg++;mx[neg]=arr[i].ind;
		}
	}
	int x1,x2;
	x1=n>>1;x2=n-x1;
	if(n&1) pd(mx[x2]+1-mn[x2]);
	else pd(mx[x2]+mx[x2+1]+1-mn[x2+1]-mn[x2]);
	return 0;
}

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

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

    long long minv = 1e9;
    for(long long i = 0; i + 2< s.size(); i++){
        string t= s.substr(i, 3);
        //printf("t %s\n", t.c_str());
        long long a = stoll(t);
        minv = min(minv, abs(a-753));
    }
    cout << minv << endl;
    return 0;
}

Measured memory_bytes: 3644
import itertools
n,m,q = [int(x) for x in input().split()]
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
    a[i],b[i],c[i],d[i] = [int(x) for x in input().split()]

ans = 0

for A in itertools.combinations_with_replacement(range(1,m+1), n):
    tmp = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            tmp += d[i]
    ans = max(tmp,ans)
print(ans)


Measured memory_bytes: 9116
#include <iostream>
#include <cmath>
#include <vector>
#include <utility>

using namespace std;


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

    int Cn[12];
    int An[12][12];
 
    for(int i=0;i<N;++i){
        cin >>Cn[i]; 
        for(int j=0;j<M;++j){
            cin >> An[i][j];
        }
    }
    uint32_t mask;
    uint32_t tempsum;
    uint32_t result=10000000;
    uint32_t Xsum[12];
    uint32_t judge[12];
    for(mask=1;mask < (1<<N); ++mask){
//        cout<<mask;
        for(int j=0;j<M;++j){
            Xsum[j]=0;
            judge[j]=0;
        }
        tempsum=0;     
        for(int i=0;i<N;i++){
            if(mask & (1<<i)){
                tempsum+=Cn[i];
                for(int j=0;j<M;++j){
                    Xsum[j] += An[i][j];
                    if(Xsum[j]>=X){
                        judge[j] =1;
                    }
                }
            }
        }
        int temp=1;
        for(int j=0;j<M;++j){
            if(judge[j]==0){
                temp=0;
                break;
            }
        }
        if(temp==1){
            if(result > tempsum){
                result =tempsum;
            }
        }
    }   

    if(result ==10000000){
        cout<<-1<<endl;
    }
    else{
        cout<< result <<endl;
    }

}



Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long re =0;
		Map<String,Long>  map = new HashMap<String,Long> ();
		int N = sc.nextInt();
		for (int i=0;i<N;i++) {
			String s = sc.next();
			char[] c = s.toCharArray();
			Arrays.parallelSort(c);
			String temp = String.valueOf(c);
			if (map.containsKey(temp)==false) {
				map.put(temp, 1l);
			} else {
				Long in = map.get(temp);
				map.put(temp, in+1);
			}
		}
		Set<String> set = map.keySet();
		for (String s: set) {
			Long in = map.get(s);
			if (in>1) {
				re +=(in)*(in-1)/2;
			}
		}
		System.out.println(re);
	}
}

Measured memory_bytes: 68192
N,M = [ int(it) for it in input().split() ]
li = [ int(it) for it in input().split() ]

comall = [-1,2,5,5,4,5,6,3,7,6]
com = [ (i,comall[i]) for i in li ]
com.sort( key=lambda x:-x[0])

dp = [-1]*(N+1)
dp[0] = 0

for i in range(N+1):
  for j,c in com:
    if (c==-1):
      continue
    if ( i-c < 0 ):
      continue
    if ( dp[i-c] == -1 ):
      continue
    dp[i] = max( dp[i] , dp[i-c] + 1 )

match = N
keta = dp[N]
st = ""


for i in range( 10000 ):
  for j,c in com:
    if (match-c<0):
      continue
    if (keta-1==dp[match-c]):
      keta-=1
      match-=c
      st+=str(j)
      break
  if (match==0):
    break
print ( st )
    

Measured memory_bytes: 42092
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
int dp[100005][11];
int k;
int solve(int val ,int n)
{
    if(n == 0)
        return val;
    if(dp[val][n] != -1)
        return dp[val][n];
    else
        return dp[val][n] = min(solve(val*2, n-1), solve(val+k,n-1));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int z; cin>>z>>k;
    memset(dp,-1,sizeof dp);
    cout<<solve(1, z);

    return 0;
}


Measured memory_bytes: 4608
#include <stdio.h>

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void push(int);
void pop(void);
void dfs(int);
void dfs_pre(void);
int next(int);

int S[MAX],top;
int M[MAX+1][MAX+1],D[MAX+1],F[MAX+1],colr[MAX+1];
int n,count;
int nt[MAX+1];

int main(){
  int i,j,u,k,v;
  
  scanf("%d",&n);
  
  for(i=0;i<n+1;i++){
    for(j=0;j<n+1;j++){
      M[i][j]=0;
    }
  }
  
    for(i=1;i<=n;i++){
      scanf("%d %d",&u,&k);
      
      for(j=1;j<=k;j++){
        scanf(" %d",&v);
        
        M[u][v] = 1;
      }
    }

    dfs_pre();
    
    return 0;
}


void push(int x){

  top++;
  S[top] = x;
 
}

void pop(void){
  top--;
  }

 void dfs_pre(void){
   int u,i;

   for(i=0;i<n+1;i++){
     colr[i] = WHITE;
     nt[i] = 0;
   }
   count=0;
   
   for(u=1;u<=n;u++){
     if(colr[u] == WHITE)dfs(u);
   }

   for(i=1;i<=n;i++){
     printf("%d %d %d\n",i,D[i],F[i]);
   }
 }

void dfs(int r){
  int i,j,u;
  int v = 0;

  for(i=0;i<n+1;i++)nt[i] = 0;
  
  push(r);
  colr[r] = GRAY;
  D[r] = ++count;
  
  while(top > 0){
    u = S[top];
    v = next(u);
    
    if( v != 0 ){
      if(colr[v] == WHITE){
        colr[v] = GRAY;
        D[v] = ++count;
        push(v);
      }
    }
    
    else{
      pop();
      colr[u] = BLACK;
      F[u] = ++count;
    }
  }        
}
int next(int u){
  int v;

  for(v = nt[u]+1;v <= n;v++){
    nt[u] = v;
    if(M[u][v])return v;
  }
  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> b(n-1);
  for(int i = 0; i < n-1; i++) std::cin >> b[i];
  int res = 0;
  for(int i = 0; i < n-2;i++)
  {
    std::cerr << "sss " << b[i] << std::endl;
    res += std::min(b[i], b[i+1]);
  } 
  std::cerr << "res " << res << std::endl;
  res+= b[0];
  res+= b[n-2];
  std::cout << res << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;



ll calc(ll w, ll h) {
	ll ret = 1e18;
	for(int i = 1; i < h; i++) {
		ll h1 = i, h2 = h - i;
		vl v(3);
		v[0] = h1*w;
		v[1] = h2*(w/2);
		v[2] = h2*((w+1)/2);
		sort(all(v));
		ret = min(v[2]-v[0], ret);
	}
	return ret;
}

ll calc2(ll w, ll h) {

}

int main(){
	ll h, w;
	cin >> h >> w;
	if(h % 3 == 0 || w % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	cout << min({calc(h, w), calc(w, h), h, w}) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

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

    int h = 0, m = 0;
    while( !(S < 60) ) S -= 60, ++m;
    while( !(m < 60) ) m -= 60, ++h;

    printf("%d:%d:%d\n", h, m, S);

    return 0;
}

Measured memory_bytes: 592
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N;
	static int[][] X, Y;
	static int[] minX = new int[4];
	static int[] minY = new int[4];

	public static void main(String[] args) {
		N = sc.nextInt();
		Arrays.fill(minX, Integer.MAX_VALUE);
		Arrays.fill(minY, Integer.MAX_VALUE);
		X = new int[4][N];
		Y = new int[4][N];
		for (int i = 0; i < N; ++i) {
			int x = Integer.parseInt(sc.next());
			int y = Integer.parseInt(sc.next());
			X[0][i] = x + y;
			Y[0][i] = x - y;
			X[1][i] = X[0][i];
			Y[1][i] = -Y[0][i];
			X[2][i] = -X[0][i];
			Y[2][i] = Y[0][i];
			X[3][i] = -X[0][i];
			Y[3][i] = -Y[0][i];
			for (int j = 0; j < 4; ++j) {
				minX[j] = Math.min(minX[j], X[j][i]);
				minY[j] = Math.min(minY[j], Y[j][i]);
			}
		}
		int l = 0;
		int r = 1000000;
		while (r - l > 1) {
			int m = (l + r) / 2;
			if (ok(m)) {
				r = m;
			} else {
				l = m;
			}
		}
		System.out.println(r);
	}

	static boolean ok(int len) {
		for (int i = 0; i < 4; ++i) {
			int left = 1 << 25;
			int right = -(1 << 25);
			int bottom = 1 << 25;
			int top = -(1 << 25);
			for (int j = 0; j < N; ++j) {
				if (X[i][j] <= minX[i] + len && Y[i][j] <= minY[i] + len) continue;
				left = Math.min(left, X[i][j]);
				right = Math.max(right, X[i][j]);
				bottom = Math.min(bottom, Y[i][j]);
				top = Math.max(top, Y[i][j]);
			}
			if (right - left <= len && top - bottom <= len) return true;
		}
		return false;
	}

}

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

const double pi = 3.14159265359;

int main() {
  double a, b, h, m; cin >> a >> b >> h >> m;
  double sx, sy, lx, ly;
  double sa, la;

  la = 2 * pi * m / 60;
  sa = 2 * pi * (h * 60 + m) / 720;

  sx = a * cos(sa);
  sy = a * sin(sa);
  lx = b * cos(la);
  ly = b * sin(la);

  double d = sqrt((sx-lx)*(sx-lx) + (sy-ly)*(sy-ly));
  cout << fixed << setprecision(12) << d << endl;
}


Measured memory_bytes: 4100
s = list(input())
for i in range(2 ** (len(s) - 1)):
  st = str(s[0])
  num = int(s[0])
  for j in range(len(s) - 1):
    if (i >> j) & 1:
      st = st + "+" + str(s[j+1])
      num += int(s[j+1])
    else:
      st = st + "-" + str(s[j+1])
      num -= int(s[j+1])
  
  if num == 7:
    print(st + "=7")
    break



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


int main() {
	int N; cin >> N;
	vector<pair<double, int>> a(N); //first : gpa, second : id
	map<double,int> m;
	vector<int> points;

	for (int i = 0; i < N; i++) {
		double A; cin >> A;
		a[i] = make_pair(A,i);
		m[A]++;
		//cout << m[A] << endl;
	}

	sort(a.begin(), a.end());

	vector<int> num(N,0);
	for (int i = 1; i < N; i++) {
		if (a[i].first - a[i-1].first < 0.00001) {
			num[i] = num[i-1];
		}else {
			num[i] = num[i-1] + m[a[i-1].first];
		}
	}
	vector<pair<int,int>> ans(N);// first : id , second : point
	for (int i = 0; i < N; i++) {
		int p = (num[i] * 3) + m[a[i].first] - 1;
		ans[i] = make_pair(a[i].second, p);
	}

	sort(ans.begin(), ans.end());

	for (int i = 0; i < N; i++) {
		cout << ans[i].second << endl;
	}
	return 0;
}



Measured memory_bytes: 5572
#include <stdio.h>
#include <math.h>

int main(){
  int n,i,j,k=0;
  int A[10000];

  scanf("%d",&n);

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

    if(A[i] == 2){
      continue;
    } else if(A[i]%2 == 0){
      k++;
      continue;
    }
    for(j=3; j <= sqrt(A[i]); j += 2){
      if(A[i]%j == 0){
      k++;
      break;
      }
    }
  }
  printf("%d\n",n-k);

  return 0;
}



Measured memory_bytes: 2056
#include<stdio.h>
#include<stdlib.h>
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;} 
int main(void)
{
  int r;
  scanf("%d",&r);
  printf("%f",2*r*3.1415);
  
}


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

using namespace std;

void warshall_fl(int c[][10]){
  int tmp;
  for (int k = 0; k < 10; k++){
    for (int i = 0; i < 10; i++){
      //if(i == j) continue;
      for(int j = 0; j < 10; j++){
        tmp = c[i][k] + c[k][j];
        if(c[i][j] > tmp) c[i][j] = tmp;
      }
    }
  }
}

int main (void) {
  int h, w;
  int c[10][10];
  cin >> h >> w;
  cin.ignore();
  for (int i = 0; i < 10; i++){
    for (int j = 0; j < 10; j++){
      cin >> c[i][j];
    }
    cin.ignore();
  }
  warshall_fl(c);
  int tmp;
  unsigned long long sum = 0;
  int a[10] = {0};
  for (int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> tmp;
      if(tmp!=-1) {
        sum += c[tmp][1];
        a[tmp]++;
      }
    }
    cin.ignore();
  }

  cout << sum << endl;
/*
  for (int i = 0; i < 10; i++) cout << a[i] << "," << flush;
  cout << endl;
  for (int i = 0; i < 100; i++){
    cout << c[i] << "," << flush;
    if(i != 0 && i%10 == 9) cout << c[i] << endl;
  }
*/
  sum = 0;
  for(int i = 0; i < 10; i++){
    if(i == 1) continue;
    if(a[i] >= 0) sum += a[i] * c[i][1];
  }
  //cout << sum << endl;
  return 0;
}
      


Measured memory_bytes: 256
#include <iostream>

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    int Q,c,a,n;
    cin >> Q;
    
    for(int i=0;i<Q;i++){
        cin >> c >> a >> n;
        int lim = (c+a+n)/3,res = 0;
        if(lim>c)lim = c;
        int j = 0,k = 0,l = 0;
        for(;(j+k+l<=lim&&j*3+k*2+l<=c)&&(k+l<=a&&l<=n);j++){
            for(;(j+k+l<=lim&&j*3+k*2+l<=c)&&(k+l<=a&&l<=n);k++){
                for(;(j+k+l<=lim&&j*3+k*2+l<=c)&&(k+l<=a&&l<=n);l++){
                    if(j+k+l>res)res = j+k+l;
                }
                l = 0;
            }
            k = 0;
        }
        j = 0;
        cout << res << endl;
    }
        
    return 0;
}

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

int main() {
  int x;
  cin >> x;
  while(true){
    for(int i =1; i <=1000;i++){
      for(int j = 2; j <= 10; j++){
        if(pow(i,j) == x){
          cout << x << endl;
          return 0;
        }
      }
    }
    x--;
  }
 } 

Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  int x;
  int d = 0;
  for(int i = 0;i<N;i++){
    cin >> x;
	if(x<=K/2)
   	  d+=x;
    else
      d+=K-x;
  }
  cout << 2*d << endl;
}
      

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,K;
map<string,int>H;
void solve(){
	scanf("%d",&n);
	string s;
	long long ans=0;
	for(int i=1;i<=n;i++){
		cin>>s;
		sort(s.begin(),s.end());
		ans+=H[s];
		H[s]++;		
	}
	printf("%lld\n",ans);
}
int main (){
	solve();
	return 0;
}

Measured memory_bytes: 11136
// atcoder/abc131/F/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<pair<int, int>> v(n);
    cin >> v;


    const int N = 1e5 + 5;
    const int M = N * 2;
    static vector<int> g[M];
    fill(g, g + M, vector<int>());
    each (i, v) {
      int a = i.first;
      int b = i.second + N;
      g[a].push_back(b);
      g[b].push_back(a);
    }

    set<int> vis;
    vector<int> u;
    function<void(int, int)> rec = [&] (int curr, int prev) {
      vis.insert(curr);
      u.push_back(curr);
      each (next, g[curr]) {
        if (next == prev || vis.count(next)) continue;
        rec(next, curr);
      }
      return ;
    };

    lli sum = 0;
    for (int i = 0; i < M; ++i) {
      if (vis.count(i) == 0) {
        u.clear();
        rec(i, -1);
        lli a = 0;
        lli b = 0;
        each (j, u) {
          if (j < N) {
            a += g[j].size();
          } else {
            ++b;
          }
        }
        sum += (u.size() - b) * b - a;
      }
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 23544
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)

int_fast32_t nn, n, sqrtN;
int_fast64_t ans, d;
char c;
char wr[15];
char *w = wr;
main() {
    char c;
    while(1) {
        c = getwchar_unlocked();
        if(c != '\n')
            nn = nn * 10 + c - '0';
        else
            break;
    }
    const int_least32_t n = nn;
    const int_fast32_t sqrtN = sqrt(n);
    ans = -(int_fast64_t)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
    for(int i = 1; i <= sqrtN; ++i) {
        const int_fast32_t a = n / i;
        ans += ((int_fast64_t)i * (i + a) * (a + 1 - i));
    }
    while(ans) {
        *w = ans % 10 + '0';
        ans /= 10;
        w++;
    }
    while(1) {
        w--;
        putwchar_unlocked(*w);
        if(w == wr) break;
    }
}

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


int main(){
    ll N,ans=0;
    cin>>N;
    for(ll i=1;i<=1000000;i++){
        ll x=N-i;
        if(x%i!=0) continue;
        ll num=x/i;
        if(num<=i) continue;
        ans+=num;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<N; i++){ ;
int main() {
    int N,K,Y,X;
    cin>>N>>K>>Y>>X;
    if(N<K){
        cout<<Y*N<<endl;
    }
    else
    {
    cout<<K*Y+(N-K)*X<<endl;
    }
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

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

    int K, N;
    cin >> K >> N;

    vector<int> dis(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> dis[i];
    }

    sort(dis.begin(), dis.end());

    int maxm = -123;

    for (int i = 0; i < N - 1; ++i)
    {
        maxm = max(maxm, dis[i + 1] - dis[i]);
    }

    maxm = max(maxm, K - dis[N - 1] + dis[0]);

    cout << K - maxm << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  vl ANS;
  bool ok = false;
  cin >> N;
  vector<ll> A(N, 0);
  REP(i, N) cin >> A[i];
  RREP(i, N) {
    ok = false;
    RREP(j, i + 1) {
      if (A[j] == j + 1) {
        ANS.push_back(A[j]);
        A.erase(A.begin() + j);
        ok = true;
        break;
      }
    }
    if (!ok)
      break;
  }
  if (ok)
    RREP(i, N) cout << ANS[i] << endl;
  else
    cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
using ll = long long;
using P = pair<ll, ll>;

const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void fail() {
    cout << -1 << endl;
    exit(0);
}

ll digit_sum(ll num){
    if(num < 10) return num;
    return digit_sum(num/10) + num % 10;
}

int main(){
    string s;
    cin >> s;
    ll n = s.size();
    ll dp[n+1][2][10];
    for(ll i=0; i < n+1; i++){
        for(ll j=0; j < 2; j++){
            for(ll k=0; k < 10; k++){
                dp[i][j][k] = -1000000;
            }
        }
    }
    dp[0][1][0] = 0;
    ll pre_d = 0, d = 0;
    for(ll i=1; i < n+1; i++){
        pre_d = d;
        d = s[i-1] - '0';
        for(ll j=0; j < 2; j++){
            if(j == 0){
                for(ll k=0; k < 10; k++){
                    for(ll m=0; m < 2; m++){
                        if(m==0){
                            for(ll l=0; l < 10; l++){
                                if(k >= d) break;
                                chmax(dp[i][j][k], dp[i-1][1][l] + k);
                            }
                        }else{
                            for(ll l=0; l < 10; l++){
                                chmax(dp[i][j][k], dp[i-1][0][l] + k);
                            }
                        }
                    }
                }
            }else{
                chmax(dp[i][1][d], dp[i-1][1][pre_d] + d);
            }
        }
    }
    ll ans = 0;
    for(ll i=0; i < 2; i++){
        for(ll j=0; j < 10; j++){
            chmax(ans, dp[n][i][j]);
            // cout << ans << endl;
        }
    }
    // for(ll k=0; k < n+1; k++){
    //     for(ll i=0; i < 2; i++){
    //         for(ll j=0; j < 10; j++){
    //             cout << dp[k][i][j] << " ";
    //         }
    //         cout << endl;
    //     }
    // }
    cout << ans << endl;
}

Measured memory_bytes: 256