akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, K, i, A[200001], st=-1, en=-1, en_num=-1, pos, cnt=1;
    set<ll> se;

    cin >> N >> K;

    for(i=1; i<=N; i++){
        cin >> A[i];
    }

    // 始点
    se.insert(1);

    pos = A[1];

    while(1){
        if(se.count(pos)){
            en = cnt;
            en_num = pos;
            break; 
        }

        cnt++;
        se.insert(pos);
        pos = A[pos];
    }

    cnt = 0;

    pos = 1;

    if(pos==en_num) st = cnt;
    
    else{
        while(1){
            if(pos==en_num){
                st = cnt;
                break;
            }

            cnt++;
            pos = A[pos];
        }
    }
    
    if(K < st){
        pos = 1;

        for(i=1; i<=K; i++){
            pos = A[pos];
        }

        cout << pos << endl;
    }

    else{
        pos = en_num;

        ll x = (K-st) % (en-st);

        for(i=1; i<=x; i++){
            pos = A[pos];
        }

        cout << pos << endl;
    }

    return 0;
}

Measured memory_bytes: 14396
#include <cstdio>
const long long MOD = 1000000007;
int N, M, a[100001];
long long bit[31][4][4], f[4];
void MUL(long long (*a)[4], long long (*b)[4], long long (*c)[4])
{
	static long long tmp[4][4];
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 4; j++)
		{
			tmp[i][j] = 0;
			for (int k = 0; k < 4; k++)
				tmp[i][j] = (tmp[i][j] + a[i][k] * b[k][j]) % MOD;
		}
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 4; j++)
			c[i][j] = tmp[i][j];
}
void PBK(long long *f, long long (*a)[4], long long *g)
{
	static long long tmp[4];
	for (int i = 0; i < 4; i++)
	{
		tmp[i] = 0;
		for (int j = 0; j < 4; j++)
			tmp[i] = (tmp[i] + f[j] * a[j][i]) % MOD;
	}
	for (int i = 0; i < 4; i++)
		g[i] = tmp[i];
}
void PBK(long long *f, long long n, long long *g)
{
	static long long tmp[4];
	tmp[2] = tmp[3] = ((f[0] * n + f[1] * 2) % MOD * n + f[2]) % MOD;
	tmp[0] = (f[0] + tmp[3]) % MOD;
	tmp[1] = (f[1] + f[0] * n) % MOD;
	for (int i = 0; i < 4; i++)
		g[i] = tmp[i];
}
void PWR(int L)
{
	for (int i = 0; i <= 30; i++)
		if (L >> i & 1)
			PBK(f, bit[i], f);
}
int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= M; i++)
		scanf("%d", a + i);
	f[0] = 1;
	f[1] = 0;
	f[2] = 0;
	f[3] = 1;
	bit[0][0][0] = 2;
	bit[0][1][0] = 2;
	bit[0][2][0] = 1;
	bit[0][3][0] = 0;
	bit[0][0][1] = 1;
	bit[0][1][1] = 1;
	bit[0][2][1] = 0;
	bit[0][3][1] = 0;
	bit[0][0][2] = 1;
	bit[0][1][2] = 2;
	bit[0][2][2] = 1;
	bit[0][3][2] = 0;
	bit[0][0][3] = 1;
	bit[0][1][3] = 2;
	bit[0][2][3] = 1;
	bit[0][3][3] = 0;
	for (int i = 1; i <= 30; i++)
		MUL(bit[i - 1], bit[i - 1], bit[i]);
	if (!M)
		PWR(N);
	else
	{
		a[0] = -1;
		for (int last = 0, l = 1, r; l <= M; last = r, l = r + 1)
		{
			r = l;
			while (r < M && a[r + 1] == a[r] + 1)
				r++;
			PWR(a[l] - a[last] - 2);
			PBK(f, r - l + 2, f);
		}
		PWR(N - a[M] - 1);
	}
	printf("%lld\n", f[3]);
	return 0;
}


Measured memory_bytes: 512
N = int(input())

def dfs(s,N):
    if int(s)>N:
        return 0
    if all(s.count(c)>0 for c in "753"):
        count = 1
    else:
        count = 0
    for c in "753":
        count += dfs(s+c,N)
    return count

