akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    static int tc=1;
    static String[] s;
 
    public static long[] ila(String[] s){
        long[] array=new long[s.length];
        for(int i=0;i<array.length;i++)
            array[i]=Long.parseLong(s[i]);
        return array;
    }
    public static void main (String[] args) throws java.lang.Exception
    {
        //tc=Integer.parseInt(br.readLine());
        t:
        while(tc-->0){
		  int k=Integer.parseInt(br.readLine());
		  String s=br.readLine();
		  StringBuilder sb=new StringBuilder("");
		  for(int i=0;i<s.length();i++){
		  	char x=s.charAt(i);
		  	x=(char)(x+k);
		  	if(x>90)
		  		x=(char)(64+(x%90));
		  	//System.out.println((int)x);
		  	sb.append(x);
		  }
		  System.out.println(sb);
        }
    }
}

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

int main(){
  ll a[7];
  rep(i,7) cin >> a[i];
  ll ans = a[1];
  bool can = (a[0] % 2 && a[3] % 2 && !(a[4] % 2) && a[4] > 0) || (a[0] % 2 && !(a[3] % 2) && a[4] % 2 && a[3] > 0) || (!(a[0] % 2) && a[3] % 2 && a[4] % 2 && a[0] > 0) || (a[0] % 2 && a[3] % 2 && a[4] % 2);
  if(can) {
    ans += 3;
    a[0]--; a[3]--; a[4]--;
  }
  ans += a[0]/2*2 + a[3]/2*2 + a[4]/2*2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<int,int> pii;
int main(){
	vector<pii> data;
	int i1,i2;
	for(scanf("%d",&i1);~scanf("%d%d",&i1,&i2);)data.emplace_back(i1,i2);
	sort(data.begin(),data.end(),[](const pii &a,const pii &b){return a.second<b.second;});
	int f=0,r=0;
	for(int i=0;i<data.size();i++){
		if(data[i].first>f){ //終端は閉区間。開区間なら>=になる。
			r++;
			f=data[i].second;
		}
	}
	printf("%d\n",r);
}


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

static const int MAX = 100;
static const ll INFTY = (1LL<<32);

int n;
ll d[MAX][MAX];

// A_k :: {1, 2,..,k}のみを経由する頂点i->jの最短コスト
void floyd() {
  for (int k = 0; k < n; k++) { //すべての頂点に対して調べる
    for (int i = 0; i < n; i++) {
      if (d[i][k] == INFTY) continue;
      for (int j = 0; j < n; j++) {
        if (d[k][j] == INFTY) continue;
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  int e;
  cin >> n >> e;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = (i == j ? 0 : INFTY);
    }
  }

  for (int i = 0; i < e; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    d[a][b] = c;
  }

  floyd();

  bool negative = false;
  for (int i = 0; i < n; i++) d[i][i] < 0 ? negative = true : 0;
  //もしi -> i の閉路の合計コストが負になるなら、無限にコストを下げられるのでダメ

  if (negative) {
    cout << "NEGATIVE CYCLE" << endl;
  }
  else {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (j > 0) cout << " ";
        if (d[i][j] == INFTY) cout << "INF";
        else cout << d[i][j];
      }
      cout << endl;
    }
  }

  return 0;
}



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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

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

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

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

	int N=in(),M=in();
	ll S=0;
	priority_queue<ll,vector<ll>,greater<ll>> Q;
	REP(i,N){
		ll V=in();
		S  += V;
		Q.push(V);
	}
	vector<pair<ll,ll>> P(M);
	REP(i,M){
		P[i].first=in();
		P[i].second=in();
	}
	sort(ALL(P),PAIRCOMP(second,>));

	REP(i,M){
		REP(j,P[i].first){
			auto V=Q.top();
			if(V<P[i].second){
				Q.pop();
				S += P[i].second-V;
				Q.push(P[i].second);
			}
			else{
				out(S);
				return 0;
			}
		}
	}

	out(S);
	return 0;
}


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

using namespace std;

