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

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

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  ll n=s.size()+1;
  vll a(n);
  
  ll cnt=0;
  rep(i,n-1){
    a[i]=cnt;
    
    if(s[i]=='<') cnt++;
    else cnt=0;
  }
  a[n-1]=cnt;
  
  cnt=0;
  rrep(i,n-1){
    chmax(a[i+1],cnt);
    
    if(s[i]=='>') cnt++;
    else cnt=0;
  }
  a[0]=cnt;
  
  ll ans=0;
  rep(i,n) ans+=a[i];
  cout<<ans<<endl;
}

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

bool a[100010];
int tmp[100000];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<100010;i++)a[i]=false;
	int numAC=0,num=0;
	vector<int>p(m);
	vector<string>s(m);
	for(int i=0;i<m;i++){
		cin>>p[i]>>s[i];
		if(s[i]=="WA"&&!a[p[i]])tmp[p[i]]++;
		if(s[i]=="AC"&&!a[p[i]]){
			a[p[i]]=true;
			numAC++;
			num+=tmp[p[i]];
			tmp[p[i]]=0;
		}
	}
	cout<<numAC<<" "<<num<<endl;
	return 0;
}


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

int main () {
  int N;
  int x;
  
  cin >> N;
  if( (N%2) == 0 ){
   x = N / 2; 
  }else {
   x = (N/2) + 1;  
  }
  
  cout << x << endl;
    
 return 0; 
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, n = map(int, readline().split())
ab = [list(map(int, readline().split())) for i in range(n)]
inf = float('inf')
dp = [inf] * (2 * 10 ** 4)
dp[0] = 0
for a, b in ab:
    for n in range(h):
        if dp[n + a] > dp[n] + b:
            dp[n + a] = dp[n] + b

ans = min(dp[h:])
print(ans)


Measured memory_bytes: 43484
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
int main(){
	ll n; cin >> n;
	ll arr[n], arr1[n];
	vector<ll> v;
	for(ll i = 0; i < n; ++i){
		cin >> arr[i];
	}
	ll ans = 0, sum = 0;
	for(ll i = 0; i < n; ++i){
		cin >> arr1[i];
		if(arr[i] > arr1[i]){
			v.push_back(arr[i] - arr1[i]);
		}else if (arr1[i] > arr[i]){
			ans++;
			sum += (arr1[i] - arr[i]);
		}
	}
	if(sum > accumulate(v.begin(), v.end(), ll(0))){
		cout << -1;
	}else if(sum == 0){
		cout << 0;
	}else{
		ll cur = 0;
		sort(v.begin(), v.end(), greater<ll>());
		while(sum > 0){
			sum -= v[cur];
			cur++;
			ans++;
		}
		cout << ans;
	}
    return 0;
}


Measured memory_bytes: 5288
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    string s;
    cin>>s;

    cout<<s[0]<<s[1]<<s[2]<<endl;




    return 0;
}


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

int main(){
	bool is_prime[1000000];
	
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
				}
			}
		}
		
	while(true){
			int n,count;
			count=0;
			cin>>n;
			if(n==0)
				break;
				
			for(int i=2;i<=(n/2);i++){
				if(is_prime[i]&&is_prime[n-i]){
					count++;
				}
			}		
		cout<<count<<endl;			
	}
		
		return 0;	
}	
					

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

