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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  map<int, int> cnt;
  rep(i, n) {
    int a; std::cin >> a;
    cnt[a]++;
  }
  ll ma1 = 0, ma2 = 0;
  for (auto &p : cnt) {
    if (p.se < 2) continue;
    if (ma1 < p.fi) {
      ma2 = ma1;
      ma1 = p.fi;
      if (p.se > 3) ma2 = p.fi;
    } else if (ma2 < p.fi) {
      ma2 = p.fi;
    }
  }
  std::cout << ma1 * ma2 << "\n";
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

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

int main(){
  int a,b,n;
  while(~scanf("%d%d%d",&a,&b,&n)){
    int sum = 0;
    while(n){
      if( a/b==0 ){
	int k = a*10/b;
	sum += k;
	a = a*10 - k*b;
	n--;
      }else{
	int k = a/b;
	a = a - k*b;
      }
#if DEB
      printf("%d/%d\n",a,b);
#endif
    }
    printf("%d\n",sum);
  }
  return 0;
}

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

int main(){

  int N;
  cin >> N;
  int L;
  cin >> L;
  int A=abs(L);

  for(int i=0; i<N; i++){
	if(abs(A)>abs(L+i))A = L+i;
  }

  cout << (N*L+0.5*(N-1)*N - A) << endl;


  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
using namespace std;
int main(void){
  int H,W;
   while(1){
       cin>>H>>W;
       if(H==0&&W==0)break;
      
   for(int i=1;i<=H;i++){
     for(int j=1;j<=W;j++){
        if((i+j)%2==0){
            cout<<"#";
        }
        else cout<<".";
      }
     cout<<"\n";
    }
  cout<<"\n";
   }
}
   



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

#define get_variable_name(x) #x
#define debug(x) cout << #x << " = " << x << endl

#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define REVERSE(x) reverse( (x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define PW(x) (1LL<<(x))

using namespace std;
using ll = int64_t;
using P = pair<int, int>;

template<class T,class U>
ostream& operator<<(ostream &os, const pair<T, U> &p) {
    os << get_variable_name(p) << " = (" << p.first <<", " << p.second << ")";
    return os;
}

template<class T>
ostream& operator <<(ostream& os, const vector<T> &v){
    cout << get_variable_name(v) << " = [";
    for(auto i : v) 
        os << " " << i;
    os << " ]";
    return os;
}


const int INF = 1e8;

int main() {
    ios::sync_with_stdio(false);
    string A, B, C;
    cin >> A >> B >> C;
    A = "A";
    A += B[0];
    A += "C";
    cout << A << endl;
}


Measured memory_bytes: 256
// AOJ Volume 1 Problem 0100

#include <stdio.h>
#include <string.h>

typedef struct {
	int no;
	long long sales;
} DATA;


int main(void)
{
	DATA sale[4000];
	int i, j;
	int n;
	int no, price, quantity;
	int data_no;
	int flag;

	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		memset(sale, 0, sizeof(sale));
		data_no = 0;

		for (i = 0; i < n; i++){
			scanf("%d%d%d", &no, &price, &quantity);
			
			for (j = 0; j < data_no; j++){
				if (sale[j].no == no){
					break;
				}
			}
			if (j == data_no){
				sale[j].no = no;
				sale[j].sales = 0;
				data_no++;
			}
			
			if (sale[j].sales < 1000000){
				sale[j].sales += ((long long)price * quantity);
			}
		}
		
		flag = 0;
		for (i = 0; i < data_no; i++){
			if (sale[i].sales >= 1000000){
				printf("%d\n", sale[i].no);
				flag = 1;
			}
		}
		if (flag == 0){
			printf("NA\n");
		}
	}
	
	return (0);
}



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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (998244353)
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long a, b, c, d;
        cin >> a >> b >> c >> d;

        for (long i = 0; i < 1000; i++) {
            if (i % 2 == 0) {
                c -= b;
                if (c <= 0) {
                    puts("Yes");
                    return 0;
                }
            } else {
                a -= d;
                if (a <= 0) {
                    puts("No");
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 3596
n = int(input())

flag = False
for i in range(1, 10):
    if n%i == 0:
        remain = n/i
        for j in range(1, 10):
            if remain== j:
                print("Yes")
                flag =True
                break
        
        if flag:
            break
            
if not flag:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
 
using namespace std;
 
int main(void){
  while(1){
    int n , m;
    cin >> n;
    cin >> m;
    if(n == 0 && m == 0){
      return 0;
    }
 
    int a[n];
    for(int i = 0 ; i < n ; i ++){
      cin >> a[i];
    }
 
    int sum[n][n];
 
    for(int i = 0 ; i < n ; i ++){
      for(int j = 0 ; j < n ; j++){
        if(i != j){ sum[i][j] = a[i] + a[j]; }
        else{ sum[i][j] = -1000; }
      }
    }
 
    int max = -1000;
 
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
        if( sum[i][j] > max && sum[i][j] <= m ){
          max = sum[i][j];
        }
      }
    }
 
    if(max == -1000){
      cout << "NONE" << endl;
    }else{
      cout << max << endl;
    }
  }
 
}

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

const int MAX_N = 1e5 + 1;

int D[MAX_N];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> D[i];
    sort(D, D + N);
    int mid1 = D[N / 2 - 1];
    int mid2 = D[N / 2];
    if (mid1 == mid2) cout << 0 << endl;
    else cout << mid2 - mid1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b;
    cin >> a >> b ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    //*/
    
    //*
    if( abs(a - b) % 2 != 0 ){
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << abs(a - b) / 2 + min(a, b) << endl;
    }
    //*/
    
    //cout << max(c - a + b, 0) << endl;

    return 0; 
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define MAX_N 2002

vector<int> G[MAX_N];
queue<int> que;
bool d[MAX_N][MAX_N]={};
int db1[MAX_N][MAX_N]={};
int dc1[MAX_N][MAX_N]={};
int dc2[MAX_N][MAX_N]={};
vi v;
int main() {
	int n,m,q;
	cin>>n>>m>>q;
	rep(i,n){
		rep(j,m){
			char chr;
			cin>>chr;
			if(chr=='1')d[i+1][j+1]=true;
		}
	}
	rep(i,n){
		int d1=0;
		int d2=0;
		int d3=0;
		rep(j,m){
			db1[i+1][j+1]=db1[i][j+1];
			if(d[i+1][j+1])	++d1;
			db1[i+1][j+1]+=d1;
			dc1[i+1][j+1]=dc1[i][j+1];
			dc2[i+1][j+1]=dc2[i+1][j];
			if(d[i+1][j+1]&&d[i][j+1])++dc1[i+1][j+1];
			if(d[i+1][j+1]&&d[i+1][j])++dc2[i+1][j+1];
		}
	}
	rep(i,q){
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		int t=db1[x2][y2]-db1[x2][y1-1]-db1[x1-1][y2]+db1[x1-1][y1-1];
		REP(i,x1,x2+1)t-=dc2[i][y2]-dc2[i][y1];
		REP(i,y1,y2+1)t-=dc1[x2][i]-dc1[x1][i];
		cout<<t<<endl;
	}
	return 0;
}


Measured memory_bytes: 52736
#include<cstdio>
#include<queue>
using namespace std;
#define N 200050
int fa[N],sz[N],head[N],cnt,mx[N],f[N],ti=1,as[N],n,a,b,fr[N],vl[N];
struct edge{int t,next;}ed[N*2];
priority_queue<pair<int,int> > st;
int finds(int x){return fa[x]==x?x:fa[x]=finds(fa[x]);}
void adde(int f,int t){ed[++cnt]=(edge){t,head[f]};head[f]=cnt;ed[++cnt]=(edge){f,head[t]};head[t]=cnt;}
void dfs1(int u,int fa){f[u]=fa;mx[u]=mx[f[u]],fr[u]=fr[f[u]];if(mx[u]<fa)mx[u]=fa,fr[u]=u;for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)dfs1(ed[i].t,u);}
int que(int x){if(x<ti)return sz[finds(x)]-1;int as=0;for(int i=head[x];i;i=ed[i].next)if(ed[i].t<ti)as+=sz[finds(ed[i].t)];return as;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)scanf("%d%d",&a,&b),adde(a,b);
	for(int i=1;i<=n;i++)fa[i]=i,sz[i]=1;
	dfs1(1,0);
	for(int i=head[1];i;i=ed[i].next)st.push(make_pair(-1,ed[i].t));
	while(!st.empty())
	{
		int las=ti;
		ti=-st.top().first;int s=st.top().second;st.pop();
		for(int i=las;i<ti;i++)
		for(int j=head[i];j;j=ed[j].next)if(ed[j].t<i){int a=finds(i),b=finds(ed[j].t);fa[a]=b,sz[b]+=sz[a];}
		as[s]+=as[mx[s]]+que(s)+1-vl[fr[s]];
		for(int i=head[s];i;i=ed[i].next)if(ed[i].t!=f[s])st.push(make_pair(-mx[ed[i].t],ed[i].t)),vl[ed[i].t]=ed[i].t<ti?sz[finds(ed[i].t)]:0;
	}
	for(int i=2;i<=n;i++)printf("%d ",as[i]);
}

