akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		int[] a = new int[N];
		for(int i = 0;i < N;i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		sc.close();

		int cnt = 0;
		Arrays.sort(a);
		for(int i = 0;i < N;i++) {
			x -= a[i];
			if(x < 0)break;
			if((x >= 0 && i < N-1) || (x == 0 && i ==N-1)) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21844
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int dp[41][410][410];

int main() {

	int n, ma, mb; cin >> n >> ma >> mb;

	for (int i = 0; i < 41; i++) {
		for (int j = 0; j < 410; j++) {
			for (int k = 0; k < 410; k++) {
				dp[i][j][k] = INF;
			}
		}
	}

	dp[0][0][0] = 0;

	for (int i = 0; i < n; i++) {
		int a, b, c; cin >> a >> b >> c;
		for (int j = 0; j < 410; j++) {
			for (int k = 0; k < 410; k++) {

				//枝刈り
				if (dp[i][j][k] == INF)continue;

				//取らない
				dp[i + 1][j][k] =min(dp[i + 1][j][k], dp[i][j][k]);

				//取る
				dp[i + 1][j+a][k+b] = min(dp[i + 1][j+a][k+b], dp[i][j][k]+c);
			}
		}
	}

	int ans = INF;
	
	for (int j = 1; j < 410; j++) {
		for (int k = 1; k < 410; k++) {
			
			if (j*mb == k * ma) {
				ans = min(ans, dp[n][j][k]);
			}
			
		}
	}

	if (ans == INF) {
		cout << "-1" << endl;
	}
	else {
		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 27136
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    s = input()
    n = len(s)
    dp = [[0]*13 for i in range(n+1)]
    dp[0][0] = 1

    for i,s in enumerate(s[::-1],start = 1):
        p10 = pow(10,i-1,13)
        if s!= "?":
            for k in range(13):
                dp[i][(int(s)*p10 + k)%13] += dp[i-1][k]
                dp[i][(int(s)*p10 + k)%13] %= MOD
        else:
            for j in range(10):
                for k in range(13):
                    dp[i][(j*p10 + k)%13] += dp[i-1][k]
                    dp[i][(j*p10 + k)%13] %= MOD
    print(dp[n][5] % MOD)


if __name__=="__main__":
    main()


Measured memory_bytes: 97628
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.141592653589793
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;
ll num[ten52];
ll path[ten52];

int main(void)
{
    //double ans=0.0,d,d1,d2;
    double f,g,h,f1,f2,m,f1x,f1y,f2x,f2y,fsum,angle;
    //long long int m,n,i,j,k=0,h,save;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    //char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>f1>>f2>>h>>m;
    angle=abs(h*30-m*6+m/2);
    f1x=f1*cos((h*30+m/2)*PI/180.0f);
    f1y=f1*sin((h*30+m/2)*PI/180.0f);
    f2x=f2*cos(m*6*PI/180.0f);
    f2y=f2*sin(m*6*PI/180.0f);
    f=f1x*f1x+f1y*f1y;
    g=f2x*f2x+f2y*f2y;
    fsum=sqrt(f+g-2*f1*f2*cos(angle*PI/180.0f));
    cout<<setprecision(17)<<fsum;
    return 0;
}


Measured memory_bytes: 4200
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define pi 3.14159265
const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    double a,b,x;
    cin>>a>>b>>x;
    if(x<a*a*b/2){
        cout <<setprecision(15) <<90-atan(2*x/(a*b*b))*180/pi<<"\n";
    }
    else cout <<setprecision(15) <<atan((2*(a*a*b-x))/(a*a*a))*180/pi<<"\n";
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int h,w,d;
  cin >> h >> w >> d;
  map<int,pair<int,int>> dict;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      int a;
      cin >> a;
      dict[a] = make_pair(i+1,j+1);
    }
  }

  map<int,int> dist;
  for(int i = 1;i <= h * w;i++)dist[i] = -1;

  for(auto p:dict){
    if(dist[p.first] != -1)continue;
    dist[p.first] = 0;
    int now = p.first;
    int sum = 0;
    int y = p.second.first;
    int x = p.second.second;
    while(now + d <= h * w){
      int ny = dict[now+d].first;
      int nx = dict[now+d].second;
      sum += abs(x - nx) + abs(y - ny);
      dist[now+d] = sum;
      now += d;
      x = nx;
      y = ny;
    }
  }

  int q;
  cin >> q;
  vector<int> ans(q);
  for(int i = 0;i < q;i++){
    int l,r;
    cin >> l >> r;
    ans[i] = dist[r] - dist[l];
  }

  for(int i = 0;i < q;i++)cout << ans[i] << endl;
}

Measured memory_bytes: 11392
#include<stdio.h>
#include<string.h>

int main(){

	int i,k,x;
	char s[102];

	scanf("%d",&k);
	scanf("%s",&s);
	x=strlen(s);
	
	for(int i=0; i<k; i++){
		if (i<x) { printf("%c", s[i]);}	}
  
  if (x>k)printf("...");
 }

Measured memory_bytes: 1728
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll INFL = 1e18;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    vector<int> sum(9);
    for (int i = 0;i < n;i++){
        int a;
        cin >> a;
        sum[min(a/400, 8)]++;
    }
    int mini = 0;
    for (int i = 0;i < 8;i++){
        if (sum[i]) mini++;
    }
    cout << max(1, mini) << " ";
    cout << mini + sum[8] << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define SORT(x) (sort(x.begin(),x.end()))
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    int N,M,ans=0,A[100007],B[100007];cin >> N >>M;
    rep(i,M){
        cin >> A[i];
    }
    if(M<=N){
        cout << 0 <<endl;
        return 0;
    }
    sort(A,A+M);
    rep(i,M-1){
        B[i]=A[i+1]-A[i];
    }
    sort(B,B+M-1);
    rep(i,M-N){
        ans+=B[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define inf 100000000
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

Point median_Point(Point a,Point b){
  Vector v=a-b;
  return b+(v/2);
}

Point Convexcut(Polygon p){
  Point res(-1,-1),tmp;
  int n=p.size();
  for(int i=0;i<n/2;i++){
    if(res.x==-1){
      res=median_Point(p[i],p[i+n/2]);
    }
    else {
      tmp=median_Point(p[i],p[i+n/2]);
      if((res.x-tmp.x)>eps || (res.y-tmp.y)>eps)return Point(-1,-1);
    }
  }
  return res;
}

int main()
{
  int n;
  Polygon p;

  cin>>n;
  p.resize(n);
  for(int i=0;i<n;i++)cin>>p[i].x>>p[i].y;

  if(n%2==1){
    cout<<"NA"<<endl;
  }else {
    Point ans=Convexcut(p);
    if(ans.x==-1)cout<<"NA"<<endl;
    else printf("%.10f %.10f\n",ans.x,ans.y);
  }
  return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a[3];
    for(int i=0;i<3;i++)
        cin >> a[i];
    sort(a,a+3,greater<int>());
    cout << a[0]*10+a[1]+a[2];
}

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

int main() {
  int n, d, count=0;
  cin >> n >> d;
  int p[n][d];
  // 入力
  for(int i=0; i<n; i++){
    for(int j=0; j<d; j++){
      cin >> p[i][j];
    }
  }
  // 距離求める
	for(int i=0; i<n-1; i++){
    for(int j=i+1; j<n; j++){
      float dist=0;
      for(int k=0; k<d; k++){
        dist += pow(float (p[i][k]-p[j][k]),2.0);
      }
      dist = sqrt(dist);
      if(ceil(dist) == floor(dist)){
        count++;
      }
    }
  }
  cout << count << endl;
}

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

int main()
{
    int A,B,C,K,d,i,e,f=0;
    cin >> A>>B>>C>>K;
    int a[3];
    a[0]=A;
    a[1]=B;
    a[2]=C;
    sort(a,a+2);
    d=a[2];
    while(i<K){
        d=d*2;
        i+=1;
    }
//    cout <<a[0]+a[1]+d<<endl;
    
    cout << A + B + C + std::max({ A, B, C }) * ((1 << K) - 1)<<endl;

}

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

int dfs( int, int, int );

int BallData[10];

int main()
{

	int N, ans;

	cin >> N;

	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < 10; j++ ) {
		
			cin >> BallData[j];

			ans = dfs(0, 0, 0);

		}

		if ( ans == 0 ) {
			cout << "NO" << endl;
		}
		else {
			cout << "YES" << endl;
		}

	}
	
	return 0;

}

int dfs( int i, int Left, int Right )
{

	int ans = 0;

	if( i == 10 ) ans = 1;

	if( BallData[i] > Left ) {
		ans = dfs( i + 1, BallData[i], Right );	
	}
	if( BallData[i] > Right ) {
		ans = dfs( i + 1, Left, BallData[i] );
	}

	return ans;

}

Measured memory_bytes: 1152
Imports System
Module ABC105B
	Sub Main()
		Dim n As Integer = Integer.Parse(Console.ReadLine())
		Dim ans As Boolean = False
		For x As Integer = 0 To 25
			For y As Integer = 0 To 15
				If x * 4 + y * 7 = n
					ans = True
					Exit For
				End If
			Next
			If ans = True Then Exit For
		Next
		
		If ans
			Console.WriteLine("Yes")
		Else
			Console.WriteLine("No")
		End If
	End Sub
End Module


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;
typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    
    int cnt = 0;
    REP(i, N) {
        while (a[i] % 2 == 0) {
            a[i] /= 2;
            cnt++;
        }
    }
    print(cnt);
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define N 17
#define N1 301
using namespace std;
void DP(int);
int main(){
  int n;
  while(1){
    cin >> n;
    if(n==0) break;
    DP(n);
  }
  return 0;
}
void DP(int n){
  int dp[N][N1],c[N];
  for(int i=0;i<N;i++) dp[i][0]=1,c[i]=(i+1)*(i+1);
  for(int i=0;i<=n;i++) dp[0][i]=1;
  for(int i=1;i<N;i++){
    for(int j=1;j<=n;j++){
      if(c[i]<=j){
	dp[i][j]=dp[i-1][j]+dp[i][j-c[i]];
      }else{
	dp[i][j]=dp[i-1][j];
      }
    }
  }
  cout << dp[N-1][n] << endl;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // dp[0] = 0
  // dp[i] = dp[i-1] + (R, S, P)
  // dp[i] = dp[i-1] (T[i] == T[i-K]のとき)
  // dp[N]
  int N, K; cin >> N >> K;
  ll R, S, P; cin >> R >> S >> P;
  string T; cin >> T, T = "x" + T;
  vector<ll> dp(N+1, 0);
  string j = "X";
  for(int i = 1; i <= N; i++){
    if(i < K){
      if(T[i] == 'r'){
        dp[i] = dp[i-1] + P;
        j += "P";
      }else if(T[i] == 's'){
        dp[i] = dp[i-1] + R;
      j += "R";
      }else{
        dp[i] = dp[i-1] + S;
        j += "S";
      }
    }else{
      if(T[i] == 'r' && j[i-K] != 'P'){
        dp[i] = dp[i-1] + P;
        j += "P";
      }else if(T[i] == 's' && j[i-K] != 'R'){
        dp[i] = dp[i-1] + R;
        j += "R";
      }else if(T[i] == 'p' && j[i-K] != 'S'){
        dp[i] = dp[i-1] + S;
        j += "S";
      }else{
        dp[i] = dp[i-1];
        j += "X";
      }      
    }
  }
  cout << dp[N] << endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

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

typedef pair<int, int> P;
ll modnum = 1e9+7;

const int MAX = 1e5+5;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll m)
{
    if(n == 0) return 1;
    ll t = modpow(a, n >> 1, m);
    t = t * t % m;
    if(n & 1) t = t * a % m;
    return t; 
}

ll modinv(ll a, ll m)
{
    return modpow(a, m - 2, m);
}

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % modnum;
        inv[i] = modnum - inv[modnum%i] * (modnum / i) % modnum;
        finv[i] = finv[i - 1] * inv[i] % modnum;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % modnum) % modnum;
}

