akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(i==a)
		{
			if(s[i]!='-')
			{
				cout<<"No";
				exit(0);
			}
		}	
		else
		{
			if(s[i]>='0'&&s[i]<='9')
			{
				continue;
			}
			else
			{
				cout<<"No";
				exit(0);
			}
		}
	} 
	cout<<"Yes";
	return 0;
}

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


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18



int main(){ 

	int n, m;

	while (1) {
		cin >> n >> m;

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

		vector<int> tarou(n);
		vector<int> hanako(m);

		int sum = 0;
		int sumtarou = 0;
		int sumhanako = 0;
		for (int i = 0; i < n; i++) {
			cin >> tarou[i];
			sumtarou += tarou[i];
		}

		for (int j = 0; j < m; j++) {
			cin >> hanako[j];
			sumhanako += hanako[j];
		}

		sum = sumtarou + sumhanako;

		int d = sumhanako - sumtarou;

		if (d % 2 !=0) {
			cout << "-1" << endl;
			continue;
		}

		d /= 2;
		int mi = INF;
		int anst = 0;
		int ansh = 0;
		bool isfound = false;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int bufd = hanako[j] - tarou[i];

				if (d == bufd) {
					if (hanako[j] + tarou[i] < mi) {
						mi = min(mi, hanako[j] + tarou[i]);
						anst = tarou[i];
						ansh = hanako[j];
						isfound = true;
					}
				}
			}
		}

		if (isfound) {
			cout << anst << " " << ansh << endl;
		}
		else {
			cout << "-1" << endl;
		}
		


	}

	return 0;
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
//gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) //最大値更新 返り値はbool
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) //最小値更新 返り値はbool
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;

    rep(i, a, b + 1)
    {
        if (i % k == 0)
        {
            cout << "OK\n";
            return 0;
        }
    }
    cout << "NG\n";
}

Measured memory_bytes: 3584
MOD = 1000000007

N = int(input())
S = list(input())

s = 'S'
w = 'W'
c = 0
c1 = 0
c2 = 0

for i in [s, w]:
    if(c == 1): break
    for j in [s, w]:
        if (c == 1): break
        t = list()
        t.append(i)
        t.append(j)

        for k in range(1, N-1):
            if(S[k] == 'o'):
               if(t[k] == s):
                   t.append(t[k-1])
               else:
                    if(t[k-1] == s): t.append(w)
                    else: t.append(s)

            else:
                if (t[k] == w):
                    t.append(t[k - 1])
                else:
                    if (t[k - 1] == s):
                        t.append(w)
                    else:
                        t.append(s)

        c1 = 0
        if(t[0] == s):
            if(S[0] == 'o'):
                if(t[1] == t[N-1]):
                    c1 = 1
            else:
                if (t[1] != t[N - 1]):
                    c1 = 1
        else:
            if (S[0] == 'x'):
                if (t[1] == t[N - 1]):
                    c1 = 1
            else:
                if (t[1] != t[N - 1]):
                    c1 = 1
        c2 = 0
        if (t[N-1] == s):
            if (S[N-1] == 'o'):
                if (t[0] == t[N - 2]):
                    c2 = 1
            else:
                if (t[0] != t[N - 2]):
                    c2 = 1
        else:
            if (S[N-1] == 'x'):
                if (t[0] == t[N - 2]):
                    c2 = 1
            else:
                if (t[0] != t[N - 2]):
                    c2 = 1
        if(c1 == 1 & c2 == 1): c = 1

if(c == 1):
    print(''.join(t))
else:
    print('-1')

Measured memory_bytes: 5056
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[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'};
char moji2[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'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    FOR(i,1,10){
        if( n % i == 0 and n / i < 10){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

}

Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

      Scanner scanner = new Scanner(System.in);
      String line = scanner.next();
      String line2 = scanner.next();
     
      int a = Integer.parseInt(line);
      int b= Integer.parseInt(line2);


      System.out.println((a*b) + " "+ (2*(a+b)));
      }
}



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

