akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque



def run():
    S = input()
    T = input()
    ref = 'abcdefghijklmnopqrstuvwxyz'
    ans =[]
    for i in range(len(S)-len(T)+1):
        checked = True
        for j in range(len(T)):
            if S[i+j] == T[j] or S[i+j]=='?':
                continue
            else:
                checked = False
                break
        if checked:
            ret = S[:i].replace('?', 'a') + T + S[i+len(T):].replace('?', 'a')
            ans.append(ret)
    try:
        print(sorted(ans)[0])
    except:
        print('UNRESTORABLE')



if __name__ == "__main__":
    run()


Measured memory_bytes: 9096
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# Nと空白区切の入力値を数値の配列で返却する
def gets_n_and_i_list()
  return gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
end
N, a_list = gets_n_and_i_list

ua_list = a_list.uniq.sort
if ua_list.size == 1 && ua_list.first == 0
  puts "Yes"
  exit
elsif ua_list.size == 2
  x0, x1 = ua_list
  if x0 == 0 &&
    a_list.count(x0) == N/3 &&
    a_list.count(x1) == 2 * N/3
    puts "Yes"
    exit
  end
elsif ua_list.size == 3
  x0, x1, x2 = ua_list
  if x0 ^ x1 ^ x2 == 0 &&
    a_list.count(x0) == N/3 &&
    a_list.count(x1) == N/3 &&
    a_list.count(x2) == N/3
    puts "Yes"
    exit
  end
end
puts "No"


Measured memory_bytes: 13576
s=input()

def ranlength(A):
    num = list(A)
    count = 1
    table = []
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                table.append(count)
                count = 1
        except:
            table.append(count)
    return(table)

rl=ranlength(s)
w=0
for i in range(len(rl)//2):
    w+=(rl[i*2]-rl[i*2+1])/2

if len(rl)%2==1:
    w+=rl[-1]/2

w=int(w)
print(w)

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

int main() {
	vector<int> AT;
	int N, V[20], C[20], T[20], ANS = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}
	for (int i = 0; i < N; i++) {
		T[i] = V[i] - C[i];
		if (T[i] >= 0) {
			AT.push_back(T[i]);
		}
	}
	int counter = AT.size();
	for (int i = 0; i < counter; i++) {
		ANS = ANS + AT[i];
	}
	cout << ANS << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;


const ll modo=998244353;
const ll inf=1e16;
const ll ms=(2e5) +5;


int ar[ms]={0};
int dis[ms]={0};

vector<int> vv[ms];


int main()
{
    idfc;
    int n;
    int x,y;
    cin>>n>>x>>y;
    int i;
    for(i=1;i<n;i++)
    {
        vv[i].pb(i+1);
        vv[i+1].pb(i);
    }
    vv[x].pb(y);
    vv[y].pb(x);
    int u,v;
    int j;
    for(i=1;i<=n;i++)
    {
        queue<int> q;
        q.push(i);
        dis[i]=1;

        while(!q.empty())
        {
            u=q.front();
            q.pop();
            for(int ii:vv[u])
            {
                if(!dis[ii])
                {
                    dis[ii]=dis[u]+1;
                    q.push(ii);
                }
            }
        }
        for(j=1;j<=n;j++)
        {
            ar[dis[j]-1]++;
            dis[j]=0;
        }
    }

    for(i=1;i<n;i++)
    {
        cout<<(ar[i]/2)<<"\n";
    }


    return 0;
}

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

int main(void)
{
  while (true)
  {
    int price, pay;
    cin >> price >> pay;
    if ( price == 0 && pay == 0 ) break;
    int change = pay - price;

    int sen_yen = change / 1000;
    change -= sen_yen * 1000;
    int gohyaku_yen = change / 500;
    change -= gohyaku_yen * 500;
    int hyaku_yen = change / 100;

    cout << hyaku_yen << ' ' << gohyaku_yen << ' ' << sen_yen << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N,M,X = map(int,input().split())
toll_index = [int(i) for i in input().split() if int(i) not in [0,N,X]]
toll_array = [1 if j in toll_index else 0 for j in range(N+1)]
ZtoX, XtoN = sum(toll_array[0:X]),sum(toll_array[X:N])
print([ZtoX,XtoN][ZtoX>XtoN])

Measured memory_bytes: 3064
// Gracias, Rodolfo
// Gracias, Roman
// Gracias, Maxi
// Gracias, MarcosK
// Obrigado, Dilson
//#pragma GCC optimize ("Ofast,unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for (int i = a; i < b; i++)
#define roF(i,a,b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) (v).begin(),(v).end()
#define SZ(v) ((int)v.size())

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int N = 1e6;
const ll INF = 1e18;
const ld EPS = 10e-9;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random(ll a, ll b) { return uniform_int_distribution<ll> (a, b) (rng); }

void solve() {
    long long x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    long long p[a], q[b], r[c];
    for (int i = 0; i < a; i++) cin >> p[i];
    for (int j = 0; j < b; j++) cin >> q[j];
    for (int k = 0; k < c; k++) cin >> r[k];
    sort(p, p + a);
    sort(q, q + b);
    sort(r, r + c);
    vector<long long> target;
    for (int i = a - 1; i > a - 1 - x; i--) target.push_back(p[i]);
    for (int i = b - 1; i > b - 1 - y; i--) target.push_back(q[i]);
    sort(target.begin(), target.end());
    int l = min(x + y, c);
    for (int i = 0; i < l; i++) target[i] = max(target[i], r[c - 1 - i]);
    long long sum = 0;
    int sz = target.size();
    for (int i = 0; i < sz; i++) sum += target[i];
    cout << sum << endl;
}

int main() {
	fastio;
	int t = 1;
	//cin >> t;
	while (t--) solve();
	return 0;
}

Measured memory_bytes: 4852
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
	long long i,n,k=0,sum=0;
	vector<long long> a(200010),b(200010),c;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i] >> b[i];
		sum += a[i];
		if(a[i] > b[i]){
			k++;
			c.push_back(b[i]);
		}
	}
	if(k==0){
		cout << 0 << endl;
		return 0;
	}
	sort(c.begin(),c.end());
	cout << sum-c[0] << endl;
}
	