Measured memory_bytes: 17280
N, M = list(map(int,input().split()))
s = []
k = []
for i in range(M):
    in1 = list(map(int,input().split()))
    k.append(in1[0])
    s.append(in1[1:])
p = list(map(int,input().split()))

def bit_all():
    ret = 0
    for x in range(2 ** N):
        b = str(format(x, '010b'))
        add = 1
        for i in range(M):
            count = 0
            for j in s[i]:
                j -= 1
                if b[-(j + 1)] == "1": 
                    count += 1
            if count % 2 != p[i]:
                add = 0
        ret += add
    return ret

ans = bit_all()
print(ans)

Measured memory_bytes: 41456
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
using namespace std;
using ll = long long;

int main() {
  int W, H;
  cin >> W >> H;
  vector<pair<ll, int>> es;
  for (int i = 0; i < W; i++) {
    ll p;
    cin >> p;
    es.emplace_back(p, 0);
  }
  for (int i = 0; i < H; i++) {
    ll q;
    cin >> q;
    es.emplace_back(q, 1);
  }
  sort(es.begin(), es.end());
  ll res = 0;
  vector<int> rem(2, 0);
  rem[0] = W + 1;
  rem[1] = H + 1;
  for (auto e: es) {
    ll p = e.first;
    int t = e.second;
    res += rem[t^1] * p;
    --rem[t];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 6512
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > P;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
const long long int mod = 1e9 + 7;

int A[101];
int main()
{
    int N,M,X,f=0,b=0;
    cin >> N >> M >> X;
    rep(i,0,M) cin >> A[i];   
    rep(i,0,M){
        if(A[i]<X) f++;
        else b++;
    }
    if(f > b) cout << b << endl;
    else cout << f << endl;
}

Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n; cin >> n;
  map<str, ll> a;
  rep(i, n)
  {
    str s; cin >> s;
    a[s]++;
  }
  cout << "AC x " << a["AC"] << "\nWA x " << a["WA"] << "\nTLE x " << a["TLE"] << "\nRE x " << a["RE"] << "\n";
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int sum = 0;
    int sumt = 0;
    for (int i = 0; i < n; i++){
        int x;
        scanf("%d",&x);
        sum += x;
        sumt += x*x;
    }
    sum *= sum;
    printf("%d",(sum-sumt)/2);
}


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

print(" ".join(map(str, A)))

for i in range(1, N):
  v = A[i]
  j = i - 1
  while j >= 0 and A[j] > v:
    A[j + 1] = A[j]
    j -= 1
  A[j+1] = v
  print(" ".join(map(str, A)))




Measured memory_bytes: 5600
N, M = (int(x) for x in input().split())
A = list(map(int, input().split()))
sum=0
cnt=0
for i in range(N):
  sum+=A[i]
sum/=4*M
for i in range(N):
  if A[i]>=sum:
    cnt+=1
if cnt>=M:
  print("Yes")
else:
  print("No")

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

int main() {
  int n,l; cin>>n>>l;
  int a=n*(2*l+n-1)/2;
  if(l>=0)a-=l;
  else if(l<1-n)a-=l+n-1;
  cout<<a;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1e9 + 7;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int cnt = 0;
	ll ans = 1;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		cnt++;
		if (cnt * 2 > x + 1) {
			(ans *= cnt) %= MOD;
			cnt--;
		}
	}

	for (int i = 2; i <= cnt; i++) {
		(ans *= i) %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF=1e9;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n),cost(n,INF);
    rep(i,n) cin>>a[i];
    cost[0]=0;
    cost[1]=abs(a[0]-a[1]);
    for(int i=1;i<n;i++){
        for(int j=1;j<n&&j<=k;j++){
            if(i-j>=0){
                cost[i]=min(cost[i-j]+abs(a[i]-a[i-j]),cost[i]);
            }
        }
    }
    cout<<cost[n-1]<<endl;
}

