akhauriyash/Code-Regression huggingface dataset:
using System; 
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int[] s = Console.ReadLine().Select(x => x - '0').ToArray();

        long res = 0;
        int max = Convert.ToInt32(Math.Pow(2, s.Length - 1));
        for (int i = 0; i < max; i++)
        {
            bool[] bitmask = Convert.ToString(i, 2).PadLeft(s.Length - 1, '0').Select(x => x == '1').ToArray();
            long num = s[0];
            for (int j = 1; j < s.Length; j++)
            {
                if (bitmask[j - 1])
                {
                    res += num;
                    num = s[j];
                }
                else
                {
                    num = num * 10 + s[j];
                }
            }
            res += num;
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int main()
{
   int A, B, C;
   cin >> A >> B >> C;
   if ( A == 5 && B == 5 && C == 7)
    cout << "YES";
    else if ( A == 5 && B == 7 && C == 5)
    cout << "YES";
    else if ( A == 7 && B == 5 && C == 5)
        cout << "YES";
    else
        cout << "NO";

    return 0;
}


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

int A[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int B[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

bool isSorted(void)
{
	int i = 1;
	while(A[i]!=0 && i<=9)
	{
		if(A[i] < A[i-1]) return false;
		i++;
	}

	i = 1;
	while(B[i]!=0 && i<=9)
	{
		if(B[i] < B[i-1]) return false;
		i++;
	}

	return true;
}

int main(void)
{
	int n;
	cin >> n;
	bool enable = false;
	for(int i=0; i<n; i++)
	{
		int X[10];
		for(int j=0; j<10; j++)
			cin >> X[j];

		for(int j=0; j<1024; j++)
		{
			int a = 0, b = 0;
			int e = 1;
			for(int k=0; k<10; k++)
			{
				if( (j & e) == e)
				{
					A[a] = X[k];
					a++;
				}
				else
				{
					B[b] = X[k];
					b++;
				}
				e *= 2;
			}
			if(isSorted())
			{
				enable = true;
			}

			//initialize
			for(int j=0; j<10; j++)
			{
				A[j] = 0; B[j] = 0;
			}
		}
		if(enable) cout << "YES" << endl;
		else cout << "NO" << endl;
		enable = false;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main() {
    string a;
    cin >> a;
    for (int i = 0; i < a.size(); i++) {
        if (a[i]=='9') {
            a[i]='1';
        }
        else{
            a[i]='9';
        }
    }
    cout << a;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

vector<int> G[100100];
vector<int> children[100100]; //0が根
const ll MOD=1000000007;
ll dp[2][100100]; 
bool used[100100];

void make_child(int n){
    used[n]=true;
    for(auto x : G[n]){
        if(used[x]) continue;
        children[n].push_back(x);
        make_child(x);
    }
}


pair<ll, ll> dfs( int n){
    ll ans0=1LL, ans1=1LL; //
    for(auto x : children[n]){
        if(dp[0][x]==0){
        P p=dfs(x);
        ans0 *= (p.first+p.second);
        ans0 %= MOD;
        ans1 *= p.first;
        ans1 %= MOD;
        }
        else{
            ans0 *= (dp[0][x]+dp[1][x]);
            ans1 *= dp[0][x];
            ans0 %= MOD; ans1 %= MOD;
        }
    }
    dp[0][n]=ans0; dp[1][n]=ans1;
    return P(ans0, ans1);
}


int main(){
    int N; cin >> N;
    for(int i=0; i<N-1; i++){
        int x, y; cin >> x >> y; x--; y--;
        G[x].push_back(y); G[y].push_back(x);
    }
    make_child(0);
    pair<ll, ll> P=dfs(0);
/*    for(int i=0; i<N; i++){
        cout << dp[0][i] << " " << dp[1][i] << endl;
    }
*/    cout << (P.first+P.second)%MOD << endl;
}

Measured memory_bytes: 18432
fun main(args : Array<String>) {
    (1..2).map { readLine() }.map { requireNotNull(it) }.let {
        val result= WhiteCells().exec(*it.toTypedArray())
        println(result)
    }
}

class WhiteCells {
    fun exec(vararg args : String) : String{
        // 1 =< hw =< 20
        val HW = args[0].split(" ").let {
            Pair(it[0].toInt(), it[1].toInt())
        }

        // 1 =< h < H 1 =<w =< W
        val hw = args[1].split(" ").let {
            Pair(it[0].toInt(), it[1].toInt())
        }

        val table = Table(HW.first, HW.second)

        table.selectRow(hw.first)

        table.selectColumn(hw.second)

        return "${table.getWhiteCount()}"
    }

    class Table(
        height : Int,
        width : Int
    ) {
        val rows : List<Row> = (1..height).map { Row(width) }

        fun selectRow(num : Int) {
            (1..num).forEach {position ->
                rows[position-1].cells.forEach { it.isBlack = true }
            }
        }

        fun selectColumn(num :Int) {
            (1..num).forEach {col ->
                rows.forEach {
                    it.cells[col-1].isBlack = true
                }
            }
        }

        fun getWhiteCount() : Int {
            return rows.flatMap { it.cells }.count { !it.isBlack }
        }
    }

    class Row(
        width: Int
    ) {
        val cells : List<Cell> = (1..width).map { Cell() }
    }

    class Cell(var isBlack : Boolean = false)
}

Measured memory_bytes: 36236
// 1B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<cmath>

using namespace std;
typedef unsigned long long ull;

ull power(ull x, ull n, ull M) {
    ull res = 1;
    if (n > 0) {
        res = power(x, n / 2, M);
        if (n % 2 == 0)res = (res * res) % M;
        else res = (((res * res) % M) * x) % M;
    }

    return res;
}
int main()
{
    int m, n;

    cin >> m >> n;

    cout << power(m, n, 1000000007) << endl;

    return 0;
}


Measured memory_bytes: 3104
import java.util.Scanner;
import java.io.IOException;

class Main {
	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.nextLine());
		int big = Integer.MIN_VALUE;
		int small = Integer.MAX_VALUE;
		long total = 0;
		for (int i = 0; i < n; i++) {
			int a = scan.nextInt();
			if (big < a) {
				big = a;
			}
			if (a < small) {
				small = a;
			}
			total = total + a;
		}
		System.out.println(small + " " + big + " " + total);
	}
}

Measured memory_bytes: 42424
import java.util.Scanner;

public class Main {

	/**
	 * 入力された数のうち素数の数がいくつかを出力する
	 * 
	 * @param args
	 *            入力数、素数判定する数字
	 */
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();

		long check;
		int count = 0;// 素数の数
		// 入力された数の素数を判定する
		for (int i = 0; i < num; i++) {
			check = scan.nextLong();
			if (PrimeNumber_Checker(check)) {
				count++;
			}
		}
		System.out.println(count);
	}

	/**
	 * 素数であるかどうかを判定数
	 * 
	 * @param check_num
	 *            判定する数字
	 * @return 判定結果(true:素数)
	 */
	public static boolean PrimeNumber_Checker(long check_num) {
		if (check_num < 2) {// 1は素数ではない
			return false;
		}
		if (check_num == 2) {// ２は素数
			return true;
		}
		if (check_num % 2 == 0) {// 偶数は素数でない
			return false;
		}

		//素数判定では、「合成数xはp≦√xを満たす素因子pをもつ」という性質を利用することができます。
		//を適用
		double sqrtNum = Math.sqrt(check_num);
		for (int k = 3; k <= sqrtNum; k = k + 2) {
			if (check_num % k == 0) {
				return false;
			}
		}
		return true;

	}
}


Measured memory_bytes: 42028
//Link : https://atcoder.jp/contests/dwacon6th-prelims/tasks/dwacon6th_prelims_c

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 20
#define M 1001
#define mod 1000000007
int a[N];
int combi[M][M],invFactorial[M];

int add(int x,int y) {
    int ret = x+y;
    if(ret>=mod) {
        ret -= mod;
    }
    return ret;
}

int mul(int x,int y) {
    return (ll)x*y%mod;
}

int mypow(int x,int c) {
    int ret = 1;
    while(c>0) {
        if(c&1) {
            ret = mul(ret,x);
        }
        c/=2;
        x = mul(x,x);
    }
    return ret;
}

void init() {
    invFactorial[0] = 1;
    int f = 1;
    for(int i=1;i<M;++i) {
        f = mul(f,i);
        invFactorial[i] = mypow(f,mod-2);
    }
    for(int i=0;i<M;++i) {
        combi[i][i] = combi[i][0] = 1;
        for(int j = 1;j<i;++j) {
            combi[i][j] = add(combi[i-1][j-1],combi[i-1][j]);
        }
    }
}

int dp[N][M];

int solveDp(int ind,int rem,int k,int n) {
    if(ind==k) {
        return rem==n ? 1 : 0;
    }
    int &ret = dp[ind][rem];
    if(ret!=-1) {
        return ret;
    }
    ret = 0;
    for(int i=0;rem +i<=n && i<=a[ind];++i) {
        int tmp = mul(invFactorial[i], combi[n-i][a[ind]-i]);
        ret = add(ret, mul(tmp, solveDp(ind+1,rem+i,k,n)));
    }
    return ret;
}

void solve() {
    int n,k;scanf("%d %d",&n,&k);
    init();
    int fac = 1;
    for(int i=0;i<k;++i) {
      scanf("%d",&a[i]);
    }
    for(int i=2;i<=n;++i) {
        fac = mul(fac,i);
    }
    memset(dp,-1,sizeof(dp));
    int ret = mul(fac,solveDp(0,0,k,n));
    printf("%d\n",ret);
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (d >= max(a,b)-min(a,b) && d >= max(b,c)-min(b,c) || d >= max(a,c)-min(a,c)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

#define fast ios_base::sync_with_stdio(false); cin.tie(0);
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(x) x.begin(),x.end()
#define watch(x) cout<<#x<<" = "<<x<<endl;
#define V(x) vector<x>
#define P(x,y) pair<x,y>
#define UMP(x,y) unordered_map<x,y>
#define MP(x,y) map<x,y>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl "\n"
#define coutd(n) cout << fixed << setprecision(n)
typedef long long ll;
typedef double db;
typedef long double ld;
const ll mod = 1000000007;

using namespace std;

int main(){
	fast
	
	//int t;
	//cin>>t;
	//rep(_,0,t){
		
	//}
	int s,w;
	cin>>s>>w;
	if(w>=s)
		cout<<"unsafe";
	else
		cout<<"safe";
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include<vector>
#include<cmath>
#include <iomanip>
using namespace std;

int main() {
	long long sx,sy,gx,gy;cin>>sx>>sy>>gx>>gy;
	int n;cin>>n;
	vector<long long> x(n),y(n),r(n);
	vector<vector<double>> d;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i]>>r[i];
	}
	x.push_back(sx);
	y.push_back(sy);
	r.push_back(0);
	x.push_back(gx);
	y.push_back(gy);
	r.push_back(0);
	n+=2;
	for(int i=0;i<n;i++){
		vector<double> d2;
		for(int j=0;j<n;j++){
			double l=sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]))-r[i]-r[j];
			if(l<0)l=0;
			d2.push_back(l);
		}
		d.push_back(d2);
	}
//	for(int i=0;i<d.size();i++){
//		for(int j=0;j<d[i].size();j++){
//			cout<<d[i][j]<<' ';
//		}
//		cout<<endl;
//	}
	vector<int> use(n,1);
	use[n-2]=0;
	double ans;
	for(int i=0;i<n;i++){
		double min=-1;
		int minnum=-1;
		for(int j=0;j<n;j++){
			if(use[j]){
				if((min<0)+(min>d[n-2][j])){
					min=d[n-2][j];
					minnum=j;
				}
			}
		}
		use[minnum]=0;
		if(minnum==n-1){
			ans=min;
			break;
		}
		for(int j=0;j<n;j++){
			double l=d[n-2][minnum]+d[minnum][j];
			if(d[n-2][j]>l){
				d[n-2][j]=d[n-2][minnum]+d[minnum][j];
			}
		}
	}
	cout<<setprecision(12)<<ans<<endl;

	return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    ll x,y,z,K;
    cin >> x >> y >> z >> K;
    vector<ll>a(x),b(y),c(z);
    vector<ll>ans;
    rep(i,x) {
        cin >> a[i];
    }
    rep(i,y) {
        cin >> b[i];
    }
    rep(i,z) {
        cin >> c[i];
    }
    sort(a.rbegin(),a.rend());
    sort(b.rbegin(),b.rend());
    sort(c.rbegin(),c.rend());
    rep(i,x) rep(j,y) {
        if((i+1)*(j+1) > K) continue;
        rep(k,z) {
            if((i+1)*(j+1)*(k+1) > K) continue;
            ans.push_back(a[i]+b[j]+c[k]);
        }
    }
    sort(ans.rbegin(),ans.rend());
    rep(i,K) cout << ans[i] << endl;
    
    
}

Measured memory_bytes: 4212
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<bitset>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;
#define rep(i,n) for(int i = 0;i < (n); ++i)
using namespace std;

typedef long long LL;
typedef long double LD;
const LL mod = 1000000007;

LL k;
vector<LL> res;

void dfs(LL keta, vector<LL>& parray){
    LL tmp, tmp2;
    vector<LL> carray;
    for(LL i = 0;i < parray.size(); i++){
        tmp = parray[i] % 10;
        tmp2 = parray[i];
        if(tmp != 0 && tmp != 9){
            tmp2 *= 10;
            res.push_back(tmp2 + tmp - 1);
            res.push_back(tmp2 + tmp);
            res.push_back(tmp2 + tmp + 1);
            carray.push_back(tmp2 + tmp - 1);
            carray.push_back(tmp2 + tmp);
            carray.push_back(tmp2 + tmp + 1);
        }
        else if(tmp == 0){
            tmp2 *= 10;
            res.push_back(tmp2 + tmp);
            res.push_back(tmp2 + tmp + 1);
            carray.push_back(tmp2 + tmp);
            carray.push_back(tmp2 + tmp + 1);
        }else{
            tmp2 *= 10;
            res.push_back(tmp2 + tmp - 1);
            res.push_back(tmp2 + tmp);
            carray.push_back(tmp2 + tmp - 1);
            carray.push_back(tmp2 + tmp);
        }
    }
    sort(res.begin(), res.end());
    if(res.size() >= k);
    else{
        dfs(keta++, carray);
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> k;
    
    vector<LL> rarray;
    for(LL i = 1; i <= 9; i++){
        rarray.push_back(i);
        res.push_back(i);
    }
    dfs(1, rarray);
    if(k < 10)cout << k << endl;
    else cout << res[k - 1] << endl;
}

Measured memory_bytes: 7244
#include <bits/stdc++.h>
using namespace std;
#define INF 200005

int main()
{
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
	int n;
	cin >> n;
	if(n>=30)
	{
		cout << "Yes\n"; 
	}else
	{
		cout << "No\n";
	}
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
#define MAX 1111111
#define MIN 0
typedef pair<int,int> P;
void init(int n);
void update(int k,int x);
P maxx(int k1,int k2);
P dat[4*100001];
int tim[100001]={0};
int N;

int main(){
  int R,L;
  cin >> N >> R >> L;
  int n_tmp = N;
  init(N);
  memset(tim,0,n_tmp+1);
  int now = 0;
  dat[0]=P(MIN,1);
  for(int i=0;i<R;i++){
    int d,t,x;
    cin >> d >> t >> x;
    tim[dat[0].second] += t - now;
    update(d,x);
    now = t;
  }
  tim[dat[0].second] += L - now;
  int *ans = max_element(tim,tim+n_tmp+1);
  cout << ans - tim << endl;
}

void init(int n){
  N=1;
  while(N<n) N*=2;
  for(int i=0;i<2*N-1;i++){
    dat[i]=P(MIN,MAX);
  }
  for(int i=N-1;i<N-1+n;i++){
    dat[i]=P(0,i-(N-2));
  }
  return;
}

void update(int k,int x){
  k += N - 2;
  P p = dat[k];
  int score = p.first;
  int team = p.second;
  //cout << score << " " << team << endl;
  dat[k] = P(score+x,team);
  while(k > 0){
    k = (k - 1) / 2;
    dat[k] = maxx(k*2+1,k*2+2);
    //cout << dat[k].first << " " << dat[k].second << endl;
  }
  return;
}

P maxx(int k1,int k2){
  P p;
  if(dat[k1].first == dat[k2].first){
    p = P(dat[k1].first,min(dat[k1].second,dat[k2].second));
  }
  else {
    p = max(dat[k1],dat[k2]);
  }
  return p;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int n;
	string s;
	cin>>n>>s;
	if(n%2==0&&s.substr(0,n/2)==s.substr(n/2))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    string n; cin>>n;
    int l = n.size();
    rep(i,l/2)if(n[i]!=n[l-1-i]){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3588
import java.util.Scanner;
class Main{
public static void main(String[] args){
 Scanner scan = new Scanner(System.in);
 
 long N = scan.nextLong();
 long K = scan.nextLong();
 long x = N % K;
 long y = Math.abs(K - x);
    if(x > y){
      x = y;
    }
  System.out.println(x);
 }
}

Measured memory_bytes: 23252
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    ans = 0
    for i in range(len(s)):
        if s[i] == t[i]:
            ans += 1
    print(ans)
    return

#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 39408
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)

#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll n, m;
const int MAX_NM = 100000;
ll x[MAX_NM], y[MAX_NM];

int main(){
  cin >> n >> m;
  REP(i, n) cin >> x[i];
  REP(j, m) cin >> y[j];

  ll sumx = 0;
  for(ll i = 1; i < n; i++) {
    sumx = (sumx + i * (n - i) * (x[i] - x[i - 1])) % MOD;
  }
  ll sumy = 0;
  for(ll j = 1; j < m; j++) {
    sumy = (sumy + j * (m - j) * (y[j] - y[j - 1])) % MOD;
  }

  cout << sumx * sumy % MOD << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
#include <cstdio>
#include <iomanip>
using namespace std;
#define INF (2147483647)
#define mod (1000000007)


double dp[303][303][303] = {};
int N;

double calc(int n1, int n2, int n3){
  double tmp = N;
  if(dp[n1][n2][n3] != 0){
    return dp[n1][n2][n3];
  }else if(n1+n2+n3==0){
    return 0;
  }else{
    if(n1!=0){
      tmp += n1*calc(n1-1,n2,n3);
    }if(n2!=0){
      tmp += n2*calc(n1+1,n2-1,n3);
    }if(n3!=0){
      tmp += n3*calc(n1,n2+1,n3-1);
    }
    tmp /= n1+n2+n3;
    dp[n1][n2][n3] = tmp;
    return tmp;
  }
}

int main(void){
  cout << fixed << setprecision(15);
  cin >> N;
  vector<int> aa(N,0);
  for (size_t i = 0; i < N; i++) {
    cin >> aa[i];
  }

  vector<int> cnts(4,0);
  for(auto a: aa){
    cnts[a]++;
  }

  cout << calc(cnts[1],cnts[2],cnts[3]) << endl;

}


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

int main()
{
	string s,t;
	cin>>s>>t;
	int n=s.length(),m=t.length();
	int dp[n+1][m+1];
	string ans="";
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if(i==0 ||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] );
		}
	}
	int i=n,j=m;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			ans+=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;
	return 0;
}

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

using namespace std;

int names[5];

string march = "MARCH";

long long dfs(short now, short select) {
	if (select == 3) return 1;
	if (now == 5) return 0;
	return names[now] * dfs(now + 1, select + 1) + dfs(now + 1, select);
}

void hawawa()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string name;
		cin >> name;
		for(int j = 0; j < 5; j++) {
			if (march[j] == name[0]) {
				names[j]++;
				break;
			}
		}
	}
	cout << dfs(0, 0) << "\n";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e+18
#define int long long
using namespace std;

signed main(){
	int a,b,q,s[100010],t[100010];
	cin >> a >> b >> q;
	for(int i = 0;i < a;i++) cin >> s[i];
	for(int i = 0;i < b;i++) cin >> t[i];
	for(int i = 0;i < q;i++){
		int x,inda,indb,ans = INF;
		cin >> x;
		inda = lower_bound(s,s + a,x) - s;
		indb = lower_bound(t,t + b,x) - t;
		if(inda && indb) ans = min(ans,x - min(s[inda - 1],t[indb - 1]));
		if(inda && indb != b) ans = min(ans,t[indb] - s[inda - 1] + min(t[indb] - x,x - s[inda - 1]));
		if(inda != a && indb) ans = min(ans,s[inda] - t[indb - 1] + min(s[inda] - x,x - t[indb - 1]));
		if(inda != a && indb != b) ans = min(ans,max(s[inda],t[indb]) - x);
		cout << ans << endl;
	}
}

Measured memory_bytes: 2816
#include<cstdio>
#include<iostream>
#include<sstream>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<climits>
#include<functional>

#include<memory.h>

#define ll long long

using namespace std;

int helper(int T, ll k, bool flag3, bool flag5, bool flag7) {
	if (k > T) {
		return 0;
	}
	else {
		int count(0);
		if (flag3 && flag5 && flag7) {
			++count;
		}
		count += helper(T, k * 10 + 3, true, flag5, flag7);
		count += helper(T, k * 10 + 5, flag3, true, flag7);
		count += helper(T, k * 10 + 7, flag3, flag5, true);
		return count;
	}
}


int main()
{
	int T(0);
	while (cin >> T) {
		cout << helper(T, 0, false, false, false) << endl;
	}
	return 0;
}

Measured memory_bytes: 888
T=int(input())
a,b=map(int,input().split())
ll=list(map(int,input().split()))
mins=0
for i in range(len(ll)):
    ans=a-0.006*ll[i]
    if abs(ans-b)<abs((a-0.006*ll[mins])-b):
        mins=i

print(mins+1)

Measured memory_bytes: 39864
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n,k;
  cin>>n>>k;
  if(n==1){
    int s=k,t=k+1,u=k+2;
    if(s+t<=u){
      cout<<s<<" "<<t<<" "<<u<<endl;
      return 0;
    }else{
      cout<<-1<<endl;
      return 0;
    }
  }
  int cross_point=n-k;
  std::vector<int> a,b,c;
  if(n%2==0){
    if(cross_point<n/2){
      cout<<-1<<endl;
      return 0;
    }else{
      for(int i=0;i<n/2;i++){
        a.push_back(k+i*2);
        b.push_back(k+3*n/2-i-1);
        c.push_back(k+2*n+i);
      }
      for(int i=n/2;i<n;i++){
        a.push_back(k+(i-n/2)*2+1);
        b.push_back(k+2*n-1-(i-n/2));
        c.push_back(k+2*n+i);

      }
    }
  }else{
    if(cross_point<n/2){
      cout<<-1<<endl;
      return 0;
    }
    else{
      for(int i=0;i<=n/2;i++){
        a.push_back(k+i*2);
        b.push_back(k+3*n/2-i);
        c.push_back(k+2*n+i);
      }
      for(int i=n/2+1;i<n;i++){
        a.push_back(k+(i-n/2-1)*2+1);
        b.push_back(k+2*n-(i-n/2-1)-1);
        c.push_back(k+2*n+i);

      }
    }
  }

  for(int i=0;i<n;i++){
    cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<endl;
  }




}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int x[60001]={};
    for(int i=1;i<=100;i++)for(int j=1;j<=100;j++)for(int k=1;k<=100;k++)x[i*i+j*j+k*k+i*j+j*k+k*i]++;
    for(int i=1;i<=n;i++)cout<<x[i]<<endl;
    return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.length();
    int a=0,b=0;
    for(int i=0;i<n;i++){
    	if(s[i]=='0')a++;
    	else b++;

    }
    cout << min(a,b)*2 <<endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
