akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef long long Int;


int main() {
  int A, B;
  cin >> A >> B;
  
  if ((A*B) % 2 == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;

typedef long long ll;

int main()	{
  ll n; 
  cin >> n;
  ll a;
  unordered_set<ll> sheet;
  for (ll i = 0; i < n; i++)	{
    cin >> a;
    if (sheet.find(a) == sheet.end())	{
      //not present, insert
      sheet.insert(a);
    }
    else	{
      sheet.erase(a);
    }
  }
  cout << sheet.size() << endl; 
  return 0;
}

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

int main(){
	string s;
	cin >> s;
	int one = 0, zer = 0;
	for(int i = 0; i < s.length(); i++){
		if(s[i]=='0') zer++;
		else one++;
	}

	printf("%d\n", 2*min(one,zer));

	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

#define MAXN 100000

using namespace std;

int A[MAXN];

int main ()
{
  int N;
  int now = 0;
  int cnt = 0;
  int sum = 0;

  cin >> N;

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

  sort(A, A+N);

  for ( int i = 0; i < N; ++i ) {
    if ( A[i] != now ) {
      if ( now > cnt ) sum += cnt;
      else sum += cnt-now;
      cnt = 1;
      now = A[i];
    } else ++cnt;
  }
  if ( now > cnt ) sum += cnt;
  else sum += cnt-now;

  cout << sum << "\n";
}


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

int main() {
  long N;
  cin >> N;
  vector<long> vec(5);
   cin >> vec.at(0) >> vec.at(1) >>vec.at(2) >> vec.at(3) >>vec.at(4);
  sort(vec.begin(), vec.end());
  if ( N % vec.at(0) == 0){
    long ans;
    ans = (N / vec.at(0)) + 4 ;
  cout << ans << endl;
  }
  else{
    long ans;
    ans = (N / vec.at(0)) + 5 ;
    cout << ans <<  endl;
  }
}



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

using namespace std;
typedef long long int ll;
#define space " "
#define debug(val) "[ " << #val " : " << (val) << " ]" << space
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1)*4)
#define pb push_back
#define ff first
#define ss second
#define pi pair<int , int >
#define INF LONG_LONG_MAX
#define EPS (double)0.0000000001
#define mp make_pair
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};
const int Mod = (int) ((int) 1e9 + 7);

void solve() {
    int n ; 
    cin >> n ; 
    vector<int> dp(n+ 1 , 0) ; 
    dp[0] = 1 ; 
    for(int i=3 ;i <= n ;i++){ 
        for(int j=3 ;i-j >=0;j++){
            dp[i] += dp[i - j ] ; 
            dp[i] %= Mod ; 
        }
    }
    cout << dp[n] << endl; 

}

int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0); // FAST IO
    int q = 1;
   // cin >> q;
    for (int i = 1; i <= q; i++) {
        // cout << "Case #" << i << ": ";
        solve();
    }
}

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

using namespace std;


