akhauriyash/Code-Regression huggingface dataset:
def main():
    n = int(input())
    abc = [[0, 0, 0] for _ in range(n + 1)]
    for i in range(1, n + 1):
        abc[i] = list(map(int, input().split()))
    dp = [[0, 0, 0] for _ in range(n + 1)]
    dp[1] = abc[1]

    for i in range(1, n + 1):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + abc[i][k])

    print(max(dp[-1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 110676
#include <iostream>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(int i=0,_i=(n);i<_i;++i)
#define _rep3(i,a,b) for(int i=(a),_i=(b),_ii=(b)>(a)?1:-1;abs(_i-i)>0;i+=_ii)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
int N;
int a[400];
ll sum[401];
const ll INF = 1e15;
ll dp[401][401];
ll dfs(int l, int r) {
  // [l, r)
  if (l == r) return 0;
  if (l + 1 == r) return 0;
  if (dp[l][r] != INF) return dp[l][r];

  ll ans = INF;
  rep(i, l+1, r)
    ans = min(ans, dfs(l, i) + dfs(i, r) + sum[r] - sum[l]);

  return dp[l][r] = ans;
}
int main() {
  cin >> N;
  rep(i, N) cin >> a[i];

  sum[0] = 0;
  rep(i, N) sum[i+1] = sum[i] + a[i];

  rep(i, 401) rep(j, 401) dp[i][j] = INF;

  cout << dfs(0, N) << endl;

  return 0;
}


Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>

int main()
{
long long i = 10;
    char ring[101], p[101], line[505];
    scanf("%s", ring);
    scanf("%s", p);

    int ring_length, p_length;
    ring_length = strlen(ring);
    p_length = strlen(p);

    for(int i = 0; i < 5; i++){
      strcpy((line+i*(ring_length)),ring);
    }

    char string[101];
    int line_length = strlen(line);
    int counter = 0, k = 0;

    while(1){
        int i;
        for(i = 0; i < p_length; i++){
            if(i + k < line_length){
              string[i] = line[i + k];}
            else{
              break;
            }
        }
        string[i] = '\0';
        if(strcmp(string, p) == 0){
            counter = 1;
            break;
        }
        k++;
        if(k == line_length - p_length + 1 + 1) break;
    }

    if(counter == 0) printf("No\n");
    else printf("Yes\n");

    return 0;
}

Measured memory_bytes: 960
def examC():
    N = I()
    A = LI()
    newA = []
    for i in range(N):
        cur = A[i]-i-1
        newA.append(cur)
    newA.sort()
    b = newA[N//2]
    ans = 0
    for i in range(N):
        ans += abs(newA[i]-b)
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


Measured memory_bytes: 26400
#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 cnt = 0;
  for (int i = 0; i < N; i += 2) {
    if (A.at(i) % 2 == 1) cnt++;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3624
def partition(A, p, r):
    x = A[r][1]
    i = p-1
    for j in range(p, r):
        if A[j][1] <= x:
            i = i + 1
            (A[i], A[j]) = (A[j], A[i])

    (A[i+1], A[r]) = (A[r], A[i+1])

    return i+1
    
def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)

def stable(A, B):
    for i in range(len(A)):
        if A[i] != B[i]:
            return "Not stable"
    return "Stable"

def merge(A, left, mid, right):
    count = 0
    n1 = mid - left
    n2 = right - mid
    L = []
    R = []

    for i in range(n1):
        L.append(A[left+i])
    for i in range(n2):
        R.append(A[mid+i])

    L.append(10**9)
    R.append(10**9)

    i = 0
    j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
            count = count + n1 - i
    return count

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right)//2
        return mergeSort(A, left, mid) + mergeSort(A, mid, right) + merge(A, left, mid, right)
    else:
        return 0

n = int(input())
X = list(map(int, input().split()))
x = mergeSort(X, 0, n)

print(x)


Measured memory_bytes: 28340
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    auto f = [&](char c1, char c2) {
        string ans = "";
        char next  = 'A';
        char last;
        for (auto e : s) {
            if (e == 'o' && next == 'A') {
                ans.push_back(c1);
                next = c2;
                if (c1 == 'S') last = c2;
                else
                    last = (c2 == 'S' ? 'W' : 'S');
            } else if (e == 'x' && next == 'A') {
                ans.push_back(c1);
                next = c2;
                if (c1 == 'S') last = (c2 == 'S' ? 'W' : 'S');
                else
                    last = (c2 == 'S' ? 'S' : 'W');
            } else if (e == 'o' && next == 'S') {
                ans.push_back(next);
                next = (ans[ans.size() - 2] == 'S' ? 'S' : 'W');
            } else if (e == 'x' && next == 'S') {
                ans.push_back(next);
                next = (ans[ans.size() - 2] == 'S' ? 'W' : 'S');
            } else if (e == 'o' && next == 'W') {
                ans.push_back(next);
                next = (ans[ans.size() - 2] == 'S' ? 'W' : 'S');
            } else if (e == 'x' && next == 'W') {
                ans.push_back(next);
                next = (ans[ans.size() - 2] == 'S' ? 'S' : 'W');
            }
        };
        if (next == ans[0] && last == ans[ans.size() - 1]) {
            cout << ans << '\n';
            exit(0);
        }
    };

    f('S', 'S');
    f('S', 'W');
    f('W', 'S');
    f('W', 'W');
    
    cout << "-1" << '\n';
}


Measured memory_bytes: 3904
#include<stdio.h>
#include<string.h>
int N,M,P,m[8][8][8],x,y,i,j,h,r,p,C[14];
int dfs(int px,int py,int ph,int mx,int my,int mh,int P)
{
	if(0>px||px>N||0>py||py>N||0>ph||ph>N||m[px][py][ph]!=P)
		return 0;
	return dfs(px+mx,py+my,ph+mh,mx,my,mh,P)+1;
}

int main()
{
	for(;scanf("%d%d%d",&N,&M,&P),N;)
	{
		memset(m,0,sizeof(m));
		for(i=r=0,p=1;i<P;i++,p*=-1)
		{
			memset(C,0,sizeof(C));
			scanf("%d%d",&x,&y);
			x--;y--;
			for(h=0;m[x][y][h];h++);
			m[x][y][h]=p;
			if(r!=0)continue;
			C[0]=dfs(x,y,h,0,0,-1,p)+dfs(x,y,h,0,0,1,p)-1;
			C[1]=dfs(x,y,h,0,-1,0,p)+dfs(x,y,h,0,1,0,p)-1;
			C[2]=dfs(x,y,h,-1,0,0,p)+dfs(x,y,h,1,0,0,p)-1;
			C[3]=dfs(x,y,h,0,-1,-1,p)+dfs(x,y,h,0,1,1,p)-1;
			C[4]=dfs(x,y,h,0,1,-1,p)+dfs(x,y,h,0,-1,1,p)-1;
			C[5]=dfs(x,y,h,-1,0,-1,p)+dfs(x,y,h,1,0,1,p)-1;
			C[6]=dfs(x,y,h,1,0,-1,p)+dfs(x,y,h,-1,0,1,p)-1;
			C[7]=dfs(x,y,h,-1,-1,0,p)+dfs(x,y,h,1,1,0,p)-1;
			C[8]=dfs(x,y,h,1,-1,0,p)+dfs(x,y,h,-1,1,0,p)-1;
			C[9]=dfs(x,y,h,-1,-1,-1,p)+dfs(x,y,h,1,1,1,p)-1;
			C[10]=dfs(x,y,h,1,-1,1,p)+dfs(x,y,h,-1,1,-1,p)-1;
			C[11]=dfs(x,y,h,-1,-1,1,p)+dfs(x,y,h,1,1,-1,p)-1;
			C[12]=dfs(x,y,h,1,-1,-1,p)+dfs(x,y,h,-1,1,1,p)-1;
			for(j=0;j<13;j++)
				if(C[j]>=M)
					r=i;
		}
		printf("%s",r==0?"Draw":r%2?"White":"Black");
		if(r==0)
			puts("");
		else
			printf(" %d\n",r+1);
	}
	return 0;
}

Measured memory_bytes: 612
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		Set<String> list = new HashSet<String>();
		int num = sc.nextInt();
		
		for(int i=0;i<num;i++){
			list.add(sc.next());
		}
		
		if(list.size() == 3){
			System.out.println("Three");
		}else if(list.size() == 4){
			System.out.println("Four");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"

void solve() {
  string a, b;
  int m, n;
  cin >> a >> b;
  m = a.size();
  n = b.size();

  int t[m+1][n+1];

  for(int i = 0; i <= m; i++){
    for(int j = 0; j <= n; j++){
      if(i == 0 || j == 0)
        t[i][j] = 0;
    }
  }

  for(int i = 1; i <= m; i++){
    for(int j = 1; j <= n; j++){
      if(a[i-1] == b[j-1]){
        t[i][j] = 1 + t[i-1][j-1];
      }
      else{
        t[i][j] = max(t[i-1][j], t[i][j-1]);
      }
    }
  }

  // printing
  // for(int i = 1; i <= m; i++){
  //   for(int j = 1; j <= n; j++){
  //     cout << t[i][j] << " ";
  //   }cout << endl;
  // }

  vector<char> ans; // rev
  int i = m, j = n;
  int check = 10000;
  while(i > 0 && j > 0 && check > 0){
    check--;
    if(a[i-1] == b[j-1]){
      ans.push_back(a[i-1]);      
      i--;
      j--;
    }
    else if(t[i][j-1] > t[i-1][j]){
      j--;
    }
    else{
      i--;
    }
  }
  for(int k = ans.size() - 1; k >= 0; k--) cout << ans[k];
  cout << endl;
}
int main(){
//#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
// #endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 38856
#include <bits/stdc++.h>
#define vc vector<int>
#define um unordered_map<int,int>
#define ll long long 
#define rep(i,a,b) for(__typeof(a) i=a; i<b; i++)
#define si(a) a.size()
#define all(a) a.begin(),a.end()
#define ss(a) a.second
#define ff(a) a.first
#define M 1000000
#define pb push_back
#define repit(i,a) for(auto i=a.begin(); i!=a.end(); i++)
#define take(arr,n) for(int i=0;i<n;i++)cin>>arr[i]
#define out(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<' '
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define reprev(i,b,a) for(__typeof(b) i=b; i>=a; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define doublearray vector<vector<int>>
#define mod 1000000007
using namespace std;
ll max(ll a, ll b){ return a>b?a:b; }
ll min(ll a, ll b){ return a<b?a:b; }
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}
int main(){
    fastio;
   	int n; cin>>n;
  vc arr(n);
  	take(arr,n);
  	int c=0;
  	sort(all(arr));
  	//out(arr,n); cout<<endl;
  	rep(i,0,n-2){
      rep(j,i+1,n-1){
        rep(k,j+1,n){
          if(arr[i]+arr[j]>arr[k] && arr[i]!=arr[j] && arr[j]!=arr[k]){ c++;}
        }
      }
    }
  cout<<c<<endl;
    return 0;
}





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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

int gcd(int a, int b){
  if(a == 0) return b;
  else return gcd(b%a, a);
}

int32_t main(){
  //DESYNC;
  int n;
  cin >> n;
  int m = (1LL<<n);
  multiset<int, greater<int> > need;
  for(int i=0; i<m; i++){
    int x;
    cin >> x;
    need.insert(x);
  }
  multiset<int, greater<int> > slimes;
  slimes.insert(*need.begin());
  need.erase(need.begin());
  while(slimes.size() < m){
    //cout << "here" << endl;
    vector<int> add;
    for(int x : slimes){
      auto it = need.upper_bound(x);
      if(it == need.end()){
        cout << "No" << endl;
        return 0;
      }
      //cout << "adding " << *it << endl;
      add.pb(*it);
      need.erase(it);
    }
    for(int x : add) slimes.insert(x);
  }
  if(need.size() == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  
    
}



Measured memory_bytes: 14068
#include<iostream>
#include<algorithm>
using namespace std;
int a[100005];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	a[0] = 0;
	a[n + 1] = 0;
	int cnt = 0;
	for (int i = 0; i < n+1; i++) {
		cnt += abs(a[i + 1] - a[i]);
	}
	for (int i = 1; i <= n; i++) {
		cout << cnt - abs(a[i + 1] - a[i]) - abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i - 1]) << endl;
	}
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,i;
	ll a,p=1ll,ans=0ll;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a;
		ans += (a-1)/p;
		if((a-1)/p){
			a = 1ll;
		}
		if(a==p){
			++p;
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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 int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int x[20][20], y[20][20], A[20];

int main() { 
    int N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
        REP(j, A[i]) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int ans = 0;
    REP(ss, 1 << N) {
        bool ok = true;
        REP(i, N) {
            if (!((ss >> i) & 1)) continue;
            REP(j, A[i]) {
                if (((ss >> x[i][j]) & 1) == y[i][j]) continue;
                ok = false;
            }
        }
        if (ok) {
            ans = max(ans, (int)bitset<32>(ss).count());
        }
    }

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

Measured memory_bytes: 256
import sys

#+++++
		
def main():
	b , c = map(int, input().split())
	if c==1:
		return 0
		
	kuti=b
	kosuu=1
	while kuti < c:
		kosuu+=1
		kuti += b - 1
		
	print(kosuu)
	
	
#+++++


if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
  int i,N,a,b;
  long long int K;
  long long int num[100001] = {0};
  scanf("%d %lld",&N,&K);
  for(i=1;i<=N;i++){
    scanf("%d %d",&a,&b);
    num[a] += b;
  }
 
  for(i=1;i<=100000;i++){
    K = K-num[i];
      if(K <= 0){
        printf("%d",i);
        return 0;
      }
  }
  
  return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <algorithm>

using namespace std;

int a[3];

int main(){

	scanf("%d %d %d", &(a[0]), &(a[1]), &(a[2]));
	sort(a, a + 3);

	if (a[0] + a[1] == a[2]){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}


	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    stack <char> s1;
    char s[10000];
    int n,i,c=0;
    scanf("%d",&n);
    scanf(" %s",s);
    for(i=0;s[i];i++)
    {
        if(s[i]=='(')
        {
            s1.push(s[i]);
        }
        else
        {
            if(s1.empty())
            c++;
            else
            s1.pop();
        }
    }
    for(i=0;i<c;i++)
    printf("(");
    printf("%s",s);
    while(!s1.empty())
    printf(")"),s1.pop();
}


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

#define int long long int
#define ff first
#define ss second
#define pb push_back


int bexp(int a, int b)
{
	int res = 1;

	while (b)
	{
		if (b & 1) res = (res * a);

		a = (a * a); 
		b >>= 1;
	}
	return res;
}

int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

#define N 200010
#define MOD 1000000007


int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(10);

	int h, w;
	cin >> h >> w;

	if (h == 1 || w == 1)
	{
		cout << 1 << endl;
		return 0;
	}
	int ans = ((h + 1) / 2) * ((w + 1) / 2) + (h / 2) * (w / 2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String input = br.readLine();
    int time = Integer.parseInt(input);
    int h = time / 3600;
    int m = (time % 3600) / 60;
    int s = (time % 3600) % 60;
    System.out.println(h + ":" + m + ":" + s);
  }
}

Measured memory_bytes: 24308
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
	
int F(int alpha,int beta,int ch){
	return (alpha*ch+beta)%26;
}
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int main(){
	int n;
	string in,s,ans;
	cin>>n;
	getline(cin,in);
	while(n--){
		getline(cin,in);
		for(int i=1;i<26;i++){
			if(gcd(26,i)!=1)continue;
			for(int j=0;j<26;j++){
				int table[26];
				for(int k=0;k<26;k++){
					table[F(i,j,k)] = k;
				}
				s.resize(in.size());
				for(int k=0;k<in.size();k++){
					if(in[k]==' ')s[k]=' ';
					else s[k] = table[in[k]-'a']+'a';
				}
				if(s.find("that",0)!=string::npos
					|| s.find("this",0)!=string::npos){
					cout<<s<<endl;
					goto BREAK;
				}
			}
		}
		BREAK:;
	}
	return 0;
}

Measured memory_bytes: 1212
import numpy as np
import sys
from collections import deque

n,k=list(map(int,input().strip().split(" ")))
a=np.sort(np.array(list(map(int,input().split(" ")))))

zero=len(a[a==0])
pos=a[a>0]
neg=a[a<0]

l,r=10**18,-10**18
while l-r>1:
    c=(r+l)//2
    cnt=0
    if c>=0:
        cnt+=n*zero
    
    cnt+=np.searchsorted(a,c//pos,side='right').sum()+(n-np.searchsorted(a,(-c-1)//(-neg),side='right')).sum()
    cnt-=np.count_nonzero(a*a<=c)
    cnt//=2

    if cnt>=k:
        l=c
    else:
        r=c

print(l)

Measured memory_bytes: 32324
#include <stdio.h>
int main()
{
	int a,b,h;
    // 台形の上辺、底辺、高さを入力
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &h);

    if(1<=a && a<=100 && 1<=b && b<=100 && 1<=h && h<=100){
	    printf("%d\n",(a+b)*h/2);
	}
    return 0;

}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

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

	private void solve() throws IOException {
		try {
			solveA();
			//			 solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int p = nextInt();
		int q = nextInt();
		int r = nextInt();

		out.println(Math.min(q + r, Math.min(p + q, p + r)));
	}

	private void solveB() {
		int n = nextInt();

		out.println("");
	}

	private void solveC() {
		int n = nextInt();

		out.println("");
	}

	private void solveD() {
		int n = nextInt();

		out.println("");
	}

	private void solveE() {
		int n = nextInt();

		out.println("");
	}

	private void solveF() {
		int n = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	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;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

	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();
		}
	}
}

Measured memory_bytes: 22484
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, Integer> map = new TreeMap<>();
        for (int i = 1; i <= n; i++) {
            map.put(sc.nextInt(), i);
        }
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            System.out.print(entry.getValue() + " ");
        }
        System.out.println();
        sc.close();
    }
}

