akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A == B && C != B) {
        cout << "Yes" << endl;
        return 0;
    } 
    if(A == C && C != B) {
        cout << "Yes" << endl;
        return 0;
    }
    if(B == C && C != A) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;

map<int, int> ct;

int main()
{
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    int a;
    for (int i = 0; i < n; i++){
        cin >> a;
        ct[a]++;
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; i++){
        cin >> a;
        if (ct[a] <= 0){
            cout << "NO";
            return 0;
        }
        ct[a]--;
    }
    cout << "YES";
    return 0;
}



Measured memory_bytes: 9696
#include<iostream>
#include<cstdlib>
#include<stack>
using namespace std;

int main()
{
    stack<int> S;
    string s;
    int a,b,x;
    while(cin>>s){
        if(s[0]=='+'){
            a=S.top();S.pop();
            b=S.top();S.pop();
            S.push(a+b);
        }else if(s[0]=='-'){
            b=S.top();
            S.pop();
            a=S.top();
            S.pop();
            S.push(a-b);
        }else if(s[0]=='*'){
            a=S.top();
            S.pop();
            b=S.top();
            S.pop();
            S.push(a*b);
        }else{
           S.push(atoi(s.c_str()));
        }
    }
    cout<<S.top()<<endl;
    return 0;
}

Measured memory_bytes: 3160
using System;
using System.Collections.Generic;
using System.Linq;

namespace Test01
{
    class Program
    {
        const int INF = 1000000009;
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[,] A = new int[3, N + 1];
            for(int i = 1; i <= 2; i++)
            {
                int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                for(int j = 1; j <= N; j++)
                {
                    A[i, j] = input[j - 1];
                }
            }
            //dp[i, j] := (i, j)のマスに行くのに得られる最大のアメの数
            int[,] dp = new int[3, N + 1];

            for (int i = 1; i <= 2; i++)
            {
                for (int j = 1; j <= N; j++)
                {
                    dp[i, j] = A[i, j] + Math.Max(dp[i - 1, j], dp[i, j - 1]);
                }
            }

            Console.WriteLine(dp[2, N]);
        }
    }
}


Measured memory_bytes: 11348
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		for(;;){
			int num1 = scan.nextInt();
			int num2 = scan.nextInt();

			if(num1 == 0 && num2 ==0){
				scan.close();
				break;
			}
			else{
				if(num1 <= num2){
					System.out.println(num1 + " " + num2);
				}
				else if(num2 < num1){
					System.out.println(num2 + " " + num1);
				}
			}
		}
	}

}

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

int n, a[110];

int main(){
  cin >> n;
  rep(i, n) cin >> a[i];
  int res = 1e9;
  for(int i = -100; i <= 100; i++){
    int sum = 0;
    rep(j, n){
      sum += pow(a[j] - i, 2);
    }
    res = min(sum, res);
  }
  cout << res << endl;
  return 0;
}


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

int main()
{
  int N, M;
  cin >> N >> M;
  
  int counter = 0;
  rep(i, N)
  {
    for (int j = i + 1; j < N; j++)
    {
      counter++;
    }
  }
  
  rep(i, M)
  {
    for (int j = i + 1; j < M; j++)
    {
      counter++;
    }
  }
  
  cout << counter << endl;

  return 0;
}


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

int main(void){
	int N,A,B;

	scanf("%d %d %d", &N, &A, &B);

	if(N == 2) printf("Borys\n");
	else if(A == 1 && B == 2) printf("Borys\n");
	else if((B-A-1)%2 == 1) printf("Alice\n");
	else if((B-A-1)%2 == 0) printf("Borys\n");

	return 0;
}

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


