akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass
{
	static void Main(string[] args)
	{
		Answer();
	}
	public static void Answer()
	{
	  var N = int.Parse(Console.ReadLine());
      var val = N;
      if (val % 2 != 0) { val *= 2;}
      WriteLine(val);
	}
  
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13140
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] a = new int[N];
   for(int i=0;i<N;i++) a[i] = sc.nextInt();
   int ans =0;
   int count = 0;
   for(int i =0;i<N;i++)
   {
     if(a[i]==i+1)
     {
       count++;
     }
     else
     {
       if(count%2==0) ans += count/2;
       else ans += count/2 +1;
       count=0;
     }
   }
   if(count%2==0) ans += count/2;
   else ans += count/2 +1;
   System.out.println(ans);
 }
}

Measured memory_bytes: 52232
def main(a):
  for i in range(4):
    for j in range(i+1, 5):
      if a[j] - a[i] > k:
        print(":(")
        return 
  else :
    print("Yay!")
    return

a = []
for i in range(5):
  a.append(int(input()))
  
k = int(input())
main(a)


Measured memory_bytes: 2940
def main():
    n, x = map(int, input().split())
    l = [int(s) for s in input().split()]

    print(solve(x, l))
    
def solve(x, l):
    pos = 0
    c = 0
    if x >= 0:
        c += 1
    
    for li in l:
        pos += li
        if pos <= x:
            c += 1

    return c

main()


Measured memory_bytes: 3060
from collections import defaultdict

N = int(input())
S = [input() for _ in range(N)]

cnt = defaultdict(int)
for s in S:
    cnt[s] += 1

cnt = list(cnt.items())
cnt.sort(key = lambda x: x[0])
cnt.sort(key = lambda x: -x[1])

tmp = cnt[0][1]
for c in cnt:
    if tmp == c[1]:
        print(c[0])

Measured memory_bytes: 43496
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define re(i , n) for(Long i = 0; i < (Long)n ; i++)
#define rer(i, a, b) for (Long i = a, to = b; i < to; i++)
 
using namespace std;
typedef long long Long;
const Long MX=2e5 + 1;
const Long MOD=1000000007;
const Long MX2=9223372036854775806;


int main(){
	ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	string s;cin>>s;
	if(s[1]=='R'){
		cout<<"ABC";
	}else{
		cout<<"ARC";
	}
	
}

