akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
        ll n, k;
        ll r, s, p;
        string t;
        cin >> n >> k >> r >> s >> p >> t;
        for (size_t i = 0; i < t.size(); ++i) {
                if (i >= k) {
                        if (t[i] == t[i - k]) {
                                t[i] = 'x';
                        }

                }
        }
        ll c = 0;
        for (size_t i = 0; i < t.size(); ++i) {
                if (t[i] == 'r')
                        c += p;
                if (t[i] == 's')
                        c += r;
                if (t[i] == 'p')
                        c += s;
        }
        cout << c << endl;
        return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;int n;
char a[10000];
int main()
{cin>>n;
	scanf("%s",a);
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<strlen(a);j++)
		{
			a[j]++;if(a[j]>'Z')a[j]='A';
		}
	}cout<<a;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    double t,a;
    cin>>n>>t>>a;
    int ans;
    double mi=1e9;
    for(int i=1;i<=n;i++)
    {
        double k;
        cin>>k;
        if(fabs(t-k*0.006-a)<mi) ans=i,mi=fabs(t-k*0.006-a);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) (x.begin(), x.end())

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int a, b;
    cin >> a >> b;
    cout << (a*3+b)/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N, D;
    int x[10][10];
    cin >> N >> D;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < D; j++){
            cin >> x[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < i; j++){
            int d = 0;
            for(int k = 0; k < D; k++) d += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            //cout << d << endl;
            for(int k = 0; k <= 600; k++){
                if(d == k*k) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll H, W;
    cin >> H >> W;
    ll mat[H][W];
    rep(i, H) {
        string s;
        cin >> s;
        rep(j, W) {
            if (s[j] == '.') mat[i][j] = 0;
            else mat[i][j] = 1;
        }
    }
    rep(i, H) {
        bool flag = false;
        rep(j, W) {
            if (mat[i][j] > 0) flag = true;
        }
        if (!flag) {
            rep(j, W) {
                mat[i][j] = -1;
            }
        }
    }
    rep(j, W) {
        bool flag = false;
        rep(i, H) {
            if (mat[i][j] > 0) flag = true;
        }
        if (!flag) {
            rep(i, H) {
                mat[i][j] = -1;
            }
        }
    }
    rep(i, H) {
        bool flag = false;
        rep(j, W) {
            if (mat[i][j] == 0) cout << ".";
            else if (mat[i][j] == 1) cout << "#"; 
            
            if (mat[i][j] != -1) flag = true;
        }
        if (flag) cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn factorial(n: u64) -> u64 {
    let mut res = 1;
    let mut i = n;
    while i > 0 {
        res *= i;
        i -= 1;
    }
    res
}

fn order(target_vec: &Vec<u64>, num_list: &mut Vec<u64>) -> u64 {
    // println!("{:?}", target_vec);
    let mut sum = 0;
    for i in 0..target_vec.len() {
        let mut idx = 0;
        for j in 0..num_list.len() {
            if target_vec[i] == num_list[j] {
                idx = j;
                break;
            }
        }
        num_list.remove(idx);
        sum += idx as u64 * factorial((target_vec.len()- 1 - i) as u64);
    }
    sum
}

fn main() {
    let n: u64 = input();
    let p_vec = input_vec();
    let q_vec = input_vec();
    let mut num_list: Vec<u64> = Vec::new();
    for i in 1..(n+1) {
        num_list.push(i);
    }
    let p = order(&p_vec, &mut num_list);
    let mut num_list: Vec<u64> = Vec::new();
    for i in 1..(n+1) {
        num_list.push(i);
    }
    let q = order(&q_vec, &mut num_list);
    if p < q {
        println!("{}", q - p);
    } else {
        println!("{}", p - q);
    }

}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		int arr[] = new int[n];
		for(int i=0;i<n;i++)
			arr[i] = Integer.parseInt(st.nextToken());
		Arrays.sort(arr);
		int count = 0;
		if(n==1)
		{
			System.out.println("1");
			return;
		}
		if(arr[0]==arr[n-1])
		{
			System.out.println(count);
			return;
		}
		int freq[] = new int[arr[n-1]+1];
		int prim[] = new int[arr[n-1]+1];
		for(int i=0;i<n;i++)
		{
			freq[arr[i]]++;
		}
		for(int i=0;i<n;i++)
		{
			if(prim[arr[i]]==0){
			for(int j=2*arr[i];j<=arr[n-1];j+=arr[i])
			{
				prim[j]=1;
			}
		}
		}
		for(int i=0;i<n;i++)
		{
			if(prim[arr[i]]==0 && freq[arr[i]]==1)
				count++;
		}
		System.out.println(count);

	}
}

Measured memory_bytes: 54816
#!/usr/bin/env python3
from bisect import bisect_left

n, k = map(int, input().split())
*a, = map(int, input().split())
def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
    return sum(-(-i // arg) - 1 for i in a) <= k


def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok
print(meguru_bisect(0, max(a)))


Measured memory_bytes: 32100
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int p=998244353;
int n,m,i,j,k,l,ans,sz0,sz1,flag,v[303][303][303],f[303][303][303];
char s[303];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	//if(n>100)return puts("0"),0;
	f[n+1][0][0]=1;
	for(i=n+1;i>=1;i--){
		for(j=0;j<=n;j++)
		 for(k=0;k<=n-j;k++)if(f[i][j][k]){
		 	if(i==1||s[i-1]!='0')(f[i][j+1][k]+=f[i][j][k])%=p;
		 	if(i==1||s[i-1]!='1')(f[i][j][k+1]+=f[i][j][k])%=p;
		 	if(i>1){
		 		/*if(s[i-1]=='0')(f[i-1][j][k]+=f[i][j][k])%=p;
		 		if(s[i-1]=='1')(f[i-1][j])*/
		 		(f[i-1][j][k]+=f[i][j][k])%=p;
			 }
		 }
	}
	v[0][0][0]=1;
	for(i=0;i<=n;i++)
	 for(j=n;j>=0;j--)
	  for(k=n-j;k>=0;k--)if(v[i][j][k]){
	  	if(j+k>=2){
	  		if(j)v[i][j-1][k]=1;
	  		if(k)v[i][j][k-1]=1;
		  }
		if(i<n){
			if(j+k>0)v[i+1][j][k]=1;
			if(s[i+1]=='0'){
				if(k)v[i+1][j+1][k-1]=1;
			}
			if(s[i+1]=='1'){
				if(j)v[i+1][j-1][k+1]=1;
			}
		}
		if(i+1<n){
			if(s[i+1]=='0'||s[i+2]=='0')v[i+2][j+1][k]=1;
			if(s[i+1]=='1'||s[i+2]=='1')v[i+2][j][k+1]=1;
		}
	  }
	  for(i=n;i;i--)
	   for(j=0;j<=n;j++)
	    for(k=0;k<=n-j;k++)if(v[i][j][k]){
	    	if(s[i]=='0'&&j)v[i-1][j-1][k]=1;
	    	if(s[i]=='1'&&k)v[i-1][j][k-1]=1;
		}
	  for(i=0;i<=n;i++)
	   for(j=0;j<=n;j++)
	    for(k=0;k<=n-j;k++)if(v[i][j][k]){
	    	//printf("%d %d %d %d\n",i,j,k,f[i+1][j][k]);
	    	ans=(ans+f[i+1][j][k])%p;
	    	/*flag=0;sz0=sz1=0;
	    	for(l=i-1;l<=n;l++){
	    		if(v[l][j+sz0][k+sz1]){
	    			flag=1;break;
				}
				if(s[l+1]=='0')sz0++;
				 else sz1++;
			}
			if(flag){
			  ans=(ans+f[i][j][k])%p;
			  //printf("%d %d %d %d\n",i,j,k,f[i][j][k]);
		   }*/
		}
	printf("%d",ans);
}
/*

*/

Measured memory_bytes: 139368
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    CIN(N);
    V<LL> A,B;
    LL sum = 0;
    REP(a,N){
        LCIN(b);
        A.push_back(b);
    }
    REP(a,N){
        LCIN(b);
        B.push_back(b);
    }
    I vec;
    REP(a,N){
        vec.push_back(A.at(a)-B.at(a));
    }
    LL ans = 0;
    V<LL> pulus;
    LL minus = 0;
    for(int a = 0;a < N;a++){
        if(vec.at(a)<0){
            ans++;
            minus += vec.at(a);
        }else{
            pulus.push_back(vec.at(a));
        }
    }
    sort(ALL(pulus),greater<LL>());
    int i = 0;
    while(minus < 0){
        if(i == pulus.size()){
            COUT(-1);
            return 0;
        }
        minus += pulus.at(i);
        i++;
        ans++;
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 3828
n=int(input())
es=[[] for _ in range(n)]

for _ in range(n-1):
    a,b,c=map(int,input().split())
    es[a-1].append((b-1,c))
    es[b-1].append((a-1,c))

q,k=map(int,input().split())
k-=1
dist=[float('inf')]*n

dist[k]=0
stack=[k]
while stack:
    now=stack.pop()
    for e,w in es[now]:
        if dist[e]==float('inf'):
            dist[e]=dist[now]+w
            stack.append(e)

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

Measured memory_bytes: 102892
import sys
import math

A, B = map(int, sys.stdin.readline().split())
C, D = max(A, B), min(A, B)

#ユーグリッド互除法
while True:
    amari = C%D
    C, D = D, amari
    if amari ==0:
        gcd = C
        break
#print(gcd)

#素因数分解
L = [1]
n = int(math.sqrt(gcd))
for i in range(2, n+1):
    while True:
        if gcd%i ==0:
            L.append(i)
            gcd = gcd//i
        else:
            break
if gcd>1:
    L.append(gcd)
L = set(L)
print(len(L))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl;
#define mod 1000000007
#define pb push_back
#define endl '\n'


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

	int n;
	cin>>n;
	int a[n];
	for(auto &it:a)
	{
		cin>>it;
	}
	int ans = 1;
	for(auto it:a)
	{
		if(it%2 == 0)
		{
			if(!(it%6 == 0 || it%10 == 0)) ans =0; 
		}
	}

	if(ans) cout<<"APPROVED"<<endl;
	else cout<<"DENIED"<<endl;



}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

using Graph=vector<vector<int>>;
int main(){
    int n;
    cin>>n;
    Graph g(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    priority_queue<int,vector<int>,greater<int>> que;
    int sum=0;
    int ma=0;
    for(int i=0;i<n;i++){
        int c;
        cin>>c;
        sum+=c;
        ma=max(ma,c);
        que.push(c);
    }
    
    queue<int> vque;
    vector<int> d(n);
    for(int i=0;i<n;i++){
        d[i]=g[i].size();
        if(d[i]==1) vque.push(i);
    }
    vector<int> res(n);
    while(!vque.empty()){
        int v=vque.front(); vque.pop();
        res[v]=que.top(); que.pop();
        for(auto to:g[v]){
            d[to]--;
            if(d[to]==1) vque.push(to);
        }
    }
    
    cout<<sum-ma<<endl;
    for(int i=0;i<n;i++){
        cout<<res[i]<<(i+1==n ?  "\n" :" ");
    }

    
    
    return 0;
}

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


using namespace std;
using ll = long long;

#define pb push_back
#define sz(x) (int)(x).size()

int main () {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);

  string s; cin >> s;
  string ss = s.substr(0, 4), sss = s.substr(5, 2), t = s.substr(8, 2);
  if (stoi(ss) > 2019 || (stoi(ss) == 2019 && stoi(sss) > 4)) {
    cout << "TBD" << '\n';
  }else {
    cout << "Heisei" << '\n';
  } 

  return 0;
}



Measured memory_bytes: 3624
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<stack>
#include<queue>
using namespace std;

int num_cnt[100001];

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    num_cnt[a[i]]++;
  }

  sort(num_cnt , num_cnt + 100001, greater<int>() );
  long long num1 = 0;
  long long sum = 0;
  for(int i = 0; i < 1000001; i++) {
    if(num_cnt[i] == 0) break;
    num_cnt[i]--;
    num1++;
  }
  for(int i = 0; num_cnt[i] != 0; i++) {
    sum += num_cnt[i];
  }

  cout << num1 - (sum % 2)<< endl;

  return 0;
}


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


int main(){
  long long n,c,k,i,co;
  cin >> n >> c >> k;
  vector<long long> t(n),wait(n);
  priority_queue<long long,vector<long long>,greater<long long>> que;
  for(i=0;i<n;++i){
    cin >> t[i];
    que.push(t[i]);
  }
  long long ans=0;
  co=1;
  long long a=que.top();
  que.pop();
  while(!que.empty()){
    if(co<c && a+k>=que.top()){
      co++;
      que.pop();
    }else{
      ans++;
      co=1;
      a=que.top();
      que.pop();
    }
  }
  ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2936
#include<bits/stdc++.h>
#define inf 1e18
#define ll long long int
using namespace std;
int main(void){

  int n,i,j;
  cin>>n;
  int a[n],b[n],c[n];
  for(i=0;i<n;i++)
  cin>>a[i]>>b[i]>>c[i];
  int dp[n+1][3];
  dp[1][0]=a[0];
  dp[1][1]=b[0];
  dp[1][2]=c[0];
  for(i=2;i<=n;i++){
	  dp[i][0]=a[i-1]+max(dp[i-1][1],dp[i-1][2]);
	  dp[i][1]=b[i-1]+max(dp[i-1][0],dp[i-1][2]);
	  dp[i][2]=c[i-1]+max(dp[i-1][0],dp[i-1][1]);
  }
  cout<<max({dp[n][0],dp[n][1],dp[n][2]});
}


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

int main() {

    int k, s;
    cin >> k >> s;
    int x, y, z;
    int count = 0;
    rep(x, k + 1){
       rep(y, k + 1){
           z = s - x - y;
           if(z >= 0 && z <= k) count++;    
       } 
    }
    cout << count << endl;

}

Measured memory_bytes: 256
n, a, b = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp.split("")

count_a = 0
count_b = 0
s.length.times do |i|
  if s[i] == 'a'
    if count_a + count_b < a + b
      puts 'Yes'
      count_a += 1
    else
      puts 'No'
    end
  elsif  s[i] == 'b'
    if count_a + count_b < a + b && count_b < b
      puts 'Yes'
      count_b += 1
    else
      puts 'No'
    end
  else
    puts 'No'
  end
end

Measured memory_bytes: 9852
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("YES")
no = lambda: print("NO")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
t = int(input())
a = LI()
d = {}
for i in a:
	if i not in d:
		d[i] = 1
	else:
		d[i]+=1
for i in range(1,t+1):
	if i in d:
		print(d[i])
	else:
		print(0)


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

int main() {
    string S;
    cin >> S;
    if (S == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (S == "Rainy") {
        cout << "Sunny" << endl;
    } else {
        cout << "Rainy" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    
    rep(i,N) cin >> h[i];
    
    int ans = 0;
    
    rep(i,N){
        if (h[i] >= K) {
            ans += 1;
        }
    }
    
    cout << ans << endl;
    
    
    return 0;
}



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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> gx(n);
  vector<int> gy(n);
  vector<int> cx(m);
  vector<int> cy(m);
  for(int i = 0;i<n;i++){
    cin>>gx[i]>>gy[i];
  }
  for(int i = 0;i<m;i++){
    cin>>cx[i]>>cy[i];
  }
  for(int i = 0;i<n;i++){
    int ans = 1000000000;
    int ansn;
    int j;
    for(j = m-1;j>=0;j--){
      int dir=abs(gx[i]-cx[j])+abs(gy[i]-cy[j]);
      if(ans>=dir){
        ans=dir;
        ansn=j;
      }
    }
    cout<<ansn+1<<endl;
  }
  return 0;

}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
	//Implement solution here.
		String in = next();
		int[] cmp = {2019,4,30};
		String[] ymd = in.split("/");
		boolean hflg = false;
		for(int i = 0; i < 3; i++){
			if(cmp[i] > Integer.parseInt(ymd[i])){
				System.out.println("Heisei");
				return;
			}else if(cmp[i] < Integer.parseInt(ymd[i])){
				break;
			}
		}
		if("2019/04/30".equals(in)){
			System.out.println("Heisei");
			return;
		};
		System.out.println("TBD");
	}

    //Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
                scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    long long a, b, n;
    cin >> a >> b >> n;
    if (n < b) cout << floor(a * n / b) - a * floor(n / b) << endl;
    else cout << floor((a * (b - 1) / b)) << endl;
    return 0;
}

Measured memory_bytes: 3784
n,m=map(int,input().split())
a=set([int(input()) for i in range(m)])
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    if i in a:dp[i]=0
print(dp[n])

Measured memory_bytes: 13212
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner fs = new FastScanner();

        final String S = fs.next();

        final long K = fs.nextLong();

        int ans = 1;

        for (int i = 0; i < S.length(); i++) {
            if (K <= (long)i) break;

            if (S.charAt(i) != '1') {
                ans = Character.getNumericValue(S.charAt(i));
                break;
            }
        }

        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22356
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if( c>= b && b >= a ){
    printf("%d",c*10+b+a);
  }else if( b>= a && a>= c){
    printf("%d",b*10+a+c);
  }else if( a>= b && b>=c){
    printf("%d",a*10+b+c);
  }else if( c>= a && a >= b){
    printf("%d",c*10+a+b);
  }else if( b>= c && c>= a){
    printf("%d",b*10+c+a);
  }else if(a >=c && c>=b){
    printf("%d",a*10+c+b);
  }
}

