akhauriyash/Code-Regression huggingface dataset:
/*input
3 1
ABC
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define int long long 
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define FOR(i,n) for(int i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int power(int x, int y, int mod = 2e18)
{int ans = 1;x%=mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1 << "  ";
        __f(comma + 1, args...);
    }
#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) os << v[i] << " "; return os; } 
template <typename T> ostream& operator << (ostream& os, const set<T>& v) { for (auto it : v) os << it << " "; return os; } 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T, S>& v) { os << v.first << " " << v.second; return os; } 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << "\n"; return os; } 

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
int const MOD = 1e9+7;
int const inf = 2e18;
int const N = 2e5+10;

signed main() {
  IOS;
  
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  s[k-1] = s[k-1] - 'A' + 'a';
  cout << s << endl;

return 0;
}

Measured memory_bytes: 768
#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 <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

ll N,A,B,ans;

int main(){
  cin>>N>>A>>B;
  ll a=max(A,B),b=min(A,B);
  if((a-b)%2==0){
    ans=(a-b)/2;
  }else{
    ans=min(b+(a-b-1)/2,(N-a+1)+(a-b-1)/2);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

int main () {
	int n;
	scanf("%d",&n);
	int cnt[3]={0,0,0};
	for (int i=1;n>=i;i++) {
		int x;
		scanf("%d",&x);
		if (x%4==0) cnt[2]++;
		else if (x%2==1) cnt[1]++;
		else cnt[0]++;
	}
	if (cnt[2] + 1 == cnt[1] & cnt[0]==0) puts("Yes");
	else if (cnt[2] + 1 > cnt[1]) puts("Yes");
	else puts("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair

typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//find_by_order(x) -> returns an iterator to the element at a given position
//order_of_key(x) -> returns the position of a given element

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;

const int mod = (int)1e9 + 7;
const int MAXN = 2e5+12;
//indexed_set s;

int n,m;
ll a[MAXN], b[MAXN], k;
ll firstPref[MAXN], secondPref[MAXN];

int main() {

    NoType;

    cin >> n >> m >> k;
    firstPref[0] = 0;
    secondPref[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        firstPref[i] = firstPref[i - 1] + a[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        secondPref[i] = secondPref[i - 1] + b[i];
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        int l = 1;
        int r = m;
        if (firstPref[i] > k) break;
        int cur = 0;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (firstPref[i] + secondPref[mid] <= k) cur = mid, l = mid + 1;
            else if (firstPref[i] + secondPref[mid] > k) r = mid - 1;
        }
        ans = max(ans, i + cur);
    }

    cout << ans;

return 0;
}


Measured memory_bytes: 9856
n, m = map(int, input().split())
M = 1000000007
dp = [0]*(n+1)
dp[0] = 1
i = 1
for _ in range(m):
  a = int(input())
  while i < a:
    dp[i] += dp[i-1]
    dp[i] %= M
    if i >= 2:
      dp[i] += dp[i-2]
      dp[i] %= M
    i += 1
  i += 1
  
while i <= n:
  dp[i] += dp[i-1]
  dp[i] %= M
  if i >= 2:
    dp[i] += dp[i-2]
    dp[i] %= M
  i += 1
  
print(dp[n])

Measured memory_bytes: 6888
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<utility>
#include<iostream>
#include<vector>
#include<map>
#include<queue>
using namespace std;
const int maxn = 2e5 + 233;
char s[maxn];
int pre[maxn],ans=1<<30;
int main()
{
	int n;cin>>n;
	scanf("%s",s+1);
	pre[0]= 0;
	for(int i=1;i<=n;i++){
		pre[i] = pre[i-1];
		if(s[i]=='.')pre[i]++;
	}
	for(int i=0;i<=n;i++){
		int tmp = i-pre[i]+pre[n]-pre[i];
		ans = min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 1280
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;

int main(void)
{
	int i,j,a,b,n,x[41],y[41];
	int dp[17][17];
	while(1) {
		scanf("%d %d",&a,&b);
		if(a==0 && b==0) break;
		scanf("%d",&n);	
		for(i=1;i<=b;i++) {
			for(j=1;j<=a;j++) {
				dp[i][j]=0;
			}
		}
		for(i=1;i<=n;i++) {
			scanf("%d %d",&x[i],&y[i]);
			dp[y[i]][x[i]]=-1;
		}
		dp[1][1]=1;
		for(i=1;i<=b;i++) {
			for(j=1;j<=a;j++) {
				if(dp[i][j]!=0 && dp[i][j]!=-1) {
					if(dp[i+1][j]!=-1 && i+1<=b)
						dp[i+1][j]+=dp[i][j];
					if(dp[i][j+1]!=-1 && j+1<=a)
						dp[i][j+1]+=dp[i][j];
				}
			}
		}
/**///	for(i=1;i<=b;i++) {
/**///		for(j=1;j<=a;j++) {
/**///			printf("%5d",dp[i][j]);
/**///		}
/**///		printf("\n");
/**///	}
/**///	printf("\n");
/**///	for(i=b;i>=1;i--) {
/**///		for(j=1;j<=a;j++) {
/**///			printf("%5d",dp[i][j]);
/**///		}
/**///		printf("\n");
/**///	}
		printf("%d\n",dp[b][a]);
	}
	return 0;
}
/*	while(1) {
		scanf("%d %d",&a,&b);
		if(a==0 && b==0) break;
		scanf("%d",&n);	
		for(i=0;i<=b;i++) {
			for(j=0;j<=a;j++) {
				dp[i][j]=0;
			}
		}
		for(i=0;i<n;i++) {
			scanf("%d %d",&x[i],&y[i]);
			dp[y[i]][x[i]]=-1;
		}
		dp[1][1]=1;
		for(i=1;i<=b;i++) {
			for(j=1;j<=a;j++) {
				if(dp[i][j]!=-1) {
					if(dp[i-1][j]==-1) dp[i][j]=dp[i][j-1];
					if(dp[i][j-1]==-1) dp[i][j]=dp[i-1][j];
					if(dp[i-1][j]==-1 && dp[i][j-1]==-1)dp[i][j]=0;
					else dp[i][j]=dp[i-1][j]+dp[i][j-1];
				}
			}
		}
		for(i=0;i<=b;i++) {
			for(j=0;j<=a;j++) {
				printf("%3d",dp[i][j]);
			}
			printf("\n");
		}
		printf("\n");
		for(i=b;i>=0;i--) {
			for(j=0;j<=a;j++) {
				printf("%3d",dp[i][j]);
			}
			printf("\n");
		}
		printf("%d\n",dp[b][a]);
		break;
		
	}
	return 0;
}*/
		

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

