akhauriyash/Code-Regression huggingface dataset:
import math

def solve():
    N = int(input())
    S = input()
    R = []
    G = []
    B = []

    # color separate
    for i in range(len(S)):
        if S[i] == 'R':
            R.append(i)
        elif S[i] == 'G':
            G.append(i)
        elif S[i] == 'B':
            B.append(i)

    # after color map
    lR = len(R)
    lG = len(G)
    lB = len(B)
    RGBmap = []
    for i in range(len(S)):
        if S[i] == 'R':
            lR -= 1
        elif S[i] == 'G':
            lG -= 1
        elif S[i] == 'B':
            lB -= 1
        RGBmap.append([lR, lG, lB])

    # calculate
    sum = 0
    for i in range(len(S)):
        if S[i] == 'R':
            a1 = G
            a2 = B
            b1 = 2
            b2 = 1
            c1 = 'B'
            c2 = 'G'
        elif S[i] == 'G':
            a1 = R
            a2 = B
            b1 = 2
            b2 = 0
            c1 = 'B'
            c2 = 'R'
        else:
            a1 = G
            a2 = R
            b1 = 0
            b2 = 1
            c1 = 'R'
            c2 = 'G'
        for a in a1:
            if i < a:
                sumb = RGBmap[a][b1]
                if sumb == 0:
                    continue
                if a + (a - i) < len(S) and S[a + (a - i)] == c1:
                    sumb -= 1
                sum += sumb
        for a in a2:
            if i < a:
                sumb = RGBmap[a][b2]
                if sumb == 0:
                    continue
                if a + (a - i) < len(S) and S[a + (a - i)] == c2:
                    sumb -= 1
                sum += sumb
    print(sum)
 

if __name__ == '__main__':
    solve()


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(2e3) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#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++)


