akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

constexpr int INF = 1e9;
int n;
vector<int> a(200000), parent(200000, -1), dp(200100, INF), ans(200000);
vector<vector<int>> graph(200000), to(200000);

void dfs_tree(int u) {
    for (int v : graph[u]) {
        if (parent[u] != v) {
            to[u].push_back(v);
            parent[v] = u;
            dfs_tree(v);
        }
    }
    return;
}

void dfs_lis(int u) {
    auto iter0 = lower_bound(dp.begin(), dp.end(), a[u]);
    int idx = distance(dp.begin(), iter0);
    int old = dp[idx];
    dp[idx] = a[u];
    auto iter1 = lower_bound(dp.begin(), dp.end(), INF);
    ans[u] = distance(dp.begin(), iter1) - 1;
    for (int v : to[u]) {
        dfs_lis(v);
    }
    dp[idx] = old;
    return;
}

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        graph[u - 1].push_back(v - 1);
        graph[v - 1].push_back(u - 1);
    }
    
    dfs_tree(0);
    dp[0] = -INF;
    dfs_lis(0);
    rep(i, n) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 48276
import sys
input = sys.stdin.readline

N = int(input())
A = list(zip(list(map(int, input().split())), range(N)))
A.sort(reverse=True)
dp = [[0] * (N+1) for _ in range(N+1)]
for i in range(1, N+1):
    a, k = A[i-1]
    dp[i][0] = dp[i-1][0] + a * abs(N-i-k)
    for j in range(1, i):
        dp[i][j] = max(dp[i-1][j] + a * abs(N-(i-j)-k), dp[i-1][j-1] + a * abs(j-1-k))
    dp[i][i] = dp[i-1][i-1] + a * abs(i-1-k)
print(max(dp[N]))

Measured memory_bytes: 100532
import java.util.Scanner;

class	Main {
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		String nyuryoku = scanner.nextLine();
		String[] array = nyuryoku.split(" ",0);
		int a = Integer.parseInt(array[0]) , b = Integer.parseInt(array[1]) ;
		hikaku(a,b);
		scanner.close();
	}

	public static void hikaku(int a , int b){
			if(a > b ){System.out.println("a > b");}
			else if(a < b){System.out.println("a < b");}
			else if(a == b){System.out.println("a == b");}
	
		return ;
	}
}

Measured memory_bytes: 25772
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
dp=[0]+[float("inf") for i in range(n+k)]
for i in range(n-1):
    for j in range(k):
        if j+i+1>n-1:break
        dp[j+i+1]=min(dp[j+i+1],dp[i]+abs(h[j+i+1]-h[i]))
print(dp[n-1])

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

using namespace std;

int n;
map<int, set<int>> edge;

bool bfs(int start, int goal) {
  vector<int> cost = vector<int>(n + 1, 1e9);
  queue<pair<int, int>> q;
  cost[start] = 0;
  cost[goal] = 0;
  q.push(make_pair(start, 0));
  q.push(make_pair(goal, 1));
  int black = 0, white = 0;
  while (!q.empty()) {
    auto p = q.front();
    int u = p.first, color = p.second;
    q.pop();
    for (auto v: edge[u]) {
      if (cost[v] != 1e9) {
        continue;
      }
      if (color == 0) {
        black++;
      } else {
        white++;
      }
      cost[v] = cost[u] + 1;
      q.push(make_pair(v, color));
    }
  }
  return black > white;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    edge[a].insert(b);
    edge[b].insert(a);
  }
  if (bfs(1, n)) {
    cout << "Fennec" << endl;
  } else {
    cout << "Snuke" << endl;
  }
  return 0;
}

