akhauriyash/Code-Regression huggingface dataset:
n=int(input())
s=input()
cnt=[[0,0,0] for _ in range(n)]
for i in range(n):
    if s[i]=='R':
        cnt[i][0]+=1
    elif s[i]=='G':
        cnt[i][1]+=1
    elif s[i]=='B':
        cnt[i][2]+=1
acum=[[0,0,0]]
for i in range(n):
    tmp=[0,0,0]
    for j in range(3):
        tmp[j]+=acum[-1][j]
        tmp[j]+=cnt[i][j]
    acum.append(tmp)
ans=0
for i in range(n):
    for j in range(i+1,n):
        if s[i]==s[j]:
            continue
        if 'R' not in (s[i],s[j]):
            ans+=acum[-1][0]-acum[j][0]
            if 2*j-i<n and s[2*j-i]=='R':
                ans-=1
        elif 'G' not in (s[i],s[j]):
            ans+=acum[-1][1]-acum[j][1]
            if 2*j-i<n and s[2*j-i]=='G':
                ans-=1
        elif 'B' not in (s[i],s[j]):
            ans+=acum[-1][2]-acum[j][2]
            if 2*j-i<n and s[2*j-i]=='B':
                ans-=1
print(ans)

Measured memory_bytes: 69468
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
int main(void){
    // Your code here!
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    bool l = 0;
    if(abs(a-c) <= d) l = 1;
    if(abs(a-b) <= d && abs(b-c) <= d) l = 1;
    if(l){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

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

fn main() {
    let n = read::<i64>();
    let m = read::<i64>();

    println!("{}", (1900*m + 100* (n - m))* 2_i64.pow(m as u32))
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #include<boost/multiprecision/cpp_int.hpp>
// using boost ::multiprecision::cpp_int;
/*__builtin_clz();
__builtin_ctz();
__builtin_popcount();*/
map<ll,ll>mp;
vector<ll>dis(1000005,1000000000);
void bfs(vector<ll>v[], vector<bool> & vis, ll x)
{
    queue<ll>q;
    q.push(x);
    dis[x]=1;
    while(q.size() > 0)
    {
        ll z= q.front();
        q.pop();
        for(ll i=0;i<v[z].size();i++)
        {
            if(dis[v[z][i]]    >  dis[z] + 1)
            {
                dis[v[z][i]] = dis[z]+1;
                mp[v[z][i]]=z;
                q.push(v[z][i]);
            }
        }

    }
}
int main()
{
    boost;
    ll n,m;
    cin>>n>>m;
    vector<ll>v[n+1];
    // memset(dis,1000000000,sizeof dis);
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    vector<bool>visited(n+1,false);
    bfs(v,visited,1);
    for(ll i=2;i<=n;i++)
    {
        // cout<<dis[i]<<" ";
        if(dis[i] == 1000000000 || mp[i]==0)
        {
            cout<<"No"<<"\n";
            return 0;
        }
    }
    cout<<"Yes"<<"\n";
    for(ll i=2;i<=n;i++)
    cout<<mp[i]<<"\n";
    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
}
/* AnsHuman_7 || Anshuman Gaur */


Measured memory_bytes: 26112
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int64)n;i++)
#define FORr(i,k,n)  for(int64 i=(int64)k;i>=n;i--)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define FOREACHr(it, l) for (auto it = l.rbegin(); it != l.rend(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}


int main(){
	//in_o();
	int n;
	cin>>n;
	MPII hsh;
	FOR(i,0,n){
		int x;
		cin>>x;
		hsh[x]++;
		hsh[x-1]++;
		hsh[x+1]++;
	}
	int mx=0;
	for(auto i:hsh){
		mx=max(mx,i.second);
	}
	cout<<mx<<endl;
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int a=0;
  int b=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='0'){
      a++;
    }
    else{
      b++;
    }
  }
  cout << min(a,b)*2 << endl;
}


Measured memory_bytes: 3764
import math
A,B,N,M=map(int,input().split())
h_angle=0
m_angle=0
m_angle=M*6
angle_1=0
angle_2=0
angle=0
if N>=12:
    h_angle=(N-12)*30+M/2
else:
    h_angle=N*30+M/2
angle_1=abs(h_angle-m_angle)
angle_2=360-angle_1
if angle_1>=angle_2:
    angle=angle_2
else:
    angle=angle_1
