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

using ll = long long;

int N;
int a[111];

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

   ll cost = 1e15;
   for (int i = -1000; i <= 1000; i++) {
      ll sum = 0;
      for (int j = 0; j < N; j++) {
         ll x = (i - a[j]);
         sum += x * x;
      }
      cost = min(cost, sum);
   }
   cout << cost << endl;

   return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
    int r, D, x2000;
    cin >> r >> D >> x2000;
    int x = x2000;
    rep(i, 10) {
        x = r * x - D;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
map<int, ll> mp;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  vector<int> a(n);
  REP(i, n) {
    cin >> a[i];
    mp[a[i]]++;
  }

  ll ans = 0;
  for(auto const& x : mp) {
    if(x.second > 1) ans += ((x.second * (x.second - 1)) / 2);
  }

  REP(i, n) {
    int t = 0;
    int t2 = 0;
    if(mp[a[i]] > 1) t = ((mp[a[i]] * (mp[a[i]] - 1)) / 2);
    if(mp[a[i]] - 1 > 1) t2 = (((mp[a[i]] - 1) * (mp[a[i]] - 2)) / 2);
    cout << ans - t + t2 << endl;
  }
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf
#define itn int
using namespace std;
const int N=1e6;
const long long mod=1e9+7;
const int oo=0x7fffffff;
const int sup=0x80000000;
typedef long long ll;
typedef unsigned long long ull;
template <typename it>void db(it *begin,it *end){while(begin!=end)cout<<(*begin++)<<" ";puts("");}
template <typename it>
string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;}
template <typename it>int o(it a){cout<<a<<endl;return 0;}
ll mul(ll a,ll b,ll c){ll ans=0;for(;b;b>>=1,a=(a+a)%c)if(b&1)ans=(ans+a)%c;return ans;}
ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=mul(a,a,c))if(b&1)ans=mul(ans,a,c);return ans;}
int n,k;
ll dp[3005][3005];
int main(){
	for(int i=0;i<3005;i++)dp[i][0]=1;
	for(int i=1;i<3005;i++)
	for(int j=1;j<=i;j++)dp[i][j]=(dp[i-1][j]+dp[i-1][j-1])%mod;
	cin>>n>>k;
	for(itn i=0;i<k;i++)o(1ll*dp[k-1][i]*dp[n-k+1][i+1]%mod);
}


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