Measured memory_bytes: 4012
r, g, b, n = map(int, input().split())

rm = n // r
gm = n // g
count = 0
for i in range(rm + 1):
    for j in range(gm + 1):
        if ((n - r * i - g * j) % b == 0 and (n - r * i - g * j) // b >= 0):
            count += 1

print(count)


Measured memory_bytes: 40940
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner ob=new Scanner(System.in);
		String s=ob.nextLine();
		int n=s.length();
		String arr=""+s.charAt(0);
		
		int i,j;
		i=1;
int r=1;
		while(i<n)
		{
			String v="";
			j=i;
			while(j<n)
			{
				v=v+s.charAt(j);
			
				if(v.equals(arr))
				{j++;
				}
				else 
					break;
			}
			i=j+1;
			if(v.equals(arr))
				r--;
			arr=v;
		
			r++;
			
		}
		System.out.println(r);
	}
}

Measured memory_bytes: 40940
N,A,B = map(int,input().split())
S = input()
for i in range(N):
	if S[i] == "c":
		print("No")
	elif S[i] == "a" and A + B > 0:
		print("Yes")
		A-=1
	elif S[i] == "b" and A + B > 0 and B > 0:
		print("Yes")
		B-=1
	else:
		print("No")

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define EPS 0.0000000001
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    for (int i = 0; i < k; i++)
    {
        cin >> d[i];
    }
    bool dd = true;
    string ans;
    for (int i = n; i <= n * 10; i++)
    {
        string s = to_string(i);

        int x = s.size();
        dd = true;
        for (int iii = 0; iii < x; iii++)
        {
            for (int j = 0; j < k; j++)
            {
                if ((s[iii] - '0') == d[j])
                {
                    dd = false;
                }
            }
        }
        if (dd == true)
        {
            ans = s;
            break;
        }
    }
    
        cout << ans << endl;
    
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
V = LIST()
V.sort()

