akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
int main()
{
    int N;
    cin >> N;
    vector<string> s(N);
    vector<int> t(N);
    REP(i, N)  {
        cin >> s[i] >> t[i];
    }
    string X;
    cin >> X;
    int ans = 0;
    bool flg = false;
    REP(i, N) {
        if(flg) ans += t[i];
        if(s[i] == X) flg = true;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i,j,n;
    int card[128][14]={{0}};
  scanf("%d", &n);
  
  for(j=0; j<=n; j++){
      int m;
  char c;
  scanf("%c",&c);
      scanf("%c %d", &c, &m);
      card[c][m]=1;
  }
  for(i=1;i<=13; i++){
  if(card['S'][i]==0)
      printf("S %d\n", i);
  }
   for(i=1;i<=13; i++){
  if(card['H'][i]==0){
      printf("H %d\n", i);
  }
   }
   for(i=1;i<=13; i++){
   if(card['C'][i]==0){
      printf("C %d\n", i);
   }
  }
   for(i=1;i<=13; i++){
   if(card['D'][i]==0){
      printf("D %d\n", i);
   }
  }
  return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int maxn = 1e6 + 10;

int main() {
    int n;
    cin >> n;
    string _357 = "357";
    if (n < 357) {
        cout << 0 << endl;
    } else {
        vector<int> nums = {357, 375, 537, 573, 735, 753};
        nums.reserve(30000);
//        vector<int> tmp = {357, 375, 537, 573, 735, 753};
        vector<set<string>> tmp(10);
        tmp[3] = {"357", "375", "537", "573", "735", "753"};
        for (int i = 4; i < 10; ++i) {
            for (auto& x : tmp[i - 1]) {
                for (int j = 0; j < x.length(); ++j) {
                    string t = x;
                    t.insert(j, "3");
//                    cout << t << endl;
                    tmp[i].insert(t);
                }
                tmp[i].insert(x + "3");
                for (int j = 0; j < x.length(); ++j) {
                    string t = x;
                    t.insert(j, "5");
                    tmp[i].insert(t);
                }
                tmp[i].insert(x + "5");
                for (int j = 0; j < x.length(); ++j) {
                    string t = x;
                    t.insert(j, "7");
                    tmp[i].insert(t);
                }
                tmp[i].insert(x + "7");
            }
        }
        for (int i = 4; i < 10; ++i) {
            for (auto& s : tmp[i]) {
                nums.push_back(stoi(s));
            }
        }
        sort(nums.begin(), nums.end());
        auto it = upper_bound(nums.begin(), nums.end(), n);
        cout << distance(nums.begin(), it) << endl;
    }
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();


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

using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
const ll MOD = 1e9 + 7;
int n;
ll dp[N][2];
vector<int> v[N];

ll solve(int src, int prev, int color) {
	if (dp[src][color] != -1) {
		return dp[src][color];
	}
	ll ways = 1, ans = 0;
	if (color == 0) {
		for (auto it : v[src]) {
			if (it != prev) {
				ways = (ways * solve(it, src, 1)) % MOD;
			}
		}
		ans = (ans + ways) % MOD;
	}
	ways = 1;
	for (auto it : v[src]) {
		if (it != prev) {
			ways = (ways * solve(it, src, 0)) % MOD;
		}
	}
	ans = (ans + ways) % MOD;
	return dp[src][color] = ans;
}

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

	cin >> n;
	int x, y;
	for (int i = 1; i <= n - 1; i++) {
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	memset(dp, -1, sizeof(dp));
	ll answer = solve(1, 0, 0);
	cout << answer;

	return 0;
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s;
  cin >> s;

  ll n = s.size();
  ll cnt = 0;
  rep(i, n) {
    if (s[i] == '0') {
      cnt++;
    }
  }

  if (n-cnt > cnt) {
    cnt = n-cnt;
  }

  cout << n-(cnt-(n-cnt)) << endl;
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();

		//double[] a = new double[n];
		double temp =0;
		List<Double> list = new ArrayList<>();
		for(int i=0;i<n;i++) {
			list.add(sc.nextDouble());
		}
		Collections.sort(list);

		temp = (list.get(0)+list.get(1))/2;
		for(int i =2; i<n;i++) {
			temp = (temp+list.get(i))/2;
		}
		System.out.println(temp);
	}

	}

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

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if (a>=b) {
        cout << "delicious" << endl;
    } else if (b-a <= x) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

struct z{
  ll x;
  ll y;
};

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll h,w;cin>>h>>w;
  vector<string> s(h);
  vector<vector<ll>> a(h,vector<ll>(w,0));
  for(i=0;i<h;i++)cin>>s[i];
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      l=0;r=0;
      if(a[i][j]==0&&s[i][j]=='.'){
        queue<struct z> p;
        p.push({i,j});
        while(!p.empty()){
          ll x=p.front().x;
          ll y=p.front().y;
          if(a[x][y]==0&&s[x][y]=='.'){
            a[x][y]=1;
            l++;
            if(x<=h-2&&s[x+1][y]!=s[x][y])p.push({x+1,y});
            if(y<=w-2&&s[x][y+1]!=s[x][y])p.push({x,y+1});
            if(x>=1&&s[x-1][y]!=s[x][y])p.push({x-1,y});
            if(y>=1&&s[x][y-1]!=s[x][y])p.push({x,y-1});
          }
          else if(a[x][y]==0&&s[x][y]=='#'){
            a[x][y]=1;
            r++;
            if(x<=h-2&&s[x+1][y]!=s[x][y])p.push({x+1,y});
            if(y<=w-2&&s[x][y+1]!=s[x][y])p.push({x,y+1});
            if(x>=1&&s[x-1][y]!=s[x][y])p.push({x-1,y});
            if(y>=1&&s[x][y-1]!=s[x][y])p.push({x,y-1});
          }
          p.pop();
        }
      res+=l*r;  
      }

    }
  }
  cout<<res<<endl;


  return 0;
}

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