string s, t="keyence";
int cnt;
int main() {
	int i, j, k;
	cin >> s;
	for(i=0; s[i] && s[i]==t[i]; i++) cnt++;
	for(j=s.size()-1, k=6; j>i && s[j]==t[k]; j--, k--) cnt++;
	puts(cnt==7 ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ken = []
for i in range(m):
    p,y = map(int,input().split())
    ken.append([p,y,i+1])

k = sorted(ken)
a = []
cnt = 1
for i in range(m):
    if i >= 1:
        if k[i][0] == k[i-1][0]:
            cnt += 1
        else:
            cnt = 1
    a.append([k[i][-1],k[i][0],cnt])
    
aa = sorted(a)
b = []
for i in range(m):
    b.append([aa[i][1],aa[i][2]])

for i in range(m):
    print("{0:06d}".format(b[i][0]) + "{0:06d}".format(b[i][1]))

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 200010;
int N;
ll ret;
int pos[MN];

int main() {
	cin >> N;
	set<int> s;

	rep(i, N) {
		int x;
		cin >> x;
		pos[x] = i;
		s.insert(i);
	}
	s.insert(N);
	s.insert(-1);

	for (int i = N; i >= 1; --i) {
		s.erase(pos[i]);		
		auto it = s.lower_bound(pos[i]);
		auto it2 = it; --it2;
		int l = pos[i], r = pos[i];
		ll t = (ll)(pos[i]-*it2)*(*it-pos[i]);
		ret += t * i;
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 10876
#include<stdio.h>

int main(){
    int i32_KthTerm[32] = {
         1, 1, 1, 2, 1, 2, 1, 5,
         2, 2, 1, 5, 1, 2, 1,14,
         1, 5, 1, 5, 2, 2, 1,15,
         2, 2, 5, 4, 1, 4, 1,51
    };
    int i32_KthTermLength = 32;
    int i32_InputK = 0;
    
    /* Standard Input */
    (void)scanf("%d", &i32_InputK);

    /* Answer */
    (void)printf("%d", i32_KthTerm[i32_InputK-1]);

    return 0;
}

Measured memory_bytes: 128
abc = input()
abc_int = int(abc)
prolist = []
chk = int(abc_int**0.5)+2
for c1 in range(chk):
	if abc_int % (c1+1) == 0:
		prolist.append(c1+1+abc_int//(c1+1)-2)
print(min(prolist))

Measured memory_bytes: 3064
#include<stdio.h>

#define MAX 100

void Selection(int N,int *A){

  int i;
  int j;
  int min;
  int cnt = 0;
  int temp;

  for(i = 0;i < N;i++){

    min = i;
    for(j = i;j < N;j++){
      if(A[j] < A[min]){
	min = j;
      }
    }
    if(min != i){
      temp = A[i];
      A[i] = A[min];
      A[min] = temp;
      cnt++;
    }
  }

  for(i = 0;i < N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[N-1]);
  printf("%d\n",cnt);
}

int main(){

  int i;
  int num;
  int A[MAX];

  scanf("%d",&num);

  for(i = 0;i < num;i++){
    scanf("%d",&A[i]); 
  }

  Selection(num,A);

  return 0;

}

Measured memory_bytes: 600
import sys
from sys import stdin
import numpy as np

N, M = map(int, input().split())
L, R = list(), list()
for i in range(M):
  l,r = stdin.readline().rstrip().split()
  L.append(int(l))
  R.append(int(r))

L = np.array(L)
R = np.array(R)

if R.min() - L.max() < 0:
  print(0)
else:
  print(R.min() - L.max() + 1)
  


Measured memory_bytes: 20788
i = gets.strip.to_i
r = case i.to_s.size
  when 1..3
    1000 - i
  when 4..Float::INFINITY
    _i = i.to_s.scan(/\d+\K\d{3}$/)[0].to_i
    _r = case _i
      when 0
        0
      else
        1000 - _i
      end
  when 0
    0
  end
puts r

Measured memory_bytes: 14384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
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 n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    while (true) {
        cin >> n >> k;
        if (n == 0 && k == 0) break;
        vector<string> a(n);
        map<string, bool> mm;
        rep(i, 0, n) cin >> a[i];
        sort(all(a));
        do {
            string sub = "";
            rep(i, 0, k) sub += a[i];
            mm[sub] = true;
        } while (next_permutation(all(a)));
        cout << mm.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 3408
import sys
n = int(input())

ansl = []
if n == 0:
    print("0")
    sys.exit()
while n:
    if n % -2 == 0:
        ansl.append("0")
    else:
        n -= 1
        ansl.append("1")
    n = n // -2

ansl.reverse()
print("".join(ansl))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
// #include <atcoder/all>

using boost::multiprecision::cpp_int;
using namespace std;
// using namespace atcoder;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
const long long MOD = 1e16+7;

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

typedef long long ll;
typedef pair<ll, ll> p;

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];

  vector<ll> nums(100);

  rep(i, n){
    ll cnt = 0;
    while(cnt < 100){
      nums[cnt] += (v[i] % 2);
      cnt++;
      v[i] /= 2;
    }
  }

  ll res = 0;
  for (ll i = 49; i >= 0; i--) {
    if(nums[i] * 2 < n && mint(2).pow(i).x <= k){
      res += mint(2).pow(i).x * (n - nums[i]);
      k -= mint(2).pow(i).x;
    }else{
      res += mint(2).pow(i).x * nums[i];
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 3960
# coding: utf-8
# Your code here!

while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        exit()
    else:
        count=0
        for a in range(1,n):
            for b in range(a+1,n):
                c=x-a-b
                if a<b and b<c and c<=n:
                    #print(a,b,c)
                    count+=1
        print(count)





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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int cnt = 1;
            int status = 0;
            for (int i = 0; i < n - 1; i++)
            {

                if (status > 0 && a[i + 1] - a[i] < 0)
                {
                    cnt++;
                    status = 0;
                    continue;
                }
                if (status < 0 && a[i + 1] - a[i] > 0)
                {
                    cnt++;
                    status = 0;
                    continue;
                }
                if (a[i] < a[i + 1]) status = 1;
                if (a[i] > a[i + 1]) status = -1;
            }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 19680
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
		}
	public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];

			var Aarray = retreiveLongArray().OrderByDescending(x=>x).ToArray();
			var Barray = retreiveLongArray().OrderByDescending(x => x).ToArray();
			var Carray = retreiveLongArray().OrderByDescending(x => x).ToArray();

			var a = 0;
			var b = 0;


			var bAns = Enumerable.Repeat((long)0, (int)N).ToArray();

			while (b <N && a < N) {
				if (Barray[b] <= Aarray[a]) {
					a++;
					continue;
				}
				bAns[b] = N - a;
				b++;
			}

			var bRuiseki = new long[N];
			bRuiseki[N - 1] = bAns[N - 1];
			for (var i = N-2; i >= 0; i--) {
				bRuiseki[i] = bAns[i] + bRuiseki[i + 1];
			}

			var b2 = 0;
			var c2 = 0;
			long ans = 0;

			while (b2 < N && c2 < N) {
				if (Carray[c2] <= Barray[b2]) {
					b2++;
					continue;
				}
				ans += bRuiseki[b2];
				c2++;
			}

			//答えの出力
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


Measured memory_bytes: 61812
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int n;
vector<vector<vector<double> > > dp;

double rec (int i, int j, int k) {
    eprintf("(%d,%d,%d)", i, j, k);
    if (i == 0 && j == 0 && k == 0) {
        return 0;
    } else if (dp[i][j][k] != 0) {
        return dp[i][j][k];
    } else {
        double tmp = n;
        if (i > 0) tmp += i * rec(i - 1, j, k);
        if (j > 0) tmp += j * rec(i + 1, j - 1, k);
        if (k > 0) tmp += k * rec(i, j + 1, k - 1);
        return dp[i][j][k] = tmp / (i + j + k);
    }
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    dp.resize(n + 1);
    rep (i, n + 1) {
        dp[i].resize(n + 1);
        rep (j, n + 1) {
            dp[i][j].resize(n + 1);
            rep (k, n + 1) dp[i][j][k] = 0;
        }
    }
    int a[3] = {};
    rep (i, n) {
        int x; cin >> x;
        a[x - 1]++;
    }

    printf("%.16lf\n", rec(a[0], a[1], a[2]));
    rep (i, 3) {
        eprintf("\n");
        rep (j, 3) {
            rep (k, 3) {
                eprintf("%lf ", dp[i][j][k]);
            }
            eprintf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 216192
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define ll long long
using namespace std;
ll mod=pow(10,9)+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll ans=0;
        vector<pair<ll,ll> > v;
        set<ll> s;
        for(ll i=1;i<=n;++i)
        {
            ll k,l,r;
            s.insert(-1*i);
            cin>>k>>l>>r;
            v.push_back(make_pair(l-r,k));
            ans+=l;
        }
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        ll index=-1;ll count=0;
        for(ll i=0;i<n;++i)
        {
            if(v[i].first < 0)
            {
                index=i;
                break;
            }
            ll num=v[i].second;
            set<ll>:: iterator it=s.lower_bound(num*-1);
            if(it!=s.end())
            {
               s.erase(it);
            }
            else
            {
                ++count;
                ans-=v[i].first;
            }
        }
        if(index==-1)
        {
            cout<<ans<<endl;
            continue;
        }
        s.clear();
        ll avai=index+1;
        avai-=count;
        for(ll i=avai;i<=n;++i)
        {
            s.insert(i);
        }
        for(ll i=n-1;i>=index;--i)
        {
            ll num=v[i].second;
            set<ll>:: iterator it=s.upper_bound(num);
            if(it!=s.end())
            {
               s.erase(it);
               ans+=(v[i].first*-1);
            }
           
        }

        cout<<ans<<endl;

    }
}


Measured memory_bytes: 15748
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    vector<int> a(n);
    for (auto i = 0; i < n; i++) cin >> a[i];

    int ans = a[0];
    for (auto i = 1; i < n; i++) {
        ans = __gcd(ans, a[i]);
    }

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

Measured memory_bytes: 640
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	El3zba;
	int n;
	cin >> n;
	vector<int>a(n);
	LL mx = 0;
	int idx = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] >= mx)
		{
			mx = a[i];
			idx = i;
		}
	}
	for (int i = 1; i < n; i++)
	{
		if (a[i] < a[i - 1])
		{
			int dif = abs(a[i] - a[i - 1]);
			if (dif > 1)return cout << "No\n", 0;
			else
			{
				a[i]++;
				if (a[i]<mx&&i>idx)
					return cout << "No\n", 0;
				else if (a[i] >= mx)
				{
					mx = a[i];
					idx = i;
				}
			}
		}
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 640
N=int(input())
A=[]
B=[]
for _ in range(N):
    a=int(input())
    A.append(a)
    B.append(a)

B.sort()

max_a = B[N-1]
max_dup = False
if B[N-2] == max_a:
    max_dup = True
second_max_a = -1
for i in range(N-1,-1,-1):
    if B[i] < max_a:
        second_max_a = B[i]
        break

for a in A:
    if a < max_a:
        print(max_a)
    elif max_dup:
        print(max_a)
    else:
        print(second_max_a)

Measured memory_bytes: 81880
#include <stdio.h>
#include <stdlib.h>

int main() {
    long i, n, done = 0, place, temp;
    long b[101], sub[101];

    scanf("%ld", &n);

    b[0] = 0;
    sub[0] = 0;
    for (i=1; i<=n; i++) {
        scanf("%ld", &b[i]);
        sub[i] = 0;
    }

    while (done < n) {
        place = n - done;
        temp = place;
        for (i = n; i >= 1; i--) {
            if (b[i] == 0) {
                continue;
            }
            if (place == b[i]) {
                sub[n-done] = place;
                b[i] = 0;
                done++;
                break;
            }
            place--;
        }
        if (temp == n - done) {
            printf("-1\n");
            return 0;
        }
    }

    for (i = 1; i <= n; i++) {
        printf("%ld\n", sub[i]);
    }

    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	int n; cin >> n;
	ll x[1005],y[1005];
	int mod;
	for (int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		if(i==0)mod=abs(x[i]+y[i])%2;
		else if(mod!=abs(x[i]+y[i])%2){
			cout<<-1<<endl;
			return 0;}}
	vector<string> w(n,""),p(n,"");
	if(mod==0){
		cout<<32<<endl<<1<<" ";
		for(int i=0;i<=30;i++)cout<<(1<<i)<<" ";
		for (int i=0;i<n;i++){
			p[i]+="R";
			x[i]-=1;
		}
	}else{
		cout <<31<<endl;
		for (int i=0;i<=30;i++)cout<<(1<<i)<<" ";
    }
	cout<<endl;
	for(int i=0;i<n;i++){for (int j=30;j>=0;j--){
			ll d=1<<j;
			ll nx=d-1;
			if(abs(x[i]-d)+abs(y[i])<=nx){
				w[i]="R"+w[i];x[i]-=d;
			}else if(abs(x[i]+d)+abs(y[i])<=nx){
				w[i]="L"+w[i];x[i]+=d;
			}else if(abs(x[i])+abs(y[i]+d)<=nx){
				w[i]="D"+w[i];y[i]+=d;
			}else if(abs(x[i])+abs(y[i]-d)<=nx){
				w[i]="U"+w[i];y[i]-=d;
			}}cout<<p[i]+w[i]<<endl;}
	return 0;
}


Measured memory_bytes: 384
N =  int(raw_input())
B = list(map(int, raw_input().split())) 
A = [0]*N
A[0] = B[0]
A[1] = B[0]
for i in range(1,N-1):
  if A[i] > B[i]:
    A[i] = B[i]
    A[i+1]= B[i]
  else:
    A[i+1] = B[i]
  
print sum(A)  

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

int main(){
		int a,b,c,t;
		cin >> a>>b>>c;
		if(a>b){
			t=a;
			a=b;
			b=t;
				}
			if(b>c){
				t=b;
				b=c;
				c=t;
					}
				if(a>b){
					t=a;
					a=b;
					b=t;
						}
			cout<<a<<" "<<b<<" "<<c<<endl;
}

Measured memory_bytes: 1164
program main
 implicit none
 character(len=6) S
 character(len=1) a(6)
 integer i

 read *, S

 do i=1,6
  a(i)=S(i:i)
 end do

 if (a(3)==a(4) .and. a(5)==a(6) ) then
  print '(A)', 'Yes'
 else
  print '(A)', 'No'
 end if

endprogram main


Measured memory_bytes: 256
#include<iostream>
#define re register
using namespace std;
int da[100005];
int ans[100005];
long long add;
int main(){
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	for(int i = 1;i<=N;i++){
		cin >> da[i];
		add += da[i];
	}
	ans[N] = add;
	for(int i = 1;i<=N-2;i+=2){
		ans[N] -= (da[i] << 1);
	}
	for(int i = N-1;i>=1;i--){
		ans[i] = (da[i] - ((ans[i+1])>>1))<<1;
	}
	for(int i = 1;i<=N;i++){
		cout << ans[i] <<' ';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
using namespace std;
int main()
{
	int s,fir,end;
	scanf("%d",&s);
	fir=s/100;
	end=s%100;
	if(fir>0&&fir<13&&end>0&&end<13)
	printf("AMBIGUOUS");
	else if(fir>0&&fir<13)
	printf("MMYY");
	else if(end>0&&end<13)
	printf("YYMM");
	else printf("NA");
	return 0;
 } 

Measured memory_bytes: 256
s=input()

s=list(s)

b=[]

for i in range(len(s)):
    if(s[i]=="0"):
        b.append(0)
    elif(s[i]=="1"):
        b.append(1)
    elif(s[i]=="B"):
        if(len(b)!=0):
            b.pop(-1)

#b.reverse()

c=str(b)
c=c.replace(",","")
c=c.replace("[","")
c=c.replace("]","")
c=c.replace(" ","")

print(c)
        


Measured memory_bytes: 3064
#include <stdio.h>
int n,k;
long long a[20];
long long b[20];
int cnt;
long long min(long long a, long long b){
	return a<b?a:b;
}
long long f(int x){
	long long res = 1e9;
	res = res * res;
	if(x==n+1){
		if(cnt < k){
			return res;
		}
		long long ans = 0;
		long long max_height = a[1];
		int cur_cnt = 1;
		if(b[cur_cnt]==1) cur_cnt++;
		for(int i=2;i<=n;i++){
			if(cur_cnt > cnt) break;
			if(i==b[cur_cnt]){
				if(max_height >= a[b[cur_cnt]]){
					ans+=max_height-a[b[cur_cnt]]+1;
					max_height++;
				} else {
					max_height = a[b[cur_cnt]];
				}
				cur_cnt++;
			} else {
				if(max_height < a[i]){
					max_height = a[i];
				}
			}
		}
		return ans;
	}
	res = min(res,f(x+1));
	b[++cnt] = x;
	res = min(res,f(x+1));
	cnt--;
	return res;
}
int main(){
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	printf("%lld\n",f(1));
}

Measured memory_bytes: 1708
//%std
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
int main()
{
	int x=read()+read()+read();
	if(x>=22)
		puts("bust");
	else
		puts("win");
	return 0;
}


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


int main() {
  int x;
  cin>>x;
  int y=x%10;
  if(y==2 || y==4 || y==5 || y==7 || y==9) {
    cout<<"hon";
    return 0;
  }
  if(y==0 || y==1 || y==6 || y==8) {
    cout<<"pon";
    return 0;
  }
  cout<<"bon";
  return 0;
}

Measured memory_bytes: 3556
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int n,cnt;cin>>n;
    bool f=false;
    vector<vector<int>> res(2*n);
    for(int i=1;i<=2*n;i++){
        if((2*n)%i!=0) continue;
        if(2*n/i-1 != i) continue;
        cnt=2*n/i;
        int idx=1;
        f=true;
        for(int j=0;j<2*n/i;j++){
            for(int k=0;k<i-j;k++){
                res[j].push_back(idx);
                res[j+k+1].push_back(idx);
                idx++;
            }
        }
        break;
    }
    if(!f){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    cout<<cnt<<endl;
    for(int i=0;i<cnt;i++){
        int sz=res[i].size();
        cout<<sz;
        for(int j=0;j<sz;j++){
            cout<<" "<<res[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 7040
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

class AABProblem {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll n,a,b;
	    in>>n>>a>>b;
	    if(a>b){
	        out<<0<<endl;
            return;
	    } else if(n==1 && a!=b){
	        out<<0<<endl;
            return;
	    } else if(n==1){
	        out<<1<<endl;
            return;
	    }

	    out<<(b-a)*(n-2)+1<<endl;




	}
};


int main() {
	AABProblem solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 2005
using namespace std;
typedef long long ll;
int n,k,a,b,tot,Maxde,deep[N],sum,ans=0x7fffffff;
int head[N],to[N<<1],nex[N<<1],fa[N],de[N];
int leaves[N],tmp;
void add(int x,int y)
{
	to[++tot]=y;
	nex[tot]=head[x];
	head[x]=tot;
}
void dfs(int x,int fath)  //O(n)
{
	fa[x]=fath;
	de[x]=de[fath]+1;
	deep[de[x]]++;
	Maxde=max(Maxde,de[x]);
	for(int i=head[x];i;i=nex[i])
	{
		if(to[i]==fath) continue;
		dfs(to[i],x);
	}
}
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n-1;i ++)
	{
		scanf("%d %d",&a,&b);
		add(a,b);add(b,a);
	}
	de[0]=-1;
	if(k&1)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=head[i];j;j=nex[j])
			{
				memset(deep,0,sizeof(deep));
				Maxde=sum=0;
				de[to[j]]=-1; dfs(i,to[j]);
				de[i]=-1; dfs(to[j],i);
				for(int j=k/2+1;j<=Maxde;j++)
				{
					sum+=deep[j];
				}
				ans=min(ans,sum);
			}
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			memset(deep,0,sizeof(deep));
			sum=Maxde=0;
			dfs(i,0);
			for(int j=k/2+1;j<=Maxde;j++)
			{
				sum+=deep[j];
			}
			ans=min(sum,ans);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        Console.WriteLine(ReadInt() >= 30 ? "Yes" : "No");
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
}


Measured memory_bytes: 28316
# coding: utf-8
# Your code here!

n =int(input())
s=input()


for i in range(len(s)):
    if(ord(s[i])+n>90):
        print(chr(ord(s[i])+n-26), end="")
    else:
        print(chr(ord(s[i])+n), end="")
    


Measured memory_bytes: 4468
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
  ll a,b,c,d,flag=0;
  cin>>a>>b>>c>>d;
  while(a>0 && c>0)
  {
      if(flag==0)
      {
          c=c-b;
          flag=1;
      }
      else
      {
          a=a-d;
          flag=0;
      }
  }
  if(a>0)
    cout<<"Yes";
  else
  cout<<"No";
    return 0;
}

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

typedef long long ll;

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

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

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

string last = "zyxwvutsrqponmlkjihgfedcba";

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	if(n == 26){
		if(s == last){
			ANS(-1);
		}else{
			vector<char> kouho;
			FORR(i,n-1,1){
				kouho.pb(s[i]);
				if(s[i-1] < s[i]){
					//cout << i << "\n";
					sort(ALL(kouho));
					FOR(j,0,(int)kouho.size()){
						if(kouho[j] > s[i-1]){
							kouho[0] = kouho[j];
							break;
						}
					}
					s = s.substr(0, i-1) + kouho[0];
					break;
				}
			}
			ANS(s);
		}
	}else{
		bool used[26];
		FOR(i,0,26)used[i] = false;
		FOR(i,0,n)
			used[s[i] - 'a'] = true;
		FOR(i,0,26){
			if(!used[i]){
				s += 'a' + i;
				break;
			}
		}
		ANS(s);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 


int main(){

	int n,l;
	cin>>n>>l;

	vector<string> a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++) cout<<a[i];
	cout<<endl;

}

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

int main(){
	int a, b;
	char op;
	
	while(1){
		cin >> a >> op >> b;

		if (op == '+'){
			cout << a + b << endl;
		}
		else if (op == '-'){
			cout << a - b << endl;
		}
		else if (op == '*'){
			cout << a*b << endl;
		}
		else if (op == '/'){
			cout << a / b << endl;
		}
		else {
			break;
		}
	}
	return 0;
}

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

int main(){
	int N;
	cin >> N;
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			if(i*4 + j*7 == N){
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";

	return 0;
}

Measured memory_bytes: 256
nm = raw_input().split()
n = int(nm[0])
m = int(nm[1])
d = raw_input().split()

c = [0] * 100000
c[0] = 0

for i in range(n):
    min = 100000
    for j in range(m):
        if int(d[j]) < i + 2:
            x = c[i + 1 - int(d[j])]
            if x < min:
                min = x
    c[i + 1] = min + 1

print c[n]

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    vector<ll> s(n),b(0);
    ll x = 0;
    for(int i = 0;i < n;i ++){
        ll a;
        cin >> a;
        if(i==0) s[i] = a; 
        else s[i] = s[i-1] + a;
    }
    for(int i = 0;i < n;i ++){
        for(int j = i;j < n;j ++){
            if(i==0) b.push_back(s[j]);
            else b.push_back(s[j]-s[i-1]);
        }
    }
    for(int i = 39;i >= 0;i --){
        int cnt = 0;
        ll y = pow(2,i);
        for(int j = 0;j < b.size();j ++){
            if(((x+y)&b[j])==(x+y)) cnt ++;
        }
        if(cnt>=k) x += y;
    }
    cout << x << endl;

    return 0;
}

Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1e9+7
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int a[n];
	for(int i= 0; i < n; i++) cin >> a[i];
	int dp[n + 2];
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for(int i= 2; i < n; i++){
		dp[i] = min(abs(a[i] - a[i -2]) + dp[i -2], abs(a[i] - a[i -1] )+ dp[i -1]);
	}
	cout<<dp[n - 1];
}

Measured memory_bytes: 4436
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include <iomanip>
#include <unordered_map>

using namespace std;

#define ll long long int

bool is_palindrome(string t)
{
    string x;
    x=t;
    reverse(t.begin(),t.end());
    return (x==t);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s, a , b;
    int sz;
    cin>>s;
    sz=s.size();
    a=s.substr(0,sz/2);
    b=s.substr(sz/2 + 1, sz/2);
    if(is_palindrome(s) && is_palindrome(a) && is_palindrome(b)) cout<<"Yes";
    else cout<<"No";

 }


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

using namespace std;

int main(){
  int n;
  string s;
  cin>>n>>s;
  if(n%2!=0) cout<<"No"<<endl;
  else if(s.substr(0,n/2)==s.substr(n/2,n)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
main :: IO ()
main = do
    [n,t] <- map read . words <$> getLine :: IO [Integer]
    ts <- map read . words <$> getLine :: IO [Integer]
    let m = sum $ map (\n -> max 0 (-(n - t))) $ f ts
    print $ n*t - m

f (n:m:ns) = m - n : f (m:ns)
f _ = []

Measured memory_bytes: 70012
#include<iostream>
using namespace std;
int main() {
	int a,b;
	cin>>a>>b;
	if(a<=0 && b>=0) {
		cout<<"Zero"<<endl;
		return 0;
	}
	if(a>0) {
		cout<<"Positive"<<endl;
		return 0;
	}
	int n;
	n=min(b,-1)-a+1;
	if(n%2==0) {
		cout<<"Positive"<<endl;
	}
	else {
		cout<<"Negative"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int ans=MAX,cnt=MAX;
  string S;
  cin>>S;
  int Q[26][S.size()+1];
  for(int i=0; i<26; ++i){
    for(int j=0; j<=S.size(); ++j){
      Q[i][j]=0;
    }
  }
  
  for(int t=0; t<26; ++t){
    char L='a'+t;
    for(int i=0; i<S.size(); ++i){
      Q[t][i+1]=Q[t][i];
      if(S.at(i)==L) Q[t][i+1]++;
    }
  }
  
  for(int t=0; t<26; ++t){
    char L='a'+t;
    for(int i=1; i<=S.size(); ++i){
      bool CAN=true;
      for(int j=0; j<=S.size()-i; ++j){
        if(Q[t][j+i]-Q[t][j]<=0) CAN=false;
      }
      if(CAN) chmin(ans,i-1);
    }
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,cnt=0,maxn=0;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<=n;i++)
	{
		if(s[i]=='I') cnt++;
		if(s[i]=='D') cnt--;
		maxn=max(maxn,cnt);
	}
	cout<<maxn<<endl;
	return 0;
}

Measured memory_bytes: 256
def func(d, c):
    color = [[0 for _ in range(len(d))] for _ in range(3)]
    for i in range(len(c)):
        for j in range(len(c)):
            color[(i + j) % 3][c[i][j]] += 1
    # print("color:{}".format(color))
    _min = 10**10
    for i in range(len(d)):
        # %3==0を色iにする場合
        cost1 = sum([d[prev][i]*color[0][prev] for prev in range(len(color[0]))])
        for j in range(len(d)):
            if i == j:
                continue
            # %3==1を色jにする場合
            cost2 = sum([d[prev][j] * color[1][prev] for prev in range(len(color[0]))])
            for k in range(len(d)):
                if i == k or j == k:
                    continue
                # %3==2を色kにする場合
                cost3 = sum([d[prev][k] * color[2][prev] for prev in range(len(color[0]))])
                _min = min(_min, cost1+cost2+cost3)
                # print("->{} cost1:{} ->{} cost2:{} ->{} cost3:{} total:{}".format(i, cost1, j, cost2, k, cost3, cost1+cost2+cost3))
    return _min
n, C = [int(i) for i in input().split()]
d = [[0 for _ in range(C)] for _ in range(C)]
c = [[0 for _ in range(n)] for _ in range(n)]
for i in range(C):
    d[i] = [int(i) for i in input().split()]
for i in range(n):
    c[i] = [int(i) - 1 for i in input().split()]
print(func(d, c))
"""
# print("print(func({},{}))".format(d, c))
print(func([[0, 1, 1], [1, 0, 1], [1, 4, 0]],[[0, 1], [2, 2]]))
print(func([[0, 12, 71], [81, 0, 53], [14, 92, 0]],[[0, 0, 1, 0], [1, 0, 0, 1], [1, 1, 0, 2], [0, 0, 1, 1]]))
"""


Measured memory_bytes: 5236
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return x*f;
}
string ch[N];
char str[20];
int main()
{
	int n;
	n=read();
	for(int i=1;i<=n;i++)
	{
		scanf("%s",str);
		sort(str,str+10); 
		for(int j=0;j<10;j++)ch[i]+=str[j];
	}
	sort(ch+1,ch+n+1);
	long long num=0,ans=0;
	for(int i=1;i<n;i++)
	{
		if(ch[i]==ch[i+1])num++;
		else 
		{
			ans+=(1+num)*num/2;
			num=0;
		}
	}
	ans+=(1+num)*num/2;
	printf("%lld",ans);
	return 0;
 } 
 /*
10
oneplustwo
ninemodsix
acornistnt
peanutbomb
constraint
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
 */

Measured memory_bytes: 7296
N, K = map(int,input().split())
X = list(map(int,input().split()))

Xr = [0]
Xl = [0]

for x in X:
    if x>=0:
        Xr.append(x)
    else:
        Xl.append(-x)
Xl.sort()

S = []
for i in range(K+1):
    r = i
    l = K-i
    if r<=len(Xr)-1 and l<=len(Xl)-1:
        S.append(2*min(Xr[r],Xl[l]) + max(Xr[r],Xl[l]))
    
print(min(S))

Measured memory_bytes: 14252
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>

#define true 1
#define false 0

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)

//グローバル変数のつもり
int count=0;

//訪れるノードの順番をn!の順列で考える。
//さらに(n,n)行列に(i,j)がエッジで繋がっているかの情報を保持。

//順列を作る再帰関数
void jyun(int *t, int n, int N, int **linking);
//配列が一筆書きを満たしているか否かを判定する。true or false
int judge(int *t, int N, int **linking);


void jyun(int *t, int n, int N, int **linking){
  if(n<2){
    //一つの順列が完成
    count=count+judge(t, N, linking);
    // if(judge(t, N, linking)==true){
    //   printf("t[N] = ");
    //   rep(i,N){
    //     printf("%d ",t[i]);
    //   }
    //   printf("\n");
    // }
    return ;
  }

  int k,temp;
  k=n-1;
  rrep(i,n){
    temp=t[k];
    t[k]=t[i];
    t[i]=temp;
    jyun(t, k, N, linking);
    t[i]=t[k];
    t[k]=temp;
  }
}


int judge(int *t, int N, int **linking){
  int flag=1;
  if(t[0]!=0){
    flag=0;
  }
  rep(i,N-1){
    if(linking[t[i]][t[i+1]]==false){
      flag=0;
    }
  }

  return flag;
}


int main(){
  char buf[1024];
  int N,M;

  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%d %d", &N, &M);

  int *t=(int *)malloc(sizeof(int)*N);
  rep(i,N){
    t[i]=i;
  }
  //ノードは 0~N-1

  int **Sides=(int **)malloc(sizeof(int *)*M);
  rep(i,M){
    Sides[i]=(int *)malloc(sizeof(int)*2);
  }

  rep(i,M){
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d %d", &Sides[i][0], &Sides[i][1]);
  }

  //ノードは0~Nであることに注意して
  rep(i,M){
    Sides[i][0]--;
    Sides[i][1]--;
  }


  //ノードiとノードjがエッジで繋がっているかの判定。true or false
  //linkingは (N,N) 行列
  int **linking=(int **)malloc(sizeof(int *)*N);
  rep(i,N){
    linking[i]=(int *)malloc(sizeof(int)*N);
  }
  rep(i,N){
    rep(j,N){
      if(i==j){
        linking[i][j]=true;
      }
      else{
        linking[i][j]=false;
      }
    }
  }

  rep(i,N){
    rep(j,M){
      if(Sides[j][0]==i){
        linking[i][Sides[j][1]]=true;
      }
      else if(Sides[j][1]==i){
        linking[i][Sides[j][0]]=true;
      }
    }
  }

  // rep(i,N){
  //   rep(j,N){
  //     printf("%d ", linking[i][j]);
  //   }
  //   printf("\n");
  // }


  jyun(t, N, N, linking);

  printf("%d\n",count);

  return 0;
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        GrandGarden solver = new GrandGarden();
        solver.solve(1, in, out);
        out.close();
    }

    static class GrandGarden {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }

            long result = 0;
            int i = 0;
            while (i < n) {
                if (h[i] == 0) {
                    i++;
                    continue;
                }
                int v = 1;
                result += 1;
                h[i] -= v;
                for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                }
            }
            out.print(result);
        }

    }
}



Measured memory_bytes: 35996
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int pop();
int main(){
  int i,now=0,n,remain,q,time[100000];
  char name[100000][10];
  scanf("%d %d",&n,&q);
  remain =n;
  for(i=0;i<n;i++) scanf("%s %d",name[i],&time[i]);
    i=0;
  while(remain!=0){
	if(now==n) now=0;
    if(time[now]<=0){
      while(time[now]<=0) {
	now++;
	if(now==n) now=0;
      }
      
    }
    if(time[now] -q <= 0){
      printf("%s %d\n",name[now],i + time[now]);
      i+=time[now];
      remain--;
      time[now]-=q;
      continue;
    }
    time[now]-=q;
    i+=q;
    now++;
  }
}


Measured memory_bytes: 2392
#include<iostream>
using namespace std;
int main(){
char c11,c12,c13;
char c21,c22,c23;
char c31,c32,c33;

 cin>>c11>>c12>>c13;
 cin>>c21>>c22>>c23;
 cin>>c31>>c32>>c33;

 cout<<c11<<c22<<c33<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;

int main(){
  int n;
  cin >> n ;
  vector<vector<bool>>honest(n,vector<bool>(n)),unkind(n,vector<bool>(n));
  
  rep(i,n){
    int a;
    cin >> a;
    rep(j,a){
      int x,y;
      cin >> x >> y;
      x--;
      if(y==1)honest[i][x]=true;
      else unkind[i][x]=true;
    }
  }
  int ans=0;
  for(int bit=0;bit<(1<<n);bit++){
    bool ok = true;
    int count_honest=0;
    rep(i,n){
      if(!(bit&(1<<i)))continue;
      count_honest++;
      rep(j,n){
        if(bit&(1<<j)){
          if(unkind[i][j]) ok=false;
        }
        else{
          if(honest[i][j]) ok = false;
        }
      }
    }
    if(ok)ans=max(ans,count_honest);  
  }     
  cout<<ans<<endl;
}
    

Measured memory_bytes: 256