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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

string s;

void jump(const int i, const int j, VI& A)
{
    A[i] = 1;
    FOR(x,i,j) if (A[x]) {
        FOR(d,1,3) if (x+d <= j && s[x+d] != '#') {
            A[x+d] = 1;
        }
    }
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n,a,b,c,d; 
    while (cin >> n >> a >> b >> c >> d >> s) {
        s = ' ' + s;
        {
            bool ans = true;
            FOR(i,a,c) if (s[i-1] == '#' && s[i] == '#')
                ans = false;
            FOR(i,b,d) if (s[i-1] == '#' && s[i] == '#')
                ans = false;
            if (ans && c > d) {
                ans = false;
                FOR(i,b,d+1)
                    if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.')
                        ans = true;
            }
            cout << (ans ? "Yes" : "No") << endl;
        }
        continue;
        {
            VI A(n+1), B(n+1);
            jump(a,c,A);
            jump(b,d,B);
            bool ans = A[c] && B[d];
            if (ans && c > d) {
                ans = false;
                FOR(i,1,n+1)
                    ans |= A[i-1] && B[i] && A[i+1];
            }
            cout << (ans ? "Yes" : "No") << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 720
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fill(x,c) memset(x,c,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int SIZE = 1e6+10;
ll a[SIZE];
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n,p,l;
	cin>>n;
	vector<pair<ll,ll>> r;
	rep(i,0,n){
		cin>>p>>l;
		r.pb({p+l,p-l});
	}
	sort(r.begin(),r.end());
	ll end = r[0].fi;
	ll ans=1;
	//贪心算法 
	rep(i,1,r.size()){
		if(r[i].se>=end){
			ans++;
			end = r[i].fi;
		}
	}
	cout<<ans;
  	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int takahashi=0;
    int aoki=0;
    while(a>0){
        takahashi++;
        a=a-d;
    }
    while(c>0){
        aoki++;
        c=c-b;
    }
    if(takahashi>=aoki){
        cout<<"Yes"<<endl;
    }
    else if(aoki>takahashi){
        cout<<"No"<<endl;
    }
}


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

#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

int main()
{
    
   int n,m;
   cin>>n>>m;
   vector<pair<int,int>> all;
   REP(i,n)
   {
       int a;
       cin>>a;
       all.push_back(make_pair(a,1));
   }
   REP(i,m)
   {
       int b,c;
       cin>>b>>c;
       all.push_back(make_pair(c,b));
   }
   sort(all.begin(),all.end(),greater<pair<int,int>>());
   int64_t ans=0;
   int i=0;
   while(n)
   {
       int64_t k=min(n,all.at(i).second);
       ans+=k*all.at(i).first;
       n-=k;
       i++;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 2420
//C - One-stroke Path: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int n, m, x, y;
int ans = 0;

void dfs(int no, vector<bool> vis, int total, vector<int> adj[]) {
    if(vis[no]) return;
    if(total == n-1) ans++;
    vis[no] = true;
    for(auto x: adj[no]) {
        dfs(x, vis, total+1, adj);
    }
} 

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> n >> m;
    vector<int> adj[n+1];
    loop(i, 0, m) {
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    vector<bool> vis(n+1, false);
    dfs(1, vis, 0, adj);
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/

int main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    while(true){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int n, m;

    while (cin >> n >> m)
    {
        int mp[101] = {0};
        if (n == 0 && m == 0)
            break;
        int a, b;
        rep(i, n)
        {
            cin >> a >> b;
            mp[a] = max(mp[a], b);
        }
        int ans = 0;
        rep(i, 101)
        {
            if (mp[i] != 0)
                ans += mp[i];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3068
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			m = scanner.nextInt();
			n = scanner.nextInt();
			if ((m | n) == 0)
				break;
			map = new int[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					map[i][j] = scanner.nextInt();
				}
			}
			count = 0;
			for (int i = 0; i < m; i++) {
				slove(i, 0, 0);
			}
			System.out.println(count);
		}
	}

	private void slove(int x, int y, int r) {
		if (y == n) {
			count++;
			return;
		}
		if (x < 0 || x == m)
			return;

		if (map[y][x] == 1)
			return;
		if (map[y][x] == 2 && r != 1)
			return;

		if (y == n - 1) {
			count++;
			return;
		}
		if (map[y][x] == 2)
			slove(x, y + 2, 1);
		else
			for (int i = 0; i < 3; i++) {
				slove(x + i - 1, y + 1, i);
			}
	}

	int count;
	int m;
	int n;
	int[][] map;
}

Measured memory_bytes: 24312
#include<bits/stdc++.h>
#define int long long

using namespace std ;


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ;

    char c ;

    cin >> c ;
    if(c>= 'A' && c <='Z')
    {
        cout << "A" <<endl;
    }
    else{cout <<"a"<<endl ;}


}


Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanNumber = new Scanner(System.in);

        String S = scanNumber.next();

        String T = scanNumber.next();

        scanNumber.close();

        char[] charS = S.toCharArray();
        char[] charSalfa = S.toCharArray();
        char[] charT = T.toCharArray();

        String answer = "No";

        char work = ' ';

        for(int i = 0; i < T.length() ; i++){
            work = charS[0];
            for(int j=0; j<T.length()-1 ; j++){
                charS[j] = charS[j + 1];
            }
            charS[T.length() -1] = work;
            if(Arrays.equals(charS, charT)){
                answer = "Yes";
                break;
            }

        }

        System.out.print(answer);

    }
}


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

int n, tmax = 0, d = 0;
int t[100000];
vector<int> dd;

int main()
{	
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> t[i];
		if (t[i] > tmax)
			tmax = t[i];
	}

	for (int i = 1; i <= tmax; i++) {
		if (tmax % i == 0)
			dd.push_back(i);
	}

	for (int i = 0; i < n; i++) {
		vector<int>::iterator itr = dd.begin();
		while (*itr < t[i])
			itr++;
		d += *itr - t[i];
	}

	cout << d << endl;

	return 0;
}



Measured memory_bytes: 3500
#include <bits/stdc++.h>
 
#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))
 
using namespace std;
 
typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
 
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = INT_MAX / 2;
 
string S;
 
string solve() {
	reverse(all(S));
	int i = 0;
	string s;
	while (i < S.size()) {
		if (S[i] == 'm') {
			s += "maerd";
			i += 5;
		} else if (S[i] == 'e') {
			s += "esare";
			i += 5;
		} else if (S[i] == 'r') {
			if (i + 6 < S.size() && S[i + 6] == 'd') {
				s += "remaerd";
				i += 7;
			} else {
				s += "resare";
				i += 6;
			}
		} else {
			return "NO";
		}
	}
	return (s == S? "YES" : "NO");
}
 
int main(){
	cin >> S;
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) ((a>b)?a:b);
#define min(a,b) ((b>a)?a:b);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert                                                                      //copy NUL check.cpp
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ 1ad.cpp -o 1ad.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 




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

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

int main() {
    string S; cin >> S;
    int ans = -1;
    int cnt = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T') {
            cnt++;
        } else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    // ループの最後を考慮
    if (cnt > 0) ans = max(ans, cnt);
    cout << ans << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn min (a: &i64, b: &i64)-> i64{
    if *a <= 0i64 {*b}
    else if *b <= 0i64  {*a}
    else if *a < *b {*a}
    else {*b}
}

fn max (a: &i64, b:&i64) -> i64{
    if *a < *b {*b} else {*a}
}

fn abs (a: &i64, b: &i64) -> i64{
    if *a - *b <= 0 {*b - *a} else {*a - *b}
}

fn main(){
    input!{
        n: usize,
        a: [usize; n]
    }
    let mut result = 0;
    for i in a.iter(){
        let mut h = *i;
        while h % 2 == 0{
            result += 1;
            h /= 2;
        }
    }
    print!("{}", result);
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

typedef long long ll;

inline ll read()
{
	ll x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

const int N=1e5+9;

ll n,k,sum;
ll a[N],d[N];

int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		sum+=(a[i]=read());
	k=sum/(n*(n+1)/2);
	if(sum%(n*(n+1)/2)!=0)
	{
		puts("NO");
		return 0;
	}

	for(int i=1;i<n;i++)
		d[i]=a[i+1]-a[i];
	d[n]=a[1]-a[n];
	for(int i=1;i<=n;i++)
		if((k-d[i])%n!=0 || k-d[i]<0)
		{
			puts("NO");
			return 0;
		}
	puts("YES");

	return 0;
}


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

typedef long long ll;
typedef long double ld;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll n, m, i, j, k;
        cin >> n;
        bool ok = 1;
        for (i = 0; i < n; i++)
        {
            cin >> j;
            if (j % 2 == 0)
                if (j % 3 != 0 && j % 5 != 0)
                {
                    cout << "DENIED\n";
                    ok = 0;
                    break;
                }
        }
        if (ok)
            cout << "APPROVED\n";
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e2 + 5, M = 2 * N + 5;

int main(){
    int n;
    scanf("%d", &n);
    printf("%d\n", n * (n + 1) / 2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;	// 998244353
using ll = long long;
using namespace std;

const int bound = 1e5+10;

int memo[bound];
bool visited[bound];

vector<int> h;

int f( int x ){
	if( visited[x] ) return memo[x];
	visited[x] = true; 
	int ans = inf;
	if( x-1 >= 0 ) ans = min( ans, f(x-1)+abs(h[x]-h[x-1]) );
	if( x-2 >= 0 ) ans = min( ans, f(x-2)+abs(h[x]-h[x-2]) );
	return memo[x] = ans;
}

int main(){
	int n; cin >> n;
	h.resize(n);
	visited[0] = true;
	for( auto &k : h ) cin >> k;
	cout << f(n-1) << endl;
}

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

int main() {
	int64_t x, y;
	cin >> x >> y;
	if (x == y || y == 1 || x % y == 0) {
		cout << -1 << endl;
		return 0;
	}
	cout << x << endl;
	return 0;
}

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

#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pair<int,int>>
#define mi          map<int,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(i=a;i<b;i++)
#define inf         INT_MAX
#define llinf       LLONG_MAX


template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }

using namespace std;
void solve()
{
    int n;
    cin>>n;
    if(n)cout<<0;
    else cout<<1;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#define MAX_N 100
using namespace std;
int A[MAX_N];


int main(){
  int N,M,count=0,sum=0;
  cin >> N >> M;
  float th;
  th = 1.0/(4*M);
  for(int i=0;i<N;i++){
    cin >> A[i];
    sum += A[i];
  }

  //cout << th << endl;
  for(int i=0;i<N;i++){
    //cout << (float)A[i]/(float)sum << endl;
    
    if((float)A[i]/(float)sum >= th){
      count++;
    }
  }
  
  if(count >= M){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
r,d,x=map(int,input().split())
num1=r*x-d
num2=num1*r-d
num3=num2*r-d
num4=num3*r-d
num5=num4*r-d
num6=num5*r-d
num7=num6*r-d
num8=num7*r-d
num9=num8*r-d
num10=num9*r-d
print(num1)
print(num2)
print(num3)
print(num4)
print(num5)
print(num6)
print(num7)
print(num8)
print(num9)
print(num10)

Measured memory_bytes: 3064
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        a_s: [i64; n],
    }
    // (2 - (b + 1)).abs() + (2 - (b + 2)).abs() + (3 - (b + 3)).abs() + (5 - (b + 4)).abs() + (5 - (b + 5)).abs()
    // (2 - (b + 1)).abs(): -2 => 3, -1 => 2, 0 => 1, 1 => 0, 2 => 1   min: a - i = 1
    // (2 - (b + 2)).abs(): -2 => 2, -1 => 1, 0 => 0, 1 => 1, 2 => 2   min: a - i = 0
    // (3 - (b + 3)).abs(): -2 => 2, -1 => 1, 0 => 0, 1 => 1, 2 => 2   min: a - i = 0
    // (5 - (b + 4)).abs(): -2 => 3, -1 => 2, 0 => 1, 1 => 0, 2 => 1   min: a - i = 1
    // (5 - (b + 5)).abs(): -2 => 2, -1 => 1, 0 => 0, 1 => 1, 2 => 2   min: a - i = 0
    let mut mins = a_s
        .iter()
        .enumerate()
        .map(|(i, a)| a - (i as i64 + 1))
        .collect::<Vec<_>>();
    mins.sort();
    let mid = mins[n / 2];
    let bs = [mid.saturating_sub(1), mid, mid + 1];
    let ans = bs
        .iter()
        .map(|b| {
            a_s.iter()
                .enumerate()
                .map(|(i, a)| (a - (b + i as i64 + 1)).abs())
                .sum::<i64>()
        })
        .min()
        .unwrap();
    println!("{}", ans);
}


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

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

	int mdif = -1;
	for(int i=0;i<n;i++){
		if(i ==n-1)mdif= max(mdif,a[0]+k-a[n-1]);
		else mdif = max(mdif,a[i+1]-a[i]);
	}
	cout << k-mdif << endl;

	return 0;
}

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

int main()
{
  string s,t;
  cin >> s >> t;
  int a = t.size();
  s += t.at(a-1);
  if(s == t) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main() {
    int64_t n;
    cin >> n;

    int i;
    int a, b;
    for(i = sqrt(n); i > 0; i--) {
        if (n % i == 0) {
            a = i;
            b = n / i;
            break;
        }
    }

    int ans = 0, tmp = 0;
    for(i = a; i > 0; i /= 10) {
        ans++;
    }
    for(i = b; i > 0; i /= 10) {
        tmp++;
    }
    cout << max(ans, tmp) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< double,double> dd;
#define pb push_back
#define eb emplace_back
#define sz(a) (int)a.size()
#define all(c) c.begin(),c.end()
#define FOR(i,a,b) for(i=a; i<b; i++)
#define FORR(i,a,b) for(i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define x first
#define y second
#define mp make_pair

const int INF = 1000000007;
const long long INFLL = (ll)INF * (ll)INF;

int32_t main()
{
	IOS;
	string s,t;
	int count=0;
	cin>>s>>t;
	for(int i=0;i<(int)s.length();i++)
	{
		if(s[i]!=t[i])
		count++;
	}
	cout<<count;
	return 0;
}


Measured memory_bytes: 3884
words = lambda t : list(map(t, input().split()))
n = int(input())
a = input()

d = {}
r_nums = [0] * 10
for i in range(1,n):
    r_nums[int(a[i])] += 1
l_nums = [0] * 10

for i in range(1,n-1):
    center = int(a[i])
    r_nums[int(a[i])] -= 1
    l_nums[int(a[i-1])] += 1
    #print(l_nums, center, r_nums)
    for j in range(10):
        for k in range(10):
            if r_nums[j] > 0 and l_nums[k] > 0:
                d[k*100 + center*10 + j] = 1
    #print(d)
print(len(d))


Measured memory_bytes: 43756
/**
 * Heaps - Maximum Heap
 */

#include <iostream>

using namespace std;

int H, A[500001];

void heapfy(int *a, int i) {

    int l, r;
    l = i * 2;
    r = i * 2 + 1;

    int i_ = i;

    if (l <= H && a[l] > a[i]) i_ = l;
    if (r <= H && a[r] > a[i_]) i_ = r;

    if (i_ != i) {
        int tmp = a[i];
        a[i] = a[i_];
        a[i_] = tmp;
        heapfy(a, i_);
    }
}

int main() {

    cin >> H;

    for (int i = 1; i <= H; i++) {
        cin >> A[i];
    }

    for (int i = H / 2; i >= 1; i--) {
        heapfy(A, i);
    }

    for (int i = 1; i <= H; i++) {
        cout << " " << A[i];
    }
    cout << endl;
}


Measured memory_bytes: 5016
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
// const int N = ;
#define singleCase
// #define multipleCase
int a,b,c;

void work() {
   in(a); in(b); in(c);
   int mini = min(a , c);
   a -= mini, c -= mini;
   int sol = mini;
   if (c > 0) {
      mini = min(b , c);
      sol += 2 * mini;
      b -= mini, c -= mini;
      sol += (c > 0) + b;
   } else {
      sol += b;
   }
   printf("%d\n" , sol);
   return;
}

int main() {
   #ifdef multipleCase
      int nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   return 0;
}

void in(int &x) {
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-') {
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	  x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 3696
#include <iostream>
#include <set>

using namespace std;

int N,M;
set<int> s[200000];

int main(){
    int a,b;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        cin >> a >> b;
        s[a-1].insert(b-1);
        s[b-1].insert(a-1);
    }
    for(auto x : s[0]){
        for(auto y : s[x]){
            if(y == N-1){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

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

using namespace std;

int main(){

   int n;
   vector<int> Rt;
   int ans;

   cin >> n;

   for(int i = 0; i < n; i++){
      int r;
      cin >> r;
      Rt.push_back(r);
   }
   
   int min = Rt[0];
   ans = Rt[1] - Rt[0];

   for(int i = 1; i < n; i++){
      if(ans < Rt[i] - min){
         ans = Rt[i] - min;
      }
      if(min > Rt[i]){
         min = Rt[i];
      }
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int a,b; cin>>a>>b;
  COUT( (b-1) / (a-1) + ( (b-1) % (a-1) > 0));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 81
#define pii pair<int, int>
#define pb push_back
#define inf 1e18
#define fi first
#define se second
#define mt make_tuple
typedef long long ll;

using namespace std;

int n, m, a[MAXN][MAXN];
bool s[MAXN][MAXN][81 * 81 * 2];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            int t;
            cin >> t;
            a[i][j] -= t;
            a[i][j] = abs(a[i][j]);
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(i == j and i == 0){
                s[i][j][a[i][j]] = 1;
                continue;
            } 
            if(j){
                for(int k = 0; k < 81 * 81 * 2; k++){
                    if(s[i][j - 1][k]){
                        s[i][j][abs(k + a[i][j])] = 1;
                        s[i][j][abs(k - a[i][j])] = 1;
                    } 
                } 
            }
            if(i){
                for(int k = 0; k < 81 * 81 * 2; k++){
                    if(s[i - 1][j][k]){
                        s[i][j][abs(k + a[i][j])] = 1;
                        s[i][j][abs(k - a[i][j])] = 1;
                    } 
                } 
            }
        }
    }
    int ans = 1e9;
    for(int k = 0; k < 81 * 81 * 2; k++){
        if(s[n - 1][m - 1][k]){
            ans = k;
            break;
        }
    }
    cout << ans;
}

Measured memory_bytes: 83456
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

#define NUM_MAX 100

enum type {
    TYPE_WHITE = '.',
    TYPE_BLACK = '#',
};

int main(void) {
    int whites, blacks;
    get_int2(&whites, &blacks);
    static char map[NUM_MAX][NUM_MAX];
    whites--; blacks--;
    memset(map, TYPE_WHITE, NUM_MAX*NUM_MAX);
    memset(map, TYPE_BLACK, NUM_MAX*(NUM_MAX/2));

    int row, col;
white_dot:
    for(row = 0; row < (NUM_MAX/2)-1; row+=2) {
        for(col = 0; col < NUM_MAX; col+=2) {
            if(whites<=0) goto black_dot;
            map[row][col] = TYPE_WHITE;
            whites--;
        }
    }

black_dot:
    for(row = (NUM_MAX/2)+1; row < NUM_MAX; row+=2) {
        for(col = 0; col < NUM_MAX; col+=2) {
            if(blacks<=0) break;
            map[row][col] = TYPE_BLACK;
            blacks--;
        }
    }

    printf("%d %d\n", NUM_MAX, NUM_MAX);
    for(row = 0; row < NUM_MAX; row++) {
        for(col = 0; col < NUM_MAX; col++) {
            putchar(map[row][col]);
        }
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String a;
        String b;
        int count = 0;

        Scanner sc = new Scanner(System.in);
        a = sc.next();
        b = sc.next();
        String new_b = "";
        new_b = b.substring(0,a.length());
        if(a.equals(new_b))
        {
            System.out.println("Yes");
        }
        else System.out.println("No");
    }
}


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

int main(){
    int k,a,b;
    cin >> k>>a>>b;
    
    bool flag = false;
    
    for(int i=a;i<=b;i++){
        if(i%k == 0){
            flag = true;
        }
    }
    
    if(flag){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
}

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

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0

int n,m,z;
int edge[64][64];
int edge2[200][200];
vector<pair<int,int> > v;


vector<vector<int> > calc(vector<vector<int> > a, vector<vector<int> > b){
	vector<vector<int> > ret(a.size());
	int sz = a.size();
	rep(i,sz){
		rep(j,sz){
			int sum = 0;
			rep(k,sz){
				sum |= a[i][k]*b[k][j];
			}
			ret[i].pb(sum);
		}
	}
	return ret;
}

vector<vector<int> > multi(vector<vector<int> >& matrix, int k){
	if( k==1 ) return matrix;

	vector<vector<int> > tmp = multi(matrix,k/2);
	if( k%2 ){
		return calc(matrix,calc(tmp,tmp));
	}else{
		return calc(tmp,tmp);
	}
}

int main(){

	while(scanf(" %d%d%d ",&n,&m,&z),n|m|z){
#if DEB
		printf("n,m,z:%d,%d,%d\n",n,m,z);
#endif
		rep(i,64)rep(j,64)edge[i][j]=0;
		rep(i,200)rep(j,200)edge2[i][j]=0;
		
		v.clear();
		rep(i,m){
			int s,d; scanf("%d%d",&s,&d);
			edge[s][d] = edge[d][s] = 1;
		}
		REP(i,1,n+1)edge[i][i]=1;
		
		REP(i,1,n+1){
			REP(j,1,n+1)if( edge[j][i]==1 ){
				v.pb(mp(i-1,j-1));
			}
		}
#if DEB
		rep(i,v.size()){
			printf("(%d,%d)\n",v[i].first,v[i].second);
		}
#endif
		rep(i,v.size()){
			rep(j,v.size()){
				if( v[i].first!=v[j].first && v[i].first==v[j].second && v[i].second!=v[j].first ){
					edge2[i][j] = 1;
				}
			}
		}
#if DEB
		printf("v_size:%d\n",v.size());
#endif
		
		vector<vector<int> > mat(v.size());
		rep(i,v.size()){
			rep(j,v.size()){
				mat[i].pb(edge2[i][j]);
			}
		}

		
#if DEB

		printf("h:%d  , w:%d\n",mat.size(),mat[0].size());
		rep(i,mat.size()){
			rep(j,mat[i].size()){
				printf("%d ",mat[i][j]);
			}
			puts("");
		}
#endif

		vector<vector<int> > hoge = multi(mat,z);

#if DEB
		printf("z:%d\n",z);
		rep(i,hoge.size()){
			rep(j,hoge[i].size()){
				printf("%d ",hoge[i][j]);
			}
			puts("");
		}
#endif

		bool f = false;
		rep(i,v.size())if( v[i].first==n-1 ){
			if( hoge[0][i]>0 ){
				f = true;
				break;
			}
		}
		puts(f?"yes":"no");
	}
	return 0;
}

Measured memory_bytes: 1952
#include<stdio.h>
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int h[n];
	int flag[n];
	for(int i=1;i<=n;i++){
	scanf("%d",&h[i]);
	flag[i]=1;
	}
	for(int i=1;i<=m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		if(h[a]>=h[b]){
			flag[b]=0;
		}
		if(h[a]<=h[b])
		flag[a]=0;
	}
	int count=0;
	for(int i=1;i<=n;i++){
		if(flag[i]==1)
		count++;
	}
	printf("%d",count);
}

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

int main() {
  int N;
  cin >> N;
  bool answer = false;
  
  for(int i=0; i <= N/4; i++) {
    for(int j=0; j <= N/7; j++) {
     if(4*i + 7*j == N) answer = true;
    }
  }
  if(answer == true)  cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    char s[3];
    while(cin>>s){
        int cnt=0;
        for(int i=0;i<3;i++){
            if(s[i]=='1')cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int n, i, c[52] = { 0 }, j, d, l;
	char k[2];
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%s %d", k, &j);
		switch(k[0]) {
			case 'S':
				c[j - 1]++;
				break;
			case 'H':
				c[j + 12]++;
				break;
			case 'C':
				c[j + 25]++;
				break;
			case 'D':
				c[j + 38]++;
		}
	}
	for (i = 0; i < 52; ++i) {
		d = i / 13;
		l = i + 1 - (d * 13);
		if(!c[i]) {
			switch(d) {
				case 0:
					printf("S %d\n", l);
					break;
				case 1:
					printf("H %d\n", l);
					break;
				case 2:
					printf("C %d\n", l);
					break;
				case 3:
					printf("D %d\n", l);
			}	
		}
		
	}
	return 0;
}



Measured memory_bytes: 2104
// Aizu Vol-2 0287: Jinkoki
// 2017.8.10

#include <stdio.h>

#define N       10000
#define SIZE    25

void mpMul(int *ret, int *a, int *b);
void mpPow(int *ret, int *a, int *b);

char *unit[19] = { 0, "\0", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan",
"Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts" };

int mm[SIZE], nn[SIZE], ans[SIZE];

int main()
{
	int m, n;
	int i, j;
	int *p;
	char b[10], *q;

	while (1) {
		scanf("%d%d", &m, &n); if (m == 0) break;
		mm[0] = 1, mm[1] = m;
		nn[0] = 1, nn[1] = n;
		mpPow(ans, mm, nn);

		p = ans;
		if (*p == 0 || (*p == 1 && *(p + 1) == 0)) { putchar('0'), putchar('\n'); continue; }
		for (i = ans[0], p = ans + i; i >= 1; i--, p--) {
			int x = *p;
			if (x == 0) continue;
			for (q = b+5, *q = 0, j = 0; j < 4 && x > 0; j++) *--q = x % 10 + '0', x /= 10;
			printf("%s%s", q, unit[i]);
		}
		putchar('\n');
	}
	return 0;
}

void mpPow(int *ret, int *a, int *b)
{
	int i, len, cur;
	unsigned k, bit;
	static int tmp[2][SIZE];

	if (*b == 0 || (*b == 1 && *(b + 1) == 0) || (*a == 1 && *(a + 1) == 1)) { *ret = 1, *(ret + 1) = 1; return; }
	if (*b == 1 && *(b + 1) == 1) {
		for (i = 0, len = *a; i <= len; i++) *ret++ = *a++;
		return;
	}
	k = *(b + 1), tmp[0][0] = 1, tmp[0][1] = 1, cur = 0;
	for (bit = 0x10000; bit > 0; bit >>= 1) {
		if (tmp[cur][0] > 1 || tmp[cur][1] > 1) mpMul(tmp[!cur], tmp[cur], tmp[cur]), cur = !cur;
		if (k & bit) mpMul(tmp[!cur], tmp[cur], a), cur = !cur;
	}
	for (i = 0, len = tmp[cur][0]; i <= len; i++) *ret++ = tmp[cur][i];
}

void mpMul(int *ret, int *a, int *b)
{
	int  i, j, la, lb, ca;
	int  *aa;
	long long x;

	la = *a, lb = *b;
	if (la == 0 || lb == 0) { *ret = 0;	return;	}
	for (i = la + lb; i > 0; i--) *(ret + i) = 0;
	for (j = 1; j <= lb; j++) {
		ca = 0, b++;
		for (i = 1, aa = a; i <= la; i++) {
			x = *++aa;
			x = x * *b + *(ret + i + j - 1) + ca;
			*(ret + i + j - 1) = x % N;
			ca = (int)(x / N);
		}
		*(ret + i + j - 1) = ca;
	}
	*ret = (ca != 0) ? la + lb : la + lb - 1;
}

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

int main() {
  int N,M;
  cin>>N>>M;
  
  if ((N==0)&&(M==0))
    cout<<0<<endl;
  if ((N==0)&&(M!=0))
    cout<<M*(M-1)/2<<endl;
  if ((N!=0)&&(M==0))
    cout<<N*(N-1)/2<<endl;
  if ((N!=0)&&(M!=0))
    cout<<N*(N-1)/2+M*(M-1)/2<<endl;
      
}


Measured memory_bytes: 256
//https://www.hamayanhamayan.com/entry/2020/05/03/224516
#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>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int N, A, B, C;
string S[101010];
//---------------------------------------------------------------------------------------------------
vector<char> ans;
bool dfs(int cu, int a, int b, int c) {
    if (cu == N) return true;

    if (S[cu] == "AB") {
        if (a == 0 && b == 0) return false;
        if (0 < a && dfs(cu + 1, a - 1, b + 1, c)) {
            ans.push_back('B');
            return true;
        }
        if (0 < b && dfs(cu + 1, a + 1, b - 1, c)) {
            ans.push_back('A');
            return true;
        }
        return false;
    }

    if (S[cu] == "AC") {
        if (a == 0 && c == 0) return false;
        if (0 < a && dfs(cu + 1, a - 1, b, c + 1)) {
            ans.push_back('C');
            return true;
        }
        if (0 < c && dfs(cu + 1, a + 1, b, c - 1)) {
            ans.push_back('A');
            return true;
        }
        return false;
    }

    if (S[cu] == "BC") {
        if (b == 0 && c == 0) return false;
        if (0 < b && dfs(cu + 1, a, b - 1, c + 1)) {
            ans.push_back('C');
            return true;
        }
        if (0 < c && dfs(cu + 1, a, b + 1, c - 1)) {
            ans.push_back('B');
            return true;
        }
        return false;
    }
}
//---------------------------------------------------------------------------------------------------
int main() {
    cin >> N >> A >> B >> C;
    rep(i, N) cin >> S[i];

    dfs(0, A, B, C);

    if (ans.size() == 0) cout << "No" << endl;
    else {
        printf("Yes\n");
        reverse(ans.begin(),ans.end());
        for(char c: ans) printf("%c\n", c);
    }
    return 0;
}

Measured memory_bytes: 14856
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N;
    cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    int max = 0, next_max = 0;
    for(int i = 0; i < N; i++){
        if(max <= a[i]){
            next_max = max;
            max = a[i];
        }else{
            if(next_max < a[i] && max > a[i]){
                next_max = a[i];
            }
        }
    }

    rep(i, N){
        if(a[i] == max){
            cout << next_max << endl;
        }else{
            cout << max << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const LL MOD = 1000000007;

template<typename T>
void dump(T a, int n) { for (int i = 0; i < n; i++) cout << a[i] << (i == n - 1 ? '\n' : ' '); }

template<typename T>
void dump(T a) { dump<T>(a, a.size()); }

int main(void) {
	for (int N, K, M; cin >> N >> K >> M, N;) {
		VI a(N);
		iota(a.begin(), a.end(), 1);
		int i = (M - 1) % N;
		while (N > 1) {
			auto rm = a.begin() + i;
			a.erase(rm);
			N--;
			(i += K - 1) %= N;
		}
		cout << a[0] << endl;
	}

	return 0;
}

Measured memory_bytes: 1252
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, nl, nr, i, j, max, q, count, d;
    int[] c;
    String s;

    for(q = sc.nextInt();q-- > 0;out.println(count)){
      n = sc.nextInt(); max = 0;
      for(count = -1;max != -1;count++){
        d = caldig(n);
        j = 10; max = -1;
        for(i = 1;i < d;i++){
          nr = n % j; nl = n / j;
          if(max < nr * nl)max = nr * nl;
          j *= 10;
        }
        n = max;
      }
    }

    sc.close();
  }
  private static int caldig(int n){
    int i;
    for(i = 1;i < 10;i++){
      if(n / 10 == 0)return i;
      n = n / 10;
    }
    return 0;
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 26612
#include<stdio.h>
int main(void)
{
	int n,x,y,b,p,i;
	int a,z;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&x,&y,&b,&p);
		a=(x*b)+(y*p);
		if(b<5)	b=5;
		if(p<2)	p=2;
		z=((x*b)+(y*p))*8/10;
		if(a<z)	printf("%d\n",a);
		else if(a>z)	printf("%d\n",z);
		else	printf("%d\n",a);
	}
	return 0;
}



Measured memory_bytes: 2740
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
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 LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out





int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    ll i,n;
    ll sum=0,ans=0,minans;
    cin>>n;
    vector<ll> v(n+10,0),w(n,0);
    rep(i,n){
        cin>>v[i];
    }
    
    int s;
    for(i=0,s=1;i<n;i++,s*=-1){
        sum+=v[i];
        if(sum*s<=0) ans+=abs(sum-s),sum=s;
    }
    
    minans=ans;
    ans=0;
    sum=0;
    for(i=0,s=-1;i<n;i++,s*=-1){
        sum+=v[i];
        if(sum*s<=0) ans+=abs(sum-s),sum=s;
    }
    
    minans=min(ans,minans);
    cout<<minans<<endl;

//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std;

int main()
{
    bool is_leap[3000] = {};
    for( int i=1; i<3000; ++i ) {
        if ( i % 4 == 0 ) {
            if ( i % 100 == 0 ) {
                if ( i % 400 == 0 ) {
                    is_leap[i] = true;
                }
            } else {
                is_leap[i] = true;
            }
        }
    }

    int a, b;
    bool d=false;
    while( cin >> a >> b, a||b ) {
        vector<int> v;
        for( int i=a; i<=b; ++i ) {
            if ( is_leap[i] )
                v.push_back( i );
        }

        if ( d )
            cout << endl;
        else
            d = true;

        if ( v.empty() ) {
            cout << "NA" << endl;
        } else {
            copy( v.cbegin(), v.cend(), ostream_iterator<int>( cout, "\n" ) );
        }
        
    }
}

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

using namespace std;
#define INF 1e12
static const int WHT = 0;
static const int GRY = 1;
static const int BLK = 2;

void dijkstra(  const vector<vector<pair<int,int> > > &adj,
                vector<long> &d,
                vector<int> &color,
                int s)
{
    priority_queue<pair<int,int>,
       std::vector<pair<int,int> >,
       greater<pair<int,int> > > PQ; 
    d[s] = 0;
    PQ.push(make_pair(d[s],s));
    color[s] = GRY;

    while(!PQ.empty()){
        pair<int,int> f = PQ.top();
        int u = f.second;
        PQ.pop();
        color[u] = BLK;

        if(d[u] < f.first) continue;
        for(auto itr = adj[u].begin(); itr != adj[u].end();itr++){
            int v = itr->first;
            if(color[v] != BLK){
                if(d[v] > d[u] + (long)itr->second){
                    d[v] = d[u] + (long)itr->second;
                    color[v] = GRY;
                    PQ.push(make_pair(d[v],v));
                }
            }
        }
    }

    
}

int main()
{
    // ----- Input ----- //
    int V,E,r;
    int s,t,w;

    cin >> V >> E >> r;
    vector<vector<pair<int,int> > > adj(V);
    vector<long> d(V,INF);
    vector<int> color(V,0);
    for(int i = 0;i < E;i++){
        cin >> s >> t >> w;
        adj[s].push_back(make_pair(t,w));
    }
    dijkstra(adj,d,color,r);

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




Measured memory_bytes: 13800