ll ans(ll n, ll k, vec a) {
    // 二項係数テーブルを作成しておく
    COMinit();

    sort(a.begin(), a.end());
    ll ans = 0;
    REP(i,0,n) {
        if(i >= k-1) {
            ans += COM(i, k-1) * a[i];
            ans %= modnum;
        }
        if(n-i-1 >= k-1) {
            ans -= COM(n-i-1, k-1) * a[i];
            ans %= modnum;
        }
    }

    return ans < 0 ? ans + modnum : ans;
}


int main()
{
    ll N, K;
    cin >> N >> K;
    vec A(N+1, -INF);
    REP(i,1,N+1) {
        cin >> A[i];
    }

    if(K >= 2 && N >= 2) {

        ASC(A);

        vec S(N+1, 0);
        REP(i,0,N) S[i+1] = (S[i] + A[i+1]) % MOD;

        vec C(N+1, 0);
        C[K-2] = 1;
        REP(i,K-2,N) {
            C[i+1] = (C[i] * (i+1)) % MOD;
            C[i+1] = (C[i+1] * modinv(i-K+3, MOD)) % MOD;
        }

        ll sum = 0;
        REP(i,K,N+1) {
            sum = (sum + C[i-2] * (S[N] - S[i-1] - S[N-i+1])) % MOD;
        }
        sum = (sum < 0 ? sum + MOD : sum);

        PR(sum);
    
    }
    else {
        PR(0);
    }

    return 0;
}