Measured memory_bytes: 1724
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

#define DEBUG(x) cerr << #x << ": " << x << endl

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;



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

   int K, N;
   cin >> K >> N;

   VI A(N);
   REP(i, N)
      cin >> A[i];

   int max_gap = 0;
   FOR(i, 1, N-1)
      max_gap = max(max_gap, A[i] - A[i-1]);

   max_gap = max(max_gap, K - A[N-1] + A[0]);

   int res = K - max_gap;
   cout << res << '\n';

   return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>

long long gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a%b);
}

int main() {
    long long a, b, c, d; std::cin >> a >> b >> c >> d;
    long long p = b / c - (a - 1) / c;
    long long q = b / d - (a - 1) / d;
    long long l = c / gcd(c, d) * d;
    long long r = b / l - (a - 1) / l;
    std::cout << (b - a + 1) - p - q + r << std::endl;
    return 0;
}


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

int main(){
  ll N,K;cin>>N>>K;
  vll A(N);rep(i,N){cin>>A[i];A[i]--;}
  vector<pair<ll,ll>> v(N+10);
  //場所、回数
  rep(i,N) v[i] = make_pair(0,0);
  ll cnt=0;ll i=0;
  v[0].second = 1;
  while(cnt<=2*1e5+10){
    i = A[i];
    cnt++;
    if(v[i].second>0) break;
    v[i].first = cnt;
    v[i].second++;
    //cout << "i " << i << endl;
  }
  //周期
  ll t = cnt - v[i].first;
  //cout << t << v[i].first << endl;
  //cout << "cnt " << cnt << "v[i]" << v[i].first << v[i].second << endl;
  ll tmp;
  if(K<v[i].first) tmp=K;
  else tmp = (K-v[i].first)%t+v[i].first;
  i=0;
  //cout << "tmp" << tmp << endl;
  for(int j=0;j<tmp;++j){
    i=A[i];
  }
  cout<<i+1<<endl;
}

