akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int func(int n)
{
    int p=n;
    int q;
    int b[10];
    int i=0;
    while(p)
    {
      q=p%10;
      b[i]=q;
      p=p/10;
      i++;
    }

    i--;
    int o=3;
    for(int j=0;j<i;j++)
    {
        if(b[j]-b[j+1]==1)o=1;
            else
        {
            o=0;
            break;
        }
    }
    return o;
}

int main()
{
    int n;
    int a[1005];
    scanf("%d",&n);

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

    int c,d;
    int ans=-1;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i!=j)
            {
                c=a[i]*a[j];

                d=func(c);

                if(d==1 or d==3) ans=max(ans,c);
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3260
import sys
array = []
for i in sys.stdin.readlines():
    array.append(i.rstrip().split())
for i in range(0,len(array),2):
    hit = 0
    blow = 0
    for i2 in range(4):
        if array[i][i2] == array[i+1][i2]:
            hit += 1
        for i3 in range(4):
            if array[i][i2] == array[i+1][i3]:
                if i2 == i3:
                    continue
                blow += 1
    print(str(hit)+" "+str(blow))

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

#define ll long long
#define pb push_back

const int maxn = 2e5 + 20;

pair<int , int> a[maxn];

int res[maxn];

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

	int n;
	cin >> n;

	for(int i = 0; i < n; i++)
		cin >> a[i].first , a[i].second = i;

	sort(a , a + n);

	for(int i = 0; i < n / 2; i++)
		res[a[i].second] = a[n / 2].first;

	for(int i = n / 2; i < n; i++)
		res[a[i].second] = a[n / 2 - 1].first;

	for(int i = 0; i < n; i++)
		cout << res[i] << endl;
}







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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  int dp[n + 3];
 
  rep(i, n + 3) dp[i] = INF;
  dp[0] = 0;

  for (int i = 1; i <= n+1; ++i) {
    int p = 1;
    while (p <= i) dp[i] = min(dp[i], dp[i - p] + 1), p *= 6;
 
    p = 1;
    while (p <= i) dp[i] = min(dp[i], dp[i - p] + 1), p *= 9;
 
    dp[i] = min(dp[i], dp[i - 1] + 1);
  }

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

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

