akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int h,w,d;
int mp[2003][2003];
int main(){
    cin>>h>>w>>d;
    for(int i=0;i<=2000;i++){
        for(int j=0;j<=2000;j++){
            int tmp=((i/(d))%2)*2+(j/(d))%2;
            mp[i][j]=tmp;
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            int x=i+j+500,y=i-j+500;
            if(mp[x][y]==0){
            	cout<<"R";
			}else if(mp[x][y]==1){
            	cout<<"Y";
			}else if(mp[x][y]==2){
            	cout<<"G";
			}else{
            	cout<<"B";
			}
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 16128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int main(){
int x,y;
cin>>x>>y;
if(y&1)cout<<"No";
else if(y>4*x||y<2*x)cout<<"No";
else cout<<"Yes";

return 0;}


Measured memory_bytes: 3636
def main():
    repeat = int(input())
    announced_num = [int(input()) for _ in range(repeat)]
    count = {}
    for number in announced_num:
        if number in count:
            if count[number] % 2:
                count[number] = 0
            else:
                count[number] = 1
        else:
            count[number] = 1
    answer = 0
    for i in count.values():
        answer += i
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 16268
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    ll x;
    cin >> x;
    ll num = 0; //カンガルーのいる位置
    ll mn = 0;
    for(ll i = 0;; i++){
        num += i;
        if(x <= num){
            mn = i;
            break;
        }
    }
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
    int(name);   \
    scanf("%d", &(name))
#define GI2(name1, name2) \
    int(name1), (name2);  \
    scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3)  \
    int(name1), (name2), (name3); \
    scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)      \
    vector<int>(name)(size); \
    FOR(i, (size))           \
    scanf("%d", &(name)[i])

using namespace std;

string to_hex(int x)
{
    stringstream ss;
    ss << hex << x;
    return ss.str();
}

inline int get_int()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}

inline vector<int> get_ints(int n)
{
    vector<int> ret(n);
    FOR(i, n)
    {
        scanf("%d", &ret[i]);
    }
    return ret;
}

inline string get_str()
{
    string ret;
    cin >> ret;
    return ret;
}