int main(){
    double x, y;
    int n, m, r;
    while(scanf("%d,%d", &n, &m), n+m){
        x += n*sin(r*M_PI/180.0);
        y += n*cos(r*M_PI/180.0);
        r += m;
    }
    cout << (int)x << "\n" << (int)y << endl;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> E(N+1,0), W(N+1,0);
  for(int i = 0; i < N; ++i) E[i+1] += E[i] + (S[i] == 'E');
  for(int i = N-1; i >= 0; --i) W[i] += W[i+1] + (S[i] == 'W');
  //for(int i = 0; i <= N; ++i) cout << E[i] << " ";cout << endl;
  //for(int i = 0; i <= N; ++i) cout << W[i] << " ";cout << endl;
  int ans = N;
  for(int i = 0; i < N; ++i){
    ans = min(ans, N - 1 - E[i] - W[i+1]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 
vector<ll>ad[200005];
bool vis[200005];
ll glo;
void dfs(ll idx)
{
	vis[idx]=true;
	glo++;
	for(auto it:ad[idx])
		if(!vis[it])dfs(it);
}
int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> n >> m;
	for(i=1;i<=m;i++)
	{
		cin >> x >> y;
		ad[x].pb(y);
		ad[y].pb(x);
	}
	ll ans=0;
	for(i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			glo=0;
			dfs(i);
			ans=max(ans,glo);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 21020
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < (int) n; i++)
#define forin(i, a, b) for(int i = a; i < (int) b; i++) 
#define rofin(i, a, b) for(int i = a; i > b; i--)
#define v vector
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define debug(i) cout << #i << ": " << i << endl
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

int main() {
    crap;
    string s;
    int n;
    cin >> n >> s;
    int R = 0, G = 0, B = 0;
    for(char c : s) {
        if(c=='R') R++;
        else if(c=='G') G++;
        else if(c=='B') B++;
    }
    ll sum = 1ll * R * G * B;
    
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            if(s[i]==s[j]) continue;
            int k = 2 * j - i;
            if(k >= n) continue;
            if(s[k]!=s[i] && s[k]!=s[j]) sum--;
        }
    }
    cout << sum << endl;

}

Measured memory_bytes: 3656
import java.util.*;
class Main {
 public static void main(String[] args) {
   int x, y;
   Scanner scan=new Scanner(System.in);
   while(true){
    x = scan.nextInt();
    y = scan.nextInt();
    if ( x == 0 && y == 0 ) break; 
    if ( x < y ){
        System.out.printf("%d %d\n",x,y);
    } 
    else {
        System.out.printf("%d %d\n",y,x);
    }
   }
 }
 }


Measured memory_bytes: 39136
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;
    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] P = cin.ArrayInt(N);
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = i * N + 1;
            B[i] = (N - 1 - i) * N + 1;
        }
        for (int i = 0; i < N; i++)
        {
            A[P[i] - 1] += i;
            B[P[i] - 1] += i;
        }
        Console.WriteLine(string.Join(" ", A));
        Console.WriteLine(string.Join(" ", B));

    }
    
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 16992
using System;

class Task2
{

