akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

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

int main(void) {
    ll N;
    cin >> N;
    ll i;
    ll a[MAX];
    for(i=0; i<N; i++) cin >> a[i];
    sort(a, a+N);
    
    ll ans=a[0];
    for(i=1; i<N; i++) {
        ans=gcd(ans, a[i]);
    }
    pt(ans);
}





Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
   int cnt=0,mx=0,ar[100009],i,j,n;
   cin>>n;
   for(i=1; i<=n; i++)
   {
    cin>>ar[i];
   }

   for(i=1; i<n; i++)
   {
     if(ar[i]>= ar[i+1])
     {
       cnt++;
       mx=max(mx,cnt);
     }

     else
     {
       cnt=0;
     }
   }

   cout<<mx<<endl;
   return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>

typedef long long LL;
const int Mod = 1000000007, Inv2 = (Mod + 1) / 2;
const int MN = 3005;

int N, Q, A[MN], p1[MN], p2[MN];
int dp[MN][MN], Coef, Sum;

int main() {
	scanf("%d%d", &N, &Q), Coef = 1;
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
	for (int i = 1; i <= Q; ++i) {
		scanf("%d%d", &p1[i], &p2[i]);
		if (p1[i] > p2[i]) std::swap(p1[i], p2[i]);
	}
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= N; ++j)
			dp[i][j] = A[i] > A[j];
	for (int i = 1; i <= Q; ++i) {
		static int tmp[MN][MN];
		for (int x = 1; x <= N; ++x)
			if (x != p1[i] && x != p2[i]) {
				tmp[x][p1[i]] = (LL)Inv2 * (dp[x][p1[i]] + dp[x][p2[i]]) % Mod;
				tmp[p1[i]][x] = (LL)Inv2 * (dp[p1[i]][x] + dp[p2[i]][x]) % Mod;
				tmp[x][p2[i]] = (LL)Inv2 * (dp[x][p2[i]] + dp[x][p1[i]]) % Mod;
				tmp[p2[i]][x] = (LL)Inv2 * (dp[p2[i]][x] + dp[p1[i]][x]) % Mod;
			}
		for (int x = 1; x <= N; ++x)
			if (x != p1[i] && x != p2[i]) {
				dp[x][p1[i]] = tmp[x][p1[i]];
				dp[p1[i]][x] = tmp[p1[i]][x];
				dp[x][p2[i]] = tmp[x][p2[i]];
				dp[p2[i]][x] = tmp[p2[i]][x];
			}
		dp[p2[i]][p1[i]] = dp[p1[i]][p2[i]] = (LL)Inv2 * (dp[p1[i]][p2[i]] + dp[p2[i]][p1[i]]) % Mod;
		Coef = 2ll * Coef % Mod;
	}
	for (int x = 1; x < N; ++x)
		for (int y = x + 1; y <= N; ++y)
			Sum = (Sum + dp[x][y]) % Mod;
	printf("%lld\n", (LL)Coef * Sum % Mod);
	return 0;
}

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

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

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

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

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