int main() {
  long long n,a,b,c;
  cin>>n>>a>>b>>c;
  string st[n];
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    st[i]=s;
  }
  bool t=true;
  if(a+b+c>1){
  if(a==0&&b==0&&st[0]=="AB")t=false;
    else if(a==0&&c==0&&st[0]=="AC")t=false;
    else if(b==0&&c==0&&st[0]=="BC")t=false; 
    else{
      cout<<"Yes"<<endl;
      for(int i=0;i<n;i++){
        if(st[i]=="AB"){
          if(a==0){
            cout<<'A'<<endl;
            a++;
            b--;
          }
          else if(b==0){
            cout<<'B'<<endl;
            b++;
            a--;
          }
          else{
            if(st[i+1]=="BC"){
              cout<<'B'<<endl;
              b++;
              a--;
            }
            else{
              cout<<'A'<<endl;
              a++;
              b--;
            }
          }
        }
        if(st[i]=="BC"){
          if(b==0){
            cout<<'B'<<endl;
            b++;
            c--;
          }
          else if(c==0){
            cout<<'C'<<endl;
            c++;
            b--;
          }
          else{
            if(st[i+1]=="AC"){
              cout<<'C'<<endl;
              c++;
              b--;
            }
            else{
              cout<<'B'<<endl;
              b++;
              c--;
            }
          }
        }
        if(st[i]=="AC"){
          if(a==0){
            cout<<'A'<<endl;
            a++;
            c--;
          }
          else if(c==0){
            cout<<'C'<<endl;
            c++;
            a--;
          }
          else{
            if(st[i+1]=="BC"){
              cout<<'C'<<endl;
              c++;
              a--;
            }
            else{
              cout<<'A'<<endl;
              a++;
              c--;
            }
          }
        }
      }
    }
  }
  if(a+b+c==0)t=false;
  char ch[n];
  if(a+b+c==1){
    for(int i=0;i<n;i++){
      if(st[i]=="AB"){
        if(a==1){
          ch[i]='B';
          a=0;
          b=1;
        }
        else if(b==1){
          ch[i]='A';
          a=1;
          b=0;
        }
        else {
          t=false;
          break;
        }
      }
      if(st[i]=="BC"){
        if(c==1){
          ch[i]='B';
          c=0;
          b=1;
        }
        else if(b==1){
          ch[i]='C';
          c=1;
          b=0;
        }
        else {
          t=false;
          break;
        }
      }
      if(st[i]=="AC"){
        if(a==1){
          ch[i]='C';
          a=0;
          c=1;
        }
        else if(c==1){
          ch[i]='A';
          a=1;
          c=0;
        }
        else {
          t=false;
          break;
        }
      }
    }
    if(t){
      cout<<"Yes"<<endl;
      for(int i=0;i<n;i++){
        cout<<ch[i]<<endl;
      }
    }
  }
  if(!t)cout<<"No"<<endl;
}

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

#define ll long long

#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define fill(a,b) memset(a,b,sizeof(a))

#define f first
#define s second
#define pb push_back

#define inf 1e17
#define ninf -1*1e17
#define mod 1000000007
#define N 500005
#define Ns 5005

string s;
unsigned long long int n,m,o,x,y,z,d,k,l,r;


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int t=1;
	//cin>>t;
	while(t--){
	    
	    ll ans=0,a,b,c,d;
	    cin>>a>>b>>c>>d;
	    
	    ans= max( max(a*c,a*d),max(b*c,b*d));
	   // ans=(n==0);

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


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

int main(){
  int n,d[100];
  int r=1;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>d[i];
  }
  sort(d,d+n,greater<int>());
  for(int i=1;i<n;++i){
    if(d[i-1]>d[i])
      ++r;
  }
  cout<<r;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;
ll INF = 1e9+10;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
vector<pair<ll, ll> > pairs;

ll n, mod = 998244353;
const ll MAX = 1e7 + 1;
vector<ll> v(MAX);

ll inv[MAX];

int main()
{
    ll N;
    cin >> N;
    string S;
    cin >> S;
    
    if (N % 2 != 0){
        cout << "No";
        return 0;
    }
    rep(i,N/2){
        if (S[i] != S[i + N/2]){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;    
}


Measured memory_bytes: 78336
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll bur(ll N, ll X);


int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll X = 0;
	//ll T = 0;
	//ll M = 0;
	ll h[1000] = {};
	//ll b[100] = {};
	//ll c[100] = {};
	//ll d[100] = {};

	//ll v[3] = {};
	//ll *c, *s, *n;
	string S[50],T[50],U[52];
	ll count = 0;
	ll count2 = 0;
	float sum = 0;
	ll min = 1000000000000;
	ll max = 0;
	ll smax = 0;
	ll max2 = 0;
	ll smax2 = 0;
	int tmax = 0;
	int tmax2 = 0;
	//int flag = 0;
	char temp,head;
	//int is = 0;
	bool flag = false;
	
	//char p;

	ll all = 0;
	ll niku = 0;
	ll state = 2;
	bool down = true;
	

	//cin >> S;
	
	vector<pair<int,int>> ch(1000);
	
	

	cin >> N >> A >> B;

	rep(i, 0, N) {
		cin >> ch[i].first >> ch[i].second;
	}
		
	rep(i, 0, N) {

		if (A <= ch[i].first && B <= ch[i].second)
			count++;

	}


	cout << count << endl;

	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	
	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	//cin >> N >> M;

	//vector<pair<int,int>> c(M);
	////vector<pair<int, int>> e(M);
	//vector<ll> d(M);

	//rep(i, 0, M) {
	//	cin >> c[i].first >> c[i].second;
	//	//e[i].first = c[i].first;
	//	//e[i].second = c[i].second;

	//}
	////sort(c.begin(), c.end());

	//

	//rep(i, 0, M) {

	//	
	//	
	//	rep(j, 0, M) {
	//		if (c[i].first == c[j].first && c[j].second < c[i].second) {
	//			d[i]++;
	//			//cout << j << endl;
	//		}
	//	}
	//	cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
	//	cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 << endl;
	//}

	return 0;

}

ll bur(ll N,ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}



Measured memory_bytes: 256
import itertools

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

if P == Q:
    print(0)

else:
    M = [i for i in range(1, N+1)]
    X = list(itertools.permutations(M, N))

    for i in X:
        if list(i) == P:
            a = X.index(i) + 1
        if list(i) == Q:
            b = X.index(i) + 1

    print(abs(a - b))

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

using ll = long long;

int main() {
    int N, s = 0;
    cin >> N;
    vector<int> A(N + 1, 0);
    rep(i, N) {
        cin >> A[i + 1];
        s += abs(A[i + 1] - A[i]);
    }
    A.push_back(0);
    s += abs(A[N]);
    rep(i, N) {
        int ans = s - abs(A[i] - A[i + 1]) - abs(A[i + 1] - A[i + 2]) + abs(A[i] - A[i + 2]);
        cout << ans << "\n";
    }
}

Measured memory_bytes: 1656
#include <cstdio>

int main(void)
{
	int n;
	int i, j;
	int count, ct, k;
	int num[2][15];
	
	while (scanf("%d", &n), n){
		count = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &num[0][i]);
		}
		k = 0;
		while (1){
			for (i = 0; i < n; i++){
				ct = 0;
				for (j = 0; j < n; j++){
					if (num[k][i] == num[k][j]) ct++;
				}
				num[1 - k][i] = ct;
			}
			ct = 0;
			for (i = 0; i < n; i++){
				if (num[0][i] == num[1][i]) ct++;
			}
			if (ct == n){
				break;
			}
			k = 1 - k;
			count++;
		}
		
		printf("%d\n%d", count, num[0][0]);
		for (i = 1; i < n; i++){
			printf(" %d", num[0][i]);
		}
		printf("\n");
	}
	return (0);
}

