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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
void p(string s){
  cout << s <<endl;
}
//-----------------------------------------

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


  int h, w;
  cin >> h >> w;
  vvll vec(h+1,vll(w+1,0));
  REP(i,h) REP(j,w) cin >> vec[i][j];
  REP(i,h) REP(j,w) vec[i][w] += vec[i][j];
  REP(j,w+1) REP(i,h) vec[h][j] += vec[i][j];
  REP(i,h+1){
    REP(j,w+1){
      if(j) cout << " ";
      cout << vec[i][j];
    }
    cout <<endl;
  }




  return 0;
}



Measured memory_bytes: 3320
N = int(input())
X = list(map(int, input()))[::-1]
p = sum(X)

if p==0:
    for _ in range(N):
        print(1)
    exit()

if p==1:
    if X[0]==0:
        ans = [2]
        for n in range(1, N):
            ans.append(1 if X[n]==0 else 0)
    else:
        ans = [0] + [2]*(N-1)

    for a in ans[::-1]:
        print(a)
        
    exit()
    

pp = p+1
rp = []
k = 1
for n in range(N):
    rp.append(k%pp)
    k = k*2%pp

sp = 0
for r,x in zip(rp, X):
    if x==1: sp = (sp+r)%pp
    
pn = p-1
rn = []
k = 1
for n in range(N):
    rn.append(k%pn)
    k = k*2%pn

sn = 0
for r,x in zip(rn, X):
    if x==1: sn = (sn+r)%pn

def popcount(x):
    p = 0
    while x:
        p += x&1
        x>>=1
    return p

def op(x):
    p = popcount(x)
    return x%p

def f(x):
    n = 0
    while x:
        n+=1
        x = op(x)
    return n
    
ans = []
for n,x in enumerate(X):
    if x==0:
        ans.append(1+f((sp+rp[n])%pp))
    else:
        ans.append(1+f((sn-rn[n])%pn))

for a in ans[::-1]:
    print(a)




Measured memory_bytes: 29676
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
 #define big 1000000007
int main(){
    int a,b;
    cin >> a>>b;
    if(a+b==3){
        cout << 3 <<endl;
    }
    else if(a+b==4){
        cout << 2 <<endl;
    }
    else{
        cout <<1 <<endl;
    }

}

Measured memory_bytes: 256
n,k = map(int,input().split())
h = [int(input()) for _ in range(n)]
h = sorted(h)

res = 10 ** 100
for i in range(n):
    j = i + k - 1
    if j >= n:
        break
    res = min(res, h[j] - h[i])
print(res)

Measured memory_bytes: 8280
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	string S;
	cin>>S;
	int N=S.size();
	
	if(S[0]!='A') return _P("WA\n");
	S[0]='a';
	int C=0;
	for(i=2;i<N-1;i++) if(S[i]=='C') C++, S[i]='c';
	if(C!=1) return _P("WA\n");
	FORR(c,S) {
		if(c>='A' && c<='Z') return _P("WA\n");
	}
	_P("AC\n");
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
s = input()
l = []
count = 0
for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
        count += 1
    else:
        l.append(count)
        count = 0
    if i == len(s)-1:
        l.append(count)