ll fac(ll n) {
  if(n < 2) return 1ll;
  else return n*fac(n-2);
}
int main()
{
  auto z_algorithm = [&](string s) {
    vector<int> res(s.size());
    res[0] = s.size();
    int i = 1, j = 0;
    while(i < s.size()) {
      while(i+j < s.size() && s[j] == s[i+j]) ++j;
      res[i] = j;
      if(j == 0) {++i; continue;}
      int k = 1;
      while(i+k < s.size() && k+res[k] < j) res[i+k] = res[k], ++k;
      i += k; j -= k;
    }
    return res;
  };

  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  for(int i = 0; i < n; ++i) {
    auto vec = z_algorithm(s.substr(i, n-i));
    for(int i = 1; i < vec.size(); ++i) chmax(ans, min(i, vec[i]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF 1<<30
#define LINF 1LL << 62

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N; cin >> N;
	vector<ll> A(N);
	map<ll, ll> bou;
	for (int i = 0; i < N;i++) {
		cin >> A[i];
		bou[A[i]]++;
	}
	ll ans = 0;
	ll tate = 0, yoko = 0;
	for (auto it = bou.rbegin(); it != bou.rend();it++) {
		if (tate == 0) {
			if (it->second >= 4) {
				tate = it->first;
				yoko = it->first;
				break;
			}
			else if (it->second >= 2) {
				tate = it->first;
			}
		}
		else {
			if (it->second >= 2) {
				yoko = it->first;
				break;
			}
		}
	}
	ans = tate* yoko;
	cout << ans << endl;

}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

struct S{
	int h,w,l;

	S(int h,int w):h(h),w(w){
		l=h*h+w*w;
	}

	bool operator<(const S &s)const{
		if(l==s.l) return h<s.h;
		return l<s.l;
	}
};

void Solve(){
	vector<S> rects;
	rep(i,1,151) rep(j,i+1,151) rects.push_back(S{i,j});
	sort(rects.begin(),rects.end());

	int h,w;
	while(true){
		cin >> h >> w;
		if(h==0&&w==0) break;

		auto it=++lower_bound(rects.begin(),rects.end(),S{h,w});
		cout << it->h << ' ' << it->w << endl;
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 1336
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string str;
    int k;
    cin >> k;
    cin >> str;
    
    for (int i=0;i<str.size();i++) {
    char asc = (str[i]-'A'+k)%26+'A';
    cout << asc;
}
    cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        String[] numbers = line.split(" ");
        System.out.println(gcd(Integer.parseInt(numbers[0]), Integer.parseInt(numbers[1])));
    }
    
    private static int gcd(int x, int y) {
        int l = Math.max(x, y);
        int s = Math.min(x, y);
        
        if (l % s == 0) {
            return s;
        }
        return gcd(l % s, s);
    }
}



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

int main(){
int a,b;
  cin>>a>>b;
  int B;
  if(b/10==0){B=10;}
  else if(b/100==0){B=100;}
  else if(b/1000==0){B=1000;}
  int X=a*B+b;
  
  bool ans=false;
  for(int i=0; i<=1000; i++){
   if(X==i*i){ans=true;}
  }
  if(ans){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define fir first
#define sec second
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define maxd 1000000007
#define eps 1e-6
typedef long long ll;
const int N=100000;
const double pi=acos(-1.0);
int n,m,k,nx,ny,x,y;
char s[200200],t[200200];

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

int main()
{
	n=read();m=read();k=read();
	x=read(),y=read();
	scanf("%s%s",s+1,t+1);
	nx=x;ny=y;
	rep(i,1,k)
	{
		if (s[i]=='L') ny--;
		if (ny<=0) {printf("NO");return 0;}
		if ((t[i]=='R') && (ny<m)) ny++;
	}
	nx=x;ny=y;
	rep(i,1,k)
	{
		if (s[i]=='R') ny++;
		if (ny>m) {puts("NO");return 0;}
		if ((t[i]=='L') && (ny>1)) ny--;
	}
	nx=x;ny=y;
	rep(i,1,k)
	{
		if (s[i]=='U') nx--;
		if (nx<=0) {puts("NO");return 0;}
		if ((t[i]=='D') && (nx<n)) nx++;
	}
	nx=x;ny=y;
	rep(i,1,k)
	{
		if (s[i]=='D') nx++;
		if (nx>n) {puts("NO");return 0;}
		if ((t[i]=='U') && (nx>1)) nx--;
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] map = new int[3];
		map[0] = sc.nextInt();
		map[1] = sc.nextInt();
		map[2] = sc.nextInt();
		Arrays.sort(map);
		System.out.println(Math.abs(map[0] - map[1]) + Math.abs(map[1] - map[2]));
	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair


vector<ll> v;
void solve()
{
  ll k=1;
  for(ll i=0;i<=100;i++)
  {
    v.pb(k);
    k+=(i+2);
  }
}
int main()
{
  solve();
  ll a;
  cin>>a;
  if(a==1)
  cout<<0<<endl;
  else
  {
    ll count=0,ans=0;
    while(a%2==0)
    {
      count++;
      a/=2;
    }
  //  cout<<count<<endl;
    ll j=lower_bound(v.begin(),v.end(),count)-v.begin();
    if(v[j]==count)
    ans+=(j+1);
    else
    ans+=(j);
    for(ll i=3;i*i<=a;i+=2)
    {
      count=0;
      while(a%i==0)
      {
        count++;
        a/=i;
      }
      //cout<<count<<endl;
      if(count!=0)
      {
        j=lower_bound(v.begin(),v.end(),count)-v.begin();
        if(v[j]==count)
        {
          ans+=(j+1);
        }
        else
        {
          ans+=j;
        }
      }
    }
    if(a>2)
    ans+=1;
    if(ans==0)
    cout<<1<<endl;
    else
    cout<<ans<<endl;
  }
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int N; cin >> N;
  map<int, int> ma;
  rep(i, N) {
    int a; cin >> a;
    ma[a]++;
  }
  int ans = 0;
  each(m, ma) {
    if (m.second % 2) ans++;
  }
  cout << ans << '\n';
}


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

int main() {
    int n;cin>>n;
    string s;cin>>s;
    int ans = 1;
    repd(i,1,n){
        if(s[i]!=s[i-1])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int main() {
	ll N;
	cin >> N;
	cout << N*(N-1)/2 << endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
      cin >> vec.at(i);
    }
    int count = 0;
    int max1 = 0; 
    for(int i=1;i<n;i++){
      if(vec[i-1]-vec[i]>=0){
        count++;
        max1 = max(max1,count);
      }
      else count = 0;
    }
    cout << max1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define repeat_from_reverse(i, m, n) for( int i = (n) - 1; (i) >= (m); --(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t t=0; t<v.size(); ++t){cout << " " << #v << "[" << t << "]=" << v[t];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n; cin >> n;
    string s; cin >> s;
   
    int ans = 0;
    int now = 0;
    repeat(i, (int)s.length()) {
        if (s[i] == 'I') ++now;
        else --now;
        ans = max(ans, now);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int x;
  cin>>x;
  int a = x/500;
  x-=500*a;
  int b = x/5;
  cout << a*1000+b*5 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int w, h, x, y, r;
	int tmp;

	scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);
	
	if(x-r>=0 && x+r<=w && y-r>=0 && y+r<=h)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 584
#include<stdio.h>
#include<stdlib.h>
int main(){
	char c,a,e,i,o,u;
	scanf("%c",&c);
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
		printf("vowel\n");
	}else{
		printf("consonant\n");
	}
	system("pause");
}

Measured memory_bytes: 504
#include<iostream>
#include<vector>

using namespace std;

int H, W,N;

int  a[10005];

vector<int>c;

int B[105][105];

int main(void) {

	cin >> H >> W;

	cin >> N;

	int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp; a[i] = tmp;
	}

	c.push_back(-888);
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= a[i]; j++) {
			c.push_back(i);
		}
	}

	int count = 1; int q;

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if ((i % 2) == 0) {
				q = j;
			}
			else {
				q = W - j + 1;
			}
			B[i][q] = c[count]; count++;
		}
	}

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (j != 1) { cout << " "; }
			cout << B[i][j];
		}cout << endl;
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-7
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int main() {
	speed;
	ll l, r, ans = inf;
	cin >> l >> r;
	for (ll i = l; i < min(l + 4096, r); ++i)
		for (ll j = i + 1; j <= min(l + 4096, r); ++j)
			ans = min(ans, (i * j) % 2019);
	cout << ans;
}

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

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       




        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var abm = Reads();
            var A = abm[0];
            var B = abm[1];
            var M = abm[2];
            var a = Reads();
            var b = Reads();
           
            long ans = a.Min() + b.Min();
            for (int i = 0; i < M; i++)
            {
                var input = Reads();
                var x = input[0];
                var y = input[1];
                var c = input[2];
                ans = Math.Min(a[x - 1] + b[y - 1]-c,ans);
            }

            Console.WriteLine(ans);





            Console.Out.Flush();
        }
    }
}




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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<int> h(n);
	for (auto &v : h) {
		cin >> v;
	}

	vector<int> dp(n);
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; i++) {
		int aScore = dp[i - 1] + abs(h[i - 1] - h[i]);
		int bScore = dp[i - 2] + abs(h[i - 2] - h[i]);
		dp[i] = min(aScore, bScore);
	}

	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1024
