akhauriyash/Code-Regression huggingface dataset:
// 1_2_A
#include <stdio.h>
#include <stdlib.h>

void BubbleSort(int *numbers, int length){
    int flag = 1, i, tmp, cnt = 0;
    while(flag){
        flag = 0;
        for(i = length - 1; i >=1; i--){
            if(numbers[i] < numbers[i-1]){
                tmp = numbers[i];
                numbers[i] = numbers[i-1];
                numbers[i-1] = tmp;
                flag = 1;
                cnt += 1;
            }
        }
    }

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

int main(){
    int n, *numbers, i;
    scanf("%d", &n);
    numbers = (int *)malloc(sizeof(int)*n);
    for(i = 0; i < n; i++){
        scanf("%d", &numbers[i]);
    }

    BubbleSort(numbers, n);

    free(numbers);
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D ;
  int X = A + B;
  int Y = C + D;
  
  if(X > Y){
    cout << "Left" << endl;
  }
  else if(X == Y){
    cout << "Balanced" << endl;
  }
  else if (X < Y){
    cout << "Right" << endl;
  }
  
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

for i in range(1, N):
    print(' '.join(map(str, A)))

    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v

print(' '.join(map(str, A)))


Measured memory_bytes: 5596
#include <stdio.h>
int main(void){
 int n,i,c=0;
 scanf("%d",&n);
 int a[n+1];
 for(i=1;i<n+1;i++){
  scanf("%d",&a[i]);
 }
 for(i=1;i<n+1;i++){
  if(i==a[a[i]]) c++;
 }
 printf("%d",c/2);
 return 0;
}

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

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<vector<int>> vvi;           // intの2次元vector
typedef vector<vector<double>> vvd;        // doubleの2次元vector
typedef vector<vector<ll>> vvll;           // llの2次元vector
typedef vector<vector<ld>> vvld;           // ldの2次元vector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* stringstream */
stringstream ss;
stringstream init_ss; // save default formatting

/* upper, lower */
struct ToUpper
{
    char operator()(char c)
    {
        return toupper(c);
    }
};
struct ToLower
{
    char operator()(char c)
    {
        return tolower(c);
    }
};

/* main */
void Main(void)
{
    ll a;
    cin >> a;
    ld b;
    cin >> b;
    ll c = a * b;
    cout << c << endl;
}

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

    return 0;
}


Measured memory_bytes: 3748
#! /usr/local/bin/python3
# coding: utf-8

def insertion_sort(a):
    for i in range(1, len(a)):
        print(" ".join(map(str, a)))
        w = a[i]
        j = i - 1
        while j >= 0 and w < a[j]:
            a[j + 1] = a[j]
            j -= 1
        a[j + 1] = w

n = int(input())
a = [int(i) for i in input().split()]
insertion_sort(a)
print(" ".join(map(str, a)))



Measured memory_bytes: 5612
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

lint prime[1100000];

multiset<lint> decomp(lint N){
    multiset<lint> res;
    for(int i=2;i<=1000;i++){
        while(N%i==0) N/=i,res.insert(i);
        if(N==1) break;
        if(i==1000) res.insert(N);
    }
    return res; 
}

lint powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}

