akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[3005][3005];
int main()
{
    string s1,s2,s3;
    cin>>s1>>s2;
    ll i,j;
    for(i=0;i<=s1.length();i++)
    {
        for(j=0;j<=s2.length();j++)
        {
            if(i==0||j==0) dp[i][j]=0;
            else if(s1[i-1]==s2[j-1]) dp[i][j]=1+dp[i-1][j-1];
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    i=s1.length(),j=s2.length();
    while(i>0&&j>0)
    {
        if(s1[i-1]==s2[j-1]) { s3=s1[i-1]+s3; i--; j--;}
        else if(dp[i-1][j]>dp[i][j-1]) i--;
        else j--;
    }
    cout<<s3<<endl;
    return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;

ll i,j;

int main(){
   ll N,K;
   cin>>N>>K;
   V h(N);
   rep(i,N)cin>>h[i];
   V cost(N);
   rep(i,N){
      if(i==0)cost[i]=0;
      else{
         cost[i]=INF;
         for(ll k=1;k<=min(K,i);k++){
            cost[i]=min(cost[i],cost[i-k]+abs(h[i]-h[i-k]));
         }
      }
   }
   cout<<cost[N-1]<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000007
vector<int> H;
vector<int> dp;

int N, K, h;

int CC(int s, int e){         //Calculation Cost
  return abs(H[s]-H[e]);
}

int main(){
  cin >> N >> K;
  dp.resize(N+1, MAX);
  H.resize(N+1, 0);

  for(int i = 1; i <= N; i++){ cin >> h; H[i] = h; }
  dp[1] = 0;

  /*iは目標位置、jは移動回数*/
  for(int i = 2; i <= N; i++){  
    for(int j = 1; j <= min(i-1, K); j++) 
      dp[i] = min(dp[i], dp[i-j]+CC(i,i-j));
  }
      

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

    

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,i,sum=0;
    cin>>a>>b;
    long long arr[b];
    for(i=0; i<b; i++)
    {
        cin>>arr[i];
    }
    for(i=0; i<b; i++)
    {
        sum=sum+arr[i];
    }
    if((sum)>a)
        cout<<"-1"<<endl;
    else
        cout<<a-sum<<endl;
}




Measured memory_bytes: 3656
from bisect import bisect_left,bisect_right
import sys
def input(): return sys.stdin.readline().strip()

def main(bisect_left=bisect_left, bisect_right=bisect_right):
    n = int(input())
    for i in range(1,10):
        for j in range(1,10):
            if i * j == n:
                print('Yes')
                return
    print('No')
main()

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cmath>
#include <cstdio>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
LL MOD = 1000000007;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N, 0);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    vector<LL> dp(K+1, 0);
    dp[0] = 1;
    for(int i=0; i<N; i++) {
        vector<LL> sum(K+2, 0);
        for(int j=0; j<=K; j++) {
            sum[j+1] = sum[j] + dp[j];
            sum[j+1] %= MOD;
        }
        vector<LL> next(K+1, 0);
        for(int j=0; j<=K; j++) {
            int right = j+1;
            int left = max(0, j - A[i]);
            next[j] = sum[right] - sum[left];
            next[j] %= MOD;
        
        }
        for(int j=0; j<=K; j++)
            dp[j] = next[j];

    }
    LL ans = dp[K];
    ans %= MOD;
    ans += MOD;
    ans %= MOD;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2644
import itertools

N = int(input())
point = []
length = 0
average = 0

for _ in range(N):
    point.append(list(map(int, input().split())))
    
combo = list(itertools.permutations(point, N))

for i in combo:
    for j in range(N - 1):
        average += ((i[j][0] - i[j+1][0])**2 + (i[j][1] - i[j+1][1])**2)**0.5
        
print(average / len(combo))

Measured memory_bytes: 10100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner (System.in);
		
		int a,b,c;
	   a = input.nextInt(); b = input.nextInt(); c  = input.nextInt();
	   
	  
	   if (a+b == c || c+a == b || b+c==a) {
		   System.out.println("Yes");
	   }
	   else {
		   System.out.println("No");
	   }
		   
	  
	}

}


Measured memory_bytes: 27076
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define MIN(a,b) (((a)<=(b))?(a):(b))
#define MAX(a,b) (((a)>=(b))?(a):(b))
#define ll long long int
using namespace std;

int CountTriangles(int A[], int n){
    sort(A, A + n);
    int count = 0;
    for( int i = (n - 1); i >= 1; i--){
        int l = 0, r = (i - 1);
        while(l < r){
            if((A[l] + A[r]) > A[i]){
                count += (r - l);
                r--;
            }
            else
                l++;
        }
    }
    return count;
}

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    cout << CountTriangles(a, n) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


class Solver(object):

    def solve(self):

        def checker(current, X):
            for idx, value in enumerate(current):
                if idx == 0:
                    continue
                elif value < X:
                    return False
            return True

        def add_list(a, b):
            for i in range(len(a)):
                a[i] += b[i]
            return a

        N, M, X = [int(i) for i in input().split()]
        book_list = [[int(i) for i in input().split()] for _ in range(N)]
        init = [0] * (M + 1)
        ans = []
        for i in range(1 << N):  # 2^N のパターンを全探索
            cur = [0] * (M + 1)
            for j in range(N):  # bitの長さを取る
                if (i >> j) & 1:
                    cur = add_list(cur, book_list[j])
            if checker(cur, X):
                ans.append(cur[0])

        if len(ans) > 0:
            return min(ans)
        else:
            return -1


def main():
    solver = Solver()
    print(solver.solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 9256
n=int(input())
l=[list(map(int, input().split())) for i in range(n-1)]

#print(l)
for i in range(n-1):
    t=l[i][1]+l[i][0]
    for j in range(i+1,n-1):
        if l[j][1]>=t:
            t=l[j][1]+l[j][0]
        elif l[j][1]<t:
            if (t-l[j][1])%l[j][2]==0:
                t+=l[j][0]
            else:
                x=(t-l[j][1])//l[j][2]+1
                t=l[j][2]*x+l[j][1]+l[j][0]           
    print(t)
    #print(l)
print(0)

        

Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sll set<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
using namespace std;

void solve(){
	int n;
	cin>>n;
	cout<<n+n*n+n*n*n<<endl;
}
 
int main(){
    IOS;
    int q=1;
    //cin>>q;
    while(q--){
        solve();
    }
}

Measured memory_bytes: 3660
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 1000005

const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1e9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void nCrModPFermat(ll n, ll r, ll p, vl& fac)
{
	// if (r == 0)
	// 	return 1;
	fac[0] = 1;
	for (ll i = 1 ; i <= n; i++)
		fac[i] = fac[i - 1] * i % p;
	// return (fac[n] * modinvfermat(fac[r], p) % p * modinvfermat(fac[n - r], p) % p) % p;
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {

	fast
	ll k;
	cin >> k;
	string s;
	cin >> s;
	ll n = s.length();
	ll ans = 0;
	vl fac(n + k + 1, 0);
	nCrModPFermat(n + k, n, MOD, fac);
	vl p(n + k + 1, 1);
	FOR(i, 1, n + k)
	{
		p[i] = (p[i - 1] * 25) % MOD;
	}
	FOR(i, n, n + k)
	{
		ans = (ans + (fac[n + k] * modinvfermat(fac[i], MOD) % MOD * modinvfermat(fac[n + k - i], MOD) % MOD) % MOD * p[n + k - i]) % MOD;
	}
	cout << ans << END;



	return 0;
}

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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
template <typename T> using VVV = vector<vector<vector<T>>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {
    lint N, M, X, Y;
    cin >> N >> M >> X >> Y;

    V<lint> x(N);
    V<lint> y(M);

    for(auto &&it : x) {
        cin >> it;
    }
    for(auto &&it : y) {
        cin >> it;
    }

    lint max_x = *max_element(x.begin(), x.end());
    lint min_y = *min_element(y.begin(), y.end());

    string ans;
    if(max_x >= min_y) {
        ans = "War";
    } else if((max_x < X + 1 and X + 1 <= min_y) or
              (max_x < Y and Y <= min_y)) {
        ans = "No War";
    } else if(X + 1 <= max_x and min_y < Y) {
        ans = "No War";
    } else {
        ans = "War";
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
void calc_comb(vector<vector<long long>> &v){
    rep(i,v.size()){
        v[i][0]=1;
        v[i][i]=1;
    }
    for(int i=1; i<v.size(); i++){
        for(int j=1; j<i; j++){
            v[i][j]=(v[i-1][j-1]+v[i-1][j]);
            v[i][j]%=(ll)1e9+7;
        }
    }
}
int main(){
    string S;
    cin>>S;
    bool ok=true;
    int cnt=0,l=0,r=S.size()-1;
    while(r-l>0){
        if(S[l]!=S[r]){
            if(S[l]!='x' && S[r]!='x'){ ok=false; break; }
            else if(S[l]=='x'){ l++; cnt++; }
            else if(S[r]=='x'){ r--; cnt++; }
            
        }else{
            l++; r--;
        }
    }
    if(ok) cout<<cnt<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 512
C1 = list(map(int, input().split()))
C2 = list(map(int, input().split()))
C3 = list(map(int, input().split()))

if C1[1] + C2[0] - C1[0] == C2[1] and C1[1] + C3[0] - C1[0] == C3[1] and \
   C1[2] + C3[0] - C1[0] == C3[2] and C1[2] + C2[0] - C1[0] == C2[2] :
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int flag = 0;
    while (n > 0) {
        int temp;
        temp = n%10;
        if (temp == 7) {
            flag = 1;
            break;
        }
        n=n/10;
    }
    
    if (flag == 1) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 3592
use std::io::stdin;
use std::ops::Add;

fn main(){
    let ks = getvec();
    let (k, s) = (ks[0], ks[1]);
    let ans = (0..k+1).map(|x| solve2(s-x, k)).fold(0, Add::add);
    println!("{}", ans);
}

fn solve2(s :i64, k:i64) -> i64{
    if s>2*k || s<0 {0}
    else if s > k { (2*k)-s+1 }
    else {s+1}
}

#[allow(dead_code)]
fn getline() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn getvec() -> Vec<i64>{
    let line = getline();
    line.split_whitespace().map(|x| x.parse().unwrap()).collect()
}

Measured memory_bytes: 380
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
 
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

const int maxN = (int)2020;

ll dp[maxN][maxN];

void solve() {
  int n;
  cin >> n;
  vector<pli> a(n);
  for (int i = 0 ; i < n ; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(all(a));
  reverse(all(a));
  dp[0][0] = 0;
  for (int i = 0 ; i < n ; i++) {
    int pos = a[i].second;
    ll val = a[i].first;
    for (int l = 0 , r = i; l <= i ; l++, r--) {
      dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + abs(pos - l - 1) * val);
      dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + abs(n - pos - r) * val);
    }
  }
  ll res = 0;
  for (int l = 0 ; l <= n ; l++) {
    res = max(res, dp[l][n - l]);
  }
  cout << res << endl;
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
 
  return 0;
}

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

const int DIM = 3e2 + 5;

char mat[DIM][DIM];
int cst[DIM][DIM], dp[DIM][DIM];

int main( void ) {
    
    int n, m;
    scanf( "%d %d", &n, &m );
    
    for( int i = 1; i <= n; i ++ )
        scanf( "%s", mat[i] + 1 );
    
    int ans = 0;
    for( int k = 1; k <= m - 1; k ++ ) {
        
        for( int i = 0; i <= n; i ++ ) {
            cst[i][0] = 0;
            
            for( int j = i + 1; j <= n; j ++ )
                cst[i][0] += ( mat[j - i][k] == mat[j][k + 1] );
        }
        
        for( int i = 0; i <= n; i ++ ) {
            cst[0][i] = 0;
            
            for( int j = i + 1; j <= n; j ++ )
                cst[0][i] += ( mat[j][k] == mat[j - i][k + 1] );
        }
        
        for( int i = 1; i <= n; i ++ )
            for( int j = 1; j <= n; j ++ )
                cst[i][j] = cst[i - 1][j - 1] - ( mat[n - i + 1][k] == mat[n - j + 1][k + 1] );
        
        for( int i = 1; i <= n; i ++ )
            dp[i][0] = dp[i - 1][0] + cst[i - 1][0];
        
        for( int i = 1; i <= n; i ++ )
            dp[0][i] = dp[0][i - 1] + cst[0][i - 1];
        
        for( int i = 1; i <= n; i ++ )
            for( int j = 1; j <= n; j ++ )
                dp[i][j] = min( dp[i - 1][j] + cst[i - 1][j], dp[i][j - 1] + cst[i][j - 1] );
        
        ans += dp[n][n];
    }
    
    printf( "%d\n", ans );
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#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() {
	ll a,b,c;
	cin >> a >> b >> c;
	string ans = (4*a*b < (c-a-b)*(c-a-b)) ? "Yes" : "No";
	if (c-a-b < 0) ans = "No";
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;

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

    string s; cin>>s;
    int N=s.size();

    int at=N;
    vector<int> cnt(2*N+1);
    cnt[at]=1;
    stack<pair<int,int>> prev;
    stack<int> prevAt;
    stack<Lint> prevAns;
    Lint ans=0;
    for(int i=0;i<N;i++){
        if(s[i]=='-'){
            ans=prevAns.top(); prevAns.pop();
            at=prevAt.top(); prevAt.pop();
            auto p=prev.top(); prev.pop();
            cnt[p.first]=p.second;
        }else{
            if(s[i]=='('){
                prevAt.push(at); at++;
                prev.push({at,cnt[at]}); cnt[at]=1;
                prevAns.push(ans);
            }else{
                prevAt.push(at); at--;
                prevAns.push(ans); ans+=cnt[at];
                prev.push({at,cnt[at]}); cnt[at]++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 8944
#include <iostream>
// #include<bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	while (A >= 0 || C >= 0)
	{
		C -= B;
		if (C <= 0) { 
			cout << "Yes" << endl;
			break;
		}

		A -= D;
		if (A <= 0) {
			cout << "No" << endl;
			break;
		}
	}
	
}


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

int N,ans;
int A[100];

void show(){
    rep(i,0,N){
        if(i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

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

int main() {
    scanf("%d", &N);
    rep(i,0,N) scanf("%d", &A[i]);
    bubbleSort();
    show();
    printf("%d\n",ans);
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF (1<<29)
 
struct State{
    int s,t;
    State(){}
    State(int s,int t) : s(s),t(t) {}
};
 
int getMin(int h,int m){
    return h*60+m;
}
 
bool check(State &s1,State &s2){
    return (s2.s <= s1.s && s1.t <= s2.t);
}
 
int main(){
    int V,N,M,h1,m1,h2,m2,K;
    cin >> V;
    vector<State> v(V);
    vector<int> cnt(V, 0),cnt2(V, 0);
    for(int i = 0 ; i < V ; i++){
        scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
        v[i] = State(getMin(h1,m1),getMin(h2,m2));
    }
    cin >> N;
    for(int i = 0 ; i < N ; i++){
        cin >> K;
        for(int j = 0 ; j < K ; j++){
            scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
            State s = State(getMin(h1,m1),getMin(h2,m2));
            for(int k = 0 ; k < V ; k++){
                if(check(v[k],s)) cnt[k]++;
            }
        }
    }
    cin >> M;
    for(int i = 0 ; i < M ; i++){
        cin >> K;
        for(int j = 0 ; j < K ; j++){
            scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
            State s = State(getMin(h1,m1),getMin(h2,m2));
            for(int k = 0 ; k < V ; k++){
                if(check(v[k],s)) cnt2[k]++;
            }
        }
    }
    int res = 0;
    for(int i = 0 ; i < V ; i++){
        res += min(cnt[i], cnt2[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3224
import Control.Arrow
import Data.Sequence as Sq

q ac n
    | n < Sq.length ac = ac`index`n
    | otherwise =
    q (let (x,xs) = ((`index`0) &&& Sq.drop 1) ac in
    (if x`rem`10/=9 then(|> 10*x + x`rem`10 +1)else id)$
    (|> 10*x + x`rem`10)$
    (if x`rem`10/=0 then(|> 10*x + x`rem`10 -1)else id)
    xs) (n-1)

main = readLn>>=print.q(fromList[1..9]).pred

Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

int N;
pair<int,int> P[100];

void solve()
{
	if(N<=2){
	    cout << 1 << endl;
	    return;
	}
	int most = 0;
	for(int i=0;i<N;++i)for(int j=0;j<N;++j){
		const int p = P[j].first-P[i].first, q = P[j].second-P[i].second;
		if(p||q){
			int cnt = 0;
			for(int x=0;x<N;++x)for(int y=0;y<N;++y){
				if(P[x].first+p==P[y].first && P[x].second+q==P[y].second)cnt++;
			}
			most = max(most, cnt);
		}
	}
	cout << N-most << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N;++i)cin >> P[i].first >> P[i].second;
	solve();
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var r = sc.nextInt();
		var c = sc.nextInt();
		var k = sc.nextInt();
		var v = new long[r][c][5];
		for (var i = 0; i < k; i++) {
			v[sc.nextInt() - 1][sc.nextInt() - 1][0] = sc.nextInt();
		}
		sc.close();

		for (var i = 0; i < r; i++) {
			for (var j = 0; j < c; j++) {
				var cv = v[i][j][0];
				v[i][j][0] = 0;
				for (var ic = 0; ic < 4; ic++) {
					var rv1 = (i > 0 ? getValue(v, i - 1, j) : 0);
					var rv2 = (j > 0 ? v[i][j - 1][ic] : 0);
					var rv3 = (j > 0 ? v[i][j - 1][ic + 1] : 0);
					if (cv > 0) {
						if (ic == 0) {
							v[i][j][ic + 1] = Math.max(Math.max(rv1 + cv, rv2 + cv), rv3);
						} else if (rv2 > 0) {
							v[i][j][ic + 1] = Math.max(rv2 + cv, rv3);
						}
					} else {
						if (ic == 0) {
							v[i][j][ic] = Math.max(rv1, rv2);
						} else {
							v[i][j][ic] = rv2;
						}
					}
				}
				//System.out.printf("%d %d %d %d\r\n", v[i][j][0], v[i][j][1], v[i][j][2], v[i][j][3]);
			}
			//System.out.println("----------");
		}

		System.out.println(getValue(v, r - 1, c - 1));
	}

	private static long getValue(long[][][] v, int i, int j) {
		return Math.max(Math.max(Math.max(v[i][j][0], v[i][j][1]), v[i][j][2]), v[i][j][3]);
	}
}


Measured memory_bytes: 825848
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		String S = sc.next();
		char first = S.charAt(0);
		int index = -1;
		for (int i=0;i<N;i++) {
			if (S.charAt(i)!=first) {
				if (i==N-1) {
					K--;
					index = i-1;
				} else if (S.charAt(i+1)!=first) {
					continue;
				} else {
					K--;
					if (K==0) {
						index = i;
						break;
					}
				}
			} else {
				if (i==N-1) {
					index = i-1;
				}
				continue;
			}
		}
		// System.out.println(index);
		int ans = index+1;
		if (index+1<N) {
			char before = S.charAt(index+1);
			for (int i=index+2;i<N;i++) {
				if (S.charAt(i)==before) {
					ans++;
				}
				before = S.charAt(i);
			}
		}
		// System.out.println(N);
		// System.out.println(index);
		System.out.println(ans);
	}
}

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

int main(){
    vector<int> a(5);
    rep(i,5)cin>>a.at(i);
    int mil;
    int l=max(a.at(3),a.at(4));
    for(int i=0;i<=l;i++){
        int k=max(0,(a.at(3)-i));
        int j=max(0,(a.at(4)-i));
        int tmp=a.at(0)*k+a.at(1)*j+a.at(2)*i*2;
        if((tmp<mil)||(i==0))mil=tmp;
    }
    cout<<mil<<endl;
    return 0;
}


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

#define lp(n) for(int i=0;i<n;i++)
#define LP(n,i) for(int i=0;i<n;i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define intmin -2147483637
#define llmax 9223372036854775807
typedef long long ll;

using namespace std;


ll gcd(ll x,ll y){
	if(y==0)return x;
	return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	ll g=gcd(x,y);
	return x/g*y;
}

int main(){
	int r;
	cin>>r;
	if(r<1200)cout<<"ABC"<<endl;
	else if(r<2800)cout<<"ARC"<<endl;
	else cout<<"AGC"<<endl;	
	return 0;
}


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

using namespace std;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define PI 3.141592653589793
#define vi vector<int>
#define vll vector<long long>
#define p pair<int,int>
const int MOD = 1000000007;
inline double degcos(double ang) {return cos(ang*PI/180);}
inline double degsin(double ang) {return sin(ang*PI/180);}
#define rep(i,j,k,in) for (int i = j; i < k; i += in)


/*---END OF TEMPLATE---*/

const int MXSIZE = 3005;
double dp[MXSIZE][MXSIZE];
bool visited[MXSIZE][MXSIZE];
double prob[MXSIZE];

double solve (int idx, int heads) {
    if (heads < 0) return (double)0;
    if (idx == 0) {
        return heads == 0;
    }
    if (visited[idx][heads]) return dp[idx][heads];
    visited[idx][heads] = 1;

    return dp[idx][heads] = solve(idx-1,heads-1)*prob[idx] + ((double)1 - prob[idx])*solve(idx-1,heads);


}


int main() {
    //cin.sync_with_stdio(0);
    //cin.tie(0);
    //ifstream fin("data.in");
    //ofstream fout("data.out");
    int n;
    cin >> n;
    double tot = 0;
    rep(i,1,n+1,1) {
        cin >> prob[i];
    }
    rep(i,0,n+1,1) {
        if (i > n- i) {
            tot += solve(n,i);
        }
    }
    printf("%.9f",tot);


}

Measured memory_bytes: 79300
#import<atcoder/all>
#define f(i)std::cout<<i<<' ';
int n,m,a;int main(){std::cin>>n>>m;atcoder::scc_graph g(n);for(;std::cin>>a>>n;)g.add_edge(a,n);auto v=g.scc();f(size(v))for(auto i:v){f(size(i))for(auto j:i)f(j)}}

Measured memory_bytes: 40100
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#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 <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ll long long
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;
const ll INF = 1e14;

int main() {
	string s, t;
	cin >> s >> t;
	string res;
	vector<vector<ll> > dp(s.size()+1, vector<ll>(t.size()+1, 0));
	FOR(i, 1, s.size()+1) FOR(j, 1, t.size()+1) {
		if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1]+1;
		else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
	}
	
	for(ll i = s.size(), j = t.size(), k = 0; k < dp[s.size()][t.size()]; k++) {
		while(dp[i-1][j] == dp[i][j]) i--;
		while(dp[i][j-1] == dp[i][j]) j--;
		res.push_back(s[i-1]);
		i--; j--;
	}
	reverse(res.begin(), res.end());
	cout << res << endl;
}


Measured memory_bytes: 70784
void main()
{
    long n, r;
    rdVals(n, r);

    writeln(n >= 10 ? r : r + 100 * (10 - n));
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


const int MAX = 510000;
int n, m;
vector<int> G[MAX];

int dist[MAX];

int main()
{
    while (cin >> n >> m) {
        for (int i = 0; i < MAX; ++i) G[i].clear();
        for (int i = 0; i < m; ++i) {
            int a, b;
            cin >> a >> b;
            --a, --b;
            G[a].push_back(b);
            G[b].push_back(a);
        }
        
        memset(dist, -1, sizeof(dist));
        dist[0] = 0;
        queue<int> que;
        que.push(0);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (int i = 0; i < G[v].size(); ++i) {
                int to = G[v][i];
                if (dist[to] != -1) continue;
                dist[to] = dist[v] + 1;
                que.push(to);
            }
        }
        if (dist[n-1] == 2) puts("POSSIBLE");
        else puts("IMPOSSIBLE");
    }
}


















Measured memory_bytes: 21616
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <cmath>         // sqrt
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b)
{
  // Eucledean algorithm
  while (a)
  {
    if (a < b)
    {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n)
{
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n)
{
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++)
  {
    if (n % i == 0)
    {
      divs.push_back(i);
      if (i != n / i)
      {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

int main()
{

  string S, T;
  cin >> S >> T;
  rep(i, S.length())
  {
    if (S.at(i) != T.at(i))
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3748
#create date: 2020-05-03 21:37

import sys
stdin = sys.stdin
from collections import defaultdict

import numpy as np

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = np.array(na())
    b = np.arange(1, n+1)
    c = a + b
    d = b - a
    l = defaultdict(lambda: 0)
    ans = 0
    for ci in c:
        l[ci] += 1
    for di in d:
        ans += l[di]
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 77372
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    sc.close();

    String ans = null;
    int m = N % 10;
    switch (m) {
      case 2 :
      case 4 :
      case 5 :
      case 7 :
      case 9 :
        ans = "hon";
        break;
      case 0 :
      case 1 :
      case 6 :
      case 8 :
        ans = "pon";
        break;
      case 3 :
        ans = "bon";
        break;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 35756
package main

import (
	"fmt"
)

func main(){

	var N int
	fmt.Scan(&N)
 
	a := make([]int, N)
	for i := range a {
		fmt.Scan(&a[i])
	}

	judg := true

	for _,number := range a{

		if number % 2 == 0 && (number % 3 == 0 || number % 5 ==0){
			continue
		}else if number % 2 != 0{
			continue
		}
		judg = false
		fmt.Println("DENIED")
		break
	}

	if judg == true{
		fmt.Println("APPROVED")
	}

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#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() {
	string	s;
	getline(cin, s);
	rep(i, s.size())
	{
		if (isalpha(s.at(i)))
			s.at(i) ^= 32;
		cout << s.at(i);
	}
	cout << endl;
}



Measured memory_bytes: 3216
/*

    author : s@if

*/

#include<bits/stdc++.h>
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			99999999
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)


bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n;

    if(n==3)
        cout<<180<<endl;
    else
        cout<<n*180-360<<endl;

  //  main();

    return 0;
}


Measured memory_bytes: 256
'''
https://atcoder.jp/contests/abc150/tasks/abc150_d
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    a = list(set(a))

    if len(a) == 1:
        if m >= a[0]//2:
            print((m-a[0]//2) // a[0] + 1)
        else:
            print(0)
        exit()

    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    g = gcd_group(a)
    for i in a:
        if (i//g)%2 == 0:
            print(0)
            exit()
    lcm = lcm_group(a)
    semi_lcm = lcm // 2
    if m >= semi_lcm:
        print((m-semi_lcm)//lcm + 1)
    else:
        print(0)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14620
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int n,k;
using Graph=vector<vector<int>>;
Graph G;
ll ans=0;
ll MOD=1e9+7;
vector<int>d;
vector<int>subtree_size;
int dfs(int v,int p){
    int use_c;
    if(p==-1) use_c=k-1;
    else use_c=k-2;
    if(k<G[v].size()) {
        return 0;
    }
    else{
        ll cnt=1;
    for( auto nv: G[v] ){
        if(nv==p) continue;
        cnt*=use_c;
        use_c--;
        cnt%=MOD; 
    }
    for(auto nv: G[v]){
        if(nv==p) continue;
        cnt*=dfs(nv,v);
        cnt%=MOD;
    }
    return cnt;
    }
}
bool vis[100010];
signed main(){
    
    cin >> n >> k;
    G.assign(n,vector<int>());
    for (int i = 0; i < n-1; i++)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<int>q;
    q.push(0);
    ll ans=1;
    int p=-1;
    while(!q.empty()){
        int v=q.front();
        vis[v]=true;
        q.pop();
        int copy;
        if(v==0) copy=k-1;
        else copy=k-2;
        for(auto u : G[v]){
            if(vis[u]) continue;
            ans*=copy;
            copy--;
            ans%=MOD;
            q.push(u);
        }
    }
 cout<<(k*ans)%MOD<<endl;

   //cout<< (k* dfs(0,-1)) % MOD <<endl;
  
    
    return 0;
}

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

using namespace std;

int main() {
    constexpr long MOD = 1e9 + 7;

    string s;
    cin >> s;

    int l = s.size();

    vector<long> mods(13);

    mods[0] = 1;

    for(int i=0; i<l; i++) {
        vector<long> cmods(13);

        if(s[i] == '?') {
            for(int d=0; d<=9; d++)
                for(int j=0; j<13; j++) {
                    cmods[(j * 10 + d)%13] += mods[j];
                    cmods[(j * 10 + d)%13] %= MOD;
                }
        } else {
            int d = s[i] - '0';
            for(int j=0; j<13; j++) {
                cmods[(j * 10 + d)%13] += mods[j];
                cmods[(j * 10 + d)%13] %= MOD;
            }
        }
        mods = cmods;
    }

    cout << mods[5] % MOD << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (ll i = 0; i < ll(n); i++)

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vl c(n);
    rep(i, n) cin >> c[i];
    sort(c.begin(), c.end());

    mint ans;
    for (int i = 0; i < n; i++) {
        ans += mint(c[i]) * mint(n - i + 1);
    }
    ans *= mint(4).pow(n - 1);
    cout << ans.x << endl;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
int a;
int main () {
    cin >> a;
    if (a<1200) {
        cout << "ABC" <<endl;
    }
    else if (1200<=a && a<2800)
        cout << "ARC" << endl;
    else if (2800<=a)
        cout<< "AGC" <<endl;
    
 
   }

Measured memory_bytes: 3544
N = int(input())
h = list(map(int, input().split()))
ans = 0
now = 1
while now <= max(h):
    kukan = 0
    flag = False # 区間を数え始めていいかどうか
    for i, hi in enumerate(h):
        if hi < now and flag:
            kukan += 1
            flag = False
        elif i == len(h)-1 and hi >= now:
            kukan+=1
        elif hi >= now and flag == False:
            flag = True
    now +=1
    ans += kukan
print(ans)


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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353




int main() {
    int x,y; cin >> x >> y;
    cout << x + y/2 << endl;
}




Measured memory_bytes: 256