akhauriyash/Code-Regression huggingface dataset:
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int BN = 4;
const int FN = 3;
const int RN = 10;

/* typedef */

/* global variables */

int vs[BN][FN][RN];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) {
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    b--, f--, r--;
    vs[b][f][r] += v;
  }

  for (int b = 0; b < BN; b++) {
    if (b) {
      for (int r = 0; r < RN; r++) printf("##");
      putchar('\n');
    }

    for (int f = 0; f < FN; f++) {
      for (int r = 0; r < RN; r++) printf(" %d", vs[b][f][r]);
      putchar('\n');
    }
  }

  return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

long long pro(long long a){
    long long ret = 1;
    rep(i,a) ret*=3;
    return ret;
}

int main(){
    long long n;
    cin >> n;
    rep(i,21){
        if(pro(i) <= n && pro(i + 1) >= n){
            cout << i + 1 << endl;
            break;
        }
    }
}

Measured memory_bytes: 3104
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    while(true){
        
        cin >> H >> W;
        
        if(H == 0 && W == 0) break;
        
        for(int i=0;i<H;i++){
            
            for(int j=0;j<W;j++){
                if(i == 0 || i == (H-1)){
                    cout << '#';
                }
                else if(j == 0 || j == (W-1)){
                    cout << '#';
                }
                else{
                    cout << '.';
                }
            }
            
            cout << endl;
        }
        cout << endl;
    }

}


Measured memory_bytes: 3084
#include <stdio.h>

void C(int,int);
void I(int,int,int);
void E(int,int);

void C(int i, int n){
  int x = i;
  if ( x % 3 == 0 ){
    printf(" %d",i);
    E(i,n);
  }
  else{
    I(i,n,x);
  }
}

void I(int i,int n,int x){
  if ( x % 10 == 3 ){
    printf(" %d",i);
    E(i,n);
  }
  else{
      x /= 10;
      if ( x ){
	I(i,n,x);
      }else {
	E(i,n);
      }
  }
}

void E(int i,int n){
  if(++i<=n){
    C(i,n);
  }else{
    printf("\n");
  }
}

int main(){

  int i=1,n;
  scanf("%d",&n);
  C(i,n);


  return 0;
}



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

int main()
{    
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i,n) cin >> a[i] >> b[i];

    vector<int> dp(h+9,-1);
    dp[0] = 0;

    rep2(i,1,h+1)
    {
        int min_b = 1e9+9;
        rep(j,n)
        {
            int prev = i - a[j];
            if(prev < 0) 
                min_b = min(b[j], min_b);
            else if(dp[prev] >= 0)
                min_b = min(dp[prev]+b[j], min_b);
        }
        
        if(min_b != 1e9+9) dp[i] = min_b;
    }

    cout << dp[h] << endl;
    return 0;
}

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

using namespace std;
inline void
prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
//printf("%.12lf\n",mid);
int mod;

