akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;

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

    vector<pair<int,int>> v[m];

    int s, t, e;
    while(scanf("%d %d %d", &s, &t, &e), s+t+e){
        v[--t].push_back({--s,e});
    }

    int l;
    scanf("%d", &l);

    for(int i = 0; i < l; i++){
        vector<int> sal(n), b(m);
        for(int i = 0; i < m; i++)  scanf("%d", b.begin()+i);
        for(int i = 0; i < m; i++){
            for(int j = 0; j < v[i].size(); j++){
                sal[v[i][j].first] += v[i][j].second * b[i];
            }
        }
        for(int i = 0; i < n; i++)  cout << sal[i] << " \n"[i == n-1];
    }
    
    return 0;
}


Measured memory_bytes: 4276
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
	int a, b,ans=1;
	cin >> a >> b ;
	for (int i = 0; i < a; i++) {
		if (ans * 2 < ans + b) ans = ans * 2;
		else ans = ans + b;
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public 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 (a < b && b < c){
			System.out.println("Yes");
		} else {
			System.out.println("No");
			
		}
	}

}

Measured memory_bytes: 26192
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	for(ll i=0; i<k; i++) {
		if((i*3)%k==i) {
			if(n<i) continue;
			ll cnt=(n-i)/k+1;
			if(i==0) cnt--;
			ans+=cnt*cnt*cnt;
		} else continue;
	}
	cout<<ans<<endl;
	return 0;
}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    string s;
    cin >> s;
    bool ok = 1;
    FOR(i, 1, s.size() - 1)
        if(s[i] == s[i - 1]) ok = 0;
    if(ok) cout << "Good";
    else cout << "Bad";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL               long long
#define PB               push_back
using namespace std;
int main(){
    string s;cin>>s;
    for (long unsigned int i=0;i<s.length();i++){
        if ((i%2 && s[i]=='R') || ((i%2==0) && s[i]=='L')) {
            cout <<"No"; 
            return 0;
        }
    }
     cout <<"Yes"; 
}

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

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++)
  {
    cin >> c[i];
  }
  
  int ans=0;

  for (int i = 0; i < n; i++)
  {
    if(v[i]>c[i]){
      ans+=v[i]-c[i];
    }
  } 
  
  cout << ans << endl;
}

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