Measured memory_bytes: 19456
#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(){
  string s, ans="Good";
  cin >> s;
  rep(i, 3){
    if(s[i]==s[i+1]){
      ans="Bad";
      break;
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std ; 

const int N =1e6 + 7 ; 

int n , k ;  
long long C ; 


        struct line{
                long long x , b; 
                line(){
                        x = 0LL , b = 4e18 ; 
                }
                line(long long _x , long long _b){
                        x = _x ; 
                        b = _b ; 
                }
                long long eval(long long X){ 
                        return 1LL * X * x + b ; 
                }
        } c[N<<2] ; 
        

        void update(line r , int node = 1 , long long L = 1 , long long R = N ){
                
                long long m = (L + R) >> 1 ; 



                bool le = (c[node].eval(L) > r.eval(L)) ; 
                bool mid = (c[node].eval(m) > r.eval(m)) ; 
                
                if(mid){
                        swap(c[node] , r) ; 
                }


                if(L == R -1 ){
                        return ; 
                }
                if(le == mid){
                        update(r , node *2 +1 , m , R ) ; 
                }
                else{
                        update(r , node *2 , L , m ) ; 
                }

        }

        long long query( long long x , int node = 1, long long L = 1 , long long R = N ){

                long long m = (L + R) >> 1 ; 

                long long evalx = c[node].eval(x) ; 

                if(R - L == 1)
                        return evalx ;

                if(x < m){
                        return min(evalx , query(x , node * 2 , L , m ) )  ;
                }
                else {
                        return min(evalx , query(x , node * 2 + 1 , m , R) )  ; 
                }

        }

        vector<line> lns ; 

long long dp[N] ;

int main(){

        ios_base::sync_with_stdio(0) ; 
        cin.tie(0) ; 
       // freopen("in.in" , "r" ,stdin) ; 

        cin >> n >> C ;

        for(int i = 0 ;i < n;i++){
                long long x ; 
                cin>> x ; 

                if(i){
                        dp[i] = 1LL * x * x + query(x)  + C ; 
                }

                update(line( -2LL * x, dp[i] + x * x )) ; 
        }

        cout<< dp[n-1] ; 
        return 0; 
}

Measured memory_bytes: 67712
// ABC154
// a.cs

using System;

class A
{
    public static void Main()
    {
        string[] str1 = Console.ReadLine().Split(' ');
        string[] str2 = Console.ReadLine().Split(' ');
        string[] str3 = Console.ReadLine().Split(' ');

        string S = str1[0];
        string T = str1[1];
        int A = int.Parse(str2[0]);
        int B = int.Parse(str2[1]);
        string U = str3[0];

        if (S == U)
        {
            A--;
        }
        else if (T == U)
        {
            B--;
        }
        Console.WriteLine(A + " " + B);
    }
}

Measured memory_bytes: 13140
N = input()
N = int(N)
s = [[ int(i) for i in input().split()] for i in range(N)]
time = 0
hoge = "Yes"
s = sorted(s, key=lambda s:s[1])
for i in s:
    time += i[0]
    if time > i[1]:
        hoge = "No" 
        break

print(hoge)

Measured memory_bytes: 42716
// Author by Md. Jashim Uddin_RMSTU

#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     ll              long  long
#define     fast            ios_base :: sync_with_stdio(false);cin.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)

#define     forn(i,n)       for(int i=1;i<=n;i++)
#define     min3(a,b,c)     min(a,min(b,c)
#define     M             32000

int main()
{
  ll a,b,c;
  cin>>a>>b>>c;
  swap(a,b);
  swap(a,c);
  cout<<a<<" "<<b<<" "<<c;
return 0;

}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
    static int binarySearch(long Y , long A[]){
        int N = A.length;
        if(A[N - 1] < Y){
            return N;
        }
        if(A[0] >= Y){
            return 0;
        }
        int low = 0; // false
        int high = N - 1; // true
        while(low < high - 1){
            int mid = (low + high) / 2;
            if(A[mid] >= Y){
                high = mid;
            }else{
                low =  mid;
            }
        }
        return high;
    }
    // 幸福度X以上の握手の数
    static long numberOfHandshake(long X , long A[] ){
        int N = A.length;
        long ret = 0;
        for(int i = 0 ; i < N ; ++i){
            ret += N - binarySearch(X - A[i], A);
        }
        return ret;
    }
    static long totalHappiness(long X , long A[]){
        int N = A.length;
        long S[] = new long[N + 1];
        for(int i = 0 ; i < N ; ++i){
            S[i + 1] = S[i] + A[i];
        }
        long ret = 0;
        for(int i = 0 ; i < N ; ++i){
            int idx = binarySearch(X - A[i], A);
            ret += S[N] - S[idx] + (N - idx) * A[i];
        }
        return ret;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long M = sc.nextLong();
        long A[] = new long[N];
        for(int i = 0 ; i < N ; ++i){
            A[i] = sc.nextLong();
        }
        sc.close();
        Arrays.sort(A);
        long low = 0; // ?
        long high = A[N - 1] * 2 + 1; // true
        while(low < high){
            long mid = (low + high) / 2;
            long c = numberOfHandshake(mid , A);
            if(c <= M){
                high = mid;
            }else{
                low = mid + 1;
            }
        }
        long c = numberOfHandshake(low, A);
        long h = totalHappiness(low, A);
        if(c < M){
            h += (low - 1) * (M - c);
        }
        System.out.println(h);
    }
}


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


/*
int main()
{

  int n, capa;cin>>n>>capa;
  vector<tuple<double,int,int>> vw(n);
  for (auto &&i : vw)
  {
    int v,w;cin>>v>>w;
    double rate = (double)v/(double)w;
    get<0>(i) = rate;
    get<1>(i) = v;
    get<2>(i) = w;
    
  }

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

  
  reverse(vw.begin(),vw.end());

  for (auto &&i : vw)
  {
    cout << get<0>(i) << " " << get<1>(i) << " " <<  get<2>(i) << endl;
  }

  int sum = 0;
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    while(1)
    {
      if(sum + get<2>(vw.at(i)) > capa)break;
      else
      {
        sum += get<2>(vw.at(i));
        ans += get<1>(vw.at(i));
      }
    }
    
    
  }
  
  cout << ans << endl;
  
}
*/


int main()
{
  int n,w;cin>>n>>w;
  int dp[10005];
  fill_n(dp,10005,-1);
  dp[0] = 0;

  for (int i = 0; i < n; i++)
  {
    int val, wei;cin>>val>>wei;

    for (int j = 0; j <= w; j++)
    {
      if (j - wei >= 0 && dp[j - wei] != -1)
      {
        dp[j] = max(dp[j - wei] + val,dp[j]);
      }
      
    }
    
  }
  

  cout << *max_element(dp,dp+w+1) << endl;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
 
	double rate, maxrate=-1.0;
	int water,sugar,maxsugar;
	int x,y;
	for(int i=0; i*a*100<=f; i++) {
		for(int j=0; j*b*100<=f; j++) {
			water=i*a*100+j*b*100;
			maxsugar=(i*a+j*b)*e;
			for(int k=0; k*c<=maxsugar; k++) {
				for(int l=0; l*d<=maxsugar; l++) {
					sugar=k*c+l*d;
					rate=(double)100*sugar/(water+sugar);
					if(maxrate<rate&&sugar<=maxsugar&&water+sugar<=f) {
						maxrate=rate;
						x=water;
						y=sugar;
					}
				}
			}
		}
	}
	
	cout<<x+y<<' '<<y<<endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

typedef pair<int,int> P;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    bool open[h][w];
    int dist[h][w], xy[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    fill(dist[0], dist[h], k+1);
    queue<P> q;
    for (int i = 0; i < h; i++) {
        char a;
        for (int j=0; j<w; j++) {
            cin >> a;
            open[i][j] = (a == '.');
            if (a == 'S') {
                q.push({i, j});
                dist[i][j] = 0;
            }
        }
    }
    while (!q.empty()) {
        P now = q.front(); q.pop();
        int d = dist[now.first][now.second];
        if (d == k) break;
        for (int i=0; i<4; i++) {
            int x = now.first  + xy[i][0],
                y = now.second + xy[i][1];
            if (0 <= x && x < h && 0 <= y && y < w && open[x][y]) {
                open[x][y] = false;
                dist[x][y] = d + 1;
                q.push({x, y});
            }
        }
    }
    int magic = 100000;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (dist[i][j] > k) continue;
            magic = min( {magic, (i+k-1)/k, (j+k-1)/k, (h-i+k-2)/k, (w-j+k-2)/k} );
        }
    }
    cout << magic + 1 << '\n';
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <map>
using namespace std;

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

int main() {
	string s; cin >> s;
	int n = s.size();
	map<char, int> mp;
	for (int i = 0; i < n; i++) {
		mp[s.at(i)]++;
	}
	int np = n / 2;
	int ng = n - np;
	int w = np;
	int a = mp['g'] - np;
	int l = n - w - a;
	cout << w - l << endl;
	return 0;
}

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

using namespace std;

const int Maxn = 2e5+7;

string S;
int a[Maxn], b[Maxn];
long long ans;

void merge_sort(int l, int r)
{
    if(l == r) return;
    int mid = (l+r)>>1;
    merge_sort(l, mid);
    merge_sort(mid+1, r);

    int i = l, j = mid+1, k = l;
    while(k <= r)
    {
        if(j <= r && (i > mid || a[j] < a[i]))
        {
            ans += mid-i+1;
            b[k++] = a[j++];
        }
        else b[k++] = a[i++];
    }
    memcpy(a+l, b+l, sizeof(int)*(r-l+1));
}

int main()
{
    cin >> S;
    for(int i = 0; i < S.length(); ++i)
        a[i+1] = S[i] == 'B' ? 1 : 0;
    merge_sort(1, S.length());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2180
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>

using namespace std;

const int maxn=100000;
const int maxk=100000;

//union find tree
int par[maxn];
int rank1[maxn];

void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank1[i]=0;
  }
}

