akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string N;
	int cnt = 0;
	bool ans = false;

	cin >> N;
	rep(i, 3) {
		if (N[i] == N[i + 1]) cnt++;
		else cnt = 0;

		if (cnt >= 2) {
			ans = true;
			break;
		}
	}

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] age){
		Scanner imput = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		while(true){
			String x = imput.nextLine();
			String[] arrayimput = x.split(" ");
			int a = Integer.parseInt(arrayimput[0]);
			int b = Integer.parseInt(arrayimput[1]);
			int c;
			if(a == 0 & b == 0) break;
			if(a > b){
				c = a;
				a = b;
				b = c;
			}
			sb.append(Integer.toString(a)).append(" ").append(Integer.toString(b)).append("\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 34768
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int lcs (string x, string y) {

    int m, n, c[1001][1001], i, j, maxl = 0;

    m = x.size();
    n = y.size();

    x = ' ' + x;
    y= ' ' + y;

    for (i = 0; i <= m; i++) {
        c[i][0] = 0;
    }
    for (j = 1; j <= n; j++) {
        c[0][j] = 0;
    }

    for (i = 1; i <= m; i++) {
            for (j = 1; j <= n; j++) {

                if (x[i] == y[j]) {
                    c[i][j] = c[i - 1][j - 1] + 1;
                } else {
                    c[i][j] = max (c[i - 1][j], c[i][j - 1]);
                }

                maxl = max (maxl, c[i][j]);

            }
    }

    return maxl;

}



int main () {

    int N, i;
    string x, y;

    cin >> N;

    for (i = 0; i < N; i++) {
        cin >> x >> y;
        cout << lcs (x, y) << endl;

    }

    return 0;

}

    

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

int main() {
	int N, cnt = 1;
	string S;
	cin >> N >> S;
	for (int i = 1; i < S.length(); i++) {
		if (S.substr(i, 1) != S.substr(i - 1, 1)) ++cnt;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 512
N = int(input())
a = list(map(int, input().split()))

h = N // 2 + N % 2
ans = [-1] * N

for i in range(h, N):
    ans[i] = a[i]
for i in range(h - 1, -1, -1):
    ans[i] = ((sum(ans[i::i + 1]) + 1) % 2) ^ a[i]

print(sum(ans))
for i, x in enumerate(ans):
    if x == 1:
        print(i+1)


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

using namespace std;

typedef long long int lli;

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

    int n, m;
    priority_queue<pair<int, pair<int, int>>> qu;

    cin >> n >> m;
    int a, b;
    for (int i=0; i<m; i++) {
        cin >> a >> b;
        qu.push(make_pair(-a, make_pair(-b, 1)));
        qu.push(make_pair(-b, make_pair(-a, 0)));
    }

    vector<int> table(100001, 0);
    int ans = 0;
    while (!qu.empty()) {
        auto q = qu.top();
        qu.pop();
        if (q.second.second == 1) {
            table[-q.first] = 1;
        }
        else {
            if (table[-q.second.first] == 1) {
                ans++;
                table = vector<int>(100001, 0);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4980
#include<bits/stdc++.h>
typedef long long ll;
const int N=45;
ll f[N][N][N],ans;
int n,i,j,k,l,r,p,q,l2,r2;
char c[N][N];
int main(){
	scanf("%d",&n);for(i=1;i<=n*2;++i)scanf("%s",c[i]+1),f[i][i][i]=1;
	for(i=2;i<n*2;i+=2)for(j=1;j+i<=n*2;++j){
		l=j;r=j+i;
		for(l2=l;l2+1<r;++l2)for(r2=l2+2;r2<=r;++r2){
			ll s=0;
			for(p=l;p<=l2;++p)for(q=r2;q<=r;++q)if(c[p][q]=='1')s+=f[l][l2][p]*f[r2][r][q];
			for(p=l2+1;p<r2;++p)f[l][r][p]+=s*f[l2+1][r2-1][p];
		}
	}
	for(k=2;k<=n*2;++k)if(c[1][k]=='1')ans+=f[2][n*2][k];
	printf("%lld\n",ans);
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define MP make_pair

int main() {
	while (true) {
		int n;
		pair<int, double> ans = MP(0, (1<<29));
		cin >> n;
		if (n == 0) break;

		REP(i, n) {
			double a, b, c, bmi;
			scanf("%lf %lf %lf", &a, &b, &c);
			bmi = c / (b/100 * b/100);

			if (ans.second > abs(22 - bmi)) {
				ans.first = a;
				ans.second = abs(22 - bmi);
			}
		}
		cout << ans.first << endl;
	}
	return 0;
}

Measured memory_bytes: 1268
/*C - Sum of gcd of Tuples (Easy)*/
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
    if(a < b){
        swap(a, b);
    }
    
    while(a%b > 0){
        int r = a%b;
        a = b;
        b = r;
    }
    return b;
}

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

    int sum = 0;
    for(int i=1; i<=K; i++){
        for(int j=1; j<=K; j++){
            for(int k=1; k<=K; k++){
                sum += gcd(gcd(i ,j), k);
            }
        }
    }
    cout<< sum <<endl;
    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    LL x;cin >> x;
    LL t = x / 500;
    LL ans = t * 1000;
    x -= t * 500;
    ans += x / 5 * 5;
    cout << ans << endl;
    return 0;
}






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

int main()
{
    int A,B; cin >> A >> B;
    int ansSum = 0;
    for (int i = 0; i < 2; i++)
    {
        if(A > B) {
            ansSum += A;
            A = A-1;
        } else {
            ansSum += B;
            B = B-1;
        }
    }
    cout << ansSum << endl;
}

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

ll mod=pow(10,9)+7;
 
ll modf(ll x,ll y){
  ll res=1;
  for(int i=1;i<=y;i++){
    res=res*x%mod;
  }
  return res;
}

int main(){
  ll N;
  cin >>N;
  ll ans=modf(10,N)-modf(9,N)-modf(9,N)+modf(8,N);
  ans %=mod;
  ans=(ans+mod)%mod;
  cout << ans <<endl;
}
    
    

Measured memory_bytes: 3636
def resolve():
    '''
    code here
    '''
    N = int(input())
    stones = input()

    w = []
    r = []

    for i in range(N):
        if stones[i] == 'W':
            w.append(i)
        else:
            r.append(i)

    if len(w) != 0 and len(r) != 0:
        res = 0
        for i, val in enumerate(w):
            if val <= r[-1*(i+1)]:
                res += 1
            else:
                break
        print(res)
    else:
        print(0)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 17284
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<cmath>
#include<vector>
#include<algorithm>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
const int maxn = 2e5+5;
ll q[maxn];

struct Mos{
	ll x, h;
}mos[maxn];

bool cmp(Mos a, Mos b){
	return a.x < b.x;
}

int main(){
	ll n, d, a; cin >> n >> d >> a;
	for(int i = 1; i <= n; i++) cin >> mos[i].x >> mos[i].h;
	sort(mos+1, mos+n+1, cmp);
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		q[i] += q[i-1];
		mos[i].h -= q[i] * a;
		if(mos[i].h <= 0) continue;
		ll t = mos[i].h / a + (mos[i].h % a ? 1 : 0);
		ans += t;
		q[i] += t;
		ll l = i, r = n, mid, w;
		while(l <= r){
			mid = (l + r) / 2;
			if(mos[mid].x <= mos[i].x + 2*d){
				w = mid;
				l = mid + 1;
			}
			else r = mid - 1;
		}
		q[w + 1] -= t;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
n, p = map(int, input().split())
s = input()


def solve1(s, p):
    v = 0
    pow10 = 1
    ans = 0
    cnt = [0] * p
    cnt[0] = 1

    for i in range(n - 1, -1, -1):
        v = (pow10 * int(s[i]) + v) % p
        pow10 = (pow10 * 10) % p
        ans += cnt[v]
        cnt[v] += 1
    return ans


def solve25(s, p):
    cnt = 0
    ans = 0
    for i in range(len(s) - 1, -1, -1):
        if int(s[i]) % p == 0:
            cnt += 1
        ans += cnt
    return ans



if p in (2,5):
    print(solve25(s, p))
else:
    print(solve1(s, p))


Measured memory_bytes: 3500
#include <iostream>

using namespace std;

int main()
{
    string b1,b2;
    cin>> b1>> b2;
    int k,m;
    cin>> k >> m;
    string st;
    cin>>st;
    if(b1 == st)
    {
        k--;
    }else if (b2 == st)
    {
        m--;
    }
    cout<< k << " "<< m ;
    return 0;
}


Measured memory_bytes: 256
use std::cmp;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let ab: Vec<i64> = sc.vec(2);
    let cd: Vec<i64> = sc.vec(2);

    let mut max = std::i64::MIN;
    for i in 0..2 {
        for j in 0..2 {
            max = cmp::max(ab[i] * cd[j], max);
        }
    }

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

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2192
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef pair<int, int> P;
//typedef pair<int, pair<int, int> > PP;
//const int MAX=1e5+10;

vi G[51];
int rc[51];

void initrc(){
	rep(i,51)rc[i]=false;
}

void initG(vi v){
	rep(i,51)G[i].clear();
	rep(k,sz(v)){
		int d=v[k];
		rep(i,51)G[i].push_back(i%d);
	}
}
void dfs(int v){
	rc[v]=true;
	rep(i,sz(G[v]))if(!rc[G[v][i]])dfs(G[v][i]);
}



int main(){
	int N;
	cin>>N;
	int a[50], b[50];
	rep(i,N)cin>>a[i];
	rep(i,N)cin>>b[i];
	
	ll ans=0;
	vi S;
	for(int p=51;p>=1; p--){
		vi T=S;
		rep1(i,p-1)T.push_back(i);
		initG(T);
		bool ok=true;
		rep(i,N){
			initrc();
			dfs(a[i]);
			if(!rc[b[i]])ok=false;
		}
		if(ok)continue;
		else{
			if(p==51){
				ans=-1;
				break;
			}
			else{
				S.push_back(p);
              	ll ad=(ll)exp2(p);
				ans+=ad;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vl vector
#define pb push_back
using namespace std;
int main()
{
    ll a,b,i,j,n,k;
    cin>>n;
    while(n)
    {
        //cout<<n<<endl;
        if(n<100) break;
        a=n%10;
        if(n%100>=10 && n>100) a=5;
        else if(a>5) a-=5;
        a+=100;
        n-=a;
    }
    if(n==0) cout<<"1";
    else cout<<"0";
}

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

int count_subordinate(int target, vector<int> &A){
    int count = 0;

    for(int i = 0; i < A.size();i++){
        if(A.at(i) == target+1){
            count++;
        }
    }

    return count;
}

int main(){
    int N = 0;
    cin >> N ;

    vector<int> A(N);
    vector<int> C(N,0);
    for(int i=0; i<N; i++){
        if(i == 0){
            A.at(i) = -1;
        }else{
        cin >> A.at(i);
        C.at(A.at(i)-1)++;
        }
    }

    for(int i=0; i<N; i++){
        cout << C.at(i) << endl;
    }

}

Measured memory_bytes: 4840
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    if (s.equals("ABC")) {
      System.out.println("ARC");
    } else {
      System.out.println("ABC");
    }
  }
}


Measured memory_bytes: 35568
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
    int A, B, sum = 0;
    cin >> A >> B;

    sum += max(A, B);
    if (A >= B) {
        A--;
    } else {
        B--;
    }

    sum += max(A, B);

    cout << sum << endl;


    return 0;
}

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

using namespace std;


int main(void){
int n;
int arr[100001];
cin >> n;
for(int i=1;i<=n;i++)
    cin >> arr[i];
int cnt=0;
for(int i=1;i<=n;i++)
    if(arr[i]<=0)cnt++;
long long sum=0;
for(int i=1;i<=n;i++)
    sum+=abs((long long)arr[i]);
if(cnt%2==0){
    cout << sum;
}
else{
    int mi=2000000000;
    for(int i=1;i<=n;i++)
        mi=min(mi,abs(arr[i]));
    cout << sum-mi*2;
}
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstdlib> 
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 27
#define ll long long int
#define ld long double
#define mmset(arr, n) memset(arr, n, sizeof arr)
#define debug(x) cerr << '#' << ' ' << x << '\n'
#define len(s) s.length()
#define ForA(i,a,b) for(int i = a; i < b; i++)
#define ForA1(i,a,b) for(int i = b - 1; i >= a; i--)
#define ForB1(i,a,b) for(int i = b; i > a; i--)
#define ForB(i,a,b) for(int i = a; i <= b; i++)
#define INT_SIZE 18 
#define maxn 310
#define Maxn 100010

using namespace std;

const ll INF = (ll)(8e18);
const ll MOD = 1000000007;

int a[maxn], dp[Maxn];

int main()
{
    IOS;        
    int n,k; cin >> n >> k;
    ForB(i,1,n) cin >> a[i]; 
    ForB(i,0,k){
        ForB(j,1,n){
            if(i >= a[j] && !dp[i - a[j]]){
                dp[i] = true;
            }
        }
    }
    cout << (dp[k] ? "First" : "Second") << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0 ;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

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

    int n;
    cin >> n;
    vector<int> arr(n);
    int tot = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        tot ^= arr[i];
    }
    for (int i = 0; i < n; i++) {
        cout << (tot ^ arr[i]) << ' ';
    }
    cout << '\n';

    fflush(stdout);
    return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> ball(N);
    vector<long long> bucket(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> ball.at(i);
        bucket.at(ball.at(i)-1)++;
    }
    
    //まず全て足す
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        ans += bucket.at(i) * (bucket.at(i) - 1) / 2;
    }
    for (int i = 0; i < N; i++) {
        cout << ans - (bucket.at(ball.at(i)-1) - 1) << endl;
    }
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define int ll

using namespace std;

const int N = 405;
int n;
int p[N];

int sum(int a,int b){
    int ans=0;
    for(int i=a;i<=b;i++) ans+=p[i];
        return ans;
}
int MatrixChainOrder() 
{ 
  
    /* For simplicity of the program, one  
    extra row and one extra column are  
    allocated in m[][]. 0th row and 0th 
    column of m[][] are not used */
    int m[n][n];

  
    int i, j, k, L, q; 
  
    /* m[i,j] = Minimum number of scalar  
    multiplications needed to compute the 
    matrix A[i]A[i+1]...A[j] = A[i..j] where 
    dimension of A[i] is p[i-1] x p[i] */
  
    // cost is zero when multiplying 
    // one matrix. 
    for (i = 0; i < n; i++) 
        m[i][i] = 0; 
  
    // L is chain length. B
    for (L = 2; L<=n; L++) 
    { 
        for (i = 0; i < n - L + 1; i++) 
        { 
            j = i + L - 1; 
            m[i][j] = LLONG_MAX; 
            for (k = i; k <= j - 1; k++) 
            { 
                // q = cost/scalar multiplications 
                q = m[i][k] + m[k + 1][j] +sum(i,j); 
                if (q < m[i][j]) 
                    m[i][j] = q; 
            } 
        } 
    } 
  
    return m[0][n - 1]; 
} 

int32_t main()
{
   
   
    crap;
    cin>>n;
    for(int i=0;i<n;i++) cin>>p[i];

    int ans = MatrixChainOrder();
	cout<<ans<<endl;
  	
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
  int a,p;cin>>a>>p;
  int k = a * 3;
  cout << (k+p)/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int d1[4] = {0,1,0,-1};
int d2[4] = {1,0,-1,0};

int H, W;
vector<string> fi;
bool seen[405][405];
ll numb, numw;

void dfs(int i, int j){
    seen[i][j] = true;
    if(fi[i][j] == '#') numb++;
    if(fi[i][j] == '.') numw++;

    for(int dir=0; dir<4; dir++){
        int ni = i+d1[dir];
        int nj = j+d2[dir];

        if(ni < 0 || H <= ni || nj < 0 || W <= nj) continue;
        if(fi[i][j] == fi[ni][nj]) continue;
        if(seen[ni][nj]) continue;

        dfs(ni, nj);    
    }
}

int main(){
    cin >> H >> W;
    fi.resize(H);
    for(int i=0; i<H; i++) cin >> fi[i];
    for(int i=0; i<405; i++) for(int j=0; j<405; j++) seen[i][j] = false;


    ll ans = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(seen[i][j]) continue;
            if(fi[i][j] == '.') continue;
            
            numb = 0; numw = 0;
            dfs(i, j);
            ans += numb*numw;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 18176
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(true){
			int hit = 0;
			int blow = 0;
			int[] all = new int [10];
			int a2 =in.nextInt();
			int b2 =in.nextInt();
			if(a2  == 0 && b2 == 0)break;
			int[] a = new int [4];
			int[] b = new int [4];
			for(int i = 0;i < 4;i++){
				a[i] = a2 % 10;
				all[a[i]] = 1;
				a2 = a2 / 10;
			}
			for(int i = 0;i < 4;i++){
				b[i] = b2 % 10;
				if(a[i] == b[i]){
					hit++;
				}else{
					for(int j = 0;j < 4;j++){
						if(a[j] == b[i]){
							blow++;
						}
					}
				}
				b2 = b2 / 10;
			}
			System.out.println(hit +" "+blow);
		}
	}
}

Measured memory_bytes: 47692
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int ss[100002],st[100002];
int main(){
    string s,t;
    cin>>s>>t;
    rep(i,s.size()){
        int p;
        if(s[i]=='A') p=1;
        else p=2;
        ss[i+1]=ss[i]+p;
    }
    rep(i,t.size()){
        int p;
        if(t[i]=='A') p=1;
        else p=2;
        st[i+1]=st[i]+p;
    }
    int q,a,b,c,d;
    cin>>q;
    rep(i,q){
        cin>>a>>b>>c>>d;
        --a,--c;
        int x=ss[b]-ss[a];
        int y=st[d]-st[c];
        //cout<<x<<" "<<y<<endl;
        if(x%3==y%3) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include<bits//stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	long long int n,sum =0;cin >> n;vector<int> a(n),c(n + 1,0);
	rep(i, n) {
		cin >> a[i];
		sum += c[a[i]];c[a[i]]++;
	}
	rep(i,n) cout << sum - c[a[i]] + 1 << endl;
}

Measured memory_bytes: 4096
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <math.h>

int main()
{
    int n;
    int count=1;
    int hoge=0;
    int H[100];
    std::cin >> n; 
    for(int i=0; i<n; i++){
    std::cin >> H[i];
    }

    for(int i=1; i<n; i++){
        for(int j=0; j<i; j++){
            if(H[i] < H[j]){
                goto a;
            }
        }
        count++;
        a:
        hoge++;
    }
    std::cout << count <<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  map<int,int>M;
  vector<int>A(N);
  for(int i=0;i<N;i++){
  int a;cin>>a;
    A[i]=a;M[a]=i;
  }sort(A.begin(),A.end());
  int ans=0;
  for(int i=0;i<N;i++){
  int b=M.at(A.at(i));
    if(b%2!=i%2)
      ans++;
  }cout<<ans/2<<endl;
  return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(3*N);

    REP(i, 3*N){
        cin >> A[i];
    }

    ll f = 0;
    ll b = 0;

    priority_queue<ll, vector<ll>, greater<ll> > que1;
    vector<ll> F(N+1, 0);

    REP(i, N){
        f += A[i];
        que1.push(A[i]);
    }
    F[0] = f;
    for(ll i=N; i<2*N; i++){
        que1.push(A[i]);
        f += A[i];
        f -= que1.top();
        que1.pop();
        F[i-N+1] = f;
    }

    // cout << "test" << endl;
    priority_queue<ll> que2;
    vector<ll> B(N+1, 0);

    for(ll i=3*N-1; i>=2*N; i--){
        b += A[i];
        que2.push(A[i]);
    }
    B[0] = b;
    for(ll i=2*N-1; i>=N; i--){
        que2.push(A[i]);
        b += A[i];
        b -= que2.top();
        que2.pop();
        B[2*N-i] = b;
    }

    // cout << "F" << endl;
    // for(ll i=0; i<=N; i++){
    //     cout << F[i] << endl;
    // }
    // cout << "B" << endl;
    // for(ll i=0; i<=N; i++){
    //     cout << B[i] << endl;
    // }

    ll ans = -LINF;
    for(ll i=0; i<=N; i++){
        ans = max(ans, F[i] - B[N-i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9520
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define FOR(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

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

	int H, W;
	cin >> H >> W;

	vs vec(H);
	REP(i, H) {
		cin >> vec[i];
	}

	REP(i, H) {
		cout << vec[i] << endl;
		cout << vec[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
h,w,n=map(int,input().split())
x,y=map(lambda x:int(x)-1,input().split())
s=input()
t=input()

d=[0,h-1,0,w-1]
f=True
for i in range(n-1,-1,-1):
  if t[i]=="D":
    d[0]=max(d[0]-1,0)
  if t[i]=="U":
    d[1]=min(d[1]+1,h-1)
  if t[i]=="R":
    d[2]=max(d[2]-1,0)
  if t[i]=="L":
    d[3]=min(d[3]+1,w-1)
  
  
  if s[i]=="U":
    d[0]+=1
  if s[i]=="D":
    d[1]-=1
  if s[i]=="L":
    d[2]+=1
  if s[i]=="R":
    d[3]-=1
  if d[0]>d[1] or d[2]>d[3]:
    f=False
    break

if f and d[0]<=x and x<=d[1] and d[2]<=y and y<=d[3]:
  print("YES")
else:
  print("NO")

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

int main() {
    int n,m;
    cin>>n>>m;
    vector<long long> x(n), y(n), z(n);
    for(int i=0; i<n; i++) {
        cin>>x[i]>>y[i]>>z[i];
    }

    long long maxs=0;
    for(int i=0; i<2; i++) {
        for(int j=0; j<2; j++) {
            for(int k=0; k<2; k++) {
                vector<long long> as(n);
                for(int l=0; l<n; l++) {
                    as[l] = x[l]*(2*i-1)+y[l]*(2*j-1)+z[l]*(2*k-1);
                }
                sort(as.begin(), as.end());
                long long sum=0;
                for(int l=n-m; l<n; l++) {
                    sum += as[l];
                }
                maxs = max(maxs, sum);
            }
        }
    }
    cout<<maxs<<endl;
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int N = 100005;

int n, q;
int dat[N], freq[N];

int main() {
	scanf("%d", &n);
	ll curSum = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &dat[i]);
		freq[dat[i]]++;
		curSum += dat[i];
	}
	scanf("%d", &q);
	while (q--) {
		int x, y; scanf("%d %d", &x, &y);
		curSum -= 1ll * freq[x] * x;
		curSum += 1ll * freq[x] * y;
		freq[y] += freq[x];
		freq[x] = 0;
		printf("%lld\n", curSum);
	}
	return 0;
}

Measured memory_bytes: 4536
#include<stdio.h>
#include<math.h>
 
typedef struct{
  double x;
  double y;
}Point;
 
int koch(int , Point , Point);
 
int main(){
 
  int n;
  Point p1,p2;
 
  p1.x=0.0;
  p1.y=0.0;
  p2.x=100.0;
  p2.y=0.0;
 
  scanf("%d",&n);
 
  printf("%f %f\n",p1.x,p1.y);
  koch(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
 
  return 0;
}
 
 
int koch(int n , Point p1 , Point p2){
 
  Point s,t,u;
 
  if(n==0) return 0;
 
  
  s.x=(p2.x+2*p1.x)/3.0;
  s.y=(p2.y+2*p1.y)/3.0;
      
  t.x=(p1.x+2*p2.x)/3.0;
  t.y=(p1.y+2*p2.y)/3.0;
   
  u.x=(t.x-s.x)/2-(t.y-s.y)*(sqrt(3)/2)+s.x;
  u.y=(t.x-s.x)*(sqrt(3)/2)+(t.y-s.y)/2+s.y;
  
 
 koch(n-1, p1, s);
  printf("%f %f\n",s.x,s.y);
   
  koch(n-1, s, u);
  printf("%f %f\n",u.x,u.y);
   
  koch(n-1, u, t);
  printf("%f %f\n",t.x,t.y);
   
  koch(n-1, t, p2);
}

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

class Main{

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

	public static void main(String[] args) {
		FastReader sc = new FastReader();

		int t=sc.nextInt();
		long ans=0;
		for(int i=0;i<t;i++)ans+=sc.nextLong()-1;
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define N 100
const int infty = 1<<28;
struct Node{
  vector<int> con;
  vector<int> cost;
};
struct State{
  int now;
  int cost;
  State():now(-1),cost(infty){}
  State(int pos,int c):now(pos),cost(c){}
  bool operator>(const State &t)const{return cost>t.cost;}
};
typedef vector<Node> Graph;
int dijkstra(int s, int g, Graph &G)
{
  int A[G.size()];
  bool vis[G.size()];
  priority_queue< State,vector<State>,greater<State> > qs;
  fill(A,A+G.size(),infty);
  fill(vis,vis+G.size(),false);
  qs.push(State(s,0));
  A[s]=0;
  while(!qs.empty()){
    State now=qs.top();qs.pop();
    //if(vis[now.now])continue;
    //vis[now.now]=true;
    for(int i=0;i<G[now.now].con.size();++i){
      int next_id=G[now.now].con[i];
      if(now.cost+G[now.now].cost[i]<A[next_id]){
	A[next_id]=now.cost+G[now.now].cost[i];
	//if(!vis[next_id]){
	qs.push(State(next_id,A[next_id]));
	  //}
      }
    }
  }
  return A[g];
}
int main()
{
  int n,m,s,g1,g2;
  while( (cin >> n >> m >> s >> g1 >> g2) && n && m && s && g1 && g2 ){
    int ans=infty;
    --s;--g1;--g2;
    Graph G(n);
    for(int i = 0; i < m; ++i){
      int src,dst,cost;
      cin >> src >> dst>> cost;--src;--dst;
      G[src].con.push_back(dst);
      //G[dst].con.push_back(src);
      G[src].cost.push_back(cost);
      //G[dst].cost.push_back(cost);
    }
    for(int i = 0; i < n; ++i){
      int tmp=dijkstra(s,i,G)+dijkstra(i,g1,G)+dijkstra(i,g2,G);
      if(tmp<ans)ans=tmp;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	int lst = -1;
	for(int i=0; i<n; i++) {
		int cur;
		cin >> cur;
		if(cur > lst)
			lst = cur-1;
		else if(cur < lst)
			return !(cout << "No");
	}
	cout << "Yes";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
int h[200000];
ll a[200000];
ll dp[200001];

class segtree
{
  public:
  int depth;//セグ木の深さ(最上部が0）
  int size;
  vector<ll> node;//セグ木本体

  //コンストラクタ
  //初期値の代入もする
  segtree(int n)
  {
    depth=0;
    size=1;
    while(n>size)
    {
      size*=2;
      depth++;
    }
    size*=2;
    node.resize(size,0);
  }

  //値の更新
  //node[k]をaにする
  void update(int k,ll a)
  {
    k+=(1<<depth);//セグ木上のインデックスに読み替え
    node[k]=a;
    while(k>1)
    {
      k/=2;
      node[k]=max(node[k*2],node[k*2+1]);
    }
    return;
  }
  
  //値の取得
  //閉区間[a,b]での値の最大値
  ll get(int a,int b)
  {
    a+=(1<<depth);
    b+=(1<<depth);
    if(a==b)
      return node[a];
    ll nowa=node[a];
    ll nowb=node[b];
    while(a/2<b/2)
    {
      //左側はより右側を見る
      if((a&1)==0)
        nowa=max(nowa,node[a+1]);
      //右側はより左側を見る
      if((b&1)==1)
        nowb=max(nowb,node[b-1]);
      a/=2;
      b/=2;
    }
    ll ret=max(nowa,nowb);
    return max(ret,node[a]);
  }
};
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>h[i];
	for(int i=0;i<n;i++)
		cin>>a[i];
	fill(dp,dp+200001,0);
	segtree t=segtree(n+1);
	for(int i=0;i<n;i++)
	{
		ll tmp=t.get(0,h[i]-1);
		if(dp[h[i]]<tmp+a[i])
		{
			dp[h[i]]=tmp+a[i];
			t.update(h[i],dp[h[i]]);
		}
	}
	for(int i=0;i<n+1;i++)
		ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8192
#include<stdio.h>

int main(){
    int c=0,i,n,max=0,h[100];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&h[i]);
        if(h[i]>=max){
            max=h[i];
            c++;
        }
    }
    printf("%d\n",c);
    return 0;
}

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

int main() {
  int K, A, B;
  cin >> K >> A >> B;

  // B以下の最大のKの倍数がA以上である
  if (A <= (B / K) * K)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;

  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int d[5]={},ans=0;
	rep(i,0,5){
		cin>>d[i];
		if(d[i]<40) d[i]=40;
		ans+=d[i];
	}
	o(ans/5);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
	FastIO
	lld r;
	cin >> r;
	cout << (3*(r*r));
	return 0;
}

Measured memory_bytes: 256
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"


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

	int a,b;
	cin>>a>>b;
	if(b==1){cout<<0<<endl;return 0;}
	int c=1,d=a;
	while(d<b)c++,d+=a-1;
	cout<<c<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int ans;
map <string ,int>m;
string s;
signed main(){
	//ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>s;
    	sort(s.begin(),s.end());
    	ans+=m[s];
    	m[s]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 11136
#include <cstdio>
using namespace std;
int n, q, f[100005];
long long sum;
int find(int v)
{
    int r = v;
    while(r != f[r])
        r = f[r];
    return r;
}
int main()
{
    while (scanf("%d %d", &n, &q) != EOF)
    {
        if (n == 0 && q == 0)
            break;
        sum = 0;
        f[1] = 1;
        for (int i = 2; i <= n; i++)
            scanf("%d", &f[i]);
        for (int i = 0; i < q; i++)
        {
            getchar();
            char s[10];
            int a;
            scanf("%s %d", s, &a);
            if (s[0] == 'M')
                f[a] = a;
            else if (s[0] == 'Q')
                sum += find(a);
        }
        printf("%lld\n", sum);
    }
    return 0;
}


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

int main(){
  int N;
  cin>>N;
  int A[N];
  int flag=1;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(A[i]%2==1){
      flag=0;
    }
  }
  if(flag==1){
    cout<<"second"<<endl;
  }
  else{
    cout<<"first"<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n, s) for (int i = (s); i < (n); i++)
using namespace std;
typedef long long int LL;
typedef long double LD;

const int MAXN = 1e5 + 1;
const int LOGV = 17;

int dp[LOGV][MAXN], X[MAXN];

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

	int N, L, i, j, Q, logV;

	cin >> N;
	for (i = 1; i <= N; i++) {
		cin >> X[i];
	}
	for (logV = 1; (1 << (logV + 1)) <= N; logV++);
	cin >> L;
	for (i = 1, j = 1; i <= N; i++) {
		while (j <= N && X[j] - X[i] <= L) j++;
		dp[0][i] = j - 1;
	}
	for (i = 1; i <= logV; i++) {
		for (j = 1; j + (1<<i)-1 <= N; j++) {
			dp[i][j] = dp[i-1][dp[i-1][j]];
		}
	}
	cin >> Q;
	int a, b;
	while (Q--) {
		cin >> a >> b;
		if (a > b) a ^= b ^= a ^= b;
		int step = 0;
		for (i = logV; i >= 0; i--) {
			if (dp[i][a] && dp[i][a] < b) {
				step += 1 << i;
				a = dp[i][a];
			}
		}
		cout << step + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
const int MAXN = 100000 + 10;
const int MOD = 1e9 + 7;

int n;
char input[MAXN];
long long num[MAXN];
long long ans = 1;

int main(){
	scanf("%d", &n);
	scanf("%s", input);
	
	for(register int i=0; i<n; i++){
		num[input[i] - 'a']++;
	}	
	
	for(register int i=0; i<26; i++){
		ans = (ans * (num[i] + 1)) % MOD;
	}
	
	printf("%lld", ans - 1);

	return 0;
}


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

using namespace std;

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

    double ans = 0;
    for ( int init = 1; init <= n; init++ ) {
        double ans_ = 1.0 / n;
        int score = init;
        while ( score < k ) {
            score *= 2;
            ans_ /= 2;
        }
        ans += ans_;
    }

    printf("%.10lf\n", ans);
    return 0;
}


Measured memory_bytes: 3672
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, M = map(int, readline().split())
H = list(map(int, readline().split()))
ng = []
for _ in range(M):
    A, B = map(int, readline().split())
    A -= 1
    B -= 1
    if H[A] == H[B]:
        ng.append(A)
        ng.append(B)
        continue
    if H[A] > H[B]:
        ng.append(B)
    else:
        ng.append(A)

answer = N - len(set(ng))
print(answer)


Measured memory_bytes: 20332
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()

def kosuu(x):
    re = [0,0]
    while x % 2 == 0:
        x = x//2
        re[1]+=1
    re[0]=x
    return re

        
 
def main():
    n,m=map(int, input().split())
    a=list(map(int, input().split()))
    li = [kosuu(a[0])[0]]
    hantei = kosuu(a[0])[1]
    for i in a[1:]:
        hantei2 = kosuu(i)
        if hantei2[1] != hantei:
            print(0)
            break
        else:
            li.append(hantei2[0])
    else:
        lc = np.lcm.reduce(li)
        print(((m//(lc*2**(hantei-1)))+1)//2)
            


if __name__=='__main__':
    main()

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

int main() {
    int n;
    cin >> n;
    const int MAX = 20;
    vector<int> last(MAX, -1);
    long long result = 0;
    for (int i = 0, left = 0, a; i < n; i++) {
        cin >> a;
        bitset<MAX> bits(a);
        for (int j = 0; j < MAX; j++) {
            if (bits[j]) {
                left = max(left, last[j] + 1);
                last[j] = i;
            }
        }
        result += i - left + 1;
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd,numbers)

cnt=0  
b=gcd_list(a)
for i in range(2**30):
  if b%2==0:
    cnt+=1
  b=b/2
  if b%2==1 or b==1/2:
    break

print(cnt)

Measured memory_bytes: 9528
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int N;
int d[MAX_N];

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  REP(i, N) cin >> d[i];

  priority_queue<int> q;
  REP(i, N) q.push(d[i]);

  int ans = 0;
  int prev = INT_MAX;
  while (!q.empty()) {
    int cur = q.top();
    q.pop();
    if (cur < prev) {
      ans++;
      prev = cur;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
N,M=map(int,input().split())
lamp=[list(map(int,input().split())) for _ in range(M)]
restrict=list(map(int,input().split()))
l=[0]*N
cnt=0
flag=0
ans=0
for i in range(pow(2,N)):
    for j in range(N):
        l[j]=(i>>j)&1
    for j in range(M):
        for k in range(len(lamp[j])-1):
            cnt=cnt+l[lamp[j][k+1]-1]
        if (cnt%2)==restrict[j]:
            flag=flag+1
        cnt=0
    if flag==M:
        ans=ans+1
    flag=0
print(ans)

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


vector<long long int>all1;




int solve(long long int number)
{
  int siz=all1.size()-1;
  int i=0,j=siz;
  int index=0;
  while(i<=j)
  {

    int mid=i+(j-i)/2;

    if(all1[mid]<=number)
    {
      index=mid;
      i=mid+1;
    }
    else
     j=mid-1;

   //cout<<i<<" "<<j<<endl;

  }

  return index;

}


int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    

    long long int a,b,c;
    cin>>a>>b>>c;
    vector<long long int>all;
    all.push_back(0);
    all1.push_back(0);

    for(int i=1;i<=a;i++)
    {
      int first;
      cin>>first;
      all.push_back(first+all[i-1]);
    }
    for(int i=1;i<=b;i++)
    {
      int first;
      cin>>first;
      all1.push_back(first+all1[i-1]);
    }

   /* for(int i=0;i<a;i++)
    {
      cout<<all[i]<<" "<<all1[i]<<endl;
    }*/


    int count=0;
    for(int i=0;i<=a;i++)
    {
      int temp=0;
      if(c-all[i]>=0){
      int index=solve(c-all[i]);
      temp=(i+index);
      count=max(count,temp);
      }
      else
        break;

    }

    cout<<count<<endl;


    return 0;
    
}

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

int main() {
    int n, m,i,sum=0, ans = 0;
    cin >>n >> m;
    int lst[n];
    for(i = 0; i < n; i++){
        cin >>lst[i];
        sum += lst[i];
    }
    for(i = 0; i < n; i++){
        if(sum%(4*m) == 0){
            if(lst[i] >= sum/(4*m)) ans++;
        }
        else{
            if(lst[i] > sum/(4*m)) ans++;
        }
    }
    if(ans >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    ll N, M;
    string S;
    cin >> N >> M >> S;
    ll po[N] = {};
    vector<vector<ll>> edges(N), an(N), bn(N);
    for(ll i = 0; i < M; i++){
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        (S[b] == 'A' ? an : bn)[a].push_back(b);
        (S[a] == 'A' ? an : bn)[b].push_back(a);
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    bool ng[N] = {};
    vector<ll> starts;
    for(ll i = 0; i < N; i++) if(an[i].empty() || bn[i].empty()) starts.push_back(i);
    for(auto start : starts){
        if(ng[start]) continue;
        ng[start] = 1;
        queue<ll> q;
        q.push(start);
        while(q.size()){
            ll now = q.front();
            q.pop();
            for(ll next : edges[now]){
                if(ng[next]) continue;
                ll tmp = 0;
                for(ll po : an[next]) if(!ng[po]) tmp |= 1;
                for(ll po : bn[next]) if(!ng[po]) tmp |= 2;
                if(tmp == 3) continue;
                q.push(next);
                ng[next] = 1;
            }
        }
    }
    for(ll i = 0; i < N; i++){
        if(!ng[i]){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 31104
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;

int main(){
  int n;
  int i,j,k;
  int era;

  while(cin >> n){
    int count = 0;
    int S[n+1];
    for(i=2 ; i<n+1 ; i++){
      S[i] = i;
    }

    for(i=2 ; i<(
                 (int)sqrt(n)+1) ; i++){
      if(S[i] != 0){
        era = S[i];
        for(j=2 ; (j*era)<(n+1) ; j++){
          S[j*era] = 0;
        }
      }
    }

    for(i=2 ; i<n+1 ; i++){
      if(S[i] != 0){
        count++;
      }
    }
      
    cout <<  count << endl;
  }

    
  return 0;
}

Measured memory_bytes: 5064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define cu continue
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf LLONG_MAX
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define f first
#define s second
#define vll vector <ll>
#define dbg(n) cout<<n<<' ';


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


    ll k,n;
    cin>>k>>n;

    ll a[n],b[n];
    for(ll i=0;i<n;i++)
        cin>>a[i]>>b[i];
    ll dp[10005];
    for(ll j=1;j<10005;j++)
        dp[j]=inf;
    for(ll i=0;i<n;i++)
    {
        for(ll j=1;j<10005;j++)
        {
            if(j-a[i]<=0)
            {
                dp[j]=min(dp[j],b[i]);
                cu;
            }
            dp[j]=min(dp[j],b[i]+dp[j-a[i]]);
        }
    }
    cout<<dp[k]<<'\n';
}       


Measured memory_bytes: 384
import java.util.Scanner;

/**
 * 【問題概要】
 *
 * 二つの正整数 aa, bb が与えられます。 aa と bb の積が偶数か奇数か判定してください。
 *
 * @author tsuch
 *
 */
public class Main {

	private static Scanner sc = new Scanner(System.in);

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

	private void solve() {
		try {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if ((a * b / 2 - (a * b + 1) / 2) == 0) {
				System.out.println("Even");
			} else {
				System.out.println("Odd");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 21844