akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.size();
    ll ans=n;
    rep(i,n-1){
        if(s[i]!=s[i+1]){
            chmin(ans,max(i+1,n-1-i));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
 // freopen("input.txt","r",stdin);
#endif

  int n;
  cin>>n;
  string a;
  cin>>a;
  int count=0;
  for(int i=0;i<n;i++)
  {
    if(a[i]=='A')
    {
      if(i+1<n && a[i+1]=='B')
      {
        if(i+2<n && a[i+2]=='C')
        {
          count++;
        }
      }
    }
  }

  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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

vector<int>u1,v1,u2,v2;
void f(int x,int y,vector<int>& u1,vector<int>& v1,vector<int>& u2,vector<int>& v2){
	int c=0; int a,b,c1,c2;
	rep(i,u1.size()){
		c+=v1[i]-u1[i]+1;
		if(c>=x){
			a=i; c1=c; break;
		}
	}
	c=0;
	rep(i,u1.size()){
		c+=v1[i]-u1[i]+1;
		if(c>=y){
			b=i; c2=c; break;
		}
	}


	if(c2!=y){
		u2.push_back(v1[b]-(c2-y)+1);
		v2.push_back(v1[b]);

		REP(i,b+1,u1.size()-1){
			u2.push_back(u1[i]);
			v2.push_back(v1[i]);
		}
	}
	else{
		REP(i,b+1,u1.size()-1){
			u2.push_back(u1[i]);
			v2.push_back(v1[i]);
		}
	}


    if(a!=b){

	if(c1!=x){
		u2.push_back(v1[a]-(c1-x)+1);
		v2.push_back(v1[a]);

		REP(i,a+1,b-1){
			u2.push_back(u1[i]);
			v2.push_back(v1[i]);
		}
		u2.push_back(u1[b]);
		v2.push_back(v1[b]-(c2-y));
		}
	else{
		REP(i,a+1,b-1){
			u2.push_back(u1[i]);
			v2.push_back(v1[i]);
		}
		u2.push_back(u1[b]);
		v2.push_back(v1[b]-(c2-y));
	}
    }

    else{

    	u2.push_back(v1[a]-(c1-x)+1);
    	v2.push_back(v1[b]-(c2-y));
    }


		REP(i,0,a-1){
			u2.push_back(u1[i]);
			v2.push_back(v1[i]);
		}
		u2.push_back(u1[a]);
		v2.push_back(v1[a]-(c1-x));

}

int main(){

	int m,n,p,q,r,x,y;

	while(1){

		cin >> n;
		if(n==0) break;
		cin >> m >> p >> q >> r;


		REP(i,1,m){

			cin >> x >> y;

			if(i==1){
				u1.push_back(y+1); v1.push_back(n);
				u1.push_back(x+1); v1.push_back(y);
				u1.push_back(1); v1.push_back(x);
			}
			else if(i%2==0){ u2.clear(); v2.clear(); f(x,y,u1,v1,u2,v2);}
			else if(i%2==1){ u1.clear(); v1.clear(); f(x,y,u2,v2,u1,v1);}
		}


		int s=0; int c=0; int a,b,c1,c2;
		if(m%2==0){

			rep(i,u2.size()){
				c+=v2[i]-u2[i]+1;
				if(c>=p){
					a=i; c1=c; break;
				}
			}
			c=0;
			rep(i,u2.size()){
				c+=v2[i]-u2[i]+1;
				if(c>=q){
					b=i; c2=c; break;
				}
			}

			if(a!=b){

			REP(i,v2[a]-(c1-p),v2[a])
			if(i<=r) s++;
			REP(i,a+1,b-1){
				REP(j,u2[i],v2[i]){
				if(j<=r) s++;
				}
			}
			REP(i,u2[b],v2[b]-(c2-q))
			if(i<=r) s++;

			}

			else{

			REP(i,v2[a]-(c1-p),v2[a]-(c2-q))
			if(i<=r) s++;
			}

			cout << s << endl;

		}


		else{

			rep(i,u1.size()){
				c+=v1[i]-u1[i]+1;
				if(c>=p){
					a=i; c1=c; break;
				}
			}
			c=0;
			rep(i,u1.size()){
				c+=v1[i]-u1[i]+1;
				if(c>=q){
					b=i; c2=c; break;
				}
			}

			if(a!=b){

			REP(i,v1[a]-(c1-p),v1[a])
			if(i<=r) s++;
			REP(i,a+1,b-1){
				REP(j,u1[i],v1[i]){
				if(j<=r) s++;
				}
			}
			REP(i,u1[b],v1[b]-(c2-q))
			if(i<=r) s++;

			}

			else{

			REP(i,v1[a]-(c1-p),v1[a]-(c2-q))
			if(i<=r) s++;
			}

			cout << s << endl;

		}

		u1.clear(); v1.clear(); u2.clear(); v2.clear();

	}

	return 0;
}

Measured memory_bytes: 1368
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;


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

    int ans = 0;
    REP(i, 1, n+1){
        string s = to_string(i);
        if(s.size() % 2 == 1 ){ans++;}
    }
    p(ans);


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	ll ans = 1;
	for(int i = 2;i<=n;i++)
		ans = (ans*i)%mod;
	cout<<ans<<endl;
	return 0;
}

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

ll mod=998244353;

int main(){
    ll n;
    cin>>n;
    
    map<ll,ll> m;
    for(ll i=1;i<=n;++i){
        ll t;
        cin>>t;
        m[t]++;
    }
    ll cnt=0;
    cin>>cnt;
    for(ll i=0;i<cnt;++i){
        ll t;
        cin>>t;
        if(!m[t]){
            cout<<"NO";
            return 0;
        }
        m[t]--;
    }
    cout<<"YES";
}

Measured memory_bytes: 16060
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int a,b,h;
  cin >> a >> b >> h;
  cout << (a+b)*h/2;

  return 0;
}


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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int cnt = 0;
  for(int i = 1; i <= n; ++i){
    int sum = 0;
    int t = i;
    while(t){
      int tmp = t % 10;
      sum += tmp;
      t = t /10;
    }
    if(sum >= a && sum <= b) cnt += i;
  }
  cout << cnt << endl;


}


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

