akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[][] used;
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        String s = sc.next();
        String t = sc.next();
        System.out.println(s.equals(t.substring(0,t.length()-1)) ? "Yes" : "No");
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 25400
def merge(num_list,left,right,cnt):
    mid = (left+right)//2
    L = num_list[left:mid][:]
    R = num_list[mid:right][:]
    L.append(float("inf"))
    R.append(float("inf"))
    i = 0
    j = 0

    for k in range(left,right):
        if L[i] > R[j]:
            cnt = cnt + len(L)-i-1
            num_list[k] = R[j]
            j += 1
        else:
            num_list[k] = L[i]
            i += 1
    return cnt

def merge_sort(num_list,left,right,cnt):
    mid = (left+right)//2
    if left+1 < right:
        cnt_l = merge_sort(num_list,left,mid,cnt)
        cnt_r = merge_sort(num_list,mid,right,cnt)
        cnt_all = cnt_l+cnt_r
        cnt = merge(num_list,left,right,cnt_all)

    return cnt

if __name__ == "__main__":
    n = int(input())
    cnt = 0
    num_list = list(map(int,input().split()))
    cnt = merge_sort(num_list,0,len(num_list),cnt)
    print(cnt)


Measured memory_bytes: 27480
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const ll mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X;
string S, T;

int main(){
  cin >> S;
  int cnt = 0;
  while ((int)S.size() > 1){
    char s = S[0];
    char t = S[S.size()-1];
    if( s == t ){
      S.pop_back();
      S.erase(0,1);
    }else if(s!=t && s == 'x'){
      S.erase(0,1);
      cnt++;
    }else if(s!=t && t == 'x'){
      S.pop_back();
      cnt++;
    }else{
      cout << -1 << endl;
      return 0;
    }
//    cout << S << endl;
  }
  if(S.size() <= 1 )  cout << cnt << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n)cin >> a[i];
	int ret = 0;
	int mx = a[0];
	for(int i = 1;i < n;i++){
		if(mx > a[i])ret += mx - a[i];
		mx = max(mx,a[i]);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, int> P3;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-11;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#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 ALL(v) (v).begin(), (v).end()

struct SegmentTree {
    int N;
    vector<int> node;

    SegmentTree(){}
    SegmentTree(int n_){
        init(n_);
    }

    void init(int siz){
        N = 1;
        while (N < siz) N *= 2;
        node.resize(2*N-1, 0);
    }

    void build(vector<int> &dat){
        int siz = dat.size();
        for(int i=0; i<siz; i++){
            node[i+N-1] = dat[i];
        }
        for(int i=N-2; i>=0; i--){
            node[i] = node[2*i+1] + node[2*i+2];
        }
    }

    void update(int k, int a) {
        k += N - 1;
        node[k] = a;
        while (k > 0) {
            k = (k-1)/2;
            node[k] = node[k*2+1] + node[k*2+2];
        }
    }
    int getSum(int a, int b) {return getSum(a, b, 0, 0, N);}
    int getSum(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)
            return 0;
        if (a <= l && r <= b)
            return node[k];
        else {
            int vl = getSum(a, b, k*2+1, l, (l+r)/2);
            int vr = getSum(a, b, k*2+2, (l+r)/2, r);
            return vl + vr;
        }
    }
};