const int mod = 1e9+7;
ll dp[2005][2005];
ll sum[2005][2005];

int main() {
    int n, m; cin >> n >> m;
    vector<int> s(n+1), t(m+1);
    rep(i,n) cin >> s[i+1];
    rep(i,m) cin >> t[i+1];

    ll ans2 = 0;
    REP(i,1,n+1)REP(j,1,m+1) {
        if (s[i]==t[j]) {
            dp[i][j] = sum[i-1][j-1]+1;
            dp[i][j] %= mod;
        }
        sum[i][j] = sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j]+mod;
        sum[i][j] %= mod;
    }

    ll ans = 1+sum[n][m];
    ans %= mod;
    cout << ans << endl;

}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9+7

using namespace std;
bool infected[20000];

struct logs{
  int t, f, d;
  logs(int t, int f, int d) : t(t), f(f), d(d) {}
  logs() : t(INF), f(0), d(0) {}
  bool operator<(logs &x)const{
    if(t < x.t) return true;
    return false;
  }
};

array<logs, 20000> data;

int main(){
  int n, m;
  while(cin >> n >> m and n + m){
    memset(infected, 0, sizeof(infected));
    REP(i, 20000){
      data[i] = logs();
    }
    REP(i, m){
      int t, s, d;
      cin >> t >> s >> d; s--; d--;
      data[i] = logs(t, s, d);
    }
    sort(ALL(data));
    infected[0] = true;
    REP(i, m){
      if(infected[data[i].f]) infected[data[i].d] = true;
      else if(infected[data[i].d]) infected[data[i].f] = false;
    }
    int res = 0;
    REP(i, n) if(infected[i]) res++;
    cout << res << endl;
  }
}

Measured memory_bytes: 3344
#include "stdio.h"

int main()
{
	int age;

	scanf("%d", &age);

	if ((age == 7) ||
		(age == 5) ||
		(age == 3))
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}

	return 0;
}

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

using namespace std;