using namespace std;

int main() {
	string arr[3];
	cin >> arr[0] >> arr[1] >> arr[2];

	if (arr[0][arr[0].length() - 1] == arr[1][0] && arr[1][arr[1].length() - 1] == arr[2][0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s;
	cin >> s;
	int r = 0, p = 0;
	int ans = 0;
	rep(i, s.size()){
		if(s[i] == 'g'){
			if((p + 1) <= r) p++, ans++;
			else r++;
		}
		else{
			if((p + 1) <= r) p++;
			else r++, ans--;
		}
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

long long H, W, A[1009], B[1009], ret = 1, mod = 1000000007;

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> A[i]; A[H] = (1LL << 30);
	for (int i = 0; i < W; i++) cin >> B[i]; B[W] = (1LL << 30);
	sort(A, A + H);
	sort(B, B + W);
	bool ok = true;
	for (int i = 0; i < H - 1; i++) { if (A[i] == A[i + 1]) ok = false; }
	for (int i = 0; i < W - 1; i++) { if (B[i] == B[i + 1]) ok = false; }
	if (ok == false) {
		cout << "0" << endl;
		return 0;
	}

	int cx = 0, cy = 0, rem = H * W;
	while (cx < H || cy < W) {
		if (A[cx] < B[cy]) {
			cx++; long long V = (H - cx) * (W - cy);
			for (int i = H * W - rem + 1; i < H*W - V; i++) { ret *= (A[cx - 1] - i); ret %= mod; }
			ret *= (rem - V); ret %= mod;
			rem = V;
		}
		else if (A[cx] == B[cy]) {
			cx++; cy++; long long V = (H - cx) * (W - cy);
			for (int i = H * W - rem + 1; i < H*W - V; i++) { ret *= (A[cx - 1] - i); ret %= mod; }
			rem = V;
		}
		else {
			cy++; long long V = (H - cx) * (W - cy);
			for (int i = H * W - rem + 1; i < H*W - V; i++) { ret *= (B[cy - 1] - i); ret %= mod; }
			ret *= (rem - V); ret %= mod;
			rem = V;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<math.h>
using namespace std;

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

  if(n == 1){
    cout <<2<<endl;
  }else if(n == 0 || n == 2){
    cout <<1<<endl;
  }else{
    cout <<0<<endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 998244353
using namespace std;
typedef long long ll;

ll power(ll n, ll p, ll mod) {
    ll ans = 1;
    while (p > 0) {
        if (p & 1) ans = ans * n % mod;
        n = n * n % mod;
        p >>= 1;
    }
    return ans;
}

class CombinationN {
   public:
    CombinationN(int n, int maxk) {
        N = n; K = maxk + 1; 
        fac = new ll[K];
        numerator = new ll[K];

        fac[0] = 1; numerator[0] = 1;
        REP(i, 1, K) {
            fac[i] = fac[i - 1] * i % MOD;
            numerator[i] = numerator[i - 1] * (n - i + 1) % MOD; 
        }
    }

    ll cnr(int k) {
        if (N - k < k) return cnr(N - k);
        return numerator[k] * power(fac[k], MOD - 2, MOD) % MOD;
    }

   private:
    int N, K;
    ll *fac, *numerator;
};

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

    CombinationN comb(N - 1, K);

    ll ans = 0;
    REP(k, 0, K + 1) ans = (ans + ((comb.cnr(k) * M) % MOD * power(M - 1, N - 1 - k, MOD)) % MOD) % MOD; 
    cout << ans << endl;

    return 0;
}

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


int main(){

int p,q,r;
cin>>p>>q>>r;

int check = 0 ;

for(int i = 1; ; i++){
    int ans = r*i;
    if(ans>q) break;

    if(p<=ans && ans<=q) check++;
}
cout<<check<<endl;



}


Measured memory_bytes: 3568
a,b = map(int,input().split())

for i in range(2001):
    for j in range(2001):
        if 10000*i + 5000*j + 1000*(a-i-j) == b and a-i-j>=0:
            print(i,j,a-i-j)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++) 
#define repb(i, n) for (int i = (int)n; i >= 0; i--) 
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++) 
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--) 
#define SORT(v, n) sort(v, v + n); 
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a) 
#define INF 999999999999999999 
int dy[] = {0, 0, 1, -1, 0}; 
int dx[] = {1, -1, 0, 0, 0}; 
using namespace std; 
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << (c/a)*b << endl;
    }


Measured memory_bytes: 256
import string
ABC=list(string.ascii_lowercase)
s=input()
S=list(s[::-1])

if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    if len(s)==26:
        for i in range(len(s)):
            n=ABC.index(S[i])
            if not set(ABC[n+1:])<=set(S[i+1:]):
                j=i
                break
        L=list(set(ABC[n+1:])-set(S[j+1:]))
        L.sort()
        sgyku=L[0:1]+S[j+1:]
        print("".join(sgyku[::-1]))
    else:
        L=list(set(ABC)-set(s))
        L.sort()
        print(s+L[0])

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

const int N = 200005, P = 1000000007;
int n, pro[N], t1[N], t2[N];
vector<tuple<int*, int, int>> v;
pair<int, int> A[N];

int power(int a, int x) {
	int ans = 1;
	for (; x; x >>= 1, a = 1LL * a * a % P)
		if (x & 1) ans = 1LL * ans * a % P;
	return ans;
}

void upd(int *t, int x, int y, bool record = true) {
	if (record)
		v.emplace_back(t, x, y);
	for (; x <= n; x += x & -x)
		t[x] = (t[x] + y) % P;
}
int qry(int *t, int x) {
	int s = 0;
	for (; x; x &= x - 1)
		s = (s + t[x]) % P;
	return s;
}
void clear() {
	for (const auto &p : v)
		upd(get<0>(p), get<1>(p), -get<2>(p), false);
	v.clear();
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &A[i].first), A[i].second = i;
	sort(A + 1, A + 1 + n);
	int all = pro[0] = 1;
	for (int i = 1; i <= n; ++i) {
		all = 1ll * all * (A[i].first - i + 1) % P;
		if (all <= 0) return puts("0"), 0;
		pro[i] = 1ll * pro[i - 1] * power(A[i].first - i + 1, P - 2) % P;
		if (A[i].first - i)
			pro[i] = 1ll * pro[i] * (A[i].first - i) % P;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans = (ans + 2 * (i - 1 - qry(t1, A[i].second))) % P, upd(t1, A[i].second, 1);
	clear();
	for (int i = 1; i <= n; ++i) {
		ans = (ans + (2ll * qry(t2, A[i].second) - qry(t2, n)) * power(A[i].first - i + 1, P - 2) % P * pro[i - 1]) % P;
		if (A[i].first == i)
			clear();
		else
			upd(t2, A[i].second, (A[i].first - i + 1ll) * power(pro[i - 1], P - 2) % P);
	}
	ans = (P + 1ll) / 2 * all % P * ans % P;
	printf("%d\n", (ans + P) % P);
	return 0;
}


Measured memory_bytes: 9328
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <tuple>
using namespace std;
const double PI = 3.14159265358979323846;



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

	string str;
	cin >> str;

	if (str.size() <= K) {
		cout << str << endl;
	}
	else {
		const char* c_str = str.c_str();

		for (int i = 0; i < K; i++) {
			cout << c_str[i];
		}
		cout << "..." << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  rep(i,n){ cin >> a[i]; a[i]--; }
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];

  ll ans = 0;
  rep(i,n){
    ans += b[a[i]];
  }
  rep(i,n-1){
    if(a[i]+1==a[i+1]) ans += c[a[i]];
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int num[30];
int main()
{
    int n,m;
    int a,b;
    cin>>n>>m;
    while(m--)
    {
        cin>>a>>b;
        num[a]++;
        num[b]++;
    }
    for(int i=1;i<=n;i++)
        cout<<num[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<int> H(N+1,0);
  for (int i = 1; i < N+1; i++){
    cin >> H[i];
  }
  
  bool ans = true;
  
  for (int i = 1; i < N+1; i++){
    if(H[i] - H[i-1] >= 1){
      H[i]--;
    }
    else if(H[i] - H[i-1] == 0){
      
    }
    else{
      ans = false;
      break;
    }
  }
  
  if (ans){
    cout << "Yes";
  }else{
    cout << "No";
  }
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a,b;
  cin >> a >> b;
  int count =0;
  int c = a.size();
  for(int i=0;i<c;i++){
    if(a.at(i)!=b.at(i)){
      count++;
    }
  }
   cout << count << endl;
}

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

int main(){
    string s,t;cin>>s>>t;
    int acc = 0;
    for (int i=0;i<s.size();i++){
        if (s[i] != t[i]){
            acc++;
        }
    }
    cout << acc << endl;
    return 0;
}

Measured memory_bytes: 3848
#include <iostream>
#include <iomanip> // setprecision
#include <cmath>

using namespace std;
typedef long long ll;
const double long PI = acos(-1);

void solve() {
  ll year;
  cin >> year;
  if (year == 3 || year == 5 || year == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

int main(void) {
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 256
input = gets.split

input.size.times do |i|
    input[i] = input[i].to_i
    input[i] = 14 if (input[i] == 1)
end

if input[0] < input[1]
    puts "Bob"
elsif input[0] > input[1]
    puts "Alice"
else
    puts "Draw"
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define int long long
#define N 1000005
using namespace std;
string s;
int a[N];
vector < int > v;
main()
{
    cin>>s;
    memset(a,-1,sizeof(a));
    s=' '+s;
    for(int i=1;i<s.size();i++)
    {
        if(s[i]=='>' && s[i+1]=='<')
        {
            a[i]=0;
            v.push_back(i);
            continue;
        }
        if(s[i]=='<' && s[i-1]!='<'){a[i-1]=0;v.push_back(i-1);}
        if(s[i]=='>' && s[i+1]!='>'){a[i]=0;v.push_back(i+1);}
    }
    for(int i=0;i<v.size();i++)
    {
        int st=v[i];
        while(st>=0 && s[st]=='>' && s[st-1]=='>')
        {
            a[st-1]=a[st]+1;
            st--;
        }
        int ed=v[i];
        while(ed<s.size() && s[ed+1]=='<' && s[ed+2]=='<')
        {
            a[ed+1]=a[ed]+1;
            ed++;
        }
    }
    int sum=0;
    for(int i=0;i<s.size();i++)
    {
        if(a[i]==-1)
        {
            a[i]=max(a[i-1],a[i+1])+1;
        }
        sum+=a[i];
    }
    cout<<sum;
}


Measured memory_bytes: 11156
#include<bits/stdc++.h>
using namespace std;
int main(){
	int i,sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	for(i=1;i<=ty-sy;i++) cout<<"U";//上 
	for(i=1;i<=tx-sx;i++) cout<<"R";//右 
	for(i=1;i<=ty-sy;i++) cout<<"D";//下 
	for(i=1;i<=tx-sx;i++) cout<<"L";//左 
	cout<<"L";
	for(i=1;i<=ty-sy+1;i++) cout<<"U";//上 
	for(i=1;i<=tx-sx+1;i++) cout<<"R";//右 
	cout<<"DR";
	for(i=1;i<=ty-sy+1;i++) cout<<"D"; 
	for(i=1;i<=tx-sx+1;i++) cout<<"L"; 
	cout<<"U";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
// #define endl "\n"

ll dfsvisit(ll cur, vector<vector<ll>>& adj, vector<bool>& visited, vector<ll>& dp) {
    if (visited[cur]) {
        return dp[cur];
    }

    visited[cur] = true;
    dp[cur] = 0;
    for (auto a: adj[cur]) {
        dp[cur] = max(dp[cur], 1 + dfsvisit(a, adj, visited, dp));
    }
    return dp[cur];
}

ll dfs(ll n, ll m, vector<vector<ll>>& adj) {
    vector<ll> dp (n+1, -1);
    vector<bool> visited (n+1, false);
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {

        ans = max(ans, dfsvisit(i, adj, visited, dp));
        
    }
    return ans;
}

int main(void) {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    ll n, m;
    cin >> n >> m;

    vector<vector<ll>> adj (n+1);

    for (ll i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b;
        adj[a].push_back(b);
    }
    cout << dfs(n, m, adj) << endl;



    
    return 0;
}

Measured memory_bytes: 9984
import math
mod=10**9+7
n,m=map(int,input().split())
ans=0
if abs(n-m)==0:
    ans=math.factorial(n)*math.factorial(m)*2
elif abs(n-m)==1:
    ans=math.factorial(n)*math.factorial(m)
else:
    ans=0
ans=ans%mod
print(ans)

Measured memory_bytes: 5184
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] a1=new int[n];
		int[] a2=new int[n];
		int[] s1=new int[n];
		int[] s2=new int[n];
		
		for(int i=0;i<n;i++) a1[i]=sc.nextInt();
		for(int i=0;i<n;i++) a2[i]=sc.nextInt();
		
		s1[0]=a1[0]; s2[n-1]=a2[n-1];
		for(int i=1;i<n;i++) s1[i]=s1[i-1]+a1[i];
		for(int i=n-2;i>=0;i--) s2[i]=s2[i+1]+a2[i];
		
		int score=0;
		for(int i=0;i<n;i++) score=Math.max(score, s1[i]+s2[i]);
		
		System.out.println(score);
	}
}


Measured memory_bytes: 23764
#include <stdio.h>

int main(void)
{
	int num[5];
	int i, j;
	int tmp;

	for (i = 0; i < 5; i++){
		scanf("%d", &num[i]);
	}

	for (i = 0; i < 4; i++){
		for (j = 4; j > i; j--){
		   if (num[j] > num[j - 1]){
			   tmp = num[j];
			   num[j] = num[j - 1];
			   num[j - 1] = tmp;
		   }
		}
	}

	for (i = 0; i < 5; i++){
		if (i == 4){
			printf("%d\n", num[4]);
		}
		else {
			printf("%d ", num[i]);
		}
	}

	return (0);
}

Measured memory_bytes: 596
n, m = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
MOD = int(1e9 + 7)
row = sum([(i+1) * (n-i-1) * (xs[i+1] - xs[i]) % MOD for i in range(n-1)]) % MOD
col = sum([(i+1) * (m-i-1) * (ys[i+1] - ys[i]) % MOD for i in range(m-1)]) % MOD
ans = row * col % MOD
print(ans)

Measured memory_bytes: 18556
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
int h, w;
char s[maxn][maxn];

int fidd(int a, int b){
    int cot = 0;
    if(a-1 >=0 && s[a-1][b] == '#') cot++;
    if(a-1 >=0 && b-1 >= 0 && s[a-1][b-1] == '#') cot++;
    if(a-1 >=0 && b+1 >= 0 && s[a-1][b+1] == '#') cot++;
    if(a+1 >=0 && s[a+1][b] == '#') cot++;
    if(a+1 >=0 && b-1 >= 0 && s[a+1][b-1] == '#') cot++;
    if(a+1 >=0 && b+1 >= 0 && s[a+1][b+1] == '#') cot++;
    if(b-1 >=0 && s[a][b-1] == '#') cot++;
    if(b+1 >=0 && s[a][b+1] == '#') cot++;
    return cot;
}

int main(){
    scanf("%d%d", &h, &w);
    for(int i = 0; i < h; i++){
        scanf("%s", s[i]);
    }
    /*for(int i = 0; i < h; i++){
        printf("%s\n", s[i]);
    }*/
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '.'){
                s[i][j] = '0' + fidd(i, j);
            }
        }
    }
    for(int i = 0; i < h; i++){
        printf("%s\n", s[i]);
    }
    return 0;
}


Measured memory_bytes: 256
s=input()
K=int(input())

sub_list=[]
i,j=0,1
while True:
    if(i+j>=len(s) and i==len(s)):
        break
    else:
        sub_list.append(s[i:i+j])
        if(j<=K):
            j+=1
        else:
            i+=1
            j=1
set_list=set(sub_list)

dict_list=list(set_list)
dict_list.sort(key=str)

print(dict_list[K-1])

Measured memory_bytes: 5680
#include <stdio.h>

int main(void) {
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  printf("%d", (b < d ? b : d) - (a > c ? a : c) > 0 ? (b < d ? b : d) - (a > c ? a : c) : 0);
  return 0;
}

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

using namespace std;
const int N = 1e5 + 3;
int	 main() {
//	freopen("input.in", "r", stdin);
	int n, m;
	scanf("%d %d", &n, &m);
	int l = 1, r = n;
	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		l = max(l, u);
		r = min(r, v);
	}
	printf("%d\n", max(0, r - l + 1));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long gcd(long a,long b){return b?gcd(b,a%b):a;}
int t;
long A,B,C,D;
main()
{
	cin>>t;
	for(;t--;)
	{
		cin>>A>>B>>C>>D;
		if(A<B)cout<<"No"<<endl;
		else
		{
			if(B>D)cout<<"No"<<endl;
			else
			{
				if(B-1<=C)cout<<"Yes"<<endl;
				else
				{
					long b=B-A%B,c=C-A%B;
					long dis=gcd(B,D);
					if(b>(c+dis)/dis*dis)cout<<"No"<<endl;
					else cout<<"Yes"<<endl;
				}
			}
		}
	}
}


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

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

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    // cumulaive sum
    vector<long long int> sa1(n+1), sa2(n+2);
    for(int i=0; i<n; i++){
        sa1[i+1] = sa1[i] + a[i];
        sa2[i+2] = sa2[i] + a[i];
    }
    /*
    for(int i=0; i<n+1; i++) cout << sa1[i] << " ";
    cout << endl;
    for(int i=0; i<n+2; i++) cout << sa2[i] << " ";
    cout << endl;
    */

    for(int i=0; i<q; i++){
        long long int x;
        cin >> x;

        int upper = n-1, lower = 0, mid;
        while(upper - lower > 1){
            mid = (upper + lower) / 2;// the largest card Aoki-san takes

            int count = 1;
            if(a[mid] >= x){
                count = lower_bound(a.begin(),a.end(),a[mid]) - lower_bound(a.begin(),a.end(), a[mid] - 2 * (a[mid] - x)) + 1;
                //cout << "a[" << mid << "] = " << a[mid] << " : count = " << count << endl;
            }
            if(count > (n-1) - (mid+1) + 1) upper = mid;
            else lower = mid;
        }

        long long int ans = sa1[n] - sa1[lower+1];
        int j = lower - ((n-1) - (lower+1)) - 1;
        ans += sa2[j+2];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5640
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var sc = bufio.NewScanner(os.Stdin)
var ReadString func() string

func init() {
	ReadString = newReadString()
}

/*------ scan ------*/

func newReadString() func() string {
	sc.Buffer(make([]byte, 1024), 2048)
	sc.Split(bufio.ScanWords)
	return func() string {
		if !sc.Scan() {
			panic("scanできなかった")
		}
		return sc.Text()
	}
}

func ReadLine() string {
	if !sc.Scan() {
		panic("line をscanできなかった")
	}
	return sc.Text()
}

func ReadInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		fmt.Println("parseInt失敗")
		panic(err.Error())
	}
	return int64(i)
}

