akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
const int N = 200010;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
LL a[N];
bool cmp(LL a,LL b){
	return abs(a)>abs(b);
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,k;
	cin>>n>>k;
	bool f=true;
	for(int i=1;i<=n;i++){
		scanf("%lld",a+i);
		f=f && (a[i]<=0);
	}
	
	sort(a+1,a+n+1,cmp);
	
	LL ans=1;
	for(int i=1;i<=k;i++){
		ans*=a[i];
		ans%=mod;
	}
	
	if(ans>0 || n==k){
		cout<<(ans+mod)%mod<<endl;
	}
	else if(f){
		ans=1;
		int cnt=0;
		bool exis=false;
		for(int i=n;i>=1 && cnt<=k;i--){
			if(a[i]!=0 && cnt<k){
				ans*=a[i];
				ans%=mod;
				cnt++;
			}
			if(a[i]==0){
				exis=true;
			}
		}
		
		cnt<k || (ans<0 && exis);
		cnt>=k && (ans>=0 || exis==false);
		
		if(cnt<k || (ans<0 && exis)){
			cout<<0<<endl;
		}
		else{
			cout<<(ans+mod)%mod<<endl;
		}
	}
	else{
		LL t1=inf;		//1-k		min()  +
		LL t2=inf;		//1-k		min()  -
		LL t3=0;		//k+1-n		max()  +
		LL t4=0;		//k+1-n		max()  -
		
		for(int i=1;i<=k;i++){
			if(a[i]>=0){
				t1=min(t1,a[i]);
			}
			else{
				t2=min(t2,-a[i]);
			}
		}
		
		for(int i=k+1;i<=n;i++){
			if(a[i]>=0){
				t3=max(t3,a[i]);
			}
			else{
				t4=max(t4,-a[i]);
			}
		}
		
		if(t1==inf || t2*t4<t1*t3){
			bool f=false;
			ans=1;
			for(int i=1;i<=k;i++){
				if(a[i]==-t2 && !f){
					ans*=t3;
					ans%=mod;
					f=true;
				}
				else{
					ans*=a[i];
					ans%=mod;
				}
			}
			cout<<ans<<endl;
		}
		else{
			bool f=false;
			ans=1;
			for(int i=1;i<=k;i++){
				if(a[i]==t1 && !f){
					ans*=-t4;
					ans%=mod;
					f=true; 
				}
				else{
					ans*=a[i];
					ans%=mod;
				}
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int main(){ cin.tie(0); ios::sync_with_stdio(false);
    lint X = in, Y = in, Z = in, K = in;
    vector<lint> A(X), B(Y), C(Z);
    rep( i, X ) A[i] = in; sort( all(A), greater<lint>() );
    rep( i, Y ) B[i] = in; sort( all(B), greater<lint>() );
    rep( i, Z ) C[i] = in; sort( all(C), greater<lint>() );

    vector<lint> ans(0);
    rep( x, X ) rep( y, Y ) rep( z, Z ) {
        if( (x+1)*(y+1)*(z+1) <= K ) ans.push_back( A[x]+B[y]+C[z] );
        else break;
    }

    sort( all(ans), greater<lint>() );
    rep( i, K ) cout << ans[i] << "\n";
}


Measured memory_bytes: 1404
#include <iostream>
#include <cstdio>
#define N 10005
using namespace std;

string a;
int main()
{
	int i, j;
	cin >> a;
	for (i = 0, j = a.size() - 1; i < j; i++, j--) {
		if (a[i] != a[j]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> 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<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-9;
const int inf=1e8;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	int l=0,r=s.size()-1;
	while(s[l]!='A')l++;
	while(s[r]!='Z')r--;
	cout<<r-l+1<<endl;
}










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

#define EPS 1e-5

float point[300][2] = { {0.0} };
float l[180000][2] = { { 0.0 } };

int search(int num);
int dist(int a, int b, double d);
int dist2(int a, int b, double d);

int main(void) {
	int i, num;

	while (1) {
		scanf("%d\n", &num);
		if (num == 0) {
			break;
		}

		for (i = 0; i < num; i++) {
			scanf("%f %f\n", &point[i][0], &point[i][1]);
		}

		printf("%d\n", search(num));

		for (i = 0; i < num; i++) {
			point[i][0] = 0.0;
			point[i][1] = 0.0;
		}
	}
	return 0;
}

int search(int num) {
	int i, j, s = 0;
	int count, maxcount;
	double a, a0, d;

	for (i = 0; i < num; i++) {
		for (j = 0; j < num; j++) {
			if (dist(i, j, 2) && i != j) {

				float X = (point[i][0] - point[j][0]);
				float Y = (point[i][1] - point[j][1]);

				d = sqrt(X*X + Y*Y);
				a = atan2(point[j][1] - point[i][1], point[j][0] - point[i][0]);
				a0 = acos(0.5 * d);

				l[s][0] = point[i][0] + cos(a0 + a);
				l[s][1] = point[i][1] + sin(a0 + a);
				s++;
				l[s][0] = point[i][0] + cos(a0 - a);
				l[s][1] = point[i][1] + sin(a0 - a);
				s++;
			}
		}
	}

	maxcount = 1;
	for (i = 0; i < s; i++) {
		count = 0;
		for (j = 0; j < num; j++) {
			if (dist2(j, i, 1)) {
				count++;
			}
		}
		if (count > maxcount) {
			maxcount = count;
		}
	}
	return maxcount;
}

int dist(int a, int b, double d){
	float X = (point[a][0] - point[b][0]);
	float Y = (point[a][1] - point[b][1]);
	if (sqrt(X*X + Y*Y) - d > EPS) {
		return (0);
	}
	return (1);
}

int dist2(int a, int b, double d) {
	float X = (point[a][0] - l[b][0]);
	float Y = (point[a][1] - l[b][1]);
	if (sqrt(X*X + Y*Y) - d > EPS) {
		return (0);
	}
	return (1);
}

Measured memory_bytes: 1172
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 1055050
ll dp[N];
main(){
    ll n=in();
    string s;
    cin>>s;
    ll ans=1;
    rep(i,26){
        char c=('a'+i);
        int count=0;
        rep(j,n){
            if(s[j]==c)count++;
        }
        ans*=count+1;
        ans%=MOD;
    }
    cout<<ans-1;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int n, i, j, tmp, temp;
    cin>>n;
    int a[n+2];
    for(i=0; i<n; ++i){
        scanf("%lld", &a[i]);
    }
    sort(a, a+n);
    int ans = 0;
    for(i=0; i<n; ++i){
        for(j = i + 1; j<n; j++){
            int *x = lower_bound(a,a+n,a[i]+a[j]);
            int dist = x - 1 - (a + j);
            ans += dist;
        }
    }
    cout<<ans; return 0;
}

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

int main() {
  // ここにプログラムを追記
   int a, b;
    cin >> a >> b;
    int x=500*a;
        if (x >= b) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }

}
  
  



Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
    
        int K =sc.nextInt();
        int N = sc.nextInt();
        Integer[]home = new Integer[N];
        for(int i=0;i<home.length;i++){
            home[i]=sc.nextInt();
        }
        
        int[]distance = new int[N];
        int ans=0;
        for(int i=0;i<N-1;i++){
            distance[i]=home[i+1]-home[i];
            ans+=distance[i];
        }
        distance[N-1]=K-home[N-1]+home[0];
        ans+=distance[N-1];
        
        Arrays.sort(distance);
        ans-=distance[N-1];
        System.out.println(ans);
        
    }
}

Measured memory_bytes: 90556
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline

def main():
    #入力
    N, Q = (int(_) for _ in input().split())
    edge = [[int(_) for _ in input().split()] for __ in range(N-1)]
    query = [[int(_) for _ in input().split()] for __ in range(Q)]

    tree = [[] for _ in range(N+1)]
    for a, b in edge:
        tree[a].append(b)
        tree[b].append(a)

    cc = [0] * (N+1)
    seen = [False] * (N+1)

    for p, x in query:
        cc[p] += x

    def dfs(x):
        for p in tree[x]:
            if seen[p] == False:
                seen[p] = True
                cc[p] += cc[x]
                dfs(p)
        return

    seen[1] = True
    dfs(1)

    print(*cc[1:])

    return

if __name__ == '__main__':
    main()


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

namespace abc60
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = int.Parse(str[2]);
            int g = Gcd(A, B);
            if (C % g == 0)
            {
                Console.WriteLine("YES");
            }else
            {
                Console.WriteLine("NO");
            }
        }
        public static int Gcd(int a, int b)
        {
            if (a < b)
                
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}


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

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

using namespace std;
using ll = long long;

int main(void) {
  string s;
  cin >> s;
  int ans = 0;
  int tmp = 0;
  vector<int> vec(s.size());
  rep(i, s.size()) {
    if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') {
      tmp++;
    } else {
      tmp = 0;
    }
    vec[i] = tmp;
  }
  vector<int>::iterator iter = max_element(all(vec));
  ans = *iter;
  cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
// 0168_Kannondou.cpp
//
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX_N = 30;
ll dp[MAX_N+1];
int n;
int main() {
  dp[1]=1, dp[2]=2, dp[3]=4;
  for(int i=4; i<=MAX_N; ++i) {
    dp[i] = dp[i-1]+dp[i-2]+dp[i-3];
  }

  while(cin >> n, n){
    ll day = (dp[n] + 10-1)/10;
    ll year = (day + 365-1)/365;
    cout << year << endl;
  }
  return 0;
}



Measured memory_bytes: 2976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define OUT(x) cout << (x) << endl;
#define ALL(v) v.begin(), v.end()
#define REP(i, n) for (int i=0; i<(int)(n); ++i)
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

const int MAX_X=50, 
          MAX_Y=50;
const ll INF = 10e9;

int main() {
    int A, B; cin >> A >> B;
    cout << 6-A-B << endl;
}

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

int main(){
	int n,k;
	cin >> n >> k;
		
	for(int i = n-1; i >= 1 ;--i) 
		cout << k-i << ' ';

	cout << k << ' ';

	for(int i = 1; i < n ;++i)
		cout << k+i << ' ';
	
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll long long
#define nl "\n"
#define mod 1000000007
#define pb push_back
#define po pop_back
#define f(i,x,n) for(ll i=x; i<n; i++)
#define all(c) c.begin(),c.end()
#define unique_sort(x) sort(all(x)),x.resize(distance(x.begin(),unique(all(x))))
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
ll min(ll a,ll b)
{
 return a<b?a:b;
}
ll pw(ll a,ll b){
    if(b==0) return 1;
    ll x=pw(a,b/2);
    x=(x*x)%mod;
    if(b%2) x=(x*a)%mod;
    return x;
}
ll GCD(ll a, ll b)
{
    if(b==0) return a;
    return GCD(b,a%b);
}
void solve()
{
  ll n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  vector<char> v;
  f(i,0,n)
  {
    v.pb(s[i]);
    v.pb(t[i]);
  }
  f(i,0,2*n)
  cout<<v[i];
}
int main()
{
// fast();
// #ifndef ONLINE_JUDGE
//             freopen("input.txt", "r", stdin);
//             freopen("output.txt","w",stdout);
// #endif
    // int t;
    // cin>>t;
    // while(t--)
    // {
         solve();
    // }
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)
#define INT_MAXI 2147483647
#define INT_MINI -2147483648
#define REV(a) reverse(a.begin(),a.end())
#define NP(a) next_permutation(a.begin(),a.end())

typedef pair<int,int> pi;
typedef pair<ll,ll> pl; 

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //cout<<"input"<<endl;freopen("input.txt","r",stdin);
    //cout<<"output"<<endl;freopen("output.txt","w",stdout);
    
    
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x = a*c;
    x = max(x,b*d);
    x = max(x,a*d);
    x = max(x,b*c);
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 3652
import Control.Monad (replicateM)
main = do
        n <- readLn
        nums <- replicateM n readLn
        print.maxProfit $ nums
maxProfit :: [Int] -> Int
maxProfit = fst.searchMinMax

searchMinMax :: [Int] -> (Int, Int)
searchMinMax (x:y:xs) = foldl func (y-x,min x y) xs

func (dif,l) x
    | l > x     = (max (x-l) dif,x)
    | otherwise = (max (x - l) dif,l)

Measured memory_bytes: 126004
#include <cstdio>
#include <set>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>

using namespace std;

typedef pair<string, int> state;
const int MAX_N = 42;
int N, start, goal;
bool G[MAX_N][MAX_N];
vector<string> ws[MAX_N][MAX_N];
set<string> dist[MAX_N][MAX_N];

inline bool strictLarge(string a, string b){
	int len = min(a.length(), b.length());
	for(int i=0; i<len; i++){
		if(a[i] != b[i]) return a[i]>b[i];
	}
	return false;
}

void init(){
	for(int k=0; k<N; k++){
		for(int i=0; i<N; i++){
			for(int j=0; j<N; j++){
				G[i][j] |= (G[i][k] && G[k][j]);
			}
		}
	}
	for(int i=0; i<N; i++)if(!G[i][goal] && i!=goal){
		for(int j=0; j<N; j++){
			G[j][i] = false;
		}
	}
}

string solve(){
	init();
	if(!G[start][goal]){
		return "NO";
	}
	priority_queue< state, vector<state>, greater<state> > Q;
	vector< set<string> > dist(N);

	Q.push( make_pair("", start) );
	dist[start].insert("");

	while(!Q.empty()){
		state tp = Q.top(); Q.pop();
		string str = tp.first;
		if(str.length() > 6*N){
			return "NO";
		}
		int cur = tp.second;
		if(cur == goal){
			return str;
		}
		if(strictLarge(str, *dist[cur].rbegin())){
			continue;
		}
		for(int i=0; i<N; i++)if(G[i][goal] || i==goal){
			for(int j=0; j<(int)ws[cur][i].size(); j++){
				string wd = str + ws[cur][i][j];
				if(dist[i].find(wd) == dist[i].end()){
					dist[i].insert(wd);
					Q.push( make_pair(wd, i) );
				}
			}
		}
	}
	return "ERROR";
}

int main(){
	int A;
	while(scanf("%d%d%d%d",&N,&A,&start,&goal), N){
		for(int i=0; i<N; i++)for(int j=0; j<N; j++) G[i][j] = false;
		for(int i=0; i<N; i++)for(int j=0; j<N; j++) ws[i][j].clear();
		for(int i=0; i<A; i++){
			char buf[10];
			int x, y;
			scanf("%d%d %s ", &x, &y, buf);
			G[x][y] = true;
			ws[x][y].push_back(string(buf));
		}
		puts(solve().c_str());
	}
	return 0;
}

Measured memory_bytes: 2480
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int C, N, M;
	vector<pair<int,int>> gift;
	
	cin>>C>>N>>M;
	
	gift.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>gift[i].first>>gift[i].second;
	}
	
	sort(gift.begin(), gift.end());
	
	vector<int> dp(C+1);
		
	for(int j = 0; j < gift.size(); j++){
		if(gift[j].first > C) break;
		
		for(int k = C - gift[j].first; k >= 0; k--){
			dp[k + gift[j].first] = max(dp[k] + gift[j].second, dp[k + gift[j].first]);
		}
	}
		
	for(int i = 1; i <= M; i++){
		
		cout<<*max_element(dp.begin(), dp.begin() + C/i + 1) * i<<endl;
	}
	
	return 0;
}


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

int main() {
  ios::sync_with_stdio(false); 
  cin.tie(0);
  int n;
  cin >> n;
  int res = 0;
  for (int x, i = 1; i <= n; i++) {
    cin >> x;
    res += x % 2 && i % 2;
  } 
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 3552
#include<cstdio>
using namespace std;
inline int read()
{
    int x=0;bool f=1;char c=getchar();
    while(c<'0' || c>'9'){if(c=='-') f=0;c=getchar();}
    while(c>='0' && c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return f?x:-x;
}
int k;
int ans[]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
int main()
{
    k=read();
    printf("%d\n",ans[k-1]);
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
int main(){
    int n,t[100],tsum=0,m,p,x;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&t[i]);
        tsum+=t[i];
    }
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        scanf("%d%d",&p,&x);
        printf("%d\n",tsum-t[p-1]+x);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

string s;

stack<P> st;
stack<int> ope;  // 0:( 1:) 2:| 3:&

void calc(int op){
    P p1, p2, pr;
    p1 = st.top(); st.pop();
    p2 = st.top(); st.pop();
    // OR
    if(op == 2){
        pr.first = p2.first + p1.first;
        pr.second = min(p2.second, p2.first+p1.second);
    }
    // AND
    if(op == 3){
        pr.first = min(p2.first ,p2.second+p1.first);
        pr.second = p2.second + p1.second;
    }
    st.push(pr);
}

int main() {
    cin >> s;
    for(int i=0;i<int(s.size());i++){
        if(s[i] == '?') st.push({1,1});
        else if(s[i] == '(') ope.push(0);
        else if(s[i] == ')'){
            while(ope.top() != 0){
                calc(ope.top());
                ope.pop();
            }
            ope.pop();
        }
        else if(s[i] == '|'){
            while(!ope.empty() && ope.top() > 2){
                calc(ope.top());
                ope.pop();
            }
            ope.push(2);
        }
        else if(s[i] == '&') ope.push(3);
    }
    while(!ope.empty()){
        calc(ope.top());
        ope.pop();
    }
    cout << st.top().first << " " << st.top().second << endl;
    return 0;
}



Measured memory_bytes: 3404
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 55, I = 2e9;

ll n, x, d, p[N], dt[N][N*N*N], o;

struct r {
	ll v, c, z;
	bool operator < (const r &T) {
		return v * T.c < T.v * c;
	}
} a[N];

int main(){
	scanf("%lld%lld%lld%lld",&n,&x,&d,&a[1].v);
	a[1].c = 1; a[1].z = I;
	for(ll i=2;i<=n;i++) {
		scanf("%lld%lld",&a[i].v,&p[i]);
		a[i].c = 1; a[i].z = d;
	}
	for(ll i=n;i>=2;i--) {
		a[p[i]].v += a[i].v;
		a[p[i]].c += a[i].c;
	}
	sort(a+1, a+1+n);
	fill(dt[0]+1, dt[0]+N*N*N*N, I);
	for(ll i=1;i<=n;i++) {
		for(ll k=0;k<=min(n,a[i].z);k++) {
			for(ll j=0;j<=n*n*n-k*a[i].c;j++) {
				dt[i][j+k*a[i].c] = min(dt[i][j+k*a[i].c], dt[i-1][j] + k*a[i].v);
			}
		}
	}
	for(ll i=0;i<=n*n*n;i++) {
		if(dt[n][i] > x) continue;
		ll L = x - dt[n][i], V = i;
		for(ll j=1;j<=n;j++) {
			ll S = 0, E = max(0ll, a[j].z - n);
			while(S < E) {
				ll M = (S+E)/2 + 1;
				L >= a[j].c * M && L >= a[j].v * M ? S = M : E = M-1;
			}
			L -= a[j].v * S;
			V += a[j].c * S;
		}
		o = max(o, V);
	}
	printf("%lld\n", o);
}


Measured memory_bytes: 71680
#include<iostream>
using namespace std;
int main() {
	string a;
	int p(0);
	cin >> a;
	//cout << a[0] << a[1] << a[2];
	for (int i = 0; i < 3; ++i) {
		if (a[i] == 'A') {
			++p;
			//cout << "P" << endl;
		}
		
	}
	if (p == 1 || p == 2) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int K;
ll t, a[16];

double snuke(ll x) {
	double d = 0;
	for (int i = 0; i != 15; ++i) {
		d += (x%a[i + 1]) / a[i];
	}
	return x / d;
}

int main() {
	a[0] = 1;
	for (int i = 1; i != 16; ++i)
		a[i] = a[i - 1] * 10;
	cin >> K;
	t = 1;
	cout << 1 << endl;
	for (int i = 0; i != K - 1; ++i) {
		ll nextt;
		double d = llmax;
		for (int j = 0; j != 15; ++j) {
			ll k = t - t%a[j] + a[j] * 2 - 1;
			if (d > snuke(k)) {
				d = snuke(k);
				nextt = k;
			}
		}
		t = nextt;
		cout << t << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
/*
digit : 0-9
number : (digit)+
block :("("expression")"|number)
term : block(("*"|"/")block)*
expression : term(("+"|"-")term)*
*/

int getExpression(char* exp,int &it);

bool isDigit(char *exp,int it)
{
    return '0' <= exp[it] && exp[it] <= '9';
}

int getDigit(char *exp,int &it)
{
    it++;
    return (int)(exp[it-1]-'0');
}

int getNumber(char *exp,int &it)
{
    int r=0;
    while(isDigit(exp,it))
    {
	r*=10;
	r+=getDigit(exp,it);
    }
    return r;
}

int getBlock(char *exp,int &it)
{
    int r;
    if (exp[it] == '(')
    {
	it++;
	r = getExpression(exp,it);
	it++;
	return r;
    }
    return getNumber(exp,it);
}

int getTerm(char *exp,int &it)
{
    int r=getBlock(exp,it);
    while(exp[it] == '*' || exp[it] == '/')
    {
	if (exp[it] == '*') {
	    it++;
	    r*=getBlock(exp,it);
	} else {
	    it++;
	    r/=getBlock(exp,it);
	}
    }
    return r;
}

int getExpression(char *exp,int &it)
{
    int r=getTerm(exp,it);
    while (exp[it] == '+' || exp[it] == '-')
    {
	if (exp[it] == '+')
	{
	    it++;
	    r+=getTerm(exp,it);
	} else {
	    it++;
	    r-=getTerm(exp,it);
	}
    }
    return r;
}


int main()
{
    int n;
    cin >> n;
    for (int i=0; i<n; i++)
    {
	int it=0;
	char input[101] = "";
	scanf("%s", input);
	printf("%d\n", getExpression(input,it));
    }
    return 0;
}

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

int main() {
	int a, b;
	long s;
	char op;
	while (true) {
		cin >> a >> op >> b;
		if (op == '+') s = a + b;
		if (op == '-')s = a - b;
		if (op == '*')s = a*b;
		if (op == '/')s = a / b;
		if (op == '?')break;
		cout << s << endl;
	}
}

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

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

const int INF = 1000000007;

int gcd(int x, int y){
	int r;
	if(x<y) swap(x, y);
	while(y>0){
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

int main(void){
	int n,x;
	cin>>n>>x;
	int d[100010]={0},a[100010]={0};
	for(int i=0;i<n;i++) cin>>d[i];

	for(int i=0;i<n;i++) a[i] = abs(x - d[i]);
	int maxv = gcd(a[0], a[1]);
	for(int i=0;i<n-1;i++){
		maxv = gcd(maxv, a[i]);
		//cout<<maxv<<endl;
	}

	printf("%d\n", maxv);
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>

using namespace std;


int main()
{
    //    string S;


    //double K, S;
    //double x, y, z;
    int N, M;


    cin >> N ;

    M = N / 2;

    if (M * 2 < N) {
        M = M  + 1;
    }


    cout << M << endl;


     return 0;

}






Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cassert>
#include<algorithm>
#include<vector>
#include <sys/time.h>
#include <sys/resource.h>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

double e_time(void){
  static struct timeval now;
  gettimeofday(&now, NULL);
  return (double)(now.tv_sec  + now.tv_usec/1000000.0);
} 

const int N = 75;
typedef long long ll;
const ll mod = 1000000000+9;
const int dx[]={-1,0,1};
ll mat[N][N],buf[N][N],ori[N][N];
void matmul(int n,ll c[N][N],ll a[N][N],ll b[N][N]){
  rep(i,n)rep(j,n)buf[i][j]=0;
  rep(i,n){
    rep(j,n){
      buf[i][j]=0;
      rep(k,n){
	ll tmp = (a[i][k]*b[k][j])%mod;
	buf[i][j] += tmp;
	buf[i][j] %= mod;
      }
    }
  }
  rep(i,n)rep(j,n)c[i][j]=buf[i][j];
}
void matpow(int n,ll p,ll mat[N][N],ll ori[N][N]){
  if (p == 1){
    rep(i,n)rep(j,n)mat[i][j]=ori[i][j];
    return;
  }
  matpow(n,p/2,mat,ori);
  matmul(n,mat,mat,mat);
  if (p%2 == 1)matmul(n,mat,mat,ori);
  return;
}

ll A[64][N][N];
void precomp(int c){
  rep(i,c){
    rep(j,c)ori[i][j] = 0;
  }
  rep(i,c){
    if (i-1>=0)ori[i][i-1] = 1;
    ori[i][i] = 1;
    if (i+1< c)ori[i][i+1] = 1;
  }
  rep(i,c)rep(j,c)A[0][i][j] = ori[i][j];
  ll p = 2;
  REP(i,1,64){
    matmul(c,A[i],A[i-1],A[i-1]);
    p <<= 2;
  }
}

void matvec(int c,ll p,vector<ll> & vec){
  vector<ll> next(c);
  rep(i,63){
    if ((1LL<<i)&p){
      rep(ii,c){
	next[ii] = 0;
	rep(jj,c){
	  next[ii] += (A[i][ii][jj]*vec[jj]);
	  next[ii] %= mod;
	}
      }
      vec = next;
    }
  }
}

ll solve(ll r,ll c,vector<pair<ll,int> > in){
  vector<ll> y;
  rep(i,(int)in.size())y.push_back(in[i].first);
  y.push_back(r-1);
  sort(y.begin(),y.end());
  y.erase(unique(y.begin(),y.end()),y.end());

  vector<ll> cur(c);
  rep(i,c)cur[i] = 0;cur[0] = 1;
  
  rep(i,c)rep(j,c)ori[i][j] = 0;
  rep(i,c){
    if (i)ori[i][i-1] =1;
    ori[i][i] = 1;
    if (i+1<c)ori[i][i+1]=1;
  }

  ll lasty = 0;
  rep(k,y.size()){
    ll p = y[k]-lasty;
    lasty = y[k];
    if (p != 0){
      matvec(c,p,cur);
    }
    rep(i,in.size()){
      if (y[k] == in[i].first)cur[in[i].second] = 0;
    }
  }
  return cur[c-1];
}

main(){
  int c,n;
  ll r;
  int tc = 1;
  while(cin>>c>>r>>n && r){
    precomp(c);
    vector<pair<ll,int> > in;
    rep(i,n){
      ll y;
      int x;
      cin>>x>>y;
      y--;x--;
      in.push_back(make_pair(y,x));
    }
    ll ans = solve(r,c,in);
    cout <<"Case " << tc++ << ": " << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3824
#include<bits/stdc++.h>
#define ll long long
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define pb push_back
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define mod 1000000007
#define f first
#define sec second
#define gcd(x,y) __gcd(x, y)
using namespace std;
int main()
{
	ll n,d;
	cin>>n>>d;
	ll res=0;
	while(n--)
	{
		ll x,y;
		double ans;
		cin>>x>>y;
		ans=(double)sqrt(x*x+y*y);
		if(ans<=d)
		res++;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N);
  rep(i,N)cin >> v[i];
  sort(all(v));
  cout << v[N-1] - v[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define DEBUG
#ifdef DEBUG
#define dump(x) cout << "[*] " #x ": " << x << endl
#define debug(x) x
#else
#define dump(x)
#define debug(x)
#endif

typedef long long ll;
//#define int long long
constexpr int INF = 1e9;
constexpr int MOD = 1000000007;
const int MAX = 2002;

long long fac[MAX], finv[MAX], inv[MAX];

void com_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; ++i) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long com(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

decltype(1) main() {
    int n, k;
    cin >> n >> k;

    com_init();

    const int n_blue = k;
    const int n_red = n - k;
    dump(n_blue);
    dump(n_red);
    for (int i = 1; i <= k; ++i) {
        const auto c1 = com(n_blue-1, i-1);
        const auto c2 = com(n_red+1, i);
        dump(i);
        dump(c1);
        dump(c2);
        cout << (c1 * c2) % MOD << endl;
    }
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int r;
  cin >> r;
  if (r < 1200) P("ABC");
  else if (r < 2800) P("ARC");
  else P("AGC");

  return 0;
}



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

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);

		int X = sc.nextInt();

		if (X >= 30) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}

	private static class FastScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

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

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

	}
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<int> dp(n+k);
    rep(i, n+k) dp[i] = 1e9;
    dp[0] = 0;

    rep(i, n) {
        for (int j=1; j<=k; j++) {
            if (dp[i+j] > dp[i] + abs(h[i] - h[i+j])) dp[i+j] = dp[i] + abs(h[i] - h[i+j]);
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  ll n; cin >> n;
  ll cnt74=0;
  ll cnt24=0;
  ll cnt14=0;
  ll cnt4=0;
  ll cnt2=0;
  vector<ll> v{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
  for(auto d:v){
    ll cnt=0;
    for(ll i=n;i>0;i--){
      ll t=i;
      while(t%d==0){
        t/=d;
        cnt++;
      }
    }
    if(cnt>=74) cnt74++;
    if(cnt>=24) cnt24++;
    if(cnt>=14) cnt14++;
    if(cnt>=4) cnt4++;
    if(cnt>=2) cnt2++;
  }
  ll ans = cnt74;
  ans += (cnt2-cnt24)*cnt24+cnt24*(cnt24-1);
  ans += (cnt4-cnt14)*cnt14+cnt14*(cnt14-1);
  ans += ((cnt2-cnt4)*cnt4*(cnt4-1)/2)+(cnt4*(cnt4-1)*(cnt4-2)/2);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;

#define PI 3.14159265359
#define all(v) v.begin(),v.end()
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define sfstr(v) scanf("%s", v);
#define sz(v) (int)v.size()
#define ndl puts("")
#define SS stringstream
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

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

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

void PLAY() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int xx[8000];
int yy[8000];

int main() {
//	PLAY();

	string s;
	cin >> s;
	int  x, y, j, c, xm = 0, ym = 0;

	cin >> x >> y;

	c = 0; j = 0;
	for (int i = 0; i <= sz(s); i++){
		if (s[i] == 'F')
			c++;
		else {
			if (j % 2) yy[j] = c;
			else xx[j] = c;
			c = 0;
			j++;
		}
	}
	xm = xx[0];
	xx[0] = 0;
	sortad(xx, sz(s));
	sortad(yy, sz(s));
	for (int i = 0; xx[i] != 0; i++) {
		if (xm <= x)
			xm += xx[i];
		else
			xm -= xx[i];
	}
	for (int i = 0; yy[i] != 0; i++) {
		if (ym <= y)
			ym += yy[i];
		else
			ym -= yy[i];
	}

	printf("%s\n", xm == x&&ym == y ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 256
n=gets.to_i
book=Array.new(n).map{Hash.new}
n.times do |i|
    book[i][:id]=i+1
    s=gets.split
    book[i][:name]=s[0]
    book[i][:price]=s[1].to_i
end
book.sort_by!{|book| [book[:name], -book[:price]]}
book.each do |book|
    puts book[:id]
end


Measured memory_bytes: 14248
n=int(input())
record=[[[0 for r in range(10)] for f in range(3)] for b in range(4)]
for i in range(n):
    b,f,r,v=[int(x) for x in input().split()]
    record[b-1][f-1][r-1]+=v
for b in range(4):
    for f in record[b]:
        print(" "+" ".join([str(x) for x in f]))
    if b!=3:
        print("".join(["#" for x in range(20)]))

Measured memory_bytes: 7744
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<ll> mat_mul2(int n, vector<ll>& a, vector<ll>& b) {
  vector<ll> ret(n+1);
  for(int i=1; i<=n; i++) {
    ret[i] = a[b[i]];
  }
  return ret;
}

vector<ll> mat_pow2(vector<ll> mat, int n, int size) {
  vector<ll> res(size+1);
  vector<ll> a = mat;
  for(int i=1; i<=size; i++) {
    res[i] = i;
  }
  while(n > 0) {
    if (n&1) {
      res = mat_mul2(size, res, a);
    }
    a = mat_mul2(size, a, a); n >>= 1;
  }
  return res;
}

vector<ll> mat_inv(vector<ll>& a, int n) {
  vector<ll> ret(n+1);
  for(int i=1; i<=n; i++) {
    ret[a[i]] = i;
  }
  return ret;
}

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

  int n, k; cin >> n >> k;
  vector<ll> p(n+1);
  vector<ll> q(n+1);
  vector<ll> ip(n+1);
  vector<ll> iq(n+1);

  for(int i=1; i<=n; i++) {
    cin >> p[i];
    ip[p[i]] = i;
  }
  for(int i=1; i<=n; i++) {
    cin >> q[i];
    iq[q[i]] = i;
  }

  k--;
  vector<ll> A;
  A = mat_mul2(n, q, ip);
  A = mat_mul2(n, A, iq);
  A = mat_mul2(n, A, p);

  A = mat_pow2(A, k/6, n);
  k = k%6;

  vector<ll> IA(n+1);
  for(int i=1; i<=n; i++) {
    IA[A[i]] = i;
  }

  vector<ll> ans;
  if (k==0) {
    ans = p;
  } else if (k==1) {
    ans = q;
  } else {
    k--;
    while(k--) {
      p = mat_inv(p, n);
      ans = mat_mul2(n, q, p);
      p = q;
      q = ans;
    }
  }

  ans = mat_mul2(n, A, ans);
  ans = mat_mul2(n, ans, IA);

  for(int i=1; i<=n; i++) {
    cout << ans[i] << ' ';
  }
  cout << endl;
}


Measured memory_bytes: 7576
#include<stdio.h>
#include<math.h>
int check(int k) {
	int i = 1;
	while (1) {
		if ((k * i) % 360 == 0) {
			return i;
		}
		i++;
	}
	return -1;
}
int main() {
	int k;
	scanf("%d", &k);

	int ans;
	ans = check(k);

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
#define eps 1e-10
#define N 209
using namespace std;

int n,cnt,bin[N],inv[N]; double b[N];
struct node{ int x,y; }a[N];
int main(){
	scanf("%d",&n);
	int i,j,k;
	for (i=bin[0]=1; i<=n; i++) bin[i]=(bin[i-1]<<1)%mod;
	inv[0]=inv[1]=1;
	for (i=2; i<=n; i++) inv[i]=mod-(ll)inv[mod%i]*(mod/i)%mod;
	for (i=1; i<=n; i++) scanf("%d%d",&a[i].x,&a[i].y);
	int ans=bin[n]-1;
	for (i=1; i<=n; i++){
		for (j=1,cnt=0; j<=n; j++)
			if (i!=j) b[++cnt]=min(atan2(a[j].y-a[i].y,a[j].x-a[i].x),atan2(a[i].y-a[j].y,a[i].x-a[j].x));
		sort(b+1,b+cnt+1);
		for (j=k=1; j<=cnt; j=k){
			for (; k<=cnt && abs(b[k]-b[j])<eps; k++);
			ans=(ans-(ll)(bin[k-j+1]-k+j-2)*inv[k-j+1]%mod+mod)%mod;
		}
	}
	printf("%d\n",(ans-n+mod)%mod);
	return 0;
}


Measured memory_bytes: 384
n,k = map(int,input().split())
a_list = list(map(int,input().split()))

num_list = [1]
n_set = set([1])
flag = True
while flag:
    tmp = a_list[num_list[-1]-1]
    if tmp in n_set:
        flag = False
    else:
        n_set.add(tmp)
        num_list.append(tmp)
        
idx = num_list.index(tmp)
loop = len(num_list) - idx
if k < idx:
    print(num_list[k])
else:
    print(num_list[(k-idx)%loop  + idx])

Measured memory_bytes: 32372
#include <bits/stdc++.h>
#include <algorithm>
#define MIN(a,b)  (a<b?a:b)
#define MAX(a,b)  (a>b?a:b)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230

using namespace std;

int main(int argc, char* argv[])
{
	unsigned long long  n;
	cin >>n;
	cout << n * (1 + n + (n*n)) <<"\n";
  return 0;
}

Measured memory_bytes: 3632
n, m = map(int, input().split())
*a, = map(int, input().split())
sorted_a = sorted(a, reverse=True)

needs = [9,2,5,5,4,5,6,3,7,6]
table = [-1] * (n+10)
table[0] = 0

for i in range(n):
    if table[i] != -1:
        for j in sorted_a:
            table[i + needs[j]] = max(table[i]*10 + j, table[i + needs[j]])

print(table[n])

Measured memory_bytes: 14836
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] y = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int[] abs = new int[n];

            for (int i = 0; i < n; i++)
            {
                abs[i] = Math.Abs(x[i] - y[i]);
            }

            double D_M = 0;
            double D_E_2 = 0;
            double D_3_3 = 0;
            double D_C = abs.Max();

            foreach (int item in abs)
            {
                D_M += item;
                D_E_2 += Math.Pow(item, 2);
                D_3_3 += Math.Pow(item, 3);
            }

            double D_E = Math.Sqrt(D_E_2);
            double D_3 = Math.Pow(D_3_3, 1.0 / 3.0);

            Console.WriteLine($"{D_M}\n{D_E}\n{D_3}\n{D_C}");

        }
    }
}


Measured memory_bytes: 18544
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      n: usize,
      ss: [chars; n],
    }
    let mut abs = vec![0; 3];
    let mut ans = 0;
    for i in 0..n {
        let s = &ss[i];
        let nn = s.len() - 1;

        if s[0] == 'B' && s[nn] == 'A' {
            abs[2] += 1;
        } else if s[0] == 'B' {
            abs[1] += 1;
        } else if s[nn] == 'A' {
            abs[0] += 1;
        }

        for i in 1..s.len() {
            if s[i-1] == 'A' && s[i] == 'B' {
                ans += 1;
            }
        }
    }
    debug!(abs, ans);
    if abs[2] > 1 {
        ans += abs[2]-1;
        abs[2] = 1;
    }
    if abs[2] == 1 {
        if abs[0] > 0 || abs[1] > 0 {
            ans += 1;
        }
    }
    ans += min(abs[0], abs[1]);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
int r[100];
int s[100];
int main(){
    char p[100][100];
    int H, W;
    scanf("%d%d", &H, &W);
    for(int i=0; i<H; i++){
            scanf("%s", &p[i]);       
            }
    for(int i=0; i<H; i++){
            int cnt = 0;
            for(int j=0; j<W; j++){
                    if(p[i][j]=='.'){
                                     cnt++;
                                     }
                    }
            if (cnt == W)
               r[i] = 0;
            else
               r[i] = 1;
    }
    for(int i=0; i<W; i++){
            int cnt = 0;
            for(int j=0; j<H; j++){
                    if(p[j][i]=='.'){
                                     cnt++;
                                     }
                    }
            if (cnt == H)
               s[i] = 0;
            else
               s[i] = 1;
    }

    for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                    if(s[j]==1 && r[i]==1){
                               printf("%c", p[i][j]);
                               }
                    }
            if(r[i]==1){
                        printf("\n");
                        }
            }
return 0;          
}


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

using namespace std;
int a[100005],b[100005];
vector<pair<int,int> >v;
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		v.push_back(make_pair(a[i],b[i]));
	}
	long long ans=0;
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		long long k=min(m,v[i].second);
		ans+=k*v[i].first;
		m-=k;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1912
N, M = map(int, input().split())
a = []
cnt = 0
for i in range(N):
    tmp = list(map(int, input().split()))
    a += tmp[1:]

for i in range(1, M+1):
    x = a.count(i)
    if x == N:
    	cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int pos;
    for(int i = 0;i<k && a+i<=b; ++i){
        cout<<a+i<<endl;
        pos = a+i;
    }
    for(int i = 0;i<k; ++i){
        int p = b-k+1+i;
        if(p>pos&&p<=b)cout<<p<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long mp = 0;
    int wall;
    int map[10][10];
    int width,height;
    std::cin >> width >> height;
    for(int i = 0;i < 10;i++){
        for(int j = 0;j < 10;j++){
            cin >> map[i][j];
        }
    }
    for(int k = 0;k < 10;k++){
        for(int i = 0;i < 10;i++){
            for(int j = 0;j < 10;j++){
                if(map[i][j] > map[i][k] + map[k][j]){
                    map[i][j] = map[i][k] + map[k][j];
                }
            }
        }
    }
    for(int i = 0;i < width;i++){
        for(int j = 0;j < height;j++){
            cin >> wall;
            if(wall >= 0){
                mp += map[wall][1];
            }
        }
    }
    cout << mp;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
score=0
for i in range(n):
  if i==0:
    score+=b[a[i]-1]
    #print("first ",a[i],b[a[i]-1])
  else:
    if a[i]-a[i-1]==1:
      score+=b[a[i]-1]+c[a[i-1]-1]
      #print("order ",a[i],b[a[i]-1]+c[a[i-1]-1])
    else:
      score+=b[a[i]-1]
      #print("ordinaly ",a[i],b[a[i]-1])
print(score)

Measured memory_bytes: 3064