akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, lbuf, rbuf, mi;
	cin >> n;
	P lr[n];
	ll ans = 0;
	zep(i, 0, n){
		cin >> lbuf >> rbuf;
		lr[i] = P(rbuf, lbuf);
		if(rbuf-lbuf+1 > ans){
			ans = rbuf-lbuf+1;
			mi = i;
		}
	}
	ll lm = 0;
	ll rm = 1e9;
	zep(i, 0, n){
		if(i != mi){
			lm = max(lr[i].second, lm);
			rm = min(lr[i].first, rm);
		}
	}
	ans += max(rm-lm+1, 0LL);
	
	sort(lr, lr+n);
	zep(i, 0, n){
		ll tmp = lr[i].first;
		lr[i].first = lr[i].second;
		lr[i].second = tmp;
	}
	
	ll al[n], dl[n], ar[n], dr[n];
	al[0] = lr[0].first;
	ar[0] = lr[0].second;
	zep(i, 1, n){
		al[i] = max(lr[i].first, al[i-1]);
		ar[i] = min(lr[i].second, ar[i-1]);
	}
	
	dl[n-1] = lr[n-1].first;
	dr[n-1] = lr[n-1].second;
	rrep(i, n-2, 0){
		dl[i] = max(lr[i].first, dl[i+1]);
		dr[i] = min(lr[i].second, dr[i+1]);
	}
	
	zep(i, 0, n-1){
		ans = max(ar[i]-al[i]+1+dr[i+1]-dl[i+1]+1, ans);
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <math.h>
int main(void)
{
 int A, B, X, i, j;
 scanf("%d %d", &A, &B);
 if(B < 10) {
   X = A * 10 + B;
 }
 else if(B < 100) {
   X = A * 100 + B;
 }
 else{
   X = A * 1000 + B;
 }
 for(j = 3; j * j <= 100100; j++) {
   if(X == j * j) {
     printf("Yes");
     return 0;
   }
 }
   printf("No");
 return 0;
}

Measured memory_bytes: 128
puts Enumerator.new{|y|
	 t=i=1
	 loop{
	 	s=i.to_s.chars.map(&:to_i).reduce(:+)
	 	if s*t<i
	 		i+=9*t
	 		t*=10
		else
			y<<i
			i+=t
		end
	 }
}.lazy.take(gets.to_i).to_a

Measured memory_bytes: 1916
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Person[] arr = new Person[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = new Person(i + 1, sc.nextInt());
		}
		Arrays.sort(arr);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (i != 0) {
		        sb.append(" ");
		    }
		    sb.append(arr[i].idx);
		}
		System.out.println(sb);
   }
   
   static class Person implements Comparable<Person> {
       int idx;
       int num;
       
       public Person (int idx, int num) {
           this.idx = idx;
           this.num = num;
       }
       
       public int compareTo(Person another) {
           return num - another.num;
       }
   }
}


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

int main()
{
  int n;
  while(cin >> n && n > 0)
    {
      int s[100];
      int max=-1, min=1001;
      int sum=0, ave=0;
      for(int i=0;i<n;i++)
	{
	  cin >> s[i];
	  sum += s[i];
	  if(s[i] > max)
	    max = s[i];
	  if(s[i] < min)
	    min = s[i];
	}
      sum -= (max + min);
      ave = sum/(n-2);
      cout << ave << endl;
    }
}



Measured memory_bytes: 3012
strength = [0,13,1,2,3,4,5,6,7,8,9,10,11,12]
main = do
    [a,b] <- map read . words <$> getLine
    if (strength!!a) > (strength!!b) then putStrLn "Alice" else if (strength!!a) < (strength!!b) then putStrLn "Bob" else putStrLn "Draw"

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

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

