akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int n;

	void run(){
		int q=sc.nextInt();
		for(int i=0; i<q; i++){
			n=sc.nextInt();
			solve();
		}
	}

	void solve(){
		int step;
		for(step=0; n>=10; step++){
			String s=n+"";
			n=0;
			for(int i=1; i<s.length(); i++){
				int p=Integer.parseInt(s.substring(0, i));
				int q=Integer.parseInt(s.substring(i, s.length()));
				n=max(n, p*q);
			}
		}
		println(step+"");
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AtCoder
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            double result = 0;

            // 整数の入力
            long n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; ++i) {
                var m = n - i;

                double x = Math.Sqrt((double)m);
                if (x == (int)x) {
                    result = m;
                    break;
                }
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 18484
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>

using namespace std;

int main()
{
  int A[3][3];
  bool hit[3][3];
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j)
    {
      cin >> A[i][j];
      hit[i][j] = false;
    }

  int N;
  cin >> N;

  for (int i = 0; i < N; ++i)
  {
    int b;
    cin >> b;

    for (int j = 0; j < 3; ++j)
      for (int k = 0; k < 3; ++k)
      {
        if (A[j][k] == b) hit[j][k] = true;
      }
  }

  for (int i = 0; i < 3; ++i)
  {
    if      (hit[i][0] == true && hit[i][1] == true && hit[i][2] == true) break;
    else if (hit[0][i] == true && hit[1][i] == true && hit[2][i] == true) break;
    else if (hit[0][0] == true && hit[1][1] == true && hit[2][2] == true) break;
    else if (hit[0][2] == true && hit[1][1] == true && hit[2][0] == true) break;

    if (i == 2)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

vector<bool> seen;
vector<int> p, sum;
void dfs(vector<vector<int>> &g, int v, int &ptr) {
    seen[v] = true;
    ptr += p[v];
    sum[v] += ptr;
    for (auto now : g[v]) {
        if (seen[now])
            continue;
        dfs(g, now, ptr);
    }
    ptr -= p[v];
}
int main() {
    int n, q, a, b;
    cin >> n >> q;
    vector<vector<int>> u(n);
    p.assign(n, 0);
    seen.assign(n, false);
    sum.assign(n, 0);
    rep(i, n - 1) {
        cin >> a >> b;
        u[a - 1].push_back(b - 1);
        u[b - 1].push_back(a - 1);
    }
    rep(i, q) {
        cin >> a >> b;
        p[a - 1] += b;
    }
    int ptr = 0;
    dfs(u, 0, ptr);
    rep(i, n) {
        cout << sum[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 28344
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	int n;
	sd(n);
	ll S[2001]={0};
	for(int i=3;i<2001;i++){
		S[i]=1;
		for(int j=3;j<=i-3;j++){
			S[i]=(S[i]+S[j])%MOD;
		}
	}
	cout<<S[n];
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  sort(begin(a), end(a));
  int sum = accumulate(begin(a), end(a), 0) - a.back();
  cout << (a.back() < sum ? "Yes" : "No") << '\n';
}

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

#define print(x) cerr << #x << " is " << x << endl;
#define int long long int
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define all(v) (v).begin(), (v).end()   
#define pii pair<int, int>
#define pb push_back
#define PI 3.1415926535897932384626
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define out cout << fixed << setprecision(12) <<

const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const double lifeofpi = acos(-1);


int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int k;
    cin >> k;
    string s;
    cin >> s;
    if(s.size() > k){
        for(int i = 0; i < k; ++i){
            cout << s[i];
        }
        cout << "...\n";
    }
    else{
        cout << s << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

ll gcd(ll a, ll b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

vector<ll> enum_div(ll n){//nの約数を列挙
  vector<ll> ret;
  for(ll i=1 ; i*i<=n ; ++i){
    if(n%i == 0){
      ret.push_back(i);
      if(i!=1 && i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  sort(ret.begin(),ret.end());
  return ret;
}

bool is_prime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
  ll a,b; cin >> a >> b;
  ll g = gcd(a,b);
  vector<ll> c = enum_div(g);
  c.push_back(g);
  
//  for(auto c1:c){
//    cout << c1 << " ";
//  }
//  cout << endl;
  ll ans = 0;
  for(int i = 0; i < c.size(); i++){
    if(is_prime(c[i])) ans++;
  }
  
  cout << ans+1 << endl;
  
  return 0;
}

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

namespace AGC023_B___Find_Symmetries
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static long solver()
        {
            var N = int.Parse(Console.ReadLine());
            var baseBoard = new int[N, N];
            for (int i = 0; i < N; i++)
            {
                var read = Console.ReadLine();
                for (int j = 0; j < N; j++) baseBoard[i, j] = read[j] - 'a';
            }

            var count = 0;
            for (int offset = 0; offset < N; offset++)
            {
                var offsetBoard = new int[N, N];
                for (int h = 0; h < N; h++) for (int w = 0; w < N; w++) offsetBoard[h, (w + offset) % N] = baseBoard[h, w];
                var isSymmetry = true;
                for (int h = 0; h < N; h++)
                {
                    for (int w = h; w < N; w++)
                    {
                        if (offsetBoard[h, w] != offsetBoard[w, h])
                        {
                            isSymmetry = false;
                            break;
                        }
                    }
                    if (!isSymmetry) break;
                }
                if (isSymmetry) count++;
            }
            return count * N;
        }
    }
}


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

int main() {
  
  int H, W;
  cin >> H >> W;
  vector<vector<char>> a(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a.at(i).at(j);
    }
  }
  
  vector<bool> isWhiteRow(H, true);
  vector<bool> isWhiteColumn(W, true);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a.at(i).at(j) == '#') {
        isWhiteRow.at(i) = false;
        break;
      }
    }
  }
  for (int j = 0; j < W; j++) {
    for (int i = 0; i < H; i++) {
      if (a.at(i).at(j) == '#') {
        isWhiteColumn.at(j) = false;
      }
    }
  }
/*  for (int i = 0; i < H; i++) {
    cout << "isWhiteRow.at(i) = " << isWhiteRow.at(i) << endl;
  }
  for (int j = 0; j < W; j++) {
    cout << "isWhiteColumn.at(j) = " << isWhiteColumn.at(j) << endl;
  }
*/  
  for (int i = 0; i < H; i++) {
    if (isWhiteRow.at(i)) continue;
    for (int j = 0; j < W; j++) {
      if (isWhiteColumn.at(j)) continue;
      cout << a.at(i).at(j);
    }  
    cout << endl;
  }   
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;

int main() {
  FAST();
  ll n, x;
  cin >> n;
  string ans = "";
  while(n > 0) {
    x = (n - 1) % 26;
    ans += (char)(x + 'a');
    n = (n - x - 1) / 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3584
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	string s; cin >> s;
	if (s[0] == 'S') {
		if (s[1] == 'U')print(7);
		else if (s[1] == 'A')print(1);
	}
	else if (s[0] == 'T') {
		if (s[1] == 'U')print(5);
		else if (s[1] == 'H')print(3);
	}
	else if (s[0] == 'W') print(4);
	else if (s[0] == 'M')print(6);
	else if (s[0] == 'F')print(2);






	return 0;
}


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

int main(void){
    
    int sum = 0;
    vector<int> data(3);
    
    for(int i=0;i < 3; i++){
        cin >> data.at(i);
    }    
    
    for(int i = 0 ; i < 3 ; i++){
        if(data.at(i) != (5 || 7)){
        }
        sum = sum + data.at(i);
        
    }
    
    if(sum == (5 + 7 + 5)){
    cout << "YES" << endl;
    }

    else{
    cout << "NO" << endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  int count=1;
  int max = h[0];
  for(int j = 1; j < n; j++) {
    if(max <= h[j]){
      count++;
      max = h[j];
    }
  }
  cout << count;
  return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 3041.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, q;
  scanf("%d%d", &n, &q);

  int h = 0;
  while (q--) {
    int op, k;
    scanf("%d%d", &op, &k);

    if (op == 0) {
      k--;
      printf("%d\n", (h + k) % n + 1);
    }
    else
      h = (h + k) % n;
  }
  return 0;
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n, v) rep(i, n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1, 0, -1, 0}, y_pos[4] = {0, 1, 0, -1};
int ctoi(char c)
{
	if (c >= '0' && c <= '9')
	{
		return c - '0';
	}
	return 0;
}

char upper(char c)
{
	return c - 0x20;
}

char lower(char c)
{
	return c + 0x20;
}

void unique_vector(vector<int> &v)
{
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
	std::fill((T *)array, (T *)(array + N), val);
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y)
{
	if (y == 0)
		return x;
	return gcd(y, x % y);
}

//最小公倍数
ll lcm(ll x, ll y)
{
	ll g = gcd(x, y);
	return x / g * y;
}

ll myPow(ll x, ll n, ll m)
{
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

//素因数分解
map<ll, ll> prime_factor(ll n)
{
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++)
	{
		while (n % i == 0)
		{
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1)
		ret[n] = 1;
	return ret;
}

int main()
{
	ll n, k;
	cin >> n >> k;
	cout << min(n % k, k - n % k) << endl;
}


Measured memory_bytes: 256
// Problem : B - Multiplication 2
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 1e18;
const int N = 5e5+5;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		int arr[n];
		int x = 1;
		bool flag = true;
		for(int i=0;i<n;++i)
		{
			cin>>arr[i];
			if(arr[i]==0)
			flag = false;
			
		}
		if(!flag)
		{
			cout<<0;
			return 0;
		}
		for(int i=0;i<n;++i)
		{
			if(arr[i]>(inf/x))
			{
				cout<<-1;
				return 0;
			}
			x*=arr[i];
		}
		cout<<x;
		    	
    }
    return 0;
}


Measured memory_bytes: 4416
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, K;
    cin >> n >> K;
    vector<P> d;
    vector<int> x;
    vector<int> y;
    // map<int, vector<int> > mpx;
    // map<int, vector<int> > mpy;
    rep(i, 0, n){
        int ix, iy;
        cin >> ix >> iy;
        d.push_back(P(ix, iy));
        x.push_back(ix);
        y.push_back(iy);
        // mpx[ix].push_back(iy);
        // mpy[iy].push_back(ix);
    }
    sort(all(x));
    sort(all(y));
    int MIN = 4 * 1e18 + 10;
    rep(i, 0, n){
        rep(j, i + 1, n){
            rep(k, 0, n){
                rep(l, k + 1, n){
                    int cnt = 0;
                    rep(m, 0, n){
                        if(x[i] <= d[m].first && d[m].first <= x[j] && y[k] <= d[m].second && d[m].second <= y[l]){
                            cnt++;
                        }
                    }
                    if(cnt >= K){
                        int s = (x[j] - x[i]) * (y[l] - y[k]);
                        if(s < MIN){
                            MIN = s;
                            // cout << x[i] << " " << x[j] << " " <<y[k] << " " << y[l] << endl;
                        }
                    }
                }
            }
        }
    }
    cout << MIN << endl;
}

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

using namespace std;

string S;
int ans;

int main()
{
    cin >> S;

    ans = 0;
    for (int i = 0; i < S.length() / 2; i++)
        if (S[i] != S[S.length() - 1 - i]) ans++;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mo=1e9+7;
const int maxn=1e5+10;
int h[maxn];
LL f[maxn];
long long gcd(long long a,long long  b,long long &x,long long &y){
  if (b==0){
    x=1;y=0;
    return a;
  } else {
    long long r=gcd(b,a%b,y,x);
    y-=x*(a/b);
    return r;
  }
}
long long sol(long long a,long long b,long long n){
  long long x,y;
  long long d=gcd(a,n,x,y);
  x%=n;x+=n;x%=n;
  return x*(b/d)%(n/d);
}
LL c(LL n,LL m){
   if (m>n) return 0;
   return ((f[n]*sol(f[m],1,mo))%mo*sol(f[n-m],1,mo))%mo;
}
int main()
{
    int n,i,x,r;
    f[0]=1;
    for (i=1;i<maxn;i++) f[i]=(f[i-1]*i)%mo;
    while (scanf("%d",&n)!=-1){
      for (i=1;i<=n;i++) h[i]=0;
      for (i=1;i<=n+1;i++){
        scanf("%d",&x);
        if (h[x]) r=n+1-(i-h[x]+1);
        h[x]=i;
      }
      for (i=1;i<=n+1;i++){
        printf("%lld\n",(c(n+1,i)-c(r,i-1)+mo)%mo);
      }
    }
    return 0;
}


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

template<long long modulus>
class ModInt{
    long long num;

    long long mod(long long n){
        if(n < 0LL){
            n += (abs(n + 1LL) / modulus + 1LL) * modulus;
        }
        return n % modulus;
    }

    long long ext_gcd(long long a, long long b, long long &x, long long &y){
        if(b == 0LL){
            x = 1;
            y = 0;
            return a;
        }

        long long d = ext_gcd(b, a % b, y, x);
        y -= a / b * x;

        return d;
    }

    long long get_inv(long long n){
        long long x, y;
        ext_gcd(n, modulus, x, y);
        return mod(x);
    }

public:
    ModInt(long long n = 0LL){
        init(n);
    }

    void init(long long n = 0LL){
        num = mod(n);
        return;
    }

    long long get(void){
        return num;
    }

    ModInt &operator+=(const ModInt &rhs){
        num += rhs.num;
        if(num >= modulus){
            num -= modulus;
        }
        return *this;
    }

    ModInt &operator-=(const ModInt &rhs){
        num -= rhs.num;
        if(num < 0LL){
            num += modulus;
        }
        return *this;
    }

    ModInt &operator*=(const ModInt &rhs){
        num = num * rhs.num % modulus;
        return *this;
    }

    ModInt &operator/=(const ModInt &rhs){
        long long inv = get_inv(rhs.num);
        num = num * inv % modulus;
        return *this;
    }

    ModInt operator+(const ModInt &rhs) const {
        return ModInt(*this) += rhs;
    }

    ModInt operator-(const ModInt &rhs) const {
        return ModInt(*this) -= rhs;
    }

    ModInt operator*(const ModInt &rhs) const {
        return ModInt(*this) *= rhs;
    }

    ModInt operator/(const ModInt &rhs) const {
        return ModInt(*this) /= rhs;
    }

    ModInt &operator=(const ModInt &rhs){
        num = rhs.num;
        return *this;
    }

    bool operator<(const ModInt &rhs) const {
        return num < rhs.num;
    }
};

template<long long modulus>
istream &operator>>(istream &lhs, ModInt<modulus> &rhs){
    long long val;
    lhs >> val;
    rhs.init(val);
    return lhs;
}

template<long long modulus>
ostream &operator<<(ostream &lhs, ModInt<modulus> &rhs){
    lhs << rhs.get();
    return lhs;
}

using mint = ModInt<1000000007LL>;

int main(){
    int k, s;
    cin >> k >> s;
    int n = 3;

    vector<mint> fact(s + n + 1);
    fact[0] = mint(1);
    for(int i = 1 ; i <= s + n ; ++i){
        fact[i] = fact[i - 1] * mint(i);
    }

    vector<mint> inv(s + n + 1);
    inv[s + n] = mint(1) / fact[s + n];
    for(int i = s + n ; i > 0 ; --i){
        inv[i - 1] = inv[i] * mint(i);
    }

    mint ans;
    for(int i = 0, sign = 1 ; i <= n && i * (k + 1) <= s ; ++i, sign = -sign){
        ans += mint(sign) * (fact[n] * inv[i] * inv[n - i]) * (fact[s - i * (k + 1) + n - 1] * inv[s - i * (k + 1)] * inv[n - 1]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


N = read()[:-1]
if sum(map(int, list(N))) % 9 == 0:
    print('Yes')
else:
    print('No')


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
//#define ll __int128
//#define int ll
//#define int ll
//#define char ll
#define double ld
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
//#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T0, class T1>
inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template<class T0, class T1>
inline istream &operator>>(istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template<class T0, class T1, class T2>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template<class T0, class T1, class T2, class T3>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " << get<3>(a) << "}";
}

template<class T>
inline ostream &operator<<(ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\nTOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


void smain() {
    ll x;
    cin >> x;
    ll lcm = x * 360 / __gcd(x, 360LL);
    cout << lcm / x;
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;

int main() {

	int N, K, X, Y;
	cin >> N >> K >> X >> Y;

	int res;
	if (K < N) {
		res = X*K + Y*(N - K);
	}
	else {
		res = X*N;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin>>s;
  vector<int>vec(s);
  for(int i=0;i<s;i++){
    cin>>vec[i];
  }
  sort(vec.begin(),vec.end());
  int sum=0;
  for(int i=0;i<s;i++){
    sum+=vec[i];
  }
  cout<<sum-vec[s-1]/2<<endl;
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    vector<int> a(n+1);
    for(int i=0;i<n;i++) {
        cin >> a.at(i);
    }
    a.at(n) = a.at(0);

    int ans = 1e7;

    int d;
    for(int i=0;i<n;i++) {
        d = a.at(i) - a.at(i+1);
        if(d<0) d += k;
        ans = min(ans, d);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include <numeric>
#include<cmath>
#include<string>
using namespace std;
#define ll long long

int main(void){
    string s;
    cin >> s;
    int zero = count(s.begin(),s.end(),'0');
    int one = count(s.begin(),s.end(),'1');
    if(zero<one){
        cout << zero*2<<endl;
    }else{
        cout << one*2 << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int n;
bool prime(int p){
	if(p==1)return false;
	if(p==57)return true;
	for(int i=2;i<=sqrt(p);i++){
		if(p%i==0)return false;
	}
	return true;
}
int main(){
	cin>>n;
	int c=0;
	for(int i=6;c<n;i+=5){
		if(prime(i)){
			cout<<i<<" ";
			c++;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int n,A[26],i,j,k;
long long ans;
int main() {
	cin>>s;
	n=s.size();
	for(i=0;i<n;i++) {
		A[s[i]-'a']++;
	}
	ans=1LL*n*(n-1)/2;
	for(i=0;i<26;i++) {
		if(A[i]>1) {
			ans-=1LL*A[i]*(A[i]-1)/2;
		}
	}
	cout<<ans+1<<endl;
}

Measured memory_bytes: 640
def main():
    r, d, x = map(int, input().split())
    gram_list = [x]

    for i in range(10):
        gram = gram_list[i]*r - d
        gram_list.append(gram)
        #print(gram)

    set(gram_list)
    for i in range(10):
        print(gram_list[i+1])

main()


Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <map>

#define int long long

using namespace std;


class Solver {

};

signed main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		map<int, int> vals;
		for (int i = 0; i < n; i++) {
			int id, m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int val = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
			vals.emplace(val,id);
		}

		int itr = 0;
		for (auto val : vals) {
			if (itr == 0 || itr == 1 || itr == vals.size() - 2) {
				cout << val.second << endl;
			}
			itr++;
		}
	}

}


Measured memory_bytes: 3388
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string a,b;
    cin>>a>>b;
    string s=a+b;
    int x=stoi(s);
    bool ok=false;
    rep(i,10000){
        if(i*i==x)ok=true;
    }
    cout<<(ok?"Yes":"No")<<endl;
    return 0;
}

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

#define ll long long
#define ld long double
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    ll n;
    cin >> n;
    ll a[n] = {};
    map<ll, ll> mp;
    for(int i = 0; i<n; i++) {
        cin >> a[i];
        mp[a[i]] ++;
    }
    ll sum = 0;
    for(auto it: mp) {
        ll x = mp[it.first];
        sum += (x * (x-1))/2;
    }
    for(int i = 0; i<n; i++) {
        ll curr = mp[a[i]];

        ll prev = (curr * (curr-1))/2;
        curr --;
        ll now = (curr * (curr-1))/2;

        ll sub = prev - now;
        cout << sum -sub << '\n';
    }
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 11136
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();  
        int M, limit, max = 1;
        {int[] a = r.ii(); M = a[1]; limit = M/a[0];}
        for(int i = 1; i*i < M+1; i++){
            if(M%i == 0){
                if(i <= limit) max = i;
                else break;
                int pair = M/i;
                if(pair <= limit){
                    max = pair;
                    break;
                }
            }
        }
        print(max);
    }

    static void print(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int Int(String s){
            return Integer.parseInt(s);
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 22612
N=int(input())
xy=[[-1]*N for i in range(N)]
count=0
for i in range(N):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        xy[i][x-1]=y
for i in range(1<<N):
    honest=[0]*N
    for j in range(N):
        if (i>>j)&1:
            honest[j]=1
    flag=True
    for j in range(N):
        if honest[j]:
            for k in range(N):
                if xy[j][k]==-1:
                    continue
                if xy[j][k]!=honest[k]:
                    flag=False
    if flag:
        count=max(count,honest.count(1))
print(count)

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if(a == b + c || b == c + a || c == a + b){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
H, W = map(int, input().split())

def getMinDiff(A, B):
    if A % 3 == 0:
        return 0
    elif B % 2 == 0:
        return B // 2
    else:
        ans = B # 横3段に分ける場合の値

        # T字型に分ける場合
        for i in range(A % 3 + 1):
            A1 = A // 3 + i # 上半分の縦幅
            B1, B2 = B // 2, (B + 1) // 2 # 下半分の左側、右側の横幅
            Ss = [A1 * B, (A - A1) * B1, (A - A1) * B2]
            ans = min(ans, max(Ss) - min(Ss))
        return ans

print(min(getMinDiff(H, W), getMinDiff(W, H)))


Measured memory_bytes: 3064
#include<stdio.h>
int a,b,c,d,i,j,k,l,p,r,s,arr[100005],arr1[100005];
int abss(int o,int u)
{
	if(o-u<0)
	return(u-o);
	else
	return(o-u);
}
int minn(int K,int L)
{
	if(K<L)
	return(K);
	else
	return(L);
}
int dp(int g,int h)
{
	if(g>a)
	return 1000000000;
	if(arr1[g]!=-1)
	return(arr1[g]);
	if(g==a)
	{
		return(h);
	}
	arr1[g]=dp(g+1,h)+abss(arr[g],arr[g+1]);
c=arr1[g];
arr1[g]=dp(g+2,h)+abss(arr[g],arr[g+2]);
d=arr1[g];
//printf("%d %d\n",c,d);
	return(arr1[g]=minn(c,d));
}
int main ()
{
	scanf("%d",&a);
	for(i=1;i<=a;i++)
	{
		scanf("%d",&arr[i]);
		arr1[i]=-1;
	}
	p=dp(1,0);
	printf("%d\n",p);
	return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h> 
#define MOD 1000000007
using namespace std;
 
typedef long long int ll;
typedef unsigned long long ull;
int dp[100002];

int main(){

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    int n,k;
    cin >> n >> k;
    int h[n];
    for(int i = 0;i<n;i++){
        cin >> h[i];
        dp[i] = INT_MAX;
    }
    
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j <= i + k; ++j) {
            if(j < n) {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }
    printf("%d\n", dp[n-1]);
}


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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

int main() {
  ll A, B;
  cin >> A >> B;

  
  vector<ll> C;
  ll num = GCD(A, B);
  ll ans = 1;
  
  for(ll i = 2; i * i <= num; i++) {
    if(num % i != 0) continue;
    ll ex = 0;
    while(num % i == 0) {
      if(ex == 0) ans++;
      ++ex;
      num /= i;
    }
  }

  if(num != 1) ans++;

 cout << ans;
   return 0;
}

Measured memory_bytes: 3568
n, m, q = 0, 0, 0
ABCD = []
ans = 0


def dfs(A):
    global ans

    if len(A) == n:
        s = 0
        for qi in range(q):
            a, b, c, d = ABCD[qi]
            if A[b - 1] - A[a - 1] == c:
                s += d

        ans = max(s, ans)
        return

    for i in range(A[-1], m + 1):
        AC = A.copy()
        AC.append(i)
        dfs(AC)


def main():
    global n, m, q, ABCD
    n, m, q = [int(e) for e in input().split()]
    ABCD = [[int(e) for e in input().split()] for i in range(q)]

    for mi in range(1, m + 1):
        dfs([mi])

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

signed main()
{
	//freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int p[n];
	int ans = 0;
	int ln = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> p[i];
		if(p[i] == i + 1)
		{
			ln++;
		}
		if(p[i] != i + 1 || i + 1 == n)
		{
			ans += (ln + 1) / 2;
			ln = 0;
		}
	}
	cout << ans << endl;
    return 0;
}


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

int main(){
  
  string a,b;
   getline(cin,a);
  cin >> b;
  int c = 0;
  for(int i = 0;i<a.length();i++){
    if(a[i]!=b[i])
      c++;
    }
  cout << c;
  return 0;
  }


Measured memory_bytes: 3852
/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/

#define _USE_MATH_DEFINES

#include <iostream> // ?¨??????\??????
#include <fstream>  // ??????????????\??????
#include <string>   // ???????????¢???
#include <vector>   // ???????????????
#include <cmath>    // ??°??????
#include <iomanip>  // stream???????????¢???
#include <algorithm>// max??¢??°??????

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;        // ????´???°????????????????????????
using std::fixed;         // ???????????????????¨???????????????????????????????
using std::setprecision;  // ?????°????°???°?????\???????????°????????????????????¨????????\???

int main() {
	double a, b, p, c, d, q;
	double x, y;

	while (cin >> a >> b >> p >> c >> d >> q)
	{
		x = (p*d - b*q) / (a*d - b*c);
		y = (a*q - p*c) / (a*d - b*c);
		if (-0.0005 < x && x < 0.0005) x = 0.0;
		if (-0.0005 < y && y < 0.0005) y = 0.0;
		cout << fixed << setprecision(3) << x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#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()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
constexpr ll INF = 1LL<<60;

int main() {
    ll n, m;
    cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
namespace my_std {
using namespace std;
#define reg register
#define Rint register int
#define FOR(i, a, b) for (register int i = (a), ed_##i = (b); i <= ed_##i; ++i)
#define ROF(i, a, b) for (register int i = (a), ed_##i = (b); i >= ed_##i; --i)
typedef long long i64;
#define Templ(T) template <typename T>
Templ(_Tp) inline int chkmin(_Tp &x, _Tp y) { return x > y ? x = y, 1 : 0; }
Templ(_Tp) inline int chkmax(_Tp &x, _Tp y) { return x < y ? x = y, 1 : 0; }
const int mod = 998244353;
inline void inc(int &x, const int &y) { x += y; if (x >= mod) x -= mod; }
inline void dec(int &x, const int &y) { x -= y; if (x < 0) x += mod; }
} // namespace my_std
using namespace my_std;

#define N 350
char s[N];
int n;
int dp[N][N][N];
bool tr[N][N][N];
//[i][c0][c1]: 剩下 i 个字符没有匹配，多了 c0 个 0 和 c1 个 1

int main() {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    tr[0][0][0] = 1;
    FOR(i, 1, n){
        ROF(c0, n, 0) ROF(c1, n, 0){
            if(i == n && !c0 && !c1) continue;
            tr[i][c0][c1] |= tr[i - 1][c0][c1];
            if(s[i] == 48) tr[i][c0][c1] |= tr[i][c0][c1 + 1];
            if(s[i] == 49) tr[i][c0][c1] |= tr[i][c0 + 1][c1];
            //删掉两个把第二个加回原来位置
            //加回去的可能是多出来的字符
        }
        if(i > 1) FOR(c0, 0, n) FOR(c1, 0, n){
            if((s[i - 1] == 48 || s[i] == 48) && c0){
                tr[i][c0][c1] |= tr[i - 2][c0 - 1][c1];
                //前面两个都不是多余的，把'0'扔到多余的位置
            }
            if(s[i - 1] == 48 && s[i] == 48 && c0){
                tr[i][c0][c1] |= tr[i - 1][c0 - 1][c1 + 1];
                //前面是"10"（'1'是多余的），并把'0'扔到多余的位置
            }
            if((s[i - 1] == 49 || s[i] == 49) && c1){
                tr[i][c0][c1] |= tr[i - 2][c0][c1 - 1];
                //前面两个都不是多余的，把'1'扔到多余的位置
            }
            if(s[i - 1] == 49 && s[i] == 49 && c1){
                tr[i][c0][c1] |= tr[i - 1][c0 + 1][c1 - 1];
                //前面是"01"（'0'是多余的），并把'1'扔到多余的位置
            }
        }
    }
    dp[n][0][0] = 1;
    ROF(i, n, 1){
        FOR(c0, 0, n) FOR(c1, 0, n){
            Rint t(dp[i][c0][c1]);
            inc(dp[i - 1][c0][c1], t);
            if(s[i] == 48) inc(dp[i][c0][c1 + 1], t);
            if(s[i] == 49) inc(dp[i][c0 + 1][c1], t);
        }
    }
    Rint ans(0);
    FOR(i, 0, n){
        FOR(c0, 0, i) FOR(c1, 0, i){
            if(tr[i][c0][c1]) inc(ans, dp[i][c0][c1]);
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 161028
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
   
/* brownsands :Arpit */			

void solve()
{   string s,s1,s2;int a,b;
    cin >> s >> s1 >> a >> b >> s2;
    if(s==s2)cout<<a-1<<" "<<b;
    else cout<<a<<" "<<b-1; 
}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case "<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 
               
			
 

				
		
		




Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;

typedef long long ll;
#define pb push_back

#define rep(i, n) for (int i=0;i<(n);++i)
#define rep2(i, s, n) for (int i=s;i<(n);++i)
#define INF (1e9)

class Edge{
public:
    int u, v, cost;
    Edge(int u, int v, int cost):
        u(u), v(v), cost(cost) {}
    bool operator < (const Edge& e) const {
        return cost != e.cost ? cost < e.cost :
            u != e.u ? u < e.u : v < e.v;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

/* Bellman Ford algorithm */
bool bellman_ford(Graph& G, vector<int>& d, vector<int>& p, int s)
{
    int V = G.size();
    d[s]  = 0;
    rep(k,V-1) rep(i,V) for(auto e:G[i]) if(d[e.u] != INF && d[e.v] > d[e.u] + e.cost) {
            d[e.v] = d[e.u] + e.cost;
            p[e.v] = e.u;
        }
    rep(i,V) for(auto e:G[i]) if(d[e.u] != INF && d[e.v] > d[e.u] + e.cost) return true;
    return false;
}
/* AOJ GRL1 */
int main()
{
    int V,E,s; cin>>V>>E>>s;
    Graph G(V);
    rep(i,E) {
        int u,v,c; cin>>u>>v>>c;
        G[u].pb(Edge(u,v,c));
    }

    vector<int> d(V,INF), p(V,-1);
    bool neg_cycle = bellman_ford(G,d,p,s);

    if(neg_cycle) cout << "NEGATIVE CYCLE" << endl;
    else rep(i,V)
             if(d[i] == INF) cout << "INF" << endl;
             else cout << d[i] << endl;   
}

Measured memory_bytes: 3120
n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]


def bit(n, k): return (n >> k) & 1


dp = [0]*(1 << n)
flag = [False]*(1 << n)


def dfs(s):
    if flag[s] or bin(s).count("1") <= 1:
        return dp[s]
    flag[s] = True
    tmp = 0
    for i in range(n):
        for j in range(i+1, n):
            if bit(s, i) & bit(s, j):
                tmp += a[i][j]
    score = tmp
    t = (s-1) & s
    while 0 < t:
        score = max(score, dfs(t)+dfs(s ^ t))
        t = (t-1) & s
    dp[s] = score
    return dp[s]


print(dfs(2**n-1))


Measured memory_bytes: 52572
N, W = map(int, input().split())
dp = [0]*(W+1)
max_weight = 0
for i in range(N):
    v, w, m = map(int, input().split())
    n = 1
    while m > 0:
        m -= n
        _v, _w = v*n, w*n
        max_weight = min(W, max_weight + _w)
        for k in range(max_weight, _w-1, -1):
            if dp[k] < dp[k-_w] + _v:
                dp[k] = dp[k-_w] + _v
        n = m if n << 1 > m else n << 1

print(max(dp))

Measured memory_bytes: 7988
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    int ans = 1;
    int joutai = 0;
    REP(i, N) {
        if (joutai == 1 && A[i - 1] > A[i]) {
            ++ans;
            joutai = 0;
            continue;
        }
        if (joutai == 2 && A[i - 1] < A[i]) {
            ++ans;
            joutai = 0;
            continue;
        }
        if (A[i - 1] < A[i]) joutai = 1;
        if (A[i - 1] > A[i]) joutai = 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
# Using BFS
from collections import defaultdict, deque
import sys


def input():
    return sys.stdin.readline()


def push(v, d, dist, q, INF=1e10):
    if dist[v] != INF:
        return
    dist[v] = d
    q.append(v)


def main():
    n, x, y = map(int, input().split())
    # modify the values of x, y so that they start from zero
    x, y = x - 1, y - 1
    INF = 1e10
    ans = defaultdict(int)
    for i in range(n):
        # dist[idx]: distance between i and idx.
        dist = [INF] * n
        q = deque()
        push(i, 0, dist, q)
        while len(q) != 0:
            v = q.popleft()
            d = dist[v]
            if v - 1 >= 0:
                push(v-1, d+1, dist, q)
            if v + 1 < n:
                push(v+1, d+1, dist, q)
            if v == x:
                push(y, d+1, dist, q)
            if v == y:
                push(x, d+1, dist, q)

            ans[dist[v]] += 1

    for i in range(n):
        if i != 0:
            print(ans[i] // 2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 89564
#include<bits/stdc++.h>
using namespace std;
#define nn 200006
#define ll long long
ll n,t,e;
ll x[nn];ll f[nn];
int main()
{
	scanf("%lld%lld%lld",&n,&e,&t);
	for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
	deque<int> q;ll oops=1e17;
	q.push_back(0);x[0]=0;int ls=0;
	for(int i=1;i<=n;i++)
	{
		while(ls<i and 2*(x[i]-x[ls+1])>t)
		{
			if(q.size() and ls==q.front()) q.pop_front();
			oops=min(oops,f[ls]-x[ls+1]*2-x[ls]);
			ls++;
		}
		
		if(q.size()) f[i]=f[q.front()]+t+x[i]-x[q.front()];
		else f[i]=1e17;
		f[i]=min(f[i],oops+x[i]*3);
		while(q.size() and f[q.back()]-x[q.back()]>=f[i]-x[i]) 
			q.pop_back();
		q.push_back(i);
	}	
	
	printf("%lld\n",f[n]+e-x[n]);
}


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

using namespace std;

const int maxN = 1e5+10;
typedef pair<int, int> ii;
struct
{
    int x, d, c;
} query[maxN];
int N,M,Q,color[maxN];
vector <int> E[maxN];
map <ii, bool> mapa;

void paint(int x, int d, int c)
{
    if (mapa.count(ii(x,d))) return;
    mapa[ii(x,d)] = 1;
    if (d == 0)
    {
        color[x] = c;
        return;
    }
    paint(x, d-1, c);
    for (int i=0; i < E[x].size(); i++)
    {
        int y = E[x][i];
        paint(y, d-1, c);
    }
}

int main()
{
    cin >> N >> M;
    for (int i=0,x,y; i < M; i++)
    {
        cin >> x >> y;
        E[x].push_back(y);
        E[y].push_back(x);
    }
    cin >> Q;
    for (int i=0; i < Q; i++) cin >> query[i].x >> query[i].d >> query[i].c;
    for (int i=Q-1; i >= 0; i--) paint(query[i].x, query[i].d, query[i].c);
    for (int i=1; i <= N; i++) cout << color[i] << '\n';
}


Measured memory_bytes: 65912