bool is_prime(int n)
{
    int s = sqrt(n) + 1;
    for (int i = 2; i <= s; ++i)
    {
        if (n % i == 0)
        {
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n)
{
    vector<P> ret;
    int s = sqrt(n) + 1;
    int c = 0;
    for (int i = 2; i <= s; ++i)
    {
        if (n % i == 0)
        {
            c = 0;
            do
            {
                ++c;
                n /= i;
            } while (n % i == 0);
            ret.push_back(P(i, c));
        }
    }
    return ret;
}

string to_string(string s)
{
    return s;
}

template <class T>
string to_string(vector<T> v)
{
    string ret = "{";
    FOR(i, v.size() - 1)
    {
        ret += to_string(v[i]) + ",";
    }
    if (v.size() > 0)
    {
        ret += to_string(LAST(v));
    }
    ret += "}";
    return ret;
}

void debug_print()
{
    cerr << endl;
}

template <class Head, class... Tail>
void debug_print(Head head, Tail... tail)
{
    cerr << to_string(head) << " ";
    debug_print(tail...);
}

template <class... T>
void debug(T... args)
{
    cerr << "[" << __LINE__ << "]: ";
    debug_print(args...);
}

void print()
{
    cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail)
{
    cout << to_string(head);
    print(tail...);
}

int main()
{
    GI(n);
    deque<int> deq;
    bool mode = 1;
    FOR(i, n)
    {
        GI(a);
        if (mode)
        {
            deq.push_front(a);
        }
        else
        {
            deq.push_back(a);
        }
        mode = !mode;
    }
    if (n % 2 == 1)
    {
        FOR(i, n - 1)
        {
            cout << deq[i] << " ";
        }
        cout << deq[n - 1] << endl;
    }else{
        FOR(i, n - 1)
        {
            cout << deq[n-1-i] << " ";
        }
        cout << deq[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
///////////////////////////////////////////////////////////
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
///////////////////////////////////////////////////////////
#define ll long long
#define ull insigned lon long
///////////////////////////////////////////////////////////
int absolute(int n);
void input(vector<int>& vec);
void print(vector<int> vec);
void upsort(vector<int>& vec);
void downsort(vector<int>& vec);
int maxvec(vector<int> vec);
int minvec(vector<int> vec);
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    input(L);
    vector<int> D(N + 1);
    D.at(0) = 0;
    D.at(1) = L.at(0);
    for (int i = 0; i < N; ++i) {
        if (D.at(i) <= X && D.at(i + 1) > X) {
            cout << i + 1 << endl;
            return 0;
        }
        if (i < N - 1) {
            D.at(i + 2) = D.at(i + 1) + L.at(i + 1);
        }
    }
    cout << N + 1 << endl;
    return 0;
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int absolute(int n)
{
    if (n < 0) {
        return (-n);
    }
    return n;
}

void input(vector<int>& vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cin >> vec.at(i);
    }
}

void print(vector<int> vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cout << vec.at(i) << " ";
    }
    cout << endl;
}

void upsort(vector<int>& vec)
{
    sort(vec.begin(), vec.end());
}

void downsort(vector<int>& vec)
{
    sort(vec.begin(), vec.end(), greater<int>());
}

int maxvec(vector<int> vec)
{
    int m = vec.at(0);
    for (size_t i = 0; i < vec.size(); ++i) {
        m = max(m, vec.at(i));
    }
    return m;
}

int minvec(vector<int> vec)
{
    int m = vec.at(0);
    for (size_t i = 0; i < vec.size(); ++i) {
        m = min(m, vec.at(i));
    }
    return m;
}
///////////////////////////////////////////////////////////

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

int main() {
    int T;
    cin >> T;
    for (int z = 0; z < T; z++) {
        int N;
        cin >> N;
        vector<ll> A(N);
        for (int i = 0; i < N; i++) cin >> A[i];
        string S;
        cin >> S;
        bool win0 = true;
        vector<ll> vspace;
        for (int i = N-1; i >= 0; i--) {
            if (S[i] == '1') {
                if (vspace.empty()) {
                    win0 = false;
                    break;
                }
                int t = 0;
                int K = vspace.size();
                ll tgt = A[i];
                for (int j = 60; j >= 0; j--) {
                    if ((tgt>>j)&1) {
                        while (t < K && ((((vspace[t]>>j)&1)==0) || (vspace[t]>>(j+1)) > 0)) {
                            t++;
                        }
                        if (t >= K) {
                            win0 = false;
                            break;
                        }
                        tgt ^= vspace[t];
                        t++;
                    }
                }
                if (tgt != 0) {
                    win0 = false;
                }
            }
            if (S[i] == '0') {
                vspace.insert(vspace.begin(), A[i]);
                int t = 0;
                int K = vspace.size();
                for (int j = 60; j >= 0; j--) {
                    bool check = false;
                    for (int k = t; k < K; k++) {
                        if ((vspace[k]>>j)&1) {
                            swap(vspace[t], vspace[k]);
                            check = true;
                            break;
                        }
                    }
                    if (check) {
                        for (int k = t+1; k < K; k++) {
                            if ((vspace[k]>>j)&1) {
                                vspace[k] ^= vspace[t];
                            }
                        }
                        t++;
                    }
                }
            }
        }
        cout << (win0 ? '0' : '1') << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <queue> 
using namespace std;
int main(){
    int n,i,sum1=0,sum2=0,ans=10000000;
    cin>>n;
    int w[n];
    for(i=0;i<n;i++){
        cin>>w[i];
        sum1+=w[i];
    }
    for(i=0;i<n;i++){
        sum2+=w[i];
        sum1-=w[i];
        ans=min(ans,abs(sum1-sum2));
    }
    cout<<ans<<endl;
    return 0;
}



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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e8;


//collision time
int colltime(vector<P> yu){
    int res = iINF;
    sort(yu.begin(),yu.end());
    rep(i,yu.size()-1){
        if( yu[i].second == 0 && yu[i+1].second != 0 ){
            chmin(res, (yu[i+1].first - yu[i].first));
        }
    }
    return res;
}

int min_colltime(map<int,vector<P>>& UD){
    int res = iINF;
    for(auto udi : UD) chmin(res,colltime(udi.second));
    return res;
}


//---main---------------------------------------------
int main(){
    //main
    int N;
    cin >> N;
    vector<int> X(N),Y(N),U(N);
    char c;
    rep(i,N){
        cin >> X[i] >> Y[i] >> c;
        if(c=='U') U[i] = 0;
        if(c=='R') U[i] = 1;
        if(c=='D') U[i] = 2;
        if(c=='L') U[i] = 3;
    }


    int ans = iINF;
    rep(d,4){
        //同じx座標でU,Dのものをまとめる
        map<int,vector<P>> UD;
        rep(i,N) if(U[i]==0 || U[i]==2) UD[X[i]].emplace_back(Y[i],U[i]);
        chmin(ans, min_colltime(UD)*5);

        //同じ直線上でU,Rのものをまとめる
        map<int,vector<P>> UR;
        rep(i,N) if(U[i]==0 || U[i]==1) UR[X[i]+Y[i]].emplace_back(Y[i],U[i]);
        chmin(ans, min_colltime(UR)*10);

        //rotate
        int xi;
        rep(i,N){
            xi = X[i];
            X[i] = Y[i];
            Y[i] = -xi;
            U[i] = (U[i]+1)%4;
        }
    }

    if(ans == iINF) cout << "SAFE" << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 48748
#include <iostream>
#include <limits.h>
using namespace std;
int main(void){
    long w,i,j,k,n,a,b;
    long mass=0;
    k=0;
    cin>>n>>w;
    long stuff[n][2];//stuff[i][0]が重さでstuff[i][1]が価値
    for(i=0;i<n;i++){
        cin>>stuff[i][0]>>stuff[i][1];
        mass = mass+stuff[i][1];
    }
    long chart[n+1][mass+1];
    for(i=0;i<n+1;i++){
        for(j=0;j<mass+1;j++){
            if(i==0&&j!=0){
                chart[i][j]=LONG_MAX/2;
                continue;
            }
            if(j==0){
                chart[i][j]=0;
                continue;
            }
            if(j<stuff[i-1][1])
            a=stuff[i-1][0];
            else 
            a=stuff[i-1][0]+chart[i-1][j-stuff[i-1][1]];
            b = chart[i-1][j];
            if(a>b)
            chart[i][j]=b;
            else
            chart[i][j]=a;
            
            if(j>k&&chart[i][j]<=w&&chart[i][j]!=0)
            k=j;
        }
    }
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 79104
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H = sc.nextInt();

		Integer a[] = new Integer[N];
		Integer b[] = new Integer[N];

		int max = 0;
		int cnt = 0;

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		}

		Arrays.sort(b);

		int x = N - 1;

		while (x >= 0 && b[x] > max && H > 0) {
			H -= b[x];
			x--;
			cnt++;
		}

		if (H > 0) {
			cnt += H / max;
			if (H % max != 0)
				cnt++;
		}

		System.out.println(cnt);
	}
}


Measured memory_bytes: 87552
arr = Array.new(13, nil)
n = 1
while arr[1..12].include?(nil)
    sum = 0
    1.upto(n){|x| sum += 1 if n % x == 0}
    arr[sum] = n if arr[sum].nil?
    n += 1
end
puts arr[gets.to_i]


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

int main(){
  int a ,b ,c ,x ; 
  cin >> a >> b >> c >> x ; 
  int cnt = 0 ; 
  
  for(int i= 0 ; i <= a ; i++){
    for(int j = 0 ; j <= b ; j++){
      for(int k = 0 ; k <= c ; k++){
        if(i*500+j*100+k*50 == x ) cnt++ ; 
      }
    }
  }
  cout << cnt <<endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

#define ll long long

#define MOD 1000000007
#define REP(i, n) for(int i = 0;i < n;i++)

int beki(int n,int m)
{
    int temp = 1;
    for (int i = 0; i < m; i++)
    {
        temp = temp*n;
    }
    return temp;
}


int main()
{
    int n,m;
    cin >> n >> m;
    int* k;
    k = new int[n];
    int** s;
    s = new int*[m];
    for (int i = 0; i < m; i++)
    {
        s[i] = new int[n];
    }
    
    REP(i,m)
    {
        REP(j,n)
        {
            s[i][j] = -10;
        }
    }

    int number = 0;

    REP(i,m)
    {
        cin >>k[i];
        REP(j,k[i])
        {
            cin >> number;
            number--;
            s[i][j] = number;
        }
    }

    int* p;
    p = new int[m];
    REP(i,m)
    {
       cin >> p[i];
    }

    int* real_s;
    real_s = new int[n];
    int counter = 0;//行ごとのスイッチonの数

    int flag = 0;//on_offのジャッジ。nなら全点灯

    int ans = 0;
    int temp = 1;

    for (int i = 0; i < n; i++)
    {
        temp = 2*temp;
    }
    

    int num;
    for (int i = 0; i < temp; i++)//場合
    {

        num = i;
        for (int j = n-1; j >= 0; j--)//実際のonoffを確保
        {
            real_s[j] = num/beki(2,j);
            if (real_s[j]==1)
            {
                num = num-beki(2,j);
            }
            
        }


        for (int o = 0; o < m; o++)
        {
            for (int q = 0; q < n; q++)
            {
                if (real_s[s[o][q]]==1)
                {
                    counter++;
                }
                
            }
            if (counter%2==p[o])
            {
                flag++;
            }
            counter = 0;
            
        }
        //cout << i << "の時" ;
        /*for (int j = 0; j < n; j++)
        {
            cout << real_s[j];
        }
        
       cout << " " << "flagは"<< flag << endl;*/
        if (flag == m)
        {
            ans++;
        }
        flag = 0;
        
    }

    cout << ans << endl;
}


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

A -= 1

if A % 4 == 1:
    A = 1
elif A % 4 == 2:
    A += 1
elif A % 4 == 3:
    A = 0

if B % 4 == 1:
    B = 1
elif B % 4 == 2:
    B += 1
elif B % 4 == 3:
    B = 0

answer = A^B
print(answer)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
from itertools import accumulate

def rightTrip(x,v,N,C)->int:
    accum_v = list(accumulate(v))
    ## スタート位置から左回りの距離
    left_v = v[::-1]
    left_accum_v = list(accumulate(left_v))

    ## v - 2x
    rightRoundTrip = [accum_v[i]-2*x[i] for i in range(N)]
    """
    右行って左
    """
    dp_left = [0]*(N)
    dp_left[0] = left_v[0] - (C-x[N-1])
    ## dp_left[i] = 左i番目までの最大
    for i in range(1,N):
        dp_left[i] = max(left_accum_v[i]-(C-x[N-i-1]),dp_left[i-1])
    
    answer = 0
    # rightがjまで行ったとき左からはN-2-jまでいける

    for i in range(0,N-1):
        r = rightRoundTrip[i]
        l = dp_left[N-2-i]
        answer = max(r+l,answer)
    
    """
    右行って退店
    """
    rightTrip = [accum_v[i]-x[i] for i in range(N)]
    answer = max(answer,max(rightTrip))
    return answer

def solve(N: int, C: int, x: "List[int]", v: "List[int]"):
    ## 右行って左→どこまで右行くのがいいか全探索
    ## 右行って退店
    ## 左行って右
    ## 左行って退店
    left_v = v[::-1]
    left_x = [C-x[i] for i in range(N-1,-1,-1)]
    print(max(rightTrip(x,v,N,C),rightTrip(left_x,left_v,N,C)))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, C, x, v)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38012
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int count = 0;
		int N = sc.nextInt();
		for(int i = 0; i < N; i++){
			int a = sc.nextInt();
			if(a%2 == 0){
				while(a%2 == 0){
					a /= 2;
					count++;
				}
			}else{
				
			}
		}
			System.out.println(count);
	}
}

Measured memory_bytes: 35700
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;


int main()
{
    int h,w;
    cin >> h >> w;
    vector<string> s;
    rep(i,h)
    {
        string a;
        cin >>a;
        bool ok=true;
        rep(k,a.length())
        {
            if(a[k]=='#')
            {
                ok = false;
                break;
            }
        }
        if(!ok) s.push_back(a);
    }
    vector<bool> p(w);
    rep(i,w)p[i]=true;

    rep(i,w)
    {
        bool ok=true;
        rep(k,s.size())
        {
            if(s[k][i]=='#')
            {
                ok=false;
                break;
            }
        }
        if(ok) p[i]=false;
    }

    rep(i,s.size())
    {
        rep(k,w)
        {
            if(p[k])cout<<s[i][k];
        }
        cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    if((a[0]+a[1])%2==0) {
        cout << (a[2]-a[0] + a[2]-a[1])/2 << endl;
    } else {
        a[2]++; a[1]++;
        cout << (a[2]-a[0] + a[2]-a[1])/2 + 1 << endl;
    }

    return 0;
}



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

class Program
{

	//Main
	static void Main(string[] args)
	{
		//読み込む
		string[] S = Console.ReadLine().Split(' ');
		int N = int.Parse(S[0]);
		int K = int.Parse(S[1]);

		/*

		//累積和を格納する配列
		long[] sumArr = new long[N+1];
		for(int i=1; i<N+1; i++){
				long idx = (long)i;
				sumArr[i] = idx*(idx+1)/2;
		}

		*/

		/*
		K<=i<=N+1となる各iについて、有り得る組み合わせの数は、
		それぞれ最大値-最小値+1通りである。（∵最小値から最大値までの全ての数を作成可能）
		最大値-最小値については、累積和から容易に求められる
		*/
		long ans = 0;

		for(long i=K; i<=N+1; i++){
				/*
					//最小値
					long min = sumArr[i-1];
					//最小値
					long max = sumArr[N] - sumArr[N-i];

					//組み合わせの数を答えに加算
					ans += (max-min+1);
				*/

				//上記計算式を一般化して解く
				//（sumArr[j] = j(j+1)/2であることに着目）
				ans += (i*N - i*(i-1) + 1);
		}

		Console.WriteLine(ans%1000000007);
	}
}



Measured memory_bytes: 17872
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
const int INF = 1<<30, mod = 1000000007;
const double pi = 3.14159265;
const ll LLINF = 1LL << 50;
using namespace std;

bool judgeten(int num) {
    while (num > 1) {
        if (num % 10 != 0) return false;
        num /= 10;
        if (num == 1)return true;
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    if (judgeten(n))cout << "10" << endl;
    else {
        int t = 0;
        while (n >= 1) {
            t += n % 10;
            n /= 10;
        }
        cout << t << endl;
    }
    return 0;
}


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

using namespace std;

typedef pair<int, int> pii;

#define M 1000000007

#define B ((1<<30)+1)

long long power(long long x, long long y) 
{ 
    long long res = 1;     // Initialize result 
   
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % M; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % M;  // Change x to x^2 
    } 
    return res; 
}


int main() {
    // oh hi mark
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    long long a[n], b[n];
    for(int i = 0 ;i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0 ;i < n; i++) {
        cin >> b[i];
    }

    long long xa[n], xb[n];

    for(int i = 0 ; i < n; i++) {
        xa[i] = (a[i] ^ a[(i+1)%n]);
        xb[i] = (b[i] ^ b[(i+1)%n]);
        // cout << xb[i] << endl;
    }

    long long hash = 0;
    long long H = 0;
    for(int i = 0; i < n; i++) {
        H = (H*B) %M;
        H = (H + (xb[i]) % M) % M;
        // cout << H << endl;
        hash=(hash*B) % M;
        hash = (hash + (xa[i]) % M) % M; 
    }

    vector<pii> ans;

    if(hash == H) {
        ans.push_back(make_pair(0, a[0] ^ b[0]));
    }
    
    for(int i = 0; i < n-1; i++) {
        hash = ((hash - (xa[i]*power(B, n-1)) % M) + M) % M;
        hash = (hash * B) % M;
        hash = (hash + xa[i]) % M;
        // cout << hash << "  -- hsh " << H << endl ;
        if(hash == H) {
            ans.push_back(make_pair(i+1, a[i+1]^b[0]));
        }
    }

    // if(ans.size() > 0)
    //     cout << ans.size() << endl;
    for(int i = 0 ; i < ans.size(); i++) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }


    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_keyence2020() {
	ll h, w, n;
	ll ans = 0;
	cin >> h >> w >> n;

	if (h > w) {
		ans = (ceil)((double)n / h);
	}
	else {
		ans = (ceil)((double)n / w);
	}

	cout << ans << "\n";
}

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

	solve_keyence2020();

	return 0;
}


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

if (b-a)*(d-c)>0 and max(a,b) < min(c,d):
  for i in range(min(a,b)-1,max(c,d)):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  print('Yes')

elif (b-a)*(d-c)>0 and max(a,b) > min(c,d):
  for i in range(a-1,c):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  for i in range(b-1,d):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  print('Yes')
 
else:
  for i in range(min(a,b)-1,max(c,d)):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  for i in range(max(a,b)-1,min(c,d)):
    if s[i-1]=='.' and s[i]=='.' and s[i+1]=='.':
      print('Yes')
      exit()
  print('No')

Measured memory_bytes: 61296
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		int a , b;
		String str = br.readLine();
		String strARY[] = str.split(" ");
		
		a= Integer.parseInt(strARY[0]);
		b = Integer.parseInt(strARY[1]);
		
		System.out.println((a*b) + " " + (a+b)*2);
		
		
	
	}
}

