akhauriyash/Code-Regression huggingface dataset:
//...code_sm....

//27-03-20 19:26
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int n=s.length();
	int f=(n-1)/2;
	string s1(s.begin(),s.begin()+f);
	string s2(s.begin()+f+1,s.end());
		if(s==string(s.rbegin(),s.rend())&&s1==string(s1.rbegin(),s1.rend())&&s2==string(s2.rbegin(),s2.rend()))
	cout<<"Yes";
	else
	cout<<"No";
	}


Measured memory_bytes: 256
program atcoder_contest_scheduling
  implicit none
  integer :: d, c(26) = 0, s(26, 365) = 0, i, j, x = 0
  read(*,*) d
  read(*,*) c
  read(*,*) (s(:, i), i = 1, d)
  do i = 1, d
    write(*,'(i0)') mod(i - 1, 26) + 1
  end do
end program atcoder_contest_scheduling

Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    cout << k - (k > a ? k - a : 0 ) - (k > a + b ? k - (a + b) : 0) << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

#define N 20005

struct q{
    int t, s, d;
};

void bubbleSort(struct q q[N], int n){
    rep(i,n){
        rep(j,n - 1){
            if(q[j].t > q[j + 1].t){
                struct q temp = q[j];
                q[j] = q[j + 1];
                q[j + 1] = temp;
            }
        }
    }
}


int main(){
    int n, m;
    while(cin >> n >> m,n||m){
        bool com[N] = {0};
        com[1] = true;
        q q[N];
        rep(i,m){
            cin >> q[i].t >> q[i].s >> q[i].d;
        }
        bubbleSort(q, m);
        rep(i,m){
            if(com[q[i].d] != 1) com[q[i].d] = com[q[i].s];
        }
        int sum = 0;
        rep(i,n + 1) sum+=static_cast<int>(com[i]);
        cout << sum << endl;
    }
}

Measured memory_bytes: 1420
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		
		while(true)
		{
			//読み込み
			int a = scan.nextInt();
			int b = scan.nextInt();
			if(a+b==0)
				break;

			int[][] work = new int[b+1][a+1];
			int n = scan.nextInt();
			for(int i=0;i<n;i++)
			{
				int x = scan.nextInt();
				int y = scan.nextInt();
				work[y-1][x-1]=1;
			}

			//探索
			int[][] data = new int[b+1][a+1];
			data[0][0]=1;
			for(int i=0;i<b;i++)
			{
				for(int j=0;j<a;j++)
				{
					if(work[i+1][j]==0)
						data[i+1][j]+=data[i][j];
					if(work[i][j+1]==0)
						data[i][j+1]+=data[i][j];
				}
			}

			System.out.println(data[b-1][a-1]);

		}
	}
}

Measured memory_bytes: 20208
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);String l;for(int r=0,x[]={95,63,7,2,3,-3},i;!(l=s.nextLine()).matches("(0 )+0");System.out.println(r+100))for(r=i=0;i<6;)r+=new Integer(l.split(" ")[i])*x[i++];}}

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

int main() {
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    vector<vector<int>> dp(n,vector<int>(3,0));
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(int i=1;i<n;i++)
    {
        dp[i][0] = max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
        dp[i][1] = max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
        dp[i][2] = max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
    }
    int ans=INT_MIN;
    for(int i=0;i<3;i++)
    ans = max(ans,dp[n-1][i]);
    cout<<ans;
	return 0;
}

Measured memory_bytes: 9808
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 1e5 + 5;

char s[3][N];
int cur[3], len[3];

int main()
{
	scanf("%s%s%s", s[0], s[1], s[2]);
	for (int i = 0; i < 3; i++)  len[i] = strlen(s[i]), cur[i] = 0;
	int round = 0, winner = -1, who = 0;
	while (1)
	{
		round++;
		if (cur[who] == len[who])  break;
		char ch = s[who][cur[who]++];
		who = ch - 'a';
	}
	printf("%c\n", 'A' + who);
}

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

int c[10][10];
int a[500][500];