Measured memory_bytes: 70680
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2==0:
                print("#",end="")
            else:
                print(".",end="")
                
        print()    
    print()
 


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

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

using namespace std;

int main(){
  int n;cin>>n;
  vector<string> abc(3);
  rep(i,3)cin>>abc[i];
  int result=0;
  rep(i,n){
    set<char>s;
    rep(j,3)s.insert(abc[j][i]);
    result+=(s.size()-1);
  }

  cout<<result;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
  int N;
  cin >> N;
  vector<string> ans;
  
  auto dfs = [&](auto&& dfs_, string S, int p) -> void {
    if(S.size() == N) {
      ans.emplace_back(S);
      return;
    }
    
    for(char c = 'a'; c != 'a'+p+1; c++){
      string T = S;
      T.push_back(c);
      dfs_(dfs_, T, p+(c=='a'+p));
    }
    return;
  };
  
  dfs(dfs, "a", 1);
  string s = "";
  rep(i, N-1) s += "a";
  if(N > 2) s.push_back('a' + N-1);
  sort(all(ans));
  for(auto& c : ans){
    if(c == s) continue;
    cout << c << endl;
  }
}


Measured memory_bytes: 7796
#include<bits/stdc++.h>
#define N 200005
using namespace std;
struct wzp{
	int c0,c1,id;
	bool operator <(const wzp &a)const{
		return 1ll*c0*a.c1<1ll*c1*a.c0;
	}
};
priority_queue<wzp> q;
int f[N],fa[N],c0[N],c1[N],n;
int get(int x){
	return fa[x]==x?x:fa[x]=get(fa[x]);
}
int main(){
	scanf("%d",&n);
	for (int i=2;i<=n;i++) scanf("%d",&f[i]);
	for (int i=1;i<=n;i++)
		scanf("%d",&c1[i]),c0[i]=1-c1[i];
	for (int i=2;i<=n;i++)
		q.push((wzp){c0[i],c1[i],i});
	for (int i=1;i<=n;i++) fa[i]=i;
	long long ans=0;
	while (!q.empty()){
		wzp tmp=q.top(); q.pop(); int x=tmp.id;
		if (tmp.c0!=c0[x]||tmp.c1!=c1[x]) continue;
		int y=fa[x]=get(f[x]);
		ans+=1ll*c1[y]*c0[x];
		c1[y]+=c1[x]; c0[y]+=c0[x];
		if (y!=1) q.push((wzp){c0[y],c1[y],y});
	}
	printf("%lld",ans);
}

