akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int n, a, b, m, now;

long long v[55];
long long vv[55], num[55];
long long sum, f = 1;

long long prime[55] = {1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};

long long calc(int AA, int BB){
	int CC = AA - BB;
	int aa[55], bb[55];
	memset(aa, 0, sizeof(aa));
	memset(bb, 0, sizeof(bb)); 
	long long res = 1;
	for(int j = 1; j <= BB; j ++){
		int B = j;
		for(int i = 1; i <= 15; i ++){
			while(B && B % prime[i] == 0){
				bb[i] ++;
				B /= prime[i];
			}
		} 
	}
	for(int j = 1; j <= CC; j ++){
		int C = j;
		for(int i = 1; i <= 15; i ++){
			while(C && C % prime[i] == 0){
				bb[i] ++;
				C /= prime[i];
			}
		} 
	}
	for(int j = 1; j <= AA; j ++){
		int A = j;
		for(int i = 1; i <= 15; i ++){
			while(A && A % prime[i] == 0){
				aa[i] ++;
				A /= prime[i];
			}
		} 
	}
	for(int i = 1; i <= 15; i ++){
		aa[i] -= bb[i];
	}
	for(int i = 1; i <= 15; i ++){
		while(aa[i]) res *= (prime[i]), aa[i] --;
	}
	return res;
}

int main(){
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i ++) cin >> v[i];
	sort(v+1, v+1+n);
	for(int i = 1; i <= n; i ++){
		if(v[i-1] != v[i]){
			vv[++ m] = v[i];
			num[m] ++;
		}else num[m] ++;
	}
	if(num[m] >= a){
		printf("%lf\n", (double)v[m]);
		if(num[m] <= b) for(int i = a; i <= num[m]; i ++) f += calc(num[m], i);
		else for(int i = a; i <= b; i ++) f += calc(num[m], i);
		cout << f - 1;
		return 0;
	}
	for(int i = m; i >= 1; i --){
		if(now + num[i] >= a){
			int ss = a - now;
			sum += ss * vv[i];
			printf("%lf\n", (double)(1.0*sum/a));
			cout << calc(num[i], ss);
			return 0;
		}else now += num[i], sum += num[i] * vv[i];
	}
	 
	return 0;
}

Measured memory_bytes: 256
import Foundation

let input:String = readLine()!
let n = Int(input)!