const int M = 1e9+7;
ll mul(ll a, ll b) { 
  a += M; a %= M;
  b += M; b %= M;
  return (a*b)%M;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> pos, neg;
  rep(i,n) cin >> a[i];
  rep(i,n) {
    if (a[i] < 0) neg.push_back(a[i]);
    else pos.push_back(a[i]);
  }

  int ps = pos.size();
  int ns = neg.size();
  bool ok = false;
  if (ps > 0) {
    if (n == k) ok = (ns%2 == 0);
    else ok = true;
  } else {
    ok = (k%2 == 0);
  }

  ll ans = 1;
  if (!ok) {
    sort(a.begin(), a.end(), [] (int x, int y) {
      return abs(x) < abs(y);
    });
    rep(i,k) ans = mul(ans, a[i]);
  } else {
    sort(pos.begin(), pos.end());
    sort(neg.rbegin(), neg.rend());
    if (k%2 == 1) {
      ans = mul(ans, pos.back());
      pos.pop_back();
    }
    vector<ll> q;
    while (pos.size() >= 2) {
      ll tmp = pos.back();
      pos.pop_back();
      tmp *= pos.back();
      pos.pop_back();
      q.push_back(tmp);
    }
    while (neg.size() >= 2) {
      ll tmp = neg.back();
      neg.pop_back();
      tmp *= neg.back();
      neg.pop_back();
      q.push_back(tmp);
    }
    sort(q.rbegin(), q.rend());
    rep(i,k/2) ans = mul(ans, q[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 6268
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
    double r;
    cin >> r;
    double S = r * r * M_PI;
    double L = 2.0 * r * M_PI;
    cout << fixed << S << " ";
    cout << fixed << L << endl;
return 0;
}
    

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i < N; i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    float sum;
    float ave;
    sum = accumulate(a.begin(), a.end(), 0);
    ave = sum / a.size();
    int y = round(ave);
    int ans = 0;
    for(int i = 0; i < N; i++){
        ans += abs(y - a[i]) * abs(y - a[i]); 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define pbb pair<bool,bool>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xmod (ll)(1e9+7) 
#define hmod 1286031825167LL
using namespace std;

int n,a[100005],b[100005],ans;
map <int,int> m;
int main(){	
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i=1;i<=n;i++){
    	cin >> a[i];
    	b[i]=a[i];
	}
	sort(b+1,b+1+n);
	for (int i=1;i<=n;i++){
		m[b[i]]=i;
	}
	for (int i=1;i<=n;i++){
		if (i%2 != m[a[i]]%2)
		ans++;
	}
	cout << ans/2 << "\n";
    return 0;
}	
//1 2 3 4
//2 4 3 1
//4 1 3 2

Measured memory_bytes: 9100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

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

ll n,m;
string s,t;

int main(){
	cin >> n >> m >> s >> t;
	if(n < m){
		swap(n,m);
		string ss = s;
		s = t;
		t = ss;
	}
	ll GCD = gcd(n,m);
	ll LCM = n*m/gcd(n,m);
	if(GCD == 1){
		if(s[0] != t[0])cout << -1 << endl;
		else cout << LCM << endl;
	}
	else{
		bool ok = true;
		ll nn = LCM / n;
		ll mm = LCM / m;
		ll cntn = 0;
		ll cntm = 0;
		while(cntn < s.size() && cntm < t.size()){
			if(s[cntn] != t[cntm]){
				cout << -1 << endl;
				return 0;
			}
			cntn += mm;
			cntm += nn;
		}
		cout << LCM << endl;
	}
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

signed main(){
	fast;
	int n;
	cin>>n;
	int a[n+1],b[n];
	for(int i=0;i<n+1;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		cnt+=min(a[i],b[i]);
		if(b[i]>a[i]){
			cnt+=min(b[i]-a[i],a[i+1]);
			a[i+1]=max((int)0,a[i+1]-(b[i]-a[i]));
		}
	}
	cout<<cnt;
	return 0;
}



Measured memory_bytes: 1792
h,w,k = map(int,input().split())
s = [list(map(int,input())) for _ in range(h)]
    
ans = h*w
for div in range(1<<(h-1)):
    row = 0
    S = [[0]*w]
    S[row] = [s[0][i] for i in range(w)]
    for i in range(1,h):
        if 1&(div>>i-1):
            row += 1
            S.append([s[i][j] for j in range(w)])
        else:
            S[row] = [S[row][j]+s[i][j] for j in range(w)]
            
    count = [0]*(row+1)
    ans_ = row
    a = True
    for i in range(w):
        for j in range(row+1):
            if S[j][i] > k:
                a = False
                break
            count[j] += S[j][i]
            if count[j] > k:
                ans_+=1
                count = [0]*(row+1)
                for l in range(row+1):
                    count[l] += S[l][i]
                break
        if ans_ >= ans or a==False:
            break
    
    if a:
        ans = min(ans,ans_)

print(ans)

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

int main(){
  int i,j,d;
  string S;

  cin>>S;

  string d1="dream";
  string e1="erase";

  i=0;
  d=0;

  while(1){

    if(i+4>=S.size())
    d=1;

    else if(S.at(i)=='d'){
      for(j=i;j<i+5;j++){
        if(S.at(j)!=d1.at(j-i))
        d=1;
      }

      if((i+4==S.size()-1)&&d==0){
        cout<<"YES"<<endl;
        break;
      }

      if(d==0){
        if((i+5<=S.size()-1)&&(S.at(i+5)=='d'))
        i+=5;
        else if((i+5<=S.size()-1)&&(S.at(i+5)=='e')){
          if((i+6<=S.size()-1)&&S.at(i+6)=='r'){
            if(i+6==S.size()-1){
              cout<<"YES"<<endl;
              break;
            }
            else if(S.at(i+7)=='a'&&(i+7<=S.size()-1))
            i+=5;
            else
            i+=7;
          }
          else
          d=1;
        }
        else
        d=1;
      }
    }
    else if(S.at(i)=='e'){
      for(j=i;j<i+5;j++){
        if(S.at(j)!=e1.at(j-i))
        d=1;
      }

      if((i+4==S.size()-1)&&d==0){
        cout<<"YES"<<endl;
        break;
      }

      if(d==0){
        if((i+5<=S.size()-1)&&S.at(i+5)=='d')
        i+=5;
        else if((i+5<=S.size()-1)&&S.at(i+5)=='e')
        i+=5;
        else if((i+5<=S.size()-1)&&S.at(i+5)=='r'){
          if(i+5==S.size()-1){
            cout<<"YES"<<endl;
            break;
          }
          else
          i+=6;
        }
        else
        d=1;
      }
    }
    else
    d=1;

    if(d==1){
      cout<<"NO"<<endl;
      break;
    }

  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll                long long int
#define ld                long double
#define pb                push_back
#define pf                push_front
#define ppb               pop_back
#define ppf               pop_front
#define sz                size()
#define pi                acos(-1.0)
#define mod               1000000007
#define F                 first
#define S                 second
#define C                 continue
#define G                 goto done
#define maxe              max_element
#define mine              min_element
#define min3(a,b,c)       min(a,min(b,c))
#define max3(a,b,c)       max(a,max(b,c))
#define min4(a,b,c,d)     min(a,min(b,min(c,d)))
#define max4(a,b,c,d)     max(a,max(b,max(c,d)))
#define mem(a,b)          memset(a,b,sizeof(a))
#define all(a)            (a).begin(),(a).end()
#define gcd(a,b)          __gcd(a,b)
#define lcm(a,b)          ((a)*((b)/gcd(a,b)))
#define case(a)           cout<<"Case "<<(a)<<": "
#define point(a)          fixed<<setprecision(a)
#define get(a)            for(auto &x:a) cin>>x
#define print(a)          for(auto x:a) cout<<x<<" "; cout<<endl
#define see(x)            cout<<#x<<" = "<<x<<endl
#define uniq(a)           sort(all(a)); (a).erase(unique((a).begin(),(a).end()),(a).end())
#define big(a)            transform((a).begin(),(a).end(),(a).begin(),::toupper)
#define small(a)          transform((a).begin(),(a).end(),(a).begin(),::tolower)
#define ischar(a)         (('a'<=a&&a<='z')('A'<=a&&a<='Z'))
#define isvowel(a)        (a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
#define fast              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define tc                int test; cin>>test; while(test--)
using namespace std;
int main()
{
    ll n; cin>>n; cout<<n*n*n;
}




















Measured memory_bytes: 3580
from sys import stdin
from collections import deque

# 入力
n = int(input())

# command = [stdin.readline()[:-1] for a in range(n)]
command = stdin

# process
output = deque([])

for a in command:
    if a[0] == 'i':
        output.appendleft(int(a[7:]))
    elif a[0:7] == 'delete ':
        try:
            output.remove(int(a[7:]))
        except ValueError:
            pass
    elif a[6] == 'F':
        output.popleft()
    else:
        output.pop()

# 出力
print(*list(output))



Measured memory_bytes: 45892
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;cin>>N>>M;
  int L,R,aL=0,aR=100000;
  for(int i=0;i<M;i++){
    cin>>L>>R;
    aL=max(aL,L);
    aR=min(aR,R);
  }
  int ans=aR-aL+1;
  if(ans<0)ans=0;
  cout<<ans<<endl;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int func(long long n, std::vector<long long> a) {
    // cout << fixed << setprecision(5);

    // 累積和
    // 左右の端の場合はそのまま記録
    // それ以降のは2つの値のgcdを求めていく
    vll left(n + 1), right(n + 1);
    left[1]  = a[0];
    right[1] = a[n - 1];
    // なぜ１から入れているのか？
    // 累積和はa[0]に0を入れることが重要な項目の一つ。
    // これは累積和の0と0の差分を取る時に必要となる。
    // なのでleft[1]にa[0]を right[1]にa[n-1]を代入している。
    rep(i, n) {
        left[i + 1]  = gcd(left[i], a[i]);
        right[i + 1] = gcd(right[i], a[n - 1 - i]);
    }

    ll ans = left[n];  //全体の最大公約数
    // ll ans = right[n];  //全体の最大公約数
    // 累積和はsum[i+1]=sum[i]+a[i]が基本
    // 	配列 a に対して累積和 s を求めると、配列 a の区間 [left, right) の総和が
    // s[right] - s[left]
    // で O(1) で求められる
    rep(i, n) {
        ll res;
        if (i == 0)  //左端
            res = right[n - 1];
        else if (i == n - 1)  //右端
            res = left[n - 1];
        else
            res = gcd(left[i], right[n - 1 - i]);
        ans = max(ans, res);
    }
    cout << ans << endl;

    return 0;
}

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

    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    func(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2560
import itertools
import math
n,d = map(int,input().split())

x = []
for i in range(n):
    x.append(list(map(int,input().split())))
    
mc=(list(itertools.combinations(range(n), 2)))

count = 0 
for i in mc:
    ans2=0
    for j in range(d):
        ans2+= abs(x[i[1]][j] - x[i[0]][j])**2
    ans = math.sqrt(ans2)
    if ans.is_integer():
        count+=1

print(count)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

bool check(string s,string t){
    REP(i,s.size()){
        if(s[i]!='?' and s[i]!=t[i]) return false;
    }
    return true;
}

signed main()
{   
    string s,t; cin>>s>>t;
    set<string> st;
    REP(i,s.size()-t.size()+1){
        if(check(s.substr(i,t.size()),t)){
            string u;
            for(int j=0;j<i;j++)
                u+=(s[j]=='?'? 'a':s[j]);
            u+=t;
            for(int j=i+t.size();j<s.size();j++)
                u+=(s[j]=='?'? 'a':s[j]);
            st.insert(u);
        }
    }
    if(st.empty()) cout<<"UNRESTORABLE"<<endl;
    else cout<<*st.begin()<<endl;
}


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

int main(){
  int N;
  cin >> N;
  if (N == 1) {
    cout << "Hello World" << endl;
  }else{
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
#define VI vector<int>
#define VL vector<LL>
#define VII vector< vector<int> >
#define VLL vector< vector<LL> >
#define VS vector<string>
#define PII pair<int,int>
#define PIS pair<int,string>
#define PSI pair<string,int>
#define PLL pair<ll,ll>
LL facctorialMethod(int k);
int main(){
    LL a,b,k,tmp;
    cin >> a >> b >> k;
    tmp = k;
    if(a <= k) {
        k = k - a;
        a = 0;        
        if(b <= k) {
            k = k - b;
            b = 0;
        }else{
            b = b - k;
        }
    }else{
        a = a -k;
    }
    cout << a << " " << b << endl;


    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3612
// 解き直し.
// http://agc005.contest.atcoder.jp/data/agc/005/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int io[202020], oi[202020];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N){
        scanf("%d", &io[i]);
        oi[io[i]] = i + 1;
    }
    
    // 2. l, r を 計算(※解説参照).
    LL ans = 0;
    set<int> s;
    s.insert(0);
    s.insert(N + 1);
    // ※ 解説上, N, N - 1, N - 2, ... の 順で, l, r を 求めていくと説明されているが, 
    // 上手く行かなかったので, 1, 2, ... の 順で, l, r を 求めていくように実装している.
    repx(i, 1, N + 1){
        // i の 出現位置.
        int at = oi[i];
        
        // 検索.
        set<int>::iterator itl, itr;
        itl = s.lower_bound(at);
        itr = s.lower_bound(at);
        int l = *(--itl);
        int r = *itr;
        // printf("at=%d l=%d r=%d\n", at, l, r);
        
        // 加算.
        ans += (LL)io[at - 1] * (LL)(at - l) * (LL)(r - at);
        
        // 登録.
        s.insert(at);
    }
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 14684
n = int(input())
s = [input() for i in range(n)]

ans = 0
A = 0
B = 0
BA = 0
for i in s:
    ans += i.count("AB")
    if i[0:1] != "B" and i[-1:] == "A":
        A += 1
    elif i[0:1] == "B" and i[-1:] != "A":
        B += 1
    elif i[0:1] == "B" and i[-1:] == "A":
        BA += 1

#print(ans)
#print(A,B,BA)

while 1:
    if BA == 0 or A == B:
        break
    if A >= B:
        B += 1
    else:
        A += 1
    BA -= 1
#print(A,B,BA)
if A == 0 and B == 0:
    if BA != 0:    
        BA -= 1
print(ans + min(A,B) + BA)

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

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

  vector<int> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];

  int sum = accumulate(s.begin(), s.end(), 0);
  if (sum % 10 != 0) {
    cout << sum << endl;
    return 0;
  }

  sort(s.begin(), s.end());
  int t = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] % 10 != 0) {
      t = s[i];
      break;
    }
  }
  int ans;
  if (t == 0)
    ans = 0;
  else
    ans = sum - t;

  cout << ans << endl;
}


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

using namespace std;
using ll = long long;

int main() {
    int k;
    cin>>k;
    ll ans=0;
    for(int i = 1;i <= k;++i) {
        for(int b = 1;b <= k;++b) {
            for(int c = 1;c <= k;++c) {
                ans+=gcd(i,gcd(b,c));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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


int main() {
    int A, B; cin >> A >> B;
    set<int> all;
    all.insert(1); all.insert(2); all.insert(3);
    all.erase(A); all.erase(B);
    auto ans = all.begin();
    cout << *ans << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    H, W = [int(i) for i in input().split()]
    if H == W == 0:
        break

    for h in range(H):
        for w in range(W):
            if (w + h) % 2 == 0  :
                print('#', end='')
            else:
                print('.', end='')

        print()

    print()

Measured memory_bytes: 9128
#include <iostream>

using namespace std;

int n, k;
int t[100005];

int dp[100005];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> t[i];
		dp[i] = 1000000005;
	}
	dp[1] = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = i-1; j >= max(i-k, 1); --j) {
			dp[i] = min(dp[i], dp[j]+abs(t[j]-t[i]));
		}
	}
	cout << dp[n] << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	char C[20];
	int i;
	for(i=0;i<7;i++)
	{
		scanf("%c",&C[i]);
	}
	if(C[0]==C[6]&&C[1]==C[5]&&C[2]==C[4])
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
	return 0;
}

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

#include <algorithm>
#include <string>

using namespace std;
int main(void){
    string a,b,c;
    cin >> a >> b >> c;
    a.at(0)=a.at(0)-32;
    b.at(0)=b.at(0)-32;
    c.at(0)=c.at(0)-32;
    cout << a.at(0) << b.at(0) << c.at(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double PI = 3.14159265358979323846;

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

    int r;
    cin >> r;
    ld ans = 2 * PI * r;
    cout << fixed;
    setprecision(20);
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3760
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    lli N;
    cin >> N;
    lli tmpN = N;
    vector<lli> a;
    bool f = true;
    for (lli i = 2; i <= sqrt(N); i++)
    {
        while (N % i == 0)
        {
            if (f == true)
            {
                a.push_back(i);
            }
            f = false;
            N /= i;
        }
        f = true;
        if (N == 1)
        {
            break;
        }
    }
    if (N != 1)
    {
        a.push_back(N);
    }
    lli cnt = 0;
    if (a.size() >= 1)
    {
        lli ans = 0;
        lli div = 1;
        //lli j = 0;
        for (lli i = 0; i < a.size(); i++)
        {
            for (lli j = a[i]; j <= (lli)(pow(10, 12)); j = j * a[i])
            {
                if (tmpN == 1 || tmpN % j != 0)
                {
                    break;
                }
                else
                {
                    tmpN /= j;
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
    else
    {
        if (tmpN == 1)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << 1 << endl;
        }
    }
    return 0;
}


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

using namespace std;

const int N = 1 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
int g[N][N];
int U[N], col[N];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;

        for (int j = 0; j < n; ++j)
            g[i][j] = s[j] - '0';
    }

    return true;
}

bool dfs(int v, int c) {
    U[v] = 1;
    col[v] = c;

    for (int to = 0; to < n; ++to)
        if (g[v][to]) {
            if (!U[to]) {
                if (!dfs(to, 1 - c))
                    return false;
            } else {
                if (col[to] != 1 - c)
                    return false;
            }
        }

    return true;
}

void solve() {
    for (int i = 0; i < n; ++i)
        if (!U[i] && !dfs(i, 0)) {
            cout << "-1\n";
            return ;
        }

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            if (g[i][j] == 0)
                g[i][j] = n;

    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);

    int mx = 0;

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            if (i != j)
                mx = max(mx, g[i][j]);

    cout << 1 + mx << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 1024
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <tuple>
using namespace std;

// Union-Find 木 (Verified: AtCoder Typical Contest 001 B)
struct UnionFind {
private:
    const int n;
    int size_;
    vector<int> uf;
public:
    // 初期化 UnionFind uni(n) のように宣言すれば良い
    UnionFind(int _n) : n(_n), size_(_n), uf(_n, -1) {}
    // find (木の根を求める)
    int find(int x) {return (uf[x] < 0) ? x : uf[x] = find(uf[x]);}
    // x と y が同じ集合に属するかどうか
    bool same(int x, int y) {return find(x) == find(y);}
    // x が属する集合の要素数
    int size(int x) {return -uf[find(x)];}
    // 集合はいくつあるか
    int size()      {return size_;}
    // x と y の属する集合を併合
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        size_--;
        if(uf[x] < uf[y]) swap(x, y);
        uf[x] += uf[y]; uf[y] = x;
        return true;
    }
};

// Boruvka's algorithm (最小全域木を求める)
// その時点で存在するそれぞれの木について、それに接続している辺で重み最小のものを探す関数が必要
// 依存ライブラリ: UnionFind

template <typename T, typename F>
T boruvka(int N, F f) {
    UnionFind uf(N);
    vector<int> group(N), rev(N);
    T ans(0);

    while(uf.size() > 1) {
        // 各頂点が何番目の連結成分に属するか？
        // ある連結成分について代表元はなにか？
        int ptr = 0;
        for(int i=0; i<N; i++) {
            if(uf.find(i) == i) {
                group[i] = ptr++;
                rev[ group[i] ] = i;
            }
        }
        for(int i=0; i<N; i++) group[i] = group[ uf.find(i) ];

        // 異なる連結成分同士を結んでいる辺の候補をもってくる
        // 各連結成分に対して (最小コスト・繋げる先 (ないなら -1))
        auto edges = f(ptr, group);

        bool changed = false;
        for(int u=0; u<ptr; u++) {
            T cost; int v; tie(cost, v) = edges[u];
            if(v >= 0 and uf.unite(rev[u], rev[v])) {
                ans += cost;
                changed = true;
            }
        }

        if(!changed) return false;
    }

    return ans;
}

void GRL_2_A() {
    int N, M; scanf("%d%d", &N, &M);
    vector<int> s(M), t(M), w(M);
    for(int i=0; i<M; i++) {
        scanf("%d%d%d", &s[i], &t[i], &w[i]);
    }

    const int INF = 1 << 30;
    auto f = [&](int sz, vector<int> group) {
        vector< pair<int, int> > res(sz, {INF, -1});
        for(int i=0; i<M; i++) {
            int gs = group[ s[i] ], gt = group[ t[i] ];
            if(gs == gt) continue;
            res[gs] = min(res[gs], {w[i], gt});
            res[gt] = min(res[gt], {w[i], gs});
        }
        return res;
    };

    cout << boruvka< int, decltype(f) >(N, f) << endl;
}

int main() {
    GRL_2_A();
}



Measured memory_bytes: 4388
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int x;
    cin >> x;
    if(x==0){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

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

const ll MOD = 1000000007;
const ll MAXN = 200000;

ll N, ans=1, tmp=0;
vector<ll> A(MAXN, 0), M(MAXN, 3);

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<N;i++) {
        if(!A[i]) {
            ans *= M[A[i]];
            M[A[i]]--;
        }
        else {
            ans *= M[A[i]] - M[A[i]-1];
            ans %= MOD;
            M[A[i]]--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(int i=int(x);i<int(y);++i)
#define For(i,x,y)  for(int i=int(x);i<=int(y);++i)
#define FOr(i,x,y)  for(int i=int(x);i>=int(y);--i)
#define pi acos(-1) 
#define mk make_pair
#define pa pair<ll,ll>
#define lf else if
#define IL inline
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
#define Add(x,y)    ((x)=((x)+(y))%mod)
#define Max(x,y)    ((x)=((x)<(y)?(y):(x)))
#define Min(x,y)    ((x)=((x)>(y)?(y):(x)))
#define E(x)        return writeln(x),0
#define LL			(long long)
#define p(x)        printf("~%lld~\n",LL(x))
#define pp(x,y)     printf("~~%lld %lld~~\n",LL(x),LL(y))
#define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",LL(x),LL(y),LL(z))
#define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",LL(a),LL(b),LL(c),LL(d))
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define fi first
#define se second
#define GuYue		puts("\nGuYueNa________________________________________________________________________________")
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_; 
#endif 
#define NEG 1
    static const int GYN=2333333;
    char SZB[GYN],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,GYN,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,g=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') g=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*g; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);}
	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);}
	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);}
	void writeln(ll x){write(x);puts("");}
}using namespace SHENZHEBEI;
const ll N=200010;
ll head[N],nxt[N],vet[N],remain[N],n,tot;
void insert(ll x,ll y){nxt[++tot]=head[x];head[x]=tot;vet[tot]=y;}
void dfs(ll x,ll pre){
	remain[x]=1;
	for(ll i=head[x];i;i=nxt[i])if (vet[i]!=pre){
		dfs(vet[i],x);
		if (remain[x]&&remain[vet[i]])	remain[x]=remain[vet[i]]=0;
		lf (!remain[x]&&remain[vet[i]]){puts("First");exit(0);}
	}
}
int main(){
	n=read();
	rep(i,1,n){ll x=read(),y=read();insert(x,y);insert(y,x);}
	dfs(1,0);	puts(remain[1]?"First":"Second");
}

Measured memory_bytes: 7680
from sys import stdin
from collections import deque

N, K = [int(x) for x in stdin.readline().rstrip().split()]
AB = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N - 1)]

tree = [[] for _ in range(N)]
inf = 10 ** 9 + 7

for i in range(N - 1):
    tree[AB[i][0] - 1].append(AB[i][1] - 1)
    tree[AB[i][1] - 1].append(AB[i][0] - 1)

ans = 1
q = deque([0])
visited = [False] * N

while len(q) > 0:
    c = q.popleft()
    visited[c] = True
    if c == 0:
        m = K - 1
        ans *= K
        ans %= inf
    else:
        m = K - 2
    for i in range(len(tree[c])):
        if not visited[tree[c][i]]:
            ans *= m
            ans %= inf
            m -= 1
            q.append(tree[c][i])

print(ans)

Measured memory_bytes: 75100
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;

struct UnionFind
{
	int N;
	vector<int> parent;
	vector<int> size_r;
	int num_of_sets;

	UnionFind(int N) :  N(N), parent(N), size_r(N, 1), num_of_sets(N) {
		for (int i = 0; i < N; ++i) parent[i] = i;
	}

	int root(int x) {
		if (parent[x] == x) return x;
		return parent[x] = root(parent[x]);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (size_r[x] < size_r[y]) swap(x, y);
		parent[y] = x;
		size_r[x] += size_r[y];
		size_r[y] = 0;
		num_of_sets--;
		return true;
	}

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

	int size(int x) {
		return size_r[root(x)];
	}

	vector<int> roots() {
		vector<int> v(N);
		for (int i = 0; i < N; ++i) v[i] = root(i);
		return v;
	}
};

int main() {
	int n, k, l;
	cin >> n >> k >> l;
	UnionFind U1(n), U2(n);
	for (int i = 0; i < k; i++) {
		int p, q;
		cin >> p >> q;
		p--; q--;
		U1.merge(p, q);
	}
	for (int i = 0; i < l; i++) {
		int r, s;
		cin >> r >> s;
		r--; s--;
		U2.merge(r, s);
	}
	map<pair<int, int>, int> mp;
	vector<int> v1 = U1.roots(), v2 = U2.roots();
	for (int i = 0; i < n; i++) {
		mp[{v1[i], v2[i]}]++;
	}
	for (int i = 0; i < n; i++) {
		int ans = mp[{v1[i], v2[i]}];
		cout << ans;
		if (i < n-1) cout << ' ';
		else cout << endl;
	}
	return 0;
}

Measured memory_bytes: 19284
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
  string a,b;
  int len;


  cin >> a >> b;
  len = (int)(b.length());

  b = b.substr(0,len-1);
 
  if(a == b){
      cout << "Yes";

  }else{
      cout << "No";
  }
}
   



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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 110