module Main where

import Control.Applicative
import Text.Printf
import Numeric

main :: IO ()
main = loop

loop :: IO()
loop = do
  {[as, os, bs] <- getStrings
  ; case os of
      "?" -> return ()
      "+" -> print(readInt' as + readInt' bs) >> loop
      "-" -> print(readInt' as - readInt' bs) >> loop
      "*" -> print(readInt' as * readInt' bs) >> loop
      "/" -> print(readInt' as `div` readInt' bs) >> loop
  }
--
  
getInts :: IO[Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO()
putInts = putStrLn . unwords. map show

getDoubles :: IO[Double]
getDoubles = map read. words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble x = showFFloat Nothing x ""

getStrings :: IO [String]
getStrings = words <$> getLine

readInt' :: String -> Int
readInt' = read



Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

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

Measured memory_bytes: 256
s = input()

ac = 0
bc = 0
cc = 0
variety = 0
for c in s:

    if c == 'a':
        ac += 1
        if ac == 1:
            variety += 1

    elif c =='b':
        bc += 1
        if bc == 1:
            variety += 1

    else:
        cc += 1
        if cc == 1:
            variety += 1
#print(ac,bc,cc)

length = ac+bc+cc
ans = 'YES' if length == 1 \
    or length == 2 and variety>=2 \
    or variety == 3 and max(ac,bc,cc) - min(ac,bc,cc) <= 1 \
    else 'NO'

print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define _GLIBCXX_DEBUG
const int INF=1e15;

signed main(){
    int N;cin>>N;
    int pcost=0;
    int mcost=0;
    vector<int>vec(N);
    REP(i,N) cin>>vec[i];
    vector<int>S(N,0);
  	vector<int>Sc(N,0);
    S[0]=vec[0];
  	Sc=S;
    REP(i,N){
      	if(i%2==0&&S[i]<=0){
            int d=1-S[i];
            pcost+=d;	
            if(i!=N-1) S[i+1]=S[i]+vec[i+1]+d;
     		continue;
        }
        if(i%2==1&&S[i]>=0){
            int d=S[i]+1;
            pcost+=d;
            if(i!=N-1) S[i+1]=S[i]+vec[i+1]-d;
          continue;
        }
      	if(i!=N-1) S[i+1]=S[i]+vec[i+1];
    }
  	REP(i,N){
       if(i%2==0&&Sc[i]>=0){
            int d=1+Sc[i];
            mcost+=d;
            if(i!=N-1) Sc[i+1]=Sc[i]+vec[i+1]-d;
          continue;
        }
        if(i%2==1&&Sc[i]<=0){
            int d=1-Sc[i];
            mcost+=d;
            if(i!=N-1) Sc[i+1]=Sc[i]+vec[i+1]+d;
          continue;
        }
      	if(i!=N-1) Sc[i+1]=Sc[i]+vec[i+1];
    }
  	cout<<min(mcost,pcost)<<endl;
}


Measured memory_bytes: 2560
import sys
sx,sy,tx,ty = map(int,input().split())

if not ( -1000 <= sx <= 1000 and sx < tx <= 1000 ): sys.exit()
if not ( -1000 <= sy <= 1000 and sy < ty <= 1000 ): sys.exit()
if not ( isinstance(sx,int) and isinstance(sy,int) and isinstance(tx,int) and isinstance(ty,int)): sys.exit()

x=tx-sx
y=ty-sy
print('U'*y+'R'*x+'D'*y+'L'*x+'L'+'U'*(y+1)+'R'*(x+1)+'DR'+'D'*(y+1)+'L'*(x+1)+'U')

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

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

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

    int m;
    cin>>m;

    vector<int> p(m),x(m);
    for(int i=0; i<m; i++){
        cin>>p[i]>>x[i];
    }

    for(int i=0; i<m; i++){
        int sum=0;
        for(int j=0; j<n; j++){
            if(j==p[i]-1){
                sum+=x[i];
                continue;
            }
            sum+=t[j];
        }

        cout<<sum<<endl;
    }
}

