akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll a[3],cnt=0;
    rep(i,3) cin>>a[i];
    rep(i,3){
        while(1){
            if(max({a[0],a[1],a[2]})-a[i]<=1) break;
            a[i]+=2;
            cnt++;
        }
    }
    ll def=0;
    rep(i,3) def+=(a[i]!=max({a[0],a[1],a[2]}));
    if(def==1) cnt+=2;
    if(def==2) cnt++;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
var lines = [];

var readline = require("readline");
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.on('line', function (x) {
  lines.push(x);
});

rl.on('close', function () {
  var N = Number(lines[0]);
  var A = lines[1].split(" ").map(value => Number(value));

  A.sort((a, b) => a - b);
  var min = A[0]; var before_min = -1
  var i = 0;

  while (before_min !== min) {
    for (var i = 0; i < N; i++) {
      before_min = min;

      if (A[i] % min !== 0) { A[i] = A[i] % min }

      min = Math.min(min, A[i]);

    }
  }

  console.log(min);
});


Measured memory_bytes: 27596
/*" بِسْمِ اللهِ الرَّحْمٰنِ الرَّحِيْمِ -In the name of Allah."
   Never stop chasing!-MD.SOURAV.

   ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
   ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
   ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
   [███████████████████].░░░░░░░░░░░░░░
   ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░
*/

#include <bits/stdc++.h>

#define endl "\n"
#define MAX 32000
#define F first
#define S second
#define sz(x) x.size()
#define li long int
#define gcd(a, b) __gcd(a, b)
#define pb push_back
#define mp make_pair
#define asrt(a, n) sort(a, a + n)
#define MOD 1000000007
#define ll long long int
#define lcd(a, b) (a * b) / gcd(a, b)
#define mp(x, y) make_pair(x, y)
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
#define f(i, a, n) for (int i = a; i < n; i++)
#define test  int t;cin >> t;while (t--)
#define srt(v) sort(v.begin(), v.end())
#define basrt(a, n) sort(a, a + n, greater<int>())
#define debug(x) cout << #x << ": " << x << endl;
#define sumof(x) accumulate(x.begin(), x.end(), 0);
#define rsrt(v) sort(v.begin(), v.end(), greater<int>())
#define enter(v, n) for (ll i = 0; i < n; i++) { ll x;cin >> x;v.pb(x);}
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define start  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define ignore cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
#define deb(args...){string _s = #args;replace(_s.begin(), _s.end(), ',', ' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it, args);}

using namespace std;

double pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef map<ll, ll> mllll;
typedef map<char, ll> mchll;
typedef map<string, ll> msll;
typedef vector<pair<ll, ll>> vpllll;
typedef vector<pair<int, int>> vpiiii;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    for (const auto &x : v)
        os << " " << x;
    return os << '}';
}

void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
vector<int>dist(100001,1);
void solve()
{

    ll n,m;
    cin>>n>>m;
    int a,b;
    vector<vector<int>>v(n+1);
    for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
		dist[a]=0;
		dist[b]=0;

	}
	vector<int>road;
	for(int i=1;i<=n;i++)
	{
		  if(dist[i]==0)
		  {
		  	int cnt=0;
		  	dist[i]=1;
		  	queue<int>q;
		  	q.push(i);
		  	while(!q.empty())
			{
				int x=q.front();
				q.pop();
				for(auto &zz:v[x])
				{
					if(dist[zz]==0)
					{
						dist[zz]=1;
						q.push(zz);
						cnt++;
					}
				}

			}
			 road.pb(cnt);
		  }

	}
	ll sum=0;
	for(auto &z:road)
	{
		sum+=z;
	}
	cout << n-1-sum << endl;

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll test_case;
    test_case = 1;
    //cin>>test_case;
    while (test_case--)
    {
        solve();

    }

    return 0;
}

Measured memory_bytes: 9032
#include<cstdio>
int main(){
  int k,s;
  scanf("%d%d",&k,&s);
  int re=(s+2)*(s+1);
  if(k<=s) re-=3*(s-k+1)*(s-k);
  if(2*k<=s) re+=3*(s-2*k)*(s-2*k-1);
  printf("%d\n",re/2);
  return 0;
}


Measured memory_bytes: 256
n , w = map(int, input().split())
val_w = []
for i in range(n):
    a , b = map(int, input().split())
    val_w += [(-a/b, b)]
val_w.sort()
Sum = 0
i = 0
while w and i <= n-1:
    wei = min(w, val_w[i][1])
    Sum += (-val_w[i][0])*wei
    w -= wei
    i += 1
