akhauriyash/Code-Regression huggingface dataset:
/*Alohomora*/
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define mod1        987654319 
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll fact(ll n){ if(n==0){return 1;}return (n*fact(n-1))%mod1;}
ll power(ll x, ll y,ll mod){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
ll inverse(ll a){return power(a,mod1-2,mod1);}
ll gcd(ll a,ll b){if(b==0){return a;}gcd(b,a%b);}
ll a[2000000];
void sieve(){ll i,j;fli(i,2,1000001){if(a[i]==0){for(j=i*i;j<1000001;j+=i){a[j]=1;}}}}
map<ll,vector<ll> >m1;
vector<ll>v1;
bool compar(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second);
} 
ll level[1000000];
vector<ll>root;
set<ll>s1;
void factorise(long long n) 
{ 
    while (!(n%2)) 
    { 
        n >>= 1; 
        s1.insert(2);
    } 
    for (long long i=3; i<=sqrt(n); i+=2) 
    { 
        while (n%i==0) 
        { 
        	s1.insert(i);
            n=n/i; 
        } 
    } 
  	if (n>2) 
  	{
       s1.insert(n);
	}
} 
void comp()
{
	ll l,i,j,k,q,n,d,m,temp=0,sum,count=0;
	cin>>n;
	vector<pair<ll,ll> >v1;
	fl(i,n)
	{
		cin>>j;
		v1.pb(mp(j,i+1));
	}
	sort(v1.begin(),v1.end());
	fl(i,n)
	{
		if(v1[n-1].second==i+1)
		{
			cout<<v1[n-2].first;
		}
		else
		{
			cout<<v1[n-1].first;
		}
		cout<<endl;
	}
} 
int main()
{
	speedup;
	ll i=0,t;
	ll n;
	//cin>>t;
	t=1;
	while(t--)
	{
	 comp();
	}
}

Measured memory_bytes: 8048
import java.util.Arrays;
import java.util.Scanner;

//Old Bridges
public class Main{