print(max(l))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long 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 long long INF = 1LL << 60;

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

  cout << (s[0] == s[2] ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main()
{
    int a,b;
    cin >> a >> b;
    int res = (b-a);
    res = res*(res+1)/2;
    res -=b;
    cout << res << endl;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    s = input().strip()
    length = len(s)
    o = "10" * (length // 2 + (length % 2))
    o_len = len([i for i, j in zip(s, o) if i == j])
    z_len = len([i for i, j in zip(s, o[::-1]) if i == j])
    print(length - max([z_len, o_len]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 4212
using System;
using System.Collections.Generic;

namespace _0175
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == -1)
                {
                    break;
                }
                List<int> four = new List<int>();
                while (n > 3)
                {
                    four.Add(n % 4);
                    n = n / 4;
                }
                four.Add(n);
                for (int i = four.Count - 1; i >= 0; i--)
                {
                    Console.Write(four[i]);
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9276
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1e9+1;


void solve(){
    int n,time;
    cin >> n >> time;
    int ans = 10000;
    vector<pair<int,int>> v;
    rep(i,n){
        int c,t;
        cin >> c >> t;
        v.emplace_back(make_pair(c,t));
    }
    rep(i,n){
        int c,t;
        c = v[i].first;
        t = v[i].second;
        if(t <= time){
            ans = min(ans, c);
        }
    }
    if(ans==10000) cout << "TLE" << endl;
    else cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (C >= A && C <= B) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp=[100000000000000000]*n
dp[0]=0
for i in range(1,n):
  for j in range(k):
    if i > j:
      dp[i] = min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))
print(dp[-1])

Measured memory_bytes: 52604
#include<bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define fp first
#define sp second
typedef long long int ll;
typedef pair<ll,ll> pp;
#define check(x, i) ((x>>i)&1)
#define set(x,i) (x|(1<<i))
#define unset(x,i) (x&~(1<<i))
#define INF LONG_MAX
#define MAX_N 20
#define MAX 4000005
#define mod 1000000007
#define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define len(i,s) for(i=0;s[i];i++)
#define T() while(t--)
ll gcd (ll a, ll b){return (a?gcd(b%a,a):b);}
ll pow1(ll a,ll b,ll MOD){ll ans=1;while(b!=0){if(b&1)ans=(ans*a)%MOD;a=(a*a)%MOD;b=b/2;}return ans;}
ll modInverse(ll a,ll p){return pow1(a,p-2,p);}

int main()
{
	boost
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);    
    freopen("output.txt", "w", stdout);
#endif
 ll a,b,c,k,ans;
 cin>>a>>b>>c>>k;
 if(k<=a)
 {
 	cout<<k;
 return 0 ;
}
ans=a;
k=k-a;
 if(k>b)
 	k=k-b;
 else if(k<=b)
 {
 	cout<<ans;
 	return 0 ;
 }
 if(k<=c)
 {
 	ans-=k;
 	cout<<ans;
 	return 0;
 }
cout<<ans;
}

Measured memory_bytes: 3640
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!{
        n: usize,
        xs: [i64; n]
    }
    let m1 = xs.iter().map(|&x| x).sum::<i64>() / n as i64;
    let m2 = m1 + 1;
    let v1 = xs.iter().map(|&x| (x - m1) * (x - m1)).sum::<i64>();
    let v2 = xs.iter().map(|&x| (x - m2) * (x - m2)).sum::<i64>();
    println!("{}", min(v1, v2));
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main()
{
    int n,i,j;
    cin>>n;
    int m[2][n];
    for(i=0;i<2;i++)
    {
        for(j=0;j<n;j++)
        {
            cin>>m[i][j];
        }
    }
    int dp[3][n+1];
    dp[0][0]=m[0][0];
    for(i=1;i<2;i++)
    {
        dp[i][0]=dp[i-1][0]+m[i][0];
    }
    for(i=1;i<n;i++)
    {
        dp[0][i]=dp[0][i-1]+m[0][i];
    }
    for(i=1;i<2;i++)
    {
        for(j=1;j<n;j++)
        {
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])+m[i][j];
        }
    }
    cout<<dp[1][n-1]<<endl;
    return 0;
}


Measured memory_bytes: 3576
const Main = () => {
    const line = require('fs').readFileSync('/dev/stdin', 'utf8');
    let [tHp, tAtk, aHp, aAtk] = line.split(' ').map(v => parseInt(v, 10));
    while (true) {
        aHp -= tAtk;
        if (aHp <= 0) {
            console.log('Yes');
            break;
        }
        tHp -= aAtk;
        if (tHp <= 0) {
            console.log('No');
            break;
        }
    }
}

Main();

Measured memory_bytes: 29612
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <functional>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int MAX = 5000000;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    map<int,int> mp;
    for(int j = 2;j * j <= m;j++){
        while(m % j == 0){
            m /= j;
            mp[j]++;
        }
    }
    if(m != 1)mp[m]++;

    ll ans = 1;

    for(auto p:mp){
        int k = p.second;
        ans *= COM(n+k-1,k);
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 117376
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int s; cin >> s;
  set<int> st;
  while (st.count(s) == 0) { // s が既に現れていれば 1
    st.insert(s);
    if (s & 1) s = 3 * s + 1;
    else s >>= 1;
  }
  // 重複する分は st に含まれていない
  cout << st.size() + 1 << '\n';
  return 0;
}


Measured memory_bytes: 256
/*      Abhijith    */
#include<bits/stdc++.h>
#include<iomanip>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
using namespace std;
// Moving in a DAG from left to right
vector<lld>     adj[100005];
vector<int> visited(100005,0);
vector<lld> dist(100005,0),indegree(100005,0);
void dfs(lld s)
{
    visited[s]=1;
    lld sz=adj[s].size();
    for(lld y:adj[s])
    {
        dist[y]=max(dist[y],dist[s]+1);
        indegree[y]--;
        if(indegree[y]==0)
            dfs(y);
    }
}
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
      lld x,y,n,m;
      cin>>n>>m;
      rep(i,0,m-1)
      {
          cin>>x>>y;
          adj[x].pb(y);
          indegree[y]++;
      }
      rep(i,1,n)
      adj[0].pb(i);
      rep(i,1,n)
      if(!visited[i]&&!indegree[i])
      dfs(i);
      lld ans=(*max_element(all(dist)));
      cout<<(ans)<<endl;
    return 0;
}