int root(int x){
  if(par[x]==x){
    return x;
  }
  else{
    return par[x]=root(par[x]);
  }
}

void unite(int x, int y){
  x=root(x);
  y=root(y);
  if(x==y) return;
  if(rank1[x]<rank1[y]){
    par[x]=y;
  }
  else{
    par[y]=x;
    if(rank1[x]==rank1[y])rank1[x]++;
  }
}

bool same(int x,int y){
  return root(x)==root(y);
}

int main(int argc, char* argv[]){
  int n,m;
  scanf("%d%d",&n,&m);
  int p[100001];
  int x[100001];
  int y[100001];
  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  for(int i=0;i<m;i++){
    scanf("%d%d",&x[i],&y[i]);
  }
  init(n);
  for(int i = 0;i<m;i++){
    unite(x[i],y[i]);
  }
  /*
  set<int> rt;
  for(int i=0;i<n;i++){
    rt.insert(root(i));
  }*/
  int ans = 0;
  for(int i=1;i<=n;i++){
    if(root(i)==root(p[i-1]))ans++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define MAX 3
#define MAX2 9

using namespace std;

struct Puzzle{
  int f[MAX2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const {
    int i;
    for(i = 0; i < MAX2; i++){
      if( f[i] == p.f[i] ){
        continue;
      }
      return f[i] > p.f[i];
    }
    return false;
  }
};

string bfs(Puzzle);
bool isTarget(Puzzle);

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p){
  int i;
  for(i = 0; i < MAX2; i++){
    if( p.f[i] != (i+1) ){
      return false;
    }
  }
  return true;
}//end of isTarget func

int main(){
  Puzzle in;
  int i;
  for(i = 0; i < MAX2; i++){
    cin >> in.f[i];
    if( in.f[i] == 0 ){
      in.f[i] = MAX2;
      in.space = i;
    }
  }
  string ans = bfs(in);
  cout << ans.size() << endl;
  return 0;
}//end of main func

string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u,v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  int r,tx,ty;
  int sx,sy;
  int tmp;

  while( !Q.empty() ){
    u = Q.front();
    Q.pop();
    if( isTarget(u) ){
      return u.path;
    }
    sx = u.space / MAX;
    sy = u.space % MAX;
    for(r = 0; r < 4; r++){
      tx = sx + dx[r];
      ty = sy + dy[r];
      if( tx < 0 || ty < 0 || tx >= MAX || ty >= MAX){
        continue;
      }
      v = u;
      /*swap*/
      tmp = v.f[u.space];
      v.f[u.space] = v.f[tx * MAX + ty];
      v.f[tx * MAX + ty] = tmp;

      v.space = tx * MAX + ty;
      if( !V[v] ){
        V[v] = true;
        v.path += dir[r];
        Q.push(v);
      }
    }
  }
  return "unsolvable";
}

Measured memory_bytes: 30588
from operator import itemgetter
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l,key=itemgetter(1))
f=0
ct=0
for i in range(n):
  x=l[i][1]
  ct+=l[i][0]
  if ct>x:
    f=1
    break