Measured memory_bytes: 3616
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;

	public static void main(String[] args) {
		String S=sc.next();
		long K=sc.nextLong();
		int ans=1;
		for(int i=0;i<Math.min(S.length(), K);i++) {
			if(S.charAt(i)>49) {
				ans=S.charAt(i)-48;
				break;
			}
		}
		p(ans);
	}
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

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

    sort(a.begin(), a.end());

    for(int i = 0; i < 3; i++){
        cout << a[9 - i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3144
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int n,a,b ;
	cin >> n >> a >> b ;
	cout << min(a,b) << " " << max(a+b-n,0) << endl ;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){
    // Your code here!
    int n,i,R;
    cin>>n;
    int maxv,minv;
    maxv = -1000000000;
    cin>>R;
    minv=R;
    
    for(i=1; i<n; i++){
        cin>>R;
        maxv=max(maxv,R-minv);
        minv=min(minv,R);
    }
    printf("%d\n", maxv);
    return 0;
}



Measured memory_bytes: 3224
#include<cstdio>
#include<iostream>
#include<algorithm>

#define MAX 1000001

using namespace std;

int main(){
	
	char sosu[MAX]={0};
	sosu[0]=1;
	sosu[1]=1;
	for(int i=2;i<MAX;i++){
		if(sosu[i]==0){
			for(int j=i+i;j<MAX;j+=i){
				sosu[j]=1;
			}
		}
	}
	while(1){
		int n,m;
		scanf("%d%d",&n,&m);
		if(n==0 && m==0){
			break;
		}
		int item[30];
		for(int i=0;i<n;i++){
			scanf("%d",&item[i]);
		}
		bool dp[MAX]={0};
		for(int i=0;i<MAX;i++){
			dp[i]=0;
		}
		dp[0]=1;
		for(int i=0;i<=m;i++){
			for(int j=0;j<n;j++){
				if(item[j]<=i){
					if(dp[i-item[j]]==1){
						dp[i]=1;
						break;
					}
				}
			}
		}
		
		
		for(int i=m;;i--){
			if(i==0){
				printf("NA\n");
				break;
			}
			if(dp[i]==1 && sosu[i]==0){
				printf("%d\n",i);
				break;
			}
		}
	}
}

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

int main(){
	int k;
  	cin>>k;
  	long long int sum=0;
  	int n1, n2;
  	int t;
  	for(int i=1;i<=k;i++){
    	for(int j=1;j<=k;j++){
          	n1=i; n2=j;
          	if(n1<n2){
            	t=n1;
              	n1=n2;
              	n2=t;
            }
          	t=n1%n2;
          	while(t!=0){
            	n1=n2;
              	n2=t;
              	t=n1%n2;
            }
          	int g1=n2;
        	for(int l=1;l<=k;l++){
            	n1=g1; n2=l;
              	if(n1<n2){
                    t=n1;
                    n1=n2;
                    n2=t;
                }
                t=n1%n2;
                while(t!=0){
                    n1=n2;
                    n2=t;
                    t=n1%n2;
                }
                sum+=n2;
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define X first
#define Y second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod=1e9+7;
const ll MAXN=5e5+5;
const ll inf=1e18;



int main()
{
    fastio;
    ll a,b,num1=0,num2=0;
    cin>>a>>b;
    for(int i=0;i<b;i++) num1=num1*10+a;
    for(int i=0;i<a;i++) num2=num2*10+b;
    if(a<b) cout<<num1<<endl;
    else cout<<num2<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  int v[n];
  int c[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &c[i]);
  }

  int max = 0;
  int dif;
  for (int i = 0; i < n; i++) {
    dif = v[i] - c[i];
    if (dif > 0) {
      max += dif;
    }
  }
  printf("%d\n", max);

  return 0;
}

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

#define log(x) cout << (x) << endl
#define par(x) ((x)&1)

int main() {
	int a,b,c,m;
	cin>>a>>b>>c;
	m = max(a,max(b,c));

	if (par(3*m) == par(a+b+c)) {
		log((3*m - (a+b+c))>>1);
	} else {
		log((3*(m+1) - (a+b+c))>>1);
	}
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <vector>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef double f2;
typedef long double f3;
#define N 200050
#define mod 1000000007
inline void upd(ll &x,ll y) {x+=y;if(x>=mod)x-=mod;}
int n,c[N],b[N];
ll f[N],g[N],tmp[N];
int main() {
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++) scanf("%d",&c[i]);
	int ln=0;
	for(i=1;i<=n;i++) if(c[i]!=c[i-1]) b[++ln]=c[i];
	n=ln;
	for(i=1;i<=n;i++) c[i]=b[i];
	f[0]=1;
	for(i=1;i<=n;i++) {
		g[i]=f[i]=f[i-1];
		upd(f[i],tmp[c[i]]);
		// for(j=1;j<i;j++) if(c[i]==c[j]) {
		// 	upd(f[i],g[j]);
		// }
		upd(tmp[c[i]],g[i]);
	}
	printf("%lld\n",f[n]);
}


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

int main(){
    int N, ans;
    cin >> N;
    ans = N%10;
    if(ans == 3){
        cout << "bon" << endl;
    } else if(ans == 0 || ans == 1 || ans == 6 || ans == 8){
        cout << "pon" << endl;
    } else{
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3584
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int a, b;

int main() {
  cin >> a >> b;
  if (a+b == 15) cout << '+' << endl;
  else if (a*b == 15) cout << '*' << endl;
  else cout << 'x' << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// Code for B - Can you solve this?
	var N, M, C int
	fmt.Scanf("%d %d %d", &N, &M, &C)

	B := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scanf("%d", &B[i])
	}

	var A, sum, answer int
	for j := 0; j < N; j++ {
		sum = 0
		for i := 0; i < M; i++ {
			fmt.Scanf("%d", &A)
			sum += A * B[i]
		}
		sum += C
		if sum > 0 {
			answer++
		}
	}
	fmt.Println(answer)
}


Measured memory_bytes: 1856
#include<iostream>
using namespace std;
int main() {
int x,y;
cin >> x >> y;
int l,r,t,b;
l = b = 0;
r = t = 1;
bool f = true;
int i;
for(i=0;f;i++) {
if(l<=x&&x<r&&b<=y&&y<t)f = false;
if(i%4==0)r+=t-b;
else if(i%4==1)t+=r-l;
else if(i%4==2)l+=b-t;
else b+=l-r;
}
cout << (i-1)%3+1 << endl;
}


Measured memory_bytes: 3104
//
// ~oisín~ C++ Template
//

#include                <bits/stdc++.h>
#define MX_N            5001
#define mp              make_pair
#define mod7            1000000007
#define modpi           314159
#define PI              3.141592653589793238
#define pb              push_back
#define FastIO          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define All(a)          a.begin(),a.end()
#define fi              first
#define se              second
#define ll              long long int
#define ull             unsigned long long int

int kx[8]  =            {+2, +2, -2, -2, +1, +1, -1, -1};
int ky[8]  =            {+1, -1, +1, -1, +2, -2, +2, -2};
int d9x[9] =            {+1, +1, +1, +0, +0, +0, -1, -1, -1};
int d9y[9] =            {+1, +0, -1, +1, +0, -1, +1, +0, -1};
int dx4[4] =            {+0, +0, +1, -1};
int dy4[4] =            {+1, -1, +0, +0};

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

ll lcm(ull a, ull b){
    return a*(b/gcd(a,b));
}

const long long INF = 1e18;

using namespace std;

int main(){
    long long A;
    cin >> A;
    string s;
    cin >> s;
    s.erase(s.size()-3, 1);
    stringstream ss;
    ss << s;
    long long B;
    ss >> B;
    long long ans = A * B;
    ans /= 100;
    cout << ans << endl;
}


Measured memory_bytes: 3644
from collections import defaultdict
march = "MARCH"
n = int(input())
dic = defaultdict(int)
for i in range(n):
    s = input()
    for j in range(5):
        if s[0] == march[j]:
            dic[march[j]] += 1
            break
        

ans = 0
for i in range(5):
    if dic[march[i]] >= 1:
        for j in range(i + 1, 5):
            if dic[march[j]] >= 1:
                for k in range(j + 1, 5):
                    if dic[march[k]] >= 1:
                        ans += dic[march[i]] * dic[march[j]] * dic[march[k]]


print(ans)

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

int main() {
	string str;
	cin >> str;
	long ans = 0;
	for (int i = 0; i < (1 << (str.size() - 1)); i++) {
		string tmp;
		tmp += str[0];
		for (int j = 0; j < str.size() - 1; j++) {
			if (i & (1 << j)) {
				ans += stol(tmp);
				tmp = str[j + 1];
			}
			else {
				tmp += str[j + 1];
			}
		}
		ans += stol(tmp);
	}
	cout << ans << endl;			
}


Measured memory_bytes: 256
A, B, N = [int(i) for i in input().split()]
ans = 0
if N < B:
    ans = int(( A * (N % B) - (A * N) % B) / B)
else:
    tmp_ = int(( A * (N % B) - (A * N) % B) / B)
    x = (N - N % B - 1)
    tmp = int(( A * (x % B) - (A * x) % B) / B)
    ans = max(tmp, tmp_)
print(ans)

Measured memory_bytes: 61868
H, W = map(int, input().split())
S = [[""]]*H
for i in range(H):
  S[i] = input()

dh = [-1,-1,-1,0,0,1,1,1]
dw = [-1,0,1,-1,1,-1,0,1]

for i in range(H):
  for j in range(W):
    count=0
    if S[i][j]==".":
      for l in range(8):
        if H>i+dh[l]>-1 and W>j+dw[l]>-1:
          if S[i+dh[l]][j+dw[l]]=="#":
            count+=1
      S[i]=S[i][:j] + str(count) + S[i][j+1:]

for i in range(H):
  print(S[i])

Measured memory_bytes: 3064
#include<stdio.h>
int n;
double count[305][305][305];
double ways(int p,int q,int r)
{
    if(p == -1 || q == -1 || r == -1)
        return 0;
    else if(p == 1 && q == 0 && r == 0)
        count[p][q][r] = n;
    else if(p == 0 && q == 1 && r == 0)
        count[p][q][r] = 2*n;
    else if(p == 0 && q == 0 && r == 1)
        count[p][q][r] = 3*n;
    else if(count[p][q][r] == -1)
        count[p][q][r] = (n+q*ways(p+1,q-1,r)+p*ways(p-1,q,r)+r*ways(p,q+1,r-1))/(p+q+r);
    return count[p][q][r];
}

int main()
{
    int x=0,y=0,z=0;
    scanf("%d",&n);
    int store[n];
    for(int i=0;i<n;i++) {
        scanf("%d", &store[i]);
        if(store[i]==1)
            x++;
        if(store[i]==2)
            y++;
        if(store[i]==3)
            z++;
    }
    for(int i=0;i<=300;i++)
        for(int j=0;j<=300;j++)
            for(int k=0;k<=300;k++)
                count[i][j][k]=-1;
    printf("%.10f\n",ways(x,y,z));
}

Measured memory_bytes: 219392
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int cmp(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a > b ? -1 : a < b;
}

int N, K;
int H[271828];

int main(void) {
	int i;
	int64_t answer = 0;
	if (scanf("%d%d", &N, &K) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &H[i]) != 1) return 1;
	}
	qsort(H, N, sizeof(*H), cmp);
	for (i = K; i < N; i++) {
		answer += H[i];
	}
	printf("%" PRId64 "\n", answer);
	return 0;
}


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

#define sl(x) scanf("%ld", &x)
#define ss(x) scanf("%s", x)
#define pl(x) printf("%ld\n", x)

#define INF 100000000000
#define M 1000000007

#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

int main() {
	long i, j;
	long N;
	long p[20001];
	long a[20001];
	long b[20001];
	long step = 40000;
	
	sl(N);
	for(i=1;i<=N;i++) {
		sl(p[i]);
		b[N-i+1] = a[i] = i * step;
	}
	
	step = N;
	for(i=1;i<=N;i++) {
		a[p[i]] -= step;
		step--;
	}
	
	for(i=1;i<N;i++) {
		printf("%ld ", a[i]);
	}
	printf("%ld\n", a[i]);
	
	for(i=1;i<N;i++) {
		printf("%ld ", b[i]);
	}
	printf("%ld\n", b[i]);
	
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<array>
#include<cstdlib>
#include<ctime>
#include<climits>
using namespace std;

int f(int n){
	if(n % 2 == 0){
		return n / 2;
	}
	else{
		return 3 * n + 1;
	}
}

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

	//int a[1000000];
	//vector<int> a;
	vector<int> a(1000000);
	a[0] = s;
	int ans = 0;
	for(int i = 1;; i++){
		a[i] = f(a[i - 1]);

		for(int j = i - 1; j >= 0; j--){
			if(a[i] == a[j]){
				ans = i + 1;
				goto Exit;//
			}
		}
	}

Exit://
	cout << ans << endl;
}

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

#include <atcoder/all>
using namespace atcoder;

using namespace std;
using ll = long long;

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

    dsu d(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        d.merge(a - 1, b - 1);
    }
    vector<vector<int>> g = d.groups();
    cout << g.size() - 1 << endl;

    return 0;
}


Measured memory_bytes: 9016
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_V = 1000;
const int LIMIT = 999999;

int d[MAX_V][MAX_V]; // コスト i==jのとき0, それ以外INF
int n, m; // 町, 街道

void warshall_floyd() {
  for(int k=0; k<m; k++)
    for(int i=0; i<m; i++)
      for(int j=0; j<m; j++)
	d[i][j]=min(d[i][j], d[i][k]+d[k][j]); // i-jの最短経路
}

int main() {
  int a, b;
  int start, hashira, givenMoney, cost;
  int ans;

  for(int i=0; i<MAX_V; i++) {
    for(int j=0; j<MAX_V; j++) {
      d[i][j]=LIMIT;
    }
  }

  cin>>n;
  cin>>m;
  for(int i=0; i<m; i++) {
    cin>>a;
    cin.ignore();
    cin>>b;
    cin.ignore();
    cin>>d[a][b];
    cin.ignore();
    cin>>d[b][a];
  }
  cin>>start;
  cin.ignore();
  cin>>hashira;
  cin.ignore();
  cin>>givenMoney;
  cin.ignore();
  cin>>cost;

  warshall_floyd();

  ans = givenMoney - cost - (d[start][hashira] + d[hashira][start]);
  cout<<ans<<endl;
}

Measured memory_bytes: 5068
n, a, b = map(int, input().split())
if abs(a-b)%2==0:
  print(abs(a-b)//2)
else:
  m = min(a,b)
  M = max(a,b)
  if M - m == 1:
    if m-1 < n-M:
      print((M-1))
    else:
      print((n-m))
  else:
    if m-1 < n-M:
      print((m-1)+1+(M-m-1)//2)
    else:
      print((n-M)+1+(M-m-1)//2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m,r,s,p;
  string t;
  cin >> n >> m >> r >> s >> p >> t;
  vector<char> v[m];
  rep(i,n) v[i%m].pb(t[i]);
  ll ans=0;
  rep(k,m) {
    ll dp[v[k].size()+1][3];
    rep(i,v[k].size()+1)rep(j,3)dp[i][j]=-MAX;
    rep(i,3) dp[0][i]=0;
    rep(i,v[k].size()) {
      rep(j,3) {
        if(v[k][i]=='s') {
          dp[i+1][0]=max(dp[i+1][0],dp[i][1]+r);
          dp[i+1][0]=max(dp[i+1][0],dp[i][2]+r);
          dp[i+1][1]=max(dp[i+1][1],dp[i][0]);
          dp[i+1][2]=max(dp[i+1][2],dp[i][0]);
        } else if(v[k][i]=='p') {
          dp[i+1][1]=max(dp[i+1][1],dp[i][0]+s);
          dp[i+1][1]=max(dp[i+1][1],dp[i][2]+s);
          dp[i+1][0]=max(dp[i+1][0],dp[i][1]);
          dp[i+1][2]=max(dp[i+1][2],dp[i][1]);
        } else {
          dp[i+1][2]=max(dp[i+1][2],dp[i][0]+p);
          dp[i+1][2]=max(dp[i+1][2],dp[i][1]+p);
          dp[i+1][0]=max(dp[i+1][0],dp[i][2]);
          dp[i+1][1]=max(dp[i+1][1],dp[i][2]);
        }
      }
    }
    ans+=max({dp[v[k].size()][0],dp[v[k].size()][1],dp[v[k].size()][2]});
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int main() {
    lld H1,H2,M1,M2;
    lld K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    lld minute = ((H2 - (H1+1)) * 60) + (60-M1) + M2;
    cout << max(0LL, minute - K) << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define INF 1e10
using namespace std;
const int maxn = 1e5+10;
int n,m,a[maxn],b[maxn];
int32_t main(){
    IOS;
    cin>>n;
    int ans=0;
    int one=0,two=0;
    int tt=0,t=0;
    fu(i,1,n)
    {
        string k;
        cin>>k;
        int len=k.length();
        if(len>=2)
            fd(i,len-1,1)if(k[i]=='B' && k[i-1]=='A')ans++;
        if(k[len - 1] == 'A' && k[0] == 'B') {
            tt++;
            continue;
        }
        if (k[len - 1] == 'A')one++;
        if (k[0] == 'B')two++;

    }
    if(tt) {
        if (one) {
            ans++;
            one--;
        }
        if (two) {
            ans++;
            two--;
        }
        cout<<ans+min(one,two)+tt-1;
    }else cout<<ans+min(one,two);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int n;
  cin>>n;
  queue<pii> q;
  rep(i,n-1)
    for(j=i+1;j<n;j++){
      string s="";
      rep(k,n)
        if(k!=i && k!=j)s+="0";
        else s+="1";
      cout<<"? "<<s<<endl;
      int d;
      cin>>d;
      if(d)q.push(pii(i,j));
    }

  cout<<"!";
  while(q.size()){
    cout<<" ("<<q.front().first<<","<<q.front().second<<")";
    q.pop();
  }
  cout<<endl;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  string S;
  cin >> S;

  rep(i,S.size()) cout << 'x';
  cout << endl;
}


Measured memory_bytes: 3588
#include<iostream>
#include<map>
#include<vector>
#include<string>
using namespace std;

map<string, vector<string> > mix;
map<string, int> prise;
map<string, int> min_prise;

int cal_min(string s)
{
  if(min_prise.find(s) != min_prise.end())
    return min_prise[s];
  if(mix.find(s) == mix.end())
    return prise[s];
  int p = 0;
  for(vector<string>::iterator i = mix[s].begin(); i != mix[s].end(); i++)
  {
    p += cal_min(*i);
    if(p >= prise[s])
    {
      min_prise.insert(pair<string, int>(s, prise[s]));
      return min_prise[s];
    }
  }
  min_prise.insert(pair<string, int>(s, p));
  return p;
}

int main()
{
  int n, m;
  while(1)
  {
    mix.clear();
    prise.clear();
    min_prise.clear();
    cin >> n;
    if(!n)
      break;
    for(int i = 0; i < n; i++)
    {
      string s;
      int p;
      cin >> s >> p;
      prise.insert(pair<string, int>(s, p));
    }
    cin >> m;

    for(int i = 0; i < m; i++)
    {
      string item;
      int d;
      vector<string> v;
      cin >> item >> d;
      for(int j = 0; j < d; j++)
      {
        string s;
        cin >> s;
        v.push_back(s);
      }
      mix.insert(pair<string, vector<string> >(item, v));
    }

    string str;
    cin >> str;
    cout << cal_min(str) << endl;
  }
}

Measured memory_bytes: 1236
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

inline int f(int y, int x){
  return 2 * y + y * (y + 1) / 2 + x;
}
int table[15000000];

int main(){
  int N, M;
  while(cin >> N >> M && N){
    REP(i, M){
      int Y, X, L; 
      scanf("%d %d %d", &Y, &X, &L);
      Y--; X--;
      table[f(Y, X)]++;
      table[f(Y, X + 1)]--;
      table[f(Y + L + 1, X)]--;
      table[f(Y + L + 1, X + L + 2)]++;
      table[f(Y + L + 2, X + 1)]++;
      table[f(Y + L + 2, X + L + 2)]--;
    }
    for(int y = 0; y < N + 2; y++){
      for(int x = 1; x <= y + 2; x++){
        table[f(y, x)] += table[f(y, x - 1)];
      }
    }
    for(int y = 1; y < N + 2; y++){
      for(int x = 0; x <= y + 1; x++){
        table[f(y, x)] += table[f(y - 1, x)];
      }
    }
    for(int y = 1; y < N + 2; y++){
      for(int x = 1; x <= y + 2; x++){
        table[f(y, x)] += table[f(y - 1, x - 1)];
      }
    }
    int ans = 0;
    for(int y = 0; y < N; y++){
      for(int x = 0; x <= y; x++){
        if(table[f(y, x)] > 0) ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 50388
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char s[10];
	scanf("%s",s+1);
	for (int i=1;i<=strlen(s)-1;i++)
	{
		if (s[i]=='A' && s[i+1]=='C')
		 {
		 	printf("Yes\n");
			return 0;
		 }
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
//#include <intrin.h>  //AtCpder (gcc) 上ではこれがあると動かない。__popcnt用のincludeファイル。
using namespace std;
using Graph = vector<vector<int>>;

typedef long long ll;
typedef long double ld;


#define int long long
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((long double) (d), 0.50)

const ll INF = 2e9;
const ll large_P = 1e9 + 7;



//繰り返し2乗法
//N^aの、Mで割った余りを求める。
//M = 1000000007 (1e9 + 7) など。
//M = 1000000009 (1e9 + 9) もある。
//M = 998244353 もある。

ll my_pow(ll N, ll a, ll M) {
	ll tempo;
	if (a == 0) {
		return 1;
	}
	else {
		if (a % 2 == 0) {
			tempo = my_pow(N, a / 2, M);
			return (tempo * tempo) % M;
		}
		else {
			tempo = my_pow(N, a - 1, M);
			return (tempo * N) % M;
		}
	}
}




signed main() {
	ll N; cin >> N;
	vector<ll> A(N);
	rep(i, N) cin >> A.at(i);

	sort(A.begin(), A.end(), greater<int>());
	vector<ll> amari(N, 0);


	ll res = 0LL;
	ll ones = 0LL;
	ll zeros = 0LL;

	ll M = ceil(log(A.front()) / log(2));
	rep(i, M) {
		//i桁目を検討。
		ones = 0;
		rep(j, N) {
			//if (A.at(j) & (1 << i)) ones++;
			if (A.at(j) % 2 == 1) {
				ones++;
				amari.at(j) = 1;
			}
			else {
				amari.at(j) = 0;
			}
			A.at(j) = (A.at(j) - amari.at(j)) / 2;
		}
		zeros = N - ones;

		ll temp1 = 1LL;
		temp1 *= zeros; temp1 %= large_P;
		temp1 *= ones; temp1 %= large_P;

		ll temp2 = my_pow(2, i, large_P);

		ll temp = temp1 * temp2 % large_P;
		if (zeros == 0LL || ones == 0LL) temp = 0LL;

		res += temp;
		//cout << zeros << " " << ones << " " << temp1 << " " << temp2 << endl;
		res %= large_P;
	}


	cout << res << endl;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] sArr = sc.next().toCharArray();

        int indexA = sArr.length;
        int indexZ = 0;
        for (int i = 0; i < sArr.length; i++) {
            switch (sArr[i]) {
                case 'A':
                    if (indexA > i) indexA = i;
                    break;
                case 'Z':
                    if (indexZ < i) indexZ = i;
                    break;
            }
        }


        System.out.println(indexZ - indexA + 1);

    }
}


Measured memory_bytes: 26576
package main

import (
	"bufio"
	"os"
	"strconv"
	"sort"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func main() {
	scanner.Split(bufio.ScanWords)
	nums := make([]int, 5)
	for i := 0; i < 5; i++ {
		nums[i] = nextInt()
	}
	sort.Sort(sort.Reverse(sort.IntSlice(nums)))
	for i, v := range nums {
		if i == len(nums)-1 {
			fmt.Printf("%d\n", v)
		} else {
			fmt.Printf("%d ", v)
		}
	}
}


Measured memory_bytes: 1144
L,R = map(int,input().split())
mod = 10**9+7
l = '{:060b}'.format(L)[::-1]
r = '{:060b}'.format(R)[::-1]

dp = [[[[-1 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(60)]

def f(n,a,b,c):
    if n==-1:
        return 1
    if dp[n][a][b][c]!=-1:
        return dp[n][a][b][c]
    res = 0
    if a or l[n]=='0':
        res += f(n-1,a,1 if r[n]=='1' else b,c)
    if (a or l[n]=='0') and (b or r[n]=='1') and c:
        res += f(n-1,a,b,c)
    if b or r[n]=='1':
        res += f(n-1,1 if l[n]=='0' else a,b,1)
    res %= mod
    dp[n][a][b][c] = res
    return res

ans = f(59,0,0,0)
print(ans)

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = Long.parseLong(sc.next());
        long deposit = 100;
        int yearCount = 0;
        
        while(deposit < x){
            deposit += Math.floor(deposit*0.01);
            yearCount++;
        }
        
        System.out.println(yearCount);
    }
}

Measured memory_bytes: 35656
a = input()
for bit in range(1<<3):
    ans1 = int(a[0])
    ans = []
    for i in range(3):
        mask = 1<<i
        if mask&bit:
            ans.append('+')
            ans1 += int(a[i+1])
        else:
            ans.append('-')
            ans1 -= int(a[i+1])
            
    if ans1==7:
        break
ans.append('=7')
d = []
for i in range(4):
    d.append(a[i])
    d.append(ans[i])
print(''.join(d))

Measured memory_bytes: 38484
# -*- coding: utf-8 -*-
n,x = map(int, input().split())

if x==1 or x==2*n-1:
    print("No")
    exit()
if n==2:
    print("Yes")
    print(1)
    print(2)
    print(3)
    exit()

ret = [0 for _ in range(2*n-1)]
if x!=2:
    ret[n-1-1] = x-1
    ret[n-1] = x
    ret[n+1-1] = x+1
    ret[n+2-1] = x-2
    d = [x-2,x-1,x,x+1]
else:
    ret[n-1-1] = x+1
    ret[n-1] = x
    ret[n+1-1] = x-1
    ret[n+2-1] = x+2
    d = [x-1,x,x+1,x+2]
i = 0
j = 1
while i<2*n-1:
    if ret[i]==0:
        while j in d:
            j += 1
        ret[i] = j
        j += 1
    i += 1
print("Yes")
for x in ret:
    print(x)


Measured memory_bytes: 12528
#include "iostream"
#include "string"

int main()
{
	int n, x;
	int val = 0;

	while (true) {
		std::cin >> n >> x;
		if ((n + x) == 0)
			break;

		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				for (int k = j + 1; k <= n; k++) {
					if ((i + j + k) == x)
						val++;
				}
			}
		}
		std::cout << val << std::endl;
		val = 0;
	}
    return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll dp[MAX_N];

int main() {
    ll n;
    cin >> n;

    vl dp(MAX_N, -1);
    dp[0] = 0;
    queue<ll> Q;
    Q.push(0);
    while(!Q.empty()) {
        ll v = Q.front();
        Q.pop();
        for(ll pow6 = 1; v + pow6 <= n; pow6 *= 6) {
            if(dp[v + pow6] == -1) {
                dp[v + pow6] = dp[v] + 1;
                Q.push(v + pow6);
            }
        }
        for(ll pow9 = 1; v + pow9 <= n; pow9 *= 9) {
            if(dp[v + pow9] == -1) {
                dp[v + pow9] = dp[v] + 1;
                Q.push(v + pow9);
            }
        }
    }
    
    out(dp[n]);
    re0;
}

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

int main(){
  int a, b, c;
  cin>> a >> b >> c;
  
  if(a==5 && b==5 && c==7)
    cout<<"YES"<<endl;
  else if(a==5 && b==7 && c==5)
    cout<<"YES"<<endl;
  else if(a==7 && b==5 && c==5)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}

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

using namespace std;

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

    int A, B;
    cin >> A >> B;
    int ans = max(A + B, A - B);
    ans = max(ans, A * B);
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
int main() {
    int a,b,c,k,ans=0;
    cin >> a >> b >> c >> k;
    if(a<=k){
        ans += a;
        k-=a;
        if(b<=k){
            k-=b;
            ans -= k;
        }
    }else{
        ans = k;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <cctype>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

int n;
int dd[200000];
int lef[200000];
int rig[200000];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> dd[i];
	}
	lef[0] = dd[0];
	for (int i = 1; i < n; i++)
	{
		if (lef[i - 1] < dd[i])
		{
			lef[i] = dd[i];
		}
		else
		{
			lef[i] = lef[i - 1];
		}
	}
	rig[n - 1] = dd[n - 1];
	for (int i = n - 2; i >= 0; i--)
	{
		if (rig[i + 1] < dd[i])
		{
			rig[i] = dd[i];
		}
		else
		{
			rig[i] = rig[i + 1];
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (i == 0)
		{
			cout << rig[1] << endl;
		}
		else if (i == n - 1)
		{
			cout << lef[n - 2] << endl;
		}
		else
		{
			cout << max(lef[i - 1], rig[i + 1]) << endl;
		}
	}
}



Measured memory_bytes: 35200
#include<iostream>
using namespace std;
int main()
{
    long long n,i,count,m;

    cin >> n;

    long long p[n];

    for(i=0; i<n; i++)
        cin >> p[i];

    m = p[0];
    count = 1;

    for(i=1; i<n; i++)
    {
        if(p[i]<=m){
            count++;
            m = p[i];
        }
    }

    cout << count << '\n';
}


Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
int main() {
	int i;
	string N,S;
	cin >> N;
	for (i = 0; i < 3; i++) {;
		if (N.at(i) == '7') {
			S="Yes";
			break;
		}
		else {
			continue;
		}
	}
	if (S != "Yes") {
		S = "No";
	}
	cout<< S << endl;

	system("pause");
}



Measured memory_bytes: 3636
#include <stdio.h>

int main(void){
    int n;
    int a[200];
    int i;
    int flag = 1;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
        if(a[i] % 2 == 0){
            if(a[i] % 3 && a[i] % 5){
                flag = 0;
            }
        }
    }
    
    if(flag){
        puts("APPROVED");
    }else{
        puts("DENIED");
    }
    return 0;
}

Measured memory_bytes: 128
from collections import deque
n = int(input())
output = deque()
for i in range(n):
    li = input().split(' ')
    if(li[0] == 'insert'):
        output.appendleft(li[1])
    elif(li[0] == 'deleteFirst'):
        output.popleft()
    elif(li[0] == 'deleteLast'):
        output.pop()
    elif(li[0] == 'delete'):
        try:
            output.remove(li[1])
        except:
            pass
print(' '.join(output))


Measured memory_bytes: 69736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T>
inline bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template <class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) { return (a * b) / GCD(a, b);}

int main(){
   string s;
   cin >> s;
   int n = s.size();
   vector<int> v(n, 1);
   int cnt = 0;
   rep(i, n - 1){
       if (s[i] == 'R' && s[i + 1] == 'R'){
           v[i]--;
           cnt++;
       }
       if (s[i] == 'R' && s[i + 1] == 'L'){
           v[i] += cnt / 2;
           v[i + 1] += cnt / 2 + cnt % 2;
           cnt = 0;
       }
   }
   int cn = 0;
   for (int i = n - 1; i; i--){
       if (s[i] == 'L' && s[i - 1] == 'L'){
           v[i]--;
           cn++;
       }
       if (s[i] == 'L' && s[i - 1] == 'R') {
            v[i] += cn / 2;
            v[i - 1] += cn / 2 + cn % 2;
            cn = 0;
        }
   }
   rep(i,n){
       if (i == n -1)
           cout << v[i] << endl;
        else{
            cout << v[i] << ' ';
        }
   }
   return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
  int h,n,i,j,sum[100000],xmax=0,num1[100000],num2[100000];

  while(1){
    xmax=0;
    for(i=0;i<100000;i++)sum[i]=0;
    

    cin >> n;
    if(n == 0)break;

    for(i=0;i<n;i++){
	cin >> num1[i];
      for(j=1;j<9;j++){

	cin >> num2[j];

	if(j>0 && j%2 == 0){
	  sum[i]+=num2[j];
	}
	else if(j>0 && j%2 != 0){
	  sum[i]+=(num2[j]*60);
	}

      }


    }


    for(i=0;i<n;i++){
      xmax=i;
      for(j=i;j<n;j++){
	if(sum[xmax]<sum[j])xmax=j;
      }
      h=sum[xmax];
      sum[xmax]=sum[i];
      sum[i]=h;

      h=num1[xmax];
      num1[xmax]=num1[i];
      num1[i]=h;
    }
    /*
       
    for(i=0;i<n;i++){
	cout << "num1["<<i<<"]="<<num1[i];
	cout << "  sum["<<i<<"]="<<sum[i];
      cout << endl;
    }
      
    */  


    cout<< num1[n-1] << endl;
    cout << num1[n-2] << endl;
    cout<< num1[1] << endl;






  }







}

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

using namespace std;
using ll = long long;

int main() {
    vector<int> a(5);
    int s=0;
    int res=0;
    for(int i = 0;i < 5;++i) {
        cin>>a[i];
        int t=10-a[i]%10;
        if(t==10)t=0;
        s+=(a[i]+t);
        res=max(res,t);
    }
    cout<<s-res<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<endl
#define AA(i) cout<<i<<endl
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

ll POW(ll n,ll m){
  long long pow = 1;
  while (m>0) {
    if ((m&1) == 1) pow = (pow*n)%MOD;
    m >>= 1;
    n = (n*n)%MOD;
  }
    return pow;
}

#define size 200010
long long fac[size],finv[size],inv[size];
void COMvec(ll N,int s){
  fac[0] = 1; fac[1] = N % MOD;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < s+1; i++){
    fac[i] = fac[i-1] * (N - i + 1) % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}
ll COM(ll n,ll k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[k] * finv[k] % MOD;
}

int main(){
    ll n; cin>>n;
    int a,b; cin>>a>>b;
    COMvec(n,b);
    ll ans = (POW(2,n) - 1 - (COM(n,a) + COM(n,b)) % MOD  + MOD )% MOD;
    AA(ans);
    return 0;
}

Measured memory_bytes: 4992
n,m=map(int,input().split())
path=[[] for i in range(n+1)]
anser=[0 for i in range(n+1)]
for i in range(m):
  a,b=map(int,input().split())
  path[a].append(b)
  path[b].append(a)
nowlis=[1]
nowdone=1
anser[1]=1
while nowdone<n:
  now=nowlis.pop(0)
  done=path[now]
  #print("now",now,"次",done)
  for i in done:
    if anser[i]==0:
      anser[i]=now
      nowlis.append(i)
      nowdone+=1
  #print("anser",anser)
kad=anser.pop(0)
kadd=anser.pop(0)
print("Yes")
for i in anser:
  print(i)
      
  



Measured memory_bytes: 33908
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;


struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1){}

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

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

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

    int size(int x){
        return -par[root(x)];
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i,m) {
        cin >> a[i] >> b[i]; a[i]--, b[i]--;
    }

    UnionFind uf(n);
    vector<ll> ans;
    ll now = n*(n-1)/2;
    rep(i,m){
        ans.push_back(now);
        int aa = a[m-1-i], bb = b[m-1-i];
        if(uf.same(aa, bb)) continue;
        ll s = uf.size(aa), t = uf.size(bb);
        now -= s*t;
        uf.unite(aa, bb);
    }
    reverse(all(ans));
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5344
N, M = map(int, input().split())
edges = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    edges.append([a-1, b-1])

nodes = [0]*N

mat = [[0]*N for _ in range(N)]

for s, g in edges:
    nodes[s] += 1
    nodes[g] += 1
    mat[s][g] = 1
    mat[g][s] = 1

ans = 0


def check(nodes):
    return all(n != 1 for n in nodes)


ans = 0
while not check(nodes):
    for i in range(N):
        if nodes[i] == 1:
            for j in range(N):
                if mat[i][j]:
                    mat[i][j] = 0
                    mat[j][i] = 0
                    ans += 1
                    nodes[i] -= 1
                    nodes[j] -= 1
                    break
print(ans)


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

int main()
{
	ll n,m;
	cin>>n>>m;
	ll res=0,a;
	for(ll i=0;i<m;++i){
		cin>>a;
		res+=a;
	}
	if(res>n)	cout<<-1<<endl;
	else cout<<n-res<<endl;
}

Measured memory_bytes: 3624