akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }


  int dist[1005][1005];


int main() {
  int H,W;
  scanf("%d%d", &H,&W);
  char a[H][W];
  queue<pint> que;
  

  for (int i = 0; i < H; ++i) {
    FOR(j,0,W-1){
      cin >> a[i][j];
      if(a[i][j]=='.') dist[i][j] = -1;
      else {
        dist[i][j] = 0;
        que.push(pint(i,j));
      }
    }
  }

  // cout  << 999 << endl;

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

  while(!que.empty()){
      auto holda = que.front();
      que.pop();
      FOR(i,0,3){
      // cout << que.size() << endl;

      int nx = holda.first + dx[i];
      int ny = holda.second + dy[i];

      // cout << nx << " " << ny << endl;

      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if(dist[nx][ny]==-1){
      dist[nx][ny] = dist[holda.first][holda.second] +1;
      // cout << nx << " " << ny << " " << dist[nx][ny] << endl;
      que.push(pint(nx,ny));
      }
    }
  }

  

  int ans = 0;
  FOR(i,0,H-1){
    FOR(j,0,W-1){
      chmax(ans,dist[i][j]);
      // if(ans == 3) cout << i << " " << j << endl;
    }
  }

  cout << ans << endl;




}



Measured memory_bytes: 13328
#include<iostream>
using namespace std;
#define MAX 100000
int parent(int i) {return i/2;}
int left(int i) {return 2*i;}
int right(int i) {return 2*i+1;}
int main(){
  int H,i,A[MAX+1];
  cin >> H;
  for(i=1;i<=H;i++) cin >> A[i];
  for(i=1;i<=H;i++){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if( parent(i) >= 1 ) cout << "parent key = " << A[parent(i)] << ", ";
    if( left(i) <= H ) cout << "left key = " << A[left(i)] << ", ";
    if( right(i) <= H ) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }
  return 0;
}
    



Measured memory_bytes: 3116
using System;

class Program
{
    static void Main()
    {
        Console.ReadLine(); //１行目を無視


        var line = Console.ReadLine().Split(' ');
        int[] values= new int[line.Length];
        var i = 0;
        foreach (var s in line)
        {
            values[i] = int.Parse(s);i++;
        }
        Console.WriteLine("{0} {1} {2}", Min(values), Max(values), Sum(values));
    }

    static int Max(params int[] x)
    {
        int ans=x[0];
        foreach (var xx in x) if (ans < xx) ans = xx;
        return ans;
    }

    static int Min(params int[] x)
    {
        int ans = x[0];
        foreach (var xx in x) if (ans > xx) ans = xx;
        return ans;
    }

    static long Sum(params int[] x)
    {
        int i; long ans;
        ans = 0;
        for (i = 0; i < x.Length; ans += x[i++]) ;
        return ans;
    }
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	int hap[n][3];
	for (int i = 0; i < n; i++){
		cin >> hap[i][0] >> hap[i][1] >> hap[i][2];
	}
	int dp[n][3];
	dp[0][0] = hap[0][0];
	dp[0][1] = hap[0][1];
	dp[0][2] = hap[0][2];
	for (int i = 1; i < n; i++){
		for (int j = 0; j < 3; j++){
			dp[i][j] = -1;
			for (int k = 0; k < 3; k++) if (k != j){
				dp[i][j] = max(dp[i][j], dp[i-1][k]);
			}
			dp[i][j] += hap[i][j];
		}
	}

	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
	return 0;
}


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

int table[MAX][MAX];

int LCS(string s, string t);

int main(){
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        string s,t; cin >> s >> t;
        cout << LCS(s, t) << endl;
    }
    return 0;
}

int LCS(string s, string t){
    int slen = s.length(), tlen = t.length();

    for(int i = 0; i <= slen; i++) table[0][i] = 0;
    for(int i = 0; i <= tlen; i++) table[i][0] = 0;
    for(int i = 0; i < slen; i++){
        for(int j = 0; j < tlen; j++){
            if(s[i] == t[j]){
                table[i+1][j+1] = table[i][j] +1;
            }else{
                table[i+1][j+1] = max(table[i][j+1], table[i+1][j]);
            }
        }
    }
    return table[slen][tlen];

}