typedef struct{
	int f1;
	int f2;
	int f3;
	int f4;
	int f5;
	int f6;
	int tmp;
}Dice;
int main(void)
{
	int i, Y=0;
	Dice D0, D1;
	scanf("%d%d%d%d%d%d", &D0.f1, &D0.f2, &D0.f3, &D0.f4, &D0.f5, &D0.f6);
	scanf("%d%d%d%d%d%d", &D1.f1, &D1.f2, &D1.f3, &D1.f4, &D1.f5, &D1.f6);
	i=0;
	while((D0.f1 != D1.f1 || D0.f6 != D1.f6) && i<6){
		D1.tmp = D1.f1;
		i++;
		switch(i%2){
			case 0:
				D1.f1 = D1.f4;
				D1.f4 = D1.f6;
				D1.f6 = D1.f3;
				D1.f3 = D1.tmp;
				break;
			case 1:
				D1.f1 = D1.f2;
				D1.f2 = D1.f6;
				D1.f6 = D1.f5;
				D1.f5 = D1.tmp;
		}
	}
	for(i=0; i<4; i++){
		D1.tmp = D1.f2;
		D1.f2 = D1.f3;
		D1.f3 = D1.f5;
		D1.f5 = D1.f4;
		D1.f4 = D1.tmp;
		D0.f2==D1.f2 && D0.f3==D1.f3 && D0.f5==D1.f5 && D0.f4==D1.f4 ? Y++ : 0;
	}
	Y>0 ? puts("Yes") : puts("No");
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main()
{
	FAST;
	ll n, k, i;
	string s;
	cin >> n >> k;
	cin >> s;
	if(s[k-1] == 'A')
		s[k-1] = 'a';
	if(s[k-1] == 'B')
		s[k-1] = 'b';
	if(s[k-1] == 'C')
		s[k-1] = 'c';
	cout << s;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val b = IntArray(n-1)
    for(i in 0..n-2){
        b[i] = scanner.nextInt()
    }
    var sum = b[0]
    for(i in 0..n-3){
        if(b[i] <= b[i+1]){
            sum += b[i]
        }
        else sum += b[i+1]
    }
    println(sum+b[n-2])
}

Measured memory_bytes: 31004
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod = 10**9+7

S = s()
N = len(S)
dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(13):
        if S[i] == '?':
            for k in range(10):
                dp[i+1][(10*j+k)%13] = (dp[i+1][(10*j+k)%13]+dp[i][j])%mod
        else:
            x = int(S[i])
            dp[i+1][(10*j+x)%13] = (dp[i+1][(10*j+x)%13]+dp[i][j])%mod
print(dp[N][5])

Measured memory_bytes: 100688
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	static int[][] map;
	static long[][] dp;
	static int[] dx = {1,-1,0,0};
	static int[] dy = {0,0,1,-1};
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		//char[] c = sc.next().toCharArray();
		int INF = Integer.MAX_VALUE;
		int ans = 0;
		
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int X = Integer.parseInt(sc.next());
		int[] L = new int[N];
		int x = 0;
		int count = 1;
		for(int i=0; i<N; i++){
			x += Integer.parseInt(sc.next());
			if(x<=X)count++;
		}
		
		System.out.println(count);
		
	}
}



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