for i in range(n-1):
    V[i+1] = V[i]+V[i+1]
    V[i+1] = V[i+1]/2
    # print(V)
print(V[-1])


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

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

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

vector<int> v[9];
bool seen[9];

ll dfs(int idx, int pat, int n,ll &cnt){
    if(pat==n-1){
        cnt++;
        return cnt;
    }
    int next;
    rep(i,v[idx].size()){
        next = v[idx][i];
        if(seen[next] == false){
            seen[next] = true;
            cnt = dfs(next,pat+1,n,cnt);
            seen[next] = false;
        }

    }
    return cnt;
}

int main(){
    int n, m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll cnt=0 ;
    seen[1] = true;
    dfs(1,0,n,cnt);
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
P = [int(input())-1 for i in range(n)]

A = [0] * n
for i in range(n):
    A[P[i]] = i

ans = 1
ans1 = 1
for i in range(1, n):
    if A[i] > A[i-1]:
        ans1 += 1
    else:
        ans = max(ans1, ans)
        ans1 = 1
ans = max(ans1, ans)

print(n - ans)

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

int main(){
    ll n;
    set<string> list;
    cin>>n;
    string w;
    char s;
    int size=list.size();
    bool flg=true;
    rep(i,n){
        cin>>w;
        list.insert(w);
        if(size==list.size()){
            flg=false;
            // cout<<"double:"<<w<<endl;
        }
        size=list.size();

        if(i==0){
            s = w[w.size()-1];
        }else{
            if(s!=w[0]){
                flg=false;
                // cout<<"no siritori:"<<s<<","<<w<<endl;
            }
            s = w[w.size()-1];
        }
    }

    if(flg==false) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

}



Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int indexBF(char str[],char a[],int index,int N)
{
    int i=index;
    int j=0;
    while(i<N && j<3)
    {
        if(str[i]==a[j])
        {
            i++;
            j++;
        }
        else
        {
            i=i-j+1;
            j=0;
        }
    }
    if(j>=3)
        return i;
    else
        return N+1;
}
int main()
{
    int N;
    int num=0;
    char str[55];
    char a[5];
    strcpy(a,"ABC");
        scanf("%d",&N);
    scanf("%s",str);
    int i=indexBF(str,a,0,N);
    while(i<N+1)
{
        num++;
        i=indexBF(str,a,i,N);

    }
    printf("%d",num);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> Count(N);
  for (int i = 0; i < M; i++) {
    int a,b;
    cin >> a >> b;
    Count[a - 1]++; Count[b - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << Count[i] << endl;
  }
  return 0;
}


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

int main(){
    ll N,a,MIN=999999999999,ans=0,cn=0;cin>>N;
    rep(i,0,N){
        cin>>a;
        if(a<0)cn++;
        MIN=min(MIN,abs(a));
        ans+=abs(a);
    }
    if(cn%2==1)ans=ans-2*MIN;
    cout<<ans<<endl;
}







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

int main(){
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  int total=0;
  for(int i=1;i<=N;i++){
    if(i < K+1){
      total+=X;
    }else{
      total+=Y;
    }
  }
  cout << total << endl;

}


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

const int limit = 11729;
string dp[limit];
int match[10] = {8901016, 2, 5, 5, 4, 5, 6, 3, 7, 6};

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

  int n, m;
  cin >> n >> m;

  vector<int> al(m);
  for(int i = 0; i < m; i++) {
    cin >> al[i];
  }
  sort(al.begin(), al.end(), greater<int>());
  for(int i =0; i < limit; i++) {
    dp[i] = "";
  }
  for(int i = 0; i < n; i++) {
    if(i > 0 && dp[i].size() ==0) { 
      continue; 
    }
    for (auto j : al) {
      int idx = i + match[j];
      dp[idx] = [&](string s, string t) {
        if (t.size() > s.size() || t > s) {
          return t;
        }
        return s;
      }(dp[idx], dp[i] + to_string(j));
    }
  }

  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 33536
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  long n,x;
  cin>>n>>x;

  vector<long> v(51);
  vector<long> p(51);
  v[0] = 1;
  p[0] = 1;
  rep(i,50) v[i+1] = v[i]*2 + 3;
  rep(i,50) p[i+1] = p[i]*2 + 1;

  long ans = 0;
  for(int i=n-1;i>=0;i--){
    if(x >= v[i]+2){
      ans += p[i] + 1;
      x -= v[i] + 2;
    } else if(x > 0){
      x--;
    }

    dbg(i,x,ans);
  }
  if(x >= 1) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main() {
	long long int n, s[100001] = {},m,count=0;
  	scanf("%lld",&n);
    
	
      
      	for (int k = 1; k*k <= n; k++) {
			m=k*k;
		}
		
		printf("%lld", m);

}

Measured memory_bytes: 128
/*
  AtCoder Beginner Contest 099
  D - Good Grid
*/

#include<iostream>
#include<vector>
#include<limits>
using namespace std;

int N, C;
int D[30][30];
int c[3][500] = {0};

int main() {
  scanf("%d%d", &N, &C);
  
  for (int i = 0; i < C; ++i) for (int j = 0; j < C; ++j) scanf("%d", &D[i][j]);
  
  int buf;
  for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
    scanf("%d", &buf);
    for (int k = 0; k < C; ++k) c[((i+1)+(j+1))%3][k] += D[buf-1][k];
  }

  int minval = numeric_limits<int>::max();
  for (int i = 0; i < C; ++i) for (int j = 0; j < C; ++j){
    if(i!=j) {
      for (int k = 0; k < C; ++k){
        if(i!=k && j!=k) {
          int val = c[0][i] + c[1][j] + c[2][k];
          if (val < minval) minval = val;
        }
      }
    }
  }

  printf("%d\n", minval);
  return 0;
}


Measured memory_bytes: 256
#ifndef TEMPLATE
#define TEMPLATE

#include <bits/stdc++.h>
using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
const double eps = 1e-8;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n; cin >> n;
    vi a(n);
    for(int i=0;i<n;++i) {
      cin >> a[i];
    }
    vvi cost(n, vi(5, INF));
    for(int i=0;i<n;++i) {
      for(int j=0;j<5;++j) {
        if(j == 0 || j == 4) {
          cost[i][j] = a[i];
        } else if(j == 1 || j == 3) {
          if(a[i] % 2 == 0 && a[i] > 0) {
            cost[i][j] = 0;
          } else if(a[i] > 0) {
            cost[i][j] = 1;
          } else {
            cost[i][j] = 2;
          }
        } else if(j == 2) {
          cost[i][j] = a[i] % 2 == 0;
        } else {
          assert(false);
        }
      }
    }

    vvll dp(n+1, vll(5, LINF));
    dp[0][0] = 0;
    for(int i=0;i<n;++i) {
      for(int j=0;j<5;++j) {
        if(dp[i][j] >= LINF) continue;
        for(int k=j;k<5;++k) {
          dp[i+1][k] = min(dp[i+1][k], dp[i][j] + cost[i][k]);
        }
      }
    }

    ll mi = LINF;
    for(int j=0;j<5;++j) {
      mi = min(mi, dp[n][j]);
    }
    cout << mi << endl;
}