/*



*/

Measured memory_bytes: 5572
def selection(a, n):
    cnt = 0
    for i in range(n):
        flag = 0
        minj = i
        for j in range(i+1,n):
            if a[j] < a[minj]:
                minj = j
                flag = 1
        if flag == 1:
            temp = a[minj]
            a[minj] = a[i]
            a[i] = temp
            cnt += 1
    return cnt

n = int(input())
a = list(map(int, input().split()))

cnt = selection(a, n)   
ans = str(a[0])
for i in range(1,n):
    ans += ' '+str(a[i])           
print(ans)
print(cnt)


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

	double p[n];
	rep(i, n) cin >> p[i];

	double dp[n+1][n+1];
	rep(i, n+1) rep(j, n+1) dp[i][j] = 0.0;
	// dp[i][j] : コインをi枚使い、表がj枚である確率

	dp[0][0] = 1.0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= i; j++){
			if(j-1 >= 0) dp[i][j] = dp[i-1][j-1] * p[i-1] + dp[i-1][j] * (1.0 - p[i-1]);
			else dp[i][j] = dp[i-1][j] * (1.0 - p[i-1]);
		}
	}

	double ans = 0.0;
	for(int i = n / 2 + 1; i <= n; i++) ans += dp[n][i];
	cout << fixed << setprecision(11) << ans << endl;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 1000000000000000005
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	int n;
	while(~getI(n)){
		int ans=0;
		while(n){
			if(n%10==2) ans++;
			n/=10;
		}
		printf("%d\n",n==2?ans+1:ans);
	}
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ab = sorted(ab, key = lambda x: x[1])
a_cur = -1
ans = 0
for a, b in ab:
    if a_cur < a:
        ans += 1
        a_cur = b-1
    else:
        pass