int main() {
  int X;
  cin >> X;
  if (X>=30) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

int main(void) {
	int a0, l;
	while(1) {
		cin >> a0 >> l;
		if(a0 == 0 and l == 0) {
			break;
		}

		bool frag = true;
		vector<int> a;
		a.push_back(a0);
		int ptr = 0;

		while(frag) {
			priority_queue<int> queue;
			int now = a[ptr];
			for(int i = l; i > 0; i--) {
				int tmp;
				tmp = now / pow(10, i - 1);
				now -= tmp * pow(10, i - 1);
				queue.push(tmp);
				//cout << tmp << endl;
			}

			int max = 0, min = 0;
			for(int i = 0; i < l; i++) {
				int tmp;
				tmp = queue.top();
				queue.pop();
				max += tmp * pow(10, l - 1 - i);
				min += tmp * pow(10, i);
				//cout << tmp << " ";
			}

			int value = max - min;
			//cout << max << " " << min << " " << value << endl;
			for(int i = 0; i < a.size(); i++) {
				if(a[i] == value) {
					frag = false;
					cout << i << " " << value << " " << a.size() - i << endl;
				}
			}

			a.push_back(value);
			ptr++;
		}
	}
	return 0;
}

Measured memory_bytes: 3252
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
string s;

// アンバランスならばいずれか3文字のうち2文字はunbalance

int main() {
  INCANT;
  cin >> s;
  int n = s.size();
  if (n==2) {
    if (s[0]==s[1]) {
      cout << 1 << ' ';
      cout << 2 << endl;
      return 0;
    }
    cout << -1 << ' ';
    cout << -1 << endl;
    return  0;  
  }

  for (int i=2; i<n; i++) {
    if (s[i-2]==s[i] || s[i-1]==s[i] || s[i-2]==s[i-1]) {
      cout << i-1 << ' ';
      cout << i+1 << endl;
      return 0;
    }
  }

  cout << -1 << ' ';
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 512
// Shift-JIS（シフトジス）

#include <bits/stdc++.h>
using namespace std;

int gcd(long long a, long long b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

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

int lcm(long long a, long long b)
{
    return a * b / gcd(a, b);
}

int main()
{
    int N;
    cin >> N;
    int num, e = 0;
    for (int i = 1; i <= N; i++)
    {
        cin >> num;
        if (i != num)
        {
            e++;
        }
    }
    if (e == 0 || e == 2)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

unordered_map<int,int> aa;
int n,ans;

main(){
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	for(int i=1;i<n;i++){
		a[i]+=a[i-1];
	}
	for(int x:a)debug(x);
	for(int x:a)amp(aa,x);
	for(auto x:aa){
		if(x.fi==0)ans+=((x.se+1)*x.se)/2;
		else ans+=(x.se*(x.se-1))/2;
	}
	dans;
}


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

using namespace std;
typedef long long ll;

int main() {
  ll n;
  scanf("%lld", &n);
  vector<ll> a(n);
  for(int i=0; i<n; i++) scanf("%lld", &a[i]);

  sort(a.begin(), a.end());
  double m = double(a[n-1]) / 2.0;
  ll cand = a[0];
  for(int i=0; i<n-1; i++) {
    if(abs(m-cand) > abs(m-a[i])) {
      cand = a[i];
    }
  }

  printf("%lld %lld\n", a[n-1], cand);

  return 0;
}


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

int main(){
    int k,n;
    cin>> k >> n;
    int ie[n],aida[n];
    for(int i=0; i<n; i++){
        cin>> ie[i];
    }

    for(int i=0; i<n-1; i++){
        aida[i]=ie[i+1]-ie[i];
    }

    aida[n-1]=ie[0]+k-ie[n-1];

    int mx=0,tmp;

    for(int i=0; i<n; i++){
        if(mx<aida[i]){
            mx=aida[i];
            tmp=i;
        }
    }

    cout << k-aida[tmp] << endl;

}

Measured memory_bytes: 1792
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s, t; cin >> s >> t;
	if(t.length()-s.length() != 1) { println("No"); return 0; }
	forl(i, 0, s.length()) {
		if(s[i] != t[i]) { println("No"); return 0; }
	}
	println("Yes");
}


Measured memory_bytes: 3612
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()
	N := readInt()
	T := readInt64()
	a := make([]int64, N)
	for i := range a {
		a[i] = readInt64()
	}
	ans := T
	for i := 0; i+1 < N; i++ {
		d := a[i+1] - a[i]
		ans += minInt64(d, T)
	}
	println(ans)
}


Measured memory_bytes: 4608
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
      if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= i;
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};

int main(){
  int N, K;
  std::cin >> N >> K;
  std::vector<int > A(N);
  for (int i=0; i<N; i++) {
    std::cin >> A[i];
  }
  for (int i=K; i<N; i++) {
    if (A[i]>A[i-K]) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

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 { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  ll n, p;
  string s;
  cin >> n >> p >> s;
  ll ans = 0;
  if(p == 2 || p == 5) {
    rep(i, n) {
      ll k = s[i] - '0';
      if(k % p == 0) ans += i + 1;
    }
  } else {
    mod = p;
    map<ll, ll> mp;
    mp[0]++;
    mint now = 0;
    reverse(all(s));
    rep(i, n) {
      ll k = s[i] - '0';
      now += mint(10).pow(i) * k;
      ans += mp[now.x];
      mp[now.x]++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4072
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,N,n) for(int i=N;i>=n;i++)
#define CH(n,a,b) (a)<=(n)&&(n)<(b)
#define p(s) cout<<(s)<<endl
typedef long long ll;
using namespace std;

int main() {
	int H;
	while(cin>>H,H){
		int field[12][5];
		bool flag[12][5];
		int ans=0;
		REP(j,0,5) field[0][j]=-1;
		REP(i,1,H+1) REP(j,0,5) cin>>field[i][j];
		bool ok=true;
		while(ok){
			REP(i,0,12) REP(j,0,5) flag[i][j]=false;
			ok=false;
			REP(i,1,H+1){
				int prev=0,tmp=1;
				REP(j,0,5){
					if(field[i][j]==-1){
						prev=-1;
						tmp=1;
						continue;
					}
					if(field[i][j]==prev){
						tmp++;
						if(j==4&&tmp>2){
							ok=true;
							ans+=prev*tmp;
							for(int k=4;k>j-tmp;k--) flag[i][k]=true;
							break;
						}
					}
					else{
						if(tmp<3) {
							prev=field[i][j];
							tmp=1;
						}
						else{
							ok=true;
							ans+=prev*tmp;
							for(int k=j-1;k>=j-tmp;k--) flag[i][k]=true;
							break;
						}
					}
				}
			}
			REP(i,1,H+1){
				REP(j,0,5){
					if(flag[i][j]) {
						for(int k=i;(k>0&&field[k][j]!=-1);k--)field[k][j]=field[k-1][j];
					}
				}
			}
		}
		p(ans);
	}
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    int Q;
    cin >> Q;
    vl A(Q),B(Q);
    rep(i,Q) cin >> A[i] >> B[i];
    
    rep(i,Q) {
        if(A[i] > B[i]) swap(A[i],B[i]);
        ll ab = A[i]*B[i];
        ll mid_ab = sqrt(ab);
        
        ll ans = 0;
        
        if(A[i]-1 != 0 && A[i]-1 <= mid_ab){
            if((ab)/(A[i]-1) > B[i]) ans += A[i]-1;
            else{
                ll a = ab/(B[i]+1);
                ans += a;
            }
            
        }
        
        if(mid_ab == B[i]) ans *= 2;
        else{

           
           if(ab/mid_ab > mid_ab){
               ans += mid_ab;
               ans += mid_ab-A[i];
               
               
           }else{
               
               ans += mid_ab-1-(A[i]);
               ans += mid_ab;
               
           }
            
            if(mid_ab * mid_ab == ab) ans--;
            else if(mid_ab*(mid_ab+1) == ab) ans--;
            
        }
        
        
        
        
        
        cout << ans << endl;
        
    }
    
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> v(n), c(n);
  rep (i, n) cin >> v[i];
  rep (i, n) cin >> c[i];
  int sum = 0;
  rep (i, n) sum += max(0, v[i] - c[i]);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 1000000
bool marked[M];
bool isPrime(int n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  return marked[n] == false;
}
void sieve(int n) {
  for (int i = 3; i * i <= n; i += 2) {
    if (marked[i] == false) {
      for (int j = i * i; j <= n; j += i + i){
        marked[j] = true;
      }
    }
  }
}
int main()
{
    vector<int> v1,v2;
    int n;
    cin>>n;
    sieve(n);
    for(int i=1;i<=n;i++){
     if(isPrime(i)==true) v1.push_back(i);
    }

     sieve(1000000);
    for(int i=1;i<=1000000;i++){
     if(isPrime(i)==true) v2.push_back(i);
    }

    if(v1[v1.size()-1]==n) cout<<n<<endl;
    else cout<<v2[v1.size()]<<endl;


  return 0;
}



Measured memory_bytes: 1984
import itertools
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))

k = []
s = []
for i in range(len(ks)):
    k.append(ks[i][0])
    s.append(ks[i][1:])

ans = 0
for x in itertools.product([0, 1], repeat=N):
    total = 0
    for i in range(M):
        count = 0
        for j in range(k[i]):
            if x[s[i][j]-1]:
                count += 1
        if p[i] == count % 2:
            total += 1
    if total == M:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
        #include<stdlib.h>
          int compare(const void *a, const void *b){
            return *(int*)a - *(int*)b;
              }
          int main(){
            int N,median,i;
            int A[200000];
            long long int mixsum = 0;
            scanf("%d",&N);
            for(i = 0; i < N;i++){
              scanf("%d",&A[i]);
              A[i] += -i;
            }
            qsort(A,N,sizeof(int),compare);
         
            median = A[N/2];
            for(i = 0;i < N;i++)mixsum += abs(A[i] - median);
            printf("%lld\n",mixsum);
            return 0;
          }

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pi> vpi;
typedef vector<bool> vbool;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define forall(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define F0(i,n) for(ll i = 0; i < n; i++)
#define F1(i,n) for(ll i = 1; i <= n; i++)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define per(i,a,b) for(int i = b-1; i >= a; i--)
#define FIN ios::sync_with_stdio(false);cin.tie(0);
#define db(x) cout<<#x<<" = "<<x<<"\n"
#define all(v) v.begin(),v.end()
#define modulo(a,b) ((a%b)+b)%b
#define F first
#define S second
#define INF 1000000010
#define eps 0.000000000001
#define mod 1000000007
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;}

//=======================//
const int maxn = 3000;
double dp[maxn][maxn];
int n;
double p[maxn];

int main () {
	//FIN
	cin >> n;
	F1(i,n) cin >> p[i];
	F0(i,n) dp[1][i] = 0.0;
	dp[1][0] = 1-p[1];
	dp[1][1] = p[1];
	rep(i,2,n) rep(j, 0, i) {
		dp[i][j] = 0.0;
		if (j < i) dp[i][j] += dp[i-1][j] * (1-p[i]);
		if (j > 0) dp[i][j] += dp[i-1][j-1] * p[i];
	}
	double res = 0.0;
	for (int i = (n+1)/2; i<=n; i++) {
		res += dp[n][i];
	}
	cout << fixed << setprecision(12) << res << "\n";


	return 0;
}










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

// calculate |gcd|.
// if  ether num is 0, return 0
long long GCD(long long left, long long right) {
  if(left == 0 || right == 0) return 0;
  if(left < 0) left *= -1;
  if(right < 0) right *= -1;
  if(left < right) swap(left, right);
  long long nextnum, ansgcd = -1;
  while(ansgcd == -1) {
    nextnum = left % right;
    if(nextnum == 0) ansgcd = right;
    left = right;
    right = nextnum;
  }
  return ansgcd;
}

long long LCM(long long left, long long right) {
  return left / GCD(left, right) * right;
}

long long n;
long long t[1005] = {0}, a[1005] = {0};

long long solve();

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

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long now = 1, nowl = t[0], nowr = a[0];
  for(int i = 1; i < n; ++i) {
    long long nextl, nextr, nextnum;
    if(a[i] == a[i - 1] && t[i] == t[i - 1]) continue;
    if(nowl % t[i] == 0 && nowl / t[i] * a[i] > nowr) {
      nowr = nowl / t[i] * a[i];
      continue;
    }
    if(nowr % a[i] == 0 && nowr / a[i] * t[i] > nowl) {
      nowl = nowr / a[i] * t[i];
      continue;
    }
    nextl = (nowl / t[i] + 1) * t[i];
    nextr = (nowr / a[i] + 1) * a[i];
    if(nextr / a[i] * t[i] < nowl)
      nextnum = nextl / t[i];
    else if(nextl / t[i] * a[i] < nowr)
      nextnum = nextr / a[i];
    else
      nextnum = min(nextl / t[i], nextr / a[i]);
    nowl = nextnum * t[i];
    nowr = nextnum * a[i];
  }
  return nowl + nowr;
}

Measured memory_bytes: 256
#include<iostream>

int main(){
	int n;
	int a[100];

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

	for (int l = n-1; l >=0 ; l--){
		if (l == 0){
			std::cout << a[l]<<'\n';
			break;
		}
		std::cout << a[l] << ' ';
	}


}


Measured memory_bytes: 3080
#include <stdio.h>
int main(void){
	int a,b,c=0,s=0,n=0;
	double ave;
	while(scanf("%d,%d",&a,&b)!=EOF){
		s+=a*b;
		n+=b;
		c++;
	}
	ave=(double)n/c;
	if(ave-(n/c)>=0.5)
		n=n/c+1;
	else
		n=n/c;
	printf("%d\n%d\n",s,n);
	return 0;
}

Measured memory_bytes: 592
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l    ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long k, a, b;
    scan(k, a, b);
    if(b - a <= 2 || a >= k)
    {
        writeln(k + 1);
    }
    else
    {
        k -= a - 1;
        writeln(a + (k / 2) * (b - a) + (k % 2));
    }
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

int main() {
        int n;
        cin >> n;
        int a = 0,
            b = 0;
        string taro, hanako;

        int i;
        for(i = 0; i < n; i++) {
                cin >> taro >> hanako;
                if (taro > hanako) {
                        a += 3;
                }
                else if (hanako > taro) {
                        b += 3;
                }
                else {
                        a++;
                        b++;
                }
        }

        cout << a << " " << b << endl;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
using namespace std;

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

int main(){
	string S,T,U;
	ll A,B;
	cin>>S>>T>>A>>B>>U;
	
	if(S==U) A--;
	else B--;
	
	cout<<A<<" "<<B<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif

    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &el : a) cin >> el;
    ll S = 1e18;
    for (int x = -100; x <= 100; ++x)
    {
        ll s = 0;
        for (int i = 0; i < n; ++i)
        {
            s += (a[i] - x) * (ll)(a[i] - x);
        }
        chkmin(S, s);
    }
    cout << S << '\n';

    return 0;
}



Measured memory_bytes: 256
import sys
from collections import Counter
import string

# input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

def divisor(n):
    """
    n の約数をリストで返す
    :param int n:
    :rtype: list of int
    """
    ret = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


def factorization(n):
    """
    素因数分解
    :param int n:
    :rtype: list of int
    """
    if n <= 1:
        return []

    ret = []
    while n > 2 and n % 2 == 0:
        ret.append(2)
        n //= 2
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            ret.append(i)
            n //= i
        else:
            i += 2
    ret.append(n)
    return ret


def is_prime(n):
    """
    nの素数判定
    :param int n:
    :rtype: Bool
    """
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def coprime(a, b):
    return gcd(a, b) == 1


def main():
    S = input()
    ans = 0
    cur = 0
    stack_initial = 0
    stack_count = 0
    # arr = []

    for i in range(len(S)):
        if i == 0 and S[i] == '<':
            cur = 0
            ans = 0
            cur = 1
        elif i == 0 and S[i] == '>':
            stack_count = 1
        elif S[i-1] == '<' and S[i] == '<':
            ans += cur
            cur += 1
        elif S[i-1] == '<' and S[i] == '>':
            # ans += cur
            stack_initial = cur
            # print('stack_initial', i, stack_initial)
            stack_count = 1
            cur = 0
        elif S[i-1] == '>' and S[i] == '>':
            stack_count += 1
        elif S[i-1] == '>' and S[i] == '<':
            stack_count += 1
            # ans += (stack_count * (0 + (stack_count)) // 2)
            # print(i, stack_initial, stack_count)
            if stack_count > stack_initial:
                ans += (stack_count * (0 + (stack_count - 1)) // 2)
            else:
                ans += stack_initial + ((stack_count - 1) * (0 + ((stack_count - 1) - 1)) // 2)
            stack_initial = 0
            stack_count = 0
            cur = 1
        # print(i, ans)

    if S[len(S)-1] == '<':
        ans += cur
        # print(cur)
    elif S[len(S)-1] == '>':
        stack_count += 1
        #
        if stack_count > stack_initial:
            ans += (stack_count * (0 + (stack_count - 1)) // 2)
        else:
            ans += stack_initial + ((stack_count - 1) * (0 + ((stack_count - 1) - 1)) // 2)
        # print(stack_count, ans)
        stack_count = 0
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42608
'use strict';
const main = input => {
  input = input[0].split(' ').map(val => parseInt(val));
  const a = input[0], b = input[1], c = input[2];
  console.log((a+b+c)>=22?'bust':'win');
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 11468
/*
ID: dorijan1
TASK: tu napisi ime zadatka molim te molim te ali samo ako si na usaco training
LANG: C++11
*/
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define rand rund
#define pb push_back

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
const int MOD=1000000007;
const int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

ll raand()
{
	ll a=rand();
	a*=RAND_MAX;
	a+=rand();
    return a;
}

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

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

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

int sub(int a,int b)
{
	return (a-b+MOD)%MOD;
}

int add(int a,int b)
{
	return (a+b)%MOD;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

ll has(string x)
{
	ll h1=0,h2=0;
	x=to_lower(x);
	for (char a: x)
	{
		h1*=bases[0];
		h1+=a-'a';
		h1%=bases[3];
		h2*=bases[1];
		h2+=a-'a';
		h2%=bases[4];
	}
	return h1*(MOD+13893829)+h2;
}

const int N=300010;
int n,dp[3][N];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(raand()%MOD+13893829);
	cin>>n;
	for (int i=1;i<=n;++i)
	{
		int a,b,c;
		cin>>a>>b>>c;
		dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a;
		dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b;
		dp[2][i]=max(dp[0][i-1],dp[1][i-1])+c;
	}
	cout<<max({dp[0][n],dp[1][n],dp[2][n]});
}



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

int main(){
    int n;
    cin >>n;
    vector<int> v(n);
    for( auto &i : v ) cin >> i;
    int mx = 0;
    Long ans = 0LL;
    for( int i = 0 ; i < n ; ++i ){
        mx = max( mx , v[i]);
        ans += 1LL * ( mx - v[i] );
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4024
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());
ll n,m,vis[21][21],dx[]={-1,1,0,0},dy[]={0,0,-1,1};
string s[21];

void bfs(ll xx,ll yy,ll h)
{
	queue<pll> qu;
	ll x,y;
	vis[xx][yy]=1;
	qu.push({xx,yy});
	while(!qu.empty())
	{
		x=qu.front().ff;
		y=qu.front().ss;
		qu.pop();
		rep(i,4)
		{
			ll p=x+dx[i],q=y+dy[i];
			if(p>=0 && p<n && q>=0 && q<m && s[p][q]!='#' && !vis[p][q])
			{
				qu.push({p,q});
				vis[p][q]=vis[x][y]+1;
				// debug2(x,y);
				// debug3(p,q,vis[x][y]);
			}
		}
	}
}

int main()
{
	IOS;
	ll k,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	while(t--)
	{
		cin>>n>>m;
		// n=s.length();
		// ll a[n];
		ll p=0,q=0;
		rep(i,n)
		{
			cin>>s[i];
			if(s[p][q]!='.')
			{
				rep(j,m)
				{
					if(s[i][j]=='.')
					{
						p=i,q=j;
						break;
					}
				}
			}
		}
		rep(xx,n) rep(yy,m)
		{
			if(s[xx][yy]=='.')
			{
				k=0;
				memset(vis,0,sizeof vis);
				bfs(xx,yy,1);
				rep(i,n)
				{
					rep(j,m)
					{
						k=max(vis[i][j],k);
						// cout<<vis[i][j]<<" ";
					}
					// cout<<"\n";
				}
				c=max(c,k);
			}
		}
		cout<<c-1;

		
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())
s = list(input())

sum_w = [0]*(n+1)
sum_b = [0]*(n+1)
ans = n

for i in range(n):
    if s[i] == '#':
        sum_b[i+1] = sum_b[i] + 1
    else:
        sum_b[i+1] = sum_b[i]

    if s[i] == '.':
        sum_w[i+1] = sum_w[i] + 1
    else:
        sum_w[i+1] = sum_w[i]

ans = n
for i in range(n+1):
    ans = min(ans, sum_b[i]+sum_w[n]-sum_w[i])
print(ans)

Measured memory_bytes: 14148
import java.util.Scanner;
import static java.lang.Math.min;

public class Main {
    public static void main(String[] args) {
        Scanner get = new Scanner(System.in);
        long n = get.nextLong(), k = get.nextLong();
        System.out.println(Math.min((n % k), k - (n % k)));
    }
}


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

using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  int n, m, R;
  cin >> n >> m >> R;
  vector<int> r(R);
  for (int i = 0; i < R; i++) {
    int k;
    cin >> k;
    r[i] = k - 1;
  }
  vector<vector<ll>> d(n, vector<ll>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = INF;
    }
  }

  for (int i = 0; i < m; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    d[a - 1][b - 1] = c;
    d[b - 1][a - 1] = c;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  SORT(r);
  ll ans = INF;
  do {
    ll total = 0;
    for (int i = 0; i < R - 1; i++) {
      total += d[r[i]][r[i + 1]];
    }
    ans = min(total, ans);
  } while (next_permutation(r.begin(), r.end()));
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void){
  int l,i;
  scanf("%d",&l);
  int num[l];
  for(i=0;i<l;i++){
    scanf("%d",&num[i]);
    if(num[i]%2==0){
      if(num[i]%3!=0&&num[i]%5!=0){
        printf("DENIED");
        return 0;
      }
    }
  }
  printf("APPROVED");
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  int N=S.size();
  bool a=true;
  string T=S;
  reverse(T.begin(),T.end());
  if(S!=T){
    a=false;
  }
  string U=S.substr(0,(N-1)/2);
  string V=U;
  reverse(V.begin(),V.end());
  if(U!=V){
    a=false;
  }
  string A=S.substr((N+1)/2,(N-1)/2);
  string B=A;
  reverse(B.begin(),B.end());
  if(A!=B){
    a=false;
  }
  if(a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
 using namespace std;
 char in[110];
 int main(){
 int a,b;scanf("%d%d",&a,&b);
 for(int i=0;i<b;i++)in[i]='0'+a;
 string L=in;
 for(int i=0;i<a;i++)in[i]='0'+b;
 in[a]=0;
 string R=in;
 printf("%s\n",min(L,R).c_str());
 }

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > s(m);
    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;
        s[i].resize(k);
        for (int j = 0; j < k; j++) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }

    vector<int> p(m);
    for (int i = 0; i < m; i++) {
        cin >> p[i];
    }

    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        bool ok = true;
        for (int j = 0; j < m; j++) {
            int c = 0;
			for (int id : s[j]) {
				if ((i >> id) & 1) {
					c++;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
        }
        if (ok) {
			++ans;
		}
    }

    cout << ans ;
	return 0;
}


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

using namespace std;


int main()
{
    std::ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    n--;
    int a[n];
    for(int i = 0;i < n;i++)
    {
        cin>>a[i];
    }
    int sum = 0;
    for(int i = n-1;i >= 0;i--)
    {
        //cout<<a[i]<<endl;
        if(i + 1 < n)
        {
            if(a[i] > a[i+1])
            {
                sum += a[i+1];
                continue;
            }
        }
        sum += a[i];

    }

    cout<<sum + a[0];
        return 0;
}


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

ll c(ll x, ll k, ll d) {
  if(x == 0) {
    if(k % 2 == 0) {
      return 0;
    }
    return d;
  }
  ll xx = x > 0? x : -1 * x;
  ll offset = xx / d;
  if(offset >= k) {
    return xx - (k*d);
  }
  // offset < k
  ll kk = k - offset;
  ll base = xx - (offset * d);

  if(kk % 2==0) {
    return base;
  }
  return abs(base-d);
}

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  cout << c(x, k, d);
}

Measured memory_bytes: 3628