akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	//2040 start
	//2123 cording end
	//2321 sample matched
	
	int n;
	int [] data, accdata;
	int [] work;
	boolean [] used;
	boolean isNA;
	double ans, length;
	double EPS = 1.0e-08;
	
	private void doit(){
		Scanner sc = new Scanner (System.in);
		int dataset = sc.nextInt();
		while(dataset-- > 0){
			length = sc.nextDouble();
			n = sc.nextInt();
			data = new int[n];
			for(int i = 0 ; i < n;i ++){
				data[i] = sc.nextInt();
			}

			
			work = new int[n];
			used = new boolean[n];
			isNA = false;
			ans = -1.0;
			dfs(0);
			
			if(ans < 0){
				System.out.println(-1);
			}
			else{
				System.out.println(ans);
			}
		}
	}

	private void dfs(int deep) {
		if(deep == n){
			accdata = new int[n + 1];
			for(int i = 0; i < n; i++){
				accdata[i+1] = accdata[i] + work[i];
			}
			HashMap<Double, Double> res = dfs2(0, n-1);
//			System.out.println("work = " + Arrays.toString(work));
//			System.out.println("acc = " + Arrays.toString(accdata));
//			System.out.println();
			for(double d: res.keySet()){
				double value = d + res.get(d);
				if(value > length + EPS){
					continue;
				}
				ans = Math.max(ans, value);
			}
			return;
		}
		
		for(int i = 0; i < n; i++){
			if(! used[i]){
				used[i] = true;
				work[deep] = data[i];
				dfs(deep + 1);
				work[deep] = -1;
				used[i] = false;
			}
		}
	}

	private HashMap<Double, Double> dfs2(int i, int j) {
		HashMap<Double, Double> res = new HashMap<Double,Double>();
		if(i == j){
			res.put(0.0, 0.0);
			return res;
		}
		if(i + 1 == j){
			double right = (double)work[i]/(work[i] + work[j]);
			double left =  (double)work[j]/(work[i] + work[j]);
			res.put(left, right);
			return res;
		}
		
		for(int k = i; k < j; k++){
			HashMap<Double, Double> resleft = dfs2(i, k);
			HashMap<Double, Double> resright = dfs2(k+1, j);
			double nowvalue1 = (double)(accdata[k + 1] - accdata[i]);
			double nowvalue2 = (double)(accdata[j + 1] - accdata[k + 1]);
			for(double leftkey: resleft.keySet()){
				for(double rightkey: resright.keySet()){
					double nowvalueR =  nowvalue1 / (accdata[j + 1] - accdata[i]);
					double nowvalueL =  nowvalue2 / (accdata[j + 1] - accdata[i]);
					double valueright = Math.max(resleft.get(leftkey) - nowvalueL, resright.get(rightkey) + nowvalueR);   
					double valueleft = Math.max(rightkey - nowvalueR, leftkey + nowvalueL);
					res.put(valueleft, valueright);
				}
			}
		}
		return res;
	}

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

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	const int dx = tx - sx, dy = ty - sy;
	cout << string(dy, 'U') << string(dx, 'R') << string(dy, 'D') << string(dx, 'L');
	cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
	cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
	cout << '\n';
	return 0;
}

Measured memory_bytes: 256
S = input()

p = 0
l = []
for s in S:
    if s == '<':
        if p <= 0:
            p -= 1
        else:
            l.append(p)
            p = -1
    else:
        if p >= 0:
            p += 1
        else:
            l.append(p)
            p = 1
l.append(p)

n = len(l)
ans = 0

for ll in l:
    if ll < 0:
        ll *= -1
    for i in range(ll):
        ans += i


for i in range(n - 1):
    if l[i] < 0:
        ans += max(-l[i], l[i +1])

if l[0] > 0:
    ans += l[0]
if l[-1] < 0:
    ans -= l[-1]
# print(l)
print(ans)