int x[MAX_N];

signed main()
{
    int N, K;
    cin >> N >> K;
    int ans = 0;
    REP(i, N) {
        cin >> x[i];
        ans += min(x[i], K - x[i]) * 2;
    }
    printf("%lld\n", ans);

    return 0;
}


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


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

    string S;
    int flg = 0;
    cin >> S;
    int n = S.size();
    for (int i=0; i<n; i+=2){
        if (S[i] == 'L'){
            flg++;
            break;
        }
    }
    for (int i=1; i<n; i+=2){
        if (S[i] == 'R'){
            flg++;
            break;
        }
    }
    if (flg > 0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}

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

int main(){
    int n;
    cin >> n;
    double V[n];
    for(int i = 0; i < n; i++){
        cin >> V[i];
    }
    sort(V, V + n);
    for(int i = 0; i < n-1; i++){
        V[i+1] = (V[i] + V[i+1])/2;
    }
    cout << V[n-1] << endl;

    return 0;
}

Measured memory_bytes: 256
#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;

typedef long long int ll;
typedef tree< ll, null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

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

  ll n, z, w;
  cin >> n >> z >> w;
  vector < ll > a(n + 1);
  for(int i = 1; i <= n; i++) cin >> a[i];
  ll ans = abs(w - a[n]);
  if(n > 1) ans = max(ans, abs(a[n] - a[n - 1]));

  cout << ans << '\n';
}


