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

#define fi                      first
#define se                      second
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x)                   ((int)x.size())

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void solve();

int32_t main()
{
        fast;
        int t = 1;
        // cin >> t;
        for(int i = 1; i <= t; ++i)
                solve();
        cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}

const int N = 1e6+2;
int a[N],n,u,v;
std::vector<int> adj[N];

void dfs(int node,int pre,int dis) {
	a[node] = dis;
	for(auto i:adj[node]) {
		if(i != pre) {
			dfs(i,node,dis+1);
		}
	}
}

int ans = 0;

void dfs2(int node,int pre, int dis) {
	ans = max(ans,a[node] - (1));
	for(auto i:adj[node]) {
		if(i != pre and (dis+1) <= a[i]) {
			dfs2(i,node,dis+1);
		}
	}
}


void solve() {

	cin >> n >> u >> v;
	for(int i = 0; i < n-1; ++i) {
		int p,q;
		cin >> p >> q;
		adj[p].pb(q);
		adj[q].pb(p);
	}
	dfs(v,-1,0);
	dfs2(u,-1,0);
	cout << ans << endl;
}

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

void Insertion(int a[], int n) {
    for (int i = 1; i < n; i++) {
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > v) {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for (int j = 0; j < n; j++) {
            cout << a[j]; 
            if (j != n - 1) cout << ' ';
        }
        cout << endl;
    }
}

int main() {
    int n; cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cout << a[i];
        if (i != n - 1) cout << ' ';
    }
    cout << endl;
    Insertion(a, n);
}


Measured memory_bytes: 3076
N, M, K = map(int, input().split())
AStr = input().split()
BStr = input().split()

A = []
B = []

tmp = 0
for i in AStr:
    tmp += int(i)
    if (tmp > K):
        break
    A.append(int(i))

tmp = 0
maxB = 0
for i in BStr:
    tmp += int(i)
    if (tmp > K):
        break
    B.append(int(i))
    maxB = tmp

num = 0
tmp = 0
maxNum = len(A)
if maxNum < len(B):
    maxNum = len(B)

numB = len(B)
tmpj = 0
for i in range(len(A)+1):
    if i != 0:
        tmpj += A[i-1]

    while (tmpj + maxB > K):
        a = B.pop()
        maxB -= a
        numB -= 1

    if i + numB > maxNum:
        maxNum = i + numB

print(maxNum)


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

int G[200][200];
int A[201];

int main() {
	int n,m,r;
	cin >> n >> m >> r;
	for(int i=0;i<r;i++){
		cin >> A[i];
		A[i]--;
	}
	sort(A,A+r);
	
	memset(G, 0x3f, sizeof(G));
	int a,b,c;
	for(int i=0;i<m;i++){
		cin >> a >> b >> c;
		a--,b--;
		G[a][b] = G[b][a] = c;
	}
	
	for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++){
		G[i][j]=min(G[i][j], G[i][k]+G[k][j]);
	}
	
	int sum,MN=1e9;
	do{
		sum=0;
		for(int i=0;i<r-1;i++){
			sum+=G[A[i]][A[i+1]];
		}
		MN=min(MN,sum);
	}while(next_permutation(A,A+r));
	

	cout << MN << endl;
	return 0;
}

Measured memory_bytes: 384
// https://atcoder.jp/contests/abc079/tasks/abc079_c
#include <bits/stdc++.h>
using namespace std;

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

