akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N, M;
	cin >> N >> M;
	vector<bool> A(N, false);
	vector<bool> B(N, false);
	bool ans = false;
	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		if (a == 1)
			A[b-1] = true;
		if (b == N)
			B[a-1] = true;
	}
	for (int i = 0; i < N; i++)
	{
		if (A[i] && B[i])
			ans = true;
	}
	cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}



Measured memory_bytes: 256
s = input()
ans = 0
mod = [0]*2019
t = s[len(s)-1]
n = 1
for i in range(len(s)-1,-1,-1):
#     mod.append(int(s[i:])%2019)
    mod[int(t)%2019] += 1
#     t = int(t) + (10**(len(s)-i-1))*int(s[i])
    t = int(t) + n*10*int(s[i-1])
    n = n*10%2019
for i in range(0,2019):
    ans += mod[i]*(mod[i]-1)/2
ans += mod[0]
print(int(ans))

Measured memory_bytes: 9140
n, k, q = map(int, input().split())
a = []

for i in range(q):
  a.append(int(input()))

points = [k for i in range(n)]

for i in range(q):
    points[a[i]-1] += 1
  
for i in range(n):
    points[i] -= q

for i in range(n):
  if points[i] > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 56536
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

int f(int n){
    int sum = 0;
    while(n>0){
        sum += n%10;
        n/=10;
    }
    return sum;
}

void Main(){
    int A, B;
    cin >> A >> B;
    int X = B*10;
    REP(i, 10){
        if((int)(X*0.08) == A){
            cout << X << el;return;
        }
        X++;
    }
    cout << -1 << el;
}



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

bool cmp(int a, int b){
    return a>b;
}

int main(){
    int a[3],total=0,tmp;
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3,cmp);
    tmp = (a[1]-a[2]);
    total += tmp/2 + tmp%2;
    a[0]+=tmp%2;
    total+=a[0]-a[1];
    cout<<total<<endl;

return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
#define Q 50000
main(){

  int s,t,c=0,i,j,m,r,l;
  int a[N],b[Q],d[N];
  scanf("%d",&s);
  for(i = 0; i < s; i++){
    scanf("%d",&a[i]);
  }
    scanf("%d",&t); 
   for(i = 0; i < t; i++){
      scanf("%d",&b[i]);   
      d[i] = b[i];
      r = s;
      l = 0;
      while(l < r){
	m = (r + l) / 2;
	if(b[i] == a[m])
	  {
	    c++;
	    break;
	  }
	else if(b[i] > a[m]) l = m + 1;
	else if(b[i] < a[m]) r = m;
      }
   }
printf("%d\n",c);
 return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
 
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << ((a + b) * c / 2);
  return 0;
}

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

using namespace std;