int main()
{
	int64_t n, k;
	cin >> n >> k;
	vector<int64_t> as(n);
	for (auto &&a : as)
	{
		cin >> a;
		a--;
	}

	vector<int64_t> hs, ts;
	{
		set<int64_t> st;
		int64_t now = 0;
		while (true)
		{
			if (st.find(now) != st.end())
			{
				vector<int64_t> cs;
				for (auto &&h : hs)
				{
					if (h == now)
					{
						break;
					}
					cs.emplace_back(h);
				}
				swap(hs, cs);
				break;
			}

			hs.emplace_back(now);

			st.insert(now);

			now = as[now];
		}

		st.clear();
		while (true)
		{
			if (st.find(now) != st.end())
			{
				break;
			}

			ts.emplace_back(now);

			st.insert(now);
			now = as[now];
		}
	}

	if (k < hs.size())
	{
		cout << (hs[k] + 1) << endl;
		return 0;
	}

	k -= hs.size();

	cout << (ts[k % ts.size()] + 1) << endl;

	return 0;
}

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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll sum=0;
    ll n; cin >> n;
    rep(x,1,n+1) {
        sum += (n/x) * ((n/x) + 1) / 2 * x;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
const int M =1<<30;
int main() {
  int h,n,p,q,g=0,dp[20010],ans=M;
  fill(dp,dp+20010,M);
  dp[0]=0;
  cin>> h >> n;
  pair<int,int> x[n];
  rep(i,n){
    cin>>p>>q;
    x[i]=make_pair(p,q);
    g=max(g,p);
  }
  rep(i,h+g)
     rep(j,n)
      if(i>=x[j].first)
        dp[i]=min(dp[i],dp[i-x[j].first]+x[j].second); 
  
  for(int i=h;i<=h+g;i++)
    ans=min(ans,dp[i]);
  cout<<ans;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

#define NIL 500003;

int n, heap[500000];
void maxheapify(int *, int);
int left(int *, int);
int right(int *, int);
void buildmaxheap(int *);

main() {
  int i, j;
  
  scanf("%d", &n);
  
  for(i = 1; i < n + 1; i++) {
    scanf("%d", &heap[i]);
  }
  
  buildmaxheap(heap);
  
  for(j = 1; j < n + 1; j++) {
    printf(" %d", heap[j]);
  }
  printf("\n");
  return 0;
}

void maxheapify(int *a, int i) {
  int largest, l, r, tmp;
  l = left(a, i);
  r = right(a, i);
  if(l <= n && a[l] > a[i]) {
    largest = l;
  }
  else {
    largest = i;
  }
  if(r <= n && a[r] > a[largest]) {
    largest = r;
  }
  if(largest != i) {
    tmp = a[i];
    a[i] = a[largest];
    a[largest] = tmp;
    maxheapify(a, largest);
  }
}

int left(int *a, int i) {
  if(n < 2 * i) {
    return NIL;
  }
  else {
    return 2 * i;
  }
}
int right(int *a, int i) {
  if(n < (2 * i + 1)) {
    return NIL;
  }
  else {
    return 2 * i + 1;
  }
}

void buildmaxheap(int *a) {
  int i;
  for(i = (n / 2); i >= 1; i--) {
    maxheapify(a, i);
  }
}

Measured memory_bytes: 2552
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
#include <list>
#include <iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
typedef pair<string,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
const ll MODatc = 1000000007;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
bool pairCompare2(P firstElof,P secondElof){
    return (firstElof.second)%1000>(secondElof.second)%1000;
}
bool less_mod1000(int lhs, int rhs) {
  if ((lhs - rhs) % 1000 != 0)
    return lhs % 1000 < rhs % 1000;
  else // 5で割った余りが等しいなら普通に大小比較する
    return lhs < rhs;
}
string Alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alpha="abcdefghijklmnopqrstuvwxyzaaaaaaa";
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll cnt=1;
    ll n;cin>>n;
    ll s[n];
    char sz;
    rep(i,0,n){
      cin>>sz;
      if(sz=='a')s[i]=0;
      if(sz=='b')s[i]=1;
      if(sz=='c')s[i]=2;
      if(sz=='d')s[i]=3;
      if(sz=='e')s[i]=4;
      if(sz=='f')s[i]=5;
      if(sz=='g')s[i]=6;
      if(sz=='h')s[i]=7;
      if(sz=='i')s[i]=8;
      if(sz=='j')s[i]=9;
      if(sz=='k')s[i]=10;
      if(sz=='l')s[i]=11;
      if(sz=='m')s[i]=12;
      if(sz=='n')s[i]=13;
      if(sz=='o')s[i]=14;
      if(sz=='p')s[i]=15;
      if(sz=='q')s[i]=16;
      if(sz=='r')s[i]=17;
      if(sz=='s')s[i]=18;
      if(sz=='t')s[i]=19;
      if(sz=='u')s[i]=20;
      if(sz=='v')s[i]=21;
      if(sz=='w')s[i]=22;
      if(sz=='x')s[i]=23;
      if(sz=='y')s[i]=24;
      if(sz=='z')s[i]=25;
    }
    rep(i,1,n){
      if(s[i]!=s[i-1])cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 1024
h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=set()
for i in range(m):
  h1,w1=input().split()
  l.add(h1+"_"+w1)
  lh[int(h1)-1]+=1
  lw[int(w1)-1]+=1

hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    for m in lh2:
      if str(m+1)+"_"+str(i+1) not in l:
        print(hmax+wmax)
        exit()      
print(hmax+wmax-1)

Measured memory_bytes: 52756
//k_k_dubey_
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define mx 500005
#define non __builtin_popcount
#define ml map<ll, ll> 
#define uml unordered_map<ll, ll>
#define ms map<string , ll> 
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define pl pair<ll, ll>
#define vl vector<ll>
#define vll vector<pl>
#define tpl pair<pl, ll>
#define vlll vector<tpl>
#define vs vector<string>
#define pb push_back
#define mk make_pair
#define M_PI 3.14159265358979323846
#define endl '\n'
#define fst ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%I64d",&x)
#define inf ((ll)1e18 + 1)
#define bs binary_search
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define pow powr
#define rep(i,a,b)  for (i=(a);i<(b);i++)
#define nrep(i,a,b) for (i=(a);i>(b);i--)
using namespace std;
 
bool isp[mx];
 
void sv(){
 
	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}
 
ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

void bta_de_yarr(){
    
	ll  i, j,n, a[mx];
	cin>>n;
	rep(i, 1, n+1)
	cin>>a[i];

    ll kk= 1;
    rep(i, 1, n+1){

        if(a[i] == kk)
        kk++;
    }

    ll ans= n- kk+1;

    if(ans == n)
    ans= -1;
    
    cout<<ans;
	
	cout<<endl;
}

int main(){
    fst
	ll t;
    t= 1;
	//cin>>t;
    while(t--){
        bta_de_yarr();
    }
    return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 3456
#include<iostream>
#include<string>
using namespace std;
string a[101];
int main()
{
	int n;
	cin>>n;
	cin>>a[1];
	for(int i=2;i<=n;i++)
	{
		cin>>a[i];
		if(a[i-1][a[i-1].length()-1]!=a[i][0])
		{
//			cout<<"pd"<<endl;
			cout<<"No";
			return 0;
		}
		for(int j=1;j<i;j++)
		{
			if(a[j]==a[i])
			{
//				cout<<"chong"<<endl;
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <complex>
#include <cmath>
#include <iostream>
using namespace std;
typedef complex<double> xy_t;
double x[4],y[4];
string ok;

double cross_product(xy_t a,xy_t b) {
  return (conj(a)*b).imag()/2.0;
}

int main () {
  while (true) {
    for (int i=0; i<4; ++i) {
      cin >> x[i] >> y[i];
    }
    if (!cin) break;
    xy_t a(x[0],y[0]), b(x[1],y[1]), c(x[2],y[2]),p(x[3], y[3]);
    double pab = cross_product(a-p,b-p);
    double pbc = cross_product(b-p,c-p);
    double pca = cross_product(c-p,a-p);
    if ((pab>0&&pbc>0&&pca>0)||(pab<0&&pbc<0&&pca<0)) {
      ok = "YES";
    }
    else {
      ok = "NO";
    }
    cout << ok << endl;
  }
}

Measured memory_bytes: 1220
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main() {
	long long a,b;
	cin>>a>>b;
	if(a==1 or b==1){
		cout<<'1';
	}
	else{
		cout<<((a*b+1)/2);
	}
}



Measured memory_bytes: 3456
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define __V vector
#define all(x) x.begin(), x.end()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}
template<typename X, typename Y>
istream& operator>>(istream& in, pair<X, Y> &a) {
	in >> a.first >> a.second;
	return in;
}
template<typename T>
void getv(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv(vector<T>& v, int n, Ns ... ns) {
	v.resize(n);
	for (auto& i : v)
		getv(i, ns...);
}
template<typename T>
void getv1(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv1(vector<T>& v, int n, Ns ... ns) {
	v.resize(n + 1);
	for (int i = 1; i <= n; i++)
		getv(v[i], ns...);
}
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
inline void getch(char &x) {
	while (x = getchar_unlocked(), x < 33) {
		;
	}
}
inline void getstr(string &str) {
	str.clear();
	char cur;
	while (cur = getchar_unlocked(), cur < 33) {
		;
	}
	while (cur > 32) {
		str += cur;
		cur = getchar_unlocked();
	}
}
template<typename T> inline bool sc(T &num) {
	bool neg = 0;
	int c;
	num = 0;
	while (c = getchar_unlocked(), c < 33) {
		if (c == EOF)
			return false;
	}
	if (c == '-') {
		neg = 1;
		c = getchar_unlocked();
	}
	for (; c > 47; c = getchar_unlocked())
		num = num * 10 + c - 48;
	if (neg)
		num *= -1;
	return true;
}
typedef unsigned long long ull;
typedef long long ll;
typedef float ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
using AntonTsypko = void;
using arsijo = AntonTsypko;
using god = arsijo;
uniform_real_distribution<double> double_dist(0, 1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	doin();
	string t, a, b;
	cin >> t;
	a = string(1, t[0]) + t[1];
	b = string(1, t[2]) + t[3];
	int n = stoi(a), m = stoi(b);
	if ((m <= 12 && m >= 1) && (n <= 12 && n >= 1))
		cout << "AMBIGUOUS";
	else if (n <= 12 && n >= 1)
		cout << "MMYY";
	else if (m <= 12 && m >= 1)
		cout << "YYMM";
	else
		cout << "NA";
	return 0;
}


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

using ll = long long;

const ll mod = 1e+9 + 7;

int main() {

    int n;

    cin >> n;

    priority_queue<ll, vector<ll>, greater<ll>> q;

    for(int i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        q.push(x);
    }

    int d = 1;

    if(n % 2) {

        ll value = q.top(); q.pop();
        if(value != 0) {
            cout << 0 << endl;
            return 0;
        }

        d = 2;

    }

    ll answer = 1;

    while(!q.empty()) {

        ll x1 = q.top(); q.pop();
        ll x2 = q.top(); q.pop();


        if(x1 != x2 || x1 != d) {
            cout << 0 << endl;
            return 0;
        }

        answer *= 2;
        answer %= mod;
        d += 2;
    }

    cout << answer << endl;
    return 0;

    return 0;

}

Measured memory_bytes: 4260
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int K, o, e;

  std::cin >> K;

  e =  K      / 2;
  o = (K + 1) / 2;

  std::cout << e * o << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  string S;
  cin >> S;
  map<char, int> mp{};
  REP(i, S.size()) { mp[S[i]]++; }
  bool t = true;
  for(auto s : mp){
    if (mp[s.first] != 1) t = false;
  }
  if (t) cout << "yes" << endl;
  else
    cout << "no" << endl;
}

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

class Main {

	void solve() {

		char a = inchar(), b = inchar();
		
		if (a == 'H') out.println(b);
		else {
			out.println(b=='H' ? "D" : "H");
		}

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}

	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

	public char[][] incharmap(int h, int w) {
		char[][] a = new char[h][w];
		for (int i=0; i<h; i++) {
			String temp = in.next();
			for (int j=0; j<w; j++) {
				a[i][j] = temp.charAt(j);
			}
		}
		return a;
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;


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

    // 満点解法 O(CX + NC^2)
    // X: A, B の上限 (400)

    // 部分点解法のDPにおける x_i ^ k を
    // A_i ^ k + (A_i + 1) ^ k + ... + B_i ^ k で置き換える

    int N, C;
    cin >> N >> C;
    vi a(N + 1);
    rep(i, N) cin >> a[i + 1];
    vi b(N + 1);
    rep(i, N) cin >> b[i + 1];

    // S[i][k] = 0^k + 1^k + ... + i^k
    vvi S(401, vi(C + 1));
    rep(i, 401) {
        rep(k, C + 1) {
            S[i][k] = k == 0 ? 1 : (S[i][k - 1] * i) % mod;
        }
    }

    rep(i, 401 - 1) {
        rep(k, C + 1) {
            S[i + 1][k] += S[i][k];
        }
    }

    vvi dp(N + 1, vi(C + 1));
    dp[0][0] = 1;
    rep(i, N) {
        rep(j, C + 1) {
            rep(k, j + 1) {
                int A = a[i + 1], B = b[i + 1];
                int t = (S[B][k] - S[A - 1][k] + mod) % mod;
                (dp[i + 1][j] += dp[i][j - k] * t) %= mod;
            }
        }
    }

    cout << dp[N][C] << endl;

}


Measured memory_bytes: 2816
#include<stdio.h>
#include<bits/stdc++.h>
int main()
{
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(abs(b-a)<=d && abs(c-b)<=d || abs(c-a)<=d)
    printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
struct cmp{
    bool operator()(const LL &a,const LL &b){
        return a>b;
    }
};
multiset<LL,cmp> s;
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        LL x;
        scanf("%lld",&x);
        s.insert(x);
    }

    multiset<LL>::iterator it;
    priority_queue<LL> Q;
    LL maxx=0;
    int num=0;
    for(it=s.begin();it!=s.end();it++){
        if(*it==maxx)
            num++;
        else{
            maxx=*it;
            num=1;
        }
        if(num>=2){
            num=0;
            Q.push(*it);
        }
    }
    if(Q.size()<2)
        printf("0\n");
    else{
        LL w=Q.top();Q.pop();
        LL h=Q.top();Q.pop();
        printf("%lld\n",w*h);
    }
    return 0;
}


Measured memory_bytes: 5628
n,k=map(int,input().split())
mod=10**9+7
ans=0
d=[0]*(k+1)
for i in range(k,0,-1):
	c=k//i
	t=pow(c,n,mod)
	t+=(d[i]//mod+1)*mod-d[i]
	t%=mod
	ans+=t*i
	ans%=mod
	for j in range(1,int(i**.5)+1):
		if i%j==0:
			d[j]+=t
			if j!=i//j:
				d[i//j]+=t
print(ans)


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


int main(){
	int n,a;
	map<int,int> mp;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a;
		mp[a]++;
	}
	
	int cnt=0;
	for(auto x:mp){
		if(x.second%2) cnt++;
	}
	
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4864
#include <iostream>

 

using namespace std;

 

int main() 
{
    int i, a ,b, c;
    for ( i=1; i<=3000; i++)
     {  
         cin >> a >> b;
        if(a == 0&&b == 0)
        break;
      
        //Swap a & b
        if(a>b)
        { 
            
            c=b;
            b=a;
            a=c;
        }
       
        
        cout << a << " " << b << endl;
     }
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb emplace_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define rreps(i,j,k) for(int i = (j); i >= (k); --i)
#define rrep(i,j) rreps(i,j,0)
#define all(a) (a).begin(),(a).end()
#define MOD 10007 
typedef pair<int,int> Pii;
typedef pair<int, ll> Pil;
typedef pair<int,string> Pis;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int N,L;
	cin >> N >> L;
	vector < string > data;
	rep(i,N){
		string x;
		cin >> x;
		data.pb(x);
	}
	sort(data.begin(),data.end());
	rep(i,N){
		cout << data[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <map>
#include <iomanip>
#include <string>
#include <queue>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for (int i = 0; i < (int)n; ++i)
#define loop1(i, n) for (int i = 1; i <= (int)n; ++i)
#define pb push_back
#define pi pair<double, double>
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define ti tuple<int, int, int, int>
#define mkt make_tuple
#define mkp make_pair
#define cerr if (1) cerr

const int N = 2e5 + 7;

vector <int> g[N];
int p[N];

void bfs() {
    queue <int> q;
    q.push(1); p[1] = 1;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int u : g[v])
            if (!p[u]) {
                q.push(u);
                p[u] = v;
            }
    }
}

void solve() {
    int n, m; cin >> n >> m;
    loop(i, m) {
        int u, v; 
        cin >> u >> v;
        g[u].pb(v); g[v].pb(u);
    }
    bfs();
    for (int i = 2; i <= n; ++i)
        if (!p[i]) {
            cout << "No"; return;
        }
    cout << "Yes\n";
    for (int i = 2; i <= n; ++i)
        cout << p[i] << "\n";
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

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

int main() {
    int n, k, x, y, ans=0;
    vector<int> vec(200000);
    cin >> n >> k;
    ans=n;
    for(int i=0; i<n; i++) {
        cin >> y;
        vec[y-1]++;
    }
    priority_queue<int> q;
    for(int i=0; i<200000; i++) {
        q.push(vec[i]);
    }
    for(int i=0; i<k; i++) {
        x=q.top();
        q.pop();
        ans -= x;
    }
    cout << ans;
}

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

#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int main(){
    CIN2(n,k) 
    vector<long long> v(n);
    rep(i,n) cin >> v[i];

    sort(v.begin(),v.end());

    long long ans;
    for(int i=0;i+k<=n;i++){
        long long tmp = v[i+k-1] - v[i];
        if(!i) ans = tmp;
        else{
            ans = min(ans,tmp);
        }
    }    
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <unordered_map>

int N;
long long M;
std::unordered_map<long long, long long> collect;

int main()
{
	std::cin >> N >> M;
	long long sum = 0;
	for (int i = 0; i < N; ++i) {
		long long temp;
		std::cin >> temp;
		sum += temp;
		++collect[sum % M];
	}

	long long ans = 0;
	for (auto i : collect) {
		long long temp = i.second;
		ans += temp * (temp - 1) / 2;
	}
	ans += collect[0];

	std::cout << ans << '\n';

	return 0;
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long H, long long A){
    cout << (H + A - 1) / A << endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long A;
    scanf("%lld",&A);
    solve(H, A);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

vector<vector<int>> g;
vector<int> cost, ans, d;
int temp = 0;


void dfs(int v, int p = -1) {
	int j = upper_bound(d.begin(), d.end(), cost[v]) - d.begin();
	bool change = false;
	int val = -1;
	if (d[j - 1] < cost[v] && cost[v] < d[j]) {
		val = d[j];
		if (val == INT32_MAX)temp++;
		d[j] = cost[v];
		change = true;
	}
	ans[v] = temp;
	for (auto i : g[v]) {
		if (i != p) {
			dfs(i, v);
		}
	}
	if (change) {
		if (val == INT32_MAX)temp--;
		d[j] = val;
	}
}

int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	g.resize(n);
	cost.resize(n);
	d.resize(n + 1, INT32_MAX);
	d[0] = INT32_MIN;
	ans.resize(n);
	for (int i = 0; i < n; i++)cin >> cost[i];
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0);
	for (auto i : ans)cout << i << "\n";
}

Measured memory_bytes: 30832
K = int(input())


import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(a, b, c)

print(ans)

Measured memory_bytes: 69804
from collections import Counter

class Unionfind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)
        
    def find(self, x):
        if(self.parents[x] < 0):
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if(x == y):
            return
        
        if(self.parents[x] > self.parents[y]):
            x, y = y, x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}:{}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
p = list(map(int, input().split()))

uf = Unionfind(N)

for i in range(M):
    x, y = map(int, input().split())
    uf.union(x-1, y-1)

cnt = sum(uf.same(p[i]-1, i) for i in range(N))
print(cnt)

Measured memory_bytes: 20656
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(vi) (vi.begin(),vi.end())
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
lli fact[100005];

int main() 
{
    fact[0]=1;
    int n,m;
    si(n);si(m);
    
    for(int i=1;i<100005;i++) fact[i]=(i*fact[i-1])%mod;
    
    if(abs(n-m)>1){
        cout<<0<<endl;
        return 0;
    }
    
    lli ans=1;
    if(n==m+1 || m==n+1){
        ans*=fact[n];
        ans%=mod;
        ans*=fact[m];
        ans%=mod;
        cout<<ans<<endl;
    }
    else if(n==m){
        ans*=fact[n];
        ans%=mod;
        ans*=fact[m];
        ans%=mod;
        ans*=2;
        ans%=mod;
        cout<<ans<<endl;
    }
	return 0;
}

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

typedef long long ll;
const ll mod = 1e9 + 7;
const ll inf = 184467440737095516;

int n, k;

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

	cin >> n >> k;
	vector<int> stone(n + 1);
	vector<int> dp(k + 1);
	for (ll i = 1; i <= n; i++){
		cin >> stone[i];
	}
	for (ll i = 1; i <= k; i++){
		for (ll j = 1; j <= n; j++){
			if(i - stone[j] >= 0){
				if (dp[i - stone[j]] == 0){
					dp[i] = 1;
				}
			}
		}
	}
	if (dp[k] == 1){
		cout << "First" << '\n';
	}
	else{
		cout << "Second" << '\n';
	}
}
  

Measured memory_bytes: 640
a,b,c,d = gets.split.map(&:to_i)
alice = Array.new(101,0)
bob = Array.new(101,0)
sum = []

(a + 1..b).each do |i|
  alice[i] = 1
end

(c + 1..d).each do |j|
  bob[j] = 1
end

(0..100).each do |k|
  sum << alice[k] + bob[k]
end

p sum.count(2)


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

char tmp[72][72];
int flg[72][72];
string score[72][72];
void score_cl(){
	for(int i=0;i<5184;i++)score[i/72][i%72]="";
}
string ans;
void in(int w,int h){
	for(int i=0;i<5184;i++)flg[i/72][i%72]=0;
	ans="";
	score_cl();
	for(int i=0;i<5184;i++)tmp[i/72][i%72]='#';
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>tmp[j][i];
		}
	}
}

int com(string a,string b){
	if(a.size()>b.size())return 1;
	if(a.size()<b.size())return 0;
	if(a==b)return 2;
	for(int i=0;i<a.size();i++){
		if(a[i]>b[i])return 1;
		if(a[i]<b[i])return 0;
	}
}



int main(){
	int w,h;
	while(cin>>w>>h,w){
		in(w,h);
		for(int j=1;j<=w;j++){
			for(int i=1;i<=h;i++){
				if('1'<=tmp[j][i] && tmp[j][i]<='9' && flg[j][i]==0){
					score_cl();
					queue<int>X,Y;
					X.push(j);Y.push(i);
					while(!X.empty()){
						int x=X.front();X.pop();
						int y=Y.front();Y.pop();
						score[x][y]+=tmp[x][y];
						flg[x][y]=1;
						if(w-x+h-y+score[x][y].size()<ans.size())continue;
						if(com(score[x][y],ans))ans=score[x][y];
						if('0'<=tmp[x+1][y] && tmp[x+1][y]<='9' && com(score[x][y],score[x+1][y])){
							if(score[x+1][y]==""){
								X.push(x+1);
								Y.push(y);
							}
							score[x+1][y]=score[x][y];
						}
						if('0'<=tmp[x][y+1] && tmp[x][y+1]<='9' && com(score[x][y],score[x][y+1])){
							if(score[x][y+1]==""){
								X.push(x);
								Y.push(y+1);
							}
							score[x][y+1]=score[x][y];
						}
					}
				}
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

struct UnionFind{
    std::vector<int> parent, rank, cnt;

    UnionFind(int n) : parent(n), rank(n, 0), cnt(n, 1) {
        std::iota(parent.begin(), parent.end(), 0);
    }

    int find(int v){
        if(v == parent[v]){return v;}
        return parent[v] = find(parent[v]);
    }

    bool same(int v, int w){
        return find(v) == find(w);
    }

    void unite(int v, int w){
        v = find(v);
        w = find(w);

        if(v == w){return;}

        if(rank[v] > rank[w]){
            parent[w] = v;
            cnt[v] += cnt[w];
        }else{
            parent[v] = w;
            cnt[w] += cnt[v];
            if(rank[v] == rank[w]){rank[w] += 1;}
        }
    }

    int count(int v){
        return cnt[find(v)];
    }
};

int N, M;

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

    std::cin >> N >> M;

    UnionFind uf(N + 100);

    for(int i=0;i<M;++i){
        int x, y, z;
        std::cin >> x >> y >> z;

        uf.unite(x, y);
    }

    int c = 0;

    for(int i=1;i<=N;++i){
        if(uf.find(i) == i){
            c += 1;
        }
    }

    std::cout << c << std::endl;
}


Measured memory_bytes: 1408
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
q, h, s, d = map(int, sys.stdin.readline().rstrip().split())
N = I()
D = d
qh = min(2*q, h)
S = min(2*qh, s)
x = min(2*S, D)
if N%2 == 0:
    print(N//2*x)
else:
    print(N//2*x + S)

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

int main(){
	int n,x;
	cin >> n >> x;
	for(int i=-n+1;i<n;i++){
		cout << x+i;
		if(i!=n-1) cout << " ";
	}
	cout << endl;
		
//	for(int i=0;i<n;i++)
//		cout << x+i << " ";
	
}

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

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll n_): num((n_ + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint pow(const modint x, ll r) {
        return x^r;
    }

    static modint fact(int n){
        if((int)factorial.size() <= n) {
            int size = factorial.size();
            factorial.resize(n+1);
            for (int i = size; i <= n; i++) {
                factorial[i] = fact(i-1) * modint(i);
            }
        }
        return factorial[n];
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial = {1};
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)


int main(void){
    int n;
    cin >> n;
    map<int, int> mp;
    mp[-1] = 3;
    modint res = 1;
    rep(i,n){
        int a;
        cin >> a;
        res *= max(mp[a-1] - mp[a], 0);
        mp[a]++;
    }
    cout << res << endl;
    return 0;
}


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B){
    cout << C << endl;
  }else if(A>B && C-(A-B) >= 0){
    cout << C-(A-B) << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>

#define BUFSIZE 200000
#define INTMIN -2000000000

int main(){
    int n, buf[BUFSIZE];
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", buf + i);
    }
    int min = buf[0];
    int max = INTMIN;
    for(int i = 1; i < n; i++){
        if(max < buf[i] - min)max = buf[i] - min;
        if(min > buf[i])min = buf[i];
    }
    printf("%d\n", max);
}


Measured memory_bytes: 3452
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    ll N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    ll L = lcm(N,M);
    /*
    vector<char> v(L, '-');
    rep(i,N){
        v[i*(L/N)] = S[i];
    }
    print(v);
    rep(j,M){
        if(v[j*(L/M)] == T[j])continue;
        if(v[j*(L/M)] != '-'){
            cout << -1 << endl;
            return 0;
        }
        v[j*(L/M)] = T[j];
    }
    print(v);
    rep(i,L){
        if(v[i] == '-')v[i] = 'a';
    }*/

    for(ll j = 0; j < M; j++){
        ll to = j * (L / M);
        if(to % (L/N) == 0){
            ll i = to / (L / N);
            if(S[i] != T[j]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << L << endl;
}


Measured memory_bytes: 3792
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/
#define INF 10000000010

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

	int N, W;
	
	cin >> N >> W;

	ll dp[N+1][W+1];
	memset(dp, 0, sizeof(dp));

	int v[N], w[N];

	rep(i, N)
	{
		cin >> v[i] >> w[i];

		for(int j=0; j <= W; j++)
		{
			/*
			if (j + w[i] <= W)
			{
				dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j+w[i]]);
				dp[i+1][j+w[i]] = max(dp[i][j] + v[i], dp[i+1][j+w[i]]);
			}
			*/
			if (j-w[i] >= 0)
			{
				dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
				dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i+1][j]);
			}
			else
			{
				dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			}
			
			
		}
		
	}

	/*
	rep(i, N+1)
	{
		rep(j, W+1)
		{
			cout << "i=" << i << "; j=" << j << "; " << dp[i][j] << endl;  
		}
	}
	*/
	cout << dp[N][W] << endl;

	
	return 0;
}



Measured memory_bytes: 11116
n,X = gets.split.map(&:to_i)

x = gets.split.map(&:to_i)
x << X
x.sort!

gcd = x[1] - x[0]

if n == 1
  puts gcd
  exit
end

#n>=2
2.upto(n) do |i|
  d = x[i] - x[i-1]
  gcd = d.gcd(gcd)
end

puts gcd


Measured memory_bytes: 9716
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

class segtree{
public:
  int Node;
  vector<int> table;
  segtree(int);
  int ope(const int,const int);
  void update(int index,const int value){ // index is 0-indexed.
    index += Node; // query function
    table[index] += value;//update section
    while(index > 0){
      index /= 2;
      table[index] = ope(table[2*index],table[2*index+1]);
    }
  }
  int find(int l, int r);
};
int segtree::find(int l,int r){ // l,r is 0-indexed.
    if(l == r) return table[r+Node];
    l += Node; r += Node;
    int ans = 0;
    for(; l <= r;l >>=1, r >>=1){
      if(r == l){ans=ope(ans,table[l]); return ans;}
      if(r%2 == 0) ans=ope(ans,table[r]),--r;
      if(l%2) ans=ope(ans,table[l]),++l;
    }
    return ans;
}
segtree::segtree(int Max_Node){  // initialize
  Node = 2;
  while(Node < Max_Node)
    Node *= 2;
  table.resize(2*Node);
  for(int i = Node;i < Node*2; i++)
    table[i] = 0; // initialize
  for(int i= Node-1; i > 0; i--)
    table[i] = ope(table[i*2],table[i*2+1]);
}

int segtree::ope(const int a,const int b){
  return a+b;
}


int main()
{
	int n,q;
	cin >> n >> q;
	
	segtree seg(n);
	
	//SHOW1d(seg.table,(seg.Node*2));
	
	REP(i,q)
	{
		int a,b,c;
		cin >> a >> b >> c;
		
		if(a)
		{
			cout << seg.find(b,c) << endl;
		}
		else
		{
			seg.update(b,c);
		//	SHOW1d(seg.table,(seg.Node*2));
		}
	}
	
	return 0;
}

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

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; a++) {
        if (N % a != 0) continue;

        long long ex = 0;
        while (N % a == 0) {
            ex++;
            N /= a;
        }
        res.push_back({a, ex});
    }

    if (N != 1) res.push_back({N, 1});
    
    return res;
}

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

    const auto &pf = prime_factorize(P);
    long long res = 1;
    for (auto p : pf) {
        for (int j=0; j<p.second/N; j++) res *= p.first;
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

void bubbleSort(int [], int);

int main(){
  int N,A[100];
  int i;
  
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  bubbleSort(A, N);// N 個の要素を含む 0-オリジンの配列 A
  return 0;
}

void bubbleSort(int A[],int N){
  int i,j,tmp,k,count=0;

  for(i=0;i<N-1;i++){
    for(j=N-1;j>=i+1;j--){
      //ソートを入れ替える
      if(A[j]<A[j-1]){
	tmp=A[j];
	A[j]=A[j-1];
	A[j-1]=tmp;
	//入れ替えた回数を足す
	count++;
      }
    }
  }

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



Measured memory_bytes: 2104
def solve():
  n = int(input())
  query = []
  for i in range(n):
    tmp = input()
    s,p = tmp.split()
    query.append((s,p,i+1))
  query.sort()
  count = 0
  while count<n:
    count += 1
    for i in range(n):
      for j in range(i+1,n):
        if query[i][0] == query[j][0]:
          if int(query[i][1]) <int(query[j][1]):
            buf = query[i]
            query[i] = query[j]
            query[j] = buf
            
    
  for i in range(n):
    print(query[i][2])
solve()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Main {

	/* several useful subroutines */
	private static final BigDecimal BD1000000007 = new BigDecimal(1000000007);
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	private static BigDecimal mod1000000007(BigDecimal bd) {
		return bd.subtract(BD1000000007.multiply(bd.divide(BD1000000007, BigDecimal.ROUND_DOWN))) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(int i) {
		return mod1000000007(new BigDecimal(i)) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(long l) {
		return mod1000000007(new BigDecimal(l)) ;
	}

	
	/* main routine */
	public static void main(String args[]) throws IOException {
		int n = getInt();
		Map<String,Integer> m = new HashMap<String,Integer>();

		int max = 1;
		for ( int i = 0 ; i < n ; i++ ) {
			char[] ca = getString().toCharArray();
			Arrays.sort(ca);
			String key = new String(ca);
			if ( m.containsKey(key) ) {
				int j = m.get(key)+1;
				m.put( key, j );
				if ( max < j ) {
					max = j;
				}
			} else {
				m.put( key, 1 );
			}
		}
		long c[] = new long[max+1];
		c[1] = 0L;
		for ( int i = 1 ; i < max ; i++ ) {
			c[i+1] = c[i] + i;
		}
		
		long ans = 0;
		for ( int cnt : m.values() ) {
			ans += c[cnt];
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 46936
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
using namespace std;


int main(void){
    int n, m, c;
    cin>>n>>m>>c;
    vector<int> b(m);
    for(int i=0; i<m; i++){
        cin>>b[i];
    }
    vector<vector<int>> a(n, vector<int>(m, 0));
    
    int cnt=0;
    for(int i=0; i<n; i++){
        int sum=0;
        for(int j=0; j<m; j++){
            int t;
            cin>>t;
            sum+=t*b[j];
        }
        
        if(sum>-c){
            cnt++;
        }
    }
    
    cout<<cnt<<endl;
}


Measured memory_bytes: 256