if f==1:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 55268
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		List<Double> list = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			list.add((double)y/(double)x);
		}
		Double max = list.stream().mapToDouble(Double::doubleValue).max().getAsDouble();
		System.out.println(BigDecimal.valueOf(max*t).toPlainString());
	}
}


Measured memory_bytes: 38212
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		String N = new Scanner(System.in).next();
		String[] eachNum = N.split("");

		if( eachNum[0].equals(eachNum[2]) ) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

class Solve {
private:
	using vi = std::vector<int>;
	using vvi = std::vector<vi>;

	using vb = std::vector<bool>;
	using vvb = std::vector<vb>;

	int H, W, C;

	int calcSize(vvi &board, int h, int w)
	{
		vvb visited(H + 2, vb(W + 2));
		std::stack<std::pair<int, int>> previsit;
		previsit.push({h, w});

		int count{};
		while (!previsit.empty())
		{
			auto now{previsit.top()};
			previsit.pop();
			if (visited[now.first][now.second]) continue;
			if (board[now.first][now.second] != C) continue;
			count++;
			visited[now.first][now.second] = true;
			previsit.push({now.first + 1, now.second});
			previsit.push({now.first - 1, now.second});
			previsit.push({now.first, now.second + 1});
			previsit.push({now.first, now.second - 1});
		}
		return count;
	}

	int rc(int turn, vvi &board)
	{
		int ret{};
		if (turn == 5)
			return calcSize(board, 1, 1);
		for (int c_i{1}; c_i <= 6; c_i++)
		{
			vvi next_board{board};
			if (c_i != board[1][1])
				changeColor(next_board, c_i);
			ret = std::max(ret, rc(turn + 1, next_board));
		}
		return ret;
	}

	void changeColor(vvi &board, int new_color)
	{
		std::stack<std::pair<int, int>> previsit;
		previsit.push({1, 1});

		int pre_color{board[1][1]};
		while (!previsit.empty())
		{
			auto now{previsit.top()};
			previsit.pop();
			if (board[now.first][now.second] != pre_color) continue;

			board[now.first][now.second] = new_color;

			previsit.push({now.first + 1, now.second});
			previsit.push({now.first - 1, now.second});
			previsit.push({now.first, now.second + 1});
			previsit.push({now.first, now.second - 1});
		}
	}

public:
	bool is_last_query{};
	Solve()
	{
		scanf("%d%d%d", &H, &W, &C);
		if (H == 0 && W == 0 && C == 0)
		{
			is_last_query = true;
			return;
		}
		vvi board(H + 2, vi(W + 2));
		for (int h_i{1}; h_i <= H; h_i++)
			for (int w_i{1}; w_i <= W; w_i++)
				scanf("%d", &board[h_i][w_i]);
		int ans{};
		for (int i{1}; i <= H; i++)
			for (int j{1}; j <= W; j++)
				ans = std::max(ans, calcSize(board, i, j));

		ans = std::max(ans, rc(0, board));
		printf("%d\n", ans);
	}

};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


Measured memory_bytes: 3152
#include <stdlib.h> 
 int main() { 
     int a, b, c; 
     int i; 
     int j; 
     scanf("%d %d %d", &a, &b, &c); 
     j = 0; 
     for (int i = a; i <= b; i++) { 
         if (c % i == 0) j++; 
         
     } printf("%d\n", j); 
     return 0; 
     
 } 


Measured memory_bytes: 2104
import fractions as fra
#import math as fra
a,b,c,d = map(int,input().split())

e = c * d // fra.gcd(c,d)
x = b//c + b//d - (a-1)//c - (a-1)//d
y = b//e - (a-1)//e

print(b - (a-1) - x + y)

Measured memory_bytes: 5048
import java.util.Scanner;

public class Main {
	static int n,A,B,C;
	static int lengths[];
	static int INF=10000000;
	public static int dfs(int cur,int a,int b,int c)
	{
		int ret0,ret1,ret2,ret3;
		
		if(cur==lengths.length)
		{
			if(a==0||b==0||c==0) {
				return INF;
			}
			return Math.abs(a-A)+Math.abs(b-B)+Math.abs(C-c)-30;
			
		}
		ret0=dfs(cur+1,a,b,c);
		ret1=dfs(cur+1,a+lengths[cur],b,c)+10;
		ret2=dfs(cur+1,a,b+lengths[cur],c)+10;
		ret3=dfs(cur+1,a,b,c+lengths[cur])+10;
		return Math.min(Math.min(ret0, ret1),Math.min(ret2, ret3));
	}
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		 n=scan.nextInt();
		 A=scan.nextInt();
		 B=scan.nextInt();
		 C=scan.nextInt();
		 lengths=new int[n];
		for(int i=0;i<n;i++)
		{
			lengths[i]=scan.nextInt();
		}
		System.out.println(dfs(0,0,0,0));
	}
}


Measured memory_bytes: 22868
n,l=map(int,input().split())
*a,=map(int,input().split())
v=[0]

for i in range(n-1):
  if a[i]+a[i+1]>=l:
    v[0]=i+1
    v+=list(range(1,i+1)[::-1])
    v+=list(range(i+2,n))
    print("Possible")
    print(*v[::-1],sep="\n")
    break
else:
  print("Impossible")

Measured memory_bytes: 14076
using System;
using System.Collections.Generic;