int main(){
  ll N,a=0;
  cin>>N;
  vector<string> S(N);
  set<string> x;
  vector<ll> ans;
  vector<pair<ll,string>> p(N);
  for(ll i=0;i<N;i++) cin>>S.at(i);
  sort(S.begin(),S.end());

  for(ll i=0;i<N;i++){
    if(x.count(S[i])){
      p[a].first++;
    }
    else{
      if(i!=0) a++;
      x.insert(S[i]);
      p.at(a)=make_pair(0,S[i]);
    }
  }
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  ll b=p[0].first;
  reverse(p.begin(),p.end());
  for(ll i=0;i<N;i++){
    if(p[i].first==b) cout<<p[i].second<<endl;
  }
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define MAX 200
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 9999

int n, m[MAX][MAX], d[MAX], c[MAX];

void dijkstra_init(){
	for(int i=0; i<n; i++){
		d[i]=INF;
		c[i]=WHITE;
	}
	return;
}

void dijkstra(int s){
	d[s]=0;
	c[s]=GRAY;
	while(1){
		int minv=INF, u=-1;
		for(int i=0; i<n; i++){
			if(minv>d[i] && c[i]!=BLACK){
				u=i;
				minv=d[i];
			}
		}
		if(u==-1) break;
		c[u]=BLACK;
		for(int v=0; v<n; v++){
			if(c[v]!=BLACK && m[u][v]!=INF){
				if(d[v]>d[u]+m[u][v]){
					d[v]=d[u]+m[u][v];
					c[v]=GRAY;
				}
			}
		}
	}
	return;
}

int main(){
	cin >> n;
	for(int i=0; i<n; i++){
		string s;
		cin >> s;
		for(int j=0; j<n; j++){
			if(s[j]=='1') m[i][j]=1;
			else m[i][j]=INF;
		}
	}

	int l[n][n];
	for(int i=0; i<n; i++){
		dijkstra_init();
		dijkstra(i);
		for(int j=0; j<n; j++){
			l[i][j]=d[j];
		}
	}

	//奇数長ループ検出
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			for(int k=j+1; k<n; k++){
				if((l[i][j]+l[j][k]+l[k][i])%2==1){
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}

	int dist=0;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(l[i][j]==INF) continue;
			dist=max(dist, l[i][j]);
		}
	}
	dist++;
	cout << dist << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <iterator>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MAX = 100001;
int n, k;
ll T[100001];

int check(ll P)
{
    int i = 0;
    REP(j, k)
    {
        ll s = 0;
        while (s + T[i] <= P)
        {
            s += T[i];
            i++;
            if (i == n)
                return n;
        }
    }
    return i;
}

int solve()
{
    ll left = 0;
    ll right = 100000 * 10000;
    ll mid;
    while (right - left > 1)
    {
        mid = (left + right) / 2LL;
        int v = check(mid);
        if (v >= n)
            right = mid;
        else
            left = mid;
    }
    return right;
}

int main()
{
    cin >> n >> k;
    REP(i, n)
    {
        cin >> T[i];
    }
    ll ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 3884
#include <bits/stdc++.h>
#define int long long
#define FLASH                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

signed main()
{
    int h, w;
    cin >> h >> w;
    vector<string> v(h + 1);
    v[0] = string(w + 1, '#');
    rep(i, 1, h + 1)
    {
        string s;
        cin >> s;
        v[i] = "#" + s;
    }
    vector<vector<pair<int,int>>> dp(h+2, vector<pair<int, int>>(w+2, {0, 0}));
    rep(i, 0, h+1)
        rep(j, 0, w+1)
        {
            if (v[i][j] == '.')
            {
                dp[i][j].first = dp[i-1][j].first + 1;
                dp[i][j].second = dp[i][j-1].second + 1;;
            }
        }

    rep(i, h+1, 0)
        rep(j, 0, w+1)
            if (dp[i][j].first != 0 && dp[i+1][j].first != 0)
                dp[i][j].first = dp[i+1][j].first;

    rep(i, 0, h+1)
        rep(j, w+1, 0)
            if (dp[i][j].second != 0 && dp[i][j+1].second != 0)
                dp[i][j].second = dp[i][j+1].second;
    
    int res = 0;
    vector<int> maxLine(h+1);
    rep(i, 0, h+1)
        rep(j, w+1, 0)
            res = max(res, dp[i][j].first + dp[i][j].second);
    cout << res - 1;
    return 0;
}
// 0 0 0 0 0 0 0 0 0
// 0 1 1 0 1 1 1 0 1
// 0 2 2 1 2 0 2 1 2
// 0 0 0 2 3 1 3 2 3
// 0 1 1 0 0 0 4 3 0
// 0 2 2 1 0 1 5 0 1
// 0 0 0 2 1 2 6 0 2
// 0 0 1 3 2 0 7 1 3
// 0 0 0 0 3 0 8 2 0

// 0 0 0 0 0 0 0 0 0
// 0 2 2 0 3 1 8 0 3
// 0 2 2 2 3 0 8 3 3
// 0 0 0 2 3 1 8 3 3
// 0 2 2 0 0 0 8 3 0
// 0 2 2 3 0 2 8 0 3
// 0 0 0 3 3 2 8 0 3
// 0 0 1 3 3 0 8 2 3
// 0 0 0 0 3 0 8 2 0

Measured memory_bytes: 70056
# coding: utf-8
# Your code here!
N=int(input())

H=list(map(int,input().split()))

H.reverse()
#print(H)

for i in range(N-1):
    if H[i]<H[i+1]:
        H[i+1]-=1
        
#print(H)
        
if all(H[i]>=H[i+1] for i in range(N-1)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }
constexpr int MOD = 1'000'000'007;
int N;
int mat[22][22];
int dp[22][1 << 21 | 1];

int slv(int idx, int bit)
{
  if (idx >= N) {
    return __builtin_popcount(bit) == N ? 1 : 0;
  }
  int &ret = dp[idx][bit];
  if(~ret) { return ret; }

  ret = 0;
  for(int i = 0; i < N; ++i) {
    if(mat[idx][i] && !((bit >> i) & 1)) {
      ret = (ret + slv(idx+1, (bit | (1 << i)))) % MOD;
    }
  }

  return ret;
}

signed main()
{
  cin >> N;
  for (int i = 0;i < N; ++i) {
    for(int j=0; j<N; ++j) {
      cin >> mat[i][j];
    }
  }

  memset(dp, -1, sizeof(dp));
  cout << slv(0, 0) << endl;
  return 0;
}



Measured memory_bytes: 180608
#include<iostream>
#include<string>
#include<cctype>

using namespace std;

int main( )
{
	string w, p;
	int i;
	
	cin>>w;
	
	int cnt = 0;
	while( cin>>p ) {
		if( "END_OF_TEXT" == p ) { break; }
		
		i = 0;
		while( i<p.length() ) { 
			p[i] = tolower( p[i] );
			i++;
		}
		if( p == w ) {
			cnt++;
		}
	}
	
	cout<<cnt<<endl;
	
	return 0;
}

Measured memory_bytes: 1192
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;


int main(){

int N;
cin>>N;
ll h[N+1];
rep3(i,N){
    cin>>h[i];
}
ll dp[N+1];
dp[1]=0;
dp[2]=abs(h[2]-h[1]);
rep4(i,3,N){
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
}
cout<<dp[N]<<endl;


return 0;
}

Measured memory_bytes: 5180
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>

using namespace std;
typedef long long int ll;

int n,a[1000],r=0;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n*2;i++)scanf("%d",&a[i]);
    sort(a,a+n*2,greater<int>());
    for(int i=0;i<n;i++){
        r+=a[i*2+1];
    }
    printf("%d\n",r);
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;
int f(ll x) {
    int t=0;
    while(x%2==0) {
        x/=2;t++;
    }
    return t;
}
int main() {
    cs
    int n,m;cin>>n>>m;
    vector<ll> v(n);
    for(auto &i:v) cin>>i;
    ll t=f(v[0]);
    for(auto i:v) if(f(i)!=t) bye(0)
    t=1;
    for(auto i:v) {
        t*=(i/2)/__gcd(t,i/2);
        if(t>m) bye(0)
    }
    cout<<((m/t)+1)/2;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define all_acc(x) (x).begin(),(x).end(),0LL
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

void output(vector<int> s){
    int n=s.size();
    for(int i=0;i<n;i++){
        //if(i!=0) cout<<" ";
        cout<<s[i]<<endl;
    }
    //cout<<endl;
}


int D,score;
vector<int> c(27);
vector<int> last_day(27);
vector<vector<int>> s(D,vector<int>(27));

int unpresure(int d,int i){
    return c[i]*(d-last_day[i]);
}

void day(int d,int i){
    score+=s[d][i];
    last_day[i]=d;
    for(int j=1;j<=26;j++){
        score-=unpresure(d,j);
    }
}

signed main(){ 
   cin>>D; score=0;
   last_day.assign(27,0);
   s.assign(D+1,vector<int>(27));


   for(int i=1;i<=26;i++) cin>>c[i];

   for(int i=1;i<=D;i++){
       for(int j=1;j<=26;j++){
           cin>>s[i][j];
       }
   }

   vector<int> t;

   int ma=distance(c.begin(),max_element(c.begin()+1,c.end()));
   for(int i=0;i<D;i++){
       t.push_back(i%26 + 1);
   }

   output(t);

}  

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

typedef long long ll;
typedef long double ld;
#define size(a) int((a).size())
#define present(c, x) (c.find(x) != c.end()) 
#define printArray(arr) for (int i = 0; i<size(arr); i++) cout << arr[i] << '\n';cout << '\n'
#define printVerdict(verdict) cout << (verdict ? "Yes": "No") << '\n'
#define printDecimal(d) printf("%.9f\n", d)
#define inrange(val, start, end) (val >= start && val <= end)

const int inf = 0x3f3f3f3f;
const int mod = 998244353;

template <class T1, class T2, class T3> 
void printTuple(tuple<T1, T2, T3> t) {cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n';}
template <class T1, class T2>
void printPair(pair<T1, T2> p) {cout << p.first << " " << p.second << '\n';}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	int total = 0;
	for (int i = 0; i<size(s); i++) total += s[i]-'0';
	printVerdict(total%9==0);
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> list(4);
  for (int i=0; i<3; i++) {
    int t;
    cin >> t;
    list.at(i) = t;
  }
  sort(list.begin(),list.end());
  int a=0;
  for (int i=1; i<=2; i++) {
    a += list.at(i+1)-list.at(i);
  }
  cout << a << endl;
}

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

class UnionFind {
private:
	vector<ll> par;
public:
	UnionFind(int N) {par = vector<int>(N, -1);}
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};

int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}
 
ll UnionFind::size(int x) {
	return -par[find(x)];
}
 
void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);
 	if (x == y) return;
	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}
 
bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}

int MAX = 110000;

bool solve() {
	int n;cin >> n;
	UnionFind uf(MAX*2);
	REP (i,n) {
		int x,y; cin >> x >> y;
		uf.unite(x,y+MAX);
	}
	map<int,int> mx,my;
	REP (i,MAX) mx[uf.find(i)]++;
	FOR (i,MAX,2*MAX) my[uf.find(i)]++;
	int ans = 0;
	REP (i, 2*MAX) ans += mx[i] * my[i];
	ans -= n;
	cout << ans << endl;
}

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

Measured memory_bytes: 29440
# coding: utf-8
# Your code here!
x,y=map(int,input().split())
if abs(x)==abs(y):
    print(1)
elif x<0 and y<0:
    if abs(x)<abs(y):
        print(abs(abs(x)-abs(y))+2)
    else:
        print(abs(x)-abs(y))
elif x>=0 and y>=0:
    if x>y:
        if y==0:
            print(x-y+1)
        else:
            print(x-y+2)
    else:
        print(y-x)
elif x>=0 and y<0:
    if x>=abs(y):
        print(x-abs(y)+1)
    else:
        print(abs(y)-x+1)
elif x<0 and y>=0:
    if abs(x)>=y:
        if y==0:
            print(abs(x))
        else:
            print(abs(x)-y+1)
    else:
        print(y-abs(x)+1)

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