	class R implements Comparable<R>{
		int a, b;
		public R(int a, int b) {
			super();
			this.a = a;
			this.b = b;
		}
		public int compareTo(R o) {
			return b-o.b;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			R[] r = new R[n];
			for(int i=0;i<n;i++)r[i]=new R(sc.nextInt(), sc.nextInt());
			Arrays.sort(r);
			int s = 0;
			boolean f = true;
			for(int i=0;i<n;i++){
				s += r[i].a;
				if(r[i].b < s)f = false;
			}
			System.out.println(f?"Yes":"No");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
C = [list(map(int,input().split())) for _ in range(3)]

b = [C[0][i]-0 for i in range(3)]
a = [C[i][0]-b[0] for i in range(3)]

ans = "Yes"
for i in range(3):
  for j in range(3):
    if(C[i][j] != a[i]+b[j]):
      ans = "No"
print(ans)

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

int main()
{
    char a, b;
    cin >> a >> b;
    if (a == 'H')
        cout << b << endl;
    else
    {
        if (b == 'H')
            cout << 'D' << endl;
        else
            cout << 'H' << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i=int(a),nn=int(b);i<=nn;++i)
#define vep(i,a,b) for(int i=int(a),nn=int(b);i>=nn;--i)
#define xep(i,b) for(int i=0,nn=int(b);i<nn;++i)
#define x first
#define y second
#define mp make_pair
#define ad insert
#define dl erase

typedef pair<int,int> ii;
typedef multiset<int> mi;

const int N = 100100;

mi lk[N];
map<ii, bool> mii;
queue<ii> q;

int tms, n;
int xx[N], yy[N];
int sz[N], f[N];

void inst(int x, int y) {
	if (x > y) swap(x, y);
	if (mii[mp(x,y)]) return;
	mii[mp(x,y)] = 1, q.push(mp(x,y));
}

void in(int &x) {
	char c = getchar(); int f=1;
	for (; c<'0' || c>'9'; c=getchar()) f=(c=='-'?-1:f);
	for (x=0; c>='0' && c<='9'; c=getchar()) x=x*10+c-48;
	x *= f;
}

int find(int x) {
	if (f[x] != x) f[x] = find(f[x]);
	return f[x];
}

int main() {

	in(n);
	int x, y;
	rep(i, 1, n-1) {
		in(x), in(y);
		lk[x].ad(y), lk[y].ad(x);
	}
	rep(i, 1, n-1) {
		in(x), in(y);
		lk[x].ad(y), lk[y].ad(x);
		xx[i] = x, yy[i] = y;
	}

	rep(i, 1, n-1) {
		x = xx[i], y = yy[i];
		if (lk[x].count(y) >= 2)
			inst(x, y);
	}

	rep(i, 1, n) sz[i] = 1, f[i] = i;

	ii no;
	mi::iterator it;
	int nx;
	while (!q.empty()) {
		no = q.front(), q.pop();
		x = no.x, y = no.y;

		if (find(x) != x || find(y) != y || find(x) == find(y))
			continue;
		++ tms;
		if (sz[x] < sz[y]) swap(x, y);
		sz[x] += sz[y];
		f[y] = x;

		lk[x].dl(y), lk[y].dl(x);
		for (it = lk[y].begin(); it != lk[y].end(); it++) {
			nx = *it;
			lk[x].ad(nx);
			if (lk[x].count(nx)>=2) inst(x, nx);
			int tmp = lk[nx].count(y);
			if (!tmp) continue;
			lk[nx].dl(y);
			while (tmp --) lk[nx].ad(x);
		}
		lk[y].clear();
	}

	if (tms == n-1) puts("YES");
	else puts("NO");
	return 0;
}



Measured memory_bytes: 28544
N = int(input())
W = []
for i in range(N):
    W.append(input())

already = [W[0]]
out='Yes'
for i in range(1,N):
    if W[i-1][-1] != W[i][0]:
        out='No'
        break
    elif W[i] in already:
        out='No'
        break
    already.append(W[i])

print(out)

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

using namespace std;
#define INF 999999999
class Position
{
public:
	int x, y;
};

void solve()
{
	int N;
	while(cin >> N, N)
	{
		vector<Position> p(N);
		for(int i = 0; i < N; ++i)
		{
			cin >> p[i].x >> p[i].y;
		}
		Position current;
		current.x = 10;
		current.y = 10;
		int M;
		cin >> M;
		int count = 0;
		for(int i = 0; i < M; ++i)
		{
			char c;
			int move;
			cin >> c >> move;
			if(c == 'N')
			{
				for(int j = 0; j < move; ++j)
				{
					current.y += 1;
					for(int k = 0; k < N; ++k)
					{
						if(current.x == p[k].x && current.y == p[k].y)
						{
							++count;
							p[k].x = INF;
							p[k].y = INF;
						}
					}
				}
			}
			else if(c == 'E')
			{
				for(int j = 0; j < move; ++j)
				{
					current.x += 1;
					for(int k = 0; k < N; ++k)
					{
						if(current.x == p[k].x && current.y == p[k].y)
						{
							++count;
							p[k].x = INF;
							p[k].y = INF;
						}
					}
				}
			}
			else if(c == 'S')
			{
				for(int j = 0; j < move; ++j)
				{
					current.y -= 1;
					for(int k = 0; k < N; ++k)
					{
						if(current.x == p[k].x && current.y == p[k].y)
						{
							++count;
							p[k].x = INF;
							p[k].y = INF;
						}
					}
				}
			}
			else if(c == 'W')
			{
				for(int j = 0; j < move; ++j)
				{
					current.x -= 1;
					for(int k = 0; k < N; ++k)
					{
						if(current.x == p[k].x && current.y == p[k].y)
						{
							++count;
							p[k].x = INF;
							p[k].y = INF;
						}
					}
				}
			}
		}
		if(count == N)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
}

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

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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

vector<int> g[maxn];
const int l = 17;
int tin[maxn], tout[maxn], timer;
int up[20][maxn];

void dfs(int u, int p = 0) {
    tin[u] = timer++;
    up[0][u] = p;
    for (int i = 1; i <= l; i++) {
        up[i][u] = up[i - 1][up[i - 1][u]];
    }
    for (auto x : g[u]) {
        if (x != p) {
            dfs(x, u);
        }
    }
    tout[u] = timer++;
}

bool isAncestor(int a, int b) {
    return tin[a] <= tin[b] and tout[a] >= tout[b];
}

int lca(int a, int b) {
    if (isAncestor(a, b))
        return a;
    if (isAncestor(b, a))
        return b;

    for (int i = l; i >= 0; i--) {
        if (!(isAncestor(up[i][a], b)))
            a = up[i][a];
    }
    return up[0][a];
}

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

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

        for(int j = 0; j < k;j++){
            int p;
            cin >> p;

            g[i].push_back(p);
            g[p].push_back(i);
        }
    }

    dfs(0 , 0);

    int q;
    cin >> q;

    while (q--) {
        int a, b;
        cin >> a >> b;

        cout << lca(a, b) << endl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 28932
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
int main(){
    //freopen("tt.in","r",stdin),freopen("tt.out","w",stdout);
    cin>>a>>b;
    ll gys=gcd(a,b);
    int ans=1;
    for(ll i=2;i*i<=gys;i++){
        if(gys%i==0){
            ans++;
            while(gys%i==0)gys/=i;
        }
    }
    if(gys>1)ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.range;
import std.stdio;
import std.math;
import std.array;
import std.string;
import std.conv;

/// 数列の読み込み
auto readNums() {
	return readln().chomp.split.map!(to!int);
}

/// 数の読み込み
auto readNum() {
	return readNums.front;
}

void main() {
    const nums = readNums.array;
    immutable h = nums[0];
    immutable w = nums[1];

	const field = generate(() => readln).map!strip.take(h).array;

    char[][] answer = [];
    answer.length = h;
    foreach(ref s; answer) {
        s.length = w;
    }

    foreach(y; 0 .. h) {
        foreach(x; 0 .. w) {
            if(field[y][x] == '#') {
                answer[y][x] = '#';
                continue;
            }

            size_t n = 0;
            immutable left = (x == 0);
            immutable right = (x == w - 1);
            immutable top = (y == 0);
            immutable bottom = (y == h - 1);

            n += (!left && (field[y][x - 1] == '#')) ? 1 : 0;
            n += (!right && (field[y][x + 1] == '#')) ? 1 : 0;
            n += (!top && (field[y - 1][x] == '#')) ? 1 : 0;
            n += (!top && !left && (field[y - 1][x - 1] == '#')) ? 1 : 0;
            n += (!top && !right && (field[y - 1][x + 1] == '#')) ? 1 : 0;
            n += (!bottom && (field[y + 1][x] == '#')) ? 1 : 0;
            n += (!bottom && !left && (field[y + 1][x - 1] == '#')) ? 1 : 0;
            n += (!bottom && !right && (field[y + 1][x + 1] == '#')) ? 1 : 0;
            answer[y][x] = cast(char)('0' + cast(int) n);
        }
    }

    answer.each!writefln;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#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>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

const int inf=2147483647;

int n;
int a[222222];
int b[222222];

int main()
{
	cin>>n;
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n/2;i++)
	{
		b[i]=a[(n/2-i+1)*2];
	}
	for(int i=n/2+1;i<=n;i++)
	{
		b[i]=a[(i-n/2)*2-1];
	}
	
	if(n%2==1)
	{
		reverse(b+1,b+n+1);
	}
	
	for(int i=1;i<=n;i++)
	{
		cout<<b[i]<<' ';
	}
	cout<<endl;
	
	return 0;
}

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

int main() {
	int H;
	long long a[251];
	cin >> H;
	for (int i = 1; i <= H; i++)
		scanf("%lld", &a[i]);
	for (int i = 1; i <= H; i++) {
		cout << "node " << i << ": key = " << a[i] << ", ";
		if (i != 1) cout << "parent key = " << a[i / 2] << ", ";
		if (2 * i <= H) cout << "left key = " << a[2 * i] << ", ";
		if (2 * i + 1 <= H) cout << "right key = " << a[2 * i + 1] << ", ";
		cout << endl;
	}
}


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

int main(){
    int k; cin >> k;
    string s; cin >> s;
    if(s.size() <= k) cout << s << endl;
    else{
        for(int i = 0; i < k; ++i) cout << s[i];
        cout << "..." << endl;
    }
    return 0;
}


Measured memory_bytes: 3588
import java.util.*
//
//fun <T> permutationList(sortedList: List<T>): List<List<T>> {
//    val queue = ArrayDeque<List<T>>()
//    queue.addLast(arrayListOf())
//    val permutations = mutableListOf<List<T>>()
//    while (queue.isNotEmpty()) {
//        val p = queue.removeLast()
//
//        if (p.size == sortedList.size) {
//            permutations.add(p)
//            continue
//        }
//
//        for (item in (sortedList - p)) {
//            queue.addLast(p + item)
//        }
//    }
//
//    return permutations
//}

fun <T> permutation2(sortedList: List<T>): List<List<T>> {
    if (sortedList.size == 1) {
        return listOf(sortedList)
    }

    val aa = mutableListOf<List<T>>()
    for (item in sortedList) {
        for (b in permutation2(sortedList - item)) {
            aa.add(listOf(item) + b)
        }
    }

    return aa
}

fun main(args: Array<String>) {
    val n = readInteger()
    val p = readIntegerList()
    val q = readIntegerList()

    val per = permutation2((1..n).toList())
    Math.abs(per.indexOf(p) - per.indexOf(q)).let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 62988
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

int main(){
	int n, m, x, suml = 0, sumr = 0;
	cin >> n >> m >> x;
	int a[m];
	REP(i,m) cin >> a[i];
	REP(i,x){
		REP(j,m){
			if(i == a[j]) suml++;
		}
	}
	FOR(i,x,n){
		REP(j,m){
			if(i == a[j]) sumr++;
		}
	}
	cout << min(suml, sumr) << endl;
	return 0;
}


Measured memory_bytes: 256
a,b=map(int,input().split())
if a%2==0 and b%2==0:
    k=(b-a)//2
    print(b^(k%2))
elif a%2==0 and b%2==1:
    k=(b-a+1)//2
    print(k%2)
elif a%2==1 and b%2==0:
    k=(b-a-1)//2
    print(a^b^k%2)
else:
    k=(b-a)//2
    print(a^(k%2))

Measured memory_bytes: 3064
def solve():
    N = int(input())

    numDivs = [0] * (N+1)
    for div in range(1, N+1):
        for x in range(div, N+1, div):
            numDivs[x] += 1

    ans = 0
    for C in range(1, N+1):
        ans += numDivs[N-C]

    print(ans)


solve()


Measured memory_bytes: 75524
n,m = map(int,input().split())
path = {}
for i in range(m):
    a,b = map(int,input().split())
    if a not in path:
        path[a] = [b]
    else:
        path[a].append(b)

ns = []
if 1 in path:
    for p in path[1]:
        ns.append(p)

    flag = False
    for mid in ns:
        if mid in path:
            if n in path[mid]:
                flag = True
                break

    if flag:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

else:
    print("IMPOSSIBLE")



Measured memory_bytes: 30736
<?php

fscanf(STDIN, "%d %d", $n, $k);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));

$i1;
$l = 0;
$r = $n;
while ($r - $l >= 1) {
    $mid = intdiv($r + $l, 2);
    /* echo "l: $l, r: $r, mid: $mid", PHP_EOL; */
    if ($A[$mid] === 1) {
        $i1 = $mid;
        break;
    } else if ($A[$mid] > 1) {
        $r = $mid;
    } else {
        $l = $mid + 1;
    }
}

// 左には$i1こ
// 右には$n - 1 - $i1こ

/* echo "i1: $i1, " . ceil($i1 / ($k - 1)) . ", " . ceil(($n - 1 - $i1) / ($k - 1)), PHP_EOL; */
echo ceil($i1 / ($k - 1)) + ceil(($n - 1 - $i1) / ($k - 1));


Measured memory_bytes: 16884
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)        (x).begin(), (x).end()    //昇順
#define rall(x)       (x).rbegin(), (x).rend()  //降順
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes           out("Yes");
#define no            out("No");

int main() {
    in(x);
    if (1800 <= x) {
        out(1);
        return 0;
    }
    if (1600 <= x) {
        out(2);
        return 0;
    }
    if (1400 <= x) {
        out(3);
        return 0;
    }
    if (1200 <= x) {
        out(4);
        return 0;
    }
    if (1000 <= x) {
        out(5);
        return 0;
    }
    if (800 <= x) {
        out(6);
        return 0;
    }
    if (600 <= x) {
        out(7);
        return 0;
    }
    if (400 <= x) {
        out(8);
        return 0;
    }
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);  
    int k , a, b;
    cin >> k >> a >> b;
    repk(i,a,b+1){
        if(i%k==0) {cout << "OK" << endl;return 0;}
    }
    cout << "NG" << endl;

    return 0;
}


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

class Cmondai
{
    static void Main()
    {
        var ny = Console.ReadLine().Split(' ').Select(x=>Int64.Parse(x)).ToArray();
        var N = ny[0];
        var Y = ny[1];
        for (long x=0;x<=N;++x)
        {
            for (long y=N-x;0<=y;--y)
            {
                long z = N - (x + y);
                if (10000 * x + 5000 * y + 1000 * z == Y)
                {
                    Console.WriteLine($"{x} {y} {z}");
                    return;
                }
            }
        }
        Console.WriteLine($"-1 -1 -1");
    }
}

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

#define S 10000000
int par[S];
int  r[S];

void init(int n){
    for(int i = 0;i < n;i++){
        par[i] = i;
        r[i] = 0;
    }

}

//calculate tree's root
int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

//union x-set and y-set
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return ;

    if(r[x] < r[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(r[x] == r[y]) r[x]++;
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}

int main(){
    int n, m;
    cin >> n >> m;
    int p[n];
    for(int i = 0;i < n;i++) cin >> p[i];
    int x[m],y[m];
    for(int i = 0;i < m;i++){
        cin >> x[i] >> y[i];
    }
    init(n);

    for(int i = 0;i < m;i++){
        unite(x[i]-1, y[i]-1);
    }

    int ans = 0;
    for(int i = 0;i < n;i++){
        if(same(i, p[i]-1)) ans++;
    }
    cout << ans << endl;


}

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

int main(){
    int N;
    cin >> N;
    char dam = getchar();

    int red = 0;
    for(int i = 0; i < N; i++){
        char ltr = getchar();
        if(ltr == 'R')
            red++;
    }
    
    if(red > N / 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

const int IINF = 2002002002;
const ll LINF = 9009009009009009009L;

//===



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


	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}

	Vi X(M);
	for (int i = 0; i < M; ++i) {
		cin >> X[i];
	}

	sort(X.begin(), X.end());

	int sum = 0;
	Vi dist(M - 1);
	for (int i = 0; i < M - 1; ++i) {
		int d = X[i + 1] - X[i];
		dist[i] = d;
		sum += d;
	}
	
	sort(dist.begin(), dist.end());

	for (int i = M - 2; i >= M - N; --i) {
		sum -= dist[i];
	}

	cout << sum << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int Thp,Tat,Ahp,Aat;
  cin>>Thp>>Tat>>Ahp>>Aat;
  if((Thp+Aat-1)/Aat >= (Ahp+Tat-1)/Tat){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

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

int main(){
  int K;
  cin >> K;
  queue<int64_t> que;
  for(int i=1;i<10;i++){
    que.push(i);
  }
  for(int i=0;i<K;i++){
    int64_t x=que.front();
    que.pop();
    if(i==K-1){
      cout << x << endl;
      return 0;
    }
    if(x%10!=0){
      que.push(x*10+x%10-1);
    }
    que.push(x*10+x%10);
    if(x%10!=9){
      que.push(x*10+x%10+1);
    }
  }
  return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll n, z, w;
	vector<ll> v;

	cin >> n >> z >> w;

	REP(i, n) {
		ll a;
		cin >> a;
		v.push_back(a);
	}

	if (n > 1) {
		cout << max(abs(v[n - 1] - w), abs(v[n - 2] - v[n - 1])) << endl;
	}
	else {
		cout << abs(v[n - 1] - w) << endl;
	}
}

Measured memory_bytes: 256
#https://atcoder.jp/contests/abc070/tasks/abc070_b

a,b,c,d=map(int,input().split())

s1=set()
s2=set()

for i in range(a,b+1):
    s1.add(i)

for i in range(c,d+1):
    s2.add(i)

s1_s2_and=s1&s2
if len(s1_s2_and)==0:
    print(0)
else:
    print(len(s1_s2_and)-1)

Measured memory_bytes: 61808
#include<iostream>
#include<vector>
using namespace std;
int n,m,ts,sum=0;
int p[10];
bool s_list[10];
vector<int> s[10];
void nib(int i){
  if(i==n){
    bool f=true;
    for(int j=0;j<m;j++){
      int su=0;
      for(int k=0;k<s[j].size();k++){
        if(s_list[s[j][k]-1]) su++;
      }
      if(su%2 != p[j]) return;
    }
    sum++;
    return;
  }
  s_list[i]=true;
  nib(i+1);
  s_list[i]=false;
  nib(i+1);
}
int main(){
int k;
  cin >> n >> m;
  for(int i=0;i<n;i++) s_list[i]=false;
  for(int i=0;i<m;i++){
    cin >> k;
    for(int j=0;j<k;j++){
      cin >> ts;
      s[i].push_back(ts);
    }
  }
  for(int i=0;i<m;i++){
    cin >> p[i];
  }
  nib(0);
  cout << sum <<endl;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n;
string s;

int main(void) {
  // Here your code !
  scanf("%d", &n);
  cin >> s;

  s.push_back('_');  // guard

  int ans = 0;

  for (int i = 1; i <= n; ++i) {
    if (s[i] != s[i - 1]) ans += 1;
  }

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

  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
//void quick(int *,long long,long long);
//int comp(char *a,char *b);

int main(){
	
	char a[100];
	char b[100];
	char c;
	int i,j,k,n;

	n=100;
	i=0;
	j=0;
	while(scanf("%c",&c)!=EOF){
		if(c=='\n'){
			j--;
			if(j==2&&( (b[0]-'t')-(b[1]-'h')+52 )%26==0&&( (b[0]-'t')-(b[2]-'e')+52 )%26==0)
				n=b[0]-'t';
			if(j==3&&( (b[0]-'t')-(b[1]-'h')+52 )%26==0&&( (b[0]-'t')-(b[2]-'i')+52 )%26==0&&( (b[0]-'t')-(b[3]-'s')+52 )%26==0)
				n=b[0]-'t';
			if(j==3&&( (b[0]-'t')-(b[1]-'h')+52 )%26==0&&( (b[0]-'t')-(b[2]-'a')+52 )%26==0&&( (b[0]-'t')-(b[3]-'t')+52 )%26==0)
				n=b[0]-'t';
			n+=52;
			n=n%26;

			if(n==100)
				printf("error");
			for(j=0;j<i;j++){
				if(a[j]>='a'&&a[j]<='z'){
					a[j]-=n;
					if(a[j]<'a')
						a[j]+=26;
					else if(a[j]>'z')
						a[j]-=26;
				}
					printf("%c",a[j]);
			}
			printf("\n");
			n=100;
			i=0;
			j=0;
		}else{
			a[i]=c;
			i++;
			if(c>='a'&&c<='z'){
				b[j]=c;
				j++;
				if(j>10)
					j=0;
			}else{
				j--;
				if(j==2&&( (b[0]-'t')-(b[1]-'h')+52 )%26==0&&( (b[0]-'t')-(b[2]-'e')+52 )%26==0)
					n=b[0]-'t';
				if(j==3&&( (b[0]-'t')-(b[1]-'h')+52 )%26==0&&( (b[0]-'t')-(b[2]-'i')+52 )%26==0&&( (b[0]-'t')-(b[3]-'s')+52 )%26==0)
					n=b[0]-'t';
				if(j==3&&( (b[0]-'t')-(b[1]-'h')+52 )%26==0&&( (b[0]-'t')-(b[2]-'a')+52 )%26==0&&( (b[0]-'t')-(b[3]-'t')+52 )%26==0)
					n=b[0]-'t';
				j=0;
			}
		}
	}
	//for(i=0;i<=1000000000;i++);
	return 0;
}

Measured memory_bytes: 524
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int a = sc.nextInt();
                int b = sc.nextInt();
                String s = sc.next();
                sc.close();
                for(int i = 0 ; i < n ; i++){
                        if(s.charAt(i) == 'c'){
                                System.out.println("No");
                        }else if(s.charAt(i) == 'a'){
                                if(a + b > 0){
                                        a--;
                                        System.out.println("Yes");
                                }else{
                                        System.out.println("No");
                                }
                        }else{
                                if(a + b > 0 && b > 0){
                                        System.out.println("Yes");
                                        b--;
                                }else{
                                        System.out.println("No");
                                        b = 0;
                                }
                        }
                }
        }
}

Measured memory_bytes: 50852
#include<iostream>
#include<queue>
#include<tuple>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

template<typename T>
std::vector<std::vector<T>> mk2d(size_t s1, size_t s2, T const& val) {
  std::vector<T> tmp(s2, val);
  return std::vector<std::vector<T>>(s1, tmp);
}
int const dx[4] = {0, 1, 0, -1};
int const dy[4] = {1, 0, -1, 0};
int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int H, W; std::cin >> H >> W;
  int count = 0;
  auto bm = mk2d(H+2, W+2, '#');
  for(int h = 1; h <= H; ++h) {
    for(int w = 1; w <= W; ++w) {
      std::cin >> bm[h][w];
      if(bm[h][w]=='.') ++count;
    }
  }
  auto dist = mk2d(H+2, W+2, H*W+1);
  std::queue<std::tuple<int,int,int>> q;
  q.emplace(1, 1, 0);
  while(!q.empty()) {
    int x, y, c;
    std::tie(x, y, c) = q.front(); q.pop();
    if(dist[y][x] <= c) continue;
    dist[y][x] = c;
    for(int i = 0; i < 4; ++i) {
      int nx = x+dx[i];
      int ny = y+dy[i];
      if(bm[ny][nx] == '.') q.emplace(nx, ny, c+1);
    }
  }
  if(dist[H][W] == H*W+1) fin(-1);
  fin(count - (dist[H][W]+1));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)

void self_min(ll &a, ll b) {
	a = min (a,b);
}
template <class T>
void self_max(T &a, T b) {
	a = max(a,b);
}
void add(ll &a, ll b) {
	a = (a+b)% 1000000007;
}

int main() {
	ios::sync_with_stdio(false);

	string s, t; cin >> s >> t;
	if (sz(t) > sz(s)) {
		swap(t,s);
	}

	vvl dp(sz(t) + 1, vl(sz(s) + 1, 0));

	FOR(i,1,sz(t) + 1) {
		FOR(j,1,sz(s) + 1) {
			if (t[i-1] == s[j-1]) {
				self_max(dp[i][j], dp[i-1][j-1] + 1);
			}
			self_max(dp[i][j], dp[i][j-1]);
			self_max(dp[i][j], dp[i-1][j]);
		}
	}

	vector<char> erg;
	pll pos = {sz(t)-1, sz(s)-1};
	while(true) {
		if (pos.xx < 0 || pos.yy < 0) {
			break;
		}

		if(t[pos.xx] == s[pos.yy]) {
			erg.pb(t[pos.xx]);
			if (pos.xx == 0 && pos.yy == 0) {
				break;
			}
			pos.xx--;
			pos.yy--;
			continue;
		}

		if (pos.yy == 0) {
			pos.xx--; continue;
		}
		if (pos.xx == 0) {
			pos.yy--; continue;
		}

		if (dp[pos.xx][pos.yy+1] < dp[pos.xx+1][pos.yy]) {
			pos.yy--;
		} else {
			pos.xx--;
		}
	}
	FORD(i,0,sz(erg)) {
		cout << erg[i];
	}
	cout << endl;


}


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

int main() {
    string s;
    cin >> s;
    for (int i = 1; i < s.length(); i++) {
        if (s[i] == s[i - 1]) {
            cout << "Bad\n";
            return 0;
        }
    }
    cout << "Good\n";
    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string a[55][55];
  for (int i=0; i<H; i++) {
    string str;
    cin >> str;
    for (int j=0; j<W; j++) {
      a[i][j] = str[j];
    }
  }

  const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
  const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

  string b[55][55];
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (a[i][j] == "#") {
        b[i][j] = a[i][j];
        continue;
      } else {
        int num = 0;
          for (int d = 0; d < 8; ++ d) {
            const int ni = i + dy[d];
            const int nj = j + dx[d];
            if (ni < 0 or H <= ni) continue;
            if (nj < 0 or W <= nj) continue;
            if (a[ni][nj] == "#") num++;
          }
          b[i][j] = char(num + '0');
      }
    }
  }
  for (int i=0; i<H; i++) {
    stringstream ss;
    for (int j=0; j<W; j++) {
      ss << b[i][j];
    }
    cout << ss.str() << endl;
  }
  return 0;
}


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

int main(){
  string S;
  cin>>S;
  
  int a=0,b=0,c=0;
  for(int i=0;i<3;i++){
    if(S[i]=='a') a++;
    if(S[i]=='b') b++;
    if(S[i]=='c') c++;
  }
  if(a==1&&b==1&&c==1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
  	cin >> a >> b >> c >> d;
  	a=a+b;
  	c+=d;
  	if(a>c){
    	cout << "Left\n";
    }
  	else if(a<c){
    	cout << "Right\n";
    }
  	else{
    	cout << "Balanced\n";
    }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
template<typename T>
T lcm(T a, T b) {
    return a / gcd(max(a, b), min(a, b)) * b; //先に割る!!
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    int l[n];
    l[0] = a[0];
    rrep(i, 1, n) l[i] = gcd(a[i], l[i - 1]);
    int r[n];
    r[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; --i) {
        r[i] = gcd(a[i], r[i + 1]);
    }
    int ans = 0;
    if (n == 1) {
        cout << a[0] << endl;
        return 0;
    } else if (n == 2) {
        cout << max(a[0], a[1]) << endl;
        return 0;
    }
    ans = max(r[1], l[n - 2]);
    rep(i, n - 2) {
        int tmp = gcd(l[i], r[i + 2]);
        chmax(ans, tmp);
    }
    cout << ans << endl;
}




Measured memory_bytes: 1408
#入力
N = int(input())
H = list(map(int,input().split()))
#後述のif文条件にて、条件から外れる時のみ記録するので終端が壁(大きい値)になるようにする。
H.append(float('inf'))
#カウント用変数
count = 0
ans = 0
#リストの前後要素比較。壁にぶち当たったら記録&カウントリセット。
for i in range(N):
  if H[i] >= H[i+1]:
    count += 1
  else:
    ans = max(ans,count)
    count = 0
#結果
print(ans)

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

int main(int argc, char const *argv[])
{
    long k;
    cin >> k;
    if (k % 2 == 0 || k % 5 == 0)
    {
        cout << -1 << endl;
        return 0;
    }
    long counter = 1;
    long seven = 7;
    while (true)
    {
        if (seven % k == 0)
        {
            break;
        }
        seven %= k;
        seven = (seven * 10) + 7;
        counter++;
    }
    cout << counter << endl;
    return 0;
}


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

int main(void) {
    char b;cin>>b;
    if (b == 'A') cout << "T" << endl;
    if (b == 'C') cout << "G" << endl;
    if (b == 'T') cout << "A" << endl;
    if (b == 'G') cout << "C" << endl;
    return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b/a, c) << "\n";
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.array;

void main() {
    int n = readln.chomp.to!int;
    string[] s = new string[](n);
    char[5] initial = ['M', 'A', 'R', 'C', 'H'];
    long[5] num;

    for (int i = 0; i < n; ++i) {
        s[i] = readln.chomp;
        
        for (int j = 0; j < 5; ++j) {
            if (s[i][0] == initial[j]) {
                num[j]++;
                break;
            }
        }
    }

    long ans;

    for (int i = 0; i < 5; ++i) {
        for (int j = i + 1; j < 5; ++j) {
            for (int k = j + 1; k < 5; ++k) {
                ans += (num[i] * num[j] * num[k]);
            }
        }
    }

    writeln(ans);

    return;
}

Measured memory_bytes: 6780
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

ll m=1e9+7,a[200005],dp[200005],c[200005];

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
rep(i,0,n-1)cin>>a[i];

dp[0]=1;
c[a[0]]=1;

rep(i,1,n-1)
{
	dp[i]=dp[i-1];
	if(a[i]==a[i-1])continue;
	dp[i]=(dp[i]+c[a[i]])%m;
	c[a[i]]=(dp[i])%m;
}

ol(dp[n-1]);

return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(i == n-1)
        {
          if(x == a[i]) ans++;
          break;
        }
        if(x >= a[i])
        {
            ans++;
            x -= a[i];
        }
        else break;
    }
    cout << ans << endl;
}


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

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

struct Node{
    int key;
    Node *prev, *next; 
};

Node *sentinel;

void init() {
    sentinel = (Node *)malloc(sizeof(Node));
    sentinel->prev = sentinel;
    sentinel->next = sentinel;
}

void insert(int key) {
    // 与えられたキーをもつノードを生成
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;

    // それをリストの先頭に追加
    x->next = sentinel->next;
    sentinel->next->prev = x;
    sentinel->next = x;
    x->prev = sentinel;
}
// 見つけたノードのポインタまたは番兵を返す
Node* linerSearch(int key) {
    // 番兵の次の要素から探す
    Node *current = sentinel->next;
    while(true) {
        // 発見もしくは番兵sentinelまで戻ってしまった場合、探索終了
        if(current->key == key || current == sentinel) break;

        current = current->next;
    }
    return current;
}

// ポインタを繋ぎ変えることで、指定されたノードtを削除する
// C++では、削除するノードのメモリを解放する必要がある
void deleteNode(Node* t) {
    if(t == sentinel) return; // 番兵のとき処理をしない

    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(sentinel->next);
}

void deleteLast() {
    deleteNode(sentinel->prev);
}

void deleteKey(int key) {
    Node* target = linerSearch(key);
    deleteNode(target);
}

void printList() {
    Node* x = sentinel->next;
    
    while(x != sentinel) {
        if(x->next == sentinel) { // xが最後のノードの場合
            printf("%d\n",x->key);
        }
        else {
            printf("%d ", x->key);
        }
        x = x->next;
    }
}

int main() {
    int n,key;
    char command[20];

    init();
    
    scanf("%d",&n);
    rep(i,n) {
        //scanf("%s%d",command,&key);
        scanf("%s", command);
        //printf("command:%s\n", command);

        if(command[0] == 'i') {
            scanf("%d",&key);
            insert(key);
            continue;
        }
        if(command[0] == 'd') {
            if(strlen(command) < 7) {
                scanf("%d",&key);
                deleteKey(key);
                continue;
            }
            if(command[6] == 'F') {
                //printf("deleteFirstが呼び出された\n");
                deleteFirst();
            }
            else if(command[6] == 'L') {
                //printf("deleteLastが呼び出された\n");
                deleteLast();
            }
        }
    }
 
    printList();
    
    return 0;
}


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

int main() {
  
  int a,b;
  cin >> a >> b;
  
  cout << (a-1) * (b-1) << endl;
  
}


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

const int nmax=8;
bool graph[nmax][nmax];

int dfs(int v,int N,bool visited[nmax]){
    bool all_visited=true;
    for (int i = 0; i < N; i++) {
        if(visited[i]==false){
            all_visited=false;
        }
    }
    if(all_visited)return 1;
    
    int ret=0;
    
    for (int i = 0; i < N; i++) {
        if(graph[v][i]==false) continue;
        if(visited[i]) continue;
        
        visited[i]=true;
        ret+=dfs(i,N,visited);
        visited[i]=false;
    }
    
    return ret;
}

int main(void){
    int n,m;
    std::cin >> n >>m;
    for (int i = 0; i < m; i++) {
        int a,b;
        std::cin >> a >>b;
        graph[a-1][b-1]=graph[b-1][a-1]=true;
    }
    
    bool visited[nmax];
    for (int i = 0; i < n; i++) {
        visited[i]=false;
    }
    visited[0]=true;
    std::cout << dfs(0,n,visited) << std::endl;
    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=double;

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

const int limit=150010;
using edge=struct{int to,rev;};
vector<edge> graph[limit];
vector<R> dp[limit];

vector<R> sum;
vector<int> cnt;

void add_edge(int from,int to){ 
	graph[from].push_back({to,int(graph[to].size())});
	graph[to].push_back({from,int(graph[from].size())-1});
	dp[from].push_back(-1.0);
	dp[to].push_back(-1.0);
}

R dfs(int v,int i){
	if(i==-1){
		const int m=graph[v].size();
		
		R ret=0.0;
		if(cnt[v]>=2) return sum[v]/m;
		
		rep(j,m){
			const int nv=graph[v][j].to;
			const int ni=graph[v][j].rev;
			ret+=dfs(nv,ni)+1.0;
		}
		sum[v]=ret,cnt[v]=2;
		ret/=m;
		return ret;
	}else{
		R &ret=dp[v][i];
		if(ret>=0.0) return ret;
		ret=0.0; 

		const int m=int(graph[v].size());
			
		if(cnt[v]<=1){
			rep(j,m){
				if(j==i) continue;
				const int nv=graph[v][j].to;
				const int ni=graph[v][j].rev;
				ret+=dfs(nv,ni)+1.0;
			}

			sum[v]=ret;
			if(m!=1) ret/=(m-1);
			
			cnt[v]++;
			if(cnt[v]==2){
				const int nv=graph[v][i].to;
				const int ni=graph[v][i].rev;
				sum[v]+=dfs(nv,ni)+1.0;
			}
		}else{
			ret=sum[v];
			{
				const int nv=graph[v][i].to;
				const int ni=graph[v][i].rev;
				ret-=dfs(nv,ni)+1.0;
			}
			if(m!=1) ret/=(m-1);
		}
		return ret;
	}
}

int main(void){
	int n;
	scanf("%d",&n);
	
	cnt=vector<int>(n,0);
	sum=vector<R>(n,0.0);

	rep(i,n-1){
		int u,v;
		scanf("%d %d",&u,&v);
		u--,v--;
		add_edge(u,v);
	}

	rep(i,n) printf("%.20lf\n",dfs(i,-1));

	return 0;
}

Measured memory_bytes: 31104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/


const int MAX = 105000;
const int mod = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
 
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

vector<pair<int, int>> factorization(int M){
    vector<pair<int, int>> factors;

    for(int i=2; i*i<=M; i++){
        int cnt = 0;
        while(M%i == 0){
            cnt++;
            M /= i;
        }
        if(cnt) factors.push_back({i, cnt});
    }
    if(M != 1) factors.push_back({M, 1});

    return factors;
}

int main(){
    int N, M; cin >> N >> M;
    
    vector<pair<int, int>> factors = factorization(M);

    COMinit();
    ll ans = 1;
    for(int i=0; i<factors.size(); i++){
        int s = factors[i].second;
        ans *= COM(s+N-1, s);
        ans %= mod;
    }

    cout << ans << endl;
}



Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    n %= 10;
    if (n == 3) {
        cout << "bon" << newl;
    } else if (n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon" << newl;
    } else {
        cout << "hon" << newl;
    }
}

Measured memory_bytes: 3604
import sys
A, B = map(int, input().split())
S = input()
if len(S) != A + B + 1:
    print('No')
    sys.exit()
for i, s in enumerate(S):
    if i < A:
        if s not in '0123456789':
            print('No')
            sys.exit()
    elif i == A:
        if s != '-':
            print('No')
            sys.exit()
    else:
        if s not in '0123456789':
            print('No')
            sys.exit()
print('Yes')

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    char c;
    cin >> c;
    if(c == 'a' or c=='e' or c=='i' or c=='o' or c=='u') cout << "vowel" << endl;
    else cout << "consonant" << endl;
}


Measured memory_bytes: 256
N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a%b)


def lcm(a, b):
    return a*b // gcd(a, b)


ans = 1
for t in T:
    ans = lcm(ans, t)
print(ans)


Measured memory_bytes: 9060