int main() {
    int n,k;
    P p[55];
    cin >> n >> k;
    REP(i,n){
        cin >> p[i].first >> p[i].second;
    }
    sort(p,p+n);
    ll ans = LLINF;
    REP(i,n){
        FOR(j,i+1,n){
            ll yh = p[i].second, yl = p[j].second;
            if(yh<yl)swap(yh,yl);
            int l = 0, r = 0, cnt = 0;
            while(r<=n){
                if(cnt==k){
                    ans = min(ans,(yh-yl)*(p[r-1].first-p[l].first));
                }
                if(cnt<k){
                    ll yt = p[r].second;
                    if(yt>=yl && yt<=yh)cnt++;
                    r++;
                }
                else{
                    ll yt = p[l].second;
                    if(yt>=yl && yt<=yh)cnt--;
                    l++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n) cin>>a[i];
    if(n==1){
        cout<<1;
        return 0;
    }
    sort(a.begin(),a.end());
    int b=1;
    int c=0;
    for(int i=0;i<n-1;i++){
    if(a[i]!=a[i+1]){
        if(b%2==1){
            c++;
            b=1;
        }else{
            b=1;
        }
    }else{
        b++;
    }
    }
    if(b%2==1){
        c++;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<queue>
using namespace std;
int main(){
	int nr,canhave,time,normal,special,distance;
	queue<int> que;
	cin>>nr>>canhave>>time>>normal>>special>>distance;
	int x;
	for(int i=0;i<nr;i++){
		cin>>x;
		que.push(x);
	}
	int sum=0;
	bool dont=false;
	int nowtime=0;
	double now=0;
	int nowhave=0,count=0;
	for(int i=1;i<distance;i++){
		if(!que.empty()){
			int q=que.front();
			if(q==i){
				if(canhave>nowhave){
					nowhave++;
				}else{
					nowtime=time*special+1;
				}
				
				que.pop();
			}
		}
		
		
		if(!nowtime)
			now+=(double)1/normal;
		else{
			now+=(double)1/special;
			count++;
			nowtime--;
		}
		if(!nowtime&&nowhave){
			nowtime=time*special;
			nowhave--;
		}
		/*cout<<i<<"-----"<<nowtime<<endl;
		cout<<(double)1/normal<<endl;
		*/
		if(nowtime)
			sum++;
	}
	//cout<<sum<<endl;
	//int ans=now;
	//cout<<n/normal+s/special<<endl;
	//distance++;
	printf("%lf\n",(double)(distance-sum)/normal+(double)sum/special);
	/*printf("%lf\n",(double)(distance-sum)/normal);
	printf("%lf\n",(double)sum/special);
	cout<<(double)(distance-sum)/normal+(double)sum/special<<endl;
	cout<<(double)(distance-sum)/normal<<endl;
	cout<<(double)sum/special<<endl;
	cout<<now<<endl;
	//cout<<now<<endl;
	cout<<count<<endl;
	*/
	return 0;
}

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

int main(){
    int n;
    int ans=0;
    cin >> n;
    vector <int> vec(n);
    rep(i,n){
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    if(n%2==1){
        cout << 0 << endl;
        return 0;
    }
    ans=vec.at(n/2)-vec.at(n/2-1);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;

#define pb push_back
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
struct d_ {
    template<typename T> d_ & operator ,(const T & x) { cerr << ' ' <<  x; return *this;}
    template<typename T> d_ & operator ,(const vector<T> & x) { for(auto x: x) cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) begin(x),end(x)
#define IN(n) ll n;cin >> n;
#define x first
#define y second

#define MXC 33
#define MXN 507
ll D[MXC][MXC];
ll C[MXN][MXN];
ll n,c;
ll m2c[3][MXC];

ll solve(ll pos, ll msk) {
    if(pos==3) return 0;
    ll ret=INF;
    F(c) if(((1ll<<i) & (msk))==0) {
        ll price=0;
        FF(c) price += m2c[pos][j] * D[j][i];
        ret = min(ret, solve(pos+1, msk|(1ll<<i)) + price);
    }
    return ret;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin >> n >> c;
    F(c)FF(c) cin >> D[i][j];
    F(n)FF(n) {
        cin >> C[i][j];
        C[i][j]--;
    }
    F(n)FF(n) {
        m2c[(i+j+2)%3][C[i][j]]++;
    }
    cout << solve(0,0) << endl;
    return 0;
}


Measured memory_bytes: 2304
n = int(input())
l = [int(x) for x in input().split()]

order = 0
subs = []
tmp = []

prev = 0
d = []
t = [l[0]]
for x in range(len(l)-1):
  a,b = l[x],l[x+1]
  c = a-b
  # print(a,b,c, prev)
  if c == 0:
    t.append(b)
  elif prev == 0:
    t.append(b)
    prev = c
  elif (c < 0  and prev < 0) or (c > 0 and prev > 0):
    t.append(b)
  else:
    prev = 0
    d.append(t)
    t = [b]
d.append(t)

print(len(d))


Measured memory_bytes: 14428
#include<iostream>
#include<algorithm>

using namespace std;

const int N = 100005;
int pre[N];		//存??点之?的?系
int marked[N];	//存?是否被??以及??的?序

int operation_order[N];		//按?序存??入的Q操作
int operation_node_index[N];//存?Q操作??的?点下?

long long sum;
int process_time;

int find_ance(int index) {
	if (marked[index] < process_time) {
		return index;
	}
	else {
		pre[index] = find_ance(pre[index]);
		return pre[index];
	}
}

int main() {
	int n, q;
	char op;
	int index;

	while (cin >> n >> q, n) {
		sum = 0;
		pre[1] = 1;
		marked[1] = 0;
		for (int i = 2; i <= n; ++i) {
			cin >> pre[i];
			marked[i] = q + 1;
		}
		int Q_operation_num = 0;
		for (int i = 1; i <= q; ++i) {
			cin >> op >> index;
			if (op == 'Q') {
				operation_order[Q_operation_num] = i;
				operation_node_index[Q_operation_num++] = index;
			}
			else {
				marked[index] = min(marked[index], i);
			}
		}

		while (Q_operation_num--) {
			process_time = operation_order[Q_operation_num];
			sum += find_ance(operation_node_index[Q_operation_num]);
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 2496
# スペース区切りの整数の入力
start, end = map(int, input().split())

count=0
value = start
while value <= end:
  if value // 10000 == value % 10 and value // 1000 % 10 == value % 100 // 10:
    count += 1
  value += 1

print( count )

Measured memory_bytes: 2940
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    long long ans = 0;
    string s;
    cin >> s;
    for(int i = 0;i < (1 << (s.size() - 1));i++)
    {
        int tmp = 0;
        for(int j = 0;j < s.size() - 1;j++)
        {
            if(i & (1 << j))
            {
                ans += stoll(s.substr(tmp,j - tmp + 1));
                tmp = j + 1;
            }
        }
        ans += stoll(s.substr(tmp,s.size() - tmp));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
using pii = pair<int, int>;
using vi = vector<int>;
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
int di[] = {0, 0, -1, 1, -1, 1, -1, 1}; //右、左、マイナス、プラス
int dj[] = {1, -1, 0, 0, -1, 1, 1, -1};
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
//manip
template<class T> bool chmax(T &a, T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, T &b) {if (a > b) {a = b; return 1;} return 0;}
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power(T a, T b)
{return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0

int dp[1000007];
int dpodd[1000007];
int main() {
    //cast caution
    //look constraints always
    cin.tie(0); ios::sync_with_stdio(false);
    
    
    
    
    
    
    
    int cand[200] = {0};
    cand[0] = 0;
    rep3(i, 1, 200) {
        cand[i] = i * (i + 1) * (i + 2) / 6;
    }
    
    int n;
    while (cin >> n && n) {
        rep(i, n + 1) {dp[i] = dpodd[i] = i;}
        rep3(i, 1, 183) {
            if (cand[i] > n + 1) break;
            rep3(j, cand[i], n + 1) {
                if (j > n + 1) break;
                dp[j] = min(dp[j], dp[j - cand[i]] + 1);
                if (cand[i] % 2 != 0) dpodd[j] = min(dpodd[j], dpodd[j - cand[i]] + 1);
            }
            //rep(i, n + 1) cout << dp[i] << " "; cout << endl;
        }
        cout << dp[n] << " " << dpodd[n] << endl;
        
        
        
        
        
    }
    
    
    
    
    
    
}
//cast caution







Measured memory_bytes: 10756
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
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);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int X; cin >> X;
    cout << (X >= 30 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long x = sc.nextLong();
    long[] a = new long[n];
    long sum = 0;
    for (int i = 0; i < n; i++){
      a[i] = sc.nextLong();
      sum += a[i];
    }
    if(sum == x){
      System.out.println(a.length);
    }
    else if(sum < x){
      System.out.println(a.length - 1);
    }
    else{
    int count = 0;
    Arrays.sort(a);
    for(int i = 0; i < n; i++){
      if(a[i] <= x){
        count++;
        x -= a[i];
      }
      else{
        break;
      }
    }
    System.out.println(count);
  }
  }
}

Measured memory_bytes: 21844
# coding: utf-8

renga_count = int(input())
renga_list = [int(i) for i in input().rstrip().split(" ")]

count = 0
for i in renga_list:
    if i == count + 1:
        count += 1

if count == 0:
    print(-1)
else:
    print(renga_count - count)

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cout.precision(12);
    cout << fixed;

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    set<pair<int, int> > s;
    for (int i = 0; i < n; i++) {
        s.insert({b[i], i});
    }
    long long ans = 0;
    while (!s.empty()) {
        auto p = *s.rbegin();
        s.erase(p);
        int x = p.first;
        int i = p.second;
        if (a[i] > b[i]) {
            cout << -1 << endl;
            return 0;
        }
        if (a[i] == b[i]) {
            continue;
        }
        int i0 = (i+n-1)%n;
        int i1 = (i+1)%n;
        int once = (b[i0] + b[i1]);
        int mx = max(b[i0], b[i1]);
        mx = max(mx, a[i]);
        int need = b[i] - mx;
        if (need < 0) {
            cout << -1 << endl;
            return 0;
        }
        int times = (need + once - 1) / once;
        ans += times;
        b[i] -= once * times;
        if (b[i] < a[i]) {
            cout << -1 << endl;
            return 0;
        }
        if (b[i] > a[i]) {
            s.insert({b[i], i});
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13312
package main

import "fmt"

func main(){
  var a, b int
  result := "No"
  fmt.Scan(&a, &b)
  c_ary := []int{1, 2, 3}
  for i :=0; i < len(c_ary); i++ {
    if ans := a * b * c_ary[i]; ans % 2 != 0 {
      result = "Yes"
    }
  }
  fmt.Println(result)
}

Measured memory_bytes: 512
#include<stdio.h>

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

  char s[12];
  scanf("%s", s);

  int K;
  scanf("%d", &K);

  int i;

  int c = s[K - 1];

  for(i = 0; i < N; i++){
    if(s[i] == c) printf("%c", s[i]);
    else printf("*");
  }

  printf("\n");

  return 0;
}


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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

Int bp[200001];

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n), b(n);
    Int dz, az, bz;
    dz = az = bz = 0;
    for (Int i = 0; i < (Int)n; i++) {
        cin >> a[i] >> b[i];
        //assert(a[i] != 0 or a[i] != 0);
        if (a[i] == 0 and b[i] == 0) {
            dz++;
            continue;
        }
        if (a[i] == 0) {
            az++;
            continue;
        }
        if (b[i] == 0) {
            bz++;
            continue;
        }
        Int x = gcd(abs(a[i]), abs(b[i]));
        a[i] /= x;
        b[i] /= x;
    }
    bp[0] = 1;
    for (Int i = 0; i < (Int)n; i++) {
        bp[i + 1] = bp[i] * 2LL % mod;
    }
    map<pair<Int, Int>, Int> mp;
    for (Int i = 0; i < (Int)n; i++) {
        if (a[i] == 0 or b[i] == 0) continue;
        mp[{a[i], b[i]}]++;
    }
    Int other = 0;
    for (auto i : mp) {
        pair<Int, Int> p = i.first;
        if (p.first == 0 or p.second == 0) continue;
        if (mp[{p.second, -p.first}] == 0 and mp[{-p.second, p.first}] == 0) {
            other += mp[p];
            mp[p] = 0;
            //print(p.first, p.second);
        }
    }
    Int res = bp[other];
    Int adda = 0, addb = 0;
    if (az > 0) {
        adda = res * bp[az] % mod;
    }
    if (bz > 0) {
        addb = res * bp[bz] % mod;
    }
    if (az > 0 and bz > 0) {
        res = (adda + addb - res + mod) % mod;
    } else if (az > 0) {
        res = adda;
    } else if (bz > 0) {
        res = addb;
    }
    for (auto i : mp) {
        if (i.second == 0) continue;
        pair<Int, Int> p = i.first;
        //print(p.first, p.second);
        Int x = i.second + mp[{-p.first, -p.second}];
        Int y = mp[{p.second, -p.first}] + mp[{-p.second, p.first}];
        //print(x, y);
        Int aa = res * bp[x] % mod;
        Int bb = res * bp[y] % mod;
        res = (aa + bb - res + mod) % mod;
        mp[p] = mp[{-p.first, -p.second}] = mp[{p.second, -p.first}] = mp[{-p.second, p.first}] = 0;
    }
    print((res + dz - 1 + mod) % mod);
    return 0;
}

Measured memory_bytes: 54836
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX 5000001
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const ll INF = 10010010010001;

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 0;
    if((a+b) > c*2){
        int t1 = 0,t2 = 0;
        t1 += min(x,y)*(c*2);
        if(x > y){
            t1 += (x-y)*a;
        }
        else{
            t1 += (y-x)*b;
        }
        t2 += max(x,y)*(c*2);
        ans = min(t1,t2);
    }
    else{
        ans += x*a;
        ans += y*b;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = a[0];
    Rep(i, 1, n) ans = gcd(ans, a[i]);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int D[100011];

void MAIN() {
    scanf("%d", &N);
    REP (i, 100011) D[i] = D[i/10] + i%10;

    int ans = 1<<29;
    for (int a=1; a<N; a++) {
	amin(ans, D[a] + D[N-a]);
    }
    printf("%d\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 640
while True:
	a,b=map(int,input().split())
	if a==0 and b==0:
		break
	o=0
	for i in range(1,a-1):
		for j in range(i+1,b):
			for c in range(j+1,a+1):
				if i+j+c==b:
					o+=1
	print(o)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	map<ll,int> mp;
	rep(i,n){
		ll a;cin>>a;
		mp[a]++;
	}
	vector<ll> vec;
	for(auto p:mp){
		if(p.second>1){
			if(p.second>3){
				vec.push_back(p.first);
			}
			vec.push_back(p.first);
		}
	}
	int m=vec.size();
	ll ans=0;
	if(m>1) ans=vec[m-1]*vec[m-2];

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

Measured memory_bytes: 6528
#include <iostream>
#include <string>

using namespace std;


int main() 
{
	string o, e;
	cin >> o;
	cin >> e;

	int size = e.size();

	for (int i = 0;i < size;i++)
	{
		cout << o[i];
		cout << e[i];
	}

	

	if (o[size] != '\0') cout << o[size];

	cout << endl;
	

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
   public static void main(String arg[]) throws java.io.IOException{
       Scanner scan =new Scanner (System.in);
    
       while(true){
    	   int n=scan.nextInt();
    	   int sum=0;
    	   if(n==0)break;
    	   int [][] m=new int[n+1][n+1];
    	   for(int i=0;i<n;i++){
    		   for(int j=0;j<n;j++){
    			   sum+=m[i][j]=scan.nextInt();
    		   }
    	   }
    	   for(int i=0;i<n;i++){
    		   for(int j=0;j<n;j++){
    			   m[i][n]+=m[i][j];
    			   m[n][i]+=m[j][i];
    		   }
    	   }
    	   m[n][n]=sum;
    	   
    	   for(int i=0;i<n+1;i++){
    		   for(int j=0;j<n+1;j++){
    			  System.out.printf("%5d",m[i][j]);
    		   }
    		   System.out.println();
    	   }
   
       }
    
}
}
    

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(void)
{
    string S;
    cin >> S;
    if (S.size() == 2) cout << S << endl;
    else 
    {
        for (int i = 2; i >= 0; i--) cout << S[i];
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x,ll y){
    if(y==0){
        return x;
    }else{
        return GCD(y, x % y);
    }
}
ll LCM(ll x,ll y){
    return x / GCD(x, y) * y;
}
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main()
{
    int n,x;
    cin >> n>>x;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin >> vec[i];
    }
    ll sum = 0;
    if(vec[0]>x){
        sum += (vec[0] - x);
        vec[0] = x;
    }
    for (int i = 1;i<n;i++){
        if(vec[i]+vec[i-1]>x){
            sum += vec[i] + vec[i - 1] - x;
            vec[i] = x - vec[i-1];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 640
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define x first
#define y second
typedef long long LL;
typedef pair<int, int> PII;
bool suc = true;
string s;

int main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cin >> s;
	if(s.size() & 1) suc = false;
	else{
		for(int i = 0; i < sz(s); i += 2){
			if(s[i] != 'h') suc = false;
		}
		for(int i = 1; i< sz(s); i += 2){
			if(s[i] != 'i') suc = false;
		}
	}
	if(suc) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>

using namespace std;

#define mod (1e9 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

typedef long long ll;

void solve1() {
    string s; cin >> s;
    int cnt = 0;
    for(int i = 0; i < (int)s.size(); i++) {
        if(s[i] == '2') {
            cnt ++;
        }
    }

    cout << cnt << endl;
}

int main()
{
    solve1();
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n, ans;
	while (cin >> n) {
		ans = 0;
		for (int a = 0; a < 10; a++) {
			for (int b = 0; b < 10; b++) {
				for (int c = 0; c < 10; c++) {
					for (int d = 0; d < 10; d++) {
						if (a + b + c + d == n) {
							ans++;
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define dd double
#define f0(i, n) for(int i = 0; i < n; i++)
#define fab(i,a,b) for(int i=a;i<b;i++)
#define f1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

string s1, s2;


// int LCS(int n, int m) {

// 	if (n == 0 || m == 0) {
// 		return 0;
// 	}

// 	if (dp[n - 1][m - 1] != -1) {
// 		return dp[n - 1][m - 1];
// 	}

// 	if (s1[n - 1] == s2[m - 1]) {

// 		return dp[n - 1][m - 1] = 1 + LCS(n - 1, m - 1);
// 	}



// 	return dp[n - 1][m - 1] = max(LCS(n - 1, m), LCS(n, m - 1));

// }


int main() {


	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif


//ios_base& scientific (ios_base& str);
	// memset(dp, , sizeof(dp));
	cin >> s1 >> s2;

	int n = s1.length();
	int m = s2.length();

	int dp[n + 1][m + 1] = {0};

	for (int i = 0; i <= m; i++) {
		dp[0][i] = 0;
	}
	for (int i = 0; i <= n; i++) {
		dp[i][0] = 0;
	}


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

		for (int j = 1; j <= m; j++) {

			if (s1[i - 1] == s2[j - 1]) {

				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else {

				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}

	// cout << dp[n][m] << endl;


	// for (int i = 0; i <= n; i++) {

	// 	for (int j = 0; j <= m; j++) {

	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

	string ans = "";

	int i = n, j = m;

	while (i > 0 && j > 0) {


		if (dp[i][j] == dp[i][j - 1]) {
			j--;
		}
		else if (dp[i][j] == dp[i - 1][j]) {
			i--;
		}
		else if (dp[i][j] == dp[i - 1][j - 1] + 1) {
			ans += s1[i - 1];
			i--;
			j--;
		}
	}

	reverse(ans.begin(), ans.end());

	cout << ans << endl;




	return 0;
}

Measured memory_bytes: 35456
from numpy import array


MOD = 10 ** 9 + 7

def solve(n, k):
    is_prime = array([True] * (k+1))
    is_prime[:2] = False
    for i in range(2, k+1):
        if i**2 > k: break
        if is_prime[i]:
            is_prime[i**2::i] = False
    primes = [i for i, _ in enumerate(is_prime) if is_prime[i]]
    
    res = [0] + [pow(k//i, n, MOD) for i in range(1, k+1)]

    for p in primes:
        for i in range(1, k//p+1):
            res[i] -= res[i*p]
            
    return sum(i*res[i] for i in range(k+1)) % MOD


def test():
    ...

if __name__ == "__main__":
    n, k = map(int, input().split())
    print(solve(n, k))


Measured memory_bytes: 30672
(def weeks ["MON" "TUE" "WED" "THU" "FRI" "SAT" "SUN"])
(def week (read-line))
(def i (.indexOf weeks week))
(cond
  (= i 0) (print 6)
  (= i 1) (print 5)
  (= i 2) (print 4)
  (= i 3) (print 3)
  (= i 4) (print 2)
  (= i 5) (print 1)
  (= i 6) (print 7))

Measured memory_bytes: 65000
#include<stdio.h>

int main() {
	int n, i, j;
	int A[1000];
	int v;

	scanf("%d", &n);

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

	for (i = 0; i < n; i++) {
		v = A[i];
		j = i - 1;

		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}

		A[j + 1] = v;

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

	return 0;
}

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


int main(){
  int k,a,b;
  cin >>k;
  cin>>a>>b;
  int ans = k;
  int count = 1;
  bool flag=false;
  while(ans<=b){
    if(ans>=a&&ans<=b){
      flag=true;
    }
    ans=k*count;
    ++count;
  }
  if(flag)cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		int e[3];
		for (int j = 0; j < 3; ++j)
			scanf("%d", e+j);
		sort(e, e+3);

		if (e[0]*e[0]+e[1]*e[1] == e[2]*e[2])
			puts("YES");
		else
			puts("NO");
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        for (int i = 0; i < n * 2; i++) {
            pq.add(Integer.parseInt(sc.next()));
        }
        sc.close();

        // 主処理
        int result = 0;
        while (!pq.isEmpty()) {
            result += pq.poll();
            pq.poll();
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 35868
using System;
using System.Collections.Generic;

namespace abc132_c
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var d = CIn.ReadIntArray(n);

      Array.Sort(d);

      Console.WriteLine(d[n / 2] - d[n / 2 - 1]);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

Measured memory_bytes: 20832
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int i,j,c=0;
  string s;
  cin >> s;
  for (i=0;i<3;i++) for (j=i+1;j<4;j++) if (s.at(i)==s.at(j)) c++;
  if (c==2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MAXN = 2e5 + 5;

LL s[MAXN + 5], sum[MAXN + 5];

int N;
int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%lld", &s[i]);
	for(int i = 1; i <= N; i++) sum[i] = sum[i - 1] + s[i];
	LL Min = abs(sum[N] - sum[1] - sum[1]);
	for(int i = 1; i <= N - 1; i++) Min = min(Min, abs(sum[N] - sum[i] - sum[i]));
	printf("%lld\n", Min);
}


Measured memory_bytes: 3328
function Main(input) {
    var N = parseInt(input[0], 10);
    var M = parseInt(input[1], 10);
    var LR = input.slice(2).map(v => parseInt(v, 10));

    var L = [];
    var R = [];

    LR.forEach((value, index) => {
        if (index % 2 === 0) {
            L.push(value);
        } else {
            R.push(value);
        }
    });

    var maxL = 0;
    for (var li = 0; li < L.length; li++) {
        maxL = maxL < L[li] ? L[li] : maxL;
    }
    var minR = 100000;
    for (var ri = 0; ri < R.length; ri++) {
        minR = minR > R[ri] ? R[ri] : minR;
    }

    if (maxL > minR) {
        console.log(0);
    } else {
        console.log(Math.abs(maxL - minR) + 1);
    }


}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 37824
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
const int MAX_N = 2*1e5 + 1;


struct RMQ{
	int n;
	int dat[MAX_N*2 - 1];
	void init(int& n_){
		n = 1;
		while(n<n_)n*=2;//n????????????????????§????????¨update????????°???
		REP(i,2*n-1)dat[i] = INT_MAX;
	}
	//??????????????????i?????????x????????´
	void update(int i,int x){
		i += n-1;
		dat[i] = x;
		while(i > 0){
			i = (i-1)/2;
			dat[i] = min(dat[i*2+1],dat[i*2+2]);
		}
	}
	//[a,b)???????°?????????????????????????????????????????????\?????????????????????
	//?????????query(a,b,0,0,n)??§?????????????????????????§???????????????£??????????????????
	int query(int a,int b,int k,int l,int r){
		if(r <= a||b <= l)return INT_MAX;//???????????????
		if(a <= l && r <= b)return dat[k];//?????¨?????????
		else{
			int vl = query(a,b,k*2+1,l,l+(r-l)/2);
			int vr = query(a,b,k*2+2,l+(r-l)/2,r);
			return min(vl,vr);
		}
	}
};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n,q;
	cin >> n >> q;
	RMQ rmq;
	rmq.init(n);
	REP(i,q){
		int com,x,y;
		cin >> com >> x >> y;
		//rmq?????????n???????????§????????¨,y+1?????¨???
		if(com)cout << rmq.query(x,y+1,0,0,rmq.n) << endl;
		else rmq.update(x,y);
	}
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  long long ans = 0;
  for (int i=1 ; i<=n ; i++){
    if (i%3 != 0 && i%5 != 0){
      ans += i;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  double A,B,H,M;
  cin>>A>>B>>H>>M;
  long double angle_a,angle_b;
  angle_a=2*M_PI*H/12+M_PI/6*M/60;
  angle_b=2*M_PI*M/60;
  long double angle=abs(angle_a-angle_b);
  long double a_x,a_y,b_x,b_y;
  a_x=0;
  a_y=A;
  b_y=cos(angle)*B;
  b_x=sin(angle)*B;
  long double dist=sqrt(A*A+B*B-2*A*B*cos(angle));
  cout<<fixed<<setprecision(16)<<dist<<endl;
  return 0;
}


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

void compress(vector<ll> &x) {
  vector<ll> v(x.size());
  REP(i, 0, x.size()) v[i] = x[i];
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  REP(i, 0, x.size()) x[i] = lower_bound(v.begin(), v.end(), x[i]) - v.begin();
}

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

  if(A + B - 1 <= N && N <= A * B) {
    vector<ll> ans;
    ll cnt = 0, limit = N - B;
    REP(i, 0, B) {
      ans.push_back(B - i);
      REP(j, 1, A) {
        if(cnt >= limit) break;
        ans.push_back((B - i) + B * j);
        cnt++;
      }
    }

    compress(ans);

    REP(i, 0, ans.size()) cout << ans[i] + 1 << (i + 1 != ans.size() ? " " : "\n");
  } else {
    cout << -1 << endl;
  }
}


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

using namespace std;

const int MX = 300005;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

int n;
int seq[MX];
bool same[MX];

bool check(int l, int r)
{
	int mn = n+1, mx = 0, ll = 0, lr = 0;
	for(int i=l; i<=r; i++)
	{
		if(seq[i]>i && seq[i]<lr) return false;
		if(seq[i]<i && seq[i]<ll) return false;
		if(seq[i] > i) lr = seq[i];
		if(seq[i] < i) ll = seq[i];
		cmin(mn, seq[i]);
		cmax(mx, seq[i]);
	}
	if(mn != l) return false;
	if(mx != r) return false;
	return true;
}

int main()
{
	auto fuck = [](){puts("No"), exit(0);};
	read(n);
	for(int i=1; i<=n; i++) read(seq[i]), same[i] = (i==seq[i]);
	for(int i=2; i<n; i++) if(!same[i-1] && !same[i] && !same[i+1]) fuck();
	int lst = 1;
	for(int i=1; i<n; i++)
	{
		if(same[i] == same[i+1])
		{
			if(!check(lst, i)) fuck();
			else lst = i+1;
		}
	}
	if(!check(lst, n)) fuck();
	puts("Yes");
	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <climits>
#include <cmath>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


long dist(pair<int, int> s1, pair<int, int> s2) {
  return abs(s1.first - s2.first) * (s1.second + s2.second);
}

int main(void) {
  while(1) {
    long N, M;
    vector< pair<long, long> > S[150];
    vector<long> dp[150][150];

    cin >> N >> M;
    if(N == 0 && M == 0) break;
    REP(i, 0, N) {
      int k;
      cin >> k;
      REP(j, 0, k) {
        long x, d;
        cin >> x >> d;
        S[i].push_back(pair<long, long>(x, d));
      }
    }

    long ans = INT_MAX;
    REP(i, 0, N) {
      REP(j, 0, M + 1) {
        REP(k, 0, S[i].size()) {
          long m = INT_MAX;
          if(i >= 1) {
            REP(l, 0, S[i - 1].size()) {
              m = min(m, dp[i - 1][j][l] + dist(S[i][k], S[i - 1][l]));
            }
          }
          if(i >= 2 && j >= 1) {
            REP(l, 0, S[i - 2].size()) {
              m = min(m, dp[i - 2][j - 1][l] + dist(S[i][k], S[i - 2][l]));
            }
          }
          if(i == 0 && j == 0) m = 0;
          if(i == 0 && j >= 1) m = INT_MAX;
          if(i == 1 && j == 1) m = 0;
          dp[i][j].push_back(m);

          if(((i == N - 2 && j < M) || (i == N - 1))) {
            ans = min(ans, m);
          }
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3364
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int K;
    string S;
    cin >> K >> S;
    int N = min((int)S.size(),K);
    for(int i=0;i<N;++i){
        cout << S[i];
    }
    if(S.size()>N){
        cout << "...";
    }
    cout << endl;
}


Measured memory_bytes: 3632
N, W = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
    vi, wi = map(int, input().split())
    for w in range(W + 1):
        if wi <= w:
            dp[i + 1][w] = max(dp[i + 1][w], dp[i][w - wi] + vi)
        dp[i + 1][w] = max(dp[i + 1][w], dp[i][w])

print(dp[N][W])


Measured memory_bytes: 42012
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;


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

  vector <ll> A(N);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }


  vector <ll> yakusuu;
  for (ll i = 1; i * i <= sum; i++){
    if (i * i == sum){
      yakusuu.push_back(i);
    }else if(sum % i == 0){
      yakusuu.push_back(i);
      yakusuu.push_back(sum / i);
    }
  }
  sort(yakusuu.begin(), yakusuu.end(), greater<ll>());
  
  for (int i = 0; i < yakusuu.size(); i++){
    ll now = yakusuu[i];

    vector <int> dig(N);
    for (int j = 0; j < N; j++){
      dig[j] = A[j] % now;
    }
    sort(dig.begin(), dig.end());


    int end = N - 1;
    ll cnt = 0, rest = 0;

    for (int j = 0; j < end; j++){
      cnt += dig[j]; rest += dig[j];


      while (dig[end] + rest >= yakusuu[i]){
        rest = dig[end] + rest - yakusuu[i];
        end--;
      }
      
    }

    if (cnt <= K){
      cout << yakusuu[i] << endl;
      break;
    }
    
  }
  

  return 0;
}


Measured memory_bytes: 256
MAX = 100005
ws = [0 for i in range(MAX)] 
par = [-1 for i in range(MAX*2)]


def weight(x):
    root(x)
    return ws[x]

def root(x):
    if par[x] < 0: return x
    p = root(par[x])
    ws[x] = ws[x] + ws[par[x]]
    par[x] = p
    return par[x]


def unite(y, x, z):
    z = z + weight(x)
    z = z - weight(y)
    x = root(x)
    y = root(y)
    if x == y: return 0
    if par[y] < par[x]:
        tmp = x
        x = y 
        y = tmp 
        z = -z
     
    par[x] = par[x] + par[y]
    par[y] = x
    ws[y] = z
    return 1 

def diff(x,y):
    if root(x) != root(y) :return 0
    ans = ws[x] - ws[y]
    return 1 ,ans


if __name__=='__main__':
   global ans
   N, Q =  (int(x) for x in  input().split())
   for q in range(Q):
        t, *cmd =  (int(x) for x in  input().split())
        if t:
            x, y = cmd
            z = diff(x, y)
            if z==False :print("?")
            else :print(z[1])
        else:
            x, y, z = cmd
            unite(x, y, z)




Measured memory_bytes: 11136
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        s: Bytes,
        t: Bytes,
    }

    let mut ans = t.len();
    for i in 0..s.len() - t.len() + 1 {
        let mut count = 0;
        for j in 0..t.len() {
            if t[j] != s[i + j] {
                count += 1;
            }
        }
        ans = min(ans, count);
    }

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


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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second

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

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;

	bool ans = true;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		if (x%2 == 0) ans &= x%3 == 0 or x%5 == 0; 
	}

	cout << (ans ? "APPROVED" : "DENIED") << '\n';

	return 0;
}

Measured memory_bytes: 256
from itertools import permutations

n, m = list(map(int, input().split()))
mat = [[False] * n for i in range(n)]
for i in range(m):
    a, b = list(map(int, input().split()))
    mat[a - 1][b - 1] = mat[b - 1][a - 1] = True
ans = 0
for pat in permutations(range(n)):
    if pat[0] != 0:
        continue
    f = True
    for i in range(n - 1):
        if not mat[pat[i]][pat[i + 1]]:
            f = False
    if f:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n; string s;
    cin >> n >> s;
    int x = 0,ans = 0;
    rep(i,n){
        if(s[i]=='I') x++;
        else x--;
        ans = max(ans,x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
import java.util.Scanner;


public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int count_1 = 0,count_2 = 0;
		
		while(sc.hasNext()){
			String[] s = sc.nextLine().split(",");
			int len1 = Integer.parseInt(s[0]);
			int len2 = Integer.parseInt(s[1]);
			int len3 = Integer.parseInt(s[2]);
			if(len3*len3 == len1*len1 + len2*len2) count_1++;
			if(len1 == len2) count_2++;
		}
		System.out.println(count_1);
		System.out.println(count_2);
	}
}

Measured memory_bytes: 15300
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = (int)1e9 + 7;
int pw(int a, int b) {
    int c = 1;
    for (int i = 0; i  < b;i ++) {
        c = (1LL * c * a) % mod;
    }
    return c;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    ll f = pw(10, n);
    f -= 2LL * pw(9, n);
    f += pw(8, n);
    f %= mod;
    if (f < 0) f += mod;
    cout << f;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
 
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};
 
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 H,N;
int A[1005];
int B[1005];

int dp[20005];

void init(){
    for(int i=0;i<20005;++i)dp[i]=INF;
}

signed main(){
    init();
    cin>>H>>N;
    for(int i=0;i<N;++i)cin>>A[i]>>B[i];
    dp[0]=0;
    for(int h=0;h<=H;++h){
        for(int i=0;i<N;++i){
            chmin(dp[h+A[i]],dp[h]+B[i]);
        }
    }
    int ans=INF;
    for(int h=H;h<20005;++h)chmin(ans,dp[h]);
    cout<<ans<<endl;
}


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

public class Main {
    public static void main (String[] args) throws IOException {
        int a,b;
        int d,r;
        String f;
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String data = reader.readLine();
        String[] number = data.split(" ");
        a = Integer.parseInt(number[0]);
        b = Integer.parseInt(number[1]);
        d = a / b;
        r = a % b;
        f = (String.format("%.5f",((double)a /(double)b)));
        
        builder
           .append(d)
           .append(" ")
           .append(r)
           .append(" ")
           .append(f)
           .append("\n");
        System.out.print(builder);
        }        
}

Measured memory_bytes: 24884