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

typedef pair<int64_t, int64_t> P;
const int64_t INF = 1e18;

vector<int64_t> dijkstra(int N, int s, vector<P> edges[]){
    vector<int64_t> dist(N, INF);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, s});
    while(que.size()){
        auto p = que.top(); que.pop();
        int i = p.second;
        int64_t d = p.first;
        if(d > dist[i]) continue;
        for(auto& e : edges[i]){
            int j = e.first;
            int64_t d2 = d + e.second;
            if(d2 < dist[j]){
                dist[j] = d2;
                que.push({d2, j});
            }
        }
    }
    return dist;
}

int main(){
    int X, Y, Z, N, M, S, T;
    cin >> X >> Y >> Z >> N >> M >> S >> T;
    S--; T--;
    T += N;
    int sand_start = N+M;
    int katsu_start = sand_start + X;
    int curry_start = katsu_start + Y;
    int V = curry_start + Z;

    static vector<P> edges[500000];
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        a += sand_start;
        b += katsu_start;
        edges[i].emplace_back(a, 1);
        edges[i].emplace_back(b, 1);
        edges[a].emplace_back(i, 0);
        edges[b].emplace_back(i, 0);
    }
    for(int i=N; i<N+M; i++){
        int c, d;
        cin >> c >> d;
        c--; d--;
        c += katsu_start;
        d += curry_start;
        edges[i].emplace_back(c, 1);
        edges[i].emplace_back(d, 1);
        edges[c].emplace_back(i, 0);
        edges[d].emplace_back(i, 0);
    }
    auto dist = dijkstra(V, S, edges);
    int64_t ans = dist[T];
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}



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

int main() {
	int n, j, a[500], b[500], c[500];
	std::cin >> n;
	for (int i = 0;i < n-1;i++) {
		std::cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 0;i < n - 2;i++) {
		int nSum = 0;
		nSum += b[i];
		nSum += a[i];
		for (j = i+1;j < n-1;j++) {
			if (nSum >= b[j]) {
				int d = b[j];
				while (d< nSum) {
					d += c[j];
				}
				nSum = d;
			}
			else if (nSum < b[j]) {
				nSum = b[j];
			}
			nSum += a[j];
		}
		std::cout << nSum << std::endl;
		if (i == n - 3) {
			std::cout << a[i + 1] + b[i + 1] << std::endl;
		}
	}
	std::cout << 0 << std::endl;
	return 0;
}
	


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<math.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
int main(void){
    // Here your code !

double a,b,c,d,e,f;
double x,y;
while(cin>>a>>b>>c>>d>>e>>f){
x=(double)((e*c-b*f)/(e*a-b*d));
y=(double)((d*c-a*f)/(d*b-a*e)); 

if(x==0)x=0;
if(y==0)y=0;
printf("%.3f %.3f\n",x,y);
}



return 0;
}

Measured memory_bytes: 1236
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc  = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int h = Integer.parseInt(sc.next());
		
		System.out.println((a + b) * h / 2);
	}
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            input = Console.ReadLine().Split(' ');
            bool[] a = new bool[n];
            for (int i = 0; i < n; i++)
            {
                if (input[i] == "1") // 奇数はtrue
                {
                    a[i] = true;
                }else
                {
                    a[i] = false;
                }

            }

            bool[] box = new bool[n];
            List<int>ans = new List<int>();
            for (int i = n; i > n / 2; i--)
            {
                //後ろ半分は自身のみで決まる
                box[i-1] = a[i-1];
                if (box[i - 1])
                {
                    ans.Add(i);
                }
            }
            for (int i = n / 2; i > 0; i--)
            {
                bool sum = false;
                for (int j = i * 2; j <= n; j = j + i)
                {
                    sum = sum ^ box[j - 1];
                }
                box[i-1] = sum ^ a[i-1];
                if (box[i - 1])
                {
                    ans.Add(i);
                }
            }

            Console.WriteLine(ans.Count);
            if (ans.Count != 0)
            {
                Console.WriteLine(string.Join(" ", ans));
            }
            
        }
    }
}

Measured memory_bytes: 34264
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    
      Scanner sc = new Scanner(System.in);
      
      int W = sc.nextInt();
      
      int H = sc.nextInt();
      
      int x = sc.nextInt();
      
      int y = sc.nextInt();
      
      int r = sc.nextInt();
      
      if(( x - r ) < 0 || ( x + r ) > W){
          System.out.println("No");
      }else if(( y - r ) < 0 || ( y + r ) > H){
          System.out.println("No");
      }else{
    	  System.out.println("Yes");
      }
 

  }
}