angle=math.radians(angle)
print(math.sqrt((min(A,B)*math.sin(angle))**2+(max(A,B)-min(A,B)*math.cos(angle))**2))

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

void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c)
{
    for (int i = 0; i < M; i++)
        s[i] = s[i] - 1;

    int num[N] = {0};
    for (int i = 0; i < M; i++)
    {
        if (num[s[i]] == 0)
        {
            num[s[i]] = c[i] + '0';
        }
        // 同じ桁に異なる数字を入れようとしたとき
        else if (num[s[i]] != c[i] + '0')
        {
            cout << "-1" << endl;
            return;
        }
    }

    // 先頭が指定されていない時
    if (N != 1 && num[0] == 0)
        num[0] = '1';

    // 他が指定されていない時
    for (int i = 0; i < N; i++)
    {
        if (num[i] == 0)
        {
            num[i] = '0';
        }
    }

    // 数字に戻す
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += (int)(num[i] - '0') * pow(10, N - i - 1);
    }
    if (N == 1 && ans == 0)
        cout << ans << endl;
    else if (pow(10, N - 1) <= ans && ans < pow(10, N))
        cout << ans << endl;
    else
        cout << "-1" << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> s(M);
    std::vector<long long> c(M);
    for (int i = 0; i < M; i++)
    {
        scanf("%lld", &s[i]);
        scanf("%lld", &c[i]);
    }
    solve(N, M, std::move(s), std::move(c));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin >> S;
    
  int slen=(int)S.length();
  
  for(int i=0;i<=(slen);i++){
    S.erase((int)S.length()-1);
    //cout<<S<<endl;
    string last = S.substr((int)S.length()/2);
    string front = S.substr(0,S.length()/2);
     
    //cout<<front<<" "<<last<<endl;
    if(S.substr((int)S.length()/2)==S.substr(0,S.length()/2)){
      cout<<S.length()<<endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        String[] split = line.trim().split("\\s+");
        int n = Integer.parseInt(split[0]);
        int a = Integer.parseInt(split[1]);
        int b = Integer.parseInt(split[2]);
        in.close();

        System.out.println(Math.min(a, b) + " " + Math.max(0, a + b - n));
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,A;
  cin >> N >> A;
  if(N%500<=A)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);
template<long long Mod = mod>
constexpr long long MOD(long long in) {
    return in % Mod;
}
template<class T>
constexpr T UP(T left, T div) {
    return (left + div - 1) / div;
}

int n, m;
std::vector<int> g[100005];
bool d[100005];
int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> n >> m;
    std::fill(d, d + n, false);

    int l = 0, r = 0;
    for (int i = 0; i < m; ++i) {
        int a, b;
        std::cin >> a >> b;
        --a, --b;

        if (i == 0)
            l = a, r = b;

        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    std::vector<int> left, right;
    left.emplace_back(l);
    right.emplace_back(r);

    d[l] = true, d[r] = true;
    while (true) {
        bool update = false;
        for (int i = 0; i < g[l].size(); ++i) {
            auto val = g[l][i];

            if (!d[val]) {
                d[val] = true;
                l = val;
                left.emplace_back(val);
                update = true;
                break;
            }
        }

        if (!update)
            break;
    }

    while (true) {
        bool update = false;
        for (int i = 0; i < g[r].size(); ++i) {
            auto val = g[r][i];

            if (!d[val]) {
                d[val] = true;
                r = val;
                right.emplace_back(val);
                update = true;
                break;
            }
        }

        if (!update)
            break;
    }

    std::cout << left.size() + right.size() << std::endl;
    for (int i = left.size() - 1; i >= 0; --i)
        std::cout << left[i] + 1 << " ";
    for (int i = 0; i < right.size(); ++i) {
        std::cout << right[i] + 1;
        if (i != right.size() - 1)
            std::cout << " ";
        else
            std::cout << std::endl;
    }

    return 0;
}


Measured memory_bytes: 6904
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        LDeque solver = new LDeque();
        solver.solve(1, in, out);
        out.close();
    }

    static class LDeque {
        int n;
        int[] arr;
        long[][][] memo;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            n = sc.nextInt();
            arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            memo = new long[2][n][n];
            for (long[][] x : memo)
                for (long[] y : x)
                    Arrays.fill(y, -1);
            pw.println(dp(0, n - 1, 0));
        }

        private long dp(int i, int j, int bool) {
            if (i > j)
                return 0;
            if (memo[bool][i][j] != -1)
                return memo[bool][i][j];
            if (bool == 0) {
                long left = arr[i] + dp(i + 1, j, bool ^ 1);
                long right = arr[j] + dp(i, j - 1, bool ^ 1);
                return memo[bool][i][j] = Math.max(left, right);
            } else {
                long left = -arr[i] + dp(i + 1, j, bool ^ 1);
                long right = -arr[j] + dp(i, j - 1, bool ^ 1);
                return memo[bool][i][j] = Math.min(left, right);
            }
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

const int MAXN = 1.1e5;
int N;
ll M;

int par[MAXN];
int sz[MAXN];
int getpar(int a) {
	return par[a] == -1 ? a : (par[a] = getpar(par[a]));
}
bool merge(int a, int b) {
	a = getpar(a), b = getpar(b);
	if (a == b) return false;
	if (sz[a] < sz[b]) swap(a,b);
	par[b] = a;
	sz[a] += sz[b];
	return true;
}

const int MAXQ = 1.1e5;
int Q;
vector<pair<int, int>> paths[2];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> M >> Q;
	for (int i = 0; i < N; i++) {
		par[i] = -1;
		sz[i] = 1;
	}

	ll numE = 0;
	for (int i = 0; i < Q; i++) {
		int a, b, c; cin >> a >> b >> c;
		paths[c].emplace_back(a,b);
		if (c == 0) {
			if (merge(a,b)) {
				numE++;
			}
		}
	}
	ll numCC = 0;
	for (int i = 0; i < N; i++) {
		if (getpar(i) == i) {
			numCC ++;
		}
	}
	assert(numCC + numE == N);
	for (auto e : paths[1]) {
		int a = e.first, b = e.second;
		if (getpar(a) == getpar(b)) {
			cout << "No\n";
			exit(0);
		}
	}
	if (numE + (numCC - paths[1].empty()) <= M && M <= numE + numCC * (numCC - 1) / 2) {
		cout << "Yes\n";
		exit(0);
	} else {
		cout << "No\n";
		exit(0);
	}

	return 0;
}