print(dfs("0",N))


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll k;
    cin >> k;

    ll m = k/2;
    if(k%2 == 0) {
        out(m*m);
    }
    else {
        out(m*(m+1));
    }

    re0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
    
    int sum = A*X + B*Y;
    
    int i=0;
    for(; i<min(X, Y); ++i){
        int tmp = sum - A - B + 2*C;
        sum = min(sum, tmp);
    }
    for(; i<X; ++i){
        int tmp = sum - A + 2*C;
        sum = min(sum, tmp);
    }
    for(; i<Y; ++i){
        int tmp = sum - B + 2*C;
        sum = min(sum, tmp);
    }
    
    cout << sum << endl;
    
    return 0;
}

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

int main(){
  long n,ct=0;
  cin>>n;
  string s;
  cin>>s;
  
  ct=1;
  for(long i=1;i<n;i++){
    if(s[i]!=s[i-1])
      ct++;
  }
  cout<<ct<<endl;
  
  
}

Measured memory_bytes: 512
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    d=parseMap(split(readline()))
    l=maximum(d)
    cnt=[0 for i in 0:l]
    for i in d
        cnt[i+1]+=1
    end
    if 0 in cnt || d[1]>0 || cnt[1]>1
        println(0)
    else
        ans=1
        for i in 2:l+1
            ans*=powermod(cnt[i-1],cnt[i],998244353)
            ans%=998244353
        end
        println(ans)
    end
end
main()

Measured memory_bytes: 174524
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N, K = map(int, input().split())

for i in range(1, K + 1):
    if N - K + 1 < i:
        print(0)
    else:
        print((cmb(N - K + 1, i) * cmb(K - 1, i - 1)) % (10**9 + 7))


Measured memory_bytes: 3944
m, f, r = map(int, input().split())

while m+f+r != -3:
    if m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif m + f >= 65:
        print("B")
    elif m + f >= 50:
        print("C")
    elif m + f >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")

    m, f, r = map(int, input().split())

Measured memory_bytes: 7712
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979;

int main() {
  string s,u,t;
  ll a,b;
  cin>>s>>u>>a>>b>>t;
  if(s==t){
    a--;
  }
  else{
    b--;
  }
  cout<<a<<" "<<b;
}


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

int main() {
    int N;
    cin >> N;
    vector<string> s(N + 1);
    int a = 0, b = N, c = 0;
    cout << c << endl;
    cin >> s[0];
    if (s[0] == "Vacant") return 0;
    s[N] = s[0];
    while (true) {
        c = (a + b) / 2;
        cout << c << endl;
        cin >> s[c];
        if (s[c] == "Vacant") return 0;
        if ((s[c] == s[a]) ^ ((c - a) % 2 == 1)) a = c;
        else b = c;
    }
}

Measured memory_bytes: 1620
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main(){
	for (string s; getline(cin,s), s != "."; ) {
		stack<char> st;
		bool ok = true;
		rep (i, s.size()) {
			if (s[i] == ')') {
				if (st.size() == 0 || st.top() == '[') {
					ok = false;
					break;
				}
				st.pop();
			}
			else if (s[i] == ']') {
				if (st.size() == 0 || st.top() == '(') {
					ok = false;
					break;
				}
				st.pop();
			}
			else if(s[i] == '(' || s[i] == '[') {
				st.push(s[i]);
			}
		}
		if (ok && st.size() == 0) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c && c==a){
        cout<< "No"<<endl;
    }else if(a!=b && b!=c && c!=a){
        cout<< "No"<<endl;
    }else{
        cout<< "Yes"<<endl;
    }

    return 0;
}



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

