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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  if ((N * A) < B) {
    cout << N * A << endl;
  }
  else if ((N * A) > B) {
    cout << B << endl;
  }
  else {
    cout << B << endl;
  }
} 
  

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

using namespace std;

vector<int> p, r;


void makeSet(int x){
  p[x] = x;
  r[x] = 0;
}

int findSet(int x){
  if(x != p[x])p[x] = findSet(p[x]);
  return p[x];
}

void link(int x, int y){
  if(r[x] > r[y]) p[y] = x;
  else {
    p[x] = y;
    if(r[x] == r[y]) r[y] = r[y] + 1;
  }
}



void unite(int x, int y){
  link(findSet(x), findSet(y));
}


struct Edge{
  int a, b, cost;

  bool operator<(const Edge& o) const{
    return cost < o.cost;
  }
};


struct Graph{
  int n;
  vector<Edge> es;

  int kruskal(){
    sort(es.begin(), es.end());

    int min_cost = 0;

    for(int i=0; i<es.size(); i++){
      Edge& e = es[i];
      if(!(findSet(e.a)==findSet(e.b))){
	min_cost += e.cost;
	unite(e.a, e.b);
      }
    }

    return min_cost;
  }
};

Edge e;


int main(){

  int V, E, i;
  Graph g;

  cin >> V >> E;

  p.resize(V);
  r.resize(V);

  for(i=0; i<V; i++) makeSet(i);

  for(i=0; i<E; i++){
    cin >> e.a >> e.b >>e.cost;
    g.es.push_back(e);
  }


  cout << g.kruskal() << endl;

  return 0;
}



Measured memory_bytes: 4604
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        for(int i=1;;i++){
                int x;
                cin>>x;
                if(x){
                    printf("Case %d: %d\n",i,x);
                }else{
                        break;
                }
        }
        return 0;
}

Measured memory_bytes: 1136
#include<iostream>
using namespace std;
 
int main(){
  while(1){
  int N,M,P;
  int sum=0;
  cin>>N>>M>>P;
  if(N+M+P==0) break;
  int X[1001];
  for(int i=1;i<=N;i++){
    cin>>X[i];
    sum+=X[i];
  }
  sum*=100;
  sum=sum-(sum*P)/100;
  if(X[M]==0) sum=0;
  else sum/=X[M];
  cout<<sum <<endl;
  }
   
  return 0;
  }
   
  

Measured memory_bytes: 2984
import java.util.Scanner;
public class Main {
public static void main(String[] args){
		
		{
	         int a,b ;
	         
	      
	         Scanner sc = new Scanner(System.in);
	         
	     
		a = sc.nextInt();
        b = sc.nextInt();
	
        int d=a/b;
        int r=a%b;
        double f=(double)a/(double)b;
   
        System.out.printf(d+" "+r+" "+"%.8f",f);
     
        sc.close();
	}
	}
}
	



Measured memory_bytes: 26448
#include <iostream>
//#include <math.h>
#include <set>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

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

const int maxn = 100000;

