akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

        int n = sc.nextInt();

        int[] a = new int [n];

        for(int i = 0; i < n - 1; i++){
            a[sc.nextInt() - 1]++;
        }

        for(int i = 0; i < n; i++){
            System.out.println(a[i]);
        }

    }
}


Measured memory_bytes: 61836
#include <iostream>
#include <vector>

using namespace std;

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

	int n;
	cin >> n;

	string s;
	cin >> s;

	vector<vector<int> > suf;
	suf.resize(n);

	for(int i = 0; i < n; ++i) {
		suf[i].resize(3);
	}

	suf[n - 1][0] += (s[n - 1] == 'R');
	suf[n - 1][1] += (s[n - 1] == 'G');
	suf[n - 1][2] += (s[n - 1] == 'B');

	for(int i = n - 2; i >= 0; --i) {
		suf[i][0] = suf[i + 1][0] + (s[i] == 'R');
		suf[i][1] = suf[i + 1][1] + (s[i] == 'G');
		suf[i][2] = suf[i + 1][2] + (s[i] == 'B');
	}

	long long ans = 0;

	vector<char> c = {'R', 'G', 'B'};

	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			int p = -1;

			if(s[i] == s[j]) {
				continue;
			}

			for(int k = 0; k < c.size(); ++k) {
				if(c[k] != s[i] && c[k] != s[j]) {
					p = k;
					break;
				}
			}

			if(j + 1 < n) {
				ans += suf[j + 1][p];
			}

			if(j + j - i < n) {
				ans -= (s[j + j - i] == c[p]);
			}
		}
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3420
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N;
int h[101010];

signed main() {
  cin >> N;
  vector<int> dp(N + 100, INF);
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }

  dp[1] = 0;

  for (int i = 1; i <= N; i++) {
    if (i + 1 <= N) chmin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
    if (i + 2 <= N) chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
  }

  cout << dp[N] << endl;
  return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main(){
  	int A, B,x,y,z,res;
  	cin >> A >> B;
  	x = A+B;
  	y = A-B;
  	z = A*B;
  	res = max(z, max(x,y));
  	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main( void ) {

  while( 1 ) {
    int i, j;
    int n, m;
    int quest[ 1000 ][ 100 ];
    int count[ 100 ], pre[ 100 ], ans[ 100 ];
    int cont;

    scanf( "%d%d", &n, &m );
    if( !n && !m ) break;

    for( i = 0; i < n; i++ )
      for( j = 0; j < m; j++ )
        scanf( "%d", &quest[ i ][ j ] );

    for( j = 0; j < m; j++ ) {
      count[ j ] = 0;

      for( i = 0; i < n; i++ )
        count[ j ] += quest[ i ][ j ];
    }

    for( j = 0; j < m; j++ ) {
      int k;
      int max = count[ 0 ];
      int mIndex = 0;

      for( k = 1; k < m; k++ )
        if( max < count[ k ] ) {
          max = count[ k ];
          mIndex = k;
        }

      count[ mIndex ] = 0;
      pre[ mIndex ] = j + 1;
    }

    for( j = 0; j < m; j++ )
      ans[ j ] = j + 1;

    cont = 1;
    while( cont ) {
      int tmp; 

      cont = 0;

      for( j = 0; j < m - 1; j++ )
        if( pre[ j ] > pre[ j + 1 ] ) {
          cont = 1;
          tmp = pre[ j ]; pre[ j ] = pre[ j + 1 ]; pre[ j + 1 ] = tmp;
          tmp = ans[ j ]; ans[ j ] = ans[ j + 1 ]; ans[ j + 1 ] = tmp;
        }
    }

    for( j = 0; j < m; j++ ) {
      printf( "%d", ans[ j ] );
      if( j < m - 1 )
        printf( " " );
    }
    printf( "\n" );
  }

  return ( 0 );
}

Measured memory_bytes: 0
n,y=map(int,input().split())
a,b,c=-1,-1,-1
for i in range(n+1):
    for j in range(n+1-i):
        if (i*10000 + j*5000 + (n-i-j)*1000) == y:
            a=i
            b=j
            c=n-i-j
print(a,b,c)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int n;
  while(cin >> n && n!=0) {
    string s;
    cin >> s;
    int i=0,a[n],sum=0;
    fill(a,a+n,0);
    while(i<s.size()) {
      int t=i%n;
      if(s[i]=='L') {
	a[t]+=sum+1;
	sum=0;
      } else if(s[i]=='S') {
	sum+=a[t]+1;
	a[t]=0;
      } else {
	a[t]++;
      }
      i++;
    }
    sort(a,a+n);
    for(int i=0; i<n; i++) {
      if(i!=0) cout << " ";
      cout << a[i];
    }
    cout << " " << sum << endl;
  }
  return 0;
}
      


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

