akhauriyash/Code-Regression huggingface dataset:
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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; }
vector<int> divisor(int n)
{
    vector<int> res;
    for (int i = 1; i * i <= n; i++)
        if (n % i == 0)
        {
            res.push_back(i);
            if (i != n / i)
                res.push_back(n / i);
        }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i+=2){
        vector<int> d=divisor(i);
        if(d.size()==8)ans++;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;

int main(){
  int x; cin >> x;
  vector<vector<bool>> dp(7,vector<bool>(101000,false));
  int a[6] = {100,101,102,103,104,105};
  dp[0][0] = true;
  for(int i = 0; i < 6;i++){
    for(int j = 0; j < 101000; j++){
      if(dp[i][j]){
        int cnt = 0;
        while(j+a[i]*cnt < 101000){
          dp[i+1][j+a[i]*cnt] = true;
          cnt++;
        }
      } 
    }
  }
  
  if(dp[6][x]) cout << 1 << endl;
  else cout << 0 << endl;
  
  return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    class Lowlink(object):
        """
        construct: O(V+E)
        """
        def __init__(self,edges,root=0):
            """
            edges: list of list of int (adjacency list)
            root: int
            """
            # initialization
            self.__n=len(edges)
            self.__edges=edges
            self.__count=0
            self.__ord=[-1]*self.__n
            self.__low=[-1]*self.__n
            self.__bridge=[]
            self.__articulation=[]
            # construct
            self.__dfs(root,-1)

        def __dfs(self,v,p): # p:parent
            self.__ord[v]=self.__count
            self.__low[v]=self.__count
            self.__count+=1
            isArticulation=False
            count=0 # DFS treeの子の数(rootのarticulate判定に必要)
            for u in self.__edges[v]:
                if self.__ord[u]==-1: # まだ見てない
                    count+=1
                    self.__dfs(u,v)
                    self.__low[v]=min(self.__low[v],self.__low[u])
                    if (self.__ord[v]<self.__low[u]): self.__bridge.append([min(u,v),max(u,v)])
                    if (p!=-1 and self.__ord[v]<=self.__low[u]): isArticulation=True
                elif u!=p: # uは見たけどvuは通ってない(=後退辺(backward edge))
                    self.__low[v]=min(self.__low[v],self.__low[u])
            if (p==-1 and count>=2): isArticulation=True
            if isArticulation: self.__articulation.append(v)

        @property
        def bridge(self):
            return self.__bridge

        @property
        def articulation(self):
            return self.__articulation

    # input
    n,m=map(int,input().split())
    edges=[[] for _ in range(n)]
    for _ in range(m):
        u,v=map(lambda x:int(x)-1,input().split())
        edges[u].append(v)
        edges[v].append(u)
    low=Lowlink(edges)
    print(len(low.bridge))

resolve()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n;cin>>n;
    vector<ll>a(3*n);
    rep(i,n*3){
        cin>>a[i];
    }
    priority_queue<ll,vector<ll>,greater<ll> >que;
    vector<ll>dp1(n);
    ll sum=0;
    rep(i,n){
        que.push(a[i]);
        sum+=a[i];
    }
    rep(i,n){
        ll c=que.top();
        if(a[n+i]<=c){
            if(i==0)dp1[i]=sum;
            else dp1[i]=dp1[i-1];
        }else{
            que.pop();
            que.push(a[n+i]);
            if(i==0)dp1[i]=sum-c+a[n+i];
            else dp1[i]=dp1[i-1]-c+a[n+i];
        }
    }
    reverse(all(a));
    ll sum2=0;
    priority_queue<ll>pq;
    rep(i,n){
        pq.push(a[i]);
        sum2+=a[i];
    }
    vector<ll>dp2(n);
    rep(i,n){
        ll c=pq.top();
        if(a[n+i]>=c){
            if(i==0)dp2[i]=sum2;
            else dp2[i]=dp2[i-1];
        }else{
            pq.pop();
            pq.push(a[n+i]);
            if(i==0)dp2[i]=sum2-c+a[n+i];
            else dp2[i]=dp2[i-1]-c+a[n+i];
        }
    }
    ll ans=max(sum-dp2[n-1],dp1[n-1]-sum2);
    rep(i,n-1){
        ans=max(ans,dp1[i]-dp2[n-2-i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5876
import java.util.*;

public class Main {

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

        int count = 0;
        while (b >= a) {
            b -= a;
            count++;

            if (count >= c) break;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int L, N, X[200100], sum1r[200100], sum2r[200100], sum1l[200100], sum2l[200100];
int ans = 0;

signed main()
{
    cin >> L >> N;
    for(int i = 0; i < N; i++){
        cin >> X[i];
    }
    if(N == 1){
        printf("%lld\n", max(X[0], L - X[0]));
        return 0;
    }
    ///後ろから
    sum1r[0] = X[0];
    sum2r[0] = X[0] * 2;
    for(int i = 1; i < N; i++){
        sum1r[i] = sum1r[i - 1] + X[i - 1] + X[i];
        sum2r[i] = sum2r[i - 1] + X[i] * 2;
    }
    sum1l[N - 1] = L - X[N - 1];
    sum2l[N - 1] = (L - X[N - 1]) * 2;
    for(int i = N - 2; i >= 0; i--){
        sum1l[i] = sum1l[i + 1] + L - X[i + 1] + L - X[i];
        sum2l[i] = sum2l[i + 1] + (L - X[i]) * 2;
    }
    /*for(int i = 0; i < N; i++){
        printf("sum1r[%lld]:%3lld sum2r[%lld]:%3lld sum1l[%lld]:%3lld sum2l[%lld]:%3lld\n", i, sum1r[i], i, sum2r[i], N - 1 - i, sum1l[N - 1 - i], N - 1 - i, sum2l[N - 1 - i]);
    }*/
    int m;
    for(int i = 0; i < N; i++){
        int res = 0;
        if((i + 1) <= N - 1 - i){
            res = sum1r[i] + sum2l[i + 1] - sum2l[i + 1 + i + 1];
            m = 1;
        }
        else {
            res = sum2l[i + 1] + sum1r[i];
            if(i + 1 - (N - 1 - i) > 1){
                res -= sum2r[i - (N - 1 - i) - 1];
            }
            m = 2;
        }
        //printf("i:%lld m:%lld res:%lld\n", i, m, res);
        ans = max(ans, res);
    }
    for(int i = N - 1; i >= 0; i--){
        int res = 0;
        if(N - i <= i){
            res = sum1l[i] + sum2r[i - 1];
            if(i - 1 - (N - i) >= 0){
                res -= sum2r[i - 1 - (N - i)];
            }
            m = 3;
        }
        else {
            res = sum1l[i];
            if(i - 1 >= 0) res += sum2r[i - 1];
            res -= sum2l[N - (N - i - i - 1)];
            m = 4;
        }
        //printf("i:%lld m:%lld res:%lld\n", i, m, res);
        ans = max(ans, res);
    }
    cout << ans << endl;


    return 0;
}

/*

100
4
1
2
98
99


*/


Measured memory_bytes: 8064
def main():
    # n = int(input())
    n, q = map(int, input().split())
    # a = list(map(int, input().split()))
    s = input()
    # h = [int(input()) for _ in rane(n)]
    lr = []
    for i in range(q):
        l, r = list(map(int, input().split()))
        lr.append([l-1, r-1])

    count = [0] * (10**6)
    for i in range(1, n):
        if s[i-1] == "A" and s[i] == "C":
            count[i] = count[i-1] + 1
        else:
            count[i] = count[i-1]

    for i in range(q):
        print(count[lr[i][1]] - count[lr[i][0]])


if __name__ == '__main__':
    main()


Measured memory_bytes: 98608
// abc114_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  ll s,subS,ans=999999;
  cin>>s;
  while(s>100) {
    subS=s%1000;
    ans=min(ans,abs(753-subS));
    s/=10;
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<climits>
#include<algorithm>
using namespace std;
int main()
{
    int n, x = 0, xmax = 0;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; i++){
        if(s[i] == 'I') x += 1;
        else x -= 1;
        xmax = max(xmax, x);
    }
    cout << xmax << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    int N;
    string S, T;
    cin >> N >> S >> T;

    for (int i = 0; i < N; i++) {
        cout << S[i] << T[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int h = s / (60 * 60);
		int m = (s - h * 60 * 60 ) / 60;
		s = s - h * 60 * 60 - m * 60;
		System.out.printf("%d:%d:%d\n",h,m,s);
	}
}



Measured memory_bytes: 26456
#include <iostream>
#include <fstream>
#include <stdio.h>

using namespace std;

static const int MAX = 100;

int n;
double A[MAX];

int main(int argc, const char * argv[]) {
    
    /////////
    //write//
    /////////
    
    cin >> n;
    double sum;
    for(int i=0; i<n; i++){
        cin >> A[i];
        A[i] = 1 / A[i];
        sum += A[i];
    }
    sum = 1/sum;
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, K, i;
    int ans = 1;
    cin >> N >> K;
    for (i = 0; i < N; i++){
        if (ans + K > 2 * ans){
            ans *= 2;
        }else{
            ans += K;
        }
 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
l = {}
for i in a:
    if i in l:
        l[i] += 1
    else:
        l[i] = 1
ans = 0
for i in l.keys():
    if i <= l[i]:
        ans += l[i]-i
    else:
        ans += l[i]
print(ans)

Measured memory_bytes: 67112
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main () {
cin >> a >> b;
if(a==1) a+=13;
if(b==1) b+=13;
if (a>b){
	cout<< "Alice"<< endl;
}else if (a<b){
	cout<< "Bob"<<endl;
}else if (a==b){
	cout<< "Draw"<<endl;
}
return 0;
}


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

int main(){
	int n, m;
	scanf("%d %d", &n, &m);

	vector<int> k;
	for (int i=0; i<n; i++){
		int t;
		scanf("%d", &t);
		k.push_back(t);
	}

	vector<int> v(n, 0);

	for (int i=0; i<m; i++){
		int c;
		scanf("%d", &c);
		for (int j=0; j<n; j++){
			if (k[j] <= c){
				v[j]++;
				break;
			}
		}
	}

	for (int i=0; i<n; i++){
		bool first = true;
		for (int j=0; j<n; j++){
			if (v[i] < v[j]){
				first = false;
			}
		}
		if (first) {
			printf("%d\n", i+1);
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1056
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)1e9+7)
#define MAX ((ull)1e9)

int main(){
	double t, x;
	cin >> t >> x;
	printf("%.6f\n", t/x);
	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000+7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, last, cnt, ans, sum,a[201000], b[201000];
string str[1000], ss[1000];
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
class BIT {
public:
	vector<LL> Bit;
	LL M;
	BIT(LL n_) {
		M = 1;
		while (n_ > M) {
			M *= 2;
		}
		Bit.resize(M+1);
	}
	LL sum(LL i) {
		LL s = 0;
		while (i>0) {
			s += Bit[i];
			i -= (i&(-i));
		}
		return s;
	}
	LL sum(LL i, LL j) {
		return sum(j) - sum(i - 1);
	}
	void add(LL i, LL x) {
		while (i <= M) {
			Bit[i] += x;
			i += (i&(-i));
		}
	}
};

int main() {
	cin >> n;
	BIT bit(200100 + 1);
	rep(i, n) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	rep(i,n){
		auto it = lower_bound(b, b + n, a[i])-b;
		LL x = it;
		x++;
		ans += i - bit.sum(x);
		bit.add(x, 1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8292
import bisect

N = int(input())

A = [int(input()) for _ in range(N)]

colors = []

for i in range(N-1, -1, -1):
    target = bisect.bisect_right(colors, A[i])

    if target == len(colors):
        colors.append(A[i])
    else:
        colors[target] = A[i]

print(len(colors))


Measured memory_bytes: 7848
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<int> expo(x+1);

    expo[1] = 1;
    for(int b = 2; b <= x; b++) {
        int v = b*b;
        while(v <= x) {
            expo[v] = 1;
            v *= b;
        }
    }

    for(int i = x; i >= 1; i--) {
        if(expo[i]) {
            cout << i << endl;
            return 0;
        }
    }
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

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

  if (A >= 13)
    cout << B << endl;
  else if (6 <= A && A <= 12)
    cout << B / 2 << endl;
  else
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-15
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int A,B,C,D,E,F;
int dp[3010];
int main(){
	scanf("%d %d %d %d %d %d",&A,&B,&C,&D,&E,&F);
	if(C<D)swap(C,D);
	dp[0]=1;
	for(int i=1;i<=3000;i++){
		if(i>=C&&dp[i-C]==1)dp[i]=1;
		if(i>=D&&dp[i-D]==1)dp[i]=1;
	}
	int aw=0,as=0;
	for(int a=0;a<=30;a++){
		for(int b=0;b<=30;b++){
			int w = 100*(a*A+b*B);
			if(w==0)continue;
			if(w>F)continue;
			int mx = (a*A+b*B)*E;
			chmin(mx,F-w);
			int s = mx;
			while(dp[s]==0)s--;
			if((aw+as==0)||as*(s+w)<s*(aw+as)){
				as = s;
				aw = w;
			}
		}
	}
	cout << aw+as << ' ' << as << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

#define MAX 1000000
#define OVER 10000

int main(void) {
    int sieve[MAX+1]={0},count=0,i,j,num,sum;
    sieve[1]=1;
    for (i=2; ; i++) {
        if (sieve[i]==0) {
            for (j=2*i; j<=MAX; j+=i) sieve[j]=1;
            count++;
        }
        if (count==OVER) break;
    }
    while (1) {
        scanf("%d",&num);
        if (num==0) break;
        sum=0;
        for (i=2; ; i++) {
            if (sieve[i]==0) {
                sum+=i;
                num--;
            }
            if (num==0) {
                printf("%d\n",sum);
                break;
            }
        }
    
    }
    return 0;
}

Measured memory_bytes: 4512
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    double n, m, d;
    cin >> n >> m >> d;
    std::cout << std::fixed;
    if(d == 0) {
        cout << std::setprecision(6) << 1 / n * (m - 1) << endl;
    } else {
        cout << std::setprecision(6) << 2 * (n - d) / (n * n) * (m - 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;


const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}
LL lcm(LL a,LL b){
    LL g=gcd(a,b);
    return a/g*b;
}

LL kaijo(LL n){
    LL ans=1;
    for(LL i=1;i<=n;++i){
        (ans*=i)%=MOD;
    }
    return ans;
}


int main(){
    LL n;
    cin>>n;
    VEC a;
    map<int,int> coun;
    for(int i=0;i<n;++i){
        LL b;
        cin>>b;
        coun[b]++;
        if(coun[b]==2)a.push_back(b);
        if(coun[b]==4)a.push_back(b);
    }
    if(a.size()==0||a.size()==1)cout<<0<<endl;
    else{
    sort(a.begin(),a.end(),greater<LL>());
        cout<<a[0]*a[1]<<endl;
    }
    
}

Measured memory_bytes: 4992
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
		
		long x=0;
		
		if(b<=0 && c<=0) {
			x=a*c;
		}
		else if(a>=0&&d>=0){
			x=b*d;
		}
		else if(b<=0&&c>=0) {
			x=b*c;
		}
		else if(a>=0&&d<=0){
			x=a*d;
		}
		else if(a<=0&&b>=0&&c<=0&&d>=0) {
			if(a*c>=b*d) {
				x=a*c;
			}
			else {
				x=b*d;
			}
		}
		else if(a<=0&&b>=0&&d<=0) {
			x=a*c;
		}
		else if(a<=0&&b>=0&&c>=0) {
			x=b*d;
		}
		System.out.println(x);
		sc.close();
	}
}

Measured memory_bytes: 35588
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(s: "List[str]"):
    print((s[0][0]+s[1][0]+s[2][0]).upper())
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = [next(tokens) for _ in range(3)]  # type: "List[str]"
    solve(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
// しゃくとり法
let NMK: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
let As: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
let Bs: [Int] = readLine()!.split(separator: " ").map { Int($0)! }

var t: Int = Bs.reduce(0, +)   // 本を読むのにかかった時間. 初期値は机Aから0冊, 机BからM冊読むのにかかる時間
var b: Int = NMK[1] // 机Bの本を読んだ冊数. 初期値はM冊
var res: Int = 0

for a in 0...NMK[0] {   // 机Aの本を読んだ冊数
    t += a>0 ? As[a-1] : 0
    
    while b > 0 && t > NMK[2] {   // 机Aからa冊読むとき, 机Bから何冊読めるか?(・・？)
        b -= 1
        t -= Bs[b]
    }
    if t > NMK[2] { break }
    res = max(res, a + b)
}
print(res)  // (๑•ૅㅁ•๑)

Measured memory_bytes: 26380
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <cassert>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define fore(e, u, v) for (int p = e(u), v = e[p].y; p; v = e[p = e[p].nxt].y)
#define ri rd<int>
using namespace std;
const int maxN = 2e5 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n;

struct vec {
	static const int maxE = maxN << 1;
	int g[maxN], te, rt;
	struct edge {int y, nxt;} e[maxE << 1];
	vec() { te = 1; }
	inline void push(int x, int y) { e[++te] = (edge){y, g[x]}; g[x] = te; }
	inline void link(int x, int y) { if (x == -1) { rt = y; return; } push(x, y), push(y, x); }
	inline int& operator () (int x) { return g[x]; }
	inline edge& operator [] (int x) { return e[x]; }
}T[2];

namespace way1 {
	int deg[maxN], rr[maxN];
	bool vis[maxN]; int kd[maxN];
	vec e;

	void dfs(int x, int fa, int id) {
		++deg[x + id]; int las = 0;
		fore (T[id == n], x, y) if (y != fa) {
			++deg[x + id];
			dfs(y, x, id);
			if (!rr[y]) continue;
			if (las) { e.link(las, rr[y]), las = 0; }
			else las = rr[y];
		}

	}

	void col(int x, int c) {
		vis[x] = 1; kd[x] = c;
		fore (e, x, y)
			if (!vis[y]) col(y, -c);
			else assert(kd[x] == -kd[y]);
	}
	
	void main() {
		dfs(T[0].rt, 0, 0);
		dfs(T[1].rt, 0, n);
		
		rep (i, 1, n) if ((deg[i] & 1) != (deg[i + n] & 1)) {
			puts("IMPOSSIBLE");
			return;
		}

		puts("POSSIBLE");
		rep (i, 1, n) if (!vis[i]) {
			if (!e.g[i]) kd[i] = 0, vis[i] = 1;
			else col(i, 1);
		}
		if ((deg[T[0].rt] & 1) && (deg[n + T[1].rt] & 1)) { // 说明都没边
			if (T[0].rt != T[1].rt) kd[T[0].rt] = -1, kd[T[1].rt] = 1;
			else kd[T[0].rt] = 1;
		}
		rep (i, 1, n) printf("%d%c", kd[i], " \n"[i == n]);
	}
}

namespace way2 {
	int deg[maxN], kd[maxN];
	int q[maxN << 2], tt;
	bool use[maxN << 2];
	vec e;

	void dfs(int x, int fa, int id) {
		++deg[x + id];
		fore (T[id == n], x, y) if (y != fa) {
			++deg[x + id];
			e.link(x + id, y + id);
			dfs(y, x, id);
		}
	}

	void euler(int x) {
		while (e.g[x]) {
			while (use[e.g[x]]) e.g[x] = e[e.g[x]].nxt;
			if (e.g[x]) {
				int p = e.g[x], y = e[p].y;
				e.g[x] = e[p].nxt;
				use[p] = use[p^1] = 1;
				euler(y);
				q[++tt] = y;
			}
		}
	}
	
	void main() {
		dfs(T[0].rt, 0, 0);
		dfs(T[1].rt, 0, n);
		e.link(0, T[0].rt), e.link(0, n + T[1].rt);

		rep (i, 1, n) if ((deg[i] & 1) != (deg[i + n] & 1)) {
			puts("IMPOSSIBLE");
			return;
		}
		rep (i, 1, n) if (deg[i] & 1) e.link(i, i + n);

		puts("POSSIBLE");
		euler(0); q[++tt] = 0;
		For (i, 1, tt) {
			if (q[i] <= n && q[i+1] > n) kd[q[i]] = -1;
			else if (q[i] > n && q[i+1] <= n) kd[q[i+1]] = 1;
		}
		rep (i, 1, n) printf("%d%c", kd[i], " \n"[i == n]);
	}
}

int main() {
	n = ri();
	rep (i, 1, n) T[0].link(ri(), i);
	rep (i, 1, n) T[1].link(ri(), i);
	
	//way1::main();
	way2::main();

	return 0;
}


Measured memory_bytes: 32256
var
 a,b,c,d,n,k:longint;
begin
 readln(a,b,c,d);
 readln(n);
 k:=a*4;
 if k>b*2 then k:=b*2;
 if k>c then k:=c;
 if k*2<d then
 writeln(n*k)
 else
 writeln((n mod 2)*k+(n div 2)*d);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
#if 1
   int n, k; cin >> n >> k;
   vector<int> p(n);
   rep(i, n) cin >> p[i];
#else
   int n = 200000;
   int k = 200000;
   vector<int> p(n);
   rep(i, n) p[i] = 1000;
#endif
   int sum = 0;
   rep(i, k) sum += p[i] + 1;
   int ans = sum;
   for( int i = k; i < n; i++ )
   {
       sum -= p[i - k];
       sum += p[i];
       ans = max(ans, sum);
   } 

   cout << ans / 2;
   if( ans % 2 == 1 ) cout << ".5";  
}

Measured memory_bytes: 3980
n = int(input())
a_l = list(map(int,input().split()))

num = 1
flag = -1 # -1:initial, 0:increasing, 1:decreasing
for i in range(1,n):
    if a_l[i] > a_l[i-1]:
        new_flag = 0
    elif a_l[i] < a_l[i-1]:
        new_flag = 1
    else:
        continue
    if new_flag != flag:
        if flag == -1:
            flag = new_flag
        else:
            flag = -1
            num += 1

print(max(num,1))

    



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

public class Main{
    static Scanner sc = new Scanner(System.in);
    static int n = sc.nextInt();
    static int[] a = new int[n];
    static int[] b = new int[n];
    static int[] c = new int[n];

    public static void main(String[] args){
        for (int i=0; i<n; i++) a[i] = sc.nextInt();
        Arrays.sort(a);
        for (int i=0; i<n; i++) b[i] = sc.nextInt();
        Arrays.sort(b);
        for (int i=0; i<n; i++) c[i] = sc.nextInt();
        Arrays.sort(c);

        long ans = 0;

        for (int i=0; i<n; i++){
            long low = lowerBound(a, b[i]);
            long up = n-upperBound(c, b[i]);
            long tmp = low*up;
            ans += tmp;
        }

        System.out.println(ans);

    }

    public static int lowerBound(int[] array, int value) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int middle = (right + left) / 2;
            if (array[middle] >= value) {
                right = middle;
            } else {
                left = middle;
            }
        }
//        System.out.println(right);
        return right;
    }

    public static int upperBound(int[] array, int value) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int middle = (right + left) / 2;
            if (array[middle] > value) {
                right = middle;
            } else {
                left = middle;
            }
        }
//        System.out.println(right);
        return right;
    }

}

Measured memory_bytes: 95760
#include <cstdio>
#define k 1024
#define r(a) for(int i=0;i<a;i++)
#define s(a) scanf("%d",&a);
#define m(a,b) a<b?a:b
int w,n,m,c[k],d[k],p[k];
int main(){s(n)s(m)r(n)s(d[i])r(m)s(c[i])r(n+1)p[i]=1<<29;p[0]=0;r(m*n)w=n-i%n,p[w]=m(p[w],p[w-1]+c[i/n]*d[w-1]);printf("%d\n",p[n]);}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

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

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(len(a)-1):
    if a[i+1] - a[i] <= 0:
        b.append(1)
    else:
        b.append(0)
tmp_max = 0
max_ = 0
for i in b:
    if i == 1:
        tmp_max += 1
        if max_ < tmp_max:
            max_ = tmp_max
    else:
        tmp_max = 0
print(max_)

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

const ll MOD = 1e+9+7;

bool used[100000] = {};
pl dp[100000] = {};

pl solve(ll node, vector<vector<int>>& edge){
    if(used[node]) return dp[node];
    used[node] = true;
    ll wcnt = 1, bcnt = 1;
    for(auto dst: edge[node]){
        if(used[dst]) continue;
        ll white, black;
        tie(white, black) = solve(dst, edge);
        wcnt *= white + black; // white 
        bcnt *= white;         // black
        wcnt %= MOD;
        bcnt %= MOD;
    }
    dp[node] = make_pair(wcnt, bcnt);
    return dp[node];
}

int main(){
    int n;
    cin >> n;
    vector<vector<int>> edge(n, vector<int>());
    int x,y;
    for(int i=0;i<n-1;i++){
        cin >> x >> y;
        x--; y--;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    ll white, black;
    tie(white, black) = solve(0, edge);
    cout << (white + black) % MOD << endl;
}

Measured memory_bytes: 15744
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n = int(input())
a = list(map(int,input().split()))
pair = []
for i in range(len(a)):
    koho = [i,a[i]-1]
    koho.sort()
    pair.append(koho)
pair.sort()
cnt = 0
for i in range(len(pair)-1):
    if pair[i] == pair[i+1]:
        cnt+=1
print(cnt)

Measured memory_bytes: 32692
#include <iostream>
using ll = long long;
using namespace std;
int main(void){
    int n;
    ll d;
    cin>>n>>d;
    int ans=0;
    
    for (int i = 0; i<n; i++){
        
        ll x,y;
        cin >> x >>y;
        
        if(x*x + y*y <= d*d) ans++;
        
    }
    
    
    cout << ans <<endl;
    
    
    
}


Measured memory_bytes: 3572
from collections import Counter
import sys
s = input()
N = len(s)
sc = Counter(s)
odds = [1 for x in sc if sc[x] % 2 == 1]
if len(odds) > 1:
    print(-1)
    sys.exit(0)

class BIT:
    def __init__(self, size):
        self.bit = [0] * (size+1)
    def add(self, index, elem):
        index += 1
        while index < len(self.bit):
            self.bit[index] += elem
            index += index & -index
    def get(self, index):
        index += 1
        ret = 0
        while 0 < index:
            ret += self.bit[index]
            index -= index & -index
        return ret

indices = [-1] * N
tb = {c: [None] * (sc[c]//2) for c in sc}
lens = {c: 0 for c in sc}
p = 0
for i in range(N):
    c = s[i]
    l = lens[c]
    if 2 * (l+1) <= sc[c]:
        indices[p] = i
        tb[c][l] = p
        lens[c] += 1
        p += 1
    elif 2 * (l+1) == sc[c] + 1:
        indices[N//2] = i
        lens[c] += 1
    else:
        indices[N-1-tb[c][sc[c]-l-1]] = i
        lens[c] += 1

ans = 0
bit = BIT(N)
for i in indices:
    bit.add(i, 1)
    ans += bit.get(N-1) - bit.get(i)
print(ans)


Measured memory_bytes: 50252
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();
    let q: usize = iterator.next().unwrap().parse().unwrap();

    let mut candidates = std::collections::HashSet::new();
    for i in 1..2_u64.pow(n as u32) {
        let bs: Vec<char> = binary_string(i as usize, n).chars().collect();
        let mut sum = 0;
        for j in 0..n {
            if bs[j] == '1' {
                sum += a[j];
            }
        }
        candidates.insert(sum);
    }

    let mut result = String::new();
    for _ in 0..q {
        let m: usize = iterator.next().unwrap().parse().unwrap();

        if candidates.contains(&m) {
            result.push_str("yes\n");
        } else {
            result.push_str("no\n");
        }
    }

    return result.trim().to_string();
}

fn binary_string(n: usize, keta: usize) -> String {
    return format!("{:0>1$b}", n, keta);
}



Measured memory_bytes: 5052
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll maxi=0,f=0,mini=INF,sum=0;
    string str,str2;
    ll h,w;
    ll n;
    ll a,b,c,d;
    cin>>a>>b>>str;
    f=1;
    rep(i,str.length()){
        if(i==a){if(str[i]!='-') f=0;}
        else if('0'>str[i]||str[i]>'9') f=0;
        //cout<<" "<<str[i];
    }
    if(f==1) Yes;
    if(f==0) No;
    return 0;
}


Measured memory_bytes: 256
from itertools import product
import math
n = int(input())

ans = 0
for k in range(3, 1 -int(-math.log10(n)//1)):
    for li in product('357', repeat=k):
        if len(set(li)) < 3:
            continue
        if int(''.join(li)) > n:
            continue
        ans += 1

print(ans)

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**6)

H, W = map(int, input().split())
S = [list(map(str, input())) for _ in range(H)]

tmp = 0
for i in range(H):
	tmp += S[i].count("#")

w_count = (H*W) - tmp

def bfs(field, dp, q):
	cp = q.pop(0)
	np = [[cp[0]+1,cp[1]], [cp[0]-1,cp[1]], [cp[0],cp[1]+1], [cp[0],cp[1]-1]]

	for n in np:
		if 0 <= n[0] <= H-1 and 0 <= n[1] <= W-1:
			if field[n[0]][n[1]] == "." and dp[n[0]][n[1]] == inf:
				q.append(n)
				dp[n[0]][n[1]] = dp[cp[0]][cp[1]] + 1
			if n == [H-1,W-1]:
				return dp[n[0]][n[1]]

	if len(q) == 0:
		return -1

	return bfs(field, dp, q)

inf = float("inf")
dp = [[inf for _ in range(W)] for _ in range(H)]
dp[0][0] = 0
nes = bfs(S, dp, [[0,0]])
if nes == -1:
	print(-1)
else:
	print(w_count-nes-1)

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

#define NIL NULL
#define INF 1000000001

using namespace std;



struct node {
    int key;
    struct node *right;
    struct node *left;
    struct node *parent;
};
typedef node * Node;



Node root = NIL;

void insert(int key){
    Node y = NIL;
    Node x = root;
    Node z;

    z = (Node)malloc(sizeof(struct node));
    z->key  = key;
    z->left = NIL;
    z->right= NIL;
    
    while(x != NIL){
        y = x;
        if(z->key < x->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;

    if(y == NIL)root = z;
    else if(z->key < y->key) y->left = z;
    else y->right = z;     
}

void inOrder(Node current_node){
    if(current_node == NIL) return;
     inOrder(current_node->left);
    printf(" %d",current_node->key);
    inOrder(current_node->right);
}

void preOrder(Node current_node){
    printf(" %d",current_node->key);
    if(current_node->left != NIL)        preOrder(current_node->left);
    if (current_node->right != NIL) preOrder(current_node->right);
}



int main(){
    int num_query;
    char command[20];
    
    int key;
    scanf("%d",&num_query);
    for(int i = 0;i < num_query;i++){
        scanf("%s",command);
        if(command[0] == 'i'){
            scanf("%d",&key);
            insert(key);
        }else if(command[0] == 'p'){
            inOrder(root);printf("\n");
            preOrder(root);printf("\n");
        }
    }
    return 0;   
}



Measured memory_bytes: 26648
/**
*    author:  y_takano
*    created: 23.06.2020 15:17:48
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

using namespace std;

struct _dice
{
    int dt, ds, de, dw, dn, du;
};

void dice(_dice &dice, char c)
{
    int tmp;

    switch (c)
    {
    case 'E':
        tmp = dice.dt;
        dice.dt = dice.dw;
        dice.dw = dice.du;
        dice.du = dice.de;
        dice.de = tmp;
        break;
    case 'N':
        tmp = dice.dt;
        dice.dt = dice.ds;
        dice.ds = dice.du;
        dice.du = dice.dn;
        dice.dn = tmp;
        break;
    case 'S':
        tmp = dice.dt;
        dice.dt = dice.dn;
        dice.dn = dice.du;
        dice.du = dice.ds;
        dice.ds = tmp;
        break;
    case 'W':
        tmp = dice.dt;
        dice.dt = dice.de;
        dice.de = dice.du;
        dice.du = dice.dw;
        dice.dw = tmp;
        break;
    }
}

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

    _dice sdice;

    int n, a, b;
    string s = "SSSSNESSSESSSWSSSWSSSESSS";

        cin >> sdice.dt;
        cin >> sdice.ds;
        cin >> sdice.de;
        cin >> sdice.dw;
        cin >> sdice.dn;
        cin >> sdice.du;

    cin >> n;

    REP(i, n)
    {
        cin >> a >> b;
        REP(i, s.size())
        {
            dice(sdice, s[i]);
            if (sdice.dt == a && sdice.ds == b)
            {
                cout << sdice.de << '\n';
                break;
            }
        }
    }

    return 0;
}


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

int main(){
	int N;
	cin >> N;
	vector<long long> A(N);
	for(auto &i:A)cin >> i;
	
	long long sum=0;
	int c=0;
	int ans=0;
	
	sort(A.begin(),A.end());
	
	for(int i=0;i<N;i++){
		if(sum*2>=A[i])c++;
		else c=0;
		sum+=A[i];
	}
	ans=c+1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    int x = 0;
    rep(i, n) x ^= a[i];
    rep(i, n) cout << (x ^ a[i]) << " "; cout << endl;
}


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


int main() {


    int l;
    cin >> l ;

    double l1;
    l1 = l/3.0;
  // cout << l1 << endl;
    
    double ans;
    ans = l1 * l1 * l1;
    cout << setprecision(25) << ans << endl;

    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int a[8];
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6]>>a[7])
	{
		string merry="41412121";
		string ans;
		int cans=10000000;
		for(int i = 0; i < 8; ++i)
		{
			int cnt=0;
			for(int j = 0; j < 8; ++j)
			{
				int num=merry[j]-'0';
				cnt+=a[j]-num<0?0:a[j]-num;
			}
			if(cnt<cans)
			{
				cans=cnt;
				ans=merry;
			}
			else if(cnt==cans&&merry<ans)
			{
				ans=merry;
			}
			char tmp=merry[0];
			for(int j = 1; j < 8; ++j)
			{
				merry[j-1]=merry[j];
			}
			merry[7]=tmp;
		}
		for(int i = 0; i < 8; ++i)
		{
			if(i==0) cout<<ans[0];
			else cout<<" "<<ans[i];
		}
		cout<<endl;
	}
  return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	ll x;
	cin >> x;

	int i = 0;
	ll ans = 100;
	while(true){
		if(ans >= x){
			cout << i << endl;
			return 0;
		}
		cerr << ans << endl;
		ans *= 1.01;
		i++;
	}
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	string s, t, u;
	ll a, b;
	cin >> s >> t >> a >> b >> u;
	if(s == u){
		a--;
	}
	if(t == u){
		b--;
	}
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<char>>a(n,vector<char>(n));
    vector<vector<char>>b(m,vector<char>(m));
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>a[i][j];
    for(int i=0;i<m;i++)for(int j=0;j<m;j++)cin>>b[i][j];
    for(int i=0;i+m<=n;i++){
        for(int j=0;j+m<=n;j++){
            bool match=1;
            for(int k=0;k<m;k++)for(int l=0;l<m;l++)if(a[i+k][j+l]!=b[k][l])match=0;
            if(match){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
main()
{
	int N,K,X,Y,SUM=0;
	scanf("%d %d %d %d",&N,&K,&X,&Y);
	if (N<=K)
		SUM=X*N;
	else
		SUM=X*K+(N-K)*Y;
	printf ("%d",SUM);
}

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

int main() {
  int x, y;
  cin >> x >> y;
  vector<int> group{0,2,0,1,0,1,0,0,1,0,1,0};
  if (group.at(x-1) == group.at(y-1)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, Q = sc.nextInt()
  val S = sc.next().toCharArray
  val indecies = (1 until N).scanLeft(0) { (acc, i) =>
    if (S(i - 1) == 'A' && S(i) == 'C') acc + 1 else acc
  }.toArray
  List.fill(Q)(sc.nextInt() -> sc.nextInt()).map { case (l, r) =>
    indecies(r - 1) - indecies(l - 1)
  }.foreach(println)
}


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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  if(K<=A) cout << K << endl;
   if(A<K && K<=A+B) cout << A << endl;
   if(A+B<K) cout << A-(K-A-B) << endl; 
}

Measured memory_bytes: 3576