#endif


Measured memory_bytes: 26112
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

ans = abs(T - H[0] * 0.006 - A)
idx = 0
for i in range(1, N):
    diff = abs(T - H[i] * 0.006 - A)
    if diff < ans:
        ans = diff
        idx = i
print(idx+1)

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>

int main(){
    int N;
    std::cin >> N;
    int numCnt = 0;
    for(int i = 1; i <= N; i += 2){
        int cnt = 1; // 1は約数
        for(int j = 3; j <= i; j += 2){
            if(i % j == 0) cnt++;
        }
        if(cnt == 8) numCnt++;
    }
    std::cout << numCnt << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {
  long mod = 1000000007;
  int n;
  cin >> n;
  char str[n + 1];
  cin >> str;
  int cnt[26] = {};
  for (int i = 0; i < n; i++) {
    cnt[0 + str[i] - 'a']++;
  }
  long long int res = 1;
  for (int i = 0; i < 26; i++) {
    res *= (cnt[i] + 1);
    res %= mod;
  }
  res -= 1;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1016
s = input()

s_set = set(s)
s_list = list(s_set)
s_list.sort()

afb = "abcdefghijklmnopqrstuvwxyz"

flag = True
for i in afb:
    if i not in s_list:
        flag = False
        print(i)
        break
if flag:
    print("None")


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
vector<ll> solve(ll n){
    vector<ll>v;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            v.push_back(i);
            if(i * i != n)
                v.push_back(n/i);
        }
    }
    return v;
}
int main()
{
    Hello
    ll n, ans;
    cin >> n;
    vector<ll> v = solve(n - 1);
    vector<ll> V = solve(n);
    ans = v.size() - 1;
    for(int i = 0; i < V.size(); i++){
        ll temp = n;
        while(V[i] != 1 && temp % V[i] == 0)
            temp /= V[i];
        if(temp % V[i] == 1)
            ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 384
import sys
readline = sys.stdin.buffer.readline
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().rstrip().split())
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1)

    print(ans % MOD)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<vector<int>> idx(10);
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        idx[a].push_back(i);
    }
    vector<int> id(10);
    int b = -1;
    string s = "";
    for (int i = 0; i < n - k; i++) {
        for (int j = 9; j >= 1; j--) {
            while (id[j] < idx[j].size() && idx[j][id[j]] <= b) {
                id[j]++;
            }
            if (id[j] >= idx[j].size()) {
                continue;
            }
            if (idx[j][id[j]] > b && n - 1 - idx[j][id[j]] >= n - k - 1 - i) {
                b = idx[j][id[j]];
                s += (char)('0' + j);
                id[j]++;
                break;
            }
        }
    }
    cout << s << endl;
}