int main() {
  ll n, m;
  cin >> n >> m;

  ll total = 0;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    total += a[i];
  }

  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    if (total <= a[i] * 4 * m) {
      cnt++;
    }
  }
  
  if (cnt >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
	ll N,M;
	cin >> N;
	vector<ll> d(N);
	for(ll i=0;i<N;i++)	cin >> d[i];
	sort(d.begin(),d.end());
	cin >> M;
	vector<ll> t(M);
	for(ll i=0;i<M;i++) cin >> t[i];
	sort(t.begin(),t.end());
	if(N<M)	cout << "NO\n";
	else{
		ll j = M;
		for(ll i=N-1;i>=0;i--){
			if(d[i]==t[j-1]){
				j--;
				if(j==0){
					cout << "YES\n";
					return 0;
				}
			}
		}
		cout << "NO\n";
	}
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <fstream>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (b - a + 1 <= 2*c){
        for (int i = a; i<=b; i++){
            cout << i << '\n';
        }
    }
    else{
        for (int i = a; i<=a+c - 1; i++){
            cout << i << '\n';
        }
        for (int i = b-c+1; i<=b; i++){
            cout << i << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 256
%:pragma GCC optimize("Ofast")
%:pragma GCC target("sse3","sse2","sse")
%:pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
%:pragma GCC target("f16c")
%:pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
%:pragma GCC diagnostic error "-fwhole-program"
%:pragma GCC diagnostic error "-fcse-skip-blocks"
%:pragma GCC diagnostic error "-funsafe-loop-optimizations"
%:pragma GCC diagnostic error "-std=c++14"

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>

using namespace std;

#define Whats(x) cout<<#x<<" is "<<x<<endl
#define Divhe() cout<<">>>>>>>>>>>>>>>"<<endl
#define Divshe() cout<<"<<<<<<<<<<<<<<<"<<endl
#define Oops() cout<<"!!!!!!!!!!!!!!!"<<endl

/*
-<Unlimited Blade Works>-
*/

const int N=5200;
const int MOD=1e9+7;

int Mul(int a,int b)
{
	unsigned long long x=(long long)a*b;
	unsigned xh=(unsigned)(x>>32),xl=(unsigned)x,d,m;
	asm
		(
		 "divl %4;\n\t"
		 :"=a"(d),"=d"(m)
		 :"d"(xh),"a"(xl),"r"(MOD)
		);
	return m;
}

int U(int x,int y)
{
	return ((x+=y)>=MOD)?(x-MOD):x;
}

void SU(int& x,int y)
{
	((x+=y)>=MOD)?(x-=MOD):0;
}

int D(int x,int y)
{
	return ((x-=y)<0)?(x+MOD):x;
}

void SD(int& x,int y)
{
	((x-=y)<0)?(x+=MOD):0;
}

int n;
vector<int> G[N];

int sz[N],dp[N][N],cm[N];

void Dfs(int u,int fa=0)
{
	sz[u]=dp[u][1]=1;
	for(int v:G[u])if(v!=fa)
	{
		Dfs(v,u);
		int sm=0;
		for(int i=2;i<=sz[v];i+=2)
			SD(sm,Mul(dp[v][i],cm[i>>1]));
		static int x[N];
		int s=sz[u]+sz[v];
		for(int i=sz[u];i;--i)
			x[i]=Mul(dp[u][i],sm);
		for(int i=sz[u]+1;i<=s;++i)
			x[i]=0;
		for(int i=sz[u];i;--i)
			for(int j=sz[v];j;--j)
				SU(x[i+j],Mul(dp[u][i],dp[v][j]));
		for(int i=s;i;--i)
			dp[u][i]=x[i];
		sz[u]=s;
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1,u,v;i<n;++i)
	{
		scanf("%d%d",&u,&v);
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}

	cm[1]=1;
	for(int i=2;i<=n;++i)
		cm[i]=Mul(cm[i-1],(i<<1)-1);

	Dfs(1);

	int ans=0;
	for(int i=2;i<=n;i+=2)
		SU(ans,Mul(dp[1][i],cm[i>>1]));
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 102528
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int kurikaeshi;
	vector<int> answer;
	cin >> kurikaeshi;
	for (int variable = 0;variable < kurikaeshi;++variable) {
		int X, Y;
		cin >> X >> Y;
		vector< vector<int> > heian(X + 1, vector<int>(Y + 1));
		for (int i = 0;i <= X;++i)
			for (int j = 0;j <= Y;++j)
				heian[i][j] = 0;
		int n;
		cin >> n;
		//????????§????????????????????¢???????????????????????¨????¨????????????????????????????????????????????????????????????¢???????????????????????\??????????????????
		for (int i = 0;i < n;++i) {
			int x1, y1, x2, y2;
			cin >> x1 >> y1 >> x2 >> y2;
			if (x1 == x2) {
				if (y1 > y2) {
					heian[x1][y1] = heian[x1][y1] == -2 ? -3 : -1;
				}
				else {
					heian[x2][y2] = heian[x2][y2] == -2 ? -3 : -1;
				}
			}
			if (y1 == y2) {
				if (x1 > x2) {
					heian[x1][y1] = heian[x1][y1] == -1 ? -3 : -2;
				}
				else {
					heian[x2][y2] = heian[x2][y2] == -1 ? -3 : -2;
				}
			}
		}
			for (int j = 0;j <= X;++j) {
				if (heian[j][0] == -2) {
					for (int k = j;k <= X;++k) heian[k][0] = 0;
					break;
				}
				else {
					heian[j][0] = 1;
				}
			}
			for (int j = 0;j <= Y;++j) {
				if (heian[0][j] == -1) {
					for (int k = j;k <= Y;++k) heian[0][k] = 0;
					break;
				}
				else {
					heian[0][j] = 1;
				}
			}
			for (int xzahyou = 1;xzahyou <= X;++xzahyou) {
				for (int yzahyou = 1;yzahyou <= Y;++yzahyou) {
					switch (heian[xzahyou][yzahyou]) {
					case -1:
						heian[xzahyou][yzahyou] = heian[xzahyou-1][yzahyou];
						continue;
					case -2:
						heian[xzahyou][yzahyou] = heian[xzahyou][yzahyou-1];
						continue;
					case -3:
						heian[xzahyou][yzahyou] = 0;
						continue;
					default:
						heian[xzahyou][yzahyou] = heian[xzahyou - 1][yzahyou] + heian[xzahyou][yzahyou - 1];
						continue;
					}
				}
			}
			answer.push_back(heian[X][Y]);
	}
	for (int i = 0;i < kurikaeshi;++i) {
		if (answer[i] == 0) {
			cout << "Miserable Hokusai!" << endl;
		}
		else {
			cout << answer[i] << endl;
		}
	}
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}


ll INF = 1e18;

int n;
vector<ll> a;

// ll exp(int a, int b){
//     if(!b) return 1LL;
//     ll temp = exp(a, b/2);
//     if(b%2) return temp * temp * a;
//     return temp * temp;
// }

void solve(){
    cin >> n;
    n++;
    a = vector<ll>(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    vector<ll> m(n);
    m[0] = 1;
    //cout << m[0] << " ";
    for(int i = 1; i < n; i++){
        if(a[i-1] > m[i-1]){
            cout << "-1\n";
            return;
        }
        if((m[i-1]-a[i-1]) > INF/2){
            m[i] = INF;
        }
        else{
            m[i] = (m[i-1]-a[i-1])*2LL;
        }
        //cout << m[i] << " ";
    }//cout << '\n';

    if(a[n-1] > m[n-1]){
        cout << "-1\n";
        return;
    }

    vector<ll> dp(n);
    dp[n-1] = a[n-1];
    for(int i = n-2; i >= 0; i--){
        if((dp[i+1]+1)/2LL + a[i] > m[i]){
            cout << "-1\n";
            return;
        }
        
        dp[i] = min(m[i], dp[i+1]+a[i]);
    }

    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += dp[i];
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 5576
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N, M;
int co[100010], wa[100010];


signed main(){
    cin >> N >> M;
    rep(i, 0, M){
        int p;
        string S;
        cin >> p >> S;
        if(S == "AC") co[p] = 1;
        else if(S == "WA" and co[p] != 1) wa[p]++;
    }

    int c = 0, w = 0;
    repe(i, 1, N){
        c += co[i];
        if(co[i] == 1) w += wa[i];
    }

    cout << c << ' ' << w << endl;

    return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>

int main(void) {                                                                
    int w, n, i, src, dest;                                                     
    int a[30], b[30], x[30];                                                    
                                                                                
    scanf("%d", &w);                                                            
    scanf("%d", &n);                                                            
    for (i = 0; i < n; i++) {                                                   
        scanf("%d,%d", &a[i], &b[i]);                                           
    }                                                                           
    for (src = 1; src <= w; src++) {                                            
        dest = src;                                                             
        i = 0;                                                                  
        while (i < n) {                                                         
            if (dest == a[i])                                                   
                dest = b[i];                                                    
            else if (dest == b[i])                                              
                dest = a[i];                                                    
            i++;                                                                
        }                                                                       
        x[dest] = src;                                                          
    }                                                                           
    for (src = 1; src <= w; src++)                                              
        printf("%d\n", x[src]);                                                 
                                                                                
    return 0;                                                                   
}

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

int n,k,ans=1,mn = 100000;
void square(int ans, int op){
	if(op == n){
		if(ans < mn)
			mn = ans;
	}
	else{
		square(ans * 2, op + 1);
		square(ans + k, op + 1);
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>k;
	square(ans, 0);
	cout<<mn;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#define ll long long
#define add push_back
 
using namespace std; 


int main() {

    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);

    int t;  t = 1; //cin >> t;
    while(t--){
        int n; int d; cin >> n >> d;
        int answ = 0;
        for(int i = 0; i < n; i++){
            double x,y; cin >> x >> y;
            if((double)sqrt(x*x + y*y) <= d) answ++;
        }
        cout << answ << endl;
    }
    return 0;
}

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

using namespace std;

struct Node {
    int key;
    Node *left, *right;
};
Node *root, *NIL;

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

        Node *x = root;
        while(true) {
            if(k < x->key) {
                if(x->left == NIL) {
                    x->left = z;
                    break;
                }
                else x = x->left;
            }else {
                if(x->right == NIL) {
                    x->right = z;
                    break;
                }
                else x = x->right;
            }
        }
    }
}

void inorder(Node *node) {
    if(node == NIL) return;
    inorder(node->left);
    printf(" %d", node->key);
    inorder(node->right);
}

void preorder(Node *node) {
    if(node == NIL) return;
    printf(" %d", node->key);
    preorder(node->left);
    preorder(node->right);
}

int main()
{

    int n, x;
    string str;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        cin >> str;
        if(str == "insert") {
            scanf("%d", &x);
            insert(x);
        }else if(str == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;

  /*
    int n, x;
    const char *str;
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
        scanf("%s", str);
        if(strcmp(str, "insert") == 0) {
            scanf("%d", &x);
            insert(x);
        }else if(strcmp(str, "print") == 0) {

            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
    */
}

Measured memory_bytes: 18744
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  int N;
  cin >> N;
   vector<ll>A(N, 0);
   for(int i=0; i < N; i++)
     cin >> A[i];
   ll ans = 0;
   for(int i=0; i < N; i++){
     for(int j=i+1; j < N; j++){
       ans = max(ans, abs(A[i]-A[j]));
     }
   }
   cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
DIV7 = 10**9 + 7
DIV7_5_LIST = (1..31).select do |i|
  (DIV7 - 2) & (1 << (i - 1)) != 0
end

# n! mod (10^9+7)
FACT_MOD7 = []
# {n!}^(-1) mod (10^9+7)
INV_FACT_MOD7 = []

def make_fact_mod7(n)
  # (a * b) mod m = (a mod m) * (b mod m)
  FACT_MOD7[0] = 1
  FACT_MOD7[1] = 1
  (2..n).each do |i|
    FACT_MOD7[i] = (FACT_MOD7[i - 1] * i) % DIV7
  end
end

def make_inv_fact_mod7(n)
  INV_FACT_MOD7[0] = 1
  INV_FACT_MOD7[1] = 1
  (2..n).each do |i|
    INV_FACT_MOD7[i] = (INV_FACT_MOD7[i - 1] * inv_mod(i)) % DIV7
  end
end

def inv_mod(n)
  bq = [1, n]
  (2..31).each do |i|
    bq[i] = (bq[i - 1]**2) % DIV7
  end
  return DIV7_5_LIST.inject(1) do |acc, num|
    (acc * bq[num]) % DIV7
  end
end

def permutation(height, width)
  return FACT_MOD7[height + width - 2] *
         INV_FACT_MOD7[height - 1] *
         INV_FACT_MOD7[width - 1] %
         DIV7
end

h, w, a, b = gets.split.map(&:to_i)

make_fact_mod7(h + w)
make_inv_fact_mod7([h, w].max)

total = ((b + 1)..w).map do |x|
  permutation(h - a, x) * permutation(a, (w - x + 1))
end.inject(&:+)
puts total % DIV7


Measured memory_bytes: 5212
S = input()


def solve(current='', index=0):
    if index is len(S) - 1:
        return eval(current + S[index])
    return solve(current + S[index], index + 1) + solve(current + S[index] + '+', index + 1)


def solve2():
    total = 0
    for source in range(1 << (len(S) - 1)):
        # in binary '1' means '+'
        # 125 ->  1 (source bit:0 ) + 2 + '(+ if (source bit: 1) & 1)
        current = ''
        for i, s in enumerate(S):
            current = current + s
            if (source >> i) & 1:
                total += int(current)
                current = ''
        total += int(current)
    return total

print(solve2())


Measured memory_bytes: 3064
H, W, A, B = gets.split.map(&:to_i)
MOD = 1_000_000_007

def extended_gcd(a, b)
  r0, r = a.abs, b.abs
  x, x0, y, y0 = 0, 1, 1, 0
  while r != 0
    r0, (q, r) = r, r0.divmod(r)
    x, x0 = x0 - q*x, x
    y, y0 = y0 - q*y, y
  end
  [r0, x0 * (a < 0 ? -1 : 1)]
end

def mod_inv(n)
  g, x = extended_gcd(n, MOD)
  x % MOD
end

@f = [1, 1]; M = H + W
(2 .. M).each{|n| @f[n] = @f[n - 1] * n % MOD}
@fi = []; @fi[M] = mod_inv(@f[M])
M.downto(1){|n| @fi[n - 1] = @fi[n] * n % MOD}

def mod_c(a, b)
  @f[a] * @fi[a - b] * @fi[b] % MOD
end

def sq(h, w)
  return 1 if h * w == 0
  mod_c(h + w, h)
end

ans = (1 .. [H - A, W - B].min).inject(0) do |s, n|
  (s + sq(H - (A + n), B + n - 1) * sq(A + n - 1, W - (B + n))) % MOD
end
puts ans

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

int main()
{
  int a,b,n;
  cin>>n>>a>>b;
  if((b-a)%2==1)
  {
    cout<<"Borys"<<endl;
    return 0;
  }
  else
  {
    cout<<"Alice"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    string n;
    int k;
    cin >> n >> k;
    int m=n.size();
    
    
    set<int> D;
    rep(i,k){
        int tmp;
        cin >> tmp;
        D.insert(tmp);
    }

    vector<int>U(0);
    for(int i=0; i<=9; i++) if(D.count(i)==0) U.push_back(i);

    vector<int> ans(0);
    int pos,use;
    int flag =true;
    for(pos=0; pos<m; pos++){
        int make = n[pos]-'0';
        auto iter =lower_bound(ALL(U), make);
        if(iter==U.end()) {
            flag=false;
            pos++;
            break;
        }
        else {
            use = *iter;
        }
        ans.push_back(use);
        if(use>make) {
        pos++;
        break;
        }
    }

    for(;pos<m;pos++){
        ans.push_back(U[0]);
    }

    if(flag){
        rep(i,ans.size()) cout << ans[i];cout << endl;
    }else{
        if(U[0]==0) {cout << U[1];rep(i,m) cout << U[0];cout << endl;}
        else {rep(i,m+1) cout << U[0];cout << endl;}
    }

    return 0;
}

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

int main(){
	int N;
	cin >> N;
	int price[N];
	int ans = 0;
	for(int i = 0; i < N; i++){
		cin >> price[i];
		ans += price[i];
	}
	int maxp = price[0];
	for(int i = 0; i < N; i++)
		maxp = max(maxp, price[i]);
	ans -= maxp/2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  ll N, A, B;

  cin >> N >> A >> B;

  if((A-B)%2==0) cout << "Alice"<< endl;
  else cout << "Borys" << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if (a > b){
        printf("a > b\n");
        
    }
        else if(a < b){
            printf("a < b\n");
        }else {
            printf("a == b\n");
            return 0;
        }
    
}


Measured memory_bytes: 2060
import java.util.*;

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

    String str = sc.nextLine();

    String[] strArray = str.split(" ");

    int cntFive = 0;
    int cntSeven = 0;
	
    for (int i = 0; i < strArray.length; i++){
      if(!strArray[i].equals("5") && !strArray[i].equals("7")){
        System.out.print("NO");
        return;
      }else{
        if(strArray[i].equals("5")){
          cntFive++;
        }else{
          cntSeven++;
        }
      }
    }
    if(cntFive != 2 || cntSeven != 1){
        System.out.print("NO");
    }else{
        System.out.print("YES");
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

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

    int N = D % 10;
    if(N == 0 || N == 1 || N == 6 || N == 8) cout << "pon" << endl;
    else if(N == 3) cout << "bon" << endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;

int main() {
	string S;
	int ans = 1 << 30;
	cin >> S;
	rep(i, 26) {
		string s = S;
		int cnt = 0;
		while (1) {
			string t = "";
			bool ok = 1;
			rep(j, s.size()) {
				if (s[j] != 'a' + i) {
					ok = 0;
					break;
				}
			}
			if (ok) break;
			rep(j, s.size() - 1) {
				if (s[j] == 'a' + i || s[j + 1] == 'a' + i) t.push_back('a' + i);
				else t.push_back(s[j]);
			}
			s = t;
			cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# Python3 program to implement Disjoint Set Data 
# Structure. 
  
class DisjSet: 
    def __init__(self, n): 
        # Constructor to create and 
        # initialize sets of n items 
        self.rank = [1] * n 
        self.parent = [i for i in range(n)] 
  
  
    # Finds set of given item x 
    def find(self, x): 
          
        # Finds the representative of the set 
        # that x is an element of 
        if (self.parent[x] != x): 
              
            # if x is not the parent of itself 
            # Then x is not the representative of 
            # its set, 
            self.parent[x] = self.find(self.parent[x]) 
              
            # so we recursively call Find on its parent 
            # and move i's node directly under the 
            # representative of this set 
  
        return self.parent[x] 
  
  
    # Do union of two sets represented 
    # by x and y. 
    def Union(self, x, y): 
          
        # Find current sets of x and y 
        xset = self.find(x) 
        yset = self.find(y) 
  
        # If they are already in same set 
        if xset == yset: 
            return
  
        # Put smaller ranked item under 
        # bigger ranked item if ranks are 
        # different 
        if self.rank[xset] < self.rank[yset]: 
            self.parent[xset] = yset 
  
        elif self.rank[xset] > self.rank[yset]: 
            self.parent[yset] = xset 
  
        # If ranks are same, then move y under 
        # x (doesn't matter which one goes where) 
        # and increment rank of x's tree 
        else: 
            self.parent[yset] = xset 
            self.rank[xset] = self.rank[xset] + 1
  
# Driver code 
'''obj = DisjSet(5) 
obj.Union(0, 2) 
obj.Union(4, 2) 
obj.Union(3, 1) 
if obj.find(4) == obj.find(0): 
    print('Yes') '''
n,m=map(int,input().split())
obj = DisjSet(n)
for i in range(m):
    a,b=map(int,input().split())
    obj.Union(a-1,b-1) 
c=0
l1=[0]*n
for i in range(n):
    l1[obj.find(i)]+=1
print(max(l1))

Measured memory_bytes: 20196
#include <bits/stdc++.h>
#define llong long long int
#define IOI_GOLD ios_base::sync_with_stdio(0); cin.tie(); cout.tie()
using namespace std;

int main(){
IOI_GOLD;
int a, b, c;
cin >> a >> b >> c;
if((c - abs(a-b)) >= 0){
    cout << abs(c - abs(a-b));
}
else{
    cout << 0;
}
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        String line = sc.next();
        
        int happy = 0;
        for(int i = 0 ; i < N-1; i++){
            if( line.charAt(i) == line.charAt(i+1) ) happy++;
        }
        
        int ans = Math.min(happy + 2 * K ,N-1);
        System.out.println(ans);
    }
}

Measured memory_bytes: 25940
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
static const int MAX_D = 200;
static const int MAX_N = 200;
static const int INF = INT_MAX;

int D, N;
int T[MAX_D];
int A[MAX_N], B[MAX_N], C[MAX_N];
int max_c[MAX_D], min_c[MAX_D];
int memo[2][2][MAX_D];

int main(){
	cin >> D >> N;
	for(int i = 0; i < D; i++) cin >> T[i];
	for(int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i];
	
	fill(max_c, max_c + D, 0);
	fill(min_c, min_c + D, INF);
	fill(memo[0][0], memo[2][0], 0);
	for(int i = 0; i < D; i++){
		for(int j = 0; j < N; j++){
			if(A[j] <= T[i] && B[j] >= T[i]){
				max_c[i] = max(max_c[i], C[j]);
				min_c[i] = min(min_c[i], C[j]);
			}
		}
	}
	for(int i = 1; i < D; i++){
		memo[0][0][i] = max(memo[0][0][i - 1], memo[1][0][i - 1]) + abs(max_c[i] - max_c[i - 1]);
		memo[0][1][i] = max(memo[0][0][i - 1], memo[1][0][i - 1]) + abs(min_c[i] - max_c[i - 1]);
		memo[1][0][i] = max(memo[0][1][i - 1], memo[1][1][i - 1]) + abs(max_c[i] - min_c[i - 1]);
		memo[1][1][i] = max(memo[0][1][i - 1], memo[1][1][i - 1]) + abs(min_c[i] - min_c[i - 1]);
	}
	int ans = 0;
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 2; j++){
			ans = max(ans, memo[i][j][D - 1]);
		}
	}
	
	cout << ans << endl;
	return 0;
}



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

int main(void){
    ll N,M,sum=0;
    cin >> N >> M;
    vector<ll> A(M);
    for(int i = 0; i<M; i++){
        cin >> A[i];
        sum+=A[i];
    }
    if(sum<=N){
        cout << N-sum << endl;
    }
    else{
        cout << -1 << endl;
    }
    
}


Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
static const int INFTY = (1 << 21);

class Edge{
public:
	int from, to, cost;
	int backedge;
	Edge(int from = 0, int to = 0, int cost = 0) :
		from(from), to(to), cost(cost){
		backedge = -1;
	}

};

class Node{
public:
	vector<Edge> edges;
	int prenum;
	int parent;
	int lowest;
	Node(){
		prenum = -1;
		parent = -1;
	}
};

class Graph{
public:
	vector<Node> nodes;
	int prenum;
	Graph(int n) {
		rep(i, n) { Node n;  nodes.push_back(n); }
		prenum = 0;
	}
};

Graph G(0);

void dfs(Edge &e){

	Node *n = &(G.nodes[e.to]);

	if (n->prenum != -1) {
		int parent = G.nodes[e.from].parent;
		if (e.to == parent){
			e.backedge = -1; // neither backedge nor treeedge
		}
		else{
			e.backedge = 1;
		}
		return;
	}

	// set parameter
	G.prenum++;
	e.backedge = 0; // not backage
	n->prenum = G.prenum;
	n->parent = e.from;
	n->lowest = n->prenum;

	for (auto &ee : n->edges){
		dfs(ee);
	}

	for (auto &ee : n->edges){
		if (ee.backedge != -1){
			n->lowest = min(n->lowest, G.nodes[ee.to].lowest);
		}
	}

}


int main() {

	int V, E;
	cin >> V >> E;

	G = Graph(V);

	rep(i, E){
		int from, to;
		cin >> from >> to;
		G.nodes[from].edges.push_back(Edge(from, to, 0));
		G.nodes[to].edges.push_back(Edge(to, from, 0));
	}

	Edge e(-1, 0, 0);
	dfs(e);

	rep(i, V){
		// printf("%d %d %d %d\n", i, G.nodes[i].parent, G.nodes[i].prenum, G.nodes[i].lowest);
	}

	set<int> ret;
	rep(i, V){
		if (G.nodes[i].parent == -1){
			int count = 0;
			rep(j, V){
				if (G.nodes[j].parent == i) count++;
			}
			if (count > 1) ret.insert(i);
		}
		else{
			Node n = G.nodes[i];
			Node p = G.nodes[n.parent];
			if (p.prenum <= n.lowest && p.parent != -1){
				ret.insert(n.parent);
			}
		}
	}

	for (auto &i : ret){
		cout << i << endl;
	}
}

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

int main() {
  string S;
  cin >> S;
  int K = S.size();
  vector<int> vec(K);
  rep(i, K){
   vec.at(i) = S.at(i) - '0';
  }
  int sum = 0;
  rep(i, K){
   sum += vec.at(i);
  }
  if(sum % 9 == 0){
  	cout << "Yes";
  }else{
    cout << "No";
  }
}

Measured memory_bytes: 4440
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

#define ll long long

int main(void){

    string O,E;
    cin>>O>>E;

    for(int i=0;i<O.size()+E.size();i++){
        if(i%2==0)cout<<O[i/2];
        else cout<<E[i/2];
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 764
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

x,y=MI()
if x+y>=10:
    print("error")
else:
    print(x+y)

Measured memory_bytes: 3316
import bisect

s = input()
t = input()

se = set(list(s))
for ti in t:
    if not ti in se:
        print(-1)
        exit()

word = [[] for _ in range(26)]
for i, si in enumerate(s):
    word[ord(si) - ord('a')].append(i)

ans = 0
now = 0
for i, ti in enumerate(t):
    j = bisect.bisect_left(word[ord(ti) - ord('a')], now)
    if j < len(word[ord(ti) - ord('a')]):
        j = word[ord(ti) - ord('a')][j]
        ans += j - now + 1
        now = (j + 1) % len(s)
    else:
        ans += len(s) - now
        now = 0
        j = bisect.bisect_left(word[ord(ti) - ord('a')], 0)
        j = word[ord(ti) - ord('a')][j]
        ans += j - now + 1
        now = j + 1


print(ans)


Measured memory_bytes: 47224
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n , a , b ;
    cin >> n >> a >> b ; 
    vector<int> v(n) ;
    for(int i = 0; i < n; i++){
        cin >> v[i] ;
    }
    int L = 0, R = 2e9 ;
    int ans = -1 ;
    while(L <= R){
        int mid = L + (R - L) / 2 ;
        int cnt = 0 ;
        for(int i = 0; i < n; i++){
            int h = v[i] ;
            h = h - mid * b ;
            if( h > 0 ) {
                cnt += (h + (a - b - 1)) / (a - b) ;
            }
        }
        if ( cnt <= mid ){
            ans = mid ;
            R = mid - 1;
        }
        else L = mid + 1;
    }
    assert(ans != -1) ;
    cout << ans <<endl;
    return 0; 
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,k;
  cin >>n >> k;
  vi a(n);
  rep(i,n)cin >> a[i];
  sort(rng(a));
  int ans = 0;
  rep(i,k)ans+=a[i];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3588
def inputs(): return [int(x) for x in input().split()]
from collections import defaultdict
n= int(input())
a = inputs()
#a1 = sorted(a)
ans = 0
l = defaultdict(list)
l1 = defaultdict(int)
for i in range(n):
    l1[a[i]]+=1
for i in l1.keys():
    ans+=(l1[i]*(l1[i]-1))//2
    if 1<l1[i]:
        l[i].append([(l1[i]*(l1[i]-1))//2,((l1[i]-2)*(l1[i]-1))//2])
    else:
        l[i].append([(l1[i]*(l1[i]-1))//2,0])
for i in a:
    #print(l[i])
    f,s = l[i][0]
    print(ans-f+s)



Measured memory_bytes: 51080
N = int(input())
S1 = list(input())
S2 = list(input())
cnt= 0
ans = 0
flag= 0
while cnt<N:
  if S1[cnt]==S2[cnt]:
    if cnt==0:
      ans+=3
    elif flag==1:
      ans*=2
    elif flag==2:
      ans*=1
    flag=1
    cnt+=1
  elif S1[cnt]!=S2[cnt]:
    if cnt==0:
      ans +=6
    elif flag==1:
      ans*=2
    elif flag==2:
      ans*=3
    flag=2
    cnt+=2
  ans %=(10**9+7)
print(ans)

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


int main(){
  int n; cin>>n;
  vector<int> v(n);
  int ans=0;
  rep(i,n){
    cin>>v.at(i);
    ans+=v.at(i);  
    if(v.at(i)%10==0){v.at(i)=0;}
  }
  sort(v.begin(),v.end());
  while(v.at(0)==0){
    v.erase(v.begin());
    if(v.size()==0)break;
  }
  
  if(ans%10!=0){cout<<ans;}
  else if(v.size()==0)cout<<0;
  else{cout<<ans-v.at(0);}
}

Measured memory_bytes: 256
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append(b)
vis = {}
vs = []
def dfs(i):
    if i in vis:
        if vis[i]:
            del vs[:vs.index(i)]
        return vis[i]
    vis[i] = True
    vs.append(i)
    for j in g[i]:
        if dfs(j):
            return True
    vis[i] = False
    vs.pop()
    return False
for i in range(n):
    if dfs(i):
        break
else:
    print(-1)
    exit()
dist = {v: i for i, v in enumerate(vs)}
vis = set()
ws = []
nxt = 0
for i in vs:
    if dist[i] < nxt:
        continue
    k = -1
    for j in g[i]:
        if j not in dist or dist[j]<dist[i] and j not in vis:
            continue
        if k == -1:
            k = j
            continue
        dj = (dist[j]-dist[i])%len(vs)
        dk = (dist[k]-dist[i])%len(vs) 
        if dj > dk:
            k, j = j, k
    nxt = dist[k]
    vis.add(i)
    ws.append(i)
    if k in vis:
        del ws[:ws.index(k)]
        break
print(len(ws))
for i in ws:
    print(i)

Measured memory_bytes: 44632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    string s;
    getline(cin,s);
    int le=s.size();
    rep(i,le){
        if(s[i]-'a'<=25&&s[i]-'a'>=0)s[i]-=32;
        else if(s[i]-'A'<=25&&s[i]-'A'>=0)s[i]+=32;
    }
    std::cout << s << std::endl;
}


Measured memory_bytes: 3160
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    static private Scanner scan = new Scanner(System.in);
    public static void main(String args[]) {
//        int int1 = Integer.parseInt(scan.next());
//        int int2 = Integer.parseInt(scan.next());
//        int int3 = Integer.parseInt(scan.next());
        String temp_str1 = "";
        String temp_str2 = "";
        int temp_int1 = 0;
        String str1 = scan.next();
        int ans_int = 0;
        String ans = "";
        double ans_dob = 0;

        if(str1.matches("[aeiou]")){
            ans = "vowel ";
        }else{
            ans = "consonant";
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(ans);
        out.flush();
        scan.close();
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n;
    cin >> n;

    int ans = 0;
    // A × B < N を満たす正整数の組 (A,B) に対し,
    // A × B + C = N となるような正整数Cはちょうど一つに定まります
    for (int i = 1; i < n; i++) {
        ans += (n - 1) / i;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3608
#include<stdio.h>
int main()

{
  float a,b,c,d,e,f;
  double x,y;
  while(scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f)!=EOF &&(a>=-1000&&a<=1000)&&(b>=-1000&&b<=1000)&&(c>=-1000&&c<=1000)&&(d>=-1000&&d<=1000)&&(e>=-1000&&e<=1000)&&(f>=-1000&&f<=1000))

   {

     x=(e*c-b*f)/(e*a-b*d);
      y=(d*c-a*f)/(d*b-a*e);
      if(x==-0.000)
        x=0.000;
      if(y==-0.000)
        y=0.000;

      printf("%.3f %.3f\n",x,y);
  }


    return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
#include<string>
#include<map>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define vii         vector<pair<ll,ll> >
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define rep1(i,a,b) for(ll i=a;i<= b;i++)
#define PI          3.14159
#define MAX         100000001
#define fast_io      ios_base::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
#define scan(var)    scanf("%lld",&var)
#define print(var)   printf("%lld\n", var);
#define BLOCK 317
#define double       long double
#define mod          998244353
using namespace std;
ll dp[100001][2];
vector<ll> adj[100001];
ll solvedp(ll child, ll parent,ll color)
{
  if(dp[child][color] != -1)
  {
    return dp[child][color];
  }
  ll ans = 1;
  for(auto it : adj[child])
  {
    if(it != parent)
    {
      if(color == 0)
      {
        ans = (ans*solvedp(it,child,1))%hell;
      }
      else
      {
        ans = (ans*(solvedp(it,child,0) + solvedp(it,child,1)))%hell;
      }
    }
  }
  dp[child][color] = ans;
  return ans;
}
int main()
{
  fast_io
  ll n;
  cin >> n;
  memset(dp,-1,sizeof(dp));
  rep(i,0,n - 1)
  {
    ll u,v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  cout << (solvedp(1,-1,0) + solvedp(1,-1,1))%hell;
  return 0;
}



Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
int dp[101][4][4][4];
int main(){
int N;
int MOD = 1000000000+7;
scanf("%d",&N);
dp[0][3][3][3] = 1;

for(int len=0;len<N;len++){
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			for(int k=0;k<4;k++){
				if(dp[len][i][j][k]==0) continue;
				
				for(int a=0;a<4;a++){
					if(a==2&&i==1&&j==0) continue;	
					if(a==1&&i==2&&j==0) continue;	
					if(a==2&&i==0&&j==1) continue;	
					if(a==2&&i==1&&k==0) continue;	
					if(a==2&&j==1&&k==0) continue;	
					
					dp[len+1][a][i][j]+=dp[len][i][j][k];
					dp[len+1][a][i][j]%=MOD;
				}
			}
		}
	}
}

int ans = 0;
for(int i=0;i<4;i++){
	for(int j=0;j<4;j++){
		for(int k=0;k<4;k++){
			ans+=dp[N][i][j][k];
			ans%=MOD;
		}
	}
}

printf("%d\n",ans);
}

Measured memory_bytes: 256