Measured memory_bytes: 16896
/* Your prologue will be the story. */
/* Copyright by HenryLi */
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<sstream>
#include<stack>
#include<ctime>
#include<cmath>
#include<cctype>
#include<climits>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<bitset>
#include<complex>
using namespace std;
template <class _T> inline void read(_T &_x) {
	int _t; bool _flag=false;
	while((_t=getchar())!='-'&&(_t<'0'||_t>'9')) ;
	if(_t=='-') _flag=true,_t=getchar(); _x=_t-'0';
	while((_t=getchar())>='0'&&_t<='9') _x=_x*10+_t-'0';
	if(_flag) _x=-_x;
}
typedef long long LL;
const int maxn = 100010;
int n, l[maxn], r[maxn];
int main() {
	//freopen("C.in","r",stdin);
	//freopen("C.out","w",stdout);
	read(n);
	for (int i = 1; i <= n; ++i) read(l[i]), read(r[i]);
	sort(l, l + n + 1), sort(r, r + n + 1);
	LL ans = 0;
	for (int i = 0; i <= n; ++i) ans += max(l[n - i] - r[i], 0);
	cout << ans * 2 << endl;
	return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

// G13E_5.cpp

const LL MOD = 1000000007;

void mat_prod(LL a[3][3], LL b[3][3], LL c[3][3]) { // a = b * c;
	LL d[3][3];
	inc(i, 3) {
	inc(j, 3) {
		d[i][j] = 0;
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
	inc(k, 3) {
		(d[i][j] += b[i][k] * c[k][j]) %= MOD;
	}
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = d[i][j];
	}
	}
}

void mat_exp(LL a[3][3], LL b[3][3], LL c) { // a = b ^ c;
	static LL t[60][3][3];
	static bool flag = true;
	
	if(flag) { // いいかげんな高速化
		inc(i, 3) {
		inc(j, 3) {
			t[0][i][j] = b[i][j];
		}
		}
		inc(i, 60 - 1) {
			mat_prod(t[i + 1], t[i], t[i]);
		}
		flag = false;
	}
	
	LL cc = c, d = 0;
	while(cc) { cc >>= 1; d++; }
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = 0;
	}
	}
	inc(i, 3) { a[i][i] = 1; }
	inc(i, d) {
		if((c >> i) & 1) {
			mat_prod(a, a, t[i]);
		}
	}
}