Measured memory_bytes: 7284
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],cnt[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long n,q,a,b,c,x,y,z,i,j,k;
    cin>>n;
    z=0;
    for (i=0;i<n;i++)
    {
    	cin>>arr[i];
    	cnt[arr[i]]++;
    	z+=arr[i];
	}
	cin>>q;
	for (i=0;i<q;i++)
	{
		cin>>a>>b;
		x=cnt[a];
		z=z-x*a+b*x;
		cnt[a]=0;
		cnt[b]+=x;
		cout<<z<<endl;
	}
}

Measured memory_bytes: 5204
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int ans;
    int k,i;
    for(i=1;i<=n;i++)
    {
        ans=0;
        ans=i*i;
        if(ans==n)
        {
            printf("%d",n);
             break;
        }
        if(ans>n)
        {
            k=i-1;
            printf("%d",k*k);
            break;
        }
    }



       return 0;
}


Measured memory_bytes: 128
from collections import deque

n,u,v=map(int,input().split())

tree=[[] for i in range(n)]
for i in range(n-1):
 i,j=map(int,input().split())
 tree[i-1].append(j-1)
 tree[j-1].append(i-1)

def BFS(s):
 dist=[-1 for i in range(n)]
 dist[s]=0

 que=deque()
 que.append(s)

 while que:
  x=que.popleft()
  for p in tree[x]:
   if dist[p]==-1:
    que.append(p)
    dist[p]=dist[x]+1

 return dist