print(Sum)


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

#define int long long

const int N = 1e5 + 10, mod = 1e9 + 7;
int n, k, dp[N], par[N], fac[N], inv[N];
vector <int> adj[N];

int C(int i, int j) {
	return (i > j || i < 0? 0: fac[j] * inv[i] % mod * inv[j - i] % mod);
}

int dfs(int v, int p) {
	int tmp = 1;
	for (int u : adj[v])
		if (u != p)
			dfs(u, v), tmp = (tmp * dp[u]) % mod;
	
	int cnt = 1 + (v > 0), ch = (int)adj[v].size() - (v > 0);
	dp[v] = C(ch, k - cnt) * fac[ch] % mod * tmp % mod;
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	fac[0] = inv[0] = fac[1] = inv[1] = 1;
	for (int i = 2; i < N; i++)
		inv[i] = (-(mod / i) * inv[mod % i] % mod + mod) % mod, fac[i] = (i * fac[i - 1]) % mod;
	for (int i = 2; i < N; i++)
		inv[i] = (inv[i] * inv[i - 1]) % mod;
	
	cin >> n >> k;
	for (int i = 1; i < n; i++) {
		int v, u;
		cin >> v >> u;
		v--; u--;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	dfs(0, 0);
	cout << (dp[0] * k) % mod << endl;
}

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

void solve(string S, ll K){
    for(ll i = 0; i < min((ll)S.size(), K); ++i){
        if(S[i] >= '2'){
            cout << S[i] << endl;
            return;
        }
    }
    cout << '1' << endl;
}

int main(){
    string S;
    ll K;
    cin >> S;
    cin >> K;
    solve(S, K);
    return 0;
}

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

int main(){
    int a,b,c1=0,c2=0,c3=0,c4=0;
    for(int i=0;i<3;i++){
        cin >> a >> b;
        if(a==1)c1++;
        if(a==2)c2++;
        if(a==3)c3++;
        if(a==4)c4++;
        if(b==1)c1++;
        if(b==2)c2++;
        if(b==3)c3++;
        if(b==4)c4++;
    }
    if(c1==1&&c2==2&&c3==2&&c4==1)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    int n;
    cin >> n;
    vector<ll> ini(5,0);
    rep(i,n){
        string s;
        cin >> s;
        if(s[0] == 'M')ini[0]++;
        if(s[0] == 'A')ini[1]++;
        if(s[0] == 'R')ini[2]++;
        if(s[0] == 'C')ini[3]++;
        if(s[0] == 'H')ini[4]++;
    } 
    ll res = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                res += ini[i] * ini[j] * ini[k];
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n);
    REP(i,n) cin >> v[i];
    int m; cin >> m;
    REP(i,m) {
        int a; cin >> a;
        a--;
        if (find(ALL(v),v[a]+1) == v.end() && v[a] != 2019) v[a]++;
    }

    REP(i,v.size()) cout << v[i] << endl;

    return 0;
}


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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