Measured memory_bytes: 1032
def main():
    n, m = map(int, input().split())
    sc = [tuple(map(int, input().split())) for _ in range(m)]
    answer = -1
    lower_lim = 10 ** (n - 1)
    if n == 1:
        lower_lim = 0
    for i in range(lower_lim, 10 ** n):
        tmp = 0
        if not answer == -1:
            break
        for j in range(m):
            if str(i)[sc[j][0] - 1] == str(sc[j][1]):
                tmp += 1
        if tmp == m:
            answer = i
            break
    print(answer)


if __name__ == '__main__':
    main()



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

int main() {
  int N;
  cin >> N;
  vector<int> B(N - 1);
  for(int i = 0; i < N - 1; i++)
    cin >> B.at(i);
  int ans = B.at(0) + B.at(B.size() - 1);
  for(int i = 0; i < N - 2; i++) {
    ans += min(B.at(i), B.at(i + 1));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define INF 1000000007

ll dp[310][310][310];

int main(){
  ll n,K;
  cin>>n>>K;
  rep(i,0,310)rep(j,0,310)rep(k,0,310)dp[i][j][k] = 1000000000000000000LL;
  vector<ll> v;
  vector<ll> v1;
  v.pb(0);
  v1.pb(0);
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
    v1.pb(a);
  }
  sort(all(v1));
  map<ll,ll> ma;
  rep(i,0,v1.sz){
    ma[v1[i]] = i;
  }
  dp[0][0][0] = 0;
  rep(i,1,v.sz){
    ll h2 = v[i];
    rep(j,0,v1.sz){
      ll h1 = v1[j];
      rep(k,0,305){
        // use
        dp[i][ma[h2]][k] = min(dp[i][ma[h2]][k],dp[i-1][j][k]+max(0LL,h2-h1));
        // no use
        dp[i][ma[h1]][k+1] = min(dp[i][ma[h1]][k+1],dp[i-1][j][k]);
      }
    }
  }
  ll mn = 1000000000000000000LL;
  rep(i,0,310){
    rep(j,0,310){
      if(j<=K)mn = min(mn,dp[v.sz-1][i][j]);
    }
  }
  cout << mn << endl;
  return 0;
}

Measured memory_bytes: 232960
import sys
n=int(input())
a=list(map(int,input().split()))
ans=0
m=sum(a)
leaf=1
for i in range(n+1):
    ans+=leaf
    leaf=leaf-a[i]
    m-=a[i]

    if leaf<0 or (leaf==0 and m>0):
        print(-1)
        sys.exit()

    tmp=leaf
    for j in range(min(n-i,60)):
        tmp*=2
        if tmp>=m: break
    if tmp<m:
        print(-1)
        sys.exit()        

    if leaf*2>=m: leaf=m
    else: leaf*=2

print(ans)

Measured memory_bytes: 83524
n, k = map(int, input().split())
D = [0] * k
A = [0] * k
for i in range(k):
    D[i] = int(input())
    Atemp = [0] * D[i]
    Atemp = list(map(int, input().split()))
    A[i] = Atemp
    # print()
    # print(D)
    # print(A)
AA = []
for elem in range(k):
    AA += A[elem]
# print(AA)

AA = set(AA)
# print(AA)

# AA = []
# for i in range(k):
#     for j in range(k):
#         if j + 1 not in A[i]:
#             AA.append(j + 1)
#             print(AA)

print(n - len(AA))


Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;


struct Graph {
    Graph(const int n) : edge(n) {}
    void addEdge(const int from, const int to)
    {
        edge[from].push_back(to);
        edge[to].push_back(from);
    }
    vector<vector<int>> edge;
};

using P = pair<int, int>;
P dfs(const Graph& g, const int s, vector<int>& color, bool black = true)
{
    int b = 1;
    int w = 0;
    color[s] = (int)(black);
    for (const int to : g.edge[s]) {
        if (color[to] != -1) {
            if (black == color[to]) {
                return make_pair(-1, -1);
            }
            continue;
        }
        int sb, sw;
        tie(sw, sb) = dfs(g, to, color, not black);
        if (sw == -1) {
            return make_pair(-1, -1);
        }
        w += sw;
        b += sb;
    }
    return make_pair(b, w);
}

int main()
{
    ll V, E;
    cin >> V >> E;
    Graph g(V);
    for (int i = 0; i < E; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g.addEdge(a, b);
    }
    vector<int> div;
    vector<int> color(V, -1);
    for (int i = 0; i < V; i++) {
        if (color[i] != -1) {
            continue;
        }
        const auto p = dfs(g, i, color);
        if (p.first == -1) {
            cout << -1 << endl;
            return 0;
        }
        div.push_back(abs(p.first - p.second));
    }

    sort(div.begin(), div.end());
    vector<int> a = div;
    a.erase(unique(a.begin(), a.end()), a.end());
    vector<int> num(a.size());
    int pos = 0;
    for (int i = 0; i < a.size(); i++) {
        int n = 0;
        for (; pos < div.size(); pos++) {
            if (div[pos] == a[i]) {
                n++;
            } else {
                break;
            }
        }
        num[i] = n;
    }
    const int sum = accumulate(div.begin(), div.end(), 0);
    vector<int> dp(sum + 1, -1);
    const int size = a.size();
    dp[0] = 0;
    for (int i = 0; i < size; i++) {
        for (int j = 0; j <= sum; j++) {
            if (dp[j] >= 0) {
                dp[j] = num[i];
            } else if (j < a[i] or dp[j - a[i]] <= 0) {
                dp[j] = -1;
            } else {
                dp[j] = dp[j - a[i]] - 1;
            }
        }
    }
    constexpr ll INF = 1LL << 60;
    ll mini = INF;
    for (int i = 0; i <= sum; i++) {
        if (dp[i] > -1) {
            mini = min(mini, (ll)abs(i - (sum - i)));
        }
    }
    cout << ((V - mini) / 2) * ((V + mini) / 2) - E << endl;

    return 0;
}

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

using ll = long long;
const int mod = 1e9 + 7;

vector<vector<int>> mul(vector<vector<int>>& a, vector<vector<int>>& b) {
    int n = a.size();
    vector<vector<int>> ret(n, vector<int>(n));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            for(int k = 0; k < n; k++) {
                ret[i][j] += (ll)a[i][k]*b[k][j] % mod;
                ret[i][j] = ret[i][j] % mod;
            }
        }
    }
    return ret;
}