Measured memory_bytes: 8012
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

const int MAX_N = 101;
const int INF = 1e+8;
typedef pair<int,int> P;

// ノード数
int N;

struct edge{
	int to, cost;
	edge(int to_, int cost_){
		to = to_; cost = cost_;
	}
};
// グラフ
vector<edge> G[MAX_N];

// 初期化
void init(){
	for(int i=0 ; i < MAX_N ; i++ ){
		G[i].clear();
	}
}

// 辺の追加
void add_edge(int u, int v, int cost){
	edge e( v , cost );
	G[u].push_back( e );
	e.to = u;
	G[v].push_back( e );
}

// ダイクストラ法
int solve(int s, int g, int M, vector<bool> ice){
	// (コスト,(ノード番号,時間))
	typedef pair<int,P> State;
	
	// d[i][t] := ノード i に残り時間 t でたどり着く最小コスト
	int d[101][101];
	// visited[i][t] := ノード i に残り時間 tでたどり着いているかどうか
	bool visited[101][101];
	// 初期化
	for(int i=0 ; i < 101 ; i++ ){
		for(int j=0 ; j < 101 ; j++ ){
			d[i][j] = INF;
			visited[i][j] = false;
		}
	}
	
	// 始点のノード
	P start( s , M );
	// コストの小さい順に取り出せる優先度付きキュー
	priority_queue< State , vector<State> , greater<State> > q;
	// 初期状態をキューに入れる
	q.push( State(0,start) );
	d[s][M] = 0;
	
	int ans = INF;
	while( !q.empty() ){
		// キューから取り出す
		int now_cost = q.top().first;
		int v = q.top().second.first;
		int t = q.top().second.second;
		q.pop();
		
		// 訪れた状態をメモ
		visited[v][t] = true;
		
		// ゴールにたどり着いたとき
		if( v == g ){
			ans = min( ans , now_cost );
			break;
		}
		
		// 冷凍する(街の位置は変わらない)
		if( ice[v] ){
			for(int next_t = t+1 ; next_t <= M ; next_t++ ){
				int cost = next_t - t;
				
				// まだ訪れていない かつ より小さいコストでたどり着ける頂点のときキューに入れる
				if( now_cost + cost < d[v][next_t] && !visited[v][next_t] ){
					d[v][next_t] = now_cost + cost;
					P next(v,next_t);
					q.push( State(now_cost + cost , next) );
				}
			}
		}
		// つながっている街へ移動する
		for(int i=0 ; i < G[v].size() ; i++ ){
			int cost = G[v][i].cost;
			int to = G[v][i].to;
			int next_t = t - cost;
			
			// 冷凍が持たなかったらcontinue
			if( next_t < 0 ) continue;
			
			// まだ訪れていない かつ より小さいコストでたどり着ける頂点のときキューに入れる
			if( now_cost + cost < d[to][next_t] && !visited[to][next_t] ){
				d[to][next_t] = now_cost + cost;
				P next(to,next_t);
				q.push( State(now_cost + cost , next) );
			}
		}
	}
	return ans;
}