print(ans)


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

int main() {
  string S; cin >> S;
  int L = S.size();
  vector<long long> v(L, 0);
  for (int i = L-1; i >= 0; i--) {
    if (i != L-1) v.at(i) = v.at(i+1);
    if (S.at(i) == 'W') v.at(i)++;
  }
  long long ans = 0;
  for (int i = 0; i < L; i++) {
    if (S.at(i) == 'B') ans += v.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2180
require 'prime'

N = gets.to_i

D = (1..N).inject(:*).prime_division.map(&:last)

ans = 0

def dcnt(num)
  D.count { |k| k + 1 >= num }
end

ans += dcnt(75)
ans += dcnt(25) * (dcnt(3) - 1)
ans += dcnt(15) * (dcnt(5) - 1)
ans += (dcnt(5) * (dcnt(5) - 1) * (dcnt(3) - 2)) / 2

puts ans


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 312345
int cnt[N] = {};
map<int, int, greater<int>> cnts, cur;
int ans[N] = {};

int main(){
	int n; scanf("%d", &n);
	REP(i, n) {
		int a; scanf("%d", &a);
		cnt[a]++;
	}
	int m = 0; // number of blocks
	REP(i, N) if(cnt[i]) m++, cnts[cnt[i]]++;

	int sm = 0;
	FOR(i, 1, n+1){
		sm += i * cnts[i];
		m -= cnts[i];
		int q = m + sm/i;
		ans[q] = i;
	}

	for(int i = N-2; i>=0; i--) if(!ans[i]) ans[i]=ans[i+1];
	FOR(i, 1, n+1){
		printf("%d\n", ans[i]);
	}
}


Measured memory_bytes: 17280
#include <bits/stdc++.h>
#define ALL(V) (V).begin(),(V).end()
using namespace std;
using ll = int64_t;
template <typename T> using V = vector<T>;

pair<long double, long double> lr_theta[300][300];
ll default_cnt[300];
pair<long double, long double> circle[300];

long double eps = 1e-5;
const long double inf = 5e15;
auto error = make_pair(-inf, -inf);

long double length(long double x, long double y) { return sqrt(x * x + y * y); }

ll solve(ll N) {
    for(ll i = 0; i < N; i++) {
        long double x, y;
        cin >> x >> y;
        circle[i] = make_pair(x, y);
    }

    sort(circle, circle + N);

    auto fix_theta = [](long double theta) { return theta < 0 ? theta + 2 * M_PI : theta; };

    ll ans = 1;
    for(ll i = 0; i < N; i++) {
        V<pair<long double, bool>> lr_lis;
        ll cur = 1;
        long double xi, yi, xj, yj;
        tie(xi, yi) = circle[i];
        for(ll j = 0; j < N; j++) {
            if(i == j) continue;
            tie(xj, yj) = circle[j];
            long double dx = xj - xi;
            long double dy = yj - yi;
            long double cen_len = length(dx, dy);
            if(2.0 < cen_len) continue;
            long double orx = -dy, ory = dx;
            long double cur_orlen = length(orx, ory);
            long double orlen = sqrt(1 - cen_len * cen_len / 4);
            (orx *= orlen) /= cur_orlen;
            (ory *= orlen) /= cur_orlen;
            long double theta1 = fix_theta(atan2(dy / 2 + ory, dx / 2 + orx));
            long double theta2 = fix_theta(atan2(dy / 2 - ory, dx / 2 - orx));
            if(theta2 < theta1) swap(theta1, theta2);
            if((theta1 + 2 * M_PI) - theta2 <= theta2 - theta1) {
                cur++;
                lr_lis.emplace_back(theta1, false);
                lr_lis.emplace_back(theta2, true);
            } else {
                lr_lis.emplace_back(theta1, true);
                lr_lis.emplace_back(theta2, false);
            }
        }
        ans = max(ans, cur);
        sort(ALL(lr_lis));
        for(auto &&ele : lr_lis) {
            cur += ele.second ? 1 : -1;
            ans = max(ans, cur);
        }
    }
    return ans;
}

int main() {
    while(true) {
        ll N;
        cin >> N;
        if(!N) break;
        cout << solve(N) << endl;
    }
    return 0;
}



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

const int N=1e5+10;
int n;
int a[2*N];
int b[2*N];

int check(int mid){
	for(int i=1;i<2*n;i++)
		if(a[i]>=mid) b[i]=1;
		else b[i]=0;
	for(int i=1;i<n;i++){	
		if(b[n-i]==b[n-i+1]) return b[n-i];
		if(b[n+i]==b[n+i-1]) return b[n+i];
	}
	return b[1];
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<2*n;i++) scanf("%d",a+i);
	int l=1,r=2*n-1;
	while(l<r){
		int mid=(l+r+1)/2;
		if(check(mid)) l=mid;
		else r=mid-1;
	}
	printf("%d\n",l);
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<set>
#include<algorithm>

using namespace std;
#define int long long

signed main(){
    int N,M;cin>>N>>M;
    set<int> A,B;
    for(int i=0;i<M;++i){
        int a,b;cin>>a>>b;
        if(a==1) A.insert(b);
        else if(b==N) B.insert(a);
    }

    bool yes = false;
    for(auto i : A){
        if(B.find(i) != B.end()){
            cout<<"POSSIBLE\n";
            return 0;
        } 
    }
    cout<<"IMPOSSIBLE\n";
}

Measured memory_bytes: 9600
unittest
{
	assert( [ "1 25 25 50" ].parse.expand.solve == 2 );
	assert( [ "4 50 50 0" ].parse.expand.solve == 312500008 );
	assert( [ "1 100 0 0" ].parse.expand.solve == 1 );
	assert( [ "100000 31 41 28" ].parse.expand.solve == 104136146 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nabc = input.front.split.to!( long[] );
	return tuple( nabc[ 0 ], nabc[ 1 ], nabc[ 2 ], nabc[ 3 ] );
}

auto solve( long n, long a, long b, long c )
{
	auto ra = a.divMod( 100 );
	auto rb = b.divMod( 100 );
	auto rab = ra.addMod( rb );
	
	// 引き分けを除いたときの勝ちと負けの確率を計算
	auto raa = ra.divMod( rab );
	auto rbb = rb.divMod( rab );
	
	// 引き分けを除いたn+m回のうち、片方がn回勝ってm回負けたときを想定
	auto ans = 0L;
	for( auto m = 0L, nm = n; m < n; m++, nm++ )
	{
		// 引き分けを含めた回数を計算
		auto nmd = nm.divMod( rab );
		
		// 引き分けを除いたn+m回になる確率を計算
		// （「引き分けを含めたn+m+d回になる確率」と「引き分けを除いたn+m回になる確率」は同じになる）
		auto p = ( nm - 1 ).combinationMod( n - 1 );							// 勝ち負けパターン数（最後だけ勝ち固定で、それ以前の順序は自由）
		auto wa = p.mulMod( raa.powMod( n ) ).mulMod( rbb.powMod( m ) );		// 高橋君が勝ったときの確率
		auto wb = p.mulMod( raa.powMod( m ) ).mulMod( rbb.powMod( n ) );		// 青木君が勝ったときの確率
		auto wab = wa.addMod( wb );
		
		// 期待値を計算して合計
		ans = ans.addMod( nmd.mulMod( wab ) );
	}
	return ans;
}

// 足し算
auto addMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( x + y ) % MOD;
}

// 掛け算
auto mulMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y % MOD;
}

// 割り算
auto divMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y.powMod!MOD( MOD - 2 ) % MOD;
}