Measured memory_bytes: 3516
require 'set'

def main
    m = 100
    x = gets.to_i
    cnt = 0
    while m < x
        m *= 1.01
        m = m.to_i
        cnt += 1
    end
    puts cnt
end

main

## イディオムなど
# until s.empty? do
#
## 配列のインデックス
# s[0,6] # 0番目から6文字
# s[0..6] # 0番目から6番目まで
# s[5..-1] # 5番目から最後まで
#
## 全探索
# [0, 1].repeated_permutation(n) do |combination| # bit全探索
# array.combination(i) do |selected| # array から要素が i 個である部分列を全部抽出
#
## 無向グラフの幅優先探索(BFS)
# to = Array.new(n).map{Array.new()} # ある頂点と繋がる頂点のリスト
# m.times do
#     a,b = gets.chomp.split(" ").map(&:to_i)
#     to[a].push b
#     to[b].push a
# end
# q = Queue.new # BFS は queue
# ds = Array.new(n, -1)
# pre = Array.new(n, -1)
#
## その他
# a1 = Marshal.load(Marshal.dump(a2)) # 深いコピー
# matrix = Array.new(n).map{Array.new()} # 二次元配列の初期化
# 

Measured memory_bytes: 14444
N = int(input())
A = list(map(int,input().split()))