Measured memory_bytes: 26356
n = int(input())
l = sorted([sorted(list(input())) for i in range(n)])
ans = []
las = l[0]
count = 1
for i in range(1,n):
    if las == l[i]:
        count += 1
    else:
        ans.append(count)
        count = 1
        las = l[i]
if sum(ans) != n:
    ans.append(count)
#print(ans)
a = 0
for i in range(len(ans)):
    if ans[i] != 1:
        for j in range(1,ans[i]):    
            a += j
print(a)

Measured memory_bytes: 103000
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll arr[5];
  for(int i=0;i<5;i++){
    cin>>arr[i];
  }
  for(int i=0;i<5;i++){
    if(arr[i]==0){
      cout<<i+1;
      break;
    }
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int N=110;
int a[N][N],vis[N],vv[N];

int main(){
	int n,m;scanf("%d%d",&n,&m);
	char ch;
	for(int i=1;i<=n;++i)
	 for(int j=1;j<=m;++j){
	 	cin>>ch;
	 	if(ch=='#') a[i][j]=1;
	 }
	for(int i=1;i<=n;++i){
		int flag=1;
		for(int j=1;j<=m;++j){
			if(a[i][j]){
				flag=0;break;
			}
		}
		if(flag) vis[i]=1;
	}
	for(int i=1;i<=m;++i){
		int flag=1;	
		for(int j=1;j<=n;++j)
			if(a[j][i]){
				flag=0;break;
			}	
		if(flag) vv[i]=1;
	}
	int ff=1,f=1;
	for(int i=1;i<=n;++i) if(!vis[i]) ff=0;
	for(int i=1;i<=m;++i) if(!vv[i]) f=0;
	if(ff&&f) return 0;
	for(int i=1;i<=n;++i){
		if(vis[i]) continue;
		for(int j=1;j<=m;++j){
			if(!vv[j]) {
				if(a[i][j]) cout<<"#";
				else cout<<".";
			}
		}
		cout<<endl;
	}
	return 0;
}

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

typedef int i32;
typedef long long i64;
typedef unsigned int u32;
typedef unsigned long long u64;

#define loop(i,n) for(i64 i = 0; i < n; ++i)
#define pi  pair<int,int>
#define ti  tuple<int,int,int>
#define mt  make_tuple
#define mk  make_pair
#define vi  vector<int>
#define vll vector<i64>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";

i32 h,w,n;
int main() 
{ 
    fastInOut
    cin>>h>>w;
        
    if(h>w)
       for(int i=0;i<h;i++)
                cout<<w;
    else
       for(int i=0;i<w;i++)
               cout<<h;   
  
   return 0; 
} 

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)

N, M = map(int, input().split())
XYZ = []
for _ in range(M):
    XYZ.append(tuple(map(int, input().split())))

G = [[] for _ in range(N + 1)]
for el in XYZ:
    x, y, z = el
    G[x].append(y)
    G[y].append(x)

seen=[False] * (N + 1)
def dfs(parent):
    seen[parent] = True
    for child in G[parent]:
        if seen[child] == False:
            dfs(child)

cnt = 0
for start in range(1, N + 1):
    if seen[start] == False:
        dfs(start)
        cnt += 1
print(cnt)


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
int32_t main(){
    
    int a,b;
  	cin >> a >> b;
  	if((1 <= a && a <= 9) && (1 <= b && b <= 9) ){
    	cout << a*b << endl;
    } else {
    	cout << -1 << endl;
    }
}



Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi;
typedef vector<double> vd;
 
double mypow(double b ,int e){
      if(e == 0) return 1;
      if(e%2==0)
            return mypow( b*b, e/2 );
      else
            return mypow( b*b, e/2 ) * b;
}
 