Measured memory_bytes: 6300
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef long double ld;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

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

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; };
int main(){
  ll x,y; cin>>x>>y;
  ll res = 1LL<<60;
  if(x<=y) chmin(res, y-x);
  if(-x<=y) chmin(res, y+x+1);
  if(x<=-y) chmin(res, -y-x+1);
  if(-x<=-y) chmin(res, -y+x+2);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools


def rev(x):
    return sumA - x


if __name__ == "__main__":
    n = int(input())
    A = list(map(int, input().split()))
    q = int(input())
    M = list(map(int, input().split()))
    sumA = sum(A)
    all_sum = set()
    for i in range((n+1)//2):
        com = set(itertools.combinations(A, i+1))
        com_sum = set(map(sum, com))
        com_sum_rev = set(map(rev, com_sum))
        all_sum = all_sum.union(com_sum)
        all_sum = all_sum.union(com_sum_rev)
    for m in M:
        if m in all_sum:
            print("yes")
        else:
            print("no")

Measured memory_bytes: 63256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::str::FromStr;

// good-grid.rs --- Good Grid
// author: Seong Yong-ju <sei40kr@gmail.com>

#[allow(unused_macros)]
macro_rules! get {
  ($t:ty) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      line.trim().parse::<$t>().unwrap()
    }
  };
  ($($t:ty),*) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      let mut iter = line.split_whitespace();
      (
        $(iter.next().unwrap().parse::<$t>().unwrap(),)*
      )
    }
  };
  ($t:ty; $n:expr) => {
    (0..$n).map(|_|
                get!($t)
    ).collect::<Vec<_>>()
  };
  ($($t:ty),*; $n:expr) => {
    (0..$n).map(|_|
                get!($($t),*)
    ).collect::<Vec<_>>()
  };
  ($t:ty ;;) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      line.split_whitespace()
        .map(|t| t.parse::<$t>().unwrap())
        .collect::<Vec<_>>()
    }
  };
  ($t:ty ;; $n:expr) => {
    (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
  };
}

#[allow(unused_macros)]
macro_rules! debug {
  ($($a:expr),*) => {
    println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
  }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("Failed to parse token")
}

#[allow(dead_code)]
fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer);
}