Measured memory_bytes: 4136
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  ui N{}; std::cin >> N;
  vector<ll> A(N), B(N);
  rep(0, N) cin >> A[i];
  rep(0, N) cin >> B[i];

  typedef pair<ui, ll> Pair;
  auto cmp = [](Pair p1, Pair p2){ return p1.second < p2.second; };
  std::priority_queue<Pair, vector<Pair>, decltype(cmp)> queue(cmp);
  rep(0, N)
  {
    if(B[i] > A[i])
    {
      queue.push({i, B[i]});
    }
    else if(B[i] < A[i])
    {
      cout << "-1" << '\n';
      return;
    }
  }

  // ll ans = queue.empty() ? -1 : 0;
  ll ans{};
  while(!queue.empty())
  {
    Pair p = queue.top();
    queue.pop();
    auto curr = p.first;
    auto sum = B[(curr + N - 1) % N] + B[(curr + 1) % N];

    if((A[curr] - B[curr]) % sum == 0)
    {
      ans += (B[curr] - A[curr]) / sum;
      B[curr] = A[curr];
      continue;
    }
    if(B[curr] <= sum)
    {
      ans = -1;
      break;
    }
    
    ans += B[curr] / sum;
    B[curr] %= sum;
    if(B[curr] < A[curr])
    {
      ans = -1;
      break;
    }

    queue.push({curr, B[curr]});

  }

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

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

  solve();

  return 0;
}


Measured memory_bytes: 9456
LEFT = "L"
RIGHT = "R"
LOOP_STR="RL"

S = gets.chomp

def S.find_rl_idx
  rl_idxes = []
  pre_s = ""
  self.chars.each_with_index do |s, i|  
    if pre_s == RIGHT && s == LEFT
      rl_idxes << i-1
    end
    pre_s = s
  end
  # 良くないプログラム、だが、rl_idxesが多い場合は総当たりで探した方が早いはずなので、
  # その閾値(今回は適当に10)をきちんと算出してやったら良いかな。
  # ただ、rl_idxesが必要なのはRL左右の両端にしかないような場合など、かなり極端なケースで計算量が
  # S^2になるのを回避するためなので、まぁ...
  rl_idxes.size < 10 ? rl_idxes : nil
end

def find_terminal_idx i, rl_idxes
  if rl_idxes
    rl_idx = if S[i] == RIGHT
      rl_idxes.find{|j| j >= i}
    else
      rl_idxes.reverse.find{|j| j < i}
    end
  else
    rl_idx = if S[i] == RIGHT
      i + S[i..-1].index(LOOP_STR)
    else
      S[0..i].rindex(LOOP_STR)
    end
  end
  used_times = (rl_idx - i).abs
  used_times.even? ? rl_idx : rl_idx + 1
end

rl_idxes = S.find_rl_idx
ans_data = S.size.times.map do |i|
  find_terminal_idx i, rl_idxes
end

ans = Array.new(S.size, 0)
ans_data.each do |datum|
  ans[datum] += 1
end

puts ans.join(" ")


Measured memory_bytes: 98972
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

const long long MOD = 1000000007;

