akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
#include<set>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
long long fact[310000];
long long inv[310000];
long long finv[310000];
int p[110000];
int cnt[110000];
vector<int>g[110000];
vector<int>rev[110000];
int v[110000];
int cur;
int num[110000];
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		b/=2;a=a*a%mod;
	}
	return ret;
}
void dfs(int a){
	for(int i=0;i<g[a].size();i++){
		if(v[g[a][i]])continue;
		v[g[a][i]]=1;
		dfs(g[a][i]);
	}
	num[cur++]=a;
}
int scc[110000];
void dfs2(int a){
	scc[a]=cur;
	for(int i=0;i<rev[a].size();i++){
		if(v[rev[a][i]])continue;
		v[rev[a][i]]=1;
		dfs2(rev[a][i]);
	}
}
int dfs3(int a,int b){
	int ret=1;
	for(int i=0;i<rev[a].size();i++){
		if(b==scc[rev[a][i]])continue;
		ret+=dfs3(rev[a][i],b);
	}
	return ret;
}
int cy[110000];
int in[110000];
int out[110000];
int sz[110000];
int fi[110000];

int ren[110000];

long long dp[110000];
int main(){
	fact[0]=finv[0]=1;
	inv[1]=1;
	for(int i=1;i<310000;i++){
		fact[i]=fact[i-1]*i%mod;
	}
	for(int i=2;i<310000;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<310000;i++){
		finv[i]=finv[i-1]*inv[i]%mod;
	}
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);p[i]--;
		cnt[p[i]]++;
	}
	for(int i=0;i<a;i++)if(cnt[i]>2){
		printf("0\n");return 0;
	}
	for(int i=0;i<a;i++){
		g[i].push_back(p[i]);
		rev[p[i]].push_back(i);
	}
	for(int i=0;i<a;i++){
		if(v[i])continue;
		v[i]=1;
		dfs(i);
	}
	cur=0;
	for(int i=0;i<a;i++)v[i]=0;
	for(int i=a-1;i>=0;i--){
		if(v[num[i]])continue;
		v[num[i]]=1;
		fi[cur]=num[i];
		dfs2(num[i]);
		cur++;
	}
	for(int i=0;i<a;i++){
		in[scc[p[i]]]++;
		sz[scc[i]]++;
		if(scc[p[i]]!=scc[i])out[scc[i]]++;
	}
	for(int i=0;i<a;i++){
		if(cnt[i]>1&&scc[i]!=scc[p[i]]){
			printf("0\n");return 0;
		}
	}
	long long ret=1;
	for(int i=0;i<cur;i++){
		//printf("%d %d\n",in[i],sz[i]);
		if(out[i])continue;
		if(in[i]==sz[i]){
			cy[sz[i]]++;
			continue;
		}
		if(out[i])continue;
		vector<int>L;
		int at=fi[i];
		while(1){
			L.push_back(dfs3(at,scc[at])-1);
			at=p[at];
			if(at==fi[i])break;
		}

		int now=0;
		for(int j=0;j<L.size()*2;j++){
			ren[j%L.size()]=now;
			if(L[j%L.size()]==0)now++;
			else now=1;
		}
		for(int j=0;j<L.size();j++){
			if(L[j]==0)continue;
			if(ren[j]<L[j])ret*=0;
			else if(ren[j]>L[j])ret=ret*2%mod;
		}
	}
	for(int i=1;i<=a;i++){
		long long tmp=0;
		for(int j=0;j*2<=cy[i];j++){

			long long ks=pw(i,j)*fact[cy[i]]%mod*finv[cy[i]-j*2]%mod*finv[j]%mod*pw(500000004,j)%mod;
			if(i%2&&i!=1){
				ks=ks*pw(2,cy[i]-j*2)%mod;
			}
			tmp=(tmp+ks)%mod;
		}
		ret=ret*tmp%mod;
	}
	printf("%lld\n",ret);
}


Measured memory_bytes: 26492
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(max(a*c,a*d),max(b*c,b*d))<<endl; 
	return 0;
}


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 0; i <= n; i++)
#define REp(i,n) for(ll i = 1; i < n; i++)
#define REP(i,n) for(ll i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

set<int> can;

void f(int n, V<int> &m) {
  if(n > 100000) return;
  can.insert(n);
  rep(i,6) {
    int nx = n + m[i];
    if(can.find(nx) == can.end()) f(nx,m);
  }
}

