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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] ncards = new String[n];
		for(int i=0; i<n; i++) ncards[i]=sc.next();

		int m = sc.nextInt();
		String[] mcards = new String[m];
		for(int i=0; i<m; i++) mcards[i]=sc.next();

		int count=0,ans=0;
		for(int i=0; i<n; i++) {
			String s = ncards[i];

			for (String string : ncards) {
				if(s.equals(string)) count++;
			}

			for (String string2 : mcards) {
				if(s.equals(string2)) count--;
			}
			if(ans < count) ans = count;
			count = 0;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21712
#include <stdio.h>

int main(void) {
	int case_num,current_case;
	long long x,y;
	long long rx,ry;
	long long rd,cd;
	long long dx,dy;
	scanf("%d",&case_num);
	for(current_case=0;current_case<case_num;current_case++) {
		x=y=0;
		rx=ry=0;
		rd=0;
		while(1) {
			scanf("%lld%lld",&dx,&dy);
			if(dx==0 && dy==0)break;
			x+=dx;y+=dy;
			cd=x*x+y*y;
			if(cd>rd || (cd==rd && x>rx)) {
				rd=cd;
				rx=x;ry=y;
			}
		}
		printf("%lld %lld\n",rx,ry);
	}
	return 0;
}

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

void CountingSort(vector<int>& A, vector<int>& B, vector<int>& C) {
  int n = A.size();
  for (int i = 0; i < n; i++) {
    C[A[i]]++;
  }
  for (int i = 1; i < 10001; i++) {
    C[i] = C[i] + C[i - 1];
  }
  for (int i = n - 1; i >= 0; i--) {
    B[C[A[i]] - 1] = A[i];
    C[A[i]]--;
  }
};

int main() {
  vector<int> C(10001, 0);
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  CountingSort(A, B, C);
  for (int i = 0; i < n; i++) {
    if (i != n - 1) cout << B[i] << ' ';
    else cout << B[i] << endl;
  }
};



Measured memory_bytes: 18404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 998244353
#define M 1000003
#define INF 1e9
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,q,i,j,t,k,l,r;
   	cin>>n;
   	int a[n+5],b[n+5],c[n+5];
   	for(i=0;i<n;i++){
   		cin>>a[i]>>b[i]>>c[i];
	}
	int dp[n+5],dp2[n+5],dp3[n+5];
	dp[0]=a[0];
	dp2[0]=b[0];
	dp3[0]=c[0];
	for(i=1;i<n;i++){
		if(dp2[i-1]>dp3[i-1]){
			dp[i] = dp2[i-1] + a[i];
		}else{
			dp[i] =dp3[i-1]+ a[i];
		}
		if(dp[i-1]>dp3[i-1]){
			dp2[i] = dp[i-1] + b[i];
		}else{
			dp2[i] =dp3[i-1] + b[i];
		}
		if(dp2[i-1]>dp[i-1]){
			dp3[i] = dp2[i-1] + c[i];
		}else{
			dp3[i] =dp[i-1] + c[i];
		}
	}
	cout<<max(dp[n-1],max(dp2[n-1],dp3[n-1]));
 }

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, L;
ll T[3005];
long double ansx, ansy;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> L;
    for(int i = 0; i < N; i++) cin >> T[i];
    for(int i = 0; i < N; i++) {
        double tansum = 0.0;
        double nowsum = 0.0;
        for(int num = 1; num < N; num++) {
            int index = (i + num) % N;
            long double theta = 2 * PI * (T[index] - T[i]) / L;
            if(index < i) theta += 2 * PI;
            theta /= 4;
            nowsum += (num - 1) * 0.5;
            nowsum -= 0.5 * tansum / tan(theta);
            tansum += tan(theta);
        }
        nowsum /= N * (N - 1) * (N - 2) / 6;
        long double theta = 2 * PI * (T[i]) / L;
        ansx += cos(theta) * nowsum;
        ansy += sin(theta) * nowsum;
    }
    cout << fixed << setprecision(15) << ansx << " " << ansy << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;