int main(){
 int data[11]={};
 for(int i=0;i<3;i++){
  int temp;
  cin >> temp;
  data[temp]++;
 }
 if(data[5]==2&&data[7]==1){
  cout << "YES" << endl;
 }else{
  cout << "NO" << endl;
 }
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool solve(string a, string b){
    for(int i = 0; i < max(a.length(), b.length())-1; i++) {
    if(a[i] != b[i]) return false;
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string a, b;
    cin >> a >> b;
    if(solve(a, b)) cout << "Yes";
    else cout << "No";
    return 0;
}


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

using namespace std;

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

	int N, R;
	cin >> N >> R;

	if (N>=10) {
		cout << R << '\n';
		return 0;
	}

	cout << R + 100 * (10 - N) << '\n';
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

type request struct {
	a, b int
}

type requests []request

func (e requests) Len() int {
	return len(e)
}

func (e requests) Swap(i, j int) {
	e[i], e[j] = e[j], e[i]
}

func (e requests) Less(i, j int) bool {
	return e[i].b < e[j].b
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	reqs := make(requests, m)
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		r := request{a, b}
		reqs[i] = r
	}

	// sort.Slice(reqs, func(i, j int) bool { return requests[i].b < requests[j].b })
	sort.Sort(reqs)
	ans := 0
	end := 0
	for i := range reqs {
		if reqs[i].a >= end {
			ans++
			end = reqs[i].b
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ep emplace_back
#define st first
#define sc second

using namespace std;

const ll mod = 998244353;
const int e = 1e6 + 69;
const int base = 311;

// dung igt thay cho gt luc tinh giai thua
// 3
// cach tao hoan vi tu n so : n*(n+1)/2;

ll a[e];
ll dp[e][2];

int main()
{
    int n;
    cin >> n;
    ll dem = 0;
    ll ans = 0;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
        if(a[i] < 0)
        {
            a[i]*=-1;
            dem++;
        }
        ans += a[i];
    }
    sort(a+1, a+n+1);
    if(dem % 2 == 0) cout << ans;
    else
    {
        cout << ans - a[1] * 2;
    }
}


Measured memory_bytes: 4352
use proconio::input;

fn main() {
    input! {
        n: usize,
    }

    let s : String;
    match n % 10 {
        2 | 4 | 5 | 7 | 9 => {s = "hon".to_string()},
        0 | 1 | 6 | 8 => {s = "pon".to_string()}
        _ => { s = "bon".to_string()}
    }

    println!("{}", s);
}


Measured memory_bytes: 2160
#include <iostream>
#include <string>
using namespace std;
string sr;
int a[4];
string s[4] = { "AC","WA","TLE","RE" };
int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		cin >> sr;
		int i;
		for (i = 0; i < 4; i++)
		{
			if (sr == s[i])
				a[i]++;
		}
	}
	int i;
	for (i = 0; i < 4; i++)
	{
		cout << s[i] << " x " << a[i] << '\n';
	}
}

Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n;
	while( cin >> n ){
		int s = 512;
		stack<int> st;
		while( n != 0 ){
			if( n - s >= 0 ){
				st.push(s);
				n -= s;
				s /= 2;
			}
			else{
				s /= 2;
			}

		}

		while( !st.empty() ){	
			cout << st.top();
			if( st.size() == 1 )
				cout << endl;
			else
				cout << " ";
			st.pop();
		}
	}
	ret 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(std::string S, std::string T){
    int answer = 0;
    rep(i,0,S.size()) if(S[i] != T[i]) answer++;
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 4076
#include<bits/stdc++.h>
#define P 3.1415926535897932384626433832
using namespace std;

void fun()
{
    long double cir,rad;
    cin>>rad;

    cir=2*P*rad;

    cout<<setprecision(20)<<fixed<<cir<<endl;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    fun();
    return 0;
}


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

struct job {
    string name;
    int rem;
};

int main() {
    int n, quantum;
    cin >> n >> quantum;
    queue<job> que;
    for (int i = 0; i < n; i++) {
        string name;
        int rem;
        cin >> name >> rem;
        que.push({name, rem});
    }
    int elapsed = 0;
    while (que.size()) {
        job top = que.front();
        que.pop();
        if (top.rem <= quantum) {
            cout << top.name << " " << elapsed + top.rem << endl;
            elapsed += top.rem;
        } else {
            top.rem -= quantum;
            que.push(top);
            elapsed += quantum;
        }
    }
}


Measured memory_bytes: 6284
def main():
    _ = int(input())
    S = input()
    ri = S.count("R")  # 右側の換えるべき個数
    le = 0
    ans = max(ri, le)
    for s in S:
        if s == "R":
            ri -= 1
        else:
            le += 1
        ans = min(ans, max(ri, le))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 72732
# 素数を３からN個
N = int(input())

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i] and i%5 == 1]