namespace ABC
{
    public class B
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);

            var listP = new List<int>();

            string[] inputP = Console.ReadLine().Split(' ');
            for (int i = 0; i < N; i++)
            {
                int p = int.Parse(inputP[i]);
                listP.Add(p);
            }
            listP.Sort((a, b) => a- b);

            int ans = 0;

            for (int i = 0; i < K; i++)
            {
                ans = ans + listP[i];
            }

            Console.WriteLine(ans);
        }
    }
}


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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	string ans = "No";
	if (abs(b - a)  <= d && abs(c - b) <= d) { 
		ans = "Yes";
	} else if (abs(c - a) <= d) {
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
#define int long long
inline int read()
{
	register int x = 0 , f = 0; register char c = getchar();
	while(c < '0' || c > '9') f |= c == '-' , c = getchar();
	while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0' , c = getchar();
	return f ? -x : x;
}
int n;
int a[20];

int dfs(int l , int r , int xl , int xr)
{
	if(r - l <= 1) return 0; // 开区间 
	int ans = 1e18;
	for(int i = l + 1 ; i <= r - 1 ; ++i) // i 是最后一个选的，然后加上将左右两边合并的贡献 
		ans = min(ans , dfs(l , i , xl , xl + xr) + dfs(i , r , xl + xr , xr) + a[i] * (xl + xr));
	return ans; // 开区间的好处， (l , pos) + (pos , r) + [pos , pos] = (l , r) 
}

signed main()
{
	n = read();
	for(int i = 1 ; i <= n ; ++i) a[i] = read();
	cout << dfs(1 , n , 1 , 1) + a[1] + a[n] << '\n'; 
	return 0;
}

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

#define MAX_H 1400
#define MAX_W 1400

int H, W;

int dp[MAX_H + 1][MAX_W + 1];

int main()
{
	cin >> H >> W;
	for( int i = 1; i <= H; i++ ) {
		for( int j = 1; j <= W; j++ ) {
			int c;
			cin >> c;
			if( c == 0 ) {
				dp[i][j] = 1;
			}
		}
	}

	int maxw = 0;
	for( int i = 1; i <= H; i++ ) {
		for( int j = 1; j <= W; j++ ) {
			if( dp[i][j] ) {
				dp[i][j] = min( dp[i - 1][j], min( dp[i][j - 1], dp[i - 1][j - 1] ) ) + 1;
				maxw = max( maxw, dp[i][j] );
			}
		}
	}

	cout << maxw * maxw << endl;

	return 0;
}



Measured memory_bytes: 9684
#include<cstdio>
#define int long long
const int N=200005;
int n,v[20][20],a;
inline void rd()
{
	int x=9,r=0;char c;
	for(;(c=getchar())<'0'||c>'9';);
	for(r=c^48;(c=getchar())>='0'&&c<='9';r=r*10+(c^48));
	if(c=='.')for(;(c=getchar())>='0'&&c<='9';r=r*10+(c^48),--x);
	int y=x,z=x;for(;!(r&1)&&y<18;r>>=1,++y);for(;!(r%5)&&z<18;r/=5,++z);
	for(int i=18-y;i<=18;++i)for(int j=18-z;j<=18;++j)a+=v[i][j];++v[y][z];
}
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;++i)rd();
	return printf("%lld",a),0;
}

Measured memory_bytes: 1696
import Data.List

day :: [String]
day = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]

main = print =<< ((pure nextDay) <*> getLine)

nextDay :: String -> Int
nextDay s = (8 - ) $ (+ 1) $ (\(Just t) -> t) $ elemIndex s day



Measured memory_bytes: 380
N, K = map(int, input().split())
X = [[0] * (2*K) for _ in range(3*K)]
for _ in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
    if c == "B":
        x += K
    x %= 2*K
    y %= 2*K
    if y >= K:
        x, y = (x+K) % (2*K), y - K
    for dx, dy in ((0, 0), (2*K, 0), (K, K), (-K, K)):
        xx, yy = x + dx, y + dy
        if 0 <= xx < 3*K and 0 <= yy < 2*K:
            X[xx][yy] += 1

for i in range(1, 3*K):
    for j in range(2*K):
        X[i][j] += X[i-1][j]
for i in range(3*K):
    for j in range(1, 2*K):
        X[i][j] += X[i][j-1]

ma = 0
for i in range(2*K):
    for j in range(K):
        ma = max(ma, X[i+K][j+K] - X[i][j+K] - X[i+K][j] + X[i][j])
print(ma)

Measured memory_bytes: 97500
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define el "\n" ;
ll  k ; 
vector<ll> v(100005) ;
vector<ll> dp(100005, -1) ;

ll f(ll n ){
    if(n < 1){
        return  0 ; 
    }
    if(dp[n] >= 0 ){
        return dp[n] ;
    }
    else
    {
        ll  mini = INT32_MAX;
        for(ll i = 1 ; i <= min(k  , n ) ; i++){
            mini = min(mini , f(n - i) + abs(v[n-i] - v[n])) ;
            //cout << mini  << " # "   ;
        }
        //cout << el ;
        dp[n] = mini  ;  
    }
    return  dp[n] ;
    
}

int main(){
    ll n ; 
    cin >> n ; 
    cin >> k ; 
    //cout << dp[0] << " " << dp[1] << el ;
    for( ll i = 1 ; i <= n ; i++){
        cin >> v[i] ;
    }
    v[0] = v[1] ;
    cout << f(n) << el ;
    return 0 ;
}