int32_t main()
{


    IOS


    int k;
    cin >> k;


    int x = k;
    int ans = 1;

    while(x%360 !=0)
    {
      x += k;
      ans++;
    }

    cout << ans;




    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
    int A[3];
    cin>>A[0]>>A[1]>>A[2];

    sort(A,A+3);

    cout<<A[0]+A[1]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
using namespace std;
int main(){
    string s;
    cin>>s;
    bool a=0,b=0;
    int i=0;
    for(i=0;i<s.size();i++){
        if(s[i]=='C'){
            a=1;
            break;
        }
    }
    for(;i<s.size();i++){
        if(s[i]=='F'){
            b=1;
            break;
        }
    }
    if(a&&b){
        puts("Yes");
    }else{
        puts("No");
    }
}

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

#define ll long long
#define pb push_back
#define ins insert
#define mp make_pair
#define pii pair<int, int>
#define pil pair<int, ll>
#define pib pair<int, bool>
#define SET(a, c) memset(a, c, sizeof(a))
#define MOD 1000000007
#define enld endl
#define endl "\n"
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define FOUND(u, val) u.find(val) != u.end()
#define max_self(a, b) a = max(a, b);

#include <string>
#include <vector>
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
//#include <algorithm>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <cmath>
//#include <cstring>
//#include <sstream>
//#include <stack>
//#include <queue>
int n;
vl pre;
vl ar;

ll recurse(int i, int j, bool player) {
    if (i == j)
        return ar[i];
    ll best = 0;
    if (player) {
        best = ar[i] + ((pre[j + 1] - pre[i + 1]) - recurse(i + 1, j, 0));
        best = max(best, ar[j] + ((pre[j] - pre[i]) - recurse(i, j - 1, 0)));
    } else {
        // Other player's turn so Player 1 does not get points for choosing
        // Also, player 2 will make move that gives least poitns to Player 1
        ll worst = ((pre[j + 1] - pre[i + 1]) - recurse(i + 1, j, 1));
        ll worst2 = max(worst, ((pre[j] - pre[i]) - recurse(i, j - 1, 1)));
        cout << " worst: " << worst << endl;
        cout << " worst2: " << worst << endl;
        best = worst2;
    }
    cout << "Player " << (player ? 1 : 2) << " | " << i << " " << j << "  == " << best << endl;
    return best;
}

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

    cin >> n;
    ar.resize(n);
    pre.resize(n + 1);

    for (int i = 0; i < n; i++) {
        cin >> ar[i];
        pre[i + 1] = pre[i] + ar[i];
    }

    // ll ans = recurse(0, n - 1, 1);

    ll dp[n][n];
    for (int L = n - 1; L >= 0; --L) {
        for (int R = L; R < n; ++R) {
            if (L == R) {
                dp[L][R] = ar[L];
            } else {
                dp[L][R] = max(ar[L] - dp[L + 1][R], ar[R] - dp[L][R - 1]);
            }
        }
    }

    cout << dp[0][n - 1];
}

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

