akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int n, ans = 0;
void dfs(vector<vector<int>> &a, string flag){
    if(flag.size() == n){
        rep(i, n){
            if(flag[i] == '0') continue;
            rep(j,n){
                if(a[i][j] == -1) continue;
                if(a[i][j] == 1 && flag[j] == '0') return;
                if(a[i][j] == 0 && flag[j] == '1') return;
            }
        }
        int memo = 0;
        rep(i, n){
            if(flag[i] == '1') memo++;
        }
        ans = max(ans, memo);
        return;
    }
    dfs(a, flag + "0");
    dfs(a, flag + "1");
    return;
}

int main(){
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n, -1));
    rep(i,n){
        int b;
        cin >> b;
        rep(j, b){
            int x, y;
            cin >> x >> y;
            a[i][x-1] = y;
        }
    }
    dfs(a, "");
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math 
k,n = map(int , input().split())
a = list(map(int , input().split()))
ans = 0
for i in range(0,n-1):
  ans = max(ans,abs(a[i] - a[i+1]))

ans = max(ans,abs(k + a[0] - a[-1]))
print(k - ans)



Measured memory_bytes: 26444
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

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

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
  ini(N);
  vll S(N);
  rep(i, N) cin >> S[i];

  sort(S.begin(), S.end());
  ll sum = accumulate(S.begin(), S.end(), 0);
  if (sum % 10 == 0) {
    auto it = find_if(S.begin(), S.end(), [](auto x) { return x % 10 != 0; });
    if (it == S.end())
      out(0);
    else
      out(sum - *it);
  } else {
    out(sum);
  }
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;
 