LL n, m, x[100002];

int main() {
	cin >> n >> m;
	inc1(i, m) { cin >> x[i]; }
	x[0] = 0;
	x[m + 1] = n + 1;
	
	LL a[3][3] = { { 2, 1, 1 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL b[3][3] = { { 1, 0, 0 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL c[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
	LL d[3][3];
	
	inc(i, m + 1) {
		if(i != 0) { mat_prod(c, b, c); }
		mat_exp(d, a, x[i + 1] - x[i] - 1);
		mat_prod(c, d, c);
	}
	
	cout << c[2][0] << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

int main(){
    int n;
    cin >> n;
    vi b(n-1);
    rep(i, n-1)  cin >> b[i];

    int ans;

    if(n==2){
        ans = 2*b[0];
    }else{
        ans = b[0] + b[n-2];
        for(int i=0;i<n-2;i++){
            ans += min(b[i], b[i+1]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n,p=map(int,input().split())
a=list(map(lambda x: x%2, map(int,input().split())))
e=a.count(0)

ans=2**(n-1)
if p==1 and e==n:
    ans=0
if p==0 and e==n:
    ans=2**n
print(ans)

    


Measured memory_bytes: 3060
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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


def ask(la):
    out = "?"
    for a in la:
        out += " " + str(a+1)
    print(out, flush=True)
    c = input()
    return c

def answer(ans):
    out = "! "
    for a in ans:
        if a == 'Red':
            out += "R"
        else:
            out += "B"
    print(out, flush=True)
    return

def find_same(n):
    ids = [i for i in range(2*n)]
    l = 0
    r = n
    bc = ask(ids[:n])
    while (r-l > 1):
        mid = (l+r)//2
        c = ask(ids[mid:mid+n])
        if c == bc:
            l = mid
        else:
            r = mid
    return ids[l+1:l+n]

def main():
    n = ri()
    ids = [i for i in range(2*n)]
    ans = [None for _ in range(2*n)]
    if n == 1:
        c = ask([0])
        if c == 'Red':
            ans[0] = 'Red'
            ans[1] = 'Blue'
        else:
            ans[0] = 'Blue'
            ans[1] = 'Red'
        answer(ans)
        return
        
    # bef = None
    # same = None
    # for i in range(n):
    #     c = ask(ids[i:i+n])
    #     if bef != None and c != bef:
    #         # print("!!!!!!", bef, c)
    #         ans[i-1] = bef
    #         ans[i+n-1] = c
    #         same = ids[i:i+n-1]
    #         break
    #     bef = c
    same = find_same(n)
    # print(ans)
    for i in range(same[0]):
        if ans[i] is not None:
            continue
        ids = [i] + same
        c = ask(ids)
        ans[i] = c
    for i in range(same[-1]+1, 2*n):
        if ans[i] is not None:
            continue
        ids = same + [i]
        c = ask(ids)
        ans[i] = c
    # print(ans)
    half = (n-1) // 2
    cr = 0
    cb = 0
    same2 = []
    for i in range(2*n):
        if ans[i] is None:
            continue
        if ans[i] == "Red":
            if cr < half:
                same2.append(i)
                cr += 1
        else:
            if cb < half:
                same2.append(i)
                cb += 1
    for i in range(same[0], same[-1]+1):
        ids = [i] + same2 
        c = ask(ids)
        ans[i] = c
    answer(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 4032
// Problem : A - Station and Bus
// Contest : AtCoder - AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    string s;
    cin>>s;
    set<char> st;
    for(char c : s) st.insert(c);
    if(sz(st) > 1) cout<<"Yes\n";
    else cout<<"No\n";
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, int num=0){
  if(num == 0) num = (int)v.size();
  for(int i=0; i<num; i++){ cout << v[i]; if(i!=num-1) cout << " ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  for(int i=0; i<num; i++){ cout << v[i].first << v[i].second; if(i!=num-1) cout << " ";}
  cout << endl;
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

template <typename T>
void SWAP(T &a, T &b){
  a = a^b;// a^b 
  b = a^b;// (a^b)^b
  a = a^b;// (a^b)^(a^b^b)
}

template <typename T>
void insertionSort(vector<T> &a, T N){
  //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A&lang=ja
  print_vec(a);
  for(int i=0; i<N-1; i++){
    int j = i;
    while(j>=0 && a[j] > a[j+1]){
      SWAP(a[j], a[j+1]);
      j--;
    }
    print_vec(a);
  }
}
template <typename T>
void bubbleSort(vector<T> &a, int n){
  //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=ja
  ll num = 0;
  for(int i=0; i<n; i++){
    for(int j=n-1; j>i; j--){
      if(a[j-1] > a[j]){
        SWAP(a[j-1], a[j]);
        num++;
      }
    }
  }
  print_vec(a);
  cout << num << endl;
  return;
}

template <typename T>
void selectionSort(vector<T> &a, int n){
  ll num = 0;
  for(int i=0; i<n; i++){
    int min_id = i;
    for(int j=i+1; j<n; j++){
      if(a[min_id] > a[j]) min_id = j;
    }
    if(min_id != i){
      num++;
      SWAP(a[i], a[min_id]);
    }
  }
  print_vec(a);
  cout << num << endl;
  return;
}

using cP = pair<char, int>;
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C&lang=ja
void BubbleSort(vector<cP> &a, int n){
  for(int i=0; i<n; i++){
    for(int j=n-1; j>i; j--){
      if(a[j-1].second > a[j].second) swap(a[j-1], a[j]);
    }
  }
}

void SelectionSort(vector<cP> &a, int n){
  for(int i=0; i<n; i++){
    int min_id = i;
    for(int j=i+1; j<n; j++){
      if(a[min_id].second > a[j].second) min_id = j;
    }
    if(min_id != i) swap(a[i], a[min_id]);
  }
}
int main(){
  int n;
  cin >> n;
  // vector<int> a(n);
  // for(int i=0; i<n; i++) cin >> a[i];
  // insertionSort(a, n);
  // bubbleSort(a, n);
  // selectionSort(a, n);

  vector<cP> a(n), b, c;
  for(int i=0; i<n; i++) cin >> a[i].first >> a[i].second;
  b = a;
  c = a;
  BubbleSort(b, n);
  SelectionSort(c, n);

  print_pairvec(b);
  cout << "Stable" << endl;//BubbleSortは常に安定
  print_pairvec(c);
  if(b==c) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  return 0;
}




Measured memory_bytes: 3112
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
const int mod = 1000000007;
struct mint {
int64_t x;
mint(int64_t x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod;return *this;}
mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod;return *this;}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(int64_t t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) {return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
ll n;
vec<int> res;
vec<vec<pint>> g;

void dfs(ll v, ll p, ll w){
    res[v] = w;
    for(auto e:g[v]){
        if(e.first != p){
            if(e.second%2==1) dfs(e.first,v,1-w);
            else dfs(e.first,v,w);
        }
    }
}

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

    cin>>n;
    g.assign(n, vec<pint>());
    res.assign(n,0);
    rep(i,n-1){
        ll u,v,w;
        cin>>u>>v>>w;
        u--;v--;
        g[u].push_back(pint(v,w));
        g[v].push_back(pint(u,w));
    }

    dfs(0,-1,0);

    for(auto c: res) cout<<c<<endl;
    
}

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

int main(){
  double N, K;
  cin >> N >> K;
  double Ans;
  for(int i=1; i<=N; i++){
    if(i>=K){
      Ans+=1/N;
    }
    else{
      int k=i;
      while(k<K){
        k*=2;
      }
      Ans+=i/(N*k);
    }
  }
  cout << setprecision(20) << Ans << endl;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> a;
    int m;
    if(n==0){
    cout<<0<<endl;
    return 0;
    }
        while(n!=0){
            a.push_back(abs(n%2));
            n=(n-abs(n%2))/(-2);//切り捨てを信用しない
        }
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();i++){
        cout<<a.at(i);
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
    double x;
    cin >> x;
    int ans = -1;
    if(x == 1){
          ans = 1;
    }else{
          for(int i = 2;i * i <= x;i++){
                int temp = i * i;
                while(temp <= x){
                      temp *= i;
                }
                temp /= i;
                ans = max(ans,temp);
          }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

const int N = int(1e5 + 5);
const int mod = int(1e9 + 7);
const double eps = 1e-9;
const double pi = 3.1415926535897932384626433832795;

multiset<int> s;

void solve() {
  s.insert(-1);
  int n; scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x; scanf("%d", &x);
    auto j = s.lower_bound(x);
    if (j != s.begin()) {
      j--; s.erase(j);
    }
    s.insert(x);
  }
  printf("%d\n", s.size());
}

int main() {
  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
  int tests = 1;
  //scanf("%d", &tests);
  while (tests--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 4992
// ?????¬???????????¬??????

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, K, T, U, V, L;
bool point[10010];

signed main() {
    cin >> N >> K >> T >> U >> V >> L;
    rep(i,0,N) {
        int p; cin >> p;
        point[p] = true;
    }

    int stock = 0, prev = -1, da = 0, db = 0;
    repq(i,1,L) {
        if((prev < 0 || prev + T*V < i) && stock) prev = i-1, stock--;
        (prev < 0 || prev + T*V < i ? da : db)++;
        if(point[i]) {
            if(stock == K) prev = i;
            else stock++;
        }
    }
    double ans = 1.0 * da / U + 1.0 * db / V;
    printf("%.12f\n", ans);
    return 0;
}

Measured memory_bytes: 3236
import java.io.{BufferedReader, IOException, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.min

object Main {
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val t = Array.ofDim[Int](N + 1) // t...tiまで累積
    (1 to N) foreach (i => t(i) = t(i - 1) + sc.nextInt())
    val v = Array.ofDim[Int](N + 2)
    (1 to N) foreach (i => v(i) = sc.nextInt())

    var ans = 0.0
    var v0 = 0.0
    var _t = 0.0
    for {
      i <- 1 to N
      _ <- 1 to (t(i) - t(i - 1)) * 2 // 0.5秒単位
    } {
      _t += 0.5
      val break = ((i to N) map (j => v(j + 1) + (t(j) - _t))).min // i+1以降の速度制限からブレーキをかけ始める場所がきまる
      val v1 = min(min(v(i), v0 + 0.5), break)
      ans += (v1 + v0) * 0.5 / 2
      v0 = v1
    }

    println(f"$ans%.4f")
  }

  def main(args: Array[String]): Unit = {
    solve()
  }

  class InputReader(val stream: InputStream) {
    val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextChar(): Char = next.charAt(0)
  }

}


Measured memory_bytes: 52484
# ARC080D - Grid Coloring (ABC069D)
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    N = int(input())
    A = tuple(map(int, input().split()))
    F = []  # flatten grid
    for color, cnt in enumerate(A, 1):
        F += [color] * cnt
    for p, i in enumerate(range(1, H + 1), 1):
        if p & 1:  # odd rows (1-idx)
            print(*F[(i - 1) * W : i * W])
        else:
            print(*F[(i - 1) * W : i * W][::-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 3828
#include<cstdio>
int main(){
    int S[10000];
    int T[500];
    int n,q;
    int nums = 0;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d",&S[i]);
    scanf("%d", &q);
    for(int i=0; i<q; i++)
        scanf("%d",&T[i]);
    for(int i=0; i<q; i++)
    {
        for(int j=0; j<n; j++)
        {
            if(T[i] == S[j])
            {
                nums++;
                break;
            }
        }
    }
    printf("%d\n",nums);
    
    return 0;
}


Measured memory_bytes: 2708
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
 
#define pb push_back
#define mp make_pair

typedef long long ll; 

#define fi first
#define se second
 
#define all(x) (x).begin(), (x).end()
 
using namespace std;             
//using namespace __gnu_pbds;
 
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int INF = (int)1e10;
const int MAXN = (int)1e5 + 500;

int n, a[MAXN], b[MAXN], c[MAXN];
int dp[4][MAXN];

void solve() {       
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[1][1] = a[1];
    dp[2][1] = b[1];
    dp[3][1] = c[1];
    for (int i = 2; i <= n; i++) {                                       
        dp[1][i] = max(dp[2][i - 1], dp[3][i - 1]) + a[i];
        dp[2][i] = max(dp[1][i - 1], dp[3][i - 1]) + b[i];
        dp[3][i] = max(dp[2][i - 1], dp[1][i - 1]) + c[i];
    }
    cout << max(max(dp[1][n], dp[2][n]), dp[3][n]);
}           
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int tt = 1;
 
    while (tt--) {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 2688
N, M = gets.split.map(&:to_i)

ac = Array.new(N, 0)
wa = Array.new(N, 0)
wa_sum = 0

(0..(M-1)).each do |i|
  p, s = gets.split
  p = p.to_i
  s = s.chomp
  if ac[p - 1] == 0
    if s == "WA"
      wa[p - 1] += 1
    else
      ac[p - 1] = 1
    end
  end
end

(0..(N-1)).each do |i|
  if ac[i] == 1
    wa_sum += wa[i]
  end
end

puts "#{ac.inject(:+)} #{wa_sum}"

Measured memory_bytes: 3836