void solve() {
    int n = 2019;
    int x, y;
    cin >> x >> y;
    if (y-x >= n-1){
        cout << 0; return;
    }
    int res = 2018;
    for (int i = x; i <= y; i++) {
        for (int j = i+1; j <= y; j++) {
            int u = i%n, v = j%n;
            int tmp = u*v % n;
            res = min(res, tmp);
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t;
  cin>>n;
  t=10;
  vector<vector<int>> f(n,vector<int>(t));
  for(int i=0;i<n;i++)
    for(int j=0;j<t;j++)
      cin>>f.at(i).at(j);
  vector<vector<int>> p(n,vector<int>(t+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<=t;j++)
      cin>>p.at(i).at(j);
  int m;
  for(int b=1;b<(1<<t);b++){
    vector<int> c(n,0);
    int x=b;
    for(int i=0;i<t;i++){
      for(int j=0;j<n;j++)
        c.at(j)+=f.at(j).at(i)*x%2;
      x/=2;
    }
    int s=0;
    for(int i=0;i<n;i++)
      s+=p.at(i).at(c.at(i));
    m=(b==1?s:max(m,s));
  }
  cout<<m<<endl;
}

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

int gcd(int a,int b) {
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}

int main() {
    int k;
    long long sum;
    cin >> k;

    sum = 0;
    for (int i=1; i<k+1; i++) {
        for (int j=1; j<k+1; j++) {
            for (int l=1; l<k+1; l++) {
                sum += gcd(gcd(i,j), l);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main()
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if((a==b&&c==d)||(a==c&&b==d)||(a==d&&c==b))
		printf("yes\n");
	else
		printf("no\n");
	return 0;
}



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

int main() {
    int i, n;
    cin >> n;
    int ans = 0;
    for (i = 1; i <= n; i++) {
        int count = 0, k = i;
        while (k) {
            count++;
            k /= 10;
        }
        if (count % 2 == 1) 
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    V<int>a;
    a.pb(1);
    a.pb(1);
    a.pb(1);
    a.pb(2);
    a.pb(1);
    a.pb(2);
    a.pb(1);
    a.pb(5);
    a.pb(2);
    a.pb(2);
    a.pb(1);
    a.pb(5);
    a.pb(1);
    a.pb(2);
    a.pb(1);
    a.pb(14);
    a.pb(1);
    a.pb(5);
    a.pb(1);
    a.pb(5);
    a.pb(2);
    a.pb(2);
    a.pb(1);
    a.pb(15);
    a.pb(2);
    a.pb(2);
    a.pb(5);
    a.pb(4);
    a.pb(1);
    a.pb(4);
    a.pb(1);
    a.pb(51);
    int k;cin>>k;
    cout<<a[k-1]<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
import java.util.*;

public class Main{
	//0110 start
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m) == 0) break;
			String [] name = new String[n];
			int [] start = new int[n];
			int [] end = new int[n];
			for(int i = 0; i < n; i++){
				name[i] = sc.next();
				int a = sc.nextInt();
				end[i] = sc.nextInt();
				start[i] = end[i] - a + 1;
			}
			
			for(int i = 0; i < m; i++){
				int yy = sc.nextInt();
				boolean flg = true;
				for(int j = 0; j < n; j++){
					if(start[j] <= yy && yy <= end[j]){
						flg = false;
						int res = yy - start[j] + 1;
						System.out.println(name[j] + " " + res);
						break;
					}
				}
				if(flg){
					System.out.println("Unknown");
				}
			}
		}
	}

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

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

#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//////////////////

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

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)




void solve(){
    int X;
    cin >> X;
    int ans;
    if(X<=599) ans = 8;
    else if(X<=799) ans = 7;
    else if(X<=999) ans = 6;
    else if(X<=1199) ans = 5;
    else if(X<=1399) ans = 4;
    else if(X<=1599) ans = 3;
    else if(X<=1799) ans = 2;
    else ans=1;
    
    cout << ans << endl;
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


signed main(void) 
{
    ll a, b, c, k;
    cin >>a >> b>> c>> k;
    
    ll abk, bbk, cbk;
    abk = a;
    bbk = b;
    cbk = c;
    
    
    rep(i1, k+1) {
        rep(i2, k+1) {
            rep(i3, k+1) {
                if (i1 + i2 + i3 > k) continue;
                a *= pow(2, i1);
                b *= pow(2, i2);
                c *= pow(2, i3);
                
                if (a < b && b < c) {
                    mes("Yes");
                    re0;
                }
                
                
                a = abk;
                b = bbk;
                c = cbk;
            }
        }
        
    }
    
    
    mes("No");
    
    


}


Measured memory_bytes: 4004
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

long long N, ans;
map<int, int> m;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> N;
	for (int i = 1; i <= N; ++i)
	{
		int v; cin >> v;
		ans += m[i - v];
		m[v + i]++;
	}
	cout << ans;
}

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

int main(){
    string A,B;
    cin >> A >> B;
    if(A[0] == B[0]){
        cout << "=" << endl;
        return 0;
    }
    if(A[0] > B[0]){
        cout << ">"  << endl;
    }else{
        cout << "<" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<Int, Int>;
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
struct SetupIO {
    SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;

template <class T> std::ostream& print(std::ostream& out, T const& val) { return (out << val << " "); }
template <class T1, class T2> std::ostream& print(std::ostream& out, std::pair<T1, T2> const& val) {
    return (out << "{" << val.first << " " << val.second << "} ");
}
template <template <class, class...> class TT, class... Args>
std::ostream& operator<<(std::ostream& out, TT<Args...> const& cont) {
    for (auto&& elem : cont) print(out, elem);
    return out;
}

void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) {
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#ifdef _MY_DEBUG
#define dump(...)                                                                                                    \
    cerr << "/* " << #__VA_ARGS__ << " [" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
#else
#define dump(...)
#endif

/**
 *    author:  knshnb
 *    created: CREATED_TIMESTAMP
 **/

Int f(Int x) {
    if (x == 1) return 300000;
    if (x == 2) return 200000;
    if (x == 3) return 100000;
    return 0;
}
signed main() {
    Int x, y;
    cin >> x >> y;
    Int ans = f(x) + f(y);
    if (x == 1 && y == 1) ans += 400000;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }
};

int main()
{
    input in;
    int a, b;
    in >> a, b;

    std::cout << ((a & 1 && b & 1) ? "Odd" : "Even");

    return 0;
}


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

int main() {
  string s;
  cin>>s;
  int k;
  cin>>k;
  int n = s.length();
  for (char c='a'; c<='z'; c++) {
    set<string> ss;
    for (int i=0; i<n; i++) {
      if (s[i] != c) {
        continue;
      }
      for (int j=1; j<=k; j++) {
        ss.insert(s.substr(i, j));
      }
    }
    if (ss.size() < k) {
      k -= ss.size();
    } else {
      vector<string> v(ss.begin(), ss.end());
      cout<<v[k-1]<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
#define h_p 1110111110111;
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
int main()
{
       int k;
       cin>>k;
       int a,b;
       cin>>a>>b;
       for(int i = a ; i <= b ; i++)
       {
              if((i%k) == 0){
                     cout<<"OK";
                     return 0;
              }
       }
       cout<<"NG"<<endl;
}


Measured memory_bytes: 3596
/**
 * B - 0 or 1 Swap
 * https://atcoder.jp/contests/abc135/tasks/abc135_b
 **/
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int MAX_N = 50;

int N;
vector<int> p;
vector<int> copy_p;

void solve() {
    sort(p.begin(), p.end());
    int dep = 0;
    for (int i = 0; i < p.size(); i++) {
        if (p[i] != copy_p[i]) {
            dep += 1;
        }
    }
    if (dep <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
        copy_p.push_back(tmp);
    }
    solve();
}

Measured memory_bytes: 256
n = int(input())
s   = input()

if n % 2 == 1:
    print('No')
else:
    f = True
    for i in range(n // 2):
        if s[i] != s[n // 2 + i]:
            f = False
    if f :
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 38256
#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, t;
  cin >> s >> t;
  int ans = 0;
  rep(i,s.size()) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3824
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let mut n = read::<String>()
        .chars()
        .map(|x| x.to_digit(10).unwrap())
        .collect::<Vec<_>>();
    n.reverse();
    n.push(0);
    let mut dp = vec![vec![0; 2]; n.len() + 1];
    for (i, &ch) in n.iter().enumerate() {
        dp[i + 1][0] = dp[i][0] + ch;
        dp[i + 1][1] = dp[i][0] + (10 - ch);
        if i != 0 {
            if ch == 9 {
                dp[i + 1][1] = min(dp[i][1], dp[i + 1][1]);
            } else {
                dp[i + 1][0] = min(dp[i][1] + ch + 1, dp[i + 1][0]);
                dp[i + 1][1] = min(dp[i][1] + (10 - (ch + 1)), dp[i + 1][1]);
            }
        }
    }
    println!("{}", min(dp[n.len()][0], dp[n.len()][1]));
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 39152
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	VI H(N);
	REP(i, N) {
		cin >> H[i];
	}
	int ans = 1;
	int cnt = H[0];
	FOR(i,1, N) {
		if (cnt <= H[i]) {
			ans++;
			cnt = H[i];
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		String[] nl = n.split("");
		if (nl[0].equals(nl[1]) && nl[1].equals(nl[2]) || nl[1].equals(nl[2]) && nl[2].equals(nl[3])) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		}
	}


Measured memory_bytes: 23764
#include <stdio.h>
long long a [100010];
int main (){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    int zero =0;

    for(int i=0;i<n;i++)
        if(a[i]==0)
            zero ++;
        if(zero >0){
            // a[i] contains 0
            printf("0\n");
            return 0;
        }
        long long prod =1;
        for(int i=0;i<n;i++){
        if(a[i ] <=1000000000000000000/ prod ){
           // This condition is equivalent to prod*a[i] <=10ˆ18
            prod *=a[i];
        }
        else
        {
        printf("-1\n");
        return 0;
        }
    }
    printf("%lld\n",prod );
}


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

long long N,A,B;
vector<long long> h(100010);

bool C(long long n){
  long long sum=0;
  for (long long i=0;i<N;i++){
    sum+=max((long long)0,(h[i]-B*n+A-B-1)/(A-B));
  }
  return sum<=n;
}

int main(){
  cin >> N >> A >> B;
  long long m=0;
  for (long long i=0;i<N;i++){
    cin >> h[i];
    m=max(m,h[i]);
  }
  long long lb=0,ub=m;
  while (ub-lb>1){
    long long mid=(lb+ub)/2;
    if (C(mid)){
      ub=mid;
    }
    else {
      lb=mid;
    }
  }
  cout << ub << endl;
}

Measured memory_bytes: 1024
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

slist = gets_nsp_list

b = ""
count = 0
slist.each do |s|
  if b == ""
    b = s
    next
  else
    if b == s
      b = s == "0" ? "1" : "0"
      count += 1
    else
      b = s
    end
  end
end

puts count

Measured memory_bytes: 21396
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int n,tmp;
    cin >> n;
    pair<int,int> max_first = make_pair(0,0);
    vector<int> input_list;
    int max_second = 0;

    REP(i,0,n){
        cin >> tmp;
        input_list.push_back(tmp);
        if(tmp > max_first.first){
            max_first = make_pair(tmp,1);
        }else if(tmp == max_first.first){
            max_first.second++;
        }
    }
    REP(i,0,n){
        if(max_first.first==input_list[i]) continue;
        if(input_list[i]>max_second) max_second = input_list[i];
    }

    if(max_first.second>=2){
        REP(i,0,n) P(max_first.first);  
    }else{
        REP(i,0,n){
            if(input_list[i]==max_first.first){
                P(max_second);
            }else{
                P(max_first.first);
            }
        }
    }
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}

int main(){
  int n; cin >> n;
  cout << 0 << endl;
  flush(cout);
  string s; cin >> s;
  char fst=s.front();
  if(fst == 'V'){
    cout << 0 << endl;  
    return 0;
  }
  int l = 0, r = n;
  for(;;){
    int mid = (l+r)/2;
    cout << mid << endl;
    flush(cout);
    cin >> s;
    char c = s.front();   
    if(c == 'V'){
      cout << mid << endl;
      return 0;
    }
    bool b = c == fst;
    if((b) ^ (mid%2))l = mid;
    else r = mid;
  }
}


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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define ll  long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

int mod = 1000000007;
const int N = 1005;

// gcd
ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}
ll lucas(ll n)
{
	if ( n == 0)
		return 2;
	if ( n == 1)
		return 1;
	ll a = 2;
	ll b = 1;
	for ( int i = 2; i <= n; i++)
	{
		ll c = a + b;
		a = b;
		b = c;
	}
	return b;
}
int c[11][11];

int dist[11][11];
ll solve()
{
	int i, j, k;
	
	for ( int i = 0; i < 10; i++)
	{
		for ( int j = 0; j < 10; j++)
			dist[i][j] = c[i][j];
	}
	for (k = 0; k < 10; k++)
    {
       
        for (i = 0; i < 10; i++)
        {
            for (j = 0; j < 10; j++)
            {
            	
                if (dist[i][k] + dist[k][j] < dist[i][j])
                    dist[i][j] = dist[i][k] + dist[k][j];
               // cout << dist[i][j] << endl;

            }
        }
    }
    
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n, m;
	

	cin >> n >> m;
	for ( int i = 0; i < 10; i++)
	{
		for ( int j = 0; j < 10; j++)
			cin >> c[i][j];
	}
	ll ans = 0;
	solve();
	for ( int i = 0; i < n; i++)
	{
		for ( int j = 0; j < m; j++)
		{
			ll x;
			cin >> x;
			if ( x == -1 or x == 1)
				continue;
			
			ans += dist[x][1];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
open Scanf
open Printf

let id a = a
let pair a b = a, b
let triplet a b c = a, b, c

let rec scan_list = function
  | 1 -> scanf "%d" (fun k -> [k])
  | n -> scanf "%d " (fun k -> k :: scan_list (n-1))

let () = let a,b = scanf "%d %d\n" pair in
  let n = b - a - 1 in
  printf "%d\n" (n*(n+1)/2 - a)

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    
    long long int ans = 1e18;
    for(int r=0; r<2; r++){
        long long int sub=0;
        int sum = 0;
        for(int i=0; i<n; i++){
            sum += a[i];
            if(i%2==r && sum>=0){
                sub += sum+1;
                sum = -1;
            }
            if(i%2==1-r && sum<=0){
                sub += -sum+1;
                sum = 1;
            }
        }
        ans = min(ans, sub);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
#define fs first
#define sc second
using namespace std;


typedef pair<ll,ll> P;



int main(){
  ll n,cnt = 0;
  cin >> n;
  ll a[n];
  rep(i,0,n) cin >> a[i];
  
  rep(i,0,n-1){
    if(a[i] == i+1){
      a[i] ^= a[i+1];
      a[i+1] ^= a[i];
      a[i] ^= a[i+1];
      cnt++;
    }
  }

  if(a[n-1] == n){
    a[n] ^= a[n-1];
    a[n-1] ^= a[n];
    a[n] ^= a[n-1];
    cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int f(unsigned long long N) {
    int ans = 0;
    while (N >= 3) {
        N = (N - 1) / 2;
        ans++;
    }
    return ans;
}
int main()
{
    int X; cin >> X;
    unsigned long long ok = 0, ng = -1;
    while (ng - ok > 1) {
        unsigned long long mid = ok + (ng - ok) / 2;
        (f(mid) <= X ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 256
def read_valus():
    return map(int, input().split())


def read_list():
    return list(read_valus())


def read_lists(N):
    return [read_list() for n in range(N)]


def get_bit(n, i):
    return n >> i & 1


def f(T, n):
    # for i in range(len(T)):
    #     if get_bit(n, i):
    #         for x, y in T[i]:
    #             if get_bit(n, x) != y:
    #                 return False
    # return True
    return all(all(get_bit(n, x) == y for x, y in T[i]) for i in range(len(T)) if get_bit(n, i))


def main():
    N = int(input())
    T = [[] for n in range(N)]
    for n in range(N):
        A = int(input())
        for _ in range(A):
            x, y = read_valus()
            x -= 1
            T[n].append((x, y))

    res = 0
    for n in range(2 ** N):
        if f(T, n):
            res = max(res, bin(n).count("1"))

    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
int main(void)
{
	int h,max(0);
	scanf("%d",&h);
	h=0;
	char c;
	getchar();
	while(scanf("%c",&c)!=EOF)
		max=std::max(max,h+=(c=='I'?1:-1));
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
 
namespace IO{
    const int insiz = 1 << 12, outsiz = 1 << 18;
    char in[insiz], *A(in), *B(in); char out[outsiz], *ptr(out);
    inline char getc(){
    	#ifndef LOCAL
        return (A == B) && (B = (A = in) + fread(in, 1, insiz, stdin), A == B) ? EOF : *A++;
        #endif
        return getchar();
    }
    template <typename T> inline T read(){
        T ret(0), p(1); char ch(getc());
        while(ch < '0' || ch > '9'){
            if(ch == '-') p = -1; ch = getc();
        }
        while(ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getc();
        return ret*p;
    }
    inline void flush(){ fwrite(out, 1, ptr - out, stdout); ptr = out; }
    template <typename T> inline void write(T x, char cmd = '\n'){
        if(x < 0) *ptr++ = '-', x = -x;
        if(x == 0) *ptr++ = '0';
        static char s[123]; int cnt = 0;
        for(; x; x /= 10) s[++cnt] = x % 10 + '0';
        for(; cnt; --cnt) *ptr++ = s[cnt];
        *ptr++ = cmd;
        if((outsiz >> 1) > ptr - out) flush();
    }
} using IO::getc; using IO::read; using IO::write; using IO::flush;
 
int main(){
	int n = read<int>();
	int ans(0), Max(0);
	for(int i(1) ; i <= n; ++i){
		int t = read<int>();
		if(t >= Max) ++ans, Max = t;
	}
	write(ans);
	flush(); return 0;
}
 
 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


signed main() {
	int n, q;
	cin >> n >> q;
	while (q--) {
		int v, w;
		cin >> v >> w;
		if (n == 1) cout << min(v, w) << endl;
		else {
			while (v != w) {
				if (v < w) w = (w - 2) / n + 1;
				else v = (v - 2) / n + 1;
			}
			cout << v << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
using ll = long long;
using ull = unsigned long long;

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

    int N = n * (n - 1) / 2;
    int M = m * (m - 1) / 2;
    int ans = N + M;
    println(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main() {
    ullong N; cin >> N;
    ullong deno = 26;
    string S("");
    while(N) {
        N--;
        ullong c = N % deno;
        S += ('a' + c);
        N /= deno;
    }
    reverse(S.begin(), S.end());
    cout << S << endl;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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; }

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll dp(n+1,n);
  dp[0]=0;
  rep(i,n){
    for(ll pow=1;pow+i<=n;pow*=6){
      chmin(dp[pow+i],dp[i]+1);
    }
    for(ll pow=1;pow+i<=n;pow*=9){
      chmin(dp[pow+i],dp[i]+1);
    }
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  long long int n,ans;
  cin>>n;
  ans=n/11;
  if(n%11>6)
    cout<<ans*2+2<<endl;
  else if(n%11==0)
    cout<<ans*2<<endl;
  else
    cout<<ans*2+1<<endl;
}

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

int main(){
    int r, D, x, y;
    cin >> r >> D >> x;
    for(int i = 0; i < 10; i++){
        y = r * x - D;
        cout << y << endl;
        x = y; 
    }
    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin>>n;
    vector<ll> t(n);
    ll ans=1;

    for(int i = 0; i < n; i++)
    {
        cin>>t[i];
        ans = ans / __gcd(ans,t[i]) * t[i];
    }
    cout << ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

char c[2][3];
void mainp()
{
    long long sq=0;
    int n;
    cin>>n;
    for(int i=100000; i>=0; i--)
    {
        sq=i*1ll*i;
        if(sq<=n) break;
    }
    
    cout<<sq<<endl;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mainp();
    return 0;
}

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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "YES"
#define NO  "NO"
#define MOD 1000000000+7

#define forit(v) for(auto it = v.begin(); it != v.end(); ++it)

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int h, w; cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; ++i) cin >> a[i];

  for (int j = 0; j < w + 2; ++j)
    cout << '#';
  cout << endl;
  for (int i = 0; i < h; ++i) {
    cout << '#' << a[i] << '#' << endl;;
  }
  for (int j = 0; j < w + 2; ++j)
    cout << '#';
  cout << endl;

  // cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t[100100];
    int n;
    cin >> n;
    int i = 1;
    while(n --)
    {
        cin >> t[i];
        i ++;
    }
    int m;
    cin >> m;
    while(m --)
    {
        int p, x;
        cin >> p >> x;
        int c;
        c = t[p];
        t[p] = x;
        int sum = 0;
        for(int j = 1; j < i; j ++)
        {
            sum += t[j];
        }
        cout << sum <<endl;
        t[p] = c;
    }
    return 0;
}

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

typedef long long ll;
const int MAXN = 2010;
const ll MOD = 1000000007;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

inline ll qpow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b & 1LL) res = res * a % MOD;
		b >>= 1, a = a * a % MOD;
	}
	return res;
}

int e, st[MAXN], to[MAXN];
int nxt[MAXN];
inline void Add(int u, int v) {
	to[++e] = v, nxt[e] = st[u];
	st[u] = e;
}

int n, fa[MAXN], size[MAXN];
ll dp[MAXN][MAXN][3], inv2;
ll tmp[MAXN][3];
ll fac[MAXN], ans;

inline void update(ll &cur, ll val) {
	cur = cur+val;
	if(cur >= MOD) cur -= MOD;
}

void dfs(int u) {
	int i, j, k;
	dp[u][1][0] = 1, size[u] = 1;
	for(i = st[u]; i; i = nxt[i]) {
		int v = to[i];
		dfs(v), size[u] += size[v];
	}
	if(size[u] == 1) return;
	for(i = st[u]; i; i = nxt[i]) {
		for(k = size[u]; k >= 1; k--) {
			tmp[k][0] = dp[u][k][0];
			tmp[k][1] = dp[u][k][1];
			tmp[k][2] = dp[u][k][2];
			dp[u][k][0] = dp[u][k][1] = dp[u][k][2] = 0;
		}
		int v = to[i];
		for(k = size[u]-size[v]+1; k >= 1; k--) {
			for(j = size[v]; j >= 1; j--) {
				if(j+k-1 != size[u]) {
					update(dp[u][j+k][0], dp[v][j][0]*tmp[k][0]%MOD);
					update(dp[u][j+k][1], dp[v][j][0]*tmp[k][1]%MOD);
					update(dp[u][j+k][2], dp[v][j][0]*tmp[k][2]%MOD);
					update(dp[u][j+k][0], dp[v][j][1]*tmp[k][0]%MOD);
					update(dp[u][j+k][1], dp[v][j][1]*tmp[k][1]%MOD);
					update(dp[u][j+k][2], dp[v][j][1]*tmp[k][2]%MOD);
					update(dp[u][j+k][0], dp[v][j][2]*tmp[k][0]%MOD);
					update(dp[u][j+k][1], dp[v][j][2]*tmp[k][1]%MOD);
					update(dp[u][j+k][2], dp[v][j][2]*tmp[k][2]%MOD);
				}
				update(dp[u][j+k-1][2], dp[v][j][0]*tmp[k][1]%MOD);
				update(dp[u][j+k-1][2], dp[v][j][1]*tmp[k][1]%MOD*inv2%MOD);
				update(dp[u][j+k-1][1], dp[v][j][0]*tmp[k][0]%MOD*2%MOD);
				update(dp[u][j+k-1][1], dp[v][j][1]*tmp[k][0]%MOD);
			}
		}
		/*if(u == 1) {
			printf(":");
			for(k = 1; k <= size[u]; k++)
				printf("(%lld,%lld,%lld) ", dp[u][k][0], dp[u][k][1], dp[u][k][2]);
			printf("\n");
		}*/
	}
	/*for(k = 1; k <= size[u]; k++)
		printf("(%lld,%lld,%lld) ", dp[u][k][0], dp[u][k][1], dp[u][k][2]);
	printf("\n");*/
}

int main() {
	int i;

	n = read();
	for(i = 2; i <= n; i++) Add(read(), i);

	inv2 = qpow(2, MOD-2);
	dfs(1);
	//printf("%lld\n", dp[4][1][0]);
	//printf("%lld\n", dp[3][1][1]);
	//printf("%lld\n", dp[3][2][0]);

	fac[0] = 1;
	for(i = 1; i <= n; i++) fac[i] = fac[i-1]*i%MOD;
	for(i = 0; i < n; i++) {
		int f = i & 1 ? MOD-1 : 1;
		update(ans, f*fac[n-i]%MOD*((dp[1][n-i][0]+dp[1][n-i][1]+dp[1][n-i][2])%MOD)%MOD);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 94720
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LaL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
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 namespace std;

int main(){
  int K,A,B,ans=0;
  cin>>K>>A>>B;
  bool CAN=false;
  
  for(int i=A; i<=B; ++i){
    if(i%K==0) CAN=true;
  }
  
  if(CAN) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<utility>
#include<vector>
#include <algorithm>
int main(){
    unsigned long long h;
    int n;
    std::cin>>h>>n;
      std::vector<int> atack(n);
    for(int i = 0;i < n;i++){
        std::cin>>atack[i];
    }
    std::sort(atack.begin(),atack.end());
    unsigned long long int sum = 0;
    for(int i = n - 1;n - i <= n;i--){
        sum += atack[i];
    }
    if(sum >= h){
        std::cout<<"Yes"<<std::endl;
    }else{
        std::cout<<"No"<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    char ch;
    cin >> ch;
    if (ch == 'A') cout << "T" << endl;
    else if (ch == 'C') cout << "G" << endl;
    else if (ch == 'T') cout << "A" << endl;
    else cout << "C" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		char[] octs;
		while (!(line = br.readLine()).equals("0")) {
			octs = Integer.toOctalString(Integer.parseInt(line)).toCharArray();
			for (int i = 0; i < octs.length; i++) {
				switch (octs[i]) {
				case '4':
					octs[i] = '5';
					break;
				case '5':
					octs[i] = '7';
					break;
				case '6':
					octs[i] = '8';
					break;
				case '7':
					octs[i] = '9';
					break;
				}
			}
			System.out.println(String.valueOf(octs));
		}
	}
}

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

fn main() {
    let v = read_vec::<u64>();
    let n = v[0];
    let mut x = v[1];

    let mut len = 1;
    for _ in 0..n {
        len = 2u64 * len + 3u64;
    }
    let mut pat = 1;
    for _ in 0..n {
        pat = 2u64 * pat + 1u64;
    }

    let mut count: u64 = 0;
    loop {
        //println!("{} {} {} {}", len, pat, x, count);
        let mid = (len + 1) / 2;

        if x == 1 {
            if len == 1 { count += 1; }
            break;
        } else if x == mid - 1 {
            count += (pat - 1) / 2;
            break;
        } else if x == mid {
            count += (pat + 1) / 2;
            break;
        } else if x > mid {
            count += (pat + 1) / 2;
            x -= mid;
        } else {
            x -= 1; // ban
        }

        pat = (pat - 1) / 2;
        len = (len - 3) / 2;
    }
    println!("{}", count);
}


Measured memory_bytes: 4352