Measured memory_bytes: 7088
#include <iostream>
using namespace std;
int main(){
        int a,b,c;
        cin >> a >> b >> c;
        if (a==b) {
                cout << c << '\n';
        }
        else if(a==c) {
                cout << b <<'\n';
        }
        else{
                cout << a << '\n';
        }

        return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def dfs(v, color):
    colors[v] = color
    for to in g[v]:
        if colors[to] == color: return
        if colors[to] == 0 and not dfs(to, -color):
            return False
    return True

def Washall_Floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d

n = int(input())
g = [[] for _ in range(n)]
f_inf =float('inf')
dist = [[f_inf]*n for _ in range(n)]
for i in range(n): dist[i][i]=0

for i in range(n):
    S = input()
    for j in range(n):
        if S[j] == '1':
            g[i].append(j)
            dist[i][j] = 1
            dist[j][i] = 1

colors = [0] * n
ans = -1
if not dfs(0, 1):
    print(ans)
else:
    Washall_Floyd(dist)
    for d in dist:
      tmp = max(d)
      ans = max(tmp, ans)
    print(ans+1)

Measured memory_bytes: 55260
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;
bool primes[1000001];vi prime; void seive(); int gcd(int a, int b); int power(int x, int y);

int32_t main(void){
	IOS;
	string s1, s2;
	cin>>s1>>s2;
	int n = s1.length();
	int ans = 0;
	rep(i, 0, n)
	{
	    if(s1[i] != s2[i]) ans += 1;
	}
	cout<<ans<<endl;
}

void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}
int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}
int power(int x, int y){ int res = 1;x = x % mod; if (x == 0) return 0;
while (y > 0){ if(y & 1) res = (res*x) % mod; y = y>>1; x = (x*x) % mod;} return res;}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){	
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n;
	llong x;
	cin >> n >> x;
	llong *a = new llong[n]();
	cin >> a[0];
	llong cost = 0;
	if(a[0] > x){
		cost += (a[0] - x);
		a[0] = x;
	}
	llong tmp, tmp_cost;
	FOR(i, 1, n){
		cin >> a[i];
		tmp = x-(a[i]+a[i-1]);
		if(tmp < 0){
			tmp_cost = min(a[i], -tmp);			
			a[i] -= tmp_cost;
			cost += tmp_cost;
		}
	}
	
	cout << cost << '\n';

	delete[] a;
	return 0;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll N,M,H,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;

ll dp[105][100005];

int main(){
    ll n,W;
    cin >> n>>W;
    rep(i,n){
        ll w,v;
        cin >> w>>v;
        if(i==0){
            reps(j,w,W+1){
                dp[0][j]=v;
            }
            continue;
        }
        rep(j,W+1){
            dp[i][j]=dp[i-1][j];
            if(j-w>=0){
                dp[i][j]=max(dp[i][j],dp[i-1][j-w]+v);
            }
        }
    }
    cout<<dp[n-1][W]<<endl;
    return 0;
}



Measured memory_bytes: 80128
while True:
    n, x = map(int, input().split())
    if (n, x) == (0, 0):
        break
    c = 0
    for i in range(n):
        for j in range(i + 1, n):
            for k in range(j + 1, n):
                if i + j + k == x - 3:
                    c += 1
    print(c)



Measured memory_bytes: 5600
fun main() {
    val builder = StringBuilder()

    val N = readInputLine().toLong()

    val divisors = mutableMapOf<Long, Long>()

    var Ntmp = N

    for (i in LongRange(2L, Math.sqrt(N.toDouble()).toLong() + 1L)) {
        if (Ntmp == 1L) {
            break
        }
        while (Ntmp % i == 0L) {
            divisors[i] = (divisors[i] ?: 0L) + 1L
            Ntmp /= i
        }
    }

    if (Ntmp != 1L) {
        divisors[Ntmp] = 1L
    }

    val sumArr = LongArray(100)

    for (i in 1 until 100) {
        sumArr[i] = sumArr[i - 1] + i.toLong()
    }


    var ans = 0L

    for ((_, v) in divisors) {
        for (i in 1 until 100) {
            if (v < sumArr[i]) {
                ans += (i - 1).toLong()
                break
            }
        }
    }

    builder.appendln(ans)

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const int INF = 999999999;

int main() {
    int N, Q; cin >> N >> Q;
    string S; cin >> S;
    vector<pair<int, int>> lr(Q);
    vector<int> cs(N+1, 0);
    for(int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        lr[i] = (make_pair(l, r));
    }

    for(int i = 2; i <= N; i++) {
        cs[i] = cs[i-1];
        if(S[i-2] == 'A' && S[i-1] == 'C') {
            cs[i] += 1;
        }
    }

    for(int i = 0; i < Q; i++) {
        int rtn = cs[lr[i].second] - cs[lr[i].first];
        cout << rtn << endl;
    }
}

Measured memory_bytes: 2240
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;

int main() {

	int K, X; cin >> K >> X; K--;

	for (int i = max(-1000000, X - K); i <= min(1000000, X + K); i++) cout << i << " ";

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  string s;
  s = to_string(n);
  if(s[0]=='7' or s[1]=='7' or s[2]=='7'){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;

int main() {
  int n; cin >> n;
  for(int i = 1; i <= 50000; ++i){
    int x = floor(i*1.08);
    if(x==n){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long Int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    Int n, m; cin >> n >> m;

    if ((Int)n*m == 1) puts("1");
    else if ((Int)n*m == 2) puts("0");
    else if ((Int)n*m == 3) ("1");
    else {
        if (n == 1 || m == 1) {
            cout << (Int)n*m - 2 << endl;
        }
        else cout << (Int)(n-2)*(m-2) << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
a = []
b = []
for i in range(n):
  x, y = map(str, input().split())
  if(i==0):b.append(int(y))
  else:b.append(b[-1] + int(y))
  a.append(x)
s = input()
print(b[-1] - b[a.index(s)])
  

  

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
using UL=unsigned int;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

struct Edge{ UL u,v; UL c; UL r; };

UL N,M;
vector<UL> E[100];
Edge J[2000];

UL fD[100];
UL fF[100];
UL fAns;

UL fDFS(UL p,UL c=10000000){
 if(p==N-1) return c;
 UL f=0;
 for(UL& i=fF[p]; i<E[p].size(); i++){
  Edge& e = J[E[p][i]];
  if(c-f==0) return f;
  if(fF[e.v]) continue;
  if(e.c==0) continue;
  if(fD[e.v]!=fD[p]+1) continue;
  UL tmp = fDFS(e.v,min(c-f,e.c));
  e.c -= tmp; J[e.r].c += tmp;
  f += tmp;
 }
 return f;
}

UL flow(){
 rep(i,N) fD[i]=~0u;
 fD[0]=0;
 queue<UL> Q; Q.push(0);
 while(Q.size()){
  UL p=Q.front(); Q.pop();
  for(UL j:E[p]){
   if(fD[J[j].v]!=~0u) continue;
   if(J[j].c==0) continue;
   fD[J[j].v]=fD[p]+1;
   Q.push(J[j].v);
  }
 }
 rep(i,N) fF[i]=0;
 UL res=fDFS(0);
 fAns += res;
 return res;
}

int main(){
 scanf("%u%u",&N,&M);
 rep(i,M){
  UL u,v,c; scanf("%u%u%u",&u,&v,&c);
  J[i]={u,v,c,M+i};
  J[M+i]={v,u,0,i};
  E[u].push_back(i);
  E[v].push_back(M+i);
 }
 while(flow());
 printf("%u\n",fAns);
 return 0;
}



Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

vector<vector<string>> dp;

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int n;
	cin >> n;
	dp = vector<vector<string>>(n+1);
	dp[0].push_back("");

	for(int len = 1; len <= n; len++) {
		vector<vector<string>> after(n + 1);
		for(int prev = 0; prev < len; prev++) {
			for(auto x : dp[prev]) {
				for(int nxt = 0; nxt <= prev; nxt++) {
					after[max(prev, nxt+1)].push_back(x + (char)('a'+nxt));
				}
			}
		}
		dp = after;
	}

	vector<string> rets;
	rep(i, n+1) {
		for(auto x : dp[i]) {
			rets.push_back(x);
		}
	}
	sort(all(rets));
	for(auto ret : rets) cout << ret << endl;
	return 0;
}

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

bool judgePrimeNumber( int a )
{
    for( int i = 2; i <= sqrt(a); i++ )
        if( a % i == 0 )
            return false;
    return true;
}

int main()
{
    int n;

    while( cin >> n )
    {
        if( n == 0 )
            break;
        
        int cnt = 0;
        for( int i = n + 1 ; i <= 2 * n; i++ )
            if( judgePrimeNumber(i) )
                cnt++;

        cout << cnt << endl;

    }
    return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll N;
  std::cin >> N;

  ll cnt = 0LL;
  for (ll i = 1; i <= N; i++) {
    if ((ll)std::to_string(i).length() % 2 == 1) cnt++;
  }

  print(cnt);
  return 0;
}


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

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define MAXX 1000005


#define PI 3.14159265358979323846264338327950

#define ll  long long int
ll mod = 1000000007;
ll dp[MAXX];


int main()
{
	FAST;
	ll n, t , h = 1;
	cin >> n;
	t = 360;
	h = (360*n)/(__gcd(n, t));
	h /= n;
	cout << h ;
    return 0;
	
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		for (int i = 0; i < arr.length; i++) {
		    arr[i] = (char)((arr[i] - 'A' + n) % 26 + 'A');
		}
		System.out.println(arr);
	}
}


Measured memory_bytes: 22356
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int cnt = 0;

vector<int> bubbleSort(vector<int> &A, int N) {
    bool flag = true;
    while (flag) {
        flag = 0;
        for (int j = N - 1; j > 0; j--) {
            if (A[j] < A[j - 1])
                swap(A[j], A[j - 1]), cnt++, flag = true;
        }
    }

    return A;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }

    vector<int> sortedA = bubbleSort(A, N);
    rep(i, N - 1) { cout << sortedA[i] << " "; }
    cout << sortedA[N - 1] << endl;
    cout << cnt << endl;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll H, W;
    cin >> H >> W;
    vector<string> A(H);
    REP(i, H)
    {
        cin >> A[i];
    }

    queue<pair<ll, ll>> q;
    REP(i, H)
    {
        REP(j, W)
        {
            if (A[i][j] == '#')
            {
                pair<ll, ll> p = make_pair(i, j);
                q.push(p);
            }
        }
    }

    ll ans = 0;
    while(true)
    {
        queue<pair<ll, ll>> nextQ;
        while(!q.empty())
        {
            pair<ll, ll> p = q.front();
            q.pop();
            ll i, j;
            i = p.first;
            j = p.second;
            if (j - 1 >= 0 && A[i][j - 1] == '.')
            {
                A[i][j - 1] = '#';
                nextQ.push(make_pair(i, j - 1));
            }
            if (j + 1 < W && A[i][j + 1] == '.')
            {
                A[i][j + 1] = '#';
                nextQ.push(make_pair(i, j + 1));
            }
            if (i - 1 >= 0 && A[i - 1][j] == '.')
            {
                A[i - 1][j] = '#';
                nextQ.push(make_pair(i - 1, j));
            }
            if (i + 1 < H && A[i + 1][j] == '.')
            {
                A[i + 1][j] = '#';
                nextQ.push(make_pair(i + 1, j));
            }
        }
        if (!nextQ.empty())
        {
            ans++;
            q = nextQ;
        }
        else
        {
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 17988
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H,P,L;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll a[1000000];
ll b[1000000];
ll c[1000000];
ll t[1000000];
ll p[1000000];
ll n[1000000];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
int main() {
	cin>>S;
	string tmp="keyence";
	rep(i,0,8){
		string tmp1=S.substr(0,i);
		tmp1+=S.substr(S.size()-7+i);
		cerr<<i<<" "<<tmp1<<endl;
		if(tmp1==tmp){
			cout<<"YES"<<endl;
			return 0;
		}
		
	}
	cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int main () {
  int a, b, c, d;
  std::string ans = "";
  std::cin >> a >> b >> c >> d;
  int x = a + b - c - d;
  if(x > 0) ans = "Left";
  else if(x == 0) ans = "Balanced";
  else ans = "Right";
  std::cout << ans << std::endl;
}


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

int main() {
  int a ;
  cin>>a;
  int b=a%10 , c=((a%100)-b)/10,d=((a%1000)-(b+c))/100,e=(a-(b+c+d))/1000 ;
  if ((e==d&&d==c) || (b==c&&c==d)) {
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int64_t N;
  cin >> N;
  int64_t res = 0;
  for (int64_t i = 1; i * i < N + 1; i++) {
    if (N % i == 0) res = i;
  }
  cout << res + N / res - 2 << '\n';
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [0] + [int(i) for i in input().split()] + [0]
d = [abs(a[i] - a[i + 1]) for i in range(n + 1)]
sumd = sum(d)
for i in range(n):
  print(abs(a[i] - a[i + 2]) + sumd - d[i] - d[i + 1])

Measured memory_bytes: 14048
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, m;
llint a[105];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	llint ans = 0, sum = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		sum += a[i];
	}
	
	for(int i = 1; i <= n; i++){
		if(a[i]*4*m >= sum) ans++;
	}
	if(ans >= m) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define ALL(v) v.begin(),v.end()
#define mod 1000000007

int main(){
  ll n,k;
  cin >> n >>k;
  ll ans=0;
  if(k%2==1){
    ll res=n/k;
    //resC3
    ans+=(res*(res-1)*(res-2)/3/2)*6;
    //resC2 last *2 separate (a,a,b) (a,b,b)
    ans+=(res*(res-1)/2)*3*2;
    //resC1
    ans+=res*1;
  }else if(k%2==0){
    ll res=n/k;
    ans+=(res*(res-1)*(res-2)/3/2)*6;
    //resC2 last *2 separate (a,a,b) (a,b,b)
    ans+=(res*(res-1)/2)*3*2;
    //resC1
    ans+=res*1;
    ll l=k/2;
    if(k/2+res*k<=n){
      ll res=n/k+1;
      ans+=(res*(res-1)*(res-2)/3/2)*6;
      //resC2 last *2 separate (a,a,b) (a,b,b)
      ans+=(res*(res-1)/2)*3*2;
      //resC1
      ans+=res*1;
    }else{
      ans*=2;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> num(n, 1);
    vector<bool> red(n, false);
    red[0] = true;
    vector<vector<int>> d(m, vector<int> (2));
    rep(i, m) {
        cin >> d[i][0] >> d[i][1];
        d[i][0]--;
        d[i][1]--;
    }
    rep(i, m) {
        if(red[d[i][0]]) red[d[i][1]] = true;
        num[d[i][0]]--;
        num[d[i][1]]++;
        if(num[d[i][0]] == 0) red[d[i][0]] = false;
    }
    int count = 0;
    rep(i, n) if(red[i]) count++;
    cout << count << "\n";
}

Measured memory_bytes: 8992
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

int H, W;
vector<vector<char> > field;
ll dp[1100][1100];

int main() {
    cin >> H >> W;
    field.resize(H+1);
    rep(i, H+1) field[i].resize(W+1);
    rep(i, H) {
        string s; cin >> s;
        for (int j = 0; j < W; j++) {
            field[i+1][j+1] = s[j];
        }
    }

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (i == 1 && j == 1) dp[i][j] = 1;
            else if (field[i][j] == '#') dp[i][j] = 0;
            else dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
        }
    }

    // for (int i = 0; i <= H; i++) {
    //     for (int j = 0; j <= W; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[H][W] << endl;
}


Measured memory_bytes: 9856
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	ans := 0.0
	for i := 0; i < N; i++ {
		x, u := sc.nextFloat(), sc.nextStr()
		if u == "JPY" {
			ans += x
		} else {
			ans += x * 380000
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
fn main() {
    let k = read::<usize>();

    let a = vec![
        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,
    ];
    println!("{}", a[k - 1]);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
#define NOTFOUND 0
#define MAX 10000

int linearSearch(int n, int *A, int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key)
    i++;
  if(i==n) return NOTFOUND;

  return 1;

}


int main(){
  int i,n,q,A[MAX],B[MAX],count=0;
  
  scanf("%d",&n);

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

  scanf("%d",&q);

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

  for(i=0;i<q;i++){
    if(linearSearch(n,A,B[i])==1) count++;
  }

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

  return 0;
}



Measured memory_bytes: 2108
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** *******  *** ************* **
*** ******** ** *************** *
**********_**********************
* |   /  / \  \     /    /\     *
* |  /  |   |  \   /    /  \    *
* | /   |   |   \ /    /    \   *
* |+\   |   |    |    /______\  *
* |  \  |   |    |   |        | *
* |   \  \_/     |   |        | *
********************************/
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a<b) ? b : a))
#define remin(a, b) (a = ((a<b) ? a : b))
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout<<fixed<<setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

lli power(lli x,lli y,lli p = (lli)(1e13)) { 
	lli res = 1;	 
	x = x % p; 
	while (y > 0) 
	{ 
		if (y & 1) 
			res = (res*x) % p; 
		y = y>>1; 
		x = (x*x) % p; 
	} 
	return res; 
} 

const lli N = 5e5 + 3;
lli n, m, a, b;

void solve(){
    cin >> n;
    string res = "", crs = "abcdefghijklmnopqrstuvwxyz";
    while(n > 26){
        res += crs[(n-1)%26];
        n -= (n-1)%26;
        n /= 26;
    }
    res += crs[(n-1)%26];
    reverse(all(res));
    cout << res ;
    return;
}


int main(){
    fastIO; 
    lli t = 1; 
    // cin>>t;
    NA(i,0,t) {
        // cout<<"Case "<<i+1<<": "; 
        solve();
    }
    return 0;
}


Measured memory_bytes: 3624
day = chomp(readline())
if day == "SUN"
    println(7)
elseif day == "MON"
    println(6)
elseif day == "TUE"
    println(5)
elseif day == "WED"
    println(4)
elseif day == "THU"
    println(3)
elseif day == "FRI"
    println(2)
elseif day == "SAT"
    println(1)
end


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

const int mxn=1e5+10;
ll vis[mxn];
vector<ll> adj[mxn];
ll dp[mxn];

vector<ll> top;

void dfs(ll u){
  vis[u]=1;
  for(auto c:adj[u]){
    if(!vis[c]){
      dfs(c);
    }
  }
  top.push_back(u);
}

int main(){
  ll n,m;
  cin >> n >> m;
  ll i,j;
  ll x,y;
  for(i=0;i<m;i++){
    cin >> x >> y;
    adj[x].push_back(y);
  } 

  for(i=1;i<=n;i++){
    if(!vis[i]){
      dfs(i);
    }
  }
  ll mx=0;
  for(auto c:top){
    ll ans=0;
    //cout << c << endl;
    for(auto d:adj[c]){
      ans=max(ans,dp[d]);
    }
    ans++;
    dp[c]=ans;
    mx=max(mx,ans);
  }
  cout << mx-1 << endl;



}

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


int main(){
    int N,M;
    int p;
    string s;
    int q[100000] = {};

    cin >> N >> M;
    int ans = 0;
    int pena = 0;
    for(int i = 0;i < M;i++){
        cin >> p >> s;
        if(s == "WA"){
            if(q[p] <= 0) q[p] --;
        }else if(s == "AC" && q[p] <= 0){
            ans++;
            pena += abs(q[p]);
            q[p] = 1;
        }
    }
    cout << ans << " " << pena << endl;

}

Measured memory_bytes: 640
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long A, B;
    scan(A, B);
    repeat(min(A, B)).take(max(A, B)).map!text().join().writeln();
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debug_out() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

int main() {
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
#define debug(...) 3
    fastIO;
#endif
    int h, w, k;
    cin >> h >> w >> k;
    char mat[h + 1][w + 1];
    forn(i, h) {
        string cad;
        cin >> cad;
        forn(j, w) {
            mat[i][j] = cad[j];
        }
    }
    int ans = 0;
    for(int mask1 = 0; mask1 < (1 << h); mask1++) {
        for(int mask2 = 0; mask2 < (1 << w); mask2++) {
            int cnt = 0;
            forn(i, h) {
                forn(j, w) {
                    bool bit1 = (mask1 & (1 << i));
                    bool bit2 = (mask2 & (1 << j));
                    if(!(bit1 || bit2) && mat[i][j] == '#')cnt++;
                }
            }
            if(cnt == k)ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
vector<int>v;
int main(void)
{
    int testCase,n;
    scanf("%d",&testCase);
    while(testCase--){
        v.clear();
        int i=3;
        while(i--){
            scanf("%d",&n);
            v.push_back(n);
        }
        sort(v.begin(),v.end());
        if((v[0]*v[0]+v[1]*v[1])==(v[2]*v[2]))printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, PLL> PP;
typedef unsigned int ui;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const ll INF = 1e18;
#define maxn 510
int dp[maxn][maxn], odp[maxn][maxn], n, m, mod;


int main()
{
	boost;
	cin >> n;
	int parz = 0, nparz = 0;
	FOR(i, 1, n)
	{
		int a;
		cin >> a;
		if (a % 2 == 0) parz++;
		else nparz++;
	}
	if (nparz % 2 == 1) cout << "NO";
	else cout << "YES";
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    A.sort()
    sa = [0]
    for a in A:
        sa.append(sa[-1] + a)

    b = []
    for i in range(N-1):
        if 2*sa[i+1] >= A[i+1]:
            b.append(True)
        else:
            b.append(False)
    b.append(True)

    ans = 0
    for c in b[::-1]:
        if c:
            ans += 1
        else:
            break
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


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

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

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

  int mi = a[0], ma = 0;
  int ans = 0, dis = 0;
  for(int i=1; i<n; i++){
    if(a[i] < mi){
      mi = a[i];
      ma = 0;
    }
    else{
      if(a[i] - mi > dis){
        ans = 1;
        dis = a[i] - mi;
      }
      else if(a[i] - mi == dis){
        ans++;
      }
      ma = max(ma, a[i]);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#K番目に"大きいもの"なのでおおきいものから調べないといけない

A, B , K = map(int, input().split())

ans = 1
counter = 0

for i in range(min(A,B), 0 , -1):
    if A % i == 0 and B % i == 0:
        counter += 1
        ans = i
    
    if counter == K:
        break

print(ans)




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

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define sort(vec) std::sort(all(vec))
#define rev(vec) std::reverse(all(vec))

void input(){return;}
template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}

void inputVector(){return;}
template<typename First,typename... Rest> void inputVector(std::vector<First> &first,Rest&... rest){
    int N = first.size();
    for(int i = 0;i < N;i++){
        std::cin >> first[i];
    }
    inputVector(rest...);
}

template<typename First,typename Second> void inputTwoVector(std::vector<First> &first,std::vector<Second>& second){
    int N = first.size();
    for(int i = 0;i < N;i++){
        std::cin >> first[i] >> second[i];
    }
}

int getsum(int N){
    int sum = 0;
    while(N != 0){
        sum += N % 10;
        N /= 10;        
    }
    return sum;
}

void calculate(){
    int N;
    input(N);
    int min = 100000;
    for(int a = 1;a < N;a++){
        int b = N - a;
        min = std::min(min,getsum(a) + getsum(b));
    }
    std::cout << min << '\n';
}

int main(int,char**){
    calculate();    
}




Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 10:51:17 2020

@author: liang
"""
A, B = map(int, input().split())

res = B*10

for i in range(10):
    tmp =int((res + i)*0.08)
    if  tmp == A:
        print(res+i)
        break
else:
    print(-1)

Measured memory_bytes: 9156
#include<iostream>
#include<map>
#include<cctype>
using namespace std;
#define inRange(x,a,b) (a <= x && x <= b)

map<string, int> table;
string s;
bool ng;

int num(int &pos){
    int ret = 0;
    while(pos < s.length() && isdigit(s[pos]))  ret = ret*10 + s[pos++]-'0';
    return ret;
}

int f(int &pos){
    if(s[pos] == '('){
        pos++;  // (
        int acc = 0;
        while(pos < s.length() && s[pos] != ')'){
            acc += f(pos);
        }
        pos++;  // )
        acc *= num(pos);
        return acc;
    }else{
        string mol = "";
        mol += s[pos++];
        if(pos < s.length() && inRange(s[pos], 'a', 'z'))   mol += s[pos++];
        if(table.count(mol) == 0)   ng = true;
        int acc = table[mol];
        if(pos < s.length() && isdigit(s[pos])) acc *= num(pos);
        return acc;
    }
}

int main(){
    while(cin >> s, s != "END_OF_FIRST_PART"){
        int x;  cin >> x;
        table[s] = x;
    }
    while(cin >> s, s != "0"){
        s = "(" + s + ")1";
        ng = false;
        int pos = 0;
        int ans = f(pos);
        if(ng)  cout << "UNKNOWN" << endl;
        else    cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a, b; cin >> a >> b;
  if (a*b % 2 == 0) cout << "Even" << endl;
  else cout << "Odd" << endl;
  return 0;
}

Measured memory_bytes: 3136
#include<stdio.h>

#define N 100

int main()
{
  int kin,i,chiyonosuke,j,sotaro[N],flag=0,tmp;

  scanf("%d",&kin);
  for(i=0;i<kin; i++){
    scanf("%d",&sotaro[i]);
  }
  for(i=0;i<kin;i++)
  {
      for(j=kin-1;j>i;j--)
	{
	  if(sotaro[j]<sotaro[j-1]){
	    tmp=sotaro[j-1];
	    sotaro[j-1]=sotaro[j];
	    sotaro[j]=tmp;
	    flag++;
	  }
	}
    }
  for(i=0;i<kin;i++)
    {
      if(i>0)printf(" ");
      printf("%d",sotaro[i]);
    }
  printf("\n");
  printf("%d\n",flag);
  return 0;
}



Measured memory_bytes: 2108
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define PII pair<int, int>
using namespace std;
const int MAXN = 1000000;

int sum[MAXN+5];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    sum[1] = 0;
    for (int i = 2; i <= MAXN; i++) {
        if (sum[i] == 0) {
            for (int j = i + i; j <= MAXN; j += i) {
                sum[j] = 1;
            }
        }
        sum[i] = sum[i - 1] + !sum[i];
    }

    int N;
    while (cin >> N) {
        cout << sum[N] << "\n";
    }
}



Measured memory_bytes: 6964
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(usize);
    let ps = util::gets::<usize>();

    let mut amos = vec![1i64; n];
    let mut bmos = vec![-1i64; n];

    for (i, &p) in ps.iter().enumerate() {
        let d = i as i64;
        amos[0] -= d;
        amos[p - 1] += d;
        if p < n {
            bmos[p] -= d;
        }
    }

    let mut x = n as i64 * n as i64;
    let mut a = Vec::new();

    for &t in &amos {
        x += t;
        a.push(x);
    }

    let mut x = n as i64 * n as i64;
    let mut b = Vec::new();

    for &t in &bmos {
        x += t;
        b.push(x);
    }

    println!(
        "{}",
        a.iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );

    println!(
        "{}",
        b.iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}


Measured memory_bytes: 6780