akhauriyash/Code-Regression huggingface dataset:
//Mitesh Agrawal
//Dinic's algorithm implementation adapted from -> http://www.geeksforgeeks.org/dinics-algorithm-maximum-flow/
#include <bits/stdc++.h>
using namespace std;

#define MAXN 1000005
#define INF 1e9

struct Edge
{int v,flow,C,rev;};
 
class Graph{
    int V; 
    int *level ; 
    vector< Edge > *adj;
public :
    Graph(int V)
    {
        adj = new vector<Edge>[V];
        this->V = V;
        level = new int[V];
    }
 
    void addEdge(int u, int v, int C)
    {
        Edge a = {v, 0, C, (int)adj[v].size()};
 
        Edge b = {u, 0, 0, (int)adj[u].size()};
 
        adj[u].push_back(a);
        adj[v].push_back(b); 
    }
 
    bool BFS(int s, int t);
    int sendFlow(int s, int flow, int t, int ptr[]);
    int DinicMaxflow(int s, int t);
};
 
bool Graph::BFS(int s, int t){
    for (int i = 0 ; i < V ; i++)
        level[i] = -1;
 
    level[s] = 0;  
 
    list< int > q;
    q.push_back(s);
 
    vector<Edge>::iterator i ;
    while (!q.empty())
    {
        int u = q.front();
        q.pop_front();
        for (i = adj[u].begin(); i != adj[u].end(); i++)
        {
            Edge &e = *i;
            if (level[e.v] < 0  && e.flow < e.C)
            {
                level[e.v] = level[u] + 1;
 
                q.push_back(e.v);
            }
        }
    }
 
    return level[t] < 0 ? false : true ;
}
 
int Graph::sendFlow(int u, int flow, int t, int start[]){
    if (u == t)
        return flow;
 
    for (  ; start[u] < adj[u].size(); start[u]++)
    {
        Edge &e = adj[u][start[u]]; 
                                     
        if (level[e.v] == level[u]+1 && e.flow < e.C)
        {
            int curr_flow = min(flow, e.C - e.flow);
 
            int temp_flow = sendFlow(e.v, curr_flow, t, start);
 
            if (temp_flow > 0)
            {
                e.flow += temp_flow;
 
                adj[e.v][e.rev].flow -= temp_flow;
                return temp_flow;
            }
        }
    }
 
    return 0;
}
 
int Graph::DinicMaxflow(int s, int t){
    if (s == t)
        return -1;
    int total = 0;  

    while (BFS(s, t) == true)
    {
        int *start = new int[V+1];
 
        while (int flow = sendFlow(s, INT_MAX, t, start))
 
            total += flow;
    }
 
    return total;
}

string s[105]; 

int main()
{
	int i,j,n,m;
	scanf("%d %d", &n, &m);
	Graph g(n + m + 2);
	for(i = 1; i <= n; i++)
		cin >> s[i];
	for(i = 1; i <= n; i++)
		for(j = 0; j < m; j++){
			if(s[i][j] == 'S'){
				g.addEdge(0, i, INF);
				g.addEdge(0, j + 1 + n, INF);
			}
			else if(s[i][j] == 'T'){
				g.addEdge(i, n + m + 1, INF);
				g.addEdge(j + 1 + n, n + m + 1, INF);
			}
			else if(s[i][j] == 'o'){
				g.addEdge(i, j + 1 + n, 1);
				g.addEdge(j + 1 + n, i, 1);
			}
		}
	int flow = g.DinicMaxflow(0, n + m + 1);
	printf("%d\n", (flow >= MAXN) ? -1 : flow);
    return 0;
}




Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    ll k; cin >> k;
    vector<int> a(n);
    vector<int> f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(RALL(f));
    sort(ALL(a));
    ll l = -1, r = 1e12;
    while(l+1<r) {
        ll c = (l+r)/2;
        bool ok = [&]{
            ll s = 0;
            rep(i,n) {
                s += max((ll)0,a[i]-c/f[i]);
            }
            return s <= k;
        }();
        if(ok) r = c; else l = c;
    }
    cout << r << endl;
    return 0;
}

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

using lint = long long;

int result, endx, endy;
vector<int> xd = {0, 1, 0, -1};
vector<int> yd = {1, 0, -1, 0};