int main(){
	int h,w;scanf("%d%d",&h,&w);
	rep(i,10)rep(j,10)scanf("%d",&c[i][j]);
	rep(i,h)rep(j,w)scanf("%d",&a[i][j]);
	rep(k,10)rep(i,10)rep(j,10)c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
	int sum=0;
	rep(i,h)rep(j,w){
		if(a[i][j]==-1)continue;
		sum+=c[a[i][j]][1];
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 640
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <functional>
#include <set>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a^b^c) << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	t, x := scanFloat64(), scanFloat64()
	fmt.Fprintln(wr, t/x)
}


Measured memory_bytes: 1776
using System;

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            string input;
            while((input = Console.ReadLine()) != null) {
                string output = string.Empty;
                for(int i=0; i < input.Length; ++i) {
                    if(input[i] == '@') {
                        output += new string(input[i + 2], input[i + 1] - '0');
                        i += 2;
                        continue;
                    }
                    output += input[i];
                }
                Console.WriteLine(output);
            }
        }
    }
}

Measured memory_bytes: 5228
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
//    private static final String ex = "1\n" +
//            "10\n" +
//            "2";
//    private static final String ex = "2\n" +
//            "9\n" +
//            "3 6";
//    private static final String ex = "5\n" +
//            "20\n" +
//            "11 12 9 17 12";

    public static void main(String[] args) {
        System.out.println(solve(new Scanner(System.in)));
//        System.out.println(solve(new Scanner(ex)));
    }

    private static int solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());
        int K = Integer.parseInt(scanner.nextLine());
        int[] X = new int[N];
        String[] split = scanner.nextLine().split(" ");
        for (int i = 0; i < N; i ++) {
            X[i] = Integer.parseInt(split[i]);
        }

        int sum = 0;
        for (int i = 0; i < N; i ++) {
            if ((K - X[i]) > X[i]) sum += X[i];
            else sum += Math.abs(K - X[i]);
        }

        return sum * 2;
    }
}


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

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

int exp(int base, int e , int mod){
    int result = 1;
    base %= mod;
    while(e){
        if(e & 1 )
        result =  result  * base % mod;

            base = base * base % mod;
            e >>=1 ;
    }
    return result;
}

void solve() {
    int n;
    cin>>n;
    map<int,int> x;
    for(int i = 0 ; i< n; i++){
        int k;
        cin>>k;
        x[k]++;
    }
    if(n % 2 == 0){
        bool is = true;
        for(auto i :x){
            if(i.first % 2 == 0){
                is = false;
                break;
            }
            if(i.second != 2){
                is = false;
                break;
            }
        }
        if(is){
            cout<<exp(2 , n / 2 , MOD)<<endl;
        }else {
            cout<<0<<endl;
        }

    }else {
        bool is = true;
        int c0 = 0 , c2 = 0;
        for(auto i : x){
            if(i.first % 2 == 1){
                is = false;
                break;
            }
            if(i.second == 2){
                c2++;
            }
            if(i.first == 0){
                c0 += i.second;
            }
        }
        if(is){

            if(c0 == 1 && c2 == (n - 1) / 2){
                cout<<exp(2 , (n - 1) / 2  , MOD)<<endl;
            }else cout<<0<<endl;
        }else {
            cout<<0<<endl;
        }
    }
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
// #include <functional>

using namespace std;

void solve()
{
    // 入力の処理
    int N;
    string S, T;
    cin >> N;
    cin >> S >> T;

    string news = "";

    for (int i = 0; i < N; i++)
    {
        news += (S.substr(i, 1) + T.substr(i, 1));
    }
    cout << news << endl;
    return;
}

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


Measured memory_bytes: 256
def solve():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = list(input())

    player = []
    ans = 0
    for i in range(N):
        winHand = ''
        point = 0
        if T[i] == 'r':
            winHand = 'p'
            point = P
        elif T[i] == 's':
            winHand = 'r'
            point = R
        elif T[i] == 'p':
            winHand = 's'
            point = S

        if i >= K and winHand == player[i-K]:
            point = 0
            winHand = 'other'
        
        ans += point
        player.append(winHand)

    print(ans)
                
if __name__ == '__main__':
    solve()


Measured memory_bytes: 53900
//#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
template<class T>
using V = vector<T>;
template<class T>
using VV = vector<vector<T>>;
typedef unsigned long long ULL;

void input();
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////

string S;

void input() {
	cin >> S;
}

void solve() {
	VI SV(S.size());
	for (int n = 0; n < S.size(); n++) {
		if (S[n] == '0')SV[n] = 0;
		else SV[n] = 1;
	}
	int ans0 = 0;
	for (int n = 0; n < S.size(); n++) {
		if (SV[n] != n % 2)ans0++;
	}
	int ans1 = 0;
	for (int n = 0; n < S.size(); n++) {
		if (SV[n] == n % 2)ans1++;
	}
	cout << min(ans0, ans1) << "\n";
}

Measured memory_bytes: 3484
import static java.util.Arrays.deepToString;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			char[] s = sc.next().toCharArray();
			if (s[0] == '0') break;
			int a = 0;
			int b = 0;
			int n = s.length;
			for (int i = n - 1; i > 0; i--) {
				if (s[i] == 'A') a++; else b++;
			}
			if (a > b) a++; else b++;
			System.out.println(a + " " + b);
		}
	}
}

