akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define ll long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const ll MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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


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

class Program
{
    static void Main()
    {
        string S = Console.ReadLine();

        if(S[0] != 'A')
        {
            Console.WriteLine("WA");
            return;
        }

        int CountC = 0;
        int PlaceC = 0;
        for(int i = 2; i < S.Length - 1;i++)
        {
            if(S[i] == 'C')
            {
                CountC++;
                PlaceC = i;
            }
        }

        if(CountC != 1)
        {
            Console.WriteLine("WA");
            return;
        }

        for(int i = 0; i < S.Length; i++)
        {
            if(i == 0 || i == PlaceC)
            {
                continue;
            }

            if(S[i] < 'a' || 'z' < S[i])
            {
                Console.WriteLine("WA");
                return;
            }
        }

        Console.WriteLine("AC");
    }
}


Measured memory_bytes: 11092
public class Main {
	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int l = 0;
		int[] a = new int[1];//int[l]
		int[] b = new int[1];//int[l]
		while (true) {
			int x = sc.nextInt();
			if (x == 0) {
				break;
			}

			l++;

			a = new int[l];
			for (int i = 0; i < l - 1; i++) {
				a[i] = b[i];
			}
			a[l - 1] = x;

			b = new int[l];
			for (int i = 0; i < l; i++) {
				b[i] = a[i];
			}
		}

		for (int i = 0;i < a.length;i++) {
			System.out.println("Case " + (i+1) + ": " + b[i]);
		}
	}
}

Measured memory_bytes: 161740
/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/
#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long 
# define db double
# define inf 1e9
# define mx2 100005
# define mx 100005
ll dp[mx][2];
vector <ll> adj[mx];
void addedge(ll u,ll v)
{
	adj[u].pb(v);
	adj[v].pb(u);
}
void dfs(ll u,ll par)
{
	dp[u][1]=dp[u][0]=1;
	for(auto k:adj[u])
	{
		if(k==par)continue;
		dfs(k,u);		
		dp[u][1]*=dp[k][0];
		dp[u][1]%=mod;
		dp[u][0]*=(dp[k][0]+dp[k][1])%mod;
		dp[u][0]%=mod;
	}
}
int main()
{
	IOS;
	ll n;
	cin>>n;
	for(ll i=0;i<n-1;i++)
	{
		ll x,y;
		cin>>x>>y;
		addedge(x,y);
	}
	dfs(1,-1);
	cout<<(dp[1][0]+dp[1][1])%mod<<endl;
}


Measured memory_bytes: 14208
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

long long n, eye, ubermed, untermed;
long long mylist[200001], origlist[200001];

int main() {
    cin>>n;
    for(int i = 1; i <= n; i++)
    {
        cin>>eye;
        mylist[i] = eye;
        origlist[i] = eye;
    }
    sort(mylist+1, mylist+n+1);
    untermed = mylist[n/2];
    ubermed = mylist[n/2 + 1];
    for(int i = 1; i <= n; i++) {
        if(origlist[i] <= untermed)
            cout<<ubermed;
        else
            cout<<untermed;
    cout<<endl;
    }
}

Measured memory_bytes: 5376
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Washoum
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DBannedK solver = new DBannedK();
        solver.solve(1, in, out);
        out.close();
    }

    static class DBannedK {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            int[] tab = new int[n];
            HashMap<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                tab[i] = sc.nextInt();
                map.putIfAbsent(tab[i], 0);
                map.put(tab[i], map.get(tab[i]) + 1);
            }
            long sum = 0;
            for (int i : map.keySet()) {
                int act = map.get(i);
                sum += ((long) act * (act - 1)) / 2;
            }
            for (int i = 0; i < n; i++) {
                long act = map.get(tab[i]);
                out.print((sum - (act * (act - 1)) / 2 + ((act - 2) * (act - 1)) / 2) + " ");
            }
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main() { 
  int N;
  string S;
  cin >> N >> S;
  int b;
  for (char c : S) {
    b = (c + N - 'A') % 26 +'A';
    cout << (char)b;
  }
  cout << endl;
} 

Measured memory_bytes: 3644
S_input = list(input())
K = int(input())
 
# 書き換えの最小値を求める
def change_count(str_list):
    answer = 0
    for i in range(1,len(str_list)):
        if str_list[i] == str_list[i-1]:
            answer += 1
            str_list[i] = i
    return answer
 
count = 0
 
# K=1のとき、文字列Sを書き換えるだけ
if K == 1:
    count += change_count(S_input)
    print(count)
    exit()
 
# 文字列Sが同じ文字のとき
if len(set(S_input)) == 1:
    count += (len(S_input)*K) // 2
    print(count)
    exit()
 
# 文字列Tの両端について、書き換える
SS = S_input + S_input
count += change_count(SS)
# K=2のとき、文字列SSを書き換えるだけ
if K == 2:
    print(count)
    exit()
 
# 文字列Tの真ん中の文字列Sについて、書き換える
SSS = S_input + S_input + S_input
change = change_count(SSS) - count
 