int mymod(int num){
  if (num< 0){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

int main ()
{
  prep ();
  
  int n, l;
  cin >> n >> l;
  int arr[50];
  for (int i=0; i<n; i++){
    cin >> arr[i];
  }
  int maxx = 0;
  for (int i=0; i<=n; i++){
    for (int j=0; j<=n; j++){
      if (i+j > n || i+j > l){
        break;
      }
      long long sum = 0;
      vector<int> negatives;
      for (int k=0; k<i; k++){
        if (arr[k] > 0){
          sum+= arr[k];
        }else if (arr[k] < 0){
          negatives.push_back(arr[k]);
        }
      }
      for (int k=n-1; k>n-j-1; k--){
        if (arr[k] > 0){
          sum+= arr[k];
        }else if (arr[k] < 0){
          negatives.push_back(arr[k]);
        }
      }
      sort(negatives.begin(), negatives.end());
      int remk = l-i-j;
      
      int k = 0;
      for (k=0; k<negatives.size(); k++){
        if (remk <= 0){
            break;
        }
        remk--;
      }
      for (int kk=k; kk<negatives.size(); kk++){
          sum += negatives[kk];
      }
     
      if (sum > maxx){
        maxx = sum;
      }
    }
  }
  cout << maxx;
  return 0;
}
// in dp problems think: up until here, intervals, or "what if there's 1, 2, 3..."
// in math problems write out equations
// also in math problems to change multiplication/division to addition/subtraction use logs, add/subtract something to make the multiplication easier (like if it's 3*f(x)+2, change it to 3*(f(x)+1)-1)
// if printint pow function, put an (int) or (long long) next to it
// if checked everything check for bugs (like sorting wrong way or not putting a break in a loop)
// if n is 10^7 try brute force if the operations are simple
// if can't do dp do brute force/greedy
// to save time don't copy maps/vectors into variables if it already exists
// only use long long if need to
// if wrong on decimal problem, check if program rounds or if you can round to a certain amt of decimals
// if decimals too, if can subtract instead of divide
// in grid traversal problems check if doing sideways or not
// if TLE try to take away loop
// in recursion looking math problems look at things from the point of view of both sides (the start and the end sections of the recursion)
// think about how many possible answers there are to the problem
// if it makes it easier use +1 indexing
// think twice when writing things down that you're going to use later


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

std::map < int, int > hash;
std::vector < int > vec;



int main()
{
	int m , n;
	std :: cin >> m >> n;

	long res{};

	for(int i = 1 ; i <= m ; i++)
    {
        for(int j = 1 ; j <= n ; j++)
            if(j > 10 && (j % 10) * (j / 10) == i && (j % 10) > 1 && (j / 10) > 1)
                res++;
    }

    std :: cout << res << '\n';

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include <vector>
#define ll long long int
#define ve vector<ll>
#define vell vector<ll>
#define ve_pa vector<pair<ll,ll> >
#define pb push_back
#define mod 1000000007
#define ld long double 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define mll map<ll,ll>
#define mii map<int,int>
#define m_ve map<ll,vell >
#define min3(x,y,z) min(x,min(y,z))
#define max3(x,y,z) max(x,max(y,z))
#define se second
#define check cout<<"s"
#define checkx(x) cout<<x
#define W(x) while(x--)
#define ld long double
#define popcount(x) __builtin_popcountll(x)
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
//int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
m_ve g;
mll v;
int cnt;
void dfs(int s)
{
	v[s]=1;
	cnt++;
	for(int i=0;i<g[s].size();i++)
	{
		int c=g[s][i];
		if(v[c]==0)
		{
			dfs(c);
		}
	}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); 
cout.tie(NULL);
int n,m;cin>>n>>m;
for(int i=0;i<m;i++)
{
	ll u,v;cin>>u>>v;
	g[u].pb(v);
	g[v].pb(u);
}
int ans=0;
for(int i=1;i<=n;i++)
{
	if(v[i]==0)
	{
		cnt=0;
		dfs(i);
		ans=max(ans,cnt);
	}
}
cout<<ans;



}
 
 


Measured memory_bytes: 56688
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())
l = [a, b, c]
counter = 0
if a == b:
  counter += 1
if b == c:
  counter += 1
if a == c:
  counter += 1
if counter == 1:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 2940
/**
   	C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;


int main(){
    char first = ' ';
    char second = ' ';
    string s ;
    cin >> s;

    first = s[0];
    int fcount = 1;
    int scount = 0;
    for(int i = 1 ; i < 4 ;i++){
        if(first == s[i]){
            fcount++; 
        }
        else{
            if(second == ' '){
                second = s[i];
                scount++;
            }
            else {
                if(second == s[i]){
                    scount++;
                }
            }
        }
    }

    // cout << fcount << " " << scount << endl;
    if(first != ' ' && second != ' ' && fcount ==2 && scount ==2){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
/**
 *    author:  math2do
 *    created: 12.04.2020 17:30:36
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  bool found = false;
  while (n > 0) {
    int d = n % 10;
    found |= (d == 7);
    n /= 10;
  }
  cout << (found ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>

namespace TokorotenLab
{
    /*
    Arguments:
        Search range: [begin, end)
        Target function: f(x)
    Requirement:
        f(x) => { false, ..., false, true, ..., true }
    Judge:
        true_bound == begin => All f(x) are true
        true_bound == end => All f(x) are false
    */
    std::pair<long long, long long> binary_search(long long begin, long long end, std::function<bool(long long)> f)
    {
        long long false_bound = begin - 1LL; // ( ..., false_bound] => false
        long long true_bound = end; // [true_bound, ... ) => true
        long long x;

        while(true_bound - false_bound > 1LL)
        {
            x = false_bound + (true_bound - false_bound) / 2LL;
            if(f(x))
            {
                true_bound = x;
            }
            else
            {
                false_bound = x;
            }
        }

        return std::make_pair(false_bound, true_bound);
    }
}

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if(a >= 13) {
        cout << b << endl;
    } else if(a >= 6) {
        cout << b / 2 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define  _(x)  cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v)  (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps=1e-6;
long long gcd(long long a, long long b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main() {

   
   int n;
   cn n;

   int priv;
   cn priv;
   int c=1;

   for (int i = 0; i < n-1; ++i)
   {
       int a;
       cn a;
       if(a<=priv)c++;
       priv=min(a,priv);
   }


  ct c;nl;


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
template <typename T> T max(T, T);
int gcd(int a, int b);

int main() {
    // source
    string s;
    cin >> s;
    ll ans=0,black=0;
    rep(i,s.size()){
        if(s[i]=='B'){
            black++;
        }else{
            ans+=black;
        }
    }

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

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T max(T a, T b) {

    if (a > b) {
        return a;
    } else {
        return b;
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 640
#include<stdio.h>

int main()
{
	int a,b,c,i;
	scanf("%d",&i);
   while(i!=0){
	scanf("%d %d %d",&a,&b,&c);
	if (a > b && a > c)
		if(a*a==b*b+c*c)
		printf("YES\n");
	
	else
		printf("NO\n");
	
	else if(b > a && b > c)
		if(b*b==a*a+c*c)
		printf("YES\n");
	
	else 
		printf("NO\n");
	

	else
	if(c*c==a*a+b*b)
		printf("YES\n");
	
	else
		printf("NO\n");
	
	
	i--;
   }
return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  while(1){
  string s;cin >> s;
  if(s=="-") return 0;
  int m;cin >> m;
  for(int i=0;i<m;i++){
    int h;cin >> h;
    s=s.substr(h,s.size()-h)+s.substr(0,h);
  }
  cout << s << endl;
}
}



Measured memory_bytes: 3160
import java.util.Scanner;

public class Main {

	static int BinarySearch(long low, long high, long b) {
		// low <= ? < high
		long mid = 0;
		while(low < high) {
			mid = (low + high)/2;
			long ans = mid * mid + mid;
			if(ans == b)	return (int)mid;
			else if(ans < b) low = mid+1;
			else	high = mid;
		}
		return (int)mid;
	}

    public static void main(String[] args) throws Exception {
    	try(Scanner sc = new Scanner(System.in)) {
    	/*
    	 1. (aを最小値1として)lengthのmaxを二分探索で探してaを後から求める 
    	 2. lengthを0から線形探索してa<=0になる一歩手前を求める。
    	 ** lengthを最大値なにかで仮定できないから,aのminを二分探索で探すことはできない
    	 
    	 時間がかかる最初に考えたもの:
    	 	aを1から代入していってlengthを二分探索で求めていた。
    	 	
    	 */

//			1.
    		while(true) {
    			long b = sc.nextLong();
    			if(b == 0) break;
    			b *= 2;
    			int max = BinarySearch(1, (long)Math.sqrt(b)+2, b);
    			int size = 1;
    			int a = 0;
    			for(size = max; size > 0; size--) {
    				if(b%size != 0)	continue;
    				else if((b/size - size + 1)% 2 != 0)	continue;
    				a = (int)(b/size - size + 1)/2;
    				break;
    			}
    			System.out.println(a+" "+size);
    		}
//    		2.
//    		while(true) {
//    			int b = sc.nextInt();
//    			if(b == 0) break;
//    			long length = 0;
//    			int a = 0;
//    			for(int size=0; size<b; size++) { //size大きいほど、aが小さい
//    				int x = 2*b/(size+1) - (size+1) + 1;
//    				if(2*b%(size+1) != 0)	continue;
//    				else if(x % 2 != 0)	continue;
//    				else if(x <= 0)	break;
//    				a = x/2;
//    				length = size+1;
//    			}
//    			System.out.println(a + " " + length);
//    		}

    	}
    }
}




Measured memory_bytes: 30572
/*
 *Team hhu_6814
 *Author big_yellow_doge
 */
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <list>
using namespace std;
//ios::sync_with_stdio(false);
const int MINF = 0x7fffffff;
const int INF = 0x3f3f3f3f;
const int Maxn = 1e5+5;
typedef long long ll;
int nx[5];
int main()
{
    int a,b;
    for(int i = 0;i < 3;i++){
        scanf("%d%d",&a,&b);
        nx[a]++;
        nx[b]++;
    }
    for(int i = 1;i <= 4;i++){
        if(nx[i]>=3) {puts("NO");exit(0);}
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n, w;
  cin>>n>>w;
  vector <ll> we(w + 1);
  while(n--){
  	ll e, v;
    cin>>e>>v;
    for(ll i = w - e; i >= 0; i--){
    	we[i + e] = max(we[i + e], we[i] + v);
    }
  }

  auto ans = max_element(we.begin(), we.end());
  cout<<*ans;
  return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

int gcd(int a, int b) {
	return b != 0 ? gcd(b, a%b) : a;
}
lli gcd(lli a, lli b) {
	return b != 0 ? gcd(b, a%b) : a;
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
lli lcm(lli a, lli b) {
	return a * b / gcd(a, b);
}

#define N_MAX 200000
#define MOD 1000000007

vector<int> edge[N_MAX];
vector<pair<int,int> > table;

int visit[N_MAX];
void dfs(int index,int depth)
{
	visit[index] = 1;

	bool leaf = true;
	for (int i = 0; i < edge[index].size(); i++) {
		if (0 == visit[edge[index][i]]) {
			leaf = false;
			dfs(edge[index][i], depth + 1);
		}
	}

	if (leaf) {
		table.push_back(make_pair(depth, index));
	}

	return;
}

void solv()
{
	int N; scanf("%d", &N);
	for (int i = 0; i < N - 1; i++) {
		int s, t; scanf("%d%d", &s, &t);
		s--; t--;
		edge[s].push_back(t);
		edge[t].push_back(s);
	}

	fill(visit, visit + N, 0);
	dfs(0, 1);

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

	int idx = table[table.size() - 1].second;
	fill(visit, visit + N, 0);
	table.clear();
	dfs(idx, 1);

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

	int diam = table[table.size() - 1].first;
	if (2 == diam % 3) {
		printf("Second");
	}
	else {
		printf("First");
	}

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}


Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >> x;
  int a, b;
  for(int a = -120; a < 120; a++){
    for(int b = -120; b < 120; b++){
      if(a*a*a*a*a-b*b*b*b*b == x){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <vector>
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

using namespace std;
#define int long long
using ll = long long;
const int MX = 1e6;
const ll inf = 1e13;
const int mod = 1e9+7;

signed main() {
    string s;
    cin >> s;
    rep(i,s.length()) {
        char c = s[i];
        if(c=='A') {
            cout << "T" << flush;
        }else if(c=='T') {
        cout << "A" << flush;
            
        }else if(c=='C') {
            cout << "G" << flush;
        
        }else {
            cout << "C" << flush;
        
        }
        cout << "" << endl;
    }

    return 0;
}



Measured memory_bytes: 3608
//In the name of God:)
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define int long long
using namespace std;
void solve(){

}

int32_t main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  int n;
  cin>>n;
  int ans = 0;
  ans += n / 500 * 1000;
  n %= 500;
  ans += n - (n%5);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e15;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<vector<ll>> a(n,vector<ll>(n));
  rep(i,n)rep(j,n) {
    cin >> a[i][j];
  }

  vector<vector<ll>> d(n,vector<ll>(n, INF));
  rep(i,n) { d[i][i] = 0; }
  rep(r,n)rep(c,n) {
    if (r == c) { continue; }
    bool found = false;
    rep(k,n) {
      if (k == r || k == c) { continue; }

      if (a[r][c] > a[r][k] + a[k][c]) { // invalid. a[r][c] must be minimum.
        cout << -1 << endl;
        return 0;
      }
      if (a[r][c] == a[r][k] + a[k][c]) { // a[r][c] is representable by sum of r-k + k-c.
        found = true;
      }
    }
    // cout << "a[r][c]: " << a[r][c] << endl;
    // cout << "found: " << found << endl;
    if (!found) { // a[r][c] is min
      d[r][c] = a[r][c];
    }
  }
  // printtree(d);

  // vector<vector<ll>> d2 = d; // copy
  // rep(k,n)rep(v,n)rep(u,n) {
  //   chmin(d2[v][u], d2[v][k] + d2[k][u]);
  // }

  // // Check the equality of d2 and a.
  // bool ok = true;
  // rep(r,n)rep(c,n) {
  //   if (d2[r][c] != a[r][c]) {
  //     ok = false;
  //     break;
  //   }
  // }
  // if (!ok) { // not valid
  //   cout << -1 << endl;
  //   return 0;
  // }

  ll ans = 0;
  rep(r,n)rep(c,r) {
    if (d[r][c] != INF) {
      ans += d[r][c];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1664
def main():
    s = input()
    n = len(s) - 1
    a = 0
    for k in range(2**n):
        o = ["+ "[i == "0"] for i in bin(k)[2:]]
        o = [" "] * (n - len(o)) + o + [" "]
        a += eval("".join((a + b).strip() for a, b in zip(s, o)))
    print(a)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse = True)
    ans = 0
    for i in range(n):
        if a[i] >= sum(a) / (4 * m):
            ans += 1
    print("Yes" if ans >= m else "No")
if __name__ == "__main__":
    main() #endline===============================================

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

int main(){
   IOS;

   long int n;
   cin>>n;

   string s;
   cin>>s;

   if(n & 1)
      return cout<<"No",0;

   for(long int i = 0; i < n/2; i++){
      if(s[i] != s[n/2 + i])
         return cout<<"No",0;
   }
   cout<<"Yes";

   return 0;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

ll power(int x) {
    int tmp = 1;
    REP(i, x) tmp *= 2;
    return tmp;
}

int main(){
    int m, k;
    cin >> m >> k;

    if(m == 0) {
        if(k == 0) cout << "0 0" << endl;
        else cout << "-1" << endl;
        return 0;
    }

    if(m == 1) {
        if(k == 0) cout << "0 0 1 1" << endl;
        else cout << "-1" << endl;
        return 0;
    }

    if(power(m) <= k) {
        cout << "-1" << endl;
        return 0;
    }

    vector<ll> ans(power(m)*2);

    if(k == 0) {
        REP(i, power(m)) {
            cout << i << " " << i << endl;
        } 
        return 0;
    }

    ans[0] = 0, ans[1] = k, ans[2] = 0;
    int idx = 3;

    REPN(i, 1, power(m)) {
        if(i == k) continue;
        ans[idx] = i;
        idx++;
    }

    ans[idx] = k;
    idx++;

    REPN_REV(i, 1, power(m)) {
        if(i == k) continue;
        ans[idx] = i;
        idx++;
    }    

    REP(i, ans.size()) cout << ans[i] << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 3840
N = int(input())
flag = True
s = str(input())
b = set()
b.add(s)
for i in range(N-1):
    k = str(input())
    if (k[0] != s[-1]) or (k in b):
        flag = False
        break
    b.add(k)
    s = k
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL n;
 
int main() 
{
  cin >> n;
  for (LL i = 0; i <= n; i ++) 
    if (i * (i + 1) / 2 >= n) 
    {
      cout << i << endl;
      break;
    }
 
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a, b, c;

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


	if (((a==b)&&(b!=c))||((b==c)&&(a!=b))||((a==c)&&(a!=b))) {
		puts("Yes");
	} else {
		puts("No");
	}

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	set<int>m;
	m.insert(a);
	m.insert(b);
	m.insert(c);
	cout << m.size() << endl;
	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> p(n);
  for (int i=0; i<n; i++) cin >> p[i];
  
  int ans=0;
  for (int i=1; i<n-1; i++) {
    if ( (p[i-1]<p[i]) && (p[i]<p[i+1]) || 
         (p[i-1]>p[i]) && (p[i]>p[i+1]) ) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  vector<Int> x,y;
  auto fin=[&](){
    if(0){
      for(Int i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
      for(Int i=0;i<n-1;i++) assert(a[i]<=a[i+1]);
    }
    cout<<x.size()<<endl;
    for(Int i=0;i<(Int)x.size();i++)
      cout<<x[i]+1<<" "<<y[i]+1<<endl;
    exit(0);
  };
  for(Int i=0;i<n;i++) cin>>a[i];
  {
    bool f=1;
    for(Int i=0;i<n;i++)
      f&=(a[i]==0);
    if(f) fin();
  }
  {
    Int k=0;
    for(Int i=0;i<n;i++)
      if(abs(a[i])>abs(a[k])) k=i;
    for(Int i=0;i<n;i++){
      if(i==k) continue;
      a[i]+=a[k];
      x.push_back(k);
      y.push_back(i);
    }
  }
  bool po=1,ne=1;
  for(Int i=0;i<n;i++){
    ne&=(a[i]<=0);
    po&=(a[i]>=0);
  }
  assert(ne||po);
  if(ne&&po) fin();
  if(ne){
    for(Int i=n-1;i>0;i--){
      a[i-1]+=a[i];
      x.push_back(i);
      y.push_back(i-1);
    }
    fin();
  }
  if(po){
    for(Int i=0;i<n-1;i++){
      a[i+1]+=a[i];
      x.push_back(i);
      y.push_back(i+1);
    }
    fin();
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n, a[100010], b[100010], c[100010], dp[100010][3];
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    for (ll i = 0; i < n; i++)
    {
        dp[i + 1][0] = max(dp[i][1] + a[i], dp[i][2] + a[i]);
        dp[i + 1][1] = max(dp[i][2] + b[i], dp[i][0] + b[i]);
        dp[i + 1][2] = max(dp[i][0] + c[i], dp[i][1] + c[i]);
    }
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            
            int cnt = 0;
            
            for(int i = 0; i < n; i++)
            {
                int minj = i;

                for(int j = i; j < n; j++)
                {
                    if (A[j] < A[minj]) minj = j;
                }

                if (i != minj) cnt++;

                int temp = A[i];
                A[i] = A[minj];
                A[minj] = temp;
            }

            Console.WriteLine(string.Join(" ", Array.ConvertAll(A, a => a.ToString())));
            Console.WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 9164
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;

i64 sum_small(i64 n) {
    --n;
    if (n <= 0) return 0;
    return (n * (n+1)) / 2;
}

i64 sum_large(i64 n, i64 k) {
    if (n <= 0) return 0;
    return (n * (n+1)) / 2 - sum_small(n-k+1);
}

int main(int argc, char **argv) {
    int n, k;
    cin >> n >> k;

    i64 ans{0};
    for (int i=k; i<n+2; ++i) {
        ans += sum_large(n, i) - sum_small(i) + 1;
        ans %= mod;
    }
    cout << ans <<endl;

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n;
int a[111];

int main(){
	cin>>n;
  int res=0;
  rep(i,n)cin>>a[i];
  rep(i,n){
    int minj=i;
    repl(j,i,n){
      if(a[minj]>a[j])minj=j;
    }
    if(minj!=i){
      swap(a[minj],a[i]);
      res++;
    }
  }
  cout<<a[0];
  repl(i,1,n)cout<<" "<<a[i];
  cout<<endl;
  cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include <string>

#define f(i,n) for(int i = 0; i < n; i++)
#define fll(i,n) for(long long int i = 0; i < n; i++)
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define inf INT_MAX
#define pb push_back
#define all(x) x.begin(),x.end()
#define debug(x) cout<<" [ " << #x << " is: " << x << " ] "<<endl;
#define ans(x) cout<<x<<endl;
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define mem(x,i) memset(x,i,sizeof x)

#define cin_vi(v,n) f(i,n){int temp;cin>>temp;v.pb(temp);}
#define cin_vll(v,n) fll(i,n){ll temp;cin>>temp;v.pb(temp);}
#define sort_desc(a) sort(a.begin(), a.end(), greater<int>());
#define sort_desc_ll(a) sort(a.begin(), a.end(), greater<long long int>());

using namespace std;

int main () {
	
	fast;

	double L;
	double ans;
	cin>>L;
	ans=(L/3)*(L/3)*(L/3);
	// cout<<ans;
	printf("%.12lf\n", ans);

	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[0]*(n)
b=[0]*(n)
c=[0]*(n)
for i in range(n):
    a[i],b[i],c[i]=map(int,input().split())

INF=float("inf")
dpa=[-INF]*n
dpb=[-INF]*n
dpc=[-INF]*n
dpa[0]=a[0]
dpb[0]=b[0]
dpc[0]=c[0]

for i in range(1,n):
    dpa[i]=a[i]+max(dpb[i-1],dpc[i-1])
    dpb[i]=b[i]+max(dpc[i-1],dpa[i-1])
    dpc[i]=c[i]+max(dpa[i-1],dpb[i-1])
    
print(max(dpa[-1],dpb[-1],dpc[-1]))
    




Measured memory_bytes: 26740
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		if(S.equals("hi") || S.equals("hihi") || S.equals("hihihi") || S.equals("hihihihi") || S.equals("hihihihihi")){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int A, B;
  cin >> A >> B;
  if (A == B) {
    cout << "Draw" << endl;
  } else if (A == 1 || (B != 1 && A > B)) {
    cout << "Alice" << endl;
  } else if (B == 1 || (A != 1 && B > A)) {
    cout << "Bob" << endl;
  }
  return 0;
}


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

int main() {
  string A, B;
  cin >> A >> B;
  if (A.size() > B.size()) cout << "GREATER" << endl;
  else if (A.size() < B.size()) cout << "LESS" << endl;
  else {
    if (A > B) cout << "GREATER" << endl;
    else if (A < B) cout << "LESS" << endl;
    else cout << "EQUAL" << endl;
  }
}


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

vector<string> word{"AC", "WA", "TLE", "RE"};

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

    string S;
    vector<int> C(N, 0);
    for (int i = 0; i < N; i++){
        cin >> S;
        for (int j = 0; j < 4; j++){
            string w = word[j];
            if (S == w){
                C[j] += 1;
                break;
            }
        }
    }

    for (int j = 0; j < 4; j++){
        cout << word[j] << " x " << C[j] << endl;
    }
}

Measured memory_bytes: 3776
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

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

	map <char, int> mp;
	
	for (int i = 0; i < SZ(s); ++i)
	{
		mp[s[i]]++;
	}

	bool ok = true;
	for (const auto& a : mp)
	{
		if (a.second != 2)
		{
			ok = false;
		}
	}

	if (ok)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;

	}


	return 0;
}


Measured memory_bytes: 764
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

using ll = long long;

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

  int N;
  cin >> N;

  vector<int> A(N);
  for (int& a : A) {
    cin >> a;
    --a;
  }

  vector<int> result;

  while (!A.empty()) {
    int idx = -1;
    for (int i = A.size() - 1; i >= 0; --i) {
      if (A[i] == i) {
        idx = i;
        break;
      }
    }

    if (idx == -1) {
      cout << -1 << '\n';
      return 0;
    }

    result.push_back(idx);
    A.erase(A.begin() + idx);
  }

  reverse(result.begin(), result.end());
  for (int r : result) {
    cout << r + 1 << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())
    S = input()

    fst_num = []
    scd_num = []
    count = 0
    for i in range(len(S)-2):
        if len(fst_num) == 10:
            break
        if S[i] not in fst_num:
            fst_num.append(S[i])
            scd_num = []
            for j in range(i+1, len(S) - 1):
                if len(scd_num) == 10:
                    break
                if S[j] not in scd_num:
                    scd_num.append(S[j])
                    for k in range(10):
                        if str(k) in S[j+1:]:
                            # print(S[i],S[j],k)
                            count += 1
    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

struct WordAssert
{
	int person;
	int type;	//0--unkind, 1--honest
	int sayPerson;	//谁说的 
};
std::vector<WordAssert> words;

int honestType[20];

int N;
int maxHonest = 0;

bool check()
{
	for (int i = 0 ; i < words.size() ; i++)
	{
		if (false == honestType[words[i].sayPerson])
			continue;
			
		int person = words[i].person;
		int type = words[i].type;
		
		if (honestType[person] != type)
			return false;
	}
	
	return true;
}

void doSearch(int depth, int honestCount)
{
	if (depth > N)
	{
		if (maxHonest >= honestCount)
			return;
			
		if (true == check())
		{
			if (maxHonest < honestCount)
				maxHonest = honestCount;
		}
	}
	else
	{
		honestType[depth] = 0;
		doSearch(depth + 1, honestCount);
		
		honestType[depth] = 1;
		doSearch(depth + 1, honestCount + 1);
	}
}

int main()
{
	scanf("%d", &N);
	for (int i = 1 ; i <= N ; i++)
	{
		int szLen = 0;
		WordAssert newWord;
		scanf("%d", &szLen);
		for (int j = 0 ; j < szLen ; j++)
		{
			scanf("%d%d", &(newWord.person), &(newWord.type));
			newWord.sayPerson = i;
			words.push_back(newWord);
		}
	}
	
	doSearch(1, 0);
	
	printf("%d\n", maxHonest);
		
	return 0;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

typedef std::tuple<string, int, int> mytuple;
bool mycompare( const mytuple &lhs, const mytuple &rhs ) {
    if (get<0>(lhs) != get<0>(rhs)) return get<0>(lhs) < get<0>(rhs);
    if (get<1>(lhs) != get<1>(rhs)) return get<1>(lhs) > get<1>(rhs);
    // return std::get<2>(lhs) < std::get<2>(rhs);
}


int main(void){

	int N; cin >> N;
	// vector<pair<string, int>> city(N);
	vector<tuple<string, int, int>> city(N);
	REP(i,N){
		string s;
		int p;
		cin >> s >> p;
		// city[i] = make_pair(s, p);
		city[i] = make_tuple(s, p, i+1);
	}

	cout << endl;
	sort(city.begin(), city.end(), mycompare);
	REP(i,N){
		// cout << get<0>(city[i]) << get<1>(city[i]) << get<2>(city[i])  << endl;
		cout << get<2>(city[i]) << endl;

	}

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int main(){
	int n;
	cin>>n;
	int mx_f=-1e9;
	int pos;
	int mx_s=-1e9; 
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(mx_f<a[i]){
			mx_f=a[i];
			pos=i;
		}
	}
	for(int i=0;i<n;i++){
		if(i==pos)continue;
		mx_s=max(mx_s,a[i]);
	}
	for(int i=0;i<n;i++){
		if(a[i]==mx_f)cout<<mx_s<<endl;
		else cout<<mx_f<<endl;
	}
	return 0;
}

Measured memory_bytes: 2432
# coding: utf-8


s = input().rstrip()

a_index = -1
b_index = -1

for i in range(len(s)):
    if s[i] == "A":
        if a_index < 0:
            a_index = i
    elif s[i] == "Z":
        b_index = i

print(b_index-a_index+1)

Measured memory_bytes: 3516
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
// g++ -std=c++11 -o2 -Wall filename.cpp -o filename
#define hell 1000000009
#define bug1(x) cout<<"$ "<<x<<" $"<<endl
#define bug2(x) cout<<"% "<<x<<" %"<<endl
#define bug3(x) cout<<"# "<<x<<" #"<<endl
#define ll long long
#define pb push_back
#define mp make_pair
#define tr(z) for(auto it=z.begin(); it!=z.end(); it++)
#define rloop(i,a,b) for(long long i=a; i>=b;i--)
#define loop(i,a,b) for(long long i=a; i<b; i++)
#define vbool vector< bool >
#define vvbool  vector< vector<bool> >
#define vchar vector<char>
#define vi vector<int>
#define vvi vector< vector<int> >
#define pll pair<long long, long long>
#define vll vector<long long>
#define vvl vector< vector<long long> >
#define ninf numeric_limits<long long>::min()
#define pinf numeric_limits<long long>::max()
#define comp(a,b) (abs(a-b)<1e-9) // to compare doubles
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N,K;
    cin >> N >> K;
    vi stones(N);
    loop(i, 0, N) {
        int n;
        cin >> stones[i];
    }

    vector<int> dp(N, INT_MAX);
    dp[0] = 0;
    dp[1] = abs(stones[1] - stones[0]);
    for (int i = 2; i < N; ++i) {
        for (int step = 1; step <= K; ++step) {
            if (step <= i) {
                dp[i] = min(dp[i], dp[i - step] + abs(stones[i] - stones[i - step]));
            }
        }
    }
    cout << dp[N - 1] << "\n";
    return 0;
}


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

int gcd(int x,int y){
	return y ? gcd(y,x%y)+1 : 0;
}
int main(){
	int x,y;
	while(cin >> x >> y && (x||y)){
		if( x < y ) swap(x,y);
		cout << __gcd(x,y) << " " << gcd(x,y) << endl;	
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,cantj=0,canti=0;
	char a[10001];
	while(scanf("%s",a)!=EOF){
		for(i=0;i<strlen(a)-2;i++){
			if(a[i]=='J' && a[i+1]=='O' && a[i+2]=='I'){
				cantj++;
			}
			if(a[i]=='I' && a[i+1]=='O' && a[i+2]=='I'){
				canti++;
			}
		}
		printf("%d\n",cantj);
		printf("%d\n",canti);
		canti=0;
		cantj=0;
	}
	return 0;
}

Measured memory_bytes: 980
N=int(input())
W=list(map(int,input().split()))
S=[0]*(N+1)

for i in range(N):
    S[i+1]=S[i]+W[i]
    
ans=10**9

for i in range(N):
    ans=min(abs(S[-1]-S[i+1]*2),ans)
print(ans)



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

max_count = 0

L = [0]*10**5
for i in A:
    L[i] += 1

for i in range(10**5+1):
    count = 0
    for j in range(-1,2):
        if i+j >= 0 and i+j < 10**5:
            count += L[i+j]
    max_count = max(count, max_count)
print(max_count)

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

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

  vector<tuple< string,int,int>> a;
  for(int i=0; i<N;i++){
      int x;
      string y;
      cin>>y>>x;

      a.push_back(make_tuple(y, x*-1,i));
  }
  sort(a.begin(), a.end());


  for(tuple<string,int,int>l:a){
      int j;
      tie(ignore,ignore,j)=l;
      cout<<j+1<<endl;


  }
  
}


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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef std::pair<int, int> P;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

signed main() {
    string s;
    int K;
    cin >> s >> K;
    vector<int> S(s.length());
    rep(i, s.length()) {
        S[i] = (26 - (s[i] - 'a')) % 26;
    }
    rep(i, S.size()) {
        if (S[i] <= K) {
            K -= S[i];
            S[i] = 0;
        }
    }
    S[S.size() - 1] = (S[S.size() - 1] + (26 - (K % 26)))%26;
    vector<char> ans(s.length());
    rep(i, S.size()) {
        ans[i] = (26 - S[i]) % 26 + 'a';
    }
    rep(i, s.length()) {
        cout << ans[i];
    }
}


Measured memory_bytes: 1408
#if 1

#include <bits/stdc++.h>
using namespace std;
#define INF 10^9
vector < pair <int,int> > v[100005];
int n;
long long d[100005];

int main()
{
    long long x,y,z;
    scanf("%d", &n);
    for(int i = 1;i <= n-1;i++)
    {
        scanf("%lld %lld %lld", &x, &y, &z);
        v[x].push_back({y,z});
        v[y].push_back({x,z});
        d[i] = 1000000000000000;
    }
    d[n] = 1000000000000000;
    priority_queue < pair <long long,int> > q;
    q.push({0,1});
    while(!q.empty())
    {
        x = -q.top().first;
        y = q.top().second;
        q.pop();
        //cout << x << " : " << y << '\n';
        if(d[y] < x) continue;
        d[y] = x;
        for(int i = 0;i < v[y].size();i++)
        {
            q.push({-x-v[y][i].second,v[y][i].first});
        }
    }
    for(int i = 1;i <= n;i++)
    {
        printf("%lld\n",d[i]%2);
    }
}

#endif // 1++

Measured memory_bytes: 7296