akhauriyash/Code-Regression huggingface dataset:
S = input()
ans = 0
for i in range(2**(len(S)-1)):
    s = ''
    for j in range(len(S)-1):
        if ((i >> j) & 1) == 0:
            s += S[j]
        else:
            s += S[j]+'+'
    s += S[-1]
    ans += eval(s)
print(ans)

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


using namespace std;

int main () {
    string s;
    cin >> s;
    
    sort(s.begin(),s.end());
  
    for (char moji='a'; moji <= 'z'; moji++) {
    	if (s.find(moji) == s.npos) {
    	  cout << moji << endl;
          break;
        }
        else if (moji == 'z'&&s.find(moji)!=s.npos) {
          cout << "None" << endl;
        }
        
    }
    
    
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int N;
  cin >> N;
  int a[N+2];
  a[0]= 0 ;
  a[N+1] = 0;
  for(int i=1;i<=N;i++){
    cin >> a[i];
  }

  //全部行く場合の金額sum
  ll sum = 0LL;
  for(int i=0;i<=N;i++){
    sum += abs(a[i+1] - a[i]);
  }

  ll ans;
  for(int i=1;i<=N;i++){
    ans = sum + abs(a[i-1]-a[i+1]) - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

int N;
int v[101000];

int main(){
    cin >> N;
    int res = 0;
    for(int i = 0; i <= N; i++){
        v[i] = 0;
    }
    for(int i = 0; i < N; i++){
        int a2; cin >> a2;
        if(a2 > N){
            res++;
        }
        else{
            v[a2]++;
        }
    }

    for(int i = 1; i <= N; i++){
        if(v[i] < i){
            res += v[i];
        }
        else{
            res += (v[i] - i);
        }
    }

    cout << res << endl;


    return 0;

}


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

int main() {
    int N;
    int t[110000], x[110000], y[110000];
    std::cin >> N;
    t[0] = x[0] = y[0] = 0;
    for (int i = 0; i < N; i++) {
        std::cin >> t[i+1] >> x[i+1] >> y[i+1];
    }

    bool can = true;
    for (int i = 0; i < N; i++) {
        int dt = t[i+1] - t[i];
        int dist = std::abs(x[i+1] - x[i]) + std::abs(y[i+1] - y[i]);
        if (dt < dist) {
            can = false;
        }
        if (dist % 2 != dt % 2) {
            can = false;
        }
    }

    if (can) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <string.h>
int main()
{
  int i = 0 ;
  int len, sum ;
  char c[1010],ch ;

  while( scanf("%s", c) && c[0] != '0'){
    sum = 0 ;
    len = strlen(c) ;
    for( i = 0 ; i < len ; i++){
      sum += ( c[i] - '0' ) ;
    }
    printf("%d\n", sum) ;
  }

  return 0 ;
}



Measured memory_bytes: 2040
l = []
for _ in range(3):
  A = list(map(int, input().split()))
  l.append(A)
N = int(input())
R = []
for _ in range(N):
  b = int(input())
  for i in range(3):
    if b in l[i]:
      for j in range(3):
        if b == l[i][j]:
          R.append((i, j))
if ({(0, 0), (1, 0), (2, 0)} <= set(R)) or ({(0, 1), (1, 1), (2, 1)} <= set(R)) or ({(0, 2), (1, 2), (2, 2)} <= set(R)) or ({(0, 0), (0, 1), (0, 2)} <= set(R)) or ({(1, 0), (1, 1), (1, 2)} <= set(R)) or ({(2, 0), (2, 1), (2, 2)} <= set(R)) or ({(0, 0), (1, 1), (2, 2)} <= set(R)) or ({(0, 2), (1, 1), (2, 0)} <= set(R)):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
  int x[5], ans;
  for(int i=0; i<5; i++){
    scanf("%d",&x[i]);
  }
  
  for(int i=0; i<5; i++){
    if(x[i]==0){
      ans=i+1;
    }
  }
  printf("%d", ans); 
  return 0;
}

Measured memory_bytes: 1684
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;
/**
 *
 * @author Jeel
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long n=sc.nextLong();
        long a=sc.nextLong();
        long b=sc.nextLong();
        if(n==1&a!=b)
        {
            System.out.print("0");
            return;
        }
        else if(b<a)
        {
            System.out.print("0");
            return;
        }
        System.out.print((b*(n-1)+a)-((a*(n-1))+b)+1);
    }
    
}


Measured memory_bytes: 23764
import sys
sys.setrecursionlimit(10 ** 7)

def resolve():
    def rec(v):
        if dp[v] != -1:
            return dp[v]
        res = 0
        for nv in G[v]:
            res = max(res, rec(nv)+1)
        dp[v] = res
        return res

    N, M = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        x, y = map(lambda x:int(x)-1, input().split())
        G[x].append(y)

    dp = [-1]*N
    ans = 0
    for v in range(N):
        ans = max(ans, rec(v))
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 74584
#include<bits/stdc++.h>
#include<cstdio>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define substr(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
vvi E(100010);
int par[100010];
int dist[100010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;cin>>n>>m;
  vi hoge(100010);
  int num=n+m-1;
  int a,b;
  for(int i=0;i<num;i++){
   cin>>a>>b;
    E[a].pb(b);
    hoge[b]++;
  }
  vi cnt(100010);
  for(int i=1;i<=n;i++){
    if(hoge[i]!=0)continue;
    queue<int>que;
    que.push(i);
    while(!que.empty()){
      int now=que.front();
      que.pop();
      for(int j=0;j<E[now].size();j++){
	  cnt[E[now][j]]++;
	  par[E[now][j]]=now;
	  if(cnt[E[now][j]]==hoge[E[now][j]])
	    que.push(E[now][j]);
      }
    }
  }
  for(int i=1;i<=n;i++){
    printf("%d\n",par[i]);
  }
  return 0;
}



Measured memory_bytes: 7552
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,m=0,ans=0; cin>>n;
    rep(i,n){
        int p; cin>>p;
        ans+=p; m=max(m,p);
    }
    cout<<ans-m/2<<endl;
}


Measured memory_bytes: 3640
import sys
def input():
	return sys.stdin.readline()[:-1]

def Z_algorithm(s):
	l = len(s)
	res = [-1 for _ in range(l)]
	res[0] = l
	i, j = 1, 0
	while i < l:
		while i+j < l and s[j] == s[i+j]:
			j += 1
		res[i] = j

		if j == 0:
			i += 1
			continue
		else:
			k = 1
			while i+k < l and k + res[k] < j:
				res[i+k] = res[k]
				k += 1

			i += k
			j -= k

	return res

s = input()
s_concat = s
t = input()
ns, nt = len(s), len(t)

if ns == 1:
	if {s} == set(list(t)):
		print(-1)
	else:
		print(0)
	sys.exit()

while len(s_concat) < ns + nt - 1:
	s_concat += s
ts_concat = t + " " + s_concat
z = Z_algorithm(ts_concat)

adj = [-1 for _ in range(ns)]

for i in range(1, len(z)):
	if i-nt-1 >= ns:
		break
	if z[i] == nt:
		j = i-nt-1
		if j == (j+nt)%ns:
			print(-1)
			sys.exit()
		adj[j] = (j+nt)%ns

visited = [False for _ in range(ns)]
path_len = [0 for _ in range(ns)]

def dfs(x):
	cur = x
	res = 0
	while adj[cur] >= 0:
		visited[cur] = True
		if adj[cur] == x:
			print(-1)
			sys.exit()
		res += 1
		if path_len[adj[cur]] > 0:
			path_len[x] = path_len[adj[cur]] + res
			return path_len[adj[cur]] + res
		cur = adj[cur]
	path_len[x] = res
	return res

ans = 0
for i in range(ns):
	if not visited[i]:
		d = dfs(i)
		ans = max(ans, d)

if ans == ns:
	print(-1)
else:
	print(ans)

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 999999999;

int main(){
   string s;
   cin >> s;
   int ans = min(count(s.begin(),s.end(),'0'), count(s.begin(),s.end(),'1'));
   cout << ans*2;
   return 0;
}

Measured memory_bytes: 512
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      r: usize,
      c: usize,
      k: usize,
      rcv: [(Usize1, Usize1, usize); k]
   }

   let mut map = vec![vec![]; r];
   for (r, c, v) in rcv {
      map[r].push((c, v));
   }
   for i in 0..r {
      map[i].sort();
   }

   let mut dp = vec![0usize; c];
   for i in 0..r {
      let mut next = dp.clone();
      let m = map[i].len();
      for j in 0..m {
         let (r1, _) = map[i][j];
         let mut stock = BinaryHeap::new();
         let mut tot = 0;
         for k in j..m {
            let (r2, v) = map[i][k];
            if stock.len() < 3 {
               stock.push(Reverse(v));
               tot += v;
            } else if let Some(Reverse(u)) = stock.pop() {
               if v > u {
                  tot += v - u;
                  stock.push(Reverse(v));
               } else {
                  stock.push(Reverse(u));
               }
            }
            next[r2] = max(next[r2], dp[r1] + tot);
         }
      }
      for j in 1..c {
         next[j] = max(next[j], next[j - 1]);
      }
      dp = next;
   }
   println!("{}", dp[c - 1]);
}


Measured memory_bytes: 16232
#include<stdio.h>
int main()
  { 
    int n,i,count=0;
    scanf("%d",&n);
    if(n>1)
      { 
        for(i=2;i<=n;i++)
          { 
             if(i%2==1)
               { 
                count++;
               }
          }
       count++;
       printf("%d",count);
      }
  else if(n==1)
    printf("1");
  return 0;
  }

Measured memory_bytes: 128
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  string a, b;
  cin >> a >> b;
  if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
def main():
    D = int(input())
    C = [0] * 26
    C = list(map(int,input().split()))
    S = [ list(map(int,input().split(" "))) for i in range(D)]
    
    score = 0
    last = [0] * 26
    for i in range(D):
        t = int(input())
        for j in range(26):
            if j+1 == t:
                last[j] = 0
                score += S[i][j]
            else:
                last[j] += 1
                score -= last[j]*C[j]
        print(score)
if __name__ == '__main__':
    main()

Measured memory_bytes: 9236
#include <iostream>
#include <cstdio>
#define gc getchar()
#define pc putchar
#define rep(i,x,p) for(int i = x;i <= p;++ i)
#define sep(i,x,p) for(int i = x;i >= p;-- i)
using namespace std;
const int maxN = 1e5 + 7;

int a[maxN];

inline int read() {
    int x = 0 ,f = 1;char c = gc;
    while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
    while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}
    return x * f;
}

void print(int x) {
    if(x < 0) {
        pc('-');
        x = -x;
    }
    if(x >= 10) print(x / 10);
    pc(x % 10 + '0');
}

int main() {
    int n,maxx = 0, minn = 1e6;
    n = read();
    rep(i,1,n) a[i] = read();
    rep(i,1,n) maxx = max(maxx,a[i]);
    rep(i,1,n) minn = min(minn,a[i]);
    if(maxx != minn + 1 && maxx != minn)  {puts("No");return 0;}
    if(maxx == minn) {
        if(a[1] == n - 1 || 2 * a[1] <= n) puts("Yes");
        else puts("No");
        return 0;
    }
    int cnt = 0;
    rep(i , 1 , n) if(a[i] == minn) cnt ++;
	if(cnt >= maxx || 2 * (maxx - cnt) > n - cnt) puts("No");
	else puts("Yes");
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int a, b;
	char op;
	cin >> a >> op >> b;
	while (op != '?') {
		int c;
		if (op == '+') c = a + b;
		if (op == '-') c = a - b;
		if (op == '*') c = a*b;
		if (op == '/') c = a / b;
		cout << c << endl;
		cin >> a >> op >> b;
	}
	return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map> 
using namespace std;

#define LL long long
#define MOD (1000000007)


//C
struct LLPair
{
	LL a = 0;
	LL b = 0;
};

int main() {
	LL N;
	scanf("%lldd", &N);

	vector<LLPair> A;
	for (LL i = 1; i <= N; i++) {
		LL a;
		scanf("%lld", &a);

		LLPair p;
		p.a = i;
		p.b = a;

		A.push_back(p);
	}

	std::sort(A.begin(), A.end(), [](const LLPair &a, const LLPair &b) {
		return a.b < b.b;
	});

	for (auto item : A) {
		printf("%lld ", item.a);
	}

	printf("\n");

	return 0;
}


//B
/*
int main() {
	LL N, K;
	scanf("%lld %lld", &N, &K);

	LL result = 0;

	for (LL i = 0; i < N; i++) {
		LL h;
		scanf("%lld", &h);

		if (h >= K) {
			result++;
		}
	}

	printf("%lld\n", result);

	return 0;
}
*/

//A
/*
int main() {
	LL N;

	scanf("%lld", &N);

	double result = (double)((N + 1) / 2) / (double)N;

	printf("%0.9f\n", result);

	return 0;
}
*/

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

typedef long long ll;
#define rep(var,n)  for(int var=0;var<(n);++var)

ll solve(ll N, vector<ll>& a) {
    ll ans = 0;
    while (true) {
        ll s = 0;
        rep(i, N) {
            s += a[i] / N;
        }
        if (s == 0) break;
        ans += s;
        rep(i, N) {
            ll q = a[i] / N;
            a[i] = a[i] - q*N + (s - q);
        }
    }
    return ans;
}

int main() {
    int N; cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    cout << solve(N,a) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int i,a,b;
    for(i=0; i<9; i++){
        string name;
        cin >> name >> a >> b;
        cout << name << " " << a+b << " " << 200*a+300*b << endl;
    }
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	ll a, b, c; cin >> a >> b >> c;
	ll link = a*b*4;
	ll recht = c*c + (a+b-c*2)*(a+b);
	if( c-(a+b) > 0 && link < recht ) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

ll solve(ll w,ll a,ll b){
    int res;
    int c = min(a,b);
    int d = max(a,b);
    c += w;
    res = d-c<0 ? 0:d-c;
    return res;
}

int main(){
    int a,b;cin>>a>>b;
    ll ans;
    if(a+b>=24){
        ans = a+b-24;
    }else{
        ans = a+b;
    }
    cout<<ans;
	return 0;
}

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

int main(){

  int n;
  cin >> n;

  vector<vector<int>> hpn(n, vector<int>(3));
  for(int i = 0; i < n; i++) cin >> hpn[i][0] >> hpn[i][1] >> hpn[i][2];

  vector<vector<int>> dp(n, vector<int>(3, 0));
  dp[0][0] = hpn[0][0]; dp[0][1] = hpn[0][1]; dp[0][2] = hpn[0][2];

  for(int i = 1; i < n; i++){
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + hpn[i][0];
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + hpn[i][1];
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + hpn[i][2];
  }

  cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << endl;

  return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main() {
	int a, b, cnt[55] = {}, c, d;
	cin >> a >> b;
	for (int i = 0; i < b; i++) {
		cin >> c >> d;
		cnt[c]++; cnt[d]++;
	}
	for (int i = 1; i <= a; i++)cout << cnt[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

struct Node {
  int key;
  struct Node *right, *left, *parent;
};

struct Node *root, *NIL;

void insert(int k) {
  struct Node *y =  NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void preParse(struct Node *u) {
  if (u == NIL) return;
  preParse(u->left);
  printf(" %d", u->key);
  preParse(u->right);
}

void inParse(struct Node *u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  inParse(u->left);
  inParse(u->right);
}

int main() {

  int n, x;
  char com[10];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s%d", com, &x);
    if (com[0] == 'i') {
      insert(x);
    } else {
      preParse(root);
      printf("\n");
      inParse(root);
      printf("\n");
    }
  }
  return 0;
}



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

s={}
cnt=0
result=[]

for _ in range(n):
    temp = input()
    if temp in s:
        s[temp]+=1
        if s[temp]>cnt:
            cnt=s[temp]
            result=[temp]
        elif s[temp]==cnt:
            result.append(temp)
    else:
        s[temp]=1
        if s[temp]>cnt:
            cnt=s[temp]
            result=[temp]
        elif s[temp]==cnt:
            result.append(temp)
result.sort()
for item in result:
    print(item)



Measured memory_bytes: 97240
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1LL<<60;

int main()
{
  ll n;cin>>n;
  vector<ll> R(n);
  rep(i, n) {
    cin >> R[i];
  }

  ll max = -INF;
  ll min = R[0];

  for(int i = 1; i < n; i++) {
    if (R[i] - min > max) max = R[i] - min;
    if (min > R[i]) min = R[i];
  }

  cout << max << endl;
  return 0;
}


Measured memory_bytes: 4412
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

void solve(int node, vector<int>& counter, vector<vector<int> >& edges, vector<bool>& visited)
{
	for(int i = 0; i < edges[node].size(); ++i)
	{
		int nextNode = edges[node][i];
		if(!visited[nextNode])
		{
			counter[nextNode] += counter[node];
			visited[nextNode] = true;
			solve(nextNode, counter, edges, visited);
		}
	}
}

int main()
{
	int n, q;
	vector<int> counter;
	vector<vector<int> > edges;
	vector<bool> visited;

	cin >> n >> q;

	counter.resize(n + 1);
	edges.resize(n + 1);
	visited.resize(n + 1);

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

	for(int i = 1; i <= n; ++i)
	{
		counter[i] = 0;
	}

	for(int i = 0; i < q; ++i)
	{
		int p, x;
		cin >> p >> x;
		counter[p] += x;
	}

	visited[1] = true;
	solve(1, counter, edges, visited);

	cout << counter[1];
	for(int i = 2; i <= n; ++i)
	{
		cout << " " << counter[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 29824
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;

signed main() {
	cin >> n;
	
	int ans = 1e+15;
	for (int x = 1; x * x <= n; x++) {
		if (n % x != 0) continue;
		int y = n / x;
		ans = min(ans, x + y - 2);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){

    int N, M;
    map<string, int> blue;
    map<string, int> red;
    cin >> N;
    for (int i=0; i<N; i++){
        string buf;
        cin >> buf;
        blue[buf]++;
    }
    cin >> M;
    for (int i=0; i<M; i++){
        string buf;
        cin >> buf;
        red[buf]++;
    }

    int ans = 0, temp = 0;
    for (auto bp: blue){
        auto bkey = bp.first;
        auto bvalue = bp.second;
        
        temp += bvalue;

        for (auto rp: red){
            auto rkey = rp.first;
            auto rvalue = rp.second;

            if (bkey == rkey) temp -= rvalue;
        }
        ans = max(ans, temp);
        temp = 0;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N1 100100
#define N2 1000010
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);



signed main()
{
    
    speed
    int n,k;cin>>n>>k;
    cout<<min(n%k,abs(n%k-k))<<endl;

    
    
    return 0;
}

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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') f = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> bool chkmax(Tp &x, Tp y) {return x > y ? 0 : (x=y,1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x < y ? 0 : (x=y,1);}
template <typename Tp> Tp Max(Tp x, Tp y) {return x > y ? x : y;}
template <typename Tp> Tp Min(Tp x, Tp y) {return x < y ? x : y;}

const int MAXN = 200010;

int n, num[MAXN];

int main()
{
	in(n);
	FOR(i, 1, n) in(num[i]);

	for (int i = n; i >= 1; i -= 2) printf("%d ", num[i]);
	for (int i = (n & 1) + 1; i <= n; i += 2) printf("%d ", num[i]);

	putchar(10);
	
	return 0;
}


Measured memory_bytes: 2944
n = int(input())
p = 10**9 + 7
memo = [{} for _ in range(n+1)]
def check(L4):
  for i in range(4):
    t = list(L4)
    if i > 0:
      t[i], t[i-1] = t[i-1], t[i]
    if "".join(t).count("AGC") >= 1:
      return False
  return True
def dfs(d, L3):
  if L3 in memo[d]:
    return memo[d][L3]
  if d >= n:
    return 1
  ret = 0
  for L in list("ACGT"):
    L4 = L3 + L
    if check(L4):
      ret += dfs(d + 1, L4[1:]) 
    memo[d][L3] = ret
  return ret % p
    
  
  
print(dfs(0, "TTT"))
  

Measured memory_bytes: 52572
N = int(input())
H = list(map(int,input().split()))
H = H[::-1]
for i in range(N-1):
    if (H[i]+1<H[i+1]):
        print('No')
        exit()
    elif(H[i]+1 ==H[i+1]):
        H[i+1] = H[i]
print('Yes')

Measured memory_bytes: 20620
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	float a, b;
	
	while(cin >> a >> b){
		if(a < 35.50 && b < 71.0){
			cout << "AAA" << endl;
		} else if(a < 37.50 && b < 77.0){
			cout << "AA" << endl;
		} else if(a < 40.00 && b < 83.0){
			cout << "A" << endl;
		} else if(a < 43.00 && b < 89.0){
			cout << "B" << endl;
		} else if(a < 50.00 && b < 105.0){
			cout << "C" << endl;
		} else if(a < 55.00 && b < 116.0){
			cout << "D" << endl;
		} else if(a < 70.00 && b < 148.0){
			cout << "E" << endl;
		} else {
			cout << "NA" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
int dp[501][501]={};
int main(){
    int n,m,q,l,r,pi,qi;
    scanf("%d%d%d",&n,&m,&q);
    for(int i=0;i<m;i++){
        scanf("%d%d",&l,&r);
        dp[l][r]++;
    }
    for(int i=1;i<=n;i++){
        for(int j=2;j<=n;j++){
            dp[i][j]+=dp[i][j-1];
        }
    }
    for(int j=1;j<=n;j++){
        for(int i=n-1;i>=1;i--){
            dp[i][j]+=dp[i+1][j];
        }
    }
    for(int i=0;i<q;i++){
        scanf("%d%d",&pi,&qi);
        printf("%d\n",dp[pi][qi]);
    }
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long a,b,c=0,d,e,g,h,i,j,k;
    vector<long long>vc;
    vector<long long>dc;
    cin>>a;
    for(i=0; i<a; i++)
    {
        cin>>b;
        vc.push_back(b);
        dc.push_back(b);
    }
    sort(dc.begin(),dc.end());
    for(i=0; i<a; i++)
    {
        if(vc[i]!=dc[i])
            c++;
    }
    if(c>2)
        cout<<"NO";
    else
        cout<<"YES";
}







Measured memory_bytes: 256
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort(),c.sort()
x=len(c)
ans=0
for bi in b:
  xa=bisect.bisect_right(c,bi)
  xb=bisect.bisect_left(a,bi)
  ans+=xb*(x-xa)
print(ans)

Measured memory_bytes: 23360
N = gets.to_i
h = gets.split(' ').map(&:to_i)

dp = Array.new(N, 10**4)
N.times do |i|
  next if i == 0
  if i == 1
    dp[i] = (h[1]-h[0]).abs
  elsif i >=2
    a = dp[i-1]+(h[i]-h[i-1]).abs
    b = (h[i]-h[i-2]).abs
    b += dp[i-2] if i > 2
    dp[i] = [a, b].min
  end
end

puts dp[N-1]

Measured memory_bytes: 11404
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
#define MOD 1000000007
typedef pair<int,int> P;
typedef pair<int,P> PP;

signed main(){
  int n,w;
  cin>>n>>w;
  vector<int> wv(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>wv[i];
    sum+=wv[i];
  }
  if(sum<=w){
    cout<<1<<endl;
    return 0;
  }
  sort(all(wv),greater<int>());
  vector<vector<int> > dp(2,vector<int>(sum+1,0));
  dp[0][0]=1;
  int ans=0;
  for(int i=0;i<n;i++){
    int ii=i%2;
    int ni=(i+1)%2;
    dp[ni]=vector<int>(sum+1,0);
    for(int j=0;j<=sum;j++){
	 if(dp[ii][j]==0)continue;
	 dp[ni][j]+=dp[ii][j];
	 dp[ni][j]%=MOD;
	 dp[ni][j+wv[i]]+=dp[ii][j];
	 dp[ni][j+wv[i]]%=MOD;
	 if(sum-j-wv[i]<=w&&sum-j>w){
	   //cout<<i<<" "<<j<<endl;
	   ans+=dp[ii][j];
	   ans%=MOD;
	 }
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 23696
K = int(input())
import queue

# FIFOキューの作成
q = queue.Queue()
for i in range(1, 10):
    q.put(i)
k = 0
while k< K:
    x = q.get()
    k += 1
    if x %10 != 0:
        q.put(x*10 + x%10 - 1)
    q.put(x*10 + x%10)
    if x % 10 != 9:
        q.put(x*10 + x%10 +1)
    
print(x)

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

int main()
{
	char code[5];
	bool isbad = false;
	cin >> code;
	for (int i = 1; i < 4; i++) {
		if (code[i] == code[i - 1])isbad = true;
	}
	if (isbad) cout << "Bad" << endl;
	else cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    ll N,K;
    ll A[3];
    ll ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>A[0]>>A[1]>>A[2]>>K;
    sort(A,A+3);
    REP(i,K){
        A[2]*=2;
    }
    cout<<A[0]+A[1]+A[2];

    return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> memo(n, 0);
    memo[1] = 1;
    repd(i, 2, n) {
        if (memo[i] == 0) {
            memo[i] = i;
            for (ll j = i; j <= n; j += i) {
                if (memo[j] == 0) {
                    memo[j] = i;
                }
            }
        }
    }

    ll ans = 0;
    repd(i, 1, n) {
        map<ll, ll> m;
        ll num = i;
        while (num != 1) {
            m[memo[num]]++;
            num /= memo[num];
        }

        ll temp = 1;
        for (auto iter = m.begin(); iter != m.end(); iter++) {
            temp *= iter->second + 1;
        }
        ans += temp;
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 11120
N = int(input())
S = input()
ans = 10**8
li = [0]

b=[0]
w=[0]
for ind,i in enumerate(S):
    if(ind==0):
        if(i=='#'):
            b+=[0]
            b[-1]+=1
        else:
            w[-1]+=1
    elif(ind==N-1):
        if(i==S[ind-1]):
            if(i=='#'):
                b[-1]+=1
            else:
                w[-1]+=1
                b+=[b[-1]]
        else:
            if(i=='#'):
                b+=[b[-1]+1]
            else:
                w+=[w[-1]+1]
                b+=[b[-1]]

    else:
        if(i==S[ind-1]):
            if(i=='#'):
                b[-1]+=1
            else:
                w[-1]+=1
        else:
            if(i=='#'):
                b+=[b[-1]+1]
            else:
                w+=[w[-1]+1]
b = [0]+b
w = [0]+w
for ind,i in enumerate(w):
    ans = min(ans,w[-1]-w[ind]+b[ind])



print(ans)


Measured memory_bytes: 11948
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a[3];
	cin>>a[0]>>a[1]>>a[2];
	if(a[0]%2==0||a[1]%2==0||a[2]%2==0){cout<<"0"<<endl;return 0;}
	sort(a,a+3);
	cout<<a[0]*a[1]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <climits>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;


char dat[510][510];


int solve(vector<string> dat) {
  int n = dat.size();
  int ans = INT_MAX;

  vector<int> colwhite(n), rowwhite(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dat[i][j] == '.') {
        rowwhite[i]++;
        colwhite[j]++;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    int repaint = 0;
    int holecnt = 0;
    for (int k = 0; k < n; k++) {
      if (dat[i][k] == '#') {
        if (colwhite[k] > 0) {
          repaint++;
        }
      }
      else {
        holecnt++;
      }
    }
    if (holecnt == 0) {
      int cur = repaint;
      ans = min(ans, cur);
      continue;
    }
    for (int j = 0; j < n; j++) {
      if (dat[j][i] != '#')
        continue;
      int cur = holecnt;
      cur += repaint;
      if (rowwhite[j] > 0) {
        cur += holecnt;
      }
      ans = min(ans, cur);
    }
    if (holecnt < n && dat[i][i] == '.') { // at least one #
      int cur = 1 + holecnt;
      cur += repaint;
      cur += holecnt;
      ans = min(ans, cur);
    }
  }

  if (ans == INT_MAX)
    ans = -1;
  return ans;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<string> inp;
  for (int i = 0; i < n; i++) {
    scanf("%s", dat[i]);
    inp.emplace_back(dat[i]);
  }
  printf("%d\n", solve(inp));
  return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
     
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
     
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll, ll>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main () {
  int n, i;
  cin >> n;
  vi d(n);
  for (i = 0; i < n; i++) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
  int now = 1000;
  int cnt = 0;
  for (i = 0; i < n; i++) {
    if (d[i] < now) {
      now = d[i];
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a[5],i;
  for(i=0;i<5;i++){
  scanf("%d",&a[i]);
  }
  for(i=0;i<5;i++){
    if(a[i]==0){
    printf("%d\n",i+1);
    }
  }
}           

Measured memory_bytes: 2092
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    private static final long MOD = 1_000_000_007;

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

        final long[] accum = new long[200_001];
        final long[] sums = new long[n];
        final int first = scanner.nextInt();
        int prev = first;
        accum[first] = 1;
        sums[0] = 1;
        for (int i = 1; i < n; i++) {
            sums[i] = sums[i - 1];
            final int c = scanner.nextInt();
            if (prev == c) {
                continue;
            }
            prev = c;

            sums[i] += accum[c];
            sums[i] %= MOD;
            accum[c] += sums[i - 1];
            accum[c] %= MOD;
        }

        System.out.println(sums[n - 1]);
    }
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;
#define N 1000001

int n;
int p[N];

void initP() {

	for (int i = 2; i*i <= n; i++) {
		// p[i] += 2;
		p[i*i]++;

		for (int j = i+1; i*j <= n; j++)
			p[i*j] += 2;
	}

	// for (int i = 1; i <= n; i++)
	// 	cout << "(" << i << ")" << p[i] << ", ";
}

int numDivisors(int n) {
	if (n == 1)
		return 1;
	return p[n] + 2;
}

int main() {

	IOS

	
	cin >> n;

	initP();

	int c = 0;

	for (int i = 1; i < n; i++)
		c += numDivisors(n-i);

	cout << c;

	return 0;
}

Measured memory_bytes: 7480
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;
	int tot = (n - k) * 100 + k * 1900;
	while (k--) tot *= 2;
	cout << tot << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(void){
   
   char M[100];
   
   scanf("%s",M);
   
   int M1 = M[5] - '0';
   int M2 = M[6] - '0';
   
   int D1 = M[8] - '0';
   int D2 = M[9] - '0';

   
   if(M1 == 0 && M2 <= 4){
      printf("Heisei\n");
   }
   else {
      printf("TBD\n");
   }
 
   return 0;
   
}



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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  
  vector<ll> a(x), b(y), c(z);
  for(int i = 0; i < x; i++) cin >> a.at(i);
  for(int i = 0; i < y; i++) cin >> b.at(i);
  for(int i = 0; i < z; i++) cin >> c.at(i);
  
  vector<ll> d;
  for(int i = 0; i < x; i++){
    for(int j = 0; j < y; j++){
      d.push_back(a.at(i) + b.at(j));
    }
  }
  
  sort(d.rbegin(), d.rend());
  
  vector<ll> e;
  for(ll i = 0; i < min<ll>(k, x * y); i++){
    for(int j = 0; j < z; j++){
      e.push_back(d.at(i) + c.at(j));
    }
  }
  
  sort(e.rbegin(), e.rend());
  
  for(int i = 0; i < k; i++) cout << e.at(i) << '\n';
}

Measured memory_bytes: 43112
N = int(input())
balls = []
for i in range(2 * N):
    c, a = input().split()
    balls += [(c, int(a))]

# numB[i][b]: 初期状態において、i番目の玉より右にある、1～bが書かれた黒玉の数
numB = [[0] * (N + 1) for i in range(2 * N)]
numW = [[0] * (N + 1) for i in range(2 * N)]
for i in reversed(range(1, 2 * N)):
    c, a = balls[i]
    numB[i - 1] = list(numB[i])
    numW[i - 1] = list(numW[i])
    if c == 'B':
        for b in range(a, N + 1):
            numB[i - 1][b] += 1
    else:
        for w in range(a, N + 1):
            numW[i - 1][w] += 1

# costB[b][w]: 黒玉1～b、白玉1～wのうち、初期状態において、黒玉[b+1]より右にある玉の数
costB = [[0] * (N + 1) for i in range(N + 1)]
costW = [[0] * (N + 1) for i in range(N + 1)]
for i in reversed(range(2 * N)):
    c, a = balls[i]
    if c == 'B':
        cost = numB[i][a - 1]
        for w in range(N + 1):
            costB[a - 1][w] = cost + numW[i][w]
    else:
        cost = numW[i][a - 1]
        for b in range(N + 1):
            costW[b][a - 1] = cost + numB[i][b]

dp = [[float('inf')] * (N + 1) for i in range(N + 1)]
dp[0][0] = 0
for b in range(N + 1):
    for w in range(N + 1):
        if b > 0:
            dp[b][w] = min(dp[b][w], dp[b - 1][w] + costB[b - 1][w])
        if w > 0:
            dp[b][w] = min(dp[b][w], dp[b][w - 1] + costW[b][w - 1])

print(dp[N][N])


Measured memory_bytes: 325764
#include <bits/stdc++.h>
#define tt this->
#define ll long long
using namespace std;
int main ()
{
int n,k,sum=0;
cin>>n>>k;
int a[n];
for (int i=0 ; i<n;i++)
{
    cin>>a[i];
}

sort(a,a+n);
for (int i=0 ; i < k ;i++)
{
    sum=sum+a[i];
}
cout<<sum<<endl;
    return 0;
}

/*
▀█████████▄     ▄████████    ▄████████    ▄████████
  ███    ███   ███    ███   ███    ███   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
 ▄███▄▄▄██▀    ███    ███  ▄███▄▄▄▄██▀   ███    ███
▀▀███▀▀▀██▄  ▀███████████ ▀▀███▀▀▀▀▀   ▀███████████
  ███    ██▄   ███    ███ ▀███████████   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
▄█████████▀    ███    █▀    ███    ███   ███    █▀
                            ███    ███

*/


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

using namespace std;

using ll = long long;
struct Edge {
    int dst;
    ll w;
    Edge() {}
    Edge(int d, ll w) : dst(d), w(w) {}
};
using Graph = vector<vector<Edge>>;
struct Cube { ll p[3]; };

// グラフを構成する
Graph MakeGraph(const int n, const int s, vector<Cube> &c) {
    Graph g(n);
    ll d[3];

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = 0; k < 3; ++k)
                d[k] = s - abs(c[i].p[k] - c[j].p[k]);
//                d[k] = s + ((c[i].p[k] < c[j].p[k]) ? (c[i].p[k] - c[j].p[k]) : (c[j].p[k] - c[i].p[k]));

            // c[i]とc[j]は交差しない
            if (min({d[0], d[1], d[2]}) <= 0) continue;

            ll w = 2 * d[0] * d[1] + 2 * d[0] * d[2] + 2 * d[1] * d[2];
            g[i].emplace_back(Edge(j, w));
            g[j].emplace_back(Edge(i, w));
        }
    }

    return g;
}

int MinimumArea(const int n, const int k, const int s, const Graph &g) {
    vector<bool> used(n, false);
    ll res = -1;

    for (int u = 0; u < 2 * n; ++u) {
        if (used[u % n] || (u < n && g[u % n].size() == 2)) continue;

        const int v = u % n;

        // vが含まれる連結成分を探す
        vector<int> sub;
        int cur = v;
        while (true) {
            used[cur] = true;
            sub.push_back(cur);
            if (1 <= g[cur].size() && !used[g[cur][0].dst])
                cur = g[cur][0].dst;
            else if (g[cur].size() == 2 && !used[g[cur][1].dst])
                cur = g[cur][1].dst;
            else
                break;
        }

        const int size = sub.size();
        if (size < k) continue;

        ll sum = 0;
        for (int i = 0; i < k - 1; ++i)
            sum += ((g[sub[i]][0].dst == sub[i + 1]) ? g[sub[i]][0].w : g[sub[i]][1].w);

        const bool is_cycle = (g[sub[0]].size() == 2);
        if (size == k && is_cycle) {
            sum += ((g[sub[0]][0].dst == sub[size - 1]) ? g[sub[0]][0].w : g[sub[0]][1].w);
            res = max(res, sum);
            continue;
        }
        res = max(res, sum);

        // 連結成分内でサイズkの連結な辺部分集合を全探索する
        const int lim = (is_cycle ? size - 1 : size - k);
        for (int i = 1; i <= lim; ++i) {
            sum -= ((g[sub[i]][0].dst == sub[i - 1]) ? g[sub[i]][0].w : g[sub[i]][1].w);
            const int j1 = (i + k - 2) % size, j2 = (i + k - 1) % size;
            sum += ((g[sub[j1]][0].dst == sub[j2]) ? g[sub[j1]][0].w : g[sub[j1]][1].w);
            res = max(res, sum);
        }
    }

    return (res == -1) ? -1 : 6 * k * s * s - res;
}

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

    int n, k, s;

    while (cin >> n >> k >> s, n) {
        vector<Cube> cube(n);
        for (auto &c : cube)
            for (int i = 0; i < 3; ++i) cin >> c.p[i];

        cout << MinimumArea(n, k, s, MakeGraph(n, s, cube)) << '\n';
    }

    return 0;
}



Measured memory_bytes: 3144
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main() {
    double x, y, s, t;
    cin >> x >> y >> s >> t;
    double a, b;
    a = s - x;
    b = t - y;
    a *= a;
    b *= b;
    double ans = sqrt( a + b );
    printf("%lf\n", ans);    

    return 0;
}


Measured memory_bytes: 3284
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 110;
ll v[N],w[N];
ll f[100010];
int n,m;
int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> v[i] >> w[i];
	for(int i = 1; i <= n; i++)
	{
		for(int j = m; j >= v[i]; j--)
		{
			f[j] = max(f[j],f[j-v[i]] + w[i]);
		}
	}
	cout << f[m] << endl; 
}


Measured memory_bytes: 1024
N=int(input())
s=[int(input()) for i in range(N)]

ans=sum(s)
s.sort()
if ans%10==0:
	for i in range(N):
		if s[i]%10!=0:
			ans-=s[i]
			break
if ans%10!=0:
	print(ans)
else:
	print(0)

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             5e13
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>
#define all(a)          a.begin(),a.end()
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
LL ara[2004];
LL tree[10005];

void update(LL at,LL L,LL R,LL pos,LL val)
{
    if(pos<L or R<pos)return;

    if(pos==L and pos==R)
    {
        tree[at] = val;
        return;
    }

    LL mid = (L+R)/2;
    update(2*at,L,mid,pos,val);
    update(2*at+1,mid+1,R,pos,val);
    tree[at]=min(tree[2*at],tree[2*at+1]);
}

LL query(LL at,LL L,LL R,LL l,LL r)
{
    if(l > r)return 1e18;
    if(r<L or R<l)return 1e18;
    if(l<=L and R<=r)return tree[at];

    LL mid = (L+R)/2;
    LL x = query(2*at,L,mid,l,r);
    LL y = query(2*at+1,mid+1,R,l,r);

    return min(x,y);
}

LL n,x;
inline LL check(LL r)
{
   int bam = - r;
   LL ans = 0;
   for(int i  = 0 ; i < n;i++,bam++){
      LL mn = ara[i];
      int pos = ((bam%n) + n)%n;
      if(pos > i)
      {
         mn = min(mn, query(1,0,n-1,pos,n-1));
         mn = min(mn, query(1,0,n-1,0,i-1));
      }else{
         mn = min(mn, query(1,0,n-1,pos,i-1));
      }
      ans += mn;
   }

   ans = ans + x * r;
   return ans;
}
int main()
{
   FastRead
   cin >> n >> x;

   for(int i = 0;i < n;i++){
      cin >> ara[i];
      update(1,0,n-1,i,ara[i]);
   }

   LL lo = 0, hi = n - 1;
   while(hi - lo > 3)
   {
      LL m1 = (hi-lo)/3 + lo;
      LL m2 = (hi-lo)/3 + m1;
      if(check(m1) > check(m2)){
         lo = m1;
      }else{
         hi = m2;
      }
//      cout << lo << " " << hi << endl;
   }
   LL ans = 4e18;
   for(int i = lo;i<=hi;i++){
//      cout << i << " " << check(i) << endl;
      ans = min(ans,check(i));
   }
   cout << ans << "\n";


}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0;i<n;i++) {
			double[] x, y;
			x = new double[4];
			y = new double[4];
			for(int j=0;j<4;j++) { x[j] = sc.nextDouble(); y[j] = sc.nextDouble(); }
			boolean f = ( x[0] - x[1] ) * ( y[2] - y[3] ) - ( x[2] - x[3] ) * ( y[0] - y[1] ) == 0.0;
			System.out.println( (f? "YES": "NO") );
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main()
{
	string s;
	while(cin >> s)
	{
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='@')
			{
				for(int j=0;j<(s[i+1]-'0');j++)
				{
					cout << s[i+2];
				}
				i+=2;
			}
			else
			{
				cout << s[i];
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1168