# K>=3のとき、両端1個＆真ん中(K-2)個
count += change * (K-2)    
 
print(count)

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ABC = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(ABC[2] >= ABC[0] && ABC[2] <= ABC[1] ? "Yes" : "No");
        }
    }
}


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

using namespace std;

string b[51];
int a[51];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	for (int i=0; i<n; i++) {
		cin>>b[i]>>a[i];
	}
	string s;
	cin>>s;
	int ne=0, zb=0;
	for (int i=0; i<n; i++) {
		if (ne) zb+=a[i];
		if (s==b[i]) ne=1;
	}
	cout<<zb;
	
}



Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "vector"
#include "string"
#include "map"
#include "algorithm"
#include "functional"
#include "set"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007; 

long long int N, M, K, H, W, L, R;

void Calculate_Depth(vector<vector<int>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i] > depth[cn] + 1) {
				depth[i] = depth[cn] + 1;
				Q.push(i);
			}
		}
	}
	return;
}

void Search(vector<vector<int>>&edge, vector<int>&num, vector<long long int>&dp, vector<int>&depth, int node = 0) {
	vector<int>fig(50);
	long long int bag = 0;
	for (auto i : edge[node]) {
		if (depth[i] < depth[node])continue;
		if (num[i] == -1)Search(edge, num, dp, depth, i);
		for (int j = 0; j < 50; j++) {
			fig[j] += (dp[i] >> j) & 1;
			bag |= dp[i];
		}
	}
	int nx = -1;
	for (int i = 0; i < 50; i++) {
		if (!fig[i]) {
			if (nx == -1)nx = i;
		}
		if (fig[i] >= 2)nx = -1;
	}
	num[node] = nx;
	dp[node] = ((bag >> nx) | 1) << nx;
	return;
}

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

	cin >> N;
	vector<vector<int>>edge(N);
	for (int i = 1; i < N; i++) {
		cin >> L >> R;
		L--;
		R--;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	vector<int>num(N, -1);
	vector<long long int>dp(N, -1);
	vector<int>depth(N, MOD);
	Calculate_Depth(edge, depth, 0);
	Search(edge, num, dp, depth);
	int ans = 0;
	for (auto i : num)ans = max(ans, i);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 30104
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> W >> H;
	while (W) {
		list<pair<int, int>>l;
		l.push_back({ W,H });
		for (int i = 0; i < N; i++) {
			int a, b;
			cin >> a >> b;
			int index = 1;
			pair<int, int>box;
			for (auto j = l.begin(); j != l.end(); ++j) {
				if (index == a) {
					box = *j;
					l.erase(j);
					break;
				}
				index++;
			}
			b %= (box.first + box.second) * 2;
			if (b < box.first) {
				pair<int, int>pa, pb;
				pa = box;
				pa.first = b;
				pb = box;
				pb.first -= b;
				if (pa.first > pb.first) {
					l.push_back(pb);
					l.push_back(pa);
				}
				else {
					l.push_back(pa);
					l.push_back(pb);
				}
				continue;
			}
			b -= box.first;
			if (b < box.second) {
				pair<int, int>pa, pb;
				pa = box;
				pa.second = b;
				pb = box;
				pb.second -= b;
				if (pa.second > pb.second) {
					l.push_back(pb);
					l.push_back(pa);
				}
				else {
					l.push_back(pa);
					l.push_back(pb);
				}
				continue;
			}
			b -= box.second;
			if (b < box.first) {
				pair<int, int>pa, pb;
				pa = box;
				pa.first = b;
				pb = box;
				pb.first -= b;
				if (pa.first > pb.first) {
					l.push_back(pb);
					l.push_back(pa);
				}
				else {
					l.push_back(pa);
					l.push_back(pb);
				}
				continue;
			}
			b -= box.first;
			if (b < box.second) {
				pair<int, int>pa, pb;
				pa = box;
				pa.second = b;
				pb = box;
				pb.second -= b;
				if (pa.second > pb.second) {
					l.push_back(pb);
					l.push_back(pa);
				}
				else {
					l.push_back(pa);
					l.push_back(pb);
				}
				continue;
			}
			b -= box.second;
		}
		vector<int>ans;
		for (auto i : l) {
			ans.push_back(i.first*i.second);
		}
		sort(ans.begin(), ans.end());
		for(int i=0;i<ans.size();i++){
			if (i)cout << " ";
			cout << ans[i];
		}
		cout << endl;
		cin >> N >> W >> H;
	}
	return 0;
}


Measured memory_bytes: 3028
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long ll;

int N;

ll W;
ll weights[110], vs[110];
ll dp[110][100100] = {0};

int main() {
  cin >> N >> W;
  for (int i = 0; i < N; ++i) {
    cin >> weights[i] >> vs[i];
  }

  for (int i = 0; i < N; ++i) {
    for (int w = 0; w <= W; ++w) {
      if(w - weights[i] >= 0) {
	dp[i + 1][w] = max(dp[i + 1][w], dp[i][w - weights[i]] + vs[i]);
      }
      dp[i + 1][w] = max(dp[i + 1][w], dp[i][w]);
    }
  }

  cout << dp[N][W] << endl;
  return 0;
}


