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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 55, M = 3e3, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();

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

    ll ans = 0;
    for(int i = 0;i < n - 1;i++){
        ll sum = a[i] + a[i + 1];
        if(sum <= x)    continue;
        ll mn = min(a[i + 1], sum - x);
        a[i + 1] -= mn;
        ans += sum - x;
    }

    cout << ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int N = 300006;

int main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int>a(n);
    for(int &x : a) cin >> x;
    sort(a.begin(), a.end());
    ll ans = 0;
    for (int i = 0; i < k; i++) ans += a[i];
    cout << ans << '\n';
    return 0; 
}
 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string S, T;
	cin >> S >> T;
	int ans = 100000;
	for (int i = 0; i < (int) S.size(); i++) {
		if (i + (int) T.size() > (int) S.size()) break;
		int s = 0;
		for (int j = 0; j < (int) T.size(); j++) {
			s += (S[i + j] != T[j]);
		}
		ans = min(s, ans);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
   string a,b,c;
   cin>>a;
   if(a=="a"||a=="e"||a=="i"||a=="o"||a=="u"){
       cout<<"vowel"<<endl;
   }
   else{
       cout<<"consonant"<<endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;

int fact[N], invfact[N];

void pre() {
	fact[0] = 1;
	for(int i = 1; i < N; i++) {
		fact[i] = fact[i - 1] * i % mod;
	}
	invfact[N - 1] = modpow(fact[N - 1], mod - 2, mod);
	for(int i = N - 2; i >= 0; i--) {
		invfact[i] = invfact[i + 1] * (i + 1) % mod;
	}
}
 
int ncr(int x, int y) {
	if(y > x)
		return 0;
	int res = fact[x] * invfact[y] % mod * invfact[x - y] % mod;
	return res;
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	#endif

	pre();
	int n, k;
	cin >> n >> k;
	int a[n + 1], sum[n + 1] = {0};
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	if(k == 1) {
		cout << 0;
		return 0;
	}
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++) {
		sum[i] = sum[i - 1] + a[i];
	}
	int ans = 0;
	for(int i = k - 2; i <= n - 2; i++) {
		int t1 = sum[n] - sum[i + 1];
		while(t1 < 0) {
			t1 += mod;
		}
		t1 %= mod;
		int t2 = sum[n - (i + 1)];
		while(t2 < 0) {
			t2 += mod;
		}
		t2 %= mod;
		int tmp = (t1 - t2 + mod) % mod;
		ans = (ans + ncr(i, k - 2) * tmp % mod) % mod;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <deque>
using namespace std;

typedef deque<int> DI;

int main(void){
  int n, qn;
  vector<DI> vs;
  
  cin >> n >> qn;
  vs = vector<DI>(n);
  for (int i=0; i<qn; i++){
    int q, t;
    cin >> q >> t;
    if (q==0){
      int x;
      cin >> x;
      vs[t].push_front(x);
    } else if (q==1){
      if (!vs[t].empty()) cout << vs[t].back() << endl;
    } else { // q==2
      if (!vs[t].empty()) vs[t].pop_back();
    }
  }
  
  return 0;
}


Measured memory_bytes: 4416
import sys
input = sys.stdin.readline

n = int(input())
a = [int(i) for i in input().split()]

target = 1
size = 0
for i in range(n):
    if a[i] == target:
        target += 1
    else:
        size += 1

if size == n:
    print(-1)
else:
    print(size)

Measured memory_bytes: 72140
# AOJ ITP1_9_D

def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    string = input()
    n = int(input())
    for i in range(n):
        command = input().split()
        a = int(command[1])
        b = int(command[2])
        if command[0][0] == 'r':
            front = string[0 : a]
            back = string[b + 1 : len(string)]
        if command[0][2] == 'p':
            string = front + command[3] + back
        elif command[0][2] == 'v':
            string = front + string[a : b + 1][::-1] + back
        else:
            print(string[a : b + 1])

if __name__ == "__main__":
    main()


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

int main() {
	double a, b, x;
	cin >> a >> b >> x;
	double c, ans;
	
	if (x <= a * a * b / 2) {
		c = 2.0 * x / a / b;
		ans = atan(b / c) * 180 / acos(-1);
	} else {
		c = 2.0 * b - 2.0 * x / a / a;
		ans = atan(c / a) * 180 / acos(-1);
	}
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int n,m,f[2000005],g[2000005],fac[2000005],inv[2000005];
char s[2000005];
int qpow(int x,int y){
    int res = 1;
    while(y) {
        if(y & 1) res = (ll)res * x % mod;
        x = (ll)x * x % mod;
        y >>= 1;
    }
    return res;
}
int C(int x,int y) {
    return (ll)fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main()
{
    scanf("%d",&n);
    scanf("%s",s);
    m = strlen(s);
    fac[0] = 1;
    rep(i,1,n+m) fac[i] = (ll)fac[i-1] * i % mod;
    inv[n + m] = qpow(fac[n + m], mod - 2);
    per(i,n+m-1,0) {
        inv[i] = (ll)inv[i + 1] * (i + 1) % mod;
    }

    //dp[0][0] = 1;
    /*rep(i,1,n + m) rep(j,0,min(i,m))  {
        if(j != m) {
            dp[i][j] = dp[i-1][j] * 25ll % mod;
            if(j) {dp[i][j] += dp[i-1][j-1];if(dp[i][j] >= mod) dp[i][j] -= mod;}
        }
        else {
            dp[i][j] = dp[i-1][j] * 26ll % mod;
            if(j) {dp[i][j] += dp[i-1][j-1];if(dp[i][j] >= mod) dp[i][j] -= mod;}
        }
    }
    printf("%d\n",dp[n+m][m]);*/
    rep(i,m-1,n+m) {
        f[i] = (ll)C(i, m - 1) * qpow(25, i - m + 1) % mod;
    }
    rep(i,m,n+m){
        g[i] = (g[i - 1] * 26ll % mod + f[i - 1]) % mod;
    }
    printf("%d\n",g[n + m]);
    return 0;
}

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

int main() {
    int n, bef, tmp, ret;
    cin >>n >>bef;
    ret = bef;
    for (int i = 1; i < n-1; i++) {
        cin >> tmp;
        ret += min(bef, tmp);
        bef = tmp;
    }
    ret += bef;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
from operator import mul
from functools import reduce
import math

n,a,b=map(int,input().split())

so=10**9+7

large=(pow(2,n,so)-1)

def kumiawase(n,r):
    over=1
    for i in range(r):
        over *= n-i
        over %= so
    under = math.factorial(r)
    return over * pow(under,so-2,so)

ajogai = kumiawase(n,a) % so
bjogai = kumiawase(n,b) % so
print((large - ajogai - bjogai + 2*so) % so)

Measured memory_bytes: 6032
#include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
  using namespace std;
using namespace __gnu_pbds;
  #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define double long double
  #define all(v) v.begin(),v.end()
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define db long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const double PI = acos(-1);
  const int N = 200005;
  int mod = 1e9 + 7;
     
 
    vector<int> adj[N];
    bool vis1[N];
    bool vis2[N];
    int dist1[N];
    int dist2[N];
 
    void bfs1(int s)
    {
        queue<int> q;
        q.push(s);
        dist1[s] = 0;
        while(!q.empty())
        {
          int k = q.front();
          q.pop();
 
          for(auto i:adj[k])
          {
            if(!vis1[i])
            {
              vis1[i] = true;
              dist1[i] = dist1[k] + 1;
              q.push(i);
            }
          }
        }
    }
    void bfs2(int s)
    {
        queue<int> q;
        q.push(s);
        dist2[s] = 0;
        while(!q.empty())
        {
          int k = q.front();
          q.pop();
 
          for(auto i:adj[k])
          {
            if(!vis2[i])
            {
              vis2[i] = true;
              dist2[i] = dist2[k] + 1;
              q.push(i);
            }
          }
        }
    }
 
int32_t main()
{
       
    int n,u,v;
    cin >> n >> u >> v;
 
    rep(i,1,n-1)
    {
      int x,y;
      cin >> x >> y;
      adj[x].PB(y);
      adj[y].PB(x);
 
    }
 
    
 
    bfs1(u);
    bfs2(v);
    dist1[u] = 0;
    dist2[v] = 0;
 
 
    int ans = 0;
 
    rep(i,1,n)
    {
 
      if(dist1[i]<dist2[i])
      {
        ans = max(dist2[i]-1,ans);
      }
    }
 
 
 
    cout << ans ;
 
   return 0;
}       


Measured memory_bytes: 13860
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define forg(i,x) for(int i=first[x];i;i=nxt[i])
#define uu unsigned
#define fi first
#define se second
#define od(x) ((x)&1)
#define ev(x) (od(x)^1)
#define mi2(x) (1<<(x))
#define scanf a1234=scanf
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
int a1234;
char buf[1<<18],*bufs=buf,*buft=buf;
inline int gc(){
    return bufs==buft&&(buft=(bufs=buf)+fread(buf,1,1<<18,stdin)),bufs==buft?-1:*bufs++;
}
inline void xxx(){for(;;);}

const int mxn=5e5+3,mod=998244353;int n,m;
long long jc[mxn],inv[mxn];
inline long long por(long long a,int b){
	long long res=1;
	for(;b;b>>=1){
		if(b&1)res=res*a%mod;
		a=a*a%mod;
	}
	return res;
}
inline long long C(int a,int b){return jc[a]*inv[a-b]%mod*inv[b]%mod;}
inline long long P(int a,int b){return jc[a]*inv[a-b]%mod;}

int main(){
    scanf("%d%d",&n,&m);
    jc[0]=inv[0]=1;for(int i=1;i<mxn;++i)jc[i]=jc[i-1]*i%mod;
    inv[mxn-1]=por(jc[mxn-1],mod-2);for(int i=mxn-2;i;--i)inv[i]=inv[i+1]*(i+1)%mod;
    int ans=0;
    for(int i=0,fu=-1;i<=min(n,m);++i){
    	fu*=-1;
    	ans+=P(n,i)*C(m,i)%mod*/*por(2,i)%mod**/por(m+1,n-i)%mod*por(n+1,m-i)%mod*fu,ans%=mod;
//    	printf("%d\n",ans);
    }
    if(ans<0)ans+=mod;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 11632
#include <stdio.h>

int main(void) {
	
	int a, b;

	do {
		scanf("%d %d",&a,&b);
	} while (-1000 > a || b > 1000);

	if (a > b)
		printf("a > b\n");
	else if (a < b)
		printf("a < b\n");
	else
		printf("a == b\n");

	return 0;
}

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

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

  string T = "ACGT";
  int ans = 0;

  for (int i = 0; i < str.size(); i++) {
    int num = 0;
    for (int j = i; j < str.size(); j++) {
      bool ok = false;
      for (int k = 0; k < T.size(); k++) {
        if (str[j] == T[k]) {
          num++;
          ok = true;
        }
      }
      if (ok == false) {
        break;
      }
    }
    ans = max(ans, num);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;

class program
{

    public static void Main()
    {
        var str = Console.ReadLine().Split(' ');
        double x1 = double.Parse(str[0]);
        double y1 = double.Parse(str[1]);
        double x2 = double.Parse(str[2]);
        double y2 = double.Parse(str[3]);

        double x = Math.Abs(x2 - x1);
        double y = Math.Abs(y2 - y1);

        Console.WriteLine(Math.Sqrt(x * x + y * y));
    }
}

Measured memory_bytes: 5744
import sys
X, N = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
if X not in P:
    print(X)
    sys.exit()

for i in range(55):
    low = X - i
    if low not in P:
        print(low)
        break
    high = X + i
    if high not in P:
        print(high)
        break

Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9


bool primes[1000000];

void make_prime(){
	primes[0] = primes[1] = true;
	for(int i=2; i*i<=1000000; i++)if( !primes[i] )
		for(int j=i*2; j<1000000; j+=i)primes[j]=true;
}

int main(){
	int n,ret;
	make_prime();
	while(~scanf("%d",&n)){
		ret = 0;
		for(int i=2; i<=n; i++)if( !primes[i] )ret++;
		printf("%d\n",ret);
	}
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int x;
    cin >> x;
    if (x < 1200)
    {
        OP("ABC");
    }
    else
    {
        OP("ARC");
    }
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

int n, k, lim;
bool dislike[10];

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1, x; i <= k; ++i) {
    scanf("%d", &x);
    dislike[x] = true;
  }
  lim = n * 10;
  for (int i = n; i <= lim; ++i) {
    int tmp = i, flag = 1, now;
    do {
      now = tmp % 10;
      if (dislike[now]) {
        flag = 0;
        break;
      }
    } while (tmp /= 10);
    if (flag)
      return printf("%d\n", i), 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<numeric>
#include<limits>
#include <cstdint>
#include<stack>
#include<queue>
using namespace std;
#define ll long long int
#define rep(N) for(ll i=0;i<N;i++)
#define rep2(N1,N2) for(ll i=0;i<N1;i++)for(ll j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(ll i=0;i<N1;i++)for(ll j=0;j<N2;j++)for(ll k=0;k<N3;k++)
#define For(i,N) for(ll i=0;i<N;i++)

void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int ctoi(char c) {
	return c - '0';
}

ll kai(ll x) {
	ll a = 1;
	if (x <= 0)
		return 1;
	else {
		for (ll i = 0; i < x; i++)
			a = a * (i + 1);
		return a;
	}
}

ll rui(ll x, ll y) {
	ll a = 1;
	for (ll i = 0; i < y; i++)
		a = a * x;
	return a;
}
const int nmax = 150;
int cccc[nmax][nmax];
ll comb(ll n, ll k) {
	if (n < k) {
		cout << "error n<k" << endl;
		return -1;
	}
	if (cccc[n][k] > 0)return cccc[n][k];
	if (k == 0 || n == k)return 1;
	return cccc[n][k] = comb(n - 1, k - 1) + comb(n - 1, k);
}

ll keta(ll a) {
	ll i = 1;
	while (1) {
		if (a < pow((ll)10, i))
			return i;
		i++;
	}
}
vector<ll> v;
ll n, m;
//m進数全探索
ll inc(ll a = n - 1) {
	if (a == 0 && v[0] == m) {
		v[0] = -1;
		return v[0];
	}
	if (v[a] == m) {
		v[a] = 0;
		inc(a - 1);
		return v[a];
	}
	else {
		++v[a];
		return v[a];
	}
}

ll mod = 1000000007;

ll modpowl(ll a, ll b) {
	if (b == 0) {

		return 1;
	}
	if (b == 1) {

		return a;
	}
	if (b >= 2) {
		if (b % 2 == 0) {
			ll c = modpowl((a*a) % mod, b / 2);
			c = c % mod;

			return c;
		}
		else {
			ll c = (modpowl((a*a) % mod, b / 2) % mod)*a;
			c = c % mod;

			return c;
		}
	}
}
ll llpow(ll a, ll b) {
	if (b == 0) {

		return 1;
	}
	if (b == 1) {

		return a;
	}
	if (b >= 2) {
		if (b % 2 == 0) {
			ll c = llpow((a*a), b / 2);
			c = c;

			return c;
		}
		else {
			ll c = (llpow((a*a), b / 2))*a;
			c = c;

			return c;
		}
	}
}
std::vector<ll> Eratosthenes(ll N)
{
	std::vector<bool> is_prime(N + 1);
	for (ll i = 0; i <= N; i++)
	{
		is_prime[i] = true;
	}
	std::vector<ll> P;
	for (ll i = 2; i <= N; i++)
	{
		if (is_prime[i])
		{
			for (ll j = 2 * i; j <= N; j += i)
			{
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}

int main() {
	cout.precision(20);
	char c;
	cin >> c;
	c++;
	cout << c;
}

Measured memory_bytes: 256
#include <stdio.h>

#define NUM 100

int main()
{
  int n,i,j,k,l = 0,flag;
  int a[NUM];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }
  flag = 1;
  while(flag){
    flag = 0;
    for(j = i - 1;j > 0;j--){
      if(a[j] < a[j-1]){
	k = a[j-1];
	a[j-1] = a[j];
	a[j] = k;
	flag = 1;
	l++;
      }
    }
  }
  printf("%d",a[0]);
  for(i = 1;i < n;i++){
    printf(" %d",a[i]);
  }
  printf("\n");
  printf("%d\n",l);

  return 0;
}

      



Measured memory_bytes: 2104
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize,
        av: [u64; n]
    };

    let mut res = 0_u64;
    let mut prev = 0;
    for a in av {
        if a < prev {
            res += prev - a;
        } else {
            prev = a;
        }
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 4576
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int dist(const int a, const int b) {
    //return max(a,b) - min(a,b);
    //assert(a < b);
    return b - a;
}

int main(int argc, const char * argv[]) {
    vector<int> coords(5, 0);
    for(int i = 0; i < 5; i++) {
        cin >> coords[i];
    }
    std::sort(coords.begin(), coords.end(), greater<int>());
    
    int k = 0;
    cin >> k;
    
    for(int i = 0; i < 5; i++) {
        for(int j = 0; j < i; j++) {
            int d = dist(coords[i], coords[j]);
            if(k < d) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}


Measured memory_bytes: 256
void main() {
	auto ip = readAs!(int[]), A = ip[0], P = ip[1];
	writeln((A*3 + P)/2);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
const int INF = 1e9;
const int MOD = 1e9+7;

class BIT
{
private: 
    vector<bitset<26>> bit;
public:
    BIT(const vector<bitset<26>> &v) // v: 1-indexed
    {
        bit.resize(v.size());
        for(int i = 1; i < bit.size(); i++) add(i, v[i]);
    }

    void add(int a, bitset<26> w)
    {
        for(int x = a; x < bit.size(); x += x & -x) bit[x] |= w;
    }

    void reset(int a, bitset<26> w)
    {
        for(int x = a; x < bit.size(); x += x & -x) bit[x] ^= w;
    }

    int sum(int a)
    {
        int ret = 0;
        for(int x = a; x > 0; x -= x & -x) ret += bit[x].count();
        return ret;
    }
};

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int N, M; cin >> N >> M;
    vi count(N);
    REP(i, M)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        count[a]++;
        count[b]++;
    }
    REP(i, N)
    {
        if(count[i] % 2 == 1)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 640
def main():
    s = input().strip()
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            print(i, i + 1)
            break
    else:
        for i in range(2, len(s)):
            if s[i] == s[i - 2]:
                print(i - 1, i + 1)
                break
        else:
            print(-1, -1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
from collections import Counter
import numpy as np


def main():
    n = int(input())
    a = np.array([int(i) for i in input().split()])
    b = np.array([int(i) for i in input().split()])
    ca = Counter(a)
    cb = Counter(b)
    for k in cb.keys():
        if cb[k] > n - ca[k]:
            print("No")
            return
    while any(a == b):
        s = max(ca[k] for k in cb.keys())
        b = np.roll(b, s)
    print("Yes")
    print(*b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74360
#include <stdio.h>
int main(){
	int Elements[100][100];
	int line,column;
	int i,n;
	
	scanf("%d %d",&line,&column);
	for(i=0;i<line;i++){
		for(n=0;n<column;n++){
			scanf(" %d",&Elements[i][n]);
		}
	}
	
	int LineSum[100],ColumnSum[100];
	int a,b,c,d;
	
	for(a=0;a<line;a++){
		LineSum[a]=0;
		for(b=0;b<column;b++){
			LineSum[a]=LineSum[a]+Elements[a][b];
		}
	}
	
	for(c=0;c<column;c++){
		ColumnSum[c]=0;
		for(d=0;d<line;d++){
			ColumnSum[c]=ColumnSum[c]+Elements[d][c];
		}
	}
	
	int s,t;
	
	for(s=0;s<line;s++){
		for(t=0;t<column;t++){
			printf("%d ",Elements[s][t]);
		}
		printf("%d\n",LineSum[s]);
	}
	
	int l,lastnumber=0;
	for(l=0;l<column;l++){
		printf("%d ",ColumnSum[l]);
		lastnumber=lastnumber+ColumnSum[l];
	}
	printf("%d\n",lastnumber);
	return 0;
	
}


Measured memory_bytes: 2060
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n;
	String[] f;
	int[] w, s;
	int[] a, best;
	double bestG;

	void run(){
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			f=new String[n];
			w=new int[n];
			s=new int[n];
			for(int i=0; i<n; i++){
				f[i]=sc.next();
				w[i]=sc.nextInt();
				s[i]=sc.nextInt();
			}
			solve();
		}
	}

	void solve(){
		a=new int[n];
		best=new int[n];
		for(int i=0; i<n; i++){
			a[i]=i;
		}
		bestG=INF;
		rec(0);
		for(int e : best){
			println(f[e]);
		}
	}

	void rec(int j){
		if(j==n){
			// 0ツつェツ暗ェツ氾板可コ
			int sumW=0;
			int nW=0;
			for(int i=n-1; i>=0; i--){
				if(s[a[i]]<sumW){
					return;
				}
				sumW+=w[a[i]];
				nW+=(i+1)*w[a[i]];
			}
			double g=(double)nW/sumW;
			if(g+EPS<bestG){
				System.arraycopy(a, 0, best, 0, n);
				bestG=g;
			}
			return;
		}

		for(int i=j; i<n; i++){
			int t=a[i];
			a[i]=a[j];
			a[j]=t;
			rec(j+1);
			t=a[i];
			a[i]=a[j];
			a[j]=t;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main() {
  long n;
  cin>>n;
  
  long ans=0;
  vector<long>d(4000);
  d.at(0)=100;
  rep2(i,1,4000){
    d.at(i)=d.at(i-1)+d.at(i-1)/100;
  }
  rep(i,4000){
    if(n<=d.at(i)){
      cout<<i<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
const int N = 1e5 + 10;
using namespace std;
typedef long long ll;
int mod = 1e9 + 7;
typedef pair<int, int>pii;
vector<pii>rec;
int main()
{

    int n;
    ll k;
    while (~scanf("%d%lld", &n, &k))
    {
        rec.clear();
        for (int i = 0; i < n; i++)
        {
            int a, b;
            scanf("%d%d", &a, &b);
            rec.push_back(make_pair(a, b));
        }
        sort(rec.begin(), rec.end());
        for (int i = 0; i < rec.size(); i++)
        {
            // if (rec[i].second <= k)
            k -= rec[i].second;
            if (k <= 0)
            {
                printf("%d\n", rec[i].first);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1400
N = int(input())
table = [list(map(int, input().split(' '))) for _ in range(2)]

nexts = [(1, 0), (0, 1)]
max_n = -float('inf')
buf = [(0, 0, table[0][0])]

while buf:
    i, j, n = buf.pop(0)

    for di, dj in nexts:
        next_i, next_j = i + di, j + dj

        if 0 <= next_i < 2 and 0 <= next_j < N:
            next_n = n + table[next_i][next_j]
            max_n = max(max_n, next_n)
            buf.append((next_i, next_j, next_n))


print(max_n)






Measured memory_bytes: 39024
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int S[100000];
int main(){
  int i, j, x;
  long long res, tmp;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(S[Lj4PdHRW]);
    }
  }
  N--;
  res = 0;
  for(x=1;x<N;x++){
    i = 0;
    j = N;
    tmp = 0;
    for(;;){
      i += x;
      j -= x;
      if(i==j || i+x > N || j-x < 0){
        break;
      }
      if(N%x==0 && i > j){
        break;
      }
      tmp += S[i] + S[j];
      chmax(res, tmp);
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190526-1

// --- original code ---
// int N, S[1d5];
// {
//   int i, j, x;
//   ll res, tmp;
// 
//   rd(N, S(N));
//   N--;
// 
//   res = 0;
//   rep(x,1,N){
//     i = 0;
//     j = N;
//     tmp = 0;
//     for(;;){
//       i += x;
//       j -= x;
//       if(i==j || i+x > N || j-x < 0) break;
//       if(N%x==0 && i > j) break;
//       tmp += S[i] + S[j];
//       res >?= tmp;
//     }
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
  int n;
  cin >> n;
  int m = -1, p = 0;
  rep(i, n)
  {
    int a, b;
    cin >> a >> b;
    if (a > m)
    {
      m = a;
      p = b;
    }
  }
  cout << (m + p) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-8;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    cout<<(1000-n%1000)%1000<<endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

ll min(ll a, ll b)
{
	if (a < b) return a;
	else return b;
}

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

	cin >> a >> b >> c;

	if (a*b*c % 2 == 0) {
		cout << 0 << endl;
	}
	else {
		cout << min(min(a*b, a*c), b*c) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
a=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n=int(input())
for i in range(n):
    b,f,r,v=[int(j) for j in input().split()]
    a[b-1][f-1][r-1] += v
for i, b in enumerate(a):
    for f in b:
        for r in f:
            print(" {}".format(r),end="")
        print()
    if i< 3:
        print("#"*20)


Measured memory_bytes: 5620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();
		String target = S.charAt(K - 1) + "";
		System.out.println(S.substring(0, K - 1) + target.toLowerCase() + S.substring(K));

		sc.close();
	}
}


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

int main(){
  int n;
  cin >> n;
  int t[110000], x[110000], y[110000];
  t[0] = x[0] = y[0] = 0;
  for(int i = 0; i < n; i++){
    cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
  }
  
  bool can = true;
  for(int i = 0; i < n; i++){
    int dt = t[i + 1] - t[i];
    int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
    if(dt < dist) can = false;
    if(dist % 2 != dt % 2) can = false;
  }
  
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 4784
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

constexpr int LIM = 51, LIM_CUBE = LIM*LIM*LIM;

ll INF = 1LL << 60;

struct sp {
    ll w, v; int id;
    sp() {}
    ~sp() {}
    sp(ll w, ll v, int id): w(w), v(v), id(id) {}
    bool operator < (const sp& o) const {
        return v * o.w > o.v * w;
    }
};

ll N, X, D, M[LIM], P[LIM];

sp vp[LIM];
ll dp[LIM_CUBE];

vector<int> children[LIM];

void set_val(int v) {
    ll sum_m = M[v], sum_v = 1;
    for (int w : children[v]) {
        set_val(w);
        sum_m += vp[w].w;
        sum_v += vp[w].v;
    }
    vp[v].id = v;
    vp[v].w = sum_m;
    vp[v].v = sum_v;
}

int main() {
    cin >> N >> X >> D >> M[0];
    for (int j = 1; j < N; ++j) {
        cin >> M[j] >> P[j]; --P[j];
        children[P[j]].push_back(j);
    }

    set_val(0);

    sort(vp, vp+N);

    fill(dp, dp + LIM_CUBE, INF);
    dp[0] = 0;
    for (int j = 0; j < N; ++j) {
        int c = min(N, D);
        for (int s = 1; c > 0; s <<= 1) {
            s = min(s, c); c -= s;
            int bound = s * vp[j].v;
            ll cost = s * vp[j].w;
            for (int v = LIM_CUBE-1; v >= bound; --v)
                dp[v] = min(dp[v], dp[v - bound] + cost);
        }
    }

    ll ans = 0;

    for (int v = 0; v < LIM_CUBE; ++v) {
        ll cap = X - dp[v];
        if (cap < 0) continue;
        ll sum_v = v;
        for (int j = 0; j < N; ++j) {
            ll c = (vp[j].id == 0) ? cap : (D - min(N, D));
            ll take = min(c, cap / vp[j].w);
            sum_v += take * vp[j].v;
            cap   -= take * vp[j].w;
        }

        ans = max(ans, sum_v);
    }

    cout << ans << endl;

    return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		var a = ri();
		var s = rs();
		Console.WriteLine(a >= 3200 ? s : "red");
	}

	public Sol(){
		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
int n,m,k;
int a[100001],b[2001];
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<=n ;i++){
		cin >> a[i];
	}
	int ans=1;
	int dir=2;
	int last=0;
	for(int i=1; i<=n ;i++){
		if(i==last+1) continue;
		else if(a[i]==a[i-1]) continue;
		else if(dir==2) dir=(a[i]>a[i-1]);
		else if((dir==0)^(a[i]>a[i-1])) continue;
		else{
			last=i-1;
			ans++;
			dir=2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
vector<ll> w(100);

// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
    if (w[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(ll key) {
    ll ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll ok = (ll)w.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}
 
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
 
    ll a,b,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    sum+=v[0]-1;
    v[0]=1;
    ll size=2;
    mini=1;
    ll lastsum=0;
    for(ll i=1;i<n;i++){
        lastsum=sum;
        if(v[i]<size) a=1;
        else if(v[i]==size) {
            size++;
        }else{
            ll effective =v[i]-1;
            sum+=effective/size;
        }
        //cout<<v[i]<<" "<<sum-lastsum<<" "<<endl;
    }
    
    cout<<sum<<endl; 
    return 0;
}//14159265358979

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

int main(){
int n,k,q,tem;
cin >> n>>k>>q;
int a[n] = {0};
rep(i,q){
    cin>>tem;
    a[tem-1]++;
}

rep(i,n){
    if(a[i]+(k-q)>0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;
static const ll MAX_N = 100001;
static const ll MAX_M = 100001;

struct edge { int to, cost; };
typedef pair<ll, ll> P;
int V;
vector<edge> G[MAX_N];
ll d[MAX_N];
priority_queue<P, vector<P>, greater<P>> que;

void dijkstra(int s) {
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		rep(i, 0, G[v].size()) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	ll E, r;
	cin >> V >> E >> r;

	rep(i, 0, E) {
		int s, t, d; cin >> s >> t >> d;
		edge *e = new edge();
		e->to = t;
		e->cost = d;

		//G[s].push_back(*e);
		G[s].push_back(*(new edge{ t,d }));
	}

	dijkstra(r);

	rep(i, 0, V) {
		if (d[i] == INF)cout << "INF" << endl;
		else cout << d[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 45068
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int>q(n);
    int s = 0;
    f(i,0,n){
    	cin >> q[i];
    	s ^= q[i];
    }
    f(i,0,n){
    	int a1 = s^q[i];
    	cout << a1 << " ";
    }
    return 0;
}
 

Measured memory_bytes: 4740
def main():
    dist = []
    import numpy as np
    from collections import deque
    n, x, y = map(int,input().split())
    g = [[] for _ in range(n)] 
    for i in range(n-1):

        g[i] += i+1,
        g[i+1] += i,
    g[x-1] += y-1,
    g[y-1] += x-1,
    a = [0]*n
    for start in range(n):
        d = [-1] * n
        d[start] = 0
        q = deque([start])
        while q:
            v = q.popleft()
            for nv in g[v]:
                if d[nv] < 0:
                    d[nv] = d[v]+1
                    q.append(nv)
        for i in d:
            a[i] += 1
    #     dist.append(d)
    # dist = np.array(dist).flatten()
    # for i in range(1,n):
    #     print(int(np.count_nonzero(dist==i)/2))
    for i in range(1,n):
        print(int(a[i]/2))
    # print(' '.join(str(i//2) for i in a[1:]))
main()

Measured memory_bytes: 14552
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int N;
    cin >> N;
    vector<int> a(N * 3);
    REP(i, 0, N * 3)
    {
        cin >> a[i];
        a[i]--;
    }

    int add = 0, minf = -1e9;

    vector<vector<int>> dp(N, vector<int>(N, minf));
    vector<int> max_a(N, minf), next_max_a(N, minf);
    int max_v = 0, next_max_v = minf;
    dp[a[0]][a[1]] = 0;
    dp[a[1]][a[0]] = 0;
    max_a[a[0]] = 0;
    max_a[a[1]] = 0;

    auto update = [&](int x, int y, int val) {
        dp[x][y] = max({dp[x][y], dp[y][x], val});
        dp[y][x] = max({dp[x][y], dp[y][x], val});
        next_max_a[x] = max(next_max_a[x], dp[x][y]);
        next_max_a[y] = max(next_max_a[y], dp[x][y]);
        next_max_v = max(next_max_v, dp[x][y]);
    };

    for (int i = 2; i < N * 3 - 1; i += 3)
    {
        if (a[i] == a[i + 1] && a[i + 1] == a[i + 2])
        {
            ++add;
            continue;
        }

        vector<int> card = {a[i], a[i + 1], a[i + 2]};
        sort(card.begin(), card.end());
        vector<tuple<int, int, int>> query;

        REP(_, 0, 3)
        {
            query.emplace_back(card[1], card[2], dp[card[0]][card[0]] + 1);
            if (card[0] == card[1])
                REP(j, 0, N)
            query.emplace_back(j, card[2], max(dp[card[0]][j], dp[j][card[0]]) + 1);
            card.emplace_back(card[0]);
            card.erase(card.begin());
        }

        REP(_, 0, 3)
        {
            REP(j, 0, N)
            {
                update(j, card[0], max_a[j]);
            }
            update(card[0], card[1], max_v);
            update(card[0], card[2], max_v);

            card.emplace_back(card[0]);
            card.erase(card.begin());
        }

        for (auto &[x, y, z] : query)
        {
            update(x, y, z);
        }

        swap(max_a, next_max_a);
        max_v = next_max_v;
    }

    dp[a.back()][a.back()]++;
    int ans = 0;
    REP(i, 0, N)
    REP(j, 0, N)
    {
        ans = max(ans, dp[i][j]);
    }

    cout << ans + add << endl;
}

Measured memory_bytes: 19460
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;



int main(int argc, const char * argv[]) {
  int s;
  cin >> s;
  vector<int> a;
  a.push_back(s);
  int n;
  for(int i = 0; i < 1000000; i++){
    n = a.at(i);
    if(n%2 == 0){
      n /= 2;
    }else{
      n = 3 * n + 1;
    }
    a.push_back(n);
    for(int j = 0; j < a.size() - 1; j++){
      if(a.at(j) == n){
        cout << i + 2 << endl;
        return 0;
      }
    }
  }
  return 0;

}


Measured memory_bytes: 256
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

x, y = map(int, input().split())

n = int(((x + y) / 3))
r = min(x, y) - n

if (min(x, y)<n)or((x + y)%3!=0):   
    print(0)
else:
    a = cmb(n, r)%(10**9 + 7)
    print(int(a))

Measured memory_bytes: 46068
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <functional>
#include <bitset>
#include <queue>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using string_view = boost::string_ref;

#include <boost/function_output_iterator.hpp>

using namespace std;

int main()
{
    int a,b,t;
    cin >> a >> b >> t;
    
    cout << (t/a)*b << '\n';
    
    return 0;
}


Measured memory_bytes: 256