ll n;
vi a;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	n++;
	
	ll ct=1,p2=1;
	for (;2*p2<=n;p2*=2) {
		a.push_back(ct++);
		a.push_back(ct++);
	}
	for (ll i=2;i<ct;i+=2) a.push_back(i);

	ll num;
	for (p2>>=1,num=ct-2;p2;num-=2,p2>>=1) {
		if (p2&n) a.push_back(num);
	}

	cout << a.size() << '\n';
	for (int i=0;i<a.size();i++) {
		if (i) cout << ' ';
		cout << a[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define INF 1e9
using namespace std;
typedef long long ll;

vector<ll> ans(1000000);
vector<queue<int>> ds(1000000);
vector<ll> vs(1000000, 0);

void dfs(int idx, int prv_val){
  int cur_val;
  cur_val = prv_val + vs.at(idx);
  ans.at(idx) = cur_val;
  while(!ds.at(idx).empty()){
    int nxt = ds.at(idx).front();
    dfs(nxt, cur_val);
    ds.at(idx).pop();
  }
}

signed main() {
  // std::ifstream in ("input.txt"); std::cin.rdbuf(in.rdbuf());

  int n, q;
  cin >> n >> q;

  int frm, to;
  REP(i, n - 1){
    cin >> frm >> to;
    ds.at(frm - 1).push(to - 1);
  }

  int p, x;
  REP(i, q){
    cin >> p >> x;
    vs.at(p - 1) += x;
  }
    
  dfs(0, 0);

  cout << ans.at(0);
  REP(i, n - 1){
    cout << " " << ans.at(i + 1) ;
  }
  cout << endl;
}


Measured memory_bytes: 699264
#include <stdio.h>
#define max(a,b) (a)>(b) ? (a):(b);
int n;
int a[100][100];
long psum[100][100][100];
main(){
	int i,j,k,l;
	long maxsum;
	int t1,t2,t3[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			scanf("%d",&a[i][j]);

	maxsum=psum[0][0][0]=a[0][0];
	for(l=1;l<n;l++){
		psum[0][0][l]=psum[0][0][l-1]+a[0][l];
		maxsum=max(maxsum,psum[0][0][l]);
	}

	for(k=1;k<n;k++){
		t1=0;
		for(l=0;l<n;l++){
			psum[0][k][l]=psum[0][k-1][l];
			t1+=a[k][l];
			psum[0][k][l]+=t1;
			maxsum=max(maxsum,psum[0][k][l])
		}
	}

	for(j=1;j<n;j++){
		t1=0;
		for(k=0;k<n;k++){
			t1+=a[k][j-1];
			for(l=j;l<n;l++){
				psum[j][k][l]=psum[j-1][k][l]-t1;
				maxsum=max(maxsum,psum[j][k][l]);
			}
		}
	}

	for(i=1;i<n;i++){
		t1=0;
		t3[0]=a[i-1][0];
		for(l=1;l<n;l++)
			t3[l]=t3[l-1]+a[i-1][l];
		for(j=0;j<n;j++,t1+=a[i-1][j-1]){
			for(k=i;k<n;k++){
				for(l=j;l<n;l++){
					psum[j][k][l]-=t3[l]-t1;
					maxsum=max(maxsum,psum[j][k][l]);
				}
			}
		}
	}

	printf("%d\n",maxsum);
	return 0;
}

Measured memory_bytes: 8452
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int time = sc.nextInt();
        int h, m, s;
        
        h = time / 3600;
        m = (time%3600) / 60;
        s = time % 60;
        System.out.println(h + ":" + m +":" + s);
    }
}


Measured memory_bytes: 26404
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main(){
    string O, E;
    string ans;
    cin >> O;
    cin >> E;

    int O_size = O.size();
    int E_size = E.size();
    REP(i, E_size) {
    	ans += O[i];
    	ans += E[i];
    }
    if (O_size != E_size) ans += O[O_size - 1];

    cout << ans << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;


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

	string s;
	cin >> s;
	N = s.size();
	long long int ans = 0;
	vector<long long int>two(N + 1,1);
	vector<long long int>three(N + 1,1);
	for (int i = 1; i <= N; i++) {
		two[i] = two[i - 1] * 2;
		two[i] %= MOD;
		three[i] = three[i - 1] * 3;
		three[i] %= MOD;
	}
	ans = two[count(s.begin(), s.end(), '1')];
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (s[i] == '0')continue;
		ans += three[N - i - 1] * two[cnt];
		ans %= MOD;
		cnt++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2000
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s;

	cin >> s;
	cout <<
		s[0] <<
		s[1] <<
		s[2] <<
		s[3] <<
		' ' <<
		s[4] <<
		s[5] <<
		s[6] <<
		s[7] <<
		s[8] <<
		s[9] <<
		s[10] <<
		s[11] <<
		"\n";

	return 0;
}


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

int main() {

string s ;
cin >> s ;

int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';

char op1,op2,op3 ;

for(int i=0;i<2;++i)
{
    int tmp = a;
    if(i==0) tmp+=b ;
    if(i==1) tmp-=b ;
    for(int j=0;j<2;++j)
    {
        int tmp2 = tmp ;
        if(j==0) tmp2+=c ;
        if(j==1) tmp2-=c ;
        for(int k=0;k<2;++k)
        {
            int tmp3 = tmp2 ;
            if(k==0) tmp3+=d ;
            if(k==1) tmp3-=d ;
            if(tmp3==7){
                op1 = (i==0) ? '+' : '-' ;
                op2 = (j==0) ? '+' : '-' ;
                op3 = (k==0) ? '+' : '-' ;
                cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl ;
                return 0 ;
            }
        }
    }
}

	return 0;
}



Measured memory_bytes: 256
c = [[int(i) for i in input().split()] for _ in range(3)]
ans = 'Yes'
if not sum(c[0]) % 3 == sum(c[1]) % 3 == sum(c[2]) % 3:
    ans = 'No'
cc = [0, 0, 0]
for ary in c:
    cc[0] += ary[0]
    cc[1] += ary[1]
    cc[2] += ary[2]
if not cc[0] % 3 == cc[1] % 3 == cc[2] % 3:
    ans = 'No'
print(ans)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n,t,q;
ll a[100002],d[100002];
ll x[1002];
ll ne[100002];
ll L,R;
ll ans[1002];
int main(void){
    cin>>n>>t>>q;
    for(int i=0;i<n;i++){
        cin>>a[i]>>d[i];
        if(d[i]==1){
            if(L==100000000) L=i;
        }else{
            for(int j=L;j<i;j++){
                ne[j]=i;
            }
            if(L==100000000){
                ne[i]=ne[i-1];
            }else{
                ne[i]=i-1;
            }
            L=100000000;
        }
        
    }
    for(int i=0;i<q;i++){
        cin>>x[i];
        x[i]--;
    }
    ll A,B;
    for(int i=0;i<q;i++){
        if(d[x[i]]==1){
            A=a[ne[x[i]]],B=a[ne[x[i]]-1];
        }else{
            A=a[ne[x[i]]],B=a[ne[x[i]]+1];
        }
        ll m=(A+B)/2;
        if(abs(m-a[x[i]])>=t){
            if(d[x[i]]==1){
                ans[i]=a[x[i]]+t;
            }else{
                ans[i]=a[x[i]]-t;
            }
        }else{
            ans[i]=m;
        }
    }
    for(int i=0;i<q;i++){
        cout<<ans[i]<<endl;
    }
    
}



Measured memory_bytes: 5452
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
   int n;
   int m;
   cin >> n >> m;
  
   int a[n][2];
 
for(int i = 0;i<n;i++){
  for(int j = 0;j<2;j++){
     

      cin >> a[i][j];
   }
}
  // cout << a[1][1] << endl;
  // cout << a[2][1] << endl;
   
  int mincost = 1001;
  
  for(int i = 0;i<n;i++){
    
     if(a[i][1]<=m){
       if(a[i][0]<=mincost){
         mincost = a[i][0];
       }
     }
    
  }
  
  
  if(mincost==1001){
    cout << "TLE" <<endl;
  }else{
    cout << mincost <<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 100000000;
int n,h;
int memo[10005];
int a[1005], b[1005];
int dp(int x){
    if (x <= 0) return 0;
    if (memo[x] != -1) return memo[x];
    memo[x] = INF;
    for (int i = 0; i < n; i++){
        memo[x] = min(memo[x],dp(x-a[i])+b[i]);
    }
    return memo[x];
}
int main(){
    scanf("%d%d",&h,&n);
    for (int i = 0; i < n; i++){
        scanf("%d%d",&a[i],&b[i]);
    }
    memset(memo,-1,sizeof(memo));
    printf("%d ",dp(h));
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  vector<ll> a(n+1);
  REP(i,n+1) cin>>a[i];
  vector<ll> b(n);
  REP(i,n) cin>>b[i];
  ll sum = 0;
  ll old = 0;
  REP(i,n) {
    if (b[i] + old > a[i]) {
      ll new_old = min(a[i+1], b[i] + old - a[i]);
      sum += new_old + (a[i] - old);
      old = new_old;
    } else {
      old = 0;
      sum += b[i];
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a_c = 0;
    int b_c = 0;
    int ab_c = 0;
    int count = 0;
    for(int i = 0;i < N;i++){
      String str = sc.next();
      int len = str.length();
      if(str.charAt(0) == 'B' && str.charAt(len-1) == 'A')ab_c++;
      else if(str.charAt(0) == 'B')b_c++;
      else if(str.charAt(len-1) == 'A')a_c++;
      if(len == 2&&str.charAt(0) == 'A' && str.charAt(1) == 'B')count++;
      else for(int j = 0;j < len-2;j++)if(str.charAt(j) == 'A' && str.charAt(j+1) == 'B')count++;
    }
    int ans = count;
    if(a_c == 0 && b_c == 0 && ab_c < 2);
    else if(a_c == 0 && b_c == 0 && ab_c > 1)ans += ab_c-1;
    else{
      ans += ab_c-1;
      if(a_c > b_c){
        ans += b_c+1;
      }else{
        ans += a_c+1;
      }
    }
    System.out.println(ans);
  }
}

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

int main(void) {
    char c;
    cin >> c;
    if (c == 'A') cout << "T\n";
    else if (c == 'C') cout << "G\n";
    if (c == 'G') cout << "C\n";
    if (c == 'T') cout << "A\n";
    return 0;
}

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

int main(){
  long long L,R;  cin >> L >> R;
  if(R-L > 3000){
    cout << '0' << endl;
    return 0;
  }
  long long min = 100000000;
  for(int i=L;i<R;i++){
    for(int j=i+1;j<=R;j++){
      if(((i%2019)*(j%2019))%2019 < min) min = ((i%2019)*(j%2019))%2019;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        var n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var A = n[0];
        var B = n[1];
        var C = n[2];
        
        Console.WriteLine(Math.Min(B / A,C));
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

int main(void) {
    string s, t;
    int a, b;
    string u;
    cin >> s >> t >> a >> b >> u;
    
    if (s == u) cout << a-1 <<" "<<b <<endl;
    else cout << a << " " << b - 1 << endl;
    return 0;
}

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

long long read(){
    long long ret=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-f;ch=getchar();}
    while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
    return ret*f;
}
int n;
int a[200111];
int b[200111];
signed main(){
    //ios::sync_with_stdio(false);
    n=read();
    for(int i=1;i<=n;i++){
    	a[i]=read();
    	b[i]=a[i];
	}
	sort(b+1,b+1+n);
	int max1=b[n];
	int max2=b[n-1];
	for(int i=1;i<=n;i++){
		if(a[i]==max1){
			printf("%d\n",max2);
		}else printf("%d\n",max1);
	}
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}

const int N=1e5+5;
int a[N];
int o[N];
int u[N];
int b[N];
int n,m,v,p;
bool check(int tm){
    for(int i=1;i<=n;++i)a[i]=o[i],u[i]=0;
    u[tm]=1;
    a[tm]+=m;
    int r=v-1;
    dbg(tm);
    for(int i=1;i<=n&&r;++i){
        if(!u[i]&&a[i]+m<=a[tm]){
            u[i]=1;
            a[i]+=m;
            r--;
        }
    }
    for(int i=n;i>n-p+1&&r;--i){
        if(!u[i]){
            u[i]=1;
            a[i]+=m;
            r--;
        }
    }
    int cl=0;
    if(!r){
        for(int i=1;i<=n;++i)cl+=(a[i]>a[tm]);
        if(cl<p)return 1;
        else return 0;
    }
    int z=0;
    int t=a[tm];
    for(int i=1;i<=n;++i)
        if(!u[i]){
            if(a[i]>t)return 0;
            z+=t-a[i];
        }
    if(z>=m*r)return 1;
    else return 0;
}

int32_t main(){
    cin>>n>>m>>v>>p;
    for(int i=1;i<=n;++i)cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i)o[i]=a[i];
    int r=n,l=0;
    while(r-l>1){
        int tm=(l+r)/2;
        if(check(tm))r=tm;
        else l=tm;
    }
    cout<<n-r+1<<'\n';


    return 0;
}


Measured memory_bytes: 2688
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
using namespace std;
map<string,int>a;
int main()
{
    int n,choose,temp,l,r;
    string color;
    scanf("%d", &n);
    while (n--)
    {
        scanf("%d ", &choose);
        switch (choose)
        {
        case 0:
            cin >> color >> temp;
            //scanf("%s%d", color, &temp);
            a[color] = temp;
            break;
        case 1:
            cin >> color;
            if (a.find(color) != a.end())printf("%d\n", a[color]);
        }
    }
    
}


Measured memory_bytes: 27964
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    unsigned long long total = 1;
    vector<ll> A(N);
    unsigned long long maxA = pow(10, 18);
    for(size_t i=0;i<N; i++)
    {
        cin >> A[i];
        if(A[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    for(size_t i=0;i<N; i++)
    {
        if(A[i] <= maxA / total)
        {
            total *= A[i];
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }
    }

     cout << total << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3992
// AOJ 0519: Worst Reporter
// 2017.10.28 bal4u@uu

#include <stdio.h>
#include <string.h>

char buf[20], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

char tbl[5001][5001];
int  q[5001], top, end;
int  count[5001];

int topological_sort(int size)
{
    int i, j, f;

    memset(count, 0, sizeof(count));
    for (i = 0; i < size; i++) for (j = 0; j < size; j++) {
        if (tbl[i][j]) count[j]++;
    }
    top = end = 0;
    for (i = 0; i < size; i++) if (count[i] == 0) q[end++] = i;
    f = 0;
    while (top < end) {
		f |= (end - top) > 1;
		i = q[top++];
        printf("%d\n", i + 1);
        for (j = 0; j < size; j++) {
            if (tbl[i][j]) {
                if (--count[j] == 0) q[end++] = j;
            }
        }
    }
	return f;
}

int main()
{
	int n, m, a, b;

	fgets(p=buf, 8, stdin), n = getint();
	fgets(p=buf, 8, stdin), m = getint();
	memset(tbl, 0, sizeof(tbl));
	while (m--) {
		fgets(p=buf, 16, stdin), a = getint()-1, p++, b = getint()-1;
		tbl[a][b] = 1;
	}
	putchar('0' + topological_sort(n));
	putchar('\n');
	return 0;
}

Measured memory_bytes: 26236
#include<bits/stdc++.h>
using namespace std;
 
int main() {
    int n , k , x ;
    while(cin>>n>>k) {
        int mx = 0 , g = 0;
        for(int i = 0; i < n; i++) {
            cin>>x;
            g = __gcd(g,x);
            mx = max(mx,x);
        }
        if( k <= mx && k % g == 0 ) 
            cout<<"POSSIBLE"<<endl;
        else
            cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }

    int sum=0;
    for (int i=0; i<N; i++){
        sum += vec.at(i);
    }

    vector<int> mn(N);
    for (int i=0; i<N; i++){
        mn.at(i) = sum - 2*vec.at(i);
        sum = mn.at(i);
    }

    vector<int> mni(N);
    for (int i=0; i<N; i++){
        mni.at(i) = max( mn.at(i), (-1) * mn.at(i));
    }

    sort(mni.begin(), mni.end());
    cout << mni.at(0) << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>  
#define fi first  
#define se second  
#define pb push_back  
#define CLR(A, X) memset(A, X, sizeof(A))  
using namespace std;  
  
typedef long long LL;  
typedef pair<int, int> PII;  
const double eps = 1e-10;  
int dcmp(double x){if(fabs(x)<eps) return 0; return x<0?-1:1;}  
const LL INF = 0x3f3f3f3f;  
const LL MOD = 1e9+7;  
const int N = 1e6+5;  
  
LL a[50];  
  
int main() {  
    LL k;  
    scanf("%lld", &k);  
    for(int i = 0; i < 50; i++) a[i] = i+k/50LL;  
    int x = (int)(k%50LL);  
    for(int i = 0; i < x; i++) {  
        a[i] += 51;  
        for(int j = 0; j < 50; j++) a[j]--;  
    }  
    puts("50");  
    for(int i = 0; i < 50; i++) printf("%lld%c", a[i], i==49?'\n':' ');  
    return 0;  
} 

Measured memory_bytes: 256
import itertools

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

p = list(itertools.permutations(range(1,N+1)))

cp = 0
cq = 0

for i in range(len(p)):
    if p[i] == P:
        cp = i + 1
    if p[i] == Q:
        cq = i + 1

print(abs(cp-cq))

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

int main() {
	int N, K;
	string S;
	cin >> N >> S >> K;
	char temp;
	temp = S[K - 1];

	for (int i = 0; i < N; i++) {
		if (S[i] != temp) {
			S[i] = '*';
		}
	}

	cout << S << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int n;
	cin >> n;
	int ans = 0;
	repr(i,1, n+1) {
		int k = 1;
		int t = 0;
		while (k <= i) {
			if (i%k == 0) t++;
			k++;
		}
		//cout << t << endl;
		if (t == 8 && i%2==1) ans++;
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> 
#include <cmath> //pow

#define rep(i,n)  for(int (i) = 0; (i) < (n); (i)++)
#define rep1(i,n) for(int (i) = 1; (i) <= (n); (i)++)

using namespace std;

int main(void) {
	int n, k, q;
	cin >> n >> k >> q;


	vector<int> ans(n, k);
	rep(i, q) {
		int a;
		cin >> a;
		a--;

		ans[a]++;
	}

	rep(i,n){
		if (ans[i] > q)  cout << "Yes" << endl;
		else cout << "No" << endl;
	}

}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int N,i,j,sum=0;
    int A[100050]={0};
    scanf("%d",&N);
    for(i=1;i<N+1;i++)
        scanf("%d",&A[i]);
    for(i=1;i<N+1;i++)
        sum+=abs(A[i]-A[i-1]);
    sum+=abs(A[N]-A[0]);
    for(i=1;i<=N;i++)
        printf("%d\n",sum-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]));
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

void solve(){
  int a, b; cin >> a >> b;
  cout << a * b << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int a_rest=X;
    int b_rest=Y;
    int ans=A*X+B*Y;

    if(2*C < A+B){
        ans = 2*C*min(X,Y) + A*(X-min(X,Y))+B*(Y-min(X,Y));
        a_rest = X - min(X,Y);
        b_rest = Y - min(X,Y);
    }

    if(2*C < A && a_rest>0){
        ans= ans + 2*C*a_rest - A*a_rest;
    }
    if(2*C < B && b_rest>0){
        ans = ans + 2*C*b_rest - B*b_rest;
    }
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    vector<int> rl;
    vector<int> lr;
    lr.push_back(-1);
    for(int i = 0; i < s.length() - 1; i++){
        if(s[i] == 'R' && s[i + 1] == 'L') rl.push_back(i);
        else if(s[i] == 'L' && s[i + 1] == 'R') lr.push_back(i);
    }
    lr.push_back(s.length() - 1);
    int out[s.length()] = {};
    for(int i = 0; i < rl.size(); i++){
        int l = lr[i];
        int m = rl[i];
        int r = lr[i + 1];
        out[m] = (m - l + 1) / 2 + (r - m) / 2;
        out[m + 1] = (r - l) - out[m];
    }
    for(int i = 0;  i < s.length(); i++){
        cout << out[i] << endl;
    }
}


Measured memory_bytes: 1532
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
using namespace std;

int main(){
  int H, W;
  cin >> H >> W;
  vector <string> A(H);

  for (int i=0; i<(H); i++) cin >> A.at(i);

  for (int i=0; i<(H+2); i++){
    for (int j=0; j<(W+2); j++){

      if (i==0 || i==(H+1) || j==0 || j==(W+1)) cout << "#";
      else cout << (A.at(i-1))[j-1];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let c: i64 = read();
    let k: i64 = read();
    let mut t: Vec<i64> = (0..n).map(|_| read()).collect();

    t.sort();

    let ans = t.iter().fold((0, t[0], 1), |(bus, now, count), &t_i| {
        if t_i > now + k || bus + 1 > c {
            (1, t_i, count + 1)
        } else {
            (bus + 1, now, count)
        }
    }).2;

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
I=lambda:map(int,input().split());n,m=I();d=[0]+[9**9]*2**n
while m:
 m-=1;a,_=I();s=sum(1<<c-1for c in I())
 for j in range(2**n):d[s|j]=min(d[s|j],d[j]+a)
print(d[-2]%9**9or-1)

Measured memory_bytes: 48728
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        String s = sc.next();
        if(s.toLowerCase().equals(s)){
            System.out.println("a");
        }else{
            System.out.println("A");
        }
    }

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


Measured memory_bytes: 35732
#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;}

//-----------------------------------------

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

    ll x, k, d;
    ll ans;
    cin >> x >> k >> d;
    x = abs(x);

    ll y = (ll)ceil((ld)x/(ld)d);
    ll t = x - d * y;
    ll s = k-y;

    if(s<0) ans = abs(x - k*d);
    else if(s%2==0) ans = abs(t);
    else ans = abs(t + d);

    cout << ans <<endl;

    
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

const ll MOD = 1e9 + 7;

vector<vector<int>> calcNext(const string &S) {
  int n = (int)S.size();
  vector<vector<int>> res(n + 1, vector<int>(10, n));
  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j < 10; ++j) res[i][j] = res[i + 1][j];
    res[i][S[i] - '0'] = i;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<int>> nxt = calcNext(s);
  vector<vector<ll>> dp(n + 1, vector<ll>(4, 0));
  dp[0][0] = 1;
  REP(i, n) {
    REP(j, 10) {
      REP(k, 3) {
        if (nxt[i][j] >= n) continue;
        (dp[nxt[i][j] + 1][k + 1] += dp[i][k]) %= MOD;
      }
    }
  }
  ll ans = 0;
  REP(i, n + 1) { (ans += dp[i][3]) %= MOD; }
  cout << ans << endl;
}

Measured memory_bytes: 4480
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N = input()
a = map(int, raw_input().split())

cnt1 = cnt2 = cnt4 = 0
for num in a:
    if num % 4 == 0:
        cnt4 += 1
    elif num % 2 == 0:
        cnt2 += 1
    else:
        cnt1 += 1

if cnt2 > 0:
    if cnt4 >= cnt1:
        print "Yes"
    else:
        print "No"
else:
    if cnt4 + 1 >= cnt1:
        print "Yes"
    else:
        print "No"

Measured memory_bytes: 11436
#include <iostream>
#include <limits.h>
#include <string>
using namespace std;

int main(void){
    char s[105], moji = 0;
    bool ans = true;
    cin >> s;
    for (int i = 0; s[i] != '\0'; i++) {
        for (int j = 0; s[j] != '\0'; j++) {
            if (s[i] == s[j]) moji++;
        }
        if (moji % 2 != 0) {
            ans = false;
            break;
        }
    }
    if (ans) cout << "Yes";
    else cout << "No";
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {
    static boolean[][] white;
    static Queue<Point> q;

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] line0 = reader.readLine().split(" ");
        int h = Integer.parseInt(line0[0]);
        int w = Integer.parseInt(line0[1]);
        white = new boolean[h + 2][w + 2];
        q = new ArrayDeque<>(h * w);
        for (int x = 0; x < h; x++) {
            String line = reader.readLine();
            for (int y = 0; y < w; y++) {
                if (line.charAt(y) == '#') {
                    q.offer(new Point(x, y, 0));
                } else {
                    white[x + 1][y + 1] = true;
                }
            }
        }
        while (!q.isEmpty()) {
            Point p = q.poll();
            int x = p.x;
            int y = p.y;
            int nextDepth = p.depth + 1;
            neighbor(x - 1, y, nextDepth);
            neighbor(x + 1, y, nextDepth);
            neighbor(x, y - 1, nextDepth);
            neighbor(x, y + 1, nextDepth);
        }
        System.out.println(Point.maxDepth);
    }

    static void neighbor(int x, int y, int depth) {
        if (white[x + 1][y + 1]) {
            q.offer(new Point(x, y, depth));
            white[x + 1][y + 1] = false;
        }
    }

    static class Point {
        int x;
        int y;
        int depth;
        static int maxDepth;

        Point(int x, int y, int depth) {
            this.x = x;
            this.y = y;
            this.depth = depth;
            maxDepth = depth;
        }
    }
}


Measured memory_bytes: 72580
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int N, A, B;
        cin >> N >> A >> B;

        cout << (N - A) % B << endl;

        return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]){
		cout << "Bad\n";
	}else{
		cout << "Good\n";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

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

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  int x, y;
  cin >> x >> y;

  if ((x + y) % 3 != 0) {
    puts("0");
    return 0;
  }

  int n = (x + y) / 3;
  int a = x - n;
  int b = y - n;

  combination c(a + b);
  mint ans = c(a + b, a);
  cout << ans.x << endl;
  return 0;
}


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

using namespace std;

const int N = 3;

int main () {
    int a[N];

    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    sort(a, a + N);

    if (a[0] + a[1] == a[2]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
def dp():
    N = int(input())
    h = list(map(int, input().split()))

    DP = [0]
    for i in range(1, N):
        if i == 1:
            DP += [abs(h[i]-h[i-1])]
            continue
        DP += [min(DP[i-1]+abs(h[i]-h[i-1]), DP[i-2]+abs(h[i]-h[i-2]))]
    print(DP[-1])

dp()


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 1e5 + 5;
vector<ii> adj[2][MAX];
ll dis[2][MAX], ans[MAX];
int n, m, s, t;

void dijkstra(int source, vector<ii> graph[MAX], ll d[MAX]) {
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    fori(i, 1, n + 1) {
        d[i] = (ll) 1e18;
    }
    d[source] = 0;
    pq.emplace(d[source], source);
    while(!pq.empty()) {
        auto cur = pq.top(); pq.pop();
        ll w;
        int v;
        tie(w, v) = cur;
        if(w > d[v]) {
            continue;
        }
        for(auto &each : graph[v]) {
            int vv, ww;
            tie(vv, ww) = each;
            if(d[vv] > w + ww) {
                d[vv] = w + ww;
                pq.emplace(d[vv], vv);
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);

    cin >> n >> m >> s >> t;

    fori(i, 0, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        adj[0][u].emplace_back(v, a);
        adj[1][u].emplace_back(v, b);
        adj[0][v].emplace_back(u, a);
        adj[1][v].emplace_back(u, b);
    }

    dijkstra(s, adj[0], dis[0]);
    dijkstra(t, adj[1], dis[1]);

    ford(i, n, 1) {
        ans[i] = (ll) 1e15 - (dis[0][i] + dis[1][i]);
        ans[i] = max(ans[i], ans[i + 1]);
    }

    fori(i, 1, n + 1) {
        cout << ans[i] << '\n';
    }

    return 0;
}


Measured memory_bytes: 16380