int main(){
	int M, L, K, A, H;
	while( cin >> N >> M >> L >> K >> A >> H, N|M|L|K|A|H ){
		// 初期化
		init();
		
		// ice[i] := i は冷凍施設
		vector<bool> ice( N , false );
		
		for(int i=0 ; i < L ; i++ ){
			int a;
			cin >> a;
			ice[a] = true;
		}
		for(int i=0 ; i < K ; i++ ){
			int x,y,t;
			cin >> x >> y >> t;
			add_edge( x , y , t );
		}
		
		// ダイクストラ法
		int ans = solve( A , H , M , ice );
		
		// 出力
		if( ans == INF )
			cout << "Help!" << endl;
		else
			cout << ans << endl;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; ++i){
    cin >> a.at(i);
  }
  
  int cnt1 = 0;
  
  vector<int> b(N);
  for(int i = N-1; i >= 0; --i){
    if(N / (i+1) == 1){
      b.at(i) = a.at(i);
      if(a.at(i) == 1) cnt1++;
    }else{
      int cnt = 0;
      for(int j = 0; j < N/(i+1); j++){
        cnt += b.at((i+1) * (j+1) - 1);
      }
      if(cnt % 2 == a.at(i)){
        b.at(i) = 0;
      }else{
        b.at(i) = 1;
        cnt1++;
      }
    }
  }
  
  cout << cnt1 << endl;
  for(int i = 0; i < N; ++i){
    if(b.at(i) == 1) cout << i+1 << endl;
  }
}

Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<vector>
#define ll long long
using namespace std;
 