Measured memory_bytes: 3584
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

d = [0 for _ in range(n)]
for i in range(n):
    d[i] = pow(math.fabs(x[i]-y[i]), 1)
D_1 = pow(sum(d), 1/1)

for i in range(n):
    d[i] = pow(math.fabs(x[i]-y[i]), 2)
D_2 = pow(sum(d), 1/2)

for i in range(n):
    d[i] = pow(math.fabs(x[i]-y[i]), 3)
D_3 = pow(sum(d), 1/3)

for i in range(n):
    d[i] = math.fabs(x[i]-y[i])
D_inf = max(d)

print(D_1)
print(D_2)
print(D_3)
print(D_inf)

Measured memory_bytes: 7900
from math import factorial


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

p = abs(N-M)
if p > 1:
    ans = 0
else:
    if p == 0:
        ans = 2
    else:
        ans = 1
    for i in range(1, N+1):
        ans *= i
        ans %= 1000000007
    for i in range(1, M+1):
        ans *= i
        ans %= 1000000007

print(ans)


Measured memory_bytes: 3060
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(int i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N = 2e5 + 2;
const int OO = 1e9 + 7;
using namespace std;
int main() {
    IO;
    ll a,b,c; cin>>a>>b>>c;
    ll d=(c-a-b);

    if(4*a*b<d*d && d>0)
        cout<<"Yes";
    else
        cout<<"No";

}


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

static int INFTY = (1<<21);
int n, M[100][100];
int d[100];

void bfs(int s) {
    queue<int> q;
    q.push(s);

    for(int i = 0; i < n; i++ ) d[i] = INFTY;
    d[s] = 0;
    int u;
    while ( !q.empty() ) {
        u = q.front();
        q.pop();
        for(int v = 0; v < n; v++) {
            if(M[u][v] == 0) continue;
            if(d[v] != INFTY) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for ( int i = 0; i < n; i++) {
        if (d[i] == INFTY) d[i] = -1;
        cout << i + 1 << " " << d[i] << endl;
    }
}

int main () {
    int u, k, v;
    cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    bfs(0);
    return 0;
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  map<int, int> mp;
  int n, a;
  cin >> n;
  rep(i,n-1)
  {
    cin >> a;
    mp[a]++;
  }
  for (int i = 1; i <= (int) (n); ++i) {
    cout << mp[i] << endl;
  }
  return 0;
}

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

using namespace std;

#define pan(i,n) for(int i=0;i<n;i++)
#define pans(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define INF 1000000007
#define PI 3.141592653
#define inf 100007
#define P pair<ll,ll>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

map<int ,int> m;
void fac(ll n){
    while(!(n/2)){
        n/=2;
        m[2]++;
    }
    for(int i=3;i<sqrt(n);i+=3){
        while(!(n/i))
            n/=i,m[i]++;
    }
    if(n>1) m[n]++;
}

int main(){
    ll x,a=0,b=0,ansx=0,ansy=0;
    cin>>x;
    // fac(x);
    // for(auto i : m){
    //     bool flag=false;
    //     for(int j=1;j<=i.second;j++){
    //         a=pow(i.first,j),b=x/(a);
    //         if((a-b)*(pow(a,4)+pow(b,4)+a*a*a*b+b*b*b*a+a*a*b*b)==x){
    //             flag=true;
    //             ansx=a,ansy=b;
    //             break;
    //         }
    //     }
    //     if(flag) break;
        
    // }
    for(int i=0;i<=2000;i++){
        bool flag=false;
        for(int j=-1000;j<=1000;j++){
            if(pow(i,5)-pow(j,5)==x){
                a=i,b=j;
                break;
            }
        }
    }
    cout<<a<<" "<<b;
}

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

namespace CSharpSample01
{

    
    
    class Program
    {

        const long MOD = 1000000007;

        
        static long Power(long m, long n)
        {
            m %= MOD;
            if (m == 1 || n == 1) return m;

            if(n % 2 == 0)
            {
                return Power(m * m, n / 2);
            }
            else
            {
                return (Power(m * m, (n - 1) / 2) * m) % MOD;
            }
        }



        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int m = int.Parse(input[0]);
            int n = int.Parse(input[1]);

            Console.WriteLine(Power(m, n));
        }
    }
}


Measured memory_bytes: 17960
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define of(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
const ll mod=1e9+7;
int main()
{
  IOS
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll k=0,f;
  while(1)
  {
    if(k%2==0)
      c=c-b;
    else
      a=a-d;
    k++;
    if(c<=0)
    {
      f=1;
      break;
    }
    if(a<=0)
    {
      f=0;
      break;
    }
  }
  if(f)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	int i, n;
	string tmp;
	map<string, int> input;
	vector<string> candidate;
	int candidate_num = 1;
	
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> tmp;
		if (input.find(tmp) == input.end())
			input[tmp] = 1;
		else
			input[tmp]++;
	}

	for (auto itr = input.begin(); itr != input.end(); itr++) {
		if (itr->second == candidate_num)
			candidate.push_back(itr->first);
		else if (itr->second > candidate_num) {
			candidate.erase(candidate.begin(), candidate.end());
			candidate.push_back(itr->first);
			candidate_num = itr->second;
		}
	}

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

	for (i = 0; i < candidate.size(); i++) 
		cout << candidate[i] << endl;

	return 0;
}


Measured memory_bytes: 26868
import java.lang.*;
import java.io.*;
import java.util.*;

class Main{
	public static void main(String args[]) throws Exception{
		FScanner sc=new FScanner();
		//Scanner sc=new Scanner(System.in);
		int n=sc.readInt();
		
		while(n!=111 && n!=222 && n!=333 && n!=444 && n!=555 && n!=666 && n!=777 && n!=888 && n!=999){
			n++;
			
		}
		
		System.out.println(n);
		
	}
	
	static void solve(int cur, int nx, int en, int hld){}

	static void disp(int[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
	
	static void disp(String[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%s ",data[i]);
		}
			System.out.println();
	}
	
	static void disp(long[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
	
	static class FScanner{
		BufferedReader read=null;
		StringTokenizer tok=null;
		Scanner sc;
		FScanner() throws FileNotFoundException{
			sc=new Scanner(System.in);
		}
		boolean hasNextLine(){
			boolean has=true;
			if(!sc.hasNextLine()){
				has=false;
			}
			return has;
		}
		int readInt(){
			String buf=sc.nextLine();
			return Integer.parseInt(buf);
		}
		long readLong(){
			long i=Long.parseLong(sc.nextLine());
			return i;
		}
		int[] readIntL(){
			String[] buf=sc.nextLine().split(" ");
			int[] num=new int[buf.length];
			for(int i=0; i<buf.length; i++){
				num[i]=Integer.parseInt(buf[i]);
			}
			return num;
		}
		
		String readString(){
			return sc.nextLine();
		}
		String[] readStringL(String dlm){
			String[] s=sc.nextLine().split(dlm);
			return s;
		}
	}
}


Measured memory_bytes: 25044
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<vector<int>>graph;
vector<int>depth;
int start;
void dfs(int v) {
	for (auto next : graph[v]) {
		if (depth[next] == 0 && next != start) {
			depth[next] = depth[v] + 1;
			dfs(next);
		}
	}
}
int main() {
	int n; cin >> n;
	graph = vector<vector<int>>(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		graph[a].push_back(b); graph[b].push_back(a);
	}

	depth = vector<int>(n);	start = 0;
	dfs(start);
	int best = 0; int how = 0;
	for (int i = 0; i < n; i++) {
		if (how < depth[i]) {
			how = depth[i];
			best = i;
		}
	}

	depth = vector<int>(n);	start = best;
	dfs(start);
	how = 0;
	for (int i = 0; i < n; i++) how = max(how, depth[i]);

	cout << (how % 3 == 1 ? "Second" : "First") << endl;
	return 0;
}

Measured memory_bytes: 18688
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    int n, a;
    cin >> n >> a;

    int x[50];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        x[i] -= a;
    }

    // i枚目までを使ってkを作る通り数
    int s[2] = {};
    int64_t dp[2][5001] = {};
    int64_t *p[2];
    for (int i = 0; i < 2; i++) {
        p[i] = &dp[i][2500];
    }
    p[0][0] = 1;
    for (int i = 0; i < n; i++) {
        s[x[i] > 0] += x[i];
        for (int k = s[0]; k <= s[1]; k++) {
            p[1][k] = p[0][k] + p[0][k - x[i]];
        }
        swap(p[0], p[1]);
    }

    cout << p[0][0] - 1 << endl;

    return 0;
}

Measured memory_bytes: 384
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int D,c[27],s[366][27];
int t[27];
int lastt[27];
int main(){
	srand(time(NULL));
	std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
	int nowtime=0;
	int TIMEMAX=1950;
	nowtime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start).count();

	scan(D);
	rep(i,26) scan(c[i]);
	rep(i,D){
		rep(j,26){
			scan(s[i][j]);
		}
	}
	rep(i,26) lastt[i]=-1;
	int pt=0;
	rep(i,D){
		scan(t[i]); t[i]--;
		pt+=s[i][t[i]];
		lastt[t[i]]=i;
		rep(j,26){
			pt-=c[j]*(i-lastt[j]);
		}
		prin(pt);
	}
	return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
#include<valarray>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	int N;

	std::cin >> N ;

	std::vector<int > ax;
	std::vector<int > bx;
	ax.resize(N + 1);
	bx.resize(N + 1);

	std::vector<int > ansx;

	for (int i = 0; i < N; i++) 
	{
		std::cin >> ax[i+1];
	}

	for (int i = N; i > 0; i--)
	{
		int tmpball = 0;
		int j = 1;
		while (1)
		{
			tmpball += bx[i * j];
			j++;
			if ( (i * j) > N) break;
		}

		tmpball = tmpball & 0x1;
		if ((ax[i] == 0) && (tmpball == 0))
		{

		}
		else if ((ax[i] == 0) && (tmpball == 1))
		{
			bx[i] = 1;
			ansx.push_back(i);
		}
		else if ((ax[i] == 1) && (tmpball == 0))
		{
			bx[i] = 1;
			ansx.push_back(i);
		}
		else if ((ax[i] == 1) && (tmpball == 1))
		{

		}
	}

	std::cout << ansx.size() << std::endl;
	for (int k = ansx.size() - 1; k >= 0; k--)
	{
		std::cout << ansx[k];
		if (k != 0)
		{
			std::cout << " ";
		}
		else
		{
			std::cout <<std::endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<int> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    string s, t;
    cin >> s >> t;
    int S[27], T[27];
    int col[27];
    int scol[27];
    REP(i, 26){
        S[i] = 0;
        T[i] = 0;
        col[i] = -1;
        scol[i] = -1;
    }
    REP(i, s.size()){
        int a = s[i] - 'a';
        int b = t[i] - 'a';
        if(col[a] == -1){
            col[a] = b;
        }else if(col[a] != -1 && col[a] != b){
            print("No");
            return 0;
        }
        if(scol[b] == -1){
            scol[b] = a;
        }else if(scol[b] != -1 && scol[b] != a){
            print("No");
            return 0;
        }
    }
    print("Yes");
    return 0;

}

Measured memory_bytes: 776
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int M = int.Parse(str[1]);
        int[] d = new int[M];
        str = Console.ReadLine().Split(' ');
        for(int i=0;i<M;i++){
            d[i] = int.Parse(str[i]);
        }
        int[] DP = new int[N+1];
        for(int i=0;i<=N;i++){
            DP[i] = i;
        }
        for(int i=0;i<M;i++){
            int m = d[i];
            for(int j=m;j<=N;j++){
                DP[j] = Math.Min(DP[j],DP[j-m]+1);
            }
        }
        sb.Append(DP[N]+"\n");
    }
}

Measured memory_bytes: 9280
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define all(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define pb push_back
#define inin(x) int x; cin>>x;
#define ll long long
#define pb push_back

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

struct Calendar
{
	long long year;
	long long month;
	long long day;
	long long dat[2][13];
	Calendar(long long y, long long m, long long d)
	{
		year = y;
		month = m;
		day = d;
		dat[0][0] = dat[1][0] = 0;
		dat[0][1] = dat[1][1] = 31;
		dat[0][2] = dat[1][2] = 28;
		dat[0][3] = dat[1][3] = 31;
		dat[0][4] = dat[1][4] = 30;
		dat[0][5] = dat[1][5] = 31;
		dat[0][6] = dat[1][6] = 30;
		dat[0][7] = dat[1][7] = 31;
		dat[0][8] = dat[1][8] = 31;
		dat[0][9] = dat[1][9] = 30;
		dat[0][10] = dat[1][10] = 31;
		dat[0][11] = dat[1][11] = 30;
		dat[0][12] = dat[1][12] = 31;
		dat[1][2] = 29;
	}
	int uruu()
	{
		if (year % 4 == 0)
		{
			if (year % 400 != 0 && year % 100 == 0)
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		return 0;
	}
	int uruu(long long y)
	{
		if (y % 4 == 0)
		{
			if (y % 400 != 0 && y % 100 == 0)
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		return 0;
	}
	long long pday(long long d)
	{
		day += d;
		for (;; month++)
		{
			if (month >= 13)
			{
				year++;
				month = 1;
			}

			if (dat[uruu()][month] < day)
			{
				day -= dat[uruu()][month];
			}
			else
			{
				break;
			}
		}
		pmonth(0);
		return d;
	}
	long long pmonth(long long m)
	{
		month += m;
		for (;; year++)
		{
			if (month > 12)
			{
				month -= 12;
			}
			else
			{
				break;
			}
		}
		return m;
	}
	long long pyear(long long y)
	{
		year += y;
		return y;
	}
	long long dif(Calendar c)
	{
		long long ans = 0;
		Calendar a(year, month, day);
		ans -= a.day;
		ans += c.day;
		a.day = 0;
		c.day = 0;
		for (; a.month >= 1; a.month--)
		{
			ans -= dat[a.uruu()][a.month - 1];
		}
		for (; c.month >= 1; c.month--)
		{
			ans += dat[c.uruu()][c.month - 1];
		}
		for (; a.year != c.year; a.year++)
		{
			ans += 365;
			if (a.uruu())ans++;
		}
		return ans;
	}


};

int n;
vector<unsigned long long int> seq;
unsigned long long memo[21][120];
int obj;
unsigned long long dp(int num,int now)
{
	unsigned long long ans = 0;
	if (num > 20 || num < 0)return 0;
	if (memo[num][now] != -1)return memo[num][now];
	if (now == n&&num==obj)return 1;
	if (now == n)return 0;
	ans += dp(num + seq[now], now + 1);
	ans += dp(num - seq[now], now + 1);
	return memo[num][now] = ans;
}

int main()
{
	memset(memo, -1, sizeof(memo));
	cin >> n;
	n--;
	rep(i, n)
	{
		unsigned long long int a;
		cin >> a;
		seq.pb(a);
	}
	cin >> obj;
	cout << dp(seq[0], 1) << endl;
}

Measured memory_bytes: 1244
#include <stdio.h>

int main(){
        int n, tmp;
        scanf("%d\n", &n);
        int A[n];
        for(int i=0;i<n;i++){
                scanf("%d\n", &A[i]);
        }
        int ans = 0;
        for(int i=0;i<n;i++){
                int flag = 0;
                for(int j=i+1;j<n;j++){
                        if(A[i]==A[j]){
                                flag = 1;
                                break;
                        }
                }
                if(flag==0){ans++;}
        }
        printf("%d\n", ans);
        return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

ll N, M;
vector<vector<ll > > G;
vector<ll > cost;
priority_queue<ll > c_que;
ll ans = 0;

vector<ll > bfs(ll start){
    start;
    //距離を初期化
    vector<ll > dist(G.size(), -1);
    queue<ll > que;

    //始点start 初期化
    dist[start] = 0;
    cost[start] = c_que.top();
    c_que.pop();
    que.push(start);


    while(!que.empty()){
        ll from = que.front();
        que.pop();

        for(ll i = 0; i < G[from].size(); i++){
            ll to = G[from][i];
            //すでに探査済み
            if(dist[to] != -1) continue;

            dist[to] = dist[from] + 1;
            cost[to] = c_que.top();
            ans += min(cost[from], cost[to]);
            que.push(to);
            c_que.pop();
        }
    }

    return dist;

}
int main(){


    cin >> N;

    G.assign(N, vector<ll >());
    cost.assign(N, -1);

    for(ll i = 0; i < N - 1; i++){
        //入力
        ll u, v;
        cin >> u >> v;
        u--;
        v--;
        //双方向に貼りましょうね
        G[u].push_back(v);
        G[v].push_back(u);
    }

    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        c_que.push(t);
    }
    //cout << "a" << endl;
    vector<ll > dist = bfs(0);

    cout << ans << endl;
    for(ll i = 0; i < N; i++){
        cout << (i ? " " : "") << cost[i];
    }
    cout << endl;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n = in();
    vint x = in(n);

    ll ans = LINF;
    rep(i, 101)
    {
        ll tmp = 0;
        rep(j, n)
        {
            tmp += (x[j] - i) * (x[j] - i);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

signed main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
using namespace std;

int main()
{
    string n, m="";
    cin >> n;
    for(int i=0; i<n.size(); i++){
        if(n[i]=='1') m+="9";
        else if(n[i]=='9') m+="1";
        else m+=n[i];
    }
    cout << m;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VD vector<long double>

int main(){
    long double N, K;
    cin >> N >> K;
    VD a(N);
    VD b(N,0);
    rep(i,0,N) cin >> a[i];
    rep(i,0,K){
        b[K-1] += (long double)(a[i]/K);
        //cout << b[K-1] <<endl;
    }
    
    rep(i,K-1,N-1){
        b[i+1] = b[i];
        b[i+1] += (long double)((a[i+1] - a[i-(K-1)])/K);
      	//cout << b[i+1] << " " << b[i] << " "; 
        if(b[i+1] > b[i]) cout<<"Yes"<<endl;  
        else cout<<"No"<<endl;  
    }
    return 0;
}

Measured memory_bytes: 9592
#include<stdio.h>

int main()
{
	unsigned long long a,b,i,j,t=2018,m;
	scanf("%ld%ld",&a,&b);
	for(i=a;i<=b-1;i++)
	{
		for(j=i+1;j<=b;j++)
		{
		m=i*j%2019;
		if(m<t)
		t=m;
		if(t==0)
		break;	
		}
		if(t==0)
		break;
	}
	printf("%ld",t);
 }

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

using namespace std;

const int N = 22, oo = 1000000007;
int a[N][N]; int n;

long long f[N][2<<N];

vector<int> states[N];

int main()
{
    cin >> n;
    for (int i=1; i<=n; i++)
    for (int j=1; j<=n; j++)
        cin >> a[i][j];
    f[0][0] = 1;

    for (int i=0; i<(2<<n); i+=2)
    {
        states[__builtin_popcount(i)].push_back(i);
    }

    for (int i=1; i<=n; i++)
    {
        for (int x: states[i])
        {
            for (int j=1; j<=n; j++)
            {
                if (a[i][j] && ((x >> j) & 1))
                {
                    f[i][x] = (f[i][x] + f[i-1][x^(1 << j)]) % oo;
                }
            }
        }
    }

    cout << f[n][(2<<n)-2];
    return 0;
}


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

#define SZ(v) ((int)(v).size())
using ll = long long;

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

	string T;
	cin >> T;
	int len = SZ(T);
	vector<vector<int>> dp(len, vector<int>(2));

	for (int i(len-1); i >= 0; --i)
		for (int j(0); j < 2; ++j)
		{
			// 0 : P, 1 : D
			if (T[i] != '?' and ((!j and T[i] == 'D') or (j and T[i] == 'P')))
			{
				dp[i][j] = -1e9;
				continue;
			}
			if (i == len-1)
				dp[i][j] = j;
			else
				dp[i][j] = max(dp[i+1][0] + j, dp[i+1][1] + 1);
		}
	int which = (dp[0][0] > dp[0][1] ? 0 : 1);
	for (int i(0); i < len; ++i)
	{
		cout << (which ? 'D' : 'P');
		if (i == len -1 )
			break;
		if (dp[i+1][0] + which > dp[i+1][1] + 1)
			which = 0;
		else
			which = 1;
	}
	cout << endl;

	//cout << max(dp[0][0], dp[0][1]) << endl;
}


Measured memory_bytes: 14404
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
ans = 0
def gcd(a,b):
  if (b == 0):
    return a
  return gcd(b,a%b)

def lcm(a,b):
  return a * b // gcd(a,b)

def get_lcm(numbers):
  return reduce(lcm,numbers)
l = get_lcm(a) - 1
for i in range(n):
  ans += l % a[i]
print(ans)

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

using namespace std;


void test_case(){	
	int n,k;
	cin >> n >> k;
	int val[n+1];
	for (int i=0;i<n;i++) {
		cin >> val[i];
	}
	sort (val,val+n);
	int sum =0;
	for (int i=0;i<k;i++) {
		sum += val[i];
	}
	cout << sum << endl;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	int t;
//	cin >> t;
//	while (t--)
	test_case();
	return 0;
}

Measured memory_bytes: 3632
#実験用の写経
N = int(input())
g = {i: [] for i in range(N)}
for i in range(N - 1):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
c = list(map(int, input().split()))
c.sort()
print(sum(c[:-1]))
nums = [0] * N
stack = [0]
while stack:
    d = stack.pop()
    nums[d] = c.pop()
    for node in g[d]:
        if nums[node] == 0:
            stack.append(node)
print(' '.join(map(str, nums)))


Measured memory_bytes: 49368
use std::cmp::max;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        a:usize,
        b:usize,
        c:usize,
        d:usize,
    }
    let mut A = a * b;
    let mut B = c * d;
    println!("{}", max(A, B));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
const int N=2e5+7;
typedef long long ll;
int a[N],n,m,b[N];
ll mi,now=0,en[N];
int main(){
	scanf("%d%d",&m,&n);
	rep(i,1,m)scanf("%d",&b[i]);
	rep(i,1,m-1){
		int x,y;
		
		x=b[i],y=b[i+1];
		if(x==y)continue;
		int kk=y;
		
		if(x>y)y+=n;
		a[x+1]++,a[y]--;
		en[kk]+=y-x-1;
		
		now+=min(y-x,kk);
	}
	mi=now;
	rep(i,1,2*n)a[i]+=a[i-1];
	rep(i,n+1,2*n)a[i-n]+=a[i];
	
	rep(i,1,n){
		mi=min(mi,now);
		now-=a[i];
		now+=en[i];
	}
	printf("%lld\n",mi);
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    while(cin>>n){
        map<string,int>m;
        string str;
        int cnt=0;
        for(int i=0;i<n;i++){
            cin>>str;
            m[str]++;
            if(m[str]>cnt)cnt=m[str];
        }
        map<string,int>::iterator it;
        for(it=m.begin();it!=m.end();it++){
            if(it->second==cnt)cout<<it->first<<endl;
        }
    }
	return 0;
}


Measured memory_bytes: 25216
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.function.Function;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int[] A = in.Int(N);
            int[] B = in.Int(N);
            int[] C = in.Int(N);
            Arrays.sort(A);
            Arrays.sort(B);
            Arrays.sort(C);

            long ans = 0;
            for (int i = 0; i < N; i++) {
                int f = B[i];
                long ia = nibu(N, mid -> f <= A[mid]);
                long ic = nibu(N, mid -> f < C[mid]);
                ans += ia * (N - ic);
            }
            out.println(ans);
        }

        private int nibu(int n, Function<Integer, Boolean> check) {
            int ng = -1, ok = n;
            while (Math.abs(ok - ng) > 1) {
                int mid = (ng + ok) / 2;
                boolean f = check.apply(mid);
                if (!f) {
                    ng = mid;
                } else {
                    ok = mid;
                }
            }
            return ok;
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}



Measured memory_bytes: 69784
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	B := make([]int, N)
	C := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&(A[i]))
		fmt.Scan(&(B[i]))
		fmt.Scan(&(C[i]))
	}

	// 最後にa, b, cを選んだ場合のベストスコア
	dp_a := make([]int, N)
	dp_b := make([]int, N)
	dp_c := make([]int, N)

	for i := 0; i < N; i++ {
		if i == 0 {
			dp_a[i] = A[i]
			dp_b[i] = B[i]
			dp_c[i] = C[i]
			continue
		}

		dp_a[i] = int(math.Max(float64(dp_b[i-1]), float64(dp_c[i-1]))) + A[i]
		dp_b[i] = int(math.Max(float64(dp_a[i-1]), float64(dp_c[i-1]))) + B[i]
		dp_c[i] = int(math.Max(float64(dp_a[i-1]), float64(dp_b[i-1]))) + C[i]
	}

	max := int(math.Max(float64(dp_a[N-1]), float64(dp_b[N-1])))
	max = int(math.Max(float64(max), float64(dp_c[N-1])))
	fmt.Println(max)
}


Measured memory_bytes: 7808
import time
startTimeProblem=time.time()

import fileinput, sys, itertools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

A, P = In.ints()

P += 3*A





print(P//2)


######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Measured memory_bytes: 38508
n = int(input())

taro = 0
hanako = 0
for ni in range(n):
    t, h = input().split()
    
    if t < h:
        hanako += 3
    elif t > h:
        taro += 3
    else:
        hanako += 1
        taro += 1
        
print(taro, hanako)

Measured memory_bytes: 7644
#include <iostream>
using namespace std;
int a[1001],b[1001];
int main()
{
	while(1)
	{
		int N,M; cin >> N >> M ;
		if(N==0 && M==0) break;
		for(int i=1;i<=N;i++) cin >> a[i];
		int cur=1; int cnt=0;
		for(int i=0;i<M;i++) cin >> b[i];
		for(int i=0;i<M;i++)
		{
			cur+=b[i]; cnt++;
			cur=cur+a[cur];
			if(cur>=N) break;
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 1168
n,d = gets.split(" ").map(&:to_i)
ary = []
while a = gets
    ary.push(a.split(" ").map(&:to_i))
end

i = 0
j = 1
count = 0
a = []
b = []

def point(a,b)
    result = []
    a.length.times do |i|
        distance = (a[i]-b[i])**2
        result.push(distance)
    end
    return result
end

def sum_point(result)
    sum = 0
    result.each do |a|
        sum = sum + a
    end
    return sum.to_i
end 

def detect_n_num(sum_point)
    sum_point = Math.sqrt(sum_point)
    if sum_point.to_f - sum_point.abs.to_i == 0
        return 1
    else
        return 0
    end
end

while i < ary.length do
    a = []
    d.times do |num|
        a.push(ary[i][num].to_i)
    end
    while j < ary.length do
        b = []
        d.times do |num|
            b.push(ary[j][num])
        end
        point = point(a,b)
        sum   = sum_point(point)
        count = count + detect_n_num(sum)
        j = j + 1
    end
    i = i + 1
    j = i + 1
end

puts count

Measured memory_bytes: 1788
from fractions import gcd
mod = 10**9+7
n = int(input())
a = list(map(int,input().split()))
ans = 0
l = 1
for i in a:
    l = l*i//gcd(l,i)
l %= mod
for i in a:
    ans = (ans +l*pow(i,mod-2,mod)) % mod
print(ans)

Measured memory_bytes: 67416
/*
 * Welcome to my code!
 * -------------------------------------------- *
 * author : lynmisakura(twitter : @andoreiji11)
 */

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

//Simple Array Input
#define SAI int n;cin >> n;vi a(n);ain(a)
//Simple Graph Input
#define SGI(m) for(int i=0;i<m;i++){int a,b;cin >> a >> b;g[--a].pb(--b);g[b].pb(a);}
//Simple Tree Input
#define STI SGI(n-1)

typedef long long ll;
typedef long long integer;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){
    for(int i=0;i<a.size();i++)cout << a[i] << (i < a.size()-1 ? ' ' : '\n');
}
long long gcd(long long a, long long b) {
  return b != 0 ? gcd(b, a % b) : a;
}
long long lcm(long long a, long long b) {
  return a * b / gcd(a, b);
}
// a x + b y = gcd(a, b)
long long extgcd(long long a, long long b, long long &x, long long &y) {
  long long g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

bool func(ll n,ll a,ll b){
  
  ll g1 = gcd(a , b);
  
  ll p = a * b / g1;
  ll q = (a + b) / g1;

  ll g2 = gcd(n , p);
  
  if(4LL * p - n * q == g2){
    cout << a << ' ' << b << ' ' << n * p / g2 << '\n';
    return true;
  }else return false;

}


int main(int argc, char const *argv[])
{
  long long n;cin >> n;
  for(ll a = 1;a <= 3500;a++){
    for(ll b = 1;b <= 3500;b++){
      if(func(n,a,b))return 0; 
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Math.*;
import java.util.*;
import java.math.*;
import java.text.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        BigDecimal x1 = sc.nextBigDecimal();
        BigDecimal y1 = sc.nextBigDecimal();
        BigDecimal x2 = sc.nextBigDecimal();
        BigDecimal y2 = sc.nextBigDecimal();
        BigDecimal distance = new BigDecimal(Math.sqrt(Math.pow(Math.abs(x1.doubleValue()-x2.doubleValue()),2) 
                                                     + Math.pow(Math.abs(y1.doubleValue()-y2.doubleValue()),2)));
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(8);
        nf.setGroupingUsed(false);
        System.out.println(nf.format(distance));
    }
}

Measured memory_bytes: 19084