vector<vector<int>> my_pow(vector<vector<int>>& m, ll k) {
    int n = m.size();
    vector<vector<int>> ret(n, vector<int>(n));
    for(int i = 0; i < n; i++) {
        ret[i][i] = 1;
    }

    while(k >= 1) {
        if(k%2) {
            ret = mul(ret, m);
            k--;
        }
        k /= 2;
        m = mul(m, m);
    }
    return ret;
}

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<vector<int>> a(n, vector<int>(n));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> ansmat = my_pow(a, k);
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            ans += ansmat[i][j];
            if(ans > mod) {
                ans -= mod;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p)*(b))%m;
		b=((b)*(b))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	string s,t;
	cin>>s>>t;
	ll i=0;
	for(auto x:s)
	{
		if (x!=t[i++])
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
			cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 27068
import java.util.Scanner;
 
public class Main {
    // Making a static main function
    public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      int num = scanner.nextInt();
      
      if (num % 2 ==0) 
        System.out.println("0.5");
      else {
        System.out.println((float)((num / 2) + 1) / num);
      }     
    }
}


Measured memory_bytes: 21844
#include <cstdio>
using namespace std;

int main()
{
	int i = 1 , x;
	
	while (1){
		scanf("%d", &x);
		if (x == 0){
			break;
		}
		printf("Case %d: %d\n", i, x);
		i++;
	}
	
	return (0);
}

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