int main(){
 
 
      int N,M,L; cin >> N >> M >> L ;
      if(N==1){
            cout << 1.0 << endl;
            return 0;
      }
      vector<vd> prob(N,vd(M+1,0.0));
      vector<vd> dist(N,vd(M+1,0.0));
 
      vd p(N),t(N),v(N);
      for(int i=0; i<N; i++) cin >> p[i] >> t[i] >> v[i];
 
      // PRE PROCESS
      for(int i=0; i<N; i++){
            dist[i][0] = (double)L / v[i];
            for(int j=1; j<=M; j++){
                  dist[i][j] = dist[i][j-1] + t[i];
            }
      }
      for(int i=0; i<N; i++)
            prob[i][0] = mypow((100-p[i])/100,M);
      for(int i=0; i<N; i++){
            for(int j=1; j<=M; j++){
                  if(p[i] != 100)
                        prob[i][j] = (prob[i][j-1] * (p[i]/100)) / ((100-p[i])/100);
                  else
                        prob[i][j] = 1.0;
            }
      }
      double comb = 1;
      for(int j=1; j<=M; j++){
            comb = comb * (M - j + 1) / j; 
            for(int i=0; i<N; i++){
                  prob[i][j] *= comb;
            }
      }
       
      vector<vd> sum = prob;
      for(int i=0; i<N; i++){
            for(int j=M-1; j>=0; j--){
                  sum[i][j] += sum[i][j+1];
                  if(sum[i][j] > 1) sum[i][j] = 1;
            }
      }
 
      vector<vd> ans = prob;
      for(int i=0; i<N; i++){
            for(int j=0; j<=M; j++){
                  for(int k=0; k<N; k++){
                        if(i==k) continue;
                        int id = upper_bound(dist[k].begin(),dist[k].end(), dist[i][j]) - dist[k].begin();
                        if(id > M) ans[i][j] = 0.0;
                        else       ans[i][j] *= sum[k][id];
 
                  }
            }
      }
 
      for(int i=0; i<N; i++){
            double tmp = 0.0;
            if(p[i] == 100) tmp = ans[i][M];
            else
                  for(int j=0; j<=M; j++)
                        tmp += ans[i][j];
            if(tmp > 1) tmp = 0;
            printf("%.10f\n",tmp);
      }
                         
}

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

int main(){
    string s;
    int nc[26]={};
    
    while(getline(cin, s)){
        for(int i=0; i<s.size(); i++){
            if(('a'<=s[i])&&(s[i]<='z'))nc[s[i]-'a']++;
            if(('A'<=s[i])&&(s[i]<='Z'))nc[s[i]-'A']++;
        }
    }
    
    for(int i=0; i<26; i++){
        cout << (char)('a'+i) <<" : "<< nc[i]<< endl;
    }
    return 0;
    
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==v.size()?"":" ");
    return os;
}