Measured memory_bytes: 9536
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int N, c[509], s[509], a[509];
int main() {
	cin >> N;
	for (int i = 0; i < N - 1; i++) cin >> c[i] >> s[i] >> a[i];
	for (int i = 0; i < N; i++) {
		int p = 0;
		for (int j = i; j < N - 1; j++) {
			if (p <= s[j]) p = s[j];
			else p = (p - s[j] + a[j] - 1) / a[j] * a[j] + s[j];
			p += c[j];
		}
		cout << p << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
plist = list(map(int, input().split()))
count = 0

for i in range(n-2):
    if (plist[i+1]>plist[i] and plist[i+1]<=plist[i+2]) or  (plist[i+1]>plist[i+2] and plist[i+1]<=plist[i]):
        count += 1
print(count)

Measured memory_bytes: 3060
n = int(input())
s = list(input())

a = [0]*(2*n)
cnt = 0
for i in range(2*n):
    if s[i] == 'B':
        if cnt % 2 == 0:
            a[i] = 1
            cnt += 1
        else:
            a[i] = -1
            cnt -= 1

    else:
        if cnt % 2 == 0:
            a[i] = -1
            cnt -= 1
        else:
            a[i] = 1
            cnt += 1

pl = 0
judge = False
mod = 10**9+7
#print(a)

res = 1
for e in a:
    if e > 0:
        pl += 1
    else:
        if pl <= 0:
            judge = True
            break
        res = res*pl%mod
        pl -= 1

if judge or pl != 0:
    print(0)
    exit()

f = 1
for i in range(1,n+1):
    f = f*i%mod
#print(f,res)
print(res*f%mod)

Measured memory_bytes: 6308
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

const long MOD = 1000000007;

long n;
long c[200005];
std::vector<long> sim;
std::vector<long> back;
std::vector<long> dp;

int main(){
	scanf("%ld", &n);
	for(int i = 0; i < n; i++){
		scanf("%ld", &c[i]);
	}
	
	sim.push_back(c[0]);
	for(int i = 1; i < n; i++){
		long m = sim.size();
		if(c[i] != sim[m-1]){
			sim.push_back(c[i]);
		}
	}
	
	long bpos[200005];
	for(int i = 0; i < 200005; i++){
		bpos[i] = -1;
	}
	for(int i = 0; i < sim.size(); i++){
		if(bpos[sim[i]] == -1){
			back.push_back(-1);
			bpos[sim[i]] = i;
		}else{
			back.push_back(bpos[sim[i]]);
			bpos[sim[i]] = i;
		}
	}
	
	/*
	for(int i = 0; i < sim.size(); i++){
		printf("%3ld ", sim[i]);
	}
	printf("\n");
	for(int i = 0; i < back.size(); i++){
		printf("%3ld ", back[i]);
	}
	printf("\n");
	//*/
	
	dp.push_back(1);
	for(int i = 1; i < sim.size(); i++){
		if(back[i] == -1){
			dp.push_back(dp[i-1] % MOD);
		}else{
			dp.push_back((dp[i-1] + dp[back[i]]) % MOD);
		}
	}
	
	/*
	for(int i = 0; i < dp.size(); i++){
		printf("%3ld ", dp[i]);
	}
	printf("\n");
	//*/
	
	printf("%ld\n", dp[dp.size()-1]);
	return 0;
}


Measured memory_bytes: 9584
#encoding utf-8

a, b = map(int, input().split())

count = 0
for i in range(a,b+1):
    num = list(str(i))
    kaibun = 0
    for j in range(int(len(num)/2)):
        if num[j] == num[len(num)-j-1]:
            kaibun += 1
    if kaibun == int(len(num)/2):
        count += 1

print(count)


Measured memory_bytes: 3060
function main()
    """ver. 0.5.0

    ref:
        https://qiita.com/phigasui/items/2db20b36fb85e161e0ae
        https://nbviewer.jupyter.org/github/bicycle1885/Julia-Tutorial/blob/master/Julia%E3%82%AF%E3%83%83%E3%82%AF%E3%83%96%E3%83%83%E3%82%AF.ipynb
        https://nbviewer.jupyter.org/github/bicycle1885/Julia-Tutorial/blob/master/Julia%E9%AB%98%E9%80%9F%E3%83%81%E3%83%A5%E3%83%BC%E3%83%88%E3%83%AA%E3%82%A2%E3%83%AB.ipynb
    """
    const S = readline() |> chomp
    const ans = f(S)

    @assert ans == ans
    println(ans)
end

function f(S::String)
    const n = length(S)
    # Int: Int64
    const aa = zeros(Int, n)
    const cc = zeros(Int, n)
    const q = [0 for _ = 1:n]
    aa[1] = convert(Int, S[1] == 'A')
    cc[1] = convert(Int, S[1] == 'C')
    q[1]  = convert(Int, S[1] == '?')
    for i = 2:n
        aa[i] = aa[i - 1] + Int(S[i] == 'A')
        cc[i] = cc[i - 1] + Int(S[i] == 'C')
        q[i]  = q[i - 1]  + Int(S[i] == '?')
    end

    ans = 0
    const MOD = 10^9 + 7
    for i = 2:n - 1
        a = aa[i - 1]
        c = cc[n] - cc[i]
        l = q[i - 1] 
        r = q[n] - q[i]
        # ABC の作り方
        # AB?: ? 1つをCに割り当てる
        # ?BC: ? 1つをAに割り当てる
        # ?B?: ? 2つをACに割り当てる
        if S[i] == 'B' || S[i] == '?'
            ac = a * c * powermod(3, l + r, MOD)
            (aq, qc, qq) = (0, 0, 0)
            if l + r - 1 >= 0
                p = powermod(3, l + r - 1, MOD)
                aq = a * r * p
                qc = l * c * p
            end
            if l + r - 2 >= 0
                qq = l * r * powermod(3, l + r - 2, MOD)
            end
            # println(a, c, l, r, (ac, aq, qc, qq))
            ans += ac + aq + qc + qq
            ans = ans % MOD
        end
    end

    return ans
end

main()


Measured memory_bytes: 166796
import Control.Applicative
import Control.Monad
import Data.List

solve :: [[Int]] -> [String]
solve ([n,m,l]:matxs) =
    let (matA,matB) = splitAt n $ matxs in
    let mAB = [[sum $ zipWith (*) a b | b<-transpose matB] | a<-matA] in
    map (unwords . map show) mAB

main =
    mapM_ putStrLn =<< solve . takeInputs . lines <$> getContents
    where
    takeInputs :: [String] -> [[Int]]
    takeInputs = map (map read . words)


Measured memory_bytes: 12212
import java.util.Collections;
import java.util.Scanner;

public class Main {
    // AtCoder Beginner Contest 154
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String splt[] = scanner.nextLine().split(" ");
        String spltNum[] = scanner.nextLine().split(" ");
        String throwU = scanner.nextLine();
        if(throwU.equals(splt[0])){
            System.out.println(Integer.parseInt(spltNum[0])-1 + " " + spltNum[1]);
        }else{
            System.out.println(Integer.parseInt(spltNum[0]) + " " + (Integer.parseInt(spltNum[1]) - 1) );
        }

    }




}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> M;
  A=N+M;
  Out(N*(N-1)/2+M*(M-1)/2);
}