minuscount = 0
for i in range(0,N,1):
    if A[i] < 0:
        minuscount +=1
    if A[i]==0:
        minuscount = 0
        break

ans = 0
for i in range(0,N,1):
    ans += abs(A[i])

minabs = 10**10
if minuscount % 2 !=0:
    for i in range(0,N,1):
        minabs = min(minabs,abs(A[i]))
    ans -= 2*minabs

print(ans)

Measured memory_bytes: 20040
def check(arr)
  arr.each do |c|
    unless "ATGC".split('').include?(c)
      return false
    end
  end
  true
end

s = gets.chomp.split('')

atgc = [0]

1.upto(s.size) do |i|
  s.each_cons(i) do |arr|
    if check(arr)
      atgc << arr.size
    end
  end
end

puts atgc.max

Measured memory_bytes: 1916
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;
using namespace __gnu_pbds;

mt19937_64 gen(time(0));

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

//const int mod = 1e9 + 7;
//const int inf = 2e9 + 6555;
const int maxn = 2e5 + 55;

int a[maxn];

signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    for(int i = k; i < n; ++i)
    {
        if (a[i - k] >= a[i]) cout << "No\n";
            else cout << "Yes\n";
    }
    return 0;
}


Measured memory_bytes: 4440
a, b, k = list(map(int, input().split()))
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = set(table)
    return table
ablist = sorted(list(divisor(a) & divisor(b)),reverse=True)
print(ablist[k-1])

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

using namespace std;

#define inf 1<<30
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> P;


int main(){
	int n, h, w, cnt = 0;
	cin >> n >> h >> w;
	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		if(h <= a && w <= b)
			cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int N = 5000;
int a[N];
const int K = 8;
long long cnt[K + 1];
long long sum = 0;
char s[K + 1] = "FESTIVAL";

bool solve(long long n)
{
	int pos = 0;
	memset(cnt, 0, sizeof cnt);
	cnt[0] = 1;
	sum = 1;

	while (pos < N)
	{
		vector <int> good;
		long long bst = 0;
		int bsti = -1;
		for (int i = 0; i < K; i++)
		{
			long long nx = sum + cnt[i];
			if (nx <= n && nx > sum)
			{
				good.push_back(i);
				if (nx > bst)
				{
					bst = nx;
					bsti = i;
				}
			}
		}
		if (good.empty() ) break;
		int id = pos / 200;
		if (find(good.begin(), good.end(), id) == good.end() )
			id = good.back();

		a[pos++] = good[id];
		cnt[good[id] + 1] += cnt[good[id] ];
		sum += cnt[good[id] ];
	}
	if (sum != n) 
	{
		eprintf("sum = %lld\n  n = %lld\n\n", sum, n);
		return false;
	}
	for (int i = 0; i < K; i++)
		printf("%c", s[i] );
	for (int i = pos - 1; i >= 0; i--)
		printf("%c", s[K - a[i] - 1] );
	printf("\n");
	return true;
}


int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	long long n;
	scanf("%lld", &n);

	while (true)
	{
		if (solve(n) ) break;
	}


	return 0;
}



Measured memory_bytes: 384
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */

    //#pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(int i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(int i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(int i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 1030000;

    void solve() {
      ll a, b, k;
      cin >> a >> b >> k;
      rep(i, k){
        if(i%2) {
          a+=b/2, b/=2;
        } else {
            b+=a/2, a/=2;
        }
      }
      cout << a << " " << b << endl;
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //te
      solve();
      return 0;
    } 

Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))

m = A[0] + K - A[-1]
res = A[0] + K - A[-1]

for i in range(len(A) - 1):
    res += A[i + 1] - A[i]
    m = max(m, A[i + 1] - A[i])
print(res - m)


Measured memory_bytes: 77388
# -*- coding: utf-8 -*-
import sys