// べき乗
auto powMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	auto a = 1L;
	for( ; 0 < y; y >>= 1 )
	{
		if( y & 1 ) a = a * x % MOD;
		x = x ^^ 2 % MOD;
	}
	return a;
}

// 階乗
auto factorialMod( long MOD = 10L ^^ 9 + 7 )( long x )
{
	static memo = [ 1L ];
	if( memo.length <= x )
	{
		auto i = memo.length;
		memo.length = x + 1;
		for( ; i <= x; i++ ) memo[ i ] = memo[ i - 1 ] * i % MOD;
	}
	return memo[ x ];
}

// 組み合わせ数
auto combinationMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x.factorialMod!MOD.divMod!MOD( y.factorialMod!MOD.mulMod!MOD( ( x - y ).factorialMod!MOD ) );
}


Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int ans=0;
  string s;
  cin>>s;
  for(int i=0;i<s.length();i++)
    ans+=(s[i]-'0');
  if(ans%9==0)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n, k;
  cin >> n >> k;
  priority_queue<int, vector<int>, greater<int>> pq;
  for(int i=0; i<n; i++){
  	int pp; cin >> pp;
    pq.push(pp);
  }
  int ans = 0;
  while(k){
    ans += pq.top();
    pq.pop();
    k--;
  }
  cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n,L;
vl a,b;

ll f(){
	vl s(n+1);
	for(int i=0;i<n;i++) s[i+1]=s[i]+b[i]-a[i]+(i?a[i-1]:0);
	for(int i=1;i<=n;i++) s[i]=max(s[i],s[i-1]);
	ll res=max(0ll,s[n]),sum=0;
	for(int i=n-1;i>=0;i--){
		sum+=b[i];
		res=max(res,s[i]+sum-2*(L-a[i]));
	}
	for(int i=0;i<n;i++) a[i]=L-a[i];
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	return res;
}

int main(){
	cin>>n>>L;
	a=b=vl(n);
	for(int i=0;i<n;i++) cin>>a[i]>>b[i];
	cout<<max(f(),f())<<endl;
}