    public static void Main(string[] args)
    {
        string[] clue = Console.ReadLine().Split(' ');
        int k = int.Parse(clue[0]);
        int x = int.Parse(clue[1]);
        
        for (int i = x - k + 1; i < x + k; i++)
        {
            Console.Write(i);
            if (i != x + k - 1)
             {
             Console.Write(" ");
             }
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

//int ()



int main()
{
  int a ,b, c, d, e, X, Y;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
  int  A[200003]={};
//  long long  A[100003]={};
//  long long  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  long long ans=1;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  int tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d", &a);
  for(i=0;i<a;i++){
    scanf("%d", &A[i]);
  }
  for(i=0;i<a;i++){
    if(i+1==A[i] && flg==0);
    else if ((i+1)!=A[i] && flg==1){
      printf("NO\n");
      return 0;
    } else {
      for(j=i+1;j<a;j++){
        if(i+1==A[j]){
          tmp=A[i];
          A[i]=A[j];
          A[j]=tmp;
        }
        flg=1;
      }
    }
  }
  
  printf("YES\n");
 
  

    
//    printf("%s %d %d\n", s[i],C[i][0],C[i][1]);
   // printf("%d\n", C[i][1]);
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
//    printf("%d ", cnt);
   

return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int w, a, b;
    cin >> w >> a >> b;
    if (a > b) swap(a,b);
    int ans = a+w <= b ? b-a-w: 0;
    cout <<ans << endl;

    return 0;
}

Measured memory_bytes: 256
n, m, k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
asum = [0]
bsum = [0]

for i in range(len(aa)):
    asum.append(asum[i]+aa[i])
for i in range(len(bb)):
    bsum.append(bsum[i]+bb[i])

j = len(bsum)-1
ans = 0
for i in range(len(asum)):
    while j >= 0:
        if k >= asum[i] + bsum[j]:
            ans = max(ans, i+j)
            break
        else:
            j -= 1


print(ans)


Measured memory_bytes: 47368
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;

long long modpow(long long x,long long n,long long mod)
{
  if(n==0)return 1;
  long long res=modpow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,mod=1e9+7;
  bool f=1;
  cin>>n;
  vector<int>cnt(n,0);
  rep(i,n)
  {
    int a;
    cin>>a;
    cnt[a]++;
  }
  for(int i=n-1;i>=1;i-=2)
  {
    if(cnt[i]!=2){f=0;}
  }
  if(cnt[0]!=1&&(n&1)) f=0;
  if(f)cout<<modpow(2,n/2,mod)<<endl;
  else cout<<0<<endl;

  return 0;

}


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

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    int total = 0;
    rep(i, n) {
        cin >> w[i];
        total += w[i];
    }
    int s1 = 0, s2 = 0;
    int ans = 10000000;
    rep(i, n) {
        s1 += w[i];
        s2 = total - s1;
        ans = min(ans, abs(s1 - s2));
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int ALP='z'-'a'+1;
int cnt[ALP];
string S,t;
int N;
int main(){
	cin>>S;
	N=(int)S.size();
	REP(i,N){
		cnt[S[i]-'a']++;
		if(S[i]!='x'){
			t.push_back(S[i]);
		}
	}
	bool ans=true;
	int m=(int)t.size();
	REP(i,m){
		if(t[i]!=t[m-1-i]){
			ans=false;
		}
	}
	if(ans){
		if(m>0){
			int c=0;
			char ch=t[m/2];
			int lf,ri;
			REP(i,N){
				if(S[i]==ch){
					c++;
					if(c==(cnt[ch-'a']+1)/2){
						lf=i;
					}
					if(c==(cnt[ch-'a'])/2+1){
						ri=i;
					}
				}
			}
			int ans2=0;
			while(lf>=0 || ri<N){
				if(lf<0){
					ans2++;
					ri++;
				}else if(ri>=N){
					ans2++;
					lf--;
				}else{
					if(S[lf]!=S[ri]){
						if(S[lf]=='x'){
							lf--;
							ans2++;
						}else{
							ri++;
							ans2++;
						}
					}else{
						lf--;
						ri++;
					}
				}
			}
			cout<<ans2<<endl;
		}else{
			cout<<0<<endl;
		}
	}else{
		cout<<-1<<endl;
	}
					
}

Measured memory_bytes: 640
#include<stdio.h>
long long int h[200005];
int l;
int comp_h(int a, int b, int c)
{
	if (c == 0)
	{
		if (h[a] < h[b])
			return 1;
		else
			return -1;
	}
	else
	{
		if (h[a] > h[b])
			return 1;
		else
			return -1;
	}
}
void swap_h(int a, int b)
{
	long long int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void f1(long long int n, int c)
{
	h[l] = n;
	int now = l;
	l++;
	while (now > 0)
	{
		if (comp_h((now - 1) / 2, now, c) > 0)
			swap_h((now - 1) / 2, now);
		now = (now - 1) / 2;
	}
	return;
}
long long int f2(int c)
{
	l--;
	swap_h(0, l);
	int now = 0;
	for (;;)
	{
		if (2 * now + 2 < l)
		{
			if (comp_h(2 * now + 1, 2 * now + 2, c) > 0)
			{
				if (comp_h(now, 2 * now + 2, c) > 0)
					swap_h(now, 2 * now + 2);
				now = 2 * now + 2;
			}
			else
			{
				if (comp_h(now, 2 * now + 1, c) > 0)
					swap_h(now, 2 * now + 1);
				now = 2 * now + 1;
			}
		}
		else if (2 * now + 1 < l)
		{
			if (comp_h(now, 2 * now + 1, c) > 0)
				swap_h(now, 2 * now + 1);
			now = 2 * now + 1;
		}
		else
			break;
	}
	return h[l];
}
int main()
{
	int x, y, a, b, c;
	scanf("%d %d %d %d %d", &x, &y, &a, &b, &c);
	int i;
	long long int p[100005], q[100005], r[100005];
	for (i = 0; i < a; i++)
		scanf("%lld", &p[i]);
	for (i = 0; i < b; i++)
		scanf("%lld", &q[i]);
	for (i = 0; i < c; i++)
		scanf("%lld", &r[i]);
	l = 0;
	for (i = 0; i < a; i++)
		f1(p[i], 0);
	for (i = 0; i < a; i++)
		p[i] = f2(0);
	l = 0;
	for (i = 0; i < b; i++)
		f1(q[i], 0);
	for (i = 0; i < b; i++)
		q[i] = f2(0);
	l = 0;
	for (i = 0; i < x; i++)
		f1(p[i], 1);
	for (i = 0; i < y; i++)
		f1(q[i], 1);
	for (i = 0; i < c; i++)
	{
		f1(r[i], 1);
		r[i] = f2(1);
	}
	long long int ans = 0;
	while (l > 0)
	{
		r[0] = f2(1);
		ans += r[0];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3968
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    while(cin >> n){
        vector<int> dp(n + 1);
        dp[0] = 1;

        rep(i, 4){
            vector<int> tmp(n + 1);
            for(int j = n; j >= 0; j--){
                rep(k, 1001){
                    if(j + k > n){
                        continue;
                    }
                    tmp[j+k] += dp[j];
                }
            }
            dp = tmp;
        }
        cout << dp[n] << endl;
    }

    return 0;
}



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

int main() {
    using namespace std;
    long N;
    long X, D;
    cin >> N >> X >> D;
    if(D < 0){
        X += D * (N - 1);
        D *= -1;
    }
    if(D == 0){
        if(X == 0)return 0 & puts("1");
        cout << N + 1 << endl;
        return 0;
    }
    if(X == 0){
        X += D;
        --N;
    }
    if(N == 0){
        return 0 & puts("1");
    }
    if(X || D){
        auto g = max(__gcd(X, D), -__gcd(X, D));
        X /= g;
        D /= g;
    }
    vector<pair<long, pair<long, long>>> p(N + 1UL);
    auto x = (X % D + D) % D;
    for(long i = 0; i <= N; ++i){
        auto t = (x * i) % D;
        auto k = (X * i - t) / D;
        assert(t < D && 0 <= t);
        assert(k * D + t == X * i);
        p[i] = {t, pair<long, long>({k + i * (i - 1) / 2, k + i * (2 * N - i - 1) / 2 + 1})};
    }
    sort(p.begin(), p.end());
    vector<pair<long, pair<long, long>>> q;
    for(const auto& i : p){
        if(q.empty())q.push_back(i);
        else if(i.first != q.back().first)q.push_back(i);
        else if(q.back().second.second >= i.second.first)q.back().second.second = max(q.back().second.second, i.second.second);
        else q.push_back(i);
    }
    long ans{0};
    for(const auto& i : q)ans += i.second.second - i.second.first;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13168
<?php
fscanf(STDIN, "%s", $str);
if ($str[0] === 'R' && $str[1] === 'R' && $str[2] === 'R') {
    echo '3';
} elseif (($str[0] === 'R' && $str[1] === 'R') || ($str[1] === 'R'&& $str[2] === 'R')) {
    echo '2';
} elseif ($str[0] === 'R' || $str[1] === 'R' || $str[2] === 'R') {
    echo '1';
} else {
    echo '0';
}

Measured memory_bytes: 16156
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
A = np.array(read().split(),np.int64)

answer = 0
for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= MOD
    answer += x
answer %= MOD
print(answer)


Measured memory_bytes: 36536
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n, m; cin >> n >> m;
    ll res = 0;
    if (2 * n <= m) {
        m -= 2 * n;
        res += n;
        n = 0;
        res += m / 4;
        cout << res << endl;
    } else {
        n -= m / 2;
        res += m / 2;
        cout << res << endl;
    }
    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

class DisjointSet{
public:
	vector<int> par;
	vector<ll> rank;

	DisjointSet(){}
	DisjointSet(int size){
		rank.resize(size, 0);
		par.resize(size, 0);
		for(int i=0; i<size; i++){
			par[i]=i;
			rank[i]=1;
		}
	}

	int find(int x){
		if(par[x]==x){
			return x;
		}else{
			par[x]=find(par[x]);
			return par[x];
		}
	}

	void unite(int x, int y){
		x=find(x), y=find(y);
		if(x==y) return;

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

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

int main(){
	ll n, m;
	cin >> n >> m;
	int a[m], b[m];
	for(int i=0; i<m; i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}

	DisjointSet ds(n);

	ll tmp=n*(n-1)/2, ans[m];
	for(int i=m-1; i>=0; i--){
		ans[i]=tmp;
		if(!ds.same(a[i], b[i])){
			tmp-=ds.rank[ds.find(a[i])]*ds.rank[ds.find(b[i])];
		}
		ds.unite(a[i], b[i]);
	}
	for(int i=0; i<m; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {
	public static void main(String args[]){

		//?????£????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		while(true){
			String moji = sc.next();

			//?????????-?????£????????????
			if(moji.equals("-")){
				break;
			}

			//??°??????????????°???????????????
			int h = sc.nextInt();

			//
			for(int i = 0; i < h; i++){
				int c = sc.nextInt();

				String left = moji.substring(0,c);
				String right = moji.substring(c);

				moji = right + left ;
			}

			System.out.println(moji);
		}
	}
}

Measured memory_bytes: 26324
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll N;
    cin >> N;
    if(!cin) return;
    map<ll, ll> oe[2] = {};
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        oe[i%2][x]++;
    } // end i
    priority_queue<pair<ll, ll>> odq, evq;
    odq.emplace(0, -1); evq.emplace(0, 0);
    for (auto &&e : oe[0]) {
        evq.emplace(e.second, e.first);
    } // end e
    for (auto &&o : oe[1]) {
        odq.emplace(o.second, o.first);
    } // end o

    ll ans = 0;
    auto ev1 = evq.top(); evq.pop();
    auto ev2 = evq.top(); evq.pop();
    auto od1 = odq.top(); odq.pop();
    auto od2 = odq.top(); odq.pop();
    ll tar = N / 2;
    if(ev1.second != od1.second){
        ans = N - ev1.first - od1.first;
    }
    else{
        ans = N - max(ev1.first + od2.first, ev2.first + od1.first);
    }
    cout << ans << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
    return 0;
}


Measured memory_bytes: 8824
#include <stdio.h>
#include <stdbool.h>

const int ERA_PRE_MEIJI = -1;
const int ERA_MEIJI = 0;
const int ERA_TAISHO = 1;
const int ERA_SHOWA = 2;
const int ERA_HEISEI = 3;

const int ERA_BEGIN_YEAR[] = {1868, 1912, 1926, 1989}; 
const int ERA_BEGIN_MONTH[] = {9, 7, 12, 1};
const int ERA_BEGIN_DATE[] = {8, 30, 25, 8};

int compare_date(int y1, int m1, int d1, int y2, int m2, int d2);
int era_of_date(int year, int month, int date);
void print_date(int era, int year, int month, int date);

int main()
{
    int year, month, day;
    while (scanf("%d%d%d", &year, &month, &day) != EOF) {
        int era = era_of_date(year, month, day);
        print_date(era, year, month, day);
    }

    return 0;
}


// y1/m1/d1 と y2/m2/d2 を比較し、前者が早ければ負、後者が早ければ正、同じなら0を返す
// "2014/7/50" のように正規化されていないものは扱わない　
int compare_date(int y1, int m1, int d1, int y2, int m2, int d2)
{
    if (y1 < y2) {
        return -1;
    } else if (y1 > y2) {
        return 1;
    }

    //以下、年が同じである場合
    if (m1 < m2) {
        return -1;
    } else if (m1 > m2) {
        return 1;
    }

    //以下、年と月が同じである場合
    if (d1 < d2) {
        return -1;
    } else if (d1 > d2) {
        return 1;
    }

    //同じ日付である場合
    return 0;
}

int era_of_date(int year, int month, int date)
{
    int era = -1;
    //元号の線形探索を行う
    for (; era < ERA_HEISEI; era++) {
        // 次の元号の開始日と比較する
        int compare_result = compare_date(
                year, month, date,
                ERA_BEGIN_YEAR[era + 1], ERA_BEGIN_MONTH[era + 1], ERA_BEGIN_DATE[era + 1]
                );

        if (compare_result < 0) {
            break;
        }
    }

    return era;
}

void print_date(int era, int year, int month, int date)
{
    //まずは元号を出力する
    bool pre_meiji = false;
    if (era == ERA_MEIJI) {
        printf("meiji");
    } else if (era == ERA_TAISHO) {
        printf("taisho");
    } else if (era == ERA_SHOWA) {
        printf("showa");
    } else if (era == ERA_HEISEI) {
        printf("heisei");
    } else {
        printf("pre-meiji");
        pre_meiji = true;
    }

    //明治以降なら日付も出力する
    if (!pre_meiji) { 
        printf(" %d %d %d", year - ERA_BEGIN_YEAR[era] + 1, month, date);
    }

    //最後に改行しておしまい
    printf("\n");
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n[3];
    rep(i, 3) cin >> n[i];

    rep(i, 3) {
        if (n[i % 3] == n[(i+1) % 3]) {
            cout << n[(i + 2) % 3] << endl; 
            break;
        }
    }
    

    return 0;
}


Measured memory_bytes: 256
from decimal import Decimal
N, K = map(int, input().split())
ans = 0
for n in range(1, N + 1):
    c = 0
    while n < K:
        n = n << 1
        c += 1
    t = 1 << c
    ans += Decimal("1.0") / Decimal(str(N * t))
print(ans)

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

vector<vector<int>> g(100000+10);

vector<vector<mint>> dp(100000+10, vector<mint>(2, 0)); // 0, siro, 1 kuro

void dfs(int now = 1, int par = -1) {
  int chi = 0;

  dp[now][0] = 1;
  dp[now][1] = 1;

  for(auto next : g[now]) if(next != par) {
    dfs(next, now);
    dp[now][0] *= (dp[next][0] + dp[next][1]);
    dp[now][1] *= dp[next][0];
  }
}

int main()
{
  int n; cin >> n;
  rep(i, n-1) {
    int x, y; cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs();
  mint ans = dp[1][0] + dp[1][1];
  cout << ans.x << endl;
}

Measured memory_bytes: 18176
n, m = map(int, input().split())
a = [int(input()) for i in range(m)]
l = [1] * (n+1)
for j in a:
  l[j] = 0
x = 10 ** 9 + 7
if m > n // 2:
  print(0)
else:
  dp = [0] * (n+1)
  dp[0] = 1
  if 1 not in a:
    dp[1] = 1
  for i in range(2, n+1):
    if l[i]:
      dp[i] = (dp[i-1] + dp[i-2]) % x
  print(dp[-1])

Measured memory_bytes: 13868
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
	//作るときはParentの値を全て-1にする
	//こうするとすべてバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}
	//AとBをくっつける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついているからくっつけない
			return false;
		}
		//大きい方(A)に小さいほう(B)をくっつけたい
		//大小が逆だったらひっくり返しちゃう
		if (size(A) < size(B)) swap(A, B);
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
	//AとBが同じグループにいるか
	bool same(int A, int B) { return root(A) == root(B); }
};


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	UnionFind Uni(n);
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		Uni.connect(a, b);
	}
	set<int> st;
	rep(i, n) {
		st.insert(Uni.root(i));
	}
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>

using namespace std;
long long v[101][100001];
long long f = 1<<30;
long long w[101];
long long va[101];

long long knap(long long n,long long c){
	if(v[n][c] != f) return v[n][c];
	long long result;
	if(n == 0 || c == 0) result = 0;
	else if(c < w[n]) result = knap(n-1, c);
	else{
		long long t = knap(n-1, c);
		long long t1 = knap(n-1, c-w[n]) + va[n];
		result = max(t, t1);
	}
	return v[n][c] = result;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	long long n, c;
	cin >> n >> c;
	for (long long i = 1; i <= n; ++i)
	{
		for (long long j = 1; j <= c; ++j)
		{
			v[i][j] = f;
		}
	}
	for (long long i = 1; i <= n; ++i)
	{
		cin >> w[i] >> va[i];
	}
	knap(n, c);
	cout << v[n][c];
}

Measured memory_bytes: 81704
package main

import "fmt"

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}

func main() {
	var A, B int
	fmt.Scan(&A, &B)
	fmt.Println(lcm(A, B))
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	set<int> u;
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=0;i<c;i++){
		u.insert(a+i);
		if(a+i>=b)break;
	}
	for(int i=0;i<c;i++){
		u.insert(b-i);
		if(b-i<=a)break;
	}
	for(auto x:u)cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
deque<int> que;
void work() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        int val;
        scanf("%d", &val);
        if (i & 1) {
            que.push_front(val);
        } else que.push_back(val);
    }
    if (n & 1) {
        for (deque<int> :: iterator it = que.begin(); it != que.end(); ++it) {
            cout << *it << " ";
        }
    } else {
        deque<int> :: iterator it = que.end();
        it--;
        while (true) {
            cout << *it << " ";
            if (it == que.begin()) break;
            it--;
        }
    }
}

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    work();
    return 0;
}


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

#define int long long
#define pii pair<int, int>
#define pb push_back

int gcd(int a, int b){
    if(a > b) return gcd(b, a);
    if(b % a == 0) return a;
    return gcd(a, b%a);
}

signed main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int k;
    cin >> k;
    int res = 0;
    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= k; j++){
            for(int l = 1; l <= k; l++){
                res += gcd(gcd(i, j), l);
            }
        }
    }
    cout << res << endl;   

    return 0;
}

