akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var n int
	var m int

	sc.Split(bufio.ScanWords)
	n = nextInt()
	m = nextInt()

	conn := make([][]int, n)
	for i := 0; i < m; i++ {
		a := nextInt()
		b := nextInt()
		a--
		b--
		conn[a] = append(conn[a], b)
		conn[b] = append(conn[b], a)
	}

	signpost := make([]int, n)
	for i := 0; i < n; i++ {
		signpost[i] = -1
	}

	roomQueue := make([]int, 0)
	roomQueue = append(roomQueue, 0)
	for len(roomQueue) > 0 {
		roomTmp := roomQueue[0]
		roomQueue = roomQueue[1:]
		for _, room := range conn[roomTmp] {
			if signpost[room] != -1 {
				continue
			}
			signpost[room] = roomTmp
			roomQueue = append(roomQueue, room)
		}
	}

	for i := 1; i < n; i++ {
		if signpost[i] == -1 {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
	for i := 1; i < n; i++ {
		fmt.Println(signpost[i] + 1)
	}
}

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

using namespace std;

typedef long long ll;
const ll inf = 0x3f3f3f3f;
#define case(i) "Case #" << i << ": "
 
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
    out << '(' << p.first << ", " << p.second << ')';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++) out << v[i] << ' ';
    if (l > 0) out << v[l - 1];
    return out;
}

int h, w;
string s[21];

int bfs(int i, int j) {
    // cout << i << " " << j << endl;
    map<pair<int, int>, int> dis;
    map<pair<int, int>, int> vis;
    queue<pair<int, int>> q;
    dis[{i, j}] = 0;
    vis[{i, j}] = 1;
    q.push({i, j});

    while(!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        q.pop();
        if(i + 1 < h && s[i+1][j] == '.' && vis[{i+1, j}] == 0) {
            vis[{i+1, j}] = 1;
            dis[{i+1, j}] = dis[{i, j}] + 1;
            q.push({i+1, j});
        }
        if(i - 1 > -1 && s[i-1][j] == '.' && vis[{i-1, j}] == 0) {
            vis[{i-1, j}] = 1;
            dis[{i-1, j}] = dis[{i, j}] + 1;
            q.push({i-1, j});
        }
        if(j + 1 < w && s[i][j+1] == '.' && vis[{i, j+1}] == 0) {
            vis[{i, j+1}] = 1;
            dis[{i, j+1}] = dis[{i, j}] + 1;
            q.push({i, j+1});
        }
        if(j - 1 < w && s[i][j-1] == '.' && vis[{i, j-1}] == 0) {
            vis[{i, j-1}] = 1;
            dis[{i, j-1}] = dis[{i, j}] + 1;
            q.push({i, j-1});
        }
        
    }

    int mx = 0;

    for(auto x: dis) {
        mx = max(x.second, mx);
    }
    // cout << mx << endl;
    return mx;
}

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

    cin >> h >> w;
    for(int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    int ans = 0;
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(s[i][j] != '#') ans = max(ans, bfs(i, j));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define Rep(i,a,b) for(ll i=a;i<b;i++)
#define pb emplace_back
#define allv v.begin(),v.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
#define FASTio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<(#x)<<" "<<x<<endl
ll mod=1e9+7;
template<typename t>
ll Max(ll a,ll b)
{
    return (a>b)?a:b;
    
}
ll Min(ll a,ll b)
{
    return (a>b)?b:a;
}
ll power(ll a,ll b)
{
    ll p=1;
    a=a%mod;
    b=b%mod;
    while(b)
    {
        if(b&1)
        {
            p=((p%mod)*(a%mod))%mod;
        }
        a=((a%mod)*(a%mod))%mod;
        b=(b/2);
    }
    return p%mod;
}
int main()
{
    int t;
    t=1;
  //  cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n];
        rep(i,n)
        cin>>a[i];
        sort(a,a+n);
        bool dp[a[n-1]+1]={false};
        bool visited[1000005]={false};
        for(ll i=0;i<n;i++)
        {

               ll temp=a[i];
               if(dp[temp]==false)
               {
                   ll k=2;
                   while(temp*k<=(a[n-1]))
                   {
                       dp[temp*k]=true;
                       k++;
                   }
               }
            
        }
        ll ans=0;
        for(ll i=0;i<n;i++)
        {
           if(dp[a[i]]==false)
           {
               if( (i<(n-1)) && (a[i]==a[i+1]))
               dp[a[i]]=true;
               else
               ans++;
           }
        }
        //ll ans=0;

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


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

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

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

int frogjump(int height[], int n,int k)
{
    int dp[n+1];
    dp[0]=0;
    dp[1]=0;
    for (int i = 2; i < n+1; i++)
    {
        dp[i]=INT_MAX;
    }
    
    for (int i = 2; i < n+1; i++)
    {
        for(int j=1;j<=k&&(i-j>=1);j++)
        {
            dp[i] = min(dp[i], dp[i - j] + abs(height[i] - height[i - j]));
        }       
    }
    return dp[n];
    
}

int main()
{
    //freopen("inp.txt","r",stdin);
    int n,k;
    cin >> n>>k;
    int height[n + 1];
    for (int i = 1; i <= n; i++)
    {
        cin >> height[i];
    }
    if(n<3)
    {
        if(n==2)
        cout<<abs(height[2]-height[1]);
        if(n==1)
        {
            cout<<0;
        }
        
    }else
    {
        cout << frogjump(height, n,k);
    }
    
    return 0;
}

Measured memory_bytes: 4412
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m;
  cin>>n>>m;
  vector<pll> key(0);
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    ll s=0;
    rep(j,b){
      ll d;
      cin>>d;
      d--;
      s|=1<<d;
    }
    key.pb(pll(s,a));
  }
  vll dp(1<<n,INF);
  dp[0]=0;
  rep(s,1<<n){
    rep(i,m){
      ll t=s|key[i].F;
      ll cost=key[i].S;
      dp[t]=min(dp[t],dp[s]+cost);
    }
  }
  if(dp[(1<<n)-1]==INF){
    COUT(-1);
  }
  else COUT(dp[(1<<n)-1]);
}


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