Measured memory_bytes: 11764
#include <bits/stdc++.h>
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) v.begin(), v.end()

using namespace std;

ll mod = 1e9+7;
inline ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

inline ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

inline ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

inline ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return (dividend / divisor);
}

// 因数分解
inline vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

inline bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

//階乗
inline ll factorialMethod(ll k){
    ll sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

inline ll vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
        
        
    }
    else { // 発見できなかったとき
        return 0;
    }
}

void recursive_comb(ll *indexes, ll s, ll rest, std::function<void(ll *)> f) {
    if (rest == 0) {
        f(indexes);
    } else {
        if (s < 0) return;
        recursive_comb(indexes, s - 1, rest, f);
        indexes[rest - 1] = s;
        recursive_comb(indexes, s - 1, rest - 1, f);
    }
}

void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

int main(){
    ll n;
    cin >> n;
    cout << 2 * M_PI * n;
    
    return 0;
}


Measured memory_bytes: 3844
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, h, m int
	fmt.Scan(&a, &b, &h, &m)

	radH := (float64(h) + float64(m)/60) * 2 * math.Pi / 12
	radM := float64(m) * 2 * math.Pi / 60
	rad := math.Abs(radH - radM)
	ans := float64(a*a) + float64(b*b) - 2*float64(a*b)*math.Cos(rad)
	ans = math.Sqrt(ans)
	fmt.Println(ans)
}


Measured memory_bytes: 1824
N, W = map(int, input().split())
D = {0: 0}
for i in range(N):
  w, v = map(int, input().split())
  A = [[i, D[i]] for i in D]
  for j in A:
    if j[0] + w <= W:
      if j[0] + w in D:
        D[j[0] + w] = max(D[j[0] + w], j[1] + v)
      else:
        D[j[0]+w] = j[1]+v
print(max(D[i] for i in D))

Measured memory_bytes: 3828
import math
n,d = map(int,input().split())
xy = [list(map(int,input().split())) for _ in range(n)]
cnt = 0
for i in range(n):
	if math.sqrt((xy[i][0])**2 + (xy[i][1])**2) <= d:
		cnt += 1
print(cnt)