signed main(){
    int n;cin>>n;
    ll a[n];
    rep(i,n){
        cin>>a[i];
    }
    if(n==2){
        cout<<max(a[0],a[1])<<endl;
        return 0;
    }

    sort(a,a+n);

    ll ans=a[n-1];
    int idx=n-1;
    for(int i=2;i<n;i++){
        if(i%2==0)idx--;
        ans+=a[idx];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5216
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author YahiaAshraf74
 */

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el  '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define sz(a) (int)(a).size()
const long long N = (int) 3e3 + 2, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;


class ICoins {
public:
    void init() {
    }

    void solve(istream &cin, ostream &cout) {
        init();
        int n;
        cin >> n;
        vector<double> heads(n+1);
        for (int i = 1; i <= n; i++) {
            cin >> heads[i];
        }
        vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0.0));
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++)
            dp[i][0] = dp[i - 1][0] * (1.0 - heads[i]);
        for (int j = 1; j <= n; j++)
            dp[0][j] = 0.0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                dp[i][j] = dp[i - 1][j - 1] * heads[i] + dp[i - 1][j] * (1.0 - heads[i]);
            }
        }
        double sum = 0.0;
        for (int heads = 0; heads <= n; heads++) {
            int tails = n - heads;
            if (heads > tails)
                sum += dp[n][heads];
        }
        cout << fixed << setprecision(10) << sum;
    }
};
int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	ICoins solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 70784
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N;
    string s;

    void input() {
        cin >> N;
        cin >> s;
    }

    int calc(string a, string b) {
        set<char> tapi(all(a));
        set<char> tapu(all(b));

        int ret = 0;
        for (char c = 'a'; c <= 'z'; ++c) {
            if (tapi.count(c) && tapu.count(c)) ret++;
        }

        return ret;
    }


    void solve() {
        input();
        int ans = 0;
        for (int i = 0; i < N; ++i) {
            string a = s.substr(0, i);
            string b = s.substr(i, N - i);
//            cout << a << b << endl;
            int tmp = calc(a,b);
            chmax(ans,tmp);
        }
        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


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

typedef long long ll;
typedef tuple<ll, int, int> tlii;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define all(obj) (obj).begin(), (obj).end()
#define pb push_back
#define str to_string
#define mkp make_pair
#define mkt make_tuple
#define print(out) cout << (out) << endl
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
void chmax(ll &a, ll b) { a = max(a, b); }
void chmin(ll &a, ll b) { a = min(a, b); }

int N;
string S;
unordered_set<string> aset;

bool calc(ll m) {
    string a;
    string b;
    aset.clear();
    rep(i, 0, N-m*2+1) {
        a = S.substr(i, m);
        if (aset.find(a) == aset.end()) {
            b = S.substr(i+m);
            if (b.find(a) != -1) return true;
            aset.insert(a);
        }
    }
    return false;
}

ll bisearch_max(ll mn, ll mx) {
    ll ok = mn;
    ll ng = mx;
    ll mid;
    while (ok+1 < ng) {
        mid = (ok+ng) / 2;
        if (calc(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}

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

    cin >> N;
    cin >> S;
    print(bisearch_max(0, N));
    return 0;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
    ll l, r, d, count=0;
    cin>>l>>r>>d;
    for(ll i=l; i<=r; i++)
    {
        if(i%d==0)
        count++;
    }
    cout<<count;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
}

Measured memory_bytes: 3592
def main():
    f = False
    x, y = map(int, input().split())
    for i in range(x+1):
        a, b = i, x-i
        a *= 2
        b *= 4
        if a + b == y:
            f = True
    if f:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

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

int main()
{
  int m,n;
  
  m=1;
  n=1;

  while(true){
    if(n==10){
      m=m+1;
      n=1;
    }
    if(m==10) break;
    
    cout << m << 'x' << n << "=" << m*n << endl;
    n++;

  }
  return 0;
}

Measured memory_bytes: 1116
import sys
from _collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def Bellmanford(n, edges, r):  # r: 始点
    d = [INF] * n
    d[r] = 0

    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n - 1 and v == n - 1:
                    return 'inf'

    return -d[n - 1]

def main():
    N, M = map(int, readline().split())
    edges = []
    for _ in range(M):
        u,v,c = map(int, readline().split())
        edges.append([u-1,v-1,-c])

    d = [INF]*N
    d[0] = 0
    for i in range(N-1):
        for j in range(M):
            u, v, c = edges[j]
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
    ans = d[N-1]

    negative_loop = [False]*N
    for i in range(N):
        for j in range(M):
            u, v, c = edges[j]
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                negative_loop[v] = True
            if negative_loop[u]==True:
                negative_loop[v]=True

    if negative_loop[N-1]==True:
        print('inf')
    else:
        print(-ans)




if __name__ == '__main__':
    main()

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

typedef long long ll;
const ll mod = 998244353;

#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define FOr(i, s, e) for (ll i = s; i >= e; i--)

#define PI acos(-1)
#define sz 100005

void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

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

// int arr[1000006];

void solve()
{
	ll a; cin >> a;

	ll ans = a + (a * a) + (a * a * a);
	cout << ans << '\n';
}

int main()
{
	fastio();

	int t = 1; //cin >> t;
	while (t--)
		solve();

	return 0;
}


Measured memory_bytes: 3636
X,Y = list(map(int,input().split()))

if X==Y:
    print(0)
if X<Y:
    if X<0 and Y>0:
        print(1+abs(Y+X))
    else:
        print(Y-X)

if X>Y:
    if X>=0 and Y<=0:
        print(1+abs(X+Y))
    elif X>0 and Y>0:
        print(2+X-Y)
    elif X<0 and Y<0:
        print(2+X-Y)
    else:
        print(X-Y)

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

using Edge = pair<long long, long long>;
using Graph = vector<vector<Edge> >;

long long n;
Graph G;

vector<long long> res(100000, -1);

void dfs(long long v, long long p, long long pc){
    long long color = 1;
    if(pc == color) color++;
    
    for(auto next : G[v]){
        if(next.first == p) continue;
        res[next.second] = color;
        dfs(next.first, v, color);
        color++;
        if(pc == color) color++;
    }
}

int main(){
    cin >> n;

    G.assign(n, vector<Edge>());

    for(long long i = 0; i < n-1; i++){
        long long a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(make_pair(b, i));
        G[b].push_back(make_pair(a, i));
    }

    long long maxv = 0;

    for(long long i = 0; i < n; i++) maxv = max(maxv, (long long)G[i].size());
    
    dfs(0, -1, -1);

    cout << maxv << endl;

    for(long long i = 0; i < n-1; i++) cout << res[i] << endl;
    
    return 0;
}

Measured memory_bytes: 12136
#import math
import collections
n, m = map(int, input().split( ))
lis = [[] for _ in range(n+1)]
for _ in range(m):
  a,b = map(int, input().split( ))
  lis[a].append(b)
  lis[b].append(a)
#print(lis)
ans = [0]*(n+1)
q = collections.deque()
q.append(1)
count = [0]*(n+1)
#1の時は動かない
count[1] = 1
while len(q) != 0:
  v = q.popleft()
#  print(lis[v], count)
  #まずは1につながっている部屋を探索その後順に探索
  for u in lis[v]:
    if count[u] == 0:
      count[u] = 1
      ans[u] = v
      q.append(u)
print('Yes')
for i in range(2,n+1):
  print(ans[i])

Measured memory_bytes: 34988
N=int(input())
l=[]
for i in range(N):
    SP=input().split()
    l.append([SP[0],int(SP[1]),i+1])
l.sort(key=lambda x: x[1],reverse=True)
l.sort(key=lambda x: x[0])
for i in range(len(l)):
    print(l[i][2])

Measured memory_bytes: 3064
<?php

$n = fgets(STDIN);
$m = array();

$count = 0;

while ($n > $count) {
    $m[] = trim(fgets(STDIN));
    $count++;
}

$max = -PHP_INT_MAX;
$tmpmin = $m[0];

for ($i = 1; $i < $n; $i++) {
    
    if($max < $m[$i] - $tmpmin){
        $max = $m[$i] - $tmpmin;
    }
    
    if($tmpmin >= $m[$i]){
        $tmpmin = $m[$i];
    }
}

print $max;
?>

Measured memory_bytes: 50704
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;

    input!{
        n: usize,
        a: [usize; n],
    }
    let mut b = a;
    b.sort_by(|a, b| b.cmp(a));
    let mut alice = 0;
    let mut bob = 0;
    for i in 0..n {
        if i%2 == 0 {
            alice = alice + b[i];
        } else {
            bob = bob + b[i];
        }
    }
    println!("{}", alice-bob);
}


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

using namespace std;

typedef vector<vector<char> > field;

int search(field &f, int x, int y)
{
    if(f[y][x]=='#') return 0;
    f[y][x] = '#';
    int res = 1;
    if(f[y][x-1]!='#') res += search(f, x-1, y);
    if(f[y][x+1]!='#') res += search(f, x+1, y);
    if(f[y-1][x]!='#') res += search(f, x, y-1);
    if(f[y+1][x]!='#') res += search(f, x, y+1);
    return res;
}

int main()
{
    int w, h;
    while(cin >> w >> h, w|h)
    {
        field f(h+2, vector<char>(w+2, '#'));
        int sx, sy;
        for(int y=0; y<=h+1; y++) f[y].assign(w+2, '#');
        for(int y=1; y<=h; y++)
        {
            string ln;
            cin >> ln;
            for(int i=0; i<w; i++)
            {
                f[y][i+1] = ln[i];
                int spos = ln.find('@');
                if(spos>=0)
                {
                    sy = y;
                    sx = spos + 1;
                }
            }
        }
        cout << search(f, sx, sy) << endl;
    }
}

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

int main() {
  int A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;
  int r = 10;
  if(A % 10 != 0){
    r = A % 10;
    A = (A / 10 + 1) * 10;
  }
  if(B % 10 != 0){
    if(r > B % 10) {
      r = B % 10;
    }
    B = (B / 10 + 1) * 10;
  }
  if(C % 10 != 0){
    if(r > C % 10) {
      r = C % 10;
    }
    C = (C / 10 + 1) * 10;
  }
  if(D % 10 != 0){
    if(r > D % 10) {
      r = D % 10;
    }
    D = (D / 10 + 1) * 10;
  }
  if(E % 10 != 0){
    if(r > E % 10) {
      r = E % 10;
    }
    E = (E / 10 + 1) * 10;
  }
  cout << A+B+C+D+E-10+r << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b,c,i,t=1;
	scanf("%d %d %d",&a,&b,&c);
	if(c<=a){
		printf("%d\n",c);
	}
	else if(a==b){
		if(c%a==0){
			printf("%d\n",c);
		}
		else {
			puts("-1");
		}
	}
    else if(c>a){
        i=a+b;
        while(c<10000000){
            if(i>60*t){
                c+=60;
                t++;
            }
            if(i<=c&&c<=i+a)
                break;
            i+=a+b;
        }
        if(c>=10000000)c=-1;
		printf("%d\n",c);
    }
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
//void chmin(int &a, int b) { if (a > b) a = b; }
//void chmax(int &a, int b) { if (a < b) a = b; }

const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll com(ll n, ll r){
    ll bunsi = 1,bunbo = 1;
    for (int i = 1; i <= r; ++i) {
        bunsi = bunsi*(n-i+1)%mod;
        bunbo = bunbo*i%mod;
    }
    return bunsi*modpow(bunbo,mod-2)%mod;
}

int main() {
    ll n,a,b,ans;
    cin >> n >> a >> b;
    ans = modpow(2,n);
    ans -= com(n,a);
    ans -= com(n,b);
    ans--;
    if(ans < 0) ans += mod;
    cout << (ans%mod+mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;


int main(void) {

  int n, m;
  while(cin >> n >> m){
    if( n == 0 ) break;

    vector< pair<int, int> > p(n);
    for(int i=0; i<n; i++) cin >> p[i].second >> p[i].first;
    sort(p.begin(), p.end());
    for(int i=n-1; i>=0; i--){
      if( p[i].second < m ){
        m -= p[i].second;
        p[i].second = 0;
      }else{
        p[i].second -= m;
        m = 0;
        break;
      }
    }
    int sum = 0;
    for(int i=0; i<n; i++) sum += p[i].first * p[i].second;
    cout << sum << endl;
  }

  return 0;
}

// EOF

Measured memory_bytes: 3056
import sys

# sys.stdin = open('c1.in')

n, k = map(int, input().split())

operations = []
for i in range(n):
    a, b = map(int, input().split())
    operations.append((a, b))
operations.sort()

s = 0
for a, b in operations:
    s += b
    if k <= s:
        print(a)
        break


Measured memory_bytes: 16968
//
// Created on 2020/09/18.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    string s;
    cin>>s;
    int k;
    cin>>k;
    vector<int>ans(110,0);
    ans[0] = s[0]-'0';
    for (int i = 1; i < 110; ++i) {
        if(ans[i-1] != 1) ans[i] = ans[i-1];
        else if(i < s.size()) ans[i] = s[i] -'0';
        else ans[i] = ans[i-1];
    }
    if(k <= 100){
        cout<<ans[k-1]<<endl;
    }else{
        cout<<ans[100]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
N = int(input())
TA = [list(map(int,input().split())) for _ in range(N)]
t = 1
a = 1
for i in range(N):
  x = max(-(-t // TA[i][0]),-(-a // TA[i][1]))
  t = TA[i][0] * x
  a = TA[i][1] * x
print(t + a)

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var ss = Console.ReadLine().Split();
            var a = new int[N];
            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse(ss[i]);
            }

            var b = new int[N];
            var M = 0;
            for (int i = N - 1; i >= 0; i--)
            {
                var multi = i + 1;

                var sum = 0;
                for (int j = 2; multi * j <= N; j++)
                {
                    sum += b[(multi * j) - 1];
                }

                if (sum % 2 == 0)
                {
                    if (a[i] == 0)
                    {
                        b[i] = 0;
                    }
                    else
                    {
                        b[i] = 1;
                        M++;
                    }
                }
                else
                {
                    if (a[i] == 0)
                    {
                        b[i] = 1;
                        M++;
                    }
                    else
                    {
                        b[i] = 0;
                    }
                }
            }

            Console.WriteLine(M);
            if (M == 0) return;

            var list = new List<int>();
            for (int i = 0; i < b.Length; i++)
            {
                if (b[i] == 1)
                {
                    list.Add(i + 1);
                }
            }

            Console.WriteLine(string.Join(" ", list));
        }
    }
}

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

const int MOD = 1e9 + 7;

ll C[1010][1010];

int main() {
    for (int x = 0; x < 1010; x++) {
        C[x][0] = 1;
        for (int y = 1; y <= x; y++)
            C[x][y] = (C[x - 1][y - 1] + C[x - 1][y]) % MOD;
    }
    
    int N, X;
    cin >> N >> X;
    vector<int> a(X + 1);
    while (N--) {
        int l; cin >> l;
        a[l]++;
    }
    vector<vector<ll>> dp(X + 2, vector<ll>(X + 1));
    dp[0][0] = 1;
    for (int l = X; l >= 0; l--) {
        vector<vector<ll>> _dp(X + 2, vector<ll>(X + 1));
        for (int k = X + 1; k >= 0; k--) rep(x, X + 1) rep(dk, X + 1) {
            int _k = k + dk, _x = x + dk * l;
            if (_k + _x - 1 > X) break;
            ll z = dp[k][x] * C[_k][dk] % MOD;
            _dp[_k][_x] = (_dp[_k][_x] + z) % MOD;
        }
        dp = _dp;
        rep(k, X + 2) rep(x, X + 1) {
            if (k + x - 1 > X) break;
            ll y = x - k * (l - 1);
            rep(t, a[l]) dp[k][x] = dp[k][x] * y % MOD;
        }
    }
    ll ans = 0;
    rep(k, X + 2) rep(x, X + 1) if (k + x - 1 == X) {
        // cout << k << ' ' << x << ' ' << dp[k][x] << endl;
        ll z = dp[k][x];
        if (k % 2 == 0) z *= -1; 
        ans = (ans + z) % MOD;
    }
    cout << (ans + MOD) % MOD << endl;
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mset(x, y) memset((x), (y), sizeof(x))
#define sz(x) ((int)(x).size())
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'
using namespace std;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

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

	ll n, i, ans = 0, sum = 0, sqsum = 0;
	cin >> n;
	vl a(n);
	rep(i, 0, n)
	{
		cin >> a[i];
		(sum += a[i]) %= mod;
		(sqsum += (a[i] * a[i]) % mod) %= mod;
	}
	cout << ((sum * sum % mod) - sqsum + mod) * modinv(2) % mod;
}

Measured memory_bytes: 4752
seiseki = []
seisekid = {1:"F",2:"D",3:"C",4:"B",5:"A"}
while True:
    x,y,z = input().split(" ")
    x = int(x)
    y = int(y)
    z = int(z)
    q = x + y + z
    i = x + y
    if q == -3:
        for t in range(len(seiseki)):
            r = t - 1
            print(seisekid[seiseki[t]])
        break
    elif x == -1:
        seiseki.append(1)
        continue
    elif y == -1:
        seiseki.append(1)
        continue
    elif i < 30:
        seiseki.append(1)
        continue
    elif i >= 30:
        if i >= 50:
            if i >= 65:
                if i >= 80:
                    seiseki.append(5)
                    continue
                else:
                    seiseki.append(4)
                    continue
            else:
                seiseki.append(3)
                continue
        elif z >= 50:
            seiseki.append(3)
            continue
        else:
            seiseki.append(2)
            continue
    else:
        seiseki.append(1)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;cin >> N;
vector<int> p(N);
vector<int> q(N);
for(int i=0 ; i < N; i++){
  cin >> p[i];
  q[i] = p[i];
}
sort(q.begin(),q.end());
int count = 0;
for(int i = 0; i <N; i++){
  if(p[i] != q[i]){
    count++;
  }
}
if(count == 0 || count == 2){
  cout << "YES" << endl;
}
else{
  cout << "NO" << endl;
}
}


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

int main(){
  int N;
  cin >> N;
  if ((N/1000 ==  N%1000/100 && N/1000 == N%100/10) || (N%1000/100 == N%100/10 && N%100/10 == N%10)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3636
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <cmath>         // sqrt
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b)
{
  // Eucledean algorithm
  while (a)
  {
    if (a < b)
    {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n)
{
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n)
{
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++)
  {
    if (n % i == 0)
    {
      divs.push_back(i);
      if (i != n / i)
      {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

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

int main()
{
  ll N, K;
  ll INF = 1000000000;
  // const long long INF = 1LL << 60;
  cin >> N >> K;
  vector<ll> h(N + K + 1);
  vector<ll> dp(N + K + 1, INF);
  rep(i, N)
  {
    cin >> h.at(i);
  }
  dp.at(0) = 0;
  rep(i, N)
  {
    rep2(j, 1, K + 1)
    {
      chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }

  cout << dp.at(N - 1) << endl;
  return 0;
}


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

int main(){
  int K, S;
  cin >> K >> S;
  int ans = 0;

  for(int i=0; i<=K; i++){
    for(int j=0; j<=K; j++){
      int z = S - i - j;
      if(z <= K and z>=0){
        ans++;
      }
    }
  }
  cout << ans++ <<endl;
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int Maxn = 100010;
int a[Maxn];
int n, m;
int main() {
	int i, j, k;
	scanf("%d%d", &n, &m);
	if(m == 1){
		if(n == 1) printf("1\n1\n1\n");
		else printf("%d\n%d\n%d %d\n", n, 2, 1, n-1);
		return 0;
	}
	int odd = 0;
	for(i = 1; i <= m; i++) scanf("%d", &a[i]), odd += a[i]&1;
	if(odd > 2){ printf("Impossible\n"); return 0; }
	for(i = 1; i <= m; i++) if(a[i]&1){ swap(a[1], a[i]); break; }
	for(i = 2; i <= m; i++) if(a[i]&1){ swap(a[m], a[i]); break; }
	for(i = 1; i <= m; i++) printf("%d%c", a[i], i==m?'\n':' ');
	if(a[1] > 1) printf("%d\n%d ", m, a[1]-1);
	else printf("%d\n", m-1);
	for(i = 2; i < m; i++) printf("%d ", a[i]);
	printf("%d\n", a[m]+1);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;

#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())

ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

void mod_add(ll &a, ll b) {
  a += b;
  if(a > mod) a -= mod;
}
void mod_sub(ll &a, ll b) {
  a -= b;
  if(a < 0) a += mod;
}
void mod_mul(ll &a, ll b) {
  a = (a * b) % mod;
}
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/
const int maxn = 2e5 + 10;
ll bit[maxn];
void upd(ll pos, ll val) {
  while(pos < maxn) {
    bit[pos] = max(bit[pos], val);
    pos |= pos + 1;
  }
}
ll query(ll pos) {
  ll ret = 0;
  while(pos >= 0) {
    ret = max(bit[pos], ret);
    pos = (pos & (pos + 1)) - 1;
  }
  return ret;
}
int main()
{
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  
  ll t, n, m, i, j, k, q, u, v;
  // cin >> t;
  // ll tc = t;
  t = 1;
  while (t--)
  {
    cin >> n;
    vi a(n), h(n);
    for(i = 0; i < n; i++)
    cin >> h[i];
    for(i = 0; i < n; i++)
    cin >> a[i];

    vi dp = a;
    for(i = 0; i < n; i++) {
      dp[i] += query(h[i] - 1);
      upd(h[i], dp[i]);
    }
    cout << *max_element(all(dp));
    // cout << "Case #" << tc - t << ": ";

    cout << '\n';
  }
  return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N;cin>>N;
    vector<ll> a(N);
    REP(i,N)cin>>a[i];
    int i1=0,i2=0;
    ll m=INF,M=-INF;
    REP(i,N){
        if(a[i]<m){
            m=a[i];
            i1=i;
        }
        if(a[i]>M){
            M=a[i];
            i2=i;
        }
    }
    if(abs(M)>=abs(m)&&M>=0){
        cout<<2*N-1<<endl;
        REP(i,N){
            cout<<i2+1<<" "<<i+1<<endl;
        }
        REP(i,N-1){
            cout<<i+1<<" "<<i+2<<endl;
        }
    }else if(abs(M)>=abs(m)&&M<0){
        cout<<0<<endl;
    }else if(abs(M)<abs(m) && m>=0){
        cout<<0<<endl;
    }else{
        cout<<2*N-1<<endl;
        REP(i,N){
            cout<<i1+1<<" "<<i+1<<endl;
        }
        REP(i,N-1){
            cout<<N-i<<" "<<N-i-1<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import itertools
N, C = [int(_) for _ in input().split()]
D = [[int(_) for _ in input().split()] for _ in range(C)]
c = [[int(_) - 1 for _ in input().split()] for _ in range(N)]  #0-indexed

grid = [[0] * C for _ in range(3)]
for i, j in itertools.product(range(N), repeat=2):
    grid[(i + j) % 3][c[i][j]] += 1
ans = float('inf')
for color_after in itertools.permutations(range(C), 3):
    ans = min(
        ans,
        sum([
            sum([
                grid[g][color_before] * D[color_before][color_after[g]]
                for color_before in range(C)
            ]) for g in range(3)
        ]))
print(ans)

Measured memory_bytes: 5492
m,k=map(int,input().split())
if m==0:
    if k==0:
        print('0 0')
    else:
        print(-1)
elif m==1:
    if k==0:
        print('0 0 1 1')
    else:
        print(-1)
else:
    if k>=2**m:
        print(-1)
    else:
        print(k,end=' ')
        for i in range(2**m):
            if i!=k:
                print(i,end=' ')
        print(k,end=' ')
        for i in range(2**m-1,-1,-1):
            if i!=k:
                print(i,end=' ')

Measured memory_bytes: 4944
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 4010
const int p=998244353;
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n,K,jc[maxn],pw[maxn],inv[maxn];
int add(int x,int y)
{
	return (x+y)%p;
}
int mul(int x,int y)
{
	return 1ll*x*y%p;
}
int C(int n,int m)
{
	if(m<0)return 0;
	if(n<m)return 0;
	return mul(jc[n],mul(inv[m],inv[n-m]));
}
int main()
{
	read(K,n);
	pw[0]=1,pw[1]=2;
	jc[0]=jc[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=n+K;i++)
	{
		pw[i]=mul(pw[i-1],2);
		jc[i]=mul(jc[i-1],i);
		inv[i]=mul(p-p/i,inv[p%i]);
	}
	for(int i=1;i<=n+K;i++)
		inv[i]=mul(inv[i-1],inv[i]);
	for(int i=2;i<=2*K;i++)
	{
		int ans=0,a=(i-1)/2-max(1,i-K)+1,b=K-a*2;
		if(i&1)
		{
			for(int j=0;j<=a;j++)
			{
				ans=add(ans,mul(pw[j],mul(C(a,j),C(n+b-1,j+b-1))));
			}
		}
		else
		{
			for(int j=0;j<=a;j++)
			{
				ans=add(ans,mul(pw[j],mul(C(a,j),C(n+b-2,j+b-2))));
				ans=add(ans,mul(pw[j],mul(C(a,j),C(n+b-3,j+b-2))));
			}
		}
		printf("%d\n",ans);
	}
    return 0;
}


Measured memory_bytes: 384