Measured memory_bytes: 256
N = int(input())
a_list = tuple(map(int, input().split()))
b_list = tuple(map(int, input().split()))
a_sum = sum(a_list)
b_sum = sum(b_list)

if b_sum > a_sum:
    print(-1)
    exit()

minus = {}
plus = {}
for i in range(N):
    a = a_list[i]
    b = b_list[i]
    tmp = a - b
    if tmp < 0:
        if tmp in minus:
            minus[tmp] += 1
        else:
            minus[tmp] = 1
    else:
        if tmp in plus:
            plus[tmp] += 1
        else:
            plus[tmp] = 1

minus = sorted(minus.items(), key= lambda x:x[0])
plus = sorted(plus.items(), key= lambda x:-x[0])
ans = 0
changed = 0
for k, v in minus:
    ans += v
    changed += (k * v)
if changed <0:
    for k, v in plus:
        for j in range(1, v+1):
            ans += 1
            changed += k
            if changed >= 0:
                print(ans)
                exit()
print(ans)

Measured memory_bytes: 27884
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i,from,to) for(int i=from; i<to; ++i)
#define REP(i,from,to) for(int i=from; i<=to; ++i)
using namespace std;
template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i] << endl;
	}
	return out;
}
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	out << "[";
	size_t last = v.size() - 1;
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i];
		if (i != last) {
			out << ",";
		}
	}
	out << "]";
	return out;
}
const int maxn = 1000100;
int n;
int c[maxn];
typedef pair<string, int> P;
void print(int arr[maxn], int n) {
	for (int i = 0; i < n - 1; ++i) {
		cout << arr[i] << " ";
	}
	cout << arr[n - 1] << endl;
}