fn main() {
    let (n, c) = get!(usize, usize);
    let d = (0..c)
        .map(|_i| (0..c).map(|_j| read::<u32>()).collect::<Vec<_>>())
        .collect::<Vec<_>>();
    let mut t = vec![vec![0; c]; 3];
    for i in 0..n {
        for j in 0..n {
            let x = read::<usize>();
            t[(i + j) % 3][x - 1] += 1;
        }
    }

    let mut res = <u32>::max_value();
    for i in 0..c {
        for j in 0..c {
            if i == j {
                continue;
            }
            for k in 0..c {
                if j == k || k == i {
                    continue;
                }

                let mut tt = 0;
                for l in 0..c {
                    tt += d[l][i] * t[0][l];
                    tt += d[l][j] * t[1][l];
                    tt += d[l][k] * t[2][l];
                }

                if tt < res {
                    res = tt
                }
            }
        }
    }

    with_bufwriter(|mut out| writeln!(out, "{}", res).unwrap());
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
using namespace std;

#define ll long long
#define endl "\n"
#define pb push_back
#define mp make_pair

int solve()
{
   ll a,b,c,k;
   cin>>a>>b>>c>>k;
   
   if(k<=a)
   {
       cout<<k<<endl;
   }
   else if(k<=a+b)
   {
       cout<<a<<endl;
   }
   else
   {
       cout<<2*a+b-k<<endl;
   }
    

    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /*ll t;
    cin>>t;
    while(t--)*/
        solve();

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    char c[n];
    cin(i,c);
    sort(c,c + n, greater<>());
    fp(c[0] == 'Y',"Four","Three");
    return 0;
}

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

ll i,j;

vector<int> G[100010];

int main(){
    int n,m;cin>>n>>m;
    vector<ll> h(n);
    for(i=0;i<n;i++){
        cin>>h[i];
    }

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

    int ans=0;
    for(i=0;i<n;i++){
        bool ok=true;
        for(j=0;j<G[i].size();j++){
            if(h[i]<=h[G[i][j]]){
                ok=false;
            }
        }
        if(ok){ans++;}
    }

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

Measured memory_bytes: 9016
#include <stdio.h>

int main(void){
	char num[1001];
        int i;
	long int sum;

	while (1){
		scanf("%s", num);

		if (num[0] == '0') break;

		sum = 0;
		for (i = 0; i < 1001; i++){
			if (num[i] == '\0') break;

			sum += num[i] - '0';
		}

		printf("%d\n", sum);
	}
	
	return 0;
}

Measured memory_bytes: 536
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
# zen tansaku
maxscore = -10**9
def bittolist(x):
    ret = []
    for _ in range(10):
        ret.append(x%2)
        x //= 2
    return ret
for i in range(1, 1024):
    open = bittolist(i)
    score = 0
    for store in range(n):
        count = 0
        for time in range(10):
            if f[store][time] == 1 and open[time] == 1:
                count += 1
        score += p[store][count]
    maxscore = max(maxscore, score)
print(maxscore)

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

int sz[1<<17];
int ans[1<<17];
vector<int> g[1<<17],bl[1<<17];
int tag[1<<17];
int cnt[1<<17]={};

void dfs(int v,int nowt)
{
    tag[v]=nowt;
    cnt[nowt]++;
    for(int u:g[v])
    {
        if(tag[u]) continue;
        dfs(u,nowt);
    }
}

main()
{
    int n; cin>>n;
    int m; cin>>m;
    int k; cin>>k;
    for(int i=0;i<m;++i)
    {
        int a,b; cin>>a>>b;
        --a,--b;
        ans[a]--,ans[b]--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    for(int i=0,j=1;i<n;++i)
    {
        if(tag[i]) continue;
        dfs(i,j);
        j++;
    }
    for(int i=0;i<k;++i)
    {
        int c,d; cin>>c>>d;
        --c,--d;
        if(tag[c]==tag[d])
        {
            ans[c]--;
            ans[d]--;
        }
    }
    for(int i=0;i<n;++i)
    {
        ans[i]+=cnt[tag[i]]-1;
        cout << ans[i] << " ";
    }
}

Measured memory_bytes: 12032
N = int(input())
A = list(map(int, input().split()))
B = [0] * (10**5 + 1)

for i in A:
    if i == 0:
        B[i] += 1
        B[i+1] += 1
    else:
        B[i-1] += 1
        B[i] += 1
        B[i+1] += 1

print(max(B))


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

struct LowLink{
  int n,pos;
  vector<int> ord,low,par,blg;
  vector<vector<int> > G,C,T;
  
  vector<int> ap;
  vector<pair<int, int> > bs;

  LowLink(int n):n(n),pos(0),ord(n,-1),low(n),par(n,-1),blg(n,-1),G(n){}

  void add_edge(int u,int v){
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  bool is_bridge(int u,int v){
    if(ord[u]>ord[v]) swap(u,v);
    return ord[u]<low[v];
  }

  void dfs(int v){
    ord[v]=low[v]=pos++;
    for(int u:G[v]){
      if(u==par[v]) continue;
      if(~ord[u]){
	low[v]=min(low[v],ord[u]);
	continue;
      }
      par[u]=v;
      dfs(u);
      low[v]=min(low[v],low[u]);
      if(is_bridge(u,v)) bs.emplace_back(u,v);
    }
  }

  void fill_component(int v){
    C[blg[v]].emplace_back(v);
    for(int u:G[v]){
      if(~blg[u]) continue;
      blg[u]=blg[v];
      fill_component(u);
    }
  }

  void add_component(int v,int &k){
    if(~blg[v]) return;
    blg[v]=k++;
    C.emplace_back();
    fill_component(v);
  }
  
  void build(){
    for(int i=0;i<n;i++)
      if(ord[i]<0) dfs(i);
    
    vector<int> cnt(n,0);
    for(int i=0;i<n;i++){
      int p=par[i];
      if(p<0) continue;
      if(par[p]<0) cnt[p]++;
      else if(ord[p]<=low[i]) ap.emplace_back(p);
    }
    
    for(int i=0;i<n;i++)
      if(cnt[i]>1) ap.emplace_back(i);

    sort(ap.begin(),ap.end());
    ap.erase(unique(ap.begin(),ap.end()),ap.end());

    int k=0;    
    for(int i=0;i<n;i++) add_component(i,k);

    T.assign(C.size(),vector<int>());
    for(auto e:bs){
      int u=blg[e.first],v=blg[e.first];
      T[u].emplace_back(v);
      T[v].emplace_back(u);
    }      
  }
};


//problemId=GRL_3_A
signed main(){
  int n,m;
  scanf("%d %d",&n,&m);
  LowLink G(n);
  for(int i=0;i<m;i++){
    int u,v;
    scanf("%d %d",&u,&v);
    G.add_edge(u,v);
  }
  G.build();
  auto ap=G.ap;
  sort(ap.begin(),ap.end());
  for(int v:ap) printf("%d\n",v);
  return 0;
}



Measured memory_bytes: 4520
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long int arr[300000];
int main()
{
    int n,i,j;
    vector<long long int>v;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    if(n%2==0)
    {
        for(i=0; i<n; i++)
        {
            if((i+1)%2==0)
            {
                v.push_back(arr[i]);
            }
        }
        reverse(v.begin(), v.end());
        for(i=0; i<n; i++)
        {
            if((i+1)%2==1)
            {
                v.push_back(arr[i]);
            }
        }
        for(j=0; j<v.size(); j++)
        {
            cout<<v[j]<<" ";
        }
    }
    else
    {
        for(i=0; i<n; i++)
        {
            if((i+1)%2==1)
            {
                v.push_back(arr[i]);
            }
        }
        reverse(v.begin(), v.end());
        for(i=0; i<n; i++)
        {
            if((i+1)%2==0)
            {
                v.push_back(arr[i]);
            }
        }
        for(j=0; j<v.size(); j++)
        {
            cout<<v[j]<<" ";
        }
    }
    return 0;
}


Measured memory_bytes: 5360
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef long double lld;

const ll mod = 1000000007;

vector<vector<ll>> tmp;
void mul(vector<vector<ll>> &x, vector<vector<ll>> &y) {
	int n = x.size();
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) tmp[i][j] = 0;

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			for(int k = 0; k < n; k++) {
				tmp[i][j] = (tmp[i][j] + x[i][k] * y[k][j]) % mod;
			}
		}
	}
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) x[i][j] = tmp[i][j];
}

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

	ll n, k; cin >> n >> k;
	vector<vector<ll>> m(n, vector<ll>(n, 0));
	vector<vector<ll>> ans(n, vector<ll>(n, 0));
	tmp.resize(n, vector<ll>(n, 0));

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) cin >> m[i][j];
		ans[i][i] = 1;
	}

	while(k > 0) {
		if(k & 1) {
			mul(ans, m);
		}
		mul(m, m);
		k >>= 1;
	}

	ll cnt = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cnt = cnt + ans[i][j];
		}
	}
	cnt = cnt % mod;
	cout << cnt << endl;
}

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

