akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <sstream>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

int64 gcd(int64 a, int64 b) {
    if (a < b) a, b = b, a;
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

int64 modinv(int64 a, int64 m) {
    int64 b = m, u = 1, v = 0;
    while (b) {
        int64 t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    vector<int> L(3);
    rep(i, 3) cin >> L[i];
    sort(all(L));

    if (L[0] != L[1] || L[1] != L[2] || L[0] != L[2]) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

  ll ans = 0LL;
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n);
  REP(i,n) cin >> v[i];

  REP(i, k+1){
    REP(j, k-i+1){
      if(i == 0 && j == 0) continue;
      if(i+j > n) continue;
      vector<ll> t;
      
      REP(l, i) t.push_back(v[l]);
      ROF(r, n-1, n-j) t.push_back(v[r]);
      
      sort(t.begin(), t.end());
      int minus_cnt = k-i-j;
      ll sum = 0LL;
      REP(l, t.size()){
	if(t[l] < 0 && minus_cnt > 0) minus_cnt--;
	else sum += t[l];
      }
      ans = max(ans, sum);
      cerr << "i: " << i << " j: " << j << " ans : " << ans << endl;
    }
  }
 
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 888
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();    
        int N = r.i();
        int[] a = r.ii();
        int[] color = new int[9];
        for(int b : a)
            color[Math.min(b/400, 8)]++;
        int count = 0;
        for(int i = 0; i < 8; i++)
            if(color[i] > 0)
                count++;
        println(Math.max(count, 1)+" "+(count+color[8]));
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

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

int main() {
  int N;
  bool shurui = false;
  cin >> N;

  // ここにプログラムを追記
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    
    if (s == "Y")
      shurui = true;
  }
  cout << (shurui ? "Four" : "Three") << endl;
}

Measured memory_bytes: 256
/**
 *    author:  Mohamad Milhem
 *    created: 2020-04-29-16.54.15
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;
#define decimalpoint cout << std::fixed << setprecision(5)
int n, k;
vector<int> v;
int dp[100005];


int calc(int idx){
    if (idx >= n)return 1e9;
    if (idx == n-1)return 0;

    if (dp[idx] != -1)return dp[idx];

    int ret = 1e9;


    for (int i = 1 ; i <= k && idx + i < n; i++){
        ret = min(ret, abs(v[idx] - v[idx + i]) + calc(idx + i));
    }


    return dp[idx] = ret;

}




int main(){

    FAST;

    cin >> n >> k;

    for (int i = 0 ; i < n ; i++){
        int in;
        cin >> in;
        v.push_back(in);
    }
    memset(dp, -1 , sizeof dp);


    cout << calc(0) << endl;



    return 0;
}


Measured memory_bytes: 8952
# rainy season

def rainy(S):
  if 'RRR' in S:
    return 3
  if 'RR' in S:
    return 2
  if 'R' in S:
    return 1
  return 0

if __name__ == "__main__":
  input = list(input().split())
  print(rainy(input[0]))


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

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep2(i,a,b) for(ll i=a; i<=b; i++)
#define drep2(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back

ll count(ll t)
{
  ll ans = 0;
  while ((t>0) && ((t&1)==0)) {
    t >>= 1;
    ans++;
  }
  return ans;
}

int main ()
{
  ll N;
  cin >> N ;
  vector<ll> a(N);
  ll sum = 0;
  for (int i=0; i<N; i++) {
    ll tmp;
    cin >> tmp;
    sum += count(tmp);
  }
  cout << sum << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// 2項係数を求める
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main(){

    int N, K; cin >> N >> K;
    
    mint ans = 0;    
    for(ll i = K; i <= N+1; i++){
        mint min_v = i*(i-1)/2;
        mint max_v = i*(2*N-i+1)/2;

        ans += (max_v-min_v+1);
    }

    cout << ans << endl;    



}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define SC(a) scanf("%c", &a);
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

int N, M, H[100000];


int main() {
	S2(N, M);
	SA(i, N, H);
	vector<vector<int>> g(N);
	R(i, M) {
		int a = 1, b = 1;
		S2(a, b);
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}
	int ans = 0;
	R(i, N) {
		priority_queue<int> hei;
		R(j, g[i].size()) {
			hei.push(H[g[i][j]]);
		}
		if (hei.empty()) ans++;
		else {
			if(hei.top() < H[i]) ans++;
		}
	}
	P(ans);
}

Measured memory_bytes: 9232
#include <iostream>
#include <math.h>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
//#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	cout << (n + m)*(n + m - 1) / 2 - n * m << endl;
}


Measured memory_bytes: 256
using System;

class ABC{
  static void Main(){
    string N = Console.ReadLine();
    string[] Ai = Console.ReadLine().Trim().Split(' ');
    for (int i = 0; i < int.Parse(N); i++)
    {
      if (int.Parse(Ai[i]) % 2 == 0 && int.Parse(Ai[i]) % 3 != 0 && int.Parse(Ai[i]) % 5 != 0)
      {
        Console.WriteLine("DENIED");
        return;
      }
    }
    Console.WriteLine("APPROVED");
  }
}


Measured memory_bytes: 17704
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2010;
int n, m, d, p1, p2,cnt;
int ans[N][N];
char mp[4] = {'R', 'Y', 'G', 'B'};
int c1,c2;
int main(){
    scanf("%d%d%d", &n, &m, &d);
    for (int i = -1010; i <= 1010; i += d) {
		c1 ^= 1;
        for (int j = -1010; j <= 1010; j += d) {
			c2 ^= 1;
			int c = c1 << 1 | c2;
            for (int x = 0; x < d; x++)
                for (int y = 0; y < d; y++) {
                    if (i + x + j + y < 0 || i + x - j - y < 0) continue;
                    //cout <<((i + x + j + y) >> 1)<<"  "<<((i + x - j - y) >> 1)<<endl;
                    ans[(i + x + j + y) >> 1][(i + x - j - y) >> 1] = c;
                }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
            putchar(mp[ans[i][j]]);
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 15488
import heapq
import math
 
def LI():
  return [int(s) for s in input().split()]
 
N,M = LI()
a = LI()
a = list(map(lambda x: x*(-1), a))  # 各要素を-1倍
 
heapq.heapify(a)
 
for i in range(M):
    x = (-1)*(abs(heapq.heappop(a))//2)
    heapq.heappush(a,x)

cost = 0
for i in range(N):
  x = heapq.heappop(a)
  cost+=abs(x)
  
print(cost)

Measured memory_bytes: 14536
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
while True:
    b=[0]*n
    if c==k:
        break
    for i in range(n):
        l=max(i-a[i],0)
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    f=True
    if b[0]!=n:
        f=False
    for i in range(1,n):
        b[i]+=b[i-1]
        if b[i]!=n:
            f=False
    a=b
    c+=1
    if f:
        break
print(*a)


Measured memory_bytes: 159276
#include<iostream>

using namespace std;


int main(){

    int n;
    cin >> n;
   // vector<int> a(n);
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    long long int ans = 0;
    for(int i=1;i<n;i++){
        if(a[i] < a[i-1]){
            ans = ans + a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    cout << ans << endl;
    return 0;    
}



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

int N;
vector<int> P;

bool solve() {
    vector<int> maxLeftP(N+1, 0), minRightP(N+1, N-1);
    for (int i = 0; i < N; ++i) maxLeftP[i+1] = max(maxLeftP[i], P[i]);
    for (int i = N; i >= 1; --i) minRightP[i-1] = min(minRightP[i], P[i-1]);
    for (int i = 0; i < N-1; ++i) {
        if (P[i] == i && P[i+1] == i+1) { if (maxLeftP[i+1] != i) return false; }
        if (P[i] != i && P[i+1] != i+1) { if (maxLeftP[i+1] != i) return false; }
    }
    for (int i = 1; i+1 < N; ++i) {
        if (P[i] > i) { if (maxLeftP[i] > P[i]) return false; }
        else if (P[i] < i) { if (minRightP[i] < P[i]) return false; }
    }
    return true;
}

int main() {
    cin >> N;
    P.resize(N);
    for (int i = 0; i < N; ++i) cin >> P[i], --P[i];
    if (solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3712
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
using namespace std;

const int N=1e5+5;
const int INF=123456789;
int n,k;
int par[N],ver[N],L[N],R[N];
bool ok=true;
vector<int> nei[N],order;

void check(int x,int p){
	par[x]=p;
	if(ver[x]!=-INF) L[x]=R[x]=ver[x];
	for(int i=0;i<nei[x].size();i++){
		int to=nei[x][i];
		if(to==p) continue;
		check(to,x);
		if(L[to]!=-INF){
			if(L[x]==-INF){
				L[x]=L[to]-1;
				R[x]=R[to]+1;
			}else{
				if(abs(L[x])%2==abs(L[to])%2) ok=false;
				L[x]=max(L[x],L[to]-1);
				R[x]=min(R[x],R[to]+1);
			}
		}
	}
	if(L[x]>R[x]) ok=false;
	order.push_back(x);
}

void make(int x){
	if(par[x]==-1){
		ver[x]=L[x];
		return;
	}
	int p=par[x];
//	cout<<x<<" "<<p<<endl;
	L[x]=max(L[x],ver[p]-1);
	R[x]=max(R[x],ver[p]+1);
//	cout<<x<<" "<<L[x]<<" "<<R[x]<<endl;
	while(abs(L[x])%2==abs(ver[p])%2) L[x]++;
	ver[x]=L[x];
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) ver[i]=L[i]=-INF,R[i]=INF;
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		nei[x].push_back(y);
		nei[y].push_back(x);
	}
	scanf("%d",&k);
	while(k--){
		int x,val;
		scanf("%d%d",&x,&val);
		ver[x]=val;
	}
	check(1,-1);
	if(ok){
		puts("Yes");
		reverse(order.begin(),order.end());
		for(int i=0;i<order.size();i++) make(order[i]);
		for(int i=1;i<=n;i++) printf("%d\n",ver[i]);
	}else{
		puts("No");
	}
	return 0;
}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var x = 800*n;
            var y = 200*(int)(n/15);

            Console.WriteLine(x-y);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF 1000000007
#define MOD 1000000007
#define PI (acos(-1))
#define EPS 1e(-9);
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll D,G; cin>>D>>G;

    ll ans=INF;

    ll p[D],c[D];

    rep(i,D){
        cin>>p[i]>>c[i];
    }

    rep(i,pow(2,D)){
        bool comp[D]={};
        rep(j,D){
            comp[j]= (i>>j) &1;
            
        }
        ll ct=0;
        ll pt=0;
        rep(j,D){
            if(comp[j]){
                ct+=p[j];
                pt+=(j+1)*100*p[j]+c[j];
            }
        }
        ll ct2=0;
        ll pt2=G-pt;
        if(pt2<=0){
            mini(ans,ct); continue;
        }
        rep(j,D){
            if(comp[j]) continue;
            ct2=(pt2+((j+1)*100)-1)/((j+1)*100);
            if(ct2>=p[j]) continue;
            mini(ans,ct+ct2);
        }
    }

    cout<< ans<<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

const int maxn = 2e5 + 3;
int n, m, k, a[maxn], c[maxn], ans;

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; ++i) {
		scanf("%d", a + i);
		++c[a[i]];
	}
	std::sort(c, c + n + 1, std::greater<int>());
	for(m = n; c[m] <= 0; --m) {
	}
	while(m >= k)
		ans += c[m--];
	printf("%d\n", ans);
	return 0;
}

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

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

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const ll INF = 1e16;

int n;
ll a[120000];
ll dp[40];
ll dp2[40];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%lld", a + i);
	}
	for (int i = 0; i < 31; ++i)
		dp[i] = i;
	for (int i = 0; i < n; ++i) {
		int x = 0, y = 0;
		while ((1ll << (x + 1)) <= a[i])
			++x;
		while ((1ll << y) < a[i])
			++y;
		for (int j = 0; j < 31; ++j)
			dp2[j] = INF;
		for (int j = 0; j < 31; ++j) {
			dp2[y] = min(dp2[y], dp[j] + max(0, x - j) + y - x);
			dp2[x] = min(dp2[x], dp[j] + max(0, y - j));
		}
		for (int j = 0; j < 31; ++j)
			dp[j] = dp2[j];
	}
	ll ans = INF;
	for (int i = 0; i < 31; ++i)
		ans = min(ans, dp[i]);
	cout << ans << "\n";
	return 0;
}




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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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 ll LLINF = 1e+18;

using Edge = pair<int,ll>;
vector<vector<Edge>> G;

int N,E;

vector<int> par, rnk;

// 初期化
void init () {
    REP(i,N) {
        par[i] = i;
        rnk[i] = 0;
    }
}

// 木の根を求める
int find ( int x ){
    if ( par[x] == x ) return x;
    else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite( int x, int y){
    x = find(x);
    y = find(y);
    if ( x == y ) return;
    
    if ( rnk[x] < rnk[y] ){
        par[x] = y;
    } else {
        par[y] = x;
        if ( rnk[x] == rnk[y] ) rnk[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same( int x, int y ){
    return find(x) == find(y);
}

struct ES { int u; int v; ll cost; };
vector<ES> es;

bool comp(const ES& e1, const ES& e2){
    return e1.cost < e2.cost;
}

ll kruskal () {
    sort(es.begin(),es.end(),comp);
    init();
    
    ll res = 0;
    REP(i,E){
        ES e = es[i];
        if ( !same(e.u,e.v) ){
            unite(e.u,e.v);
            res += e.cost;
        }
    }
    return res;
}

int main() {
    cin >> N;
    par.resize(N);
    rnk.resize(N);
    G.resize(N);
    //es.resize(E);
    E = (N-1) * 2;
    
    /*REP(i,E){
        int s,t,w;
        cin >> s >> t >> w;
        es[i] = {s,t,w};
    }*/
    
    using pint = pair<int,int>;
    vector<pint> x(N),y(N);
    REP(i,N){
        int a,b;
        cin >> a >> b;
        x[i] = pint(a,i);
        y[i] = pint(b,i);
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    
    REP(i,N-1){
        es.push_back({x[i+1].second,x[i].second,x[i+1].first-x[i].first});
        es.push_back({y[i+1].second,y[i].second,y[i+1].first-y[i].first});
    }
    
    ll ans = kruskal();
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 12148
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    char c;
    cin >> c;
    if( c == 'A' ) cout << 'T';
    if( c == 'C' ) cout << 'G';
    if( c == 'G' ) cout << 'C';
    if( c == 'T' ) cout << 'A';
    cout << endl;
    return 0;
}



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

int main(){
    int k, n;
    cin >> n >> k;

    vector<int> p(n);
    rep(i,n){
        cin >> p.at(i);
    }

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

    int sum = 0;
    rep(i,k){
        sum += p.at(i);
    }

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

Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		
		int ans = 0;
		for (int i = 0; i <= 100; i++) {
			if (A < i && B >= i && C < i && D >= i) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);
  ll sum = 0;
  rep(i, n) {
    sum += a.at(i);
  }
  vector<ll> res(n);
  // 計算
  ll minus = 0;
  rep(i, n) {
    if (i % 2 == 1) {
      minus += a.at(i);
    }
  }
  res.at(0) = sum - 2 * (minus);
  rep(i, n - 1) {
    res.at(i + 1) = 2 * a.at(i) - res.at(i);
  }
  // 出力
  rep(i, n) {
    if (i != 0) {
      cout << " ";
    }
    cout << res.at(i);
  }
  return 0;
}


Measured memory_bytes: 4720
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323
//void quick(int *,long long,long long);

int main(){
     
	int a,b,o,ab,i;
	char x,y;
	a=b=o=ab=0;
	while(scanf("%d,%c%c",&i,&x,&y)!=EOF){
		if(x=='A'&&y!='B')
			a++;
		else if(x=='B')
			b++;
		else if(x=='O')
			o++;
		else
			ab++;
	}
	printf("%d\n%d\n%d\n%d\n",a,b,ab,o);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int

int main()
{
    string s, t;
    int scnt = 1, tcnt = 1;
    int a[200001] = {}, b[200001] = {};
    int sc[500] = {}, tc[500] = {};
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++)
    {
        if (sc[s[i]] == 0)
        {

            sc[s[i]] = scnt;
            scnt++;
        }
        a[i] = sc[s[i]];

        if (tc[t[i]] == 0)
        {
            tc[t[i]] = tcnt;
            tcnt++;
        }
        b[i] = tc[t[i]];
    }

    for (int i = 0; i < s.size(); i++)
    {
        if (a[i] != b[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 2436
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    ll n;
    cin>>n;
    string s;
    map<string,ll>mp;
    rep(i,n){
     cin>>s;
     sort(s.begin(),s.end());
     mp[s]++;
    }
    ll ans=0;
    for(auto p:mp){
     ll s=p.second;
     ans +=s*(s-1)/2;
    }
 
    
   cout<<ans<<endl;
}


Measured memory_bytes: 11384
#include <algorithm>
#include <vector>
#include <utility>
#include <iostream>
using namespace std;
typedef pair<int, pair<int,int> > Edge;

int* uni;
void init(int N)
{
    uni = new int[N];
    for (int i = 0; i < N; i++)
    {
        uni[i] = -1;
    }
}

int root(int a)
{
    if (uni[a] < 0) return a;
    else return uni[a] = root(uni[a]);
}

bool connect(int a, int b)
{
    a = root(a);
    b = root(b);
    if (a == b) return false;
    if (uni[a] > uni[b]) swap( a, b);
    uni[a] += uni[b];
    uni[b] = a;
    return true;
}

int main(){
  int n;
  cin >> n;
  vector<Edge> graph(n);
  for (int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int tmp;
      cin >> tmp;
      if (tmp != -1){
         graph.emplace_back(tmp, make_pair(i,j));
      }
    }
  }
  sort(graph.begin(), graph.end());
  init(n);
  int sum=0;
  for (auto ite=graph.begin();ite != graph.end();ite++){
    if (connect(ite->second.first, ite->second.second))
        sum+=ite->first;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3156
from pprint import pprint
from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
ch-=1;cw-=1
dh,dw=map(int,input().split())
dh-=1;dw-=1
INF=float("inf")
maze=[input() for _ in range(h)]
dist=[[INF]*w for _ in range(h)]
q=deque()
p=[]
q.append((ch,cw))
dist[ch][cw]=0
cur=0
# pprint(dist)
# exit()
while q:
    while q:
        x,y=q.popleft()
        # (x,y)は到達訪問済み
        d=dist[x][y]
        for i in range(-2,3):
            for j in range(-2,3):
                # absの和が1、上下左右
                if abs(i)+abs(j)==1:
                    xx=x+i
                    yy=y+j
                    # 範囲内の時
                    if 0<=xx<=h-1 and 0<=yy<=w-1:
                        # 道のとき
                        if maze[xx][yy]==".":
                            # 未到達の時
                            if dist[xx][yy]>d:
                                # 移動前のdist[x][y]と同じコスト
                                dist[xx][yy]=d
                                q.append((xx,yy))
                # ワープ 
                if abs(i)+abs(j)>=2:
                    xx=x+i
                    yy=y+j
                    if 0<=xx<=h-1 and 0<=yy<=w-1:
                        if maze[xx][yy]==".":
                            if dist[xx][yy]>d+1:
                                dist[xx][yy]=d+1
                                p.append((xx,yy))
                                
   
    cur+=1
    q=deque(p)
    p=[]
            

# pprint(dist)
ans=dist[dh][dw]
if ans==INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 99564
#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define N 2005

using namespace std;
typedef pair<int,int> Pair;
typedef long long ll;

const long double Pi = 3.14159265358979323846l;
const int mod = 1e9 + 7;
inline int add(int x, int y) { return (x += y) - (x >= mod ? mod : 0); }
inline void inc(int &x, int y) { (x += y) -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = mul(res, x);
		x = mul(x, x), y >>= 1;
	} return res;
}

template <class T> inline T	input() {
	T x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

template <class T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }
template <class T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

int n, k;
int f[N << 2];

int main() {
	read(n, k);
	f[0] = 1;
	for (int i = 1; i < n; ++i) {
		for (int j = i; j; --j)
			f[j] = add(f[j - 1], f[j + 1]);
		f[0] = f[1];
	}

	printf("%d\n", mul(f[n - k], n == k ? 1 : Power(2, n - k - 1)));
	return 0;
}


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

int main(){
  int n,i,b;
  cin >>n;
  b=n;
  vector<int>a(n);
  for(i=0;i<n;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  for(i=0;i<n-1;i++){
    if(a.at(i)==a.at(i+1)){
      b--;
    }
  }
  cout <<b<<endl;
}


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


int main()
{
    int a, b;
    std::cin >> a >> b;
    if (a <= 8 && b <= 8) {
        std::cout << "Yay!" << std::endl;
    } else {
        std::cout << ":(" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    long c;
    int i, j = 0;
    i = b;
    while (i != 0)
    {
        i = i / 10;
        a = a * 10;
    }
    c = a + b;
    for (i = 0;i>=0; i++)
    {
        if (c > i*i)
            continue;
        if (c == i * i)
        {
            printf("Yes\n");
            return 0;
        }
        if (c < i*i)
        {
            printf("No\n");
            return 0;
        }
    }

}

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

using namespace std;

int main()
{
    int N;
    cin >> N;

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

    long sum = 0;
    for(int i = 0; i < N; i++){
	while(A.at(i) % 2 == 0){
	    A.at(i) /= 2;
	    sum++;
	}
    }

    cout << sum << endl;
}


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

using namespace std;
 
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
 
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
 
#define pint(x) printf("%d",x)
#define plint(x) printf("%lld",x)
#define endl '\n'
#define nl printf("\n");
#define ps printf(" "); 
 
#define all(x) x.begin(),x.end()
#define pb push_back
#define Set(a, s) memset(a, s, sizeof (a))
#define mod1 (lli)(1e9 + 7)
#define mod2 (lli)(1e9 + 9)
#define EPS 1e-9

#define fore(i,n) for(int i=n; i>=0; i--)
#define fors(i,a,n) for(int i=a; i<n; i++)
#define fora(i,ele) for(auto i: ele)
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<lli> vli;
 
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
 
double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}
float roundoff(float val, float p){ return floor(val*pow(10.0,p)+0.5)/pow(10.0,p);}
lli power(lli a, lli b, lli mod){lli x=1,y=a; while(b > 0){if(b&1){x=(x*y)%mod;}y = (y*y)%mod; b /= 2;}return x;}
 
const int INF = 0x3f3f3f3f;
const float pi = 3.14159265;
 
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1};
 
int main(void) {
    ios_base::sync_with_stdio(true);
    cin.tie(NULL);
    cout.tie(NULL);
	//srand (time(NULL));
	/*
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	*/
    // cout<<"Execution time : "<<tick()<<"\n";
    
    int n;
    cin>>n;
    
    int xa=0,ba=0,bx=0;
    int ans = 0;
    fors(j,0,n){
		string str;
		cin>>str;
		
		fors(i,0,str.length()-1){
			if(str[i] == 'A' and str[i+1] == 'B') ans++;
		}
		if(str[0] == 'B' and str[str.length()-1] == 'A') ba++;
		else if(str[str.length()-1]=='A') xa++;
		else if(str[0] == 'B') bx++;
	}
    
    if(ba>0){
		
		ans+=ba-1;
		
		if(bx>0 and xa>0) bx--,xa--, ans+=2;
		else if(bx>0) bx--,ans+=1;
		else if(xa>0) xa--, ans+=1;
		ans += min(xa,bx);
				
	}
	else{
		ans += min(xa,bx);
	}
    
    cout<<ans;
    return 0;
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n,k; cin >> n >> k;
    vl a(n),s(n+1);
    rep(i,n) cin >> a[i];
    rep(i,n) s[i+1] = s[i] + a[i];

    ll x = 0;
    for(ll l=50; l>=0; l--){
        int cnt = 0;
        rep(i,n) REP(j,i,n){
            ll sum = s[j+1] - s[i];
            if((sum&x) == x && (sum>>l) & 1) cnt++;
        }
        if(cnt >= k) x |= 1ll<<l;
    }
    cout << x << endl;
    return 0;
}

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

int main(){
   int n; cin>>n;
   vector<int> w(n);
   rep(i,n) cin>>w[i];
   int ans=100000;
   for(int i=1;i<=n-1;i++){
      int r=0,l=0;
      for(int j=0;j<=i;j++) r+=w[j];
      for(int k=i+1;k<n;k++) l+=w[k];
      ans=min(ans,abs(r-l));
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> p;
int main(){
  int n,gr[2][3000];
  cin>>n;
  vector<p> t[2];
  char d[3000];
  for(int x,y,i=0;i<n;i++){
    cin>>x>>y>>d[i];
    t[0].push_back(p(P(x,y),i));
    t[1].push_back(p(P(y,x),i));
  }
  sort(t[0].begin(),t[0].end());
  sort(t[1].begin(),t[1].end());  
  for(int i=0;i<n;i++)
    gr[0][t[0][i].s]=i,gr[1][t[1][i].s]=i;
  int ans=0;

  for(int i=0;i<n;i++){
    bool used[3000]={};
    int ss=i,k=0;
     while(1){
       k++;
       bool f=0;
       used[ss]=1;

       if(d[ss]=='v'){
	 int g=gr[0][ss];
	 int a=t[0][g].f.f;
	 while(used[ss]){
	   if(++g==n){f=1;break;}
	   ss=t[0][g].s;
	 }
	 if(f||t[0][gr[0][ss]].f.f!=a)break;
       }

       if(d[ss]=='^'){
	 int g=gr[0][ss];
	 int a=t[0][g].f.f;
	 while(used[ss]){
	   if(!g){f=1;break;}
	   ss=t[0][--g].s;
	 }
	 if(f||t[0][gr[0][ss]].f.f!=a)break;
       }


       if(d[ss]=='>'){
	 int g=gr[1][ss];
	 int a=t[1][g].f.f;
	 while(used[ss]){
	   if(++g==n){f=1;break;}	  
	   ss=t[1][g].s;
	 }
	 if(f||t[1][gr[1][ss]].f.f!=a)break;
       }


      if(d[ss]=='<'){
	int g=gr[1][ss];
	int a=t[1][g].f.f;
	 while(used[ss]){
	   if(!g){f=1;break;}	  
	   ss=t[1][--g].s;
	 }
	 if(f||t[1][gr[1][ss]].f.f!=a)break;
      }
     }
     ans=max(ans,k);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1344
S = list(map(int,input().split()))
K = S[0]
A = S[1]
B = S[2]
if B - A <= 2:
    answer = 1 + K
else:
    if K+1 < A+2:
        answer = 1 + K
    else:
        n = (K+1-(A+2))//2 + 1
        answer = n*B - (n-1)*A + (K+1-(A+2))%2
print(answer)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

int main() {
  ll n, k, cou = 0, tmp;
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    cin >> tmp;
    if (k <= tmp) cou++;
  }
  cout << cou << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin>>s;
    ll sum=0;
    rep(i,4){
        if(s[i]=='2') sum++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	cc := make(I64, n)
	mod := int64(1e9 + 7)
	cm := Com{}
	cm.init(n)

	for i := 0; i < n; i++ {
		cc[i] = getNextInt64(scanner)
	}
	sort.Sort(cc)
	var ans int64
	doubling := make([]int64, 60)
	doubling[0] = 2
	for i := 1; i < 60; i++ {
		doubling[i] = doubling[i-1] * doubling[i-1]
		doubling[i] %= mod
	}

	nn := int64(1)

	for i := 60 - 1; i >= 0; i-- {
		if (n-1)>>uint(i)&1 == 0 {
			continue
		}
		nn *= doubling[i]
		nn %= mod
	}
	nnn := nn * cm.inv(2) % mod
	for i := n - 1; i >= 0; i-- {
		ans += ((nn + nnn*int64(i)) % mod) * cc[i]
		ans %= mod
	}
	for i := 60 - 1; i >= 0; i-- {
		if n>>uint(i)&1 == 0 {
			continue
		}
		ans *= doubling[i]
		ans %= mod
	}

	fmt.Fprintln(writer, ans)
}

type I64 []int64

func (a I64) Len() int           { return len(a) }
func (a I64) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a I64) Less(i, j int) bool { return a[i] > a[j] }

// Com ...
type Com struct {
	facs, invs []int64
	mod        int64
}

func (cm *Com) init(n int) {
	cm.facs = make([]int64, n+1)
	cm.invs = make([]int64, n+1)

	cm.facs[0] = 1
	cm.mod = int64(1e9 + 7)
	for i := 1; i <= n; i++ {
		cm.facs[i] = (cm.facs[i-1] * int64(i)) % cm.mod
	}
	cm.invs[n] = cm.inv(cm.facs[n])
	for i := n - 1; i >= 0; i-- {
		cm.invs[i] = cm.invs[i+1] * int64(i+1) % cm.mod
	}
}

func (cm *Com) inv(n int64) int64 {
	var ii [32]int64
	ii[0] = n
	for i := 1; i < 31; i++ {
		ii[i] = (ii[i-1] * ii[i-1]) % cm.mod
	}
	var ans int64
	ans = 1
	m := cm.mod - 2
	for i := 30; i >= 0; i-- {
		for m >= 1<<uint(i) {
			ans = (ans * ii[i]) % cm.mod
			m -= 1 << uint(i)
		}
	}

	return ans
}

func (cm *Com) calc(n, k int) int64 {
	ans := cm.facs[n] * cm.invs[k]
	ans %= cm.mod
	ans = ans * cm.invs[n-k]
	ans %= cm.mod
	return ans
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
 
int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	string s1,s2,s3;
	cin >> s1 >> s2 >> s3;
	putchar (toupper(s1[0]));
	putchar (toupper(s2[0]));
	putchar (toupper(s3[0]));
	return 0;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

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

  int32_t K, N;
  cin >> K >> N;
  vector<int32_t> A(N);
  int32_t max_d = 0;
  for (int32_t i = 0; i < N; ++i) {
    cin >> A[i];
    if (i != 0) {
      max_d = max(max_d, A[i] - A[i - 1]);
    }
  }
  max_d = max(max_d, K + A[0] - A[N - 1]);
  cout << (K - max_d) << endl;

  return 0;
}


Measured memory_bytes: 1024
#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 ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N) scanf("%d", &A[i]);
	
	multiset<int> ms;
	REP(i, N) {
		auto it = ms.lower_bound(A[i]);
		if (it == ms.begin()) ms.insert(A[i]);
		else {
			--it;
			ms.erase(it);
			ms.insert(A[i]);
		}
		
	}
	
	cout << ms.size() << endl;
	
	return 0;
}


Measured memory_bytes: 5376
k = int(input())
# if k < 10:
#     print(k)
#     exit()

def s(n):
    return sum(list(map(int, str(n))))

seeds = [i for i in range(1, 10)]
for i in range(15):
    for j in range(10):
        for m in range(10):
            for y in range(10):
                seeds.append(int(str(m + j*10 + y*100) + str(9)*i))

# print(seeds)

seeds = [i for i in seeds if i!=0]

l = []
for i in seeds:
    l.append([i, s(i), i/s(i)])

# for i in range(1, 10**6):
#     l.append([i, s(i), i/s(i)])


l.sort(key=lambda x:x[2])
# for i in range(len(l)):
#     print(l[i])

max = 0
ans = []
for i in range(len(l)):
    if l[i][0] > max:
        max = l[i][0]
        ans.append(l[i][0])
        # print(l[i][0], end=" ")

for i in range(k):
    print(ans[i])

# max = 0
# for i in range(len(l)):
#     if l[i][0] > max:
#         max = l[i][0]
#         print(l[i][0]+1, end=" ")
# print()


Measured memory_bytes: 5712
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int a, b, c; cin >> a >> b >> c;
    bool ok = false;
    rep(i,0,b) ok |= (a * i) % b == c;
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256