def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))
    

    A_list.sort(key=lambda x: -abs(x))
    A_plus = []
    A_minus = []
    mod = 10**9 + 7

    for val in A_list:
        if val >= 0:
            A_plus.append(val)
        else:
            A_minus.append(val)
    

    select = []
    i_p = 0  # index of A_plus
    i_m = 0  # index of A_minus

    
    while (len(select) < K):
        if (K - len(select)) == 1:
            if i_p < len(A_plus):
                select.append( A_plus[i_p] )
                i_p += 1
                break
            
            else:
                ans = 1

                for i in range( len(A_list)-K, len(A_list) ):
                    ans *= A_list[i]
                    ans %= mod

                print(ans)
                return


        if (i_m + 1) < len(A_minus):
            if (i_p + 1) < len(A_plus):
                if abs( A_plus[i_p] * A_plus[i_p + 1] ) > abs( A_minus[i_m] * A_minus[i_m + 1] ):
                    select.append( A_plus[i_p] )
                    i_p += 1
                else:
                    select.extend( [ A_minus[i_m] , A_minus[i_m + 1] ] )
                    i_m += 2

            else:
                select.extend( [ A_minus[i_m] , A_minus[i_m + 1] ] )
                i_m += 2
            
        else:
            select.append( A_plus[i_p] )
            i_p += 1
    


    ans = 1
 
    for i in range(K):
        ans *= select[i]
        ans %= mod
    
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 31704
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

using namespace std;

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

int main(){
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    vector<int> MIN(n);
    MIN[0] = a[0];
    REP(i, 1, n){
        MIN[i] = min(a[i], MIN[i-1]);
    }
    int maxProfit = 0;
    map<int, int> mp;
    rep(i, n){
        maxProfit = max(maxProfit, a[i]-MIN[i]);
        mp[a[i]-MIN[i]]++;
    }
    cout << mp[maxProfit] << endl;
    return 0;
}

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