int main() {
    int N, W;
    cin >> N >> W;
    long long w[N], v[N];
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }

    long long dp[N+1][W+1];
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= W; j++) {
            dp[i][j] = 0;
        }
    }

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

Measured memory_bytes: 79104
///*.......................Shadman Sakib Utshob............................*///

#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

#define Boost           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
#define pb              push_back
#define seecontent(v) cout << (#v) << " is "; for(auto x : v) { cout << x << " ";} cout << "\n\n";
#define inf             1e10
#define mp              make_pair
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define ll              long long
#define pii             pair<ll,ll >
#define MOD             1000000007
#define fileout         freopen("output.txt","w",stdout)
#define mem(x,i)        memset(x,i,sizeof x)
#define Ones(x)         __builtin_popcount(x);
#define PI              acos(-1.0)
#define ff              first
#define ss              second
#define T               int t;cin>>t;while(t--)
#define ok              cout<<"ok"<<endl;
#define all(x)          (x).begin(),(x).end()
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define nln	            cout<<endl;
#define maxn 300005

int dx[]={-1,0,1,0}; //up,right,down,left
int dy[]={0,1,0,-1};

int main()
{
    Boost;
    ll x;
    cin>>x;
    if(x==0)
        cout<<1<<endl;
    else
        cout<<0<<endl;


    return 0;

}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
typedef long long ll;
typedef unsigned long long ull;