int main(void){
    lint N;
    cin >> N;
    lint A[N];
    lint ans=0;
    rep(i,N) cin >> A[i];
    rep(i,N){
        multiset<lint> div=decomp(A[i]);
        while(!div.empty()){
            auto itr=div.begin();
            lint count=div.count(*itr);
            prime[*itr]=max(prime[*itr],count);
            div.erase(*itr);
        }
    }
    lint mul=1;
    for(int i=2;i<=1000000;i++) mul=(mul*powmod(i,prime[i]))%MOD;
    rep(i,N) ans=(ans+mul*powmod(A[i],MOD-2))%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 8320
<?php
   $array = explode(" ",trim(fgets(STDIN)));
   $s = trim(fgets(STDIN));
   $ans = "";
   $i = 0;

   while($i < $array[0] ){
      $chage_num = (int)$array[1] - 1;
      if($i == $chage_num)
      {
         $ans .= strtolower($s[$i]);
      }
      else
      {
         $ans .= $s[$i];
      }

      $i++;
   }

   echo $ans;
   echo "\n";
?>


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N;
  cin>>N;
  vector<ll> A(N),B(N);
  rep(i,N) cin>>A[i];
  rep(i,N) cin>>B[i];

  ll ans = 0;
  queue<ll> q; // {index}
  rep(i,N) q.push(i);

  while(!q.empty()){
    ll i = q.front(); q.pop();
    ll a = B[(N+i-1)%N];
    ll b = B[(N+i)%N];
    ll c = B[(N+i+1)%N];
    // printf("%d %d %d %d\n",i,a,b,c);

    if (b == A[i]) { // B[i]がA[i]に一致済み
      continue;
    } else if (b-A[i] >= 0 && (b-A[i])%(a+c) == 0) { // B[i]をA[i]に一致させれる
      ans += (b-A[i]) / (a+c);
      B[i] = A[i];
      q.push((N+i+1)%N);
      q.push((N+i-1)%N);
    } else if (b-a-c >= A[i]) { // B[i] をA[i]に近付けられる
      ll t = (b-A[i])/(a+c);
      ans += t;
      B[i] = B[i] - t * (a+c);
      q.push((N+i+1)%N);
      q.push((N+i-1)%N);
    } else{
      continue;
    }
  }

  if (A==B) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 5120
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// }}}
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 1e5;
int n;
int a[N];
const int mod = 1e9 + 7;

// WARN : use H with larger N
/// --- Modulo Factorial {{{ ///
template < int N, int mod = (int) 1e9 + 7 >
struct Factorial {
  constexpr ll extgcd(ll a, ll b, ll &x, ll &y) {
    ll d = 0;
    return b == 0 ? (x = 1, y = 0, a)
      : (d = extgcd(b, a % b, y, x), y -= a / b * x, d);
  }
  constexpr ll modinv(ll a) {
    ll x = 0, y = 0;
    extgcd(a, mod, x, y);
    return (x + mod) % mod;
  }
  int arr[N + 1], inv[N + 1];
  ll operator[](int i) const { return arr[i]; }
#if !defined(DEBUG)
  constexpr
#endif
    Factorial()
    : arr(), inv() {
      arr[0] = 1;
      for(int i = 1; i <= N; i++) {
        arr[i] = (ll) i * arr[i - 1] % mod;
      }
      inv[N] = modinv(arr[N]);
      for(int i = N - 1; i >= 0; i--) {
        inv[i] = (ll)(i + 1) * inv[i + 1] % mod;
      }
    }
  ll C(int n, int r) const {
    if(n < 0 || r < 0 || n < r) return 0;
    return (ll) arr[n] * inv[r] % mod * inv[n - r] % mod;
  }
  ll H(int n, int r) const { return C(n + r - 1, r); }
};
/// }}}--- ///

Factorial < N, mod > fact;

/// --- math {{{ ///
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d;
  return b == 0 ? (x = 1, y = 0, a)
    : (d = extgcd(b, a % b, y, x), y -= a / b * x, d);
}
ll modinv(ll a, ll mod = (ll) 1e9 + 7) {
  ll x, y;
  extgcd(a, mod, x, y);
  if(x < 0) x += mod;
  return x;
}
ll modpow(ll a, ll b, ll mod = (ll) 1e9 + 7) {
  ll r = 1;
  a %= mod;
  while(b) {
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}
/// }}}--- ///


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  ll dp[N + 1]; // i離れたところを取り除いて自分のところがカウントされる確率
  for(int i = 0; i < n; i++) dp[i] = modinv(i + 1, mod);
  for(int i = 1; i < n; i++) (dp[i] += dp[i-1]) %= mod;
  ll ans = 0;
  auto range = [&](int l, int r) {
    if(l > r) return 0ll;
    ll res = dp[r];
    if(l-1>=0) res += mod - dp[l-1];
    res %= mod;
    return res;
  };
  for(int i = 0; i < n; i++) {
    // 0, i
    // 1, n - 1 - i
    ans += a[i] * (range(0, i) + range(1, n - 1 - i)) % mod;
    ans %= mod;
  }
  ans = (ans * fact[n]) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(1, n - 1):
  if a[i - 1] > a[i]:
    if a[i] > a[i + 1]:
      ans += 1
  elif a[i - 1] < a[i]:
    if a[i] < a[i + 1]:
      ans += 1

print(ans)



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;



int main() {
	char s[101];
	int x;
	
	
	cin >> s;
	x = strlen(s);
	cout << s[0] << strlen(s) - 2 << s[x - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll x;
    cin >> x;
    cout << 1 - x << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
 
typedef char str255[256];

int main()
{
    string inStr; cin >> inStr;
    str255 outStr;
    int strPtr = 0;
    rep(i, 20) outStr[i] = '\0';
    int lenIn = inStr.length();

    rep(i, lenIn){
        char c = inStr[i];
        switch(c){
            case '0': outStr[strPtr] = '0'; ++strPtr; break;
            case '1': outStr[strPtr] = '1'; ++strPtr; break;
            default: --strPtr; if (strPtr < 0) strPtr = 0; outStr[strPtr] = '\0'; break;
        }
    }

    puts(outStr);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define revstr(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b)
{
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s)
{
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
// ll nck(ll N,ll K,ll mod)
// {
// 	if(N<K)
// 	{
// 		return 0;
// 	}
// 	return (((facs[N]*facsinv[N-K])%mod)*facsinv[K])%mod;
// }
ll power(ll x,ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		{
			res=(res*x)%p;
		}
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x,ll mod)
{
	if(x>=mod)
	{
		x%=mod;
	}
}
// void checktime()
// {
// 	struct timespec ts;
// 	printf("Running Program\n");
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double st=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	// Call Funcn Here
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double en=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	printf("Program ended\nTime = %Lf\n",en-st);
// }
int main(void)
{
	fastio
	ll n;
	cin>>n;
	for(ll i=1;i<10;i++)
	{
		if(n%i==0 && n/i<10)
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input().rstrip()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
# mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')

file = 1




    
def solve():

    
    # for _ in range(ii()):

        s = list(si())
        if 'S' not in s:
            print(3)
        elif('R' not in s):
            print(0)
        elif(s[1]=='R' and (s[0]=='R' or s[2]=='R')):
            print(2)
        else:
            print(1)













        
if __name__ =="__main__":

    if(file):

        if path.exists('input.txt'):
            sys.stdin=open('input.txt', 'r')
            sys.stdout=open('output.txt','w')
        else:
            input=sys.stdin.readline
    solve()


Measured memory_bytes: 69856
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string x,y;
int len;
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>len;
    cin>>x;
    cin>>y;
    ll ans=1,last=0;
    if(x[0]==y[0])
        ans=3,last=1;
    else
        ans=6,last=2;
    for(int i=last; i<len; i++)
    {
        if(x[i]==y[i])
        {
            if(last==1)
                ans*=2;
            last=1;
        }
        else{
            if(last==1)
                ans*=2;
            else
                ans*=3;
            last=2;
            i++;
        }
        ans%=MOD;
    }
    cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 3612
void main() {
    string[] tmp = readln.split;
    int a = tmp[0].to!int, b = tmp[1].to!int;
    string p = tmp[0];
    int cnt;
    foreach (i; a .. b+1) {
        char[] q = p.dup;
        reverse(q);
        if (p == q) ++cnt;
        p = p.succ;
    }
    cnt.writeln;
}

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.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 1276
#include <stdio.h>

int main(void) {
    int i, n, x;
    scanf("%d %d", &n, &x);
    int l[n+1];
    for(i = 0; i < n; ++i){
        scanf("%d", &l[i]);
    }
    l[n] = 0;
    int d = 0, count = 0;
    for(i = 0; i <= n; d=d+l[i], ++i){
        if(d <= x){count++;}
        else{break;}
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,m,v,p;
    cin>>n>>m>>v>>p;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    sort(rall(a));

    int ok=p-1,ng=n;
    while(ng-ok>1){
        int mid=(ok+ng)/2;

        if(a[mid]+m<a[p-1]){
            ng=mid;
            continue;
        }

        int vote=m*(v-(n-mid)-(p-1));

        for(int i=p-1;i<mid;i++){
            vote-=max(a[mid]+m-a[i],0LL);
        }

        if(vote<=0){
            ok=mid;
        }
        else{
            ng=mid;
        }
    }

    cout<<ok+1<<endl;
}

Measured memory_bytes: 1152
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
const int MAXN = 110 ; 
int n ; 
vector<int> score ; 
ll dp[MAXN][MAXN*MAXN] ; 
int dfs(int x,int curr){
	if ( x == n ) {
		if ( curr % 10 == 0 ) return 0 ; 
		return curr ; 
	}
	if ( dp[x][curr] != -1 ) return dp[x][curr] ; 
	int choice1 = dfs(x+1,curr) ; 
	int choice2 = dfs(x+1,curr+score[x]) ; 
	dp[x][curr] = max(choice1,choice2) ; 
	return dp[x][curr] ; 
}
int main(){
	memset(dp,-1,sizeof dp);
	cin >> n ; 
	score.resize(n) ; 
	for(int &x : score){
		cin >> x ; 
	}
	cout << dfs(0,0) << endl;
    return 0 ;
}


Measured memory_bytes: 10624
using System;

namespace ABC131A
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            if (s.Substring(0, 1) == s.Substring(1, 1) || s.Substring(1, 1) == s.Substring(2, 1) || s.Substring(2, 1) == s.Substring(3, 1))
                Console.WriteLine("Bad");
            else
                Console.WriteLine("Good");
   
            Console.ReadKey();


            
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main() {
 int a, b, c, d, r, l;
 cin >> a >> b >> c >> d;
  l = a + b;
  r = c + d;
  
  if ( r > l ) {
    cout << "Right" << endl;
  }
  else if ( r < l ){
    cout << "Left" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define int long long
const int maxn=2e5+5;
const int INF=0x3f3f3f3f3f3f3f3f;
int a[maxn],b[maxn],f_a[maxn],f_b[maxn];
signed main()
{
    int n,m,k;
    scanf("%lld%lld%lld",&n,&m,&k);
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)
        f_a[i]=f_a[i-1]+a[i];
    for(int i=1;i<=m;i++)
        scanf("%lld",&b[i]);
    for(int i=1;i<=m;i++)
        f_b[i]=f_b[i-1]+b[i];
    f_b[m+1]=INF;
    int ans=0;
    for(int i=0;i<=n;i++)
    {
        if(f_a[i]>k) break;
        int left=k-f_a[i];
        int pos=(int)(upper_bound(f_b,f_b+m+2,left)-f_b);
        pos--;
        ans=max(ans,pos+i);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 7956
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>
typedef long long LL;

using namespace std;



int main(void) {
	int n;
	cin >> n;
	vector<int>A(n), B(n);
	int max_a = 0, min_b = 10e9;
	for (int i = 0; i < n; i++) {
		cin >> A[i] >> B[i];
		max_a = max(max_a, A[i]);
		min_b = min(min_b, B[i]);
	}
	cout << max_a + min_b;
	return 0;
}

Measured memory_bytes: 1152
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

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

	public Main() {
		FasterScanner sc = new FasterScanner(System.in);

		long n = sc.nextInt()+1;
		long k = sc.nextInt();
		long MOD = 1000000007L;
		long result = 0;
		long max = 0;
		for (long i = 0; i < k; i++) {
			max += (n-1-i);
		}
		max %= MOD;
		long min = 0;
		for (long i = 0; i < k-1; i++) {
			min += i;
		}
		min %= MOD;
		for (long i = k; i <= n; i++) {
			min += i-1;
			if (i != k) {
				//min -= (i-k-1);
				max += (n-i);
			}
			//System.out.println(i + " " + min + " "  +max);
			result += max+1;
			result -= min;
			result %= MOD;
			//System.out.println(result);
		}
		result = (result+MOD)%MOD;
		System.out.println(result);
		
		sc.close();
	}
	
	class FasterScanner {
		private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FasterScanner() {
			this(System.in);
		}

		public FasterScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public void close() {
			try {
				mIs.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}


Measured memory_bytes: 32616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass
{
	static void Main(string[] args)
	{
		Answer();
	}
	public static void Answer()
	{
      var str = Console.ReadLine();
      var ans5 = new StringBuilder();
      for (int i = 0; i < str.Length; i += 2)
      {
        ans5.Append(str[i]);
      }
      Console.WriteLine(ans5);
	}
}


Measured memory_bytes: 13192
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: i64,
        b: i64,
        c: i64
    }
    if a == b {
        println!("{}", c);
    } else if b == c {
        println!("{}", a);
    } else {
        println!("{}", b);
    }
}


Measured memory_bytes: 4352
use std::io;
use std::cmp;

fn main() {
    let n: i64 = next_int();
    let k: i64 = next_int();
    let x: Vec<i64> = next_vec();

    let ans: i64 = x.into_iter().map(|i| cmp::min(i * 2, (k - i) * 2)).sum();

    println!("{}", ans);
}

fn next_int() -> i64 {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

fn next_vec() -> Vec<i64> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace().map(|n| n.parse().unwrap()).collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

pl ans = {MOD,MOD};
int dist[101],n;
vi adj[101];

void test(vi x) {
    FOR(i,1,n+1) dist[i] = MOD;
    queue<int> q;
    for (int i: x) {
        dist[i] = 0;
        q.push(i);
    }
    while (sz(q)) {
        int x = q.front(); q.pop();
        for (int i: adj[x]) if (dist[i] == MOD) {
            dist[i] = dist[x]+1;
            q.push(i);
        }
    }
    int mx = 0;
    FOR(i,1,n+1) mx = max(mx,dist[i]);
    mx ++;
    
    vi tmp(mx);
    FOR(i,1,n+1) {
        int cur = 0;
        for (int j: adj[i]) if (dist[j] == dist[i]+1) cur ++;
        tmp[dist[i]] = max(tmp[dist[i]],cur);
    }
    ll mul = sz(x);
    for (int i: tmp) if (i) mul *= i;
    ans = min(ans,{mx,mul});
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    F0R(i,n-1) {
        int a,b; cin >> a >> b;
        adj[a].pb(b), adj[b].pb(a);
    }
    FOR(i,1,n+1) test({i});
    FOR(i,1,n+1) for (int j: adj[i]) test({i,j});
    cout << ans.f << " " << ans.s;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long long A,B,V,W,T;
	cin >> A >> V >> B >> W >> T;
	if(V<=W){
		cout << "NO" << endl;
		return 0;
	}else if(abs(A-B)/double(V-W) <= T){
		cout << "YES" << endl;
		return 0;
	}else{
		cout << "NO" << endl;
		return 0;
	}
}

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

int gcd(int x,int y);

int main() {
	int a,b;
	int x,y;
	cin>>a>>b;
	x=min(a,b);
	y=max(a,b);
	gcd(x,y);
	return 0;
}

int gcd(int x,int y){
	if(y%x!=0)gcd(y%x,x);
	else cout<<x<<endl;
}

Measured memory_bytes: 3052
n,c = map(int,input().split())
arr = [0 for i in range(10**5+1)]
tv = [[0,0,0] for i in range(n)]
for i in range(n):
    s,t,c = map(int,input().split())
    tv[i][0] = s
    tv[i][1] = t
    tv[i][2] = c

tv.sort(key = lambda x:(x[2],x[0]))
# print(tv)

channel = tv[0][2]
bef = -1
for i in range(n):
    if channel != tv[i][2]:
        channel = tv[i][2]
        bef = -1
        s = tv[i][0]
        e = tv[i][1]
        if bef != s:
            arr[s]+=1
        bef = e
        for j in range(s+1,e+1):
            arr[j] += 1
    else:
        s = tv[i][0]
        e = tv[i][1]
        if bef != s:
            arr[s]+=1
        bef = e
        for j in range(s+1,e+1):
            arr[j] += 1
# print(arr[:13])
print(max(arr))

Measured memory_bytes: 28500
#include <bits/stdc++.h>
using namespace std;
long long mypow(long long x, long long y)
{
	long long result = 1;
	while (y != 0) {
		if (y%2 != 0) {
			result *= x;
			y -= 1;
		}	
		x *= x;
		y /= 2;
	}
	return result;
}
int main(void)
{
	int n, m;
	cin >> n >> m;
	priority_queue<tuple<long long, long long, int>> q; //(p, orig, num)
	for (int i = 0; i < n; i++) {
		long long a;
		cin >> a;
		q.push(make_tuple(a, a, 0));
	}
	for (int i = 0; i < m; i++) {
		auto e = q.top();
		q.pop();
		if (get<0>(e) == 0)
			break;
		q.push(make_tuple(
					(long long)floor((long double)get<1>(e)/mypow(2, get<2>(e)+1)),
					get<1>(e),
					get<2>(e)+1));
	}
	long long ans = 0;
	while (!q.empty()) {
		auto e = q.top();
		q.pop();
		ans += get<0>(e);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> shop(n + 1, false);
    for (int i = 0; i < m; i++) {
        int c, d;
        cin >> c >> d;
        for (int j = c; j < d; j++) shop[j] = true;
    }
    int ans = 0;
    for (int i = 0; i < n + 1; i++) {
        if (shop[i]) ans += 2;
    }
    cout << ans + n + 1 << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
      #define hell                         1000000007 
      #define M                            1000000007
      #define Maxi                      10000000000000000
      #define lcm(a,b)                     (a*b)/__gcd(a,b)
      #define ll                           long long
           
      #define vll                          vector<ll>
      #define vi                           vector<long long>
      #define pll                          vector< pair<ll,ll> >
      #define pb                           push_back
                  //#define mp                           make_pair
      #define all(v)                       v.begin(),v.end()
      #define lbnd                         lower_bound
      #define ubnd                         upper_bound
      #define bs                           binary_search
      #define F                            first
      #define S                            second
      #define rep(i,a,b)                   for(i=a;i<b;i++)
      #define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
      #define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
      #define ret(x)                       return cout<<x,0;
      #define dbg(x)                       cout << #x << " is " << x << endl;
      #define endl                           '\n'
           
           
                  // Debug //
           
      #define trace(x)                 cerr << #x << ": " << x << endl;
      #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;
           
           
      using namespace std;
      
     
      int main()
          {
           
          ios_base::sync_with_stdio(false);
          cin.tie(NULL);cout.tie(NULL);
        
          
          ll a,b;
          cin>>a>>b;
          if(a>9 || a<1 || b>9 || b<1)
          {
            cout<<-1<<endl;
          }
          else
            cout<<a*b<<endl;


       return 0;
        }

Measured memory_bytes: 256
N = int(input())
a = [int(input()) for _ in range(N)]

start = 0
counter = 1
temp_index = a[start]

while counter <= 10**5:

    if temp_index - 1 == 1:
        print(counter)
        exit()

    temp_index = a[temp_index-1]

    counter += 1

print(-1)


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

int main() {
    int n;
    cin >> n;
    if (n==25) {
        cout << "Christmas" << endl;
    } else if (n==24) {
        cout << "Christmas Eve" << endl;
    } else if (n==23) {
        cout << "Christmas Eve Eve" << endl;
    } else {
        cout << "Christmas Eve Eve Eve" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <string>
#include <ctype.h>
#include <set>
#include <map>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<tr1/unordered_set>
#include<tr1/unordered_map>


#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
//Make sure no overflow problems
//#define int long long
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define ld long double
const int INF = 1000000009;
const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;

using namespace std;

#pragma GCC optimize ("Ofast")
static auto _ = [] { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); return 0; } ();

int main() {
	int s,w;
    cin>>s>>w;
  	cout<<(s>w?"safe":"unsafe");
    return 0;
}



Measured memory_bytes: 3648
#include "bits/stdc++.h"
 
using namespace std;
 
#define ll long long int
#define FOR(i,a,b) for(ll i = a;i<b;i++)
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
int main(){
    boost;
    ll n;
    cin>>n;
    ll arr[n];
    cin>>arr[0];
    ll xorsum = arr[0];
    FOR(i,1,n){
        cin>>arr[i];
        xorsum = xorsum^arr[i];
    }
    //cout<<"the total xor is : "<<xorsum<<endl;
    
    FOR(i,0,n){
        cout<<(xorsum^arr[i])<<" ";
    }
    
    return 0;
}

Measured memory_bytes: 5220
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define space " "
#define cbr cout << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, A[MAXN], ans, co[MAXN], val[MAXN]; const ll MOD = 1000000007;
int main()
{
	FAST
	cin>>n;
	vector <ll> v(n);
	for(ll i = 0; i < n; i++) cin >> v[i];
	v.resize(unique(all(v))-v.begin());
	n=siz(v);
	for(ll i = 0; i < n; i++) A[i+1] = v[i];
	FOR(i,1,n+1)
	{
		if(co[A[i]] == 0) { co[A[i]] = i; val[i] = ans; }
		else
		{
			val[i]=val[co[A[i]]]+1; val[i] %= MOD;
			ans += val[i]; ans %= MOD;
			co[A[i]] = i;
			val[i]=ans;
		}
	}
	ans++; ans %= MOD;
	cout<<ans<<'\n';
}


Measured memory_bytes: 7552
#include<bits/stdc++.h>
#define EPS 1.0e-9
using namespace std;

bool is_in_a_triangle(double ax, double ay, double bx, double by, double cx, double cy, double px, double py){
    double c1 = (bx-ax) * (py-ay) - (by-ay) * (px-ax);
    double c2 = (cx-bx) * (py-by) - (cy-by) * (px-bx);
    double c3 = (ax-cx) * (py-cy) - (ay-cy) * (px-cx);
    if(c1 + EPS > 0 && c2 + EPS > 0 && c3 + EPS > 0) return true;
    else if(c1 + EPS < 0 && c2 + EPS < 0 && c3 + EPS < 0) return true;
    else return false;
}

int main(){
    double x1,y1,x2,y2,x3,y3,xp,yp;
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp) != EOF){
        if(is_in_a_triangle(x1,y1,x2,y2,x3,y3,xp,yp))cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 3200
n=int(input())
x=n//3
y=n//5
z=n//15
if n<3:
  X=0
elif 3<=n<=5:
  X=3
else:
  X=int((3+3*x)*x/2)
if n<5:
  Y=0
elif 5<=n<=9:
  Y=5
else:
  Y=int((5+5*y)*y/2)
if n<15:
  Z=0
elif 15<=n<30:
  Z=15
else:
  Z=int((15+15*z)*z/2)
  
S=[0]*(n+1)
  
for i in range(n+1):
  S[i]=i

print(sum(S)-X-Y+Z)

Measured memory_bytes: 48336
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
const int ININF = 1000000;
using pint = pair<int, int>;
using Edge = pair<long long, pint>; //<cost,<u,v>>の形
vector<Edge> edges;

int N, M;

vector<long long> d;
vector<bool> neg;

//到達可能でNへの経路中に正の閉路がある場合にtrueを返す
bool large_path(int start) {
    rep(i, 0, N) { d[i] = -INF; }
    d[start] = 0LL;
    rep(i, 0, N) {
        rep(j, 0, M) {
            Edge e = edges[j];
            long long cost = e.first;
            int to = e.second.second;
            int fr = e.second.first;
            if(d[fr] != -INF && d[to] < d[fr] + cost) {
                d[to] = d[fr] + cost;
            }
        }
    }
    rep(i, 0, N) {
        rep(j, 0, M) {
            Edge e = edges[j];
            long long cost = e.first;
            int to = e.second.second;
            int fr = e.second.first;
            if(d[fr] != -INF && d[to] < d[fr] + cost) {
                d[to] = d[fr] + cost;
                neg[to] = true;
            }
            if(neg[fr]) {
                neg[to] = true;
            }
        }
    }
    return neg[N - 1];
}
int main() {
    cin >> N >> M;
    d.assign(N, 0);
    neg.assign(N, false);
    rep(i, 0, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        edges.push_back(make_pair(c, make_pair(a, b)));
    }
    if(large_path(0)) {
        cout << "inf" << endl;
    } else {
        cout << d[N - 1] << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[50],n,k;
long long sum;
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=n-1;i>n-k-1;i--)
        sum+=a[i];
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#define ENABLE_LL
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr; typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; } char nextChar(){ char r; ist>>r; return r;} }; Scanner sc(cin);
void ALERT(bool judgememt, const char* phrase) { if (judgememt) { puts(phrase); throw "ALERT"; } }
bool alert(bool judgememt, const char* phrase) { if (judgememt) puts(phrase); return judgememt; }


void init() {
     
}

vector < int > getFactors(int u) {
    vector < int > res;
    for (int i=2;i*i<=u;i++) {
        int r=0;
        while (u%i==0) { u/=i; r++; }
        if (r) res.push_back(r);
    }
    if (u!=1) res.push_back(1);
    return res;
}

int getTimes(int u) {
    int require=1, res=0;
    while (u>=require) {
        u-=require; require++;
        res++;
    }
    return res;
}

void solve() {
    int n = sc.nextInt();
    vector < int > factors = getFactors(n);
    if (alert(factors.size()==0,"0")) return;
    int res = 0; repe(i,factors) res+=getTimes( factors[i] );
    printf(IN,res);
}


#ifdef ENABLE_LL
#undef int
#endif
int main(){
#ifndef CUSTOM_MAIN
#ifdef MULTIPLE_TEST_CASES_WITH_T

int T; scanf("%d",&T); while(T--) {init(); solve();}

#else
#ifdef MULTIPLE_TEST_CASES_WITHOUT_T

while(1) {try{init(); } catch(bool t){return 0;} solve(); }

#else

init(); solve();

#endif
#endif
#endif
    return 0;
}



Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <climits>
#include <tuple>
#include <unordered_map>

using namespace std;

typedef long long ll;

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N), B(N);
  vector<pair<ll,ll>> pA;
  for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; pA.push_back(make_pair(A[i], i)); }
  sort(pA.begin(), pA.end());

  ll count = 0;
  ll cost = 0;
  for (auto p : pA) {
    int take = min(M - count, B[p.second]);
    cost += take * p.first;
    count += take;
    // cout << p.first << " " << p.second << " " << B[p.second] << ": take " << take << endl;
  }
  cout << cost << endl;
}


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

using namespace std;

void sort_and_print(vector<int>& a) {
	int nos = 0;
	int size = a.size();
	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = size-1; i > 0; --i) {
			if (a[i] < a[i-1]) {
				swap(a[i],a[i-1]);
				++nos;
				flag = true;
			}
		}
	}
	for (int i = 0; i < size; ++i) {
		cout << a[i];
		if (i < size-1) {
			cout << " ";
		}
	}
	cout << endl;
	cout << nos << endl;
	return;
}

int main(void) {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort_and_print(a);
	return 0;
}



Measured memory_bytes: 3120