Measured memory_bytes: 17132
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

int n;
int zers, ones, twos;

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int a; scanf("%d", &a);
		int cnt = 0;
		while (a % 2 == 0) { a /= 2; cnt++; }
		if (cnt == 0) zers++;
		else if (cnt == 1) ones++;
		else twos++;
	}
	if (ones > 0 && zers <= twos || ones == 0 && zers - 1 <= twos) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

ll luca[87];

int main() {
	int n; cin >> n;
	luca[0]=2LL;
	luca[1]=1LL;
	for(int i=2;i<=n;i++) {
		luca[i]=luca[i-1]+luca[i-2];
	}
	cout << luca[n] << endl;
}

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

using P = pair<int, int>;

struct edge {
    int to, cost;
};

using edges = vector<edge>;
using graph = vector<edges>;

constexpr int INF = 1e9;

vector<int> dijkstra(graph& g, int s, vector<vector<int>>& prev) {
    vector<int> d(g.size(), INF);
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(make_pair(0, s));
    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) {
            continue;
        }
        for(auto& e : g[v]) {
            if(d[e.to] >= d[v] + e.cost) {
                if(d[e.to] > d[v] + e.cost) {
                    prev[e.to].clear();
                }
                prev[e.to].push_back(v);
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
    return d;
}

void dfs(int v, vector<vector<int>> const& prev, set<int>& s) {
    s.insert(v);
    for(auto x : prev[v]) {
        dfs(x, prev, s);
    }
}

int main() {
    int N, R;
    cin >> N >> R;
    graph g(N);
    for(int i=0; i<R; ++i) {
        int s, t, d;
        cin >> s >> t >> d;
        s--; t--;
        g[s].push_back((edge){t, d});
        g[t].push_back((edge){s, d});
    }
    int ma = 0;
    set<int> s;
    for(int i=0; i<N; ++i) {
        vector<vector<int>> prev(N);
        vector<int> d = dijkstra(g, i, prev);
        int max_d = *max_element(d.begin(), d.end());
        if(ma <= max_d) {
            if(ma < max_d) {
                s.clear();
            }
            vector<int> max_v;
            for(int j=0; j<N; ++j) {
                if(d[j] == max_d) {
                    max_v.push_back(j);
                }
            }
            for(auto v : max_v) {
                dfs(v, prev, s);
            }
            ma = max_d;
        }
    }
    cout << N - s.size() << endl;
    for(int i=0; i<N; ++i) {
        if(s.count(i) == 0) {
            cout << i + 1 << endl;
        }
    }
}


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

using namespace std;

int main(void) {
    string A, B, C;
    cin >> A >> B >> C;
    if(A.back() == B.front() && B.back() == C.front()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    ll n,t;
    ll a[100010];
    std::cin >> n>>t;
    ll ma = 0;
    ll mi = 1e10;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        ma = max(a[i],ma);
        mi = min(a[i],mi);
    }
    
    ll max_v[100010];
    ll min_v[100010];
    
    max_v[n-1] = a[n-1];
    min_v[0] = a[0];
    
    for (int i = n-2; i >= 0; i--) {
        max_v[i] = max(max_v[i+1],a[i]);
    }
    for (int i = 1; i < n; i++) {
        min_v[i] = min(min_v[i-1],a[i]);
    }
    ll p1[100010];
    ll p2[100010];
    
    for (int i = 0; i < n-1; i++) {
        p1[i] = max_v[i+1]-a[i];
    }
    for (int i = 1; i < n; i++) {
        p2[i] = a[i] - min_v[i-1];
    }
    sort(p1,p1+n-1);
    sort(p2,p2+n-1);
    ll d1 = distance(p1,lower_bound(p1,p1+n-1,p1[n-2]));
    ll d2 = distance(p2,lower_bound(p2,p2+n-1,p2[n-2]));
    // std::cout << n-1-d1<<" "<<n-1-d2 << std::endl;
    std::cout << max(n-1-d1,n-1-d2) << std::endl;
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const ll MOD = 1e9 + 7;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n; string s;
	cin >> n >> s;

	vi cnt[3];
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') cnt[0].push_back(i);
		else if (s[i] == 'G') cnt[1].push_back(i);
		else cnt[2].push_back(i);
	}

	ll ans = (ll)sz(cnt[0]) * sz(cnt[1]) * sz(cnt[2]);
	for (int i : cnt[0]) {
		for (int j : cnt[1]) {
			int a = i, b = j;
			if (a > b) swap(a, b);
			vi v { a - (b - a), b + (b - a) };
			if ((b - a) % 2 == 0 && (b - a > 0)) v.push_back(a + (b - a) / 2);
			for (int x : v) {
				auto it = lower_bound(all(cnt[2]), x);
				if (it != cnt[2].end() && *it == x) ans--;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3640
n,k=map(int,input().split(' '))
a=list(map(int,input().split(' ')))
loc=1
begin=0
end=0
d={1:0}
for i in range(n+1):
    loc=a[loc-1]
    if loc in d.keys():
        begin=d[loc]
        end=i+1
        break
    d[loc]=i+1
if k<=end:
    end=0
if end==begin+1:
    k=begin
    end=0
if end != 0:
    x=(k-begin+1)%(end-begin)
    if x==0:
        x=end-begin
    k=x+begin-1
loc=1
for _ in range(k):
    loc=a[loc-1]
print(loc)

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

const int INF = 1e9;

int main(int argc, char const *argv[]) {
    int N, K;
    vector<int> p;
    int sum = 0;

    cin >> N >> K;
    for (size_t i = 0; i < N; i++) {
        int pi;
        cin >> pi;
        p.push_back(pi);
    }

    sort(p.begin(), p.end());
    for (size_t i = 0; i < K; i++) {
        sum += p[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3596
/*May The Force Be With Me*/
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#pragma GCC optimize ("Ofast")
#define ll long long
#define MOD 1000000007
#define endl "\n"
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define pb push_back
#define f first
#define s second
#define inf INT_MAX
#define size_1d 10000000
#define size_2d 1000
#define rep(i,v,n) for(ll i = v; i < n; i++)
//Snippets: delta, sieve, fastexp, dfs, bfs, dijkstra, floodfill

using namespace std;

ll n;
double N;
double dp[305][305][305]; // each [] checks for plate type

void Input() {
	cin >> n;
	N = n;
}

double func(ll a, ll b, ll c) {
	if (a + b + c == 0)return 0.0;
	if (dp[a][b][c] > -1.0)return dp[a][b][c];
	double ret = 0.0;
	if (a) ret += (func(a - 1, b, c) + N / (a + b + c)) * a / (a + b + c);
	if (b) ret += (func(a + 1, b - 1, c) + N / (a + b + c)) * b / (a + b + c);
	if (c) ret += (func(a, b + 1, c - 1) + N / (a + b + c)) * c / (a + b + c);
	dp[a][b][c] = ret;
	return ret;
}

void Solve() {
	vll a(n), t(4, 0);
	for (ll i = 0; i < n; i++) cin >> a[i], t[a[i]]++;
	memset(dp, -1, sizeof dp);
	double ans = func(t[1], t[2], t[3]);
	cout.precision(12);
	cout << ans;
}

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

	ll T = 1;
	//cin >> T;
	//ll t = 1;
	while (T--) {
		Input();
		//cout << "Case " << t << ": ";
		Solve();
		//t++;
	}
	return 0;
}

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

struct proc {
  string p;
  int t;
};

vector<proc> Q(LEN);
int head = 1, tail = 1;

// キューに値を追加
void Enqueue(proc process) {
  Q[tail] = process;
  tail = (tail + 1) % LEN;
}

// キューから値を取り出し
proc Dequeue() {
  proc process = Q[head];
  head = (head + 1) % LEN;
  return process;
}

int main() {
  int n, q;
  cin >> n >> q;

  for (int i = 1; i <= n; i++) cin >> Q[i].p >> Q[i].t;
  tail = n + 1;

  proc u;
  int exe_time = 0, elaps = 0;
  while (head != tail) {
    u = Dequeue();
    exe_time = min(q, u.t);
    u.t -= exe_time;
    elaps += exe_time;
    if (u.t > 0) {
      Enqueue(u);
    } else {
      cout << u.p << " " << elaps << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 6664
import math 

K = int(input())

def sol(K):
    res = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            t = math.gcd(i, j)
            for k in range(1, K+1):
                res += math.gcd(k, t)

    return res
  
print(sol(K))

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

using namespace std;

typedef long long int ll;
#define inf 0x3f3f3f3f
#define endl '\n'
// #define case(i) "Case #" << i << ": "

vector<vector<ll>> dp;
vector<int> v, w;
int n, tw;

ll solve(int i, int curw) {
    if(i == -1) {
        return 0;
    }
    else {
        if(dp[i][curw] != -1) return dp[i][curw];
        if(curw < w[i]) return dp[i][curw] = solve(i-1, curw);
        else return dp[i][curw] = max(v[i] + solve(i-1, curw - w[i]), solve(i-1, curw));
    }
}

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

    cin >> n >> tw;
    v.resize(n);
    w.resize(n);

    for(int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }

    dp.resize(n+1, vector<ll>(tw + 1, -1));

    cout << solve(n-1, tw) << endl;
}

Measured memory_bytes: 80256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long


long long gcd(long long x, long long y){
    if (x > y)
        return gcd(y, x);
    
    long long m = 1;
    while(m != 0){
        m = y % x;
        y = x;
        x = m;
    }
    return y;
}

long long lcm(long long x, long long y){
    return x * y / gcd(x, y);
}

int main(){
    int n; cin >> n; cout << lcm(2, n) << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest20191101
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int k = int.Parse(s[0]);
            int x = int.Parse(s[1]);
            string ans = "";
            for (int i = 0; i < k * 2 - 1; i++) 
            {
                ans += (x - (k - 1) + i).ToString() + " ";
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,a,b,c,d,e,f,g,h,i,j,k,w,ok,ng,l,ans,q;
ll x[500005],y[500005],z[500005];
ll p[500005],ran[500005],size[500005];
char s[500005],t[500005];
bool flag,dame;

ll find(ll x){
	if(p[x]==x){
		return x;
	}else{
		return p[x] = find(p[x]);
	}
}
void unite(ll x,ll y){
	x = find(x);
	y = find(y);
	if(x==y)return;
	if(ran[x]<ran[y]){
		ans -= size[p[x]] * size[p[y]];
		size[y] = size[p[x]] + size[p[y]];
		p[x]=y;
	}else{
		ans -= size[p[x]] * size[p[y]];
		size[x] = size[p[x]] + size[p[y]];
		p[y]=x;
		if(ran[x]==ran[y])ran[x]++;
	}
}

int main(){
    cin >> n >> m;
	for(i=0;i<m;i++){
		cin >> x[i] >> y[i];
	}
	for(i=0;i<n;i++){
		p[i] = i;
		size[i] = 1;
	}
	ans = n * (n - 1) / 2;
	z[m-1] = n * (n - 1) / 2;
	for(i=m-2;i>=0;i--){
		unite(x[i+1],y[i+1]);
		z[i] = ans;
	}
	for(i=0;i<m;i++){
		p(z[i]);
	}

	return 0;
}

Measured memory_bytes: 37760
#include<iostream>
#include<math.h>
using namespace std;

bool isPrime(int n){
	int sqr = sqrt((double)n)+1;
	if(n%2 == 0)return false;
	for(int i=3;i<=sqr;i+=2){
		if(n%i == 0)return false;
	}
	return true;
}

int main(){

	int n;
	int i, j, sum;
	while(cin >> n){
		if(n==0)break;
		if(n==1)cout << "2" << endl;
		else{
			sum = 2;
			i=1;
			j=3;

			while( i<n ){

				if(isPrime(j)){
					sum+=j;
					++i;
				}
				j+=2;
			}
			cout << sum << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
N,M,C = map(int, raw_input().split())
B = map(int, raw_input().split())
count = 0
for i in range(N):
    A = map(int, raw_input().split())
    mul = [x*y for (x,y) in zip(A,B)]
    if int(sum(mul))+C > 0:
        count += 1
print count     

Measured memory_bytes: 2568
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x;
    cin>>x;
    cout<<1-x<<endl;
    return 0;
}

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

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

    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c)
        cout<<1<<"\n";
    else if(a==b || a==c || b==c)
        cout<<2<<"\n";
    else cout<<3<<"\n";
}


Measured memory_bytes: 3612
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<tuple<string, int, int>> a;
    int n;
    cin >> n;
    int i;
    FOR(i, 1, n + 1) {
      string s;
      int p, id;
      cin >> s >> p;
      p = -p;
      a.emplace_back(s, p, i);
    }
    sort(a.begin(), a.end());

    rep(i, n) {
      cout << get<2>(a[i]) << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int a,b;
  cin>>a>>b;
  
  for(int i=8;i<=1009;i++){
      if(i*8/100==a && i*1/10==b){
       cout<<i<<endl;
       return 0;   
          
      }
      
      }
  
  cout<<-1<<endl;
   
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N;
int W[200], S[200];

int main()
{
  scanf( "%d", &N );
  rep( i, N )
    scanf( "%d", W+i );

  rep( i, N )
    S[i+1] += S[i]+W[i];

  int ans = 1<<30;
  rep( t, N )
    ans = std::min( ans, abs(S[t+1]-(S[N]-S[t+1])) );

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

  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 3e18;
const ll linf = 3e18;
const double eps = 1e-9;

int N, M, K;
int A[20005];
int memo[20005];

int rec(int now)
{
    if (~memo[now]) return memo[now];

    int res = inf;
    int mi = inf, ma = -inf;
    
    for (int i = 0; i < min(N - now, M); ++i) {
        mi = min(mi, A[now + i]);
        ma = max(ma, A[now + i]);

        res = min(res, K + (ma - mi) * (i + 1) + rec(now + i + 1));
    }

    if (res == inf) res = 0;

    return memo[now] = res;
}

signed main()
{ // #define int long long ?????????????????§scanf???????????¨???????????????????????\?????????????????????
    omajinai;
    cin >> N >> M >> K;

    rep(i, N) {
        cin >> A[i];
    }

    memset(memo, -1, sizeof (memo));

    cout << rec(0) << endl;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 9e18
#define mod 1000000007

ll n;
ll st;
ll dp[3];

int main(){
  cin>>n>>st;
  dp[0]=st;dp[1]=-INF;dp[2]=-INF;
  rep(i,n-1){
    char c;
    ll a;
    cin>>c>>a;
    ll nxt[3];
    nxt[0]=nxt[1]=nxt[2]=-INF;
    if(c=='+'){
      maxch(nxt[0],dp[0]+a);

      maxch(nxt[1],dp[1]-a);
      maxch(nxt[0],dp[1]+a);

      maxch(nxt[2],dp[2]+a);
      maxch(nxt[1],dp[2]+a);
      maxch(nxt[0],dp[2]+a);
    }else{
      maxch(nxt[0],dp[0]-a);
      maxch(nxt[1],dp[0]-a);

      maxch(nxt[1],dp[1]+a);
      maxch(nxt[0],dp[1]-a);
      maxch(nxt[2],dp[1]+a);

      maxch(nxt[2],dp[2]-a);
      maxch(nxt[1],dp[2]+a);
      maxch(nxt[0],dp[2]+a);
    }
    dp[0]=nxt[0]; dp[1]=nxt[1]; dp[2]=nxt[2];
  }
  cout<<*max_element(dp,dp+3)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,a[maxn],b[maxn];
int main(){
	n=read();
	b[0]=0x3f3f3f3f;
	for(int i=1;i<n;i++)b[i]=read();
	b[n]=0x3f3f3f3f;
	for(int i=1;i<=n;i++){
		a[i]=min(b[i-1],b[i]);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=a[i];
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int main() {
	int n;
	string s;
	cin >> n >> s;
	
	string ans = "";
	
	for (int i = 0; i < s.length(); i++) {
		int num = s[i] - 'A';
		num = (num + n) % 26;
		ans += num + 'A';
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
a,b,c,d,e,f=map(int, input().split())

t=0

ans1,ans2=100*a,0
for i in range(31):
    for j in range(31):
        for k in range(101):
            for l in range(101):
                x = 100*a*i+100*b*j
                y = c*k+d*l
                if x==0:
                    break
                if x/100*e<y:
                    break
                if x+y>f:
                    break
                if y/(x+y)>t:
                    t=y/(x+y)
                    ans1,ans2=x+y,y
print(ans1,ans2)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i = 0; i < N; ++i) {
    cin >> X[i];
  }
  sort(X.begin(), X.end());
  int mn = X[0];
  int mx = X[N - 1];
  int min_j = 0;
  int min_sum = 1<<30;
  for (int j = mn; j <= mx; ++j) {
    int sum = 0;
    for (int i = 0; i < N; ++i) {
      sum += (X[i] - j) * (X[i] - j);
    }
    if (sum < min_sum) {
      min_j = j;
      min_sum = sum;
    }
  }
  cout << min_sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef long long int64;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
template<class T,class U>bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(n);
    int64 ans=0;
    rep1(i, n){
        if (i%3!=0 && i%5!=0)
            ans += i;
    }
    co(ans);

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
const ll inf = 1e9+7;

int main() {
	int n;
	cin >> n;
	int l[n];
	ll sum = 0;
	for (int i = 0;i < n;i++) {
		cin >> l[i];
		sum += l[i];
	}
	for (int i = 0;i < n;i++) {
		if (l[i] * 2 >= sum) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
def main():
    west_tower_height, east_tower_height = map(int, input().split(" "))
    east_tower_num = east_tower_height - west_tower_height
    print(east_tower_num * (east_tower_num + 1) // 2 - east_tower_height)


if __name__ == '__main__':
    main()

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const ll MAX = 10000;
static const ll INFTY = 1e12;
static const ll MOD = 1e9+7;

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() {

 string S;
 int A, B;
 cin >> A >> B >> S;

 REP(i, A){
   if(S[i] >= '0' && S[i] <= '9'){

   }else{
     cout << "No" << endl;
     return 0;
   }
 }
 if(S[A]!='-'){
     cout << "No" << endl;
     return 0;  
 }
 REP(i, B){
   if(S[i+A+1] >= '0' && S[i+A+1] <= '9'){

   }else{
     cout << "No" << endl;
     return 0;
   }
 }
 cout << "Yes" << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

const int INF = 0x3fffffff;

int N;
int M;
vector<pii> edges[2145141];
vector<int> cs;
vector<int> cols[114514];
vector<int> vers[2114514];
int mind[2145141];
bool watched[2145141];
int num_comp;

void Decompose(int c) {
  map<int, int> belong;
  map<int, vector<int>> groups;

  for (pii &p : edges[c]) {
    int u, v;
    tie(u, v) = p;
    if (!belong.count(u)) {
      belong[u] = u;
      groups[u] = vector<int>(1, u);
    }

    if (!belong.count(v)) {
      belong[v] = v;
      groups[v] = vector<int>(1, v);
    }

    int bu = belong[u];
    int bv = belong[v];
    if (bu == bv) continue;

    if (groups[bu].size() < groups[bv].size()) swap(bu, bv);
    for (int p : groups[bv]) {
      groups[bu].eb(p);
      belong[p] = bu;
    }
    groups.erase(bv);
  }

  map<int, int> mapp;
  for (auto &itr : belong) {
    int idx = itr.second;
    if (!mapp.count(idx)) {
      mapp[idx] = num_comp++;
    }
    int grp = mapp[idx];
    cols[itr.first].pb(grp);
    vers[grp].pb(itr.first);
  }
}

int main() {
  scanf("%d%d", &N, &M);
  rep(i, M) {
    int c;
    int u, v;
    scanf("%d%d%d", &u, &v, &c);
    --u;
    --v;
    edges[c].eb(pii(u, v)); 
    cs.eb(c);
  }
  sort(all(cs));
  cs.erase(unique(all(cs)), cs.end());

  rep(c, 1e6+1) {
    if (edges[c].empty()) continue;
    Decompose(c);
  }

  fill(mind, mind+2145141, INF);
  queue<int> que;
  for (int c : cols[0]) {
    mind[c] = 0;
    que.push(c);
  }

  while (!que.empty()) {
    int c = que.front(); que.pop();
    for (int v : vers[c]) {
      if (watched[v]) continue;
      watched[v] = true;
      for (int nc : cols[v]) {
        if (mind[nc] == INF) {
          mind[nc] = mind[c] + 1;
          que.push(nc);
        }
      }
    }
  }

  int ans = INF;
  for (int c : cols[N-1]) {
    ans = min(ans, mind[c]);
  }
  if (ans == INF) puts("-1");
  else 
  printf("%d\n", ans+1);
}


Measured memory_bytes: 128116
#関節点(そのノードを除くとグラフが非連結になる点)
import sys
class LowLinks:
    def __init__(self, edges, v, root=0):
        self.edges = edges
        self.root = root
        self.ord = [None] * v
        self.low = [None] * v
        self.cnt = 0
        self.bridges = []
        self.articulations = set()
        self.par = [None] * v

    def build(self):
        self.search(self.root)

    def search(self, x):
        self.ord[x] = self.cnt
        self.low[x] = self.cnt
        self.cnt += 1
        dim = 0
        for to in self.edges[x]:
            if to == self.par[x]:continue
            if self.ord[to] != None:
                self.low[x] = min(self.low[x], self.ord[to])
            else:
                self.par[to] = x
                self.search(to)
                dim += 1
                self.low[x] = min(self.low[x], self.low[to])

                if x != self.root and self.ord[x] <= self.low[to]:
                    self.articulations.add(x)

            if x == self.root and dim > 1:
                self.articulations.add(x)

            if self.ord[x] < self.low[to]:
                self.bridges.append((x, to))

sys.setrecursionlimit(1000000)
n,m=map(int,input().split())
edges=[[] for _ in range(n)]
for _ in range(m):
    s, t = map(int, input().split())
    edges[s].append(t)
    edges[t].append(s)

l=LowLinks(edges,n)
l.build()
for i in sorted(l.articulations):
    print(i)



Measured memory_bytes: 19280
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    long long n,k;
    cin>>n>>k;
    long long helf=0;
    long long zero=0;
    
    for(int i=1;i<=n;i++){
        if(i%k==(double)k/2) helf++;
        if(i%k==0) zero++;
    }
    
    cout<<helf*helf*helf + zero*zero*zero<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST_IO   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin),freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define mfill(a,v) memset(a,v,sizeof(a))
#define INF 0x3f3f3f3f
#define MAX 200005
#define v_n 5005
#define LL long long
#define ULL unsigned long long 
#define e_n 50005
#define eps 0.000000001
#define Blen 32
const LL MOD = 998244353;
using namespace std;
const int N = 2e5 + 50;
const int M = 1e6 + 50;
int n, u, v;
struct Edge {
	int v, next;
}edge[M];
int cnt;
int head[N], fir[N], sec[N];
bool vis[N];
void init() {
	cnt = 0;
	memset(head, -1, sizeof(head));
}
void addEdge(int u, int v) {
	edge[cnt] = Edge{ v,head[u] };
	head[u] = cnt++;
	edge[cnt] = Edge{ u,head[v] };
	head[v] = cnt++;
}
int ans;
//树形dp
void dfs(int u) {
	vis[u] = 1;
	//最长路和次长路
	fir[u] = 0;
	sec[u] = 0;
	for (int i = head[u]; i != -1; i = edge[i].next) {
		int v = edge[i].v;
		if (!vis[v]) {
			//递归下去更新子节点信息
			dfs(v);
			//子节点的最长路+1更长，可以更新当前节点信息
			//当前节点的最长路变成次长路
			if (fir[v] + 1 >= fir[u]) {
				sec[u] = fir[u];
				fir[u] = fir[v] + 1;
			}
			//子节点信息只能更新次长路
			else if (fir[v] + 1 > sec[u]) {
				sec[u] = fir[v] + 1;
			}
		}
	}
	//更新整个树的信息
	ans = max(ans, fir[u] + sec[u]);
	return;
}
bool dp[MAX];
int main(void) {
	//Relocate;
	scanf("%d", &n);
	init();
	for (int i = 0; i < n-1 ; i++) {
		scanf("%d%d", &u, &v);
		addEdge(u, v);
	}
	dfs(1);
	int i;
	dp[1] = 0;
	dp[2] = 1;
	ans++;
	up(i, 3, ans)
	{
		dp[i] = (!dp[i - 1] && !dp[i - 2]);
		
	}
	if (!dp[ans])
	{
		cout << "First\n";
	}
	else
	{
		cout << "Second\n";
	}
	return 0;
}

Measured memory_bytes: 12416
//Daniel Grzegorzewski
#include <bits/stdc++.h>

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios()
{
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = (int)1e5 + 10;

int h, w, n, a[N], b[N], res[11], all;
map<PII, bool> vis, visC;

int max(int a, int b)
{
	if (a >= b)
		return a;
	return b;
}

signed main()
{
    init_ios();
    cin >> h >> w >> n;
    for (int i = 1; i <= n; ++i) {
    	cin >> a[i] >> b[i];
    	vis[{a[i], b[i]}] = true;
    }
    for (int i = 1; i <= n; ++i) {
    	for (int p = max(a[i]-2, 1); p <= a[i]; ++p)
    		for (int q = max(b[i]-2, 1); q <= b[i]; ++q) {
    			if (p+2 > h || q+2 > w)
    				continue;
    			if (visC[{p, q}])
    				continue;
    			visC[{p, q}] = true;
    			int tmp = 0;
    			for (int x = 0; x < 3; ++x)
    				for (int y = 0; y < 3; ++y)
    					if (vis.find({p+x, q+y}) != vis.end())
    						++tmp;
    			if (tmp > 0) {
    				++res[tmp];
    				++all;
    			}
    		}
    }
    res[0] = (h-2)*(w-2)-all;
    for (int i = 0; i < 10; ++i)
    	cout<<res[i]<<"\n";
}

Measured memory_bytes: 64384