int main(){

  int n;
  ll ans = 0;
  ll mod = INF;
  int pre = 0;
  string s,t;

  cin >> n;
  cin >> s>>t;

  rep(i,n){
    if(i==0){
      if(s[i]==t[i]){
        ans = 3;
        pre = 0;
      }else{
        ans = 6;
        pre = 1;
        i++;
      }
    }else{
      if(s[i]==t[i]){   //縦に揃っている
        if(pre==0){   //一つ前は縦に揃っていた
          ans = ans * (ll)2 % mod;
        }else if(pre==1){   //一つ前は横が揃っていた
          ans = ans;
        }
        pre = 0;
      }else{    //横に揃っている
        if(pre==0){   //一つ前は縦に揃っていた
          ans = ans * (ll)2 % mod;
        }else if(pre==1){   //一つ前は横に揃っていた
          ans = ans * (ll)3 % mod;
        }
        i++;
        pre = 1;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>

using namespace std;

typedef long long ll;
#define INF 1000000007

int main(){
    char b; cin >> b;

    if(b == 'A') cout << 'T';
    if(b == 'C') cout << 'G';
    if(b == 'G') cout << 'C';
    if(b == 'T') cout << 'A';
    cout << "\n";
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	string s = "";
	if (a < b) {
		rep(i, b) cout << a;
	}
	else rep(i, a) cout << b;
	cout << endl;
}

Measured memory_bytes: 256
p=*0..gets.to_i
s=0
f=->a{a!=p[a]?p[a]=f[p[a]]:a}
$<.map(&:split).transpose.sum([]){|a|i=0
(x,i),*y=a.map{[_1.to_i,i+=1]}.sort
y.map{[-x+x=_1,i,i=_2]}}.sort.map{|c,*a|a,b=a.map &f
a!=b&&(s+=c
p[b]=a)}
p s

Measured memory_bytes: 61492
#include <iostream>
#include <cctype>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int ok=0;
    int okc=0;
    for(int i=0;i<s.length();i++){
        if(i==0){
            if(s[i]!='A'){
                ok=1;
            }
        }else if(i>=2 && i<=s.length()-2){
            if(isupper(s[i]) && s[i]!='C'){
                ok=1;
            }else if(isupper(s[i]) && s[i]=='C' && okc==0){
                okc++;
            }else if(isupper(s[i]) && s[i]=='C' && okc==1){
                ok=1;
            }
        }else{
            if(isupper(s[i])){
                ok=1;
            }
        }
    }
    if(ok==1 || okc==0){
        cout << "WA" << endl;
    }else{
        cout << "AC" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream> 
#include<string>
#include<string.h> 
#include<map> 
#include<set> 
#include<vector> 
#include<stdio.h> 
#include<math.h> 
#include<algorithm> 
#include<queue> 
using namespace std;
int main()
{int a,b,x;
cin>>x>>a>>b;
int c=x-a;
cout<<c%b<<endl;
system ("pause"); 
return 0;
}   

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

using namespace std;

int main(void){
    
    string s;
    cin >> s;
    
    int a = atoi(s.substr(0,2).c_str());
    int b = atoi(s.substr(2,2).c_str());
    
    bool isYYMM = false;
    bool isMMYY = false;
    if(b <= 12 && b != 0) {
        isYYMM = true;
    }
    if(a <= 12 && a != 0) {
        isMMYY = true;
    }
    
    if(isYYMM && isMMYY) {
        cout << "AMBIGUOUS" << endl;
    }
    else if(isYYMM && !isMMYY) {
        cout << "YYMM" << endl;
    }
    else if(!isYYMM && isMMYY) {
        cout << "MMYY" << endl;
    }
    else {
        cout << "NA" << endl;
    }
    
    return 0;
}


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

class Dice
{
private:
  vector<int> dice;

public:
  Dice(vector<int> num) {
    for (int i = 0; i < (int)num.size(); ++i) {
      dice.push_back(num.at(i));
    }
  }
  int at(int i) {
    return dice.at(i);
  }

  void roll(char c) {
    int tmp;
    if(c == 'S'){
      tmp = dice.at(0);
      dice.at(0) = dice.at(4);
      dice.at(4) = dice.at(5);
      dice.at(5) = dice.at(1);
      dice.at(1) = tmp;
    } else if (c == 'E') {
      tmp = dice.at(0);
      dice.at(0) = dice.at(3);
      dice.at(3) = dice.at(5);
      dice.at(5) = dice.at(2);
      dice.at(2) = tmp;
    } else if (c == 'N') {
      tmp = dice.at(0);
      dice.at(0) = dice.at(1);
      dice.at(1) = dice.at(5);
      dice.at(5) = dice.at(4);
      dice.at(4) = tmp;
    } else if (c == 'W'){
      tmp = dice.at(0);
      dice.at(0) = dice.at(2);
      dice.at(2) = dice.at(5);
      dice.at(5) = dice.at(3);
      dice.at(3) = tmp;
      // 回転p
    } else  {
      tmp = dice.at(1);
      dice.at(1) = dice.at(3);
      dice.at(3) = dice.at(4);
      dice.at(4) = dice.at(2);
      dice.at(2) = tmp;
    }
  }
};

int main(int argc, char *argv[])
{
  vector<int> num(6);
  for(int i = 0; i < 6; ++i){
    cin >> num.at(i);
  }
  Dice dice1(num);
  for(int i = 0; i < 6; ++i){
    cin >> num.at(i);
  }
  Dice dice2(num);
  bool isSameTop = false, isSameDice = true;
  for(int i = 0; i < num.size(); ++i) {
    if (dice1.at(0) == dice2.at(0)) {
      isSameTop = true;
      break;
    }
  }

  for(int i = 0;i<num.size()-1;++i){
    dice1.roll('N');
    if (dice1.at(0) == dice2.at(0)) {
      isSameTop = true;
      break;
    }
  }
  if (isSameTop == false) {
    for(int i = 0;i<num.size()-1;++i){
      dice1.roll('W');
      if(dice1.at(0) == dice2.at(0)) break;
    }
  }

  for(int i = 0;i<num.size()-1;++i){
    dice1.roll('p');
    if (dice1.at(1) == dice2.at(1)) {

      break;
    }

  }

  for (int i = 0; i < num.size(); ++i) {
    if (dice1.at(i) != dice2.at(i)) {
      isSameDice = false;
      break;
    }
  }

  cout << (isSameDice ? "Yes" : "No") << endl;

  return 0;
}



Measured memory_bytes: 3148
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<Int, P> T;

Int u[1080];

Int r(Int x){
	if(u[x] == x)return x;
	return u[x] = r(u[x]);
}

void unite(Int x, Int y){
	u[r(x)] = r(y);
}
vector<T> edge[1080000];
Int h[1080];
bool ok[1080];
int main(){
	Int n, m;
	while(cin >> n >> m, n | m){
		Int res = 0, bridge = 0, a, b, c, cnt = 0;
		for(Int i = 0;i < n;i++){
			cin >> h[i], u[i] = i;
			edge[h[i]].push_back(T(-1, P(i, i)));
		}
		for(Int i = 0;i < m;i++){
			cin >> a >> b >> c;
			a--,b--;
			edge[min(h[a], h[b])].push_back(T(c, P(a, b)));

		}
		
		Int breakpoInt = 1000010;
		for(Int i = 1000000;i > 0;i--){
			for(int j = 0;j < edge[i].size();j++){
				a = edge[i][j].second.first, b = edge[i][j].second.second;
				c = edge[i][j].first;
				if(c == -1)cnt++;
				if(r(a) != r(b)){
					unite(a, b);
					bridge++;
				}
			}
			if(cnt - 1 != bridge)breakpoInt = i;
		}
		breakpoInt--;
		for(Int i = 1000000;i > 0;i--){
			sort(edge[i].begin(), edge[i].end());
		}                    
		bridge = 0;
		vector<T> tmp;
		for(Int i = 0;i < n;i++)u[i] = i;
		for(Int i = 1000000;i >= breakpoInt;i--){
			for(Int j = 0;j < edge[i].size();j++){
				tmp.push_back(edge[i][j]);
			}
			edge[i].clear();
		}
		sort(tmp.begin(), tmp.end());
		for(Int i = 0;i < tmp.size();i++){
			Int from = tmp[i].second.first, to = tmp[i].second.second;
			if(r(from) != r(to)){
				bridge++;
				res += tmp[i].first;
				unite(from, to);
			}
		}                          
		for(Int i = breakpoInt;i > 0;i--){
			for(Int j = 0;j < edge[i].size();j++){
				Int from = edge[i][j].second.first, to = edge[i][j].second.second;
				if(r(from) != r(to)){
					bridge++;
					res += edge[i][j].first;
					unite(from, to);
				}
			}
			edge[i].clear();
		}
		if(bridge + 1 != n)res = 0;
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 32180
x,k,d = map(int, input().split())

if(x<0):
    x *= -1

if(x-k*d>0):
    ans = x-k*d
else:
    if(x//d%2==k%2):
        ans = x%d
    else:
        ans = x%d-d
print(abs(ans))
    



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

int main()
{
  int N;
  cin >> N;
  typedef long long ll;
  vector<ll> A(N), B(N);
  for (auto & a : A)
    cin >> a;
  for (auto & b : B)
    cin >> b;
  if (accumulate(A.begin(), A.end(), static_cast<ll>(0)) < accumulate(B.begin(), B.end(), static_cast<ll>(0)))
  {
    cout << -1;
    return 0;
  }
  vector<ll> D(N);
  for (int i = 0; i < N; ++i)
    D[i] = A[i] - B[i];
  sort(D.begin(), D.end());
  if (0 <= D[0])
  {
    cout << 0;
    return 0;
  }
  auto itr = find_if(D.begin(), D.end(), [](auto & d){return 0 <= d;});
  ll minus = accumulate(D.begin(), itr, static_cast<ll>(0));
  auto ritr = find_if(D.rbegin(), D.rend(), [&minus](auto & d){
    minus += d;
    return 0 <= minus;
  });
  cout << distance(D.begin(), itr) + distance(ritr.base() - 1, D.end());
  return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		String s = stdIn.nextLine();
		String p = stdIn.nextLine();
		int y = -1;
		
		
		for(int j=0;j<s.length();j++){
			if(s.charAt(j) == p.charAt(0)){
				int count = 1;
				int i = 0;
				y = func(s,p,i,j,count);
			}
			if(y==1){
				break;
			}
		}
		
		if(y==1){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
		
	}
	 static int func(String s ,String p ,int i ,int j ,int count){
		int p_count = (i+1)%p.length();
		int s_count = (j+1)%s.length();
		int ans = 0;
		
		if(count == p.length()){
			ans = 1;
		}
		else if(s.charAt(s_count) == p.charAt(p_count)){
				count++;
				ans = func(s,p,p_count,s_count,count);
			}
		else{
			ans = -1;
		}
		 
		 return ans;
	}

}

Measured memory_bytes: 17292
#include <bits/stdc++.h>
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define sc   scanf
#define pr   printf
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define ll   long long
#define ld   long double
#define N    356
#define M    1000000007
#define I    1000000000000000000
#define pdd  pair < ld, ld >
#define pll  pair < ll, ll >
#define pii  pair < int, int >
#define sqr( a )           a * a
#define all( c )           c.begin(), c.end()
#define srt( c )           sort( all( c ) )
#define rev( c )           reverse( all( c ) )
#define srtr( c )          sort( c.rbegin(), c.rend() );
using namespace std;
int n, m, k, a[N][N], cnt;

int yy, xx;
void solve()
{
    cin >> n >> m >> k;
    for( int i = 0; i <= max( n, m) + 1; i ++ )
    {
        a[i][0] = a[0][i] = -1;
    }
    for( int i = 1; i <= n; i ++ )
    {
        yy = 1;
        for( int j = 1; j <= m; j ++ )
        {
            char c;
            cin >> c;
            if( c == '#')
            {
                cnt ++;
                for( int ii = i; ii >= 0; ii -- )
                {
                    if( !a[ii][yy-1] || a[ii][yy] )
                    {
                        xx = ii + 1;
                        break;
                    }
                }
                xx = min( xx, i );
                for( int ii = xx; ii <= i; ii ++ )
                    for( int jj = yy; jj <= j; jj ++ )
                        a[ii][jj] = cnt;
                yy = j + 1;
            }

        }
    }
    for( int i = 1; i <= n; i ++ )
    {
        for( int j = 1; j <= m; j ++ )
        {
            if( a[i][j] == 0 )
            {
                a[i][j] = max( a[i-1][j], a[i][j-1]);
            }
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}
int main()
{
    ll tt = 1;
    //sc( "%d", &tt );
    for( ll i = 1; i <= tt; i ++ )
    {
        solve();
    }
}












Measured memory_bytes: 1152
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

x, y = gets.chomp.split.map(&:to_i)

puts a.include?(x) && a.include?(y) || b.include?(x) && b.include?(y) || c.include?(x) && c.include?(y) ? "Yes" : "No"

Measured memory_bytes: 3836
// [AT2333 Scc Puzzle] https://www.luogu.org/problemnew/show/AT2333
#include <iostream>
#include <algorithm>
using namespace std;

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

Measured memory_bytes: 384
N = int(input())
h = list(map(int, input().split()))

ans = 0
while True:
    if not any(h):
        break
        
    i = 0
    while i < N:
        if h[i] == 0:
            i += 1
        else:
            ans += 1
            while i < N and h[i] != 0:
                h[i] -= 1
                i += 1

print(ans)

Measured memory_bytes: 3060
#include<cstring>
#include<cstdio>
#include<queue>

using namespace std;

const int N = 100005;
int n, step[N], a[N];

void bfs(){
	queue<int> q;
	q.push(0);
	step[0] = 0;
	while(!q.empty()){
		int cur = q.front(); q.pop();
		for(int i = 1; i <= a[0]; i++){
			if(cur + a[i] <= n && step[cur+a[i]] == -1){
				q.push(cur+a[i]);
				step[cur+a[i]] = step[cur] + 1;
				if(cur + a[i] == n){
					printf("%d\n", step[cur+a[i]]);
					return;
				}
			}
		}
	}
}

int main(){
	memset(step, -1, sizeof step);
	scanf("%d", &n);
	a[++a[0]] = 1;
	int x = 9;
	while(x <= n){
		a[++a[0]] = x;
		x *= 9;
	}
	x = 6;
	while(x <= n){
		a[++a[0]] = x;
		x *= 6;
	}
	bfs();
	return 0;
}


Measured memory_bytes: 768
#include<stdio.h>

char markY = '#';

void reverse(char *mark) {
	*mark = (*mark == '#') ? '.' : '#';
}

void writeLine(int num) {
	char markX = markY;
	int i;

	for(i = 0; i < num; i++) {
		printf("%c" , markX);
		reverse(&markX);	
	}
	printf("\n");
	reverse(&markY);	
}

int main () {
	int width , height;
	int i , s;
	while(1) {
		scanf("%d %d" , &height , &width);
		if (width == 0 && height == 0) break;
		for(i = 0; i < height; i++) {
			writeLine(width);
		}
		printf("\n");
		markY = '#';
	}
	return 0;
}

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

int main() {
    int n, k, c, a;
    double ans = 0;
    
    cin >> n >> k;
    
    for (int i = 1; i <= n; i++) {
        c = i;
        a = 0;
        
        while (true) {
            if (c >= k) {
                break;
            }
            
            a++;
            c *= 2;
            //cout << "i=" << i << ", p=" << p << ", c=" << c << endl;
        }
        
        ans += 1.0 / (double)n * pow(0.5, a);
    }
    
    cout << printf("%.10f", ans) << endl;
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    int x, y, z, k;
    std::cin >> x >> y >> z >> k;

    std::vector<long long> a(x);
    for (int i = 0; i < x; i++) {
        std::cin >> a[i];
    }

    std::vector<long long> b(y);
    for (int i = 0; i < y; i++) {
        std::cin >> b[i];
    }

    std::vector<long long> c(z);
    for (int i = 0; i < z; i++) {
        std::cin >> c[i];
    }

    std::sort(a.begin(), a.end(), std::greater<long long>());
    std::sort(b.begin(), b.end(), std::greater<long long>());
    std::sort(c.begin(), c.end(), std::greater<long long>());

    std::priority_queue<std::pair<long long, long long>> q;

    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            q.push(std::make_pair(a[i] + b[j] + c[0], 0));
        }
    }

    for (int i = 0; i < k; i++) {
        std::pair<long long, long long> top = q.top();
        q.pop();

        std::cout << top.first << std::endl;
        if (top.second == z - 1) {
            continue;
        }

        q.push(std::make_pair(top.first - c[top.second] + c[top.second + 1], top.second + 1));
    }
}


Measured memory_bytes: 18668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

// void chmod(ll &M){
//     if(M >= mod) M %= mod;
//     else if(M < 0){
//         M += (abs(M)/mod + 1)*mod;
//         M %= mod;
//     }
// }

int n, m;
vector<int> lans, rans;
int ep,ep2; // End point

vector<int> adj[100005];
vector<bool> used(100005, false);

void rdfs(int now){
	bool flg = true;

	for(auto e:adj[now]) if(used[e] == false) flg = false;
	if(flg){
		return;
	}

	for(auto e:adj[now]) if(used[e] == false){
		used[e] = true;
		ep = e;
		rans.push_back(ep);
		rdfs(ep);
		return;
	}

}

void ldfs(int now){
	bool flg = true;

	for(auto e:adj[now]) if(used[e] == false) flg = false;
	if(flg){
		cout << rans.size()+lans.size() << endl;
		reverse(lans.begin(), lans.end());
		for(int i=0; i<lans.size(); ++i){
			if(i) cout << " ";
			cout << lans[i];
		}
		for(int i=0; i<rans.size(); ++i){
			cout << " " << rans[i];
		}
		cout << endl;
		return;
	}

	for(auto e:adj[now]) if(used[e] == false){
		used[e] = true;
		ep = e;
		lans.push_back(ep);
		ldfs(ep);
		return;
	}

}



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

	cin >> n >> m;

	for(int i=0; i<m; ++i){
		int a, b; cin >> a >> b;
		if(i == 0){
			used[a] = used[b] = true;
			rans.push_back(a);
			rans.push_back(b);
			ep = b;
			ep2 = a;
		}
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	rdfs(ep);
	ldfs(ep2);

	return 0;
}

Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007
void setIO(string name) {
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((name+".in").c_str(),"r",stdin);
  freopen((name+".out").c_str(),"w",stdout);
}
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}


int main() {
   fast(); 
   long long x,y;
   cin>>x>>y;
   if(x*y<0){
    cout<<abs(abs(x)-abs(y))+1<<endl;
     return 0;
   }else{
     if(y==0){
        if(x>0){
          cout<<x+1<<"\n";
          return 0;
        }else{
          cout<<abs(x)<<"\n";
          return 0;
        }
     }
     if(x==0){
        if(y>0){
           cout<<y-x<<"\n";
          return 0;
        }else{
           cout<<abs(y)+1<<"\n";
          return 0;
        }
     }
     if(x<=y){
       
       cout<<y-x<<"\n";
       return 0;
     }else{
        cout<<-y+x+2<<"\n";
       return 0;
     }
   }
   

} 


Measured memory_bytes: 3612
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		List<String> w = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			String tmp = sc.next();
			if (w.contains(tmp)) {
				System.out.println("No");
				return;
			}
			w.add(tmp);
		}
		for (int i = 0; i < w.size() - 1; i++) {
			String string = w.get(i);
			String nextString = w.get(i + 1);
			char last = string.charAt(string.length() - 1);
			char first = nextString.charAt(0);
			if (last != first) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
		sc.close();
	}
}

Measured memory_bytes: 23764
N = int(input())
L = []
for i in range(N):
    t = list(map(int, input().split()))
    L.append(t)

L.insert(0, [0,0,0])

for i in range(1, N+1):
    time = abs(L[i-1][0] - L[i][0])
    distance = abs(L[i-1][1] - L[i][1]) + abs(L[i-1][2] - L[i][2])
    if (time < distance) or (time%2 != distance%2):
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 27120
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder2020Ned
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int Employees = int.Parse(Console.ReadLine());
            int[] newList = new int[Employees];

            int[] EmpList = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            
            for(int i = 0; i < Employees-1; i++)
            {
                newList[EmpList[i]- 1]+= 1;
            }

            foreach (var item in newList)
            {
                Console.WriteLine(item);
            }
                Console.Read();
        }
    }
}


Measured memory_bytes: 43576
import collections

s = input()
t = input()
s = ''.join(sorted(s))
t = ''.join(sorted(t, reverse=True))

for i in range(min(len(s), len(t))):
    if ord(s[i]) > ord(t[i]):
        print('No')
        break
    elif ord(s[i]) < ord(t[i]):
        print('Yes')
        break
    else:
        pass
else:
    if len(s) < len(t):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>

#define INF 100000000
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; }

using namespace std;

int main(){
  int i,j,k,max=0,n,d,a[100010],b[100010],x,y;
  cin >>n;
  for(i=0;i<n;i++){cin >> a[i];}
  for(i=0;i<n+1;i++){b[i]=0;}

  d=0;
  for(i=1;i<n+1;i++){

    x=a[i];
    y=a[i-1];

    if(x<=y){
      d++;
      b[i]=d;
    }else{
      d=0;
    }
  }


  b[0]=0;
  for(i=0;i<n;i++){
    if(max<b[i])max=b[i];
  }

  cout << max << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] arr = new int[n][2];

        for(int i = 0; i< n; i++){
            for(int j=0; j<2; j++){
                arr[i][j] = sc.nextInt();
            }
        }
        int cnt = 0;

        for(int i = 0; i<n; i++){
            long di = (long)(Math.pow(arr[i][0], 2)+Math.pow(arr[i][1], 2));
            //System.out.println(di);
            if(di <= (long)Math.pow(d,2)){
                cnt++;
            }
        }

        System.out.println(cnt);


        
    }
    
}