int main(){

    int N,ans=-1000000005;
    cin>>N;
    vector<vector<int>> F(N,vector<int>(10)),P(N,vector<int>(11));
    vector<int> f(N);
    for(int i=0;i<N;i++){
        for(int j=0;j<10;j++){
            cin>>F[i][j];
            if(F[i][j]==1){
                f[i] |=(1<<(9-j));
            }
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<11;j++){
            cin>>P[i][j];
        }
    }
        for(int j=1;j<(1<<10);j++){
            int cnt=0;
            for(int i=0;i<N;i++){
            int k=(f[i]&j);
            cnt+=P[i][__builtin_popcount(k)];
        }
            ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
def redistribution(dif,minus,plus):
    while dif[minus] < 0:
        if dif[minus] + dif[plus] >= 0: #一部充当
            dif[plus] = dif[plus] + dif[minus]
            dif[minus] = 0
        else: #全部充当
            dif[minus] = dif[minus] + dif[plus]
            dif[plus] = 0
            plus -= 1
    minus += 1
    return [minus,plus]

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
check = True
for i in range(n):
    if a[i] < b[i]:
        check = False
if sum(b) > sum(a):
    print("-1")
elif check:
    print("0")
else:
    dif = []
    for i in range(n):
        dif.append(a[i]-b[i])
    dif.sort()
    minus = 0
    plus = -1
    while dif[minus] < 0:
        temp = redistribution(dif,minus,plus)
        minus = temp[0]
        plus = temp[1]
    print(abs(plus)+minus)


Measured memory_bytes: 19188
{
  const main = (
    input: string
  ): void | string | number | string[] | number[] => {
    const r = _reader(input)
    const [H, N] = r.nn()
    const A = r.nn()

    const sum = A.reduce((a, b) => b + a, 0)

    return H - sum > 0 ? 'No' : 'Yes'
  }

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
  if (typeof _res === 'object') console.log(_res.join(' '))
}


Measured memory_bytes: 16716
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\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 P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<ll> T(n);
  rep (i, n) cin >> T[i];
  
  ll ans = T[0];
  for (int i = 1; i < T.size(); i++) {
   ans = ans / gcd(ans, T[i]) * T[i];
  }

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


Measured memory_bytes: 3588
#include <iostream>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  int x_a=x-a;
  int x_b=x-b;
  if(x_a*x_a<x_b*x_b){
    cout<<"A";
  }else{
    cout<<"B";
  }
  return 0;
}

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

int main(void) {
  int n;
  bool flag = false;
  cin >> n;
  
  for (int i = 0; i * 4 <= n; i++) {
    if ((n - i * 4) % 7 == 0) {
      flag = true;
      break;
    }
  }
  
  cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#define rep(i,n) for(int i=0; i<n; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	ll N;
	cin >> N;
	vll A(N);
	vll ans(N,0);
	rep(i,N-1){
		cin >> A[i];
		ans[A[i]-1]++;
	}

	rep(i,N){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 6364
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	string str;
	cin >> str;
	
	string ans="";
	for(int i=0; i<str.size(); i++) {
		if (str[i] == 'B') {
			ans = ans.substr(0, ans.size()-1);
		} else {
			ans += str[i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
  int N;
  cin >> N;
  int odd = 0, even = 0;
  for (int i=0; i<N; i++) {
    int tmp;
    cin >> tmp;
    if (tmp % 2) odd ++; else even ++;
  }
  if (odd % 2) printf("NO\n"); else printf("YES\n");
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forn(i,o,n) for(int i=o;i<n;i++)
#define int long long
#define endl "\n"
#define mod 1000000007
#define mod2 998244353
#define double long double
#define pb push_back
#define mk make_pair
#define swap(x,y) (x^=y^=x^=y)
#define TT int ttt;cin>>ttt;while(ttt--)
#define oo 2000000000000000000


using namespace std;

int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b); 
}
bool isPrime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
int modexpo(int x,int p){
    int res = 1;
    x = x%mod;
    while(p){
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

int max(int a,int b){
    if(a>b){
        return a;
    }
    return b;
}

int min(int a,int b){
    if(a<b){
        return a;
    }
    return b;
}

int32_t main(){
    IOS
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int cost[n];
    for(int i=0;i<n;i++){
        cost[i] = 1000000000;
    }
    cost[0]=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j>=n){
                break;
            }
            cost[i+j] = min(cost[i+j],cost[i]+abs(arr[i]-arr[i+j]));
        }
    }
    /*for(int i=0;i<n;i++){
        cout<<cost[i]<<" ";
    }
    cout<<endl;*/
    cout<<cost[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    sort(ALL(a));
    ll ans = 0, tmp = 0;
    if(n & 1){
        vll b(a.begin(), a.begin()+n/2);
        vll c(a.begin()+n/2, a.end());
        vll b2(a.begin(), a.begin()+n/2+1);
        vll c2(a.begin()+n/2+1, a.end());
        dump(b, c, b2, c2);
        rep(i, SZ(c)) tmp += c[i];
        repr(i, 2, SZ(c)) tmp += c[i];
        rep(i, SZ(b)) tmp -= 2*b[i];
        chmax(ans, tmp);
        tmp = 0;
        rep(i, SZ(c2)) tmp += 2*c2[i];
        rep(i, SZ(b2)) tmp -= b2[i];
        rep(i, SZ(b2)-2) tmp -= b2[i];
        chmax(ans, tmp);
    }else{
        rep(i, n/2) ans -= a[i];
        rep(i, n/2-1) ans -= a[i];
        repr(i, n/2, n) ans += a[i];
        repr(i, n/2+1, n) ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

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

#define INF INT_MAX/2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

   int n;
   cin>>n;
   vector<string>s(n);
   for(int i=0;i<n;i++)cin>>s[i];
   vector<int>ans(26,INF);
   for(int i=0;i<26;i++){
      for(int j=0;j<n;j++){
         int c = 0;
         for(int k=0;k<s[j].size();k++){
            if(s[j][k] == (char)('a'+i))c++;
         }
         ans[i] = min(ans[i],max(c,0));
      }
   }
   //for(int i=0;i<n;i++)cout<<ans[i]<<" "<<((char)('a'+i))<<endl;
   for(int i=0;i<26;i++){
      for(int j=0;j<ans[i];j++){
         cout<<(char)('a'+i);
      }
   }
   cout<<endl;
   return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

int main() {
    ll n;
    cin >> n;
    int m = sqrt(n);
    int a;
    for(int i = m+1; i>=1; i--){
        if(n % i == 0){
            a = i;
            break;
        }
    }
    int b = n/a;
    string c = to_string(a);
    string d = to_string(b);
    cout << max(c.size(), d.size()) << endl;
    //cout << m <<  c << d << endl;
}

Measured memory_bytes: 256
N = int(input())
TT = [int(i) for i in input().split()]
M = int(input())
PP = []
XX = []
for _ in range(M):
    P, X = [int(i) for i in input().split()]
    PP.append(P)
    XX.append(X)

maxTime = 0
sumTime = sum(TT)
for i in range(len(PP)):
    print(sumTime - (TT[PP[i] - 1] - XX[i]))


Measured memory_bytes: 3064
def readinput():
    n=int(input())
    h=list(map(int,input().split()))
    return n,h

def main(n,h):
    maxstep=0
    step=0
    for i in range(n-1):
        if h[i]>=h[i+1]:
            step+=1
        else:
            maxstep=max(maxstep,step)
            step=0
    else:
        maxstep=max(maxstep,step)
    return maxstep

if __name__=='__main__':
    n,h=readinput()
    ans=main(n,h)
    print(ans)


Measured memory_bytes: 20424
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int n, m, c, s, g;
	while(cin >> n >> m >> c >> s >> g, n) {
		vector<vvi> rail(c, vvi(n, vi(n, INF)));
		int x, y, d, e;
		REP(i, m) {
			cin >> x >> y >> d >> e;
			rail[e-1][x-1][y-1] = min(d, rail[e-1][x-1][y-1]);
			rail[e-1][y-1][x-1] = min(d, rail[e-1][y-1][x-1]);
		}

		REP(l, c) {
			REP(k, n) {
				REP(i, n) {
					REP(j, n) {
						rail[l][i][j] = min(rail[l][i][j], rail[l][i][k]+rail[l][k][j]);
					}
				}
			}
		}

		vi p(c);
		REP(i, c) {
			cin >> p[i];
		}

		vvi q(c, vi());
		vvi r(c, vi());
		int tmp;
		REP(i, c) {
			REP(j, p[i]-1) {
				cin >> tmp;
				q[i].push_back(tmp);
			}
			REP(j, p[i]) {
				cin >> tmp;
				r[i].push_back(tmp);
			}
			q[i].push_back(20000);
		}

		vvi fee(c, vi(20000+1));
		REP(l, c) {
			int pos = 0;
			FOR(i, 1, 20000) {
				fee[l][i] = fee[l][i-1] + r[l][pos];
				if(q[l][pos] == i) {
					pos++;
				}
			}
		}

		REP(l, c) {
			REP(i, n) {
				REP(j, n) {
					if(rail[l][i][j] != INF) {
						rail[l][i][j] = fee[l][rail[l][i][j]];
					}
				}
			}
		}			

		vvi cost(n, vi(n, INF));
		REP(l, c) {
			REP(i, n) {
				REP(j, n) {
					cost[i][j] = min(cost[i][j], rail[l][i][j]);
				}
			}
		}

		REP(k, n) {
			REP(i, n) {
				REP(j, n) {
					cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
				}
			}
		}

		cout << (cost[s-1][g-1] == INF ? -1 : cost[s-1][g-1]) << endl;
	}

	return 0;
}

Measured memory_bytes: 3756
n = int(input())
ds = [int(x) for x in input().split()]
ds2 = [x*x for x in ds]
s = 0
s2 = 0
for i in range(n):
  s += ds[i]
  s2 += ds2[i]
ss = 0
for i in range(n):
  ss += ds[i] * s

print((ss - s2) // 2)

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int N, M, X; cin >> N >> M >> X;
    int lower = 0, upper = 0;
    rep(i, 0, M) {
      int in; cin >> in;
      if (in < X) ++lower;
      else if (X < in) ++upper;
    }
  
    cout << min(lower, upper) << endl;
}


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

using namespace std;

#define ll long long
typedef complex<double> P;

int main() {
  int n, m; cin >> n >> m;
  vector<int> adj[n];

  for (int i = 0; i < m; i++) {
    int v, u; cin >> v >> u;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }

  int sd[n] = {1};
  queue<int> que;
  que.push(0);
  int c = 1;

  while (!que.empty()) {
    int v = que.front(); que.pop();

    for (int i = 0; i < adj[v].size(); i++) {
      if(!sd[adj[v][i]]) {
        que.push(adj[v][i]);
        sd[adj[v][i]] = c;
      }
    }

    if(que.empty()) {
      for (int i = 0; i < n; i++) {
        if(!sd[i]) {
          sd[i] = ++c;
          que.push(i);
          break;
        }
      }
    }

  }

  int q; cin >> q;
  for (int i = 0; i < q; i++) {
    int s, t; cin >> s >> t;
    if(sd[s] == sd[t]) {
      cout << "yes" << endl;
    }
    else {
      cout << "no" << endl;
    }
  }
}

Measured memory_bytes: 8964
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,cc,ans=0,s[200005]={},t[200005]={},c[200005]={},cnt[200005]={};
  cin >> n >> cc;
  for(int i=0; i<n; i++) {
    cin >> s[i] >> t[i] >> c[i];
  }
  for(int i=1; i<=cc; i++) {
    int tt[200005]={};
    for(int j=0; j<n; j++) {
      if(c[j]==i) {
        tt[s[j]*2-1]++,tt[t[j]*2]--;
      }
    }
    for(int j=1; j<200005; j++) {
      tt[j]+=tt[j-1];
    }
    for(int j=0; j<200005; j++) {
      if(tt[j]) {
        cnt[j]++;
      }
    }
  }
  for(int i=0; i<200005; i++) {
    ans=max(ans,cnt[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int a[10000000];
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}

int main(){
    int A=read();
    int B=read();
    int C=read();
    cout<<C<<" "<<A<<" "<<B<<endl;
 	return 0;
} 

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

int main()
{
    int h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int diff;
    if(m2 >= m1){
        diff = 60 * (h2 - h1) + m2 - m1;
    }else{
           diff = 60 * (h2 - h1 - 1) + 60 - (m1-m2);
    }
    cout << diff - k << endl;

    return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner;

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

        String s = stdIn.next();
        char[] cs = s.toCharArray();

        if(cs[0] == cs[1] && cs[1] == cs[2]){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 21844
fun main(args: Array<String>) {
    val s = readLine()!!
        .replace("BC","X")
        .replace('B','Y')
        .replace('C','Y')
        .split("Y")
    var result = s.map {
        var count = 0.toLong()
        var acount=0
        it.forEach {c->
            if(c=='A')acount+=1
            else count+=acount
        }
        count
    }.sum()
    println(result)
}

Measured memory_bytes: 60240
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    A,B = map(int, lines.pop(0).split(' '))
    if A <= 8 and B <= 8:
        print('Yay!')
    else:
        print(':(')


#
# main
#

# 1. use list instead of stdin

# contents = '''\
# 2 9\
# '''
# lines = contents.split('\n')

# 2. use stdin

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            int a = 100000;
            int n = Integer.parseInt(br.readLine());
            for(int i=0;i<n;i++){
                 a = ((int)(a*1.05+999)/1000)*1000;
            }
            System.out.println(a);
        }catch(Exception ex){
            System.exit(0);
        }
    }
}

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

using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second
 
template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

const int MOD = 1e9 + 7;
const int N = 2e5;

int fact[N+1];

int mul(int a, int b)
{
    return (a * 1LL * b) % MOD;
}

int add(int a, int b)
{
    return (a + b) % MOD;
}

int modPow(int a, int b)
{
    int ans = 1;
    while(b)
    {
        if(b & 1)
            ans = mul(ans, a);
        a = mul(a, a);
        b >>= 1;
    }

    return ans;
}

int nCk(int n, int k)
{
    if(k > n)
        return 0;
    int ans = fact[n];
    int t1 = modPow(fact[k], MOD-2);
    int t2 = modPow(fact[n-k], MOD-2);
    return mul(ans, mul(t1, t2));
}

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

    fact[0] = fact[1] = 1;

    for(int i = 2; i <= N; ++i)
        fact[i] = mul(fact[i-1], i);
    
    int n, k;
    cin >> n >> k;
    k = min(n-1, k);

    int ans = 0;

    for(int i = 0; i <= k; ++i)
    {
        int temp = mul(nCk(n-1, i), nCk(n, i));
        //cout << "------------\n";
        //cout << i << " " << temp << "\n";
        //cout << "------------\n";
        ans = add(ans, temp);
    }

    cout << ans << "\n";
}


Measured memory_bytes: 4404
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 *
 * @author 97797
 */
public class Main {
    public static void main(String[] args) {
//        List list = Arrays.asList("()()", "(())");
//        Collections.sort(list);
//        System.out.println(list);
        System.out.println(new Main().run(args, System.in));
    }
    public String run(String[] args, InputStream in) {
        String result = null;
        try {            
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            int N = Integer.parseInt(reader.readLine());
            List<String> list = Stream.of(reader.readLine().split("")).collect(Collectors.toList());
            
            
            int L = 0;
            int R = 0;
            for (int i = 0; i < list.size(); i++) {
                String s = list.get(i);
                if (s.equals(")")) {
                    if (L == 0) {
                        R++;
                    } else {
                        L--;
                    }
                    if (R > 0) {
                        list.add(0, "(");
                        i++;
                        R--;
                    }                    
                } else {
                    L++;                    
                }
            }
            for (int i = 0; i < L; i++) {
                list.add(")");   
            }
            result = String.join("", list);            
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }
}


Measured memory_bytes: 27988
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;


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




int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    FOR(i, 1, n) {
        cin >> a[i];
    }
    vector<ll> num(n);
    FOR(i, 1, n) {
        ll boss = a[i]-1;
        num[boss] += 1;
    }
    REP(i, n) {
        cout << num[i] << endl;
    }
}


Measured memory_bytes: 6428
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
dic = Counter(A)
sticks = []
for i in dic:
    s = dic[i]
    if s>=4:
        sticks.append(i)
    if s>=2:
        sticks.append(i)
if len(sticks)<2:
    print(0)
else:
    sticks.sort(reverse=True)
    print(sticks[0]*sticks[1])

Measured memory_bytes: 18592
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

int main(){
	int n, x, base = 0, min = 1000;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		base += temp;
		if (temp < min) min = temp;
	}
	cout << n + (x - base) / min << endl;
}

Measured memory_bytes: 256
A,B,C,D,E,F=map(int,input().split())
conc = 0.0
liq,sug = 100*A,0
for a in range(1 + F//(100*A)):
  for b in range(1 + (F-100*A*a)//(100*B)):
    if a + b < 1 or F <= 100*(A*a + B*b):
      break
    for c in range(1 + min(((A*a+B*b)*E)//C,F-100*(A*a+B*b))):
      for d in range(1 + min(((A*a+B*b)*E-C*c)//D,F-100*(A*a+B*b)-C*c)):
        tmp_sug = C*c+D*d
        tmp = 100*(A*a+B*b)+tmp_sug
        if tmp <= F and tmp_sug <= (A*a+B*b)*E and conc < (100*tmp_sug/tmp):
          conc = (100*tmp_sug/tmp)
          liq = tmp
          sug = tmp_sug
print(liq,sug)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0};
const int INF = 1e9+101;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(ll i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    ll a = LINF;
    int idx = -1;
    ll ans = 0;
    int ret = 0;
    int zr = 0;
    rep(i,N){
        cin >> A[i];
        if (a > abs(A[i])) {
            a = abs(A[i]);
            idx = i;
        }
        if(A[i] < 0) {
            ret++;
        }
        if(A[i] == 0){
            zr++;
        }
    }

    if(ret % 2 == 0 || zr > 0) {
        rep(i,N){
            ans += max(A[i], -A[i]);
        }
    } else {
        rep(i,N){
            if(i == idx) ans += -a;
            else{
                ans += max(A[i], -A[i]);
            }
        }
    }

    printf("%lld\n",ans);

    return 0;  
}

Measured memory_bytes: 1024
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
	sort(all(a), greater<int>());
	
	int al, bo;
	al = bo = 0;
	rep(i, n) {
		if (i % 2 == 0) {
			al += a[i];
		}
		else {
			bo += a[i];
		}
	}
	cout << al - bo;

	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <functional>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF 100000000000000005LL
#define INF (int)1e9+1
#define endl '\n'
#define pb push_back

// debug 도구

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto& x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}\n";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)

// debug 도구 end

using llong = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VLL = vector<long long>;
using PII = pair<int, int>;

//struct cmp {
//	bool operator() (int a, int b)
//	{
//		return a > b;
//	}
//};

int main() {
    IOS;

    int n;
    cin >> n;
    cout << 10-n / 200 ;
    return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define vi vector<int>

#define ll long long int

int ctoi(char c) {return c-'0';}
int ord(char c) {return c-'a';}
int len(string s) {return s.length();}
int itoc(int i) {return i+'a';}


int main() {
string s;
cin>>s;
for(auto x: s) cout<<'x';
cout<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	double sum=0.0;
	cin >> n;
	vector<double> v(n+1);
	loop(i, 1, n+1) cin >> v[i];

	sort(all(v));
	sum = (v[1]+v[2])/pow(2.0, double(n-1));

	for(lli i=3; i<n+1; i++){
		double t = pow(2.0, double(n-i+1));
		sum += v[i]/t;
	}
	cout << fixed << setprecision(15) << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
n = int(input())
list1 = []
def f(k):
   list2 =  ["".join(x) for x in itertools.product(["3","5","7"],repeat=k) ]
   return [int(x) for x in list2 if ("3" in x) and ("5" in x) and ("7" in x)]

for i in range(3,10):
  list1 += f(i)

print(sum(1 for x in list1 if x<=n))


Measured memory_bytes: 44912
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int X, Y, A, B; cin >> X >> Y >> A >> B;
    int C; cin >> C;
    vl P(A), Q(B), R(C); F0R(i, A) cin >> P[i];
    F0R(i, B) cin >> Q[i];
    F0R(i, C) cin >> R[i];
    sort(all(P)); reverse(all(P));
    sort(all(Q)); reverse(all(Q));
    sort(all(R)); reverse(all(R));

    ll ans = 0;
    ll preP[A+1], preQ[B+1], preR[C+1];
    preP[0] = 0; preQ[0] = 0; preR[0] = 0;
    F0R(i, A) {
        preP[i+1] = preP[i] + P[i];
    }
    F0R(i, B) {
        preQ[i+1] = preQ[i] + Q[i];
    }
    F0R(i, C) {
        preR[i+1] = preR[i] + R[i];
    }

    F0R(i, X+1) {
        int redC = X - i;
        if (redC > C) continue;
        int lo = 0, hi = Y;
        int best = 0;
        while (lo < hi) {
            int mid = (lo+hi)/2; best = hi;
            int blueC = Y - mid;
            if (redC + blueC > C) {
                lo = mid+1; continue;
            }
            bool bad1 = false, bad2 = false;
            if (blueC > 0 && mid != B && Q[mid] > R[redC + blueC - 1]) bad1 = true;
            if (mid != 0 && blueC + redC != C && Q[mid-1] < R[redC + blueC]) bad2 = true;
            if (bad1) {
                lo = mid+1;
            } else if (bad2) {
                hi = mid-1;
            } else {
                best = mid; break;
            }
        }

        ans = max(ans, preP[i] + preQ[best] + preR[X+Y-i-best]);

    }

    cout << ans << endl;

	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 4992
n, x, m = map(int, input().split())
MAXM = 101010
visited = [-1 for _ in range(MAXM)]
a = x
loop = [a]
visited[a] = 0
ans = 0
for i in range(1, n):
    a = a**2%m
    if visited[a] < 0:
        visited[a] = i
        loop.append(a)
    else:
        ii = visited[a]
        l = sum(loop[ii:i]) # ループの和
        ll = i-ii # ループの長さ
        ans += sum(loop[:ii]) # ループに入るまでの和
        l_n = (n-ii)//ll # ループの回数
        ans += l*l_n
        rem = n-ii-ll*l_n # 残りの長さ
        ans += sum(loop[ii:rem+ii])
        break
if ans == 0:
    ans = sum(loop)
print(ans)

Measured memory_bytes: 73496
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
public static void main(String[] args) throws IOException {

BufferedReader br =new BufferedReader (new InputStreamReader (System.in));

String line = br.readLine( );
String[] list = line.split(" ");
int a = Integer.parseInt(list[0]);
int b = Integer.parseInt(list[1]);

System. out. println(a+b>=10?"error":a+b);
}}

Measured memory_bytes: 22996
from collections import Counter
from functools import reduce

N,P = list(map(int,input().split()))
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

counter = Counter(prime_factorize(P))

ans = reduce(lambda total, x: total * x[0] ** (x[1]//N), counter.items(), 1)
print(ans)



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

long c[27], s[366][27], t[366], last[27];
int main()
{
    int D; cin>>D;
    for(int i=1; i<=26; ++i) cin>>c[i];
    for(int i=1; i<=D; ++i)
        for(int j=1; j<=26; ++j)
            cin>>s[i][j];

    auto calc_score=[&](){
        long score=0;
        for(int d=1; d<=D; ++d) {
            score+=s[d][t[d]];
            last[t[d]]=d;
            for(int i=1; i<=26; ++i) score-=c[i]*(d-last[i]);
        }
        return score;
    };

    for(int i=1; i<=D; ++i) {
        long bestscore=-(1L<<60), typ=1;
        for(int j=1; j<=26; ++j) {
            t[i]=j;
            auto score=calc_score();
            t[i]=0;
            if (bestscore<score) {
                bestscore=score;
                typ=j;
            }
        }
        t[i]=typ;
    }

    for(int i=1; i<=D; ++i) cout<<t[i]<<endl;
}


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

int main()
{
    int n,c,k;
    int sum=0;
    int a[100005]={0};
    scanf("%d%d%d",&n,&c,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    queue <int> q;
    int cnt=0;
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
    {
        if(q.empty()||((a[i]-q.front())<=k&&cnt<c))
        {
            q.push(a[i]);
            cnt++;
        }
        else
        {
            while(!q.empty())
            {
                q.pop();
            }
            q.push(a[i]);
            cnt=1;
            sum++;
        }
    }
    printf("%d\n",sum+1);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
int main()
{
	dhoom;
	ll d , n;
	cin >> d >> n;
	ll power = 1;
	for(int i = 1 ; i <= d ; i++)
		power *= 100;
	if(n == 100LL)
		n++;
	cout << n * power << endl;

	return 0;
} 



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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, M;
signed main() {
    cin >> N >> M;
    if (N == M) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }
}


Measured memory_bytes: 256