int main(void){
  int M, D;
  scanf("%d%d", &M,&D);
  int i,j;
  int count = 0;

  for (i = 1; i <= M; i++) {
    for (j = 1; j <= D; j++) {
      int k = j % 10;
      int l = j / 10 % 10;
      if (k >= 2 && l >= 2 && i == k * l) {
        count++;
      }
    }
  }

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

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define eps 1e-6
using namespace std;
typedef long long ll;
const ll mod = 998244353;
//const double pi = acos(-1);
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,h,w,k,tot;
int a[200005];
ll ans;
int main(){
    int i,j;
    n=read();
    for(i=1;i<=n;i++) a[i]=read();
    sort(a+1,a+n+1);
    if(n==1) {cout<<0;return 0;}
    if(n==2) {cout<<a[2];return 0;}
    ans+=a[n];
    int mx=n-1;
    for(i=1;i<=n-2;i+=2) ans+=a[mx]*2,mx--; 
    if(i-n==0) ans-=a[mx+1];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4424
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

bool m[N]={0};


int main()
{
  int n;
  scf(n);

  int a[n];

  

  ll sum=0;

  rep(i,0,n)
  scf(a[i]),sum+=a[i];

  sort(a,a+n);

  int x=0;

  x=(n&1)?a[n/2]:(a[n/2]+a[(n-2)/2])/2;

  int y=(sum+n-1)/n;

  int z=sum/n;


  sum=0;

  ll res=0,ctr=0;

  rep(i,0,n)
  sum+=((a[i]-x)*(a[i]-x)),res+=((a[i]-y)*(a[i]-y)),ctr+=(pow((a[i]-z),2));
    
    res=min(res,ctr);  

    lprin(min(sum,res));






  
}

Measured memory_bytes: 3832
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Program {
    internal static void Main(string[] args) {
        var S = ReadLine();
        var T = ReadLine();

        for (int i = 0; i < S.Length; i++) {
            var ans = true;
            var idx = 0;
            var tmp = i;
            for (int j = 0; j < S.Length; j++) {
                if (tmp >= S.Length) {
                    tmp -= S.Length;
                }

                if (S[tmp] != T[idx]) {
                    ans = false;
                }
                idx++;
                tmp++;
            }

            if (ans) {
                WriteLine("Yes");
                return;
            }
        }

        WriteLine("No");
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main(){
    int N,max=0;
    cin>>N;
    int A[2][N];
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++){
            cin>>A[i][j];
        }
    }
    for(int i=0;i<N;i++){
        int a=0,b=0;
        for(int j=0;j<N;j++){
            if(j==i){
                b=1;
                a+=A[0][j];
            }
            a+=A[b][j];
        }
        if(a>max)max=a;
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iterator>
#include <set>
#include <functional>

using namespace std;

#define DT int
#define forn(i,n)for(i=0;i<n;i++)
#define forc(i,c,n)for(i=c;i<=n;i++)
typedef vector<DT> vc;
typedef list<DT> li;

int main() {
	//ifstream fin("Text.txt");
	int i, j;
	DT a,b,c,n,m=0,h,w;
	char ch;
	cin>>h>>w;
	forn(i,h){
		forn(j,w){
			cin>>ch;
			if(ch=='#')
				m++;
		}
	}
	if(m==h+w-1){
		cout<<"Possible"<<endl;
	}
	else{
		cout<<"Impossible"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2005;
struct node{
	ll num,no;
};
node p[N];
bool cmp(node node1,node node2) {
	return node1.num<node2.num;
}
ll f[N][N];
ll n;
ll calc(ll x,ll y) {
	if (f[x][y]>-1) return f[x][y];
	if (x>y) return f[x][y]=0;
	ll now=y-x+1;
	f[x][y]=max(p[now].num*abs(p[now].no-x)+calc(x+1,y),p[now].num*abs(p[now].no-y)+calc(x,y-1));
//	cout<<x<<' '<<y<<' '<<f[x][y]<<endl;
	return f[x][y];
}
int main() {
	ll i,j,ans;
	scanf("%lld",&n);
	for (i=1;i<=n;i++) {
		scanf("%lld",&p[i].num);
		p[i].no=i;
	}
	sort(p+1,p+n+1,cmp);
	for (i=1;i<=n;i++) for (j=1;j<=n;j++) f[i][j]=-1;
//	for (i=1;i<=n;i++) cout<<p[i].no<<' '; cout<<endl;
	ans=calc(1,n);
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n,m,k;
  cin>>n>>m>>k;
  ll a[n],b[m],sum=0,arr[n],brr[m];
  int max1=0;
  for(int i=0;i<n;i++) {
      cin>>arr[i];
      sum+=arr[i];
      a[i]=sum;
      if(sum<=k) {
          max1=max(max1,i+1);
      }
  }
  //co
  sum=0;
  for(int i=0;i<m;i++) {
      cin>>brr[i];
      sum+=brr[i];
      b[i]=sum;
     // cout<<b[i]<<" ";
      if(sum<=k) {
          max1=max(max1,i+1);
      }
  }
  sum=0;
  for(int i=0;i<n;i++) {
      sum+=arr[i];
      ll z=k-sum;
      if(z<0)
         break;
      int x=lower_bound(b,b+m,z)-b;
     // cout<<x<<" "<<z<<'\n';
      if(x!=m&&b[x]==z)
      max1=max(max1,x+i+2);
      else
      max1=max(max1,x+i+1);
  }
  cout<<max1;
}

Measured memory_bytes: 9904
#include <stdio.h>

inline bool isPrime(int x) {
  for(int i=2; i*i<=x; i++) {
    if(x % i == 0) return 0;
  }
  
  return 1;
}

int main() {
  int N; scanf("%d", &N);
  
  int cnt = 0;
  for(int i=0; i<N; i++) {
    int in;
    scanf("%d", &in);
    cnt += isPrime(in);
  }
  
  printf("%d\n", cnt);
  
  return 0;
}

Measured memory_bytes: 1024
/* Akshat Sharma @akshat98 */
#include <iostream>
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp   make_pair
#define pb   push_back
#define F    first
#define S    second
#define ll   long long
#define MOD  1000000007
#define MAX  1000000001
#define vi   vector<int>
#define vl   vector<ll>
#define vpi  vector<pair<int,int> >
#define vpl  vector<pair<ll,ll> >
#define rep(i,a,b) for(i=a;i<b;i++)
#define reqp(i,a,b) for(i=a;i<=b;i++)
#define ren for(i=0;i<n;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;

ll fact[200005]{},ifact[200005]{};
ll mod(ll a,ll m=MOD){
        a%=m;
        if(a<0)a+=m;
        return a;
}

ll power(ll a,ll b,ll m=MOD){
        ll res=1;
        while(b){
                if(b%2)res=mod(1ll*res*a),b--;
                else a=mod(1ll*a*a),b/=2;
        }
        return res;
}


ll ncr(ll n,ll r){
	ll res=mod(ifact[n-r]*ifact[r]);
	res=mod(res*fact[n]);
	return res;
}

ll calc(ll x1,ll y1,ll x2,ll y2){
	return ncr(x2-x1+y2-y1,x2-x1);
}


int main()
{
	#ifndef ONLINE_JUDGE
	// freopen("input_file.txt", "r", stdin);
	//freopen("output_file.txt", "w", stdout);
	#endif
	ll i,j,k,l,n,test_case,m,r,H,W;
	test_case=1;
	//cin>>test_case;
	fact[0]=fact[1]=ifact[0]=ifact[1]=1;
	rep(i,2,200005){
		fact[i]=mod(1ll*i*fact[i-1]);
		ifact[i]=power(fact[i],MOD-2);
	}
	while(test_case--){
		cin>>H>>W>>n;
		vl dp(n);
		vpi vec(n);
		ren cin>>vec[i].F>>vec[i].S;
		sort(ALL(vec),[](const pii &a, const pii &b){
			return ((a.F < b.F) || ((a.F == b.F) && (a.S < b.S)));
		});
		ll tans=0;
		rep(i,0,n){
			ll temp=0;
			rep(j,0,i){
				if((vec[j].F <= vec[i].F) && (vec[j].S <= vec[i].S)){
					temp=mod(temp+mod(dp[j]*calc(vec[j].F,vec[j].S,vec[i].F,vec[i].S)));
				}
			}
			dp[i]=mod(calc(1,1,vec[i].F,vec[i].S)-temp);
			tans=mod(tans+mod(dp[i]*calc(vec[i].F,vec[i].S,H,W)));
		}
		cout<<mod(calc(1,1,H,W)-tans)<<"\n";

	}
	
	return 0;
}

Measured memory_bytes: 3456
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(read())

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


for i in range(n, n*n, 1):
    if is_prime(i):
        break

print(i)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  vector<int> h(N);
  int M;
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
    M = max(M, h.at(i));
  }
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    int memo = 0;
    for (int j = 0; j < N; j++) {
      if (h.at(j) >= i) {
        memo = 1;
      }
      else {
        ans += memo;
        memo = 0;
      }
    }
    ans += memo;
  }
  cout << ans << endl;
}

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

int main(){
  int N,Di,Dj;
  cin >> N;
  vector<int> zoro(N);
  for(int i=0;i<N;i++){
    cin >> Di >> Dj;
    if(Di==Dj){
      zoro.at(i)=1;
    }
    if(i>=2){
      if(zoro.at(i-2)+zoro.at(i-1)+zoro.at(i)==3){
        cout << "Yes" <<endl;
        i=N;
      }
    }
    if(i==N-1){
      cout << "No" <<endl;
    }
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
 
int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    int dp[3][n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[0][0]=a[0];
    dp[1][0]=b[0];
    dp[2][0]=c[0];
    for(int i=1;i<n;i++)
    {
        dp[0][i]=a[i]+max(dp[1][i-1],dp[2][i-1]);
        dp[1][i]=b[i]+max(dp[0][i-1],dp[2][i-1]);
        dp[2][i]=c[i]+max(dp[0][i-1],dp[1][i-1]);
    }
    cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<"\n";
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y;
        for (y = 0; y < x; y++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            int d = 0;
            int e = 0;
            int f = 0;
            if (a > b) {

                d = b;
                b = a;
                a = d;
            }
            if (b > c) {
                d = c;
                c = b;
                b = d;
            }
            if (a > b) {
                d = b;
                b = a;
                a = d;
            }
            e = a * a + b * b;
            f = c * c;
            if (e == f) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }

    }
}



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

using namespace std;

int main()
{
  uint64_t N, M;
  cin >> N >> M;
  
  vector<uint64_t> k(M);
  vector<uint64_t> s(M, 0);
  for (uint64_t m = 0; m < M; ++m) {
    cin >> k[m];
    
    for (uint64_t i = 0; i < k[m]; ++i) {
      uint64_t x;
      cin >> x;
      s[m] |= 1 << (x - 1); 
    }
  }
  
  vector<uint64_t> p(M);
  for (uint64_t m = 0; m < M; ++m) {
    cin >> p[m];
  }
  
  uint64_t count = 0;
  for (uint64_t bs = 0; bs < (1 << N); ++bs) {
    bool flag = true;
    
    for (uint64_t m = 0; m < M; ++m) {
      if (bitset<10>(bs & s[m]).count() % 2 != p[m]) {
        flag = false;
        break;
      }
    }
    
    if (flag) { ++count; }
  }
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
	
   Scanner sc = new Scanner(System.in);
   
    String S = sc.next();
    int n = S.length();
    int ans = 1;
    
    for(int i=0; i<n; i++) {
    	if(i % 2 == 0) {
    		if((S.charAt(i) != 'R') && (S.charAt(i) != 'U') && (S.charAt(i) != 'D')) {
    			ans = 0;
    		}
    	}
    	if(i % 2 == 1) {
    		if((S.charAt(i) != 'L') && (S.charAt(i) != 'U') && (S.charAt(i) != 'D')) {
    			ans = 0;
    	}
    }
    }
      if(ans == 1){
        System.out.println("Yes");
      }else{
        System.out.println("No");
}
    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

ll wa(ll i) {
    ll ans = 0;
    while(i) {
        ans += i%10;
        i/=10;
    }
    return ans;
}
int main() {
    int a, n, m; cin >> a >> n >> m;
    int cnt = 0;
    REP(i,1,100) {
        ll y = i;
        ll x = pow((ll)(y+a),n);
        if(x>m) break;
        if(wa(x)==y) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3284
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        List<Integer> cost = new ArrayList<>();
        
        for(int i = 0; i < 3; i++){
            cost.add(sc.nextInt());
        }
        cost.add(cost.get(0));
        Collections.sort(cost);
        
        int totalCost = 0;
        for(int i = 1; i < cost.size(); i++){
            totalCost += cost.get(i) - cost.get(i - 1);
        }
        
        System.out.println(totalCost);
        
    }
}


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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N, K;
VL A;
map<ll, ll> memo;

int main() {
    cin >> N;
    ll ans = 0;
    REP(i, N) {
        CINT(a);
        while(!(a % 2)) {
            ans++;
            a /= 2;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int solve(int N , int s[] , int c[]){
		for(int n = 0 ; n <= 1000 ; ++n){
			String st = String.valueOf(n);
			if(st.length() != N){
				continue;
			}
			boolean f = true;
			for(int i = 0 ; i < s.length ; ++i){
				if(st.charAt(s[i] - 1) - '0' != c[i]){
					f = false;
				}
			}
			if(f)return n;
		}
		return -1;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int s[] = new int[M];
		int c[] = new int[M];
		for(int i = 0 ; i < M ; ++i){
			s[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		System.out.println(solve(N, s, c));
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
using ll=long long;

struct edge{
  int to;
  ll cost;
};

vector<edge>tree[100010];
ll cost_k[100010];//Kからのコスト

void dfs(int v, int par, ll dist){
  cost_k[v]=dist;

  for (int i=0;i<(int)tree[v].size();i++){
    if (tree[v][i].to==par)continue;
    dfs(tree[v][i].to,v,dist+tree[v][i].cost);
  }
}

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

  for (int i=0;i<N-1;i++){
    int a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    tree[a].push_back({b,c});
    tree[b].push_back({a,c});
  }

  int Q,K;
  cin >> Q >> K;
  K--;

  dfs(K,-1,0);

  for (int j=0;j<Q;j++){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    cout << cost_k[x]+cost_k[y] << endl;
  }
  
}

Measured memory_bytes: 17408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, k;
int s[110], b;

int main(){
	while (cin >> n >> k&&n + k){
		REP(i, k)cin >> s[i];
		REP(i, n){
			REP(j, k){
				cin >> b;
				s[j] -= b;
			}
		}
		REP(i, k){
			if (s[i] < 0){
				cout << "No" << endl;
				break;
			}
			if (i == k - 1)cout << "Yes" << endl;
		}
	}
}

Measured memory_bytes: 1156
using System;
using System.Collections.Generic;
using System.Linq;



namespace Test
{
    class MainClass
    {
        static void Main(string[] args) {
            string s = Console.ReadLine();
            int ans = 0;
            for (int i = 0; i < s.Length; i++) {
                if (s[i] == '+')  {
                    ans++;
                }
                else {
                    ans--;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
// 
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

vector<char> StoVec(string s) {
    int len = s.length();
    vector<char> v(len);
    int i;
    rep(i, len) {
        v[i] = s[i];
    }
    return v;
}

string VectoStr(vector<char> v) {
    int len = v.size();
    string s;
    int i;
    rep(i, len) {
        s += v[i];
    }
    return s;
}

int main() {
    string S;
    int Q, i, T, F;
    char C;
    cin >> S;

    vector<char> v = StoVec(S);
    bool is_reverse = false;
    cin >> Q;

    for (i = 0; i < Q; i++) {
        cin >> T;
        if (T == 1) {
            is_reverse = !is_reverse;
        } else if (T == 2) {
            cin >> F >> C;
            if (F == 1) {
                if (is_reverse) {
                    v.push_back(C);
                } else {
                    v.insert(v.begin(), C);
                }
            } else if (F == 2) {
                if (is_reverse) {
                    v.insert(v.begin(), C);
                } else {
                    v.push_back(C);
                }
            }
        }
    }

    if (is_reverse) {
        reverse(v.begin(), v.end());
    }

    cout << VectoStr(v) << endl;

    return 0;
}


Measured memory_bytes: 1724
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,ans=0,a[20],b[20];
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n; i++) {
    cin >> b[i];
  }
  for(int i=0; i<n; i++) {
    if(a[i]>b[i]) {
      ans+=a[i]-b[i];
    }
    else {
      ans+=0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>

using namespace std;

typedef pair<int, int> pii;

int n, m, k;
int amat[5000][5000];
int vtx[5000];
vector< vector<int> > adj(5000);
vector<int> mal;

int solve(){
	
	for(int i=0; i<n; ++i){
		vtx[i] = INT_MAX;
	}

	for(int s=0; s<k; ++s){
		
		int vtxt[5000];
		
		for(int i=0; i<n; ++i){
			vtxt[i] = INT_MAX;
		}
		
		priority_queue<pii, vector<pii>, greater<pii> > qu;
		qu.push(make_pair(0, mal[s]));
		vtxt[mal[s]]=0;
		
		while(!qu.empty()){

			int now = qu.top().second, nxt;
			qu.pop();

			for(int i=0; i<adj[now].size(); ++i){
				
				nxt = adj[now][i];
					
				if( vtxt[nxt] > vtxt[now] + amat[now][nxt]){
				
					vtxt[nxt] = vtxt[now] + amat[now][nxt];
					qu.push( make_pair(vtxt[nxt], nxt) );
				}

			}
		}

		for(int i=0; i<n; ++i){
			vtx[i] = min(vtx[i], vtxt[i]);
		}
	}

	int ma = -1;

	for(int p=0; p<n; ++p){
		for(int i=0; i<adj[p].size(); ++i){
			
			int q = adj[p][i];
			ma = max(ma, min(vtx[p], vtx[q]) + (1 + amat[p][q] + abs(vtx[p]-vtx[q]))/2 );
		}
	}

	return ma;
}

int main(){

	cin >> n >> m >> k;

	for(int i=0; i<m; ++i){
		
		int a, b, l;
		cin >> a >> b >> l;
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
		amat[a][b] = amat[b][a] = l;
	}

	for(int i=0; i<k; ++i){

		int s;
		cin>>s;
		mal.push_back(--s);
	}

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 61848
#include <iostream>
#include <cstdlib>

using namespace std;

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

    while(n > 0)
    {
        if (n % 10 == 7)
        {
            cout << "Yes" << endl;
            return 0;
        }
        else
            n = n / 10;
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
#define modmod 1000000007

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

/*
int N;
ll W;
const int MAX_N = 100;
const ll MAX_W = 1000000000;
ll w[MAX_N],v[MAX_N];

///////////// 深さ優先探索 (TLEした) //////////////////
// i番目以降の品物から重さの輪がj以下になるように選んだ時の
// 取りうる価値の総和の最大値を返す関数
ll rec(ll i, ll j){
    ll res;
    if(i == N){
        // 品物がもう残っていないときは、価値の和の最大値は0で確定
        res = 0;
    }else if(j < w[i]){
        // 残りの容量が足りず品物iを入れられないので、入れないパターンだけ処理
        // i+1 以降の品物のみを使った時の最大値をそのままこの場合の最大値にする。
        res = rec(i+1,j);
    }else{
        // 品物iを入れるか入れないか選べるので、両方試して価値の和が大きいほうを選ぶ
        res=max(rec(i+1, j), rec(i+1, j-w[i])+v[i]);
    }
    return res;
}
*/
///////////// メモ化再帰 ///////////////////

// メモ化テーブル
// dp[i][j]はi番目以降の品物から重さの和がj以下になるように選んだ時の価値の和の最大値を表す。
// -1なら未決定
// で、やろうとしたけど、Wが大きすぎるのでメモリが足りない。size of array is too largeになってしまう。
// と思ったら、v自体はintでいけるのかなこれ。→ダメだった。

/*
ll dp[MAX_N + 1][MAX_W + 1];

ll rec_dp(int i, ll j){

}*/

/////////// 漸化式 /////////////

// DPテーブル
// dp[i][j]はi番目以降の品物から重さの和がj以下になるように選んだ時の価値の和の最大値を表す。


int main(){
    int N,X;
    cin >> N >> X;
    int m[N];
    int nokori = X;
    int small = 10000;
    for(int i= 0; i < N; i++){
        cin >> m[i];
        nokori = nokori - m[i];
        if(small > m[i]){
            small = m[i];
        }
    }
    int result = N;
    result += nokori/small;

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//
int main() {
	cin >> N;
	vl A(N);
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	for (i = 0; i < N-1; i++) {
		if (A[i] == A[i + 1]) {
			cout << "NO";
			exit(0);
		}
	}
	cout << "YES";
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    //
    string strA, strB, strC;
    int indexA = 0;
    int indexB = 0;
    int indexC = 0;
    string turn = "a";
    string kekka;
 
    cin >> strA >> strB >> strC;
 
    while (true) {
        if (turn == "a") {
            if (strA.size() == indexA) {
                cout << "A";
                return 0;
            }
            turn = strA.at(indexA);
            indexA++;
        } else if (turn == "b") {
            if (strB.size() == indexB) {
                cout << "B";
                return 0;
            }
            turn = strB.at(indexB);
            indexB++;
        } else if (turn == "c") {
            if (strC.size() == indexC) {
                cout << "C";
                return 0;
            }
            turn = strC.at(indexC);
            indexC++;
        }
    }
    //
}

Measured memory_bytes: 3552
#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 MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);

int main(){
  char c;
  cin >> c;
  c++;
  cout << c << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	vector<int> A(N), B(N);
	rep(i,N)cin>>A[i]>>B[i];
	sort(all(A));
	sort(all(B));
	int ans = 0;
	if(N%2 == 0){
		ans = (B[N/2] + B[N/2-1]) - (A[N/2] + A[N/2-1])+1;
	}else{
		ans = B[N/2] - A[N/2]+1;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
using p = pair<long long, int>;
#define INF 100000000

int main(){
    int s,w;
	cin >> s >> w;
	
	if(s <= w)cout << "unsafe" <<endl;
	else cout << "safe" << endl;
	
}

Measured memory_bytes: 3600
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//D
int main(void) {
  int n, k, i, cou=0, tmp=0;
  scanf("%d", &n);
  int d[n];
  for(i=0; i < n; i++){
    scanf(" %d",&d[i]);
    tmp+=d[i];
  }
  for(i=0; i < n; i++){
    cou+=(tmp-d[i])*d[i];
  }
  printf("%d",cou/2);
}

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

// using block
#pragma region using
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using ii=pair<int,int>;
#pragma endregion

// macro block
#pragma region macro
#define INF 2e9
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define ALL(v) (v).begin(),(v).end()
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SZ(v) ((ll)(v).size())
#define PB push_back
#define MP make_pair
#define F first
#define S second
#pragma endregion

const ll MOD = 1e9 + 7;

map<ll, int> prime_division(ll n) {
    map<ll, int> factors;
    for (ll base = 2; base * base <= n; ++base) {
        int exp = 0;
        while (n % base == 0) {
            n /= base;
            exp++;
        }
        factors[base] = exp;
    }
    if (n > 1) factors[n] = 1;
    return factors;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // write your code here
    ll n;cin>>n;
    // n meets the condition
    int ans=1;
    // k that cannot divide n
    // the number of divisors of n - 1
    if (n>2LL){
        map<ll,int> divs=prime_division(n-1);
        int subans=1;
        for(auto e:divs){
            subans*=(e.S+1);
        }
        ans+=subans-1;//don't count 1
        for (ll k=2LL;k*k<=n;++k) {
        // k that can divide n
        // continue dividing n with k and mod k of it 
            if(n%k==0LL){
                ll nn=n;
                while(nn%k==0LL)nn/=k;
                if(nn%k==1LL)ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 61312
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <stdio.h>
#include <queue>
#define pb push_back
#define ppb pop_back
#define nd second
#define st first
#define ll long long
#define pi 3.1415926535897932384626433832795028841971
using namespace std;

int n;
int res; 

int check(int x)
{
	for (int i = 2; i * i <= x; i++)
		if (x % i == 0)
			return false; 
	return true; 
}

int main()
{
	cin >> n;
	
	for (int i = 2; i <= 55555; i++)
	{
		if(i%5 == 1 && check(i))
		{
			cout << i;
			res++;
			if(res == n) 
				break;
			else
				cout << " "; 
		}
	}
	cout << endl; 
	return 0; 
}

Measured memory_bytes: 256
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
H=[2,4,5,7,9]
P=[0,1,6,8]
B=[3]
if n%10 in H:
  print("hon")
elif n%10 in P:
  print("pon")
else:
  print("bon")

Measured memory_bytes: 9180
// AOJ 2431
#include<cstdio>
#include<algorithm>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef long long ll;

ll n, dat[(1<<18)-1];
int sz;

void init()
{
	sz = 1;
	while( sz < n )
		sz <<= 1;

	rep( i, (sz<<1)-1 )
		dat[i] = 0;

	return;
}

void update( int k, ll x )
{
	k += sz-1;
	dat[k] = x;

	while( k )
	{
		k = (k-1)>>1;
		dat[k] = std::max( dat[(k<<1)+1], dat[(k<<1)+2] );
	}

	return;
}

ll query( int a, int b, int k, int l, int r )
{
	if( r <= a || b <= l )
		return 0;
	else if( a <= l && r <= b )
		return dat[k];
	else
		return std::max( query( a, b, (k<<1)+1, l, (l+r)>>1 ), query( a, b, (k<<1)+2, (l+r)>>1, r ) );
}

int main()
{
	scanf( "%lld", &n );
	ll ans = 0;
	init();
	rep( i, n )
	{
		int x;
		scanf( "%d", &x );
		update( x, query( 1, x+1, 0, 0, sz ) + x );
		ans = std::max( ans, dat[x+sz-1] );
	}

	printf( "%lld\n", (n*(n+1)>>1)-ans );

	return 0;
}

Measured memory_bytes: 3072
n,m,k=map(int,input().split())
par=[-1]*n

def find(x):
  if par[x]<0:
    return x
  else:
    par[x]=find(par[x])
    return par[x]

def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return False
  else:
    if par[x]>par[y]:
      x,y=y,x
    par[x]+=par[y]
    par[y]=x
    return True

def same(x,y):
  return find(x)==find(y)

def size(x):
  return -par[find(x)]

F=[-1]*n
for _ in range(m):
  a,b=map(int,input().split())
  unite(a-1,b-1)
  F[a-1]-=1
  F[b-1]-=1
for _ in range(k):
  a,b=map(int,input().split())
  if same(a-1,b-1):
    F[a-1]-=1
    F[b-1]-=1
for i in range(n):
  F[i]+=size(i)
print(*F)


Measured memory_bytes: 13420
import java.util.Scanner;

/**
 * 解説通り実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long n = scanner.nextLong();
			long s = scanner.nextLong();
			if (n < s) {
				System.out.println(-1);
			} else if (n == s) {
				System.out.println(n + 1);
			} else {
				int sqrtN = (int) Math.sqrt(n);
				for (int b = 2; b <= sqrtN; b++) {
					if (s == f(b, n)) {
						System.out.println(b);
						return;
					}
				}
				for (int p = sqrtN; p >= 1; p--) {
					long b = (n - s) / p + 1;
					if ((b > sqrtN) && (b > p) && (s == f(b, n))) {
						System.out.println(b);
						return;
					}
				}
				System.out.println(-1);
			}
		}
	}

	/**
	 * @param b
	 * @param n
	 * @return f(b,n)
	 */
	private static long f(long b, long n) {
		if (n < b) {
			return n;
		} else {
			return f(b, n / b) + n % b;
		}
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define inl(a) cin >> a
#define prl(a) cout << a << " "
#define outl(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
#define tddd tuple<double,double,double>
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<int,pair<int,int> > >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define N 405
typedef long long int ll;
ll sum[N];
ll dp[N][N];
ll total(int a,int b)
{
    ll x=sum[b];
    if(a>0)
        x-=sum[a-1];
    return x;
}
ll fun(int a,int b)
{
    if(a==b)
        return 0;
    if(a==b-1)
        return total(a,b);
    if(dp[a][b]>0)
        return dp[a][b];
    dp[a][b]=fun(a+1,b);
    int i;
    for(i=a;i<b;i++)
        dp[a][b]=min(dp[a][b],fun(a,i)+fun(i+1,b));
    dp[a][b]+=total(a,b);
    return dp[a][b];
}
int main()
{
    int i,n;
    in(n);
    vi v(n);
    read(v,i,n);
    sum[0]=v[0];
    lp(i,1,n)
        sum[i]=sum[i-1]+v[i];
    outl(fun(0,n-1));
}









Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
template<class T> T choka_min(set<T> &S, const T &x){
    return *S.upper_bound(x);
}
template<class T> T miman_max(set<T> &S, const T &x){
    typename set<T>::iterator it = S.lower_bound(x);
    it--;
    return *it;
}
ll N;
ll s[30303];
set<ll>S[10];
ll flg[1000];

int main(){
    rep(i, 10){
        S[i].insert(-INF);
        S[i].insert(INF);
    }

    cin >> N;
    rep1(i, N){
        char c;
        cin >> c;
        s[i] = c - '0';
        S[s[i]].insert(i);
    }
    rep1(i, N)rep(j, 10)rep(k, 10)if(choka_min(S[j], i) != INF && miman_max(S[k], i) != -INF){
        flg[j * 100 + s[i] * 10 + k] = 1;
    }
    ll ans = 0;
    rep(i, 1000)ans += flg[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    const int MAX_S = 100001, MOD = 1000000007;
    string S;
    cin >> S;
    int N = S.size();
    ll dp[MAX_S][4] = {};
    dp[0][0] = 1;
    REP(i, N) {
        char c = S[i];
        REP(j, 4) {
            dp[i + 1][j] = (c == '?' ? 3LL : 1LL) * dp[i][j];
            if (j > 0 && (c == '?' || c == "ABC"[j - 1])) {
                dp[i + 1][j] += dp[i][j - 1];
            }
            dp[i + 1][j] %= MOD;
        }
    }
    cout << dp[N][3] << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
	int h, n;
	cin >> h >> n;
	vi a(n), b(n);
	rep (i, n) cin >> a[i] >> b[i];

	vll dp(n + 1, vl(h + 20000, INF));
	dp[0][0] = 0;
	rep (i, n) {
		for (int j0 = 0; j0 < a[i]; j0++) {
			ll mi = INF;
			for (int k = 0; j0 + a[i] * k <= h + 11111; k++) {
				int j = j0 + a[i] * k;
				chmin(dp[i + 1][j], min(dp[i][j], mi));
				mi = min(mi + b[i], dp[i][j] + b[i]);
			}
		}
	}

	/*
	rep (i, n + 1) {
		rep (j, h + 3) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	//*/

	ll ans = INF;
	for (int i = h; i < dp[n].size(); i++) {
		chmin(ans, dp[n][i]);
	}
	cout << ans << endl;

}

Measured memory_bytes: 236800
#include <iostream>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)

int a[100001] = {};
int c[100][100] = {};

int main()
{
	int h, w, n; cin >> h >> w >> n;
	rep(i, 0, n)cin >> a[i];
	bool r = true;
	int H = 0, W = 0;

	rep(i, 0, n) rep(j, 0, a[i]) {
		c[H][W] = i + 1;

		W = r ? W + 1 : W - 1;

		if (W >= w) {
			r = false;;
			H++;
			W--;
		}
		else if (W < 0) {
			r = true;
			H++;
			W++;
		}
	}

	rep(i, 0, h)rep(j, 0, w) {
		cout << c[i][j];
		cout << ((j != w - 1) ? " " : "") << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
const int  M = 1e9 + 7;

vector<vector<double>> dp;

double f(int n, int heads, vector<double> &v)
{

	if(n == 0)
	{
		if(2*heads > v.size())
			return 1;
		else
			return 0;
	}

	if(dp[n][heads] != -1)
		return dp[n][heads];
	double t1 = (dp[n-1][heads + 1] == -1) ? f(n-1, heads + 1, v) : dp[n-1][heads+1];
	double t2 = (dp[n-1][heads] == -1) ? f(n-1, heads, v) : dp[n-1][heads];
	
	return dp[n][heads] = v[n-1] * t1  + (1-v[n-1])*t2;
}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, i, j, wt, m;
	
	cin >> n;
	vector<double> v(n);
	for(i = 0; i < n; i++)
		cin >> v[i];

	dp.resize(n + 1);
	for(i = 0; i <= n; i++)
		dp[i].resize(n + 1, -1);

	cout << setprecision(10) << f(n, 0, v);
}


Measured memory_bytes: 74352
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

ll a[N];
int main()
{
	int n;
	cin >> n;
	map<ll, ll> mp;
	ll s = 0;
	for(int i = 1; i <= n; i ++)
	{
		cin >> a[i];
		mp[a[i]] ++;
		s += a[i];
	}
	int q;
	cin >> q;
	for(int i = 1; i <= q; i ++)
	{
		ll x, y;
		cin >> x >> y;
		s -= mp[x]*x;
		s += mp[x]*y;
		mp[y] += mp[x];
		mp[x] = 0;
		cout << s << '\n';
	}





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 10268