u_dist=BFS(u-1)
v_dist=BFS(v-1)

l=0
for u_d,v_d in zip(u_dist,v_dist):
 if u_d<v_d:
  l=max(l,v_d)

print(l-1)

Measured memory_bytes: 29500
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 200005
#define INF 1e18
lli arr[MAX];
lli dist[60][2600];
struct node{
    lli idx, s,c,d;
};
struct edge{
    lli idx,a,b;
};
vector <node> v(54);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n,m,s;
    cin>>n>>m>>s;
    set <tuple<lli,lli,lli>> pq;
    vector < vector < edge > >  adj(n+4);
    lli Amax = LONG_LONG_MIN;
    for(lli i = 0; i<m; i++){
        lli u,v,a_,b_;
        cin>>u>>v>>a_>>b_;
        Amax = max(Amax, a_);
        edge ij;
        ij.idx = v;
        ij.a = a_;
        ij.b = b_;
        adj[u].push_back(ij);
        ij.idx = u;
        adj[v].push_back(ij);
    }
    lli c_, d_;
    for(lli i = 1; i<=n; i++){
        cin>>c_>>d_;
        v[i].c = c_;
        v[i].d = d_;
    }
    lli Smax = Amax*(n-1);
    s = min(s,Smax);
    for(lli i = 1; i<=n; i++){
        for(lli j = 0; j<=Smax; j++){
            tuple <lli,lli,lli> temp;
            temp = make_tuple(INF,i,j);
            dist[i][j] = INF;
            pq.insert(temp);
        }
    }
    //cout<<"Smax = "<<Smax<<endl;
    tuple <lli,lli,lli> temp;
    temp = make_tuple(0,1,s);
    dist[1][s] = 0;
    pq.insert(temp);
    lli x,y,z;
    lli endpoint;
    lli counter = 0;
    for(auto i = pq.begin(); i!= pq.end(); i++){
        temp = *(i);
        tie(x,y,z) = temp;
       /* if(counter > 2000)
            break;*/
        for(auto j = adj[y].begin(); j != adj[y].end(); j++){
            endpoint = (*j).idx;
            if(z >= (*j).a && dist[endpoint][z-(*j).a] > x+(*j).b){
                pq.insert({x+(*j).b, endpoint, z-(*j).a});
                dist[endpoint][z-(*j).a] = x+(*j).b;
                counter++;
            }
        }
        if(z < Smax & dist[y][z+v[y].c] > x+v[y].d){
           // cout<<"Hellohello: "<<x+v[y].d<<" "<<y<<" "<<z+v[y].c<<endl;
            pq.insert({x + v[y].d, y, z + v[y].c});
            dist[y][z+v[y].c] = x + v[y].d;
            counter++;
        }
        
    }
   // cout<<counter<<endl;
    /*for(auto i = pq.begin(); i != pq.end(); i++){
        tie(x,y,z) = (*i);
        cout<<x<<" "<<y<<" "<<z<<endl;
    }*/
   // cout<<pq.size()<<endl;
   vector <lli> ans(55,LONG_LONG_MAX);
    for(lli i = 0; i<=Smax; i++){
        for(lli j = 1; j<=n; j++){
            ans[j] = min(ans[j], dist[j][i]);
        }
    }
    for(lli i = 2; i<=n; i++){
        cout<<ans[i]<<endl;
    }
}
    

