akhauriyash/Code-Regression huggingface dataset:
using System;

namespace AizuOnLine
{
    class Program
    {
        static void Main(string[] args)
        {
            string data = Console.ReadLine();
            int count = int.Parse(Console.ReadLine());

            for (int i = 0; i < count; i++)
            {
                string command = Console.ReadLine();
                string[] splitData = command.Split(' ');
                int start = int.Parse(splitData[1]);
                int end = int.Parse(splitData[2]);

                if (command.StartsWith("replace"))
                {
                    string replaceWord = splitData[3];
                    data = Program.Replace(data, start, end, replaceWord);
                }
                else if (command.StartsWith("reverse"))
                {
                    data = Program.Reverse(data, start, end);
                }
                else if (command.StartsWith("print"))
                {
                    Program.Print(data, start, end);
                }
            }
        }

        static void Print(string data, int start, int end)
        {
            Console.WriteLine(data.Substring(start, end - start + 1));
        }

        static string Reverse(string data, int start, int end)
        {
            char[] charArray = new char[data.Length];

            for (int i = 0; i < data.Length; i++)
            {
                if (start <= i && i <= end)
                {
                    charArray[i] = data[end + (start - i)];
                }
                else
                {
                    charArray[i] = data[i];
                }
            }

            return new string(charArray);
        }

        static string Replace(string data, int start, int end, string str)
        {
            string replaceStr = string.Empty;

            //????????¨???
            if (0 < start)
            {
                replaceStr = data.Substring(0, start);
            }

            replaceStr += str;

            //????????¨???
            if (end < data.Length - 1)
            {
                replaceStr += data.Substring(end + 1, data.Length - 1 - end);
            }

            return replaceStr;
        }
    }

}

Measured memory_bytes: 10068
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int mod;

struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x(x%mod) {}
    mint(std::string s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& n) {
        return os << n.x;
    }
    bool operator==(const mint a) const {
        return this->x == a.x;
    }
};

int n;
vector<vector<int>> tree;
vector<mint> node; // iを根とする部分木でiが黒に塗られる組数
vector<mint> ans;

void dfs1(int v, int p = -1) {
    mint res = 1;
    for (int &u : tree[v]) {
        if (u == p) continue;
        dfs1(u, v);
        res *= (node[u] + 1);
    }
    node[v] = res;
}

void dfs2(int v, mint d_par, int p = -1) {
    // v における答えの計算
    ans[v] = 1;
    for (int &u : tree[v]) {
        if (u == p) {
            ans[v] *= (d_par + 1);
        }
        else {
            ans[v] *= (node[u] + 1);
        }
    }
    // 左右からの累積演算を用いて子に送る d_par の計算
    // lf[i] : [:i-1]の演算結果
    // ri[i] : [i+1:]の演算結果
    int e = 1; // 演算の単位元 ( maxの場合 -INF )
    vector<mint> lf(tree[v].size(), e), ri(tree[v].size(), e);
    for (int i = 1; i < tree[v].size(); i++) {
        if (tree[v][i - 1] == p) {
            lf[i] = lf[i - 1];
        }
        else {
            lf[i] = (node[tree[v][i - 1]] + 1) * lf[i - 1];
        }
    }
    for (int i = tree[v].size() - 2; i >= 0; i--) {
        if (tree[v][i + 1] == p) {
            ri[i] = ri[i + 1];
        }
        else {
            ri[i] = (node[tree[v][i + 1]] + 1) * ri[i + 1];
        }
    }
    for (int i = 0; i < tree[v].size(); i++) {
        if (tree[v][i] == p) continue;
        dfs2(tree[v][i], lf[i] * ri[i] * (p >= 0 ? d_par + 1 : e), v);
    }
}

int main() {
    cin >> n >> mod;
    tree.resize(n);
    node.resize(n);
    ans.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    dfs1(0);
    dfs2(0, 0);
    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 19456
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String st;
		int ioiCount, joiCount;
		
		while (sc.hasNext()) {
			st = sc.next();
			ioiCount = 0;
			joiCount = 0;
			for (int i = 0; i < st.length() - 2; i++) {
				if (st.charAt(i) == 'I' && st.charAt(i + 1) == 'O' && st.charAt(i + 2) == 'I') {
					ioiCount++;
				} else if (st.charAt(i) == 'J' && st.charAt(i + 1) == 'O' && st.charAt(i + 2) == 'I') {
					joiCount++;
				}
			}
			System.out.println(joiCount);
			System.out.println(ioiCount);
		}
	}
}

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

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

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