#define INF (1001001001)

int dx[8] = {0, 1, 0, -1, -1, 1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};

using namespace std;

int main()
{
	int n;
	int cnt = 0;

	scanf("%d", &n);

	while (n > 1){
		n = (n + 2) / 3;
		cnt++;
	}

	printf("%d\n", cnt);

	return (0);
}

Measured memory_bytes: 1172
import itertools
from collections import defaultdict
import collections
import math
import sys
import queue
sys.setrecursionlimit(200000)
mod = 1000000007

n, m = map(int, input().split())

graph = {i: [] for i in range(1, n + 1)}
for _ in range(m):
    u, v = map(int, input().split())
    graph[u].append(v)
    graph[v].append(u)

tf = [False] * (n + 1)
sirube = [0] * (n + 1)
def bfs(v):
    q = queue.Queue()
    q.put([v,0])
    tf[v] = True
    while not q.empty():
        sub = q.get()
        now = sub[0]
        before = sub[1]
        for next in graph[now]:
            if tf[next]:
                continue
            tf[next] = True
            if sirube[next] == 0:
                sirube[next] = now
            q.put([next, now])

bfs(1)
for i in range(2, n + 1):
    if sirube[i] == 0:
        print("No")
        exit()

print("Yes")
for i in range(2, n + 1):
    print(sirube[i])

Measured memory_bytes: 48232
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;



int main(){
 	int n, k, coun = 0;
 	cin >> n >> k;
 	ll point;
 	double ans = 0;
 	for (int i = 1; i <= n; i++){
 		point = i;
 		double temp = 0;
 		while (point < k){
 			temp++;
 			point *= 2;
 		}
 		ans += (double)pow(0.5, temp)/n;
 	}
 	cout << setprecision(10) << ans << endl;
 	return 0;
}


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

using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ign cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef map<int,int> MCI;
typedef unordered_map<int,int> UMII;
typedef unordered_map<char,int> UMCI;
typedef set<int> SI;
typedef long long int llint;

// Display Map
//~for (auto const& pair: m) {
//~std::cout << "{" << pair.first << ": " << pair.second << "}\n";
//~}

// Extract word(w) from sentence(s)
//~stringstream str(s);
//~string w;
//~while(str >> w){
//~// w is your word
//~}

//Memset Syntax
// memset(array, value,sizeof(array)) val is 0,-1 or bool only

// To get accurate precision
//~cout.precision(20);

int main() {
    fast_io;
    int x, y;
    cin >> x >> y;
    int d = x;
    int flag = 0;
    while(d >= 0) {
        if(d*4 + ((x-d)*2) == y) {
            cout << "Yes" << endl;
            flag = 1;
            break;
        }
        d--;
    }
    if(!flag) cout << "No" << endl;
 }


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	ll n;
	cin >> n;
	ll ans;
	for(ll i = 1; i * i <= n; i++){
		if(n % i != 0) continue;
		ll j = n/i;
		if(i == 1) ans = i+j-2;
		else ans = min(ans, i + j - 2);
	}
	cout << ans << endl;
	return 0;
}

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

bool binary_search(int A[], int n, int key) {
    int lo = 0;
    int hi = n - 1;
    while(lo + 1 < hi) {
        int mid = (lo + hi) / 2;
        if(A[mid] > key) {
           hi = mid;
        } else {
            lo = mid;
        }
    }
    if(A[lo] == key) {
        return true;
    } else return A[hi] == key;
}