int main(){
	int n;
	while(scanf("%d",&n),n){
		int D[16][16] = {{0}};
		rep(i,16){
			rep(j,16){
				if(i != j)D[i][j] = INF;
			}
		}
		int v = 0;
		rep(i,n){
			int from,to,cost;
			scanf("%d%d%d",&from,&to,&cost);
			D[from][to] = cost;
			D[to][from] = cost;
			v = max(v,max(from,to));
		}
		v++;
		rep(k,v){
			rep(i,v){
				rep(j,v){
					D[i][j] = min(D[i][j],D[i][k]+D[k][j]);
				}
			}
		}
		int sum = INF,town = 0;
		rep(i,v){
			int tmp = 0;
			rep(j,v){
				if(D[i][j] == INF)tmp += 0;
				else tmp += D[i][j];
			}
			if(sum > tmp && tmp != 0){
				sum = tmp;
				town = i;
			}
		}
		printf("%d %d\n",town,sum);
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
int rock = 0, sizz = 1, par = 2;

int Point(int R, int S, int P, char opponent, int mine) {
  if (opponent == 'r') {
    if (mine == par) return P;
  } else if (opponent == 's') {
    if (mine == rock) return R;
  } else {
    if (mine == sizz) return S;
  }
  return 0;
}

int ProbS(int R, int S, int P, string T2) {
  int N = T2.size();
  VEC<VEC<int>> dp = VEC<VEC<int>>(N, VEC<int>(3, 0));
  dp[0][rock] = Point(R, S, P, T2[0], rock);
  dp[0][sizz] = Point(R, S, P, T2[0], sizz);
  dp[0][par] = Point(R, S, P, T2[0], par);

  REP(i, 1, N) {
    int pr = Point(R, S, P, T2[i], rock);
    int ps = Point(R, S, P, T2[i], sizz);
    int pp = Point(R, S, P, T2[i], par);
    dp[i][rock] = max({dp[i - 1][par] + pr, dp[i - 1][sizz] + pr});
    dp[i][sizz] = max({dp[i - 1][par] + ps, dp[i - 1][rock] + ps});
    dp[i][par] = max({dp[i - 1][rock] + pp, dp[i - 1][sizz] + pp});
  }
  return max({dp[N - 1][rock], dp[N - 1][sizz], dp[N - 1][par]});
}

int main() {
  int N, K, R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  VEC<string> subs(K, "");
  // DUMP("HI");
  REP(i, 0, N) { subs[i % K].push_back(T[i]); }

  // DUMP("HI2");

  LL sum = 0;
  REP(i, 0, K) { sum += ProbS(R, S, P, subs[i]); }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
int main()
{
        int n;
        cin>>n;
        vector<int>v(n);
        for(int i=1;i<=n;i++)
        {
                cin>>v[i];
        }
        int count=0;
        for(int i=1;i<=n;i++)
        {
                if(i%2!=0 && v[i]%2!=0)
                {
                        count+=1;
                }
        }
        cout<<count;
}

Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1e9;
const int64_t inf64=4e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}
 
using i64=int64_t;
 
void solve(){
    int N,K;
    cin >> N >> K;
 
    vector<int> x(N),y(N),xs(N),ys(N);
    rep(i,0,N){
        cin >> x[i] >> y[i];
        xs.push_back(x[i]);
        ys.push_back(y[i]);
    }
 
    sort(begin(xs),end(xs));
    sort(begin(ys),end(ys));
 
    i64 ans=inf64;
    rep(i,0,xs.size()) rep(j,i+1,xs.size()) rep(k,0,ys.size()) rep(l,k+1,ys.size()){
        int x1=xs[i],y1=ys[k],x2=xs[j],y2=ys[l];
        i64 s=i64(x2-x1)*i64(y2-y1);
        if(s>=ans) continue;
        
        int cnt=0;
        rep(i,0,N) if(x1<=x[i] and x[i]<=x2 and y1<=y[i] and y[i]<=y2) ++cnt;
        
        if(cnt>=K) ans=s;
    }
 
    cout << ans << endl;
}
 
int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, w[105];
  int sum[105] = {};
  int mini = INF;

  cin >> n;
  
  for(int i = 1;i <= n;i++){
    cin >> w[i];
  }

  for(int i = 1;i <= n;i++){
    sum[i] = sum[i - 1] + w[i];
  }

  for(int i = 1;i < n;i++){
    mini = min(mini, abs((sum[n] - sum[i]) - sum[i]));
  }

  cout << mini << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
    string N;
    cin >> N;
    ll a = N.size();
    ll Sn = 0;
    ll n = 0;
    rep(i,a) {
        Sn += N[i] - '0';
        n += (N[a - i - 1] - '0')*pow(10,i);
    }
    if (n % Sn == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 4104
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  const val = lines[0].split(" ");
  const answer = Math.floor(val[2] / val[0]) * val[1];
  console.log(answer);
});

Measured memory_bytes: 7500
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n;
int arr[N];
int nxt[N];
int prv[N];
int dp[N];
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , arr + i);
	}
	nxt[n] = n;
	prv[n] = n;
	for(int i = n - 1 ; i >= 1 ; --i){
		if(arr[i + 1] >= arr[i]){
			nxt[i] = nxt[i + 1];
		}
		else{
			nxt[i] = i;
		}
		if(arr[i + 1] <= arr[i]){
			prv[i] = prv[i + 1];
		}
		else{
			prv[i] = i;
		}
	}
	dp[n + 1] = 0;
	for(int i = n ; i >= 1 ; --i){
		dp[i] = 1 + min(dp[nxt[i] + 1] , dp[prv[i] + 1]);
	}
	printf("%d\n" , dp[1]);
}

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

int main() {
	int i,n;
	string s;
	cin>>s;
	int count=0;
	bool odd;
	n=s.size();
	for(i=0;i<n;i++){
		if(s[i]=='g'){
			count++;
		}
		else{
			count--;
		}
	}
	
	if(n%2){
		odd=true;
	}
	else{
		odd=false;
	}
	
	if(odd){
		cout<<(count-1)/2<<endl;
	}
	else{
		cout<<count/2<<endl;
	}
}