void Main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> state(n, 0);
  vector<int> box;
  for (int i = n-1; i>=0; --i) {
    if (state[i] == a[i]) continue;
    int x = 1;
    while( x*x < i+1 ) {
      if ((i+1) % x == 0) {
        state[x - 1] ^= 1;
        state[(i+1)/x - 1] ^= 1;
      }
      x++;
    }
    if (i+1 == x*x) state[x - 1] ^= 1;
    box.push_back(i+1);
  }
  cout << box.size() << endl;
  for (int b : box) cout << b << " ";
  cout << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

int a[102];
int main()
{
    int n;
    while(cin >> n)
    {
        for(int i = 0;i < n;i++)
        cin >> a[i];
        sort(a,a + n);
        int sum = 0;
        for(int i = 0;i < n - 1;i++)
        sum += a[i];
        if(sum > a[n - 1])
        cout << "Yes" << endl;
        else
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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 (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;


lint D;
lint decrease[26];
lint satis[365][26];
lint prv[26];

lint downscore(lint passed) {
	lint sum = 0;
	REP(i, 26) {
		sum += decrease[i] * (passed - prv[i]);
	}
	return -sum;
}

signed main() {
	cin >> D;
	REP(i, 26) {
		cin >> decrease[i];
	}
	REP(i, D) {
		REP(j, 26) {
			cin >> satis[i][j];
		}
	}

	REP(i, D) {
		cout << (i % 26) + 1 << endl;
	}
}


Measured memory_bytes: 3696
n,x,y=map(int,input().split())
ans=[[1000000]*n for i in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        ans[i][j]=min(j-i,abs(x-1-i)+1+abs(y-1-j))
_ans=[0]*(n-1)
for i in range(n-1):
    for j in range(i+1,n):
        _ans[ans[i][j]-1]+=1
for i in range(n-1):
    print(_ans[i])


Measured memory_bytes: 83192
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M, K;
const int EXPN = 1 << 16;
int d[20], v[110][110];
bool dp[EXPN-1][30];
int dark[110];
int to[EXPN-1][110];
int dist[EXPN-1];
bool visited[EXPN-1];

signed main() {
    memset(dp, false, sizeof(dp));
    memset(dark, -1, sizeof(dark));
    memset(visited, false, sizeof(visited));
    cin >> N >> M >> K;
    rep(i,0,M) {
        cin >> d[i];
        d[i]--;
        // i ???????????????????????????????????? (????????´?????????????????????????????????)
        dark[ d[i] ] = i;
    }
    rep(i,0,N) rep(j,0,K) {
        cin >> v[i][j];
        v[i][j]--;
        // ???????????????????????°??????????????\??????
        if(dark[ v[i][j] ] == -1) v[i][j] = -1;
        else v[i][j] = dark[ v[i][j] ];
    }

    rep(j,0,K) {
        rep(bit,0,1<<M) {
            int nbit = 0;
            rep(i,0,M) {
                if(bit >> i & 1) {
                    if(v[d[i]][j] < 0) continue;
                    int val = 1 << v[d[i]][j];
                    nbit |= val;
                }
            }
            to[bit][j] = nbit;
        }
    }
    
    rep(i,0,1<<M) dist[i] = INF;
    dist[(1<<M)-1] = 0;
    queue<int> q;
    q.push((1<<M)-1);
    while(!q.empty()) {
        int t = q.front(); q.pop();
        rep(i,0,K) {
            int nx = to[t][i];
            if(dist[nx] > dist[t] + 1) {
                dist[nx] = dist[t] + 1;
                q.push(nx);
            }
        }
    }
    cout << dist[0] << endl;
    return 0;
}

Measured memory_bytes: 62200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,s,k;
  while(cin>>a>>b,a){
    int m=1e9;
    for(int i=1;i*i<=a;i++){
      if(a%i)continue;
      for(int j=1;j*j<=b;j++){
        if(b%j)continue;
        int p[4];
        p[0]=i;p[1]=a/i;p[2]=j;p[3]=b/j;
        sort(p,p+4);
        for(s=k=0;k<3;k++)s+=(p[k+1]-p[k])*(p[k+1]-p[k]);
        m= min(m,s);
    }
  }
  cout<<m<<endl;
}
}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+10;
const int mod=1e9+7;
int col,row;
int bgx,bgy,edx,edy;
int f[N][N],vis[N][N];
int mv[4][2]={1,0,-1,0,0,1,0,-1};
queue<pair<int,int> >q;
void dfs1(int x,int y,int v){
    if(vis[x][y]!=-1) return;
    q.push(make_pair(x,y));
    vis[x][y]=v;
//    cout<<x<<":"<<y<<":"<<v<<endl;
    for(int i=0;i<4;i++){
        int dx=x+mv[i][0],dy=y+mv[i][1];
        if(dx>=1&&dx<=row&&dy>=1&&dy<=col&&vis[dx][dy]==-1&&f[dx][dy]==1)
            dfs1(dx,dy,v);
    }
    return;
}
void dfs2(int x,int y,int v){
    if(x==bgx&&y==bgy) dfs1(x,y,v);
    queue<pair<int,int> >q1;
    while(!q.empty()){
        int tx=q.front().first,ty=q.front().second;
        q.pop();
        for(int i=-2;i<=2;i++){
            for(int j=-2;j<=2;j++){
                int dx=tx+i,dy=ty+j;
                if(dx>=1&&dx<=row&&dy>=1&&dy<=col&&vis[dx][dy]==-1&&f[dx][dy]==1){
                    q1.push(make_pair(dx,dy));
//                    cout<<x<<":"<<y<<":"<<dx<<":"<<dy<<endl;
                }
            }
        }
    }
    while(!q1.empty()){
        int tx=q1.front().first,ty=q1.front().second;
//        cout<<tx<<":"<<ty<<":"<<v<<":"<<vis[tx][ty]<<endl;
        q1.pop();
        dfs1(tx,ty,v+1);
    }
    if(q.size()) dfs2(x+1,y,v+1);
    return ;
}
int main() {;
  // freopen("../in.in", "r", stdin);
//    freopen("../out.out","w",stdout);
    ios::sync_with_stdio(false);
    int t,i,j=0;
    int m,x,n,y;
    int k;
    char ch;
    cin>>row>>col>>bgx>>bgy>>edx>>edy;
    memset(vis,-1,sizeof(vis));
    for(i=1;i<=row;i++){
        for(j=1;j<=col;j++){
            cin>>ch;
            if(ch=='.') f[i][j]=1;
        }
    }
    dfs2(bgx,bgy,0);
    cout<<vis[edx][edy]<<endl;
//    cout<<vis[4][6]<<endl;
    return 0;
}


Measured memory_bytes: 143592
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	for (int t = 0; t <= 300; ++t) {
		int hoge = c + t * 60;
		if (hoge % (a + b) <= a) {
			cout << hoge << endl;
			return;
		}
	}
	cout << -1 << endl;
}
#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3216
#include<map>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
ll n,cnt,a[100005],x;
map<ll,int> m;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]),m[a[i]]++;
	sort(a+1,a+1+n);
	cnt=unique(a+1,a+1+n)-a-1;
	//for(int i=1;i<=cnt;i++) printf("%lld ",a[i]);
	for(int i=cnt;i;i--)
	{
		if(m[a[i]]<2) continue;
		if(x)
		{
			printf("%lld",x*a[i]);
			return 0;
		}
		if(m[a[i]]>=4)
		{
			printf("%lld",a[i]*a[i]);
			return 0;
		}
		x=a[i];
	}
	puts("0");
	return 0;
}

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