using namespace std;

int main(){
  int N;
  cin >> N;
  
  set<string> S;
  for(int i = 0; i < N; i++){
    string in;
    cin >> in;
    S.insert(in);
  }
  
  cout << S.size() << endl;
  
  return 0;
}

Measured memory_bytes: 19116
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    vector<int> a(3);
    rep(i,3) cin>>a.at(i);
    sort(a.begin(),a.end());
    cout<<a.at(0)+a.at(1)<<endl;

}

Measured memory_bytes: 256
Wab=list(map(int,input().split()))
W=Wab[0]
a=Wab[1]
b=Wab[2]

if b>a+W:
    print(b-a-W)
elif a<=b<=a+W or a<=b+W<=a+W:
    print(0)
else:
    print((a-b-W))
    


Measured memory_bytes: 2940
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef pair<int, int>pii;
int get(pii a,pii b)
{
	if (a > b)swap(a, b);
	return b.second - a.second + b.first - a.first;
}
vector<pii>conv(string s)
{
	s.push_back('#');
	vector<pii>r;
	for (int i = 0; i < s.size() - 1; i++)
	{
		if (s[i] == '1')
		{
			if (s[i + 1] == '1')r.push_back(make_pair(i, i + 1)), i++;
			else r.push_back(make_pair(i, i));
		}
	}
	return r;
}
int solve(vector<pii>a, vector<pii>b, int num)
{
	//for (int i = 0; i < b.size(); i++)printf("%d %d  ", b[i].first, b[i].second); printf("\n");
	int mini = 1000000000;
	for (int p = 0; p <= b.size(); p++)
	{
		int s = 0;
		int l1 = -p, u1 = int(b.size() - p);
		int l2 = 0, u2 = a.size();
		for (int i = l1; i < max(u1, u2); i++)
		{
			bool f1 = l1 <= i&&i < u1, f2 = l2 <= i&&i < u2;
			if (f1)
			{
				if (f2)s += get(a[i], b[i + p]);
				else
				{
					if (i < l2)s += b[i + p].first + b[i + p].second + 1;
					else s += (num - 1 - b[i + p].first) + (num - 1 - b[i + p].second) + 1;
				}
			}
			else if (f2)s += (num - 1 - a[i].first) + (num - 1 - a[i].second) + 1;
		}
		//printf("%d %d\n", p, s);
		mini = min(mini, s);
	}
	return mini;
}
int main()
{
	int num;
	scanf("%d", &num);
	string s1, s2;
	cin >> s1 >> s2;
	vector<pii>v1 = conv(s1), v2 = conv(s2);
	int x = solve(v1, v2, num), y = solve(v2, v1, num);
	printf("%d\n", min(x, y));
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
int mod(ll a){
    int c=a%1000000007;
    if(c>=0)return c;
    else return c+1000000007;
}
typedef pair<int,int> i_i;


int main(){
    int n,m;cin>>n>>m;
    if(n>m){int q=n;n=m;m=q;};
    if(m>=n+2)cout<<"0"<<endl;
    else if(m==n+1){
        ll ans=1;
        for(int i=1;i<=n;i++)ans=mod(ans*i);
        for(int i=1;i<=m;i++)ans=mod(ans*i);
        cout<<ans<<endl;
    }else{
        ll ans=2;
        for(int i=1;i<=n;i++)ans=mod(ans*i);
        for(int i=1;i<=n;i++)ans=mod(ans*i);
        cout<<ans<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;

int main(){
  int n;
  cin >> n;
  
  int M=0,out=1;
  rep(i,n){
    int num = i+1;
    int count = 0;
    while(num%2==0){
      num = num/2;
      count++;
    }
    if(count>M){
      out = i+1;
      M = count;
    }
  }
  
  cout << out << endl;
  
  return 0;
}

Measured memory_bytes: 256
// Last Change: 10/27/2019 21:08:32.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  for (ll i = sqrt(N) + 1, j; i >= 1; --i) {
    if (N % i == 0) {
      j = N / i;
      cout << i + j - 2 << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		int x = Integer.parseInt(input[0]);
		int y = Integer.parseInt(input[1]);

		System.out.println(gcd(x, y));

	}

	public static int gcd(int a, int b){

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

	}

}

Measured memory_bytes: 24244
def sub_c():
    n = int(input())
    a_list = list(map(int, input().split()))

    a_tuple_list = []
    for i, a in enumerate(a_list):
        temp = (a, i)
        a_tuple_list.append(temp)
    a_tuple_list.sort()

    ret = ''
    for t in a_tuple_list:
        ret += str(t[1]+1) + ' '
    print(ret)


if __name__ == '__main__':
    sub_c()


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    #ifdef KP
    freopen("z.in", "r", stdin);
    #endif
    int arr[10] = {0};
    for(int i = 0; i < 4; ++i) {
    	int x;
    	cin >> x;
    	arr[x] = 1;
    }
    if(arr[1] && arr[9] && arr[7] && arr[4]) {
    	cout << "YES" << endl;
    }
    else {
    	cout << "NO" << endl;
    }
    return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int N;
  while(cin >> N){
    vector<vector<int>> cograph(N);
    if(N%2==0){
      REP(i,N/2){
	cograph[i].push_back(N-1-i);
	cograph[N-1-i].push_back(i);
      }
    }else{
      REP(i,N/2){
	cograph[i].push_back(N-2-i);
	cograph[N-2-i].push_back(i);
      }
    }

    vector<vector<int>> graph(N);
    REP(i,N){
      sort(ALL(cograph[i]));
      vector<bool> use(N, true);
      for(auto x : cograph[i]) use[x] = false;
      REP(j,N) if(use[j]) graph[i].push_back(j);
    }

    vector<pair<int,int>> ans;
    REP(i,N){
      for(auto j : graph[i]){
	if(i<j) ans.push_back({i+1,j+1});
      }
    }

    cout << ans.size() << endl;
    for(auto &p : ans){
      cout << p.fst << " " << p.snd << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
bool check(int n,int m,int x,int y) {return x>=0&&x<n&&y>=0&&y<m;}

int a[111][111],d[1<<5][111][111];
map<P,int> ma;
int main() {
  int n,m;
  cin >> m >> n;
  string s[n];
  for(int i=0; i<n; i++) cin >> s[i];
  priority_queue<PP,vector<PP>,greater<PP> > que;
  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
      a[i][j]=1;
      for(int k=0; k<(1<<5); k++) d[k][i][j]=1<<29;
      if(s[i][j]=='S') {
        d[0][i][j]=0;
        que.push(PP(P(0,0),P(i,j)));
      }
      if(s[i][j]=='M') {
        int k=ma.size();
        ma[P(i,j)]=k;
      }
      for(int k=-2; k<=2; k++) {
        for(int l=-2; l<=2; l++) {
          int x=i+k,y=j+l;
          if(!check(n,m,x,y)||s[x][y]!='#') continue;
          int d=max(abs(i-x),abs(j-y));
          if(d==1) a[i][j]=max(a[i][j],3);
          if(d==2) a[i][j]=max(a[i][j],2);
        }
      }
    }
  }
  while(!que.empty()) {
    PP p=que.top();que.pop();
    int xx=p.second.first,yy=p.second.second,cc=p.first.first,tt=p.first.second;
    if(s[xx][yy]=='G'&&tt==(1<<ma.size())-1) {
      cout << d[tt][xx][yy] << endl;
      return 0;
    }
    if(d[tt][xx][yy]<cc) continue;
    for(int i=0; i<4; i++) {
      int x=xx+dx[i],y=yy+dy[i];
      int t=tt;
      if(!check(n,m,x,y)||s[x][y]=='#') continue;
      if(s[x][y]=='M') t|=1<<ma[P(x,y)];
      if(d[t][x][y]<=d[tt][xx][yy]+a[xx][yy]) continue;
      d[t][x][y]=d[tt][xx][yy]+a[xx][yy];
      que.push(PP(P(d[t][x][y],t),P(x,y)));
    }
  }
  return 0;
}

Measured memory_bytes: 4756
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;

int main()
{
	int x0, y0, x1, y1;
	cin >> x0 >> y0 >> x1 >> y1;

	int w = x0 - x1;
	int h = y0 - y1;

	cout << x1 + h << " " << y1 - w << " " << x0 + h << " " << y0 - w << endl;
}

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



int main(){
     char s[100];
     int hug=0;

     scanf("%s",s);
     
     for (int i =0; i < strlen(s)/2; i++){
         if (s[i] != s[strlen(s)-i-1]){
             hug++;
         }
     }
     printf("%d\n", hug);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pii = pair<int, int>; // これ以降 pii という型名はpair<int, int> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
   string s;;
   cin>>s;
   bool ans=true;
   int n=s.size();
   
   for(int i=0;i<(n-1)/2;i++){
      // cout<<s.at(i)<<endl;
      // cout<<s.at(n-1-i)<<endl;
       if(s.at(i)!=s.at(n-1-i)) ans=false;
   }
   
   int k=(n-1)/2;
   
   if(k%2!=0){
       for(int i=0;i<(k-1)/2;i++){
           if(s.at(i)!=s.at(k-1-i)) ans=false;
       }
   }else{
        
        for(int i=0;i<k/2;i++){
            
           if(s.at(i)!=s.at(k-1-i)) ans=false;
       }
   }
   if(ans)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
using namespace std;
int const maxn = 200005;
int fromone[maxn];
int ton[maxn];
int main()
{
    int n, m;
 	scanf("%d %d",&n,&m);
    while(m--)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        if (a == 1)
        {
            fromone[b] = 1;        	
		}
        if (b==n)
        {
            ton[a]=1;        	
		}
	}
    for(int i=2;i<n;i++)
    {
        if (fromone[i] & ton[i])
        {
            printf("POSSIBLE");  
			return 0;      	
		}
	}
    printf("IMPOSSIBLE");
}

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

int main(){
string C1, C2;
cin >> C1 >> C2;
if(C1.at(0) == C2.at(2) && C1.at(1) == C2.at(1) && C1.at(2) == C2.at(0)){
       cout << "YES" << endl;
}
else {
    cout << "NO" <<endl;
}
}

Measured memory_bytes: 256
n,a,b,c = map(int, input().split())
s=[input() for i in range(n)]
ans=[]

def add(c1,c2):
    global a,b,c
    ans.append(c1)
    if c1=="A":
        a+=1
    if c1=="B":
        b+=1
    if c1=="C":
        c+=1
    if c2=="A":
        a-=1
    if c2=="B":
        b-=1
    if c2=="C":
        c-=1

for i in range(n):
    que = s[i]
    nxt="NONE"
    if i!=n-1:
        nxt = s[i+1]

    if que=="AB":
        if a==b==0:
            print("No")
            exit()
        if a==b==1:
            if nxt=="NONE":
                add("A","B")
            elif "A" in nxt:
                add("A","B")
            else:
                add("B","A")
        elif a>=b:
            add("B","A")
        else:
            add("A","B")
    elif que=="AC":
        if a==c==0:
            print("No")
            exit()
        if a==c==1:
            if nxt=="NONE":
                add("A","C")
            elif "A" in nxt:
                add("A","C")
            else:
                add("C","A")
        elif a>=c:
            add("C","A")
        else:
            add("A","C")
    else: # BC
        if b==c==0:
            print("No")
            exit()
        if b==c==1:
            if nxt=="NONE":
                add("B","C")
            elif "B" in nxt:
                add("B","C")
            else:
                add("C","B")
        elif b>=c:
            add("C","B")
        else:
            add("B","C")

print("Yes")
for a in ans:
    print(a)

Measured memory_bytes: 86304
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<vector<int>>>> vvvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<vector<vector<vector<ll>>>> vvvvl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;

int N;

int main() {
  ll sum = 0;
  ll kireme = 0;
  cin >> N;
  vi bou(N);
  for(int i = 0; i < N; i++){
    cin >> bou[i];
    sum += bou[i];
  }
  ll chukan = sum/2;
  ll chukannoi = 0;
  for(int i = 0; i < N; i++){
    if(chukan < kireme + bou[i]){
      chukannoi = i;
      break;
    }
    kireme += bou[i];
  }
  //cout << kireme <<endl;
  //cout << chukannoi <<endl;
  if(max(sum - kireme,kireme) - min(sum - kireme,kireme)> max(sum - (kireme + bou[chukannoi]),kireme + bou[chukannoi]) - min(sum - (kireme + bou[chukannoi]),kireme + bou[chukannoi])){
      kireme += bou[chukannoi];
  }
  //cout << kireme <<endl;
  cout <<max(kireme, sum - kireme) - min(kireme, sum-kireme) <<endl;
}


Measured memory_bytes: 1024
#include<stdio.h>

int L1[19],L2[19],L3[19];
void add(int n);
void PRI(void);
int main(void){
	int n,i;
	
	for(i=0;i<19;i++){
		L1[i]=0;
		L2[i]=0;
		L3[i]=0;
	}
	L1[0]=2;
	L2[0]=1;
		
	scanf("%d",&n);
	if(n==0)printf("%d",2);
	else if(n==1)printf("%d",1);
	else{
		add(n-2);
		PRI();
	}
	
	
	return 0;
}
void add(int n){
	int i,w;
	if(n<0)return;
	w=0;
	for(i=0;i<19;i++){
		L3[i]=L1[i]+L2[i]+w;
		if(L3[i]>=10){
			w = 1;
			L3[i] %=10;
		}else{
			w=0;
		}
	}
	for(i=0;i<19;i++){
		L1[i]=L2[i];
		L2[i]=L3[i];
	}
	add(n-1);
}
//L2に答えが入っているのでL3を出力
void PRI(){
	int i=18;
	while(L2[i]==0)i--;
	while(i!=-1){
		printf("%d",L2[i]);
		i--;
	}
	printf("\n");
	
}

Measured memory_bytes: 128
#a = '2 2'
#b = ['*.', '.*']

h, w = map(int, input().split())
#h, w = map(int, a.split())

in1 = []
for idx1 in range(h):
    in1.append(input())
#    in1.append(b[idx1])

for item1 in in1:
    print(item1)
    print(item1)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int main(){
  string s;
  cin >> s;
  int cnt = 0;
  REP(i,s.size()){
    if(s[i]=='p'){
      cnt++;
    }
  }
  cout << s.size()/2 - cnt << endl;

  return 0;
}


Measured memory_bytes: 512