func ReadInt() int {
	i := ReadInt64()
	return int(i)
}

func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}

func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

/*------ number util ------*/

func GetIntAbs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func Atoi(a string) int {
	i, err := strconv.Atoi(a)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func FindMin(arr []int) int {
	if len(arr) == 0 {
		return 0
	}
	min := arr[0]
	for _, v := range arr {
		if v < min {
			min = v
		}
	}
	return min
}

func FindMax(arr []int) int {
	if len(arr) == 0 {
		return 0
	}
	max := arr[0]
	for _, v := range arr {
		if v > max {
			max = v
		}
	}
	return max
}


func main() {
	n := ReadInt()
	a := ReadInt()
	b := ReadInt()

  if n * a > b {
    fmt.Println(b)
  } else {
     fmt.Println(n * a)
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream &s, const map<T, S> m) { for (pair<T, S> p: m) s << p << endl; return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

int count(int a, int b) {
  if (a <= b && b < 4 * a) return 0;
  else if (a < b) {
    return -1 + count(4 * a, b);
  } else {
    return 1 + count(a, 4 * b);
  }
}
signed main() {
  int N; cin >> N;
  VI A(N);
  REP (i, N) cin >> A[i];
  VVI dp0(N, VI(16)), dp1(N, VI(16));
  REP (x, 16) {
    dp0[N - 1][x] = x;
    dp1[0][x] = x;
  }
  for (int i = N - 2; i >= 0; i--) {
    int dif = count(A[i], A[i + 1]);
    REP (x, 16) {
      int tmp = max(0LL, x + dif);
      if (tmp >= 16) {
        dp0[i][x] = dp0[i + 1][15] + x + (tmp - 15) * (N - i - 1);
      } else {
        dp0[i][x] = dp0[i + 1][tmp] + x;
      }
    }
  }
  REP (i, N - 1) {
    int dif = count(A[i + 1], A[i]);
    REP (x, 16) {
      int tmp = max(0LL, x + dif);
      if (tmp >= 16) {
        dp1[i + 1][x] = dp1[i][15] + x + (tmp - 15) * (i + 1);
      } else {
        dp1[i + 1][x] = dp1[i][tmp] + x;
      }
    }
  }
  dump(dp1);
  int ans = 1e18;
  REP (i, N) {
    int tmp = i + dp0[i][0] * 2 + (i == 0 ? 0 : dp1[i - 1][0] * 2);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 69504
import java.util.Scanner;
import java.lang.Math;
import java.lang.String;
import java.lang.System;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main{
  public static void main(String args[]){
    Scanner stdln = new Scanner(System.in);
    String str1 = stdln.nextLine(); //str1はデータの数
    String str2 = stdln.nextLine();
    int N = Integer.parseInt(str1);
    String strdata[] = str2.split(" ");
    int intdata[] = new int[strdata.length];
    intdata = changetoInt(strdata);
    int average = getAverage(intdata,N);
    int answer = getSubSquareSum(intdata,average,N);
    System.out.println(answer);
  }
  //String型の配列からint型の配列へと変更する関数
  public static int[] changetoInt(String array[]){
    int i = 0;
    int data[] = new int[array.length];
    while(i < array.length){
      data[i] = Integer.parseInt(array[i]);
      i++;
    }
    return data;
  }
  //配列と個数を受け取って平均を返す関数
  public static int getAverage(int array[],int n){
    int sum = 0;
    int i = 0;
    int N = n;
    while(n > 0){
      sum = sum + array[i];
      i++;
      n--;
    }
    double average = (double)sum / N;
    int nearaverage = (int)Math.round(average);
    return nearaverage;
  }
  //配列と平均と個数を受け取って差の二乗の和を返す関数
  public static int getSubSquareSum(int array[],int average,int n){
    int i = 0;
    int sum = 0;
    while(n > 0){
      int x = array[i] - average;
      int y = x*x;
      sum = sum + y;
      i++;
      n--;
    }
    return sum;
  }
}


Measured memory_bytes: 9428
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> P;

int main(){
	int a,b,c,n;
	int com[3][1010];
	int flg[1010];
	P r[1010];
	while(1){
	cin >> a >> b >> c;
	if(a==0 && b==0 && c == 0) break;
	cin >> n;
	int sum = a+b+c;
	for(int i=0;i<=sum;i++){
		flg[i] = -1;
	}
	for(int i=0;i<n;i++){
		int op;
		cin >> com[0][i] >> com[1][i] >> com[2][i] >> op;
		P p; p.first = -op; p.second = i;
		r[i] = p;
	}
	sort(r,r+n);
	for(int i=0;i<n;i++){
		P p = r[i];
		int op = -p.first; int ban = p.second;
		if(op == 1){
			for(int j=0;j<3;j++){
				flg[com[j][ban]] = 1;
			}
		}
		else {
			int cou = 0;
			int pos = 0;
			for(int j=0;j<3;j++){
				if(flg[com[j][ban]] == -1 || flg[com[j][ban]] == 0){
					cou++;
					pos = com[j][ban];
				}
			}
			if(cou == 1){
				flg[pos] = 0;
 			}
		}
	}
	for(int i=1;i<=sum;i++){
		if(flg[i]==-1) cout << "2" << endl;
		else cout << flg[i] << endl;
	}
	}
}

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

int main() {
  int a, b; cin >> a >> b;
  int cnt = 0;
  
  for(int i = a;i <= b; i++){
    if((i / 10000) == (i % 10) and (i / 1000) % 10 == (i % 100) / 10)
      cnt++;
  }
      cout << cnt << endl;
}


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

int sw[10][10]={};
int p[10]={};
int b[10]={};
bool judge[10]={};

void tob(int i, int n){
  if(i==0) return;
  b[n-1]=i%2;
  tob(i/2,n-1);
  return;
}

int main(){
  int N, M;
  cin >> N >> M;
  for(int i=0; i<M; i++){
    int num;
    cin >> num;
    for(int j=0; j<num; j++){
      int idx;
      cin >> idx;
      sw[i][idx-1]=1;
    }
  }
  for(int i=0; i<M; i++){
    cin >>  p[i];
  }
  int itr = pow(2,N);
  int count=0;
  for(int i=0; i<itr; i++){
    tob(i,N);
    bool flag=false;
    for(int j=0; j<M; j++){
      int sum=0;
      for(int k=0; k<N; k++){
        sum += sw[j][k]*b[k];
      }
      if(sum%2==p[j]){
        flag=true;
        continue;
      }else{
        flag=false;
        break;
      }
    }
    if(flag) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
 
ans = 1
flag = 1
if 0 in A:
    ans = 0
else:
    for i in range(N):
        ans *= A[i]
        if ans > 10 ** 18:
            flag = 0
            break

if flag == 0:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 84740
import java.util.*;

public class Main {
    static int max;
    static int count = 0;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        max = sc.nextInt();
        
        dfs(0);
        
        System.out.println(count);
    }
    
    public static void dfs(long x) {
        if (x > max) return;
        
        if (pass(x)) count++;
        
        dfs(10 * x + 7);
        dfs(10 * x + 5);
        dfs(10 * x + 3);
    }
    public static boolean pass(long x) {
        String str = String.valueOf(x);
        if (str.contains("7") && str.contains("5") && str.contains("3")) return true;
        return false;
    }
}


Measured memory_bytes: 24020
using System;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(ReadLine());
        var l = Enumerable.Repeat(0, n).Select(_ => int.Parse(ReadLine())).OrderBy(x => x).ToArray();
        for (int i = 0; i < n - 1; i++)
        {
            if (l[i] == l[i + 1])
            {
                l[i] = 0;
                l[i + 1] = 0;
            }
        }
        WriteLine(l.Count(x => x != 0));
    }
}

Measured memory_bytes: 20700
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_ABC089_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int[] march = new int[5];

            for (int i = 0; i < n; ++i)
            {
                string name = Console.ReadLine();

                switch (name[0])
                {
                    case 'M':
                        ++march[0];
                        break;
                    case 'A':
                        ++march[1];
                        break;
                    case 'R':
                        ++march[2];
                        break;
                    case 'C':
                        ++march[3];
                        break;
                    case 'H':
                        ++march[4];
                        break;
                }
            }

            List<int> marchList = new List<int>();
            for (int i = 0; i < 5; ++i)
            {
                if (march[i] > 0)
                {
                    marchList.Add(march[i]);
                }
            }

            if (marchList.Count < 3)
            {
                Console.WriteLine(0);
                return;
            }

            if (marchList.Count == 3)
            {
                Console.WriteLine(marchList[0] * marchList[1] * marchList[2]);
                return;
            }

            List<int> marchCounts = new List<int>();
            System.Int64 marchCount = 0;
            for (int i = 0; i < 3; ++i)
            {
                System.Int64 tmpMarchCountI = marchList[i];

                for (int j = i + 1; (j < i + 4 || j < marchList.Count); ++j)
                {
                    if (j >= marchList.Count)
                    {
                        break;
                    }

                    System.Int64 tmpMarchCountJ = tmpMarchCountI * marchList[j];

                    for (int k = j + 1; k < marchList.Count; ++k)
                    {
                        if (k >= marchList.Count)
                        {
                            break;
                        }

                        marchCount += tmpMarchCountJ * marchList[k];
                    }
                }
            }

            Console.WriteLine(marchCount);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
long long i,i0,n,m;
int main()
{
    scanf("%lld",&n);
	long long sum=0;
	for(long long l=1,r;l<=n;l=r+1)
	{
		r=n/(n/l);
		long long t=n/l;
		if(n%t==0)
		{
			if(n/t-1<=r&&n/t-1>=l)sum+=n/t-1;
		}
	}
	printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 256
def myAnswer(S:set)-> str:
   alf = [chr(ord('a')+i) for i in range(26)]
   counter = "None"
   for a in alf:
      if((a in S) == False):
         counter=a
         break
   return counter



   

def modelAnswer():
   tmp=1
def main():
   S = set(input())
   print(myAnswer(S))

if __name__ == '__main__':
   main()

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

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


int main() {
  string t;
  cin>>t;
  int n=t.size();
  rep(i,n){
    if(t[i]=='?')cout<<'D';
    else cout<<t[i];
  }
}


Measured memory_bytes: 3668
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(A);
    scanInt(B);
    scanInt(C);
    scanInt(D);
    printf("%d\n", max(0, min(B, D) - max(A, C)));
}


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

using namespace std;

int main()
{
	int N, Q;
	string S;
	cin >> N >> Q;
	cin >> S;
	vector<int> l(Q), r(Q);
	for (int i = 0; i < Q; i++)
		cin >> l[i] >> r[i];

	vector<int> v(N + 1);
	for (int i = 1; i < S.size(); i++) {
		int count = 0;
		if (S[i - 1] == 'A' && S[i] == 'C')
			count = 1;
		v[i + 1] = v[i] + count;
	}

	for (int i = 0; i < Q; i++) {
		cout << (v[r[i]] - v[l[i]]) << endl;
	}

	return 0;
}

Measured memory_bytes: 2176
import bisect

n = int(input())
num = list(map(int, input().split()))

q = int(input())
for _ in range(q):

    k = int(input())
    if k > num[-1]:
        print(n, n)
        continue
    else:
        print(bisect.bisect_left(num, k), bisect.bisect_right(num, k))



Measured memory_bytes: 17216
#include<iostream>
#include<vector>
#include<algorithm>
#define N 1000

using namespace std;

int num[N][N], dp[N][N];
bool prime[N][N], is_reach[N][N];

bool is_prime(int& n, vector<int>* p){
  if(n==1) return false;
  for(vector<int>::iterator it=p->begin();
      it!=p->end() && (*it)*(*it)<=n; ++it){
    if(!(n%(*it))) return false;
  }
  p->push_back(n);
  return true;
}
void init(){
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      num[i][j]=0, prime[i][j]=false;
    }
  }
  vector<int> p;
  for(int i=N/2, j=N/2-1, k=1, is=1; k<=N*N; ++k){
    num[i][j] = k;
    prime[i][j] = is_prime(k, &p);
    if(is==1){
      ++j;
      if(!num[i-1][j]) ++is;
    }else if(is==2){
      --i;
      if(!num[i][j-1]) ++is;
    } else if(is==3){
      --j;
      if(!num[i+1][j]) ++is;
    }else if(is==4){
      ++i;
      if(!num[i][j+1]) is=1;
    }
  }
}

bool is_over(int& i, int& j, int& m){
  return (i==-1 || i==N || j==-1 || j==N || num[i][j]>m);
}
void set(int i, int j, int& m){
  if(!is_over(i,j,m)) is_reach[i][j]=true;
}
int get(int i, int j, int& m){
  return (is_over(i,j,m) ? 0 : dp[i][j]);
}
bool is_max(int& i, int& j, int& max_, int& num_){
  if(!prime[i][j]) return false;
  if(dp[i][j] > max_) return true;
  if(dp[i][j]==max_ && num[i][j]>num_) return true;
  return false;
}

void solve(int& m, int& n){
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      dp[i][j]=0, is_reach[i][j]=false;
    }
  }
  int max_=0, num_=0;
  bool is=false;
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      if(num[i][j]==n){
	is=true;
	dp[i][j]=prime[i][j];
	set(i,j,m), set(i+1,j-1,m), set(i+1,j,m), set(i+1,j+1,m);
	if(prime[i][j]) max_=1, num_=num[i][j];
	break;
      }
      if(num[i][j]>m || !is || !is_reach[i][j]) continue;
      dp[i][j] = prime[i][j] +
	max(get(i-1,j-1,m), max(get(i-1,j,m), get(i-1,j+1,m)));
      set(i+1,j-1,m), set(i+1,j,m), set(i+1,j+1,m);
      if(is_max(i,j,max_,num_)) max_=dp[i][j], num_=num[i][j];
    }
  }
  cout << max_ << " " << num_ << endl;
}