Measured memory_bytes: 2560
/*input
6
7
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

/********************* MODULAR ARITHMETIC *******************************/

ll MOD = 1000000007;

void mod(ll &a){ if(a >= MOD) a %= MOD; }
ll add(ll a, ll b) { a += b; mod(a); return a; }
ll mul(ll a, ll b) { mod(a); mod(b); a *= b; mod(a); return a; }
ll sub(ll a, ll b) { mod(a); mod(b); a -= b; a += MOD; mod(a); return a; }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

ll inv(ll a) { return powr(a, (MOD - 2)); }

/************************************************************************/

string s;
int len;
int k;
int dp[10001][101][2];

int func(int idx, int rem, bool flag, string ans = "")
{
	if(idx == len) {
		return rem == 0;
	}

	if(dp[idx][rem][flag] > -1) {
		return dp[idx][rem][flag];
	}

	int res = 0;
	int c = 10;
	if(!flag) {
		c = s[idx] - '0';
		res = add(res, func(idx + 1, (rem + c) % k, 0));
	}

	for(int i = 0; i < c; i ++) {
		res = add(res, func(idx + 1, (rem + i) % k, 1));
	}
	return dp[idx][rem][flag] = res;
}

int main()
{
  cin >> s >> k;
  len = s.length();

  memset(dp, -1, sizeof(dp));
  ll ans = func(0, 0, 0);
  cout << sub(ans, 1);
  return 0;
}

Measured memory_bytes: 9472
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>

typedef long long ll;

using namespace std;

int main(){
    int N,sum=0;
    char S[4002];
    cin >> N;
    cin >> S;
    ll R = 0;
    ll G = 0;
    ll B = 0;
    for(int i = 0 ; i < N ; i++){
        if(S[i] == 'R' ){
            R++;
        }
        else if(S[i] == 'G'){
            G++;
        }
        else if(S[i] == 'B'){
            B++;
        }
    }
    ll cnt = R*G*B;
    for(int i = 0 ; i < N-2 ; i++){
        for(int j = i+1 ; j < N-1 ; j++){
            int k = (j - i) + j;
            if(k < N){
                if(S[i] != S[j] &&  S[j] != S[k] && S[k] != S[i]){
                    cnt--;
                }
            }
           
        }
    }
    cout << cnt;
    return 0;
}

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

string pic[220];

int main() {
	int h, w;
	string s;

	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> s;
		pic[i * 2] = s;
		pic[i * 2 + 1] = s;
	}

	for (int i = 0; i < 2 * h; i++) {
		cout << pic[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i, n) for (int i=1;i<=n;i++)
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a=floor(sqrt(n)),b,c;
  r(i, a) {
    if (n%i==0) {
      b=i;
      c=n/i;
    }
  }
  cout << b+c-2 << endl;
  return 0;
}

Measured memory_bytes: 256
from copy import deepcopy
INF=10**18
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
c=deepcopy(a)
for k in range(n):
  for i in range(n):
    for j in range(n):
      c[i][j]=min(c[i][j],c[i][k]+c[k][j])
for i in range(n):
  for j in range(n):
    if a[i][j]!=c[i][j]:
      print(-1)
      exit()
ans=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      if k==j or k==i:continue
      if c[i][j]==c[i][k]+c[k][j]:break
    else:ans+=c[i][j]