Measured memory_bytes: 3648
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())

print(s[n-1])

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

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        
        int n, q;
        int com;
        int x, y, d;
        WeightedUnionFind uf;

        n = sc.nextInt();
        q = sc.nextInt();

        uf = new WeightedUnionFind(n);

        for (int i = 0; i < q; i++) {
            com = sc.nextInt();

            if (com == 0) {
                x = sc.nextInt();
                y = sc.nextInt();
                d = sc.nextInt();

                uf.unite(x, y, d);
            }
            else {
                x = sc.nextInt();
                y = sc.nextInt();

                if (uf.isSameGroup(x, y)) {
                    System.out.println(uf.diff(x, y));
                }
                else {
                    System.out.println("?");
                }
            }
        }
        
    }
}

/**
 * 重み付きUnionFind木.
 * アーベル群まで拡張したいけどパフォが気になるので保留
 * ArrayList\<Integer\>がint[]よりだいぶ遅い
 * @see <a href="https://atcoder.jp/contests/arc090/submissions/5441773">検証</a>
 */
class WeightedUnionFind {
    /** 親を示す 自身が根の場合は -(集合の大きさ) を持つ */
    private int[] parent;
    
    /** ノードの重み (親との差分) */
    private int[] diff_weight;

    public WeightedUnionFind(int nmemb) {
        parent = new int[nmemb];
        diff_weight = new int[nmemb];

        Arrays.fill(parent, -1);
        Arrays.fill(diff_weight, 0);
    }