Measured memory_bytes: 79360
function range(from, to) {
    var range = [];
    for (var i = from; i <= to; i++) {
        range.push(i);
    }
    return range;
}

const chunk = require('fs').readFileSync('/dev/stdin', 'utf8');

const existCard = chunk.split('\n').slice(1);


const suits = ['S', 'H', 'C', 'D'];
const ranks = range(1, 13);

for (var i = 0; i < suits.length; i++) {
    for (var j = 0; j < ranks.length; j ++) {
        var card = suits[i] + ' ' + ranks[j];
        if (existCard.indexOf(card) === -1) {
            console.log(card);
        }
    }
}

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

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535897932;
const ll MOD = 1000000007;

int main()
{
	char C;
	cin >> C;
	cout << char(C + 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

//vector<vector<pair<int, int> > > edge(2505);
vector<vector<int> > edges(2505);
vector<vector<int> > edger(2505);

int main() {
  int N, M, P;
  cin>>N>>M>>P;
  int A[M], B[M], C[M];
  for(int i=0;i<M;++i) {
    cin>>A[i]>>B[i]>>C[i];
    A[i]--;
    B[i]--;
    //edge[A[i]].push_back(mp(B, -(C-P)));
    edges[A[i]].push_back(B[i]);
    edger[B[i]].push_back(A[i]);
  }
  bool reach0[N], reachN[N];
  for(int i=0;i<N;++i) {
    reach0[i] = false;
    reachN[i] = false;
  }
  reach0[0] = true;
  reachN[N-1] = true;
  queue<int> que;
  que.push(0);
  int state;
  while(!que.empty()) {
    state = que.front();que.pop();
    for(int i=0;i<edges[state].size();++i) {
      if(reach0[edges[state][i]]) continue;
      que.push(edges[state][i]);
      reach0[edges[state][i]] = true;
    }
  }
  que.push(N-1);
  while(!que.empty()) {
    state = que.front();que.pop();
    for(int i=0;i<edger[state].size();++i) {
      if(reachN[edger[state][i]]) continue;
      que.push(edger[state][i]);
      reachN[edger[state][i]] = true;
    }
  }
  vector<int> ans(N);
  ans[0] = 0;
  for(int i=1;i<N;++i) ans[i] = inf;
  bool can = true;
  for(int i=0;i<N;++i) {
    for(int j=0;j<M;++j) {
      if(reach0[A[j]] && reachN[A[j]] && reach0[B[j]] && reachN[B[j]]) {
        if(ans[B[j]] > ans[A[j]] + P - C[j]) {
          ans[B[j]] = ans[A[j]] + P - C[j];
          if(i==N-1) can = false;
        }
      }
    }
  }
  if(can) cout<<max(0, -ans[N-1])<<endl;
  else cout<<-1<<endl;
}



Measured memory_bytes: 3984
package main

import (
	"fmt"
)

func main() {
	var n int
	var q int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&q)
	fmt.Scan(&s)

	//累積和を計算する
	sum := make([]int, n+1)
	// ACが出る可能性があるのは2文字目から(0-indexedで1から)
	for i := 1; i < n; i++ {
		if s[i-1] == 'A' && s[i] == 'C' {
			sum[i+1] = sum[i] + 1
		} else {
			sum[i+1] = sum[i]
		}
	}

	ls := make([]int, q)
	rs := make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Scan(&ls[i])
		fmt.Scan(&rs[i])
	}

	for i := 0; i < q; i++ {
		ans := sum[rs[i]] - sum[ls[i]]
		fmt.Println(ans)
	}
}


Measured memory_bytes: 7812
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> pi;
#define PI 3.14159265359
long long mod=1000000007;
//int count=INT_MAX;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    //scanf("%d",&t);
    
    for(int l=0;l<t;l++){
        int a,b;
        cin>>a>>b;
        cout<<a*b;
        
    }
    
    return 0;
}

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