int main(){
  init();
  int m, n;
  while(1){
    cin >> m >> n;
    if(!m && !n) break;
    solve(m, n);
  }
  return 0;
}

Measured memory_bytes: 11112
#include <bits/stdc++.h>
#define MOD 1000000007
 
using namespace std;

string S,T;

int main(){

cin>>S;

string A="dream";
string B="dreamer";
string C="erase";
string D="eraser";

int k=0;

while(1){
bool f1=1,f2=1,f3=1,f4=1;
for(int i=0; i<5; i++){
    if(k+i>=S.size()) break;
    if(S[k+i]!=A[i]) f1=0;
}
for(int i=0; i<7; i++){
    if(k+i>=S.size()) break;
    if(S[k+i]!=B[i]) f2=0;
}
if(f2&&(S[k+7]=='e'||S[k+7]=='d'||k+7==S.size())){
    k=k+7; 
    if(k==S.size()) break;
    if(S.size()-k<5){
        puts("NO"); return 0;
    }

}else if(f1){
    k=k+5; 
    if(k==S.size()) break;
    if(S.size()-k<5){
        puts("NO"); return 0;
    }
}
for(int i=0; i<5; i++){
    if(k+i>=S.size()) break;
    if(S[k+i]!=C[i]) f3=0;
}
for(int i=0; i<6; i++){
    if(k+i>=S.size()) break;
    if(S[k+i]!=D[i]) f4=0;
}
if(f4&&(S[k+6]=='e'||S[k+6]=='d'||k+6==S.size())){
    k=k+6; 
    if(k==S.size()) break;
    if(S.size()-k<5){
        puts("NO"); return 0;
    }
}else if(f3){
    k=k+5; 
    if(k==S.size()) break;
    if(S.size()-k<5){
        puts("NO"); return 0;
    }
}
if(!f1&&!f2&&!f3&&!f4){
    puts("NO"); return 0;
}
}

puts("YES");

return 0;
 
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

bool vali(const vector<int> &a,ll mid,ll K){
    ll cnt=0;
    for(auto i:a){
        if(i%mid==0) cnt+=i/mid-1;
        else cnt+=i/mid;
        if(cnt>K) return false;
    }
    return cnt <= K;

}

void solve(int cn) {
    ll N,K;
    cin>>N>>K;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
    }
    ll maxi=1e9+10,mini=0;

    while(maxi-mini>1){
        ll mid=(maxi+mini)/2.0;
        if(vali(a,mid,K)){
            maxi=mid;
        }else{
            mini=mid;
        }
        //cout<<maxi<<" "<<mini<<endl;
    }
    cout<<maxi<<endl;

}


