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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int const MAX = 3e5 + 41;
int const MOD = 998244353;

int n, a, b;
ll k;

int add(int a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

int mult(int a, int b) {
	return (ll) a * b % MOD;
}

int bp(int x, int d) {
	int res = 1;
	while (d) {
		if (d & 1) res = mult(res, x);
		x = mult(x, x);
		d >>= 1;	
	}
	return res;
}

int f[MAX];
int invf[MAX];

void init() {
	f[0] = 1;
	fi(1, MAX - 1) {
		f[i] = mult(f[i - 1], i);
	}
	fi(0, MAX - 1) {
		invf[i] = bp(f[i], MOD - 2);
	}
}

int getc(int n, int k) {
	return mult(f[n], mult(invf[k], invf[n - k]));	
}

int ans;

void solve() {
	fi(0, n) {
		ll k1 = k - (ll) i * a;
		if (k1 < 0) continue;
		if (k1 % b != 0) continue;
		ll q1 = k1 / b;
		if (q1 > n) continue;
		int v1 = getc(n, i);
		int v2 = getc(n, (int) q1);
		int v = mult(v1, v2);
		ans = add(ans, v);
	}	
	printf("%d\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
	init();
	scanf("%d %d %d %lld", &n, &a, &b, &k);  
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#define N 100000
int A[N],n;
int partition(int,int);
int main(void){
  int i,ans;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  ans=partition(0,n-1);
  for(i=0;i<n;i++){
    if(i!=0) printf(" ");
    if(ans==i)printf("[%d]",A[i]);
    else printf("%d",A[i]);
  }
  printf("\n");
}
int partition(int p,int r){
  int x,i,j,tmp;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i +=1;
      tmp=A[i]; 
      A[i]=A[j]; 
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r]; 
  A[r]=tmp;
  return i+1;
}



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

void solve(string S)
{
    int n = S.size();
    long long ans = 0;
    for (int bit = 0; bit < (1 << n - 1); ++bit) //1234,1+2+3+4
    {
        string ss = "";
        for (int i = 0; i < n; i++)
        {
            ss += S[i];
            if (bit >> i & 1) //ビットをi桁だけ右にシフトさせたものが1(0b000000001)と部分一致しているか
            {
                ans += stoll(ss); //string →int変換
                ss = "";
            }
        }
        //端の足されてない奴を足す。
        ans += stoll(ss);
        ss = "";
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    string S;
    cin >> S;
    solve(S);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=100010;
const int inf=0x3f3f3f3f;
int n;
int k;
char s[maxn];
std::vector<int> v1,v2;
ll sum1[maxn];
ll sum2[maxn];
int main()
{
    
    gbtb;
    cin>>n>>k;
    cin>>s;
    int cnt=0;
    if(s[0]=='0')
    {
        v1.pb(0);
    }
    repd(i,0,n-1)
    {
        if(s[i]=='0')
        {
            while(s[i]=='0')
            {
                cnt++;
                i++;
            }
            v2.push_back(cnt);
            cnt=0;
            i--;
        }
        if(s[i]=='1')
        {
            while(s[i]=='1')
            {
                cnt++;
                i++;
            }
            v1.push_back(cnt);
            cnt=0;
            i--;
        }

    }
    int num=max(sz(v1),sz(v2));
    repd(i,1,maxn-2)
    {
        v1.push_back(0);
        v2.push_back(0);
    }
    repd(i,1,maxn-2)
    {
        sum1[i]+=sum1[i-1]+v1[i-1];
        sum2[i]+=sum2[i-1]+v2[i-1];
    }
    int w=0;
    ll ans=0ll;
    repd(i,1,n-k+4)
    {
        int l=i;
        int r=l+k;
        ll temp=sum1[r]-sum1[l-1];
        temp+=sum2[r-1]-sum2[l-1];
        ans=max(ans,temp);
    }
    cout<<ans<<endl;



    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

Measured memory_bytes: 3308
#include<stdio.h>
int main(void)
{
	int a,b,i,j,x,y,n,masu[16+1][16+1];
	scanf("%d %d",&b,&a);
	while(a!=0 && b!=0) {
		scanf("%d",&n);
		for(i=1;i<=a;i++) {
			for(j=1;j<=b;j++) {
				masu[i][j]=0;
			}
		}
		
		for(i=1;i<=n;i++) {
			scanf("%d %d",&x,&y);
			masu[y][x]=-1;
		}
		if(masu[1][1]!=-1) {
			masu[1][1]=1;
			for(i=1;i<=a;i++) {
				for(j=1;j<=b;j++) {
					if(masu[i][j]!=-1) {
						if(i-1>=1 && masu[i-1][j]!=-1){
							masu[i][j]+=masu[i-1][j];
						}
						if(j-1>=1 && masu[i][j-1]!=-1){
							masu[i][j]+=masu[i][j-1];
						}
						/*if(i==1) {
							masu[i][j]=masu[i][j-1];
						}
						else if(j==1) {
							masu[i][j]=masu[i-1][j];
						}
						else {
							masu[i][j]=masu[i][j-1]+masu[i-1][j];
						}*/
					}
				}
			}
		}
		
/*		for(i=1;i<=a;i++) {
			for(j=1;j<=b;j++) {
				printf("%d ",masu[i][j]);
			}
			printf("\n");
		}*/
		if((masu[a][b]!=-1)&&(masu[1][1]!=-1)) {
			printf("%d\n",masu[a][b]);
		}
		else {
			printf("0\n");
		}
	scanf("%d %d",&b,&a);
	}
	return 0;
}

Measured memory_bytes: 600
H,W,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*N]
d={}
for a,b in ab:
    for i in (a-1,a,a+1):
        for j in (b-1,b,b+1):
            d[(i,j)] = d.get((i,j),0)+1
cnt = [0]*10
for k,v in d.items():
    a,b = k
    if a<2 or b<2:continue
    if a>H-1 or b>W-1:continue
    cnt[v] += 1
cnt[0] = (W-2)*(H-2)-sum(cnt)
for ans in cnt:
    print(ans)

Measured memory_bytes: 165968
s = str(input())
s_len = len(s)
def palindrome(string):
    if string==string[::-1]:
        return 1

    else:
        return 0

nn = (s_len - 1) // 2
# print(nn)
# print(s[0:nn])
mm = (s_len + 3) // 2 - 1
# print(s[mm:])

if palindrome(s) == 1 and palindrome(s[0:nn]) and palindrome(s[mm:]):
    # print("c")
    print("Yes")
else:
    print("No")

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

using namespace std;

long long f(long long r){
    return r*(r+1)/2;
}

int main(void){
  long long n;
  cin >> n;
  
  long long ans = 0;
  
  for(long long i = 1; i <= n; i++){
      long long r = n / i;
      ans += i * f(r);
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3576
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>

using namespace std;

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

template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vector<T>>;

#define REP(i, s, e) for (ll i = s; i < e; ++i)

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


    vvec<int> A(3, vec<int>(3));
    REP(i, 0, 3) REP(j, 0, 3) cin >> A[i][j];
    int N; cin >> N;
    REP(i, 0, N)
    {
        int b; cin >> b;
        REP(i, 0, 3) REP(j, 0, 3)
        {
            if (A[i][j] == b)
            {
                A[i][j] = 0;
            }
        }
    }

    bool r = false;
    REP(i, 0, 3)
    {
        bool r2 = true;
        REP(j, 0, 3) r2 &= !A[i][j];
        r |= r2;

        r2 = true;
        REP(j, 0, 3) r2 &= !A[j][i];
        r |= r2;
    }

    r |= !A[0][0] && !A[1][1] && !A[2][2];

    r |= !A[2][0] && !A[1][1] && !A[0][2];

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

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 100005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

int main()
{
	int n, m, x, y, l, r;
	cin >> n >> m >> x >> y;
	l = x;
	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		l = max(x, l);
	}
	r = y;
	for (int i = 0; i < m; ++i)
	{
		cin >> x;
		r = min(x, r);
	}
	if(l < r)
		cout << "No War";
	else
		cout << "War";
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int ht,st,ha,sa;
        ht=s.nextInt();
        st=s.nextInt();
        ha=s.nextInt();
        sa=s.nextInt();
        while(true){
            ha-=st;
            if(ha<=0){
                System.out.println("Yes");
                break;
            }
            ht-=sa;
            if(ht<=0){
                System.out.println("No");
                break;
            }
        }

    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 25356
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

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

int a, b, c;

int main() {
  cin >> a >> b >> c;
  cout << min(a + b, min(b + c, c + a));
}


Measured memory_bytes: 3612
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    int K;
    read(K);
    ll ans = 0;
    for(int a = 1; a <= K; a++){
        for(int b = 1; b <= K; b++){
            int t = __gcd(a, b);
            if(t == 1) {
                ans += K;
            }
            else {
                for(int c = 1; c <= K; c++){
                    ans += __gcd(t, c);
                }
            }
        }
    }
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>       // for next_permutation
#include <numeric>
#include<cstdio>
#include<iomanip>

using namespace std;

int main(void){
  long long int N;
  std::vector<long long int> x, y;
  std::cin >>N;
  double average=0;
  int div[] ={1,2,6,24,120, 720, 5040, 40320};
  for(int i=0;i<N;i++){
    int x1, y1;
    std::cin >> x1;
    std::cin >> y1;
    x.push_back(x1);
    y.push_back(y1);
  }
  std::vector<int> v(N);
  std::iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
  do {
    for(int i=0;i<N-1;i++){
      average += sqrt( pow((x[v[i]-1]-x[v[i+1]-1]), 2) + pow((y[v[i]-1]-y[v[i+1]-1]), 2) );
    }
  } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成
  std::cout <<std::setprecision(10)<< average/div[N-1];
  return 0;
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
int main(){
    int N,L;
    cin>>N>>L;
    while(N--){
        string s;
        cin>>s;
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    for(string &s:v)cout<<s;
    cout<<endl;
    return 0;
}


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

#define    ll     long long int

int main( )
{
    int n, i, l, r;
    int s = 0;
    cin >> n;
    while (n--) {
        cin >> l >> r;
        s += (r - l + 1);
    }
    cout << s << '\n';
    return 0;
}


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

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

int main(){
	int X,Y,Z,K;
	cin >> X >> Y >> Z >> K;
	vector<long long> A(X);
	vector<long long> B(Y);
	vector<long long> C(Z);
	for(int i=0;i<X;i++)	cin >> A.at(i);
	for(int i=0;i<Y;i++)	cin >> B.at(i);
	for(int i=0;i<Z;i++)	cin >> C.at(i);

	sort(A.begin(),A.end(),greater<long long>());
	sort(B.begin(),B.end(),greater<long long>());
	sort(C.begin(),C.end(),greater<long long>());

	vector<long long> ABC;
	for(int i=0;i<X;i++){
		for(int j=0;j<Y;j++){
			if(i*j>K)	break;
			for(int k=0;k<Z;k++){
				if(i*j*k>K)	break;
				ABC.push_back(A.at(i)+B.at(j)+C.at(k));
			}
		}
	}
	
	sort(ABC.begin(),ABC.end(),greater<long long>());
	for(int i=0;i<K;i++){
		cout << ABC.at(i) << endl;
	}
	
	return 0;
}


Measured memory_bytes: 35176
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string s, t; cin >> s >> t;
    vector<int> start(26,-1);
    vector<int> goal(26,-1);

    rep(i,s.size()){
        int sc = s[i] - 'a';
        int gc = t[i] - 'a';

        if(start[sc] != -1 || goal[gc] != -1){
            if(start[sc] != gc || goal[gc] != sc){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
        start[sc] = gc;
        goal[gc] = sc;
        } 
    }

    cout << "Yes" << endl;


}
    

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 112345
int a[N] = {};
char s[5];

int main(){
	int n, m; scanf("%d%d", &n, &m);
	int ac = 0, wa = 0;
	REP(i, m){
		int p; scanf("%d%s", &p, s);
		if(!~a[p]) continue;
		if(s[0] == 'A'){
			ac++;
			wa += a[p];
			a[p] = -1;
		} else {
			a[p]++;
		}
	}
	printf("%d %d\n", ac, wa);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9+1;
const ll LINF = 1e18+1;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}
template<typename T> T lcm(T a,T b){return a*b/gcd(a, b);}


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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
    IN(ll, x);
    Yes(x>=30);
}


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

int main(){
  string s; cin >>s;
  if(s=="RSR"){
    cout << 1 << endl;
    return 0;
  }
  int cnt = 0;
  rep(i,3){
    if(s[i]=='R') cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3624
s = input()

master = "keyence"

i = 0
f = 0

if(s[0:7] == master or s[-7:] == s):
    print("YES")
else:
    i = 0
    while (s[i] == master[i]):
        i += 1
    if (s[-7+i:] == master[i:]):
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

typedef struct apple {
  int value;
  int color;
}apple;

//降順
int des(const void *a, const void *b)
{
  return ((apple *)b)->value - ((apple *)a)->value;
}

int main() {
  int x,y,a,b,c;
  scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
  apple app[a+b+c];
  for (int i=0; i<a; i++) {
    scanf("%d", &(app[i].value));
    app[i].color = 0;
  }
  for (int i=0; i<b; i++) {
    scanf("%d", &(app[a+i].value));
    app[a+i].color = 1;
  }
  for (int i=0; i<c; i++) {
    scanf("%d", &(app[a+b+i].value));
    app[a+b+i].color = 2;
  }
  qsort(app, a+b+c, sizeof(apple), des);
  int cnt[3] = {};
  long ans = 0;
  for (int i=0; i<a+b+c; i++) {
    if (cnt[0]+cnt[1]+cnt[2] == x+y)
      break;
    if (app[i].color == 0) {
      if (cnt[0] >= x)
        continue;
      cnt[0]++;
      ans += app[i].value;
    } else if (app[i].color == 1) {
      if (cnt[1] >= y)
        continue;
      cnt[1]++;
      ans += app[i].value;
    } else {
      cnt[2]++;
      ans += app[i].value;
    }
  }
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 4860
# coding: utf-8
class Case02

  def initialize
  end

  def show
    p self.instance_variables
        .map{ |sym| [sym, self.instance_variable_get(sym)] }
        .to_h
  end
  
  # 実行する
  def execute
    read
    solve
    output
  end

  # 読込
  def read
    @n = gets.chomp.to_i
    @a = []
    @n.times do
      @a << gets.chomp.to_i
    end
  end

  # 回答
  def solve
    @b = 1
    @s = 0
    while @b != 2 and @s < @n do
      @b = @a[@b-1]
      @s += 1
    end
  end
  
  # 出力
  def output
    puts (@b == 2) ? @s : -1;
  end

end

Case02.new.execute if $0 == __FILE__



Measured memory_bytes: 3836
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <random>
#include <cassert>
#include <limits>

using namespace std;

#define mp make_pair
#define pb push_back
#define repi(i, p, q) for (long i = p; i < q; i++)
#define repd(i, p, q) for (long i = p; i >= q; i--)
#define sz(x) x.size()
#define INF 2000000000
#define MOD 1000000007

typedef map<int, int> MI;
typedef pair<int, int> PI;
typedef long long int LLI;
typedef long int LI;
typedef int I;

vector<LLI> a;

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

int main()
{
    LLI n;
    cin >> n;
    LLI x;
    cin >> x;
    LLI num;
    for (int i = 0; i < n; i++)
    {
        cin >> num;
        a.pb(num);
    }
    a.pb(x);
    sort(a.begin(), a.end());
    LLI ans = a[1] - a[0];
    for (int i = 2; i < a.size(); i++)
    {
        ans = gcd(ans, a[i] - a[i - 1]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1400
import numpy as np
S = np.array([int(i) for i in input()])
N = len(S)
T = np.abs(np.diff(S))
K = N
for i in range(N // 2):
    if T[i] == 1 or T[N - 2 - i] == 1:
        K = N - i - 1

print(K)

Measured memory_bytes: 23252
N, T = map(int, input().split())

route = []
for i in range(N):
    c, t = map(int, input().split())
    route.append((c, t))
#print(route)    
    
route_ = list(filter(lambda x:x[1] <= T, route))
#print(route_)

if len(route_) == 0:
    print('TLE')
else:
    print(min(route_, key = lambda x:x[0])[0])

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String x=s.next(); 
        int y=Integer.parseInt(x.substring(5,7));

        //System.out.println(y);
        
        if(y>4){
            System.out.println("TBD");
        }
        else{
            System.out.println("Heisei");
        }
    }  
}


Measured memory_bytes: 21204
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){
ll int N;
cin >> N;
vector<ll int> d(N);
rep(i,N){
	cin >> d[i];
	}
ll int counter = 0;

sort(d.begin(),d.end());

for(long long int i=0;i<N;i++){
		for(long long int j =i+1;j<N;j++){
			for(long long int k=j+1;d[i]+d[j]>d[k];k++){
				if(d[i]<d[j]+d[k]&&d[j]<d[k]+d[i]&&d[k]<d[i]+d[j]){
					counter += 1;
				}
				else{}
			}
		}
}
cout << counter;















	return 0;

}



Measured memory_bytes: 256
import sys

input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


def count_a(A, X):
    l = -1
    r = N
    while r - l > 1:
        m = (r + l) // 2
        if A[m] < b:
            l = m
        else:
            r = m
    return l + 1


def count_c(C, X):
    l = -1
    r = N
    while r - l > 1:
        m = (r + l) // 2
        if C[m] > b:
            r = m
        else:
            l = m
    return N - r


A.sort()
B.sort()
C.sort()

ans = 0
A_min = A[0]
C_max = C[-1]

for b in B:
    if b <= A_min or b >= C_max:
        continue

    a_cnt = count_a(A, b)
    if a_cnt == 0:
        continue
    c_cnt = count_c(C, b)

    ans += a_cnt * c_cnt

print(ans)


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

using namespace std;
using ll=long long;

int main()
{
    int n;cin >>n;
    int h[n];
    int mx=0,mint=1010;
    bool flg=true;
    int ans=0;
    for(int i=0;i<n;i++){
        cin >>h[i];
        if(flg&&h[i]<mx){
            flg=false;
            ans+=mx;
            mx=0;
            mint=1010;
        }
        if(!flg&&h[i]>mint){
            flg=true;
            ans-=mint;
            mint=1010;
            mx=0;
        }
        mint=min(mint,h[i]);
        mx=max(mx,h[i]);
    }
    if(n==1||(n>2&&h[n-2]<=h[n-1]))ans+=h[n-1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
int n,m;
long long total=0;
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	vector<vector<int>> a(n,vector<int>(n,0));
	for(int i=0;i<m;i++){
		int x,y,z;
		cin>>x>>y>>z;
		--x,--y;
		a[x][y]=a[y][x]=z;
		total+=z;
	}
	const int inf=(int)1e9;
  	vector<int> inside(1<<n);
  	for(int t=0;t<(1<<n);t++){
      	for(int i=0;i<n;i++){
        	if(t&(1<<i)){
          		for(int j=i+1;j<n;j++){
            		if(t&(1<<j)){
            	  		inside[t]+=a[i][j];
            		}
          		}
        	}
      	}
  	}
  	vector<vector<int> > dp(1<<n,vector<int>(n,-1));
  	for(int t=0;t<(1<<n);t++) if(t&1) dp[t][0]=inside[t];
  	for(int t=0;t<(1<<n);t++) {
    	for(int ii=0;ii<n;ii++) {
    		if(dp[t][ii]==-1) continue;
    		int u=(1<<n)-1-t;
    		while(u>0) {
     	 		for(int j=0;j<n;j++) {
     		   		if(u&(1<<j)) {
     	    			if(a[ii][j]>0) {
    	        			dp[t|u][j]=max(dp[t|u][j],dp[t][ii]+inside[u]+a[ii][j]);
    	      			}
    	    		}
    	  		}
    	  		u=(u-1)&((1<<n)-1-t);
    		}
    	}
  	}
  	cout<<total-dp[(1<<n)-1][n-1]<<'\n';
	return 0;
}

Measured memory_bytes: 3840
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int a,b,c,d;
	std::cin >> a >> b >> c >> d;
	while(true){
		c -= b;
		if(c<=0){
			std::cout << "Yes" << std::endl;
			break;
		}
		a -= d;
		if(a<=0){
			std::cout << "No" << std::endl;
			break;
		}
	}
	return 0;
}


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

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

  vector<pair<long, long> > point;
  vector<long long> x, y;

  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    point.push_back(make_pair(a, b));
    x.push_back(a);
    y.push_back(b);
  }

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  long long ans = (x[n-1] - x[0]) * (y[n-1] - y[0]);

  for (int left = 0; left < n; left++){
    for (int right = left + k - 1; right < n; right++){
      for (int bottom = 0; bottom < n; bottom++){
        for (int top = bottom + k - 1; top < n; top++){

          int num = 0;
          for (int i = 0; i < n; i++){
            long long xi = point[i].first; long long yi = point[i].second;
            if (xi >= x[left] && xi <= x[right] && yi >= y[bottom] && yi <= y[top]){
              num++;
            }
          }

          if (num >= k) ans = min(ans, (x[right] - x[left]) * (y[top] - y[bottom]));
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INF = 2147483647;
#define rep(i, n) rep3(i, 0, n)
#define rep2(i, n) rep3(i, 1, n+1)
#define rep3(i, x, n) for(ll i = x; i < (ll)(n); i++)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}
template<class T>
void printp(vector<pair<T,T>> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}
template<class T>
void printp(map<T,T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
 
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
 
        // その結果を push
        res.push_back({a, ex});
    }
 
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(void){
    ll N;
    cin>>N;
    vector<char> res;
    do{
        char base = (N-1)%26+'a';
        res.push_back(base);
    }while(N=(N-1)/26, N>=1);
    rep(i,res.size()) cout << res[res.size()-i-1];
    cout<<endl;
    
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
int main(void){
    // Your code here!

    int a,b;
    char op;
    while(1){
      scanf("%d %c %d",&a,&op,&b);
      if(op=='?')break;
      switch(op){
        case '+' : printf("%d\n",a+b);break;
        case '-' : printf("%d\n",a-b);break;
        case '*' : printf("%d\n",a*b);break;
        case '/' : printf("%d\n",a/b);break;
      }
    }
}



Measured memory_bytes: 1916
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    a,b,c,d = readInt()
    tkhs = (a+d-1)//d
    aok = (c+b-1)//b
    if tkhs<aok:
        print("No")
    else:
        print("Yes")
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 9188
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    cin >> n;
    if (n == 0) {
        cout << 0 << endl;
        return 0;
    }
    int i = 1;
    string s;
    while (n) {
        if (abs(n) % abs(i * (-2)) != 0) {
            n -= i;
            s.push_back('1');
        }
        else
            s.push_back('0');
        i *= -2;
    }
    if (s.back() == '0')
        s.pop_back();
    reverse(s.begin(), s.end());
    cout << s << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
		int x, arr[100000], dp[100000];
		cin >> x;
		for (size_t i = 0; i < x; i++)
		{
			cin >> arr[i];
		}
		dp[0] = 0;
		dp[1] = abs(arr[1] - arr[0]);
		for (size_t i = 2; i < x; i++)
		{
			//dp[2]=2-1+dp1,2-0dp0
			dp[i] = min(abs(arr[i] - arr[i - 1]) + dp[i - 1], abs(arr[i] - arr[i - 2]) + dp[i - 2]);
		}
		cout << dp[x - 1];	
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <regex>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include<tuple>

using namespace std;

const int MAX = 100000;

int main() {
	int N, M;
	int A[MAX];
	long long sum[MAX + 1] = { 0 };
	long long ans = 0;
	map<long long, int> m;

	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> A[i];

		sum[i + 1] = (sum[i] + A[i]) % M;
	}

	for (int i = 0; i <= N; i++) {
		if (m.count(sum[i]) == 0)m[sum[i]] = 0;

		ans += m[sum[i]];
		m[sum[i]]++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

ll N;
ll X[30], Y[30], P[30], dist[30];
long double eps = 1e-9;
ll ans[35];
ll distx[40000][30], disty[40000][30];

void init_dist() {
  rep(i, 0, N) {
    ll d = INF;
    chmin(d, abs(X[i]));
    chmin(d, abs(Y[i]));
    dist[i] = d;
  }
}

void dfs(int cur, int cnt, int xx, int yy, int digit) {
  if (cur >= N) {
    ll score = 0;
    rep(i, 0, N) { score += min(distx[xx][i], disty[yy][i]) * P[i]; }
    chmin(ans[cnt], score);
    return;
  }

  dfs(cur + 1, cnt, xx, yy, digit * 2);

  dfs(cur + 1, cnt + 1, xx + digit, yy, digit * 2);

  dfs(cur + 1, cnt + 1, xx, yy + digit, digit * 2);
}

int main() {
  //
  cin >> N;
  rep(i, 0, N) { cin >> X[i] >> Y[i] >> P[i]; }

  init_dist();
  repe(i, 0, N) { ans[i] = INF; }

  for (ll bit = 0; bit < (1 << N); ++bit) {
    rep(i, 0, N) {
      distx[bit][i] = min(abs(X[i]), abs(Y[i]));
      disty[bit][i] = min(abs(X[i]), abs(Y[i]));
    }

    rep(i, 0, N) {
      if (bit & (1 << i)) {
        rep(j, 0, N) {
          chmin(distx[bit][j], abs(X[j] - X[i]));
          chmin(disty[bit][j], abs(Y[j] - Y[i]));
        }
      }
    }
  }

  /*
  for (ll bit = 0; bit < pow(3, N) + eps; ++bit) {
    ll b = bit;
    ll xx = 0;
    ll yy = 0;
    ll digit = 1;
    ll cnt = 0;
    rep(i, 0, N) {
      if (b % 3 == 1) {
        xx += digit;
        ++cnt;
      } else if (b % 3 == 2) {
        yy += digit;
        ++cnt;
      }
      digit *= 2;
      b /= 3;
    }

    ll score = 0;
    rep(i, 0, N) { score += min(distx[xx][i], disty[yy][i]) * P[i]; }
    chmin(ans[cnt], score);
  }
  */

  dfs(0, 0, 0, 0, 1);

  cout << ans[0] << "\n";
  repe(i, 1, N) {
    chmin(ans[i], ans[i - 1]);
    cout << ans[i] << "\n";
  }
}


Measured memory_bytes: 18996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
#define pb push_back

/*int pare(int en,int start,int par[])
{
	if(par[en]==start)
	{
		return en;
	}
	pare(par[en],start,par);
}*/


int main()
{
    int t=1;
	//scanf("%d",&t);
    while(t--)
    {
		ll h1,m1,h2,m2,k;
		cin >> h1 >> m1 >> h2 >> m2 >> k;
		ll mm1=(60*h1)+m1;
		ll mm2=(60*h2)+m2;
		cout << mm2-mm1-k << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <cstdio>
#include <cstdlib>

typedef long long int lld;
typedef unsigned long long int ulld;
const int mod = 1000000007;

using namespace std;

int main (void) {
	ios::sync_with_stdio (false);
	char c;
	cin >> c;
	cout << (char)(c + 1) << endl;
	return 0;
}

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

using namespace std;



int main()
{
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5])
        cout << "Yes";
    else
        cout << "No";
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct edge{
    int to,i;
};
vector<vector<edge>> e;
vector<bool> v,vis;
vector<int> ans;

bool rec(int i,int pa=-1){
    if(vis[i]) return false;
    vis[i]=true;
    bool la=true;
    for(auto&E:e[i]) if(E.to!=pa){
            la=false;
            if(rec(E.to,i)) ans.emplace_back(E.i),v[i]=!v[i];
        }
    return v[i];
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,m,f,l,r;
    in>>n>>m;
    vector<pair<int,bool>> ab(n);
    for(auto&p:ab){
        in>>p.first>>f;
        p.second=f;
    }
    sort(ab.begin(),ab.end());
    e.resize(n+1);
    map<pair<int,int>,bool> mp;
    Fr(i,m){
        in>>l>>r;
        l=lower_bound(ab.begin(),ab.end(),make_pair(l,false))-ab.begin();
        r=upper_bound(ab.begin(),ab.end(),make_pair(r,true))-ab.begin();
        if(l==r) continue;
        if(mp[make_pair(l,r)]) continue;
        mp[make_pair(l,r)]=true;
        e[l].push_back({r,i});
        e[r].push_back({l,i});
    }
    v.resize(n+1);
    v[0]=ab[0].second;
    fr(i,n-1) v[i+1]=ab[i].second^ab[i+1].second;
    vis.resize(n+1);
    rec(n);
    fr(i,n) if(rec(i)) return puts("-1"),0;
    sort(ans.begin(),ans.end());
    cout<<ans.size()<<endl;
    for(auto&i:ans) cout<<i<<" ";
    cout<<endl;
}


Measured memory_bytes: 28412
import java.io.*;
import java.util.*;

class Main {
    static Scanner scanner = new Scanner();
    static long mod = 1000000007;

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] a = new int[n];
        TreeSet<Integer> set = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (i <= k) {
                set.add(a[i]);
            }
        }
        int count = 0;
        int c = 0;
        for (int i = 1; i < n; i++) {
            if (a[i - 1] < a[i]) {
                c++;
            } else {
                if (c >= k - 1) {
                    count++;
                }
                c = 0;
            }
        }
        if (c >= k - 1) {
            count++;
        }
        if (count > 0) {
            count--;
        }
        if (n != k) {
            for (int i = k + 1; i <= n; i++) {
                if (set.first().equals(a[i - k - 1]) && set.last().equals(a[i - 1])) {
                    count++;
                }
                if (i < n) {
                    set.remove(a[i - k - 1]);
                    set.add(a[i]);
                }
            }
        }
        System.out.println(n - k + 1 - count);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 59256
N= int(input())
a_li = list(map(int,input().split()))
a_conv = []
for i in a_li:
    if 1 <= i <= 399:
        a_conv.append(1)
    elif 400 <= i <= 799:
        a_conv.append(2)
    elif 800 <= i <= 1199:
        a_conv.append(3)
    elif 1200 <= i <= 1599:
        a_conv.append(4)
    elif 1600 <= i <= 1999:
        a_conv.append(5)
    elif 2000 <= i <= 2399:
        a_conv.append(6)
    elif 2400 <= i <= 2799:
        a_conv.append(7)
    elif 2800 <= i <= 3199:
        a_conv.append(8)
    elif 3200 <= i:
        a_conv.append(9)
free = a_conv.count(9)
ans_min = 0
ans_max = 0
if free == len(a_conv):
    ans_min = 1
    ans_max = free
else:
    for i in range(1,9):
        if i in a_conv:
            ans_min += 1
    ans_max = ans_min + free
print(ans_min,ans_max)


Measured memory_bytes: 3064
/*
考虑一个很显然的O(nlogn)的做法
首先对所有线段按照右端点排序，然后按照右端点切

由于所有线段的值域为1 - n，我们可以对所有左端点，直接记录出右端点为位置
再扫一遍即可 
*/
#include<cstdio>
const int MAXN = 1e6 + 10;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
#define min(a, b) (a < b ? a : b)
char buf[(1 << 22)], *p1 = buf, *p2 = buf;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, M;
int r[MAXN];
int main() {
	N = read(); M = read();
	for(int i = 1; i <= N; i++) r[i] = N + 1;
	for(int i = 1; i <= M; i++) {
		int x = read(), y = read();
		r[x] = min(y, r[x]);
	}
	int cur = N + 1, ans = 0;
	for(int i = 1; i <= N; i++) {
		cur = min(cur, r[i]);
		if(i == cur) cur = r[i], ans++;
	}
	printf("%d", ans);
    return 0;
}
/*

*/

Measured memory_bytes: 4736
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }


int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, b;
	cin >> N;

	vector<int> B;
	B.reserve(N - 1);
	for(int i = 0; i < N - 1; i++) {
		cin >> b;
		B.push_back(b);
	}

	ll result = B[0];
	for(int i = 1; i < N - 1; i++) {
		result += min(B[i - 1], B[i]);
	}
	result += B[N - 2];
	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256