Measured memory_bytes: 512
import queue
n,q=map(int,input().split())
p=queue.PriorityQueue()
s=[0]*-~n
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v;p.put((-s[a],a))
 while 1:
  t=p.get()
  if -t[0]==s[t[1]]:print(t[1],-t[0]);p.put(t);break


Measured memory_bytes: 28868
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const int INF=1000100010;
int main(){
 long double l;cin>>l;
 cout<<setprecision(7)<<(l/3.0)*(l/3.0)*(l/3.0)<<endl;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int main(void)
{
	int a, b;

	scanf("%d %d", &a, &b);

	if (a < b) 
		puts("a < b");
	
	else if (a > b) 
		puts("a > b");
	
	else 
		puts("a == b");
	
	return 0;
}



Measured memory_bytes: 2572
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unsigned long long int ull;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;

struct UnionFindTree{
    vector<int> par,rank;
    UnionFindTree(int n):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[rx]<rank[ry]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

ll power(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1) res*=a;
        a*=a;
        x>>=1;
    }
    return res;
}

int main(){
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int ans=0;
    for(int i=0;i<n;i+=2){
        if(a[i]%2==1) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3592
n = int(input()) 
xs = [int(input())-1 for i in range(n)]
v = [False] * n

i = 0
ans = 0
while True:
  if i == 1:
    break
  elif v[i]:
    ans = -1
    break
  v[i] = True
  ans += 1
  i = xs[i]

print(ans)


Measured memory_bytes: 8108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;


int main()
{
  ll n, k;
  string s;
  cin >> n >> k;
  cin >> s;

  ll unhappy = 0;
  for (int i = 0; i < n - 1; ++i) {
    char n;
    if (s[i] == 'R' && s[i+1] == 'L') {
      if (k-- <= 0) {
        unhappy += 2;
      }
    }
  }
  if (k > 0) {
    cout << n - 1;
    return 0;
  }
  unhappy += (s[0] == 'L');
  unhappy += (s[n-1] == 'R');
  cout << n - max(1LL, unhappy);
  
  return 0;
}




Measured memory_bytes: 512
// atcoder/abc137/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  while (cin >> a >> b) {
    int x = a + b;
    int y = a - b;
    int z = a * b;
    cout << max({x, y, z}) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    
    def dfs(v):
        visited[v] = 1
        for cost, nv in edge[v]:
            if visited[nv] == 1:
                continue
            d[nv] = d[v] + cost
            dfs(nv)

    #N:頂点数   W:辺数
    edge = [[] for i in range(N)]
    #edge[i] : iから出る道の[重み,行先]の配列
    for _ in range(N-1):
        x,y,z = map(int,input().split())
        edge[x-1].append((z,y-1))
        edge[y-1].append((z,x-1))

    q,k = map(int, input().split())
    d = [-1]*N
    d[k-1] = 0
    visited = [0]*N
    dfs(k-1)

    for _ in range(q):
        x,y = map(int, input().split())
        print(d[x-1]+d[y-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 193456
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  int k;
  cin>>k;
  vector<int> len;
  char now=s[0];
  int num=1;
  int ans=0,sum=0;
  repi(i,1,s.size() ){
    if(now==s[i]){
      num++;
    }else{
      len.push_back(num);
      now=s[i];
      num=1;
    }
  }
  len.push_back(num);
  if(s[0]==s[s.size()-1]){
    ans+=len[0]/2;
    ans+=len[len.size()-1]/2;
    ans+=((len[0]+len[len.size()-1])/2)*(k-1);
    repi(i,1,len.size()-1) sum+=(len[i]/2);
    ans+=sum*k;
    if(len.size()==1){
      ans=(len[0]*k)/2;
    }
  }else{
    rep(i,len.size()) sum+=len[i]/2;
    ans+=sum*k;
  }
  cout<<ans<<endl;
 

  return 0;
}


Measured memory_bytes: 256
main = do
  getLine
  as <- map read . words <$> getLine
  print (sq as)

sq as = min (count 0 0 aas1) (count 0 0 aas2)
  where
    aas = scanl1 (+) as
    aas1 = zip aas (cycle [1,-1])
    aas2 = zip aas (cycle [-1,1])

count acc _ [] = acc
count acc d ((a,s):as)
  | signum (a + d) == s = count acc d as
  | otherwise = let r = s * (abs (a + d) + 1) in count (acc + abs r) (d + r) as

Measured memory_bytes: 54652
var
  n,s,sum:int64;
  a,f:array[0..3001] of int64;
  i,j:longint;
begin
  readln(n,s);
  for i:=1 to n do read(a[i]);
  for i:=1 to n do
    begin
      for j:=s downto a[i]+1 do f[j]:=(f[j]+f[j-a[i]]) mod 998244353;
      f[a[i]]:=(f[a[i]]+i) mod 998244353;
      sum:=(sum+(n-i+1)*f[s] mod 998244353) mod 998244353;
      f[s]:=0;
    end;
  writeln(sum);
end.

Measured memory_bytes: 128
#include <stdio.h>
int n, x, min, max;
long sum=0;
int main()
{
    scanf("%d", &n);
    scanf("%d", &x);
    min = x;
    max = x;
    
    for (int i = 1; i <= n; i++)
    {
        if (x > max)
        {
            max = x;
        }
        if (x < min)
        {
            min = x;
        }
        sum=sum+x;

        scanf("%d", &x);
    }
    printf ("%d %d %li\n",min,max,sum);
}


Measured memory_bytes: 2104
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  int x,y; cin >> x >> y;
  vector<int> a={-1,0,2,0,1,0,1,0,0,1,0,1,0};
  if (a[x]==a[y]){cout << "Yes";}
  else {cout << "No";}

  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
T = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    T[a][b] = 1
    T[b][a] = 1
ans = 0
def f(v,x,y):
    global N,M,T,a
    a[v] = 1
    for i in range(N+1):
        if (v==x and i==y) or (v==y and i==x):
            continue
        elif T[v][i]==0 or a[i]==1:
            continue
        f(i,x,y)
for i in range(1,N+1):
    for j in range(i,N+1):
        a = [0 for _ in range(N+1)]
        f(1,i,j)
        if sum(a)!=N:
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if ((A + B) % 3 == 0 || A % 3 == 0 || B % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

sum = 0
B = []
B.append(0)

for t in range(N):
    B.append(A[t] + B[t])
    
B.remove(0)
    
for i in range(N):
    sum += A[i] * (B[N-1] - B[i])
        
print(sum % (10**9+7))

Measured memory_bytes: 109720
# -*- coding: utf-8 -*-
"""
D - Triangles
https://atcoder.jp/contests/abc143/tasks/abc143_d

"""
import sys

from bisect import bisect_right

def solve(N, lines):
    return sum(b - bisect_right(lines[:b], lines[c] - lines[b]) for c in range(N - 1, -1, -1) for b in range(c - 1, -1, -1))


def main(args):
    N = int(input())
    lines = map(int, input().split())
    ans = solve(N, sorted(lines))
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 51420
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    string ans;
    if (S<="2019/04/30") {
        ans = "Heisei";
    } else {
        ans = "TBD";
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
def solve():
    n=int(input())
    num=[]
    def append(num1):
        num.append(num1)
    def count1(num2):
        return num.count(num2)
    for i in range(n):
        a=int(input())
        append(a)
    max1=max(num)
    count=count1(max1)
    if count>1:
        for i in range(n):
            print(max1)
    else:
        for i in range(n):
            if num[i]==max1:
                if i==0:
                    print(max(num[1:]))
                elif i==n-1:
                    print(max(num[:n-1]))
                else:
                    print(max(max(num[:i]),max(num[i+1:])))
            else:
                print(max1)
solve()


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

struct check_bipartite {
    int V;
    vector<vector<int>> adj;
    vector<int> depth;
    vector<bool> visited;

    check_bipartite(int v = -1) {
        if (v >= 0)
            init(v);
    }

    void init(int v) {
        V = v;
        adj.assign(V, {});
        depth.assign(V, -1);
        visited.assign(V, false);
    }

    void add_edge(int a, int b) {
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    pair<int, int> dfs(int node, int parent) {
        assert(!visited[node]);
        depth[node] = parent < 0 ? 0 : depth[parent] + 1;
        visited[node] = true;
        pair<int, int> sizes = {0, 0};

        if (depth[node] % 2 == 0)
            sizes.first++;
        else
            sizes.second++;

        for (int neighbor : adj[node])
            if (neighbor != parent) {
                if (!visited[neighbor]) {
                    pair<int, int> p = dfs(neighbor, node);

                    if (p.first < 0)
                        return {-1, -1};

                    sizes.first += p.first;
                    sizes.second += p.second;
                }

                if (depth[node] % 2 == depth[neighbor] % 2)
                    return {-1, -1};
            }

        return sizes;
    }

    vector<pair<int, int>> solve() {
        vector<pair<int, int>> sizes;

        for (int i = 0; i < V; i++)
            if (!visited[i])
                sizes.push_back(dfs(i, -1));

        return sizes;
    }

    static bool is_valid(const vector<pair<int, int>> &sizes) {
        for (pair<int, int> p : sizes)
            if (p.first < 0)
                return false;

        return true;
    }
};


const int INF = 1e9 + 5;

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

    int N;
    cin >> N;
    vector<string> S(N);

    for (int i = 0; i < N; i++)
        cin >> S[i];

    check_bipartite checker(N);

    for (int i = 0; i < N; i++)
        for (int j = i + 1; j < N; j++)
            if (S[i][j] == '1')
                checker.add_edge(i, j);

    if (!check_bipartite::is_valid(checker.solve())) {
        cout << -1 << '\n';
        return 0;
    }

    vector<vector<int>> dist(N, vector<int>(N, INF));

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            dist[i][j] = S[i][j] == '1' ? 1 : INF;

    for (int i = 0; i < N; i++)
        dist[i][i] = 0;

    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

    int maximum = 0;

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            maximum = max(maximum, dist[i][j]);

    cout << maximum + 1 << '\n';
}


Measured memory_bytes: 640
package main

import "fmt"


func main() {
  var A, B, C, K int
  fmt.Scanf("%d %d %d %d", &A, &B, &C, &K)
  
  
  if A > K {
    fmt.Println(K)
    return
  }
  
  if A+B > K {
    fmt.Println(A)
    return
  }
  
  fmt.Println(A - (K-A-B))
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int64_t x,d,k;

 cin >> x >> k >> d;
 x = abs(x);
 
 if(x<=d){
   if(k%2==0){
      cout << x << endl;
      return 0;
    }
    else{
      cout << d-x << endl;
      return 0;
    }
 }
 if(x>d*k && k > 100000000000000 && d < 100){
   cout << x-d*k << endl;
   return 0;
 }
 for(int i = 0;i < k;i++){
	if(x > 0){
      x -= d;
    }
   else{
      if((k-i)%2==0){
        cout << abs(x) << endl;
        return 0;
      }
      else{
        cout << abs(x+d) << endl;
        return 0;
      }
        
   }
 }
 cout << abs(x) << endl;
 
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,m; cin>>n>>m;
    vector<long> a(m+1,0);
    for(int i=0;i<n;i++){
        long k;cin>>k;
        for(int j=0;j<k;j++){
            long t; cin>>t;
            a[t]++;
        }
    }
    long count=0;
    for(auto x:a){
        if(x==n)
            count++;
    }
    cout<<count;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = 1 << 29;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const int MAX_V = 500;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }




void solve() {
    ll n;
    cin>>n;
    ll ans = 0;
    rep2(i,1,n){
        if(n%i==0) ans+= n/i-1;
        else ans += n/i;
    }
    cout<<ans<<endl;
}




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    ll t=1;
    
    // cin>>t;

    rep(i,t){
        solve(); 
    }

    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h> 
using namespace std;
int main()
{int n,k,a,i,sum=0;
 vector<int> ar;
  cin>>n>>k;
  for(i=0;i<n;i++)
  {cin>>a; ar.push_back(a);}
  sort(ar.begin(),ar.end());
  for(i=0;i<k;i++)
    sum=sum+ar[i];
  cout<<sum;
  return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
const int P = 1e9 + 7;
int n, k;

int qp(int a, int k) {
  int res = 1;
  for (; k; k >>= 1, a = 1ll * a * a % P) {
    if (k & 1) res = 1ll * res * a % P;
  }
  return res;
}

int main() {
  cin >> n >> k;
  ll res = 0;
  rep(i, k, n + 1) {
    ll x = 1ll * i * (i - 1) / 2;
    ll y = 1ll * n * (n + 1) / 2 - 1ll * (n - i) * (n - i + 1) / 2;
    res = (res + y - x + 1) % P;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main(){
	string str;
	cin >> str;
	
	int n, w, s, e;
	n = w = s = e = 0;
	for(int i = 0;i < str.size();i++){
		switch(str[i]){
		case 'N':
			n = 1;
			break;
		case 'W':
			w = 1;
			break;
		case 'S':
			s = 1;
			break;
		case 'E':
			e = 1;
			break;
		}
	}
	
	if(n == s && w == e){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256