let array = [11, 13, 17, 19, 22, 23, 26, 29, 31, 33, 34, 37, 38, 39, 41, 43, 44, 46, 47, 50, 51, 52, 53, 55, 57, 58, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
let answer = array.filter{ $0 == n }

if answer == [] {
  print("Yes")
} else {
  print("No")
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>

int main(void){
	int a,b,c,ans,ans2;
	
	ans=0;
	ans2=0;
	
	while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
		if(a==b)ans2++;
		if(sqrt(a*a+b*b)==c)ans++;
	}
	
	printf("%d\n%d\n",ans,ans2);
	
	return 0;
}

Measured memory_bytes: 0
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int max = sc.nextInt();
        int count = 1;

        for (int i=0; i<num-1; i++) {
            int input = sc.nextInt();

            if (input >= max) {
                count++;
                max = input;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(string, s);
    s += "~~";
    const int N = s.length();

    i64 ans = 0;
    i64 a = 0;
    i64 bc = 0;
    rep(i, 0, N) {
        if (s[i] == 'A') {
            ++a;
        } else if (s[i] == 'B' && s[i + 1] == 'C') {
            ans += a;
            ++bc;
            ++i;
        } else {
            a = 0;
            bc = 0;
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 720
#include<stdio.h>
#include<algorithm>
int F(int a,int b,int c,int x)
{
	int r=0;
	if(a>=x&&b>=x&&c>=x)r=x,a-=x,b-=x,c-=x;
	return r+a/3+b/3+c/3+std::min(a%3,std::min(b%3,c%3));
}
int main()
{
	int a[6],i,x;
	for(;;)
	{
		for(i=x=0;i<6;++i)scanf("%d",a+i),x+=a[i];
		if(!x)return 0;
		for(i=0;i<3;++i)a[i]+=a[i+3];
		for(x=i=0;i<3;++i)x=std::max(x,F(*a,a[1],a[2],i));
		printf("%d\n",x);
	}
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
	long N,L[2000],pre,len[1001]={0};
	long count = 0;
	cin>>N;
	for(int i=0;i<N;i++)cin>>L[i];
	for(int i=0;i<N-1;i++){
		for(int j=0;j<N-i-1;j++){
			if(L[j]>L[j+1]){
				pre=L[j];
				L[j]=L[j+1];
				L[j+1]=pre;
			}
		}
	}
	for(int i=0;i<N;i++)len[L[i]]++;
	for(int i=999;i>=0;i--)len[i]+=len[i+1];
	for(int i=0;i<N-2;i++){
		for(int j=i+1;j<N-1;j++){
			if(L[i]+L[j]>1000)pre = N-(j+1);
			else pre = N-len[L[i]+L[j]]-(j+1);
			if(pre>0)count+=pre;
		}
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

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

  int dig = 0, tmp_n = N;
  while(tmp_n!=0) { dig += tmp_n%10; tmp_n/=10; }

  string result = N%dig==0 ? "Yes" : "No";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define koto_memory(a) cout<<(sizeof(a)/1048576.0)<<" MB";
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
void solve(){
  int n;cin>>n;
  cout<<n+n*n+n*n*n;
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

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

int main()
{
  long long x,y;cin>>x>>y;
  long long cnt = 0;
  if (x == 1)
  {
    cnt++;
    x = 2;
  }
  
  for (size_t i = x; i <= y; i*=2)
  {
    cnt++;
  }
  cout << cnt << endl;
  
}

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

int main() {
	int n;
	cin>>n;
	int arr[2*n];
	for(int i=0;i<2*n;i++)
	{
		cin>>arr[i];
	}
	for(int i=0;i<2*n;i++)
	{
		for(int j=i;j<2*n;j++)
		{
		if(arr[i]>arr[j])
		{
			int temp;
			temp=arr[j];
			arr[j]=arr[i];
			arr[i]=temp;
		}
		}
		
	}

	int sum=0;
	for(int i=0;i<2*n;i++)
	{
		if(i%2==0)
		{
		sum=sum+arr[i];
		}
	}
	cout<<sum;
	
	return 0;
}

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

#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pf push_front
#define pb2 pop_back
#define pf2 pop_front
#define line printf("\n")
#define pq priority_queue
#define rep(k,i,j) for(int k = (int)i;k<(int)j;k++)
#define repd(k,i,j) for(int k = (int)i;k>=(int)j;k--)
#define ll long long
#define ALL(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define vi vector<int>

using namespace std;

double EPS = 1e-9;
int INF = 1e9+7;;
long long INFLL = 1e17;
double pi = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

clock_t first_attempt = clock();
inline void cek_time(){
	clock_t cur = clock()- first_attempt;
	cerr<<"TIME : "<<(double) cur/CLOCKS_PER_SEC<<endl;
}
inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of template

int n,m,K;
int main(){
    cin>> n>> m>> K;
    
    int can = 0;
    rep(a,0,n+1)rep(b,0,m+1){
        
        int ret = a*m + b*n - a*b*2;
        
        if(ret==K)can = 1;
    }
    
    printf("%s\n",can?"Yes":"No");
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=1;i<=1000;i++){
        for(int j=0;j<=1000;j++){
            int tmp=a*i-b*j;
            if(tmp==c){
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  vector<int> arr(N);
  for(int i=0;i<N;i++){
    int num=0;
    while(vec.at(i)%2==0){
      vec.at(i) = vec.at(i)/2;
      num+=1;
    }
    arr.at(i)=num;
  }
  int ans=arr.at(0);
  for(int i=1;i<N;i++){
    ans = min(ans, arr.at(i));
  }
  cout<<ans<<endl;
}

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

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

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

int n, K, ki, kc;
char s[MAXN];
int a[MAXN];
char ans[MAXN];

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

void fill ( int l, int r )
{
	lpi ( i, l, r ) ans[i] = 'B';
}



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



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d%d%s", &n, &K, s+1 );
}

void work ()
{
	// main work
	
	n = strlen ( s+1 );
	ki = 0;
	int cbl = -1;
	lpi ( i, 1, n ){
		if ( s[i] == 'B' ){
			if ( cbl == -1 ) cbl = i;
		}else{
			if ( ~cbl ) a[ki<<1] = cbl, a[ki<<1|1] = i - 1, ++ki, cbl = -1;
		}
	}
	if ( ~cbl ) a[ki<<1] = cbl, a[ki<<1|1] = n + 1, ++ki, cbl = -1;
	
	for ( int i = ki<<1; i < MAXN; i += 2 ) a[i] = a[i+1] = n + 1 + ( i - ( ki << 1 ) ) + ( s[n] == 'B' ? 2 : 0 );
	
//	lp ( i, 0, ki+1000 ) cerr << a[i] << " ";
//	cerr << endl;
	
	int nk = 0, cl = a[0], cr = a[1];
	lpi ( _t, 1, K ){
		if ( cl > 1 ){
			if ( cl > 2 ){
				cl = cr = 1;
				--nk;
			}else --cl;
		}else{
			++kc;
			cl = cr, cr = a[(nk<<1)+kc+1] - ( ( kc + 1 ) & ~1 );
		}
		
		if ( kc == ( ( n + 7 ) << 1 ) ){
			if ( n & 1 ){
				if ( ( K - _t ) & 1 ) putchar ( 'B' );
				else putchar ( 'A' );
				lp ( i, 0, n>>1 ) printf ( "BA" );
				putchar ( '\n' );
			}else{
				lp ( i, 0, n>>1 ) printf ( "BA" );
				putchar ( '\n' );
			}
			return;
		}
	}
	
	fill ( ans+1, ans+1+n, 'A' );
	fill ( cl, cr );
	lp ( i, nk+1, ki ){
//		cerr << i << " : " << a[(i<<1)+kc] << " " << a[(i<<1)+kc] - ( kc & ~1 ) << " " << a[(i<<1)+kc+1] - ( ( kc + 1 ) & ~1 ) << endl;
		fill ( a[(i<<1)+kc] - ( kc & ~1 ), a[(i<<1)+kc+1] - ( ( kc + 1 ) & ~1 ) );
	}
	ans[n+1] = '\0';
	
	printf ( "%s\n", ans+1 );
}

Measured memory_bytes: 4736
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}

int log(int x) {
    int i;
    for(i=0;(1ll<<i)<=x;i++);
    return i;
}
 
int32_t main() {
    fio
    
    cout << fixed << setprecision(15);
    int a,b,m;
    cin >> a >> b >> m;
    int ar[a],br[b];
    int c;
    fff(i,a)
    cin >> ar[i];
    fff(i,b)
    cin >> br[i];
    
    int p=LLONG_MAX,q=LLONG_MAX;
    fff(i,a) {
        if(ar[i]<p)
        p=ar[i];
    }
    fff(i,b) {
        if(br[i]<q)
        q=br[i];
    }
    c=(p+q);
    
    fff(i,m) {
        int x,y,z;
        cin >> x >> y >> z;
        x-=1;y-=1;
        int t= ar[x]+br[y]-z;
        c=min(c,t);
    }
    
    cout << c;
    
	return 0;
    
}

Measured memory_bytes: 10496
n, m = gets.split.map(&:to_i)
# nums は事前に 2 で割る
nums = gets.split.map{ |s| s.to_i >> 1 }

class Array
  def lcm
    self.inject { |a, b| a.lcm(b) }
  end

  # def gcd
  #   self.inject{ |a, b| a.gcd(b) }
  # end
end

count = nums.first.to_s(2).reverse.index("1")

# 全ての num の 2 で割り切れる回数が同じであることを確認
nums.each do |num|
  if count != num.to_s(2).reverse.index("1")
    puts 0
    exit
  end
end

ans = m / nums.lcm
ans += 1 if ans.odd?
ans /= 2
puts ans


Measured memory_bytes: 13196
#include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

int main()
{
int N,M;int ans=0;int count=1;
cin >> N >> M;
for(int i=1;i<N;i++)count*=i;
bool check=false;
vector<int> a(M);
vector<int> b(M);
vector<int> order(N);
for(int i=0;i<N;i++){order.at(i)=i+1;}
for(int i=0;i<M;i++){cin >> a.at(i) >> b.at(i);}
do{
for(int i=0;i<N-1;i++)
{
check=false;
for(int j=0;j<M;j++)
{
if((a.at(j)==order.at(i)&&b.at(j)==order.at(i+1))||(a.at(j)==order.at(i+1)&&b.at(j)==order.at(i))){check=true;break;}
}
if(!check)break;
}
if(check)ans++;
count--;
if(count==0)break;
}while(next_permutation(order.begin(),order.end()));
cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define pq priority_queue
using namespace std;
#define MZ 1000000007
bool life[100005];
vector <int> v[100005];
int ok[100005];
int n,m,gg,ans=0,wtf;
void dfs1(int x)
{
    wtf=x;
    life[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(!life[v[x][i]])
        {
            ans++;
            ok[v[x][i]]=x;
            dfs1(v[x][i]);
            break;
        }
    }
}
void dfs2(int x)
{
    ok[x]=0;
    ans++;
    for(int i=0;i<v[x].size();i++)
    {
        if(!life[v[x][i]])
        {
            ok[x]=v[x][i];
            life[v[x][i]]=1;
            dfs2(v[x][i]);
            break;
        }
    }
}
int main()
{
    int a,b;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&a,&b);
        if(a==b)
            continue;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=1;i<=n;i++)
    {
        if(v[i].size())
        {
            gg=i;
            break;
        }
    }
    ok[gg]=0;
    dfs1(gg);
    dfs2(gg);
    printf("%d\n",ans);
    while(ok[wtf])
    {
        printf("%d ",wtf);
        wtf=ok[wtf];
    }
    printf("%d\n",wtf);
    return 0;
}


Measured memory_bytes: 6784
N, M = map(int, input().split())
A = [''] * N
B = [''] * M

for i in range(N):
    A[i] = input()
for j in range(M):
    B[j] = input()

for i in range(N-M+1):
    for j in range(N-M+1):
        NO = False
        for x in range(M):
            a = A[i+x][j:j+M]
            if a != B[x]:
                NO = True
                break
        if not NO:
            print('Yes')
            exit()

print('No')

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

using namespace std;

#define li long long int

const int N = 5e1 + 3;
const int mod = 1e9 + 7;

int n;
li k;
li a[N][N];
li res[N][N];

void multiply() {
	for (int i = 1; i <= n; i++) {
		res[i][i] = 1;
	}
	li b = k;
	while (b) {
		if (b & 1) {
			li sum[n + 1][n + 1] = {0};
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int k = 1; k <= n; k++) {
						sum[i][j] += a[i][k] * res[k][j] % mod;
						sum[i][j] %= mod;
					}
				}
			}
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					res[i][j] = sum[i][j];
				}
			}
		}
		li sum[n + 1][n + 1] = {0};
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				for (int k = 1; k <= n; k++) {
					sum[i][j] += a[i][k] * a[k][j] % mod;
					sum[i][j] %= mod;
				}
			}
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				a[i][j] = sum[i][j];
			}
		}
		b >>= 1ll;
	}
}