Measured memory_bytes: 66636
k, a, b = list(map(int, input().split()))

if a+2 >= b or k <= a:
    print(k+1)
else:
    n = k - (a + 1)
    if n % 2 ==0:
        m = n // 2
        print((m+1) * b - m * a)
    else:
        m = (n-1) // 2
        print((m + 1) * b - m * a + 1)

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

int main() {
  int a, b, c;
  cin >> a >> b;

  if ( a <= 5 ) { c = 0; }
  if ( 6<= a && a <= 12 ) { c = b/2; }
  if ( 13 <= a ) { c = b; }

  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int l = int.Parse(input[0]);
		int r = int.Parse(input[1]);
		int d = int.Parse(input[2]);
		int counter = 0;
        for (int i = l; i <= r; i++)
        {
            if (i % d == 0)
            {
				counter++;
            }
        }
		Console.WriteLine(counter);
	}
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

template <class T>
inline bool chmin(T& a, T b)
{
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b)
{
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

// 負の数にも対応した % 演算
long long mod(long long val, long long m)
{
    long long res = val % m;
    if (res < 0)
        res += m;
    return res;
}

// a^n modを計算する
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    // nを2進数表示して1が埋まっている桁に関してはa^mをかけていく
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod)
{
    return modpow(a, mod - 2, mod);
}

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