int main() {
    string s;
    cin >> s;
    rep(i, s.length()) {
        cout << "x";
    } 
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <stack>
#include <iomanip>
#include <cmath>


using namespace std;


typedef long long ll;
typedef long double ld;


const ll MOD = 1000000007ll;


ll modSum(ll a, ll b) {
  return ((a % MOD) + (b % MOD)) % MOD;
}


ll modProd(ll a, ll b) {
  return ((a % MOD) * (b % MOD)) % MOD;
}


ll getPowMod(ll x, ll e) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    ll tmp = getPowMod(x, e/2);
    return modProd(tmp, tmp);
  } else {
    ll tmp = getPowMod(x, e-1);
    return modProd(tmp, x);
  }
}


ll getPow(ll x, ll e) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    ll tmp = getPow(x, e/2);
    return tmp * tmp;
  } else {
    ll tmp = getPow(x, e-1);
    return tmp * x;
  }
}


bool isEven(ll x) {
  ll tmp = ((x % 2) + 2) % 2;
  return tmp == 0;
}


ll getSumOfDigitsInBase(ll n, ll b) {
  ll ret = 0;
  while (n > 0) {
    ret += n % b;
    n /= b;
  }
  return ret;
}


vector<int> getKMP(string &s) {
  int len = (int)s.size();
  vector<int> ret (len, 0);
  for (int i = 1 ; i < len ; i++) {
    int at = ret[i-1];
    while (at > 0 && s[i] != s[at]) {
      at = ret[at-1];
    }
    if (s[i] == s[at]) {
      at++;
    }
    ret[i] = at;
  }
  return ret;
}


string getSubstring(string &s, int from, int to) {
  int l = to-from+1;
  if (l <= 0) {
    return "";
  }
  return s.substr(from, l);
}

















const int MAXN = 100002;


int H, W, N;
int a[MAXN], b[MAXN];
ll ans[10];
map< pair<int, int>, int> cells;


bool isInRange(int r, int c) {
  return (r >= 1) && (c >= 1) && (r <= H) && (c <= W);
}


void populate_cells(int r, int c) {
  for (int i = r-2 ; i <= r ; i++) {
    for (int j = c-2 ; j <= c ; j++) {
      if (isInRange(i, j) && isInRange(i+2, j+2)) {
        cells[{i, j}]++;
      }
    }
  }
}


void input() {
  cin >> H >> W >> N;
  for (int i = 1 ; i <= N ; i++) {
    cin >> a[i] >> b[i];
  }
}


void preprocess() {
}