Measured memory_bytes: 2168
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
s=input()
poss=True
for i in range(len(s)):
    if(i%2==0):
        if(s[i]=='L'):
            poss=False
            break
    else:
        if(s[i]=='R'):
            poss=False
            break
if(poss):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 65348
#include "bits/stdc++.h"
using namespace std;
#define maxn 200001
#define rep(i,n) for(int i=0; i<int(n); ++i)
#define pb push_back
#define mp make_pair
#define mod 1000000007

int n, m, x, y;
int a[maxn], b[maxn];
void solve(){
	cin >> n >> m;
	rep(_, m){
		cin >> x >> y;
		if (x == 1) a[y] = 1;
		if (y == 1) a[x] = 1;
		if (x == n) b[y] = 1;
		if (y == n) b[x] = 1;
	}
	bool ok = 0;
	rep(i, n){
		if (a[i + 1] + b[i + 1] == 2){
			ok = 1;
			break;
		}
	}
	puts(ok ? "POSSIBLE" : "IMPOSSIBLE");

}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    solve();
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define lint long long
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
using namespace std;

int main(){
 int N;
  cin >> N;
  N = N % 10;
  if(N==3) cout << "bon" << endl;
  else if(N==0 || N==1 || N==6 || N==8) cout << "pon" << endl;
  else cout << "hon" << endl;
}

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