const int di[] = { -1, 0, 1, 0 };
const int dj[] = { 0, -1, 0, 1 };
int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int ans = 0;
    rep(si, h) rep(sj, w) // 各マスに関してbfsを回して最大の距離を得たものを答え
    {
        if (s[si][sj] == '#')
            continue;
        vector<vector<int>> dist(h, vector<int>(w, INF_32));
        queue<P> q;
        auto update = [&](int i, int j, int x) {
            if (dist[i][j] != INF_32)
                return;
            dist[i][j] = x;
            q.push(P(i, j)); // .emplace(i,j)
        };
        update(si, sj, 0);
        while (!q.empty()) {
            int i = q.front().first;
            int j = q.front().second;
            q.pop();
            rep(dir, 4)
            {
                int ni = i + di[dir];
                int nj = j + dj[dir];
                if (ni < 0 || ni >= h || nj < 0 || nj >= w)
                    continue;
                if (s[ni][nj] == '#')
                    continue;
                update(ni, nj, dist[i][j] + 1);
            }
        }
        rep(i, h) rep(j, w)
        {
            if (dist[i][j] == INF_32)
                continue;
            ans = max(ans, dist[i][j]);
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
h,w=map(int,input().split())
s=[input() for _ in range(h)]
vi=[ [-1 for _ in range(w)] for _ in range(h)]
st=deque()
st.append([0,0,0])


d=[[0,1],[-1,0],[1,0],[0,-1]]
while st:
  h1,w1,i=st.popleft()

  if 0<=h1<h and 0<=w1<w and vi[h1][w1]==-1 and s[h1][w1]==".":
    vi[h1][w1]=i+1
    for m in d:
      st.append([h1+m[0],w1+m[1],i+1])

print("".join(s).count(".")-vi[h-1][w-1] if vi[h-1][w-1]!=-1 else -1)


Measured memory_bytes: 9416
#include <iostream>
using namespace std;
int main() {
  int n; cin >> n;
  int arr[n],x = 0;
  for (int i=0; i<n; i++) {cin >> arr[i]; x ^= arr[i];}
  for (int i=0; i<n; i++) cout << (arr[i] ^ x) << " "; cout << endl;
}

Measured memory_bytes: 3916
import re
s = input()
ci = s.find("C")
if s.find("A") == 0 and 2 <= ci <= len(s) - 2:
  tmp = list(s)
  del tmp[0]
  del tmp[ci - 1]
  if re.match("^[a-z]*$", "".join(tmp)):
    print("AC")
    exit()
print("WA")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int N;
ll A[100010];

int main(void){
	cin >> N;
	rep(i, N) cin >> A[i];

	ll ans = 0, sum = 0;
	rep(i, N){
		sum += A[i];
		if(A[i] == 0){
			ans += sum / 2;
			sum = 0;
		}
	}
	ans += sum / 2;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL D,G;
LL p[10],c[10];
 
LL ans = INF;

void solve(){
	//まずbit全探索
	//どの問題を全完するか先に決める
	//例えばmask = 1010なら2番目と4番目の問題を全完することに決める
    for(int mask = 0; mask < (1 << D); ++mask){
    	//score_sum:得られた総スコア
    	//solved_counter:解いた問題の総数
    	//rest_max:もし全完しても点数が足りなかったら、
    	//         rest_max題目を解いて微調整に使う
        LL score_sum = 0, solved_counter = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
        	//i番目の問題を全完すると仮定した時
            if(mask >> i & 1){//maskのi+1ビット目が1なら
            	//問題数*得点 + ボーナス点
                score_sum += 100 * (i+1) * p[i] + c[i];
                //i番目を全完するにはp[i]回解く必要あり
                solved_counter += p[i];
            }else{
            	//もし全完しても点数が足りなかったら
            	//rest_max題目を解いて微調整に使う
                rest_max = i;
            }
        }
        //目標スコアに到達していないなら貪欲に点数を獲得させておき、
        //点数がG以上になるように微調整
        if(score_sum < G){
            LL s1 = 100 * (rest_max + 1);
            //Gとscore_sumの差を埋めるのに必要な、問題を解く最小回数をneedとする
            LL need = (G - score_sum + s1 - 1) / s1;
            if(need >= p[rest_max]){//必要回数が問題の数を超えたなら無理なので飛ばす
                continue;
            }
            solved_counter += need;
        }
        ans = min(ans,solved_counter);
    }
}
 
int main(){
    cin >> D >> G;
    for(int i=0;i<D;i++){
    	cin >> p[i] >> c[i];
    }
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main
import "fmt"

/*
i 的遍历顺序从最高位到最低位
T(i, prefix_remainder, isEqual) 表示第 i 位、
更高位的数字和 mod D 为 prefix_remainder、
状态为 isEqual(true 表示前缀与 K 的相应前缀相等，false < K 的相应前缀) 的方案数
则 T(hi, 0, true) 为最终答案，其中 hi = K 的最高位对应的 i，
比如：98765，则最高位 i = 5

状态转移：
T(i, prefix_remainder, isEqual) = 
Sum{ 
	T(i-1, prefix_remainder + d_i, isEqual && d_i == d[i])
	0 <= d_i <= 9 if !isEqual = false or d[i] if isEqual
}
其中，d_i 表示在 i 位上的数字选择，d[i] 表示 K 在 i 位上的数字

边界条件：
T(0, any, any) = 1，遍历到 0 意味着个位数字都已经确定完了

下面的具体实现与上述推导不符
*/

const MAXL = 1e4+5
const MAXD = 105
const MOD = 1e9+7

var n int
var D int
var d [MAXL]int
var T [MAXL][MAXD][2]int

func cast(b bool) int {
  if b {
    return 1
  } else {
    return 0
  }
}

func solve(i int, prefix int, isEqual bool) int {
	if i == n {
      	if prefix == 0 {
        	return 1
      	} else {
        	return 0
      	}
	}
  if T[i][prefix][cast(isEqual)] >= 0 {
		return T[i][prefix][cast(isEqual)]
	}
	maxD := 9
	if isEqual {
		maxD = d[i]
	}
	var sum int64
	for digit := 0; digit <= maxD; digit++ {
      	sum += int64(solve(i+1, (prefix+digit) % D, isEqual && digit == d[i]))
	}
	sum %= MOD
    T[i][prefix][cast(isEqual)] = int(sum)
  	return int(sum)
}

func main() {
	var K string
	fmt.Scanln(&K)
	fmt.Scanln(&D)
	n = len(K)
	for i := 0; i < n; i++ {
      	d[i] = int(K[i] - '0')
	}
	for i := 0; i < n; i++ {
		for j := 0; j < D; j++ {
			T[i][j][0] = -1
          	T[i][j][1] = -1
		}
	}
	
  fmt.Println((MOD + solve(0, 0, true) - 1) % MOD) // minus 1 for 0
}

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

const int MOD = (int)1e9+7;

long long fac[2100],finv[2100],inv[2100];

void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<2100;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}

long long COM(int n,int k){
	if(n<k) return 0;
	if(n<0 || k<0)	return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

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

	COMinit();
	for(int i=1;i<=K;i++){
		long long ans;
		ans=COM(N-K+1,i)*COM(K-1,i-1)%MOD;
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f first
#define s second
int main()
{  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h,w;
    cin>>h>>w;
    char a[h+2][w+2];
    for(int x=0;x<=h+1;x++)
    for(int y=0;y<=w+1;y++)
    {
        a[x][y]='#';
    }
    for(int x=1;x<=h;x++)
    for(int y=1;y<=w;y++)
    {
        cin>>a[x][y];
    }
    ll ans=0;
    for(int x=1;x<=h;x++)
    for(int y=1;y<=w;y++)
    {
    if(a[x][y]!='#')
    {bool vis[h+2][w+2];
    memset(vis,false,sizeof(vis));
    ll dep[h+2][w+2]={0};
    queue<pair<ll,ll>> ar;
    ar.push({x,y});
    vis[x][y]=true;
    while(!ar.empty())
    {   //cout<<"a";
        pair<ll,ll> g=ar.front();
        ar.pop();
        if(a[g.f][g.s+1]!='#' && !vis[g.f][g.s+1])
        {
            dep[g.f][g.s+1]=dep[g.f][g.s]+1;
            ans=max(ans,dep[g.f][g.s+1]);
            ar.push({g.f,g.s+1});
            vis[g.f][g.s+1]=true;
        }
        if(a[g.f][g.s-1]!='#' && !vis[g.f][g.s-1])
        {
            dep[g.f][g.s-1]=dep[g.f][g.s]+1;
            ans=max(ans,dep[g.f][g.s-1]);
            ar.push({g.f,g.s-1});
            vis[g.f][g.s-1]=true;
        }
        if(a[g.f+1][g.s]!='#' && !vis[g.f+1][g.s])
        {
            dep[g.f+1][g.s]=dep[g.f][g.s]+1;
            ans=max(ans,dep[g.f+1][g.s]);
            ar.push({g.f+1,g.s});
            vis[g.f+1][g.s]=true;
        }
        if(a[g.f-1][g.s]!='#' && !vis[g.f-1][g.s])
        {
            dep[g.f-1][g.s]=dep[g.f][g.s]+1;
            ans=max(ans,dep[g.f-1][g.s]);
            ar.push({g.f-1,g.s});
            vis[g.f-1][g.s]=true;
        }
    }
    }
    }
    cout<<ans;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace aizu
{
    class OnlineJudge
    {
        const int Max = 1000000;
        static void Main()
        {
            bool[] check = new bool[Max];
            Dictionary<int, int> prime = new Dictionary<int, int>(Max);
            prime.Add(0, 0);
            prime.Add(1, 0);
            for(int i=2; i < Max; ++i) {
                prime.Add(i, prime[i - 1]);
                if(!check[i]) {
                    ++prime[i];
                    for(int l = 2; i * l < Max; ++l) {
                        check[l * i] = true;
                    }
                }
            }
            string num;
            while((num = Console.ReadLine()) != null) {
                Console.WriteLine(prime[int.Parse(num)]);
            }
        }
    }
}

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

int main() {
long long a,b;
cin >> a >> b;
if(a < 0 && b < 0){
  if((a - b + 1)%2 == 0){
  cout << "Positive" << endl;
  }else{
  cout << "Negative" << endl;
  }
}else if(a < 0 && b > 0){
  cout << "Zero" << endl;
}else if(a > 0 && b > 0){
  cout << "Positive" << endl;
}else if(a == 0 || b == 0){
  cout << "Zero" << endl;
}
}




Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int n, m;

bool solve(vector<int>& d) {
  sort(d.begin(), d.end());
  REP(i, m) {
    int t;
    cin >> t;
    auto p = lower_bound(d.begin(), d.end(), t);
    if (p == d.end())
      return false;
    if (*p != t)
      return false;
    // cout << *p << endl;
    d.erase(p);
  }
  return true;
}

int main() {
  cin >> n;
  vector<int> d(n);
  REP(i, n) cin >> d[i];
  cin >> m;
  if (solve(d))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
struct edges
{
	int to,next;
}edge[202020];
unsigned long long ans=0;
unsigned long long hhh=(1ll<<60);
void getmin(unsigned long long &now,unsigned long long v)
{
	if(now==0)
		now=v;
	else
		now=min(now,v);
}
int first[101010],now;
void adde(int x,int y)
{
	now++;
	edge[now].to=y;
	edge[now].next=first[x];
	first[x]=now;
}
int dis[111];
int ma;
int fa1[111];
void work(int p,int fa)
{
	fa1[p]=fa;
	if(dis[p]>dis[ma])
		ma=p;
	for(int e=first[p];e;e=edge[e].next)
		if(edge[e].to!=fa)
		{
			dis[edge[e].to]=dis[p]+1;
			work(edge[e].to,p);
		}
}
int q[101010],qn;
void work1(int p)
{
	qn=0;
	while(p)
	{
		q[++qn]=p;
		p=fa1[p];
	}
}
int cnt[111];
int p1,p2;
void work2(int p,int fa)
{
	int nc=0;
	for(int e=first[p];e;e=edge[e].next)
		if(edge[e].to!=fa)
		{
			if(p==p1&&edge[e].to==p2)
				continue;
			if(p==p2&&edge[e].to==p1)
				continue;
			nc++;
			dis[edge[e].to]=dis[p]+1;
			work2(edge[e].to,p);
		}
	cnt[dis[p]]=max(cnt[dis[p]],nc);
}
int rt;
int ans1;
int tt;
void work3(int pp1,int pp2)
{
	p1=pp1;
	p2=pp2;
	first[rt]=0;
	adde(rt,p1);
	adde(rt,p2);
	dis[rt]=0;
	memset(cnt,0,sizeof(cnt));
	unsigned long long nans=1;
	work2(rt,0);
	for(int i=0;i<=ans1;i++)
		if(cnt[i])
		{
			if(hhh/cnt[i]<nans)
				nans=0;
			nans*=cnt[i];
		}
	if(nans)
		getmin(ans,nans);
}
int main()
{
	int n,x,y;
	scanf("%d",&n);
	memset(first,0,sizeof(first));
	now=0;
	hhh*=8;
	hhh--;
	hhh<<=1;
	hhh++;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		adde(x,y);
		adde(y,x);
	}
	dis[1]=0;
	ma=1;
	work(1,0);
	rt=ma;
	dis[rt]=0;
	work(rt,0);
	ans1=(dis[ma]+2)/2;
	work1(ma);
	rt=n+1;
	if(dis[ma]&1)
	{
		rt=n+1;
		work3(q[qn/2],q[qn/2+1]);
	}
	else
	{
		int h=q[qn/2+1];
		memset(cnt,0,sizeof(cnt));
		unsigned long long nans=1;
		dis[h]=0;
		work2(h,0);
		for(int i=0;i<=ans1;i++)
			if(cnt[i])
				nans*=cnt[i];
		getmin(ans,nans);
		for(int e=first[h];e;e=edge[e].next)
			work3(h,edge[e].to);
	}
	printf("%d %llu",ans1,ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int a, b;
	cin >> a >> b;
	string s1(a,b+'0');
	string s2(b,a+'0');
	if(s1 < s2) cout << s1 << endl;
	else cout << s2 << endl;
	return 0;
}



Measured memory_bytes: 3564
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    long X = sc.nextLong();
    long Y = sc.nextLong();
    int ans = 0;
    while(X <= Y){
      ans++;
      X *= 2;
    }
    out.println(ans);
  }

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

Measured memory_bytes: 21844
n, m, *a = map(int, open(0).read().split())
div = 1000000007
broken = set(a)
 
f = [0] * (n + 1)
f[0] = 1
if 1 not in broken:
    f[1] = 1
 
for i in range(2, n + 1):
    if i in broken:
        continue
    f[i] = (f[i - 1] + f[i - 2]) % div
 
print(f[-1])


Measured memory_bytes: 14180
#include<iostream>
using namespace std;
int main(){
 
int a[1000];
int n;
 
cin>>n;
int i;

for(i=0; i<n; i=i+1){
  cin>>a[i];
}
 
int j;
for(j=n-1; j>-1; j=j-1){
  cout<<a[j];
         if(j>0){ cout<<" ";}
         if(j==0){ cout<<endl;}
}

}



Measured memory_bytes: 3068
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;

namespace c
{
    class Program
    {
        public static readonly long INF = 999999999999;
        public static readonly long MOD = 1000000007;

        static void Main(string[] args)
        {
            var W = Scanner.IntScan()[0];

            var dp = new long[111000];
            for (var i = 0; i <= 110000; i++) dp[i] = INF;
            var weight = new List<long>();
            for (int i = 1; i <= W; i *= 6) weight.Add(i);
            for (int i = 9; i <= W; i *= 9) weight.Add(i);
            int n = weight.Count;
            dp[0] = 0;

            for(var i = 0; i < n; i++)
            {
                for(var w = weight[i]; w <= W; w++)
                {
                    Ex.Chmin(ref dp[w], dp[w - weight[i]] + 1);
                }
            }
            Console.WriteLine(dp[W]);
        }
    }

    public class Scanner
    {
        public static string[] Scan() => Console.ReadLine().Split(' ');
        public static int[] IntScan() => Array.ConvertAll(Scan(), int.Parse);
        public static long[] LongScan() => Array.ConvertAll(Scan(), long.Parse);
        public static string[] Scan(int n) => Enumerable.Repeat(0, n).Select(_ => Scan()[0]).ToArray();
        public static int[] IntScan(int n) => Enumerable.Repeat(0, n).Select(_ => IntScan()[0]).ToArray();
        public static long[] LongScan(int n) => Enumerable.Repeat(0, n).Select(_ => LongScan()[0]).ToArray();

    }

    public class Ex
    {
        public static bool Chmin(ref int a, int b) { if (a > b) { a = b; return true; } return false; }
        public static bool Chmin(ref long a, long b) { if (a > b) { a = b; return true; } return false; }
        public static bool Chmax(ref int a, int b) { if (a < b) { a = b; return true; } return false; }
        public static bool Chmax(ref long a, long b) { if (a < b) { a = b; return true; } return false; }
        public static int[] SubArr(int[] arr, int begin, int n) { int[] a = new int[arr.Length]; Array.Copy(arr, begin, a, 0, n); return a; }
    }
}


Measured memory_bytes: 13288
#include <iostream>
#include <cstring>
#include <cmath>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


char S[16];
long len;

int main(void) {
  cin >> S;
  len = strlen(S);

  long p = pow(2, len - 1);
  long sum = 0;
  REP(i, 0, p) {
    long s = 0;
    long ds = 0;
    long q = i;
    long t = 0;
    while(t < len) {
      while(1) {
        long r = q % 2;
        q /= 2;
        ds = ds * 10 + (S[t] - '0');
        t++;
        if(r == 1 || t >= len) break;
      }
      s += ds;
      ds = 0;
    }
    sum += s;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 384
import math
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
S = sum(A)
P = []
_P = []
for i in range(1, int(math.sqrt(S)) + 1):
  if S % i:
    continue
  P.append(S // i)
  _P.append(i)
P += _P[::-1]
for p in P:
  _A = sorted([a - p * (a // p) for a in A], reverse=True)
  n = sum(_A) // p
  if sum(_A) - sum(_A[:n]) <= K:
    print(p)
    break

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d) cout << "Left" << endl;
  else if (a + b == c + d) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, t, a[200010], ta, mu, ans;

signed main() {
	cin >> n >> t;
	rep(i, n)cin >> a[i];
	rep(i, n) {
		if (ta >= a[i])ta = a[i] + t;
		else {
			ans += ta - mu;
			ta = a[i] + t;
			mu = a[i];
		}
	}
	ans += ta - mu;
	cout << ans << endl;
	getchar(); getchar();
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  if(s.at(0)!=s.at(1)&&s.at(0)!=s.at(2)&&s.at(2)!=s.at(1)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

int main()
{
    int cnt = 0;
    string S, T;
    cin >> S >> T;
    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] != T[i])
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
  int N;
  long long X, r;
  cin >> N >> X;
  vector<long long> x(N);
  for(int i = 0; i < N; i++) {
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  for(int i = 0; i < N; i++) {
    x.at(i) = x.at(i) - X;
    if(x.at(i) < 0) {
      x.at(i) = -x.at(i);
    }
  }
  sort(x.begin(), x.end());
  for(int i = 0; i < N; i++) {
    if(i == 0) {
      r = x.at(i);
    }
    else {
      r = __gcd(x.at(i),r);
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 1024