int main() {
  ll n,x;cin>>n>>x;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  sort(all(a));
  int cnt=0;
  rep(i,n){
    x-=a[i];
    if(x<0)break;
    cnt++;
    if(i==n-1&&x>0)cnt--;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3556
a,b,x = map(int,input().split())

import math

temp1 = (a**2 * b - x) * 2.0 / a**3

theta1 = math.degrees(math.atan(temp1))

temp2 = (a * b**2) * 1.0 / (2.0 * x)

theta2 = math.degrees(math.atan(temp2))

if a**2 * b < 2 * x:
    res = theta1
else:
    res = theta2

print(res)


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

using namespace std;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 3000 + 9, M = 50 + 9, OO = (int) 1e9 + 1;
const long long MOD = 1e9 + 7;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(12);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

void INPUT() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(12);
//	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

string s, t;
int mem[N][N];

int LCS(int x, int y) {
	if (x < 0 || y < 0)
		return 0;
	int &ret = mem[x][y];
	if (ret != -1)
		return ret;
	if (s[x] == t[y])
		ret = LCS(x - 1, y - 1) + 1;
	else {
		int a = LCS(x - 1, y);
		int b = LCS(x, y - 1);
		ret = max(a, b);
	}
	return ret;
}

string findLCS(int x, int y) {
	if (x < 0 || y < 0)
		return "";
	if (s[x] == t[y])
		return findLCS(x - 1, y - 1) + s[x];
	else {
		if (y > 0 && mem[x][y] > 0 && mem[x][y - 1] == mem[x][y]) {
			return findLCS(x, y - 1);
		} else if (x > 0 && mem[x][y] > 0 && mem[x - 1][y] == mem[x][y]) {
			return findLCS(x - 1, y);
		}
	}
	return "";
}
int main() {
//	INPUT();
	OUTPUT();
	clr(mem, -1);
	cin >> s >> t;
	LCS(sz(s) - 1, sz(t) - 1);
	cout << findLCS(sz(s) - 1, sz(t) - 1);
	return 0;

}


Measured memory_bytes: 36096
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N, Q;
  cin >> N >> Q;
  long long A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  long long sum[N + 1];
  sum[N] = 0;
  for (int i = N - 1; i >= 0; i--) sum[i] = sum[i + 1] + A[i];
  long long suml[N + 1];
  suml[0] = 0;
  for (int i = 1; i <= N; i++) {
    suml[i] = suml[i - 1];
    if ((i & 1) == (N & 1)) suml[i] += A[i - 1];
  }
  while (Q--) {
    long long X;
    cin >> X;
    auto check = [&](int i) {
      if (A[i] < X) return false;
      int j = lower_bound(A, A + N, 2 * X - A[i]) - A;
      return N - i <= i - j + 1;
    };
    int low = 0, high = N;
    while (high - low > 1) {
      int mid = (low + high) / 2;
      if (check(mid))
        high = mid;
      else
        low = mid;
    }
    int x = high;
    debug(x);
    long long ans = sum[x];
    debug(ans);
    int j = max(0, N - (N - x) * 2);
    debug(j);
    ans += suml[j];
    cout << ans << '\n';
  }
  return 0;
}


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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
using P = pair<int,int>;
//Write From this Line

int main()
{
	int n;
	cin >> n;
	vector<long long> a(n);
	rep(i, n)cin>>a[i];
	long long x = 1;
	rep(i,n){
		if(a[i] == 0){
			cout << 0 << endl;
			return 0;
		}
	}
	rep(i,n){
		if(x > 1000000000000000001 / a[i]){
			cout << -1 << endl;
			return 0;
		}
		x *= a[i];
	}
	if(x > 1000000000000000000 || x < 0) {
		cout << -1 << endl;
		return 0;
	}
	cout << x << endl;
}


Measured memory_bytes: 4048
N = int(input())
R = [0]*N
C = [0]*N
for i in range(N):
    R[i],C[i] = map(int, input().split())
    
DP = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
    DP[i][i] = 0

for l in range(1, N):
    for r in range(N-l):
        ri = R[r]
        le = C[r+l]
        DP[r][r+l] = min(ri*C[k]*le+DP[r][k]+DP[k+1][r+l] for k in range(r, r+l))
print(DP[0][N-1])


Measured memory_bytes: 5664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;
 
int N;

vector<int> G[212345];


bool visit[212345];
int dist[212345];
void bfs(int s){
    queue<int> que;
    que.push(s);
    dist[s]=0;
    visit[s]=true;
    while(!que.empty()){
        int q=que.front();que.pop();
        for(int i=0;i<G[q].size();i++){
            if(!visit[G[q][i]]){
                visit[G[q][i]]=true;
                dist[G[q][i]]=dist[q]+1;
                que.push(G[q][i]);
            }
        }
    }
}
void init(){
    rep(i,N){
        visit[i]=false;
        dist[i]=0;
    }
}
signed main(){
    cin>>N;

    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    bfs(0);

    int mx=0,idx=-1;
    rep(i,N){
        if(dist[i]>mx){
            mx=dist[i];
            idx=i;
        }
    }
    init();
    bfs(idx);



    rep(i,N){
        if(dist[i]>mx){
            mx=dist[i];
            idx=i;
        }
    }



    if(mx%3==1){
        cout<<"Second"<<endl;
    }else{
        cout<<"First"<<endl;
    }

    


 
}

Measured memory_bytes: 14068
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



long long W, H, x, y;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> W >> H >> x >> y) {
        double res = (double)(W) * H / 2;
        cout << fixed << setprecision(10) << res << " ";

        if (x*2 == W && y * 2 == H) cout << 1 << endl;
        else cout << 0 << endl;
    }
}






















Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int n, i;
	cin >> n >> i;
	int ans = n - i + 1;
	cout << ans << endl;
}



Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
const int mod = 1000000007;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
using namespace std;
ll gcd(ll a, ll b) {
	if (max(a, b) % min(a, b) == 0)return min(a, b);
	else return gcd(min(a, b), max(a, b) % min(a, b));
}
int main() {
	ll n,k, v[100010],mx=0,nn;
	bool b = 0;
	cin >> n >> k;
	rep(i, n) {
		cin >> v[i];
		if (k == v[i])b = 1;
		mx = max(mx, v[i]);
		if (i == 0)nn = v[i];
		else nn = gcd(nn, v[i]);
	}
	if (b)cout << "POSSIBLE" << endl;
	else if (mx < k)cout << "IMPOSSIBLE" << endl;
	else {
		cout << (nn==1||k%nn==0?"POSSIBLE":"IMPOSSIBLE") << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,n,i,ans=0,sum=0;
    cin>>k>>n;
    int a[n];
    
    for(i=0;i<n;i++){cin>>a[i];if(i)ans=max(a[i]-a[i-1],ans);}
    ans=max(ans,k-a[n-1]+a[0]);
    cout<<k-ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <random>
#include <utility>
#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1ll<<61 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void fix_cout(){cout << fixed << setprecision(20) ;}
void chmax(ll &a,ll b){	if(a<b) a = b ;}
void chmin(ll &a,ll b){ if(a>b) a = b ;}

int main(){
	ll n,x,t ;
	cin >> n >> x >> t ;
	cout << (n+x-1)/x*t << endl ;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    long long T[N];
    rep(i,N) cin >> T[i];
    long long ans=T[0];
    rep(i,N-1){
        long long x=__gcd(ans,T[i+1]);
        ans=ans*(T[i+1]/x);
    }
    cout << ans << endl;



}


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

using namespace std;

int main(void) {
	string o, e;
  	string ans = "";
  	cin >> o >> e;
  	for (int i = 0; i < e.length(); i++) {
    	ans += o[i];
      	ans += e[i];
    }
  	if (o.length() > e.length()) {
    	ans += o[o.length()-1];
    } 
  	cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	t := getNextString(scanner)
	p := getNextString(scanner)
	mp := MP{}
	mp.init(p)
	n := len(t)
	pn := len(p)
	pi := 0
	for i := 0; i <= n; i++ {
		if pi == pn {
			fmt.Fprintln(writer, i-pn)
			pi = mp.table[pi]
		}
		if i == n {
			break
		}
		if t[i] != p[pi] {
			for pi >= 0 && t[i] != p[pi] {
				pi = mp.table[pi]
			}
		}
		pi++
	}

	writer.Flush()
}

// MP ...
type MP struct {
	s     string
	table []int
}

func (mp *MP) init(s string) {
	mp.s = s
	n := len(s)
	table := make([]int, n+1)
	table[0] = -1
	j := -1
	for i := 0; i < n; i++ {
		for j >= 0 && s[i] != s[j] {
			j = table[j]
		}
		j++
		table[i+1] = j
	}
	mp.table = table
}



Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int main(){
  int a, b;
  cin>>a>>b;
  if(b%a == 0){
    cout << a+b <<endl;
  }else{
    cout << b-a <<endl;
  }
}

Measured memory_bytes: 256
def main():
  s=str(input())
  l=len(s)
  f=None
  e=None
  for i in range(l):
    if s[i]=='A':
      f=i
      break
  for i in range(1,l):
    if s[-i]=='Z':
      e=l-i
      break
  print(e-f+1)
if __name__ == "__main__":
    main()

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

long double mysqrt(long double x)
{
    long double l = 1, r = 100000;
    for (int ii = 0; ii < 10000000; ++ii)
    {
        long double m = (l + r) / 2;
        if (m * m <= x)
            l = m;
        else
            r = m;
    }
    return l;
}

int main()
{
    long double a, b, c;
    cin >> a >> b >> c;
    long double aa = mysqrt(a);
    long double bb = mysqrt(b);
    long double cc = mysqrt(c);
    if (aa + bb < cc && a + 2 * aa * bb + b < c)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

using namespace std;

bool prime(int a){
  bool flag=true;
  for(int i=2;i*i<=a;i++){
    if(a%i==0){
      flag=false;
      break;
    }
  }
  return flag;
}
int main(){
  int x;
  cin >> x;
  if(x==2){
      cout << x << endl;
      return 0;
  }
  bool ans=false;
  ans=prime(x);
  while(!ans){
    x++;
    ans=prime(x);
  }
  cout << x << endl;
}

Measured memory_bytes: 256
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll a[N], b[N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n;
    cin >> n;
    for (ll i = 0; i < n; i++)
        cin >> a[i], b[i] = a[i];
    sort(a, a + n, greater<ll>());
    for (ll i = 0; i < n; i++)
        if (b[i] == a[0])
            cout << a[1] << "\n";
        else
            cout << a[0] << "\n";
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    ll n; cin >>n;
    vector<ll> a(n); REP(i,n) cin >> a[i];

    sort(a.begin(), a.end(), greater<ll>());

    ll count = 0;
    ll res = 1;
    for (ll i = 0; i < (ll)a.size();) {
        if (count == 2) {
            break;
        } 
        if (i < n-1 && a[i] == a[i+1]) {
            res *= a[i];
            count++; 
            i += 2;
        } else {
            i++;
        }
    }

    if (count == 2) {
        cout << res << endl;
    } else {
        cout << 0 << endl;
    } 
    return 0;
}



Measured memory_bytes: 1024
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n, k = LI()
	p_list = LI()
	p_list.sort()
	print(sum(p_list[:k]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 27096
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];
    
    int min = p[0];
    int count = 1;
    for (int i = 1; i < n; i++) {
        if (p[i] <= min) {
            count++;
            min = p[i];
        }
    }
    
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    int a, b, c;
    cin >> a >> b >> c;
    set<int> st;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    cout << (st.size() == 2 ? "Yes" : "No");
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting, graph is not a tree/connected
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
	int N;
	cin >> N;
	vector<long long>A(N);
	for (int n = 0;n<N;++n) {
		cin >> A[n];
	}
	vector<mint>MOD(60);//1,2,4,8,16,,,,,,,,,,,,,,,,,,,,
	mint tmp = 1;	
	for (int n = 0; n < 60; ++n) {
		MOD[n] = tmp;
		tmp *= 2;
	}
	mint ans = 0;
	for (int n = 0;n<60;++n) {
		mint num = 0;
		for (int m = 0;m<N;++m) {
			if (1 == ((A[m]>>n)&1)) {
				num = num+1;
			}
		}
		num = ((mint)N - num)*num; 
		ans += MOD[n] * (mint)num;
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 5644
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            System.Threading.Thread.Sleep(1000);
        }

        public void Solve(ConsoleInput cin)
        {
            int[] a = cin.ReadIntArray(4);

            if ((Abs(a[0] - a[1]) <= a[3] && Abs(a[1] - a[2]) <= a[3])||(Abs(a[0] - a[2]) <= a[3])){

                Console.WriteLine("Yes");
            }
            else {
                Console.WriteLine("No");
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long num) { var ret = new string[num]; for (long i = 0; i < num; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long num) { var ret = new int[num]; for (long i = 0; i < num; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long num) { var ret = new long[num]; for (long i = 0; i < num; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11220
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>

#define INF 1<<29

using namespace std;

int main(void) {
	int n, a, b;
	string s;
	cin >> n >> a >> b >> s;
	int rank = 1;
	int b_rank = 1;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'a') {
			if (rank <= a + b) {
				cout << "Yes" << endl;
				rank++;
			}
			else {
				cout << "No" << endl;
			}
		}
		else if(s[i]=='b'){
			if (rank <= a + b && b_rank <= b) {
				cout << "Yes" << endl;
				rank++;
				b_rank++;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>

int main(void)
{
  int i, a;
  char date[11];
  char last[] = "2019/04/30";

  scanf("%s",date);

  i=0;
  a=1;
  while (date[i] != '\0'){
    if (date[i] > last[i]){
      a=0;
      break;
    }

    else if (date[i] < last[i]){
      a=1;
      break;
    }
    i++;
  }

  if (a==0)
      printf("TBD\n");
  else
      printf("Heisei\n");

  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int R=in();
	
	if(R<1200){
		cout << "ABC" << endl;
	}
	else if(R<2800){
		cout << "ARC" << endl;
	}
	else cout << "AGC" <<endl;
	return 0;
}


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

signed main () {
    int n;
    for (int i = 1; i <= 5; ++i) {
        scanf("%d", &n);
        if (n)
            continue;
        else {
            printf("%d\n", i);
            return 0;
        }
    }
}


Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
//const int mod = 1e9 + 7;
const int mod = 998244353;

int main(){
	while(1){
		ll n,m; cin >> n >> m;
		if(n+m == 0) break;
		map<int,string> mp;
		map<string,int> mx;
		rep(i,n){
			string s; ll a,b; cin >> s >> a >> b;
			mp[b-a+1] = s;
			chmax(mx[s],a);
		}
		rep(i,m){
			ll a; cin >> a;
			auto itr = mp.upper_bound(a);
			if(itr == mp.begin()){
				cout << "Unknown" << endl;
				continue;
			}
			itr--;
			ll d = a - (*itr).first + 1;
			if(mx[(*itr).second] < d) cout << "Unknown" << endl;
			else print2((*itr).second, d);
		}
	}
}


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

using namespace std;

int main() {

	int n;
	cin >> n;

	vector<char> s(100000000,0);
	//char str1[9];
	//char str2[14];
	string str1, str2;

	long long has;
	long long hass;
	for (int i = 0; i < n; i++) {
		//scanf_s("%s %s",str1,9,str2,14);
		cin >> str1 >> str2;

		has = 0;
		hass = 0;
		for (int j = 0; j < str2.size(); j++) {
			if (str2[j] == 'A') { has = 1; }
			else if (str2[j] == 'C') { has = 2; }
			else if (str2[j] == 'G') { has = 3; }
			else if (str2[j] == 'T') { has = 4; }
			hass += has *pow(5,j);
		}

		if (str1[0]== 'f') {
			if (s[hass]== 0) {
				printf("%s", "no\n");
				//cout << "no" << endl;
			}
			else {
				printf("%s", "yes\n");
//				cout << "yes" << endl;
			}
		}
		else if (str1[0] == 'i') {
			s[hass] = 1;
		}
	}

}


Measured memory_bytes: 100508
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int r = sc.nextInt();
   int D = sc.nextInt();
   int x = sc.nextInt();
   
   int[] ans = new int[11]; 
   ans[0]=x;
   for(int i=0;i<=9;i++)
   {
    ans[i+1]=ans[i]*r-D; 
   }
   
  for(int k=1;k<=10;k++)
   {
   System.out.println(ans[k]);
   }
   
   
 }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
const int INF=1e9+5;
typedef long long ll;

int main() {
  ll N;
  cin>>N;
  ll a[N];
  rep(i,N){
    cin>>a[i];
  }
  ll k=0;
  rep(i,N-1){
    if(a[i]!=i+1){
      k++;
    }
  }
  if(k<=2){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <algorithm>

int N, K, a[1123], b[1123];
int ans[1123];

int main(void) {
	scanf("%d%d", &N, &K);
	for (int i = 0; i < K; ++i) { scanf("%d%d", &a[i], &b[i]); }

	for (int i = 0; i < K; ++i) {
		ans[i] = std::min(a[i] - 1, std::min(N - a[i], std::min(b[i] - 1, N - b[i])));
		ans[i] %= 3;
	}

	for (int i = 0; i < K; ++i) { printf("%d\n", ans[i] + 1); }
	return 0;
}

Measured memory_bytes: 2652
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int N;

int main() {
    cin >> N;
    vector<int> A(N);
    map<int, int> m;
    REP(i, N) {
        cin >> A.at(i);
        m[A[i]]++;
    }

    int ans = 0;
    for (auto i : m) {
        if (i.second % 2 == 1) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>
 
int main(void){
    int i,dice[7];
    char order[101];
     
    for(i=1;i<7;i++)
        scanf("%d", &dice[i]);
     
    scanf("%s", order);
     
    for(i=0;order[i]!='\0';i++){
         
        dice[0] = dice[1];
         
        switch(order[i]){
                 
            case 'E':
                dice[1] = dice[4];
                dice[4] = dice[6];
                dice[6] = dice[3];
                dice[3] = dice[0]; 
                break;
             
            case 'N':
                dice[1] = dice[2];
                dice[2] = dice[6];
                dice[6] = dice[5];
                dice[5] = dice[0]; 
                break;
             
            case 'S':
                dice[1] = dice[5];
                dice[5] = dice[6];
                dice[6] = dice[2];
                dice[2] = dice[0]; 
                break;
                 
            case 'W':
                dice[1] = dice[3];
                dice[3] = dice[6];
                dice[6] = dice[4];
                dice[4] = dice[0]; 
                break;
 
        }
    }
     
    printf("%d\n", dice[1]);
     
    return 0;
}


Measured memory_bytes: 2132
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

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

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"

const int N = 2e5;
const int INF = 2e9;

int n, k, h[N], dp[N];

int main () {
	ios_base::sync_with_stdio(0);
	cin >> n >> k;
	for(int i = 1; i <= n; ++i) {
		cin >> h[i];
	}		
	for(int i = 2; i <= n; ++i) {
		dp[i] = INF;
		for(int j = max(1, i - k); j < i; ++j) {
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));			
		}				
	}
	cout << dp[n];
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	string s;
	cin >> s;

	int ans = 0;
	string tmp = "";
	string tmp2 = "";

	bool flg = true;

	for (int i = 0; i < s.size() - 1; i++)
	{
		if (s[i] == s[i + 1] && flg)
		{
			i++;
			flg = false;

		}
		else
		{
			flg = true;
		}
		ans++;
		if (i == s.size() - 2)
		{
			ans++;
		}
	}

	cout << ans << endl;

}

Measured memory_bytes: 720
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    int v, w, h;
    while(cin >> v >> w >> h && v)
    {
        int r = v * v + w * w;
        r = min(r, w*w + h*h);
        r = min(r, h*h + v*v);

        int n, hole; cin >> n;
        REP(n)
        {
            cin >> hole;
            if(r < hole * hole * 4) cout <<"OK" << endl;
            else cout << "NA" << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<string>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
typedef long long ll;
using namespace std;

static const ll mod  = 1e9 + 7;
static const ll inf  = 1e18;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

void pvector(vector<int> A){
    cout << "[vector]";
    for(int i = 0; i < A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    int a, b;
    cin >> a >> b;
    if(a <= 5) p("0");
    else if(12 >= a) p(b/2);
    else p(b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;

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

    int N,T; cin>>N>>T;
    vector<pair<int,int>> v;
    for(int i=0;i<N;i++){
        int a,b; cin>>a>>b;
        v.push_back({a,-b});
    }
    sort(v.begin(),v.end());

    vector<int> a(N),b(N);
    for(int i=0;i<N;i++){
        a[i]=v[i].first;
        b[i]=-v[i].second;
        // cout<<a[i]<<' '<<b[i]<<endl;
    }

    vector<vector<int>> dp(N+1,vector<int>(T+1,-1));
    dp[0][0]=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<T;j++) if(dp[i][j]!=-1){
            chmax(dp[i+1][j],dp[i][j]);
            chmax(dp[i+1][min(T,j+a[i])],dp[i][j]+b[i]);
        }
        chmax(dp[i+1][T],dp[i][T]);
    }
    cout<<*max_element(dp[N].begin(),dp[N].end())<<endl;
    return 0;
}

Measured memory_bytes: 35584
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)
/*
long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

lld fac[200001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=200000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


long long int gcd(lld b,lld a)
{
    if(a<b) return gcd(a,b);
    if(a%b==0) return b;
    return gcd(a%b , b);
}
*/
lld p1=1000000007,p2=998244353;
lld l,r,mid,ans=0;
lld n,i,j,k;
lld x,y,n1,b=0,a,n2,h,z,c;
lld p=1000000000;
double pi=3.1415926535;
    
void solve()
{
    lld a,b,h,m;
    cin>>a>>b>>h>>m;
    h=30*h;
    m=6*m;
    double x;
    x=h-m + (m*1.0/12);

   // cout<<x<<"\n";
    //cout<<a*a<<" "<<b*b<<" ";
    printf("%0.9lf",sqrt(((a*a)+(b*b)) - 2*a*b*cos((x*pi)/180)));
}   


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    // cin>>t;
    //cout<<t;
    //getfac(p2);
    for(int i=0;i<t;i++)
    {
       //cout<<"Case #"<<i+1<<": ";
            solve();
    //    cout<<"\n";
    }

    return 0;
}

Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define ld long double
#define ft first
#define sd second
using namespace std;

const int N = 3e3 + 9;
ll f[N][N], pre[N][N];

signed main() {

    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    string s; cin >> s; 
    s = "--" + s;
    f[1][1] = pre[1][1] = 1;
    for(int i = 2; i <= n; i++) {
        for(int j = 1; j <= i; j++) {
            if(s[i] == '<') {
                f[i][j] = pre[i-1][j-1];
            } else {
                f[i][j] = pre[i-1][i-1] - pre[i-1][j-1];
                if(f[i][j] < 0) f[i][j] += mod;
            }
            pre[i][j] = pre[i][j-1] + f[i][j];
            if(pre[i][j] >= mod) pre[i][j] -= mod;
        }
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++) ans += f[n][i];
    cout << ans % mod << endl;
    
    return 0;
}

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

int main()
{
	int V, E;
	scanf("%d%d", &V, &E);
	std::vector<std::list<int>> graph(V);
	std::vector<char> chara(V);
	for (auto& e: chara) scanf(" %c", &e);

	for (int i{}; i < E; i++)
	{
		int s, t;
		scanf("%d%d", &s, &t);
		graph[s].push_back(t);
		graph[t].push_back(s);
	}
	for (int i{}; i < V; i++)
	{
		if (chara[i] != '?') continue;
		bool table[26]{};
		for (auto& e: graph[i])
			if (chara[e] != '?')
				table[chara[e] - 'a'] = true;
		for (int j{}; j < 26; j++)
			if (!table[j])
			{
				chara[i] = 'a' + j;
				break;
			}
	}
	for (auto& e: chara) putchar(e);
	putchar('\n');

	return 0;
}


Measured memory_bytes: 17056
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    string s;
    cin >>n >>s;
    int sz = s.size();
    for(int i = 0; i < sz; i++){
        if(char(s[i] + n) > 'Z'){
            cout <<(char)(((int)s[i] + n) % (int)'Z' + 'A' - 1);
        }
        else
            cout <<char(s[i] + n);
    }
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define rrep(i,n) for(ll i=(ll)n-1;i>=0;--i)
#define vin(v,n) rep(i,n)cin>>v[i];
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define sz size()
#define fi first
#define se second
#define pb push_back
#define prqueue priority_queue<ll,vector<ll>,greater<ll>>
#define print(s) cout<<s<<endl;
#define inp(s) cin>>s;
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll n, v[3010];
ll gcd(ll a, ll b) {
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
int main() {
	ll ans = 0,ans2=0;
	cin >> n;
	rep(i, n) {
		cin >> v[i]; ans += v[i];
	}
	cout << ans-n << endl;
	return 0;
}

Measured memory_bytes: 256