const int N=200005;
const ll inf=1000000000000000ll;
const int mod=1000000007;
 
struct E{
	int to,next,w;
}mem[N<<1];
struct node{
	int x,y,w;
	node(){}
	node(int x,int y,int w):x(x),y(y),w(w){}
}e[N<<1];
int n,m,num,x,y,w,s,t,ans,cnt;
ll s1,s2;
int head[N],dp1[N],dp2[N],d[N];
bool vis[N];
ll dis1[N],dis2[N];
queue<int> q;
vector<int> lev[N];
 
void add(int x,int y,int w){
	num++;
	mem[num].to=y; mem[num].next=head[x]; mem[num].w=w;
	head[x]=num;
	e[++cnt]=node(x,y,w);
}

void spfa(int st,ll dis[]){
	int j,k,u,i;
	memset(vis,0,sizeof(vis));
	for (i=1;i<=n;i++) dis[i]=inf;
	q.push(st); dis[st]=0;
	while (!q.empty()){
		k=q.front(); q.pop(); vis[k]=0;
		for (j=head[k];j;j=mem[j].next){
			u=mem[j].to;
			if (dis[k]+1ll*mem[j].w<dis[u]){
				dis[u]=dis[k]+1ll*mem[j].w;
				if (!vis[u]){
					q.push(u); vis[u]=1;
				}
			}
		}
	}
}

