akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}

int main(){
    ll X,Y;
    cin>>X>>Y;
    YN(Y%2 == 0 && 2*X <= Y && 4*X >= Y);
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>

using namespace std;
#define li long long int
#define FOR(i, a, b) for (int i = a ; i < b ; ++i)
#define REP(i, n) for (int i = 0 ; i < n ; ++i)

li gcd(li a,li b) {
    return a % b == 0 ? b : gcd(b, a % b);
}

int main(void) {
    li x, y;
    cin >> x >> y;
    
    li absX = abs(x);
    li absY = abs(y);

    // yに比較したxの初期座標がどの位置かで行動が決まる
    // xとyは異なるためすべてのパターンは8通り
    
    // 同じ符号
    if (x > 0 && y > 0 && absX > absY) {
        // ともに正
        cout << (absX - absY) + 2;

    } else if (x > 0 && y > 0 && absX < absY) {
        // ともに正
        cout << absY - absX;
    } else if (x < 0 && y < 0 && absX > absY) {
        // ともに負
        cout << absX - absY;
    } else if (x < 0 && y < 0 && absX < absY) {
        // ともに負
        cout << (absY - absX) + 2;
    }
    // 異なる符号
    // 符号が異なる場合は一度反転がいる
    if (x > 0 && y < 0 && absX >= absY) {
        // x正 y負
        cout << (absX - absY) + 1;
    } else if (x > 0 && y < 0 && absX <= absY) {
        // x正 y負
        cout << (absY - absX) + 1;
    } else if (x < 0 && y > 0 && absX >= absY) {
        // x負 y正
        cout << (absX - absY) + 1;
    } else if (x < 0 && y > 0 && absX <= absY) {
        // x負 y正
        cout << (absY - absX) + 1;
    }

    // y = 0パターン
    if (y == 0) {
        if (x > 0) {
            cout << absX + 1;
        } else {
            cout << absX;
        }
    }

    // x = 0パターン
    if (x == 0) {
        if (y > 0) {
            cout << absY;
        } else {
            cout << absY + 1;
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


ll n;
ll a[100100],b[100100];
ll sum=0;
vector<ll> v1;
ll ans=0;
int main(){
	cin>>n;
	REP(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	REP(i,n){
		cin>>b[i];
		sum-=b[i];
	}
	if(sum<0){
		cout<<-1<<endl;
		return 0;
	}
	
	sum=0;
	for(ll i=0;i<n;i++){
		if(a[i]<b[i]){
			sum+=(b[i]-a[i]);
			ans++;
		}else if(a[i]>b[i]){
			v1.push_back(a[i]-b[i]);
		}
	}
	sort(v1.begin(),v1.end(),greater<ll>());
	ll t1=0;
	while(sum>0){
		sum-=v1[t1];
		ans++;
		t1++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2428
#include<stdio.h>

void trace(int A[],int N){
	int i;
	for(i=0;i<N;i++){
		if(i>0) printf(" ");
		printf("%d",A[i]);
	}
		printf("\n");
	}
	
	void insertionSort(int A[],int N){
		int j,i,v;
		for(i=1;i<N;i++){
			v=A[i];
			j=i-1;
			while(j>=0&&A[j]>v){
				A[j+1]=A[j];
				j--;
			}
			A[j+1]=v;
			trace(A,N);
		}
	}
	
	int main(){
		int N,i,j;
		int A[100];
		
		scanf("%d",&N);
		for(i=0;i<N;i++) scanf("%d",&A[i]);
		
		trace(A,N);
		insertionSort(A,N);
		return 0;
}

Measured memory_bytes: 604
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ip = 0
iq = 0
ir = 0
ans = 0
while ip+iq+ir<x+y:
    tp = 0 if ip>=x else p[ip]
    tq = 0 if iq>=y else q[iq]
    tr = 0 if ir==c else r[ir]
    if tp >= tq and tp >= tr and ip < x:
        ans += tp
        ip += 1
    elif tq >= tp and tq >= tr and iq < y:
        ans += tq
        iq += 1
    elif ir < c:
        ans += tr
        ir += 1
    elif tp > tq and ip < x:
        ans += tp
        ip += 1
    else:
        ans += tq
        iq += 1
print(ans)

Measured memory_bytes: 23328
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int gcd(int a,int b)
{
    if (a%b==0)
    {
        return(b);
    }
    else
    {
        return(gcd(b,a%b));
    }
}

int main(void)
{
    int n;
    cin >>n;
    vector<int> a;

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

    int gcdans = gcd(a[0], a[1]);
    for(int i = 2; i < n; i++){
        gcdans = gcd(a[i], gcdans);
    }

    printf("%d\n", gcdans);
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<P,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> A(N,0);
    vector<ll> B(N,0);
    for(ll i=0;i<N;i++){
        cin>>A[i]>>B[i];
    }
    priority_queue<P, vector<P>, greater<P>> pq;
    for(ll i=0;i<N;i++)pq.emplace(P(A[i],B[i]));
    ll nokori=M;
    ll ans=0;
    while(nokori>0){
        P x=pq.top();
        pq.pop();
        if(nokori>=x.second){
            ans+=x.second*x.first;
            nokori-=x.second;
        }
        else {
            ans+=x.first*nokori;
            nokori=0;
            break;
        }
    }
    print(ans)
    return 0;
}

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

constexpr int IINF = INT_MAX;

int main() {
    int n;
    string a;
    cin >> a;
    n = a.size();
    vector<int> dp(n+2, IINF);  // i文字目までの部分文字列でない最小文字数
    vector<vector<int> > pos(26);
    vector<vector<pair<pair<char,char>,int> > > pre(n+2);

    for(int i=0;i<26;i++) pos[i].push_back(0);
    for(int i=0;i<n;i++){
        pos[a[i]-'a'].push_back(i+1);
    }

    dp[n+1] = 0;
    a.push_back('#');
    for(int i=n+1; i>0; i--){
        for(int j=0; j<26; j++){
            int k = *--lower_bound(pos[j].begin(), pos[j].end(), i);
            if(dp[k] > dp[i]+1){
                dp[k] = dp[i]+1;
                pre[k].clear();
                pre[k].push_back({{'a'+j,a[i-1]},i});
            }
            else if(dp[k] == dp[i]+1){
                pre[k].push_back({{'a'+j,a[i-1]},i});
            }
        }
    }
    // 復元
    string ans = "";
    for(int i=0;i<n;){
        sort(pre[i].begin(),pre[i].end());
        ans.push_back(pre[i][0].first.first);
        i = abs(pre[i][0].second);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 39556
#include<iostream>

using namespace std;

int main()
{
	int n, v,a[100] = { 0 };

	cin >> n;
	for (unsigned int i = 0; i != n; ++i)
	{
		cin >> a[i];
	}

	for (int i = 0; i != n; ++i)
	{
		cout << a[i];
		if (i == n - 1)
		{
			cout << endl;
		}
		else
		{
			cout << " ";
		}
	}

	for (int i = 1; i != n; ++i)
	{
		v = a[i];
		for (int j = i - 1; j >= 0&&a[j]>v;)
		{
			a[j + 1] = a[j];
			--j;
			a[j + 1] = v;
		}

		for (int i = 0; i != n; ++i)
		{
			cout << a[i];
			if (i == n - 1)
			{
				cout << endl;
			}
			else
			{
				cout << " ";
			}
		}
		
	
	}

	return 0;

}


Measured memory_bytes: 3076
var
	S:String;
	c:Char;
	i,j,k,cnt:Longint;
begin
readln(S);
if length(S)<26 then begin
	for c:='a'to'z'do begin
		cnt:=0;
		for i:=1 to length(S)do if s[i]=c then inc(cnt);
		if cnt=0 then begin
			writeln(S,c);
			exit;
		end;
	end;
end else begin
	for j:=25 downto 1 do if s[j]<s[j+1]then begin
		c:=s[j+1];
		for k:=j+1 to 26 do if(s[j]<s[k])and(s[k]<c)then c:=s[k];
		writeln(copy(s,1,j-1),c);
		exit;
	end;
end;
writeln(-1);
end.

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String s = input.readLine();
        int q = Integer.parseInt(input.readLine());
        StringBuffer preSb = new StringBuffer();
        StringBuffer sb = new StringBuffer(s);
        boolean rvflag = false;

        for(int i=0;i<q;i++){
            String[] qn = input.readLine().split(" ");
            if(qn[0].equals("1")){
                rvflag = !rvflag;
            }else{
                if((qn[1].equals("1") && !rvflag) || (qn[1].equals("2") && rvflag)) {
                    preSb.append(qn[2]);
                }else if((qn[1].equals("2") && !rvflag) || (qn[1].equals("1") && rvflag)){
                    sb.append(qn[2]);
                }
            }
        }
        StringBuffer ans = new StringBuffer();
        ans.append(preSb.reverse());
        ans.append(sb);

        if(rvflag){
            ans.reverse();
        }
        System.out.println(ans.toString());
    }
}


Measured memory_bytes: 57524
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define N 8

bool isTen(char c){
  return (c == 'T' || c == 'J' || c== 'Q' || c == 'K');
}
bool isBlackjack(char c1, char c2){
  if ( c1 == 'A' ) swap(c1, c2);
  if ( c2 == 'A' && isTen(c1) ) return true;
  return false;
}

int getValue(char ch){
  return isTen(ch) ? 10 : (ch - '0');
}

void getScore(vector<char> H, int &score, bool &check11){
  int A = 0;
  score = 0;
  check11 = false;
  for ( int i = 0; i < H.size(); i++ ){
    if ( H[i] == 'A' ) { score++; A++; }
    else { score += getValue(H[i]);}
  }
  if ( A && score <= 11 ){
    check11 = true;
    score += 10;
  }
}

void simulate(char D[N+1], char c1, char c2){
  if ( isBlackjack(c1, c2) ) { cout << "blackjack" << endl; return; }
  vector<char> H;
  H.push_back(c1);
  H.push_back(c2);
  int score = 0;
  bool check11;
  for ( int i = 0; i < N+1; i++ ){
    char c = D[i];
    getScore(H, score, check11);
    if ( score > 21 ){
      cout << "bust" << endl; return;
    }
    if ( score <= 16 || (score == 17 && check11 )){
      H.push_back(c);
    } else {
      cout << score << endl; return;
    }
  }
}

main(){
  char D[N+1], c1, c2;
  int tcase; cin >> tcase;
  for ( int i = 0; i < tcase; i++ ) {
    cin >> c1 >> c2;
    for ( int j = 0; j < N; j++ ) cin >> D[j];
    D[N] = 0;
    simulate(D, c1, c2);
  }
}

Measured memory_bytes: 0
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int n,a,b;
    cin>>n>>a>>b;
    if(n*a<b)
    {
    	cout<<n*a<<endl;
	}
	else
	{
		cout<<b<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int long long

void solve() {
	int n; 
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    int now = INF, ans;
    rep(i, n) {
        if(chmin(now, abs(a[i] * n - sum))) {
            ans = i;
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
a=0
while a==0:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    else:
        cnt=0
        for i in range(1,n-1):
            for j in range(i+1,n):
                for k in range(j+1,n+1):
                    if i+j+k==x:
                        cnt+=1
        print(cnt)


Measured memory_bytes: 5596
#include <cstdio>
#include <algorithm>
using namespace std;

int N;
long long A[200005];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", A+i);
  }

  long long m = A[0];
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += max(0LL, m - A[i]);
    m = max(m, A[i]);
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 3248
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll mod=1e9+7;
ll N,K;
vector<ll> v;
ll memo[3009][3009][2];
bool vis[3009][3009][2];
ll sol(ll a,ll b,ll t){
  if(t==0 && a==b)return v[a];
  if(a==b)return -v[a];
  if(vis[a][b][t])return memo[a][b][t];
  vis[a][b][t]=1;
  if(t==0){
    return memo[a][b][t]=max(sol(a+1,b,!t)+v[a],sol(a,b-1,!t)+v[b]);
  }
  return memo[a][b][t]=min(sol(a+1,b,!t)-v[a],sol(a,b-1,!t)-v[b]);
}
signed main(){
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
		cin>>N;
		for(ll i=0;i<N;i++){
      ll a;
      cin>>a;
      v.push_back(a);
		}
		cout<<sol(0,N-1,0);
    return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  long long n;
  cin >> n;

  long long now = n;
  long long minu = 26;

  int bit26[40];
  long long last;
  int i = 0;
  int count = 0;
  while(now / minu > 0){
    now -= minu;
    if(now == 0) {
      break;
    }
    minu *= 26;
    count ++;
  }
  // last = now % minu;
  last = now;
  if(last == 0) last = minu;
  bool flag = 0;
  // if(last == 0) flag = 1;

  // cout << last << endl;
  // cout << count << endl;
  

  long long exp = 1;
  int size = count + 1;
  // count --;
  while(count >= 0){
    exp = 1;
    for(int i = 0; i < count; i++){
      exp *= 26;
    }
    bit26[count] = (last-1) / exp;
    // cout << bit26[count] << endl;
    last -= bit26[count] * exp;
    count --;;
  }
  // bit26[0] -= 1;

  char s[20];
  for(int i = 0; i < size; i++){
    s[i] = bit26[i] + 97;
  }

  if(!flag){
    for(int i = size-1; i >= 0; i--){
      cout << s[i];
    }
  }else
  {
    for(int i = size-1; i >= 0; i--){
      cout << 'z';
    }
  }
  
  
  cout << endl;

  return 0;
}

Measured memory_bytes: 3628
str1 = input()
str2 = input()

array1 = []
array2 = []

for i in range(97, 97+26):
    array1.append(str1.count(chr(i)))
    array2.append(str2.count(chr(i)))

for p in range(len(str1)):
    if(array1.count(p) != array2.count(p)):
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 3632
"""
B - Coins
"""
#合計金額の通り数 kaisu
kaisu = 0

# 500円玉の枚数 a
a = int(input())

# 100円玉の枚数 b
b = int(input())

# 50円玉の枚数 c
c = int(input())

# 合計金額 x
x = int(input())

#入力のチェック
#print(a, b, c, x)

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i*500 + j*100 + k*50 == x:
                kaisu += 1

print(kaisu)

Measured memory_bytes: 3060
#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 repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000


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

    long long int N;
    cin >> N;
    int temp = N;
    int ans = 0;

    for(int i = 0; N > 0; ++i) {
        ans += N % 10;
        N /= 10;
    }

    if(temp % ans == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}


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

int main() {
    int n;
    cin >> n;
    float total = 0;

    for (int i=1; i <= n; i++) {
        int a;
        cin >> a;
        total += (1.0/a);
    }

    cout << 1/total << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int cnt[30];
const int MOD = 1e9+7;
int main() {
   string s;
   int n;
   cin>>n>>s;
   for(int i =0;i<n;i++) {
   		cnt[s[i]-'a']++;
   }
   long long ans = 1;
   for(int i =0;i<28;i++) {
   		ans = (ans * (cnt[i]+1LL)) % MOD;
   }
   cout<<(ans+MOD-1) % MOD<<endl;
}   

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

#define dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_p(x) cerr<<#x": "<<x.first<<","<<x.second<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define st first
#define nd second

using namespace std;

const int N = 200100;
int n, k, p[N], pos[N], ans;

template<class T>
ostream& operator<<(ostream& out, vector<T> v) {
	out << v.size() << '\n';
	for(auto e : v) out << e << ' ';
	return out;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	ans = n;
	for(int i = 1; i <= n; i++)
		cin >> p[i], pos[p[i]] = i;

	int last = 0;
	for(int i = 1; i <= n; i++) {
		if(last >= i) continue;
		last = i;
		while(pos[last + 1] > pos[last]) last++;
		// dbg(last);
		// dbg(i);
		ans = min(ans, n - (last - i + 1));
	}
	cout << ans << '\n';
}	

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	string s; cin >> s;

	int ans = 0;
	REP(i,4) if(s[i] == '2') ans++;
	cout << ans << endl;


	return 0;

}


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

int main() {
	int N, M;
	cin >> N;
	cin >> M;
	vector <long> height(N);
	vector <bool> good(N, true);
	for (int i = 0; i < N; ++i) {
		cin >> height[i];
	}
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a;
		cin >> b;
		a--; b--;
		if (height[a] < height[b]) {
			good[a] = false;
		} else if (height[b] < height[a]) {
			good[b] = false;
		} else if (height[a] == height[b]) {
			good[a] = false;
			good[b] = false;
		}
	}
	
	int ngood = 0;
	for (int i = 0; i < N; ++i) {
		if (good[i]) ngood++;
	}
	cout << ngood << endl;
	return 0;
}

Measured memory_bytes: 4052
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
state = []

for _ in range(N):
    A = int(input())
    l = []
    
    for _ in range(A):
        x, y = map(int, input().split())
        l.append((x-1, y))
    
    state.append(l)
    
ans = 0

for S in range(2**N):
    flag = True
    cnt = 0
    
    for i in range(N):
        if (S>>i)&1:
            for x, y in state[i]:
                if y==0 and (S>>x)&1:
                    flag = False
                elif y==1 and not (S>>x)&1:
                    flag = False
            
            cnt += 1
    
    if flag:
        ans = max(ans, cnt)

print(ans)

Measured memory_bytes: 43500
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    string s;
    cin >> s;
    if (s == "0"){
      break;
    }
    int ans = 0;
    for (int i = 0; i < s.size(); i++){
      ans += s[i] - '0';
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
ll N;
  in(N);
  vl A(N);
  ll wa =0;
  ll ans =mod;
  rep(i,N) in(A[i]);
  rep(i,N) wa += A[i];
  
  ll yama =A[0];
  wa -= A[0];
  if(N==2){
 out(abs(yama-wa));
  return 0;
  }
  
  for(ll i=1;i<N;i++){
    ans = min(ans,abs(wa-yama));
   wa -= A[i];
    yama += A[i];
  }
  out(ans);
}
  

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

long long a[1000],mon=1;
int main(){
    int n;
    cin>>n;
    for(int i=2;i<=n;i++){
        int k=i;
        for(int j=2;j<=k;j++){
            while(k%j==0){
                a[j]++;
                k/=j;
            }
            
        }
    }
    for(int i=2;i<=n;i++){
        mon=mon*(a[i]+1)%1000000007;
    }
    cout<<mon<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
#define nl cout<<"\n"
//cout<<fixed<<setprecision(11);
const ll MOD=1e9+7;
const ll ARR_MAX = 1e5+1;
const ll VAL_MAX = 1e5+1;
const ll INF=1e14;

void solve(){
    int n,m;
    cin>>n>>m;
    ll h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    bool isbad[n]={};
    for(int i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        if(h[a]>=h[b]){
            isbad[b]=1;
        }
        if(h[b]>=h[a]){
            isbad[a]=1;
        }
    }
    int cnt=0;
    for(int i=0;i<n;i++){
        if(isbad[i]==0){
            cnt++;
        }
    }
    cout<<cnt,nl;
}

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

Measured memory_bytes: 4504
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
string f(ll n){
    if(n == 0) return "";
    n--;
    return f(n/26) + string(1, 'a'+n%26);
}

int main(){
    cout << fixed << setprecision(10);
    ll n;
    cin >> n;
    cout << f(n) << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int main(){
    while(1){
        cin>>n;
        if(n==0) break;
        vector<int> vx(250,0),vy(250,0);
        int maxx=0,minx=0,maxy=0,miny=0;
        for(int i=0;i<n-1;i++){
            int n,d;
            cin>>n>>d;
            vx[i+1]=vx[n]+dx[d];
            vy[i+1]=vy[n]+dy[d];
            //int maxx=0,minx=0,maxy=0,miny=0;
            if(vx[i+1]<minx) minx=vx[i+1];
            if(vx[i+1]>maxx) maxx=vx[i+1];
            if(vy[i+1]<miny) miny=vy[i+1];
            if(vy[i+1]>maxy) maxy=vy[i+1];
        }
        cout<<maxx-minx+1<<" "<<maxy-miny+1<<endl;
    }
    return 0;
}


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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    int n, W; cin >> n >> W;
    vector<int> v(n), w(n);
    for (int i = 0; i < n; i++) cin >> v[i] >> w[i];

    vector<vector<int>> dp(n + 1, vector<int>(W + 1, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) dp[i + 1][j] = dp[i][j];
            else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
        }
    }
    
    cout << dp[n][W] << endl;
    return 0;
}


Measured memory_bytes: 6764
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll a, b;
    cin >> a >> b;
    if (a % 2 && b % 2)
        cout << "Odd" << endl;
    else
        cout << "Even" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const ll MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

//累乗 a**n%mod
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin>>S;
    ll s=S.size();
    vector<ll> A(s),C(s),Q(s);

    if(S[0]=='A') A[0]=1;
    else A[0]=0;
    FOR(i,1,s){
        if(S[i]=='A') A[i]=A[i-1]+1;
        else A[i]=A[i-1];
    }

    if(S[0]=='C') C[0]=1;
    else C[0]=0;
    FOR(i,1,s){
        if(S[i]=='C') C[i]=C[i-1]+1;
        else C[i]=C[i-1];
    }

    if(S[0]=='?') Q[0]=1;
    else Q[0]=0;
    FOR(i,1,s){
        if(S[i]=='?') Q[i]=Q[i-1]+1;
        else Q[i]=Q[i-1];
    }

    ll ans=0;
    ll q;

    FOR(i,0,s){
        if(S[i]=='B' || S[i]=='?'){
            q=Q[s-1];
            if(S[i]=='?') --q;
            //cout<<q<<endl;
            if(i==0){
                continue;
            }else{
                ans+=(A[i-1]%MOD)*((C[s-1]-C[i])%MOD)*modpow(3,q,MOD)%MOD;
                ans%=MOD;
                //cout<<ans<<'a'<<endl;
                ans+=(A[i-1]%MOD)*((Q[s-1]-Q[i])%MOD)*modpow(3,q-1,MOD)%MOD;
                ans%=MOD;
                //cout<<ans<<'b'<<endl;
                ans+=(Q[i-1]%MOD)*((C[s-1]-C[i])%MOD)*modpow(3,q-1,MOD)%MOD;
                ans%=MOD;
                //cout<<ans<<'c'<<endl;
                ans+=(Q[i-1]%MOD)*((Q[s-1]-Q[i])%MOD)*modpow(3,q-2,MOD)%MOD;
                ans%=MOD;
                //cout<<ans<<endl;
            }
        }
    }

    cout<<ans%MOD<<endl;
    
}
//666

Measured memory_bytes: 2896
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    LL n; cin >> n;
    int ans = 0;
    for (LL i = 2 ; i * i <= n ; i++) {
        if (n % i)
            continue;
        int cnt = 0;
        while (n % i == 0)
            cnt++, n /= i;
        LL len = 1;
        while ((len + 1) * (len + 2) <= 2 * cnt)
            len++;
        ans += len;
    }
    if (n != 1)
        ans++;
    cout << ans << '\n';
}

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

int main(){
    int ans=0,sum=0;
    int a,b,c;
    
    cin >>a>>b>>c;


    //cout <<fixed<<setprecision(16)<< << endl;
    cout << c - min(a,b+c) + b << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{

        int a,b,k,i,j=0;

        scanf("%d%d%d",&a,&b,&k);

        for(i=a;j<k;i--){

                if(a%i==0&&b%i==0)
                        j++;
        }

        printf("%d\n",i+1);

        return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N;
  cin>>N;
  VL P(N);
  rep(i,N) cin>>P[i];
  ll ans=0;
  multiset<ll> X;
  X.insert(-1);
  X.insert(-1);
  X.insert(N);
  X.insert(N);
  VL Q(N);
  rep(i,N) Q[P[i]-1]=i;
  reverse(all(Q));
  rep(i,N){
    auto itr=X.lb(Q[i]);
    ll B,C,D,E;
    D=*itr;
    itr++;
    E=*itr;
    itr--;
    itr--;
    C=*itr;
    itr--;
    B=*itr;
    ans+=((E-D)*(Q[i]-C)+(C-B)*(D-Q[i]))*(N-i);
    X.insert(Q[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6528
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	vector<string> sv;
	string S;
	int K;
	cin >> S >> K;

	rep(i, 0, SZ(S))
	{
		string ts;
		rep(j, i, min(SZ(S),i + 5))
		{
			ts += S[j];
			sv.push_back(ts);
		}
	}

	sort(all(sv));
	sv.erase(unique(all(sv)), sv.end());

	cout << sv[K-1] << endl;

	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int* p);
const int maxn = 510;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int a[maxn];
int b[maxn];
int c[maxn];
int d[maxn];
int can[maxn][maxn];
int vis[maxn];
int linker[maxn];
bool dfs(int x)
{
    repd(i, 1, n)
    {
        if (can[x][i] && vis[i] == 0)
        {
            vis[i] = 1;
            if (linker[i] == 0 || (dfs(linker[i])))// 没使用或者去寻找新的增广路
            {
                linker[i] = x;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    cin >> n;
    repd(i, 1, n)
    {
        cin >> a[i] >> b[i];
    }
    repd(i, 1, n)
    {
        cin >> c[i] >> d[i];
    }
    repd(i, 1, n)
    {
        repd(j, 1, n)
        {
            if (a[i] < c[j] && b[i] < d[j])
            {
                can[i][j] = 1;
            }
        }
    }
    int ans = 0;
    repd(i, 1, n)
    {
        memset(vis, 0, sizeof(vis));
        if (dfs(i))
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int C[1000006];

long long int N;

int main(void) {

	cin >> N;
	long long int tmp = N;
	for (long long int i = 2; i*i <= N; i++) {
		while (tmp%i == 0) { tmp /= i; C[i]++; }
	}

	/*for (int i = 1; i <= 5; i++) {
		cout << "C[" << i << "]= " << C[i] << endl;
	}*/

	//if (tmp != 1) { cout << 1 << endl; return 0; }

	int ans = 0;

	for (int i = 2; i <= 1000000; i++) {
		int q = 1;
		//cout << C[i] << " " << q << endl;
		while (C[i] >= q) {  ans++; C[i] -= q; q++; }
		
	}

	if (tmp > 1) { ans++; }

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3192
#include <cstdio>
#include <iostream>

using namespace std;

struct point {
	double x, y;
}A, B, C, P;

double crossProd(point A, point B, point C) {
	return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}

int main() {
	while (scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y, &P.x, &P.y) != EOF) {
		if (crossProd(A, B, P) > 0 && crossProd(B, C, P) > 0 && crossProd(C, A, P) > 0
		 || crossProd(A, P, B) > 0 && crossProd(B, P, C) > 0 && crossProd(C, P, A) > 0) puts("YES");
		else puts("NO");
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
typedef vector<long long> vlint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<vector<long long>> vlint2;

lint powmod(lint a, lint b, lint mod = 1000000007) {
   lint res = 1;
   for (a %= mod; b; a = a * a % mod, b >>= 1)
     if (b & 1) res = res * a % mod;
   return res;
}


int main() {
    int mod = 1000000007;
    int n, k; cin >> n >> k;
    lint cnt[k+10];

    for (int x = k; x > 0; x--){
        cnt[x] = powmod(k/x, n);
        for (int y = 2 * x; y <= k; y+=x){
            cnt[x] -= cnt[y];
        }
    }
    lint ans = 0;
    For(i, 1, k+1){
        ans += (i * cnt[i]) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}



Measured memory_bytes: 4376
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
const int N=100+20;
int a[N],b[N],c[N];
int main()
{
	int k;
	cin>>k;
	for(int i=1;i<=k;i++)
		a[i]=i;
	int h=0,l=0;
	for(int i=1;i<=k;i++)
		if(i%2==0)
			b[h++];
		else
			c[l++];
	cout<<h*l;			
			 
} 


Measured memory_bytes: 256
#define rep(i,n) REP(i,0,n)
#define REP(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll MAXN = (ll)3e2+10;
const ll DIV = (ll)1e9+7;
// ll dp[MAXN][MAXN];

ll N;
double dp[MAXN][MAXN][MAXN];
double Get(int a, int b, int c) {
   if (dp[a][b][c]>0) return dp[a][b][c];
   double ret = 0;
   if (a>0) ret += (Get(a-1,b,c) + 1)*a/(N);
   if (b>0) ret += (Get(a+1,b-1,c) + 1)*b/(N);
   if (c>0) ret += (Get(a,b+1,c-1) + 1)*c/(N);
   if (a+b+c>0) ret += 1-(double)(a+b+c)/N;
   if (a+b+c>0) ret *= (double)N/(a+b+c);
   dp[a][b][c] = ret;
   // cout<<a<<" "<<b<<" "<<c<<" "<<dp[a][b][c]<<endl;
   return dp[a][b][c];
}

int main(void) {
   // ll N;
   cin>>N;
   int A[3] = {};
   rep(i,N) {
      ll a;
      cin>>a;
      A[a-1]++;
   }
   memset(dp,0,sizeof(dp));
   printf("%.10f\n",Get(A[0],A[1],A[2]));

   return 0;
}

Measured memory_bytes: 233088
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
int a[200010];
signed main() {
	int sum = 0;
	int n;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	int ans = 0;
	rep(i, n) {
		if (a[i] == sum + 1) {
			sum++;
			ans++;
		}
	}
	if (ans == 0)cout << -1 << endl;
	else cout << n - ans << endl;
}

Measured memory_bytes: 1792
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())

SortedA = sorted(A)
A_first = SortedA[N-1]
A_second = SortedA[N-2]

for i in range(N):
    if A[i] == A_first:
        print(A_second)
    else:
        print(A_first)


Measured memory_bytes: 15088
N = int(input())
A = [int(_) for _ in input().split()]
mod = 10**9+7
is_odd = N % 2
table = [0]*N
for a in A:
    table[a] += 1
for i in range(N):
    if is_odd and i == 0 and table[i] == 1:
        continue
    if is_odd and i % 2 == 0 and table[i] == 2:
        continue
    if is_odd and i % 2 == 1 and table[i] == 0:
        continue
    if not is_odd and i % 2 == 0 and table[i] == 0:
        continue
    if not is_odd and i % 2 == 1 and table[i] == 2:
        continue
    print(0)
    exit()
print(2**(N//2) % mod)


Measured memory_bytes: 13880
import java.io.*;
import java.util.*;

class MyScanner {
    BufferedReader br;
    StringTokenizer st;

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

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

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

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

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

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

}



public class Main {

    public static PrintWriter out;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int k = sc.nextInt();
        String s = sc.next();
        if (s.length()<=k){
            out.println(s);
        }else {
            String s1 = s.substring(0,k);
            out.println(s1+"...");

        }
        out.close();
    }

}


Measured memory_bytes: 36192
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int dx = tx - sx;
	int dy = ty - sy;
	string route0 = "";
	string route1 = "";
	string route2 = "";
	string route3 = "";
	
	if( dx > 0 ) route2 += 'L'; 
	else if ( dx < 0 ) route2 += 'R';

	if( dy > 0 ){
		for( int i = 0; i < dy; ++i ) route0 += 'U';
		for( int i = 0; i <= dy; ++i ) route2 += 'U';
	} else if ( dy < 0 ){
		int cy = -dy;
		for( int i = 0; i < cy; ++i ) route0 += 'D';
		for( int i = 0; i <= cy; ++i ) route2 += 'D';
	}
	if( dx > 0 ){
		for( int i = 0; i < dx; ++i ) route0 += 'R';
		for( int i = 0; i <= dx; ++i ) route2 += 'R';
	} else if ( dx < 0 ){
		int cx = -dx;
		for( int i = 0; i < cx; ++i ) route0 += 'L';
		for( int i = 0; i <= cx; ++i ) route2 += 'L';
	}
	
	if( dy > 0 ) route2 += 'D';
	else if ( dy < 0 ) route2 += 'U';

	for( int i = 0; i < route0.l_ength(); ++i ){
		if( route0[i] == 'U' ) route1 += 'D';
		if( route0[i] == 'D' ) route1 += 'U';
		if( route0[i] == 'L' ) route1 += 'R';
		if( route0[i] == 'R' ) route1 += 'L';
	}
	for( int i = 0; i < route2.l_ength(); ++i ){
		if( route2[i] == 'U' ) route3 += 'D';
		if( route2[i] == 'D' ) route3 += 'U';
		if( route2[i] == 'L' ) route3 += 'R';
		if( route2[i] == 'R' ) route3 += 'L';
	}
	
	cout << route0 << route1 << route2 << route3 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <array>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <tuple>
#include <unordered_map>
using namespace std;

constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};
constexpr int SIZE = 4;
array<array<int, SIZE>, SIZE> field;

int ans = 6;
unordered_map<long long, int> visited;

inline bool out(int x, int y) {
	return x < 0 || y < 0 || x >= SIZE || y >= SIZE;
}

inline long long encode() {
	long long res = 0;
	for(const auto &line : field) {
		for(const auto &e : line) {
			res = (res << 2) | e;
		}
	}
	return res;
}

inline void click(int cx, int cy) {
	if(++field[cy][cx] < 5) return;

	queue<tuple<int, int>> blow;
	blow.push(make_tuple(cx, cy));

	while(!blow.empty()) {
		queue<tuple<int, int, int>> que;

		while(!blow.empty()) {
			int x, y;
			tie(x, y) = blow.front();
			blow.pop();

			field[y][x] = 0;

			for(int d = 0; d < 4; ++d) {
				que.push(make_tuple(x + dx[d], y + dy[d], d));
			}
		}

		while(!que.empty()) {
			int x, y, d;
			tie(x, y, d) = que.front();
			que.pop();

			if(out(x, y)) continue;

			if(field[y][x] == 0) {
				que.push(make_tuple(x + dx[d], y + dy[d], d));
				continue;
			}

			if(++field[y][x] == 5) blow.push(make_tuple(x, y));
		}
	}
}

inline void dfs(int depth = 0) {
	const auto code = encode();
	if(code == 0) {
		ans = depth;
		return;
	}

	if(depth + 1 >= ans) return;
	if(visited.count(code) && visited[code] <= depth) return;
	visited[code] = depth;

	for(int y = 0; y < 4; ++y) {
		for(int x = 0; x < 4; ++x) {
			if(field[y][x] == 0) continue;

			const auto tmp = field;
			click(x, y);
			dfs(depth + 1);
			field = move(tmp);
		}
	}
}

int main() {
	for(auto &line : field) {
		for(auto &e : line) {
			cin >> e;
		}
	}
	dfs();
	cout << (ans == 6 ? -1 : ans) << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1432
tokens = gets.split

stack = []

until tokens.empty?
  token = tokens.shift

  case token
  when '+'
    right = stack.pop
    left = stack.pop
    stack.push(left + right)
  when '-'
    right = stack.pop
    left = stack.pop
    stack.push(left - right)
  when '*'
    right = stack.pop
    left = stack.pop
    stack.push(left * right)
  else
    stack.push(token.to_i)
  end
end

puts stack.pop

Measured memory_bytes: 8644
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;


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

struct edge{
	int to,cap,rev;
};

vector<edge> G[1001];
bool used[1001];

void add_edge(int from,int to,int cap){
	edge e;
	e.to=to,e.cap=cap,e.rev=G[to].size();
	G[from].push_back(e);
	e.to=from;
	e.cap=0,e.rev=G[from].size()-1;
	G[to].push_back(e);
}

int dfs(int v,int t,int f){
	if(v==t)return f;
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		edge &e=G[v][i];
		if(!used[e.to] && e.cap>0){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow=0;
	while(1){
		memset(used,0,sizeof(used));
		int f=dfs(s,t,1);
		if(f==0)return flow;
		flow+=f;
	}
}

int m,n;
int b[501],k[501];


int main(void){
	while(1){
		scanf("%d %d",&m,&n);
		if(m+n==0)break;
		for(int i=0;i<=m+n+2;i++)G[i].clear();
		for(int i=0;i<m;i++){
			scanf("%d",&b[i]);
		}
		for(int i=0;i<n;i++){
			scanf("%d",&k[i]);
		}
		for(int i=0;i<m;i++){
			add_edge(0,i+1,1);
			for(int j=0;j<n;j++){
				if(gcd(b[i],k[j])>=2)add_edge(i+1,j+m+1,1);
			}
		}
		for(int i=0;i<n;i++){
			add_edge(i+m+1,m+n+2,1);
		}
		printf("%d\n",max_flow(0,n+m+2));
	}
	return 0;
}

Measured memory_bytes: 7340