void solve() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> a[i][j];
		}
	}
	multiply();
	li ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			ans += res[i][j];
			ans %= mod;
		}
	}
	cout << ans;
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[5],q=-1;
int main()
{
 for(int i=0;i<5;i++)
 {
 	cin>>a[i];
 }
 for(int i=0;i<5;i++) 
 {
 	for(int j=0;j<5;j++)
    {
    	q=max(q,abs(a[i]-a[j]));
	}
 
 }
 int k;
 cin>>k;
 if(k>=q)
  {
  	cout<<"Yay!"<<endl;
  }
  else
  {
  	cout<<":("<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
ll r[1000], w[1000];
ll rsum = 0;
ll wsum;

bool dp[1005];

void solve() {
    //cout.precision(10);
    rsum = 0;
    wsum = 0;
    for(int i = 0; i < N; i++) {
        cin >> r[i] >> w[i];
        rsum += r[i];
        wsum += w[i];
    }
    for(int i = 1; i < N; i++) {
        if(r[i] > r[0]) {
            swap(r[i], r[0]);
            swap(w[i], w[0]);
        }
    }
    if(r[0] * 2 <= rsum) {
        cout << rsum + wsum << endl;
        return;
    }
    ll W = r[0] - (rsum - r[0]);
    for(int i = 0; i <= W; i++) dp[i] = false;
    dp[0] = true;
    for(int i = 1; i < N; i++) {
        for(int j = W; j >= 0; j--) {
            if(j + w[i] <= W) {
                dp[j+w[i]] |= dp[j];
            }
        }
    }
    ll maxi = 0;
    for(int i = 0; i <= W; i++) {
        if(dp[i]) maxi = i;
    }
    cout << 2 * r[0] + wsum - maxi << endl;
    return;
}

int main() {
    while(cin >> N) {
        if(N == 0) break;
        solve();
    }
}


Measured memory_bytes: 3128
S = input()
cnt = 0
max_cnt = 0
for i in range(len(S)):
  s = S[i]
  if s == 'R':
    cnt += 1
    if cnt > max_cnt:
    	max_cnt = cnt
  else:
    if cnt > max_cnt:
    	max_cnt = cnt
    cnt = 0
print(max_cnt)

Measured memory_bytes: 9032
a=int(input())
b=str(input())
sum=0

riron_sum=b.count('R')*b.count('G')*b.count('B')

for i in range(0,a):
    for n in range(0,a+1):
        j = i+n
        k = j+n
        #print(j)
        #print(k)
        if k>=a:
        	break

        if b[i]!=b[j] and b[j]!=b[k] and b[k]!=b[i]:
                riron_sum-=1

print(riron_sum)

Measured memory_bytes: 9208
#include <stdio.h>
#include <math.h>

double dis(int, int, int *, int *);

int main(void)
{
	int n, p, x[100], y[100], i;
	double max=0;
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%d",&x[i]);
	}
	for (i=0; i<n; i++) {
		scanf("%d",&y[i]);
	}
	for (p=1; p<=3; p++) {
		printf("%f\n",dis(n,p,x,y));
	}
	for (i=0; i<n; i++) {
		if (max < fabs(x[i] - y[i])) max = fabs(x[i] - y[i]);
	}
	printf("%f\n",max);
	return 0;
}

double dis(int n, int p, int *x, int *y)
{
	int i;
	double sum=0;
	
	for (i=0; i<n; i++) {
		sum += pow( fabs( x[i] - y[i] ) , p );
	}
	return pow(sum, 1/(1.0*p));
}	

Measured memory_bytes: 700
#include "bits/stdc++.h"
using namespace std;

int main()
{
	int n, m, x, y;
	vector<int> a, b;
	cin >> n >> m >> x >> y;
	int xmax = x;
	int ymin = y;
	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
		xmax = max(xmax, tmp);
	}
	for (int i = 0; i < m; i++)
	{
		int tmp;
		cin >> tmp;
		b.push_back(tmp);
		ymin = min(ymin, tmp);
	}

	if (xmax < ymin)
	{
		cout << "No War" << endl;
	}
	else
	{
		cout << "War" << endl;
	}
	return 0;
}

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int n;  cin >> n;
  map<int, int> cnt1, cnt2;
  ll ans = 0;
  for (int i = 0; i < n; ++i){
    int ai; cin >> ai;
    int one = i-ai, two = i+ai;
    ans += cnt2[one] + cnt1[two];
    cnt1[one]++, cnt2[two]++;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 37728
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin>>n;
  int br = 0, cur = 1;
  for(int i=1; i<=n; i++)
  {
  	int x; cin>>x;
  	if(x == cur) cur++;
  	else br++;
  }
  if(cur == 1) cout<<"-1\n";
  else cout<<br<<"\n";
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;

int ps[100];

int main() {
  for (int i=0; i<5; i++) {
    scanf("%d", &ps[i]);
  }
  sort(ps, ps+5, greater<int>());

  printf("%d", ps[0]);
  for (int i=1; i<5; i++) {
    printf(" %d", ps[i]);
  }
  puts("");
}

Measured memory_bytes: 2736
#include <stdio.h>

int main() {
  int m, f, r, sum;

  while (1) {
    scanf("%d %d %d", &m, &f, &r);

    if (m == -1 && f == -1 && r == -1) break;

    sum = m + f;
    if (m == -1 || f == -1) {
      printf("F\n");
    } else if (sum >= 80) {
      printf("A\n");
    } else if (sum >= 65) {
      printf("B\n");
    } else if (sum >= 50 || sum >= 30 && r >= 50) {
      printf("C\n");
    } else if (sum >= 30) {
      printf("D\n");
    } else {
      printf("F\n");
    }
  }

  return 0;
}


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

int main(){
    ll n;
    cin >> n;
    ll leng[n];
    rep(i,n){
        cin >> leng[i];
    }
    ll cnt = 0;
    rep(i,n){
        rep(j,n){
            rep(k,n){
                if(leng[i] != leng[j] && leng[j] != leng[k] && leng[i] != leng[k]){
                    ll Max = max(max(leng[i],leng[j]),leng[k]);
                    ll sum = leng[i]+leng[j]+leng[k];
                    ll rest = sum-Max;
                    if(rest > Max){
                        cnt++;
                    }
                }
            }
        }
    }
    cout << cnt/6 << endl;
}

Measured memory_bytes: 3628
l,r=map(int,input().split())

d=[int(i) for i in range(2019)]

a=l%2019
b=r%2019

if a<b:
    if r-l<2019:
        d=d[a:b+1]
    else:
        d=d
elif a>b:
    if r-l<2019:
        d=d[b:a+1]
    else:
        d=d
else:
    d=d
    
ans=2019
for i in range(len(d)):
    for j in range(i+1,len(d)):
        ans=min(ans,(d[i]*d[j])%2019)
print(ans)


Measured memory_bytes: 3064
n = int(input())
s = input()
countw = 0
counte = 0
ans = [0]*n
for i in range(1, n):
  if s[i-1] == "W":
    countw += 1
  if i != n:
    ans[i] += countw
  if s[-i] == "E":
    counte += 1
  ans[n-i-1] += counte

print(min(ans))

Measured memory_bytes: 15288
import sys

s = list(input())
k = int(input())

if len(s)==1:
    if k==1:
        print(0)
    else:
        print(k//2)
    sys.exit()  

x = 0
while True:
    if s[x]!=s[x+1]:
        break
    x += 1
    if x == len(s)-1:
        print(len(s)*k//2)
        sys.exit()

if k==1 or s[0]!=s[-1]:
    x = 0
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
    print(x*k) 
    sys.exit()

if s[0]==s[-1]:
    b = 1
    x = 0
    while True:
        if s[x]==s[x+1]:
            b += 1
            x += 1
        else:
            break
    a = 1
    x = 0
    while True:
        if s[-1-x]==s[-2-x]:
            a += 1
            x += 1
        else:
            break
    x = 0
    for i in range(len(s)-1):
        if s[i]==s[0]:
            continue
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
    print(x*k+((a+b)//2)*(k-1)+a//2+b//2)



Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e5+5;
const int mod=998244353;
int g[N],f[N],ans=0,n,k,a,b;
int poww(int val,int deg)
{
    if(deg<=1)return val;
    int res=poww(val,deg/2);
    res*=res;
    res%=mod;
    if(deg&1)return res*val%mod;
    return res;
}
void init()
{
    f[0]=1;
    g[0]=1;
    for(int i=1;i<=N-5;++i){
        f[i]=f[i-1]*i;
        f[i]%=mod;
        g[i]=poww(f[i],mod-2)%mod;
    }
}
int ckn(int k,int n)
{
    if(k>n)return 0;
    int res=1LL*g[n-k]*g[k]%mod;
    res=(res*f[n])%mod;
    return res;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>a>>b>>k;
    init();
    for(int i=0;i<=n;++i){
        if(i*a>k)break;
        int temp=k-i*a;
        if(temp%b)continue;
        temp/=b;
        int res=ckn(i,n);
        res=(res*ckn(temp,n))%mod;
        ans=(ans+res)%mod;
    }
    cout<<ans;
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

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


void solve(){
  int N;
  int a[200000 + 5];

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

  int now = 0;
  rep(i, N){
    if(a[i] == now + 1)
      now++;
  }

  if(now == 0){
    cout << -1 << endl;
  }else{
    cout << N - now << endl;
  }
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
int main(){
    double x1,x2;
    double y1,y2;

    scanf("%lf %lf",&x1,&y1);
    scanf("%lf %lf",&x2,&y2);

    x1-=x2;
    y1-=y2;

    printf("%lf\n",sqrt(x1*x1+y1*y1));

    return 0;
}


Measured memory_bytes: 2112
import itertools

s = input()

tfs = []
tfset = (True, False)
for i in itertools.product(tfset, repeat=len(s)-1):
    tfs.append(i)

allsum = 0
for tf in tfs:
    sum = 0
    digit = 0
    for i, seed in enumerate(tf):
        if seed:
            sum += int(s[digit:i+1])
            digit = i+1
    sum += int(s[digit:])
    allsum += sum

print(allsum)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int main(){
  int n,k;
  cin >> n>>k;
  if(k==1){
    cout << 0 << endl;
    return 0;
  }else{
    cout << n-k << endl;
  }
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    ll a,b;
    char op;
    cin >> a >> op >> b;
    if(op == '+'){
        cout << a + b << endl;
        return 0;
    }else{
        cout << a - b << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
/*
O(ElogV)
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

constexpr int MAX=1<<30;
constexpr ll INF=1LL<<62;
constexpr int MOD=1e9+7;



template<typename T >
struct edge {
  int to;
  T cost;
  edge()=default;
  edge(int to, T cost) : to(to), cost(cost) {}

};


template<class T>
vector<T> dijkstra(vector< vector<edge<T>> > &g,int s,const T inf,const T zero){
    vector<T> dist(g.size(),inf);
    using pti=pair<T,int>;
    priority_queue<pti,vector<pti>,greater<pti>> que;
    dist[s]=zero;
    que.emplace(dist[s],s);
    while(!que.empty()){
      T cost;
      int idx;
      tie(cost,idx)=que.top();
      que.pop();
      if(dist[idx]<cost) continue;
      for(auto &e:g[idx]){
        auto next_cost=cost+e.cost;
        if(dist[e.to]<=next_cost) continue;
        dist[e.to]=next_cost;
        que.emplace(dist[e.to],e.to);
      }
    }
    return dist;
}

signed main(){
  int v,e,r;
  cin>>v>>e>>r;
  vector< vector<edge<ll>> > g(v);
  for(int i=0;i<e;i++){
    int s,t,d;
    cin>>s>>t>>d;
    g[s].emplace_back(t,d);
  }
  auto V=dijkstra<ll>(g,r,INF,0);
  for(int i=0;i<v;i++){
    if(V[i]==INF) cout<<"INF"<<endl;
    else cout<<V[i]<<endl;
  }
}


Measured memory_bytes: 19508
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T.sort()
ans = 0
bus = 0
bus_start = 0
passengers = 0
for t in T:
    if passengers == 0:
        bus_start = t
    if bus_start <= t <= bus_start + K:
        passengers += 1
    else:
        passengers = 1
        bus += 1
        bus_start = t
    if passengers == C:
        bus += 1
        passengers = 0
if passengers > 0:
    bus += 1
print(bus)

Measured memory_bytes: 7488
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n; cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		cnt += i & 1;
	}
	printf("%.10f\n", (double)cnt / n);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n,m;cin>>n>>m;
    vector<pair<ll,ll>> p1(n),p2(m);
    rep(i,n) cin>>p1[i].first>>p1[i].second;
    rep(i,m) cin>>p2[i].first>>p2[i].second;
    
    rep(i,n){
        int res=-1;
        ll buf2=1e+10;
        rep(j,m){
            ll x=p1[i].first,y=p1[i].second,nx=p2[j].first,ny=p2[j].second;
            ll buf=abs(x-nx)+abs(y-ny);
            //cout<<buf<<endl;
            if(chmin(buf2,buf)){
                res=j;
            }
        }
        cout<<res+1<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;

int main(){
	cin >> n;
	for(int i=0;i<20;i++) if((1<<i) == n) { puts("No"); return 0;}
	if(n%2 == 1){
		puts("Yes");
		if(n%4 == 3){
			for(int i=1;i<=2*n-1;i++) cout << i << " " << i+1 << endl;
		}
		else{
			vector<int>vi;
			for(int i=1;i<=n-2;i++) vi.pb(i);
			for(int i=1;i<=n-2;i++) vi.pb(i+n);
			cout << n-1 << " " << n << endl;
			cout << n << " " << 1 << endl;
			cout << 1 << " " << 2*n-1 << endl;
			cout << 2*n-1 << " " << 2*n << endl;
			for(int i=1;i<vi.size();i++) cout << vi[i-1] << " " << vi[i] << endl;
		}
	}
	else if(n%4 == 2){
		puts("Yes");
		{
			vector<int>vi;
			for(int i=1;i<=n-3;i++) vi.pb(i);
			for(int i=1;i<=n-3;i++) vi.pb(i+n);
			cout << n-2 << " " << n-1 << endl;
			cout << n-1 << " " << 1 << endl;
			cout << 1 << " " << 2*n-2 << endl;
			cout << 2*n-2 << " " << 2*n-1 << endl;
			for(int i=1;i<vi.size();i++) cout << vi[i-1] << " " << vi[i] << endl;
		}
		cout << n << " " << n-1 << endl;
		cout << 2 << " " << 2*n << endl;
	}
	else{
	    puts("Yes");
		vector<int>vec;
		vec.pb(n-1); vec.pb(n^(n-1));
		for(int i=1;i<=n-2;i++) if(i != (n^(n-1))) vec.pb(i);
		for(int i=0;i<n-2;i++) cout << vec[i] << " " << vec[i+1] << endl;
		cout << vec[n-2] << " " << vec[0]+n << endl;
		for(int i=0;i<n-2;i++) cout << vec[i]+n << " " << vec[i+1]+n << endl;
		cout << n << " " << vec[0] << endl;
		cout << vec[1] << " " << 2*n << endl;
	}
}


Measured memory_bytes: 3700
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
int read(char *s){
	R int len=0;R char ch;while(((ch=getc())>'9'||ch<'0'));
	for(s[++len]=ch;(ch=getc())>='0'&&ch<='9';s[++len]=ch);
	return s[len+1]='\0',len;
}
const int N=10005;
char s[N],t[N];int a[N],b[N],q[N],st[N],h,top,res;
int n,m;
void calc(){
	top=0,h=0;
	fp(i,1,n)st[++top]=0;
	fp(i,1,n-1)!b[i]&&b[i+1]?st[++top]=i:0;
	fp(i,1,n)st[++top]=n;
	fp(i,1,n-1)!a[i]&&a[i+1]?q[++h]=i:0;
	int mn=0x3f3f3f3f,now;
	fp(i,1,top-n+1){
		now=0;
		fp(j,1,i-1)if(st[j])now+=st[j];
		fp(j,0,h-1)now+=abs(q[j+1]-st[i+j]);
		for(R int j=h;st[i+j]!=n;++j)now+=n-st[i+j];
		cmin(mn,now);
	}
	res+=mn;
}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),read(s),read(t);
	fp(i,1,n)a[i]=s[i]-'0',b[i]=t[i]-'0';
	if(n==1&&a[1]!=b[1])return puts("1"),0;
	if(n==2&&a[1]!=b[1]&&a[1]==a[2]&&b[1]==b[2])return puts("2"),0;
	calc();
	fp(i,1,n)a[i]^=1,b[i]^=1;
	calc();
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

const int MAX_N = 100;
const int MAX_LEN = 10;
int N;
char W[MAX_N][MAX_LEN+1];

void _main() {
  cin >> N;
  rep(i, 0, N) cin >> W[i];

  bool f = true;
  set<string> st;
  char last = W[0][0];
  rep(i, 0, N) {
    if (st.count(W[i]) == 1 || W[i][0] != last) {
      f = false;
      break;
    }
    st.insert(W[i]);
    last = W[i][strlen(W[i])-1];
  }

  if (f) cout << "Yes" << "\n";
  else cout << "No" << "\n";
}

Measured memory_bytes: 256
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,x,y) for(int i=x;i<y;i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int a,b,c;
    cin>>a>>b>>c;
    bool fl=0;
    for(int i=a;i<=10000;i+=a){
        if(i%b==c)fl=1;
    }
    cout<<((fl)?"YES":"NO");

    return 0;
}


Measured memory_bytes: 3584
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

#define INF 100000000

using namespace std;

typedef pair<int,int> paii;

int c, n, m, s, d; 
int fare[1000][1000];
int vtx[1000][1000];
	
int solve()
{
	queue<paii> qu;
	CLR(vtx);
	
	FOR(i, 1, n+1)
	{
		FOR(j, 0, c+1)
		{
			if( i != s )
				vtx[i][j] = INF;
		}
	}
	
	qu.push(paii(s, c));
	
	while( !qu.empty() )
	{
		int nowv = qu.front().first;
		int nowt = qu.front().second;
		qu.pop();
		
		FOR(j, 1, n+1)
		{
			if(( j != nowv) && (fare[nowv][j] != 0))
			{
				if( vtx[j][nowt] > vtx[nowv][nowt] + fare[nowv][j] )
				{
					vtx[j][nowt] = vtx[nowv][nowt] + fare[nowv][j];
					qu.push(paii(j,nowt));
				}
				
				if( (nowt > 0) && (vtx[j][nowt-1] > vtx[nowv][nowt] + fare[nowv][j]/2) )
				{
					vtx[j][nowt-1] = vtx[nowv][nowt] + fare[nowv][j]/2;
					qu.push(paii(j,nowt-1));
				}
			}
		}
	}
	
	int res = INF;
	
	FOR(i, 0, c)
	{
		res = min(res, vtx[d][i]);
	}
	
	return res;
}

int main()
{
	while(cin >> c >> n >> m >> s >> d, (c||n||m||s||d))
	{
		CLR(fare);
		
		FOR(i, 0, m)
		{
			int a, b, f;
			cin >> a >> b >> f;
			
			fare[a][b] = f;
			fare[b][a] = f;
		}
		
		cout << solve() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 9040
# coding: utf-8
N = int(input())
words = []
for i in range(N):
    w = input()
    if i == 0:
        words.append(w)
    else:
        if w[0] == l and w not in words:
            words.append(w)
        else:
            print("No")
            exit()
    l = w[-1]
print("Yes")
    

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

int main(){
  int N,maxA=0;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i!=j){
        maxA=max(maxA,abs(A.at(i)-A.at(j)));
      }
    }
  }
  cout << maxA << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);}

ll calc(ll a, ll b) {
    if (a == b) return a;
    if (a > b) swap(a, b);
    ll c = (b-1)/a;
    return 2*c*a + calc(a, b-c*a);
}

int main() {
    ll n, x;
    cin >> n >> x;
    ll ans = n + calc(n-x, x);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; // [9,223,372,036,854,775,807 to -9.....808] 19 digits
typedef long double ld;
#define inc(i, a, b) for (long long int i = a; i <= b; i++)
#define dec(i, a, b) for (long long int i = a; i >= b; i--)
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define lv vector<ll>
#define cv vector<char>
#define dv vector<ld>
#define rall(c) (c).rbegin(), (c).rend()
#define lpr pair<ll, ll>
#define mp make_pair
#define cin(c) \
    ll c;      \
    cin >> c;
#define lmap unordered_map<ll, ll>
#define vinp(a, n) \
    inc(i, 1, n)   \
    {              \
        cin(k);    \
        a.pb(k);   \
    }
#define LIM 1000000007
#define F first
#define S second
#define fr(i, n) inc(i, 0, n - 1)
#define fri(n, a) \
    inc(i, 0, n - 1) { cin >> a[i]; }
#define debug(p) cout << p;
#define umap unordered_map
#define uset unordered_set
#define fill(a, val, n) \
    inc(i, 0, n - 1) { a[i] = val; }
void i_love_Accepted()
{
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a;
}   
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        i_love_Accepted();
        cout<<"\n";
    } 
}


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

#define INF INT_MAX
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,a,n) for(int i=0;i<n;i++)

using namespace std;

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

	char s;
	cin >> s;
	char ans;
	if(s == 'A'){
		ans = 'T';
	}else if(s == 'G'){
		ans = 'C';
	}else if(s == 'T'){
		ans = 'A';
	}else{
		ans = 'G';
	}
	cout << ans << endl;
   
	return 0;
}


Measured memory_bytes: 256