int main() {
    int n;
    cin >> n;
    int S[n];
    for (int i = 0; i < n; ++i) {
        cin >> S[i];
    }
    int q;
    int count = 0;
    cin >> q;
    int t;
    for (int j = 0; j < q; ++j) {
        cin >> t;
        if(binary_search(S, n, t)){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3468
#include <string.h>

int W, a, b;
void solve() {
	int ans;
	if (a < b) {
		if ((b - (a + W)) < 0) {
			ans = 0;
		}
		else {
			ans = b - (a + W);
		}
	}
	else {
		if ((a - (b + W)) < 0) {
			ans = 0;
		}
		else {
			ans = a - (b + W);
		}
	}
	printf("%d\n", ans);
}
 
int main()
{
	// 標準入力から入力
	scanf("%d %d %d", &W, &a, &b);
	solve();
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  double a[N];
  double ans = 0.0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    ans += 1.0 / a[i];
  }
  
  ans = 1.0 / ans;
   cout << fixed << setprecision(10) << ans << endl;
}

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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

ll A, P;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> A >> P;
  cout << (A*3+P)/2 << endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+5;
int a[N],b[N],p=0,i;
int main()
{
    int a,b;
    cin>>a>>b;
    if((a+b)%2)
    {
        cout<<"IMPOSSIBLE"<<endl;
    }
    else cout<<(a+b)/2<<endl;
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n;
  cin >> n;
  vector<int> x(n), x2(n);
  rep(i,n)
  {
    cin >> x[i];
    x2[i] = x[i];
  }
  sort(x2.begin(), x2.end());
  int a = x2[n / 2];
  int b = x2[n / 2 - 1];
  rep(i,n)
    cout << (x[i] >= a ? b : a) << endl;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <cmath>

using namespace std;

int v[105];

int main()
{
    int n, ans=0, cost=0;

    scanf("%d",&n);

    for(int i=1; i<=n; i++)
    {
        scanf("%d", &v[i]);
        ans += v[i];
    }

    ans = round((double)ans/n);

    for(int i=1; i<=n; i++)
        cost += (ans-v[i])*(ans-v[i]);

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


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

int main(void){
    long long h, w;
    cin >> h >> w;
    
    if(h % 3 == 0 || w % 3 == 0){
        cout << 0 << endl;
        return 0;
    }
    
    long long ans = min(h, w);
    
    long long b1, b2, b3, b4;
    long long i, j;
    for(i = h / 3; i < h / 2 + 1; i++){
        for(j = w / 3; j < w / 2 + 1; j++){
            b1 = i * j;
            b2 = i * (w - j);
            b3 = (h - i) * j;
            b4 = (h - i) * (w - j);
            
            b1 += min(b2, b3);
            
            if(max(b1, b4) - min(b1, max(b2, b3)) < ans){
                ans = max(b1, b4) - min(b1, max(b2, b3));
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int a,b;
    double a_d,b_d;
    cin >> a >> b;
    a_d = a;
    b_d = b;
    //cout << a/b << " " << a%b << " " << (double)a/b << endl;
    printf("%d %d %.5f\n",a/b,a%b,a_d/b_d);
}


Measured memory_bytes: 3224
loop{
  n=gets.to_i
  if n == 0 then 
    break
  end
  hash=Hash.new("none")
  n.times do
    str=gets.chop.split(" ").map{|buf| buf.to_i}
    if hash.key?(str[0]) then 
      hash[str[0]]+=str[1]*str[2]
      else
      hash[str[0]]=str[1]*str[2]
    end
  end
  i=0
  hash.each {|key,value|
    if value >=  1_000_000 then
      puts(key)
      i+=1
    end

  }
  if i == 0 then 
    puts("NA")
  end
}

Measured memory_bytes: 6104
#include<stdio.h>
#include<stdlib.h>

int main(void){

  long long a,b,c,d,x,y,tmp,sum;
  long long all;
  long long i;
  long long gomi=0;
  long long ans;

  long long gcd,lcm;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
  all=b-a+1;
  /*for(i=a;i<=b;i++){
    if(i%c==0||i%d==0)
    gomi++;

  }
  ans=all-gomi;
  printf("%lld",ans);
  */

  //ｃとｄの最小公倍数を求める。
  x=c;
  y=d;
  if(x<y){
    tmp=x;
    x=y;
    y=tmp;
  }
gcd=y;//ワイが小さいほう
  while(1){

    tmp=x%y;
    if(tmp==0){
      gcd=y;
      break;
    }
    else{
      x=y;
      y=tmp;
    }
  }
  lcm=(c*d)/gcd;
//  printf("%d",lcm);

long long csum,dsum,sumlcm;

  csum=b/c-a/c;
  if(a%c==0){
    csum=csum+1;
  }

  dsum=b/d-a/d;
  if(a%d==0){
    dsum=dsum+1;
  }


  sumlcm=b/lcm-a/lcm;
  if(a%lcm==0)
  sumlcm=sumlcm+1;

  ans=all-(csum+dsum-sumlcm);
  printf("%lld",ans);





  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A ,B;
    cin >> A >> B;
    if (A >= 13){
        cout << B << endl;
    }
    else if (6 <= A and A <= 12){
        cout << B/2 << endl;
    }
    else {
        cout << 0 << endl;
    }
}

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

int n, m;
vector<int> r;
vector<int> l;

int main() {
    cin >> n >> m;
    r.resize(m);
    l.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> l.at(i) >> r.at(i);
    }

    int cl = l.at(0), cr = r.at(0);

    for (int i = 1; i < m; ++i)
    {
        if (cl < l.at(i))
        {
            cl = l.at(i);
        }

        if (r.at(i) < cr)
        {
            cr = r.at(i);
        }        
    }

    if (cl <= cr)
    {
        cout << cr-cl+1 << endl;
    } else {
        cout << 0 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int a, b;
    cin >> a >> b;
    int c = a*b;


    cout << c << endl;
}

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

class Solver{
	Scanner sc =new Scanner(System.in);
	
	void run(){
		
		int n = sc.nextInt();
		int a[] = new int[n];
		
		for(int i =0 ; i < n ; i++){
			a[i] = sc.nextInt();
		}
		
		Arrays.sort(a);
		int t = a[n-1];
		int minMax = 0;
		int u = 0;
		for(int i = 0 ; i < n;i++){
			if(minMax < Math.min(a[i],t-a[i])){
				minMax = Math.min(a[i],t-a[i]);
				u = i;
			};
		}
		
		System.out.println(t+" "+a[u]);
		
		
	}
}

public class Main {
	public static void main(String[] args){
		Solver s  = new Solver();
		s.run();
	}
}



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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int i=0;
  while(A>0&&C>0){
    C-=B;
    i++;
    if(C>0){
      A-=D;
      i++;
    }
  }
  if(i%2==0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  
}


Measured memory_bytes: 3636
use std::io;
use std::io::prelude::*;

fn main() {
    let mut s = String::new();
    let _ = io::stdin().read_to_string(&mut s).unwrap();
    let v: Vec<&str> = s.split('\n').collect();
    let r = v[0].parse::<f64>().unwrap();
    let ans = 3.0*r*r;
    println!("{}", ans);
}


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

using namespace std;

typedef long long ll;

#define int_max 100000

void print(vector<int> &A) {
	for (int i = 0; i < A.size(); i++)
		printf("%d ", A[i]);
	printf("\n");
}

void print_matrix(vector< vector<int> > &m) {
	for (int i = 0; i < m.size(); i++)
		print(m[i]);
}

void print_char(vector<char> &A) {
	for (int i = 0; i < A.size(); i++)
		printf("%c ", A[i]);
	printf("\n");
}

void print_matrix_char(vector< vector<char> > &m) {
	for (int i = 0; i < m.size(); i++)
		print_char(m[i]);
}

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

	vector< vector<int> > A(n, vector<int>(m));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			if (c == '#')
				A[i][j] = 0;
			else
				A[i][j] = int_max;
		}


	// left - right
	for (int i = 0; i < n; i++) {
		int cnt_left = int_max;
		int cnt_right = int_max;
		for (int j = 0; j < m; j++) {
			cnt_left = min(cnt_left + 1, A[i][j]);
			A[i][j] = min(A[i][j], cnt_left);

			cnt_right = min(cnt_right + 1, A[i][m - 1 - j]);
			A[i][m - 1 - j] = min(A[i][m - 1 - j], cnt_right);
		}
	}

	// down - up
	for (int i = 0; i < m; i++) {
		int cnt_down = int_max;
		int cnt_up = int_max;
		for (int j = 0; j < n; j++) {
			cnt_down = min(cnt_down + 1, A[j][i]);
			A[j][i] = min(A[j][i], cnt_down);

			cnt_up = min(cnt_up + 1, A[n - 1 - j][i]);
			A[n - 1 - j][i] = min(A[n - 1 - j][i], cnt_up);
		}
	}

	// print_matrix(A);

	int ans = 0;
	for (int i = 0; i < A.size(); i++)
		for (int j = 0; j < A[i].size(); j++)
			ans = max(ans, A[i][j]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4224
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>

using namespace std;
using ll = long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;







int main(){
    string s;
    getline(cin, s); 
    int n = s.size();
    
    int f = s[0] - '0';
    
    vector<int> prev(2019,0);
    vector<int> next(2019,0);
    
    prev[f] = 1;
    
    int sum = 0;
    for(int i = 1; i < n;i++){
        int c = s[i] - '0';
        next = vector<int> (2019,0);
        next[c] = 1;
        for(int j = 0; j< 2019; j++){
            
            
            int count = prev[j];
            
            if (j==0){
                sum += count;
            }
            
            int nt = (10*j+c)%2019;
            next[nt] += count;
        }
        prev = next;
    }
    // cout << n << endl;
    // cout << prev.size() << endl;
    sum += prev[0];
    cout << sum;

}









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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll N, M;
    cin >> N >> M;
    vecll L(M), R(M);
    for( ll i = 0; i < M; i++) cin >> L.at(i) >> R.at(i);

    ll  maxL = L.at(0), minR = R.at(0);
    for(ll i = 0; i < M; i++){
        if(maxL < L.at(i)) maxL = L.at(i);
        if(minR > R.at(i)) minR = R.at(i);
    }
    ll ans = minR - maxL + 1;
    cout << (ans >= 0 ? ans : 0) << endl;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n;cin>>n;
  ll a[n][3];
  rep(i,0,n)rep(j,0,3)cin>>a[i][j];

  ll dp[n][3];
  rep(j,0,3)dp[0][j]=a[0][j];

  rep(i,1,n){
    rep(j,0,3){
      dp[i][j]=a[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
    }
  }

  out(max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}));

  return 0;
}


Measured memory_bytes: 4992
#!/usr/bin/env python3

import sys

def answer(n, x, ms):
    sum = 0
    minM = 1000
    for m in ms:
        sum += m
        if m < minM:
            minM = m
    add = (x - sum) // minM
    return n + add

def main():
    firstLine = sys.stdin.readline()
    [str_n, str_x] = firstLine.split(' ')
    n = int(str_n)
    x = int(str_x)
    ms = []
    for line in sys.stdin:
        ms.append(int(line.rstrip()))
    print(answer(n, x, ms))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
total = 0
for i in range(n + 1):
    total += abs(a[i + 1] - a[i])
for i in range(n):
    diff = abs(a[i + 1] - a[i]) + abs(a[i + 2] - a[i + 1]) - abs(a[i + 2] - a[i])
    print(total - diff)

Measured memory_bytes: 13920
#include<cstdio>
#include<cmath>
#include<algorithm> 
using namespace std;
int n,a[100010],f[100010];
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  a[0]=2e9;
  for(int i=2;i<=n;i++){
    f[i]=min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));
  }
  printf("%d",f[n]);
}

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

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};

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

const ll mod=998244353;
const int INF=INT_MAX/2;
const int N_MAX=300010;

ll fact[N_MAX];
ll finv[N_MAX];

ll mul(ll x, ll y){
	return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
	ll res=1LL;
	while(y){
		if(y&1LL){
			res*=x;
		}
		res%=mod;
		x=(x*x)%mod;
		y>>=1LL;
	}
	return res;
}
ll divll(ll x,ll y){
	return (x*powll(y,mod-2))%mod;
}

ll nPr(ll n,ll r){
	if(n<r || r<0)return 0;
	return mul(fact[n],finv[n-r]);
}

ll nCr(ll n, ll r){
	if(n<r || r<0)return 0;
	return mul(mul(fact[n],finv[r]),finv[n-r]);
}

ll A,B,N,K;
int main(){
	ll cnt=0;
	cin>>N>>A>>B>>K;
	fact[0]=finv[0]=1;
	for(int i=1;i<=N;i++){
		fact[i]=(fact[i-1]*i)%mod;
		finv[i]=divll(finv[i-1],i);
	}
	for(ll a=0;a<=N;a++){
		if((K-A*a)%B==0){
			ll b=(K-A*a)/B;
			cnt+=(nCr(N,a)*nCr(N,b))%mod;
			cnt%=mod;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  string s;
  if(abs(a-b)<3) s = "Yay!";
  else s = ":(";
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

a = int(arr_data[0][0])
b = int(arr_data[0][1])


if (a == 1 and b != 1):
    
    print("Alice")
    
elif (a != 1 and b == 1):
    
    
    print("Bob")
    
elif a > b:
    
    
    print("Alice")
    
elif a < b:
    
    print("Bob")
    
else:
    
    print("Draw")
    
    
    

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



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w, a, b;
    cin >> w >> a >> b;

    if (a > b)
        swap(a, b);

    if (b > (a+w)) {
        cout <<  b - a - w << endl;
    } else if (b <= (a+w)) {
        cout << 0 << endl;
    }

    return 0;
}



Measured memory_bytes: 256
N = int(input())
S = dict()
for i in range(N):
    s = input()
    if s in S:
        S[s] += 1
    else:
        S[s] = 1

max_val = max(S.values())
max_key = [key for key in S if S[key] == max_val]
print("\n".join(sorted(max_key)))


Measured memory_bytes: 34140
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	if(a >= k) cout << k << endl;
	else if(a + b >= k) cout << a << endl;
	else cout << a - (k - a - b) << endl;
	return 0;
}

Measured memory_bytes: 3652
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

signed main(void)
{
  string s;
  int n, a, b;
  cin >> n >> a >> b >> s;

  int all = 0, f = 0;
  REP(i, n) {
    if(s[i] == 'a') {
      if(all < a+b) {
        all++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
    if(s[i] == 'b') {
      if(all < a+b && f < b) {
        all++;
        f++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
    if(s[i] == 'c') {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 896