akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
typedef long long ll;

using namespace std;

class Edge
{
	public:
	int cost;
	int next;

	Edge(int n,int c)
	{
		next=n;
		cost=c;
	}
};

vector<Edge> g[100000];
vector<int> pr[100000];
bool used[100000];
int p[100000];
int cnt;

int dfs(int now)
{
	used[now]=true;
	pr[cnt].push_back(now);
	for(int i=0;i<g[now].size();i++)
	{
		Edge e=g[now][i];
		if(!used[e.next])
		{
			dfs(e.next);
		}
	}
	return 0;
}

int main()
{
	int n,m;
	cnt=0;
	int ans=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
		p[i]--;
	}
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		g[x].push_back(Edge(y,1));
		g[y].push_back(Edge(x,1));
	}
	fill(used,used+100000,false);
	//連結判定
	for(int i=0;i<n;i++)
	{
		if(!used[i])
		{
			dfs(i);
			cnt++;
		}
	}
	
	for(int i=0;i<cnt;i++)
	{
		int s=pr[i].size();
		for(int j=0;j<s;j++)
		{
			pr[i].push_back(p[pr[i][j]]);
		}
		sort(pr[i].begin(),pr[i].end());
		for(int j=1;j<pr[i].size();j++)
		{
			if(pr[i][j]==pr[i][j-1])
				ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    ll n,k,i,j,sumf,sumb,ans;
    cin>>n>>k;
    ans=sumf=sumb=0;
    for(i=0,j=n; i<k; i++,j--)sumf+=i,sumb+=j;
    ans=(sumb-sumf+1)%mod;
    for(; i<=n; i++,j--)
    {
        sumf+=i,sumb+=j;
        ans=(ans+sumb-sumf+1)%mod;
    }
    if(ans<0)ans+=mod;
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
  int N,x;
  cin >> N >> x;
  int a[N];
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  sort(a,a+N);
  int count=0;
  for(int i=0;i<N;i++){
    x -=a[i];
    count++;
    if(x==0) break;
    else if(x<0){
      count--;
      break;
    }
  }
  if(x>0) count--;
  cout << count << endl;
}
  
    

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<climits>
#include<cmath>
#include<algorithm>

using namespace std;

#define lli long long int
int main()
{
    int n,m,a[10005],i;
    lli sum=0;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>n)   cout<<"-1"<<endl;
    else
    {
        cout<<n-sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    int k ;
    cin >> k;
    string s;
    cin >> s;
    //cout << s.size() << endl;

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

    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	ll n,k,i;
	string s,t;
	cin>>s>>t;
	int ans = 0;
	for(i=0;i<s.length();++i){
		if(s[i] != t[i])
			ans ++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3920
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;

import java.io.*;

public class Main {
	
	void solve() {
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int[] t = sc.nextIntArray(N);
		int ans = 0;
		for (int x : t) {
			if (A <= x && x < B) continue;
			ans++;
		}
		out.println(ans);
	}
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }
	static void tr(int[][] as) { for (int[] a : as) tr(a); }

	void print(int[] a) {
		if (a.length > 0) out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 8400
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
    long[,] vertexes = new long[n,3];
    for(long i = 0; i < n; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);//１行ごとに受け取る
      vertexes[i,0] = nums[0];
      vertexes[i,1] = nums[1];
      vertexes[i,2] = nums[2];
    }
    long[,] dp = new long[n+1,3];//x日語にyを行った場合の合計の最大値

    dp[1,0] = vertexes[0,0];
    dp[1,1] = vertexes[0,1];
    dp[1,2] = vertexes[0,2];

    for(int i = 2; i <= n; i++)
    {
      dp[i,0] = Math.Max(dp[i-1,1],dp[i-1,2]) + vertexes[i-1,0];
      dp[i,1] = Math.Max(dp[i-1,0],dp[i-1,2]) + vertexes[i-1,1];
      dp[i,2] = Math.Max(dp[i-1,1],dp[i-1,0]) + vertexes[i-1,2];
    }

    long answer = 0;
    answer = Math.Max(dp[n,0], dp[n,1]);
    answer = Math.Max(answer, dp[n,2]);
    
		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 19644
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int NUM_ITEM_MAX = 200;

long long int updateValue( int n, vector< long long int >& valueList, vector< vector< int > >& recipeList, vector< bool >& updatedList )
{
	if( updatedList[ n ] ){
		return valueList[ n ];
	}
	updatedList[ n ] = true;
	vector< int > recipe = recipeList[ n ];
	if( recipe.empty() ){
		return valueList[ n ];
	}
	long long int value = 0;
	for( int i = 0; i < (int)recipe.size(); ++i ){
		int id = recipe[ i ];
		value += updateValue( id, valueList, recipeList, updatedList );
	}
	if( value < valueList[ n ] ){
		valueList[ n ] = value;
	}
	return valueList[ n ];
}

int main()
{
	int n;
	while( cin >> n && n ){
		int id = 0;
		map< string, int > nameList;
		vector< long long int > valueList( NUM_ITEM_MAX + 1, 1LL << 62 );
		for( int i = 0; i < n; ++i ){
			string s;
			int v;
			cin >> s >> v;
			int d = id++;
			nameList.insert( make_pair( s, d ) );
			valueList[ d ] = v;
		}
		int m;
		vector< vector< int > > recipeList( NUM_ITEM_MAX + 1, vector< int >() );
		cin >> m;
		for( int i = 0; i < m; ++i ){
			string o;
			int k;
			cin >> o >> k;
			int count = nameList.count( o );
			if( count == 0 ){
				int d = id++;
				nameList.insert( make_pair( o, d ) );
			}
			int productId = nameList[ o ];
			for( int j = 0; j < k; ++j ){
				string q;
				cin >> q;
				count = nameList.count( q );
				if( count == 0 ){
					int d = id++;
					nameList.insert( make_pair( q, d ) );
				}
				int materialId = nameList[ q ];
				recipeList[ productId ].push_back( materialId );
			}
		}
		vector< bool > updatedList( nameList.size(), false );
		for( int i = 0; i < (int)nameList.size(); ++i ){
			updateValue( i, valueList, recipeList, updatedList );
		}

		string ansName;
		cin >> ansName;
		cout << valueList[ nameList[ ansName] ] << endl;
	}
	return 0;
}

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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=2e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

int n;
int x[N],y[N],opt[N];
int ans=INT_MAX;

struct node{
    int x,y;
}a[N];

bool cmp1(node x,node y){
    if(x.y!=y.y)return x.y<y.y;
    return x.x<y.x;
}

bool cmp2(node x,node y){
    if(x.x!=y.x)return x.x<y.x;
    return x.y<y.y;
}

bool cmp3(node a,node b){
    if(a.x-a.y!=b.x-b.y)return a.x-a.y<b.x-b.y;
    return a.x<b.x;
}

bool cmp4(node a,node b){
    if(a.x-a.y!=b.x-b.y)return a.x-a.y<b.x-b.y;
    return a.x>b.x;
}

bool cmp5(node a,node b){
    if(a.x+a.y!=b.x+b.y)return a.x+a.y<b.x+b.y;
    return a.x<b.x;
}

bool cmp6(node a,node b){
    if(a.x+a.y!=b.x+b.y)return a.x+a.y<b.x+b.y;
    return a.x>b.x;
}

int main()
{
    read(n);
    Rep(i,1,n){
        char ch;
        read(x[i]),read(y[i]),ch=getchar();
        if(ch=='U')opt[i]=0;
        if(ch=='R')opt[i]=1;
        if(ch=='D')opt[i]=2;
        if(ch=='L')opt[i]=3;
    }
    int tot=0;
    Rep(i,1,n)if(opt[i]==3)a[++tot]=(node){x[i],y[i]};
    sort(a+1,a+tot+1,cmp1);
    Rep(i,1,n)
        if(opt[i]==1){
            int pos=lower_bound(a+1,a+tot+1,(node){x[i],y[i]},cmp1)-a;
            if(pos<=tot&&a[pos].y==y[i])ans=min(ans,(a[pos].x-x[i])*5);
        }
    tot=0;
    Rep(i,1,n)if(opt[i]==2)a[++tot]=(node){x[i],y[i]};
    sort(a+1,a+tot+1,cmp2);
    Rep(i,1,n)
        if(opt[i]==0){
            int pos=lower_bound(a+1,a+tot+1,(node){x[i],y[i]},cmp2)-a;
            if(pos<=tot&&a[pos].x==x[i])ans=min(ans,(a[pos].y-y[i])*5);
        }
    sort(a+1,a+tot+1,cmp3);
    Rep(i,1,n)
        if(opt[i]==1){
            int pos=lower_bound(a+1,a+tot+1,(node){x[i],y[i]},cmp3)-a;
            if(pos<=tot&&a[pos].x-a[pos].y==x[i]-y[i])ans=min(ans,(a[pos].x-x[i])*10);
        }
    tot=0;
    Rep(i,1,n)if(opt[i]==0)a[++tot]=(node){x[i],y[i]};
    sort(a+1,a+tot+1,cmp4);
    Rep(i,1,n)
        if(opt[i]==3){
            int pos=lower_bound(a+1,a+tot+1,(node){x[i],y[i]},cmp4)-a;
            if(pos<=tot&&a[pos].x-a[pos].y==x[i]-y[i])ans=min(ans,(x[i]-a[pos].x)*10);
        }
    sort(a+1,a+tot+1,cmp5);
    Rep(i,1,n)
        if(opt[i]==1){
            int pos=lower_bound(a+1,a+tot+1,(node){x[i],y[i]},cmp5)-a;
            if(pos<=tot&&a[pos].x+a[pos].y==x[i]+y[i])ans=min(ans,(a[pos].x-x[i])*10);
        }
    tot=0;
    Rep(i,1,n)if(opt[i]==2)a[++tot]=(node){x[i],y[i]};
    sort(a+1,a+tot+1,cmp6);
    Rep(i,1,n)
        if(opt[i]==3){
            int pos=lower_bound(a+1,a+tot+1,(node){x[i],y[i]},cmp6)-a;
            if(pos<=tot&&a[pos].x+a[pos].y==x[i]+y[i])ans=min(ans,(x[i]-a[pos].x)*10);
        }
    if(ans<1e9)printf("%d\n",ans);
    else puts("SAFE");
    return 0;
}

Measured memory_bytes: 7532
#include<atcoder/all>
using namespace atcoder;

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int H, W; scanf("%d%d", &H, &W);
    
    mf_graph<int> G(H * W + 2);
    char A[100][100]; rep(y, H) rep(x, W) scanf(" %c", &A[x][y]);
    int I[100][100];
    int rI[10000][2];
    rep(y, H) rep(x, W) {
        int i = y * W + x;
        I[x][y] = i;
        rI[i][0] = x; rI[i][1] = y;
    }
    int s = H * W;
    int t = s + 1;

    rep(x, W) rep(y, H) {
        if (A[x][y] == '#') continue;
        if ((x + y) & 1) {
            G.add_edge(s, I[x][y], 1);
            if (x != 0) if (A[x - 1][y] != '#') G.add_edge(I[x][y], I[x - 1][y], 1);
            if (y != 0) if (A[x][y - 1] != '#') G.add_edge(I[x][y], I[x][y - 1], 1);
            if (x != W - 1) if (A[x + 1][y] != '#') G.add_edge(I[x][y], I[x + 1][y], 1);
            if (y != H - 1) if (A[x][y + 1] != '#') G.add_edge(I[x][y], I[x][y + 1], 1);
        }
        else {
            G.add_edge(I[x][y], t, 1);
        }
    }

    int ans = G.flow(s, t);
    printf("%d\n", ans);

    char ansG[100][100]; rep(x, W) rep(y, H) ansG[x][y] = A[x][y];
    auto E = G.edges();
    for (auto e : E) {
        if (e.flow == 0) continue;
        if (e.from == s) continue;
        if (e.to == t) continue;
        int x1 = rI[e.from][0], y1 = rI[e.from][1];
        int x2 = rI[e.to][0], y2 = rI[e.to][1];
        if (x1 == x2) {
            if (y1 > y2) swap(y1, y2);
            ansG[x1][y1] = 'v';
            ansG[x1][y2] = '^';
        }
        else {
            if (x1 > x2) swap(x1, x2);
            ansG[x1][y1] = '>';
            ansG[x2][y1] = '<';
        }
    }

    rep(y, H) {
        rep(x, W) printf("%c", ansG[x][y]);
        printf("\n");
    }

    return 0;
}

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

int main(){
  
  string s;
  cin >> s;
  
  bool good = true;
  for(int i=0; i<s.size(); i += 2){
    if(s.at(i) == 'R' || s.at(i) == 'U' ||s.at(i) == 'D'){
      continue;
    }
    else{
      good = false;
      break;
    }
  }
  
  if(good){
    for(int i=1; i<s.size(); i += 2){
      if(s.at(i) == 'L' || s.at(i) == 'U' ||s.at(i) == 'D'){
        continue;
      }
      else{
        good = false;
        break;
      }
    }
  }
  
  if(good){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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


#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define maxx 1e6+7

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


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

using namespace std;

int main(void)
{
  int ki[200000]={0};
  int N,K,cnt=0;
  int max=-1;
  
  cin >> N >> K;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
    ki[A[i]]++;
    if(max<A[i])
      max=A[i];
  }
  
  sort(ki,ki+max+1);
  for(int i=0;i<max-K+1;i++)
    cnt+=ki[i];

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define db double
#define lowbit(p) (p&(-p))
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define A first
#define B second
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
#define mo 1000000007
#define M 4005
ll ksm(ll a,ll b){
	ll res=1;
	for (;b;b>>=1){
		if (b&1)res=res*a%mo;
		a=a*a%mo;
	}
	return res;
}
int n,m;
ll val,sum,len[M];
int top[M],cnt[M],son[M],de[M],L[M],R[M],tot,fa[M];
struct edg{
	int x,y;
	ll l;
	void init(){
		read(x); read(y); read(l);
	}
}edge[M];
bool cmp(edg a,edg b){
	return a.l<b.l;
}
int get(int x){
	if (fa[x]==x)return x;
	return fa[x]=get(fa[x]);
}
ll chk(edg e){
	ll res=0;
	int i,x,y;
	for (i=1;i<=n;i++)fa[i]=i;
	x=get(e.x); y=get(e.y);
	if (x!=y){
		fa[x]=y;
		res+=e.l;
	}
	for (i=1;i<=m;i++){
		x=get(edge[i].x); y=get(edge[i].y);
		if (x!=y){
			fa[x]=y;
			res+=edge[i].l;
		}
	}
	for (i=1;i<=n;i++)if (get(i)!=get(1))return val+1;
	return res;
}
struct P1{
	void solve(){
		int i,tot=0;
		ll res;
		for (i=1;i<=m;i++){
			if (chk(edge[i])==val){
				tot++;
			}
		}		
		res=ksm(2,m-tot)%mo*(ksm(2,tot)-2)%mo;
		res=(res+mo)%mo;
		printf("%lld\n",res);
	}
}p1;
struct P2{
	void solve(){
		int i,tot1=0,tot2=0;
		ll res,tmp;
		for (i=1;i<=m;i++){
			tmp=chk(edge[i]);
			if (tmp==val){
				tot2++;
			}
			else if (tmp>val){
				tot1++;
			}
		}
		res=2ll*ksm(2,tot1)%mo*(ksm(2,tot2)-1)%mo;
		res=(res+mo)%mo;
		printf("%lld\n",res);
	}
}p2;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	freopen("1.in","r",stdin);
	read(n); read(m);
	read(val);
//	printf("val=%lld\n",val);
	int i;
	for (i=1;i<=m;i++){
		edge[i].init();
	}
	sort(edge+1,edge+m+1,cmp);
	sum=chk(edge[1]);
	if (sum>val){
		printf("0\n");
		return 0;
	}
	else if (sum==val){
		p1.solve();
		return 0;
	}
	else {
		p2.solve();
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int i = 0;
                int j = 0;
		int flg = 0;
		while(0<a){
			int b = sc.nextInt();
                        if(b == i && flg == 0){
				j++;
				flg = 1;
			}else{
				flg = 0;
			}
                        i = b;
			a = a-1;	
		}
		// 出力

		System.out.println(j);
	}
}

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

int p[200100];
int main() {
  int n;
  cin >> n;
  repi(n) cin >> p[i];
  int res = 0, m = INT_MAX;
  repi(n) {
    if (p[i] <= m) {
      m = p[i];
      ++res;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 4408
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
A=get_i.sort{|x,y| y<=>x}
if A.include?(0)
    puts 0
    exit
end
x=1
A.each do|a|
    if x*a>10**18
        puts "-1"
        exit
    end
    x*=a
end
puts x

Measured memory_bytes: 25016
#include <stdio.h> 
#include<string.h>  

const int maxn=55;  
char mp[maxn][maxn];  
int f[maxn][maxn];  
int main(){  
    int h,w;  
    scanf("%d%d",&h,&w);  
    memset(f,0,sizeof(f));  
    for(int i=0;i<h;i++){  
        scanf("%s",mp[i]);  
    }  
    for(int i=0;i<h;i++){  
        for(int j=0;j<w;j++){  
            if(mp[i][j]=='#'){  
                if(i-1>=0){  
                    f[i-1][j]++;  
                }  
                if(j-1>=0){  
                    f[i][j-1]++;  
                }  
                if(i+1<h){  
                    f[i+1][j]++;  
                }  
                if(j+1<w){  
                    f[i][j+1]++;  
                }  
                if(i-1>=0&&j-1>=0){  
                    f[i-1][j-1]++;  
                }  
                if(i+1<h&&j-1>=0){  
                    f[i+1][j-1]++;  
                }  
                if(i-1>=0&&j+1<w){  
                    f[i-1][j+1]++;  
                }  
                if(i+1<h&&j+1<w){  
                    f[i+1][j+1]++;  
                }  
            }  
        }  
    }  
    for(int i=0;i<h;i++){  
        for(int j=0;j<w;j++){  
            if(mp[i][j]=='#') printf("#");  
            else printf("%d",f[i][j]);  
        }printf("\n");  
    }  
    return 0;  
}  

Measured memory_bytes: 128
fun main(args: Array<String>) {
    var D = readLine()!!.toInt()
    var c = readLine()!!.split(" ").map{it.toInt()}

    val s = mutableListOf<List<Int>>()
    for(i in 0 until D) {
        s.add(readLine()!!.split(" ").map{it.toInt()})
    }

//    var t = mutableListOf<Int>()
//    for(i in 0 until D) {
//        t.add(readLine()!!.toInt())
//    }
    var last = Array(366){Array(26){0}}
    var point = Array(26){0}
    var t = Array(365){0}
    var P = 0

    for(i in 0 until 26) {
        point[i] = s[0][i]
        for(j in 0 until 26) {
            if(i == j) continue
            point[i] -= c[i]
        }
        if(point[t[0]] < point[i]) t[0] = i
    }
    P += point[t[0]]
    for(i in 0 until 26) {
        if(i != t[0]) last[1][i]++
    }
    for(i in 1 until D) {
        for(j in 0 until 26) {
            point[j] = s[i][j]
            for(k in 0 until 26) {
                if(j == k) continue
                point[j] -= c[j] * (i + 1 - last[i][j])
            }
            if(point[t[i]] < point[j]) t[i] = j
        }
        last[i + 1][t[i]] = 0
        for(j in 0 until 26) {
            if(j != t[i]) last[i + 1][j] = last[i][j] + 1
        }
        P += point[t[i]]
//        println(point[t[i]])
    }

//    for(i in 0 until D) {
//        for (j in 0 until 26) {
//            print("${last[i][j]} ")
//        }
//        println()
//    }
    for(i in 0 until D) {
        println(t[i] + 1)
    }
//    println(P)
}

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

using namespace std;
const long long INF = 1LL <<60;  
void func(long long x){
  if(x==0){
    cout<<"a";
  }
  else if(x==1){
    cout<<"b";
  }
  else if(x==2){
    cout<<"c";
  }
  else if(x==3){
    cout<<"d";
  }
  else if(x==4){
    cout<<"e";
  }
  else if(x==5){
    cout<<"f";
  }
  else if(x==6){
    cout<<"g";
  }
  else if(x==7){
    cout<<"h";
  }
  else if(x==8){
    cout<<"i";
  }
  else if(x==9){
    cout<<"j";
  }
  else if(x==10){
    cout<<"k";
  }
  else if(x==11){
    cout<<"l";
  }
  else if(x==12){
    cout<<"m";
  }
  else if(x==13){
    cout<<"n";
  }
  else if(x==14){
    cout<<"o";
  }
  else if(x==15){
    cout<<"p";
  }
  else if(x==16){
    cout<<"q";
  }
  else if(x==17){
    cout<<"r";
  }
  else if(x==18){
    cout<<"s";
  }
  else if(x==19){
    cout<<"t";
  }
  else if(x==20){
    cout<<"u";
  }
  else if(x==21){
    cout<<"v";
  }
  else if(x==22){
    cout<<"w";
  }
  else if(x==23){
    cout<<"x";
  }
  else if(x==24){
    cout<<"y";
  }
  else{
    cout<<"z";
  }
}

int main(void){
  long long  i,j;
  long long tmp=0;
  long long res;
  long k;
  cin>>k;
  long long base[13];
  long long order[13];
  
  base[0]=1;
  order[0]=0;
  
  for(i=1;i<13;i++){
    base[i]=pow(26,i);
    order[i]=order[i-1]+base[i];
    if(k<order[i]){
      break;  
    }
    else if(k==order[i]){
      for(;i>0;i--){
        cout<<"z";
      }
      cout<<endl;
      return 0;
    }
  }
  
  tmp=k-order[i-1]-1;
  
  for(i=i-1;i>=0;i--){
    res=tmp/base[i];
    if(i==0){
      func(res);
    }
    else{
      func(res);
    }
    tmp=tmp%base[i];
  }   

  cout<<endl;
  return 0;
}

Measured memory_bytes: 3956
n,c= map(int,input().split())
xlist=[]
for i in range(n):
    x,v= map(int,input().split())
    xlist.append((x,v))
fclock=[[0,0] for _ in range(n)]
ftemp,fval=[0]*n,[0]*n
for i in range(n):
    if i==0:
        fval[0]=xlist[i][1]
        if fval[i]-xlist[i][0]<0:fclock[i]=[-1,0]
        else:fclock[i]=[0,fval[0]-xlist[i][0]]
    else:
        fval[i]=fval[i-1]+xlist[i][1]
        if fclock[i-1][1]<fval[i]-xlist[i][0]:
            fclock[i]=[i,fval[i]-xlist[i][0]]
        else:fclock[i]=fclock[i-1]
fret=[xlist[i][0] for i in range(n)]
rxlist=[]
for i in range(n-1,-1,-1):rxlist.append([c-xlist[i][0],xlist[i][1]])
rclock=[[0,0] for _ in range(n)]
rtemp,rval=[0]*n,[0]*n
for i in range(n):
    if i==0:
        rval[0]=rxlist[i][1]
        if rval[i]-rxlist[i][0]<0:rclock[i]=[-1,0]
        else:rclock[i]=[0,rval[0]-rxlist[i][0]]
    else:
        rval[i]=rval[i-1]+rxlist[i][1]
        if rclock[i-1][1]<rval[i]-rxlist[i][0]:rclock[i]=[i,rval[i]-rxlist[i][0]]
        else:rclock[i]=rclock[i-1]

rret=[rxlist[i][0] for i in range(n)]
gmax=max(rclock[n-1][1],fclock[n-1][1])
for i in range(n-1):
    tempg=fclock[i][1]+rclock[n-2-i][1]
    if fclock[i][0]<0 or rclock[n-2-i][0]<0:pass
    else:tempg-=min(fret[fclock[i][0]],rret[rclock[n-2-i][0]])
    gmax=max(gmax,tempg)
print(gmax)

Measured memory_bytes: 78512
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

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

#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); puts("");}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return v;}
void err(vector<string>::iterator it) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) {cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}

#if (( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(),(x).end()
#define tr(c, it)   for(auto it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))

const int INF = 0x3f3f3f3f;

int n;
char s[200010];
VI a, z;

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif

    int cas = 1;
    //scanf("%d", &T);
    while(~scanf("%s",s+1))
    {
        int p1 = 0, p2 = 0;
        int len = strlen(s+1);

        for(int i=1; i<=len; i++)
        {
            if(s[i] == 'A')
            {
                p1 = i;
                break;
            }
        }

        for(int i=len; i>=1; i--)
        {
            if(s[i] == 'Z')
            {
                p2 = i;
                break;
            }
        }
        printf("%d\n", p2 - p1 + 1);



    }

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i,n) A[i] = i;
  vector<P> C(n);
  rep(i,n) {
    int x, y;
    cin >> x >> y;
    C[i] = P(x,y);
  }
  double ans = 0;
  int count = 0;
  do {
    count++;
    rep(i,n-1) {
      int j = A[i], k = A[i+1];
      ans += sqrt((C[j].first - C[k].first)*(C[j].first - C[k].first)
      + (C[j].second - C[k].second)*(C[j].second - C[k].second));
    }
  } while (next_permutation(A.begin(), A.end()));
  ans /= double(count);
  cout << fixed;
  cout << setprecision(9) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<climits>
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() 
{ 
    ll a,b,c,d,maxnum;
    maxnum=LLONG_MIN;
    cin>>a>>b>>c>>d;
    maxnum=max(a*c,maxnum);
    maxnum=max(a*d,maxnum);
    maxnum=max(b*c,maxnum);
    maxnum=max(b*d,maxnum);
    cout<<maxnum;

} 

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ft first
#define sd second
#define pd push_back
#define mk make_pair
#define ll long long
#define N 140005
using namespace std;
int n;
vector<int>v[N],q[N];
ll now;
vector<pair<ll,ll> >s[N];
map<ll,int>mp;
bool fl;
void dfs(int x)
{
    if(!v[x].size())
    {
        s[x].push_back(mk(0,0));
        return ;
    }
    dfs(v[x][0]);dfs(v[x][1]);
    if(!s[v[x][0]].size()||!s[v[x][1]].size())return ;

    for(int t=0;t<=1;t++)
    {
		int ls=q[x][0],rs=q[x][1];
    	int l=v[x][0],r=v[x][1];
		int p=-1;
		for(int i=0;i<s[l].size();i++)
	    {
	    	bool flag=0;
	        while(p+1<s[r].size())
	        {
	            if(-s[l][i].sd+s[r][p+1].ft+ls+rs<=now)p++,flag=1;
	            else break;
	        }
	        //if(x==1)cout<<p<<endl;
	        if(flag)
	        {

	        	s[x].pd(mk(s[l][i].ft+ls,s[r][p].sd-rs));
			}
	    }
		swap(v[x][0],v[x][1]);swap(q[x][0],q[x][1]);
	}
    sort(s[x].begin(),s[x].end());
	if(!s[x].size())fl=1;
}
bool pan(ll x)
{
	for(int i=1;i<=n;i++)s[i].clear();
    now=x;
    fl=0;
	dfs(1);
    return (fl^1);
}
int main()
{
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        int t1,t2;scanf("%d%d",&t1,&t2);
        v[t1].push_back(i);q[t1].push_back(t2);
    }
	ll l=0,r=1e10;
    while(l<r)
    {
        ll mid=(l+r)>>1;
        if(pan(mid))r=mid;
        else l=mid+1;
    }
    printf("%lld\n",l);
    return 0;
}


Measured memory_bytes: 36600
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない




int main() {

	int a, b,k;
	cin >> a >> b >> k;
	if (a > b)swap(a, b);

	for (int i = a; i > 0; i--) {
		if (a%i == 0 && b%i == 0) {
			k--;
		}
		if (k == 0) {
			cout << i << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
using namespace std;
ll h;ll w;
double dp[3000][3000];
int main()
{
  ll n;
  cin>>n;
  double a[40000];
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
    dp[0][0]=1.0;

  for(ll i=1;i<=n;i++){
    for(ll j=0;j<=i;j++){
            if(j==0){
                dp[i][j]=dp[i-1][j]*(1-a[i]);
            }
        dp[i][j]=dp[i-1][j]*(1-a[i])+dp[i-1][j-1]*a[i];
    }
  }
  double ans=0;
  for(ll i=(n+1)/2;i<=n;i++)
  {
      ans+=dp[n][i];
  }
  cout<<fixed<<setprecision(10)<<ans;
}


Measured memory_bytes: 68864
#include<stdio.h>
int main(){
  int i,cnt,num1,num2,num3,temp;
  // num1=0;                                                                                                                                                                         
  //num2=0;                                                                                                                                                                          
  //num3=0;                                                                                                                                                                          
  scanf("%d",&cnt);
  for(i=0; i<cnt; i++){
    scanf("%d %d %d",&num1,&num2,&num3);
    if(((num1*num1)==((num2*num2)+(num3*num3))) || ((num2*num2)==((num1*num1)+(num3*num3))) || ((num3*num3)==((num1*num1)+(num2*num2)))){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
  }
  return 0;
}

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


int main() {
  int N;
  cin >> N;
  long long l[N+1];
  l[0]=2;
  l[1]=1;
  int i;
  for(i=2;i<=N;i++) {
	l[i]=l[i-1]+l[i-2];
  }
  cout <<l[N]<<endl;
  return 0;
}    

Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(__null);
    
    int n; cin >> n;
    int cnt = 0;
    while (n > 0){
        if (n % 10 == 2) {
            ++cnt;
        }
        n /= 10;
    }
    print(cnt);    
    return 0;
}

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

int top,s[100];

void push(int data){
  s[++top] = data;
}

int pop(){
  top--;
  return s[top+1];
}

int main(){
  int i,j;
  top = 0;
  char mozi[100];
  while( scanf("%s",mozi)!= EOF){
    if(mozi[0] == '+'){
      i = pop();
      j = pop();
      push(i + j);
    }else if(mozi[0] == '-'){
      j = pop();
      i = pop();
      push(i-j);
    }else if(mozi[0] == '*'){
      i = pop();
      j = pop();
      push(i*j);
    }else{
      push(atoi(mozi));
    }
  }

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

  return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );

//#define pout cerr;

int main(void){

  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);

  vector<ll> ms(n);

  rep(i,n) cin>>a[i];

  ll sum=0;
  rep(i,n) sum+=a[i];

  vector<ll> ds;
  for(ll i=1;i<=sqrt(sum);i++){
    if( sum%i==0 ){
      ds.push_back(i);
      ds.push_back(sum/i);
    }
  }
  sort( begin(ds),end(ds),greater<ll>() );
  for(auto x:ds){
    //cerr << x << endl;
    ll sum1=0,sum2=0;
    rep(i,n){
      ms[i]=a[i]%x;
      sum2+=x-ms[i];
    }
    sort( begin(ms),end(ms) );
    /*
    for(auto y:ms){
      cerr << y << " ";
    }
    cerr << endl;
    */
    if(sum1==sum2 && sum1<=k){
      cout << x << endl;
      return 0;
    }
    rep(i,n){
      sum1+=ms[i];
      sum2-=(x-ms[i]);
      //cerr << sum1 << ","<< sum2 << endl;
      if(sum1==sum2 && sum1<=k ){
        cout << x << endl;
        return 0;
      }
    }
    
  }

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 1e5 + 10;
ll a[MAXN];
ll n;
ll ans[MAXN];

void solve(){ 
    cin>>n;

    FOR(i,1,n) cin>>a[i];

    ll temp = 0;

    FOR(i,1,n-1){
        if(i%2 == 1) temp += 2*a[i];
        else temp -= 2*a[i];
    }

    ll temp_2 = temp + 2*a[n];
    ans[1] = temp_2/2;

    FOR(i,1,n-1) ans[i+1] = 2*a[i] - ans[i];

    FOR(i,1,n) cout<<ans[i]<<" ";
}

signed main(){

   FastRead;    


    ll t;
    t = 1; 
   // cin>>t;
    FOR(i,1,t){
        // cout<<"Case "<<i<<":\n";
        solve();
    }
}


Measured memory_bytes: 2944
x,k,d = map(int, input().split())
x = abs(x)
if x > k*d:
  print(x-k*d)
else:
  a = x//d
  if (k-a)%2 == 0:
    print(x-a*d)
  else:
    print(abs(x-(a+1)*d))

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

#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;

vector<int> dx = {0,1,0,-1};
vector<int> dy = {1,0,-1,0};
int H, W;
vector<string> S;

int toId(int x, int y){
    return x*W+y;
}

struct UnionFind {
    vector<int> parent; //parent[i]はiの親の番号
    vector<int> rank; // rank[i]は木の深さ
    vector<int> bsize; // bsize[i]はグループに含まれている黒数
    vector<int> wsize; // wsize[i]はグループに含まれている白数
    vector<int> loop; // グループに含まれているloopの数

    UnionFind(int n) {
        //コンストラクタは全て自分が根
        parent = vector<int>(n);
        rank = vector<int>(n);
        bsize = vector<int>(n);
        wsize = vector<int>(n);
        loop = vector<int>(n);
        for (int i=0;i<n;i++) {
            parent[i] = i;
            rank[i] = 0;
            if (S[i/W][i%W] == '#') bsize[i] = 1, wsize[i] = 0;
            else bsize[i] = 0, wsize[i] = 1;
        }
    }

    int root(int x) { //根を再帰で辿りつつ、探索したものを繋ぎなおし
    if (parent[x] == x) return x;
    return parent[x] = root(parent[x]);
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) {
            loop[rx]++;
            return;
        }
        if (rank[rx] < rank[ry]) {
            parent[rx] = ry;
            bsize[ry] += bsize[rx];
            wsize[ry] += wsize[rx];
            loop[ry] += loop[rx];
        }
        else {
            parent[ry] = rx;
            bsize[rx] += bsize[ry];
            wsize[rx] += wsize[ry];
            loop[rx] += loop[ry];
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int getBSize(int x){
        return bsize[root(x)];
    }

    int getWSize(int x){
        return wsize[root(x)];
    }

    int getLoopNum(int x){
        return loop[root(x)];
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> H >> W;
    S = vector<string>(H);
    for (int i=0;i<H;i++) cin >> S[i];
    UnionFind uf = UnionFind(H*W);
    for (int i=0;i<H;i++){
        for (int j=0;j<W;j++){
            for (int d=0;d<4;d++){
                int ni = i + dx[d];
                int nj = j + dy[d];
                if (ni < 0 || ni >= H) continue;
                if (nj < 0 || nj >= W) continue;
                int u = toId(i,j);
                int v = toId(ni,nj);
                if (S[i][j] != S[ni][nj]){
                    uf.unite(u,v);
                }
            }
        }
    }
    int ans = 0;
    for (int i=0;i<H*W;i++){
        if (uf.root(i) == i) {
            int b = uf.getBSize(i);
            int w = uf.getWSize(i);
            ans += b*w;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 9764
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

char f(char u, char v) {
    if (u == 'm' && v == 'm')
        return 'L';
    else if (u == 'm')
        return 'D';
    else if (v == 'm')
        return 'U';
    else
        return 'R';
}

int main()
{
    ll N;
    cin >> N;
    vll X(N), Y(N);
    rep(i, N) {
        cin >> X[i] >> Y[i];
    }

    ll parity = (X[0] + Y[0] + (ll)1e10) % 2;
    rep(i, N) {
        if ((X[i] + Y[i] + (ll)1e10) % 2 != parity) {
            cout << -1 << endl;
            return 0;
        }
    }

    bool even = (parity == 0);
    rep(i, N) {
        X[i] -= even;
    }

    ll keta = 32;
    ll m = keta + even;
    vll d(keta);
    ll bin = 1;
    rep(i, keta) {
        d[i] = bin;
        bin *= 2;
    }
    reverse(all(d));
    if (even) d.push_back(1);

    cout << m << endl;
    for (auto elem : d) cout << elem << " "; cout << endl;
    
    rep(i, N) {
        ll U = X[i] + Y[i];
        ll V = X[i] - Y[i];

        ll u = 0, v = 0;
        rep(j, keta) {
            ll num = u - d[j], nup = u + d[j];
            char uc;
            if (abs(num - U) < abs(nup - U)) {
                uc = 'm';
                u = num;
            } else {
                uc = 'p';
                u = nup;
            }

            ll nvm = v - d[j], nvp = v + d[j];
            char vc;
            if (abs(nvm - V) < abs(nvp - V)) {
                vc = 'm';
                v = nvm;
            } else {
                vc = 'p';
                v = nvp;
            }

            cout << f(uc, vc);
        }
        if (even) cout << "R";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

int D[100001];
int a[100001];

void sagasu(int A, int B) {
	if (D[A] == 0) {
		D[A] = B;
		sagasu(a[A], B + 1);
	}
}


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


	int N;
	cin >> N;
	rep1(i, N) cin >> a[i];

	sagasu(1, 1);

	co(D[2] - 1);

	Would you please return 0;
}

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

using namespace std;
using ll = long long;

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

const int mod = 1e9 + 7;

ll modpow(ll k, ll n) {
  ll res = 1;

  while (n > 0) {
    if (n & 1) res = res * k % mod;
    k = k * k % mod;
    n /= 2;
  }

  return res;
}

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i, n) cin >> a[i];

  ll c[n];
  c[0] = 0;
  rep(i, n - 1) {
    if (i + 1 < k - 1)
      c[i + 1] = 0;
    else if (i + 1 == k - 1)
      c[i + 1] = 1;
    else
      c[i + 1] = (c[i] * (i + 1) % mod) * modpow(i - k + 2, mod - 2) % mod;
  }

  // rep(i, n) { cout << c[i] << endl; }

  sort(a, a + n);
  ll ans = 0;
  rep(i, n) {
    ans -= a[i] * c[n - i - 1] % mod;
    ans = (ans + mod) % mod;
    ans += a[i] * c[i] % mod;
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


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

length = 0

if b <= c or d <= a:
    length = 0
elif b <= d and c <= d and a <= c:
    length = b - c
elif d <= b and a <= d and c <= a:
    length = d -a
elif b <= d and c <= a:
    length = b - a
elif d <= b and a <= c:
    length = d - c

print (length)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;


int n,s;

int count;

void dfs(int i,int j,int sum) {

  //cout << i << " " << j << " " << sum << endl;

  if(j==0 && sum==0) {

    count++;

    return;

  }

  if(i==10 || j==0) return;

  dfs(i+1,j-1,sum-i);

  dfs(i+1,j,sum);

  return;

}
  

int main() {

  while(cin >> n >> s) {

    if(n==0 && s==0) break;

    count=0;

    dfs(0,n,s);

    cout << count << endl;

  }

  return 0;

}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//n????°?????????´??????DP[i][j]=i??\?????????????????§j?????????
//n?????§????????´???????????§????????¨?????¢????????????????????????????????§?????????????????°m?????????????£????????????????????????????????????????C[i]+(i-1)P?????§????????????????????§???C[i]+(i-1)P????°????????????????????????????
//??????????????????????????????????§£??????

int main(void){
	ll N,P,Q;
	scanf("%lld%lld%lld",&N,&P,&Q);
	ll C[500002],D[500002];
	ll C_sum=0;
	rep(i,N){
		scanf("%lld",&C[i]);
		C_sum+=C[i];
		C[i]+=i*P;
	}
	sort(C,C+N);//??????????????????????????¨???????????¨??????????????????
	D[0]=0;//???????´???????????±?????????????????????¨TLE??????
	rep(i,N){
		D[i+1]=D[i]+C[i];
	}
	ll sum;
	ll ans=LLONG_MIN;
	rep(m,N+1){//m?????????
		sum=C_sum;//?????\?£?????????????
		sum-=D[m];//?£??????????????????????????????¨??????????????????
		sum+=(m-1+Q)*P*m;//???????????????????£???£???
		if(ans<sum)ans=sum;
	}
	cout<<ans<<endl;
	return 0;
}

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

vector<int> indx[15];

char s[30005];

int main(){
    int N;
    scanf("%d", &N);

    scanf(" %s", s);

    for(int i = 0; i < N; i ++){
        indx[s[i]-'0'].push_back(i);
    }

    int ans = 0;
    for(int i = 0; i < 10; i ++){
        if(indx[i].size() == 0){continue;}
        for(int j = 0; j < 10; j ++){
            if(indx[j].size() == 0){continue;}
            for(int k = 0; k < 10; k ++){
                if(indx[k].size() == 0){continue;}
                int temp = indx[i][0];
                temp = lower_bound(indx[j].begin(), indx[j].end(), temp+1)-indx[j].begin();
                if(temp == (int)indx[j].size()){
                    continue;
                }else{
                    temp = indx[j][temp];
                }
                temp = lower_bound(indx[k].begin(), indx[k].end(), temp+1)-indx[k].begin();
                ans += (temp != (int)indx[k].size());
            }
        }
    }

    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    string s;
    int k;
    cin>>s>>k;
	vector<string> v;
	for (int i=0;i<s.size();i++)
    {
		for(int j=1;j<=5;j++)
        {
			v.push_back(s.substr(i,j));
		}
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	k--;
	cout<<v[k]<<endl;
	//system ("pause");
	return 0;
}

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

int main() {
	string a, b;
	int N, ans = 0;
	cin >> a >> N;
	for (int i = 0; i < N; ++i) {
		cin >> b;
		if ((b + b).find(a) != string::npos) ++ans;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
 
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
  int64_t N,P;
  cin >> N >>P;
  
  map<int64_t, int> factrial;
  
  factrial = prime_factor(P);

  int64_t out=1;
  for(auto p : factrial ){
    if(p.second >= N){
        out*=pow(p.first,p.second/N);
    }
  }

  cout <<out<< endl;
}

Measured memory_bytes: 3840