void stable_bubble(P arr[maxn], int n) {
	int cnt = 0;
	int flag = 1;
	while (flag) {
		flag = 0;
		for (int j = n - 1; j >= 1; j--) {
			if (arr[j].first[1] < arr[j - 1].first[1]) {
				swap(arr[j], arr[j - 1]);
				flag = 1;
				cnt++;
			}
		}
	}
}

void stable_selection(P arr[maxn], int n) {
	int cnt = 0;
	REP(i,0,n-1)
	{
		int minj = i;
		REP(j,i,n-1)
		{
			if (arr[j].first[1] < arr[minj].first[1]) {
				minj = j;
			}
		}
		if (i != minj) {
			swap(arr[i], arr[minj]);
			cnt++;
		}
	}
}

void selectionSort(int arr[maxn], int n) {
	int cnt = 0;
	REP(i,0,n-1)
	{
		int minj = i;
		REP(j,i,n-1)
		{
			if (arr[j] < arr[minj]) {
				minj = j;
			}
		}
		if (i != minj) {
			swap(arr[i], arr[minj]);
			cnt++;
		}
	}
	print(arr, n);
	cout << cnt << endl;
}

void bubbleSort(int arr[maxn], int n) {
	int cnt = 0;
	int flag = 1;
	while (flag) {
		flag = 0;
		for (int j = n - 1; j >= 1; j--) {
			if (arr[j] < arr[j - 1]) {
				swap(arr[j], arr[j - 1]);
				flag = 1;
				cnt++;
			}
		}
	}
	print(arr, n);
	cout << cnt << endl;
}