Measured memory_bytes: 23444
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<double, double, double> T;

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int n, m; cin>>n>>m;
    vector<double> l(n), a(n), b(n);
    for(int i=0; i<n; i++) cin>>l[i]>>a[i]>>b[i];

    double ans=0.0;
    for(int bit=0; bit<(1<<n); bit++){
        if(__builtin_popcount(bit)!=m) continue;

        vector<T> v;
        for(int i=0; i<n; i++){
            if(bit & (1<<i)) v.eb(T(l[i], a[i], b[i]));
        }

        double sum=0.0;
        for(int i=0; i<v.size(); i++){
            double l1, a1, b1;
            tie(l1, a1, b1)=v[i];
            for(int j=i+1; j<v.size(); j++){
                double l2, a2, b2;
                tie(l2, a2, b2)=v[j];
                sum+=(l2-l1)*(l2-l1)+(a2-a1)*(a2-a1)+(b2-b1)*(b2-b1);
            }
        }
        
        chmax(ans, sum);
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 3296
a,b,c,d,e,k = [int(input()) for _ in range(6)]
a1 = [a,b,c,d,e]

import itertools as it
x1 = list(it.combinations(range(5), 2))

ans = "Yay!"
for i,j in x1:
    if abs(a1[i] - a1[j]) > k:
        ans = ":("

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;


void array_show(int *a,int n){
	for(int i=0;i<n;i++)printf("%d%c",a[i],(i!=n-1?' ':'\n'));
}
void array_show(LL *a,int n){
	for(int i=0;i<n;i++)printf("%lld%c",a[i],(i!=n-1?' ':'\n'));
}

LL dp[3005][3005];
LL t[3005];

int main(){
	int n;
	int i,j,k;
	LL a,b,c;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t[i];
		dp[i][0]=t[i];
	}
	for(j=1;j<=n;j++){
		for(i=0;i<n;i++){
			if(i+j>=n)break;
			else dp[i][j]=max(t[i]-dp[i+1][j-1],t[i+j]-dp[i][j-1]);
		}
	}
	cout<<dp[0][n-1]<<endl;
	return 0;
}