int main() {
    long int n;
    cin >> n;
    long long int ans;

    ans = 0;

    for (int i = 1; i < n + 1; i++) {
        if (!(i % 3 == 0 || i % 5 == 0)) {
            ans += i;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  unsigned long long ab = 0, ba = 0;
  for (int i = 0; i < b; i++) {
    ab *= 10;
    ab += a;
  }
  for (int i = 0; i < a; i++) {
    ba *= 10;
    ba += b;
  }
  if (a<b) {
    cout << ab << endl;
  } else {
    cout << ba << endl;
  }
  return 0;
}

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

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

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

vector<int> bfs(int top, vector<vector<int>>& graph)
{
    int i,j;
    queue<int> que;
    int n = graph.size();
    vector<int> vdis(n,-1);
    vdis.at(top) = 0;
    que.emplace(top);
    while(!que.empty()){
        int now = que.front();
        que.pop();
        int dist = vdis.at(now);
        for(i = 0;i < graph.at(now).size();++i){
            int next = graph.at(now).at(i);
            if(vdis.at(next) == -1){
                vdis.at(next) = dist+1;
                que.emplace(next);
            }
        }
    }
    return vdis;
}

int main()
{
    int i,j;
    int n;
    cin >> n;
    vector<vector<int>> graph(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a;    --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> v = bfs(0, graph);
    int p = -1;
    int num = -1;
    rep(i,n){
        if(chmax(num, v[i])) p = i;
    }
    vector<int> u = bfs(p, graph);
    int ans = -1;
    rep(i,n) chmax(ans, u[i]);
    if(ans%3 == 1) cout << "Second" << endl;
    else cout << "First" << endl;

    return 0;
}

Measured memory_bytes: 17184
/*    nya-n   */
#include<stdio.h>
char nyan[30000] = {};
int nyaa = 0;
int main(){
nyan[nyaa]++;while(nyan[nyaa]){nyan[nyaa]=getchar();nyan[nyaa]++;while(nyan[nyaa]){nyan[nyaa]--;putchar(nyan[nyaa]);while(nyan[nyaa]){nyan[nyaa]--;}}nyan[nyaa]=getchar();nyan[nyaa]++;}return 0;}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

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

	vector<vector<int>> lm = vector<vector<int>>(n);
	vector<vector<int>> rm = vector<vector<int>>(n);

	vector<ll> lSum = vector<ll>(n);
	vector<ll> rSum = vector<ll>(n);
	vector<int> v = vector<int>(n);
	rep(0, n) {
		cin >> v[i];
		if (i > 0) {
			lSum[i] = v[i] + lSum[i - 1];
			if (v[i] < 0)lm[i].push_back(v[i]);
			for (int j = 0; j < lm[i - 1].size(); j++) {
				lm[i].push_back(lm[i - 1][j]);
			}
		}
		else {
			lSum[i] = v[i];
			if (v[i] < 0)lm[i].push_back(v[i]);
		}
		
	}
	for (int i = n - 1; i > -1; i--) {
		if (i < n - 1) {
			rSum[i] = v[i] + rSum[i + 1];
			if (v[i] < 0)rm[i].push_back(v[i]);
			for (int j = 0; j < rm[i + 1].size(); j++) {
				rm[i].push_back(rm[i + 1][j]);
			}
		}
		else {
			rSum[i] = v[i];
			if (v[i] < 0)rm[i].push_back(v[i]);
		}
	}
	ll ans = 0;
	for (int lCount = 0; lCount <= k && lCount <= n; lCount++) {
		int lIndex = lCount - 1;
		int lmCount = lIndex > -1 ? lm[lIndex].size() : 0;
		for (int rCount = 0; rCount + lCount <= k && lCount + rCount <= n; rCount++) {
			int rIndex = n - rCount;
			int rmCount = rIndex < n ? rm[rIndex].size() : 0;
			for (int mCount = 0; rCount + lCount + mCount <= k && mCount <= rCount + lCount; mCount++) {
				if (rCount + lCount + mCount == 0)break;
				ll ansTmp = 0;
				vector<int> m = vector<int>();
				if (lIndex > -1) {
					ansTmp += lSum[lIndex];
					rep(0, lm[lIndex].size())m.push_back(lm[lIndex][i]);
				}
				if (rIndex < n) {
					ansTmp += rSum[rIndex];
					rep(0, rm[rIndex].size())m.push_back(rm[rIndex][i]);
				}
				if(m.size() > 0) sort(m.begin(), m.end());
				if (m.size() + 1 < mCount)break;
				rep(0, mCount) {
					if (i < m.size()) {
						ansTmp -= m[i];
					}
					else break;
				}
				ans = max(ans, ansTmp);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
from scipy.ndimage import shift

N, A = list(map(int, input().split()))
X = list(map(int, input().split()))

dp = [np.array([[0]*(N*A+1) for _ in range(N+1)])]
#dp[0]: [0, 0]～[N, N*A]

for x in X:
  new_dp = dp[-1].copy()
  new_dp += shift(dp[-1], [1,x])
  if x<=N*A:
    new_dp[1, x] += 1
  
  dp.append(new_dp)
#print(dp[-1])
  
print(sum([dp[-1][i, i*A] for i in range(1, N+1)]))



Measured memory_bytes: 66404
import math

a,b,x = map(int,input().split())
half = a**2*b//2

if x == half:
    print(45)
elif x > half:
    print(math.degrees(math.atan(2*(a**2*b - x) / pow(a,3))))
else:    
    print(math.degrees(math.atan((a*b**2) / 2 / x)))

Measured memory_bytes: 3188
#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++)
typedef int64_t Int;

//---------- 素因数分解 ----------
map<Int, int> prime_factor(Int n) {
    map<Int, int> res;
    for(Int i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

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

    map<Int,int> p = prime_factor(N);

    Int ans = 0;
    for(pair<Int,int> x : p){
        int now = x.second;
        rep1(i,100){
            now -= i;
            if(now < 0) break;
            ans++;
            
        }
    }
    cout << ans << endl;
}

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

int main(void)
{
    string a;
    stack<char> s;
    cin>>a;
    bool flag=false;

    for(int i=0;i<a.size();i++)
    {
        s.push(a[i]);
        if(a[i]=='F')
        {
            while(!s.empty())
            {
                if(s.top()=='C')
                {
                    flag = true;
                    goto END;
                }else
                {
                    s.pop();
                }
            }
        }
    }

    END:
        if(flag)
            printf("Yes\n");
        else
            printf("No\n");
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//int a[]=new int[N];
		
		
		long N=sc.nextInt();
			
			long K=sc.nextLong();
			boolean v[]=new boolean[(int) N];
			for(int i=0;i<N;i++)v[i]=false;
			
			long t[]=new long[(int) N];
			for(int i=0;i<N;i++) {
				t[i]=sc.nextInt()-1;
			}
			
			long f=0;
			long ctn=0;
			boolean s=true;
			while(true) {
				if(v[(int) f]) {
					break;
				}
				ctn++;
				v[(int) f]=true;
				f=t[(int) f];
				if(ctn==K) {
					p((f+1));
					s=false;
				}
			}
			if(!s) {
				
			}else {
			long g=f;
			long ctn2=0;
			long ans[]=new long[(int) N];
			while(ctn2<N) {
				ans[(int) ctn2]=g;
				ctn2++;
				g=t[(int) g];
				if(g==f) {
					break;
				}
			}
			
			long x=((K-ctn)%ctn2);
			p((ans[(int)x]+1));
			}
		
		
	}
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


Measured memory_bytes: 61860
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> v, w;
    rep(i, n)
    {
        int t;
        cin >> t;
        v.push_back(t);
    }
    w = v;
    sort(ALL(v));
    rep(i, n)
    {
        if (w[i] == v[n - 1])
        {
            cout << v[n - 2] << endl;
        }
        else
        {
            cout << v[n - 1] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " = " << (x) << endl;
#define pb push_back
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;

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

    int n,a,b;
    cin>>n>>a>>b;
    vector<ll> x(n);
    rep(i,n){
        cin>>x[i];
    }
    vector<ll> y(n-1);
    rep(i,n-1){
        y[i]=x[i+1]-x[i];
    }
    sort(all(y));
    ll ans=0;
    rep(i,n-1){
        if(y[i]*a<=b){
            ans+=y[i]*a;
        }
        else{
            ans+=b;
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  
  vector<int> a(m);
  vector<int> b(m);
  vector<int> way(n);
  
  for(int i = 0; i < m; i++) cin >> a.at(i) >> b.at(i);
    
  for(int i = 0; i < m; i++){
    for(int j = 0; j < n; j++){
      if(a.at(i) == j + 1) way.at(j)++;
      if(b.at(i) == j + 1) way.at(j)++;
    }
  }
  for(int i = 0; i < n; i++) cout << way.at(i) << endl;
}

Measured memory_bytes: 3588
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
import math

def main():
    N = int(input())
    ubound = int(math.sqrt(N))
    minv = 10**12 + 100
    for i in range(1, ubound+1):
        if N % i == 0:
            ab = i + (N//i) - 2
            minv = min(minv, ab)
    print(minv)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38640
require 'bigdecimal'
require 'bigdecimal/util'

n = gets.strip.to_i
a = 0.5000000000.to_d

if n.odd?
  o = n - 1
  p = o.to_d / 2.to_d
  a = (n.to_d - p) / n.to_d
end

puts a.truncate(10).to_f

Measured memory_bytes: 1788
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            if (N[0] == '7' || N[1] == '7' || N[2] == '7') Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 25800
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

typedef long long ll;

bool debug = false;
const int INF = 1000000000;
const int NUM = 110;
clock_t START, END;

int V, E, r;
int G[NUM][NUM];
bool visited[NUM], flag[NUM];
int pre[NUM];

int mincost(int root)
{
	int sum = 0;
	int i, j, k;
	for (int i = 0; i < V; i++) {
		flag[i] = false;
	}
	pre[root] = root;
	while (true) {
		for (i = 0; i < V; i++) {
			if (flag[i] || i == root)
				continue;
			pre[i] = i;
			for (j = 0; j < V; j++) {
				if (!flag[j] && G[j][i] < G[pre[i]][i])
					pre[i] = j;
			}
			if (pre[i] == i)
				return -1;
		}
		for (i = 0; i < V; i++) {
			if (flag[i] || i == root)
				continue;
			for (j = 0; j < V; j++)
				visited[j] = false;
			visited[root] = true;
			j = i;
			do {
				visited[j] = true;
				j = pre[j];
			} while (!visited[j]);
			if (j == root)
				continue;
			i = j;
			do {
				sum += G[pre[j]][j];
				j = pre[j];
			} while (j != i);
			j = i;
			do {
				for (k = 0; k < V; k++) {
					if (!flag[k] && G[k][j] < INF && k != pre[j])
						G[k][j] -= G[pre[j]][j];
				}
				j = pre[j];
			} while (j != i);
			for (j = 0; j < V; j++) {
				if (j == i)
					continue;
				for (k = pre[i]; k != i; k = pre[k]) {
					if (G[k][j] < G[i][j])
						G[i][j] = G[k][j];
					if (G[j][k] < G[j][i])
						G[j][i] = G[j][k];
				}
			}
			for (j = pre[i]; j != i; j = pre[j])
				flag[j] = true;
			break;
		}
		if (i >= V) {
			for (i = 0; i < V; i++)
				if (!flag[i] && i != root)
					sum += G[pre[i]][i];
			break;
		}
	}
	return sum;
}

int main(void)
{
	if (debug) {
		START = clock();
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}
	int s, t, d, ans;
	cin >> V >> E >> r;
	for (int i = 0; i < V; i++) {
		for (int j = 0; j < V; j++) {
			G[i][j] = INF;
		}
	}
	for (int i = 0; i < E; i++) {
		scanf("%d%d%d", &s, &t, &d);
		G[s][t] = d;
	}
	ans = mincost(r);
	cout << ans << endl;
	if (debug) {
		END = clock();
		double endtime = (double)(END - START) / 1000;
		printf("total time = %lf s", endtime);
	}
	return 0;
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	if( n/10 == 9 || n%10 == 9 ){
		cout << "Yes" << endl;
	} else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    ll dp[n];dp[0]=0;dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1]));
    }
    cout<<dp[n-1]<<"\n";
}


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

int main() {
  
	int N;
	cin >>N;
	
	vector<double> vec(N);
	
	double total=0;
	
	for(int i=0; i<N; i++){
		
		cin >>vec.at(i);
		total+=1/vec.at(i);
		
	}
	
	cout <<1/total <<endl;
	
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>
#include<iomanip>

using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int n, m;
vi g[1000];
long double dp[1000];

void f(int block){
    dp[n] = 0;
    RREP(i,1,n){
        long double sum = 0.0;
        long double maxi = 0.0;
        int num = g[i].size();
        for(auto to : g[i]){
            sum += dp[to];
            maxi = max(maxi, dp[to]);
        }
        if(i == block && num >= 2){
            num--;
            sum -= maxi;
        }
        dp[i] = sum / num + 1;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    cin >> n >> m;
    REP(i,1,m+1){
        int s, t;
        cin >> s >> t;
        g[s].push_back(t);
    }
    long double ans = 1e18;
    rep(i,n){
        f(i);
        ans = min(ans, dp[1]);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

int nums[200000];

int main(){
	int n, k;
	while(cin >> n >> k && (n || k)){
		int res = -INF;
		int sum = 0;
		rep(i, n){
			cin >> nums[i];
		}
		rep(i, k){
			sum += nums[i];
		}
		int r = k;
		int l = 0;
		while(r < n){
			sum += nums[r++] - nums[l++];
			res = max(res, sum);
		}
		cout << res << endl;
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, m;
  cin >> n >> m;
  vi32 a(m);
  cin >> a;
  rep(i, m) n -= a[i];
  if (n < 0) {
    cout << -1 << endl;
  } else {
    cout << n << endl;
  }
}

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

int main() {
  string n;
  cin >> n;
  if(n.at(0) == n.at(1) && n.at(0) == n.at(2)){
    cout << "Yes" << endl;
  }else if(n.at(3) == n.at(1) && n.at(3) == n.at(2)){
    cout << "Yes" << endl;
  }else if(n.at(0) == n.at(1) && n.at(3) == n.at(1) && n.at(3) == n.at(2)){
    cout << "Yes" << endl;
  }else{
    cout << "No";
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1LL << 60;

int main() {
  //
  ll n, k;
  cin >> n >> k;
  vl a(n), s(n);
  rep(i, n) cin >> a[i];
  s[0] = a[0];
  REP(i, 1, n) { s[i] = s[i - 1] + a[i]; }
  vl b;
  rep(i, n) {
    REP(j, -1, i) {
      if (j < 0) {
        b.push_back(s[i]);
      } else {
        b.push_back(s[i] - s[j]);
      }
    }
  }
  ll ans = 0;
  for (int i = 40; i >= 0; i--) {
    ll tmp = 1LL << i;
    ll cnt = 0;
    for (auto& y : b) {
      // cout << y << endl;
      if ((y & (ans + tmp)) == (ans + tmp)) cnt++;
    }
    if (cnt >= k) {
      // cout << tmp << ":" << cnt << endl;
      ans += tmp;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6260
import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, m, Q = map(int, input().split())
C = [[0]*n for _ in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    l, r = l-1, r-1
    C[l][r] += 1

s = [[0]*(n+1) for _ in range(n+1)]
for i in range(n):
    for j in range(n):
        s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + C[i][j]

for i in range(Q):
    p, q = map(int, input().split())
    p, q = p-1, q-1
    ans = s[q+1][q+1]-s[q+1][p]-s[p][q+1]+s[p][p]
    print(ans)


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

const int TOP = 0,FRONT = 1,LEFT = 3, RIGHT = 2,BACK = 4,BOTTOM = 5;
class Dice {
public:
vector<int> val;
Dice() : val(6){
	for(int i=0; i<6; i++) val[i] = i;
}
Dice(int val[6]){
	for(int i=0; i<6; i++) this->val[i] = val[i];
}
Dice(vector<int> val) : val(val){
	assert(val.size() == 6);
}
int& operator [](int a){
	return val[a];
}

void rot(string s){
	if(s == "N" || s == "B") rotN();
	else if(s == "S" || s == "F") rotS();
	else if(s == "E" || s == "R") rotE();
	else if(s == "W" || s == "L") rotW();
	else if(s == "CW") rotCW();
	else if(s == "CCW") rotCCW();
	else assert(!"rot error");
}

void rot(char ch){
	rot(string(1,ch));
}

//奥に転がす
void rotN(){
	swap(val[TOP],val[FRONT]);
	swap(val[FRONT],val[BOTTOM]);
	swap(val[BOTTOM],val[BACK]);
}

//手前に転がす
void rotS(){
	swap(val[TOP],val[BACK]);
	swap(val[BACK],val[BOTTOM]);
	swap(val[BOTTOM],val[FRONT]);
}

//右に転がす
void rotE(){
	swap(val[TOP],val[LEFT]);
	swap(val[LEFT],val[BOTTOM]);
	swap(val[BOTTOM],val[RIGHT]);
}

//左に転がす
void rotW(){
	swap(val[TOP],val[RIGHT]);
	swap(val[RIGHT],val[BOTTOM]);
	swap(val[BOTTOM],val[LEFT]);
}

//上から見て時計回りに回す
void rotCW(){
	swap(val[FRONT],val[RIGHT]);
	swap(val[RIGHT],val[BACK]);
	swap(val[BACK],val[LEFT]);
}

//上からみて反時計回りに回す。
void rotCCW(){
	swap(val[FRONT],val[LEFT]);
	swap(val[LEFT],val[BACK]);
	swap(val[BACK],val[RIGHT]);
}

void init(int top,int front){
	for(int i=0; i<6; i++) {
		for(int j=0; j<4; j++) {
			if(val[TOP] == top && val[FRONT] == front) return;
			rotCW();
		}
		i%2 ? rotN() : rotE();
	}
	assert(!"can not find");
}
};

int main(){
	Dice dice;
	for(int i = 0; i < 6; i++)
		scanf("%d", &dice[i]);
	int n, top, front;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &top, &front);
		dice.init(top, front);
		printf("%d\n", dice[RIGHT]);
	}
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;


void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    bool flag = true;
    cin >> N;
    FOR(N) {
        int n;
        cin >> n;
        if (n % 2 == 1 || n % 3 == 0 || n % 5 == 0) {

        } else {
            flag = false;
        }
    }
    if (flag) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

void dfs(vector<vector<int>> &adj, vector<int> &dp, vector<bool> &vis, int i) {
  vis[i] = 1;
  for (int v : adj[i]) {
    if (!vis[v]) {
      dfs(adj, dp, vis, v);
    }
    dp[i] = max(dp[i], dp[v] + 1);
  }
}

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

  // ll n, w;
  // cin >> n >> w;
  // vector<ll> x(n), v(n);
  // for (int i = 0; i < n; ++i) {
  //   cin >> x[i] >> v[i];
  // }
  // vector<vector<ll>> dp(n + 1, vector<ll>(w + 1));
  // for (int i = 1; i <= n; ++i) {
  //   for (int j = 0; j <= w; ++j) {
  //     dp[i][j] = dp[i - 1][j];
  //     if (x[i - 1] <= j) {
  //       dp[i][j] = max(dp[i][j], dp[i - 1][j - x[i - 1]] + v[i - 1]);
  //     }
  //   }
  // }
  // cout << dp[n][w];

  int n, m;
  cin >> n >> m;
  vector<vector<int>> adj(n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    adj[x - 1].emplace_back(y - 1);
  }

  vector<bool> vis(n);
  vector<int> dp(n);
  for (int i = 0; i < n; ++i) {
    dfs(adj, dp, vis, i);
    vis[i] = 1;
  }

  cout << *max_element(dp.begin(), dp.end());
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
//int dx[]={+1,-1,+0,+0};///Four Directions
//int dy[]={+0,+0,+1,-1};///Four directions
//int dx [] = {+1,-1,+0,+0,-1,-1,+1,+1};///Eight Directions
//int dy [] = {+0,+0,+1,-1,+1,-1,-1,+1};///Eight Directions

//int mark[10007];vi prime;void seive(){for(int i=2;i<10000;i++){if(mark[i]==0){prime.pb(i);for(int j=i+i;j<=10000;j+=i)mark[j]=1;}}}

//freopen("input.txt", "r", stdin);

bool so(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{

    if(a.second == b.second) return a.ff<b.ff;
    return a.ss>b.ss;
}


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

   int a,b,c,k; cin>>a>>b>>c>>k;
   ll sum=min(a,k);
   k-=min(a,k);

   if(k<1){
    cout<<sum<<endl;
    End;
   }

   k-=min(k,b);
   if(k<1){
    cout<<sum<<endl;
    End;
   }
   sum-=min(k,c);
   cout<<sum<<endl;

   End;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
typedef long long int ll;
using namespace std;
typedef vector<int> VI;
const int INF=1<<30;
int dydx[40001];
int main() {
	int N,tmp;
	while(cin >> N && N){
		REP(i,40001)
		dydx[i]=0;
	VI a,b;
	REP(i,N){
		cin >> tmp;
		a.push_back(tmp);
	}
	REP(i,N){
		cin >> tmp;
		b.push_back(tmp);
	}
	sort(a.begin(),a.end(),greater<int>());
	sort(b.begin(),b.end(),greater<int>());
	int now=0;
	a.push_back(0);
	REP(i,N){
		while(b[i]<a[now]) now++;
		int cs=now-i;
	//	cout <<now << " " <<max(i*2,now*2-i*2) << endl;
		if(max(i*2,now*2-i*2-1)<N)
		dydx[max(i*2,now*2-i*2-1)]+=2;
		dydx[i]--;
	}
	int sum=0,ans=-1;
	REP(i,N){
//		cout << dydx[i] << endl;
		sum+=dydx[i];
		if(sum<0){
			ans=i+1;
			break;
		}
	}
	if(ans==-1 || ans==N)
		cout << "NA" << endl;
	else
		cout << ans << endl;
		
}
	// your code goes here
	return 0;
}

Measured memory_bytes: 1832