void insertionSort(int arr[maxn], int n) {
	print(arr, n);
	REP(i,1,n-1)
	{
		int v = arr[i];
		int j = i - 1;
		while (j >= 0 && arr[j] > v) {
			arr[j + 1] = arr[j];
			j--;
		}
		arr[j + 1] = v;
		print(arr, n);
	}
}

int insertionSort(int arr[maxn], int n, int g) {
	int cnt = 0;
	REP(i, 0, n-1)
	{
		int v = arr[i];
		int j = i - g;
		while (j >= 0 && arr[j] > v) {
			arr[j + g] = arr[j];
			j = j - g;
			cnt++;
		}
		arr[j + g] = v;
	}
	return cnt;
}

int triRoot(int n) {
	int ret = 0;
	while (n > 1) {
		n /= 3;
		ret++;
	}
	return ret;
}
const int maxm = 100;
void shellSort(int arr[maxn], int n) {
	int cnt = 0;
	int g[maxm];
	int m = max(1, min(maxm, triRoot(n)));
	g[0] = 1;
	rep(i,1,m)
	{
		g[i] = g[i - 1] * 3 + 1;
	}
	std::reverse(g, g + m);

	rep(i,0,m)
	{
		cnt += insertionSort(arr, n, g[i]);
	}

	//print
	cout << m << endl;
	rep(i,0,m-1)
	{
		cout << g[i] << " ";
	}
	cout << g[m - 1] << endl;
	cout << cnt << endl;
	rep(i,0,n)
	{
		cout << arr[i] << endl;
	}
}

void solve() {
	cin >> n;
	rep(i,0,n)
	{
		cin >> c[i];
	}
	shellSort(c, n);
}

int main() {
	solve();
}

Measured memory_bytes: 6968
import java.util.*;

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

    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    if(c >= a && a + b >= c) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main(){
  int n,w,h,x,y,i,j,s,max;
  while(scanf("%d",&n),n){
    int d[510][510]={0};
    scanf("%d %d",&w,&h);
    while(n--){
      scanf("%d %d",&x,&y);
      d[y][x]=1;
    }
    for(i=max=0;i<h;i++){
      for(j=0;j<w;j++)d[i+1][j+1]=d[i+1][j+1]+d[i][j+1]+d[i+1][j]-d[i][j];
    }
    scanf("%d %d",&x,&y);
    for(i=y;i<=h;i++){
      for(j=x;j<=w;j++){
	s=d[i][j]-d[i-y][j]-d[i][j-x]+d[i-y][j-x];
	if(max<s)max=s;
      }
    }
    printf("%d\n",max);
  }
  return 0;
}
  

Measured memory_bytes: 1624