Measured memory_bytes: 70016
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll M = 1000000007;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for (ll i = k; i <= n + 1; i++) { 
        ans = (ans + (n + 1 - i) * i + 1) % M;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int e, m, a, x;
	double c, d;
	while (true) {
		cin >> e;
		if (e == 0) break;
		m = 90000000;

		c = pow(e, 1.0 / 3.0);
		d = sqrt(e);
		for (int z = 0; z <= c + 100; z++) {
			for (int y = 0; y <= d; y++) {	
				x = e - y*y - z*z*z;
				if (x < 0) break;
				else {
					a = x + y + z;
					if (a < m) m = a;
				}
			}
		}

		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

ll mod(ll n, ll m){
	return ((n%m)+m)%m;
}

int main(void){
	ll n, x, d;
	cin >> n >> x >> d;
	if(d < 0){
		d = -d;
		x = -x;
	}

	if(!d){
		if(!x) co(1);
		else co(n+1);
		return 0;
	}

	map<ll, VecP> range;
	rep(i, n+1){
		ll p = i*x/d;
		ll r = mod(i*x, d);
		ll b = p+i*(0+i-1)/2;
		ll e = p+i*(n-1+n-i)/2;
		range[r].pb(mp(b, e));
	}

	ll ans = 0;
	for(auto itr : range){
		VecP &v = itr.sc;
		sort(all(v));
		ll e = -LINF;
		for(P r : v){
			if(r.fs > e) ans += r.sc-r.fs+1;
			else ans += max(0LL, r.sc-e);
			chmax(e, r.sc);
		}
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 24192
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;


int main() {
    ll X,Y;
    cin>>X>>Y;
    vel A;
    A.pub(X);
    for(ll i=0;1;i++){
        A.pub(2*A[i]);
        if(A[i+1]>Y){break;}
    }
    cout<<A.size()-1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
    	int sx, sy, tx, ty;
    	cin >> sx >> sy >> tx >> ty;
    	int dx = tx - sx;
    	int dy = ty - sy;
     
    	for (int i = 0; i < dy; i++) cout <<'U';
    	for (int i = 0; i < dx; i++) cout <<'R';
     
    	for (int i = 0; i < dy; i++) cout << 'D';
    	for (int i = 0; i < dx; i++) cout << 'L';
     
    	cout << 'L';
    	for (int i = 0; i < dy; i++) cout << 'U';
    	cout << 'U';
    	for (int i = 0; i < dx; i++) cout << 'R';
    	cout << 'R';
    	cout << 'D';
     	cout << 'R';
    	for (int i = 0; i < dy; i++) cout << 'D';
    	cout << 'D';
    	for (int i = 0; i < dx; i++) cout << 'L';
    	cout << 'L';
    	cout <<'U';
    }

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    string A, B;
  cin >> A >> B;
 
  if(A.size() > B.size()){
    cout << "GREATER" << endl;
  }else if(A.size() < B.size()){
    cout << "LESS" << endl;
  }else{
    for(int i = 0; i < A.size(); i++){
      if(A[i] > B[i]){
        cout << "GREATER" << endl;
        exit(0);
      }else if(A[i] < B[i]){
        cout << "LESS" << endl;
        exit(0);
      }
    }
  cout << "EQUAL" << endl;
  }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  cin >> n;
  vll a(n);
  deque<ll> dq;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    dq.push_back(a[i]);
  }
  ll l = 0, r = 0;
  while (!dq.empty()) {
    if (l <= r) {
      l += dq.front();
      dq.pop_front();
    }
    else {
      r += dq.back();
      dq.pop_back();
    }
  }
  cout << abs(l - r) << endl;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, w;
	cin >> n >> w;
	ll weight[n], price[n];
	for (ll i = 0; i < n; i++)
		cin >> weight[i] >> price[i];
	ll maxN = 1000 * n;
	ll dp[n + 1][maxN + 1];
	for (ll i = 0; i <= maxN; i++)
		dp[0][i] = 2e9;
	dp[0][0] = 0;
	// dp[1][price[0]] = weight[0];
	for (ll i = 1; i <= n; i++)
		for (ll j = 1; j <= maxN; j++) {
			dp[i][j] = dp[i - 1][j];
			if (price[i - 1] <= j)
				dp[i][j] = min(dp[i][j] , weight[i - 1] + dp[i - 1][j - price[i - 1]]);
		}
	ll ans = 0;
	for (ll i = 0; i <= maxN; i++)
		if (dp[n][i] <= w)
			ans = i;
	cout << ans;
	return 0;
}

Measured memory_bytes: 82552
using System;

namespace ITP1_5_D
{
	class Program
	{
		static void Main(string[] args)
		{
			call(int.Parse(Console.ReadLine()));
		}

		static void call(int n)
		{
			int i = 1;

			do {
				int x = i;

				if(x % 3 != 0) {
					do {
						if(x % 10 == 3) {
							Console.Write($" {i}");
							break;
						}

						x /= 10;
					}
					while(x != 0);
				}
				else {
					Console.Write($" {i}");
				}
			}
			while(++i <= n);

			Console.WriteLine();
		}
	}
}



Measured memory_bytes: 19888
//18
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int p[65000];
    int j[65000];
    unsigned s=0;
    for(int i=0;i<n;i++){
      cin>>p[i];
      s+=p[i];
    }
    for(int i=0;i<n-1;i++){
      cin>>j[i];
    }
    sort(j,j+n,greater<int>());
    unsigned m=s*n;
    for(int i=0;i<n;i++){
      s+=j[i];
      m=max(m,s*(n-1-i));
    }
    cout<<m<<endl;
  }
  return 0;
}