int main() {
    int n, k;
    string s, ans="";
    cin >> s >> k;
    n = s.size();
    vector<int> v(n,1), pos[26];
    SegmentTree rsq(n);
    rsq.build(v);
    REP(i,n){
        pos[s[i]-'a'].push_back(i);
    }
    REP(i,26){
        SORT(pos[i]);
        reverse(ALL(pos[i]));
    }
    REP(i,n){
        REP(j,26){
            if(pos[j].size()>0 && rsq.getSum(0,pos[j].back()) <= k){
                ans.push_back('a'+j);
                k -= rsq.getSum(0,pos[j].back());
                rsq.update(pos[j].back(),0);
                pos[j].pop_back();
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 7176
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
count = 0
sum = 0

n.times do |i|
  if a[i] < 0
    count += 1
  end

  a[i] = a[i].abs
  sum += a[i]
end

if count % 2 == 1
  sum -= a.min * 2
end

puts sum


Measured memory_bytes: 9732
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
XYC=[list(map(int,input().split())) for _ in range(m)]

cnt=10**7
for x,y,c in XYC:
    cnt=min(cnt,A[x-1]+B[y-1]-c)
print(min(cnt,min(A)+min(B)))

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

using namespace std;
const int INF = 1e9;

int main() {
    int n;
    cin >> n;
    
    vector<int> a(n, INF), b(n - 1);
    for (int &t : b)
        cin >> t;
        
    for (int i = 0; i < n - 1; ++i) {
        a[i] = min(a[i], b[i]);
        a[i + 1] = min(a[i + 1], b[i]);
    }
    
    long long ans = 0;
    
    for (int i = 0; i < n; ++i) {
        ans += a[i];
        // cout << a[i] << " ";
    }
    // cout << "\n";
    
    cout << ans;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
while (n = STDIN.gets.chomp.to_i) != 0
  array = STDIN.gets.chomp.split(/\s+/)
  hash = Hash.new(0)
  array.each do |a|
    hash[a] += 1
  end

  key, num = hash.sort{|(k1, v1), (k2, v2)| v2 <=> v1}[0]
  if num > n / 2
    puts key
  else
    puts 'NO COLOR'
  end

end

Measured memory_bytes: 241304
long n,a[3][1<<18],b,c,x,y,N[1<<18],M[1<<18],i,j;main(){scanf("%d",&n);for(i=0;i<3;++i)for(j=0;j<n;++j){scanf("%d",&a[i][j]);--a[i][j];}for (i=0;i<n;++i){if(a[0][i]/3!=a[1][i]/3||a[1][i]/3!=a[2][i]/3||a[2][i]/3!=a[0][i]/3||a[1][i]%3!=1||(a[1][i]/3-i)%2){puts("No");return 0;}x=a[1][i]/3+1;while(x){if(i&1)c-=M[x];else b-=N[x];x-=x&-x;}if(i&1)c+=i/2;else b+=i/2;y=a[2][i]/3+1;while (y<1<<18){if(i&1)++M[y];else ++N[y];y+=y&-y;}if(a[0][i]%3){if(i&1)++b;else++c;}}puts((b&1)||(c&1)?"No":"Yes");}

Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll p=1000000007ll;
const int N=100005;
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
int dp[N][2],h[N];
int main(){
	int n,i,a,b;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",&h[i]);
	dp[1][0]=dp[1][1]=1;
	for(i=2;i<=n;++i)for(a=0;a<2;++a)if(dp[i-1][a])for(b=0;b<2;++b)if(h[i-1]-a<=h[i]-b)dp[i][b]=1;
	if(dp[n][0]||dp[n][1])puts("Yes");else puts("No");
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

int main()
{

    int r,b,g;

    cin >> r >> g >> b;

    int num = r * 100 + g * 10 + b;

    if(num % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
//nani?
#include<bits/stdc++.h>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i,a,b) for( int i = a; i < b ; i++ ) 
#define sor(a) sort( a.begin(), a.end() )
#define rsor(a) sort( a.rbegin(), a.rend() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
//#define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
const ll inf=1e9;
const ll MOD=1e9+7;
// ac cmtr;
const ll MAX_N = 1e5;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif
//---------------------------

ld dp[100005];

int main(){
    fastio;
    ll n;
    cin>>n;
    vector <double> v;
    dp[0]=1;
    f(i,0,n){
        ld p;
        cin>>p;
        v.pb(p);
    }
    f(i,0,v.size()){
        for(int j=i+1;j>=0;j--){
            dp[j]=dp[j-1]*v[i] + dp[j]*(1-v[i]);
        }
    }
    ld ans=0;
    for(int i=n;i>=(n+1)/2;i--){
    	ans+=dp[i];
    }
    cout<<fixed<<setprecision(12)<<ans<<endl;


    return 0;
}   



Measured memory_bytes: 384
n=int(input())
s=input()
count=0
for i in range(n):
  str_1=s[0:i-1]
  str_2=s[i-1:n]
  if count<len(set(str_1)&set(str_2)):
    count=len(set(str_1)&set(str_2))
print(count)      

Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll n,m;
cin>>n>>m;
ll p[m+1];
string s[m+1];
ll c1=0,c2=0;
ll corr[n];
ll w[105000];
bool vis[105000];
 for(int i = 1; i <= n; i++) {
        w[i] = 0;
        corr[i]=0;
        vis[i]=false;
    }

for(int i=0;i<m;i++){
    cin>>p[i]>>s[i];
    if(vis[p[i]]) continue;
    if(s[i]=="AC"){
        vis[p[i]]=true;
       c1++;
        c2+=w[p[i]];
      
    }
    else if(s[i]=="WA"){
        w[p[i]]++;
        //cout<<w[p[i]]<<endl;
    }
}
    
cout<<c1<<" "<<c2<<endl;

}

Measured memory_bytes: 8192
#include <stdio.h>

int main() {
	int h1, h2, m1, m2, k;
	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
	printf("%d\n", 60 * (h2 - h1) + m2 - m1 - k);
	
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        n -= x;
    }
    cout << (n < 0 ? -1 : n) << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n;
string s;
int32_t main(){
CODE_START;
cin>>s;
if(s[s.size()-1]=='s'){
    cout<<s;
    cout<<"es"<<endl;
}else cout<<s<<'s'<<endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4

int main(){
  int N; cin >> N;

  for (int i=1;i<10;i++){
    if (N%i==0 && N/i>=1 && N/i<=9){
      cout << "Yes" << endl;
      return 0;
    } 
  }
  cout << "No" << endl;


  return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// #include <cstdio>
// int a;
// scanf("%d", &a);
// printf("%d\n", a);
//
// for (int i=0; i<n; ++i)
// 	scanf("%d", &a[i]);
//
// char c;
// scanf(" %c", &c);
//
// cout << "\n";

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

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

/*
ll	myPow(ll x, ll n) {
	if (0==n)
		return 1;
	if (0==n%2)
		return myPow(x*x%MOD, n/2);
	else
		return x*myPow(x, n-1)%MOD;
}
*/
ll	myPow(ll x, ll n) {
	ll r=1;
	while(n>0)
		if (0==n%2) {
			x *=x;
			x %=MOD;
			n /=2;
		} else {
			r *=x;
			r %=MOD;
			n--;
		}
	return r;
}

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int H, W;
	cin >>H >>W;
	Rep1(i, H)
		Rep0(j, W) {
			string S;
			cin >>S;
			if ("snuke"==S) {
				cout <<(char)('A'+j) <<i <<endl;
				return 0;
			}
		}
	return 0;
}



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

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

int n,m;
int dp[101][1<<16];
int s[16],d[101];
int dat[1<<16];

int main(void){
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0 && m==0)break;
		for(int i=0;i<(1<<n);i++){
			for(int j=0;j<=m;j++){
				dp[j][i]=INF;
			}
		}
		for(int i=0;i<n;i++){
			scanf("%d",&s[i]);
		}
		for(int i=0;i<m;i++){
			scanf("%d",&d[i]);
		}
		for(int i=0;i<(1<<n);i++){
			dat[i]=0;
			for(int j=0;j<n;j++){
				if(i>>j & 1){
					dat[i]+=s[j];
				}
			}
		}
		sort(d,d+m);
		dp[0][0]=0;
		for(int i=0;i<m;i++){
			for(int j=0;j<(1<<n);j++){
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]+abs(dat[j]-d[i]));
				for(int k=0;k<n;k++){
					if(!(j>>k & 1)){
						dp[i][j|(1<<k)]=min(dp[i][j|(1<<k)],dp[i][j]);
					}
				}
			}
		}
		int res=INF;
		for(int i=0;i<(1<<n);i++){
			res=min(res,dp[m][i]);
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 16676
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    char a[7][7] = {"","*abcde","*fghij","*klmno","*pqrst","*uvwxy","*z.?! "};
    char s[200];
    while(~scanf("%s",s)){
        bool flg = false;
        if(strlen(s)%2==1)flg = true;
        else{
            for(int i=0;i<strlen(s);i+=2){
                if(s[i]<49||s[i]>54||s[i+1]<49||s[i+1]>53){
                    flg = true;
                    break;
                }
            }
            if(!flg){
                for(int i=0;i<strlen(s);i+=2){
                    printf("%c",a[s[i]-48][s[i+1]-48]);
                }
            }

        }
        if(flg)printf("NA");
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 956
#-*-coding:utf-8-*-
from collections import Counter

def main():
    s = list(map(int, list(input())))
    k = int(input())

    counter = Counter(s[:k])
    if counter[1] == k:
        print(1)
        exit()
    for i in s:
        if i != 1:
            print(i)
            break

if __name__ == '__main__':
    main()
    

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

int main(int argc, char const *argv[]) {
  ll n, k;std::cin >> n >> k;
  if(n<2*k-1){
    std::cout << -1 << '\n';
    return 0;
  }
  vvl ans = vv(0, 3, 0, ll);
  if(n%2){
    for(ll i=0;i<n/2+1;i++){
      ll a = k+2*i, b = k+2*n-1-i;
      ans.push_back(vll{a+b, a, b});
    }
    for(ll i=0;i<n/2;i++){
      ll a = k+1+2*i, b = k+2*n-1-(n/2+1)-i;
      ans.push_back(vll{a+b, a, b});
    }
    sort(all(ans));
    re(i, n){
      std::cout << ans[i][1] << " " << ans[i][2] << " " << k+2*n+i << '\n';
    }
  }else{
    for(ll i=0;i<n/2;i++){
      ll a = k+2*i, b = k+2*n-1-i;
      ans.push_back(vll{a+b, a, b});
    }
    for(ll i=0;i<n/2;i++){
      ll a = k+1+2*i, b = k+2*n-1-n/2-i;
      ans.push_back(vll{a+b, a, b});
    }
    sort(all(ans));
    re(i, n){
      std::cout << ans[i][1] << " " << ans[i][2] << " " << k+2*n+i << '\n';
    }
  }

  return 0;
}


Measured memory_bytes: 8368
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> p(n), c(n);
    rep(i,n){
        cin >> p[i];
        --p[i];
    }
    rep(i,n) cin >> c[i];
    ll ans = -1e18;
    rep(si,n){
        int x = si;
        vector<int> s;
        ll tot = 0;
        while(true){
            x = p[x];
            s.push_back(c[x]);
            tot += c[x];
            if(x == si) break;
        }
        int l = s.size();
        ll t = 0;
        rep(i,l){
            t += s[i];
            if(i+1 > k) break;
            ll now = t;
            if(tot >= 0){
                ll e = (k-(i+1)) / l;
                now += tot * e;
            }
            chmax(ans, now);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

string s;
int di[] = {0,1,-1,0,1,-1,0}, dj[] = {-1,0,-1,0,1,0,1};

int filt(int a[5][5], int i, int j){
    int x = 0;
    REP(k,7){
        x += a[i+di[k]][j+dj[k]] * (1<<k);
    }
    return s[x] - '0';
}

int main() {
    int p[] = {0,1,2,0,1,2,3,0,1,2,3,4,1,2,3,4,2,3,4};
    int q[] = {0,0,0,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4};
    int u[] = {1,2,1,2,3,2,3};
    int v[] = {1,1,2,2,2,3,3};
    while (cin >> s && s != "#"){
        int a[5][5], b[5][5];
        bool f = true;
        int n = 19, m = 7;
        REP(x,1<<n){
            REP(k,n){
                a[p[k]][q[k]] = ((x>>k) & 1);
            }
            REP(k,m){
                b[u[k]][v[k]] = filt(a, u[k], v[k]);
            }
            if (b[2][2] != filt(b, 2, 2)) f = false;
        }
        cout << (f ? "yes" : "no") << endl;
    }

    return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 100001;

int n, a, b;
vector <int> v[N], cur;

void dfs(int node, int pnode){
    cur.push_back(node);
    if(cur.back() == b) return;
    for(auto &i : v[node]){
        if(i == pnode) continue;
        dfs(i, node);
        if(cur.back() == b) return;
    }
    cur.pop_back();
}
int dfs(int node, int pnode, int dep){
    int ret = dep;
    for(auto &i : v[node]){
        if(i == pnode) continue;
        ret = max(ret, dfs(i, node, dep + 1));
    }
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> a >> b;
    for(int i = 0 ; i < n - 1 ; i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(a, 0);
    int mid = cur.size() / 2;
    cout << (cur.size() + 1) / 2 - 1 + dfs(cur[mid - 1], cur[mid], 0) << endl;
}


Measured memory_bytes: 10744
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
		char a[10];
    char b[10];
    char c[10];
    int d;
    int e;

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


		scanf("%s",c);
		if(strcmp(a,c) == 0){
			d--;}
			else if (strcmp(b,c) == 0){
				e--;
		}
printf("%d %d\n",d,e);


		return 0;
}

Measured memory_bytes: 128
A, B, C, D, E, F = map(int, input().split())
water = []
sugar = []
pct = -1
ans_sugar = 0
ans_tot = 0

# water
for a in range(F + 1):
	if 100 * A * a > F: break
	for b in range(F + 1):
		x = 100 * A * a + 100 * B * b
		if x <= F:
			water.append(x)
			
# sugar
for a in range(F + 1):
	if C * a > F: break
	for b in range(F + 1):
		x = C * a + D * b
		if x <= F:
			sugar.append(x)
			
for w in water:
	for s in sugar:
		if w + s == 0: continue
		if w + s <= F and E * w / 100 >= s:
			if pct < s / (w + s):
				pct = s / (w + s)
				ans_sugar = s
				ans_tot = w + s
				
print(ans_tot, end = " ")
print(ans_sugar)

Measured memory_bytes: 52476
#include <cstdio>

int main()
{
  int n;
  scanf("%d",&n);
  int C=0;
  while((C+1)*(C+2)/2<=n){
    C++;
  }
  int A=n-C*(C+1)/2;
  for(int i=1;i<=C;i++){
    printf("%d\n",i>C-A?1+i:i);
  }
  return 0;
}


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

int main(){

    long long a;
    string b;
    cin>>a>>b;

    string tmp_b;

    for (int i=0;i<=b.size();i++){
        if (b[i]!='.') tmp_b.push_back(b[i]);
    }

    long long c=stoi(tmp_b);

    cout<<a*c/100<<endl;



    return 0;
}

Measured memory_bytes: 3644
def main():

    S = input()
    for i in range(len(S)):
        if i % 2 == 1 and S[i] == "R":
            return "No"
        if i % 2 == 0 and S[i] == "L":
            return "No"
    return "Yes"
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
import java.util.LinkedList;
import java.util.Scanner;
 
 
public class Main{
	
    public static void main(String[] args){
    	
    	final Scanner sc = new Scanner(System.in);
    	
    	String input = sc.next();
    	
    	LinkedList<LinkedList<String>> parse = new LinkedList<LinkedList<String>>();
    	
    	String prev = "";
    	LinkedList<String> tmp = new LinkedList<String>();
    	while(!input.isEmpty()){
    		//System.out.println(input);
    		
    		if(input.startsWith("egg")){
    			if(prev.equals("egg")){
    				parse.add(tmp);
    				tmp = new LinkedList<String>();
    			}
    			tmp.add("egg");
    			prev = "egg";
    			
    			input = input.substring("egg".length());
    		}else{
    			if(prev.equals("chicken")){
    				parse.add(tmp);
    				tmp = new LinkedList<String>();
    			}
    			tmp.add("chicken");
    			prev = "chicken";
    			
    			input = input.substring("chicken".length());
    		}
    	}
    	
    	if(!tmp.isEmpty()){
    		parse.add(tmp);
    	}
    	
    	//System.out.println(parse);
    	
    	int max = Integer.MIN_VALUE;
    	String str = null;
    	for(LinkedList<String> list : parse){
    		if(max < list.size()){
    			max = list.size();
    			str = list.getLast();
    		}
    	}
    	
    	System.out.println(str);
    }
     
}

Measured memory_bytes: 20616
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  bitset<3010> water,sugar;
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  a*=100;
  b*=100;
  rep(i,f/a+1){
     water|=water<<a;
     water.set(a); 
  }
  rep(i,f/b+1){
     water|=water<<b;
     water.set(b); 
  }
  rep(i,f/c+1){
     sugar|=sugar<<c;
     sugar.set(c); 
  }
  rep(i,f/d+1){
     sugar|=sugar<<d;
     sugar.set(d); 
  }
  int s;
  pair<int,int> p={0,0};
  for(int i=100;i<=f;i+=100){
    if(water.test(i)){
      s=i/100*e;
      int k=0;
      for(int j=0;j<=s&&i+j<=f;j++)
         if(sugar.test(j))
           k=j;
      if(k){
         if(p.first==0 || k>p.second*i/p.first){
            p.first=i;
            p.second=k;
         }
      }
    }
  }
  if(p.first==0){
    cout<<min(a,b)<<" "<<0;
  }else
  cout<<p.first+p.second<<" "<<p.second;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int N, c=0;
    cin >> N;
    int p[N];
	for (int i = 0; i < N; i++)
	{
		cin >> p[i];
      if (i+1 != p[i]){
        c++;
      }
	}
    if (c==0 || c==2) {
      cout << "YES";
    } else {
      cout << "NO";
    }
  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
   
class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
   
        int [][][] build = new int [4][3][10];
        int tatemon,floo,roo;
   
        for(tatemon = 0; tatemon < 4; tatemon++){
            for(floo = 0; floo < 3; floo++){
                for(roo = 0; roo < 10; roo++){
   
                build [tatemon][floo][roo] = 0;
   
                }
            }
        }
   
        int n = scan.nextInt();
        int tatemono = 0;
        int floor= 0;
        int room = 0;
        int info,person;
        String result;
   
        for(info = 0; info < n; info++){
                      
        tatemono = scan.nextInt();
        floor = scan.nextInt();
        room = scan.nextInt();
        person = scan.nextInt();
        build [tatemono-1][floor-1][room-1] = build [tatemono-1][floor-1][room-1]+person;
        }
           
                  
        for(tatemon = 0; tatemon < 4; tatemon++){
            for(floo = 0; floo < 3; floo++){
                for(roo = 0; roo < 10; roo++){ 
                       
                result = " "+build [tatemon][floo][roo];
                       
                
                System.out.print(result);
                }
                System.out.println();
            }
            if(tatemon < 3){
            System.out.println("####################");
            }
        }
          
    }
}

Measured memory_bytes: 29692
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    a,b,c = map(int, input().split())
    k = int(input())

    tmp = 0

    for i in range(k+1):
        for j in range(k+1-i):
            for l in range(k+1-i-j):
                _a = a * 2**i
                _b = b * 2**j
                _c = c * 2**l
                if _a < _b and _b < _c:
                    print('Yes')
                    return
    print('No')



if __name__ == '__main__':
    main()


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

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	
	int ans1,ans2;
	
	if(c%b==0)  ans1=c/b;
	  else ans1=c/b+1;
	
	if(a%d==0)  ans2=a/d;
	  else ans2=a/d+1;
	
	if(ans1<=ans2)  cout<<"Yes";
	  else cout<<"No";
	
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool comp(const string &a,const string &b){
	int i = 0;
	while(a[i] == b[i]){
		i++;
	}
	if(i == a.length()) return 0;
	return a[i] < b[i];
}
int main () {
	int n,l;
	cin >> n >> l;
	vector<string> vecstr;
	for (int i = 0; i < n; i++){
		string str;
		cin >> str;
		vecstr.push_back(str);
	}
	sort(vecstr.begin(), vecstr.end(), comp);
	for (int i = 0; i < n; i++){
		cout << vecstr[i];
	}

	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();

        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                if (n == i * j) {
                    System.out.println("Yes");
                    System.exit(0);
                } 
            }
        }

        System.out.println("No");
    }
}

Measured memory_bytes: 22996
n = int(input())
a = list(map(int, input().split()))

value_count = {}
for item in a:
	value_count[item] = value_count.get(item, 0) + 1

all_pairs = 0
for value in value_count:
	all_pairs += (value_count[value] * (value_count[value] -1)) // 2

for i in range(n):
	value = a[i]
	used_to =  (value_count[value] * (value_count[value] -1)) // 2
	now =  ((value_count[value] - 2) * (value_count[value] -1)) // 2
	print(all_pairs - used_to + now)



Measured memory_bytes: 87756
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<utility>
#include<vector>
using namespace std;


int main(){
    int n;
    cin >> n;
    vector<int> boss(n);
    for(int i=0;i<n-1; i++){
        int x;
        cin >> x;
        boss.at(x-1) +=1;
    }

    for(int i=0; i<n; i++){
        cout << boss.at(i) << endl;
    }
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

int main()
{

    int n, k;
    cin >> n >> k;

    double ans = 0.0;

    for (int i = 1; i <= n; i++)
    {
        double pr = (1.0 / n);
        int req = 0;

        int curr = i;

        while (curr < k)
        {
            curr *= 2;
            req++;
        }
        pr *= (1.0 / (1 << req));
        ans += pr;
    }

    cout << fixed;
    cout << setprecision(15);

    cout << ans << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<vector<int>> board(2 * K + 1, vector<int>(2 * K + 1));
  int sum = 0, white = 0;
  for (int i = 0; i < N; i++) {
    int x, y;
    string c;
    cin >> x >> y >> c;
    x = x % (2 * K), y = y % (2 * K);
    if (c == "B") {
      board[x + 1][y + 1]++;
      sum++;
    }
    if (c == "W") {
      board[x + 1][y + 1]--;
      sum--;
      white++;
    }
  }

  for (int i = 1; i <= 2 * K; i++) {
    for (int j = 1; j <= 2 * K; j++) {
      board[i][j] += board[i][j - 1];
    }
  }
  for (int i = 1; i <= 2 * K; i++) {
    for (int j = 1; j <= 2 * K; j++) {
      board[i][j] += board[i - 1][j];
    }
  }

  int res = -(1 << 28);
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      int a = board[i][j];
      int b =
          board[i + K][j + K] - board[i + K][j] - board[i][j + K] + board[i][j];
      int c = board[2 * K][j] - board[i + K][j];
      int d = board[i][2 * K] - board[i][j + K];
      int e = board[2 * K][2 * K] - board[2 * K][j + K] - board[i + K][2 * K] +
              board[i + K][j + K];
      int tmp = a + b + c + d + e;
      res = max({res, tmp, sum - tmp});
    }
  }
  res += white;
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.in","r",stdin);freopen ("myfile.out","w",stdout);
#define mod 1000000007
using namespace std;

ll n,ar[N],sum,ans[N],dad[N],sz[N],m;

lli p[N];

int find(int x)
{
	if(dad[x]==x)
		return x;
	return dad[x]=find(dad[x]);
}

void unite(int x,int y)
{
	sum-=sz[find(x)]*sz[find(y)];
	sz[find(x)]+=sz[find(y)];
	dad[find(y)]=find(x);
}

int main()
{
	fast;
	cin>>n>>m;
	sum=n*(n-1)/2;
	for(int i=1;i<=n;i++)
		dad[i]=i,sz[i]=1;
	for(int i=1;i<=m;i++)
		cin>>p[i].fi>>p[i].se;
	for(int i=m;i>=1;i--)
	{
		ans[i]=sum;
		if(find(p[i].fi)!=find(p[i].se))
			unite(p[i].fi,p[i].se);

	}
	for(int i=1;i<=m;i++)
		cout<<ans[i]<<endl;


}

Measured memory_bytes: 13184
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

void insertionSort(vector<int> &a, int g, long &cnt)
{
	int j;
	int v;
	for (int i = g; i < a.size(); i++)
	{
		v = a[i];
		j = i - g;
		while (j >= 0 && a[j] > v)
		{
			a[j + g] = a[j];
			j = j - g;
			cnt++;
			if (cnt > (int)pow(a.size(), 1.5))
			{
				return;
			}
		}
		a[j + g] = v;
	}
}

int shellSort(vector<int> &a, vector<int> &g)
{
	long cnt = 0;
	for (int i = 0; i < g.size(); i++)
	{
		insertionSort(a, g[i], cnt);
		if (cnt > (int)pow(a.size(), 1.5))
		{
			break;
		}
	}
	return cnt;
}

int main()
{
	int n;
	long cnt = 0;
	cin >> n;
	vector<int> a(n, 0);
	vector<int> org(a);
	vector<int> g;
	for (int i = 0; i < n; i++)
	{
		cin >> org[i];
	}
	for (int m = 100; m >= 1; m--)
	{
		a = org;
		g.resize(m);
		g[m - 1] = 1;
		for (int i = 1; i < m; i++)
		{
			g[m - 1 - i] = 3 * g[m - i] + 1;
			if ((g[m - 1 - i] <= 0) || (n <= g[m - 1 - i]))
			{
				g[0] = -1;
				break;
			}
		}
		if (g[0] < 0)
		{
			continue;
		}
		else
		{
			cnt = shellSort(a, g);
			if (cnt <= pow(n, 1.5))
			{
				break;
			}
		}
	}
	cout << setprecision(10) << g.size() << endl;
	for (int i = 0; i < g.size(); i++)
	{
		cout << g[i];
		if (i == g.size() - 1)
		{
			cout << endl;
		}
		else
		{
			cout << " ";
		}
	}
	cout << cnt << endl;
	for (int i = 0; i < n; i++)
	{
		cout << a[i] << endl;
	}
}


Measured memory_bytes: 10636
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

vector<pair<int, int>> s;
int n, m, city[114514], co[114514];
string ans[114514];
int main() {
	cin >> n >> m;
	REP(i, m) {
		int a;
		cin >> city[i] >> a;
		s.push_back(make_pair(a,i));
	}
	sort(ALL(s));
	REP(i, m) {
		ans[s[i].second] = to_string(co[city[s[i].second]] + 1);
		co[city[s[i].second]] ++;
		while (ans[s[i].second].size() < 6) ans[s[i].second] = '0' + ans[s[i].second];
		ans[s[i].second] = to_string(city[s[i].second]) + ans[s[i].second];
		while (ans[s[i].second].size() < 12) ans[s[i].second] = '0' + ans[s[i].second];
	}
	REP(i, m) cout << ans[i] << endl;
}	


Measured memory_bytes: 8692
#include <algorithm>
#include <iostream>
#include <set>
#include <utility>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int N, M;
int D[100005], P[100005];
void solve() {
    vector<pair<int, int>> vec;
    rep(i, N) vec.push_back(make_pair(P[i], D[i]));
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    int ans = 0;
    for (auto e : vec) {
        if (e.second < M) {
            M -= e.second;
        } else {
            ans += e.first * (e.second - M);
            M = 0;
        }
    }

    cout << ans << endl;
}
int main() {
    while (cin >> N >> M, N) {
        rep(i, N) cin >> D[i] >> P[i];
        solve();
    }
}

Measured memory_bytes: 3288
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, 
even when nobody else believes they can come true but you. These are not cliches but real tools you 
need no matter what you do in life to stay focused on your path.
*/

 /*Pppppppp    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pppppppp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pp          UU      UU     CC          CC           HH     HH     UU      UU
   pp          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
   */

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    long  a[n+1],b[n];
    for(int i=0;i<=n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    long long  s=0;
    for(int i=0;i<n;i++){
        if(a[i]+a[i+1]>b[i])
        {
           s+=b[i];
           if(b[i]>a[i])
           a[i+1] = a[i+1] - b[i] + a[i];
        }
        else{
            s += a[i] + a[i+1];
            a[i+1]=0;
        }
    }
    cout<<s<<endl;
    return 0;
}

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

int main() {
	string s;
	cin>>s;
	int i=0, j=s.size();
	for(; i<s.size(); i++){
		if (s[i]=='A') break;
	}
	
	for(; j>=0; j--){
		if (s[j]=='Z') break;
	}
	
	cout<<j-i+1;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C;
  cin>>A>>B>>C;
  if(C>A+B+1){
    cout<<A+B+1+B<<endl;
  }
  else{
    cout<<C+B<<endl;
  }
}

Measured memory_bytes: 3556
#include <stdio.h>
#include <math.h>
int n;
struct point{
  double x;
  double y;
};
void print_point(struct point p){
  printf("%.8f %.8f\n",p.x,p.y);
}
void compute(int depth,double x1,double y1,double x2,double y2)
{
  double sin60 = sqrt(3.0)/2.0;
  double cos60 = 0.5;
  struct point s,t,u,v;
 
  s.x = (x1+x1+x2)/3.0;
  s.y = (y1+y1+y2)/3.0;
  t.x = (x1+x2+x2)/3.0;
  t.y = (y1+y2+y2)/3.0;
  v.x = t.x-s.x;
  v.y = t.y-s.y;
  u.x = s.x + cos60*v.x - sin60*v.y;
  u.y = s.y + sin60*v.x + cos60*v.y;
 
  if(depth>= n) return;
 
  compute(depth +1,x1,y1,s.x,s.y);
  printf("%.8f %.8f\n",s.x,s.y);
  compute(depth +1,s.x,s.y,u.x,u.y);
  printf("%.8f %.8f\n",u.x,u.y);
  compute(depth+1,u.x,u.y,t.x,t.y);
  printf("%.8f %.8f\n",t.x,t.y);
  compute(depth+1,t.x,t.y,x2,y2);
}
 
 
 
 
int main(void)
{
  scanf("%d",&n);
  printf("%.8f %.8f\n",0.0,0.0);
  compute(0,0.0,0.0,100.0,0.0);
  printf("%.8f %.8f\n",100.0,0.0);
  return 0;
}



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

int mindiff(int H,int W){
  int w = W / 3;
  int rW = W % 3;
  int h = H / 2;
  int rH = H % 2;
  int ret = min(rW * H , H);
  for(int i = 0; i <= rW; i++){
    int S1 = (w + i) * H;
    int S2 = (2*w + rW - i) * (h + rH);
    int S3 = (2*w + rW - i) * h;
    ret = min(ret,max(S1,max(S2,S3)) - min(S1, min(S2,S3)));
  }
  return ret;
}

int main(){
  int H, W;
  cin >> H >> W;
  cout << min(mindiff(H,W), mindiff(W,H)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

typedef long long LL;
typedef vector<int> VI;

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  int samecnt = 0;
  for (int i = 1; i < N; i++) {
    if (S[i] == S[i-1]) {
      samecnt++;
    }
  }
  // 最後まで反転しきると、N-1(1だけ幸福でない状態になる)
  // Kの制限で途中までしか反転できない場合はすでに幸福な人 + 2*K
  cout << min({samecnt + 2*K, N-1});
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#define d for(x=0;x<N;x++){for(y=0;y<N;y++){

int m[10][10],c,x,y,z,N=10;

int main(){d m[x][y]=x?m[x-1][y+1]+1:y?m[x][y-1]+y:1;}}
  for(;scanf("%d",&N),N;){
    printf("Case %d:\n",++c);
    d printf("%3d",(z=x+y)<N?z%2?m[x][y]:m[y][x]:N*N+1-(z%2?m[N-1-x][N-1-y]:m[N-1-y][N-1-x]));}printf("\n");}}}

Measured memory_bytes: 616
#include<iostream>
#include<iomanip>
#include<string.h>
#include<math.h>
using namespace std;
char numero[100];
int main(){
	cin.getline(numero,100);int d=0;
	if(strlen(numero)%2==0){
		int  j=strlen(numero)/2;
		for(int i=0;i<strlen(numero)/2;i++){
			if(numero[i]==numero[j]){
				d++;
			}
			j+=1;
		}
	}
	else{
		int j=strlen(numero)/2+1;
		for(int i=0;i<strlen(numero)/2;i++){
			if(numero[i]==numero[j]){
					d++;
			}
			j+=1;
		}
	}
	

	if(strlen(numero)%2==0){
		if(d*2==strlen(numero)){
			cout<<"Yes";
		}
		else{
			cout<<"No";
		}
	}
	else{
		if(d*2+1==strlen(numero)){
			cout<<"Yes";
		}
		else{
			cout<<"No";
		}
	}
}

Measured memory_bytes: 256
from math import floor

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

N, P = map(int, input().split())
f = floor(P**(1/N) + 0.0000000003)
for i in range(f, 0, -1):
    a = P / (i ** N)	
    if is_integer_num(a):
        print(i)
        break


Measured memory_bytes: 3060
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 25, M = 200, S = (1 << 19) + 5;
const int mod = 1e9 + 7;	

vector<pii> g[N];
int u[M], v[M], depth[N], par[N], up[N];
int dep[M];
int ctr[S];
ll ways[S], sum[S];
ll prod[M][M];

void dfs(int u, int p);

int main() {
	// cout << (2 * sizeof(ways)) / 1e6 << endl;
	// return 0;
	fast_cin();
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		cin >> u[i] >> v[i];
		if (i < n - 1) {
			g[u[i]].pb({v[i], i});
			g[v[i]].pb({u[i], i});
		}
	}
	dfs(1, 0);
	for (int i = n - 1; i < m; ++i) {
		int eu = u[i], ev = v[i];
		if (depth[eu] < depth[ev]) {
			swap(eu, ev);
		}
		while (depth[eu] > depth[ev]) {
			dep[i] |= (1 << up[eu]);
			eu = par[eu];
		}
		while (eu != ev) {
			dep[i] |= (1 << up[eu]);
			dep[i] |= (1 << up[ev]);
			eu = par[eu];
			ev = par[ev];
		}
	}
	for (int i = 1; i < M; ++i) {
		prod[i][i - 1] = 1;
		for (int j = i; j < M; ++j) {
			prod[i][j] = prod[i][j - 1] * j;
			prod[i][j] %= mod;
		}
	}
	int subsets = (1 << (n - 1));
	for (int mask = 0; mask < subsets; ++mask) {
		// ctr[mask] = __builtin_popcount(mask);
		for (int i = n - 1; i < m; ++i) {
			if (dep[i] & mask) {
				++ctr[mask];
			}
		}
	}
	ways[0] = 1;
	for (int mask = 0; mask < subsets; ++mask) {
		// cout << mask << ' ' << ways[mask] << ' ' << sum[mask] << ' ' << ctr[mask] << endl;
		int b = __builtin_popcount(mask), tot = ctr[mask] + b;
		for (int i = 0; i < n - 1; ++i) {
			if (mask & (1 << i)) {
				continue;
			}
			int new_mask = mask | (1 << i);
			int k = ctr[new_mask] - ctr[mask];
			ll temp = prod[tot + 1][tot + k] * ways[mask];
			temp %= mod;
			ways[new_mask] += temp;
			ways[new_mask] %= mod;
			sum[new_mask] += prod[tot + 2][tot + k + 1] * sum[mask];
			sum[new_mask] += temp * (b + 1);
			sum[new_mask] %= mod;
		}
	}
	cout << sum[subsets - 1] << endl;
}

void dfs(int u, int p) {
	for (auto &e : g[u]) {
		int v = e.first, id = e.second;
		if (v != p) {
			depth[v] = depth[u] + 1;
			par[v] = u;
			up[v] = id;
			dfs(v, u);
		}
	}
}

Measured memory_bytes: 10880
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> p(n);
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>p[i];
        sum+=p[i];
    }
    sort(p.begin(),p.end());
    int ans= sum-p[n-1]/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import math
N,D = map(int, input().split())
X = [list(map(int, input().split()))for _ in range(N)]
ans = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        dis = math.sqrt(sum([(X[i][k]-X[j][k])**2 for k in range(D)]))

        if dis.is_integer():
            ans += 1
print(ans)

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

class Cmondai
{
    static void Main()
    {
        var abcxy = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var A = abcxy[0];
        var B = abcxy[1];
        var C = abcxy[2];
        var X = abcxy[3];
        var Y = abcxy[4];
        var ans = 0L;
        //重なり
        var kasanari = Math.Min(X,Y);
        //A+B,C*2
        ans= (A + B < C * 2)?(A+B)*kasanari:C*2*kasanari;
        //余り
        var amari = Math.Max(X-kasanari,Y-kasanari);
        var amariPiza = X < Y ? B : A;
        //A/B,C*2
        ans += (amariPiza < C * 2) ? amariPiza * amari : C * 2 * amari;
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <algorithm>    
#include <cmath>
#include <map>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <set>
#include <functional>
#define int long long
#define mod(int)(1000000007)
using namespace std;
const int INF = 1000000000000000;
int cnt[345678], test[345678];
signed main() {
	double n; cin >> n;
	double a = (n / 3) * (n / 3) * (n - (n / 3 * 2));
	printf("%.10f\n", a);
	return 0;
}

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

sm = 0
num1 = A.pop(A.index(min(A)))
num2 = A.pop(A.index(min(A)))
num3 = A.pop(A.index(min(A)))

sm += abs(num2 - num1)
sm += abs(num3 - num2)

print(sm)


Measured memory_bytes: 3060