void solve() {
  for (int i = 1 ; i <= N ; i++) {
    populate_cells(a[i], b[i]);
  }
  for (auto p : cells) {
    ans[p.second]++;
  }
  ans[0] = 1ll * (H-2) * (W-2);
  for (int i = 1 ; i <= 9 ; i++) {
    ans[0] -= ans[i];
  }
  for (int i = 0 ; i <= 9 ; i++) {
    cout << ans[i] << "\n";
  }
}


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

  int T;
//  cin >> T;
  T = 1;

  for (int i = 0 ; i < T ; i++) {
    input();
    preprocess();
    solve();
  }

  return 0;
}

Measured memory_bytes: 57344
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
b4 = 100000000
tmp = 0
d = {}
for i in b:
    if(b4!=i):
        d[b4] = tmp
        b4 = i
        tmp = 0
    tmp+=1
d[b4] = tmp
ans = 0

alls = 0
for i in d:
    t = d[i]
    alls += int(t*(t-1)/2)

for i in a:
    t = d[i]
    print(alls - (int(t*(t-1)/2) - int((t-1)*(t-2)/2)))


Measured memory_bytes: 88652
#include <iostream>
using namespace std;
int main()
{
	int a[205],i,n,s=0;
	cin>>n;
	for( i=1;i<=n;i++){
		cin>>a[i];
	}
	while(true){
		for(i=1;i<=n;i++){
			if(a[i]%2!=0){
				cout<<s<<endl;
				return 0;
			}else{
				a[i]/=2;
			}	
		} 
		s++;
	}	
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;ll k;
    cin>>n>>k;
    vin a(n);
    rep(i,n)cin>>a[i];
    vin arrive(n,0);
    arrive[0]=1;
    int prev=1;
    int next;
    int i=1;
    int circle;
    int tmp;
    while(1){
        i++;
        next=a[prev-1];
        if(arrive[next-1]!=0){
            circle=i-arrive[next-1];
            tmp=arrive[next-1]-1;
            break;
        }
        else arrive[next-1]=i;
        prev=next;
    }
    if(k<=(ll)tmp){
        rep(i,n){
            if(arrive[i]==k+1){
                cout<<i+1<<endl;
                return 0;
            }
        }
    }
    ll ans=(k-(ll)tmp)%circle;
    rep(i,n){
        if(arrive[i]==tmp+1+ans){
            cout<<i+1<<endl;
            return 0;
        }
    }
}

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