#define SINGLE
int main() {
#ifdef SINGLE
    solve(1);
#else
    int N;
    cin>>N;
    for(int i=0;i<N;++i){
        solve(i);
    }
#endif
    return 0;
}


Measured memory_bytes: 3968
X, K, D = map(int ,input().split())

if K * D < abs(X):
    ans = abs(X) - K * D
else:
    if abs(X) // D % 2 == 0:
        if K % 2 == 0:
            ans = abs(X) % D
        else:
            ans = abs(abs(X) % D - D)
    else:
        if K % 2 == 0:
            ans = abs(abs(X) % D - D)
        else:
            ans = abs(X) % D

print(ans)

Measured memory_bytes: 9172
/*  Perseverance can make miracle happens  */
/* If u identify me then u r my frnd */

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

#define int long long int
#define vi vector<int>
#define pq priority_queue<int>
#define mpi map<int,int>
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

//---------------------------------------------------------------------------------------------------------------------------------//

int mod(long long x) {
	return ((x % M + M) % M);
}
int add(int a, int b) {
	return mod(mod(a) + mod(b));
}
int diff(int a, int b) {
	return mod(mod(a) - mod(b));
}

int mul(int a, int b) {
	return mod(mod(a) * mod(b));
}

//---------------------------------------------------------------------------------------------------------------------------------//