const int64_t S_MAX = 2005;
int64_t dp[S_MAX];

void init_dp()
{
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
}

int main()
{
  int64_t S;
  cin >> S;

  init_dp();

  for (int64_t i = 6; i <= S; i++) {
    dp[i] = 0;
    for (int64_t k = 0; k <= i - 3; k++) {
      dp[i] += dp[k];
      dp[i] %= MOD;
    }
  }

  cout << dp[S] << endl;

  return 0;
}


Measured memory_bytes: 3624
def prime_factorize(num):
    """
    This function performs prime factorization on the input natural number.
    The result is returned in the form of a dictionary with the prime number as the key
    and its number as the value.
    :param num:
    :return prime_factor: Dictionary with the prime number as the key and its number as the value.
    """
    prime_factor = {}
    i = 2
    while i ** 2 <= num:
        while num % i == 0:
            num //= i
            if i in prime_factor.keys():
                prime_factor[i] += 1
            else:
                prime_factor[i] = 1
        i += 1
    if num > 1:
        prime_factor[num] = 1
    return prime_factor


from math import factorial


def comb(n, r, R):
    if n not in R:
        a = factorial(n)
        R[n] = a
    else:
        a = R[n]

    if n - r not in R:
        b = factorial(n - r)
        R[n - r] = b
    else:
        b = R[n - r]

    if r not in R:
        c = factorial(r)
        R[r] = c
    else:
        c = R[r]
    return a // (b * c)


n, m = map(int, input().split())
r = 1

R = dict()
prime_fac = prime_factorize(m)
for v in prime_fac.values():
    r *= comb(v + n - 1, v, R)
mod = 1000000000 + 7
print(r % mod)


Measured memory_bytes: 66012
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

#define MAXN 200

int h, w;
ll a[MAXN][MAXN];
ll c[10][10];

void floyd() {
    for (int k = 0; k < 10; ++k) {
        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
}


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> h >> w;

    rep(i, 10) {
        rep(j, 10) {
            cin >> c[i][j];
        }
    }

    floyd();

    ll res = 0;
    rep(i, h) {
        rep(j, w) {
            ll t;
            cin >> t;
            if (t == -1) continue;
            res += c[t][1];
        }
    }

    cout << res << endl;

    return 0;
}

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

int main() {
  int counter = 0;
  vector<char> data(4);
  for (int i=0; i<4; i++) {
    cin >> data[i];
  }
  for (int i=0; i<4; i++) {
    for (int j=0; j<4; j++) {
      if (data[i]==data[j]) {
        counter++;
      }
    }
  }
  if (counter == 8) {
    cout << "Yes";
  } else {
  cout << "No";
  }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
// #define NMAX 1000000000
ll X;

ll solve(){
	// cout<<X<<"\n";//
	ll ans = 0;
	ll yen = 100;
	while(X>yen){
		// yen = yen + yen/100;
		yen *= 1.01;
		ans++;
	}
	// cout<<yen<<"\n";//
	return ans;
}

int main(){
	cin>>X;
	cout<< solve() <<endl;
	// printf("%f\n",solve());
	// cout<<cout<<setprecision(10)<<ans<<endl;
	// solve();
}


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

left = sum(A)
n = 1
ans = 1
for a in A:
  left -= a
  if a > n or n - a > left:
    print(-1)
    break
  n = min((n - a) * 2, left)
  ans += n
else:
  if n > 0:
    print(-a)
  else:
    print(ans)

Measured memory_bytes: 20012
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define inf INT_MAX

int main(){
    FASTIO
    ll N; cin>>N;
    vector<ll> array(N);
    for(int i=0; i<N; ++i) cin>>array[i];
    ll count = 0;
    for(int i=0; i<N; ++i){
        if((i+1)%2!=0 && array[i]%2!=0) count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3656
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    print(len(s)*'x')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

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

    if(a == 'H'&& b == 'H') cout << "H" << endl;
    else if(a == 'H'&& b == 'D') cout << "D" << endl;
    else if(a == 'D' && b == 'H') cout << "D" << endl;
    else cout << "H" << endl;

    return 0;
}

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

int main() {
	long long N, ANS = 1145141919;
	pair<long long, long long> P[50];
	cin >> N;
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}
	for (int i = 0; i < N; i++) cin >> P[i].first >> P[i].second;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			int COUNT = 0;
			if (i == j) continue;
			long long p = P[i].first - P[j].first;
			long long q = P[i].second - P[j].second;
			for (int l = 0; l < N; l++) {
				if (l == i) continue;
				for (int k = 0; k < N; k++) {
					if (k == i) continue;
					if (k == l) continue;
					if ((P[l].first - P[k].first) == p && (P[l].second - P[k].second) == q) COUNT++;
				}
			}
			ANS = min(ANS, N - 1 - COUNT);
		}
	}
	cout << ANS;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m,l = LI()
    v = [[] for i in range(n)]
    for i in range(m):
        a,b,c = LI()
        a -= 1
        b -= 1
        v[a].append((b,c))
        v[b].append((a,c))
    ans = [[[float("inf")]*2 for j in range(n)] for i in range(n)]
    q = []
    for s in range(n):
        ans[s][s] = [0,0]
        heappush(q,(0,0,s))
        while q:
            da,dx,x = heappop(q)
            if [da,dx] > ans[s][x]:
                continue
            for y,w in v[x]:
                if w > l:
                    continue
                nd = dx+w
                if nd <= l:
                    na = da
                    nd_ = nd
                else:
                    na = da+1
                    nd_ = w
                if [na,nd_] < ans[s][y]:
                    ans[s][y] = [na,nd_]
                    heappush(q,(na,nd_,y))
    q = I()
    for _ in range(q):
        s,t = LI()
        s -= 1
        t -= 1
        ds = ans[s][t][0]
        if ds == float("inf"):
            print(-1)
        else:
            print(ds)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 103644
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		String numN = next();

		out.println(numN.equals(new StringBuilder(numN).reverse().toString()) ? "Yes" : "No");
	}

	private void solveB() {
		int numA = nextInt();
		int numB = nextInt();
		int numC = nextInt();
		int numD = nextInt();

		int wkRes = Math.min(numB, numD) - Math.max(numA, numC);
		//wkReが0より小さい場合、二人がスイッチを押していた時間の被りはない
		out.println(wkRes >= 0 ? wkRes : 0);
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 22612
n = gets.to_i
a = gets.split.map(&:to_i)
a.unshift(nil)

b = []

n.step(by: -1, to: 1) do |i|
  tmp = 2.step(n/i).inject(0) do |memo, j|
    memo ^ b[i*j]
  end
  b[i] = a[i] ^ tmp
end

ans = b.map.with_index do |v, i|
  i if v == 1
end.compact
puts ans.size
puts ans.join(' ') unless ans.empty?


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

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)