int main() 
{
	string s;
	cin>>s;
	int n=s.size(),sum=0,ma=0;
	for(int i=0;i<n;i++) 
	{
		if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C')
			sum++;
		else 
		{
			if(sum>ma) 
				ma=sum;
			sum=0;
		}
	}
	if(sum>ma) 
		ma=sum;
	cout<<ma<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define dup(x, y) (((x) + (y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
typedef vector<vector<int>> Graph;
template <class T> inline void chmax(T &a, T b) {
    if(a < b) {
        a = b;
    }
}
template <class T> inline void chmin(T &a, T b) {
    if(a > b) {
        a = b;
    }
}
template <class T> inline T gcd(T x, T y) {
    if(y == 0) {
        return x;
    } else if(x == 0) {
        return y;
    }
    return gcd(y, x % y);
}
template <class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template <class T> inline vector<T> convert_to_binary_number(T x) {
    vector<T> binary_num;
    while(x != 1) {
        binary_num.push_back(x % 2);
        x /= 2;
    }
    binary_num.push_back(1);
    return binary_num;
}
template <class T> inline void print_vector(vector<T> vec) {
    for(int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    cout << endl;
}
vector<LL> make_divisors(LL n) {
    vector<LL> divisors;
    for(int i = 1; i <= sqrt(n); i++) {
        if(n % i == 0) {
            divisors.push_back(i);
            if(i != n / i) {
                divisors.push_back(n / i);
            }
        }
    }
    return divisors;
}
const LL MOD = 1e9 + 7;
const int INF = 1 << 30;
const LL LLINF = 1LL << 60;
using namespace std;

int main(void) {
    int N;
    string S;
    cin >> N >> S;

    if(S.size()%2 == 1){
        cout << "No" << endl;
        return 0;
    }

    string s1 = S.substr(0, S.size() / 2);
    string s2 = S.substr(S.size() / 2, S.size() / 2);
    
    if(s1 == s2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var hash = new Dictionary<char, long>() {
            { 'M', 0 },
            { 'A', 0 },
            { 'R', 0 },
            { 'C', 0 },
            { 'H', 0 },
        };

        var ss = new List<string>();
        
        for(int i=0; i<n; i++) {
            var s = input.ReadLine();
            if (hash.ContainsKey(s[0])) {
                hash[s[0]]++;
            }
        }

        Func<char, char, char, long> f = (i1, i2, i3) => {
            return hash[i1] * hash[i2] * hash[i3];
        };

        long x = 0;
        x += f('M', 'A', 'R');
        x += f('M', 'A', 'C');
        x += f('M', 'A', 'H');
        x += f('M', 'R', 'C');
        x += f('M', 'R', 'H');
        x += f('M', 'C', 'H');
        x += f('A', 'R', 'C');
        x += f('A', 'R', 'H');
        x += f('A', 'C', 'H');
        x += f('R', 'C', 'H');

        return x;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 15200
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    printf("%d\n", n - k + 1);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define ld                 long double
#define ff                 first
#define ss                 second
#define P                 pair<int,int>
#define pb                 push_back
#define mod             1000000007
#define inf             1e18
#define endl            '\n'
const int N = 105;//change it when needed
const int V = 100005;
int a[N], b[N];
int dp[V];
int n, w, v;
int go() {
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = v; j >= 0; j--) {

            if (j >= b[i])
                dp[j] = min(dp[j], a[i] + dp[j - b[i]]);
            if (dp[j] <= w) {
                ans = max(ans, j);
            }
        }
    }

    return ans;
}
void solve() {
    cin >> n >> w;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        v += b[i];
    }
    dp[0] = 0;
    for (int i = 1; i <= v; i++)
        dp[i] = w + 1;
    cout << go();
}

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t; cin >> t; while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 1152
N,M=map(int,input().split())
A=list(map(int,input().split()))
d={2:0,3:0,4:0,5:0,6:0,7:0}
for i in A:
    if i==1:
        d[2]=1
    elif i==7:
        d[3]=7
    elif i==8:
        d[7]=8
    elif i==4:
        d[4]=4
    elif i==6 or i==9:
        if d[6]<i:
            d[6]=i
    else:
        if d[5]<i:
            d[5]=i
l=[]
for i in d.keys():
    if d[i]:
        l.append(i)
l.sort()
a=[]
m=0
if len(l)>=4:
    for i in range(4):
        for j in range(4):
            for k in range(4):
                t=N-i*l[1]-j*l[2]-k*l[3]
                if t%l[0] or t<0:
                    continue
                ke=i+j+k+t//l[0]
                if ke<m:
                    continue
                else:
                    s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[3]]]*k+[d[l[0]]]*(t//l[0])
                    s.sort(reverse=1)
                    if ke==m:
                        a.append(s)
                    else:
                        a=[s]
                        m=ke
    print(*max(a),sep="")
elif len(l)==3:
    for i in range(5):
        for j in range(5):
            t=(N-i*l[1]-j*l[2])
            if t%l[0] or t<0:
                continue
            ke=i+j+t//l[0]
            if ke<m:
                continue
            else:
                s=[d[l[1]]]*i+[d[l[2]]]*j+[d[l[0]]]*(t//l[0])
                s.sort(reverse=1)
                if ke==m:
                    a.append(s)
                else:
                    a=[s]
                    m=ke
    print(*max(a),sep="")
elif len(l)==2:
    for i in range(6):
        if (N-l[1]*i)%l[0]==0:
            a=[d[l[1]]]*i+[d[l[0]]]*((N-i*l[1])//l[0])
            a.sort(reverse=1)
            print(*a,sep="")
            break
else:
    a=[d[l[0]]]*(N//l[0])
    print(*a,sep="")

Measured memory_bytes: 71624
L = input()
A = [input() for _ in range(L)]

dp = [[float("inf")] * 5 for _ in range(L)]
dp[0][0] = A[0]
dp[0][1] = A[0] % 2 if A[0] > 0 else 2
dp[0][2] = 1 - A[0] % 2
dp[0][3] = A[0] % 2 if A[0] > 0 else 2
dp[0][4] = A[0]

for i in range(L - 1):
    dp[i + 1][0] = dp[i][0] + A[i + 1]
    dp[i + 1][1] = min(dp[i][:2]) + A[i + 1] % 2 if A[i + 1] > 0 else min(dp[i][:2]) + 2
    dp[i + 1][2] = min(dp[i][:3]) + 1 - A[i + 1] % 2
    dp[i + 1][3] = min(dp[i][:4]) + A[i + 1] % 2 if A[i + 1] > 0 else min(dp[i][:4]) + 2
    dp[i + 1][4] = min(dp[i][:5]) + A[i + 1]
print min(dp[-1])

Measured memory_bytes: 69224
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(NULL);cin.tie(0);cout.tie(0);
#define make_pair mp
#define pb push_back
#define ALL(s) s.begin(), s.end()
using namespace std;
typedef long long ll;
const int maxn = 1<<21;
const int mod = 1e9+7;
const int INF = 1e9+5;
void max_self(ll &a, ll b){
	a = max(a,b);
}
int main()
{
	int n, W;
	cin >> n >> W;
	vector<ll> dp(W+1);
	for(int item=0;item<n;item++)
	{
		ll weight, value;
		cin >> weight >> value;
		for(int weight_already=W-weight;weight_already>=0;weight_already--){
			max_self(dp[weight_already+weight], dp[weight_already]+value);
		}
	}
	ll ans = 0;
	for(int i=0;i<=W;i++)max_self(ans,dp[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
int n;cin>>n;
int ans=0;
ans=(n+1)/2;
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

/* --------------------------------------- */

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> a((1 << n));
	REP(i,(1 << n)) cin >> a[i];
	while((int)a.size() != 1) {
		vector<ll> new_a;
		REP(i, a.size() / 2) {
			if(a[2 * i] == a[2 * i + 1]) {
				new_a.pb(a[2 * i]);
			}
			else if(a[2 * i] > a[2 * i + 1]) {
				new_a.pb(a[2 * i] - a[2 * i + 1]);
			} else {
				new_a.pb(a[2 * i + 1] - a[2 * i]);
			}
		}
		a = new_a;
	}
	cout << a[0] << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 3448
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;

long long int N, M, K, W, H, L, R;

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

	cin >> N;
	vector<list<pair<int, int>>>edge(N+1);
	for (int i = 0; i < N - 1; i++) {
		cin >> L >> R >> K;
		edge[L].push_back({ R,K });
		edge[R].push_back({ L,K });
	}
	vector<long long int>dis(N + 1, LLONG_MAX);
	cin >> M >> K;
	dis[K] = 0;
	queue<int>Q;
	Q.push(K);
	while (!Q.empty()) {
		int cn = Q.front();
		long long int c = dis[cn];
		for (auto i : edge[cn]) {
			if (dis[i.first]== LLONG_MAX) {
				dis[i.first] = c + i.second;
				Q.push(i.first);
			}
		}
		Q.pop();
	}
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		cout << dis[L] + dis[R] << endl;
	}
	return 0;
}


Measured memory_bytes: 10368
Program VACATION;
uses math;
var F:array[1..1000005,1..3] of longint;
    n,i,j :longint;
    maxx:int64;
    fi:text;
//-------------------------------
begin
//assign(fi,'VACATION.inp');reset(fi);
readln(n);
for i:=1 to n do begin
                 for j:=1 to 3 do begin
                                  Read(F[i,j]);
                                  end;
                 end;
for i:=n-1 downto 1 do begin
                       F[i,1]:=F[i,1]+max(F[i+1,2],F[i+1,3]);
                       F[i,2]:=F[i,2]+max(F[i+1,1],F[i+1,3]);
                       F[i,3]:=F[i,3]+max(F[i+1,2],F[i+1,1]);
                       end;
for i:=1 to 3 do begin
                 maxx:=max(maxx,F[1,i]);
                 end;
Writeln(maxx);
//readln;
end.


Measured memory_bytes: 1408
k, s = map(int, input().split())

ans = 0
for x in range(k+1):
    if 0 <= s - x <= k:
        ans += s-x+1
    elif 0 <= s-x-k <= k:
        ans += k - s + x + k + 1
    # print(x, ans)
print(ans)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a,x,b) (a<=x && x<=b)
#define WS std::cout<<" ";
#define NL std::cout<<"\n"
#define OUT(dist) std::cout<<(dist);
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;



int main(){
    INIT;
    int N, A, B;
    cin >> N >> A >> B;
    if(N*A > B) cout << B;
    else cout << N*A;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


/*
int N;
Graph G;

int main() {
  cin >>N;
  rep(i, N-1){
    int a,b; cin >>a >>b; a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
}
*/

int main() {
  string s; cin >>s;
  int n = s.size();
  int res = 0;
  rep(i, n) res += s[i] - '0';
  cout <<res <<endl;
}

Measured memory_bytes: 384
from itertools import product


def solve(string):
    d, g, *pc = map(int, string.split())
    g //= 100
    p = [_p for _p in pc[::2]]
    c = [_c // 100 for _c in pc[1::2]]
    ans = 1000
    for f in product([True, False], repeat=d):
        sums = sum([(i + 1) * _p + _c for i, (_f, _p, _c) in enumerate(zip(f, p, c)) if _f])
        counts = sum([_p for _f, _p in zip(f, p) if _f])
        if g <= sums:
            ans = min(ans, counts)
            continue
        indices = [i + 1 for i, _f in enumerate(f) if not _f]
        for i in range(1, p[indices[-1]-1]):
            if sums + indices[-1] * i >= g:
                ans = min(ans, counts + i)
                break
    return str(ans)


if __name__ == '__main__':
    n, g = map(int, input().split())
    print(solve('{} {}\n'.format(n, g) + '\n'.join([input() for _ in range(n)])))


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

int main() {
  int n, max_val;;
  cin >> n;
  string first;
  string second;
  for (int k = 0; k < n; k++) {
    cin >> first;
    cin >> second;
    int result[first.size()+1][second.size()+1];
    max_val = 0;
    for (int i = 0; i <= first.size(); i++) result[i][0] = 0;
    for (int i = 0; i <= second.size(); i++) result[0][i] = 0;
    for (int i = 1; i <= first.size(); i++) {
      for (int j = 1; j <= second.size(); j++) {
        int col = first.size();
        if (first[i-1] == second[j-1]) {
          result[i][j] = result[i-1][j-1] + 1;
        } else {
          result[i][j] = max(result[i-1][j],
                             result[i][j-1]);
        }
        max_val = max(result[i][j], max_val);
      }
    }
    cout << max_val << endl;
  }
  return 0;
}



Measured memory_bytes: 7080
n,T=map(int,input().split())

c=[]
t=[]

for i in range(n):
    a,b=map(int,input().split())
    c.append(a)
    t.append(b)

ans=1000000   
for i in range(n):
    if t[i]<=T:
        ans=min(ans,c[i])
        
if ans==1000000:
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3064
A="".join(["11000000",
           "11"])

B="".join(["10000000",
           "10000000",
           "10000000",
           "1"])

C="".join(["1111"])

D="".join(["01000000",
           "11000000",
           "1"])

E="".join(["11000000",
           "011"])

F="".join(["10000000",
           "11000000",
           "01"])

G="".join(["01100000",
           "11"])

teto=[A,B,C,D,E,F,G]

while True:
    try:
        a="".join([raw_input() for i in xrange(8)])
        for i in range(len(teto)):
            if a.find(teto[i])>=0:
                print chr(i+ord("A"))
        raw_input()
    except:
        break

Measured memory_bytes: 23000
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=16;
int n;
int a[N+1][N+1];
int sum[1<<N];
int dp[1<<N];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>a[i][j];
	for(int i=0;i<1<<n;i++)
		for(int j=1;j<=n;j++)for(int k=j+1;k<=n;k++)
			if(i&1<<j-1&&i&1<<k-1)sum[i]+=a[j][k];
	for(int i=0;i<1<<n;i++)
		for(int j=i;j;j=j-1&i)
			dp[i]=max(dp[i],sum[j]+dp[i^j]);
	cout<<dp[(1<<n)-1];
	return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int main() {
	int a, b;
	cin >> a >> b;
	
	cout << (a <= b ? a : a - 1)<< endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
//#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define sll                     set<ll>
#define usll                    unordered_set<ll>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define umcl                    um<char,ll>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define input(a,n)              for(ll i=0;i<n;++i) cin>>a[i];
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int main()
{
	fastIO
//	inp_out();
	ll n,m;
	cin>>n>>m;
	vll a(m);
	input(a,m);
	ll sum=accumulate(all(a),0ll);
	cout<<(n-sum>=0?n-sum:-1);
	return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

bool is_prime(int p)
{
    if (p == 2 or p == 3) return true;
    if (p % 2 == 0) return false;
    int root = sqrt(p);
    for (int i = 3; i <= root; i+=2)
    {
        if (p % i == 0) return false;
    }
   return true; 
}


void solve()
{
  int X; cin >> X;
  while (!is_prime(X))
  {
      X++;
  }
  cout << X << endl;
}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout<<std::fixed<<std::setprecision(10);
  solve();
  return 0;
}

Measured memory_bytes: 256