int main(){
  int x;
  cin >> x;
  V<int> m = {100,101,102,103,104,105,106};
  f(0,m);
  for(int i : can) {
    if(i == x) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 8292
#include <bits/stdc++.h>
#define INF (1000000000000000000)
#define LL long long
//ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

int main()
{

    int n = 0 ;
    int r = 0;

    cin >> n >> r;

    if(n < 10)
    {
        cout<<r+(100*(10-n));
    }else
    {
        cout<<r;
    }



}


Measured memory_bytes: 3624
a[];main(f,l,i,n,S){for(;scanf(S="%d\n",&i)*i;){for(l=0;i--;)scanf(S,a+l++);for(n=32;n;f=!f)n-=f?~-n%5:a[++i%l],printf(S,n*=n>0);}}

Measured memory_bytes: 0
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n, m, k = nm()
    a = nl() + [k+1]
    b = nl() + [k+1]
    ai = bi = 0
    als = bs = 0
    while bs + b[bi] <= k:
        bs += b[bi]
        bi += 1
    ans = bi
    for i in range(n+1):
        als += a[i]
        if als > k:
            break
        while bs + als > k:
            bi -= 1
            bs -= b[bi]
        ans = max(ans, i + bi + 1)
    print(ans)
    return

solve()


Measured memory_bytes: 41720
/*
    AUTHOR:hruday pabbisetty
    NIT ROURKElA
*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
using namespace std::tr1;
#define opt ios_base::sync_with_stdio(0)
#define lli long long int
#define li long long int
#define ulli unsigned long long int
#define I int
#define S string
#define D double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define in3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define out(n) printf("%lld\n",n)
#define inu(a) scanf("%lld",&a)
#define outu(a) printf("%llu",a)
#define ins(s) scanf("%s",&s)
#define outs(s) printf("%s",s)
#define mod 1000000007
#define inf 100000000000000
typedef long long       ll;
typedef pair<lli,lli>  plli;
typedef vector<lli>     vlli;
typedef vector<li>     vli;
typedef vector<ulli>    vulli;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<plli>     vplli;
#define MM(a,x)  memset(a,x,sizeof(a));
#define ALL(x)   (x).begin(), (x).end()
#define P(x)       cerr<<"{"#x<<" = "<<(x)<<"}"<<endl;
#define P2(x,y)       cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<"}"<<endl;
#define P3(x,y,z)  cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<"}"<<endl;
#define P4(x,y,z,w)cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<", "#w" = "<<(w)<<"}"<<endl;
#define PP(x,i)     cerr<<"{"#x"["<<i<<"] = "<<x[i]<<"}"<<endl;
#define TM(a,b)     cerr<<"{"#a" -> "#b": "<<1000*(b-a)/CLOCKS_PER_SEC<<"ms}\n";
#define UN(v)    sort(ALL(v)), v.resize(unique(ALL(v))-v.begin())
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz() size()
#define nl cout<<"\n"
#define MX1 100005
#define MX2 1000005
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};
lli power(lli a,lli b)
    {
    lli value;
    if(b==0)
        {
        return 1;
    }
    else if(b%2==0)
        {
        value=power(a,b/2)%mod;
        return(value*value)%mod;
    }
    else
        {
        value=power(a,b/2)%mod;
        return ((a*value)%mod*(value))%mod;
    }
}

li n,m,vis[MX1],edg=0,compo=0;
vli g[MX1];

void dfs(li u){
    vis[u]=1;
    compo++;
    li i;
    rep(i,0,g[u].size()){
        int v=g[u][i];
        if(!vis[v]){
            edg++;
            dfs(v);
        }
    }
}

li C(li a,li b=2){
    return (a*(a-1))/2;
}

void solve(){
    cin>>n>>m;
    li i;
    rep(i,1,m+1){
        li x,y;
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    li one,two,edgone,edgtwo;
    dfs(1);
    one=compo;
    edgone=edg;
    compo=0;
    edg=0;
    dfs(2);
    two=compo;
    edgtwo=edg;
    li ans=C(n-one,2)-(m-edgone)+C(one,2)-edgone;
    ans=max(ans,C(n-two,2)-(m-edgtwo)+C(two,2)-edgtwo);
    cout<<ans;
}

int main()
{
      /*  #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif*/
    opt;

    solve();
    return 0;
}



Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s[21];
int dx[]={1,1,1,0,0,-1,-1,-1};
int dy[]={1,0,-1,1,-1,1,0,-1};
int h,w;
vector<string>v;
set<string> se;
void dfs(int d,int y,int x,int p,string t,int p1,int p2){
  if(d&&y==p1&&x==p2)return;
  t+=s[y][x];
  if(d){
    if(!se.count(t))se.insert(t);
    else v.push_back(t);
  }
  x+=dx[p],y+=dy[p];
  if(x<0)x=w-1;
  if(y<0)y=h-1;
  if(x>=w)x=0;
  if(y>=h)y=0;
  dfs(d+1,y,x,p,t,p1,p2);
}
int main(){
  while(cin>>h>>w,h){
    se.clear();
    v.clear();
    r(i,h)cin>>s[i];
    r(i,h)r(j,w)r(k,8)dfs(0,i,j,k,"",i,j);
    sort(v.begin(),v.end());
    int p=0;
    r(i,v.size())p=max(p,(int)v[i].size());
    if(v.size())r(i,v.size()){
      if(v[i].size()==p){
        cout<<v[i]<<endl;
        break;
      }
    }
    else cout<<0<<endl;
  }
}

Measured memory_bytes: 37624
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key   = k;
	z->left  = NIL;
	z->right = NIL;
	
	while(x != NIL) {
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL) {
		root = z;
	} else {
		if( z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}
	
int main(void) {
	int n, i, x;
	string com;
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		cin >> com;
		if(com == "insert") {
			scanf("%d",&x);
			insert(x);
		} else if(com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 26756
#include <iostream>
#include <vector>
#include <string>
#define mod 1000000007

using namespace std;

int main(void){
	int n;

	string s1, s2;

	cin >> n >> s1 >> s2;

	long long int num = 0;

	int x = 0;

	if (s1[0] == s2[0]){
		num = 3;
		x++;
	}
	else {
		num = 6;
		x = 2;
	}


	while (x < n){
		if (s1[x] == s2[x]){
			if (s1[x-1] == s2[x-1]){
				num = 2 * num % mod;
				x++;
			}
			else {
				x++;
			}
		}
		else {
			if (s1[x-1] == s2[x-1]){
				num = 2 * num % mod;
				x += 2;
			}
			else {
				num = 3 * num % mod;
				x += 2;
			}
		}
	}

	cout << num << endl;
}

Measured memory_bytes: 256
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize k;
    std::string s;
    std::cin >> k >> s;

    if (k < s.length()) {
        s = s.substr(0, k) + "...";
    }
    std::cout << s << '\n';
}


Measured memory_bytes: 3656
use proconio::input;

#[allow(unused_variables)]
fn main() {
    input! {
      l: usize, r: usize, d: usize
    };

    let mut ans = 0;

    for i in l..r + 1 {
        if i % d == 0 {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
typedef pair<int, int> P;

int N;
string S;
string ans;
bool check() {
	for (int i = 0; i < N; i++) {
		if (S[i] == 'o') {
			if (ans[i + 1] == 'S') {
				if (ans[i] == 'S') {
					ans += 'S';
				}
				else {
					ans += 'W';
				}
			}
			else {
				if (ans[i] == 'S') {
					ans += 'W';
				}
				else {
					ans += 'S';
				}
			}
		}
		else {
			if (ans[i + 1] == 'S') {
				if (ans[i] == 'S') {
					ans += 'W';
				}
				else {
					ans += 'S';
				}
			}
			else {
				if (ans[i] == 'S') {
					ans += 'S';
				}
				else {
					ans += 'W';
				}
			}
		}
	}
	//cout << ans << endl;
	if (ans[0] == ans[N] && ans[1] == ans[N + 1]) return true;
	else return false;
}

int main()
{
	cin >> N >> S;
	string tmp;
	ans.push_back('S');
	ans.push_back('S');
	if (check()) {
		for (int i = 1; i <= N; i++) {
			cout << ans[i];
		}
		cout << endl;
		return 0;
	}
	ans = tmp;
	ans.push_back('W');
	ans.push_back('S');
	if (check()) {
		for (int i = 1; i <= N; i++) {
			cout << ans[i];
		}
		cout << endl;
		return 0;
	}
	ans = tmp;
	ans.push_back('S');
	ans.push_back('W');
	if (check()) {
		for (int i = 1; i <= N; i++) {
			cout << ans[i];
		}
		cout << endl;
		return 0;
	}
	ans = tmp;
	ans.push_back('W');
	ans.push_back('W');
	if (check()) {
		for (int i = 1; i <= N; i++) {
			cout << ans[i];
		}
		cout << endl;
		return 0;
	}
	cout << -1 << endl;
}

Measured memory_bytes: 640
def makeans(s, t, n):
	ans = ''
	if n == -1: return 'UNRESTORABLE'
	for i in range(0, len(s)):
		if n <= i and i <= n+len(t)-1:
			ans = ans + t[i-n]
		else:
			if s[i] == '?':
				ans = ans + 'a'
			else:
				ans = ans + s[i]
	return ans

def find(s, t):
	for i in range(len(t), len(s)+1):
		flag = True
		for j in range(0, len(t)):
			if s[-i+j] != t[j] and s[-i+j] != '?':
				flag = False
				break
		if flag:
			return len(s) - i
	return -1

S = raw_input()
T = raw_input()

print makeans(S, T, find(S, T))

Measured memory_bytes: 2692
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

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

  string sun="Sunny",clo="Cloudy",rai="Rainy";
  if(s==sun) cout<<clo;
  else if(s==clo) cout<<rai;
  else cout<<sun;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#define debug(a) {for (int i=1; i<=nn; i++) cout << a[i] << ' '; cout << endl;}
using namespace std;
const int maxn = 2010;
const int modd = 1000000007;
int h, w, f1[maxn][maxn], f2[maxn][maxn], f3[maxn][maxn], f4[maxn][maxn], res;
char a[maxn][maxn];
/*void inarr()
{
    cin >> n;
    for (int i=1; i<=n; i++) cin >> a[i];
}*/
int main()
{
    //freopen("inp.txt","r",stdin);
    cin >> h >> w;
    for (int i=1; i<=h; i++)
        for (int j=1; j<=w; j++){
            cin >> a[i][j];
            if (a[i][j] == '.'){
                f1[i][j] = f1[i][j-1] + 1;
                f2[i][j] = f2[i-1][j] + 1;
            } else f1[i][j] = 0, f2[i][j] = 0;
        }
    for (int i=h; i>=1; i--)
        for (int j=w; j>=1; j--)
            if (a[i][j] == '.'){
                f3[i][j] = f3[i][j+1] + 1;
                f4[i][j] = f4[i+1][j] + 1;
            } else f3[i][j] = 0, f4[i][j] = 0;
    for (int i=1; i<=h; i++)
        for (int j=1; j<=w; j++)
            if (a[i][j] == '.')
                    res = max(res, f1[i][j]+f2[i][j]+f3[i][j]+f4[i][j]-3);
    cout << res;
}

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

const char *str[] = {
  " ",
  "',.!?",
  "abcABC",
  "defDEF",
  "ghiGHI",
  "jklJKL",
  "mnoMNO",
  "pqrsPQRS",
  "tuvTUV",
  "wxyz",
};


int main() {
  for( string line; cin >> line; ) {
    line += '$';
    vector<int> v;

    for(int i = 0, len = 1; i + 1 < (int)line.size(); i++) {
      if( line[i] != line[i + 1] ) {
        v.push_back( line[i] - '0' );
        v.push_back(len);
        len = 1;
      } else {
        len++;
      }
    }

    for(int i = 0; i < v.size(); i += 2) {
//       cout << v[i] << " " << v[i + 1] << endl;
      if( v[i] == 0 )
        for(int j = 0; j < v[i + 1] - 1; j++) cout << " ";
      else
        cout << str[v[i]][v[i +1] - 1];
    }
    cout << endl;

  }

}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main(){
    long long N;
    cin>>N;
    long long ans = 0;
    for(long long i = 1;i*i<=N;i++){
        if(N%i==0){
            long long a = i,b = N/i;
            if(a-1>0 && N%(a-1) == (N/(a-1))) ans+= a-1;
            if(b!=a && b-1>0&& N%(b-1) == N/(b-1)) ans+= b-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
#define mod 1000000007
using namespace std;
int n, m, r, v[230][230], a[10];
bool bl[10];
int f(int k, int p, int b) {
	if (k == r)return p;
	int rtn = mod;
	for (int i = 0; i < r; i++) {
		if (!bl[i]) {
			bl[i] = 1;
			rtn = min(rtn, f(k + 1, p + v[b][a[i]], a[i]));
			bl[i] = 0;
		}
	}
	return rtn;
}
signed main() {
	cin >> n >> m >> r;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			v[i][j] = (i == j ? (int)0 : mod);
		}
	}
	for (int i = 0; i < r; i++) cin >> a[i];
	for (int i = 0; i < m; i++) {
		int a, b, c; cin >> a >> b >> c;
		v[a][b] = min(c, v[a][b]); v[b][a] = v[a][b];
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				v[j][k] = min(v[j][i] + v[i][k], v[j][k]);
			}
		}
	}
	int ans = mod;
	for (int i = 0; i < r; i++) {
		bl[i] = 1;
		ans = min(ans, f(1, 0, a[i]));
		bl[i] = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

class Vertex {
    companion object {
        var disc = 0
    }

    val adj: MutableList<Edge> = mutableListOf()
    var num = -1
    var low = -1
    var visited = false


    fun dfs(from: Vertex?) {
        visited = true
        num = disc
        low = disc
        disc += 1


        for (edge in adj) {
            val v = edge.to
            if (!v.visited && v != from) {
                v.dfs(this)
                low = Math.min(v.low, low)
                if (v.low > num) edge.bridge = true
            }
            else if(v!=from) {
                low = Math.min(low, v.num)
            }
        }
    }
}

class Edge(val to: Vertex) {
    var bridge: Boolean = false
}

val sc = FastScanner(System.`in`)
fun main(args: Array<String>) {
    val n = sc.nextInt()
    val m = sc.nextInt()


    val vs = Array(n) { Vertex() }
    (1..m).forEach {
        val v = vs[sc.nextInt() - 1]
        val u = vs[sc.nextInt() - 1]
        v.adj.add(Edge(u))
        u.adj.add(Edge(v))
    }


    vs[0].dfs(null)


    val count = vs
        .asSequence()
        .flatMap { it.adj.asSequence() }
        .filter { it.bridge }
        .count()


    println(count)

}


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}




Measured memory_bytes: 35824
#include<bits/stdc++.h>
using namespace std;
int main(){
	//freopen("input.txt", "r", stdin);
	long long n = 0;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='+')	n++;
		else			n--;
	}
	cout<<n;
	return 0;
}

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

void pf(int64_t a,set<int64_t> &s){
  if(a<2){
    return;
  }
  int64_t n=2;
  while(n<=sqrt(a)){
    if(a%n==0){
      a/=n;
      s.insert(n);
    }else{
      n++;
    }
  }
    s.insert(a);
}

int64_t gcd(int64_t a,int64_t b){
  int64_t r=max(a,b)%min(a,b);
  if(r==0){
    return min(a,b);
  }
  return gcd(min(a,b),r);
}

int main(){
  int64_t A,B;
  cin >> A >> B;
  set<int64_t> s;
  s.insert(1);
  pf(gcd(A,B),s);
  cout << s.size() << endl;
  return 0;
}


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

struct UnionFind{
	vector<lint> rnk,par,num;
	UnionFind(lint N) : rnk(N),par(N),num(N){
		init();
	}
	void init(){
		for(lint i = 0;i < rnk.size();i++){
			rnk[i] = 0;
			par[i] = i;
			num[i] = 1;
		}
	}
	lint find(lint x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	void unite(lint x,lint y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rnk[x] < rnk[y]){
			par[x] = y;
			num[y] += num[x];
		}
		else{
			par[y] = x;
			num[x] += num[y];
			if(rnk[x] == rnk[y]) rnk[x]++;
		}
	}
	bool same(lint x,lint y){
		return (find(x) == find(y));
	}
	lint size(lint x){
		return num[find(x)];
	}
};

signed main(){
  lint N, M; cin >> N >> M;
  lint ans = 0;
  vector<lint> a(M), b(M);
  for(lint i = 0; i < M; i++) cin >> a[i] >> b[i], a[i]--, b[i]--;
  for(lint i = 0; i < M; i++){
    UnionFind tree(N);
    for(lint j = 0; j < M; j++){
      if(i != j){
        tree.unite(a[j], b[j]);
      }
    }
    if(!tree.same(a[i], b[i])) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int prime[];

		prime = new int[51000];
		for (int i = 2; i < 51000; i++) {
			for (int j = i; j < 51000; j++) {
				if (0 <= i * j && i * j < 51000) {
					prime[i * j] = 1;
				} else {
					break;
				}
			}
		}

		while (sc.hasNext()) {
			n = sc.nextInt();
			for (int i = n - 1; 0 <= i; i--) {
				if (prime[i] == 0) {
					System.out.print(i + " ");
					break;
				}
			}
			for (int i = n + 1; i < 51000; i++) {
				if (prime[i] == 0) {
					System.out.println(i);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 12000
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef long long ll;  //ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<ll, ll> > PS;

void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { rep(i, f.size())input(f[i]); input(r...); }

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// g++ -std=c++11 prac.cpp 
int main(){
    ll y=0,z,n,m=0,q,k,h,w,sum=0,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u;
    bool ok=true;
    input(n);
    VL a(n); input(a);
    VB ans(n,false);
    for(int i=n; i>=1; i--){
        for(int j=i*2; j<=n; j+=i){
            if(ans[j-1]) count++;
        }
        if(count % 2 != a[i-1])
            ans[i-1] = true;
        count = 0;
    }
    count = 0;
    rep(i,n){
        if(ans[i])
            count++;
    }
    cout << count << endl;
    rep(i,n){
        if(ans[i]) 
            cout << i+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int seen[maxn], unk[maxn], par[maxn], l[maxn], r[maxn];
vector<int> e[maxn], ord;
void dfs(int u, int v){
	ord.push_back(u);
	for(int to : e[u]) if(to != v) dfs(to, u);
}
int main(){
	int n; cin >> n;
	for(int i = 0; i < n - 1; i++){
		int x, y; cin >> x >> y; x--; y--;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	int k; cin >> k;
	for(int i = 0; i < k; i++){
		int v, p; cin >> v >> p; v--;
		unk[v] = 1; par[v] = p&1; l[v] = p; r[v] = p;
	}
	dfs(0, -1);
	auto bad = [&](){
		cout << "No" << endl;
		exit(0);
	};
	auto push = [&](int v, int m2, int ll, int rr){
		if(!unk[v]){
			unk[v] = 1;
			par[v] = m2;
			l[v] = ll;
			r[v] = rr;
		} else {
			if(par[v] != m2) bad();
			l[v] = max(l[v], ll);
			r[v] = min(r[v], rr);
			if(l[v] > r[v]) bad();
		}
	};
	auto relax = [&](int from, int to, int step){
		memset(seen, 0, sizeof(seen));
		while(from != to){
			int v = ord[from];
			seen[v] = 1;
			if(unk[v]){
				for(int u : e[v]){
					if(!seen[u]){
						push(u, par[v] ^ 1, l[v] - 1, r[v] + 1);	
					}
				}
			}
			from += step;
		}
	};
	auto force = [&](int from, int to, int step){
		memset(seen, 0, sizeof(seen));
		while(from != to){
			int v = ord[from];
			seen[v] = 1;
			if(!unk[v]) bad();
			r[v] = l[v];
			for(int u : e[v]){
				if(!seen[u]){
					push(u, par[v] ^ 1, l[v] - 1, r[v] + 1);	
				}
			}
			from += step;
		}
	};
	relax(0, n, 1);
	relax(n - 1, -1, -1);
	relax(0, n, 1);
	relax(n - 1, -1, -1);
	relax(0, n, 1);
	relax(n - 1, -1, -1);
	relax(0, n, 1);
	relax(n - 1, -1, -1);
	force(0, n, 1);
	cout << "Yes" << endl;
	for(int i = 0; i < n; i++) cout << l[i] << endl;
	return 0;
}


Measured memory_bytes: 13560
import queue

def solve():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    dist = [[h*w*100 for i in range(w)] for j in range(h)]
    dist[0][0] = 1

    q = queue.Queue()
    q.put((0,0))

    while not q.empty() :
        (x,y) = q.get()
        nd = dist[x][y] + 1
        for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
            nx = x + dx
            ny = y + dy
            if nx < 0 or nx >= h or ny < 0 or ny>= w :
                continue
            if field[nx][ny] == '.' and dist[nx][ny] > nd :
                dist[nx][ny] = nd
                q.put((nx,ny))

    if dist[h-1][w-1] >= h*w :
        return -1

    ans = h*w - dist[h-1][w-1]
    for v in field:
        ans -= v.count('#')

    return ans

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


Measured memory_bytes: 3952
--{-# LANGUAGE OverloadedStrings #-}
--{-# LANGUAGE OverloadedLists   #-}
{-# LANGUAGE BangPatterns      #-} --引数に!
{-# LANGUAGE MultiWayIf        #-}
{-# LANGUAGE TupleSections     #-}

import Data.Bits
import Data.Foldable (foldlM,foldrM)
import Data.Maybe (fromJust)
import Data.List
--import Data.Matrix.Unboxed
import Data.Array  --変数衝突
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
import Data.Graph
--import Data.Vector as V　--変数衝突
import qualified Data.Vector.Unboxed as V
import Control.Monad
import Control.Monad.State
import Control.Monad.ST
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  let bnds = (floor $ 0.5 + (sqrt $ (fromIntegral n) + 0.25))
  print $ sum $ traceShowId $ [(n-r) `div` r | r <- [1..bnds], r < (n-r) `div` r , (n-r) `mod` r == 0]


Measured memory_bytes: 2044
#include <iostream>

int main(){
    int a, b, c;
    std::cin >> a >> b >> c;

    if(a == b){
        std::cout << c << std::endl;
    }else if(b == c){
        std::cout << a << std::endl;
    }else if(c == a){
        std::cout << b << std::endl;
    }

    return 0;
}

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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug1(x) cout<<#x<<" : "<<x<<endl
#define debug2(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl

typedef long long ll;
typedef pair<ll,ll> pii;
const ll modd=1e9+7;

ll poww(ll a,ll b){
  ll ans=1;
  while(b>0){
    if(b%2==1) ans=(ans*a);
    a=(a*a);
    b=b/2;
  }
  return ans;
}

/*-----------------------------------------------------------------------*/

ll dp[1LL<<22LL];
ll matching[22][22];
ll n;

ll bitdp(ll mask){
	if(dp[mask]!=-1)
		return dp[mask];
	dp[mask]=0;
	ll pointr=__builtin_popcount(mask);
	if(pointr==n){
		dp[mask]=1;
		return 1;
	}
	for(ll i=1;i<=n;i++){
		if(matching[pointr+1][i]==1&&!(mask&(1LL<<i))){
			dp[mask|(1LL<<i)]=bitdp(mask|(1LL<<i));
			dp[mask]=(dp[mask]+dp[mask|(1LL<<i)])%modd;
		}
	}
	return dp[mask];
}

int main(){
   fastt;

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

   cin>>n;

   for(ll i=1;i<=n;i++)
   	  for(ll j=1;j<=n;j++)
   	  	  cin>>matching[i][j];

   ll ans=bitdp(0LL);

   cout<<ans<<endl;

   return 0;
}


Measured memory_bytes: 33024
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    int N, K, R, S, P;
    string T;

    cin >>N>>K>>R>>S>>P;
    cin >> T;

    ll sum = 0;
    string s_rsp = "rsp";

    rep(i, N) {
        char c = T[i];
        if (i < K) {
            if (c == 'r')      sum += P;
            else if (c == 's') sum += R;
            else if (c == 'p') sum += S;
        } else {
            if (c == T[i-K]) {
                T[i] = ' ';
            } else {
                if (c == 'r')      sum += P;
                else if (c == 's') sum += R;
                else if (c == 'p') sum += S;
            }
        }
    }

    cout << sum <<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> num(3);
  num[0] = A;
  num[1] = B;
  num[2] = C;
  sort(num.begin(), num.end());
  int count = 0;
  while (num[0] < num[1]) {
    num[0] += 2;
    count++;
    sort(num.begin(), num.end());
  }
  cout << count + num[2]-num[1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<vector>
#include<map>

using namespace std;
int main(){
  string str;
  map <char,int> m;
  map <char,int>::iterator im;
  int flag = 0;
  cin >> str;
  for(int i = 0 ; i < 4 ; i++){
    m[str[i]]++;
  }
  im = m.begin();
  if(im -> second == 2){
    im++;
    if(im ->second == 2){
      flag = 1;
    }
  }
  if(flag == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }  return 0;
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 207;

int n;
char is[MAXN][MAXN];
int g[MAXN][MAXN];
int q[MAXN], lev[MAXN];

void init ();
void input ();
void work ();

int bfs ( int beg );



int main ()
{
	init ();
	input ();
	work ();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%s", is[i] + 1 );
}

void work ()
{
	// main work

	lpi ( i, 1, n ) lpi ( j, 1, n ) g[i][j] = ( is[i][j] == '1' ) ? 1 : 0;

	int ans = -1;
	lpi ( i, 1, n ) ans = max ( ans, bfs ( i ) );
	cout << ans << endl;
}



int bfs ( int beg )
{
	INIT ( lev, -1 );
	int l = 0, r = 0, now, ml = -1;
	q[r++] = beg;
	lev[beg] = 1;
	while ( l < r ) {
		now = q[l++];
		ml = qmax ( ml, lev[now] );
		lpi ( v, 1, n ) {
			if ( g[now][v] ) {
				if ( lev[v] == -1 ) {
					lev[v] = lev[now] + 1;
					q[r++] = v;
				} else if ( abs ( lev[v] - lev[now] ) ^ 1 ) {
					return -1;
				}
			}
		}
	}
	return ml;
}

Measured memory_bytes: 512
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		int max = 0;
		for (int i = 0; i < N; i++) {
			int a = sc.nextInt();
			if (K == a) {
				System.out.println("POSSIBLE");
				return;
			}
			A[i] = a;
			max = Math.max(a, max);
		}
		if (max < K) {
			System.out.println("IMPOSSIBLE");
			return;
		}

		int gcd = A[0];
		for (int i = 1; i < A.length; i++) {
			gcd = gcd(gcd, A[i]);
			if (gcd == 1) {
				System.out.println("POSSIBLE");
				return;
			}
		}
		System.out.println(K % gcd == 0 ? "POSSIBLE" : "IMPOSSIBLE");
	}

	int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 50604
s = list(map(int, list(input())))
s2 = s[:]

ans1 = 0
ans2 = 1

for i in range(1, len(s)):
    if (s[i-1] + s[i]) % 2 == 0:
        s[i] = abs(s[i]-1)
        ans1 += 1

if s2[0] == 0:
    s2[0] = 1
else:
    s2[0] = 0

for i in range(1, len(s)):
    if (s2[i-1] + s2[i]) % 2 == 0:
        s2[i] = abs(s2[i]-1)
        ans2 += 1

print(ans1 if ans1 <= ans2 else ans2)


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

typedef long long int ll;
ll n, k;
ll cnt = 0;

void solve()
{
	ll num = n / k;
	cnt += num * num * num;
	if(k%2 == 0)
	{
		if(n >= k/2)
		{
			ll x = (n-(k/2))/k + 1; 
			cnt += x * x * x;
		} 
	}
} 

int main()
{
	cin >> n >> k;
	solve();
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 310000
using namespace std;
struct node
{
    int x,y;
};
map<pair<int,int>,int>mp;
int Find(int a[],int x)
{
    return a[x]==x?x:a[x]=Find(a,a[x]);
}
void marge(int a[],int x,int y)
{
    int fx=Find(a,x);
    int fy=Find(a,y);
    if(fx!=fy)
    {
        a[fx]=fy;
    }
}
int main()
{
    int a[200100],b[200100];
    int n,k,l,i,j,u,v;
    scanf("%d%d%d",&n,&k,&l);
    for(int i=1; i<=n; i++)
    {
        a[i]=i;
        b[i]=i;
    }
    for(int i=1; i<=k; i++)
    {
        scanf("%d%d",&u,&v);
        marge(a,u,v);
    }
    for(int i=1; i<=l; i++)
    {
        scanf("%d%d",&u,&v);
        marge(b,u,v);
    }
    node tp;
    for(int i=1; i<=n; i++)
    {
        tp.x=Find(a,i);
        tp.y=Find(b,i);
        mp[ {tp.x,tp.y}]++;
    }
    int first=1;
    for(int i=1; i<=n; i++)
    {
        if(!first) printf(" ");
        tp.x=Find(a,i);
        tp.y=Find(b,i);
        printf("%d",mp[ {tp.x,tp.y}]);
        first=0;
    }
    printf("\n");
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

string s;

int main(){
  cin>>s;
  int k=0;
  REP(i,s.size()){
    char c=s[i];
    if(c=='C'&&k==0)k=1;
    else if(c=='F'&&k==1)k=2;
  }
  puts(k==2?"Yes":"No");
  return 0;
}


Measured memory_bytes: 764
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto i: a)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        fl(i,0,n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define what(x) cerr << #x << " is " << x << endl;
int sum() { return 0; }template<typename T,typename... Args>T sum(T a, Args... args) { return a + sum(args...); }


void solve()
{ 


int l;
  cin>>l;
  float x=l*1.0/3;
  float ans=x*x*x;
  cout<<fixed<<setprecision(10)<<ans;}
signed main()
{fast
  int t;
  //cin>>t;
  t=1;
  while(t--)
    {solve();}
  
}












Measured memory_bytes: 256
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	N, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	scanner.Scan()
	M, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	canSelect := 0
	total := 0
	A := make([]int, N)

	for i := 0; i < N; i++ {
		scanner.Scan()
		a, err := strconv.Atoi(scanner.Text())

		if err != nil {
			log.Fatal(err)
		}

		A[i] = a

		total += A[i]

	}

	for _, value := range A {
		if value*4*M >= total {
			canSelect++
		}

		if canSelect >= M {
			fmt.Println("Yes")
			os.Exit(0)
		}
	}

	fmt.Println("No")

}


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

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}

int n,a,b;

int main(){
    int i,j,k,l;
    int fg=0,in=0;
    
    cin >>n>>a>>b;cin.ignore();
    string s;
    cin >> s;
    
    for (i=0;i<n;i++){
        switch(s[i]){
        case 'a':
            if (fg+in<a+b){
                in++;
                puts("Yes");
            }else{
                puts("No");
            }
            break;
        case 'b':
            if (fg+in<a+b && fg<b){
                fg++;
                puts("Yes");
            }else{
                puts("No");
            }
            break;
        case 'c':
            puts ("No");
            break;
        }
    }
    

    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			x = in.readLine();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		String[] values = x.split(" ");
		long a = Integer.parseInt(values[0]);
		long b = Integer.parseInt(values[1]);

		String ans = String.format("%f", ((double)a / b));
		System.out.println((a / b) + " " + (a % b) + " " + ans);
	}
}

Measured memory_bytes: 24860
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
const int MAX= 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
int64_t a,b;
  cin>>a>>b;
  for(int i=1;i<=b;i++)
  {
  cout<<COM(b-1,i-1)*COM(a-b+1,i)%MOD<<endl;
  }
    // 計算例
   
}


Measured memory_bytes: 12160
#include <stdio.h>
int main(){
	int N;
	scanf("%d",&N);
	int data;
	long long int cast[N-1][21];
	int i,j;
	for(i=0;i<N-1;i++){
		for(j=0;j<21;j++){
			cast[i][j]=0;
			}
	}
	scanf("%d",&data);
	cast[0][data]=1;
	for(i=1;i<N-1;i++){
		scanf("%d",&data);
		for(j=0;j<21;j++){
			if(data+j<21){
				cast[i][j+data]=cast[i][j+data]+cast[i-1][j];
			}
			if(j-data>-1){
				cast[i][j-data]=cast[i][j-data]+cast[i-1][j];
			}
		}
	}
	scanf("%d",&data);
	printf("%lld\n",cast[N-2][data]);
	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }

int D;
vector<int> c(26); 
vector<vector<int>> s(365, vector<int>(26));

int cal_score(vector<int> t){
    int satis = 0;
    vector<int> last(26, 0);
    rep(d, D){
        satis += s[d][t[d] - 1];
        last[t[d] - 1] = d + 1;
        rep(i, 26){
            satis -= c[i] * (d - last[i] + 1);
        }
    }
    return satis;
}

int ch_sch(vector<int> t, int d, int q, int score){
    // change t[d - 1] -> q
    // calculate the score
    int old = t[d - 1];
    score -= s[d - 1][old - 1];
    score += s[d - 1][q - 1];

    int last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old ) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score += c[old - 1] * (i - last_old + 1);
        score += c[q - 1] * (i - last_new + 1);
    }

    t[d - 1] = q;

    last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score -= c[old - 1] * (i - last_old + 1);
        score -= c[q - 1] * (i - last_new + 1);
    }
    return score;
}

int main(){
    srand((unsigned)time(NULL));

    // input 
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }

    // greedy
    vector<int> last(26, 0);
    vector<int> res(D);

    rep(d, D){
        int max_plus = -10000;
        int use = -1;
        rep(i, 26){
            int tmp = s[d][i] + c[i] * (d - last[i] + 1);
            if(max_plus < tmp){
                max_plus = tmp;
                use = i;
            }
        }
        last[use] = d + 1;
        res[d] = use + 1;
    }

    int cur_score = cal_score(res);
    int ch_d = D;

    while((clock() / (double)CLOCKS_PER_SEC) <= 1.98){
        int ch_c = rand() % 26 + 1;
        // int ifch = rand() % 100;
        int new_score = ch_sch(res, ch_d, ch_c, cur_score);
        if(cur_score < new_score){
            cur_score = new_score;
            res[ch_d - 1] = ch_c;
            ch_d--;
            if(ch_d == 0) ch_d = D;
        }
    }

    rep(i, D){
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 22000;
const int M = 1e6+5;
const int INF = 0x3f3f3f3f;

map <string,int> p; 

int main()
{     
    int n,Max = 0;
    string s;
    scanf("%d",&n);
    for(int i = 0;i < n;++i){
    	cin >> s;
    	p[s]++;
    	Max = max(Max,p[s]);
	}
	
	map <string,int> :: iterator it;
	for(it = p.begin();it != p.end();it++){
		if(it -> second == Max) cout << it -> first << "\n";
	}
    return 0;
}


Measured memory_bytes: 25216
<?php
  list($s) = explode(" ", trim(fgets(STDIN)));
  
  if(($s[0] == $s[1] && $s[2] == $s[3] && $s[0] != $s[2]) ||
    ($s[0] == $s[2] && $s[1] == $s[3] && $s[0] != $s[1]) ||
    ($s[0] == $s[3] && $s[1] == $s[2] && $s[0] != $s[1])){
    echo "Yes";
  }else{
    echo "No";
  }

Measured memory_bytes: 4604