Measured memory_bytes: 256
n,x = input().split()
N = int(n)
X = int(x)
m_list=[]
for i in range(N):
	m = int(input())
	X -= m
	m_list.append(m)

m_list.sort()
sum_d = int(X//m_list[0])
sum_d += N
print(sum_d)

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <queue>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

#include <complex>
typedef double ld;
typedef complex<ld> P;

struct C {
  P p; ld r;
  C() {}
  C(P p, ld r) : p(p), r(r) {}
};

P getp() { ld x, y; cin >> x >> y; return P(x, y); }

double d[1020][1020];

int main() {
  P start = getp();
  P goal = getp();
  int N; cin >> N;
  vector<C> vc(N + 2);
  vc[0] = C(start, 0);
  vc[1] = C(goal, 0);

  for (int i : range(N)) {
    vc[i + 2].p = getp();
    double r; cin >> r;
    vc[i + 2].r = r;
  }

  for (int i : range(N + 2))
  for (int j : range(N + 2)) {
    d[i][j] = max(0.0, abs(vc[i].p - vc[j].p) - vc[i].r - vc[j].r);
  }

  priority_queue<pair<double, int>> q;
  q.push({0.0, 0});

  vector<char> vis(N + 2);
  while (!q.empty()) {
    double curr_cost = -q.top().first;
    int idx = q.top().second;
    q.pop();
    if (vis[idx]) continue;
    vis[idx] = 1;

    if (idx == 1) {
      printf("%.14f\n", curr_cost);
      break;
    }

    for (int to : range(N + 2)) {
      if (vis[to]) continue;
      q.push(make_pair(-(curr_cost + d[idx][to]), to));
    }
  }
}


Measured memory_bytes: 16624
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repd(i, n) for (ll i = (n)-1; i >= 0; --i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

ll dp[100010];
vector<vector<ll>> vec(100010);

ll rec(ll i)
{
    if (dp[i] != -1)
        return dp[i];
    else
    {
        ll res = 0;
        for (auto j : vec[i])
            res = max(res, rec(dp[j]) + 1);
        dp[i] = res;
        return res;
    }
}
int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<long double> p(n);
    rep(i, n) cin >> p[i];
    long double dp[n + 1][n + 1];
    rep(i, n + 1) rep(j, n + 1) dp[i][j] = 0;
    dp[0][0] = 1;
    rep(i, n + 1) dp[i + 1][0] = dp[i][0] * (1 - p[i]);
    rep(i, n)
    {
        rep(j, i + 1)
            dp[i + 1][j + 1] += dp[i][j] * p[i] + dp[i][j + 1] * (1 - p[i]);
    }
    long double ans = 0;
    for (ll i = n / 2 + 1; i <= n; ++i)
        ans += dp[n][i];
    cout << fixed << setprecision(20);
    cout << ans << endl;
}

Measured memory_bytes: 143232
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	float a,b,c,d,e,f,x,y,i,n;
	while(cin >> a >> b >> c >> d >> e >> f){
		x=(c*e-b*f)/(a*e-b*d);
		y=(c*d-a*f)/(b*d-a*e);
		if(x==-0) x=0;
		if(y==-0) y=0;
		printf("%.3f %.3f\n",x ,y);
	}
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

ll ncr(ll n, ll r){
  if(r>n)return 0;
  if(r*2>n) r=n-r;
  if(r==0) return 1;
  ll res = n;
  for(ll i=2;i<=r;i++){
    res *= (n-i+1);
    res /=i;
  }
  return res;
}

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i,N) cin >> S[i];
  rep(i,N) sort(S[i].begin(), S[i].end());
  sort(S.begin(), S.end());
  ll ans = 0;
  vector<ll> counter;
  int tmp=1;
  for(int i=1;i<N;i++){
    if(S[i-1]==S[i]) {
      tmp++;
      if(i==N-1) counter.pb(tmp);
    }
    else {counter.pb(tmp); tmp=1;}
  }
  for(int i=0;i<(int)counter.size();i++){
    ans += ncr(counter[i],2);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8444
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt(); 
        
        // 入室した順番の配列
        int[] a = new int [N];
        for(int i = 0;i<N;i++){
          
            a[i] = sc.nextInt();
        }
        
        sc.close();

        // 出席番号を入室順に並べた配列
        int[] ans = new int [N];

        // 入室順の配列を元に出席番号配列を作成する
        for (int i = 0;i<N;i++){
            
            // 入室順配列を頭からアクセス→入室順の数値を元に出席番号を埋める
            ans[a[i]-1] = i + 1; 

        }
        
        for (int answer:ans){
            System.out.println(answer);
        }
        
    }
}