void bfs(int l, int c, int n, int m, vector<vector<char>> &grid) {
	if (grid[l][c] == '#') return;
	vector<vector<int>> dist(n, vector<int> (m, -1));
	dist[l][c] = 0;
	vector<pair<int, int>> q;
	q.push_back({l, c});
	for (int i = 0; i < q.size(); ++i) {
		pair<int,int> x = q[i];
		for (int i = 0; i < 4; ++i) {
			pair<int, int> y = {x.first+xd[i], x.second+yd[i]};
			if (y.first < 0 || y.first > n-1 || y.second < 0 || y.second > m-1 || grid[y.first][y.second] == '#') continue;
			if (dist[y.first][y.second] == -1 && grid[y.first][y.second] == '.') {
				dist[y.first][y.second] = dist[x.first][x.second]+ 1;
                endx = y.first; endy = y.second;
                result = max(result, dist[y.first][y.second]);
				q.push_back(y);
			}
		}
	}	
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int xstart, ystart;
	int n, m;
	cin >> n >> m;
	vector<vector<char>> grid(n, vector<char>(m));
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j) 
			cin >> grid[i][j];
		
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (grid[i][j] == '.') {
				bfs(i, j, n, m, grid);
			}
		}
	}
    // bfs(xstart, ystart, n, m, grid);
    // bfs(endx, endy, n, m, grid);
	cout << result << '\n';
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String[] args) throws IOException{
    long num1,num2,kouyakusu=0;
    String str="";
    BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));

    while((str=buf.readLine()) != null){
      num1 = Long.parseLong(str.substring(0, str.indexOf(" ")));
      num2 = Long.parseLong(str.substring(str.indexOf(" ")+1, str.length()));
      kouyakusu = kouyakusu(num1,num2);
      System.out.println(kouyakusu+" "+num1*num2/kouyakusu);
    }
  }
  public static long kouyakusu(long num1,long num2){
    long x = (num1>num2)? num1 : num2;
    long y = (num1>num2)? num2 : num1;
    long tmp = 0;
    while((tmp = x%y)!=0){
      x = y;
      y = tmp;
    }
    return y;
  }



}

Measured memory_bytes: 24168
#include<bits/stdc++.h>
const double PI=3.14159265358979323846;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
int main(void){
    int r;cin>>r;
    co(2*r*PI);
}