A = primes(5000) # Aの長さは55を超える
A.pop(0)
print(*A[:N])


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<algorithm>
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<<#X<<": "<<X<<" ";
#define ARDEB(i,X) cout<<#X<<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(X) {}
#define END {}
#endif
using namespace std;
int main(){
	/*int n,a[2001];
	int m,c[1001];
	cin>>n>>m;
	for(int i=0;i<n*2;i++)a[i]=i+1;
	/*for(int i=0;i<m;i++){
		cin>>c[i];
		if(c[i]==0){
			
			}
		}
	}
	for(int j=1;j<n;j++){
		swap(a[j],a[n+j-1]);
		for(int j=0;j<n*2;j++)cout<<a[j]<<" ";
		cout<<endl;
		swap(a[n+j-1],a[j+1]);
		for(int j=0;j<n*2;j++)cout<<a[j]<<" ";
		cout<<endl;
		swap(a[j+2],a[j+3]);
		for(int j=0;j<n*2;j++)cout<<a[j]<<" ";
		cout<<endl;
	}
	for(int j=0;j<n*2;j++)cout<<a[j]<<" ";*/
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[0]+a[1]<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
plus = 0
minus = 0
cur = float('inf')
S = 0
for i in range(N):
  if A[i] > 0:
    plus += 1
    S += A[i]
    if A[i] < cur:
      cur = A[i]
  elif A[i] < 0:
    minus += 1
    S += -A[i]
    if -A[i] <= cur:
      cur = -A[i]
  else:
    cur = A[i]
if minus%2 == 0:
  print(S)
else:
  if cur != float('inf'):
    print(S-2*cur)
  else:
    print(S)

Measured memory_bytes: 14492
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){
    
    // 1. 入力情報取得.
    LL N;
    scanf("%lld", &N);
    
    // 2. M1 + ... + MN の 最大値 を 計算.
    // -> 最大値になると思われるパターン.
    // 1 を 2 で 割った余り     … 1
    // 2 を 3 で 割った余り     … 2
    // ...
    // N - 1 を N で 割った余り … N - 1
    // N     を 1 で 割った余り … 0
    LL ans = (N - 1) * N / 2;
    
    // 3. 出力 ～ 後処理.
    printf("%lld", ans);
    return 0;
    
}

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

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

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> vals;
  int tmp = 1;
  REP(i, 10) {
    tmp *= 2;
    vals.push_back(tmp);}
  int ans = n;
  REP(i, 10){
    if (vals[9-i] <= n){
      ans = vals[9-i];
      cout << ans << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}



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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int ls[30][200010];

int main()
{
    int n,cc,ans=0;
    cin >> n >> cc;
    vector<int> s(n),t(n),c(n);
    m0(ls);
    for(int i = 0; i < n; i++)
    {
        cin>>s[i]>>t[i]>>c[i];
        c[i]--;
        ls[c[i]][s[i]*2]++;
        ls[c[i]][t[i]*2+1]--;
    }
    for(int i = 1; i < 200005; i++)
    {
        for(int ccc = 0; ccc < 30; ccc++)
        {
            ls[ccc][i]=ls[ccc][i-1]+ls[ccc][i];
        }
    }
    for(int i = 2; i < 200005; i+=2)
    {
        for(int ccc = 0; ccc < 30; ccc++)
        {
            if(ls[ccc][i]>0)
            {
                ls[ccc][i-1]++;
            }
        }
    }
    
    for(int i = 0; i < 200005; i++)
    {
        int tmp=0;
        for(int ccc = 0; ccc < 30; ccc++)
        {
            if(ls[ccc][i]>0)
            {
                tmp++;
            } 
        }
        ans=max(ans,tmp);
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 24832
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    vector<int64_t> h(n);
    for (auto&& hh : h) {
        cin >> hh;
    }

    vector<int64_t> cost(n);
    for (auto i : irange(1L, n)) {
        cost[i] = cost[i - 1] + abs(h[i] - h[i - 1]);

        if (i >= 2) {
            cost[i] = min(cost[i], cost[i - 2] + abs(h[i] - h[i - 2]));
        }
    }

    cout << cost[n - 1] << endl;
}

Measured memory_bytes: 1920
def solve(h, w, grid):
    dp = [[0]*w for i in range(h)]
    max_dp = 0

    for i in range(h):
        for j in range(w):
            if grid[i][j] == 1:
                dp[i][j] = 0
            else:
                if i - 1 < 0 or j - 1 < 0:
                    dp[i][j] = 1
                else:
                    dp[i][j] = min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1]) + 1
            max_dp = max(max_dp, dp[i][j])

    return max_dp * max_dp

h, w = map(int, input().split())
grid = [list(map(int, input().split())) for i in range(h)]
print(solve(h, w, grid))