double W, H, x, y;

int main() {
    cout << fixed << setprecision(20);
    cin >> W >> H >> x >> y;

    double S = W*H / 2;
    int num = 0;
    if (x == W/2 && y == H/2) num = 1;

    cout << S << " " << num << endl;
    
    return 0;
}

Measured memory_bytes: 384
#pragma comment(linker, "/stack:640000000")

#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
using namespace std;
#define ll long long int
#define scanl(a) scanf("%lld",&a)
#define scanii(a,b) scanf("%d%d",&a,&b)
#define scaniii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scanll(a,b) scanf("%lld%lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scani(a) scanf("%d",&a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
#define pii pair<int,int>
#define sqr(a) a*a
#define eps 1e-9
#define inf INT_MAX
#define pi acos(-1.0)
#define ff first
#define ss second
#define INF 1e18
#define endl '\n'
#define vsort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
int fx[]={0,0,-1,1,-1,1,1,-1};
int fy[]={1,-1,0,0,1,1,-1,-1};
#ifdef shaft
     #define debug(args...) {cerr<<"Debug: "; dbg,args; cerr<<endl;}
#else
    #define debug(args...)  // Just strip off all debug tokens
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;


int main()
{
     ios_base::sync_with_stdio(0);
     cin.tie(0);
    #ifdef shaft
       // freopen("in.txt","r",stdin);
        ///freopen("out.txt","w",stdout);
    #endif ///shaft
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a=max(a,c);
    b=min(b,d);
    int ans=max(0,b-a);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
using System.ComponentModel;

class Program
{
    static void Main(string[] args)
    {
        var alice = new Magatro();
        alice.Scan();
        alice.Solve();
    }
}

public class Scanner
{
    private StreamReader Sr;
    private string[] S;
    private int Index;
    private const char Separator = ' ';

    public Scanner() : this(Console.OpenStandardInput())
    {
        Index = 0;
        S = new string[0];
    }
    public Scanner(Stream source)
    {
        Sr = new StreamReader(source);
    }

    private string[] Line()
    {
        return Sr.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public T Next<T>()
    {
        var converter = TypeDescriptor.GetConverter(typeof(T));
        return (T)converter.ConvertFromString(Next());

    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public decimal NextDecimal()
    {
        return decimal.Parse(Next());
    }
    public string[] StringArray(int index = 0)
    {
        Next();
        Index = S.Length;
        return S.Skip(index).ToArray();
    }
    public int[] IntArray(int index = 0)
    {
        return StringArray(index).Select(int.Parse).ToArray();
    }
    public long[] LongArray(int index = 0)
    {
        return StringArray(index).Select(long.Parse).ToArray();
    }
    public bool EndOfStream
    {
        get { return Sr.EndOfStream; }
    }
}

public class Magatro
{
    private int N;
    private long[] A;

    public void Scan()
    {
        Scanner cin = new Scanner();
        N = cin.NextInt();
        A = cin.LongArray();
    }

    public void Solve()
    {
        Array.Sort(A, (a, b) => -a.CompareTo(b));

        long sum = 0L;
        for (int i = 0; i < N; i++)
        {
            sum += A[i];
        }

        for (int i = 0; i < N; i++)
        {
            sum -= A[i];
            if (sum * 2 < A[i])
            {
                Console.WriteLine(i + 1);
                return;
            }
        }
    }

}



Measured memory_bytes: 27996
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 100100;
const long double PI = acos(-1);

bool compare(vector<int> a, vector<int> b){
    int n = a.size();
    for (int i=0; i<n; i++){
        if(a[i] != b[i] ) return false;
    }
    return true;
}
 
int main (){
    int n, pi, qi;
    cin >> n;

    vector<int> p(n), q(n), a(n);

    for (auto& x: p) cin >> x;
    for (auto& x: q) cin >> x;

    for (int i=0; i<n; i++){
        a[i] = i+1;
    }
    int id = 1;
    do{
        if (compare(a, p)) pi = id;
        if (compare(a, q)) qi = id;
        id++;
    }while (next_permutation(all(a)));
    

    cout << abs(pi - qi) << endl;
    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto n = readLong();
    auto a = readLongs();
    long m0 = 0;
    long m1 = 1;
    foreach(ai; a) {
        if(ai % 2 == 0) {
            long m0_ = m0 * 3 + m1;
            long m1_ = m1 * 2;
            m0 = m0_;
            m1 = m1_;
        } else {
            m0 = m0 * 3 + m1 * 2;
        }
    }
    writeln(m0);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 6
#define NA 100
#define Q 24
using namespace std;

void change(char);
int dice[N];

int main(){
  
  char arrow[]="NWNWNW";
  string str;
  int i,j,num,x,y;

  for(i=0;i<N;i++)cin>>dice[i];
  cin>>num;
  
  for(i=0;i<num;i++){
    cin>>x>>y;
    for(j=0;j<6;j++){
      
      change(arrow[j]);
      
      if(dice[0]==x&&dice[1]==y){
	cout<<dice[2]<<endl;
	break;
      }else if(dice[0]==x&&dice[3]==y){
	cout<<dice[1]<<endl;
	break;
      }else if(dice[0]==x&&dice[4]==y){
	cout<<dice[3]<<endl;
	break;
      }else if(dice[0]==x&&dice[2]==y){
	cout<<dice[4]<<endl;
	break;
      }
    }
  }
    
}

void change(char c){
  if(c=='N'){
    swap(dice[0],dice[4]);
    swap(dice[0],dice[1]);
    swap(dice[1],dice[5]);
  }else if(c=='S'){
    swap(dice[0],dice[1]);
    swap(dice[0],dice[4]);
    swap(dice[5],dice[4]);
  }else if(c=='W'){
    swap(dice[2],dice[0]);
    swap(dice[2],dice[5]);
    swap(dice[5],dice[3]);
  }else if(c=='E'){
    swap(dice[0],dice[3]);
    swap(dice[3],dice[5]);
    swap(dice[5],dice[2]);
  }
}



Measured memory_bytes: 3092
package main
import (
	"fmt"
)

func main(){
	var a, b, k int
	fmt.Scan(&a, &b, &k)
	for i:=0; i<k && a<b; i++{
		fmt.Println(a)
		a++
	}
	/*
	for i:=k; i>=0 && b-i>a; i--{
		fmt.Println(b-i)
	}
	*/
	for i:=b; i>b-k && i>=a; i--{
		defer fmt.Println(i)
	}
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import sys
import collections
import math
import fractions 

# code start
raw_input = input


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

def main():
	count = int(input())
	i = 0
	temp = 1
	while(i<count):
		i+=1
		num = int(input())
		temp = lcm(temp,num)
	print(int(temp))


if __name__ == '__main__':
    main()

# code end


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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> l(n);
  int cur = 0;
  int ret = 1;
  for(int i = 0;i < n;i++){
    cin >> l[i];
    cur += l[i];
    if(cur <= x)ret++;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
  string a;
  cin >> a;

    if(a == "AAA" || a == "BBB"){
        cout << "No" << endl;

   
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
long long x[100005],v[100005];
long long sum1[100005],sum2[100005];
long long max1[100005],max2[100005],max3[100005];
int main()
{
    long long N,C,ans,now;
    scanf("%lld%lld",&N,&C);
    for(long long i=1;i<=N;i++)
        scanf("%lld%lld",&x[i],&v[i]);
    x[N+1]=C;
    ans=0;
    for(long long i=1;i<=N;i++)
        sum1[i]=sum1[i-1]+v[i]-(x[i]-x[i-1]);
    for(long long i=N;i>=1;i--)
        sum2[i]=sum2[i+1]+v[i]-(x[i+1]-x[i]);
    for(long long i=1;i<=N;i++)
        max1[i]=max(max1[i-1],sum1[i]);
    for(long long i=N;i>=1;i--)
        max2[i]=max(max2[i+1],sum2[i]);
    for(long long i=N;i>=1;i--)
        max3[i]=max(max3[i+1],sum2[i]-(C-x[i]));
    for(long long i=0;i<=N;i++)
        ans=max(ans,sum1[i]);
    for(long long i=N;i>0;i--)
        ans=max(ans,sum2[i]);
    for(long long i=0;i<=N;i++)
        ans=max(ans,max1[i]+max2[i+1]-x[i]);
    for(long long i=0;i<=N;i++)
        ans=max(ans,max1[i]+max3[i+1]);
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::string s;
  std::cin >> s;
  int b = 0;
  int w = 0;
  int const n = s.size();
  for (int i = 0; i < n; i++) {
    int c = s[i] == '1' ? 1 : 0;
    if ((i % 2) != 0) {
      if (c != 0) {
        w++;
      } else {
        b++;
      }
    } else {
      if (c == 0) {
        w++;
      } else {
        b++;
      }
    }
  }
  std::cout << std::min(b, w) << std::endl;
  return 0;
}


Measured memory_bytes: 512
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int cnt[1000];

int main()
{
  int i,j,n,x,y,ans;
  vector<pair<pair<int,int>,int> > a;
  scanf("%d",&n);
  for (i=0;i<n;i++)
  {
    scanf("%d%d",&x,&y);
    a.push_back(make_pair(make_pair(x,y),0));
  }
  for (i=0;i<n;i++)
  {
    scanf("%d%d",&x,&y);
    a.push_back(make_pair(make_pair(x,y),1));
  }
  sort(a.begin(),a.end());
  memset(cnt,0,sizeof(cnt));
  ans=0;
  for (i=0;i<a.size();i++)
  {
    if (a[i].second==0)
    {
      cnt[a[i].first.second]++;
    }
    else
    {
      for (j=a[i].first.second-1;j>=0;j--)
      {
        if (cnt[j]>0)
        {
          cnt[j]--;
          ans++;
          break;
        }
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;

  ll sum = 1;
  char before = S[0];
  rep(i, N) {
    if (before != S[i]) {
      sum++;
      before = S[i];
    }
  }
  COUT(sum);
  return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<vector<ll>> PartitionNumber(ll n,ll k){
	vector<vector<ll>> dp(n+1,vector<ll>(k+1));
	dp[0][0] = 1;
	for(int i = 0; i <= n; i++) {
		for(int j = 1; j <= k; j++) {
			if(i - j >= 0) dp[i][j] = dp[i][j - 1] + dp[i - j][j];
			else dp[i][j] = dp[i][j - 1];
			dp[i][j] %= atcoder_mod;
		}
	}
	return dp;
}
ll BallBoxCombination10(ll n,ll k){
	auto T = PartitionNumber(n,k);
	return T[n][k];
}

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

	ll N=in<ll>(),K=in<ll>();
	
	ll ans = BallBoxCombination10(N,K);
	out(ans);
	return 0;
}



Measured memory_bytes: 10784
#include <bits/stdc++.h>
#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 irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for(int i=(int)(n);i>=1;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


int main (void)
{
  double xa,ya,xb,yb,xc,yc,xd,yd;
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF){
    double area1,area2;
    area1=abs((xa-xb)*(yc-yb)-(ya-yb)*(xc-xb))+abs((xa-xd)*(yc-yd)-(ya-yd)*(xc-xd));
    area2=abs((xb-xa)*(yd-ya)-(yb-ya)*(xd-xa))+abs((xb-xc)*(yd-yc)-(yb-yc)*(xd-xc));

    cout << (area1==area2 ? "YES" : "NO") << endl;
  }
  return 0;
}


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

int main(){
    
    string a,b;
    cin >> a >> b;
    int ca,cb;
    cin >> ca >> cb;
    string s;
    cin >> s;
    if(s == a)
        ca--;
    else cb--;
    cout << ca << " " << cb;
    
    
    return 0;
}

Measured memory_bytes: 3524
<?php
/**
 * ABC132
 * C - Divide the Problems
 */

fscanf(STDIN, "%d", $n);
$d = array_map('intval', explode(' ', trim(fgets(STDIN))));
sort($d);
echo $d[intdiv($n, 2)] - $d[intdiv($n, 2) - 1], PHP_EOL;


Measured memory_bytes: 16884
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
#include <cmath>
#include <random>
using namespace std;
long long mod = 1000000000 + 7;


int main()
{
	long long h;
	cin >> h;
	long long keta[50];
	long long nanka[50];
	keta[0] = 1;
	nanka[0] = 1;
	for (int i = 1; i < 50; i++) {
		long long num = 1;
		nanka[i] = nanka[i - 1] * 2;
		keta[i] = keta[i - 1] + nanka[i];
	}

	int n_of_2 = 0;
	int i = 0;
	while (1) {
		
		if (h < nanka[i]) {
			break;
		}
		else {
			n_of_2 = i;
		}
		i++;
	}
	cout << keta[n_of_2] << endl;

	
	return 0;

}



Measured memory_bytes: 256
using System;

namespace B___YYMM_or_MMYY
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var a = int.Parse(s.Substring(2, 2));
            var b = int.Parse(s.Substring(0, 2));
            if ((1 <= a && a < 13) && (1 <= b && b < 13))
            {
                Console.WriteLine("AMBIGUOUS");
            }
            else if (1 <= a && a < 13)
            {
                Console.WriteLine("YYMM");
            }
            else if (1 <= b && b < 13)
            {
                Console.WriteLine("MMYY");
            }
            else
            {
                Console.WriteLine("NA");
            }
        }
    }
}

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

int main() {
  int n, count, result=0;
  cin >> n;
  for (int i=1; i<=n; i+=2) {
    count=0;
    for (int j=1; j<=i; j++) {
      if (i%j==0) count++;
    }
    if (count==8) result++;
  }
  cout << result;
  return 0;
}

Measured memory_bytes: 256
#n = int(input())
#a, b = map(int,input().split())
#l = list(map(int,input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
o = list(input())
e = list(input())
oc = 0
ec = 0

ans = ''

n = len(o)+len(e)
for i in range(1,n+1):
    if i % 2 == 0:
        add = e[ec]
        ec += 1
    else:
        add = o[oc]
        oc += 1
    ans += add

print(ans)


Measured memory_bytes: 8972
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main()
{
    int a,b;
    cin>>a>>b;
    for(int i=b-a+1;i<a+b;i++)
        cout<<i<<" ";
}

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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

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

u64 My_Combination(u32 n, u32 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}

int main() {
  cout << setprecision(18);
  u32 N, K;
  cin >> N >> K;

  for (u32 i = 1; i <= K; ++i) {
    cout << ((My_Combination(N - K + 1, i, MAX_NUM) % MAX_NUM) *
             (My_Combination(K - 1, i - 1, MAX_NUM) % MAX_NUM)) %
                MAX_NUM
         << endl;
  }

  return 0;
}


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

using namespace std;

#define BUF_SIZE 1024
struct Node
{
    int data;
    Node *next;
    Node *prev;
};

class List
{
public:
    Node *head;

    List(){
        head = new Node();
        head -> data = -1;
        head -> next = head;
        head -> prev = head;
    }

    void inset_cell(Node *p, int d)
    {
        Node *tmp = new Node();
        tmp->data = d;
        tmp->next = p->next;
        tmp -> prev = p;
        p ->next = tmp;
        tmp ->next ->prev = tmp;
    }
    
    void display()
    {
        Node *tmp = head->next;
        
        while (tmp->next != head)
        {
            cout << tmp->data << " ";
            tmp = tmp->next;
        }
        cout << tmp->data << endl;

    }
    void delet(int d){
       Node *tmp = head ->next;
       while(tmp!=head && tmp->data !=d){
           tmp = tmp->next;
       }
       if(tmp!=head){
           tmp->prev->next = tmp->next;
           tmp->next->prev = tmp->prev;
       }
       
    }
    void deletFirst(){
        head->next = head->next->next;
        head ->next ->prev = head;
    }
    void deletLast(){
        head-> prev = head->prev->prev;
        head->prev->next = head;
    }

   
};

int main()
{

    int n;
    cin >> n;
    string str;
    List list;
    int a;
    for(int i = 0;i<n;i++){
        cin >> str;
        if(str == "deleteFirst"){
            list.deletFirst();
        }else if(str == "deleteLast"){
            list.deletLast();
        }else{
            int s;
            cin >> s;
            if(str == "insert"){
                list.inset_cell(list.head,s);
            }
            if(str == "delete"){
                list.delet(s);
            }
        }

    }

    list.display();

    return 0;
}


Measured memory_bytes: 37396
#include <iostream>
using namespace std;
int main(){
  int Q;
  cin>>Q;
  for(int i=0;i<Q;i++){
    int c,a,n;
    int can=0,cca=0,ccc=0;
    cin>>c>>a>>n;
      if(1<=n&&1<=a&&1<=c){
        can=min(min(c,a),n);
        a=a-can; c=c-can;
      }
      if(1<=a&&1<=c/2){
        cca=min(c/2,a);
        c=c-cca*2;
      }


      if(1<=c/3){
        ccc=c/3;
      }

    cout<<can+cca+ccc<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

vector< int > dijkstra(graph &G, int s) {
	///stat must have "<"&">"
	///init d=vector<stat>
	vector< int > d(G.size(), INT_MAX / 2);
	d[s] = 0;
	//init q=p-queue<pair<stat,index> >
	priority_queue< pii, vector< pii >, greater< pii > > q;
	q.push(pii(0, s));

	while (!q.empty()) {
		pii p = q.top();
		q.pop();
		if (d[p.second] < p.first)
			continue;
		for (int i = 0; i < G[p.second].size(); i++) {
			edge e = G[p.second][i];
			if (p.first + e.d < d[e.to]) {
				d[e.to] = p.first + e.d;
				q.push(pii(d[e.to], e.to));
			}
		}
	}
	return d;
}
int N, M, K, T, Q;
signed main() {
	cin >> N >> M;
	graph G(N * 3);
	rep(i, M) {
		int u, v;
		cin >> u >> v;
		--u;
		--v;
		G[u].push_back(edge(u, N + v, 1));
		G[u + N].push_back(edge(u + N, v + 2 * N, 1));
		G[u + 2 * N].push_back(edge(u + 2 * N, v, 1));
	}
	int S, T;
	cin >> S >> T;
	--S;
	--T;
	vector< int > d = dijkstra(G, S);
	int ans = (d[T] == INT_MAX / 2 ? -1 : d[T] / 3);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 23680
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=900000+10;

const int mod=1e9+7;
inline int qpow(int a,int b) { int c=1;
    for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) c=1ll*c*a%mod;
    return c;
}

int fac[N],ifac[N],pw[N];
inline void init(int n) {
    fac[0]=1;
    for (re int i=1;i<=n;++i) fac[i]=1ll*fac[i-1]*i%mod;
    ifac[n]=qpow(fac[n],mod-2);
    for (re int i=n;i;--i) ifac[i-1]=1ll*ifac[i]*i%mod;
    for (re int i=pw[0]=1;i<=n;++i) pw[i]=3ll*pw[i-1]%mod;
}

inline int C(int n,int m) {
    return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}

int main() { init(900000);
    int n=read(),m=read(),k=read(); if (m<k) swap(m,k);
    int ans=0,lst=1;
    for (re int i=0;i<=m+k;++i) {
        ans=(ans+1ll*C(n+i-1,n-1)*pw[m+k-i]%mod*lst)%mod;
        if (i<k) lst=2ll*lst%mod;
        else if (i<m) lst=(2ll*lst+mod-C(i,k))%mod;
        else lst=(2ll*lst+mod-C(i,k)+mod-C(i,i-m))%mod;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
long long inc[200005];
vector< int > G[200005];
long long ans[200005];
void dfs(int to, int from, long long barao){
  	ans[to] += barao;
	for(int i=0;i<G[to].size();i++){
      int v = G[to][i];
      if(v!=from) dfs(v, to, barao+inc[v]);
    }
}

int main(){
  int n, q;
  cin>>n>>q;
  for(int i=1;i<n;i++){
   	int a,b;
    cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  for(int i=1;i<=q;i++){
   	int p,x;
    cin>>p>>x;
    inc[p]+=x;
  }
  dfs(1, -1, inc[1]);
  for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
  cout<<endl;
  return 0; 
}

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

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vi;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nl cout<<'\n'
#define pb push_back
#define all(s) s.begin(),s.end()
#define bs binary_search

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a)*(b)/(__gcd((a),(b)))

const int Mod=1e9+7;
#define sum(a,b) (((a)%Mod)+((b)%Mod))%Mod
#define sub(a,b) (((a)%Mod)-((b)%Mod))%Mod
#define mul(a,b) (((a)%Mod)*((b)%Mod))%Mod

#define count1(x) __built_popcount(x)


#define loop(i,s,e) for(i=s;i<e;i++)
#define rloop(i,s,e) for(i=e;i>=s;i--)

#define dbg(x) cout << #x <<":"<<x<<endl;

bool isPowerOfTwo (int x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
} 

ll pow(ll x, ll y, ll mod)
{
	int ans=1;
	while(y)
	{
		if(y&1)
			ans=(ans*x)%mod;
		y/=2;
		x=(x*x)%mod;
	}
	return ans;
}

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

Measured memory_bytes: 256
#include <stdio.h>
int main() {
    int n;
    int a,b;
    scanf("%d", &n);

    if(n == 1){
        printf("Hello World\n");
    } else if(n == 2) {
        scanf("%d%d", &a, &b);
        printf("%d\n", a+b);
    }

    return 0;
}

Measured memory_bytes: 128
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];
ll a[N];

int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>n>>k;
    Ff(i,0,n) cin>>a[i+1]; 

    ll fa[200001]={0};
    i=1;
    vc line;
    ll cnt=0;
    while(cnt<n)
    {
      line.pb(i);
      fa[i]++;
      ll prev=i;
      i=a[i];
      if(fa[i]>0)
      {
        y=prev;
        x=i;        
        break;
      }
      cnt++;
    }
    
    for(int i=0;i<line.size();i++)
    {
      if(line[i]==x)
      {
        x=i;
        break;
      }
    }

    for(int i=0;i<line.size();i++)
    {
      if(line[i]==y)
      {
        y=i;
        break;
      }
    }
    // cout<<x<<" "<<y<<endl;
    // for(int i=0;i<line.size();i++)
    // cout<<line[i]<<" ";
    // cout<<endl;
    if(k<line.size())
    cout<<line[k];
    else{
      k-=line.size();
      k%=(y-x+1);
      cout<<line[x+k];
    }
    return 0;
}

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

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

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

Measured memory_bytes: 15452
#include<stdio.h>

int selectionSort(int A[],int N){

   int i,j,t,sw=0,minj;

   for(i=0;i<N-1;i++){

      minj=i;

      for(j=i;j<N;j++){

         if (A[j] < A[minj]){
           minj = j;
         }

             }
   t=A[i],A[i]=A[minj];A[minj]=t;
   if(i!=minj) sw++;
   }

   return sw;
}

int main(){

   int N,i,sw;
   int A[100];

   scanf("%d",&N);

   for(i=0;i<N;i++){
      scanf("%d",&A[i]);
   }

   sw=selectionSort(A,N);

      for(i=0;i<N;i++){

      if(i>0)printf(" ");
      printf("%d",A[i]);
      }

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

   return 0;

}
   

Measured memory_bytes: 2744
if __name__ == "__main__":
  N = int(input())
  D = []
  for i in range(N):
    D += [[int(a) for a in input().split()]]
  ans = "No"
  count = 0
  for d in D:
    if d[0] == d[1]:
      count += 1
      if count == 3:
        ans = "Yes"
        break
      else:
        pass
    else:
      count = 0
  print(ans)


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

using namespace std;

int main()
{
  	int k;
  	cin >> k;
  
  	int res = 0;
  
  	for(int i = 1; i <= k; ++i)
    {
     	for(int j = 1; j <= k; ++j)
        {
          	int nzd = __gcd(i,j);
          
         	for(int u = 1; u <= k; ++u)
            {
             	 res += __gcd(nzd,u);
            }
        }
    }
  
  	cout << res << '\n';
  
 	return 0; 
}

Measured memory_bytes: 3600