Measured memory_bytes: 1676
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main(){
    string s;
    while(getline(cin,s)){
        stack<char> st;
        bool flag=true;
        if(s==".")break;

        for(int i=0;i<s.size();i++){
            char ch=s[i];
            
            if(ch=='('||ch=='['){
                st.push(ch);
            }else if(ch==')'||ch==']'){
                if(st.empty()){
                    flag=false;
                    break;
                }else if(ch==')'&&st.top()=='('){
                    st.pop();
                }else if(ch==']'&&st.top()=='['){
                    st.pop();
                }else{
                    flag=false;
                    break;
                }
            }


        }

        if(flag&&st.empty()){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
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; }
//-------------------
int n;
const int MX = 105;
int d[MX];

int main(){
    cin >> n;
    FOR(i,0,n-1) cin >> d[i];
    sort(d, d+n);
    int i = 0; int ans = 0;
    while(i < n){
        ans += 1;
        int cur = d[i];
        while(d[i] == cur && i < n){
            i++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
# https://abc076.contest.atcoder.jp/tasks/abc076_c

S = input()
T = input()

s_rev = "".join(reversed(S))
t_rev = "".join(reversed(T))

found = False
for i in range(len(S) - len(T) + 1):
    yn = all(s_rev[i + k] == "?" or s_rev[i + k] == t_rev[k] for k in range(len(T)))
    if yn:
        s_rev = s_rev[:i] + t_rev + s_rev[i + len(T) :]
        found = True
        break

if found:
    s = "".join("a" if c == "?" else c for c in reversed(s_rev))
    print(s)
else:
    print("UNRESTORABLE")


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x) do{rep(__i,(x).size()) pri(x,__i);}while(0)
#define pran(x,n) do{rep(__i,n) pri(x,__i);}while(0)
#define pral(x) do{cerr << (#x) << " =";rep(__i,(x).size()) cerr<<" "<<(x[__i]);cerr<<endl;}while(0)
#define prar(x,b,e) do{repr(__i,b,e) pri(x,__i);}while(0)

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

ll MOD = 1000000007;

function<void(int,int)> tensi_no_3p=[&](int v,int d){
};

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int N; cin >> N;
	typedef vector<ll> vll;
	vll A(N);
	rep(i, N) cin >> A[i];
	vll dp(N + 10), next(N + 10);
	ll INFLL = (ll) INF * INF;
	rep(i, N + 10) dp[i] = -INFLL, next[i] = -1;
	function<ll(int)> solve=[&](int v){
		if (dp[v] > -INFLL) return dp[v];
		ll maxans = 0;
		for (int i = 2; v + i < N; i += 2) {
			ll ret = solve(v + i);
			if (ret > maxans) {
				maxans = ret;
				next[v] = v + i;
			}
		}
		return dp[v] = A[v] + maxans;
	};
	ll ans = -INFLL, root = -1;
	rep(i, N) {
		ll ret = solve(i);
		if (ret > ans) {
			ans = ret;
			root = i;
		}
	}
	pr(ans);
	pr(root);
	
	vint good;
	good.pb(root);
	for (int i = root; i = next[i], i >= 0; good.pb(i));
	pra(good);
	
	vint ope;
	for (int i = N - 1; i > good[good.size() - 1]; i--) ope.pb(i);
	while (good.size() > 1) {
		int tail = good[good.size() - 1];
		int tail2 = good[good.size() - 2];
		while (tail - tail2 > 2) {
			ope.pb(tail - 2);
			tail -= 2;
		}
		ope.pb(tail - 1);
		good.pop_back();
	}
	rep(i, good[0]) ope.pb(0);
	
	cout << ans << endl;
	cout << ope.size() << endl;
	rep(i, ope.size()) {
		cout << ope[i] + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
typedef long long int ll;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string a;
  cin>>a;
  if(a=="SUN")
     cout<<7<<"\n";
  else if(a=="MON")
     cout<<6<<"\n";
  else if(a=="TUE")
     cout<<5<<"\n";
  else if(a=="WED")
     cout<<4<<"\n";
  else if(a=="THU")
     cout<<3<<"\n";
  else if(a=="FRI")
     cout<<2<<"\n";
  else if(a=="SAT")
     cout<<1<<"\n";
  else
    ;
  return 0;
} 

Measured memory_bytes: 3184
#include <iostream>
#include <string>
#include <list>

using namespace std;

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

    string str;
    list<int> l;
    list<int>::iterator x;
    int n, num;

    cin >> n;

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

        if (str == "insert") {
            cin >> num;
            l.push_front(num);
        }
        if (str == "delete") {
            cin >> num;
            for (x = l.begin(); x != l.end(); x++) {
                if (*x == num) {
                    l.erase(x);
                    break;
                }
            }
            
        }
        if (str == "deleteFirst") {
            l.pop_front();
        }
        if (str == "deleteLast") {
            l.pop_back();
        }
    }

    int cnt = 0;

    for (x = l.begin(); x != --l.end(); x++) {
        cout << *x << " ";
    }
    cout << *x << endl;
}



Measured memory_bytes: 34484
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int N,cnt=0;
  string A,B,C;
  cin>>N>>A>>B>>C;
  for(int i=0;i<N;i++){
    if(A[i]==B[i]&&B[i]==C[i]) continue;
    else if(A[i]==B[i]&&A[i]!=C[i]){
      C[i]==A[i];
      cnt++;
    }else if(A[i]==C[i]&&A[i]!=B[i]){
      B[i]==A[i];
      cnt++;
    }else if(B[i]==C[i]&&A[i]!=B[i]){
      A[i]==B[i];
      cnt++;
    }else if(A[i]!=B[i]&&A[i]!=C[i]){
      B[i]==A[i];
      C[i]==A[i];
      cnt+=2;
    }
  }
  cout<<cnt<<endl;
}	


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W,N,max,min,sum,c;
  cin >> H;
  cin >> W;
  cin >> N;
  if(W <= H){
	max = H;
    min = W;
  }else{
    max = W;
    min = H;
  }
  for(int i = 0; i < min; i++){
    if(sum < N){
      sum += max;
      c++;
    }else{
      break;
    }
  }
  cout << c << endl;
}
  

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int x=n%10;
  if(x==3){
    cout<<"bon\n";
  }
  else if(x==0 || x==1 ||x==6 ||x==8){
    cout<<"pon\n";
  }
  else if(x==2 || x==4 ||x==5 ||x==7 || x==9){
    cout<<"hon\n";
  }
  return 0;
}


