akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define I INT32_MAX
#define IM INT_MIN
#define MOD 1000000007
#define ll long long
#define lli long long int
#define rep(i,n) for (int i = 0; i < n; i++)
#define repk(i,k,n) for (int i = k; i <= n; i++)
#define repr(i,k,n) for (int i = k; i >= n; i--)
#define all(v) (v).begin(),(v).end()
typedef vector<int> vi;
typedef set<int> si;

void printlcs(string s, string t, ll n, ll m) {
	ll dp[n + 1][m + 1];
	rep(i, n + 1) {
		rep(j, m + 1) {
			if (i == 0 or j == 0) {
				dp[i][j] = 0;
			}
			else if (s[i - 1] == t[j - 1]) {
				dp[i][j] = 1 + dp[i - 1][j - 1];
			}
			else {
				dp[i][j] = max(dp[i - 1][j] , dp[i][j - 1]);
			}
		}
	}

	ll i = n;
	ll j = m;
	string ans;
	while (i > 0 and j > 0) {
		if (s[i - 1] == t[j - 1]) {
			ans.push_back(s[i - 1]);
			i--;
			j--;
		}
		else {
			if (dp[i - 1][j] > dp[i][j - 1]) {
				i--;
			}
			else {
				j--;
			}
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}

void solve() {
	string s, t;
	cin >> s >> t;
	ll n = s.length();
	ll m = t.length();
	printlcs(s, t, n, m);
}

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

	int t = 1;
	// cin >> t;
	while (t--)
		solve();

}






Measured memory_bytes: 73988
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0070
{
    public class Program

    {
        public static int[,] memo = new int[11, 331];
        public static bool[] m = new bool[10];

        public static void Main(string[] args)
        {
            init();
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) return;

                int[] items = Array.ConvertAll(line.Trim().Split(' '), e => int.Parse(e));
                if (items[1] > 330) Console.WriteLine(0);
                else Console.WriteLine(memo[items[0], items[1]]);
            }
        }

        private static void init()
        {
            for (int i = 1 ; i <= 10 ; i++) { GetPermutation(i, 1, 0); }
        }

        private static void GetPermutation(int n, int k, int sum)
        {
            if (n < k) memo[n, sum]++;
            else
            {
                for (int i = 0 ; i <= 9 ; i++)
                {
                    if (!m[i])
                    {
                        m[i] = true;
                        GetPermutation(n, k + 1, sum + i * k);
                        m[i] = false;
                    }
                }
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 13960
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

struct Task {
  ll A,B;
};

bool operator<(const Task& left, const Task& right) {
  if(left.B==right.B) return left.A > right.A;
  return left.B < right.B;
}

int main(int argc, const char * argv[]) {
  ll i,j;
  ll N;
  cin >> N;
  vector<Task> tasks(N);
  for(i=0;i<N;i++){
    cin >> tasks[i].A >> tasks[i].B;
  }
  sort(tasks.begin(),tasks.end());
  ll total = 0;
  for(i=0;i<N;i++){
    total += tasks[i].A;
    if(total>tasks[i].B){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  
  return 0;
}

Measured memory_bytes: 3328
/*
     _              ,_,                 
    / \   _ __, ___,| |__   __ _,_ __  
   / ^ \ | '_ \/ _ \| '_ \ / _` | /_/  
  /-/-\-\|-| |--| |-|-|_)-|-(_|-|-|    
 /_/   \_\_| |__| |_|_.__/ \__,_|_|    
 
*/
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(a)       (a).begin(),(a).end()
#define rep(i,a,n)   for(int i=a ; i<n ; i++)
 
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<ll,ll> mii;
typedef map<char,ll> mci;
 
ll gcd(ll a, ll b){
	if(b==0)return a;
	else return gcd(b, a%b);
}

signed main(){
    ll test=1;
    // cin>>test;
    while(test--){
        ll n, k; cin>>n>>k;
        vi h(n+1, 0);
        rep(i, 1, n+1)cin>>h[i];
        vi dp(n+1, 0);
        for(int i=2; i<=n; i++){
        	ll mn=INT_MAX;
        	for(int j=1; j<=k; j++){
        		if(i-j>0){
        			ll x=dp[i-j]+abs(h[i]-h[i-j]);
        			mn=min(mn, x);
        		}
        	}
        	dp[i]=mn;
        }
        cout<<dp[n]<<endl;
    }
        
}

Measured memory_bytes: 4852
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#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 ALL(a) a.begin(), a.end()

int main() {
  int N;
  cin >> N;
  cout << 180 * (N - 2) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        for(int i = 1; i <= 9; i++){
        	for(int j = 1; j <= 9; j++){
            	if(i * j == n){
                	System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
	}
}

Measured memory_bytes: 35892
class Dice:
    def __init__(self, nums):
        self.nums = nums
    def rotate(self, direction):
        nums = self.nums
        if direction=="E":
            self.nums = [nums[3], nums[1], nums[0], nums[5], nums[4], nums[2]]
        elif direction=="W":
            self.nums = [nums[2], nums[1], nums[5], nums[0], nums[4], nums[3]]
        elif direction=="N":
            self.nums = [nums[1], nums[5], nums[2], nums[3], nums[0], nums[4]]
        elif direction=="S":
            self.nums = [nums[4], nums[0], nums[2], nums[3], nums[5], nums[1]]

    def upper_num(self):
        return self.nums[0]

dice = Dice(list(map(int, input().split())))
dirs = list(input())
for i in range(len(dirs)):
    dice.rotate(dirs[i])

print(dice.upper_num())

Measured memory_bytes: 7728
#include<iostream>
using namespace std;
int main()
{
  string S;
  string T;
  cin >> S >> T;
  
  if(S[1]==T[1]&&S[2]==T[2]&&S[0]==T[0]){
    cout << "3";
  }else if(S[1]==T[1]&&S[2]==T[2] || S[1]==T[1]&&S[0]==T[0] || S[0]==T[0]&&S[2]==T[2]){
    cout << "2";
  } else if(S[1]==T[1]||S[0]==T[0] || S[2]==T[2]){
    cout <<"1";
  } else{
      cout << "0";
    }
   
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;


int main()
{
	int n,max1=0,max2=0,max_i;
	cin >> n;
	
	vector<int> a(n);
	
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(a[i] >= max1){
			max1 = a[i];
			max_i = i;
		}
	}
	
	sort(a.begin(),a.end());
	
	for(int i=0;i<n;i++){
		if(i == max_i){
			cout << a[n-2] << endl;
		}else cout << max1 << endl;
	}

	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solve(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int sum=0;
    for(int i=0;i<k;i++){
        sum+=arr[i];
    }
    cout<<sum<<"\n";
}

int32_t main(){
    fastio
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 3652
using System;

namespace B___Contest_with_Drinks_Easy
{
    class Program
    {
        static void Main (string[] args)
        {
            var n = int.Parse (Console.ReadLine ());
            var t = new int[n];
            var input = Console.ReadLine ().Split (' ');
            for (var i = 0; i < n; i++)
            {
                t[i] = int.Parse (input[i]);
            }
            var m = int.Parse (Console.ReadLine ());
            var p = new int[m, 2];
            for (var i = 0; i < m; i++)
            {
                input = Console.ReadLine ().Split (' ');
                for (var j = 0; j < 2; j++)
                {
                    p[i, j] = int.Parse (input[j]);
                }
            }
            var ans = new int[m];
            for (var i = 0; i < m; i++) //p
            {
                var sum = 0;
                for (var j = 0; j < n; j++) //t
                {
                    if (j + 1 == p[i, 0])
                    {
                        sum += p[i, 1];
                    }
                    else
                    {
                        sum += t[j];
                    }
                }
                ans[i] = sum;
            }
            foreach (var q in ans)
            {
                Console.WriteLine (q);
            }
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define print(x,n) for(int i=0;i<n;i++)cout<<x[i]<<" "
using namespace std;

int main() {
	int n, k, idx = 0;
	cin >> n >> k;
	vector<int> ht(n, 0);
	vector<int> dp_states(k + 1, 0);

	for (int i = 0; i < n; i++)
		cin >> ht[i];

	// Base case
	dp_states[idx++] = 0;
	int ans;

	//Fill states using O(k) time
	for (int i = 1; i < n; i++) {
		ans = INT_MAX;

		for (int j = idx - 1; j >= 0; j--) {
			ans = min(ans, dp_states[j] + abs(ht[i] - ht[i - (idx - j)]));
		}
		dp_states[idx++] = ans;
		
		if (idx == k + 1) {
			for (int i = 0; i < idx; i++) {
				dp_states[i] = dp_states[i + 1];
			}
			idx--;
		}
	
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3776
/*
**   Contest : AtCoder Beginner Contest 127
**   Problem : B - Algae
**
**    Author : Dhiraj Govindvira
**      Date : 24-Jun-2020 ~ Wednesday
**      Time : 08:31:22 PM
*/

#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  long long int
#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename... T> 
inline void inp(T&... args) {
    ((cin>>args), ...);
}
// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(ll &T)
{
    ll r, d, x;
    cin>>r>>d>>x;

    vector<ll> dp(14);
    dp[0] = x;

    loop(i,1,12) {
        dp[i] = dp[i-1] * r - d;
    }

    loop(i,1,11) cout<<dp[i]<<endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    loop(i,1,t+1)
    {
        cerr<<"Case #"<<i<<"\n";
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>

using namespace std;

int main(){

    string moji;
    getline(cin, moji);

    for(int i=0; i<moji.size(); i++){
        if(moji[i] >= 'a' && moji[i] <= 'z'){
            moji[i] += 'A' - 'a';
        }else if(moji[i] >= 'A' && moji[i] <= 'Z'){
            moji[i] += 'a' - 'A';
        }        
    }

    cout << moji << endl;

    return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define INT long long int
using namespace std;
INT n, a[100010], y;
map<INT, INT> d;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 0 ; i < n ; i++) cin>>a[i], d[a[i]] = 1;
    sort(a, a+n);
    for(int i = 0 ; i < n-1 ; i++ )
        y = max( y, min(a[i], a[n-1]-a[i]) );
    if( d[y] ) cout<<a[n-1]<<" "<<y<<endl;
    else cout<<a[n-1]<<" "<<a[n-1]-y<<endl;
    return 0;
}




Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define FOR(n) for(int i=0;i<n;i++)
#define till(n) for(int i=1;i<=n;i++)
#define mod 1000000007
using namespace std;



int main(){
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    string a, b;cin >> a >> b;
    int dp[a.size()+1][b.size()+1] = {0};

    for(int i=0;i<=a.size();i++){
        for(int j=0;j<=b.size();j++){
            if(i == 0 || j == 0) dp[i][j] = 0;
            else if(a[i-1] == b[j-1]) dp[i][j] = dp[i-1][j-1]+1;
            else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
        }
    }

    //cout << dp[a.size()][b.size()] << endl;

    stack<char> st;
    int i = a.size(), j = b.size();
    while(i>0&&j>0){
        if(a[i-1]==b[j-1]){
            //cout << a[i-1] << " ";
            st.push(a[--i]);j--;
        }
        else if(dp[i-1][j] == dp[i][j]){
            i--;
        }
        else{
            j--;
        }
    }

    while(!st.empty()){
        cout << st.top();st.pop();
    }

	return 0;
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
int main(){
    bool flag=0,c=0;
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='C'){
            c=true;
        }
        if((s[i]=='F')&&(c)){
            flag=true;
        }
    }
    if(flag){
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <stack>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using pii = pair<int,int>;
int main(){
    int h;
    while(cin>>h,h){
        vector< vector<int> >v(h,vector<int>(5));
        for(auto& vec : v)
            for(auto& e : vec)
                cin  >> e;
        vector< pair<pii,int> >del;
        int ans = 0;
        bool flag = true;
        vector<vector<bool>>used(h,vector<bool>(5,true));
        while(flag){
            del.clear();
            for(int i = 0; i < h;i++){
                for(int j = 0; j < 4;j++){
                    if(!used[i][j])continue;
                    bool foo=true;
                    int cnt = 1;
                    int k= j + 1;
                    while (foo && k < 5) {
                        if(!used[i][k])break;
                        if(v[i][j] == v[i][k]){
                            cnt++;
                            k++;
                        } else {
                            foo = false;
                        }
                    }
                    if(cnt < 3)continue;
                    del.emplace_back(pii(i,j),cnt);
                    rep(_,cnt-1) used[i][ j+_]=false;
                    ans += cnt * v[i][j];
                }
            }
            if(del.empty())
                break;
            vector<vector<int>>temp(h,vector<int>(5));
            rep(i,h){
                rep(j,5){
                    rep(k,del.size()){
                        if(del[k].first==pii(i,j)){
                            rep(_,del[k].second){
                                used[del[k].first.first][del[k].first.second+_]=false;
                            }
                        }
                    }
                }
            }
            int last[10000]={0};
            for(int i=h-1; i>=0;i--){
                rep(j,5){
                    if(!used[i][j])continue;
                    {
                        temp[(h-1-last[j])][j] = v[i][j];
                        used[h-1-last[j]][j]=true;
                        last[j]++;
                        
                    }
                }
            }
            v = temp;
        }
        cout << ans << endl;
    }
}





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

int main(){
	int array[101],i,min=1;
	
	for(i=0;i<101;i++)
		array[i]=0;
	while(0<=scanf("%d",&i)){
		++array[i];
	}
	
	for(i=0;i<101;i++){
		if(array[i]!=0 && min<=array[i]){
			min=array[i];
		}
	}
	
	for(i=0;i<101;i++){
		if(min==array[i]){
			printf("%d\n",i);
		}
	}
	
	return 0;
}

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

using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    int mn = b * 10;
    while (true){
        int c = mn * 0.08;
        int d = mn * 0.1;
        if((c == a) && (b == d)){
            cout << mn << endl;
            return 0;
        }
        mn++;
        if(mn > 11000){
            cout << -1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3644
// 問題名: Area
// URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_A&lang=jp
// 所要時間: 10分
// --感想--
// 符号付き面積について知れて良い勉強になった。
// 出力の桁数が指定されている問題を初めて体験した。

#include <bits/stdc++.h>
using namespace std;

typedef pair<long long,long long> point;

// 外積
long long cross(point a, point b) { return (a.first * b.second - a.second * b.first); }

#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)

int main(){
    vector<point> v;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        v.pb(point(x, y));
    }
    sort(v.begin(), v.end());
    vector<point> v1;
    for (int i = 0; i < n; i++){
        while(v1.size() > 1){
            int k = v1.size();
            point a(v1[k - 1].first - v1[k - 2].first, v1[k - 1].second - v1[k - 2].second);
            point b(v[i].first - v1[k - 1].first, v[i].second - v1[k - 1].second);
            if (cross(a, b) < 0)
                v1.pop_back();
            else
                break;
        }
        v1.pb(point(v[i].first, v[i].second));
    }
    v1.pop_back();
    vector<point> v2;
    for (int i = n - 1; i >= 0; i--){
        while (v2.size() > 1){
            int k = v2.size();
            point a(v2[k - 1].first - v2[k - 2].first, v2[k - 1].second - v2[k - 2].second);
            point b(v[i].first - v2[k - 1].first, v[i].second - v2[k - 1].second);
            if (cross(a, b) < 0)
                v2.pop_back();
            else
                break;
        }
        v2.pb(point(v[i].first, v[i].second));
    }
    v2.pop_back();
    v1.insert(v1.end(), v2.begin(), v2.end());
    cout << v1.size() << endl;
    point s(1e7, 1e7);
    for(auto &p:v1){
        point q(p.second, p.first);
        s = min(s, q);
    }
    int flag = 0;
    auto itr = v1.begin();
    while(1){
        if(itr == v1.end())
            itr = v1.begin();
        point p = *itr;
        point q(p.second, p.first);
        if(q == s){
            if(flag == 1)
                break;
            else
                flag++;
        }
        if(flag)
            cout << p.first << " " << p.second << endl;
        itr++;
    }
}


Measured memory_bytes: 7472
n = int(input())
t = list(map(int, input().split(' ')))
x, y = 0, 0
while True:
    x = 0
    for i in range(n-1):
        if t[i] > t[i+1]:
            t[i],t[i+1] = t[i+1],t[i]
            y = y + 1
        else:
            x = x + 1
    if x == n-1:
        break
print(' '.join(map(str,t)))
print(y)


Measured memory_bytes: 5596
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	int t;
	t = a + b + c;

	if (t % 2 == 1)
		cout << "No" << endl;
	else if (t / 2 == a || t / 2 == b || t / 2 == c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
}

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



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}

int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }

  if(b==0){
    return a;
  }

  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }

  return b;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}


long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  /*
  解法3
  0-indexed(0からn-1まで)として
  A[i]:=[0,i)までの和
  という(n+1)要素からなる累積和の配列を作っておく
  
  (答え)=((0~(i-1)までの総和)*(i番目の要素))の総和
  ということがわかるので，それを実装

  しっかり書くと
   A[1]*A[0]
  +A[2]*(A[1]+A[0])
  +A[3]*(A[2]+A[1]+A[0])
  ...
  ということがわかる

  常にMODを取らないといけないけど，2の逆元を考える必要がないので楽かも
  */
  long int n;
  scanf("%ld",&n);

  long int A[n+1];

  long int MOD=1e9+7;

  A[0]=0;
  for(int i=1;i<n+1;i++){
    scanf("%ld",&A[i]);
    A[i]+=A[i-1];
    
    //常にMODを取る！
    A[i]%=MOD;
  }

  long int ans=0;
  for(int i=1;i<n+1;i++){
    ans+=A[i-1]*(A[i]-A[i-1]+MOD);

    //常にMODを取る！
    ans%=MOD;
  }

  printf("%ld\n",ans);

  return 0;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 500000
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

int main()
{
    int x; scanf("%d",&x);
    puts(x>=30?"Yes":"No");
    return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
int n,m;
bool ad[51][51];
bool visit[51];
void dfs(int v){
    visit[v]=true;
    for(int i=0;i<m;i++){
        if(ad[v][i]==false){continue;}
        if(visit[i]==true){continue;}
        dfs(i);
    }
}
int main(){
    cin>>n>>m;
    int a[m],b[m],ans=0;
    bool bri;
    for(int i=0;i<m;++i){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        ad[a[i]][b[i]]=ad[b[i]][a[i]]=true;
    }

    for(int i=0;i<m;++i){
        bri=false;
        ad[a[i]][b[i]]=ad[b[i]][a[i]]=false;
        for(int j=0;j<n;++j){visit[j]=false;}
        dfs(0);
        for(int j=0;j<n;++j){if(visit[j]==false){bri=true;}}
        if(bri){ans++;}
        ad[a[i]][b[i]]=ad[b[i]][a[i]]=true;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	vector<string> ans = {"KIHBR", "AKIHBR", "KIHABR", "AKIHABR", "KIHBAR", "AKIHBAR", "KIHABAR", "AKIHABAR", "KIHBRA", "AKIHBRA", "KIHABRA", "AKIHABRA", "KIHBARA", "AKIHBARA", "KIHABARA", "AKIHABARA"};
	sort( ans.begin(), ans.end() );
	string s; cin >> s;
	if( binary_search( ans.begin(), ans.end(), s ) ) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()

num = len(s)
ans = s.count('R')*s.count('G')*s.count('B')

for i in range(num):
    for j in range(i+1, num):
        if 0 <= 2*j-i < num:
            if s[i] != s[j] and s[j] != s[2*j-i] and s[2*j-i] != s[i]:
                ans -= 1
print(ans)


Measured memory_bytes: 9124
#include <bits/stdc++.h>
// #include "stdafx.h"
// #pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
ll a[N];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,n,k,j;
	cin >> n;
	fo(i, n) cin >> a[i+1];
	sort(a+1, a+1+n);
	int lo = 0;
	Fo(i, 1, 1+n){
		a[i] += a[i-1];
		if(a[i+1] <= 2*a[i]);
		else lo = i;
	}
	cout << n-lo << endl;

	return 0;
} 

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
	if (exp & 1) result = ((ll)result * base) % mod;
	base = ((ll)base * base) % mod;
	exp >>= 1;
	}
	return result;
}

void ipgraph(int m){
	int i, u, v;
	fo(i, m){
		cin>>u>>v; 
		u++, v++;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 8320
#include<iostream>
#include<algorithm>
#define N 202000
using namespace std;
long long n,k,tree[N],sum[N],f[N],m,ans;
long long lowbit(int x){return x&-x;}
void add(int x,int k)
{
    while(x<=n)
    {
        tree[x]+=k;
        x+=lowbit(x);
    }
}
long long query(int x)
{
    int ans=0;
    while(x>0)
    {
        ans+=tree[x];
        x-=lowbit(x);
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;++i)
        cin>>sum[i];
    for(int i=1;i<=n;++i)
        f[i]=sum[i]+=sum[i-1]-k;
    for(int i=1;i<=n;++i)
        if (sum[i]>=0) ans++;
    sort(f+1,f+n+1);
    m=unique(f+1,f+n+1)-f-1;
    for(int i=1;i<=n;++i)
        sum[i]=lower_bound(f+1,f+m+1,sum[i])-f;
    for(int i=n;i>=1;--i)
    {
        ans+=query(sum[i]);
        add(1,1);add(sum[i]+1,-1);
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
string s;
int i;
stack<char>st;
int check(string s);

int main()
{
    cin>>s;
    cout<<check(s)*2<<endl;
    
    return 0;
}

int check(string s)
{
    int n=s.size();
    for(;i<n;i+=1){
        if(s[i]=='S')st.push(s[i]);
        else if(s[i]=='T'){
            if(!st.empty())st.pop();
        }
        
    }
    if(st.empty())return false;
    else return st.size();
}


Measured memory_bytes: 772
#include<stdio.h>
#include<math.h>
int main()
{
    int a,b,m;
    for(a=1;a<10;a++)
    {
        for(b=1;b<10;b++)
        {
            m=a*b;
            printf("%dx%d=%d\n",a,b,m);
        }

    }

    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <algorithm>
#include<functional>
#include<stdio.h>
#include<stdlib.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#include<vector>
using namespace std;
int main() {
	int N,sum = 0;
	cin >> N;
	int a[100];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (a[i] != i + 1) {
			sum++;
		}
	}
	if ((sum == 0) || (sum == 2)) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}


Measured memory_bytes: 256
n, k = map(int, raw_input().split())
is_bad = [ False for d in range(10) ]
for d in map(int, raw_input().split()):
  is_bad[d] = True

def good(x):
  while x != 0:
    d = x % 10
    if is_bad[d]:
      return False
    x //= 10
  return True

while True:
  if good(n):
    print(n)
    break
  n += 1


Measured memory_bytes: 14316
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
typedef vector<int> vi;
typedef vector<vector<int>> vi2;
int main(void)
{
    int N;
    cin >> N;
    lli *L;
    L = new lli[N + 1];
    L[0] = 2;
    L[1] = 1;
    for (int i = 2; i <= N; i++)
    {
        L[i] = L[i - 1] + L[i - 2];
    }
    cout << L[N] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    std::vector<int> ds;
    std::vector<std::pair<int, int>> vs;
    for (int i = 0; i < n; i++) {
        int d;
        scanf("%d", &d);
        ds.push_back(d);
        vs.emplace_back(d, i);
    }

    std::vector<std::vector<int>> es(n);
    std::map<std::pair<int, int>, int> eindex;
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        es[a].push_back(b);
        es[b].push_back(a);
        eindex[std::minmax(a, b)] = i;
    }

    std::sort(vs.begin(), vs.end());

    std::vector<int> cs(n, -1), elen(m);
    for (int i = 0; i < n;) {
        int j = i, cd = vs[i].first;
        while (j < n && vs[j].first == cd) j++;

        for (int k = i; k < j; k++) {
            int v = vs[k].second;
            if (cs[v] >= 0) continue;

            for (int to : es[v]) {
                if (ds[to] == cd) {
                    elen[eindex[std::minmax(v, to)]] = cd;
                    if (cs[to] >= 0) cs[v] = !cs[to];
                    else {
                        cs[v] = 0;
                        cs[to] = 1;
                    }
                    break;
                } else if (cs[to] >= 0) {
                    cs[v] = cs[to];
                    elen[eindex[std::minmax(v, to)]] = ds[v] - ds[to];
                    break;
                }
            }

            if (cs[v] == -1) {
                std::cout << -1 << std::endl;
                return 0;
            }
        }
        i = j;
    }

    for (int i = 0; i < n; i++) printf("%c", cs[i] ? 'B' : 'W');
    printf("\n");
    for (int i = 0; i < m; i++) printf("%d\n", elen[i] ? elen[i] : 1000000000);

    return 0;
}


Measured memory_bytes: 23280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,K,ans=0;
    int hi;
    cin >> N >> K;
    for (int i=0;i<N;i++){
        cin >> hi;
        if (hi >= K){ans++;}
        
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin>>n;
    int tmp,result=0;
    REP(i,n){
        cin>>tmp;
        result^=tmp;
    }
    if(result==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

int main() {

    int n, m, a, b, c, d;
    scanf("%d %d", &n, &m);

    int student[n][2];
    int point[m][2];

    for (int i = 0; i < n; i++) {
        scanf("%d %d", &a, &b);
        student[i][0] = a;
        student[i][1] = b;
    }

    for (int j = 0; j < m; j++) {
        scanf("%d %d", &c, &d);
        point[j][0] = c;
        point[j][1] = d;
    }


    for (int k = 0; k < n; k++) {
        int mysum = INT_MAX;
        int checkpoint = -1;

        for (int l = 0; l < m; l++) {
            //printf("%d %d %d %d\n", student[k][0], student[k][1], point[l][0], point[l][1]);
            int temp = abs(student[k][0] - point[l][0]) + abs(student[k][1] - point[l][1]);
            //printf("temp=%d %d\n",temp,checkpoint);
            if (temp < mysum) {
                mysum = temp;
                checkpoint = l + 1;
            }

        }
        printf("%d\n", checkpoint);


    }

    return 0;
}


Measured memory_bytes: 1700
s=input()
a=s[:2]
b=s[2:]
if a[0]=="0":
    a=a[1]
if b[0]=="0":
    b=b[1]
a=int(a)
b=int(b)
if 1<=a<=12:
    a=True
elif 0<=a<=99:
    a=False
if 1<=b<=12:
    b=True
elif 0<=b<=99:
    b=False
if a and b:
    print("AMBIGUOUS")
elif a:
    print("MMYY")
elif b:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define INF 0x3f3f3f3f 
#define MEM(x,y) memset(x,y,sizeof(x))
#define int long long
#define rep(i , a , b) for(int i = a ; i <= b ; i ++)
#define P pair<int,int>
#define  sc(a) scanf("%lld",&a)
#define pf(a) printf("%lld ",a)
int q[3000];
using namespace std;
signed main()
{
	int a, b;
	cin >> a >> b;
	int t = 0;
	rep(i, a, b)
	{
		if (i % 2019 == 0)
		{
			cout << "0";
			return 0;
		}
	}
	int ans = INF;
	rep(i, a, b)
		rep(j, i+1, b)
		ans = min(ans, i * j % 2019);
	cout << ans;
}











Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;

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

	vector<int> vec(N * 2);
	for (int i = 0; i < N; i++) {
		cin >> vec[i];
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());

	if (N == 2) {
		if (vec[0] > vec[1]) {
			cout << vec[0] - vec[1] << endl;
		}
		else {
			cout << vec[1] - vec[0] << endl;
		}
	}
	else {
		int ans1 = 0, ans2 = 0;
		for (int i = 1; i < N; i++) {
			ans1 = ans1 + vec[2 * i];
			ans2 = ans2 + vec[(2 * i) - 1];
		}
		cout << vec[0] + ans1 - ans2 << endl;
	}
}


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

int main()
{
    int S,h,m,s;
    scanf("%d",&S);
    h=S/3600;
    m=(S%3600)/60;
    s=(S%3600)%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include<iomanip>
#include<math.h>

long double sineTheorem(long double a, long double b, long double& c, long double radAngleC);
long double deg2rad(long double angleC);


int main()
{
	long double a;
	long double b;
	long double c;
	long double angleC;
	long double radAngleC;

	std::cin >> a >> b >> angleC;

	radAngleC = deg2rad(angleC);

	long double square;
	square = (a*b*sin(radAngleC))/2.0;

	long double triangle;
	triangle=sineTheorem(a, b, c, radAngleC);

	long double height;
	height = (square * 2.0) / a;

	
	std::cout <<std::fixed<<std::setprecision(20)<< square << std::endl << triangle << std::endl << height << std::endl;

}

//関数の定義
long double sineTheorem(long double a, long double b, long double& c, long double radAngleC){
	long double triangle;
	long double ans;
	ans = a*a + b*b - 2.0 * a*b*cos(radAngleC);
	c = sqrt(ans);
	triangle= a + b + c;

	return triangle;
	
}

long double deg2rad(long double angleC){
	const long double PI = 3.1415926535;
	return angleC*PI / 180.0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main(){
    string s;
    bool ok = 1;
    cin >> s;
    if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]);
    else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]);
    else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]);
    else
        ok = 0;
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1LL<<60

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll mod = 1e9 + 7;
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> dp(N, 0ll);
    vector<ll> available(N+1, 0ll); // rest[k]: A[i]=kのときに使える色の数
    available[0] = 2ll;
    available[1] = 1ll;

    if(A[0] > 0) {
        cout << 0 << endl;
        return 0;
    }

    dp[0] = 3ll;
    FOR(i, 1, N-1) {
        ll r = available[A[i]]--;
        available[A[i]+1]++;
        dp[i] = (dp[i-1] * r) % mod;
    }

    cout << dp[N-1] << endl;

    return 0;
}

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    if (n < 3) {
        cout << 0 << endl;
        return 0;
    }

    cout << n / 3 << endl;

    return 0;
}

Measured memory_bytes: 3604
def isParindrome(s):
  result = True
  for i in range(len(s)):
    if s[i] != s[-i-1]:
      result = False
  return result

s1 = list(input())
s2 = s1[0:int((len(s1)-1)/2)]
s3 = s1[int((len(s1)+3)/2 - 1):]

r1 = isParindrome(s1)
r2 = isParindrome(s2)
r3 = isParindrome(s3)
print("Yes" if r1 and r2 and r3 else "No")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

typedef long long ll;

void print(){ std::cout << std::endl; }
template<typename H> void print(H head){ std::cout << head << std::endl; }

int main()
{
  ll N;
  std::cin >> N;

  std::vector< ll > va(N, 0LL);
  std::string judge = "APPROVED";

  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
    if (va[i] % 2 == 0) {
      if (va[i] % 3 != 0 && va[i] % 5 != 0) judge = "DENIED";
    }
  }

  print(judge);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
  ll n,ans = 0;
  cin >> n;
  string s;
  unordered_map<string,ll> mp;
  while(n>0){
    cin >> s;
    sort(s.begin(),s.end());
    ans += mp[s];
    mp[s]++;
    n--;
  }
  cout << ans << endl;
}








































//以下、ライブラリ
//ユークリッドの互除法

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
}



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

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

  string ans = "";
  while (N > 0) {
    N--;
    ans += (char)(N % 26 + 'a');
    N /= 26;
  }
  reverse(ans.begin(), ans.end());

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????????
?????????????????????????¨??????????????????§?????????????°????????????????????????????????????´???????????¢?????´???????????§??????

1 selectionSort(A, N) // N??????????´??????????0-?????????????????????A
2   for i ??? 0 ?????? N-1 ?????§
3     minj = i
4     for j ??? i ?????? N-1 ?????§
5       if A[j] < A[minj]
6         minj = j
7     A[i] ??¨ A[minj] ?????????

"""
import math

def swap(A, i, j):
    x = A[i]
    A[i] = A[j]
    A[j] = x

def sSort(A, N):
    cnt = 0
    for i in range(0, N-1):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        if minj != i:
            swap(A,i,minj)
            cnt += 1
    return cnt

# ?????????
N = int(input().strip())
A = list(map(int,input().strip().split()))
cnt = sSort(A,N)
print(" ".join(map(str,A)))
print(cnt)

Measured memory_bytes: 7824
#include <stdio.h>
#define max(x,y)x>y?x:y
int main(){
	int n,count,ki=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int j=i;
		count=0;
		while(1){
			if(j/10==0){
				count++;
				break;
			}else{
				count++;
				j/=10;
			}
		}
		if(count%2==1){
			ki++;
		}
	}
	printf("%d\n",ki);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
double A,B,H,M;
const double PI=3.14159265358979323846;
double ans;


int main(){
    cin >> A >> B>>H>>M;
    ans = sqrt(A*A+B*B-2*A*B*cos(PI*(12*M-60*H-M)/360));
    cout << std::setprecision(20) << ans << endl;

}




Measured memory_bytes: 4212
S=input()
tmp=S[0]
i=1
ans=1
while i<len(S)-1:
    # print(S[i],tmp)
    if S[i]!=tmp:
        ans+=1
        tmp=S[i]
        i+=1
    else:
        ans+=1
        tmp=S[i:i+2]
        i+=2
if i>=len(S):
    print(ans)
elif tmp==S[i]:
    print(ans)
else:
    print(ans+1)


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

using namespace std;

long long cnts[5];

int main() {
    int N;
    cin >> N;
    string s;
    for (int i = 0; i < N; ++i) {
        cin >> s;
        if (s[0] == 'M') cnts[0]++;
        else if (s[0] == 'A') cnts[1]++;
        else if (s[0] == 'R') cnts[2]++;
        else if (s[0] == 'C') cnts[3]++;
        else if (s[0] == 'H') cnts[4]++;
    }

    long long ans = 0;
    for (int a = 0; a < 5; ++a) {
        for (int b = a + 1; b < 5; ++b) {
            for (int c = b + 1; c < 5; ++c) {
                ans += cnts[a] * cnts[b] * cnts[c];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int arr[n+1];
    arr[0]=0;
    for(int i=0;i<n;i++) cin >> arr[i+1];
    int dp[n+1];
    dp[0]=10000;
    dp[1]=arr[0];
    for(int i=2;i<=n;i++)
    {
        if(i-2>0)
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
        else
        dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

a, b, c = map(int, input().split())
print(max(int(str(a)+str(b))+c, int(str(b)+str(a))+c, int(str(b)+str(c))+a, int(str(c)+str(b))+a, int(str(c)+str(a))+b, int(str(a)+str(c))+b))


Measured memory_bytes: 3060
n = int(input())
s = len(str(n))
if s == 1:
    print(n)
elif s == 2:
    print(9)
elif s == 3:
    print(9 + (n-100) + 1)
elif s == 4:
    print(9 + 900)
elif s == 5:
    print(9 + 900 + (n-10000) + 1)
else:
    print(9 + 900 + 90000)

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

int get_sum(int i){
    int small_sum = 0;
    while(i > 0){
        small_sum += i % 10;
        i /= 10;
    }
    return small_sum;
}

int main(){
    int N, sum = 0;
    cin >> N;
    if(N % get_sum(N) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define ford(i, b, a) for (int i = (int)(b); i >= a; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const int N = (int)1e5+77;
const ll inf = (ll) 1e15+77;
const int mod = (int) 1e9 + 7;
const ld pi = acos(-1);

int main() {
    fast;
    int n;
    scanf("%d", &n);
    vector<double> dp(n + 1);
    dp[0] = 1;
    for (int coin = 0; coin < n; ++coin) {
        double p_heads;
        scanf("%lf", &p_heads);
        for (int i = coin + 1; i >= 0; --i) {
            dp[i] = (i == 0 ? 0 : dp[i - 1] * p_heads) + dp[i] * (1 - p_heads);
        }
    }
    double answer = 0;
    for (int heads = 0; heads <= n; ++heads) {
        int tails = n - heads;
        if (heads > tails) {
            answer += dp[heads];
        }
    }
    printf("%.10lf\n", answer);
    return 0;
}

Measured memory_bytes: 256