int main() {
    string s,t; cin >> s >> t;
    int ss = s.size();
    int ts = t.size();
    int ans = 999999;
    rep(i, ss - ts + 1) {
        int cnt = 0;
        rep(j, ts) {
            if (s[i+j] != t[j]) cnt ++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;

}

Measured memory_bytes: 3624
// Problem Code: abc177_b

#include <bits/stdc++.h>

using namespace std;

int B(string& S, string& T) {
	int min_cnt = numeric_limits<int>::max();
	int m = S.length(), n = T.length();
	for (int i = 0; i + n - 1 < m; i++) {
		int cnt = 0;
		for (int j = i; j - i < n; j++)
			cnt += (S[j] != T[j - i]);
		min_cnt = min(cnt, min_cnt);
	}
	return min_cnt;
}

int main() {
	string S, T;
	cin >> S >> T;
	cout << B(S, T);
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
template<typename T>
vector<T> divisor(T N) {
    vector<T> res;
    for(T i = 1; i * i <= N; i++){
        if(N % i == 0){
            res.push_back(i);
            if(i * i != N)res.push_back(N / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

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

    int N, K;
    cin >> N >> K;
    vector<ll> a(N);
    rep(i,N)cin>>a[i];
    ll sum = accumulate(all(a), 0LL);
    auto check = [&](ll X){
        if(X == 0)return true;
        // a[i]をXの倍数にするのにかかる移動の回数
        vector<ll> b(N),mi(N),pl(N);
        rep(i, N)b[i] = a[i];
        rep(i, N){
            b[i] %= X;
            mi[i] = b[i];
            pl[i] = X - b[i];
        }
        ll sumod = accumulate(all(mi), 0LL);
        sort(all(mi));
        //cerr<<"X, sum_mod: "<<X << " "<<sumod << endl;
        //print(mi);
        if(sumod % X != 0)return false;
        ll lsum = 0;
        for(int i = 0; i < N; i++){
            lsum += mi[i];
            int r = N - 1 - i;
            ll rsum = X * r  - (sumod - lsum);
            if(lsum == rsum){
                return lsum <= K;
            }
            //cerr << lsum << " " << rsum << endl;
        }
        //cerr << endl;
        return false;
    };
    auto v = divisor(sum);
    ll ans = 1;
    for(auto x : v){
        if(check(x)){
            ans = x;
        }
    }
    cout << ans << endl;
}

/*
A全てのGCDの最大値。
sum(A)は不変。
K回まで、二要素を選んで+1, -1する権利がある。

考えたこと：単調性、なし
sumの約数にしかならないので、それを全て試せば終わりか？
それになれるかどうかのチェックに時間がかかるが、できそう

*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define pint pair<int,int>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	char s[5];	cin>>s;
	if(s[0]=='1')	cout<<"9";
	else	cout<<"1";
	if(s[1]=='1')	cout<<"9";
	else	cout<<"1";
	if(s[2]=='1')	cout<<"9";
	else	cout<<"1";
	return 0;
}

Measured memory_bytes: 256
line = readlines
len = line.length
i = 0

while i < len
    line[i] = line[i].chomp.split(' ')
    i += 1
end

result = 0
x = line[0][0]
a = x.to_i/100

def cal(x,a)
 for i in 0..a 
   for j in 0..a-i
     for k in 0..a-i-j
       for l in 0..a-i-j-k
         for m in 0..a-i-j-k-l
           for n in 0..a-i-j-k-l-m
             total = 100 * i + 101 * j + 102 * k + 103 * l + 104 * m + 105 * n
             if total === x.to_i then
               return "1"
             end
           end
         end
       end
     end
   end
 end
end
  
if cal(x,a) == "1" then
  puts "1"
else
  puts "0"
end

Measured memory_bytes: 1788
A = list(map(int, open(0).read().split()))

import numpy as np

if len([(x%10, i) for i,x in enumerate(A) if x%10!=0]) == 0:
    print(sum(A))
else:
    last_order = A[min([(x%10, i) for i,x in enumerate(A) if x%10!=0])[1]]
    print(sum(A) + sum(10 - np.array([x%10 for x in A if x%10!=0])) - (10 - min([x%10 for x in A if x%10!=0])))

Measured memory_bytes: 12460
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
using namespace std;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
#define INF 1e+8
#define EPS 1e-7
#define PB push_back
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
typedef pair<int,int> Pii;
typedef vector<int> vi;
class data{
    public:
    int ay;
    int ax;
    int by;
    int bx;
    int cnt;
    data(){}
    data(int _ay,int _ax,int _by,int _bx,int _cnt){
        ay = _ay;
        ax = _ax;
        by = _by;
        bx = _bx;
        cnt = _cnt;
    }
};
bool memo[52][52][52][52];
int main(){
    int W,H;
    while(scanf("%d%d",&W,&H),W){
        memset(memo,0,sizeof(memo));
        int ax,ay;
        int bx,by;
        int stage[52][52];
        scanf("%d%d",&ax,&ay);
        scanf("%d%d",&bx,&by);
        ax--;ay--;bx--;by--;
        rep(i,H){
            rep(j,W){
                scanf("%d",&stage[i][j]);
            }
        }
        queue < data > Q;
        Q.push(data(ay,ax,by,bx,0));
        memo[ay][ax][by][bx] = 1;
        int ans = -1;
        while(!Q.empty()){
            data d = Q.front();Q.pop();
            if(d.cnt > 99){
                break;
            }
            if(d.ax == d.bx && d.ay == d.by){
                ans = d.cnt;
                break;
            }
            rep(i,4){
                int nay,nax;
                int nby,nbx;
                nax = d.ax+dx[i];
                nay = d.ay+dy[i];
                nbx = d.bx+dx[(i+2)%4];
                nby = d.by+dy[(i+2)%4];
                if(nax < 0 || nax > W-1 || nay < 0 || nay > H-1 || stage[nay][nax]){
                    if(nbx < 0 || nbx > W-1 || nby < 0 || nby > H-1 || stage[nby][nbx])continue;
                    if(memo[d.ay][d.ax][nby][nbx]++)continue;
                    Q.push(data(d.ay,d.ax,nby,nbx,d.cnt+1));
                }
                else if(nbx < 0 || nbx > W-1 || nby < 0 || nby > H-1 || stage[nby][nbx]){
                    if(memo[nay][nax][d.by][d.bx]++)continue;
                    Q.push(data(nay,nax,d.by,d.bx,d.cnt+1));
                }
                else{
                    if(memo[nay][nax][nby][nbx]++)continue;
                    Q.push(data(nay,nax,nby,nbx,d.cnt+1));
                }
            }
        }
        if(ans == -1)puts("NA");
        else printf("%d\n",ans);
    }
    return 0;
}

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

def cf(x1,x2):
    cf=[]
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

print(cf(a,b)[-k])


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int L,R,d,D,N;
  cin >> L >> R >> d;
  
  N = 0;
  D = 0;
  
  for (int i=0; i<101 ;i++) {
    D = d*i;
    if ( D >= L && D <= R ) {
      N = N + 1;
    }
    else {      
    }      
  }
  
  cout << N << endl;
  
}

Measured memory_bytes: 3580
char buf[1100000];
sz;
T;
main()
{
	read(0,buf,1100000);
	while(buf[sz]&16)++sz;
	while(buf[++sz]&16)
	{
		while(buf[sz]&16)++sz;
		T^=buf[sz-1]&1;
	}
	write(1,T?"NO\n":"YES",3);
}


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

string s;

int main()
{
    cin >> s;
    int N = s.size();
    for (int i = 0; i < N - 1; i++)
    {
        if (s[i] == s[i+1])
        {
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
    }
    for (int i = 0; i < N - 1; i++)
    {
        if (s[i] == s[i+2])
        {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <utility>
#include <queue>
using namespace std;
typedef pair<double,double> pi;
#define F first
#define S second
struct cmp{
    bool operator()(const pi &a,const pi &b){
        return a.F<b.F;
    }
};
int main(){
    int n;
    double w;
    double ans=0;
    priority_queue<pi,vector<pi>,cmp>pq;
    pi temp;
    scanf("%d%lf",&n,&w);
    while(n--){
        scanf("%lf%lf",&temp.F,&temp.S);
        temp.F/=temp.S;
        pq.push(temp);
    }
    while(!pq.empty()){
        temp=pq.top();
        pq.pop();
        if(w>temp.S){
            w-=temp.S;
            ans+=temp.S*temp.F;
        }
        else {
            ans+=w*temp.F;
            break;
        }
    }
    printf("%.20lf\n",ans);
}


Measured memory_bytes: 4488
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#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 gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<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;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n;
  scanf("%d",&n);
  vi a(n*3);
  cin>>a;
  ll ans = 0;
  sort(rng(a));
  reverse(rng(a));
  rep(i,n) ans += a[i*2+1];
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 1408
#include <string>
#include <vector>
#include <iostream>
using namespace std;
string s;
int main() {
	cin >> s;
	int n = s.size();
	int l = 0, r = n, cnt = 0; bool f = true;
	while (l < r) {
		if (s[l] == s[r - 1]) l++, r--;
		else if (s[l] == 'x') cnt++, l++;
		else if (s[r - 1] == 'x') cnt++, r--;
		else {
			f = false;
			break;
		}
	}
	if (!f) cout << -1 << endl;
	else cout << cnt << endl;
	return 0;
}

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

int main()
{
    long long n, a, b, ans;
    cin >> n >> a >> b;
    
    if(b<a || (n == 1 && a != b)) ans = 0;
    else ans = (n-2) * (b - a) + 1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3576
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#include <bitset>
#define LL long long
#define NUM 1000000007

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> v(h);
    for (size_t i = 0; i < h; i++)
    {
        cin >> v[i];
    }
    for (size_t i = 0; i < h; i++)
    {
        cout << v[i] << endl << v[i] << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int max = 1;
        int cnt = 1;
        for (int i = 1 ; i < 4 ; i++) {
            if (s.charAt(i) == s.charAt(i-1)) cnt++;
            else cnt = 1;
            max = Math.max(max, cnt);
        }
        System.out.println(max >= 3 ? "Yes" : "No");
    }
}

Measured memory_bytes: 23764
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]

a = []
for i in range(m):
    a.append(input().split())

result_dic = {}

for i in range(n):
    result_dic[str(i+1)] = {'AC': 0, 'WA': 0}

for aa in a:
    if result_dic[aa[0]]['AC'] == 0:
        result_dic[aa[0]][aa[1]] += 1


ac_sum = 0
wa_sum = 0
for i in range(n):
    if result_dic[str(i+1)]['AC'] > 0:
        ac_sum += 1
        wa_sum += result_dic[str(i+1)]['WA']

print(str(ac_sum) + ' ' + str(wa_sum))

Measured memory_bytes: 73676
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;

const double g=10.0,eps=1e-7;
const int N=200000+10,maxn=60000+10,inf=0x3f3f3f;

void debug(){cout<<-1<<endl;}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=3500;i++)
    {
        for(int j=1;j<=3500;j++)
        {
            ll x=(ll)n*i*j,y=(ll)4*i*j-n*(i+j);
            if(x>0&&y>0&&x%y==0)
            {
                cout<<i<<" "<<j<<" "<<x/y<<endl;
                return 0;
            }
        }
    }
    return 0;
}
/********************

********************/


Measured memory_bytes: 256
import math


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors


n = int(input())

d2 = make_divisors(n - 1)
ans = len(d2)

for k in make_divisors(n):
    if k == 1:
        continue
    tmp = n
    while tmp % k == 0:
        tmp //= k

    if tmp % k == 1:
        d2.append(k)

print(len(d2) - 1)


Measured memory_bytes: 39280
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int a, b;
	cin >> a >> b;
	
	if( a > 8 || b > 8 ) cout << ":(" << endl;
	else cout << "Yay!" << endl;
	
	return 0;
}


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

int n(int x, int y){
    if(y >= x) return y-x;
    else return 2+x-y;
}

int main(){
    int x, y;
    cin >> x >> y;
    int ans = min(min(n(x,y),n(-x,y)+1),min(n(x,-y)+1,n(-x,-y)+2));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s;
    cin >> s;
    cout << s.substr(0,3) << endl;
}

signed main() {
    solve();
    
    return 0;
}

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

#define fou(i,a,n) for(int i=a;i<n;i++)
int main() {
    string s;
    int ans = 0;
    cin >> s; 
    fou(i, 0, 4){
        if (s[i] == '1') {ans++;}
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
using System;
using System.Linq;

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

			var searchStr = Console.ReadLine ().Split (' ').Select (int.Parse);

			arraySize = int.Parse (Console.ReadLine ());
			arraySize.GetType ();

			var elementStr = Console.ReadLine ().Split (' ').Select (int.Parse);

			int findCount = 0;
			foreach (var item in elementStr)
			{
				bool isContain = searchStr.Any (item2 => item == item2);

				if (isContain)
				{
					findCount++;
				}
			}

			Console.WriteLine (findCount);
		}
	}
}

Measured memory_bytes: 9936
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(vector<int>& A) {
        int n = A.size();
        vector<bool> ok(n + 123, false);
        ok[0] = true;

        int res = 0;
        for (int i = 0; i < n; ++i) {
            int x = A[i];
            if (ok[x - 1]) {
                if (!ok[x]) {
                    ++res;
                    ok[x] = true;
                }
            }
        }

        res = n - res;
        return res < n ? res : -1;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    Solution sol;
    cout << sol.solve(A) << "\n";

    return 0;
}

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

ll gcd(ll a, ll b){ return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b){ return a/gcd(a,b)*b; }

void solve(long long N, std::vector<long long> T){
    ll ans = T[0];
    for(int i = 1; i < N; ++i){
        ans = lcm(ans, T[i]);
    }
    cout << ans << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> T(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&T[i]);
    }
    solve(N, std::move(T));
    return 0;
}


Measured memory_bytes: 3700
N=int(input()) 

t=[[0]*10 for _ in range(10)]
for i in range(1,N+1):
  s=str(i)
  t[int(s[0])][int(s[-1])]+=1
  
result=0
for i in range(1,10):
  for j in range(1,10):
    result+=t[i][j]*t[j][i]
    
print(result)

Measured memory_bytes: 3064
s = input()[::-1]
lst = [l[::-1] for l in ['dream', 'dreamer', 'erase', 'eraser']]
while len(s):
    flg = False
    if s[:5] == lst[0]:
        s = s[5:]
        flg = True
    elif s[:7] == lst[1]:
        s = s[7:]
        flg = True
    elif s[:5] == lst[2]:
        s = s[5:]
        flg = True
    elif s[:6] == lst[3]:
        s = s[6:]
        flg = True
    if flg is False:
        break
print('YES' if len(s)==0 else 'NO')

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

int main(){
  int N, K;
  cin >> N >> K;
  int Num = 1;
  rep(i,N){
    if(Num < K)
      Num *= 2;
    else
      Num += K;
  }
  cout << Num <<endl;
}

Measured memory_bytes: 256
n,x = map(int,input().split())
a = list(map(int,input().split()))
tmp = [0]*n
tmp[0] = a[0] if a[0] < x else x
val = a[0]
for i in range(n-1):
    if a[i+1] + val > x:
        tmp[i+1] = max(0,x-val)
    else:tmp[i+1] = a[i+1]
    val = tmp[i+1]

ans = 0
for i in range(n):
    ans += a[i] - tmp[i]
print(ans)

        
    


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

int main(void){
	double w, h, x, y;
	cin >> w >> h >> x >> y;

	cout << (w * h * 0.5) << endl;
	cout << ((x * 2 == w && y * 2 == h) ? 1 : 0) << endl;

	return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
//m.emplace(x,0).fi->se++;

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll h,w,n;cin>>h>>w>>n;
  vector<P>x(n);
  rep(i,0,n)cin>>x[i].fi>>x[i].se;
  res=h;
  sort(ALL(x));
  ll countbuf=0;
  rep(i,0,n){
    if(x[i].fi==x[i].se+countbuf)countbuf++;
    else if(x[i].fi>x[i].se+countbuf){
      chmin(res,x[i].fi-1);
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>

int main(void) {
	int x, i;
	scanf("%d", &x);
	
	i=1;
	
	do{printf("Case %d: %d\n", i, x);
		scanf("%d", &x);
		i=i+1;
	}
	while(x!=0);

	
	return 0;
}

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

signed main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int& i:a)cin>>i,--i;
    if(a[0]==0)
        return cout << 1, 0;
    map<int, int> vis;
    int cur = 0, prd, ph;
    vis[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        if(vis.count(a[cur])>0){
            prd = i - vis[a[cur]];
            ph = vis[a[cur]];
            cur = 0;
            break;
        }
        cur = a[cur];
        vis[cur] = i;
    }
    while (k > 0 && ph > 0)
        cur = a[cur], --k, --ph;
    k %= prd;
    while(k--)
        cur = a[cur];
    cout << cur + 1;
}

Measured memory_bytes: 17020
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> res;
vector<int> temp;
stack<int> st;
#define pb push_back 
#define vi vector<int>

const int inf=2e5+5;


vector<int> adj[inf];
vector<int> rev[inf];

void dfs(vi &vis,int s){
    vis[s]=1;
    bool ok=true;
    for(auto x:adj[s]){
        if(vis[x]==0){
            ok=false;
            dfs(vis,x);
        }
    }
    st.push(s);

}

void dfs1(vi &vis,int s){
    vis[s]=1;
    temp.pb(s);
    for(auto x:rev[s]){
        if(vis[x]==0){
            dfs1(vis,x);
        }
    }
   
}
void kosaraju(int nd)
{
    res.clear();
    temp.clear();
    vi vis(nd);
    for(int i=0;i<nd;i++){
        if(vis[i]==0){
            dfs(vis,i);
        }
    }
    vis.clear();
    vis.resize(nd);
    fill(vis.begin(),vis.end(),0);
    
    for(int i=0;i<nd;i++){
        for(auto x:adj[i]){
            rev[x].pb(i);
        }
    }
    while(!st.empty()){
        int i=st.top();
        st.pop();
        if(!vis[i]){
            dfs1(vis,i);
            res.pb(temp);
            temp.clear();
        }
    }
    //return res;

}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    kosaraju(n);
    int ss=res.size();
    vi boxes;
    for(int i=0;i<ss;i++){
        boxes.pb(res[i].size());
    }
    /*for(auto x:boxes){
        cout<<x<<" ";
    }*/
    //cout<<endl;
    sort(boxes.begin(),boxes.end());
    long ans=0;
    int comp=0;
    for(int i=0;i<boxes.size();i++){
        if(i==0) {
            comp+=boxes[i];
            ans+=boxes[i];
        }
        else{
            if(boxes[i]>comp){
                ans+=boxes[i]-comp;
                comp+=boxes[i]-comp;
                //ans+=boxes[i]-comp;
            }
        }
    }
    cout<<ans;
    return 0;


}

Measured memory_bytes: 37540
#include <bits/stdc++.h>
#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 rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back

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=3e3+10;
const ll MOD=1e9+7;

int N;
string S;
ll dp[MAX][MAX];
ll sum[MAX][MAX];
void solve(){
    cin>>N;
    cin>>S;

    dp[0][0]=1;
  	sum[0][0]=0;
  	sum[0][1]=1;
    rep1(i,N-1){
        rep(la,i+1){
            if(S[i-1]=='<'){
                dp[i][la]=sum[i-1][la];
            }
            else{
                dp[i][la]=(sum[i-1][i]-sum[i-1][la]+MOD)%MOD;
            }
        }
        sum[i][0]=0;
        rep1(la,i+1)sum[i][la]=(sum[i][la-1]+dp[i][la-1])%MOD;
    }
    cout<<sum[N-1][N];
}

int main(){
    solve();
}

Measured memory_bytes: 139904
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(left(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	cout << (n*m) - (n+m-1);
	return 0;
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        int M = cin.nextint;
        int X = cin.nextint;
        int Y = cin.nextint;
        var x = cin.scanint;
        var y = cin.scanint;
        int zmin = x.Max() + 1;
        int zmax = y.Min();
        for (int i = zmin; i <= zmax; i++)
        {
            if (X < i && i <= Y)
            {
                WriteLine("No War");
                return;
            }
        }
        WriteLine("War");

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n,m;
    cin >> n >> m;
    
    vector<int> s_arr(m);
    for(int i=0;i<m;++i){
        int k; cin >> k;
        s_arr[i] = 0;
        for(int j=0; j < k; ++j){
            int num;
            cin >> num;
            s_arr[i] |= (1<<(num-1));
        }
    }
    
    vector<int> p_arr(m);
    for(int i=0;i<m;++i){
        cin >> p_arr[i];
    }

    int ans = 0;
    for(int i=0; i<(1<<n); ++i){ // スイッチONOFFの組み合わせについて
        for(int j=0; j<m; ++j){ // 各電球について
        
            int sum = 0;
            for(int k=0;k<n;++k){
                if(s_arr[j] & ((1<<k) & i)){
                    sum++;
                }
            }
            if(sum % 2 == p_arr[j]){
                if( j == m-1 ){
                    ans++;
                }
            }
            else {
                break;
            }
        }
    }

    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    vector<int> a;
    rep(i,5){
        int v; 
        cin>>v;
        a.push_back(v);
    }
    int ans=0;
    rep(i,5){
        if(a[i]==0) {
            ans=i+1;
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int A , B, K;
    cin >> A >> B >> K;
    
    int ans = 0;
    int Nnum = min(A, B);
    while(true){
        if((A % Nnum == 0) && (B % Nnum == 0)){
            ++ans;
            if(ans == K){
            cout << Nnum << endl;
            return 0;
            }
        }
        --Nnum;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	double a,b,c,S,L,h;
	
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str;
	str=input.readLine();
	String strary[]=str.split(" ");
	a=Double.parseDouble(strary[0]);
	b=Double.parseDouble(strary[1]);
	c=Double.parseDouble(strary[2]);
	S=((a*b)*(Math.sin(Math.toRadians(c)))/2);
	L=a+b+Math.sqrt(Math.pow(a,2)+Math.pow(b,2)-2*a*b*(Math.cos(Math.toRadians(c))));
	h=(2*S)/a;
	System.out.printf("%f %f %f\n",S,L,h);
    }
}

Measured memory_bytes: 16940
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];
    auto bs = new int[][](K*2, K*2);
    foreach (_; 0..N) {
        auto xyc = readln.split;
        auto x = xyc[0].to!int;
        auto y = xyc[1].to!int;
        if (xyc[2] == "B") {
            bs[y%(K*2)][x%(K*2)] += 1;
        } else {
            bs[y%(K*2)][(x+K)%(K*2)] += 1;
        }
    }
    foreach (i; 0..K*2) {
        foreach (j; 0..K*2) {
            if (i > 0) bs[i][j] += bs[i-1][j];
            if (j > 0) bs[i][j] += bs[i][j-1];
            if (i > 0 && j > 0) bs[i][j] -= bs[i-1][j-1];
        }
    }

    int r;
    auto m = K*2-1;
    foreach (i; 0..K) {
        foreach (j; 0..K) {
            r = max(r,
                bs[m][m] - bs[K+i][m] - bs[m][K+j] + bs[K+i][K+j]
                + bs[K+i][K+j] - bs[i][K+j] - bs[K+i][j] + bs[i][j]
                + bs[i][m] - bs[i][K+j]
                + bs[m][j] - bs[K+i][j]
                + bs[i][j]
            );
            r = max(r,
                bs[K+i][m] - bs[K+i][K+j] - bs[i][m] + bs[i][K+j]
                + bs[m][K+j] - bs[K+i][K+j] - bs[m][j] + bs[K+i][j]
                + bs[i][K+j] - bs[i][j]
                + bs[K+i][j] - bs[i][j]
            );
        }
    }
    writeln(r);
} 

Measured memory_bytes: 19324
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>

using namespace std;

int MOD = 1000000007;

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

  vector<uint32_t> A(61,0);

  int32_t max_pow = 0;
  
  for (int n=0; n<N; ++n) {
    uint64_t a;
    cin >> a;
    for (int idx = 0; a; ++idx, a/=2) {
      if (a&1)
	++A[idx];
      max_pow = max(max_pow, idx);
    }
  }

  uint64_t sum = 0;
  for (int idx=0; idx<=max_pow; ++idx) {
    sum += ((uint64_t(A[idx])*(N-A[idx]))%MOD * uint64_t((uint64_t(1)<<idx)%MOD))%MOD;
    sum %= MOD;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var ps = new int[3].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
		Console.WriteLine(Enumerable.Range(1, 4).Any(i => ps.All(p => p.Any(x => x == i))) ? "NO" : "YES");
	}
}


Measured memory_bytes: 28392