int main(){
	string s; long long k;
	cin >> s >> k;
	string t = s,d = s;
	long long ans1 = 0,ans2 = 0,ans3 = 0;
	for(int i = 1;i < s.size();i++){
		if(s[i] == s[i-1]){
			ans1++;
			s[i] = '-';
		}
	}
	t = s + t;
	for(int i = 1;i < t.size();i++){
		if(t[i] == t[i-1]){
			ans2++;
			t[i] = '-';
		}
	}
	d = t + d;
	for(int i = 1;i < d.size();i++){
		if(d[i] == d[i-1]){
			ans3++;
			d[i] = '-';
		}
	}
	long long sum = ans1 + (ans2 + ans3) * ((k-1)/2);
	if((k-1)%2 == 1) sum += ans2;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
# reference
# https://atcoder.jp/contests/abc176/submissions/16207205
# https://atcoder.jp/contests/abc176/submissions/16157397
# https://qiita.com/QUANON/items/ca06f3068c87b3a21e18

H, W, M = gets.strip.split.map(&:to_i)

m = []
M.times do
  m.push(gets.strip.split.map { |_| _.to_i - 1 })
end

hx, hh = 0, [0] * H
wx, ww = 0, [0] * W

m.each { |h, w|
  hx = hh[h] if hx < hh[h] += 1
  wx = ww[w] if wx < ww[w] += 1
}

hm_count = hh.count(hx)
wm_count = ww.count(wx)

if hm_count * wm_count > m.count{|h,w| hh[h] == hx && ww[w] == wx}
  p hx + wx
else
  p hx + wx - 1
end


Measured memory_bytes: 40152
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int cnt[1000001]={};

int main(){
	int N;
	int A[200001];
	int ans=0;
	scan(N);
	rep(i,N){
		scan(A[i]);
		cnt[A[i]]++;
	}
	rep(i,N){
		vll yaku=divisor(A[i]);
		bool flag=1;
		for(auto x:yaku){
			if(x!=A[i]&&cnt[x]>0){
				flag=0;
				break;
			}
			else if(x==A[i]&&cnt[x]>1){
				flag=0;
				break;
			}
		}
		if(flag) ans++;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 8212
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	string N; cin >> N;

	if(N.front() == N.back()) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;

}


Measured memory_bytes: 256
// 2013/11/06 Tazoe

#include <iostream>
#include <queue>
using namespace std;

// 位置
struct point{
	int y;
	int x;
};

// 位置＋時間
struct state{
	int y;
	int x;
	int t;
};

int main()
{
	int H, W, N;
	cin >> H >> W >> N;

	char F[1002][1002];
	for(int y=0; y<=H+1; y++){
		for(int x=0; x<=W+1; x++){
			F[y][x] = 'X';
		}
	}

	struct point P[10];			// 巣(0)と工場(1〜N)の位置

	for(int y=1; y<=H; y++){
		for(int x=1; x<=W; x++){
			cin >> F[y][x];

			if(F[y][x]=='S'){
				P[0].y = y;
				P[0].x = x;
				F[y][x] = '.';
			}
			else if('0'<=F[y][x] && F[y][x]<='9'){
				P[F[y][x]-'0'].y = y;
				P[F[y][x]-'0'].x = x;
				F[y][x] = '.';
			}
		}
	}

	int sum = 0;				// 合計時間

	for(int i=0; i<N; i++){			// P[i]からP[i+1]までの時間を求める
		struct state s;
		s.y = P[i].y;
		s.x = P[i].x;
		s.t = 0;

		bool memo[1002][1002];
		for(int y=1; y<=H; y++){
			for(int x=1; x<=W; x++){
				memo[y][x] = false;
			}
		}
		memo[s.y][s.x] = true;			// スタートを訪問済

		queue<struct state> q;
		q.push(s);				// スタートをキューに挿入

		while(true){
			if(q.empty())				// キュートップに頂点がなければ
				break;

			s = q.front();
			q.pop();

			s.t++;

			s.x++;					// 東
			if(s.y==P[i+1].y && s.x==P[i+1].x)
				break;

			if(F[s.y][s.x]=='.' && !memo[s.y][s.x]){
				memo[s.y][s.x] = true;
				q.push(s);
			}
			s.x--;

			s.x--;					// 西
			if(s.y==P[i+1].y && s.x==P[i+1].x)
				break;

			if(F[s.y][s.x]=='.' && !memo[s.y][s.x]){
				memo[s.y][s.x] = true;
				q.push(s);
			}
			s.x++;

			s.y++;					// 南
			if(s.y==P[i+1].y && s.x==P[i+1].x)
				break;

			if(F[s.y][s.x]=='.' && !memo[s.y][s.x]){
				memo[s.y][s.x] = true;
				q.push(s);
			}
			s.y--;

			s.y--;					// 北
			if(s.y==P[i+1].y && s.x==P[i+1].x)
				break;

			if(F[s.y][s.x]=='.' && !memo[s.y][s.x]){
				memo[s.y][s.x] = true;
				q.push(s);
			}
			s.y++;
		}

		sum += s.t;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3176
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    T, X = map(int, input().split())
    print(T / X)

main()


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

const int N = 200000 + 5;

lld arr[N], preS[N];
inline lld sum(int l, int r){
	//1-base (l, r]
	return preS[r]-preS[l];
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;cin>>n;
	for(int i=1;i<=n;i++) cin>>arr[i];
	for(int i=1;i<=n;i++) preS[i]=preS[i-1]+arr[i];
	lld ans=abs(sum(0, 1)-sum(1,n));
	for(int i=2;i<=n-1;i++)
		ans=min(ans, abs(sum(0, i) - sum(i, n)));
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 3328
from collections import Counter
n = int(input())
a=list(map(int,input().split()))
q = int(input())
bc=[list(map(int,input().split())) for _ in range(q)]

a_c = Counter(a)
a_sum = sum(a)
for i in range(q):
    if bc[i][0] in a_c:
        a_sum += a_c[bc[i][0]] * (bc[i][1] - bc[i][0])
        if bc[i][1] in a_c:
            a_c[bc[i][1]] += a_c[bc[i][0]]
        else:
            a_c[bc[i][1]] = a_c[bc[i][0]]
        a_c[bc[i][0]] = 0
    else:
        a_sum = a_sum
    print(a_sum)


Measured memory_bytes: 36248
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    class Edge {
        int dst;

        public Edge(int dst){
            this.dst  = dst;
        }
    }

    class Node{
        boolean isFinished = false;
        int minCost = Integer.MAX_VALUE;
        int num;
        int dst;
        ArrayList<Edge> edges = new ArrayList<Edge>();

        public void addEdge(Edge edge){
            edges.add(edge);
        }
    }

    public Main(){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());

        Node[] nodes = new Node[N];
        for(int i=0;i<N;i++){
            nodes[i] = new Node();
            nodes[i].num = i+1;
        }

        for(int i=0;i<M;i++){
            int A = Integer.parseInt(sc.next())-1;
            int B = Integer.parseInt(sc.next())-1;

            nodes[A].addEdge(new Edge(B));
            nodes[B].addEdge(new Edge(A));
        }

        PriorityQueue<Node> queue = new PriorityQueue<Node>(new Comparator<Node>(){
            @Override
            public int compare(Node a, Node b){
                return a.minCost - b.minCost;
            }
        });

        nodes[0].minCost = 0;
        queue.add(nodes[0]);
        while(queue.size() != 0){
            Node n = queue.poll();
            if(n.isFinished)continue;

            for(Edge e : n.edges){
                if(nodes[e.dst].isFinished) continue;

                if(nodes[e.dst].minCost > n.minCost + 1){
                    nodes[e.dst].minCost = n.minCost + 1;
                    nodes[e.dst].dst = n.num;
                    queue.add(nodes[e.dst]);
                }
            }
            n.isFinished = true;
        }

        System.out.println("Yes");
        for(int i=1;i<N;i++){
            System.out.println(nodes[i].dst);
        }

    }

    public static void main(String[] args) {
        Main M = new Main();
    }
}


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

int main(){
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  int vx=c-a,vy=d-b;
  cout << c-vy << " "<<d+vx << " "<<c-vy-vx<< " " << d+vx-vy<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}
 
int main() {
  ll x;
  cin >> x;
  vec ans;
  ans.push_back(1);
  for(ll i=2;i<=x;i++) {
    for(ll j=2;mpow(i,j)<=x;j++) {
      ans.push_back(mpow(i,j));
    }
  }
  sort(ans.rbegin(),ans.rend());
  cout << ans[0] << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int res = max(0,min(b,d)-max(a,c));
    put(res);
    return 0;
}


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

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

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    ll count_ab = A + B;
    ll count_a = 0;
    count_a = A * (N / count_ab);  //count_ab != 0 && count_ab <= N
    count_a += min(A, N % count_ab);

    cout << count_a << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, D := ReadInt(), ReadInt()
	p := make([][]int, N)
	for i := 0; i < N; i++ {
		p[i] = ReadInts(D)
	}

	sqrtInt := make([]bool, 40000)
	for i := 0; i < 200; i++ {
		sqrtInt[i*i] = true
	}
	c := 0
	for i := 0; i < N-1; i++ {
		for j := i + 1; j < N; j++ {
			sum := 0
			for d := 0; d < D; d++ {
				sum += (p[i][d] - p[j][d]) * (p[i][d] - p[j][d])
			}
			if sqrtInt[sum] {
				c++
			}
		}
	}
	fmt.Println(c)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1952
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

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


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

int main(void){
    ll n;
    cin >> n;

    ll a[n], b[n];
    rep(i, n){
        cin >> a[i];
        b[i] = 0;
    }

    for(int i=n; i>0; i--){
        ll tmp = i;
        ll count = 0;
        while(n >= tmp){
            count += b[tmp-1];
            tmp += i;
        }
        if(a[i-1] % 2 != count % 2){
            b[i-1]++;
        }
    }

    ll count = 0;
    rep(i, n){
        if(b[i] == 1){
            count++;
        }
    }

    cout << count << endl;

    if(count){
        rep(i, n){
            if(b[i] == 1)
            cout << i+1 << " ";
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 3968
#include <iostream>

using namespace std;
int main() {
    int N;
    int d[50];
    int answer = 0;
    cin >> N;
    for (int i=0; i<N; i++) cin >> d[i];
    for (int i=0; i<N; i++) {
        for (int j=i+1; j<N; j++) {
            answer += d[i] * d[j];
        }
    }
    cout << answer << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			Deque<Integer> operando=new ArrayDeque<>();
			boolean isEOF=false;
			while(sc.hasNext()){
				String order=sc.next();
				boolean isOperator = false;
				String[] Operator= new String[3];
				Operator[0]=new String("+");
				Operator[1]=new String("*");
				Operator[2]=new String("-");
				for(String s: Operator){
					if(order.equals(s)) isOperator=true;
				}
				//if(order.equals("EOF")) isEOF=true;
				if(!isEOF){
					if(isOperator){
						int a = operando.pollFirst();
						int b = operando.pollFirst();
						operando.addFirst(calc(a,b,order));
					}else{
						operando.addFirst(Integer.parseInt(order));
					}
				}
			}
			System.out.println(operando.pollFirst());
		}
	}
	public static int calc(int a, int b, String s){
		int ans=0;
		if(s.equals("+"))ans= a+b;
		if(s.equals("-"))ans= b-a;
		if(s.equals("*"))ans= a*b;
		return ans;
	}
}

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

typedef long long ll;

const int N = 1e5 + 10;
int a[N], mark[N];
vector<int> adj[N], v[N];

void dfs(int root, int col) {
    mark[root] = col;
    for (int i = 0; i < adj[root].size(); i++) {
        int u = adj[root][i];
        if (!mark[u])
            dfs(u, col);
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, m, x, y;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int cnt = 0;
    for (int i = 0; i < n; i++)
        if (!mark[i]) {
            cnt++;
            dfs(i, cnt);
        }
    if (n < 2 * cnt - 2) {
        cout << "Impossible\n";
        return 0;
    }
    for (int i = 0; i < n; i++) {
        v[mark[i]].push_back(a[i]);
    }
    for (int i = 1; i <= cnt; i++)
        sort(v[i].begin(), v[i].end());
    ll ans = 0;
    if (cnt > 1) {
        vector<int> u;
        for (int i = 1; i <= cnt; i++) {
            ans += v[i][0];
            for (int j = 1; j < v[i].size(); j++)
                u.push_back(v[i][j]);
        }
        sort(u.begin(), u.end());
        for (int i = 0; i < cnt - 2; i++)
            ans += u[i];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 10108
#include <stdio.h>

int main(void) {
	int k,n,a,b,c;
	//printf("数字を入力してください　：\n");
	scanf("%d",&k);
	
	if(k%2==0)
	{
		a = (k/2);
		a*=a;
		printf("%d",a);
	}
	else
	{
		b = ((k+1)/2);
		c = b*(b-1);
		printf("%d",c);
	}
		
	
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
vector<pair<int,int>>adj[100005];
int val[100005],vis[100005];


void dfs(int s,int prev,int w)
{
    if(s==1)
    val[s]=1;
    else
    {
        if(w%2==0)
        {
            val[s]=val[prev];
        }
        else
        {
            val[s] = 1-val[prev];
        }
    }
    vis[s]=1;
    for(int i=0;i<adj[s].size();i++)
    {
        int v = adj[s][i].first;
        if(vis[v]==0)
        {
            dfs(v,s,adj[s][i].second);
        }
    }
    
}




int main()
{ 
    ll N,i,u,v,w;
    cin>>N;
    
    for(i=1;i<=N-1;i++)
    {
        cin>>u>>v>>w;
        adj[u].pb(mp(v,w));
        adj[v].pb(mp(u,w));
    }
    
    dfs(1,-1,0);
    for(i=1;i<=N;i++)
    {
        cout<<val[i]<<endl;
    }
    return 0;
}
    
    
    
    
    
    
    
    
    

Measured memory_bytes: 8704
// scanf 等でエラーを出さないように追加
#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <algorithm>
#include <numeric>
#include <set>
#include <functional>
#include <utility>


using namespace std;


typedef long long ll;


const int MAX_N = 1000;
int N;
int T[MAX_N], A[MAX_N];

int main() {

	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &T[i], &A[i]);
	}


	ll answer = 0;
	ll now_t = T[0], now_a = A[0];

	for (int i = 1; i < N; i++) {

		if (T[i] >= now_t && A[i] >= now_a) {
			now_t = T[i];
			now_a = A[i];
		}
		else {

			if(now_t % T[i] != 0) now_t += T[i] - (now_t % T[i]);
			if(now_a % A[i] != 0) now_a += A[i] - (now_a % A[i]);

			ll new_t = T[i];
			new_t *= now_a / A[i];
			ll new_a = A[i];
			new_a *= now_t / T[i];

			if (new_t < now_t) {
				now_a = new_a;
			}
			else if (new_a < now_a) {
				now_t = new_t;
			}
			else {
				if (new_t + now_a < now_t + new_a) {
					now_t = new_t;
				}
				else {
					now_a = new_a;
				}
			}

		}

	}
	answer = now_t + now_a;

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=998244353;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact(2000010);
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
signed main(){
    int n,k;
    cin>>n>>k;
    double ans=0;
    for(int i=1;i<=n;i++){
        double p=1;
        int j=i;
        while(j<k){
            j*=2;
            p/=2;
        }
        ans+=p;
    }
    printf("%.12lf\n",ans/n);
    return 0;
}

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

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


    ll n;
    cin>>n;
    ll sq = sqrt(n)+1;
    ll ans = 0;
    for(int i=2;i<=sq;i++){
        int cnt  = 0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        ll cur = 1;
        while(cnt>0){
            if(cnt-cur>=0){
                ans++;

            }
            cnt-=cur;
            cur++;
        }

    }
    if(n>1){
        ans++;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3696
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int d;
  cin >> d;
  cout << "Christmas";
  while (d < 25) {
    cout << " Eve";
    d++;
  }
}
#endif


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector <int> dp(m+1,0);
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int tmp;
            cin >> tmp;
            dp[tmp]++;
        }
    }
    int ans = 0;
    for(int i = 1; i <= m; i++){
        if(dp[i]==n)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3556
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007LL;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void B_task();

int main()
{
	B_task();
	fflush(stdout);
	return 0;
}

static void B_task()
{
	char dance[101] = { 0 };
	getstring(dance);
	
	int len = strlen(dance);
	const char* ans = "Yes\n";
	for (int i = 0; i < len; i++) {
		char c = dance[i];
		if ((i + 1) % 2) {
			if ((c != 'R') && (c != 'U') && (c != 'D')) {
				ans = "No\n";
				break;
			}
		}
		else {
			if ((c != 'L') && (c != 'U') && (c != 'D')) {
				ans = "No\n";
				break;
			}
		}
	}
	printf(ans);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count =0;
		String s = sc.next();
		for (int i=0;i<1000;i++) {
			String temp = String.valueOf(i);
			StringBuffer sb = new StringBuffer();
			for (int j =temp.length();j<3;j++) {
				sb.append(0);
			}
			sb.append(temp);
			temp = sb.toString();
			int j =0;
			for (;j<s.length();j++) {
				if (temp.charAt(0)==s.charAt(j)) {
					j++;
					break;
				}
			}
			if (j==s.length()) {
				continue;
			}
			for (;j<s.length();j++) {
				if (temp.charAt(1)==s.charAt(j)) {
					j++;
					break;
				}
			}
			if (j==s.length()) {
				continue;
			}
			for (;j<s.length();j++) {
				if (temp.charAt(2)==s.charAt(j)) {
					break;
				}
			}
			if (j==s.length()) {
				continue;
			}
			count ++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 39436
import sys
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(2*10**5)
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    repn = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v = map(int, input().split())
        repn[u - 1].append(v - 1)
        repn[v - 1].append(u - 1)
    
    length = [0] * (N + 1)
    dp = [-1]

    """
    やはり各頂点でLIS配列を取ると配列コピーの時間がかかってTLEするので、
    配列は唯一つを扱って、DFSからバックするときに配列も元に戻す操作を行いたい
    （ここの実装の仕方がわからなかった）

    これはdfsを再帰で書いた後に復元操作を追記すれば異常に楽に書ける。。。
    """

    def dfs(v, p=N):
        if A[v] > dp[-1]:
            dp.append(A[v])
            length[v] = length[p] + 1
            for u in repn[v]:
                if u == p: continue
                dfs(u, v)
            dp.pop()
        else:
            length[v] = length[p]
            idx = bisect_left(dp, A[v]) # bisect_rightだとdpに重複する値を書き込んでしまうのでダメ
            old = dp[idx]
            dp[idx] = A[v]
            for u in repn[v]:
                if u == p: continue
                dfs(u, v)
            dp[idx] = old
        #print("v={}, len={}, dp={}".format(v, length[v], dp))

    dfs(0)
    length.pop()
    for ans in length:
        print(ans)
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 347980
import scala.io.StdIn.{readLine,readDouble}

object Main extends App {

  def read():Unit = {
    val n = readDouble
    if(n!=0) {
      val line = readLine.split(" ").map(_.toDouble)
      val avg = line.sum / n

      println(Math.sqrt(line.foldLeft(0d)( (x,y) => x + (y - avg)*(y - avg) )/n))
      read()
    }
  }

  read()
}

Measured memory_bytes: 45172
# encoding:utf-8
import copy
import numpy as np
import random
import queue

n = int(input())

withdraws = [1]
price = 1
while True:
    price *= 6
    if price <= 10**5 and price <= n:
        withdraws.append(price)
    else:
        break

price = 1
while True:
    price *= 9
    if price <= 10**5 and price <= n:
        withdraws.append(price)
    else:
        break


withdraws.sort(reverse = True)
# print(withdraws)
money = 0
count = 0


# 幅優先探索
'''
que = queue.Queue()

que.put((0,0))
memory = []
while not(que.empty()):
    money,count = que.get()
    print(money,count)
    if money > n:
        pass
    else:
        for withdraw in withdraws:
            if money+withdraw == n:
                print(count+1)
                exit()

            elif money+withdraw in memory:
                pass
            else:
                memory.append(money+withdraw)
                next = (money+withdraw,count+1)
                que.put(next)
'''

# 分割

ans = 10**10
if n < 6:
    ans = n
for i in range(n+1):
    t = i
    count = 0
    while t>0:
        count += t%6
        t = t//6
    t = n - i
    while t>0:
        count += t%9
        t = t//9
    # print(ans)
    ans =min(ans,count)

print(ans)


Measured memory_bytes: 13408
// Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#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--)

// Type
template <typename T> using P = pair<T, T>;
using ll = long long;
using ull = unsigned long long;

// Constants
const ll INF = 1e18;
const ll MOD = 1000000007;


int gcd(int a, int b) {
  int greater = max(a, b), less = min(a, b);
  if(less == 0) return greater;

  int remainder = greater % less;
  if(remainder == 0) {
    return less;
  } else {
    return gcd(less, remainder);
  }
}

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

  int A[N];
  rep(i, N) cin >> A[i];

  int L[N + 2];
  fill((int*)L, (int*)(L+N+2), 0);
  rep(i, N) L[i + 1] = gcd(L[i], A[i]);

  int R[N + 2];
  fill((int*)R, (int*)(R+N+2), 0);
  rrep(i, N) R[i + 1] = gcd(R[i+2], A[i]);

  int M[N];
  rep(i, N) {
    M[i] = gcd(L[i], R[i+2]);
  }

  int res = 0;
  rep(i, N) res = max(res, gcd(L[i], R[i+2]));
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
typedef long long int           ll;
typedef unsigned long long int  ull;

ull check_bit(ull N,int POS){return (N & (1ULL<<POS));}

vector<ull>v;
ull gaussian_elimination()
{
    int n=v.size();
    int ind=0;  // Array index
    for(int bit=log2(v[0]);bit>=0;bit--)
    {
        int x=ind;
        while(x<n&&check_bit(v[x],bit)==0)
            x++;
        if(x==n)
            continue; // skip if there is no number below ind where current bit is 1
        swap(v[ind],v[x]);
        for(int j=0;j<n;j++)
        {
            if(j!=ind&&check_bit(v[j],bit))
                v[j]^=v[ind];
        }
        ind++;
    }
    ull ans=v[0];
    for(int i=1;i<n;i++)
        ans=max(ans,ans^v[i]);
    return ans;
}
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    vector<int>cnt(61);
    rep(i,n){
        show((bitset<7>(a[i])));
        rep(j,61){
            if(a[i] >> j & 1)cnt[j]++;
        }
    }
    show(cnt);
    ll ans = 0;
    rep(j,61)if(cnt[j]&1){
        ans += 1LL << j;
        cnt[j] = 0;
        rep(i,n)if(a[i] >> j & 1){
            a[i] ^= 1LL<<j;
        }
    }
    rep(i,n)v.push_back(a[i]);
    sort(v.rbegin(),v.rend());
    cout << ans + gaussian_elimination() * 2 << endl;
}


Measured memory_bytes: 2168
def function(N, A):
    money = 1000
    kabu = 0
    for i in range(N-1):
        if A[i] < A[i+1]:
            kabu = int(money/A[i])
            money += (A[i+1]-A[i])*kabu
    print(money)


if __name__ == '__main__':
    N = int(input())
    A = input().split()
    A = [int(a) for a in A]
    function(N, A)

    

Measured memory_bytes: 9116
sx,sy,tx,ty=map(int,input().split())
x=tx-sx;y=ty-sy
st="U"*y+"R"*x+"D"*y+"L"*(x+1)+"U"*(y+1)+"R"*(x+1)+"D"+"R"+"D"*(y+1)+"L"*(x+1)+"U"
print(st)


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

int main()
{
	int H, W;
	string s;
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> s;
			if (s == "snuke") {
				cout << char('A' + j) << i + 1 << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n,m; cin >> n >> m;
    vector<int> a(n),b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    auto aa(a);
    auto bb(b);
    set<int> sa,sb;
    rep(i,n) sa.insert(a[i]);
    rep(i,m) sb.insert(b[i]);
    if(sa.size()!=a.size() or sb.size()!=b.size()){
        cout << 0 << endl;
        return 0;
    }
    sort(all(a));
    sort(all(b));
    ll ans = 1;
    for(int i=n*m;i>0;i--){
        if(sa.count(i) && sb.count(i)) continue;

        int x = lower_bound(all(a), i) - a.begin();
        int y = lower_bound(all(b), i) - b.begin();
        x = n-x;
        y = m-y;

        if(sa.count(i) && !sb.count(i)){
            ans *= y;
        }else if(!sa.count(i) && sb.count(i)){
            ans *= x;
        }else{
            ll t = x * y - (n*m-i);
            ans *= t;
        }
        ans %= mod;
    }
    cout << ans << endl;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n;
    ll l;
    cin >> n >> l;

    vector<ll> a(n),sum(n);
    rep(i,0,n) cin >> a[i];
    sum[0]=a[0];
    rep(i,1,n) sum[i]=sum[i-1]+a[i];

    priority_queue<pair<ll,tuple<int,int,int>>,vector<pair<ll,tuple<int,int,int>>>> que;
    rep(i,0,n-1) if(a[i]+a[i+1]>=l) que.push({a[i]+a[i+1],make_tuple(i,i+1,i)});
    vector<int> head(n),tail(n);
    rep(i,0,n) head[i]=tail[i]=i;
    vector<int> ans;
    while(!que.empty()){
        auto p=que.top();
        que.pop();
        ll len=p.first;
        int s=get<0>(p.second),t=get<1>(p.second);
        if(head[s]!=s) continue;
        if(tail[t]!=t) continue;
        if(len<l) break;
        //show(s);
        //show(t);
        //show(len);
        //show(get<2>(p.second));
        head[t]=s;
        tail[s]=t;
        //cerr << head << endl;
        //cerr << tail << endl;
        ans.push_back(get<2>(p.second));
        if(s!=0){
            int s_=head[s-1],t_=s-1;
            ll len_=sum[t];
            if(s_>0) len-=sum[s_-1];
            que.push({len_,make_tuple(s_,t,t_)});
        }else if(t!=n-1){
            int s_=t+1,t_=tail[t+1];
            ll len_=sum[t_];
            if(s>0) len_-=sum[s-1];
            que.push({len_,make_tuple(s,t_,t)});
        }
    }
    if(ans.size()!=n-1){
        cout << "Impossible" << endl;
        return;
    }
    cout << "Possible" << endl;
    for(int i=n-2; i>=0; --i) cout << ans[i]+1 << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 6384
#include <iostream>
#include <vector>
#include <string>
 
using namespace std;
 
int main() {
  string s;
  cin >> s;
  for(int i = 0; i < 1 << 3; i++) {
    int sum = s[0] - '0';
    for(int j = 0; j < 3; j++) {
      if (i >> j & 1) {
        sum += s[j + 1] - '0';
      } else {
        sum -= s[j + 1] - '0';
      }
    }
    if (sum == 7) {
      cout << s[0];
      for(int j = 1; j < s.size(); j++) {
        if (i >> (j - 1) & 1) cout << "+"; else cout << "-";
        cout << s[j];
      }
      cout << "=7" << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = -10**18

for i in range(N):
    now = i
    visit = [False]*N
    visit[now] = True
    l = []
    
    for _ in range(N+10):
        nex = P[now]-1
        l.append(C[nex])
        
        if visit[nex]:
            break
        
        visit[nex] = True
        now = nex
    
    s = sum(l)
    now = 0
    
    for i in range(min(K, len(l))):
        now += l[i]
        ans = max(ans, now+(K-i-1)//len(l)*max(0, s))
    
print(ans)

Measured memory_bytes: 85548
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,b[200010];
struct node{
	LL v,ind;
}x[200010];
bool cmp(node a,node b){
	return a.v<b.v;
}
int main(){
	LL i,j,k;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x[i].v;
		x[i].ind=i;
	}
	sort(x,x+n,cmp);
	k=(n-1)/2;
	for(i=0;i<n;i++){
		j=x[i].ind;
		if(i>k)b[j]=x[k].v;
		else b[j]=x[k+1].v;
	}
	for(i=0;i<n;i++)cout<<b[i]<<endl;
	return 0;
}

Measured memory_bytes: 6912
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
n,k= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しに4 3sum変数使用はsum関数使用できないので注意
a.sort()
cnum = a[0]
ct =1
st = []
for i in range(1,n):
    if a[i] != cnum:
        cnum = a[i]
        st.append(ct)
        ct = 1
    else:ct+=1
st.append(ct)
st.sort(reverse=True)
total = 0
for i in range(min(k,len(st))):
    total+=st[i]
print(n-total)

Measured memory_bytes: 27188
#include<stdio.h>
int isprime(int);

int main(){

  int n,i=0;
  int is[10000];
  int ts;
  int cnt=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&is[i]);
  }

  for(i=0;i<n;i++){
    ts = isprime(is[i]);
    if(ts==1){
      cnt += 1;
    }
  }
    printf("%d\n",cnt);
    return 0;

  }


  int isprime(int x){
    int i;
    int true=1,false=0;

    if(x==2)
      return true;

    if(x < 2 || x%2==0)
    return false;

  i = 3;
  while(i*i <= x){
    if(x%i==0)
      return false;
    i = i + 2;
  }

  return true;
}

Measured memory_bytes: 632