Measured memory_bytes: 62356
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    if(n==0&&m==0){
	cout<<"0"<<endl;
}
    else{
        --n;
		--m;
        cout<<n*m<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int result = 1;
		boolean b = false;
		for(int i = 0; i < n; i++){
			b = result > k;
			if(b){
				result += k;
			}else{
				result *= 2;
			}

		}

		System.out.println(result);
	}
}

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

using namespace std;

int main()
{
  int A, B; cin >> A >> B;
  if (A == B) cout << "Draw";
  else if (A == 1 and B != A) cout << "Alice";
  else if (B == 1 and A != B) cout << "Bob";
  else if ((A > B)) cout << "Alice";
  else cout << "Bob";
}

Measured memory_bytes: 256
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
	int d;
	while(cin >> d) {
		ll sum = 0;
		for(int i=d; i<=600-d; i+=d) {
			sum += d*i*i;
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n, m, p;
    cin >> n >> m >> p;

    vector<li> frs(m), tos(m), costs(m);
    for (int i = 0; i < m; ++i) {
        cin >> frs[i] >> tos[i] >> costs[i];
        frs[i]--;
        tos[i]--;
        costs[i] = p - costs[i];
    }

    const li inf = 1LL << 60;
    vector<li> dists(n, inf);
    dists[0] = 0;

    vector<li> dest_costs;
    dest_costs.push_back(inf);
    for (int itr = 0; itr < n * 3 + 5; ++itr) {
        for (int e = 0; e < m; ++e) {
            dists[tos[e]] = min(dists[tos[e]], dists[frs[e]] + costs[e]);
        }
        dest_costs.push_back(dists[n - 1]);
    }

    if (dest_costs[n] != dest_costs[3 * n]) {
        // 0 -> neg loop -> n-1
        cout << -1 << endl;
    } else {
        cout << max(0LL, -dest_costs[n]) << endl;
    }

    return 0;
}

Measured memory_bytes: 512
import sys
from collections import Counter
readline=sys.stdin.readline
n=readline()
A=list(map(int,readline().split()))
q=int(readline())
D=Counter(A)
s=sum(A)
for _ in range(q):
  b,c=map(int,readline().split())
  s+=(c-b)*D[b]
  D[c]+=D[b]
  del D[b]
  print(s)

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;

int n;
int a[N];

int main() {

	FAST;

	int x;
	cin >> x;
	cout << ((x == 3 || x == 5 || x == 7) ? "YES\n" : "NO\n");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

if N < 3:
    print(0)
    exit()

ans = 0
list1=[]
for i,s in enumerate(S[:-2]):
    if s not in list1:
        list1.append(s)
        list2=[]
        for j,t in enumerate(S[i+1:-1]):
            if t not in list2:
                list2.append(t)
                list3=[]
                for k,u in enumerate(S[i+j+2:]):
                    if u not in list3:
                        ans+=1
                        list3.append(u)

print(ans)

Measured memory_bytes: 3188
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

n = I()
M = 1046527
NIL = -1
H = [None] * M
com = []
ch = []

for i in range(n):
    com_, ch_ = input().split()
    com.append(com_)
    ch.append(ch_)


table = str.maketrans({
'A':'1',
'C':'2',
'G':'3',
'T':'4',
})


def getChar(ch):
    return int(ch.translate(table))

def h1(key):
    return key % M
def h2(key):
    return 1 + (key % (M - 1))

def insert(ch):
    key = getChar(ch)
    i = 0
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] is None:
            H[h] = ch
            break
        else:
            i += 1

def find(ch):
    key = getChar(ch)
    i = 0
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] == ch:
            return 1
        elif H[h] is None:
            return 0
        else:
            i += 1


for i in range(n):
    if com[i][0] == 'i':
        insert(ch[i])
    else:
        if find(ch[i]):
            print('yes')
        else:
            print('no')


Measured memory_bytes: 146848
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  string s;
  cin>>s;
  int n=s.size();
  long long sum=0;
  rep(bit,1<<(n-1)){
    vector<long long> temp(0);
    temp.push_back(int(s[0]-'0'));
    rep(i,n-1){
      if(bit&(1<<i)) temp.push_back(s[i+1]-'0');
      else{
        temp[temp.size()-1]=temp[temp.size()-1]*10+int(s[i+1]-'0');
      }
    }
    for(auto x:temp){
      //cout<<x<<"+";
      sum+=x;
    }
    //cout<<endl<<bit<<" "<<sum<<endl;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    int n;
    double a=0,b=0,c=0,d=0;
    cin >> n;// Your code here!
    int x[2][n];
    for(int i=0;i<n;i=i+1){
        cin >> x[0][i];
    }
    for(int i=0;i<n;i=i+1){
        cin >> x[1][i];
    }
    for(int j=0;j<n;j=j+1){
        a=a+fabs(x[0][j]-x[1][j]);
        b=b+pow(x[0][j]-x[1][j],2);
        c=c+pow(fabs(x[0][j]-x[1][j]),3);
        if(d<fabs(x[0][j]-x[1][j])){
            d=fabs(x[0][j]-x[1][j]);
        }
    }
    cout << fixed << setprecision(8) << a <<endl<< sqrt(b) <<endl<< pow(c,0.33333333333333333333333333333333333) <<endl<< d <<endl;
}




Measured memory_bytes: 3448