int main() {
    int N,A,B;cin>>N>>A>>B;
    string S;cin>>S;
    int a = 0, b = 0;
    for(int i=0;i<N;++i){
        if(S[i]=='c') cout << "No";
        else if(S[i]=='b'){
            if(b < B && a+b < A+B) {
                ++b;
                cout << "Yes";
            } else {
                cout << "No";
            }
        }
        else {
            if(a+b < A+B){
                ++a;
                cout << "Yes";
            } else {
                cout << "No";
            }
        }
        cout << '\n';
    }
    return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
using Graph = vector<vector<int>>;

void dfs(int v, Graph g, vector<int> &seen){
	if(seen[v]==1) return;
	seen[v] = 1;

	for(auto nv : g[v]){
		if(seen[nv] == 1) continue;
		dfs(nv, g, seen);
	}
}

int isConnected(Graph g){
	vector<int> s;
	s.assign(g.size(), 0);
	dfs(0, g, s);
	int sum = 0;
	for(int i = 0; i < s.size(); i++){
		sum += s[i];
	}
	if(g.size() == sum){
		return 1;
	}
	else{
		return 0;
	}
}

int isBridge(Graph g, vector<pair<int, int>> v, int e){
	int a = v[e].first;
	int b = v[e].second;
	int i = 0;
	for(i = 0; i < g[a].size(); i++){
		if(g[a][i] == b){
			break;
		}
	}
	g[a].erase(g[a].begin() + i);
	for(i = 0; i < g[b].size(); i++){
		if(g[b][i] == a){
			break;
		}
	}
	g[b].erase(g[b].begin() + i);

	int ret = isConnected(g);
	if(ret==0){ 
		ret = 1;
	}
	else{
		ret = 0;
	}
	return ret;
}

int main(int argc, char* argv[]){
	int N, M;
	vector<pair<int, int>> edge;

	cin >> N >> M;
	Graph G(N);

	for(int i=1; i<=M; i++){
		int a, b;
		cin >> a >> b;
		a = a - 1; b = b - 1;
		edge.push_back( make_pair(a, b) );
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	for(int i=0; i<M; i++){
		ans += isBridge(G, edge, i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int,int>PII;
const LL inf = 1 << 30;
const int mod = 998244353;
map<int,int>mp;
map<int,int>mp1;
map<PII,int>::iterator it;
const int maxn = 1e5;
struct point{
    int x,y,flag;
}s,q;
int n;
LL num[2*maxn+5];
int main(){
	cin >> n;
	for(int i = 1;i<=n;i++){
		cin >> num[i];
		mp[num[i]] = i;
	}
	sort(num+1,num+n+1);
	int min_i = 0;
	LL min = inf;
	for(int i = 1;i<n;i++){
		if(num[i]<=num[n]/2){
			if(min > num[n]/2 - num[i]){
				min_i = i;
				min = num[n]/2 - num[i];
			}
		}
		else{
			if(min > num[i] - num[n]/2 - 1){
				min_i = i;
				min = num[i] - num[n]/2 - 1;
			}
		}
	}
	printf("%lld %lld\n",num[n],num[min_i]);
    return 0;
}

Measured memory_bytes: 5760
#include <cstdio>
#include <queue>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<double, int> P;

const double inf = 8e5;

struct E{
	E(int t, double c) :
		t(t), c(c)
	{}

	int t;
	double c;
};

int n, m, p, a, b;
int t[8];
vector<E> g[30 * (1 << 8)];
double d[30 * (1 << 8)];

int index(int i, int j){
	return i * (1 << n) + j;
}

int main(){
	while(1){
		scanf("%d%d%d%d%d", &n, &m, &p, &a, &b);
		if(n == 0){
			break;
		}
		--a;
		--b;
		rep(i, n){
			scanf("%d", &t[i]);
		}
		rep(l, p){
			int x, y;
			double z;
			scanf("%d%d%lf", &x, &y, &z);
			--x;
			--y;
			rep(i, 1 << n){
				rep(j, n){
					if(i & (1 << j)){
						int k = i - (1 << j);
						g[index(x, i)].push_back(E(index(y, k), z / t[j]));
						g[index(y, i)].push_back(E(index(x, k), z / t[j]));
					}
				}
			}
		}

		fill_n(d, m * (1 << n), inf);

		priority_queue<P, vector<P>, greater<P> > q;
		d[index(a, (1 << n) - 1)] = 0;
		q.push(P(0, index(a, (1 << n) - 1)));
		while(!q.empty()){
			P v = q.top();
			q.pop();
			if(v.first > d[v.second]){
				continue;
			}
			rep(i, g[v.second].size()){
				E e = g[v.second][i];

				if(d[e.t] > v.first + e.c){
					d[e.t] = v.first + e.c;
					q.push(P(d[e.t], e.t));
				}
			}
		}

		double ans = *min_element(d + index(b, 0), d + index(b + 1, 0));
		if(ans != inf){
			printf("%lf\n", ans);
		}
		else{
			puts("Impossible");
		}

		rep(i, m * (1 << n)){
			g[i].clear();
		}
	}
	return 0;
}

Measured memory_bytes: 23988
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1e18;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<int>E[202020];
vector<pair<int, int>>e;
map<pair<int, int>, int>mp;
set<int>st;
void dfs(int now,int pa,int ng){
	int num = 1;
	fore(x, E[now]) {
		if (x != pa) {
			if (num == ng)num++;
			mp[{min(x, now), max(x, now)}] = num;
			st.insert(num);
			dfs(x,now,num);
			num++;
		}
	}
}

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

	int N;
	cin >> N;
	for (int i = 0; i < N-1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].pb(b);
		E[b].pb(a);
		e.pb({min(a,b),max(a,b)});
	}
	dfs(0, -1, -1);
	puts(st.size());
	for (int i = 0; i < N - 1; i++) {
		int ans = mp[{e[i].first, e[i].second}];
		puts(ans);
	}
	

	return 0;
} 

Measured memory_bytes: 18300
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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



ll a[1000000];
ll N, A ,B = 1e16, C;
int main(){
  cin >> N;
  rep(i,5){
    cin >> A;
    B = min(A,B);
  }
  C = (N + (B-1))/ B;
  cout <<  C + 4 << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    string s;
    cin>>s;
    ll ans=s.size()*(s.size()-1)/2+1,alp[26]={0};
    rep(i,s.size()) alp[s[i]-'a']++;
    rep(i,26) ans-=alp[i]*(alp[i]-1)/2;
    cout<<ans;
}

Measured memory_bytes: 640
d,g = map(int,input().split())
pc = [0]*d
for i in range(d):
    pc[i] = list(map(int,input().split()))
ans_new = float("inf")
for i in range(1<<d):
    num = 0
    ans = 0
    for j in range(d):
        if (i >> j)%2 == 1:
           num += pc[j][0]*(j+1)*100 + pc[j][1]
           ans += pc[j][0]
    if num < g:
        dum = 0
        for k in range(d):
            if (i >> k)%2 == 0:
               dum = k
        for l in range(pc[dum][0]):
            num += (dum+1)*100
            ans += 1
            if num >= g:
                break
        else:
            continue
    ans_new = min(ans,ans_new)
print(ans_new)

Measured memory_bytes: 9240
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    t = 0
    for i in range(1, n + 1):
        if len(str(i)) % 2 != 0:
            t += 1
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38768
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define INF (1<<30)-1
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vi a(n);
  vector<vi> x(n),y(n);
  rep(i,n){
    cin >> a[i];
    x[i].resize(a[i]);
    y[i].resize(a[i]);
    rep(j,a[i]){
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }
  int ans = 0;
  rep(bit,1<<n){
    bool ok = true;
    rep(i,n){
      if(bit>>i & 1){
        rep(j,a[i]){
          if((bit>>x[i][j] & 1)^y[i][j]) ok = false;
        }
      }
    }
    if(ok) chmax(ans,__builtin_popcount(bit));
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3588
a, b, c = map(int, input().split())
d = []
for i in range(a, a + c):
    if i not in d and i <= b:
        d.append(i)
for i in range(b, b - c, -1):
    if i not in d and i >= a:
        d.append(i)
d.sort()
for i in d:
    print(i)


Measured memory_bytes: 3060
s=input()
c=0
d=0
i=0
while i<len(s):
    if s[i]=="A":
        c+=1
    else:
        if s[i]=="B" and c>0:
            if i<len(s)-1:
                if s[i+1]=="C":
                        d+=c
                        i+=1
                else:
                    c=0
        else:
            c=0
    i+=1
print(d)                   

Measured memory_bytes: 3500
n,k = gets.split.map(&:to_i)
a = gets.split.map{|a|a.to_i+1}

w = []
k.times{|i|
  w << a[i]
}
sum = w.inject(:+)
max = sum
(k...n).each{|i|
  sum -= w.shift
  w << a[i]
  sum += a[i]
  max = sum if max < sum
}
p max/2.0


Measured memory_bytes: 16644
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (int)(s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
constexpr long long INF = 1e18;
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;}

#define IN(a, x, b) (a<=x && x<b)

signed main(){
	int N,K;
	cin>>N>>K;
	vector<int>a(N);
	REP(i,N){
		cin>>a[i];
	}
	set<int>st;
	int ans = 1;
	REP(i,K){
		st.insert(a[i]);
	}
	REP(i,N-K){
		st.erase(a[i]);
		if(*st.begin()<a[i]||*prev(st.end())>a[i+K])ans++;
		st.insert(a[i+K]);
	}
	int minus = -1;
	int sort = 1;
	int flg = 0;
	REP(i,N-1){
		if(a[i]<a[i+1])sort++;
		else sort = 1;
		if(sort==K){minus++;flg=true;}
		//cout<<i<<" "<<sort<<" "<<minus<<endl;
	}
	if(flg)cout<<ans-minus<<endl;
	else cout<<ans<<endl;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    pii a[n];
    rep(i, n) {
        cin >> a[i].F;
        a[i].S = i;
    }
    sort(a, a + n);
    vector<int> ans(n);
    rep(i, n) ans[i] = a[n - 1].F;
    ans[a[n - 1].S] = a[n - 2].F;
    rep(i, n) out(ans[i]);
}


Measured memory_bytes: 3968
#include <stdio.h>



int main(){
  int n,i,j,k,N,K;

  scanf("%d",&n);
  int Adj[n+1][n+1];
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      Adj[i][j]=0;
			
  for(i=1;i<=n;i++){
    scanf("%d",&N);
    scanf("%d",&k);

    for(j=1;j<=k;j++){
      scanf("%d",&K);
      Adj[N][K]=1;
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j==n)   printf("%d\n",Adj[i][j]);
      else printf("%d ",Adj[i][j]);
    }
  }
  return 0;
}

Measured memory_bytes: 636
n, m = map(int, input().split())
node = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    node[a].append(b)
    node[b].append(a)

ans = [-1] * n
ans[0] = 0
stk = [[0] + node[0]]

while stk:
    s = stk.pop(0)
    fr = s[0]
    for i in s[1:]:
        if ans[i] == -1:
            ans[i] = fr + 1
            stk.append([i] + node[i])

if -1 in ans:
    print('No')
else:
    print('Yes')
    for i in range(1, n):
        print(ans[i])


Measured memory_bytes: 42948
#include <stdio.h>

int main(){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  //c-b,a-d
  while(a>0 && c>0){
    c = c-b;
    a = a-d;
  }
  if((c<=0 && a<=0)||(c<=0 && a>0)){
    printf("Yes\n");
    return 0;
  }
  else if(c>0 && a<=0){
    printf("No\n");
    return 0;
  }
  else{
    printf("違うで");
  }
}


Measured memory_bytes: 1624