typedef pair<int,int> P;
int d[2000],ans[2000];
priority_queue<P,vector<P>,greater<P>> que;
vector<int> edge[2000];
void add_edge(int u,int v){
  edge[u].push_back(v);
  edge[v].push_back(u);
}

signed main(){
  int n,x,y;cin>>n>>x>>y;x--;y--;
  for(int i=1;i<n;i++)add_edge(i-1,i);
  add_edge(x,y);
  for(int i=0;i<n;i++){
    memset(d,-1,sizeof(d));
    que.push(P(0,i));
    while(que.size()){
      P p=que.top();que.pop();
      int cost=p.first,idx=p.second;
      if(~d[idx])continue;
      d[idx]=cost;
      for(int q:edge[idx])que.push(P(cost+1,q));
    }
    for(int j=0;j<n;j++)ans[d[j]]++;
  }
  for(int i=1;i<n;i++)cout<<ans[i]/2<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

map<char, int> mp;
string S1, S2;
int N;
ll ans = 1;

int main() {
	cin.tie(0);
	cout.tie(0);

	ios::sync_with_stdio(false);

	cin >> N;
	cin >> S1 >> S2;
	int p = 0;

	FOR(i, 0, N) {
		if (S1[i] == S2[i]) {
			if(p==0)ans = (ans * 3) % MOD;
			if (p == 1)ans = (ans * 2) % MOD;
			

				p = 1;
		}
		else {
			if(p==0)ans = (ans * 6) % MOD;
			if (p == 1)ans = (ans * 2) % MOD;
			if (p == 2)ans = (ans * 3) % MOD;
			i++;

			p = 2;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;cin>>N;
  if(N%2==0){
    cout<<N*N/4<<endl;
  }
  else{
    cout<<N/2*(N+1)/2<<endl;
  }
}


Measured memory_bytes: 3552
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    ll d[N][N];
    rep(i,N){
        rep(j,N){
            d[i][j]=INF;
        }
      	d[i][i]=0;
    }
    vl a(M),b(M),c(M);
    rep(i,M){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;b[i]--;
        d[a[i]][b[i]]=d[b[i]][a[i]]=c[i];
    }
    rep(k,N){
        rep(i,N){
            rep(j,N){
                chmin(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    ll ans=0;
    rep(i,M){
        if(d[a[i]][b[i]]<c[i]){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main{
	public static void main(String[]args){
		
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
	
		int l[]=new int[n];
		for(int i=0;i<n;i++){
			l[i]=sc.nextInt();
		}
		
		int max=0;
		int total=0;
		
		for(int i=0;i<n;i++){
			if(l[i]>max){
				max=l[i];
			}
			total+=l[i];
		}
		
		if(max<total-max){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
	}
}

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

#define NMAX 100001
#define MAX(a, b) (a > b ? a : b)

using namespace std;

//ifstream fin("f.in");
//ofstream fout("f.out");

int a, b, c, d, e, k;

int main()
{
    cin >> a >> b >> c >> d >> e >> k;
    cout << (e - a <= k ? "Yay!" : ":(");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (){

    int i;
    int G, N;
    scanf("%d %d", &G, &N);
    char str [G + N +1];
    scanf("%s", &str);

    int asw = 0;
    for(i = 0; i<G+N+1; i++){
        if (i != G) 
        {if (str[i]>='0' && str[i]<='9'){
            asw++;
        }
    }else if (str[i] == '-'){
        asw++;
    }
    }
    if (asw == G + N + 1){
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}

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

int main() {
  int n;
  long ans=0;
  cin >> n;
  map<string,int> a;
  for(int i=0;i<n;i++) {
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    a[s]++;
    ans+=a[s]-1;
  };
  cout << ans << endl;
}

Measured memory_bytes: 11136
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
 
LL N, W, w[112], v[112];
std::vector<LL>list[3];
LL ans;
 
int main()
{
	in >> N >> W;
	rep(i, N) { in >> w[i] >> v[i]; }
 
	for (LL i = w[0]; i <= w[0] + 3; ++i)
	{
		rep(j, N)
		{
			if (i == w[j]) { list[i - w[0]].push_back(v[j]); }
		}
		if (list[i - w[0]].size() > 0)
		{
			std::sort(list[i - w[0]].begin(), list[i - w[0]].end(), std::greater<LL>());
			rep(j, list[i - w[0]].size() - 1) { list[i - w[0]][j + 1] += list[i - w[0]][j]; }
		}
	}
	rep(i, std::min<LL>(N, list[3].size()) + 1)
	{
		rep(j, std::min<LL>(N, list[1].size()) + 1)
		{
			rep(k, std::min<LL>(N, list[2].size()) + 1)
			{
                if (N < i + j + k) continue;
				LL v_sum = 0, w_sum = 0;
                w_sum += (w[0] + 3) * i + (w[0] + 1) * j + (w[0] + 2) * k;
                if (w_sum > W) continue;
                LL l = std::min<LL>((W - w_sum) / w[0], std::min<LL>(N - (i + j + k), list[0].size()));
				LL a[] = { l,j,k,i };
				rep(m, 4)
				{
					if (a[m] > 0)
					{
						v_sum += list[m][a[m] - 1];
					}
				}
				ans = std::max(ans, v_sum);
			}
		}
	}
 
	out << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n,q,i,t,x;
   cin>>n>>q;
   priority_queue<int>a[n];
   while(q){
   	q--;
   	cin>>i;
   	if(i==0){
   		cin>>t>>x;
   		a[t].push(x);
	   }
	if(i==1){
		cin>>t;
		 if(a[t].size()!=0)
		cout<<a[t].top()<<endl;
   }
   if(i==2){
   	cin>>t;
   	if(a[t].size()!=0)
   	a[t].pop();
   }
}
}



Measured memory_bytes: 4024
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    string s,t;
    cin>>s>>t;
    int n=s.size(),n1=t.size();
    int ans=n1;
    for(int i=0;i<n;i++)
    {
        int cur=n1;
        if((i+n1)>n)
        break;
        for(int j=i;j<min(n, i+n1);j++)
        {
            if(s[j]==t[j-i])
            cur--;
        }
        ans=min(ans, cur);
    }
    cout<<ans;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
void yes(bool c) { if (c)print("Yes"); else print("No"); };

void solve() {
    int N,M; cin >> N >> M;
    vll H(N);
    rep(i,N) cin >> H[i];
    vector<vi> to(N);
    rep(i,M){
        int a,b;cin >> a >> b;
        a--;b--;
        to[a].pb(b);
        to[b].pb(a);
    }
    int ans = 0;
    rep(i,N){
        if(to[i].size()==0){
            ans++;
        }else{
            ll myH = H[i];
            // cout << i << "::" << myH << endl;
            bool ok = true;
            rep(j,to[i].size()){
                if(myH <= H[to[i][j]]) {
                    ok = false;
                    break;
                }
            }
            if(ok) ans++;
            // if(ok) cout << "ok:" << i << endl;
        }
    }
    print(ans);
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);

    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 9152
#include <iostream>
using namespace std;
int main(void){
    long long l,r,i,j,ans=10000000000;
    cin >> l >> r;
    if(r-l>=2019) ans =0;
    else{
        for(i=l;i<r;i++){
            for(j=i+1;j<=r;j++){
                if(ans>i*j%2019) ans = i*j%2019;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//organize and stay in moment - Abhinav IIIT-A
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,x,n) for(int i=x;i<n;++i)
#define ar array
#define MAXN (int)2e5+5
#define pb push_back
int mod= 998244353;
int arr[MAXN];
int as;
void input(){
  cin>>as;
  f(i,0,as) cin>>arr[i];
}
int mod2=998244353;
void solve(){
	int h,w; cin>>h>>w;
	if(h==1 || w==1){
		cout<<"1\n";
		return ;
	}
	h*=w; ++h; h/=2;
	cout<<h<<"\n";
}
int32_t main()
{
  int t; t=1; //cin>>t;
  while(t--) solve();
  return 0;
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>

using namespace std;

int main() {
  int N, K;
  long double ans{};
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) {
    int j = i;
    long double p{1. / N};
    while (j < K) {
      j <<= 1;
      p *= 0.5;
    }
    ans += p;
  }
  cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
import collections

N = int(input())
if N == 1:
  print(1)
  exit()

MOD = 10**9+7

def prime_factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n //= 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a

F = []
for i in range(2,N+1):
  F[len(F):len(F)] = prime_factorize(i)
#print(F)
c = collections.Counter(F)
#print(c)
ans = 1
for v in c.values():
  ans *= v+1
  ans %= MOD
print(ans)


Measured memory_bytes: 39408
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        for (int i = 0; i < n-1; i++) {
            System.out.print(a[n-1-i]);
            System.out.print(" ");
        }
        System.out.print(a[0]);
        System.out.print("\n");
    }
}



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

using i64 = int64_t;

i64 cumsum[100005]={0}, stepsum[2][100005]={0};

i64 bsearch(i64 ok, i64 ng, vector<i64> &v, i64 x){
    i64 n = v.size();
    while(abs(ok-ng) > 1){
        i64 mid = (ok + ng) / 2;
        if(abs(v[n-mid-1] - x) < abs(v[n-2*mid-1] - x))ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
    int n, q;
    cin >> n >> q;
    vector<i64> v;
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        v.push_back(a);
    }

    for(int i=1;i<=n;++i){
        cumsum[i] = cumsum[i-1] + v[i-1];
        stepsum[0][i] = stepsum[0][i-1];
        stepsum[1][i] = stepsum[1][i-1];
        stepsum[i%2][i] += v[i-1];
    }

    for(int i=0;i<q;++i){
        i64 x;
        cin >> x;
        i64 p = bsearch(n/2+(n%2), 0, v, x);
        i64 ans = cumsum[n] - cumsum[n-p];
        ans += stepsum[n%2][n-2*p];
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 4980
n=int(input())
a=list(map(int,input().split()))
b=[0]*(n+1)
c=[]
for i in range(n,0,-1):
  b[i]=1-(a[i-1]==sum([b[i*(j+1)] for j in range(n//i)])%2)
  if b[i]==1:
    c+=[i]
print(len(c))
print(*c)

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


int main() {
  int A,B;
  cin >> A >> B;
  if (A + B ==3) {
    cout << 3 <<endl;
  }
  
  else if (A + B ==4) {
    cout << 2 <<endl;
  }
  else {
    cout << 1 <<endl;
  }
}


Measured memory_bytes: 256
def main():
    k, s = map(int, input().split())

    pattern = 0

    for x in range(k + 1):
        for y in range(k + 1):
            if (s - x - y >= 0) and (s - x - y <= k):
                pattern += 1

    # Wrong Anser
    # 
    # # 3,4 --> 0 start
    # # 3,5 --> 0 start
    # # 3,7 --> 1 start
    # # 3,8 --> 2 start
    # # 3,9 --> 3 start 
    # # 4,8 --> 0 start
    # # 4,9 --> 1 start
    # # 4,10 --> 2 start
    # # s // k * 2
    # 
    # for x in range(s // 3, k + 1):
    #     for y in range(s // 3, min(k + 1, s - x + 1)):
    #         for z in range(s // 3, min(k + 1, s - x - y + 1)):
    #             if x + y + z == s:
    #                 pattern += 1
    # 

    print(pattern)


if __name__ == "__main__":

    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> L(N);
    rep(i,N)cin >> L[i];
    int sum = 0;

    sort(all(L));

    for(auto itr = L.end(); itr != L.begin()+1;itr--){
        if(itr == L.end())continue;

        for(auto itr2 = itr-1;itr2 != L.begin();itr2--){
            auto ind = upper_bound(L.begin(),itr2,*itr-*itr2);
            if(itr2 - ind > 0)sum += itr2 - ind;
        }

    }

    cout << sum << endl;
}



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

using namespace std;
using ll = long long;
using cll = const long long;
using vec = vector<ll>;

ll pow(ll b, ll p, ll mod){
    ll ret = 1LL;
    ll cum = b;
    while (p){
        if (p & 1) ret = ret * cum % mod;
        cum = cum * cum % mod;
        p >>= 1;
    }
    return ret;
};

class ModuloMath{
    static constexpr ll mod = 1e9+7;
public:
    ModuloMath(ll n) : maxN(n){
        fac.resize(maxN + 1, 1);
        invfac.resize(maxN + 1, 1);
        for (ll i = 2; i <= maxN; ++i) fac[i] = fac[i - 1] * i % mod;
        invfac[maxN] = pow(fac[maxN], mod - 2, mod);
        for (ll i = maxN - 1; i != 0; --i) invfac[i] = invfac[i + 1] * (i + 1LL) % mod;
    }
    ll nCr(ll n, ll r){return fac[n] * invfac[r] % mod * invfac[n - r] % mod;}

private:
    ll maxN;
    vec fac;
    vec invfac;
};

int main() {
    ll mod = 1e9+7;
    ll H, W, A, B;
    cin >> H >> W >> A >> B;
    ModuloMath mm(H + W + 1);
    ll total = mm.nCr(H + W - 2, H - 1);
    long long w = W - B;
    for (long long h = A; h != 0; --h){
        ll tmp = mm.nCr(h + w - 2, h - 1) * mm.nCr(H - h + 1 + B - 2, H - h + 1 - 1) % mod;
        total = (mod + total - tmp) % mod;
    }
    cout << total << endl;
    return 0;
}

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

int main(){
    string s;
    cin>>s;
    if(s=="Sunny"){
        cout<<"Cloudy"<<endl;
    }else if(s=="Cloudy"){
        cout<<"Rainy"<<endl;
    }else{
        cout<<"Sunny"<<endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n;
	cin >> n;
	unordered_map<ll, ll> a;
	ll sum = 0;
	REP(i, n) {
		ll tmp;
		cin >> tmp;
		a[tmp]++;
		sum += tmp;
	}
	int q;
	cin >> q;
	vector<ll> result;
	REP(i, q) {
		ll b, c;
		cin >> b >> c;
		sum = sum - (b * a[b]) + (c * a[b]);
		a[c] += a[b];
		a[b] = 0;
		result.push_back(sum);
	}

	EACH(e, result) { cout << e << endl; }

	return 0;
}


Measured memory_bytes: 8096
S=input()
K=int(input())
if len(S)==1:
  print(K//2)
  exit()
if len(S)==2:
  if S[0]==S[1]:
    print(K)
  else:
    print(0)
  exit()
ans=0
# 内部
cnt=1
fro=0
flag=1
for i in range(len(S)-1):
  if S[i+1]==S[i]:
    cnt+=1
  else:
    if flag: 
      fro=cnt
      flag=0
    ans+=cnt//2
    cnt=1
ans+=cnt//2
ans*=K
# print(ans)
# 接続部
if fro==0:
  print((K*cnt)//2)
  exit()
if S[0]==S[-1]:
  if fro%2==1 and cnt%2==1:
    ans+=K-1
print(ans)
  

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
long long l,a[10001],t;
string s;
int main()
{
	cin>>s;
	l=s.size();
	for(int i=0;i<l;i++)
	{
		if(s[i]=='C') t=1;
		if(s[i]=='F'&&t==1) {cout<<"Yes";return 0;}
	}
	cout<<"No";
	return 0;	
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int,input().rstrip().split(" ")))
ans = 0
swap = 0
for i in range(N):
    if p[i] == i + 1:
        if i != N - 1:
            swap = p[i]
            p[i] = p[i + 1]
            p[i + 1] = swap
            ans += 1
        else:
            swap = p[i]
            p[i] = p[i - 1]
            p[i - 1] = swap
            ans += 1
print(ans)

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    print((n - 1) * n / 2);

    return 0;
}


Measured memory_bytes: 256
from sys import stdin
rs = lambda : stdin.readline().strip()
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))


def main():
    S = rs()
    T = rs()
    ls = len(S)
    lt = len(T)
    print(min([sum([0 if x == y else 1 for x, y in zip(S[i:i + lt], T)]) for i in range(ls - lt + 1)]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9072
#include <iostream>
#include <algorithm>

typedef unsigned long      ulong;

// 得点は負になりうる.
long CalcMaxSum( ulong pt1, ulong pt0, ulong ptMinus1, ulong take )
{
    long point = std::min( pt1, take );
    take -= point;  // ここで、 take は１点のカードを除いた数になっている.
    
    return ( take <= pt0 ? point : point - ( take - pt0 ) );
}

int main( void )
{
    ulong A,B,C,K;
    std::cin >> A >> B >> C >> K;
    std::cout << CalcMaxSum( A, B, C, K ) << std::endl;
    return 0;
}

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

int N,a[3010];

int dp[3010][3010];
const int INF=1e18;

int rec(int i,int j)
{
    if(i==j) return 0;
    if(dp[i][j]!=INF) return dp[i][j];

    int res;
    if(N%2==(j-i)%2){
        res=-INF;
        chmax(res,a[i]+rec(i+1,j));
        chmax(res,a[j-1]+rec(i,j-1));
    }else{
        res=INF;
        chmin(res,rec(i+1,j)-a[i]);
        chmin(res,rec(i,j-1)-a[j-1]);
    }
    return dp[i][j]=res;
}   
    
signed main()
{
    cin>>N; 
    for(int i=0;i<N;i++){
        cin>>a[i];
    }

    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            dp[i][j]=INF;
        }
    }
    cout<<rec(0,N)<<endl;
}


Measured memory_bytes: 71040
//abc174_a.cpp
//Sat Sep 12 10:34:43 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

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

int main(){
	int n;
	cin >> n;
	if (n>=30){
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3596
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

n=int(input())
s=input()
ws=s.count('W')
rs=s.count('R')
ans=min(ws,rs)
posw=[]
posr=[]
for i in range(n):
    if s[i]=='W':
        posw.append(i)
    else:
        posr.append(i)
posr=posr[::-1]
for i in range(min(len(posw),len(posr))):
    if posw[i]>posr[i]:
        ans=min(ans,i)
        break
print(ans)


Measured memory_bytes: 18584
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    if (N % 2 == 0) cout << N/2 - 1 << endl;
    else cout << N/2 << endl;
    return 0;
}

Measured memory_bytes: 256
def bisect(l, r):
    while l < r:
        m = (l + r) // 2
        s1 = sum(abs(am - m) for am in aam)
        s2 = sum(abs(am - m - 1) for am in aam)
        if s1 < s2:
            r = m
        else:
            l = m + 1
    return l


n = int(input())
aaa = list(map(int, input().split()))
aam = [a - i - 1 for i, a in enumerate(aaa)]
aas = sum(aam)
b = bisect(int(-1e9), int(1e9))
print(sum(abs(am - b) for am in aam))


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

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    vector<pair<ll, int>> ch;

    rep(i, M)
    {
        int b;
        ll c;
        cin >> b >> c;
        ch.push_back(make_pair(c, b));
    }
    sort(ch.rbegin(), ch.rend());

    int now = 0;
    int num = 0;
    rep(i, N)
    {
        num = ch[now].second;
        if (num <= 0) {
            now++;
            if (now >= N)
                break;
        }
        if (ch[now].first < A[i])
            break;
        A[i] = ch[now].first;
        ch[now].second--;
    }
    ll ans = 0;
    rep(i, N)
    {
        ans += A[i];
    }

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

Measured memory_bytes: 6152
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;


int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	if (A > B || (N == 1 && A != B)) {
		cout << 0 << endl;
	}
	else {
		cout << (B*(N - 1) + A) - (B + A*(N - 1)) + 1 << endl;
	}


	return 0;
}

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

R_i = {}
G_i = {}
B_i = {}

ans = 0
for i in range(n) :
  if s[i] == 'R' :
    R_i[i] = 1
  if s[i] == 'G' :
    G_i[i] = 1
  if s[i] == 'B' :
    B_i[i] = 1

ans = len(R_i)*len(G_i)*len(B_i)

for ri in R_i :
  for gi in G_i :
    # Rが真ん中
    if 2*ri-gi in B_i :
      ans -= 1
    # Gが真ん中
    if 2*gi-ri in B_i :
      ans -= 1
    # Bが真ん中
    if (ri+gi)%2 == 0 :
      if (ri+gi)//2 in B_i :
        ans -= 1
    
print(ans)

Measured memory_bytes: 9320
def main():
    a, b , c, d = map(int, input().split())

    if abs(a - c) <= d:
        print('Yes')
    else:
        if abs(a - b) <= d and abs(b - c) <= d:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
const int Maxn=50005;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
vector<tuple<int,int,int>>edge;
int fa[6*Maxn],chk[2][1000005];
int getid(int x,int p,int q){
    return 6*(x-1)+3*p+q;
}
int Getfa(int x){return fa[x]=(fa[x]==x?x:Getfa(fa[x]));}
int main(){
    int n,m,q,mod,g=0;scanf("%d%d%d%d",&n,&m,&q,&mod);
    for(int i=1;i<=6*n;i++)fa[i]=i;
    for(int i=1;i<=m;i++){
        static int lst=-1;
        int x,y,v;scanf("%d%d%d",&x,&y,&v);
        edge.emplace_back(x,y,v);
        if(~lst)g=gcd(g,abs(v-lst));
        lst=v;
    }
    if(g==0)g=mod;
    mod=gcd(mod,3*g);
    for(int i=0;i<2*mod;i++){
        static int j=get<2>(edge[0])%g;
        chk[i&1][j]=1;
        j=2*j%mod;
    }
    for(auto&e:edge){
        int x,y,v;tie(x,y,v)=e;
        for(int p=0;p<2;p++)
            for(int q=0;q<3;q++){
                fa[Getfa(getid(x,p,q))]=Getfa(getid(y,p^1,(2*q+(v-v%g)/g)%3));
                fa[Getfa(getid(y,p,q))]=Getfa(getid(x,p^1,(2*q+(v-v%g)/g)%3));
            }
    }
    while(q--){
        int x,y,v,succ=0;scanf("%d%d%d",&x,&y,&v);
        for(int p=0;p<2&&!succ;p++)
            for(int q=0;q<3&&!succ;q++)
                if(Getfa(getid(y,0,0))==Getfa(getid(x,p,q)))
                    if(chk[p][(v+(3-q)*g+get<2>(edge[0])%g)%mod]){
                        succ=true;
                        puts("YES");
                        break;
                    }
        if(!succ)puts("NO");
    }
    return 0;
}

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

#define null				 ""
#define all(dat)			 dat.begin(), dat.end()
#define over(msg)			 cout << msg << endl, exit(0);
#define loop(i, to)			 for (int i = 0; i < to; ++i)
#define cont(i, to)			 for (int i = 1; i <= to; ++i)
#define foreach(i, dat)      for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long			 num;

using namespace std;

struct pt {
	int x, y;
	pt() {}
	pt(int x, int y) {
		this->x = x;
		this->y = y;
	}
};

bool g[405][405], vis[405][405];
int n, m, dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
num ans;

num bfs(int sx, int sy) {
	num cnt0 = 0, cnt1 = 0;
	queue<pair<pt, int>> q;
	q.push(make_pair(pt(sx, sy), g[sx][sy]));
	vis[sx][sy] = 1;
	while (!q.empty()) {
		int x = q.front().first.x, y = q.front().first.y, c = q.front().second;
		q.pop();
		cnt0 += c == 0;
		cnt1 += c == 1;
		loop (i, 4) {
			int cx = x + dx[i], cy = y + dy[i];
			if (cx < 0 || cy < 0 || cx >= n || cy >= m || g[cx][cy] == c || vis[cx][cy])  continue;
			vis[cx][cy] = 1;
			q.push(make_pair(pt(cx, cy), c ^ 1));
		}
	}
	return cnt0 * cnt1;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	loop (i, n) {
		string s;
		cin >> s;
		loop (j, m) {
			g[i][j] = s[j] == '#';
		}
	}
	loop (i, n) {
		loop (j, m) {
			if (!vis[i][j]) {
				ans += bfs(i, j);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include<cstdio>
#include<deque>
#define f(i,a,b) for(register int i=(a),i##end=(b);i<=i##end;++i)
const int neko=200010;
int n,a[neko];
std::deque<int>q;
int main()
{
	scanf("%d",&n);
	f(i,1,n)scanf("%d",&a[i]);
	int opt=n&1;
	f(i,1,n)
	{
		if((i&1)^opt)q.push_back(a[i]);
		else q.push_front(a[i]);
	}while(!q.empty())printf("%d ",q.front()),q.pop_front();
	return 0;
}


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

int main(void) {
  int n;
  scanf("%d", &n);
  char str[n + 2];
  memset(str, '\0', n);
  scanf(" %s", str);

  long long int sum = 0;
  int r_ptr = 0, g_ptr = 0, b_ptr = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'R') {
      r_ptr++;
    } else if (str[i] == 'G') {
      g_ptr++;
    } else if (str[i] == 'B') {
      b_ptr++;
    }
  }

  for (int i = 1; i <= (n / 2); i++) {
    int x = 0, y = x + i, z = x + 2 * i;
    for (int j = 0; j < (n - z); j++) {
      if ((str[x + j] != str[y + j]) && (str[y + j] != str[z + j]) && (str[x + j] != str[z + j])) sum++;
    }
  }

  printf("%lld\n", (long long int) r_ptr * (long long int) g_ptr * (long long int) b_ptr - sum);

  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){
    
    int n,m;
    cin>>n>>m;
    int h[n];
    rep(i,n)cin>>h[i];
    int a[m],b[m];
    rep(i,m){
        cin>>a[i]>>b[i];
    }
    
    int ans=0;
    int flag=0,k=0,nowh=0;
    int g[n]={};
    rep(i,m){
        if(h[a[i]-1]==h[b[i]-1]){
            g[a[i]-1]++;
            g[b[i]-1]++;
        }
        else if(h[a[i]-1]>h[b[i]-1])g[b[i]-1]++;
        else g[a[i]-1]++;
    }
    rep(i,n)if(g[i]==0)ans++;
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 5180
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <time.h>
#include <vector>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

int main(void){
    string s, t;
    cin >> s;
    t = "2019/04/30";
    
    for (int i = 0; i < 10; i++) {
        if (s[i] < t[i]) {
            cout << "Heisei" << endl;
            return 0;
            
        }
        else if (s[i] > t[i]) {
            cout << "TBD" << endl;
            return 0;
        }
    }
    
    cout << "Heisei" << endl;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split(" ")))
path = [tuple(map(int,input().split(" "))) for _ in range(M)]
path += [(item[1], item[0]) for item in path]
visited = [False for _ in range(N)]
visited[0] = True

def dfs(v_, visited):
    if not (False in visited):
        return 1
    ret = 0
    v = v_ + 1 
    for i_ in range(N):
        i = i_ + 1
        if not ((i, v) in path):
            continue
        if visited[i_]:
            continue
        visited[i_] = True
        ret += dfs(i_, visited)
        visited[i_] = False
        
    return ret
print(dfs(0, visited))

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

int main(){
    string s;
    cin >> s;
    int l = s.size();
    if( s[l-1] == 's' ) s += "es";
    else s += 's';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    int K;
    cin>>s>>K;
    
    rep(i,s.size()){
        int n=s[i]-'a';
        if(n==0) continue;
        if(26-n<=K){
            K-=(26-n);
            s[i]='a';
            if(K<=0) break;
        }
    }
    if(K>0){
        int n=s.back()-'a';
        n=(n+K)%26;
        s.back()=(char)('a'+n);
    }
    cout1(s)
}

Measured memory_bytes: 592
class UnionFind(object):
  def __init__(self,n):
    self.table=[-1]*n
 
  def find(self,x):
    parent=self.table[x]
    if parent<0:
      return x
    else:
      root=self.find(parent)
      self.table[x]=root
      return root
 
  def union(self,a,b):
    root1=self.find(a)
    root2=self.find(b)
    if root1 != root2:
      if self.table[root1] != self.table[root2]:
        if self.table[root1] < self.table[root2]:
          self.table[root2]=root1
        else:
          self.table[root1]=root2
      else:
        self.table[root1]+=(-1)
        self.table[root2]=root1

N=int(input())
x=[]
y=[]
M=[]
for i in range(N):
  X,Y=map(int,input().split())
  x.append((i,X))
  y.append((i,Y))

x=sorted(x,key=lambda x:x[1])
y=sorted(y,key=lambda y:y[1])

for i in range(N-1):
  a,b=x[i]
  c,d=y[i]
  e,f=x[i+1]
  g,h=y[i+1]
  M.append((f-b,a,e))
  M.append((h-d,c,g))
  
uf=UnionFind(N)
ans=0

for v,s,t in sorted(M,key=lambda x:x[0]):
  if uf.find(s)!=uf.find(t):
    uf.union(s,t)
    ans+=v

print(ans)

Measured memory_bytes: 55856
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

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

  int64_t n;
  std::vector<int64_t> t, a;
  cin >> n;
  t.resize(n);
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i] >> a[i];
  }
  int64_t tak = t[0], aok = a[0];
  for (int i = 1; i < n; i++) {
    if (t[i] == a[i]) {
      tak = std::max(tak, aok);
      aok = tak;
      cerr << tak << " " << aok << endl;
      continue;
    }
    int64_t t_unit = tak / t[i];
    int64_t t_sum;
    if (tak % t[i] != 0) t_unit++;
    if (t_unit * t[i] >= tak && t_unit * a[i] >= aok) {
      t_sum = t_unit * (a[i] + t[i]);
    } else {
      t_sum = INT64_MAX;
    }
    int64_t a_unit = aok / a[i];
    int64_t a_sum;
    if (aok % a[i] != 0) a_unit++;
    if (a_unit * t[i] >= tak && a_unit * a[i] >= aok) {
      a_sum = a_unit * (a[i] + t[i]);
    } else {
      a_sum = INT64_MAX;
    }

    if (t_sum > a_sum) {
      tak = a_unit * t[i];
      aok = a_unit * a[i];
    } else {
      tak = t_unit * t[i];
      aok = t_unit * a[i];
    }
    cerr << tak << " " << aok << endl;
  }
  cout << tak + aok << endl;

  return 0;
}


Measured memory_bytes: 256