void work(int st,ll dis[],int dp[]){
	int i,j,u,k;
	memset(d,0,sizeof(d));
	for (i=1;i<=n;i++) lev[i].clear();
	for (i=1;i<=n;i++){
		for (j=head[i];j;j=mem[j].next){
			u=mem[j].to;
			if (dis[i]+1ll*mem[j].w==dis[u]){
				lev[i].push_back(u); d[u]++;
			}
		}
	}
	q.push(st); dp[st]=1;
	while (!q.empty()){
		k=q.front(); q.pop();
		for (j=0;j<lev[k].size();j++){
			u=lev[k][j]; d[u]--;
			(dp[u]+=dp[k])%=mod;
			if (!d[u]) q.push(u);
		}
	}
}

int main(){
	int i,j,u;
	scanf("%d%d",&n,&m);
	scanf("%d%d",&s,&t);
	for (i=1;i<=m;i++){
		scanf("%d%d%d",&x,&y,&w);
		add(x,y,w); add(y,x,w);
	}
	spfa(s,dis1);
	spfa(t,dis2);
	work(s,dis1,dp1);
	work(t,dis2,dp2);
	ans=1ll*dp1[t]*dp1[t]%mod;
	for (i=1;i<=n;i++){
		if (dis1[i]==dis2[i]&&dis1[i]+dis2[i]==dis1[t]){
			(ans-=1ll*dp1[i]*dp1[i]%mod*dp2[i]%mod*dp2[i]%mod)%=mod;
		}
	}
	for (i=1;i<=cnt;i++){
		x=e[i].x; y=e[i].y; w=e[i].w;
		if (2ll*dis1[x]<dis1[t]&&2ll*dis2[y]<dis1[t]&&dis1[x]+dis2[y]+1ll*w==dis1[t]){
			(ans-=1ll*dp1[x]*dp1[x]%mod*dp2[y]%mod*dp2[y]%mod)%=mod;
		}
	}
	ans=(ans%mod+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 24064
from math import factorial

N = int(input())
d = {}
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if not d.get(s_sorted):
        d[s_sorted] = 1
    else:
        d[s_sorted] += 1

ans = 0
for _, v in d.items():
    if v == 1:
        continue
    ans += v * (v - 1) // 2

print(round(ans))


Measured memory_bytes: 17888
#include <stdio.h>
#include<string.h>
int main()
{

    int a,b,c,d;
    while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
    {
    if(a<=c&&b>=d)
        printf("%d\n",d-c);
    else if(a>=c&&b<=d)
        printf("%d\n",b-a);

    else if(a>=c&&a<=d&&b>=d)
        printf("%d\n",d-a);
    else if(b<=c||a>=d)

       {

         printf("0\n");
   
       }
    else if(a<=c&&b>=c&&d>=b)
         printf("%d\n",b-c);
      }


    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <utility>
#include <algorithm>
using namespace std;

typedef pair<int, int> Pair;

int n;
Pair x[100000];
Pair y[100000];
char xgrp[100000];
char ygrp[100000];

#define BOTH 0
#define A 1
#define B 2
#define C 4
#define D 8

int check(int k) {
    int xmin = x[0].first;
    int xmax = x[n-1].first;
    int ymin = y[0].first;
    int ymax = y[n-1].first;
    char a = 0;
    char b = 0;

    memset(xgrp, BOTH, sizeof(xgrp));
    for (int i=0; i<n; i++) {
        if (abs(x[i].first - xmin) > k && abs(xmax - x[i].first) > k) return 0;
        if (abs(x[i].first - xmin) > k) xgrp[x[i].second] = A;
        if (abs(xmax - x[i].first) > k) xgrp[x[i].second] = B;
    }

    memset(ygrp, BOTH, sizeof(ygrp));
    for (int i=0; i<n; i++) {
        if (abs(y[i].first - ymin) > k && abs(ymax - y[i].first) > k) return 0;
        if (abs(y[i].first - ymin) > k) ygrp[y[i].second] = C;
        if (abs(ymax - y[i].first) > k) ygrp[y[i].second] = D;
    }

    for (int i=0; i<n; i++) {
        if (xgrp[i] != BOTH && ygrp[i] != BOTH) {
             if (a == 0) {
                 a = xgrp[i]|ygrp[i];
                 b = 15&~a;
             } else if ((xgrp[i]|ygrp[i]) != a && (xgrp[i]|ygrp[i]) != b) return 0;
        }
    }

    return 1;
}     

int main() {
    int low;
    int high;

    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        int xi, yi;

        scanf("%d %d", &xi, &yi);
        x[i] = Pair(xi-yi, i);
        y[i] = Pair(xi+yi, i);
    }
    sort(x, x+n);
    sort(y, y+n);

    low = -1;
    high = 400001;
    while (high - low > 1) {
        int mid = (low+high)/2;
        if (check(mid)) high = mid;
        else low = mid;
    }

    printf("%d\n", high);
}

Measured memory_bytes: 2792
import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        int n = ni();
        long[] w = new long[n];long sum = 0;
        for(int i = 0; i< n; i++){
            w[i] = nl();
            sum+=w[i];
            if(i>0)w[i]+=w[i-1];
        }
        long ans = sum;
        for(int i = 0; i< n; i++)ans = Math.min(ans, Math.abs(sum-2*w[i]));
        pn(ans);
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    long mod = (long)1000000007, IINF = (long)1e18;
    final int INF = (int)1e9, MX = (int)2e5+5;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
    static boolean multipleTC = false, memory = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }  
            return str;
        }
    }
}