print(ans//2)

Measured memory_bytes: 77128
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long 
int main(){
    ll n;
    cin>>n;
    string a="",b="";
    for(ll i=0;i<n;i++){ 
        ll p;
        cin>>p;
        a+=p;
    }
    for(ll i=0;i<n;i++){ 
        ll p;
        cin>>p;
        b+=p;
    }
    if(a>b) swap(a,b);
    ll ans=0;
    while(a!=b){
        ans++;
        next_permutation(a.begin(),a.end());
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long int lli;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<pll> vop;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
#define REP(i,a,b) for( long long i=a;i<b;i++)
#define REPR(i,a,b) for(long long i=a;i>=b;i--)
#define adb(a) for(auto i:a) cout << i << " "; cout << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000009
#define MAX 500005;
#define PI 3.14159265358979323846


int main()
{


    fastIO;
    int test = 1;
    //cin >> test;
    while (test--)
    {
        int n;
        cin >> n;
        int h[n + 1];
        REP(i, 1, n + 1) cin >> h[i];
        int dp[n + 1];
        memset(dp, 1000001, sizeof(dp));
        dp[0] = 0;
        dp[1] = 0;
        REP(i, 2, n + 1)
        {
            dp[i] = min(dp[i], dp[i - 1] + (abs(h[i] - h[i - 1])));
            if (i - 2 >= 1) {
                dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
            }
            //cout << dp[i] << " ";
        }
        cout << dp[n] << endl;
    }
    return 0;
}



Measured memory_bytes: 1024
def dfs(word, N):
    if len(word) == N:
        print(word)
    else:
        for i in range(len(set(word))+1):
            dfs(word + chr(97+i), N)


def main():
    N = int(input())
    dfs('a', N)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4412
N = int(input())
P = []
for i in range(N):
    r, c = map(int, input().split())
    if i == 0:
        P.append(r)
    P.append(c)


def matrix_chain():
    dp = [[None for j in range(N+1)] for i in range(N+1)]
    for i in range(1, N+1):
        dp[i][i] = 0

    for l in range(2, N+1):
        for i in range(1, N-l+2):
            j = i + l - 1
            dp[i][j] = 1000000000000000
            for k in range(i, j):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+P[i-1]*P[k]*P[j])

    return dp[1][N]


def main():
    print(matrix_chain())


if __name__ == '__main__':
    main()



Measured memory_bytes: 5668
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 200002;

int t;

int n;

struct Camel
{
    int pos;
    ll x, y;
};

bool operator < (const Camel &a, const Camel &b)
{
    return a.x - a.y > b.x - b.y;
}

Camel v[N_MAX];

set <int> s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n;
        for(int i = 1; i <= n; i++)
            cin >> v[i].pos >> v[i].x >> v[i].y;
        sort(v + 1, v + n + 1);
        s.clear();
        for(int i = 1; i <= n; i++)
            s.insert(i);
        ll ans = 0;
        for(int i = 1; i <= n; i++)
            ans += v[i].y;
        int cnt = 0;
        for(int i = 1; i <= n && v[i].x - v[i].y >= 0; i++)
        {
            cnt++;
            set <int> :: iterator it = s.upper_bound(v[i].pos);
            if(it == s.begin())
                continue;
            it--;
            ans += v[i].x - v[i].y;
            s.erase(it);
        }
        for(int i = cnt + 1; i <= n; i++)
            s.insert(i);
        for(int i = n; i >= 1 && v[i].x - v[i].y < 0; i--)
        {
            set <int> :: iterator it = s.upper_bound(v[i].pos);
            if(it == s.end())
            {
                it = s.begin();
                ans += v[i].x - v[i].y;
            }
            s.erase(it);
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 17732
// finish date: 2018/08/04
#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)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


//足し算
int add(int a, int b) {
    return (int) (((ll) a + b + bigmod) % bigmod);
}

//引き算
int sub(int a, int b) {
    return (int) (((ll) a - b + bigmod) % bigmod);
}

//掛け算
int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int modpow(int a, int b) {
    if (b == 0) return 1;
    int temp = modpow(a, b / 2);
    if (b % 2 == 1) return mul(mul(temp, temp), a);
    else {
        return mul(temp, temp);
    }
}


int main() {
    string S;
    cin >> S;
    int N = S.length();
    vi pow3(N + 1, 0);
    pow3[0] = 1;
    FOR(i, 1, N + 1) {
        pow3[i] = pow3[i - 1];
        pow3[i] = mul(pow3[i], 3);
    }

    vi A(N, 0), C(N, 0), Q(N, 0);
    rep(i, N) {
        if (i > 0) A[i] = A[i - 1], C[i] = C[i - 1], Q[i] = Q[i - 1];
        if (S[i] == 'A') A[i]++;
        if (S[i] == 'C') C[i]++;
        if (S[i] == '?') Q[i]++;
    }

    int cnt = 0;
    FOR(i, 1, N - 1) {
        if (S[i] != 'B' && S[i] != '?') continue;
        int qa = (S[i] == '?') ? Q[i] - 1 : Q[i];
        int qc = Q[N - 1] - Q[i];
        int a = A[i];
        int c = C[N - 1] - C[i];

        int sideA = mul(a, pow3[qa]);
        if (qa != 0) {
            sideA = add(sideA, mul(qa, pow3[qa - 1]));
        }

        int sideC = mul(c, pow3[qc]);
        if (qc != 0) {
            sideC = add(sideC, mul(qc, pow3[qc - 1]));
        }

        cnt = add(cnt, mul(sideA, sideC));
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
using ll = long long;

int main()
{
    ll N, P, Q;
    cin >> N >> P >> Q;
    vector<ll> D(N);
    priority_queue<ll> q;
    for (ll i = 0; i < N; i++) {
        cin >> D[i];
        D[i] += i * P;
        q.push(D[i]);
    }

    vector<ll> calc(N + 1);
    calc[0] = N * (N - 1) / 2;
    for (ll i = 1; i <= N; i++) {
        calc[i] = calc[i - 1] - (N - i) * 2;
    }
    for (ll i = 0; i <= N; i++) {
        calc[i] = (N - i) * P * Q + P * calc[i];
    }
    ll sum = 0;
    for (int i = 1; i <= N; i++) {
        sum += q.top();
        q.pop();
        calc[i] += sum;
    }
    constexpr ll INF = 1LL << 60;
    ll maxi = -INF;
    for (ll i = 0; i <= N; i++) {
        maxi = max(maxi, calc[i]);
    }
    cout << maxi << endl;
    return 0;
}

Measured memory_bytes: 14636
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define db double 
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define clr(x) memset(x,0,sizeof(x))
const ll siz=1e6+7;
const ll mod=1e9+7;
ll arr[siz];
ll n,k;
ll solve(ll x)
{
    ll ans=(ll)(ceil((x-1.0)/(k-1.0)));
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s;cin>>s;
    ll ans=0;
    for(ll i=0;i<s.length();i++)if(s[i]=='+')ans++;else ans--;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
program thumbnail
  implicit none
  integer :: n, a(100) = 0, i, s, d = 1e9, x
  read(*,*) n
  read(*,*) a(1:n)
  s = sum(a(1:n))
  do i = 1, n
    if (d > abs(s-n*a(i))) then
      d = abs(s-n*a(i))
      x = i-1
    end if
  end do
  write(*,'(i0)') x
end program thumbnail

Measured memory_bytes: 768
N = int(input())
S = input()
ans = set()
for first in range(10):
    for second in range(10):
        f_flag = False
        s_flag = False
        for i in S:
            if f_flag is False:
                if int(i) == first:
                    f_flag = True
            elif s_flag is False:
                if int(i) == second:
                    s_flag = True
            else:
                ans.add(str(first)+str(second)+i)

print(len(ans))

Measured memory_bytes: 43464
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = getInputInteger(sc);
		int b = getInputInteger(sc);
        int c = getInputInteger(sc);
        int x = getInputInteger(sc);
 
        // programming
        int result = 0;
        l1: for (int i = a; i >= 0; i--) {
            l2: for (int j = b; j >= 0; j--) {
                l3: for (int k = c; k >=0; k--) {
                    if (500*i + 100*j + 50*k == x) {
                        result++;
                    }
                }
            }
        }
        output(String.valueOf(result));
	}

	public static String getInputString(Scanner sc) {
		return sc.next();
	}

	public static int getInputInteger(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	public static void output(String... params) {
		boolean isInit = true;
		String str = "";
		for (String s : params) {
			if (!isInit) {
				str += " ";
			}
			str += s;
			isInit = false;
		}
		System.out.println(str);
	}

    public static int[] toIntegerList(String s) {
        int[] ret = new int[s.length()];
        for (int i = 0; i < s.length(); i++) {
            ret[i] = Integer.parseInt(String.valueOf(s.charAt(i)));
        }
        return ret;
    }
}

Measured memory_bytes: 23124
str = input()
def hitachi(S):
    hitachi_str = [True if S[i:i+2] == 'hi' else False for i in range(0,len(S),2)]
    if all(hitachi_str):
        result = 'Yes'
    else:
        result = 'No'
    return result
print(hitachi(str))

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

const char nl = '\n';

void solve()
{
    int x, n; cin >> x >> n;
    unordered_set<int> s;
    int val;
    if (n == 0) {
        cout << x << nl;
        return;
    }
    while (n--) {
        cin >> val;
        s.insert(val);
    }
    int dist = 0;
    int best = 0;
    for (int i = x; i >= 0; --i) {
        if (s.find(i) == s.end()) {
            best = i;
            dist = x - i;
            break;
        }
    }
    for (int i = x; i < x + dist; ++i) {
        if (s.find(i) == s.end()) {
            if (i - x < dist) {
                best = i;
                break;
            }
        }
    }
    cout << best << nl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3656
fn main() {
    let mut sc = Scanner::new();
    let (x1, y1): (f64, f64) = (sc.read(), sc.read());
    let (x2, y2): (f64, f64) = (sc.read(), sc.read());
    let (x3, y3): (f64, f64) = (sc.read(), sc.read());
    let a = dist(x1, y1, x2, y2);
    let b = dist(x1, y1, x3, y3);
    let c = dist(x2, y2, x3, y3);
    let s = (a + b + c) / 2.0;
    let t = (s * (s - a) * (s - b) * (s - c)).sqrt();
    let r = t * 2.0 / (a + b + c);
    let mut max = if a > b { a } else { b };
    max = if max > c { max } else { c };

    let x = max * r / (2.0 * r + max);
    println!("{}", x);
}

fn dist(x1: f64, y1: f64, x2: f64, y2: f64) -> f64 {
    let dx = x1 - x2;
    let dy = y1 - y2;
    (dx * dx + dy * dy).sqrt()
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 4352
N = int(input())
A = list(map(int, input().split()))

G = [[] for _ in range(N)]

for i in range(N):
    G[A[i]-1].append(i)

ans = 0

for i in range(N):
    for g in G[i]:
        if g == A[i] - 1:
            ans += 1

print(int(ans/2))

Measured memory_bytes: 61804
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m, s=0;
  cin >> n >> m;
  while(m--){
    int k;
    cin >> k;
    s+=k;
  }
  if(s>n)
    cout<<-1;
  else 
    cout<<n-s;
  return 0;
}

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

int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // int t;
    // cin >> t;
    // while (t--)
    // {
        int n;
        cin >> n;
        string s;
        for(int i=0;i<n;++i)
        {
            s+="ACL";
        }
        cout << s << endl;
            
    // }
    return 0;
}


Measured memory_bytes: 3628