int main() {
	int N; cin >> N;
	vector<vector<ll>>a(N, vector<ll>(3));
	rep(i, N)rep(j, 3)cin >> a[i][j];

	vector<vector<ll>>dp(N + 1, vector<ll>(3,0));
	dp[0][0] = 0, dp[0][1] = 0, dp[0][2] = 0;
	REP(i, 1, N + 1) {
		rep(j, 3) {
			rep(k, 3) {
				if (j == k)continue;
				chmax(dp[i][j], dp[i - 1][k] + a[i - 1][k]);
			}
		}
	}
	ll ans = 0;
	rep(i, 3) {
		chmax(ans, dp[N][i]);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	string s;
	cin>>s;
	ll n=s.length();
	
	ll st=-1,en=-1;
	for(ll i=0;i<n;i++){
		if(s[i]=='<'){
			st=i;break;
		}
	}
	
	for(ll i=n-1;i>=0;i--){
		if(s[i]=='>'){
			en=i;break;
		}
	}
	
	if(st==-1){
		cout<<(n*(n+1))/2<<endl;
		return 0;
	}
		ll ans=0;
		for(ll i=st;i<=en;){
			ll c1=0;
			while(i<=en&&s[i]=='<'){
				c1++;i++;
			}
			ll c2=0;
			while(i<=en&&s[i]=='>'){
				c2++;i++;
			}
			if(c1>c2) swap(c1,c2);
			ans+=((c1)*(c1-1)/2);
			ans+=((c2)*(c2+1)/2);
		}
		ll c1=st;
		ans+=((c1)*(c1+1)/2);
		ll c2=n-en-1;
		ans+=((c2)*(c2+1)/2);
		cout<<ans<<endl;
	
}

Measured memory_bytes: 900
#include<stdio.h>
/*
A:整数
nA%B=C
余りは0~B-1


*/
int main(void){
	int A,B,C;
	int i;
	int f=0;
	scanf("%d %d %d",&A,&B,&C);
	for(i=1;i<B+2;i++){
		if((A*i)%B==C){
			f=1;
			break;
		}
	}
	if(f)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 128
a=int(input()) # 500
b=int(input()) # 100
c=int(input()) # 50
x=int(input())
count = 0

for i in range(0, a+1):
    for j in range(0, b+1):
        for k in range(0, c+1):
            if 500 * i + 100 * j + 50 * k == x:
                count += 1
print(count)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  int key;
  struct node *right,*left,*parent;
};

typedef struct node * Node;
Node root;

Node find(Node u, int k){
  if(u == NIL || k == u->key) return u;     
  if(k < u->key) return find(u->left,k);
  else return find(u->right,k);      
}


void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(z->key < y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n, i, x, key;
    char com[20];
    scanf("%d", &n);
    for (i=0;i<n;i++)
      {
	scanf("%s", &com);
	if (com[0]=='i')
	  {
	    scanf("%d", &x);
	    insert(x);
	  }
	else if (com[0]=='p')
	  {
	    inorder(root);
	    printf("\n");
	    preorder(root);
	    printf("\n");
	  }
	else{
	  scanf("%d",&key);
	  if(find(root,key)==NIL) printf("no\n");
	  else printf("yes\n");       
	}
      }
	return 0;
      }

Measured memory_bytes: 19364
ab = lambda a,b:abs(a-b)
area = lambda a,b:ab(a[1],b[1])*ab(a[0],b[0])

N, K = map(int, input().split())
A = []
x_lst = []
y_lst = []
for i in range(N):
    a,b = map(int, input().split())
    A.append([a,b])
    x_lst.append(a)
    y_lst.append(b)

x_lst.sort()
y_lst.sort()
mn = float('INF')
for x in range(N-1):
    for x_ in range(x,N):
        for y in range(N-1):
            for y_ in range(y,N):
                cnt = 0
                for a,b in A:
                    if x_lst[x] <= a <= x_lst[x_] and y_lst[y] <= b <= y_lst[y_]:
                        cnt += 1
                if cnt >= K:
                    mn = min(mn, area([x_lst[x],y_lst[y]], [x_lst[x_], y_lst[y_]]))
print(mn)


Measured memory_bytes: 49328
import java.util.HashMap;
import java.util.Scanner;


public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            long[] A = new long[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }
            long[] cumsum = new long[N + 1];
            HashMap<Long, Integer> invCumsum = new HashMap<>();
            invCumsum.put(0L, 1);
            long count = 0;
            for (int i = 0; i < N; i++) {
                cumsum[i + 1] = A[i] + cumsum[i];
                Integer count3 = invCumsum.get(cumsum[i + 1]);
                int count2 = count3 == null ? 0 : count3.intValue();
                count += count2;
                invCumsum.put(cumsum[i + 1], 1 + count2);
            }
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 92220
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    vector<int> v(5);
    scan(v);

    SORT(v);
    ll ans = INF64;
    do {
        ll sum = 0;
        REP(i, 5) {
            sum += v[i];
            if (i != 4 && v[i] % 10 != 0)
                sum += 10 - v[i] % 10;
        }
        chmin(ans, sum);
    } while (next_permutation(ALL(v)));
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstddef>
#include<vector>
#include<map>
#include<iomanip>
#include<algorithm>
#include<numeric>

using ui32 = std::uint32_t;
using flt64 = long double;

int main(){

	ui32 n, w;
	std::cin >> n >> w;

	
	std::map<flt64, ui32, std::greater<>> store;

	for( ui32 i{}; i < n; ++i )
	{ 
		ui32 v, w;
		std::cin >> v >> w;

		const auto key = static_cast<flt64>( v ) / w;
		store[key] += w;

	}


	auto it = std::begin( store );
//	flt64 ans = 0;
	std::vector<flt64> ans;
//	flt64 fw = w;
	while( w > 0 )
	{
		
		if( it == std::end( store ) )
			break;

		const auto tv = it->first;
		const auto tw = it->second;
		++it;
		if( w > tw )
		{
			w -= tw;
			ans.emplace_back( tw * tv );
		}
		else
		{
			ans.emplace_back( w * tv);
			w = 0;
		}
	}

	
	std::cout << std::fixed << std::setprecision( 16 );


	//std::cout << ans << "\n";

	std::sort( std::begin( ans ), std::end( ans ) );

	std::cout
		<< std::accumulate( std::begin( ans ), std::end( ans ), flt64{} )
		<< "\n";


	return 0;
}


Measured memory_bytes: 12572
#include <bits/stdc++.h>
#include <cmath>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

//bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


int main() {

    cpp_int  a, b;

    cin >> a >> b;

    cout << (a - b) << endl;

}



Measured memory_bytes: 3404
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  int k,a,b;
  cin >> k >> a >> b;
  for(int i=a;i<=b;i++){
    if(i%k == 0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3636
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    N,C = map(int,input().split())
    xv = [tuple(map(int,input().split())) for i in range(N)]
    r1,r2,l1,l2= [0]*(N+1),[0]*(N+1),[0]*(N+1),[0]*(N+1)
    ans = 0
    dis = 0
    for i in range(N):
        r1[i+1] = r1[i]+xv[i][1]-(xv[i][0]-dis)
        r2[i+1] = r2[i]+xv[i][1]-2*(xv[i][0]-dis)
        dis = xv[i][0]
    dis = C
    for i in reversed(range(N)):
        l1[N-i]=l1[N-i-1]+xv[i][1]-(dis-xv[i][0])
        l2[N-i]=l2[N-i-1]+xv[i][1]-2*(dis-xv[i][0])
        dis = xv[i][0]
    for i in range(N):
        l1[i+1] = max(l1[i+1],l1[i])
        r1[i+1] = max(r1[i+1],r1[i])
    for i in range(N+1):
        subans = max(r2[i]+l1[N-i],l2[i]+r1[N-i])
        ans = max(ans,subans)
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 37272
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14
using int64 = long long;

signed main(){
	int n, x;
	cin >> n >> x;

	if(x > n - x)
		x = n - x;

    set<int> ret;
	for(int i = 1; i * i <= x; i++)
		if(x % i == 0){
			ret.insert(i);
			ret.insert(x / i);
		}


	int sa;
	for(auto itr = ret.rbegin(); itr != ret.rend(); itr++){
		if(n % *itr == 0){
			sa = *itr;
			break;
		}
	}
	cout << n + n - sa + n - sa - sa << endl;
}


Measured memory_bytes: 256
#include <cstdio>

int main(void){
	int X,N;
	scanf("%d %d",&X,&N);
	bool P[102]={0};
	for(int i=0;i<N;i++){
		int p;
		scanf("%d",&p);
		P[p]=true;
	}
	if(P[X]){
		for(int i=1;i<=100;i++){
			if(X-i>=0&&!P[X-i]){
				printf("%d\n",X-i);
				break;
			}
			if(X+i<=101&&!P[X+i]){
				printf("%d\n",X+i);
				break;
			}
		}
	}else printf("%d\n",X);
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

ll f(ll nn){
    ll ans=1;
    rep(i,nn)ans*=2;
    return ans;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    bool ok=0;
    for(ll i=0;i<=k;i++){
        rep(j,k+1){
            rep(kk,k+1){
                if(i+j+kk>k)continue;
                ll aa=a*f(i);
                ll bb=b*f(j);
                ll cc=c*f(kk);
                if(aa<bb&&bb<cc)ok=1;
            }
        }
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

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

#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()

const int NAX = 2e5 + 5, MOD = 1000000007;

int n;
ll a[NAX], cache[NAX][4];
bool vis[NAX][4];

class Solution
{
private:
    ll dp(int idx, int have)
    {
        if (idx > n)
        {
            if (have <= 1)
                return 0;
            return -1e18;
        }
        auto &ret = cache[idx][have];
        if (vis[idx][have])
            return ret;
        vis[idx][have] = true;
        if (!have)
            ret = a[idx] + dp(idx + 2, have);
        else
            ret = max(a[idx] + dp(idx + 2, have), dp(idx + 1, have - 1));
        return ret;
    }

public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        cin >> n;
        for (size_t i = 0; i < n; i++)
            cin >> a[i + 1];
        ll ans = 0;
        if (n % 2)
            ans = max(dp(1, 2), dp(2, 1));
        else
            ans = max(dp(1, 1), dp(2, 0));
        cout << ans << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef LOCAL
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


Measured memory_bytes: 20060
#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>;
#define vi vector<int>;
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false);
#define FIX(a) cout << fixed << setprecision(a)
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power(T a, T b)
{return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always

int main() {
    ios
    
    int a, b; cin >> a >> b;
    FIX(8);
    cout << 4.0 / 3 * M_PI * b * b * b << endl;
}

/*
 x方向に回転
 円錐ができる
 
 底辺は半径bの円
 
 a < bより、
 y方向に回転 -> 半径bの球
 
 
 */



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

int mod = 1'000'000'007;

int main(){
    long long n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> num(2001, 0);
    for (int i = 0; i < n; i++) num[a[i]]++;
    for (int i = 0; i < 2000; i++) num[i + 1] += num[i];
    long long ans = 0;
    for (int i = 0; i < n; i++){
        ans += (long long)num[a[i] - 1] * ((k * (k + 1) / 2) % mod) % mod;
        ans %= mod;
    }
    for (int i = 1; i < n; i++){
        for (int j = 0; j < i; j++){
            if (a[j] < a[i]){
                ans += mod - k;
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
	int N,M;
	cin >> N >> M;
	vector<P> item(N);
	rep(i,N){ cin >> item[i].first >> item[i].second; }
	sort(item.begin(), item.end());

	ll ans = 0;
	int i=0;
	while(M>0){
		ll num = min(item[i].second, M);
		ans += item[i].first * num;
		M -= num;
		i++;
	}

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

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

int main()
{
  int N;
  cin >> N;
  vector<int> B(N - 1);
  auto * const b = &B[0];
  for (int i = 0; i < N - 1; ++i)
    cin >> b[i];
  vector<int> A(N);
  auto * const a = &A[0];
  a[0] = b[0];
  a[N - 1] = b[N - 2];
  for (int i = 1; i < N - 1; ++i)
    a[i] = (b[i - 1] < b[i] ? b[i - 1] : b[i]);
  int sum = 0;
  for (int i = 0; i < N; ++i)
    sum += a[i];
  cout << sum;
  return 0;
}


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

int N, M, C, ans = 0, tmp =0;
int main(){
    string s;
    cin >> s;


    for(int i = 0; s[i] != '\0'; i++) {
	
	if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
	    tmp++;
	}
	else{
	    tmp = 0;
	}

	ans = max(ans, tmp);
    	
    }

    cout << ans << endl; 
	      
}



Measured memory_bytes: 256
X,K,D = map(int,input().split())
A = abs(X)
ans = 0
if A >= D*K:
    print( A - (D * K))
else :
    e = A//D
    K -= e
    A %= D
    if K%2 == 0:
        print(A)
    else:
        print(D-A)

Measured memory_bytes: 9184
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.La;
		var a=sc.La;
		Array.Sort(a);
		long p=0;
		var ra=new long[s[0]];
		for(int i = 0;i<=s[0]-s[3];i++) {
			p+=a[i];
			ra[i]=a[i];
			if(i!=0){ra[i]+=ra[i-1];}
		}
		int ans=0,r=(int)(s[0]-s[3]);
		long po=(s[2]-s[3]);
		if(s[2]<s[3]){
			for(int i = 0;i<s[0];i++) {
				if(a[i]+s[1]<a[s[0]-s[3]]){ans--;}
			}
			Console.WriteLine("{0}",s[0]+ans);
			return;
		}
		for(int i = 0;i<s[0];i++) {
			long c=a[i]+s[1];
			if(a[i]+s[1]<a[s[0]-s[3]]){
				ans--;
				continue;
			}
			int lb=0,ub=r,mid=0;
			while(ub-lb>1){
				mid=(ub+lb)/2;
				if(c-a[mid]<s[1]){ub=mid;}
				else{lb=mid;}
			}
			if(s[1]*po<=lb*s[1]+c*(r-lb)-(ra[r]-ra[lb])){}
			else{ans--;}
		}
		Console.WriteLine("{0}",s[0]+ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 21856
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define IO() (void)freopen("in.in", "rt", stdin),freopen("out.out", "wt", stdout)
#define FastIO() ios::sync_with_stdio(false);
#define debug(x) cout << __LINE__ << ": " << #x << " = " << (x) << endl

typedef long long ll;
const ll MOD=1e9+7;
const int N = 1e7+9, M = 1e5+9, OO = 0x3f3f3f3f;
const double EPS = 1e-10;

inline int readi(){int n;scanf("%d", &n);return n;}
inline ll readll(){ll n;scanf("%I64d", &n);return n;}
inline char readc(){char c;scanf("%c ", &c);return c;}
inline double readd(){double n;scanf("%lf", &n);return n;}
inline bool dCMP(const long double& a, const long double& b){return fabsl(a-b)<EPS;}
int arr[N];
int main()
{
	#ifdef _LOCAL_DEFINE
	IO();
	#endif
	int n = readi(),l = readi(),mn = OO;
	ll sum=0;
	for(int i=0;i<n;++i)
	{
		int x = l+i;
		sum+=x;
		mn = (abs(mn)>abs(x))?x:mn;

	}
	printf("%lld\n",sum-mn);
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> a(2, vector<int>(n));
  rep(i, 2) rep(j, n)
    cin >> a[i][j];
  vector<vector<int>> dp(3, vector<int>(n+1));
  for (int i = 1; i <= 2; i++) for (int j = 1; j <= n; j++)
    dp[i][j] = a[i-1][j-1]+max(dp[i-1][j], dp[i][j-1]);
  cout << dp[2][n] << endl;
  return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>


/* ---------- Namespace ---------- */

using namespace std;


/* ---------- Type Abbreviation ---------- */

template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

using ll = long long;
using PL = P<ll, ll>;
using PS = P<string, ll>;

using VI = V<int>;
using VVI = V<VI>;
using VL = V<ll>;
using VVL = V<VL>;
using VS = V<string>;
using VB = V<bool>;
using VVB = V<VB>;
using VPL = V<PL>;
using VPS = V<PS>;

#define fst first
#define snd second


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)


/* ---------- container ---------- */

#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define GSORT(c) sort(ALL(c), greater<decltype((c).front())>())
#define SZ(x) (LL((x).size()))


/* ---------- repetition ---------- */

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)

#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// Usual REP runs from 0 to n-1 (R: n to 0)
// Natural REP runs from 1 to n (R: n to 1)


/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = 3.14159265358979;
// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};


/* ---------- Short Functions ---------- */

template <typename T>
T square(T a) {
    return a * a;
}


/* ---------- Debug ---------- */
#define GET_VAR_NAME(variable) #variable

#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;
#define testP(p) cout << GET_VAR_NAME(p) << " = (" << (p).fst << ", " << (p).snd << ")" << endl;


/* ^^^^^^^^^^^^^^^ Settting Part ^^^^^^^^^^^^^^^ */

/* ---------- Variances ---------- */


/* ---------- Functions ---------- */


/* ---------- Main Function ---------- */

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

    string S;
    cin >> S;

    const string way = "WESN";
    VB moved(4, false);
    REP(i, SZ(S)) {
        REP(j, 4) {
            if (S[i] == way[j]) {
                moved[j] = true;
            }
        }
    }

    if (moved[0] == moved[1] && moved[2] == moved[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
  int N, K; cin >> N >> K;
  double ans=0.0;
  for (int i=1; i<=N; i++) {
    double prob=1.0/N;
    int num=i;
    while(num<K) {
      num*=2;
      prob/=2.0;
    }
    ans += prob;
   }
  std::cout<<std::fixed<<std::setprecision(15);
  cout << ans << "\n";
}

Measured memory_bytes: 256
import std.stdio,
       std.string,
       std.conv,
       std.algorithm;

long abs(long n) {
  if (n < 0) {
    return -n;
  }
  return n;
}

void main() {
  int N = readln.chomp.to!(int);
  long[] A = readln.chomp.split.to!(long[]);

  if (N == 2) {
    writeln(abs(A[1]) * 2);
    writeln(abs(A[0]) * 2);
    return;
  }

  long ans;
  long a;
  for (int i = 1; i < N; i++) {
    ans += abs(a - A[i]);
    a = A[i];
  }
  ans += abs(a);
  writeln(ans);

  for (int i = 1; i < N - 1; i++) {
    // ここで前との差分をとって表示したい
    a = 0;
    if (i - 2 >= 0) {
      a = A[i - 2];
    }
    ans -= abs(a - A[i]) + abs(A[i] - A[i + 1]);
    ans += abs(a - A[i - 1]) + abs(A[i - 1] - A[i + 1]);
    writeln(ans);
  }

  ans -= abs(A[N - 3] - A[N - 1]) + abs(A[N - 1]);
  ans += abs(A[N - 3] - A[N - 2]) + abs(A[N - 2]);
  writeln(ans);
}


Measured memory_bytes: 5240
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))


n,m = inpl()
xy = [0] * m
ball = [1] * n
check = [False] * n
check[0] = True
fl = True
res = 0
for i in range(m):
    x,y = inpl()
    ball[x-1] -= 1
    ball[y-1] += 1
    if check[x-1] == True:
        check[y-1] = True
    if ball[x-1] == 0 and check[x-1]:
        check[x-1] = False
print(check.count(True))

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

ll m = 2000000;

ll h1(ll k){
    return k % m;
}

ll h2(ll k){
    return 1 + k % (m-1);
}

ll h(ll k, ll i){
    return (h1(k) + i * h2(k)) % m;
}

void insertion(vector<ll> &T, ll k){
    ll i = 0;
    while(true){
        ll j = h(k, i);
        if(T[j] == -1){
            T[j] = k;
            break;
        } else {
            i++;
        }
    }
}

bool search(vector<ll> &T, ll k){
    ll i = 0;
    while(true){
        ll j = h(k, i);
        if(T[j] == k){
            return true;
        } else if (T[j] == -1 || i >= m){
            return false;
        } else {
            i++;
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<ll> V(m,-1);

    rep(i, n){
        string s; cin >> s;
        if (s == "insert"){
            string I; cin >> I;
            ll c = 0;
            rep(j, I.size()){
                char cc = I[j];
                int ii;
                if(cc == 'A'){
                    ii = 1;
                } else if (cc == 'C'){
                    ii = 2;
                } else if (cc == 'G'){
                    ii = 3;
                } else {
                    ii = 4;
                }
                c += ii * pow(10, j);
            }
            insertion(V, c);
        } else {
            string F; cin >> F;
            ll c = 0;
            rep(j, F.size()){
                char cc = F[j];
                int ii;
                if(cc == 'A'){
                    ii = 1;
                } else if (cc == 'C'){
                    ii = 2;
                } else if (cc == 'G'){
                    ii = 3;
                } else {
                    ii = 4;
                }
                c += ii * pow(10, j);
            }
            //文字列を数値に変換
            if (search(V, c)){
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
}


Measured memory_bytes: 18428
//sum of gcc of Tuples
//最大公約数の合計を求めよ
#include<iostream>
using namespace std;
//3重ループを使わざるを得ないか

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

int gcd3(int a,int b,int c){
    int x=0;
  x=gcd(a,b);
  return gcd(x,c);
}

int main(){
  int sum=0;
  int k;
  cin >> k;
  for(int a=1;a<=k;a++){
    for(int b=1;b<=k;b++){
      for(int c=1;c<=k;c++){
        sum+=gcd3(a,b,c);
      }
    }
  }

  cout<<sum;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 200200;
const long double PI = acos(-1);

  

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll x, y, ans = oo;

    cin >> x >> y;

    for (ll i=1; i<x; i++){
        ll ans1, ans2;
        ans1 = max(i*y, ((x-i-1)/2 + 1)*y) - min(i*y, ((x-i)/2)*y);
        ans2 = max(i*y, (x-i)*((y-1)/2 + 1)) - min(i*y, (x-i)*(y/2));
        ans = min(ans, min(ans1, ans2));
    }

    for (ll i=1; i<y; i++){
        ll ans1, ans2;
        ans1 = max(i*x, ((y-i-1)/2 + 1)*x) - min(i*x, ((y-i)/2)*x);
        ans2 = max(i*x, (y-i)*((x-1)/2 + 1)) - min(i*x, (y-i)*(x/2));
        ans = min(ans, min(ans1, ans2));
    }


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

Measured memory_bytes: 3660
# coding: utf-8

import sys
from collections import deque

n, q = map(int, input().split())
total_time = 0
tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))

for task in tasks:
    task[1] = int(task[1])

try:
    while True:
        t = tasks.popleft()
        if t[1] - q <= 0:
            total_time += t[1]
            print(t[0], total_time)
        else:
            t[1] = t[1] - q
            total_time += q
            tasks.append(t)
except Exception:
    pass

Measured memory_bytes: 23164
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        String s = stdIn.next();
        char c[] = s.toCharArray();
        
        for(int i = 0; i < s.length(); i++){
            if(i % 2 == 0){
                if(i < s.length() - 2){
                    System.out.print(c[i]);
                }else{
                    System.out.println(c[i]);
                }
            }
        }
    }
}


Measured memory_bytes: 33288
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
string zero = "999999999999999999";
int main(){
    string s = "";
    for(ll i = 1;;i++){
        char ret;
        if(i != 1){
            if(s[0] != '1'){
                string t = (char)(s[0] - 1) + s.substr(1) + '0';
                cout << "? " << t << endl << flush;
                cin >> ret;
                if(ret == 'N'){
                    cout << "! " << s << endl;
                    return 0;
                }
            }else{
                string t = s + '0';
                t = '9' + t.substr(2);
                cout << "? " << t << endl << flush;
                cin >> ret;
                if(ret == 'Y'){
                    cout << "! " << s << endl;
                    return 0;
                }
            }
            cout << "? " << s + '0' + zero.substr(0, 18 - s.size() - 1) << endl << flush;
            cin >> ret;
            if(ret == 'Y'){
                s = s + '0';
                continue;
            }
        }
        ll ng = 0, ok = 9;
        while(ok - ng > 1){
            ll mid = (ok + ng) / 2;
            cout << "? " << s + (char)(mid + '0') + zero.substr(0, 18 - s.size() - 1) << endl << flush;
            cin >> ret;
            if(ret == 'Y') ok = mid;
            else ng = mid;
        }
        s = s + (char)(ok + '0');
    }
}

Measured memory_bytes: 596
/*input
20
>>>><>>><>><>>><<>>
*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7,N = 3005;
int dp[N][N]; // 
int pf[N];
int main()
{
	int n;cin>>n;
	string s;cin>>s;

	dp[1][1]=1;
	for(int last=1;last<=n;last++) pf[last]=1;
	for(int len=2;len<=n;len++)
	{
		for(int last=1;last<=len;last++)
		{

			if(s[len-2]=='<') dp[len][last]=pf[last-1];
			else dp[len][last]=((pf[n]-pf[last-1])%mod+mod)%mod;

			// for(int sl=1;sl<=len;sl++)
			// {
			// 	int cpy = sl;
			// 	if(cpy>=last) cpy++;
			// 	if(s[len-2]=='<' && cpy<last) dp[len][last]+=dp[len-1][sl];
			// 	if(s[len-2]=='>' && cpy>last) dp[len][last]+=dp[len-1][sl];
			// }
		}
		for(int last=1;last<=n;last++) pf[last]=(pf[last-1]+dp[len][last])%mod;

	}

	int ans = 0;
	for(int last=1;last<=n;last++) ans+=dp[n][last],ans%=mod;
	cout<<ans<<"\n";

	return 0;
}


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


int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;

    int num = s.size();
    rep(i, num) {
        int rr = 'z'-s[i]+1;
        rr %= 26;
        if(k >= rr) {
            s[i] = 'a';
            k -= rr;
        }
    }

    k %= 26;

    s[num-1] += k;

    cout << s << endl;
}

Measured memory_bytes: 3752
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main() {

	int a, b, h;
	cin >> a >> b >> h;
	cout <<(a+b)*h /2<< endl;

	return 0;
}

Measured memory_bytes: 256
N=int(input())
Days=[]
for _ in range(N):
    a,b,c=list(map(int,input().strip().split(" ")))
    Days+=[(a,b,c)]

dp=[[0]*3 for i in range(N)]

for i in range(N):
    if i==0:
        for j in range(3):
            dp[0][j]=Days[0][j]
    else:
        for j in range(3):
            for k in range(3):
                if k!=j:
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+Days[i][j])
print(max(dp[-1]))
    

Measured memory_bytes: 75224
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 2019
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

l,r =mii()

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod
ans = 10**100
for i in range(l,r):
    for j in range(i+1,r+1):
        ans = min(ans,mul(i,j))
        if ans ==0:
            print(0)
            exit()
print(ans)

Measured memory_bytes: 64236
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
#define base 1000000005
long long node[maxn*10],ans[10];
int h,w,n,x,y,nodecnt;
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	while(n--)
	{
		scanf("%d%d",&x,&y);
		for(int i=0;i<3;++i)
			for(int j=0;j<3;++j)
				if(1<=x-i&&x-i<=h-2&&1<=y-j&&y-j<=w-2)
					node[++nodecnt]=1ll*base*(x-i)+(y-j);
	}
	ans[0]=1ll*(h-2)*(w-2);
	sort(node+1,node+nodecnt+1);
	for(int i=1,cnt=1;i<=nodecnt;++i)
	{
		if(node[i]==node[i+1]) ++cnt;
		else ++ans[cnt],cnt=1,--ans[0];
	}
	for(int i=0;i<10;++i) printf("%lld\n",ans[i]);
	return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef long long ll;

void solve() {
  int A, B;
  cin >> A >> B;
  if (A != 1 && B != 1) {
    cout << 1 << endl;
  } else if (A != 2 && B != 2) {
    cout << 2 << endl;
  } else if (A != 3 && B != 3) {
    cout << 3 << endl;
  }
}

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

  solve();

  return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll MOD = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll a,b,h,m; cin>>a>>b>>h>>m;
    double ans=sqrt(a*a+b*b-2*a*b*cos((h*60-11*m)*M_PI/360));
    printf("%.10lf\n",ans);
    return 0;
}


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

const int N = 2e5+5;
vector <ll> graph[N];
ll alt1[N], alt2[N];



void dfs1(ll u, ll p){
    for(auto x1: graph[u]){
        if(x1 == p) continue;
        alt1[x1] = alt1[u] + 1;
        dfs1(x1, u);
    }
}


void dfs2(ll u, ll p){
    for(auto x1: graph[u]){
        if(x1 == p) continue;
        alt2[x1] = alt2[u] + 1;
        dfs2(x1, u);
    }
}




int main()
{
	ll n,x,y;
	cin>>n>>x>>y;
	//x-->tanshik intial position
	//y-->aloki  intial position
	for(ll i=0;i<n-1;i++)
	 { ll a,b;
	   cin>>a>>b;
	 	graph[a].push_back(b);
	 	graph[b].push_back(a);
	 }
	 
	   alt1[x] = 0;
    alt2[y] = 0;
    dfs1(x, -1);
    dfs2(y, -1);
    ll ans = 0;

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

        if(alt1[i] < alt2[i]) ans = max(ans, alt2[i] - 1);
    }

    cout << ans << endl;
 	
 }

Measured memory_bytes: 14464
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

    vector<int> H(N), A(M), B(M);
    for (int i=0; i<N; i++) {
        cin >> H.at(i);
    }
    for (int i=0; i<M; i++) {
        cin >> A.at(i) >> B.at(i);
    }
    for (int i=0; i<M; i++) {
        A.at(i)--;
        B.at(i)--;
    }

    vector<int> max_height(N, 0);
    for (int i=0; i<M; i++) {
        max_height.at(A.at(i)) = max(max_height.at(A.at(i)), H.at(B.at(i)));
        max_height.at(B.at(i)) = max(max_height.at(B.at(i)), H.at(A.at(i)));
    }

    int res = 0;
    for (int i=0; i<N; i++) {
        if (H.at(i) > max_height.at(i)) {
            res += 1;
        }
    }
    
    cout << res << endl;
}


Measured memory_bytes: 4412
#include<iostream>
#include<algorithm>
#include<complex>
#include<iomanip>
using namespace std;
int main(){
	double a,b,c,d,e,f,x,y;
	int t=85000;
	for(int i=t;i;i--){
		for(int j=i;j;j--){
			if(i+j==2)a=0.0;
		}
	}
	while(cin>>a){cin>>b>>c>>d>>e>>f;
		x=(c*e-b*f)/(a*e-b*d),y=(c*d-a*f)/(b*d-a*e);
		if(x==-0)x=0;if(y==-0)y=0;
		cout<<fixed<<setprecision(3)<<x<<" ";
		cout<<fixed<<setprecision(3)<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
#define MOD (ll)(1e9+7)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b; cin>>a>>b;
	if(a/2019<b/2019)
	{
		cout<<"0\n";
	}
	else
	{
		int mn=INT_MAX;
		a%=2019; b%=2019;
		For(i,a,b-1) For(j,i+1,b)
		{
			mn=min(mn,(i*j)%2019);
		}
		cout<<mn<<"\n";
	}
	return 0;
}









Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,N;
  cin >> A >> B >> N;
  if(B-A+1 >= 2*N){
    for(int i= 0; i < N ; i++){
      cout << A+i <<endl;;
    }
    for(int i= N-1 ; i>-1 ; i--){
      cout << B-i << endl;
    }
  }
    else{
      for(int i = A; i <B+1 ; i++){
        cout << i << endl;
      }
    }

}

Measured memory_bytes: 256
N = int(input())
P = list(map(float, input().strip().split()))

dp = [[0 for i in range(N+1)] for i in range(N+1)]
dp[0][0] = 1
for i in range(1, N+1):
    dp[i][0] = (1-P[i-1])*dp[i-1][0]

for i in range(1, N+1):
    for j in range(1, N+1):
        dp[i][j] = P[i-1]*dp[i-1][j-1] + (1-P[i-1])*dp[i-1][j] 

print(sum(dp[N][N//2+1:]))

Measured memory_bytes: 224152