    /** 根を求める */
    private int root(int x) {
        if (parent[x] < 0) {
            return x;
        }

        // 累積和的に重みを再計算
        int r = root(parent[x]);
        diff_weight[x] += diff_weight[parent[x]];
        parent[x] = r;

        return parent[x];
    }

    private int weight(int x) {
        root(x);
        return diff_weight[x];
    }

    public int diff(int x, int y) {
        return weight(y) - weight(x);
    }
    
    public boolean isSameGroup(int x, int y) {
        return root(x) == root(y);
    }

    /**
     * x->yの重みをwとして併合.
     * 即ち, weight(y) = weight(x) + w が成り立つ
     * x, yが既に同じグループのときは何もしない
     */
    public void unite(int x, int y, int w) {
        if (isSameGroup(x, y)) {
            return;
        }

        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
    
        parent[y] = x;
        diff_weight[y] = w;
    }

    public int groubSize(int x) {
        return -parent[root(x)];
    }
}



Measured memory_bytes: 175664
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	string S;
	cin >> N >> S;

	map<Int, Int> cnt;

	for (Int i = 0; i < N; i++) {
		cnt[S[i] - 'a']++;
	}

	mint ans = 1;
	for (const auto& e : cnt) {
		ans *= e.second + 1;
	}

	cout << ans-1 << "\n";
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio	
	ll n;
	cin >> n;
	ll a[n];
	ll b[n+1];
	for(int i=0; i<n+1; i++)cin >> b[i];//the monstors
	for(int i=0; i<n; i++)cin >> a[i];//the hero
	ll ans = 0;
	for(int i=0; i<n; i++){
		ll suma = min(a[i],b[i]);
		a[i]-=suma;
		b[i]-=suma;
		ans+=suma;
		suma = min(a[i],b[i+1]);
		a[i]-=suma;
		b[i+1]-=suma;
		ans+=suma;
	}
	cout << ans << endl;
	return 0;
}
//