Measured memory_bytes: 55176
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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; }

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll n;
    cin>>n;
    bool a[100010]={};
    rep(i,100){
        rep(j,100){
            a[4*i+7*j]=true;
        }
    }
    if(a[n]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    solve();

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

ll PowMod(ll N,ll P,ll M){
    ll ans = 1;
    while(P >= 1){
        if(P % 2)ans = ans * N % M;
        N = N*N %M;
        P /= 2;
    }
    ans %= M;
    return ans;
}

int main(){
    string S;
    cin>>S;
    ll N =S.size();
    vector <ll> a(N);
    vector <ll> d(N+1);
    map<ll,ll> m;
    ll ans = 0;
    for(ll i =N-1;i >= 0; i--){
        d[i] = (d[i+1]+ll(S[i]-'0')*PowMod(10,N-i-1,2019))%2019;
        m[d[i]]++;
        //cout<<d[i]<<endl;
    }
    rep(i,0,2019){
        if(i == 0)ans += m[i] * (m[i]+1) / 2;
        else ans += m[i] * (m[i]-1) / 2;
        //if(m[i]>=1)cout<<i<<" "<<m[i]<<ans<<endl;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6828
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main(){
    ll x;
    cin >> x;
  	if(x == 0) cout << "1" << endl;
	if(x == 1) cout << "0" << endl;
    return 0;
}

Measured memory_bytes: 3632
int z[17][17];
main(a,b,n,i,j){
  for(;scanf("%d%d",&a,&b),a;printf("%d\n",z[a][b])){
    memset(z,0,sizeof(z));
    for(scanf("%d",&n);n;n--)
      scanf("%d%d",&i,&j),z[i][j]=-1;
    z[1][1]=1;
    for(i=1;i<=a;i++)
      for(j=1;j<=b;j++)
        if((i|j)-1&&~z[i][j])
          z[i][j]=(~z[i-1][j]?z[i-1][j]:0)+(~z[i][j-1]?z[i][j-1]:0);
  }
  return 0;
}

Measured memory_bytes: 596
#include<stdio.h>

int main() {
  int n,i,j;
  int Adj[100][100];
  int u,k,v;
  
  scanf("%d", &n);
  
  for( i = 0 ; i  < n ; i++ ) {
    for( j = 0 ; j < n ; j++ ) {
      Adj[i][j] = 0;
    }
  }
 
  for( i = 0 ;  i < n ; i++ ) {
    scanf("%d%d", &u, &k);
    for( j = 0 ; j < k ; j++ ) {
      scanf("%d", &v);
      Adj[i][v-1] = 1;
    }
    k = 0;
  }

  for( i = 0 ; i < n ; i++ ) {
    for( j = 0 ; j < n ; j++ ) {
      printf("%d",Adj[i][j]);
      if(j != n-1)printf(" ");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 636
// https://atcoder.jp/contests/abc167/tasks/abc167_f

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N;
  cin >> N;

  struct Diff {
    ll min_h, h_diff;
  };

  V<Diff> ls, rs;

  string Yes = "Yes";
  string No = "No";

  rep(i, N) {
    string s;
    cin >> s;

    ll h_diff = 0;
    ll min_h = 0;

    for (char c : s) {
      if (c == '(') {
        ++h_diff;
      } else {
        --h_diff;
      }

      chmin(min_h, h_diff);
    }

    if (h_diff >= 0) {
      ls.push_back({min_h, h_diff});
    } else {
      rs.push_back({min_h - h_diff, -h_diff});
    }
  }

  {
    ll l_sum = 0;
    ll r_sum = 0;

    for (auto l : ls) l_sum += l.h_diff;
    for (auto r : rs) r_sum += r.h_diff;

    if (l_sum != r_sum) drop(No);
  }

  auto is_ok_seq = [](V<Diff>& seq) -> bool {
    sort(all(seq), [](Diff a, Diff b) { return a.min_h > b.min_h; });

    ll cur = 0;

    for (auto d : seq) {
      unless(cur + d.min_h >= 0) return false;
      cur += d.h_diff;
    }

    return true;
  };

  unless(is_ok_seq(ls) && is_ok_seq(rs)) drop(No);
  drop(Yes);
}


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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

int main(){
	string a, b;
	cin >> a;
	cin >> b;
	b.pop_back();
	if(a == b){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3624
n=int(input())
a=list(map(int,input().split()))
if n==1:
    print(1)
else:
    u=a[0]<=a[1]
    d=a[0]>=a[1]
    res=0
    for i in range(2,n):
        u=u and a[i-1]<=a[i]
        d=d and a[i-1]>=a[i]
        #print(i,u,d)
        if not any([u,d]):
            res+=1
            u=True
            d=True
    print(res+1)
    

Measured memory_bytes: 62704
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        if (a + b == 15) {
            System.out.println("+");
        } else if (a * b == 15) {
            System.out.println("*");
        } else {
            System.out.println("x");
        }
    }
}


Measured memory_bytes: 21204
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int ans = K;
    rep(i, N - 1) {
        ans *= K - 1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
int main(void)
{
  int A, B, C, D;
  int flag = 0;
  int turn = 0;
  scanf("%d%d%d%d", &A, &B, &C, &D);
  while(flag == 0){
    if(turn % 2 == 0){
      C = C-B;
      turn = 1;
    }
    else{
      A = A-D;
      turn = 0;
    }
    if(A<=0 || C<=0)
      flag = 1;
  }
  
  if(A<=0)
    printf("No\n");
  if(C<=0)
    printf("Yes\n");
      
  return 0;
}

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

class Hoge{
 int& n_count;
 set<long> S;
public:
 Hoge(int& n_count, set<long> S) : n_count(n_count), S(S){}
 void operator()(int x){
  n_count += count(S.begin(), S.end(), x);
 }
};

int main(){
 int n = 0;
 cin >> n;
 set<long> S;
 for(int i = 0; i < n; i++){
  long buf = 0;
  cin >> buf;
  S.insert(buf);
 }

 int q = 0;
 cin >> q;
 set<long> T;
 for(int i = 0; i < q; i++){
  long buf = 0;
  cin >> buf;
  T.insert(buf);
 }

 int n_count = 0;
 for_each(T.begin(), T.end(), Hoge(n_count,S)); 
 
 cout << n_count << '\n'; 

 return 0;
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()



struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    string s;
    i64 q;
    cin >> s >> q;
    list<char> li;
    rep(i, s.length()) li.push_back(s[i]);
    bool flag = true;
    rep(i, q){
        i64 t;
        cin >> t;
        if(t == 1){
            flag = !flag;
        }else{
            i64 f;
            char c;
            cin >> f >> c;
            if(f == 1){
                if(flag) li.push_front(c);
                else li.push_back(c);
            }else{
                if(flag) li.push_back(c);
                else li.push_front(c);
            }
        }
    }
    if(!flag) reverse(li.begin(), li.end());
    for_each(li.cbegin(), li.cend(), [](char ch){
        cout << ch;
    });
    cout << endl;
    return 0;
}


Measured memory_bytes: 10064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  
  if(c=='a'||c=='e'||c=='i'||c=='u'||c=='o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

const MOD: usize = 1_000_000_007;

fn main() {
    let n: usize = read();
    let k: usize = read();
    let a: Vec<usize> = (0..n).map(|_| read::<usize>()).collect();
    
    let mut ans: usize = 0;
    for i in 0..n {
        for j in i+1..n {
            if a[i] > a[j] {
                ans += 1;
                ans %= MOD;
            }
        }
    }
    ans *= k;
    ans %= MOD;

    let mut cnt: usize = 0;
    for i in 0..n {
        for j in i+1..n {
            if a[i] != a[j] {
                cnt += 1;
            }
        }
    }
    let mut po = k * (k-1) / 2;
    po %= MOD;
    cnt *= po;
    cnt %= MOD;
    println!("{}", (ans + cnt) % MOD);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

int main() {
    long a, b, k, ans = 0;
    string s, t;
    cin >> a >> b >> k;
    if (a + b <= k) {
        cout << 0 << " " << 0 << endl;
        return 0;
    }
    if (a <= k) {
        cout << 0 << " ";
    } else {
        cout << a - k << " " << b << endl;
        return 0;
    }
    cout << a + b - k << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;

	char buf[L], *S , *T, c;

	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}

	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}

	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;

		if(!a)*--outs = '0';
		else
			while(a)
				*--outs = (a % 10) + 48, a /= 10;

		if(x)
			*--outs = x;

		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

const int MAXN = 100010;
const int MOD = 1000000007;
const f80 MI = f80(1)/MOD;
const int INF = 1000000000;

ll calc(ll n) // 0^...^n-1
{
	if (n <= 0) return 0;
	ll ret = 0;
	for (int k = 0; k <= 60; ++ k)
	{
		ll all = 1LL<<(k+1);
		ll half = all/2;
		ll cur = n/all;
		ll ans = 0;
		
		if (cur%2 == 1 && k == 0) ans ^= 1;
		
		cur = n%all;
		if (cur >= half+1 && (cur-half)%2 == 1) ans ^= 1;
		
		ret |= ans<<k;
	}
	return ret;
}

int main()
{
	
	ll n, m;
	cin >> n >> m;
	cout << (calc(m+1)^calc(n)) << endl;
	
	return 0;
}


Measured memory_bytes: 256
s = input()
t = input()

ds = {}
dt = {}
ls = []
lt = []

for ks,kt in zip(list(s),list(t)):
    if ks not in ds:
        ds[ks] = 1
    else:
        ds[ks] += 1
    if kt not in dt:
        dt[kt] = 1
    else:
        dt[kt] += 1

for ks in ds: ls.append(ds[ks])
for kt in dt: lt.append(dt[kt])

ls.sort()
lt.sort()

if ls == lt:
    ans = "Yes"
else:
    ans = "No"

print(ans)


Measured memory_bytes: 6704
#include<cstdio>
using namespace std;
#define N 16400
#define M 204
#define mod 998244353
int dp[M][N],n,m,fr[N],ifr[N],rev[N],a[N],b[N],ntt[N];
int pw(int a,int p){int as=1;while(p){if(p&1)as=1ll*as*a%mod;a=1ll*a*a%mod;p>>=1;}return as;}
int c(int a,int b){if(a<b)return 0;return 1ll*fr[a]*ifr[b]%mod*ifr[a-b]%mod;}
void dft(int s,int *a,int t)
{
	for(int i=0;i<s;i++)rev[i]=(rev[i>>1]>>1)|(i&1?s>>1:0),ntt[rev[i]]=a[i];
	for(int i=2;i<=s;i<<=1)
	{
		int st=pw(3,(mod-1)/i);
		if(t==-1)st=pw(st,mod-2);
		for(int j=0;j<s;j+=i)
		for(int k=j,t=1;k<j+(i>>1);k++,t=1ll*t*st%mod)
		{
			int v1=ntt[k],v2=1ll*ntt[k+(i>>1)]*t%mod;
			ntt[k]=(v1+v2)%mod;ntt[k+(i>>1)]=(v1-v2+mod)%mod;
		}
	}
	int inv=t==-1?pw(s,mod-2):1;
	for(int i=0;i<s;i++)a[i]=1ll*ntt[i]*inv%mod;
}
int main()
{
	scanf("%d%d",&n,&m);
	dp[0][0]=1;
	fr[0]=ifr[0]=1;for(int i=1;i<=8020;i++)fr[i]=1ll*fr[i-1]*i%mod,ifr[i]=pw(fr[i],mod-2);
	for(int i=1;i<=m;i++)
	{
		int l=1;while(l<=n*2)l<<=1;for(int j=0;j<l;j++)a[j]=b[j]=0;
		for(int j=0;j<=n;j++)a[j]=1ll*dp[i-1][j]*ifr[j]%mod;
		for(int j=1;j<=n;j++)b[j]=ifr[j+2];
		dft(l,a,1);dft(l,b,1);for(int j=0;j<l;j++)a[j]=1ll*a[j]*b[j]%mod;dft(l,a,-1);
		for(int j=0;j<=n;j++)dp[i][j]=(1ll*a[j]*fr[j+2]+1ll*(1ll*j*(j-1)%mod*499122177%mod+j+1)%mod*dp[i-1][j])%mod;
	}
	int as=0;
	for(int j=0;j<=n;j++)as=(as+1ll*dp[m][j]*c(n,j))%mod;
	printf("%d\n",as);
}

Measured memory_bytes: 12160
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <fstream>
#include <stdlib.h>  

using namespace std;

#define ll long long 
vector< vector<int> > vv;
vector<int> h;
string a, b;


signed  main()
{
	int n, m;
	cin >> n >>m;
	vv.resize(n);
	h.resize(n);
	for (int i = 0; i < m; i++)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		vv[a].push_back(b);
		h[b]++;
	}
	queue<pair<int,int> > q;
	for (int i = 0; i < h.size(); i++)
		if (h[i] == 0)
			q.push({ i,0 });
	int ans = 0;
	while (q.size())
	{
		int v = q.front().first;
		int p = q.front().second;
		ans = max(ans, p);
		q.pop();
		for (int i = 0; i < vv[v].size(); i++)
		{
			int t = vv[v][i];
			h[t]--;
			if (h[t] == 0)
				q.push({ t,p + 1 });
		}
	
	}
	cout << ans;
	cin >> ans;

 
}

Measured memory_bytes: 6144
#include <iostream>
#include <array>
//#include <fstream>
  
int main(){
    const int max_sum = 20;
    const int min_sum = 0;
    const int max_number = 100;
    int N;
    //std::ifstream ifs("557.txt");
      
    while(std::cin >> N){
        //数列を保存
        std::array<int, max_number> numbers;
        //count[i][j]:i番目までの計算でjを作ることのできるパターンを保存
        std::array<std::array<long long int, max_sum + 1>, max_number> count;
        
        for(int i = 0; i < N; ++i){
            //ifs >> numbers[i];
            std::cin >> numbers[i];
        }
        for(int i = 0; i < max_number; ++i){
            count[i].fill(0);
        }
          
        count[0][numbers[0]] = 1;
        for(int i = 1; i < N; ++i){
            for(int j = 0; j <= max_sum; ++j){
                if(j + numbers[i] <= max_sum){
                    count[i][j + numbers[i]] += count[i - 1][j];
                }
                if(j - numbers[i] >= min_sum){
                    count[i][j - numbers[i]] += count[i - 1][j];
                }
            }
        }
        std::cout << count[N - 2][numbers[N - 1]] << std::endl;
    }
      
    //ifs.close();
    return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <map>
#include <queue>
#include <tuple>

using namespace std;

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


int main(){
    int H,W;
    cin >> H >> W;
    vector<vector <char> > tile(H+2,vector<char>(W+2,'#'));
    int ans=0;
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            cin >> tile[i][j];
            if(tile[i][j]=='.') ans++;
        }
    }

    
    queue<P> que;
    que.push(P(1,1,1));
    int inf=1e9;
    vector<vector <int> > out(H+2,vector<int>(W+2,inf));
    while(!que.empty()){
        P now=que.front();que.pop();

        int h=get<0>(now),w=get<1>(now),d=get<2>(now);
        if(out[h][w]<=d) continue;
        out[h][w]=d;
        if(tile[h+1][w]=='.') que.push(P(h+1,w,d+1));
        if(tile[h][w+1]=='.') que.push(P(h,w+1,d+1));
        if(tile[h-1][w]=='.') que.push(P(h-1,w,d+1));
        if(tile[h][w-1]=='.') que.push(P(h,w-1,d+1));
    }
    
    if(out[H][W]==inf) ans=-1;
    else ans-=out[H][W];

    cout << ans << endl;




    return 0;
}

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

int N;
typedef pair<long long, int> P;
P M[1 << 18][2];
long long R[1 << 18];

void update(int i, int j) {
  P s[4] = {
    M[i][0], M[i][1], M[j][0], M[j][1]
  };
  sort(s, s + 4, greater<P>());
  M[i][0] = s[0];
  M[i][1] = s[1].second != s[0].second ? s[1] : s[2];
}

int main() {
  cin >> N;
  for(int i = 0; i < (1 << N); ++i) {
    long long a; cin >> a; M[i][0] = {a, i};
    for(int b = 0; b < N; ++b) {
      if(i & (1 << b)) {
        update(i, i & ~(1 << b));
      }
    }
    R[i] = M[i][0].first + M[i][1].first;
  }
  for(int i = 1; i < (1 << N); ++i) {
    R[i] = max(R[i], R[i - 1]);
    cout << R[i] << endl;
  }
  return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var line1 = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        long N = line1[0];
        long D = line1[1];

        var d = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

        long Q = long.Parse(Console.ReadLine());

        var q = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

        long minItazuraable = 1;
        long[] minItazuraableArray = new long[d.Length + 1];
        minItazuraableArray[d.Length] = 1;

        for(long i = 0; i < d.Length; i++)
        {
            var item = d[d.Length - i - 1];  // reverse 

            if (item / 2 >= minItazuraable)
            {
                // no change
            }
            else
            {
                minItazuraable += item;
            }

            minItazuraableArray[d.Length - i - 1] = minItazuraable;
        }

        //Console.WriteLine(String.Join(", ", minItazuraableArray));

        // aliceの目的地からの距離

        long[] aliceDistance = new long[d.Length + 1];
        aliceDistance[0] = D;

        for (long i = 0; i < d.Length; i++)
        {
            aliceDistance[i + 1] = Math.Min(Math.Abs(aliceDistance[i] - d[i]), aliceDistance[i]);
        }

        //Console.WriteLine(String.Join(", ", aliceDistance));

        foreach (var qi in q) { 
            Console.WriteLine(minItazuraableArray[qi + 1 - 1] <= aliceDistance[qi - 1] ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 92124