int main() {
	int n,m;cin>>n>>m;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	vector<int> c(n,1);
	vector<int> a(m),b(m);
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
		a[i]--;b[i]--;
		if(h[a[i]]<=h[b[i]]){
			c[a[i]]=0;
		}
		if(h[a[i]]>=h[b[i]]){
			c[b[i]]=0;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=c[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
using Graph = vector<vector<int>>;
int n, m;
Graph G;

int dp[1001000];

int dfs(int x) {
  if (dp[x] != 0) return dp[x];
  int mx = 0;
  for (int i = 0; i < G[x].size(); i++) {
    mx = max(mx, dfs(G[x][i]) + 1);
  }
  dp[x] = mx;
  return mx;
}

int main() {
  cin >> n >> m;

  G.resize(n);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
  }

  int ans = 0;

  for (int i = 0; i < n; i++) {
    ans = max(ans, dfs(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 10972
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n;
  std::cin >> n;
  vt<ll> a(n);
  rep(i,n)
    std::cin >> a[i];

  int p = 1, q = n-1;
  ll length = a[0];
  while(p <= q) {
    if(length >= 0) {
      length -= a[q];
      --q;
    }
    else {
      length += a[p];
      ++p;
    }
  }

  std::cout << (int)abs(length) << '\n';
  return 0;
}


Measured memory_bytes: 1792
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	static long MOD = 1000000007;
	static BigInteger BMOD = new BigInteger(Long.toString(MOD));
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		long total = 1;
		long pow = 2;
		for ( int i = 0 ; i < 30 ; i++ ) {
			if ( (n & (1 << i)) != 0 ) {
				total = (total * pow) % MOD;
			}
			pow = (pow * pow) % MOD;
		}

		total = (total + MOD - combination(n, a)) % MOD;
		total = (total + MOD - combination(n, b)) % MOD;

		System.out.println(total - 1);
	}

	public static long combination(long n, long a) {
		long ans = 1;
		for ( int i = 0 ; i < a ; i++ ) {
			ans = (ans * (n - i)) % MOD;
			ans = (ans * (new BigInteger(Integer.toString(i + 1))).modInverse(BMOD).longValue()) % MOD;
		}
		return ans;
	}
}


Measured memory_bytes: 94924
#pythonじゃ通らなかった…(´・ω・`)
n = int(input())
a = list(map(int,input().split()))
ans = [[0 for i in range(n+1)] for j in range(n+1)]
p = []

#それぞれの活発度と元々居た位置の記録
for i in range(n):
    p.append([a[i],i])
p.sort(reverse=True)

#活発度の高い順にそれぞれ左と右から詰めて並べていく時のうれしさの変化
for i in range(1,n+1):
    ans[0][i] = ans[0][i-1] + p[i-1][0]*abs(p[i-1][1]-i+1)
for i in range(1,n+1):
    ans[i][0] = ans[i-1][0] + p[i-1][0]*abs(n-i-p[i-1][1])

#Douteki Planning 活発度の高い順に左にi人、右にj人詰めて並べていった時の最大値
for i in range(1,n):
    for j in range(1,n-i+1):
        ans[i][j] = max(ans[i][j-1] + p[i+j -1][0]*abs(p[i+j -1][1]-j+1),
        ans[i-1][j] + p[i+j - 1][0]*abs(n-i-p[i+j-1][1]))

#全て詰め並べ終わったときのうれしさの最大値(=答え)を探す
ma = 0
for i in range(n):
    ma = max(ma,ans[0+i][n-i])
print(ma)

Measured memory_bytes: 107524
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

ll vs[60];
int N, K;

int main(void) {
  cin >> N >> K;
  REP(i, N) {
    cin >> vs[i];
  }
  ll res = 0;
  REP(ed, N+1) {
    REP(bg, ed+1) {
      vector<ll> ts;
      int k = K;
      REP(i, N) {
        if(bg <= i && i < ed) {
          // nothing
        } else {
          ts.push_back(vs[i]);
          --k;
        }
      }
      if (k < 0) {
        continue;
      }
      sort(ts.begin(), ts.end());
      ll cur = 0;
      REP(i, ts.size()) {
        if(ts[i] < 0 && k > 0) {
          --k;
        } else {
          cur += ts[i];
        }
      }
      if(cur > res) {
        // cerr << bg << " " << ed << " " << cur << endl;
        res = cur;
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 632
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex;
import std.container;

void main()
{
	auto r = regex(r"\d+", "g");
	int sum;
	foreach (line; stdin.byLine) {
		foreach (m; line.match(r)) {
			sum += m[0].to!int;
		}
	}
	sum.writeln;
}

Measured memory_bytes: 1436
#include<stdio.h>

int main()
{
 char n[5];

 scanf("%s",n);

 if((n[0]==n[1])&&(n[1]==n[2]))printf("Yes\n");
 else if((n[1]==n[2])&&(n[2]==n[3]))printf("Yes\n");
 else printf("No\n");

 return 0;
}


Measured memory_bytes: 1656
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e15)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-12)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (100006)
#define ll long double 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <char, pi> spi;
typedef pair <pi, pi> dpi;
// inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
// string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}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 first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
ll n; spi A[MAXN];
ll tstar(ll x){
	ll mxx=-LLINF,mix=LLINF,may=-LLINF,miy=LLINF;
	FOR(ii,0,n){ int i=ii;
		ll movex=0,movey=0;
		if(A[i].f=='L'){
			movex-=x;
		}else if(A[i].f=='R'){
			movex+=x;
		}else if(A[i].f=='D'){
			movey-=x;
		}else if(A[i].f=='U'){
			movey+=x;
		}else assert(0);
		mxx=max(mxx,movex+A[i].s.f);
		mix=min(mix,movex+A[i].s.f);
		may=max(may,movey+A[i].s.s);
		miy=min(miy,movey+A[i].s.s);
	}
	return (mxx-mix)*(may-miy);
}
int main()
{
	FAST
	cin>>n;
	FOR(i,0,n){
		cin>>A[(int)i].s.f>>A[(int)i].s.s>>A[(int)i].f;
	}
	ll st=0,en=2e8+100;
	FOR(i,0,120){
		ll lmid=st+(en-st)/(ld)3;
		ll umid=en-(en-st)/(ld)3;
		if(st==lmid&&en==umid)break;
		if(tstar(lmid)>tstar(umid))st=lmid;
		else en=umid;
	}
	cout<<fixed<<setprecision(15)<<tstar((st+en)/(ld)2)<<'\n';
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
long long n, a[200005], sum, sum1, ans;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i=0; i<n; i++){
	cin >> a[i]; sum+=a[i];
} ans=8000000000000000000LL;
for (int i=0; i<=n; i++){
	ans=min(ans, abs(sum-2*sum1));
	sum1+=a[i];
}
cout << ans;
return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

def input_one_number():
    return int(input())

def input_multiple_number():
    return map(int, input().split())

def input_multiple_number_as_list():
    return list(map(int, input().split()))

T = input()

ans = ''
for i in range(len(T)):
	a = T[i]
	if T[i] == "?":
		a = 'D'
	ans += a

print(ans)



Measured memory_bytes: 9468
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {

    string S;
    cin >> S;
    ll N = S.length();
    ll s[26] = {0};
    rep(i,N) s[(ll)(S[i]-'a')] = i+1;
    string out = "-1";
    if(N<26){
        rep(i,26){
            if(s[i]==0){
                out = S+(char)(i+'a');
                break;
            }
        }
    }else{
        ll cnt = 0;
        rep(i,N){
            if(S[N-1-i]>S[N-2-i]){
                cnt = i;
                break;
            }
        }
        if(cnt!=25){
            for(ll i=(ll)(S[N-2-cnt]-'a');i<N;i++){
                if(s[i]>s[(ll)(S[N-2-cnt]-'a')]){
                    out = S.substr(0,N-2-cnt)+(char)(i+'a');
                    break;
                }
            }
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if  x not in aD])
aUnList.sort()
sN = str(iN)
iF = int(sN[0])

def fCheckDigit(sTarget,iPoint,aUnList,aRet,bRev):
    iL = len(sTarget)
    iF = int(sTarget[iPoint])
    aUpper = [x for x in aUnList if x >= iF]
    aUpper.sort()
    if bRev: #遡ってきたとき
        #もうひとつ上があるかどうか
        if len(aUpper) == 1 : #==のとき。もうひとつ上はない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])] * (iL + 1)
            else:
                return fCheckDigit(sTarget,iPoint -1 , aUnList,aRet,True)
        else: #上の桁がある
            return aRet[0:iPoint]+[str(aUpper[1])]+[str(aUnList[0])]*(iL-1-iPoint)
    else: #順向
        if aUpper == []: #大きい数字がない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])]*(iL+1)
            else:
                return fCheckDigit(sTarget,iPoint-1,aUnList,aRet,True) #逆行する
        else:
            if aUpper[0] != iF:
                return aRet[0:iPoint]+[str(aUpper[0])] + [str(aUnList[0])]*(iL-1- iPoint)
            else:
                aRet.append(str(iF))
                if iPoint  < iL -1 :
                    return fCheckDigit(sTarget,iPoint+1,aUnList,aRet,False) #順行する
                else:
                    return aRet

print( ''.join(fCheckDigit(sN,0,aUnList,[],False)))


Measured memory_bytes: 3064
# seishin.py
N, M = map(int, input().split())
D = [[] for i in range(M+1)]
for i in range(N):
    l, r = map(int, input().split())
    D[r-l+1].append(l)

data = [0]*(M+2)
def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s
def add(k, x):
    while k <= M+1:
        data[k] += x
        k += k & -k

C = N
ans = []
for d in range(1, M+1):
    for l in D[d]:
        add(l, 1)
        add(l+d, -1)
        C -= 1

    cnt = C
    i = d
    while i <= M:
        cnt += get(i)
        i += d
    ans.append(cnt)
print(*ans, sep='\n')


Measured memory_bytes: 85776
# -*- coding:utf-8 -*-

def solve():
    """ dp[i+k]を求める方法（配るDP）
    Python: TLE 
    """
    N,K=list(map(int,input().split()))
    A=list(map(int,input().split()))
    
    INF=float("inf")
    
    dp=[INF]*N
    dp[0]=0
    
    for i in range(0, N-1):
        for k in range(1, K+1):
            if i+k <= N-1:
                dp[i+k]=min(dp[i+k],dp[i]+abs(A[i]-A[i+k]))
            else:
                break
    print(dp[N-1])


def solve2():
    """ dp[i]を求める方法（貰うDP）
    Python: TLE
    PyPy: AC
    (´･_･`)
    """
    N,K=list(map(int,input().split()))
    A=list(map(int,input().split()))
    
    INF=float("inf")
    
    dp=[INF]*N
    dp[0]=0
    for i in range(1, N):
        for k in range(1, K+1):
            if i-k >= 0:
                dp[i] = min(dp[i], dp[i-k]+abs(A[i]-A[i-k]))
            else:
                break
    print(dp[N-1])


if __name__ == "__main__":
    solve()


Measured memory_bytes: 55264
#include<stdio.h>
 
int main(){
		int i,ans=0,n,max=0;
		long long h[100000];
		scanf("%d",&n);
		for(i=0;i<n;i++)scanf("%lld",&h[i]);
		for(i=1;i<n;i++){
				if(h[i-1]>=h[i])ans++;
				else ans=0;
				if(max<ans)max=ans;
		}
		printf("%d\n",max);
		return 0;
}

Measured memory_bytes: 896
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

n=int(input())
V=list(map(int, input().split()))
C=list(map(int, input().split()))

s = 0
for v, c in zip(V, C):
    if (v - c) > 0:
        s += (v - c)

print(s)

Measured memory_bytes: 12396
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const int mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

ll N, M, Q, c;
vector<int> G[100000];
vector<int> col(100000, -1);
vector<P> ch;

void dfs(int v){
	col[v] = c;
	for(auto to : G[v]){
		if(col[to] != -1) continue;
		dfs(to);
	}
}

int main(){
	cin >> N >> M >> Q;
	rep(i, Q){
		int a, b, c; cin >> a >> b >> c;
		if(c) ch.pb(P(a, b));
		else{
			G[a].pb(b);
			G[b].pb(a);
		}
	}
	rep(i, N)if(col[i] == -1){ dfs(i); c++; }
	rep(i, ch.size()){
		if(col[ch[i].first] == col[ch[i].second]){
			cout << "No" << endl;
			return 0;
		}
	}
	if(N - 1 + (ch.size() > 0) <= M && M <= N + c*(c-3)/2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main() {
	string s;
  	cin >> s;
	
  	string odd = "";
  	for (int i=0; i<s.size(); i++) {
		if (i % 2 == 0) odd = odd + s[i];
    }
  	cout << odd << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

const int p=1000000007;
int n,m,f[3010][3010][2],g[3010][6010][2],ans;

int main()
{
    scanf("%d%d",&n,&m);
    repu(i,0,n)
        g[0][i][!i]=1;
    repu(i,1,m)
    {
        repu(j,0,n)
            repu(k,0,1)
                if (g[i-1][j][k])
                {
                    if (j)
                        (f[i][j][k || j==1]+=g[i-1][j][k])%=p;
                    if (j<n)
                        (f[i][j+1][k]+=g[i-1][j][k])%=p;
                }
        repu(j,1,n)
            repu(k,0,1)
                if (f[i][j][k])
                {
                    if (j)
                        (g[i][j-1][k || j==1]+=f[i][j][k])%=p;
                    (g[i][j][k]+=f[i][j][k])%=p;
                }
    }
    repu(i,0,n)
        (ans+=g[m][i][1])%=p;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 211200
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

ll INF=10000000000000000;

int main(){
    ll N;
    cin >> N;
    ll W;
    cin >> W;
    vector<ll> w(N+1,0);
    vector<ll> v(N+1,0);
    for(ll i=0;i<N;i++){
        cin>>w[i+1]>>v[i+1]
    ;}
    //dp[j]は価値j分買う時の重さの最小値
    vector<ll> dp(100001,INF);
    dp[0]=0;
    
    //1つずつ品物を解禁
    for(ll i=1;i<=N;i++){
        for(ll j=100000;j>=v[i];j--){
            dp[j]=min(dp[j-v[i]]+w[i],dp[j])
        ;}
    ;}
    ll ans=0;
    for(ll j=0;j<=100000;j++){
        if(dp[j]<=W){ans=j;}
    ;}
    cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
 #define REP(i, N) for(int i = 0; i < N; i++)
 
int main() {
    int N, a[100000];
    cin >> N;
    REP(i, N) cin >> a[i];
 
    int oddNum = 0;
    REP(i, N) {
        if(a[i]%2 == 1) oddNum++;
    }
    cout << (oddNum % 2 == 0? "YES": "NO") << endl;
}

Measured memory_bytes: 3992
N = gets.to_i
A = [0, *(gets.split.map(&:to_i)), 0]
T = (0..N).map{ |i| (A[i+1] - A[i]).abs }.inject(:+)
(0...N).each{ |i|
  p T - (A[i+1] - A[i]).abs - (A[i+2] - A[i+1]).abs + (A[i+2] - A[i]).abs
}

Measured memory_bytes: 17924
#include<iostream>
#include<ctype.h>
#include<map>
#include<string>
 
using namespace std;
 
map<string, bool> m;
 
long long calc(string s) {
	long long res = 0;
	string t;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != '+') {
			t.push_back(s[i]);
		} else {
			res += stoll(t);
			t.clear();
		}
	}
	res += stoll(t.c_str());
	//cout << s << " " << res << endl;
	return res;
}
 
//n = 今の+の数
long long solve(string s,int n = 0) {
	if (m[s]) return 0;
	m[s] = true;
 
	if (n == s.size() - 1) {
		return calc(s);
	}
 
	long long res = calc(s);
	
	for (int i = 1; i < s.size(); i++) {
		string tmp = s;
		if (s[i-1] != '+' && s[i] != '+' && s[i+1] != '+') {
			tmp.insert(tmp.begin() + i, '+');
			res += solve(tmp, n + 1);
		}
	}
	return res;
}
 
int main() {
	string s;
	cin >> s;
	cout << solve(s) << endl;
}

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

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/
int N, Ma, Mb;
int a[50], b[50], c[50];
int dp[50][500][500];
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N>>Ma>>Mb;
    REP(i,0,N){
        cin>>a[i]>>b[i]>>c[i];
    }

    //init
    REP(i,0,N+1){
        REP(j,0,410){
            REP(k,0,410){
                dp[i][j][k] = INF;
            }
        }
    }

    REP(i,0,N+1){
        dp[i][0][0] = 0;
    }

    REP(i,0,N){
        REP(asum,0,410){
            REP(bsum,0,410){
                dp[i+1][asum][bsum]
                        = min({dp[i+1][asum][bsum], dp[i][asum][bsum]});
                if(asum - a[i] < 0 || bsum - b[i] < 0) continue;
                dp[i+1][asum][bsum] = min(dp[i+1][asum][bsum], dp[i][asum - a[i]][bsum - b[i]] + c[i]);
            }
        }
    }

    int ans = INF;
    REP(i,1,N+1){
        REP(asum,1,410){
            REP(bsum,1,410){
                if(asum*Mb == bsum*Ma && dp[i][asum][bsum] != INF){
                    ans = min(ans, dp[i][asum][bsum]);
                }
            }
        }
    }

    if(ans == INF)ans = -1;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 40832
import sys
from decimal import *
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    n = int(input())
    ans = 0
    for i in range(1, n+1):
        if i % 3 == 0:
            continue
        if i % 5 == 0:
            continue
        ans += i
    print(ans)


main()


Measured memory_bytes: 77324
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++) 
#define sort(v) sort(v.begin(),v.end());
const ll mod = 1E9+7;

int main()
{
   ll n,ans = 0;
   cin>>n;
   vector<ll> v(n), e(n);
   loop(i,0,n){
      cin>>v[i];
      if(i == 0)e[i] = v[i];
      else e[i] = min(e[i-1],v[i]);
      if(e[i] == v[i]){
         ans++;
         // cout<<i<<" ";
      }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 6376
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<std::vector<int>> edg(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; std::cin >> a >> b;
        a--; b--;
        edg[a].push_back(b);
        edg[b].push_back(a);
    }
    std::vector<int> distf(n, 1e9), dists(n, 1e9);
    auto bfs = [&](std::vector<int> &dist, int s) {
        std::deque<int> que;
        dist[s] = 0;
        que.push_back(s);
        while (!que.empty()) {
            int pos = que.front();
            que.pop_front();

            for (int c : edg[pos]) {
                if (dist[c] <= dist[pos] + 1) continue;
                dist[c] = dist[pos] + 1;
                que.push_back(c);
            }
        }
    };
    bfs(distf, 0);
    bfs(dists, n - 1);
    int s = 0, f = 0;
    for (int i = 0; i < n; i++) {
        (distf[i] <= dists[i] ? f : s)++;
    }
    std::cout << (f > s ? "Fennec" : "Snuke") << std::endl;
    return 0;
}


Measured memory_bytes: 6528
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range (n)]
ans=0

def distance(a,b):
    d=0
    for i in range(len(a)):
        d+=abs(a[i]-b[i])**2
    return d
    
def check(a,b):
    f=0
    for i in range(1000):
        if distance(a,b)==i**2:
            f+=1
            break
        else:
            f=f
    if f>0:
        return True
    else:
        return False
            
    
for i in range(n):
    for j in range(i+1,n):
        if check(x[i],x[j]):
            ans+=1
print(ans)


Measured memory_bytes: 45276
import sys

#+++++
		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	bl = list(map(int, input().split()))
	cl = list(map(int, input().split()))
	
	ret=0
	pre=-10
	for i, v in enumerate(al):
		ret += bl[v-1]
		if pre == v -1:
			ret+=cl[v-2]
		pre=v
		
	print(ret)
	
	
#+++++


if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] aArr = new int[n];

        for (int i = 0; i < n; i++) {
            aArr[i] = sc.nextInt();
        }

        int count = 0;// 分けた数列の数
        for (int i = 0; i < aArr.length; i++) {
            while (i+1 < aArr.length && aArr[i] == aArr[i+1]) {
                i++;// 次の文字が現在の文字と同じならインクリメント
            }

            if (i+1 < aArr.length && aArr[i] < aArr[i+1]) {
                while (i+1 < aArr.length && aArr[i] <= aArr[i+1]) {
                    i++;
                }
            } else if (i+1 < aArr.length && aArr[i] > aArr[i+1]) {
                while (i+1 < aArr.length && aArr[i] >= aArr[i+1]) {
                    i++;
                }
            }

            count++;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 49764
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var j=0;
var str="";
while(true){
   var v=Arr.shift()-0;
   if(v==0)break;
   var m=(Arr.shift()).split(" ").map(Number);
   var money=(10*m[0]+50*m[1]+100*m[2]+500*m[3])-v;
   var M=[0,0,0,0];
   while(500<=money){M[3]++;money-=500;}
   while(100<=money){M[2]++;money-=100;}
   while(50<=money){M[1]++;money-=50;}
   while(10<=money){M[0]++;money-=10;}
   var coin=[10,50,100,500];
   m.forEach(function(v,i){
      if(v>M[i])str+=coin[i]+" "+(v-M[i])+"\n";
   });
   str+="\n";
}
console.log(str.trim());

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

int main(){
    string s;
    cin>>s;
    //cout<<s;
    int count=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='1')count++;
    }
    cout<<count;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];
ll box[200010];

int main(){
  cin >> n;
  rep(i,0,n)cin >> d[i];
  cin >> m;
  ll ans = 0;
  rep(i,0,m){
    int a,b,c;
    cin >> a >> b >> c;
    b--;
    if(a == 2){
      box[b] -= c;
      if(box[b] < 0){
        cout << b + 1 << endl;
        return 0;
        //box[b] = 0;
        //box[b] += c;
      }
    }else{
      box[b] += c;
      if(d[b] < box[b]){
        cout << b + 1 << endl;
        return 0;
        //box[b] -= c;
      }
    }
  }
  puts("0");
  return 0;
}


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

typedef long long ll;

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n = 0, k = 0;
    cin >> n >> k;
    if(n < abs(n - k)) {
        cout << n <<endl;
        return 0;
    }
    else {
        ll up = n%k;
        ll down = k - n%k;

        cout << min(up, down) << endl;
    }
    
    return 0;
}

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

int N;

void Swap(vector<int> &v, int a, int b) {
    swap(v[a], v[b]);
}

int main() {
    cin >> N;
    vector<int> Rol[4];
    for (int i = 0; i < 4; i++) {
        Rol[i].resize(30);
        for (int j = 0; j < 30; j++) {
            Rol[i][j] = j;
        }
    }

    Swap(Rol[0], 0, 23);
    Swap(Rol[0], 3, 26);
    Swap(Rol[0], 6, 29);
    Swap(Rol[0], 9, 20);
    Swap(Rol[0], 15, 17);

    Swap(Rol[1], 0, 27);
    Swap(Rol[1], 1, 28);
    Swap(Rol[1], 2, 29);
    Swap(Rol[1], 14, 15);
    Swap(Rol[1], 18, 20);

    Swap(Rol[2], 2, 21);
    Swap(Rol[2], 5, 24);
    Swap(Rol[2], 8, 27);
    Swap(Rol[2], 11, 18);
    Swap(Rol[2], 12, 14);

    Swap(Rol[3], 6, 21);
    Swap(Rol[3], 7, 22);
    Swap(Rol[3], 8, 23);
    Swap(Rol[3], 9, 11);
    Swap(Rol[3], 12, 17);

    while (N--) {
        string str;
        for (int i = 0; i < 30; i++) {char c; cin >> c; str += c;}
        string sub = "111111111222444666555333333333";

        queue<pair<int,string> > S;
        S.push(pair<int,string>(0, str));
        while (S.size()) {
            auto s = S.front(); S.pop();
            if (s.second == sub) {
                cout << s.first << endl;
                break;
            }
            else {
                for (int i = 0; i < 4; i++) {
                    string tmp;
                    for (auto j : Rol[i]) {
                        tmp += (s.second)[j];
                    }
                    S.push(pair<int,string>(s.first + 1, tmp));
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 10648
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;

double EPS = 1e-10;

double add(double a, double b){
if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
return a+b;
}



struct point{

double x, y;

point(){}

point(double x,double y) : x(x) , y(y){}

point operator + (point p){
return point(add(x,p.x), add(y,p.y));
}

point operator - (point p){
return point(add(x,-p.x), add(y,-p.y));
}

point operator * (double d){
return point(x*d,y*d);
}

};



double cross(point a, point b) {
return (a.x * b.y - a.y * b.x);
}



int is_intersected_ls(point a1, point a2, point b1, point b2) {

return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );

}



int main(void){

int n;

point p[3],k,s;

cin >> n;

while(n--){
for(int i=0;i<3;i++)
cin >> p[i].x >> p[i].y;

cin >> k.x >> k.y >> s.x >> s.y;

int cnt=0;

for(int i=0;i<3;i++)
for(int j=i+1;j<3;j++)
cnt+=is_intersected_ls(p[i],p[j],k,s);

if(cnt%2)cout << "OK" << endl;
else cout << "NG" << endl;
}

return 0;

}

Measured memory_bytes: 948
L, R = gets.split.map(&:to_i)

if R - L + 1 >= 2019
  
  ans = 0
  
else
  
  ans = 2018
  (L..R).each do |i|
    (L..R).each do |j|
      next unless i < j
      ans = [ans, i * j % 2019].min
    end
  end
  
end

puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,p;
	cin>>a>>p;
	cout<<(3*a+p)/2<<endl;
	return 0;
}


Measured memory_bytes: 256