Measured memory_bytes: 45456
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int a[100000],sum=1;
int main()
{
	int n,judge=0; 
	cin>>n;
	if(n==1)
	{
		cin>>a[1];
		cout<<1;
		return 0;
	}
	if(n==2)
	{
		cin>>a[1]>>a[2];
		cout<<1;
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(i==1)continue;
		if(a[i]>a[i-1])
		{
			if(judge==-1)
			{
				judge=0;
				sum++;
			}
			else judge=1;
		}
		if(a[i]<a[i-1])
		{
			if(judge==1)
			{
				judge=0;
				sum++;
			}
			else judge=-1;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define PUTS(x) cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define MOD 998244353

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// a^n mod m を求める
Int modpow(Int a, Int n, Int m) {
    Int b, t;
    if (n == 0) return 1;
    a %= m;
    b = a * a;
    b %= m;
    t = modpow(b, n / 2, m);
    if (n % 2 != 0) {
        t *= a;
        t %= m;
    }
    return t;
}


int main() {
    int N, M, K;
    cin >> N >> M >> K;
    if (N == 1) {
        PUTS(M);
        exit(0);
    }

    // 前処理
    COMinit();

    Int ans = 0;
    rep(m, K + 1) {
        Int a = modpow(M-1,N-1-m,MOD);
        a *= COM(N - 1, m);
        a %= MOD;
        ans += a;
        ans %= MOD;
    }
    ans *= M;
    ans %= MOD;


    cout << ans << endl;
}


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

using namespace std;

int main(void){

    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;

    for(int i = 0;i <= a;i++){
        for(int j = 0;j <= b;j++){
            for(int k = 0;k <= c;k++){
                if(x == 500*i + 100*j + 50*k) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin

def main():
    input = stdin.readline
    n = int(input())
    a = list(map(int, input().split()))
    p = []
    for i in reversed(range(n)):
        if a[i]:
            p.append(i + 1)
            u = 1
            v = i + 1
            while u * u <= v:
                if v % u == 0:
                    a[u - 1] ^= 1
                    if u != v // u:
                        a[v // u - 1] ^= 1
                u += 1
    if len(p) > 0:
        print(len(p))
        print(*p)
    else:
        print(0)
main()

Measured memory_bytes: 96036
A = []
b = []
c = []

line, row = list(map(int, input().split()))

for _ in range(line):
    A.append(list(map(int, input().split())))

for _ in range(row):
    b.append(int(input()))

for l in range(line):
    tmp = 0
    for r in range(row):
        tmp += A[l][r] * b[r]
    c.append(tmp)

for e in c:
    print(e)



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

using namespace std;

typedef long long ll;

const int N = 1e6 + 5;
const ll mod = 998244353;
ll sum[N];
ll sqsum[N];
ll f[N];
ll inv[N];

ll add(ll x, ll y) {
  x = (x + y);
  if(x >= mod) x -= mod;
  return x;
}

ll sub(ll x, ll y) {
  x = x - y;
  x %= mod;
  if(x < 0) x += mod;
  return x;
}

ll mult(ll x, ll y) {
  x = (x * y) % mod;
  if(x < 0) x += mod;
  return x;
}

ll get(int x) {
  return sub(mult(sum[x], sum[x]), sqsum[x]);
}

int main() {
  inv[1] = 1;
  for(ll i = 2; i < N; i++) {
    inv[i] = add(inv[i], mult(-(mod / i), inv[mod % i]));
  }
  int n; scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    ll x;
    scanf("%lld", &x);
    sum[x] = add(sum[x], x);
    sqsum[x] = add(sqsum[x], mult(x, x));
    //cout << sum[x] << ' ' << sqsum[x] << '\n';
  }
  for(int i = 1; i < N; i++) {
    for(int j = i + i; j < N; j += i) {
      sum[i] = add(sum[i], sum[j]);
      sqsum[i] = add(sqsum[i], sqsum[j]);
    }
    f[i] = get(i);
  }
  ll sum = 0;
  for(int i = N - 1; i >= 1; i--) {
    for(int j = i + i; j < N; j += i) {
      f[i] = sub(f[i], f[j]);
    }
    sum = add(sum, mult(f[i], inv[i]));
  }
  sum = mult(sum, inv[2]);
  printf("%lld\n", sum);
}

Measured memory_bytes: 31488
import sys
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()
 
A,B = MULT_INT_LIST()
new = []
C = A+B 
D = A-B
E = A*B
new.append(C)
new.append(D)
new.append(E)
print(max(new))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int co=0;
    loop(i,1,n){
      int sum=0;
      for(int j=i;sum<n;j++){
	sum+=j;
	if(sum==n)co++;
      }
    }
    cout<<co<<endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long lol;
int fac2[1000005],flag0,flag1,flag2;
int n,sum,a[1000005];
char s[1000005];
int get(int i,int v)
{
	if (i>n) return 0;
	if (fac2[n-1]-fac2[n-i]-fac2[i-1]==0) return v;
	return 0;
}
int main()
{int i;
	scanf("%d",&n);
	scanf("%s",s+1);
	for (i=1;i<=n;i++)
	{
		a[i]=s[i]-'1';
		if (a[i]==0) flag0=1;
		if (a[i]==1) flag1=1;
		if (a[i]==2) flag2=1;
	}
	fac2[1]=0;
	for (i=2;i<=n;i++)
	{
		//printf("%d\n",a[i]);
		if (i%2==0)
		fac2[i]=fac2[i/2]+1;
	}
	for (i=1;i<=n;i++)
	fac2[i]+=fac2[i-1];
	if (flag0+flag1+flag2==1) printf("0\n");
	else 
	{
		if (flag2==1&&flag0==1&&flag1==0)
		{
			for (i=1;i<=n;i++)
			if (a[i]==2) sum^=get(i,2);
			printf("%d",sum);
		}
		else
		{ 
			if (flag2==1&&flag1==1&&flag0==0) 
			for (i=1;i<=n;i++)
			a[i]--;
			if (flag2==1&&flag1==1&&flag0==1) 
			for (i=1;i<=n;i++)
			if (a[i]==2) a[i]=0;
			
			for (i=1;i<=n;i++)
			if (a[i]==1) sum^=get(i,1);
			printf("%d",sum);
		}
	}
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
#define ll long long
#define inf 100000000000000000ll
using namespace std;
int n;
ll mem[200005][3], ara[200005];
bool vis[200005][3];
ll dp(int pos, int skip)
{
    if(pos>=n || (pos==n-1 && skip==2))return 0;
    if(vis[pos][skip])return mem[pos][skip];
    vis[pos][skip]= 1;
    mem[pos][skip]= -inf;
    if(skip)mem[pos][skip]= dp(pos+1, skip-1);
    mem[pos][skip]= max(mem[pos][skip], ara[pos]+dp(pos+2, skip));
    return mem[pos][skip];
}
int main()
{
    scanf("%d", &n);
    for(int i=0; i<n; i++)scanf("%lld", &ara[i]);
    ll res= -inf;
    if(!(n&1))
    {
        //memset(vis, 0, sizeof vis);
        res= max(res, ara[0]+dp(2, 1));
        //memset(vis, 0, sizeof vis);
        res= max(res, ara[1]+dp(3, 0));
    }
    else
    {
        //memset(vis, 0, sizeof vis);
        res= max(res, ara[0]+dp(2, 2));
        //memset(vis, 0, sizeof vis);
        res= max(res, ara[1]+dp(3, 1));
        //memset(vis, 0, sizeof vis);
        res= max(res, ara[2]+dp(4, 0));
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 16828
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
int const mod = 998244353;
// long long const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            // res = res*a;
            res = (res*a)%m;
        }
        a=(a*a)%m;
        // a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x , int m){
    return power(x,m-2,m);
}

int const N = 1e5+5;
int const inf = 2e18;

void solve(){  
    int i,j;
    int n;
    cin >>n;
    string s;
    cin >> s;
    int cnt = 0;
    for(i=0;i<n;i++){
        cnt = cnt + (s[i] == 'R');
    }
    int ans;
    int c = 0;
    for(i=0;i<cnt;i++){
        c = c + (s[i] == 'W');
    }

    cout<<c<<endl;
}           



int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;  
    for(int tt=1;tt<=t;tt++){
        // cout << "Case #"<<tt<<": ";
        solve();
    }
    return 0;
}


/*

*/

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll r;
  cin >> r;
  cout << 3*r*r;
  return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

pair <pii,pii> solve(string s) {
	ll sv=s[0]-'0';
	ll tr=0;
	ll de=1;
	int i=1;
	while (i<(int)s.length() && s[i]!='.') {ll x=s[i]-'0'; sv=10*sv+x;i++;}
	if (i<(int)s.length()) {
		tr=s[i+1]-'0';
		de=10*de;
		for (int j=i+2;j<(int)s.length();j++) {ll x=s[j]-'0'; tr=10*tr+x; de=10*de;}
		}
	ll skai=sv*de+tr;
	ll vard=de;
	while (skai%2==0 && vard%2==0) {skai=skai/2; vard=vard/2;}
	while (skai%5==0 && vard%5==0) {skai=skai/5; vard=vard/5;}
	int a=0;
	int b=0;
	int c=0;
	int d=0;
	while (skai%2==0) {skai=skai/2; a++;}
	while (skai%5==0) {skai=skai/5; b++;}
	while (vard%2==0) {vard=vard/2; c++;}
	while (vard%5==0) {vard=vard/5; d++;}
	//cout<<s<<" "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
	return {{a,b},{c,d}};
	}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    map <pair <pii,pii>,ll> M; 
    for (int i=0;i<n;i++) {
		string s;
		cin>>s;
		M[solve(s)]++;
		}
	ll ats=0;
	for (auto u:M) {
		for (auto v:M) {
			 pii sk1=(u.first).first;
			 pii sk2=(v.first).first;
			 pii va1=(u.first).second;
			 pii va2=(v.first).second;
			 if (sk1.first+sk2.first>=va1.first+va2.first && sk1.second+sk2.second>=va1.second+va2.second) {
				 //cout<<sk1.first<<" "<<sk1.second<<" "<<va1.first<<" "<<va1.second<<" "<<sk2.first<<" "<<sk2.second<<" "<<va2.first<<" "<<va2.second<<endl;
				 ats+=u.second*v.second;
				 //cout<<ats<<endl;
				 if (u==v) {ats-=u.second;}
				 }
			}
		}
	cout<<ats/2<<endl;
    return 0;
}


Measured memory_bytes: 3580
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, k = sc.nextInt

    var ans = 0d;
    for (i <- 1 to n) {
      var p = 1d
      var x = i
      while (x < k) {
        p = p * 0.5
        x = x * 2
      }
      ans += p / n
    }
    println(ans)
  }
}


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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define STDIO
#define MP make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define PF push_front 
#define PB push_back
#define PP push
#define lb lower_bound 
#define ub upper_bound

inline void checkmin(int &x, int y){x = min(x, y);}
inline void checkmax(int &x, int y){x = max(x, y);}

int n,k;
int a;

vl pref;

struct SegTree
{
	int len=0;
	vl s;
	vl tree;
	void init()
	{
		len=1;
		while(len<=sz(s)) len<<=1;
		while(sz(s)<len) s.PB(s.back());
		tree.rsz(len*2,0);
	}
	void change(ll k,int d)
	{
		int i=lb(all(s),k)-begin(s)+len;
		while(i>0)
		{
			tree[i]+=d;
			i>>=1;
		}
	}
	ll get(int x,int l,int r,ll k)
	{
		if(s[r-1]<k) return 0;
		if(s[l]>=k) return tree[x];
		int mid=(l+r)>>1;
		return get(x*2,l,mid,k)+get(x*2+1,mid,r,k);
	}
}box;

int main() 
{
	#ifndef STDIO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n>>k;
    pref.PB(0);
    box.s.PB(0);
    for(int i=0;i<n;i++)
    {
    	cin>>a;
    	pref.PB(pref.back()+a-k);
    	box.s.PB(pref.back());
	}
	box.init();
	sort(all(box.s));
//	for(int i=0;i<sz(box.s);i++) cout<<box.s[i]<<" ";
//	cout<<endl;
	ll ans=0;
	for(int i=n;i>=0;i--)
	{
		ans+=box.get(1,0,box.len,pref[i]);
		box.change(pref[i],1);
	}
	cout<<ans<<endl;
    /* end code */
	return 0;
}

Measured memory_bytes: 8676
#include <iostream>
#include <math.h>
using namespace std;

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

  int count = 0;
  for (int c = 1; c < n; c++) {
    ab = n - c;
    int tmp;
    tmp = (int)sqrt(ab) + 1;
    for (int a = 1; a < tmp; a++) {
      if (a * a == ab){
        count += 1;
      }else if (ab % a == 0){
        count += 2;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;



int main(){FIN

    ll d;cin>>d;
    string ans;
    if(d==25) ans = "Christmas";
    else if(d==24) ans="Christmas Eve";
    else if(d==23) ans="Christmas Eve Eve";
    else ans="Christmas Eve Eve Eve";
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){
	int work[4],L,S,Result,count;
	char buf[5];

	while(true){
		scanf("%s",buf);

		if(buf[0] == '0' && buf[1] == '0' && buf[2] == '0' && buf[3] == '0')break;

		if(buf[0] == buf[1] && buf[0] == buf[2] && buf[0] == buf[3]){
			printf("NA\n");
			continue;
		}

		work[0] = buf[0] - '0';
		work[1] = buf[1] - '0';
		work[2] = buf[2] - '0';
		work[3] = buf[3] - '0';

		count = 0;

		while(true){
			if(work[0] == 6 && work[1] == 1 && work[2] == 7 && work[3] == 4)break;

			count++;
			for(int i = 1; i <= 3; i++){
				for(int k = 3; k >= i; k--){
					if(work[k] > work[k-1])swap(work[k],work[k-1]);
				}
			}

			L = 1000*work[0]+100*work[1]+10*work[2]+work[3];

			for(int i = 1; i <= 3; i++){
				for(int k = 3; k >= i; k--){
					if(work[k] < work[k-1])swap(work[k],work[k-1]);
				}
			}
			S = 1000*work[0]+100*work[1]+10*work[2]+work[3];
			Result = L - S;

			for(int i = 0,k=1000; i < 4; i++, k /= 10){
				work[i] = Result/k;
				Result %= k;
			}
		}
		printf("%d\n",count);
	}

	return 0;
}

Measured memory_bytes: 2660
#include <bits/stdc++.h>
#include <climits> //INT_MAX使える
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

/*dpの横軸重さだと10^2*10^9行列になるからTLE。大体10^(10or11)辺りがボーダー
横軸価値の合計にして10^2*(10^3*10^2)行列にすれば大丈夫
要素はその価値を実現するために必要な重さの最小値。最大で10^2*10^9だからlong long
intは4byte=32bit->符号+2^31まで表せる。大体2*10^9までセーフ*/
int main() {
  int N, W;
  cin >> N >> W;
  int w[N], v[N];
  int max_v = 0;
  for(int i=0; i<N; i++){
    cin >> w[i] >> v[i];
    max_v += v[i];
  }
  
  //long long INF = LLONG_MAX; //こっち使うと何故か上手くいかなかった
  int INF = INT_MAX;
  long long dp[110][100100]; //={INF}で初期化無理っぽい。0なら確か出来たのに
  /*=つけてなくて一番下の段INF入れられてなくて0入っちゃってた。chminに支障きたす*/
  for(int i=0; i<=N; i++){
    for(int sum_v=0; sum_v<=max_v; sum_v++)
      dp[i][sum_v] = INF; //(long long)に型変換しなくても大丈夫っぽい
  }
  
  for(int i=0; i<N; i++){
    for(int sum_v=0; sum_v<=max_v; sum_v++){
      if(sum_v<=v[i])
        chmin(dp[i+1][sum_v], (long long)w[i]); //(long long)に型変換しないとだめっぽい
      /*elseつけないとsum_v<=v[i]の時も処理しちゃって[sum_v-v[i]]が範囲外アクセスになる*/
      else
        chmin(dp[i+1][sum_v], dp[i][sum_v-v[i]]+w[i]);
      chmin(dp[i+1][sum_v], dp[i][sum_v]);
    }
  }
  
  for(int i=0; i<=max_v; i++){//dp[N][max_v]は価値最大の時で重さの総和入ってるはずだから、
    if(dp[N][max_v-i]<=W){ //必要な重さがW以下のを探す
      cout << max_v-i << endl; //最初にそうなった時の横軸(=価値)が求める値
      break;
    }
  }
}



Measured memory_bytes: 82424
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    int N, K;
    readlnTo(N, K);
    auto a = readLongs();
    long ans = long.min;
    long[] t = [0];
    foreach(i; iota(N)) {
        t ~= t.back + max(a[i], 0);
    }
    long S;
    foreach(i; iota(K)){ 
        S += a[i];
    }
    foreach(i; iota(N-K+1)) {
        ans = max(ans, t[i] + max(S, 0) + t.back - t[i+K]);
        if(i < N-K) {
            S = S - a[i] + a[i+K];
        }
    }
    writeln(ans);
}



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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

const double PI = 3.14159265359;
const int INF = (int)1e9;
const ll LINF = 1e18;
const int IMOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

int main(void)
{
    ll a, b, c;
    cin >> a >> b >> c;

    ll d = c-a-b;
    string ans;
    if(d < 0) {
        ans = "No";
    } else {
        if(d*d > 4*a*b) {
            ans = "Yes";
        } else {
            ans = "No";
        }
    }
    cout << ans << endl;    
    return 0;
}
/** atcoder **/



Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		ll ans=0;
		REP(i, N) if((i+1)%2==1 && A[i]%2==1) ans++;
		cout<<ans<<endl;
	}
	
	return 0;
}


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

int h, w;
string ma[101];

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        cin >> ma[i];
    }

    bool r_rm[101] = {0, };
    for (int i = 0; i < h; i++) {
        bool white = true;
        for (int j = 0; j < w; j++) {
            if (ma[i][j] == '#') {
                white = false;
                break;
            }
        }
        if (white) {
            r_rm[i] = true;
        }
    }

    vector<string> n_ma;
    for (int i = 0; i < h; i++) {
        if (r_rm[i]) continue;
        n_ma.push_back(ma[i]);
    }

//    for (auto it : n_ma) cout << it << '\n';

    bool c_rm[101] = {0, };
    for (int j = 0; j < w; j++) {
        bool white = true;
        for (int i = 0; i < n_ma.size(); i++) {
            if (n_ma[i][j] == '#') {
                white = false;
                break;
            }
        }
        if (white) {
            c_rm[j] = true;
        }
    }

    for (int i = 0; i < n_ma.size(); i++) {
        for (int j = 0; j < w; j++) {
            if (c_rm[j]) continue;
            cout << n_ma[i][j];
        }
        cout << '\n';
    }


    return 0;
}


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

using LL = long long;

int main() {
  LL N, A, B;
  cin >> N >> A >> B;
  vector<LL> H(N);
  for(auto& i: H) cin >> i;

  auto ok=[&](LL x) {
    auto a=0ll;
    for(auto h: H) {
      if(h <= x*B)continue;
      if((x-a)*A + a*B < h) return false;
      auto t = (h-x*B)/(A-B);
      if(t*A + (x-t)*B < h) ++t;
      a += t;
      if(x<a) return false;
    }
    return true;
  };

  LL low=0, high=1e9;
  while(low+1<high) {
    auto middle = (low+high) / 2;
    if(ok(middle)) high=middle;
    else           low=middle;
  }
  cout << high << endl;
}


Measured memory_bytes: 1024