Measured memory_bytes: 5188
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b;
    cin>>a>>b;
    long long x=a*b;
    while(b){
        a%=b;
        if(a==0)break;
        b%=a;
    }
    cout<<x/(a+b)<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int n;
    std::cin >> n;

    std::vector<long long> in(n);
    for (auto& work : in)
    {
        std::cin >> work;
        if (work == 0)
        {
            std::cout << "0";
            return 0;
        }
    }

    std::sort(in.begin(), in.end());

    long long ans = 1;
    for (const auto& prod : in)
    {
        constexpr long long MAX_18 = 1e18;
        if (prod <= MAX_18 / ans)
        {
            ans *= prod;
        }
        else
        {
            std::cout << "-1";
            return 0;
        }
    }
    std::cout << ans;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

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

	if(s * t < d) printf("No\n");
	else printf("Yes\n");
	return 0;
}


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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N, K;
    cin >> N >> K;
    cout << (N % K == 0 ? 0 : 1 ) << endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int h, w, k; scanf("%d%d%d", &h, &w, &k);
	std::vector<std::string> s(h);
	for(int i = 0; i < h; i++) cin >> s[i];

	if(h == 1) {
		int ans = 0, now = 0;
		for(int i = 0; i < w - 1; i++) {
			if(s[0][i] == '0') continue;
			now++;
			if(now == k) {
				ans++;
				now = 0;
			}
		}
		printf("%d\n", ans);
		return 0;
	}

	int ans = 1 << 30;
	for(int i = 0; i < (1 << h - 1); i++) {
		std::vector<int> v; v.push_back(0);
		for(int j = 0; j < h - 1; j++) if(i >> j & 1) v.push_back(j + 1);
		v.push_back(h);

		int cnt = v.size() - 2;
		std::vector<int> tan(v.size() - 1);
		for(int j = 0; j < w; j++) {
			bool cut = false;
			for(int l = 0; l < v.size() - 1; l++) {
				for(int k = v[l]; k < v[l + 1]; k++) tan[l] += (s[k][j] == '1');
				if(tan[l] > k) cut = true;
			}

			if(cut) {
				cnt++;

				for(auto& v: tan) v = 0;
				for(int l = 0; l < v.size() - 1; l++) {
					for(int k = v[l]; k < v[l + 1]; k++) tan[l] += (s[k][j] == '1');
				}
			}

			for(auto v: tan) if(v > k) cnt = 1 << 30;
		}
		
		ans = std::min(ans, cnt);
	}
	
	printf("%d\n", ans);
	return 0;
}


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

int main() {
	int n, m; cin >> n >> m;
    vector<vector<bool>> adj(n, vector<bool>(m, false));
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		adj[u][v] = true;
		adj[v][u] = true;
	}

	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		p[i] = i;
	}
	int cnt = 0;
	do {
		if (p[0] != 0) continue;
		bool ok = true;
		for (int i = 0; i < n - 1; i++) {
			if (!adj[p[i]][p[i + 1]]) {
				ok = false;
			}
		}
		if (ok) {
			cnt++;
		}
	} while (next_permutation(p.begin(), p.end()));
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256