Measured memory_bytes: 23124
import java.util.*;

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

        if(S.charAt(2) == S.charAt((3)) && S.charAt(4) == S.charAt(5)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22356
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<ll> B(N, 100);
  bool turn = 1;
  rep(i, N){
    if(turn){
      B[i/2] = A[N-i-1];
    }else{
      B[N-i/2-1] = A[N-i-1];
    }
    turn = !turn;
  }
  rep(i, N) cout << B[i] << " ";
  cout << endl;
}


Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
using namespace std;
double fill_probability(vector <double> &v,int n)
{
    vector <vector <double> > dp (n+1,vector <double> (n+1,0.0));
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(j==0)
            {
                dp[i][j] = dp[i-1][j]*(1.0-v[i]);
            }
            else
            {
                dp[i][j] = dp[i-1][j-1]*v[i] + dp[i-1][j]*(1.0 - v[i]);
            }
        }
    }
    double ans=0.0;
    for(int i=(n+1)/2;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    return ans;
}
int main()
{
    int n;
    cin>>n;
    vector <double> v(n+1,0.0);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    double ans = fill_probability(v,n);
    std::cout << std::setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 73776
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5; int n, k;
lli h[maxN];

int main()
{
  while (scanf("%d %d", &n, &k) != EOF)
  {
    for (int i = 0; i < n; i ++)
      scanf("%lld", &h[i]);
    sort(h, h+n);

    lli ans = 0;
    for (int i = n - k - 1; i >= 0; i --)
      ans += h[i];
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1792
from math import *
def koch(n, a, b):
    if n == 0:
        return
    th = pi * 60.0 / 180.0
    s = complex((2.0 * a.real + 1.0 * b.real) / 3.0, (2.0 * a.imag + 1.0 * b.imag) / 3.0)
    t = complex((1.0 * a.real + 2.0 * b.real) / 3.0, (1.0 * a.imag + 2.0 * b.imag) / 3.0)
    u = complex((t.real - s.real) * cos(th) - (t.imag - s.imag) * sin(th) + s.real,
                (t.real - s.real) * sin(th) + (t.imag - s.imag) * cos(th) + s.imag)
    koch(n - 1, a, s)
    print(s.real, s.imag)
    koch(n - 1, s, u)
    print(u.real, u.imag)
    koch(n - 1, u, t)
    print(t.real, t.imag)
    koch(n - 1, t, b)
n = int(input())
a = complex(0, 0)
b = complex(100, 0)
print(a.real, a.imag)
koch(n, a, b)
print(b.real, b.imag)



Measured memory_bytes: 5780
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

constexpr double EPS = 1e-7;

template <typename T>
constexpr T INF = numeric_limits<T>::max();

template <class T>
constexpr T PI = static_cast<T>(3.14159265358979323846);

constexpr int MOD = 1e9 + 7;

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

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

template <typename T>
std::vector<T> table(int n, T v) { return std::vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
	auto val = table(args...);
	return std::vector<decltype(val)>(n, std::move(val));
}

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int N, K;
	cin >> N >> K;

	auto p = table(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}

	auto e = table(N, 0.0);
	for (int i = 0; i < N; i++) {
		for (int j = 1; j <= p[i]; j++) {
			e[i] += (double)j / p[i];
		}
	}

	auto cum = table(N + 1, 0.0);
	for (int i = 0; i < N; i++) {
		cum[i + 1] = cum[i] + e[i];
	}

	double emax = -1;
	for (int i = K; i <= N; i++) {
		chmax(emax, cum[i] - cum[i - K]);
	}

	cout << emax << endl;
	return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
#define endl "\n"
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int x, y, z;
    cin>>x>>y>>z;
    swap(x, y);
    swap(x, z);
    cout<<x<<" "<<y<<" "<<z<<"\n";

    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  a=LI()

  a.sort()

  b=a[0]
  c=1
  sm=0
  for x in a[1:]:
    if b==x:
      c+=1
    else:
      if c==b:
        pass
      elif c>b:
        sm+=c-b
      else:
        sm+=c

      c=1
      b=x

  if c==b:
    pass
  elif c>b:
    sm+=c-b
  else:
    sm+=c

  return sm

print(main())


Measured memory_bytes: 17368
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		ans+=b-a+1;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256