Measured memory_bytes: 3784
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define SIZE 20
////////////////// mapで持っておくと前40文字だけ見る！なんてことは必要ない(らしい)ので書いてみること！！！！！！！！！！！！！！！
int main(){
    int N; cin>>N;
    int A[200000];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    bool trap=false;
    for(int i=1;i<N;i++){
        if(A[i]<=A[i-1]){
            trap=true;
            break;
        }
    }
    if(N==1){
        trap=false;
    }
    if(trap){//2文字以上必要
        int low=1;//不可能
        int high=200001;//可能
        //上60文字くらい見れば十分：ほんと？？？？？？？？？？？？？？
        while(low<high){
            int mid=(low+high)/2;
            //cout<<low<<' '<<mid<<' '<<high<<endl;
            if(low==mid){
                break;
            }
            //midという文字数で可能かどうか判定
            int mae[SIZE]={};
            bool flag=true;//判定をboolで保持
            for(int i=1;i<N;i++){
                bool need=false;//繰り上げの必要性
                if(A[i]==A[i-1] && A[i]<SIZE){
                    mae[A[i]]++;
                    need=true;
                }else if(A[i]<A[i-1] && A[i]<SIZE){
                    mae[A[i]]++;
                    need=true;
                    for(int j=A[i]+1;j<SIZE;j++){
                        mae[j]=0;
                    }
                }
                //繰り上げ処理
                if(need){
                    for(int j=A[i];j>0;j--){
                        if(mae[j]==mid){
                            mae[j]=0;
                            mae[j-1]++;
                        }
                    }
                }
                if(mae[0]>0){
                    flag=false;
                    break;
                }
            }
            if(flag){
                high=mid;
            }else{
                low=mid;
            }
        }
        cout<<high<<endl;
    }else{
        cout<<1<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll k, a, b;std::cin >> k >> a >> b;
  if(b-a<=2||k<a-1){
    std::cout << k+1 << '\n';
    return 0;
  }
  ll ans = 1;
  k-=a-1,ans=a;
  if(k%2==1) k--, ans++;
  ll t = k/2;
  ans += t*(b-a);
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;int main(){int a,b,c,d,e,f,g;int h[13]={0,0,31,59,90,120,151,181,212,243,273,304,334};while(1){cin>>a>>b>>c>>d>>e>>f;if(a==-1)break;g=f-c+h[e]-h[b]+(d-a)*365;if(e<3)d--;if(b<3)a--;g+=d/4-a/4-d/100+a/100+d/400-a/400;cout<<g<<endl;}return 0;}

Measured memory_bytes: 0
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt2() (int, int) {
	return nextInt(), nextInt()
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, _ := nextInt2()
	a := nextInts(n)

	// max[i]: i以後の街で最高のりんごの値段
	max := make([]int, n)
	max[n-1] = a[n-1]
	for i := n - 2; i >= 0; i-- {
		max[i] = max[i+1]
		if a[i] > max[i] {
			max[i] = a[i]
		}
	}
	// profit[i]: iでりんごを買ったとき，得られる利益の最大値
	profit := make([]int, n)
	for i := 0; i < n; i++ {
		profit[i] = max[i] - a[i]
	}

	m := map[int]int{}
	maxProfit := -1
	for _, p := range profit {
		m[p]++
		if p > maxProfit {
			maxProfit = p
		}
	}

	puts(m[maxProfit])
}


Measured memory_bytes: 7936
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {

		Scanner sc = new Scanner(System.in);
		String A =  sc.next();
		String ans = "ABC";
		
		if(A.equals(ans)) {
			ans = "ARC";
		}
		
		System.out.println(ans);
	}



}



Measured memory_bytes: 26836
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <bitset>
#include <string>
using namespace std;

int main()
{
    double n;
    while(cin >> n, n >= 0){
        int a = n;
        double b = n - a;
        if(a > 255){
            cout << "NA" << endl;
            continue;
        }
        
        string ans(bitset<8>(a).to_string());
        ans.push_back('.');
        for(int i = 0; i < 4; ++i){
            b *= 2;
            ans.push_back('0' + (int)b);
            b -= (int)b;
        }
        if(b != 0){
            cout << "NA" << endl;
            continue;
        } else {
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 1228
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var a = sc.nextInt();
		var b = sc.nextInt();
		var c = sc.nextInt();
		var d = sc.nextInt();
		sc.close();

		var tc = Math.ceil((double)c / b);
		var ac = Math.ceil((double)a / d);

		System.out.println(tc <= ac ? "Yes" : "No");
	}
}

Measured memory_bytes: 35820
a,b,c,k = map(int, input().split())
import sys
ans=0
k1 = k-a
if k1<=0:
    print(k)
    sys.exit()
else:
    ans+=a

k2 = k1-b
if k2<=0:
    print(ans)
    sys.exit()
else:
    ans=ans

print(ans-k2)

Measured memory_bytes: 9192
//============================================================================
// Name        : Hello5.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
int n;
string s;
cin>>n;
cin>>s;
rep(i,s.size()){
	s[i]=(s[i]-'A'+n)%26+'A';
}
cout<<s<<endl;
	  return 0;
	}





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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;


void solve()
{
  int n,m,x;
  cin >> n >> m >> x;
  int c[n];
  int a[n][m];
  for(int i=0;i<n;i++)
  {
    cin >> c[i];
    for(int j=0;j<m;j++)
    {
      cin >> a[i][j];
    }
  }
  int maxPrice = 12*100005;
  int ans = maxPrice;
  for(int mask = 0;mask<(1<<n);mask++)
  {
    int curans = 0;
    int skl[m]={0};
    for(int i=0;i<n;i++)
    {
      if(mask & (1 << i))
      {
        curans+=c[i];
        for(int j=0;j<m;j++)
        {
          skl[j]+=a[i][j];
        }
      }
    }
    bool ok = true;
    for(int as : skl)
    {
      if(as < x)
      {
        ok = false;
        break;
      }
    }
    if(!ok) continue;
    ans = min(ans,curans);
  }
  if(ans == maxPrice)
  {
    cout << -1;
  }
  else
  {
    cout << ans;
  }
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


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

typedef long long int ll;
ll a[100001],b[100001];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i];
	ll now=0;
	for(int i=n;i>=1;i--){
		if((a[i]+now)%b[i]==0)	continue;
		ll d=((a[i]+now)/b[i]+1)*b[i]-a[i]-now;
		now+=d;
	}	
	cout<<now<<endl;
}


Measured memory_bytes: 1792
# coding: utf-8
# Your code here!

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

c=0
for m in range(1,M+1):
    for d in range(1,D+1):
        if d>=10:
            t=str(d)
            if int(t[0])>1 and int(t[1])>1 and int(t[0])*int(t[1]) == m:
                c+=1

print(c)



Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();

		int start = a+b;
		if(start >= 24){
			start -= 24;
		}
		System.out.println(start);
	}
}