Measured memory_bytes: 3592
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        float ans;
        int a = sc.nextInt();
        int b = sc.nextInt();
        int h = sc.nextInt();
        System.out.println(((a+b)*h)/2);
    }
}


Measured memory_bytes: 35508
N = int(input())
A = [list(map(int, input().split())) for i in range(2)]
max = A[0][0] + sum(A[1])
x = max
for i in range(N - 1):
  x = x - A[1][i] + A[0][i + 1]
  if x > max:
    max = x
print(max)

Measured memory_bytes: 3060
#B問題
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
count=0
for i in range(N):
        A=list(map(int,input().split()))
        sum1=0
        for j in range(M):
              sum1+=A[j]*B[j]
        if sum1+C>0:
              count+=1
print(count)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
  int N;
  scanf("%d",&N);
  if(N%10==3){
    printf("bon");
  }else if(N%10==0 || N%10==1 || N%10==6 || N%10==8){
    printf("pon");
  }else{
    printf("hon");
  }
}

Measured memory_bytes: 1732
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
C = list(map(int, sys.stdin.buffer.readline().split()))
C.sort(reverse=True)

assert pow(2, MOD - 2, MOD) == 500000004


def div2(a):
    return a % MOD * 500000004 % MOD


pow2 = [1]
for _ in range(N):
    pow2.append(pow2[-1] * 2 % MOD)


# (1+x)^k = kC0 * x^0 + kC1 * x^1 + kC2 * x^2 + ... + kCk * x^k
# (1+x)^k * x = kC0 * x^1 + kC1 * x^2 + kC2 * x^3 + ... + kCk * x^(k+1)
# 微分して x=1 を代入すると、上から1番目からk番目になる通り数 * D の総和になる
# kC0 * 1 + kC1 * 2 + kC2 * 3 + ... + kCk * (k+1)
def df(k):
    # a(x) = (1+x)^k * x として、a'(1) を返す。
    # https://mathtrain.jp/composite
    # http://w3e.kanazawa-it.ac.jp/math/category/bibun/keisan/diff-gh.html
    # f(x) = 1+x
    # g(x) = x^k
    # h(x) = x
    # g(f(x)) * h(x) = (1+x)^k * x
    # f'(x) = 1
    # g'(x) = kx^(k-1)
    # h'(x) = 1
    # g'(f(x)) = g'(f(x)) * f'(x) = k(1+x)^(k-1)
    # (g(f(x)) * h(x))' = g'(f(x)) * h(x) + g(f(x)) * h'(x)
    #                   = k(1+x)^(k-1) + (1+x)^k
    # (g(f(1)) * h(1))' = k * 2^(k-1) + 2^k
    #                   = k * 2^k / 2 + 2^k
    #                   = (k + 2) / 2 * 2^k
    return div2((k + 2) * pow2[k])


ans = 0
for k in range(N):
    # k までの選び方 * 上から何番目か * C[k] * k より後ろの選び方
    ans += df(k) * C[k] * pow2[N - k - 1]
    ans %= MOD
print(ans * pow2[N] % MOD)


Measured memory_bytes: 23316
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int n, m;

  cin >> n >> m;

  priority_queue<int> q;
  int a;
  for (int i = 0; i < n; i++){
    cin >> a;
    q.push(a);
  }


  for (int i = 0; i < m; i++){
    a = q.top();
    q.pop();
    q.push(a/2);
  }

  ll sum = 0;
  while (!q.empty()){
    sum += q.top();
    q.pop();
  }


  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 892