const int N = 1e6 + 1;
int p[N];


void solve() {

	for (int i = 2; i < N; ++i) {
		if (p[i])continue;
		for (int j = i; j < N; j += i)p[j] = i;
	}
	for (int i = 2; i < N; ++i) {
		if (p[i])continue;
		for (int j = i; j < N; j += i)p[j] = i;
	}

	auto getFactorCnt = [&](int x) {
		int ans = 1;
		while (x > 1) {
			int prime = p[x], cnt = 1;
			while (x % prime == 0)cnt++, x /= prime;
			ans *= cnt;
		}
		return ans;
	};

	int res = 0;
	int n; cin >> n;
	for (int i = 1; i < n; ++i)
	{
		res  = res + getFactorCnt(n - i);
	}

	cout << res << endl;
}


int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t; cin >> t;
	int t = 1;

	while (t--) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 11420
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

int main(){

    int a,b,n1,n2,n3,n4,n5,cont=0;

    scanf("%d %d",&a,&b);

    for(int i=a;i<=b;i++){
        n5=i%10;
        n4=(i/10)%10;
        n3=(i/100)%10;
        n2=(i/1000)%10;
        n1=(i/10000)%10;

        if(n1==n5 && n2==n4)
            cont++;
    }
    printf("%d\n",cont);
    cont=0;



    return 0;
}


Measured memory_bytes: 128