Measured memory_bytes: 23252
#include <iostream>
using namespace std;
int main(void){
    long long N,A,B,C,D,a,b,i;
    string S;
    cin>>N>>A>>B>>C>>D>>S;
    a=1;
    for(i=A;i<C-2;i++){
        if(S[i]=='#'&&S[i+1]=='#'){
            a=0;
        }
    }
    for(i=B;i<D-2;i++){
        if(S[i]=='#'&&S[i+1]=='#'){
            a=0;
        }
    }
    b=0;
    if(C>D){
        for(i=B-1;i<D;i++){
            if(S[i-1]=='.'&&S[i]=='.'&&S[i+1]=='.'){
                b=1;
            }
        }
    }else{
        b=1;
    }
    if(a*b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 640
fun main(args:Array<String>?): Unit {
    while(true){
        val (w, h) = readLine()!!.trim().split(' ').map(String::toInt)
        if (w == 0 && h == 0) return
        println(solve(w, h))
    }
}
fun solve(w: Int, h: Int): Int {
    val mod = 100000
    class State(val northToSouth: Int, val westToEast: Int, val northToEast: Int, val westToSouth: Int) {
        fun sum(): Int = northToSouth + northToEast + westToEast + westToSouth
    }
    val memo = Array(h){Array(w){State(-1, -1,-1,-1)}}
    memo[0][0] = State(1, 1, 0, 0)
    fun sub(x: Int, y: Int): State {
        return if (x < 0 || y < 0) State(0, 0, 0, 0)
        else {
            if (memo[y][x].sum() < 0){
                val north = sub(x, y - 1)
                val east = sub(x - 1, y)
                memo[y][x] = State((north.northToSouth + north.westToSouth) % mod, (east.westToEast + east.northToEast) % mod, north.northToSouth, east.westToEast)
            }
            memo[y][x]
        }
    }
    return (sub(w - 2, h - 1).northToEast + sub(w - 2, h - 1).westToEast + sub(w - 1, h - 2).northToSouth + sub(w - 1, h - 2).westToSouth) % mod
}


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

int main(){
  int n;cin>>n;
  int m = n+1;
  int ans = 0;
  for(int i = 0; i < n; i++){
    int t; cin>>t;
     if(t<m){
       ans++;
       m=t;
     }
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){
	
	long long n,s;
	cin>>n>>s;
	
	for(long long i=2;i*i<=n;i++){
		long long a = n;
		long long sum = 0;
		while(a!=0){
			sum+=a%i;
			a/=i;
		}
		if(sum==s){
			cout<<i<<endl;
			return 0;
		}
	}
	long long X = n-s;
	
	long long ans = -1;
	for(long long k = 1;k*k <= X;k++){
		
		if(X%k!=0)continue;
		
		long long b = X/k+1;
		
		if(k>=b)continue;
		
		long long c = s-k;

		if(c<0||c>=b)continue;
		
		if(ans==-1)ans=b;
		else ans=min(ans,b);
		
		
	}
	
	if(ans==-1&&n==s)ans = n+1;
	
	cout<<ans<<endl;
	
	
	return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pvec(v) for(auto e: v) cout << e << " ";
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i, a, b) for(int i = (a); i<(b); ++i)
#define pb push_back
#define INF 1000000005
#define MOD 1000000007
#define all(v) v.begin(), v.end()

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

ll power(ll x, ll y, ll p = MOD){  
    ll res = 1LL; 
    x = x % p;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1LL)  
            res = (res*x) % p;
        y = y>>1LL; 
        x = (x*x) % p;  
    }  
    return res;  
}  

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

	ll s[n];
	for(int i = 0; i<n; ++i) cin >> s[i];
	sort(s, s + n);

	int cnt = 0;
	for(int i = 0; i<n - 2; ++i) {
		for(int j = i + 1; j<n - 1; ++j) {
			for(int k = j + 1; k<n; ++k) {
				if((s[i] + s[j] > s[k]) && (s[i] != s[j] && s[j] != s[k] && s[k] != s[i])) {
					++cnt;
				}
			}
		}
	}

	cout << cnt << endl;
	return 0;
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
11011010001011
*/

int main()
{
  string s;
  cin >> s;
  int n = s.size();

  vi cnt(2);
  rep(i, n){
    if(s[i] == '0'){
      cnt[0]++;
    }else{
      cnt[1]++;
    }
  }
  
  cout << min(cnt[0], cnt[1])*2 << endl;

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
int main ()
{
	int arr[100];
	int max=0;
	int tanda;
	for(int x=1; x<=3; x++)
	{
		scanf("%d",&arr[x]);
		if(arr[x]>max)
		{
			max=arr[x];
			tanda=x;
		}
	}
	int multp;
	scanf("%d",&multp);
	multp=pow(2,multp);
	int total=0;
	
	for(int x=1; x<=3; x++)
	{
		if(x!=tanda)
			total=total+arr[x];
	}
	total=total+multp*max;
	printf("%d\n",total);
	
	
}

Measured memory_bytes: 128
/*
ID: richard124
PROB: kimbits
LANG: C++11
*/


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <chrono>
#include <algorithm>
#include <bitset>

using namespace std;
using namespace std::chrono;

typedef pair<int, int> pii;
#define pb push_back;

int N;

int s_n(int x) {
    int sum = 0;
    while (x > 0) {
        int lastdigit = x%10;
        sum += lastdigit;
        x /= 10;
    }
    return sum;
}

int main() {
	high_resolution_clock::time_point t1 = high_resolution_clock::now();
	
	cin >> N;
	int s = s_n(N);
	if (N%s == 0) {
	    cout << "Yes";
	}
	else {
	    cout << "No";
	}

	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 2*1e5;
const int mod = 1e9+7;

vvll W;
ll w_min;
int N, w_upper;

ll dfs(int n, int value, int sum, vint &x) {
    if (n == 3) {
        x[n] = N-sum;
        ll res = 0;
        ll weight = 0;
        rep(i,4) {
            if (x[i] > W[i].size()) return 0;
            weight += (w_min+i)*x[i];
        }
        if (weight > w_upper) return 0;
        rep(i,4)rep(j,x[i]) res += W[i][j];
        return res;
    }

    ll ans = 0;
    x[n] = value;
    for (int i = 0; i <= N-sum; i++) {
        ans = max(ans,dfs(n+1,i,sum+i,x));
    }
    return ans;

}

int main() {
    vint x(4);
    cin >> N >> w_upper;
    W.resize(4);
    rep(i,N) {
        int w, v; cin >> w >> v;
        if (i == 0) w_min = w;
        W[w-w_min].push_back(v);
    }
    rep(i,4) sort(rall(W[i]));
    ll ans = 0;
    rep(i,N+1) ans = max(ans,dfs(0,i,i,x));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
long long dp[100010][3];
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  int N;
  cin >> N ;
  int h[100000][3];
  rep(i,N){
    rep(j,3){
      cin >> h[i][j];
    }
  }
  rep(i,N){
    rep(j,3){
      rep(k,3){
        if(j!=k){
          chmax(dp[i+1][j],dp[i][k]+h[i][j]);
        }
      }
    }
  }
  long long ans = 0;
  rep(i,3){
    if(ans<dp[N][i])
      ans = dp[N][i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 7048
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

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

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a, bool g){
	if(g){
		if(a[index]<key){
			return true;
		}
	}
	else{
		if(a[index]>key){
			return true;
		}
	}
	return false;
}

ll bin_search(ll key, vector<ll> &a, bool g){
	
	ll l=-1;
	ll r=a.size();

	if(g){
		l=a.size();
		r=-1;
	}

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a, g)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

int main(){

	ll d;
	cin>>d;

	if(d==22){
		cout<<"Christmas Eve Eve Eve"<<endl;
	}
	else if(d==23){
		cout<<"Christmas Eve Eve"<<endl;
	}
	else if(d==24){
		cout<<"Christmas Eve"<<endl;
	}
	else{
		cout<<"Christmas"<<endl;
	}
	
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int ans = 0;
		for(int i = 1; i <= 5; i++) {
			int n = sc.nextInt();
			if(n==0) {
				ans=i;
			}
		}
		System.out.println(ans);
	 }
}


Measured memory_bytes: 35700
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        a: i64,
        b: i64,
        c: i64,
    }

    println!("{}", max(c - (a-b), 0));
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}


int main(){
    int n,k; cin >> n >> k;
    vi p(n);

    rep(i,n){
        cin >> p[i];
    }

    Sort(p);

    int ans = INF;

    rep(i,n-k+1){
        int d = p[i+k-1]-p[i];

        ans = min(ans,d);
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
#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 VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N;
    cin >> N;
    VP A(N);
    rep(i, 0, N){
        ll a; cin >> a;
        A[i] = {a, i};
    }

    sort(ALL(A));

    ll ans = 0;
    rep(i, 0, N){
        if(i%2 != A[i].second%2) ans++;
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import itertools
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
diff_VC = list(i-j for i,j in zip(V,C))
c=[]
for i in range(N):
  c += [sum(comb) for comb in itertools.combinations(diff_VC,i+1)]
print(max(max(c),0))

Measured memory_bytes: 52376
import kotlin.math.abs

fun main(){
    val (a,b,h,m) = readLine()!!.split(" ").map{it.toDouble()}


    val rad_a : Double = 2 * Math.PI * ((h/12.0) + (m/60.0/12.0))
    val rad_b : Double = 2 * Math.PI * (m/60.0)

    val rad_diff = abs(rad_a - rad_b)

    val disdis = (a * a + b * b - 2 * a * b * Math.cos(rad_diff))

    println(Math.sqrt(disdis))
}

Measured memory_bytes: 36588
n = int(input())
p = [0] + list(map(int, input().split())) + [0]
c = [0] * n
s = abs(p[1]-0)
for i in range(1, n+1):
  c[i-1] = abs(p[i+1]-p[i-1])-abs(p[i]-p[i-1])-abs(p[i+1]-p[i])
  s += abs(p[i+1]-p[i])

for x in c:
  print(x+s)


Measured memory_bytes: 14048
# include<iostream>
using namespace std;
int main ()
{
	 int N;
	 cin>>N;
	 long long sum =0;
	 for(int i=1;i<=N;i++)
	 {
	 	 if(i%3!=0&&i%5!=0)
	 	 {
	 	 	sum+=i;
		  }
	 }
	  cout<<sum<<endl;
	
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl
#define err(x) cerr<<(x)<<endl
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200010
#define lim9 1000000010

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
	string n;
	cin >> n;
	char last = n[n.length() - 1];
	if (last == '3') {
		out("bon");
		return 0;
	} else if (last == '2' || last == '4' || last == '5' || last == '7' || last == '9') {
		out("hon");
		return 0;
	}
	out("pon");
	return 0;

}


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

int main(){
  int N,K;
  cin >> N >> K;
  if(K==1){
    int64_t mi=1e9;
    for(int i=0;i<N;i++){
      int x;
      cin >> x;
      if(mi>abs(x)){
        mi=abs(x);
      }
    }
    cout << mi << endl;
  }else{
    queue<int64_t> que;
    for(int i=0;i<K-1;i++){
      int x;
      cin >> x;
      que.push(x);
    }
    int64_t mi=1e18;
    for(int i=0;i<N-K+1;i++){
      int64_t x;
      cin >> x;
      int64_t res=abs(x-que.front())+min(abs(x),abs(que.front()));
      if(res<mi){
        mi=res;
      }
      que.pop();
      que.push(x);
    }
    cout << mi << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
# Your code here!
while True:
    m,f,r=map(int,input().split())
    
    if m==-1 and f==-1 and r==-1:
           break
    else:
            if m==-1 or f==-1:
                print('F')
            elif m+f>=80:
                print('A')
            elif 65<=m+f<80:
                print('B')
            elif 50<=m+f<65:
                print('C')
            elif 30<=m+f<50:
                if r>=50:
                    print('C')
                else:    
                    print('D')
            else:
                print('F')


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for ( int i = 0; i < N; ++i){
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    
    bool exist = false;
    
    for ( int i = 0; i < N-1; ++i){
        if ( A.at(i) == A.at(i+1) ){
            exist = true;
        }
    }
    
    if ( exist ){
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    sort(a.rbegin(),a.rend());
    ll ans = 0;
    vector<int>cnt(n,0);
    cnt[0]=1;
    int j=0;
    rep(i,n-1){
        if(cnt[j]==2){
            j++;
            ans += a[j];
            cnt[j]++;
        }
        else{
            ans += a[j];
            cnt[j]++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)998244353
#define Amx (ll)1010101

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}


ll N,A[202020];
vector<ll> d[1010101];
ll mk[1010101];
ll g[1010101];
ll i, j, k, ans;
int main(){
    scanf("%lld", &N);
    
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }

    fornum(i,1,Amx){
        for (j = i; j < Amx; j += i)
        {
            d[j].push_back(i);
        }
    }
    fornum(i,1,Amx){
        ll a = moddiv(1, i);
        fornum(j,0,d[i].size()){
            a = (a + MOD - g[d[i][j]]) % MOD;
        }
        g[i] = a;
    }

    fornum(i,0,N){
        ll a = 0,ai=A[i];
        fornum(j,0,d[ai].size()){
            a = (a + g[d[ai][j]]*mk[d[ai][j]]) % MOD;
            mk[d[ai][j]] = (mk[d[ai][j]] + ai) % MOD;
        }
        ans = (ans + a * ai) % MOD;
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 200064
/*jai mata di
 let's rock*/
#include<bits/stdc++.h>
using namespace std;
char s[40],t[40];
int h[40];
int mp[40];
int n;
void dfs(int id)
{
    if(id==n)
        return ;
    t[id]=s[id];
    mp[s[id]-'a']=1;
    dfs(id+1);
    mp[s[id]-'a']=0;
    for(int i=s[id]-'a'+1;i<26;i++)
    {
        if(!mp[i])
        {
            t[id]=i+'a';
            t[id+1]='\0';
            printf("%s\n",t+1);
            exit(0);
        }
    }
}
int main()
{
   scanf("%s",s+1);
   int i;
   n=strlen(s+1);
   for(i=1;i<=n;i++)
      h[s[i]-'a']=1;
   if(n<26)
   {
       printf("%s",s+1);
       for(i=0;i<26;i++)
         if(!h[i])
          {
              printf("%c\n",i+'a');
              return 0;
          }
   }
   else
   {
       string str="abcdefghijklmnopqrstuvwxyz";
       reverse(str.begin(),str.end());
       int f=0;
       for(i=1;i<=26;i++)
         if(s[i]!=str[i-1])
            f=1;
       if(!f)
           printf("-1\n");
       else
       {
           dfs(1);
       }
   }
   return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int m=Integer.parseInt(scan.next());
		int[] x=new int [m];
		for (int i=0;i<m;++i) {
			x[i]=Integer.parseInt(scan.next());
		}
		Arrays.parallelSort(x);
		int[] diff=new int[m-1];
		for (int i=0;i<m-1;++i) {
			diff[i]=x[i+1]-x[i];
		}
		Arrays.parallelSort(diff);
		int sum=0;
		for (int i=0;i<m-n;++i) {
			sum+=diff[i];
		}
		System.out.print(sum);
				
	}
}

Measured memory_bytes: 47596
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
    // 引数の受け取り
    int N,K,X,Y;
    scanf("%d %d %d %d", &N, &K, &X, &Y);
    int F = 0;
    F += min (K*X , N*X);
    F += max ((N-K)*Y , 0);

    printf("%d", F);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int h,n;
    cin>>h>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=a[i];
    }
    if(sum>=h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

ll N, A, B, C, D;

ll rec(ll N, map<ll, ll> &dp) {
    if(dp.count(N))
        return dp[N];
    if(N == 1) {
        return dp[N] = D;
    } else if(N == 0) {
        return dp[N] = 0;
    }
    ll l2 = (N / 2) * 2;
    ll u2 = ((N + 1) / 2) * 2;
    ll l3 = (N / 3) * 3;
    ll u3 = ((N + 2) / 3) * 3;
    ll l5 = (N / 5) * 5;
    ll u5 = ((N + 4) / 5) * 5;

    ll ret = LINF;
    if(LINF / D > N)
        ret = N * D;
    ret = min(ret, rec(l2 / 2, dp) + A + abs(N - l2) * D);
    ret = min(ret, rec(u2 / 2, dp) + A + abs(N - u2) * D);
    ret = min(ret, rec(l3 / 3, dp) + B + abs(N - l3) * D);
    ret = min(ret, rec(u3 / 3, dp) + B + abs(N - u3) * D);
    ret = min(ret, rec(l5 / 5, dp) + C + abs(N - l5) * D);
    ret = min(ret, rec(u5 / 5, dp) + C + abs(N - u5) * D);

    return dp[N] = ret;
}

int main() {
    int T;
    cin >> T;
    while(T--) {
        cin >> N >> A >> B >> C >> D;
        map<ll, ll> dp;
        cout << rec(N, dp) << endl;
    }
    return 0;
}

Measured memory_bytes: 4452
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;

    if (n == 1) {
        cout<<"Yes"<<endl;
        cout<<2<<endl;
        cout<<1<<" "<<1<<endl;
        cout<<1<<" "<<1<<endl;
        return 0;
    }

    ll k = -1;
    for (int i = 2; i <= n; ++i) {
        if (n == i * (i - 1) / 2) { 
            k = i;
            break;
        }
    }
    if (k == -1) {
        cout<<"No"<<endl;
        return 0;
    }

    vvl is(k);
    ll acc = 1;
    rep(i, k - 1) {
        for (int j = i + 1; j < k; ++j) {
            is[i].push_back(acc);
            is[j].push_back(acc);
            acc++;
        }
    }

    cout<<"Yes"<<endl;
    cout<<k<<endl;
    rep(i, k) {
        cout<<is[i].size()<<" ";
        rep(j, is[i].size()) cout<<is[i][j]<<" ";
        cout<<endl;
    }
}

Measured memory_bytes: 3200
#include<stdio.h>
int main(void)
{
	int n;
	int x,y,flg;
	flg=0;
	scanf("%d",&n);
	for(x=0;x<26;x++){
		for(y=0;y<18;y++){
			if(x*4+y*7==n){
				flg=1;
			}
		}
	}
	if(flg==1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.StringTokenizer;



public class Main {
    public static void main(String[] args) {
       
    	try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String s;
            int a , b ,temp;
            int r = 0;
            while((s = br.readLine())!=null)
            {
            StringTokenizer st = new StringTokenizer(s," ");
            a = Integer.parseInt(st.nextToken());
            b = Integer.parseInt(st.nextToken());
        
            	if(a<b)
            	{
            		temp = a;
            		a = b;
            		b = temp;
            	}
            
            	while(b!=0)
            	{
            		r = a%b;
            		a = b;
            		b = r;
            		
            	}
            	System.out.println(a);
            	
            }
    	}catch (Exception e) {
            e.printStackTrace();
        }
       
    }
   

}

Measured memory_bytes: 24120
D = int(input())
N = 26
c = [int(i) for i in input().split()]
last = [0 for i in range(N)]
s = list()
for i in range(3):
  s.append([int(j) for j in input().split()])
  
for i in range(D-3):
  d_score = -1
  ans = -1
  ans_d = -1
  for j in range(N):
    last_day = (i + 1 - last[j])
    arg = s[0][j] + c[j]*last_day
    if d_score < arg and s[0][j] > s[1][j] and s[0][j] > s[2][j]:
      d_score = arg
      ans = j+1
    if d_score < arg:
      ans_d = j+1
  if ans == -1:
    ans = ans_d
  print(ans)
  del s[0]
  s.append([int(j) for j in input().split()])
  last[ans-1] = i+1
for i in range(3):
  d_score = -1
  ans = -1
  for j in range(N):
    last_day = i + 1 - last[j]
    arg = s[i][j] + c[j]*last_day
    if d_score < arg:
      d_score = arg
      ans = j+1
  print(ans)
  last[ans-1] = i+1

Measured memory_bytes: 9308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int n = 1e5 + 5;
const ll MOD = 998244353;
int N;

ll fac(ll n){
	ll c = 1;
	for(int i = 2;i <=n; ++i){
		c = (c * i) % MOD;
	}
	return c;
}


int main(){
	string s;
	cin >> N >> s;
	ll rO = 0, gO = 0, bO = 0, rW = 0, gW = 0, bW = 0;
	ll c = 1;
	for(int i = 0; i < 3*N; ++i){
		if(s[i] == 'R'){
			if(rW > 0){
				c = (c*rW)%MOD;
				rW--;
			}else if (gO > 0){
				c = (c*gO)%MOD;
				gO--;
				bW++;
			}else if (bO > 0){
				c = (c*bO)%MOD;
				bO--;
				gW++;
			}else{
				rO++;
			}
		}else if (s[i] == 'G'){
			if(gW > 0){
				c = (c*gW)%MOD;
				gW--;
			}else if (rO > 0){
				c = (c*rO)%MOD;
				rO--;
				bW++;
			}else if (bO > 0){
				c = (c*bO)%MOD;
				bO--;
				rW++;
			}else{
				gO++;
			}
		}else{
			if(bW > 0){
				c = (c*bW)%MOD;
				bW--;
			}else if (gO > 0){
				c = (c*gO)%MOD;
				gO--;
				rW++;
			}else if (rO > 0){
				c = (c*rO)%MOD;
				rO--;
				gW++;
			}else{
				bO++;
			}
		}
	}
	c = (c*fac(N)) % MOD;
	cout << c << endl;
	return 0;
	
}


Measured memory_bytes: 900
import scala.io.StdIn.{readInt,readLine}

object Main {
  def main(args:Array[String]) = {
    val n = for(i<-1 to 5) yield readInt
    val m = if(n(0)>n(1)) n(1) else n(0)
    val pasta = if(m>n(2)) n(2) else m
    val juice = if(n(3)>n(4)) n(4) else n(3)
    println(pasta+juice-50)
  }
}

Measured memory_bytes: 43652
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = 1LL<<55;
const Int mod = (1e9)+7;
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  set<int> S;
  int q;
  cin>>q;
  while(q--){
    int cmd, num;
    cin>>cmd>>num;
    if(cmd == 0){
      S.insert(num);
      cout<<S.size()<<endl;
    }
    if(cmd == 1){
      cout<<S.count(num)<<endl;
    }
  }
  
  
  return 0;
}



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

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

using namespace std;

bool f(vector<double> &pointA, vector<double> pointB){
    double dist = 0.0;
    int n = pointA.size();
    double temp = 0.0;
    for(int i = 0; i < n; i++)
        temp += (abs(pointA[i]-pointB[i]) * abs(pointA[i]-pointB[i]));
    dist = sqrt(temp);
    return ceil(dist) == floor(dist);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, d;
    cin >>n >>d;
    vector<vector<double>> points(n);
    for(int i = 0; i < n; i++){
        vector<double> point(d);
        for(int j = 0; j < d; j++)
            cin >>point[j];
        points[i] = point;
    }
    int ans = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            if(f(points[i], points[j]))
                ans++;
        }
    }
    cout <<ans;
    return 0;
}


Measured memory_bytes: 256