int main() {
  string S;
  cin >> S;
  int len = S.size() - 1;

  rep(bit, 1 << len) {
    int ans = S[0] - '0';
    string s;
    s += S[0];
    rep(i, len) {
      char n = S[i + 1];
      if (bit & (1 << i)) {
        ans += n - '0';
        s += '+';
      } else {
        ans -= n - '0';
        s += '-';
      }
      s += n;
    }
    if (ans == 7) {
      cout << s << "=7" << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
//author Forsaken
#define Hello the_cruel_world!
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#include<numeric>
#define max(x,y) ((x) > (y) ? (x) : (y))
#define min(x,y) ((x) < (y) ? (x) : (y))
#define lowbit(x) ((x) & (-(x)))
#define FRIN freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\1.in", "r", stdin)
#define FROUT freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\1.out", "w", stdout)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define outd(x) printf("%d\n", x)
#define outld(x) printf("%lld\n", x)
#define memset0(arr) memset(arr, 0, sizeof(arr))
#define il inline
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 1e5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const double Pi = acos(-1.0);
il int read_int() {
	char c;
	int ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
il ll read_ll() {
	char c;
	ll ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
il ll quick_pow(ll base, ll index, ll p) {
	ll res = 1;
	while (index) {
		if (index & 1)res = res * base % p;
		base = base * base % p;
		index >>= 1;
	}
	return res;
}
int n, k, m;
int L[2 * maxn + 5], R[2 * maxn + 5];
int dp[105][maxn + 5];
int main()
{
	n = read_int(), k = read_int();
	for (int l = 1, r = 0; l <= n; l = r + 1) {
		r = n / (n / l);
		L[++m] = l;
		R[m] = r;
	}
	for (int i = 1; i <= m; ++i)dp[1][i] = (dp[1][i - 1] + (R[i] - L[i] + 1)) % mod;
	for (int i = 2; i <= k; ++i)
		for (int j = 1; j <= m; ++j) {
			dp[i][j] = (dp[i][j - 1] + (dp[i - 1][m - j + 1]) * 1LL * (R[j] - L[j] + 1) % mod) % mod;
		}
	outd(dp[k][m]);
	//system("pause");
	return 0;
}

Measured memory_bytes: 40704
s = input()
first = int(s[:2])
second = int(s[2:])
fv = (1 <= first <= 12)
sv = (1 <= second <= 12)
if fv and sv:
    print('AMBIGUOUS')
elif fv and not sv:
    print('MMYY')
elif not fv and sv:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define forn(i,n) for(int i=0;i<(n);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define fordec(i,a,b) for(int i=(a);i>=(b);i--)
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double>
#define vs vector<string>
#define pb push_back
#define vpi vector<pair<int, int>
#define vpl vector<pair<ll, ll>>
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); }
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////

int main()
{
    ios::sync_with_stdio(0);
	cin.tie(0);
    string s, t; cin >> s >> t;
  	int count = 0;
  	forn(i, s.size()) {
     if (s[i] == t[i]) count++; 
    }
  	cout << count;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define pb push_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int N;cin>>N;
    int A[N];
    REP(i,N)cin>>A[i];
    int cost=INF;
    for(int i=-100;i<=100;i++){
        int pre=0;
        REP(j,N){
            pre+=(i-A[j])*(i-A[j]);
        }
        cost=min(cost,pre);
    }
    cout<<cost<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  vector<vector<bool>> dp(F + 1, vector<bool>(F + 1, false));
  dp[0][0] = true;
  rep(water, F + 1) rep(sugar, F + 1)
  {
    if (dp[water][sugar])
    {
      if (water + 100 * A <= F)
        dp[water + 100 * A][sugar] = true;

      if (water + 100 * B <= F)
        dp[water + 100 * B][sugar] = true;

      if (sugar + C <= F)
        dp[water][sugar + C] = true;

      if (sugar + D <= F)
        dp[water][sugar + D] = true;
    }
  }

  pair<int, int> ans = make_pair(0, 0);
  rep(w, F + 1) rep(s, F + 1)
  {
    if (w + s > F || !dp[w][s] || E * w / 100 < s)
      continue;

    if (s * ans.first >= (s + w) * ans.second)
      ans = make_pair(w + s, s);
  }

  cout << ans.first << " " << ans.second << endl;
  return 0;
}

Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

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

ll N;
vector<int> b, ans;

int main() {

	scanf("%lld", &N);
	b.resize(N);
	rep(i, N) scanf("%d", &b[i]);

	for (int i = N - 1; i >= 0; --i) {
		for (int j = i; j >= 0; --j) {
			if (b[j] == j + 1) {
				b.erase(b.begin() + j);
				ans.push_back(j + 1);
				break;
			}
		}
	}

	if (b.size()) printf("-1\n");
	else {
		rep(i, N) printf("%d\n", ans[N - 1 - i]);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long int ll;
using namespace std;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string S,T;
cin>>S>>T;
int cnt=0;
rep(i,3){
    if(S[i]==T[i])cnt++;
}
cout<<cnt<<endl;

//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int s[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};

int disp(int a, int b){
	for(int i = a+1;;i++){
		cout << " " << s[i%15];
		if(s[i%15] == b){cout << endl;return 0;}
	}
	return 0;
}

int main(){
	int n, a, b;cin >> n;
	while(n--){
		cin >> a >> b;
		cout << a;
		if(6 <= a && a <= 9)disp(a, b);
		else disp(0 < b-a ? a : 15-a, b);
	}
	return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ote(x) cout<<(x)<<endl

ll solve(int N, int M){
	ll ans = 0;
	if(N == 1 && M == 1) ans = 1L;
	else if(N == 1) ans = (ll)M - 2;
	else if(M == 1) ans = (ll)N - 2;
	else ans = (ll)(N-2) * (M-2);
	return ans;
}

int main(){
	int N,M; cin>>N>>M;
	ote(solve(N, M));
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int t = stdIn.nextInt();
        //int n = stdIn.nextInt();
        //int p = stdIn.nextInt();
        
        System.out.println(t / a * b);
        
        //System.out.println();
        //System.out.print();
    }
}


Measured memory_bytes: 21716
/*
                " اللهم صلي و سلم علي سيدنا محمد و علي اله وصحبه اجمعين "
*/

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define f for
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define intial(s1,s2,x,dp) f(int i = 0; i < s1; i++)f(int j = 0; j < s2; j++)dp[i][j] = x;
using namespace std;
#define BI  acos(-1)
#define all(a) a.begin(), a.end()
#define loop1(n) f(int i=0;i<n;i++)
#define loop2(n) f(int j=0;j<n;j++)
#define oo 1e9;
void Open()
{
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
void madesetprobblem()
{
    //$ $
    //less than or equal => $ 1 \leq 100 $
    //  $(1 \le A,B \le 10^5 )$
    // a[i] => $a_i$
    // a[i][j] => $a_{i,j}$
    // double qoutes ''yext''
    /*
        image
        \begine{center}
        \includegraphics{image.jpg}
        \end{center}
    */
    /*
        list
        \begin{itemize}
            \item first one
            \item second one
        \end{itemize}
    */
}
int n,k,*a;
int dp[100001][3];
int ans(int x,int p)
{
  //  cout<<x<<' ';
    int& ret=dp[x][p];
    if(~ret)return ret;
    ret=!p;
    loop1(n)
    {
        if(x-a[i]>=0)
        {
            if(ans(x-a[i],!p)==p)
                ret=p;
        }
    }
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin>>n>>k;
    a=new int[n];
    loop1(n)cin>>a[i];
    cout<<(ans(k,0)?"Second":"First");
}


Measured memory_bytes: 12608
#include <iostream>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

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

int dfs(int i, vector <vector<int>> &graph, vector<int> &dp) {
  int len = 0;
  if (dp[i] != -1) return dp[i];
  for (int j = 0; j < graph[i].size(); j++) {
    len = max(len, dfs(graph[i][j], graph, dp) + 1);
  }
  dp[i] = len;
  return dp[i];
}

int main() {
  int n, m;
  cin >> n >> m;
  vector< vector<int>> graph(n);
  vector<int> dp(n, -1);
  for (int i = 0; i < m; i++) {
    int j, k;
    cin >> j >> k;
    graph[j-1].push_back(k-1);
  }
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < graph[i].size(); j++) {
  //     cout << "i: " << i << " " << graph[i][j] << endl;
  //   }
  // }
  for (int i = 0; i < n; i++) {
    dfs(i, graph, dp);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;

}


Measured memory_bytes: 8832
import itertools
N, M, R = map(int, input().split())
r = [int(x) - 1 for x in input().split()]
G = [[10 ** 7 for j in range(N)] for i in range(N)]
for i in range(N):
  G[i][i] = 0
for i in range(M):
  a, b, c = map(int, input().split())
  G[a - 1][b - 1] = c
  G[b - 1][a - 1] = c
def warshall_floyd(G):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        G[i][j] = min(G[i][k] + G[k][j], G[i][j])
  return G
G = warshall_floyd(G)
D = 10 ** 8
for L in itertools.permutations(r):
  d = 0
  pre = L[0]
  for l in L[1:]:
    d += G[pre][l]
    pre = l
  D = min(d, D)
print(D)

Measured memory_bytes: 46696
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <queue>
#include <cmath>
#include <cfloat>
#include <set>
#include <map>

// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, n);
	VAR(string, s, t);

	RREP(i, n) {
	  string sub_s = s.substr(n-i-1, i+1);
		string sub_t = t.substr(0, i+1);

		debug(sub_s);
		debug(sub_t);
		if (sub_s == sub_t){
			cout << 2 * n - i - 1 << endl;
			return 0;
		}
		
	}
	cout << 2 * n << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);


  /*
  * Insert sort
  */
  // trace(A, n);
  // for ( i = 2; i < n+1 ; i++) {
  //   int key = A[i];
  //   int j = i-1;
  //   while (j >= 1 && A[j] > key) {
  //     A[j+1] = A[j];
  //     j--;
  //   }
  //   A[j+1] = key;
  //   trace(A, n);
  //    /* code */
  // }

  /*
  * Bubble sort
  */
  // int count = 0;
  // for (i =1; i< n+1; i++){
  //   for ( j = n; j >= i+1; j--) {
  //     if (A[j] < A[j-1]){
  //       count += 1;
  //       int tmp = A[j];
  //       A[j] = A[j-1];
  //       A[j-1] = tmp;
  //     }
  //     /* code */
  //   }
  // }
  // trace(A,n);
  // printf("%d\n", count);


  /**
  * Selection sort
  */
   int count = 0;
   for (i=1; i< n+1; i++){
     int min = i;
     for (j=i; j<n+1; j++){
       if (A[j] < A[min]){
         min = j;
       }
     }
     if (min != i) {
       /* code */
       int tmp = A[min];
       A[min] = A[i];
       A[i] = tmp;
       count += 1;
     }
     
   }
   trace(A,n);
   printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
int a[10],sum;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		a[i]=1;
	}
	for(int i=100;i<=999;i++)
	{
		int b1,b2,b3;
		b1=i/100;
		b2=i%100/10;
		b3=i%10;
		if(a[b1] && a[b2] && a[b3])
		sum++;
	}
	cout<<sum;
}

Measured memory_bytes: 256
#include<stdio.h>
int binarySearch(int*,int,int);

int main(){
  int n,q;
  int i=0;
  int count=0;
  scanf("%d",&n);
  int S[n];
  for(i=0;i < n;i++){
    scanf("%d",&S[i]);
  }
  
  scanf("%d",&q);
  int T[q];
  for(i=0;i < q;i++){
    scanf("%d",&T[i]);
    if(binarySearch(S,T[i],n) != -1) count++;
  }
  printf("%d\n",count);
  return 0;
}

int binarySearch(int*s,int k,int n){
  int left=0,right=n,mid;
  while(left<right){
    mid = (left+right)/2;
    if(s[mid]==k) return mid;
    else if(k<s[mid]) right = mid;
    else left = mid + 1;
  }
  return -1;
}



Measured memory_bytes: 2440
## ?????????
def loadIcicle():
	icicles = []
	line = input().strip().split(" ")
	N, L = int(line[0]), int(line[1])
	while True:
		icicles.append(int(input().strip()))
		if len(icicles) == N: break
	return icicles, N, L
icicles, N, L = loadIcicle()

def calcDiff(icicles, N):
	diff_2times = [0]*len(icicles)

	for idx in range(len(icicles)):
		dif_right = icicles[idx+1] - icicles[idx] if idx != N-1 else -icicles[idx]
		dif_left = icicles[idx] - icicles[idx-1] if idx != 0 else icicles[idx]

		dif_right = 1 if dif_right > 0 else -1
		dif_left = 1 if dif_left > 0 else -1

		if dif_right - dif_left < 0: diff_2times[idx] = -1
		elif dif_right - dif_left > 0: diff_2times[idx] = 1
		else: diff_2times[idx] = 0

	return diff_2times

diff_2times = calcDiff(icicles, N)

time = [-1]*len(icicles)

peakX = [i for i in range(len(diff_2times)) if diff_2times[i]==-1] # ?????????(?????????)???index?????????
for i in peakX:
	time[i] = L - icicles[i]

	isLocalMinL, isLocalMinR = False, False
	posL = i
	posR = i
	while not (isLocalMinL and isLocalMinR):
		posL -= 1
		if posL < 0:
			isLocalMinL = True
		# ?£????????????£?????????????¨????
		if not isLocalMinL:
			if time[posL] == -1:
				time[posL] = (L-icicles[posL]) + time[posL+1]
			else:
				time[posL] = (L-icicles[posL]) + max(time[posL-1], time[posL+1])

			# ????????????????????????
			if diff_2times[posL] == 1:
				isLocalMinL = True

		posR += 1
		if posR >= N:
			isLocalMinR = True
		if not isLocalMinR:
			if time[posR] == -1:
				time[posR] = (L-icicles[posR]) + time[posR-1]
			else:
				time[posR] = (L-icicles[posR]) + max(time[posR-1], time[posR+1])

			if diff_2times[posR] == 1:
				isLocalMinR = True
print(max(time))

Measured memory_bytes: 17792
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(N,0);
  int a, b;
  while (cin >> a >> b) {
    ++v[a - 1];
    ++v[b - 1];
  }
  for (auto r : v) {
    cout << r << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int linklist[51][51];

int N, M;

bool check(int num, int *map, int z) {
	if (map[num] == 0) {
		// not checked
		map[num] = z;
		for (int i=1; i<=N; i++) {
			int next = linklist[num][i];
			if (next == 1) {
				// can move
				if (!check(i, map, z)) return false;
			}
		}
		return true;
	}
	if (map[num] == z) {
		// checked
		return true;
	}
	//if (map[num] != z)
	return false;
}
int main(){
	cin >> N >> M;
	int a[M], b[M];

	for (int i=0; i<M; i++) {
		cin >> a[i] >> b[i];
		linklist[a[i]][b[i]] = 1;
		linklist[b[i]][a[i]] = 1;
	}
	int count = 0;
	for (int n=1; n<=N; n++) {
		for (int i=1; i<=n; i++) {
			if (linklist[n][i] == 1) {
				// cut
				linklist[n][i] = 0;
				linklist[i][n] = 0;
				int map[51] = {0};
				if (check(n, map, 1) && check(i, map, 2)) {
					count++;
				}
				linklist[n][i] = 1;
				linklist[i][n] = 1;

			}
		}
	}

	cout << count << endl;
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    List<int>[] es;

    void calc()
    {
        cin = new Scanner();
        int[] dp = new int[10];
        int N = cin.nextInt();
        for (int i = 0; i < N; i++)
        {
            int add = cin.nextInt();
            int[] nextdp = (int[])dp.Clone();
            for (int j = 0; j < 10; j++)
            {
                if (dp[j] % 10 != j) continue;
                nextdp[(j + add) % 10] = Math.Max(nextdp[(j + add) % 10], dp[j] + add);
            }
            dp = nextdp;
        }

        int ans = 0;
        for (int i = 1; i < 10; i++)
        {
            ans = Math.Max(ans, dp[i]);
        }
        Console.WriteLine(ans);
    }
    
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;

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

	if (R < 1200)
	{
		cout << "ABC" << endl;
	}
	else if (R < 2800)
	{
		cout << "ARC" << endl;
	}
	else
	{
		cout << "AGC" << endl;
	}

	return 0;
}

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

template<int N, typename T, T M>
struct factorial_mod
{
	T mod[N + 1];
	T inv_mod[N + 1];

	constexpr factorial_mod() : mod(), inv_mod()
	{
		mod[0] = 1;
		for (int i = 0; i < N; ++i)
		{
			mod[i + 1] = (mod[i] * (i + 1)) % M;
		}
		inv_mod[N] = power(mod[N], M - 2);
		for (int i = N - 1; i >= 0; --i)
		{
			inv_mod[i] = (inv_mod[i + 1] * (i + 1)) % M;
		}
	}

	constexpr T power(T a, T b) const
	{
		T r = 1;
		while (b > 0)
		{
			if ((b & 1) != 0) r = (r * a) % M;
			a = (a * a) % M;
			b >>= 1;
		}
		return r;
	}

	constexpr T comb(T n, T r) const
	{
		if (r < 0 || r > n || n < 0) return 0;
		return (((mod[n] * inv_mod[r]) % M) * inv_mod[n - r]) % M;
	}
};

constexpr long long MOD = 1000000007;
constexpr factorial_mod<100000, long long, MOD> fmod;

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	long long a[100000];
	for (int i = 0; i < n; ++i)
	{
		scanf("%lld", a + i);
	}
	std::sort(a, a + n);
	for (int i = 0; i < n; ++i)
	{
		a[i] = (a[i] + MOD) % MOD;
	}
	long long min = 0;
	for (int i = 0; i <= n - k; ++i)
	{
		min = (min + a[i] * fmod.comb(n - i - 1, k - 1)) % MOD;
	}
	long long max = 0;
	for (int i = 0; i <= n - k; ++i)
	{
		max = (max + a[n - 1 - i] * fmod.comb(n - i - 1, k - 1)) % MOD;
	}
	printf("%lld\n", (MOD + max - min) % MOD);
	return 0;
}


Measured memory_bytes: 896
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const N = readln.chomp.to!int;
    struct Info { long x, y, h; }

    Info[] infoList;
    foreach (i; 0..N) {
        const tmp = readln.split.to!(long[]);
        const x = tmp[0], y = tmp[1], h = tmp[2];
        infoList ~= Info(x,y,h);
    }

    const maxHeight = infoList.map!(info => info.h).reduce!max;

    cartesianProduct(iota(101), iota(101), iota(maxHeight, maxHeight + 220))
        .filter!(c =>
                infoList.all!(info =>
                    info.h == max(0, c[2] - abs(c[0] - info.x) - abs(c[1] - info.y))))
        .each!(a => writefln("%d %d %d", a[0], a[1], a[2]));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
bool comp(const pair<string,ll> &a,const pair<string, ll> &b)
{
   return a.second>b.second;
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll a[n], sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    ll p=round(1.0*sum/n), ans=0;
    //cout<<sum*1.0/n<<endl;
    for(ll i=0; i<n;i++)
        ans+=(a[i]-p)*(a[i]-p);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
hen = gets.split(' ').map(&:to_i)
hen.sort!
 
triangle_total = 0
a = 0
 
while a < N - 2 do
    b = a + 1
 
    while b < N - 1 do 

        check_num = hen[a] + hen[b]
        
        if check_num <= hen[b + 1]
        elsif check_num > hen[N - 1]
            triangle_total = triangle_total + N - 1 - b
        else            
           c = hen.bsearch_index { |x|  x >= check_num }
           triangle_total = triangle_total + c - 1 - b
        end
 
        b = b + 1
 
    end
    a = a + 1
 
end
 
p triangle_total

Measured memory_bytes: 1788
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int r = Integer.parseInt(sc.next());
        int g = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        
        String input = Integer.toString(r) + Integer.toString(g) + Integer.toString(b);
        int value = Integer.parseInt(input);
        
        if(value % 4 == 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
        
    }
}

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

int n, m, d[20], count[50001] = { 0 };

int minc(int c1, int c2);


int main()
{
	int i = 0, j;

	scanf("%d %d", &n, &m);
	while (i < m) {
		scanf("%d", &d[i]);
		if (d[i] != ' ')i++;
	}
	

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

	for (i = 1; i < m; i++) {
		for (j = 1; j <= n; j++) {
			if (j - d[i] >= 0) {
				count[j] = minc(count[j], count[j - d[i]] + 1);
			}
		}
	}
	
	printf("%d\n", count[n]);

	return 0;
}

int minc(int c1, int c2)
{
	return c1 < c2 ? c1 : c2;
}

Measured memory_bytes: 788
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;

using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	ll N;cin >> N;
	ll m;
	VLL X(N);
	VLL XX(N);
	for (int i = 0;i < N;i++) {
		cin >> X[i];
		XX[i] = X[i];
	}
	m = N / 2;
	m--;
	sort(all(XX));
	ll mid1 = XX[m];
	ll mid2 = XX[m+1];
	for (int i = 0;i < N;i++) {
		if (X[i] > mid1)cout << mid1 << endl;
		else cout << mid2 << endl;
	}
}


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

Sd = input()
T = input()

is_replaced = False
for i in range(len(Sd) - len(T), -1, -1):
    can_replace = True
    k = i
    j = 0
    while can_replace and j < len(T):
        if Sd[k] == T[j] or Sd[k] == "?":
            k += 1
            j += 1
        else:
            can_replace = False
            break

    if can_replace:
        # let's replace
        Sd_l = list(Sd)
        for ti in range(len(T)):
            Sd_l[i + ti] = T[ti]
        Sd = "".join(Sd_l)
        is_replaced = True
        break

if is_replaced:
    print(Sd.replace('?', 'a'))
else:
    print("UNRESTORABLE")


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

int main() {
  string s;
  cin >> s;
  int t = 0;
  int ans = 0;
  for(int i=(int)s.size()-1;i>=0;--i) {
    if( s[i] == 'S' ) {
      if( t ) --t;
      else   ++ans;
    } else {
      ++t;
    }
  }
  cout << ans + t << endl;
  compute();
  return 0;
}


Measured memory_bytes: 640
import java.util.*;

class Main{
	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[] a=new int[n];
		Arrays.setAll(a,i->s.nextInt()*2);
		Arrays.sort(a);
		System.err.println(Arrays.toString(a));

		long r=0;
		for(int i=0;i<n;++i){
			for(int j=i+1;j<n;++j){
				int R=~Arrays.binarySearch(a,a[i]+a[j]-1)-1;
				r+=R-j;
			}
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 29156
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <math.h>
#include <complex>
#include <vector>
#include <functional>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
#define INF 100000000
typedef pair<int,int> P;
int coin[]={500,100,50,10,5,1};
int main()
{
	int n;
	while(scanf("%d",&n)&&n){
		int ans=0;
		n=1000-n;
		for(int i=0;i<6;i++){
			ans+=n/coin[i];
			n%=coin[i];
		}
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  if(n%2!=0){
    cout<<"No";
    return 0;
  }
  for(int i=0;i<n/2;i++){
    if(s.at(i)!=s.at(n/2+i)){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n;
    vector<int> L;
    cin >> n;
    while(n--){
        int x, y;
        cin >> x >> y;
        L.push_back(x);
        L.push_back(y);
    }
    sort(L.begin(), L.end());
    int SUM=0;

    for(int i=0;2*i<L.size();i++){
        SUM+=L[2*i];
    }
    cout << SUM << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		String b = "Good";
		char a = 0;
		for(int i=0; i<S.length(); i++) {
			if(a == S.charAt(i)) {
				b = "Bad";
			}
			a = S.charAt(i);
		}
		System.out.println(b);
	}

}


Measured memory_bytes: 23764
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

	private void solve() {
		// 入力
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Integer> a = new ArrayList<Integer>();
		for (int i = 0; i < 3 * N; i++) {
			a.add(sc.nextInt());
		}
		sc.close();

		// 計算
		Collections.sort(a, Collections.reverseOrder());
		long sum = 0;
		for (int i = 0; i < N; i++) {
			sum += a.get(2 * i + 1);
		}

		// 出力
		System.out.println(sum);

		return;
	}
}


Measured memory_bytes: 96384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  int N; cin >> N;
  vector <ll> A(N);
  int bit[N][21];
  for (int i = 0; i < N; i++){
    cin >> A[i];
    ll num = A[i];
    for (int j = 20; j >= 0; j--){
      bit[i][j] = num % 2;
      num = num / 2;
    }
  }

  ll ans = 0;
  int r = 0;
  vector <int> BIT(21);
  for (int i = 0; i < N; i++){
    bool flag = true;

    while (flag == true && r < N){
      for (int j = 0; j < 21; j++){
        if (BIT[j] + bit[r][j] > 1){
          flag = false;
        }
      }
      if (flag == true){
        for (int j = 0; j < 21; j++){
          BIT[j] += bit[r][j];
        }
        r++;
      }
    }
    ans += r - i;

    for (int j = 0; j < 21; j++){
      BIT[j] -= bit[i][j];
    }
     
  }
  
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 18176
let rec solve v rest a b =
    match rest with
    | 0 -> v
    | r -> if a > b then solve (v + a) (r - 1) (a - 1) b else solve (v + b) (r - 1) a (b - 1)

stdin.ReadLine().Split(" ")
|> Array.map int
|> fun [| a; b |] -> solve 0 2 a b
|> printfn "%d"


Measured memory_bytes: 30032
#include "bits/stdc++.h"
#define long int64_t
using namespace std;

struct Solver {
	void solve() {
		string S, T;
		cin >> S >> T;
		int sn = (int)S.size();
		int tn = (int)T.size();
		int ans = 0;
		for( int i = 0; i <= (sn - tn); ++i ) {
			int c = 0;
			for( int j = 0; j < tn; ++j ) {
				if( S[i+j] == T[j] ) { c += 1; }
			}
			ans = max( ans, c );
		}
		cout << tn-ans << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3620
n, k = map(int, input().split())
A = sorted(map(int, input().split()))
INF = 10**9+1
diff = INF
for x, y in zip(A, A[1:]):
    z = abs(x-y)
    if z > 0:
        diff = min(diff, z)

MAX = A[-1]
ans = False
for a in A:
    if a-k < 0:
        continue
    x, r = divmod((a-k), diff)
    if r == 0:
        ans = True
        break
print("POSSIBLE" if ans else "IMPOSSIBLE")


Measured memory_bytes: 14224
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 105000

int main() {
  int N;
  cin >> N;
  vector<int> A(MAX_N, 0);
  for (int i = 1; i <= N; i++) cin >> A[i];
  vector<int> dis(MAX_N, 0);
  vector<int> S(MAX_N, 0);

  int sum = 0;
  for (int i = 1; i <= N + 1; i++) sum += abs(A[i] - A[i - 1]);
  for (int i = 1; i <= N; i++) {
    S[i] = abs(A[i - 1] - A[i + 1]) -
           (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1]));
  }

  for (int i = 1; i <= N; i++) {
    cout << sum + S[i] << endl;
  }

  return 0;
}

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

struct town {
	int n,tn[500],m[500],a[11];
};

town to[100];

int c,n,m,s,d;

void ans() {
	int i,j,k,f;
	for (i=0;i<n;i++) for (j=0;j<=c;j++) to[i].a[j]=9999999;
	for (i=0;i<=c;i++) to[s].a[i]=0;
	while(true)  {
		f=0;
		for (i=0;i<n;i++) for (j=0;j<to[i].n;j++) {
			 for (k=0;k<=c;k++) {
			 if (to[i].a[k]+(to[i].m[j])/2<to[to[i].tn[j]].a[k+1]) {to[to[i].tn[j]].a[k+1]=to[i].a[k]+(to[i].m[j])/2; f=1;}
			 if (to[i].a[k]+to[i].m[j]<to[to[i].tn[j]].a[k]) {to[to[i].tn[j]].a[k]=to[i].a[k]+to[i].m[j]; f=1;}
		    }
	    }
	    if (f==0) break;
	}
}
int main() {
	int i,a,b,x;
	while(cin >> c >> n >> m >> s >> d && n>0) {
		s--; d--;
		for (i=0;i<n;i++) to[i].n=0;
		for (i=0;i<m;i++) {
			cin >> a >> b >> x; a--; b--;
			to[a].tn[to[a].n]=b;  to[b].tn[to[b].n]=a;
			to[a].m[to[a].n]=to[b].m[to[b].n]=x;
			to[a].n++; to[b].n++;
		}
		ans();
		cout << to[d].a[c] << endl;
		}		 
	return 0;
}

Measured memory_bytes: 1556
import math
import collections
import fractions
import itertools

def solve():
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    d = 0
    ans = 1
    for i in range(n):
        d = d + l[i]
        if d > x:
            break
        ans += 1
    print(ans)
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 10460
#include<iostream>
#include <stdio.h>
#include <vector>

using namespace std;

long long n;
vector <long long > a, b;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	cin >> n;
	a.resize(n);
	b.resize(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int j = 0; j < n; j++)
		cin >> b[j];
	long long ans1 = 0, ans2 = 0;
	for (int i = 0; i < n; i++)
		if (b[i] - a[i] < 0)
			ans1 += a[i] - b[i];
		else
			ans2 += (b[i] - a[i])/2;
	if (ans2 >= ans1)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 384
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A

from sys import stdin
input = lambda: stdin.readline().rstrip()

N = int(input())

A = list(map(int, input().split()))

join = lambda a : ' '.join(map(str, a))
print(join(A))
for i in range(1,N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j = j-1
    A[j+1] = v
    print(join(A))



Measured memory_bytes: 5600
N=int(input())
S=input()
x=dict()
for i in range(N):
    s=S[i]
    if s in x:
        x[s]+=1
    else:
        x[s]=1
count=0
for i in range(1,N+1):
    for k in range(i+1,N+1):
        tmp=i+k
        if tmp%2==0:
            j=tmp//2
            if S[i-1]!=S[j-1] and S[i-1]!=S[k-1] and S[j-1]!=S[k-1]:
                count+=1
ans=1
cnt=0
for idx in x:
    cnt+=1
    ans=ans*x[idx]
if cnt!=3:
    print(0)
    exit()
ans=ans-count
print(ans)

Measured memory_bytes: 68112
#include <iostream>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int A[2000];
ll cnt1[2000];
ll cnt2[2000];

int main(){
    ll N, K;
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(A[i] < A[j]) {
                cnt1[i]++;
                if(j < i) cnt2[i]++;
            }
        }
        //cout << cnt1[i] << ' ';
    }
    //cout << endl;
    ll ans = 0;
    for(int i = 0; i < N; i++){
        ans += K*cnt2[i];
        ans %= MOD;
        ans += (((K*(K-1))/2)%MOD)*cnt1[i];
        ans %= MOD;
    }
    cout << ans << endl;
}

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


using namespace std;

#define endl '\n'
#define PB push_back
#define MP make_pair
#define LL long long
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

typedef long long ll;

bool file=0,rt=1;
clock_t tStart ;
void FAST_IO();
////////////////////////

int main() {

    FAST_IO();
    cout << setprecision(5);
    cout << fixed;

    int five = 0, seven = 0;
    int a[3];

    for(int i = 0; i < 3; i++) {

        cin >> a[i];
        if(a[i] == 5) five++;
        else if(a[i] == 7) seven++;
    }

    if(five == 2 && seven == 1) {
        cout << "YES" << endl;
    }
    else cout <<"NO" << endl;



    return 0;
}

void FAST_IO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //cout.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(2);
    if(rt && file){ tStart = clock(); }
    if(file){
    #ifndef _offline
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    }
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#include<cmath>

using namespace std;

//int mod_num_counter[2030];

int abs(int n)
{
	return n < 0 ? -n:n;
}

int main()
{
  //fill(mod_num_counter,mod_num_counter+2030,0);
  
  int n;
  cin >> n;
  
  int a[n+1];
  
  for(int i=1;i<=n;i++) cin >> a[i];

  unordered_map<int ,int> m;
  for(int i=1;i<=n;i++)
  {
    int v = a[i] - i;
    auto itr = m.find(v);
    if(itr == m.end())
    {
      m[v]=1;
    }
    else
    {
      m[v]++;
    }
  }
  /*
  for(auto itr = m.begin(); itr != m.end(); ++itr) {
        std::cout << "key = " << itr->first           // キーを表示
                        << ", val = " << itr->second << "\n";    // 値を表示
    }
  */
  long long ans = 0;
  for(int i=1;i<n;i++)
  {
    int v = -a[i]-i;
	auto itr = m.find(v);
    if(itr != m.end())
    {
      ans+=m[v];
    }
  }
  
        cout << ans << endl;
    
  return 0;
}

Measured memory_bytes: 11984
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<n;i++)
#define ll long long
#define ld long double
#define pi 3.1415926535897932384626433832795028841971693993
#define ee 2.718281828459045
#define mod 1000000007
#define MOD mod
#define sec setprecision
using namespace std;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int ketasuu(ll h) {
	if (h < 0)return(-(ketasuu(-h)));
	else if (h < 10)return(1);
	else return(1 + ketasuu(h / 10));
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a)%mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	
}
int main() {
	int a, b, t;
	cin >>a >>  b >> t;
	int k = t / a;
	cout << k * b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(void){
	ll a,b,c;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>a>>b>>c;
	cout<<max(0ll,c-(a-b))<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)

	var s string
	fmt.Scan(&s)

	ss := strings.Split(s, "")

	if len(ss)%2 != 0 {
		fmt.Print("No")
		return
	}

	harf := len(ss) / 2
	for i := 0; i < harf; i++ {
		if ss[i] != ss[harf+i] {
			fmt.Print("No")
			return
		}
	}

	fmt.Print("Yes")
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	vector<vector<int>>c(3,vector<int>(3));
	for(auto&&i:c)for(auto&&j:i)cin>>j;
	vector<int>a(3,INT_MAX),b(3,INT_MAX);
	a.front()=0; b.front()=c.at(0).at(0);
	bool yes=true;
	for(int i=0;i<3;++i){
		for(int j=0;j<3;++j){
			if(a.at(i)==INT_MAX)a.at(i)=c.at(i).at(j)-b.at(j);
			if(b.at(j)==INT_MAX)b.at(j)=c.at(i).at(j)-a.at(i);
			if(a.at(i)+b.at(j)!=c.at(i).at(j))yes=false;
		}
	}
	cout<<(yes?"Yes"s:"No"s)<<"\n"s;
}

Measured memory_bytes: 256
package main

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

func main() {
	n := getInt()
	W := getInt()

	ws := make([]int, n)
	vs := make([]int, n)
	for i := 0; i < n; i++ {
		ws[i] = getInt()
		vs[i] = getInt()
	}

	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, W+1)
	}

	for i := 1; i < n+1; i++ {
		for j := range dp[i-1] {
          	dp[i][j] = dp[i-1][j]
			if j-ws[i-1] >= 0 {
				dp[i][j] = max(dp[i][j], dp[i-1][j-ws[i-1]]+vs[i-1])
			}
		}
	}

	fmt.Println(dp[n][W])
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 81792