using namespace std;

const int N = 21;
const int N0 = 33000;

int g[N][N], t0[N0], t1[N0][N], n, m;

int f[N][N0][2];

int cut(int s1, int s2){ return t0[s1 | s2] - t0[s1] - t0[s2];}
#define g(i) (1 << (i - 1))
int main()
{
	
	scanf("%d%d", &n, &m);
	Rep(i, m) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		g[x][y] += z, g[y][x] += z;
	}
	
	Rep0(i, (1 << n) - 1) {
		Rep(j, n) if (i & (1 << (j - 1))){
			for (int k = j; k <= n; k ++)
				if (i & (1 << (k - 1))) t0[i] += g[j][k];
			Rep(k, n) t1[i][k] += g[k][j];
		}
	}
	
	Rep(i, n) Rep0(s, (1 << n) - 1) f[i][s][0] = f[i][s][1] = ~0u>>2;
	
	f[1][1][0] = 0;
	
	Rep0(s, (1 << n) - 1) Rep(i, n) if (s & g(i)){
		int tmp = s ^ g(i);
		Rep(j, n) if ((tmp & g(j)) && g[i][j])
			f[i][s][0] = min(f[i][s][0], f[j][tmp][1] - g[i][j] + t1[tmp][i]);
		for (int s0 = tmp; ; s0 = tmp & (s0 - 1)) {
			f[i][s][1] = min(f[i][s][1], f[i][s ^ s0][0] + cut(s0, tmp ^ s0));
			if (!s0) break;
		}
	}
	
	printf("%d\n", f[n][(1 << n) - 1][1]);
	
	return 0;
}
/*
5 6
1 5 100
1 4 100
1 2 100
2 3 100
3 4 100
4 5 100

*/


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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;



void solve() {
	int n;
	cin >> n;

	int ans = 0;
	string s = to_string(n);
	rep(i, s.size()) {
		ans += (s[i] - '0');
	}

	cout << (n % ans == 0 ? "Yes" : "No") << endl;
}


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

	solve(); 
	return 0;
}

Measured memory_bytes: 256
n,k = gets.chomp.split.map(&:to_i)
ans = 0
MOD = 10**9 + 7
min_num = (0..k-1).inject(:+) % MOD
max_num = (n-k+1..n).inject(:+) % MOD

while k <= n + 1
	ans += (max_num - min_num + 1) % MOD
	k += 1
	min_num += k - 1
	max_num += n - k + 1
end

puts ans % MOD

Measured memory_bytes: 14264