akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    while(b % k != 0){
      b = b - 1;
    }
    
    if(b < a){
      System.out.println("NG");
    }else{
      System.out.println("OK");
    }
    sc.close();
  }
}

Measured memory_bytes: 35772
<?php

fscanf(STDIN, '%d', $n);
//if ($n === 1) {
//    echo 1 . PHP_EOL;
//    return;
//}

$d = [];
for ($i = 1;$i <=$n;$i++) {
    $d[trim(fgets(STDIN))] = 0;
}


//arsort($d);

echo count($d).PHP_EOL;

//$cnt = 1;
//$now = $d[0];
//
//for ($i = 0; $i < $n; $i++) {
//    if ($now > $d[$i]) {
//        $cnt++;
//    }
//    $now = $d[$i];
//
//}
//
//echo $cnt.PHP_EOL;


Measured memory_bytes: 4728
#include <iostream> 

using namespace std;

int main()
{
	int h, w, n;
	cin >> h >> w >> n;
	
	int Max = h <= w ? w : h;
	int count = 0;
	while (n > 0)
	{
		n -= Max;
		++count;
	}
	
	cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
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; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	int n;
	cin >> n;
	int i;
	V a(n + 2);
	for (i = 1; i <= n; i++) {
		cin >> a[i];
	}
	a[0] = 0;
	a[n + 1] = 0;
	int distance = 0;
	for (i = 0; i <= n; i++) {
		distance += abs(a[i] - a[i + 1]);
	}
	for (i = 1; i <= n; i++) {
		cout << distance - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <vector>
#define MAXN 100010
#define MOD 1000000007
int n, m, k, a[MAXN], b[MAXN], c[MAXN], BIT[MAXN];
std::vector<std::pair<int, int>> d;
std::vector<int> v, vl, vr;
inline void up(int &x, int y) {
	if ((x += y) >= MOD) x -= MOD;
}
inline int lowbit(int x) { return x & -x; }
inline void add(int x, int v) {
	for (; x <= k; x += lowbit(x)) up(BIT[x], v);
}
inline int qry(int x) {
	int v = 0;
	for (; x; x -= lowbit(x)) up(v, BIT[x]);
	return v;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1, x; i <= m; i++) scanf("%d", &x), v.push_back(x);
	std::sort(v.begin(), v.end());
	for (int i = 1; i <= n; i++) {
		if (a[i] >= v.front() && a[i] <= v.back()) {
			int p = std::lower_bound(v.begin(), v.end(), a[i]) - v.begin();
			d.emplace_back(a[i] - v[p - 1], v[p] - a[i]);
			vl.push_back(a[i] - v[p - 1]);
			vr.push_back(v[p] - a[i]);
		}
	}
	std::sort(vl.begin(), vl.end());
	std::sort(vr.begin(), vr.end());
	std::sort(d.begin(), d.end(), [](auto a, auto b) { return a.first == b.first ? a.second > b.second : a.first < b.first; });
	vl.erase(std::unique(vl.begin(), vl.end()), vl.end());
	vr.erase(std::unique(vr.begin(), vr.end()), vr.end());
	d.erase(std::unique(d.begin(), d.end()), d.end());
	k = (n = (int)d.size()) + 1;
	add(1, 1);
	for (int i = 1; i <= n; i++) {
		a[i] = std::lower_bound(vl.begin(), vl.end(), d[i - 1].first) - vl.begin() + 1;
		b[i] = std::lower_bound(vr.begin(), vr.end(), d[i - 1].second) - vr.begin() + 1;
		add(b[i] + 1, qry(b[i]));
	}
	printf("%d\n", qry(k));
	return 0;
}

Measured memory_bytes: 3700
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

while (line = lines.shift()) {
    const numbers = line.split(' ').map(Number);

    // Edit from here
    let a = numbers[0];
    let b = numbers[1];

    if ( a === 0 && b === 0 ) { break; }

    if ( a > b ) {
        const tmp = a;
        a = b;
        b = tmp;
    } 

    const output = a + ' ' + b;
    // to here
    
    console.log(output);
    
}


Measured memory_bytes: 18848
import java.util.*;

class Main {
    
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        long ans = 0;
        ans = Math.min(K - N % K, N % K);
        
        
        System.out.println(ans);

	}

	
}
		
	


Measured memory_bytes: 22612
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldouble = long double;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;


int main()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	if (a + b == c + d)
	{
		println("Balanced");
	}
	else if (a + b > c + d)
	{
		println("Left");
	}
	else
	{
		println("Right");
	}
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
string s;
int ans;
int main(){
	cin>>s;
	for (int i=0;i<(s.size()+1)/2;i++) if (s[i]!=s[s.size()-i-1]) ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	int arr1[n];
	arr1[n-1] = arr[n-1];
	for(int i=n-2;i>=0;i--)
	{
		arr1[i] = arr[i] + arr1[i+1];
		arr1[i] %= mod;
	}
	int sum =0;
	for(int i=0;i<n-1;i++)
	{
		int m = arr[i] * arr1[i+1]; 
		m %= mod;
		sum += m;
		sum %=mod;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 6764
<?php

fscanf(STDIN,'%d',$length);
$line = trim(fgets(STDIN));
$arr = explode(' ',$line);
$arr1 = bubble_sort($arr,$length);
$arr2 = selection_sort($arr,$length);
$bool=count(array_diff_assoc($arr1,$arr2))===0;
echo implode(' ', $arr1), PHP_EOL, 'Stable', PHP_EOL;
echo implode(' ',$arr2),PHP_EOL, $bool ? 'Stable': 'Not stable', PHP_EOL;


function bubble_sort($a,$length) {
  $flag=1;
  while($flag) {
    $flag=0;
    for($i=$length-1;$i>0;$i--) {
      if($a[$i-1][1]>$a[$i][1]){
        $temp = $a[$i-1];
        $a[$i-1] = $a[$i];
        $a[$i]=$temp;
        $flag=1;
      }
    }
  }
  return $a;
}

function selection_sort($a,$length) {
  for($i=0;$i<$length;$i++) {
    $min=$i;
    for($j=$i;$j<$length;$j++){
      if($a[$j][1]<$a[$min][1]){
        $min=$j;
      }

    }
    if($min!==$i){
      $temp = $a[$i];
      $a[$i] = $a[$min];
      $a[$min]=$temp;
    }

  }
  return($a);
}



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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;



void solve() {
    int N; cin >> N;
    string S; cin >> S;

    if (N % 2 != 0) {
        cout << "No"; 
        return;
    } else {
        for (int i = 0; i < N/2; i++) {
            if (S.at(i) != S.at(i+N/2)) {
                cout << "No"; 
                return;
            }
        }
    }

    cout << "Yes";
    // cout << ans << "\n";
}

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


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

int main()
{
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;

    for (size_t i = 0; i < s.length(); i++) {
        s[i] = (s[i] + n) % ('Z' + 1);
        if (s[i] < 'A') s[i] += 'A';
    }

    std::cout << s << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <malloc.h>
using namespace std;
int parent(int i){return i/2;}
int lefts(int i){return 2*i;}
int rights(int i){return 2*i+1;}
void maxHeapify(int A[],int i,int H)
{
    int l = lefts(i);
    int r = rights(i);
    int largest;
    if(l<=H&&A[l]>A[i]){
        largest = l;
    }
    else largest = i;
    if(r<=H&&A[r] > A[largest])
        largest = r;
    if(largest != i)
    {
        swap(A[i],A[largest]);
        maxHeapify(A,largest,H);
    }

}
void buildMaxHeap(int A[],int H)
{
    for(int i = H/2;i > 0;i--)
    {
        maxHeapify(A,i,H);
    }
}
int main()
{
    int *a,n,i;
    scanf("%d",&n);
    a = (int*)malloc(sizeof(int)*(n+1));
    for(i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
    }
    buildMaxHeap(a,n);
    for(i = 1;i <= n;i++)
    {
        printf(" %d",a[i]);
    }
    putchar('\n');
}



Measured memory_bytes: 5108
#include <stdio.h>

char judge(int year, int month, int day);


int main (void)
{
	int year,month,day;
	char era;
	while (scanf("%d %d %d", &year, &month, &day) != EOF) {
		era = judge(year, month, day);
		if (era == 'p') {
			printf("pre-meiji\n");
		}else if (era == 'm') {
			printf("meiji %d %d %d\n", year - 1867, month, day);
		}else if (era == 't') {
			printf("taisho %d %d %d\n", year - 1911, month, day);
		}else if (era == 's') {
			printf("showa %d %d %d\n", year - 1925, month, day);
		}else if (era == 'h') {
			printf("heisei %d %d %d\n", year - 1988, month, day);
		}
	}
	return 0;
}

char judge(int year, int month, int day)
{
	//pre-meiji or meiji
	if (year < 1868) {
		return 'p';
	}else if (year == 1868) {
		if (month < 9) {
			return 'p';
		}else if (month == 9) {
			if (day < 8) {
				return 'p';
			}else{
				return 'm';
			}
		}else{
			return 'm';
		}
	}else if (year < 1912) {
	//meiji or taisho
		return 'm';
	}else if (year == 1912) {
		if (month < 7) {
			return 'm';
		}else if (month == 7) {
			if (day < 30) {
				return 'm';
			}else{
				return 't';
			}
		}else{
			return 't';
		}
	}else if (year < 1926) {
	//taisho or showa
		return 't';
	}else if (year == 1926) {
		if (month < 12) {
			return 't';
		}else if (month == 12) {
			if (day < 25) {
				return 't';
			}else{
				return 's';
			}
		}else{
			return 's';
		}
	}else if (year < 1989) {
		return 's';
	}else if (year == 1989) {
		if (month == 1) {
			if (day < 8) {
				return 's';
			}else{
				return 'h';
			}
		}
		return 'h';
	}else{
		return 'h';
	}
}

Measured memory_bytes: 1032
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define input(n,a) int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];
#define ouput(n,a) for(int i=0;i<n;i++)cout<<a[i]<<" ";
#define sort(v) sort(v,v+n);
#define endl "\n"
#define umap unordered_map<int,int>
#define uset unordered_set<int>
void solve()
{
	int n;
	cin>>n;
	int cnt=0,a[n][2];
	for(int i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1];
	}
	for(int i=2;i<n;i++)
	{
		if(a[i][0]==a[i][1] && a[i-1][0]==a[i-1][1] && a[i-2][0]==a[i-2][1])
			cnt++;
	}
	if(cnt>=1)
		cout<<"Yes";
	else
		cout<<"No";
}


int32_t main()
{
	int t=1;
	//cin>>t;
	while(t--)
		solve();
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
    int n;
    cin >> n;
    vi v(n);
    rep(i,n)v[i] = i+1;
    vi p(n),q(n);
    rep(i,n)cin >> p[i];
    rep(i,n)cin >> q[i];
    int a,b;
    int cnt = 0;
    do{
        cnt++;
        if(v == p)a = cnt;
        if(v == q)b = cnt;
    }while(next_permutation(all(v)));
    cout << abs(a-b) << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp[10],cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>cmp[0]>>cmp[1]>>cmp[2];
    sort(cmp,cmp+3);
    reverse(cmp,cmp+3);
    a=cmp[0],b=cmp[1],c=cmp[2];
    ans=(a-b)/2;
    b+=2*ans;
    ans+=(a-c)/2;
    c+=2*((a-c)/2);
    if(a==b&&b==c&&a==c);
    else if(b==c)ans++;
    else ans+=2;
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
#include<vector>
struct SCC{
	int n;
	vector<int>comp,order;
	vector<bool>used;
	vector<vector<int> >G,RG;
	SCC(int _n=0):n(_n),comp(_n,-1),used(_n,false),G(_n),RG(_n){}
	void add_edge(int from,int to)
	{
		G[from].push_back(to);
		RG[to].push_back(from);
	}
	void copy(vector<vector<int> >&H)
	{
		for(int i=0;i<H.size();i++)
		{
			for(int j=0;j<H[i].size();j++)
			{
				G[i].push_back(H[i][j]);
				RG[H[i][j]].push_back(i);
			}
		}
	}
	int operator[](int u){return comp[u];}
	void dfs(int u)
	{
		used[u]=true;
		for(int i=0;i<G[u].size();i++)if(!used[G[u][i]])dfs(G[u][i]);
		order.push_back(u);
	}
	void rdfs(int u,int cnt)
	{
		comp[u]=cnt;
		for(int i=0;i<RG[u].size();i++)if(comp[RG[u][i]]==-1)rdfs(RG[u][i],cnt);
	}
	int build()
	{
		for(int i=0;i<n;i++)if(!used[i])dfs(i);
		int cnt=0;
		for(int i=n-1;i>=0;i--)if(comp[order[i]]==-1)rdfs(order[i],cnt++);
		return cnt;
	}
	int build(vector<vector<int> >&H)
	{
		int ret=build();
		H.assign(ret,vector<int>());
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<G[i].size();j++)
			{
				if(comp[i]!=comp[G[i][j]])
					H[comp[i]].push_back(comp[G[i][j]]);
			}
		}
		return ret;
	}
};
main()
{
	int n;
	while(cin>>n,n)
	{
		vector<double>p(n),P(n,1);
		SCC scc(n);
		for(int i=0;i<n;i++)
		{
			cin>>p[i];
			int k;cin>>k;
			for(;k--;)
			{
				int a;cin>>a;
				scc.add_edge(i,a-1);
			}
		}
		vector<vector<int> >G;
		int N=scc.build(G);
		for(int i=0;i<n;i++)P[scc[i]]*=p[i];
		vector<int>H(N,0);
		for(int i=0;i<N;i++)
		{
			for(int j=0;j<G[i].size();j++)
			{
				H[G[i][j]]++;
			}
		}
		double ans=1;
		for(int i=0;i<N;i++)if(H[i]==0)ans*=1-P[i];
		cout<<fixed<<setprecision(9)<<ans<<endl;
	}
}



Measured memory_bytes: 3340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
#define MOD 1000000007
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main(){
    ll d,m,ans=0;cin>>m>>d;
    For1(i,m+1){
        For1(j,d+1){
            if(j/10>1&&j%10>1&&(j/10)*(j%10)==i){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}


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

typedef long long LL;

const int N=300,mod=998244353;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

char s[N+9];
int n;

void into(){
  scanf("%s",s+1);
  n=strlen(s+1);
}

int dp[N+9][N+9][N+9];

void Get_dp(){
  dp[n][0][0]=1;
  for (int i=n;i>=1;--i)
	for (int j=0;j<i;++j)
	  for (int k=0;j+k<i;++k){
		dp[i-1][j][k]=dp[i][j][k];
		s[i]=='0'?sadd(dp[i][j][k+1],dp[i][j][k]):sadd(dp[i][j+1][k],dp[i][j][k]);
	  }
}

int f[N+9][N+9][N+9];

void Get_f(){
  for (int i=0;i<=n;++i)
	for (int j=0;j<=n;++j)
	  for (int k=0;k<=n;++k) f[i][j][k]=-1;
  f[0][0][0]=0;
  for (int i=0;i<n;++i)
	for (int j=0;j<=i>>1;++j)
	  for (int k=0;j+k<=i>>1;++k){
		if (f[i][j][k]==-1) continue;
		s[i+1]=='0'?f[i+1][j+1][k]=max(f[i+1][j+1][k],f[i][j][k]-1):f[i+1][j][k+1]=max(f[i+1][j][k+1],f[i][j][k]-1);
		if (i+2>n) continue;
		f[i+2][j][k]=max(f[i+2][j][k],f[i][j][k]+1);
		if (s[i+1]=='0'||s[i+2]=='0') f[i+2][j+1][k]=max(f[i+2][j+1][k],f[i][j][k]);
		if (s[i+1]=='1'||s[i+2]=='1') f[i+2][j][k+1]=max(f[i+2][j][k+1],f[i][j][k]);
	  }
}

int g[N+9][N+9][N+9];

void Get_g(){
  for (int i=0;i<=n;++i)
	for (int j=n;j>=0;--j)
	  for (int k=n;k>=0;--k){
		g[i][j][k]=f[i][j][k]>=0;
		if (i) g[i][j][k]|=g[i-1][j][k];
		g[i][j][k]|=g[i][j+1][k]|g[i][j][k+1];
	  }
}

int ans;

void Get_ans(){
  for (int i=0;i<=n;++i)
	for (int j=0;j<=i;++j)
	  for (int k=0;j+k<=i;++k)
		if (g[i][j][k]) sadd(ans,dp[i][j][k]);
}

void work(){
  Get_dp();
  Get_f();
  Get_g();
  Get_ans();
}

void outo(){
  printf("%d\n",sub(ans,1));
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 280552
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define chmin(i, j) i = min(i, j);
#define chmax(i, j) i = max(i, j);
#define rep(i, n) for(int i=0;i<n;i++)
int main() {
  int x, y, z, K;
  cin >> x >> y >> z >> K;
  vector<ll> a(x), b(y), c(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(c.rbegin(), c.rend());
  auto cmp = [](vector<ll> first, vector<ll> second) { return first[0] < second[0]; };
  priority_queue<ll, vector<vector<ll>>, decltype(cmp)> pq(cmp);
  map<vector<ll>, int> mp;
  vector<ll> d({a[0]+b[0]+c[0], 0, 0, 0});
  pq.emplace(d);
  mp[d]++;
  for(int it=0;it<K;it++) {
    vector<ll> v = pq.top();pq.pop();
    cout << v[0] << endl;
    ll i = v[1], j = v[2], k = v[3];
    vector<ll> p({a[(i+1)%x]+b[j]+c[k], i+1, j, k});
    vector<ll> q({a[i]+b[(j+1)%y]+c[k], i, j+1, k});
    vector<ll> r({a[i]+b[j]+c[(k+1)%z], i, j, k+1});
    if(!mp[p] && i+1 != x) {
      pq.emplace(p);
      mp[p]++;
    }
    if(!mp[q] && j+1 != y) {
      pq.emplace(q);
      mp[q]++;
    }
    if(!mp[r] && k+1 != z) {
      pq.emplace(r);
      mp[r]++;
    }
  }
  return 0;
}



Measured memory_bytes: 1408
#include <iostream>

int main() {
  std::string a, b;
  std::cin >> a >> b;
  const int x = std::stoi(a + b);
  bool is_square = false;
  for( int i = 1; i <= 320; ++i ) {
    if( x == i*i ) {
      is_square = true;
      break;
    }
  }

  if( is_square ) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}

Measured memory_bytes: 3156
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		n: usize,
	}

	if n % 2 == 0 {
		println!("{}", n);
	}
	else {
		println!("{}", n*2);
	}
}


Measured memory_bytes: 2148
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    s = input()
    res = 0
    ans = 0
    for i in range(3):
        if s[i]=='S':
            res = max(res,ans)
            ans = 0
        else:
            ans += 1
    print(max(ans,res))
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9104
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def main():
    s = list(input())
    n = len(s)
    dic = defaultdict(int)
    for i in range(n):
        dic[s[i]] += 1
    ans = 0
    for e in dic:
        ans += (n-dic[e])*dic[e]
    print(ans//2+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 59244
#include<cstdio>
#include<algorithm>

using namespace std;

const long long inf=1e12;

int N;
int A,B;
int r[155],s[155];
int Sum;

long long f[155][2][155];

int get(int i,int p,long long x){
	int res=0;
	for(int S=0;S<=Sum;S++){
		if(f[i][p][S]<=x){
			res=S;
		}
	}
	return res;
}

int simulate(int i,int p,long long x){
	if(p==0){
		int res=get(i+1,1,x+r[i])+s[i];
		if(x>0){
			int tmp=get(i+1,0,x-1-r[i]);
			res=max(res,tmp);
		}
		return res;
	}else{
		int res=get(i+1,0,x-r[i]);
		if(x<0){
			int tmp=get(i+1,1,x+1+r[i])+s[i];
			res=min(res,tmp);
		}
		return res;
	}
}

int main(){
	scanf("%d%d%d",&N,&A,&B);
	for(int i=0;i<N;i++){
		scanf("%d%d",r+i,s+i);
		Sum+=s[i];
	}
	for(int i=0;i<N;i++) for(int j=0;j<2;j++){
		for(int k=0;k<=Sum;k++){
			f[i][j][k]=inf;
		}
	}
	f[N-1][0][s[N-1]]=-inf;
	f[N-1][1][0]=-inf;
	for(int i=N-2;i>=0;i--){
		for(int j=0;j<=1;j++){
			for(int s=0;s<=Sum;s++){
				long long lb=-inf/2,ub=inf/2;
				while(ub-lb>1){
					long long x=(ub+lb)/2;
					int val=simulate(i,j,x);
					if(val>=s){
						ub=x;
					}else{
						lb=x;
					}
				}
				if(ub==(-inf/2)+1) f[i][j][s]=-inf;
				else if(ub==(inf/2)) f[i][j][s]=inf;
				else f[i][j][s]=ub;
			}
		}
	}
	int ans=0;
	for(int i=0;i<=Sum;i++){
		if(f[0][0][i]<=A-B){
			ans=i;
		}
	}
	printf("%d %d\n",ans,Sum-ans);
	return 0;
}

Measured memory_bytes: 1400
l=[]
n,a,b,c=map(int,input().split())
for i in range(n):
    li=int(input())
    l.append(li)

d=[a,b,c]
d.sort()

mpmin=sum(l)*4+len(l)*10+sum(d)
for i in range(4**n):
    k=[]
    kj=i%4
    k.append(kj)
    b=int((i-kj)/4)
    l0=[]
    l1=[]
    l2=[]
    l3=[]
    if kj==0:
        l0.append(l[0])
    elif kj==1:
        l1.append(l[0])
    elif kj==2:
        l2.append(l[0])
    elif kj==3:
        l3.append(l[0])
        
    for j in range(n-1):
        kj=b%4
        k.append(kj)
        b=int((b-kj)/4)
        if kj==0:
            l0.append(l[j+1])
        elif kj==1:
            l1.append(l[j+1])
        elif kj==2:
            l2.append(l[j+1])
        elif kj==3:
            l3.append(l[j+1])
    mp=0
    if len(l0)>=1:
        mp=mp+(len(l0)-1)*10
    if len(l1)>=1:
        mp=mp+(len(l1)-1)*10
    if len(l2)>=1:
        mp=mp+(len(l2)-1)*10
    ls=[]
    ls=[sum(l0),sum(l1),sum(l2)]
    ls.sort()
    mp=mp+abs(d[0]-ls[0])+abs(d[1]-ls[1])+abs(d[2]-ls[2])    
    if mpmin>mp and len(l0)>=1 and len(l1)>=1 and len(l2)>=1:
        mpmin=mp
print(mpmin)        
        


Measured memory_bytes: 3192
from sys import stdin
from collections import defaultdict, deque, Counter
import sys
from bisect import bisect_left
import heapq
import math
#import numpy as np

sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

s = {}
ans = 0

for i in range(n):
    l = list(str(stdin.readline().rstrip()))
    l.sort()
    l = str(l)
    if l in s:
        s[l] += 1
        ans += s[l] -1
    else:
        s[l] = 1

print(ans)


Measured memory_bytes: 22368
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
    #else
    #endif
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    forn (i, m) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        a[u] ^= 1;
        a[v] ^= 1;
    }
    forn (i, n) {
        if (a[i]) {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

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

int main()
{
  ll n, m, d;
  cin >> n >> m >> d;
  double ans = (n-d)*(m-1)*2;
  ans /= n*n;

  if(d == 0) ans /= 2;

  printf("%0.12f\n", ans);
}


Measured memory_bytes: 3732
n, m, l = gets.chomp.split(/\s/).map(&:to_i)

mat_1 = []
mat_2 = []

n.times{ mat_1 << gets.chomp.split(/\s/).map(&:to_i) }
m.times{ mat_2 << gets.chomp.split(/\s/).map(&:to_i) }

n.times do |i|
  l.times do |j|
    sum = 0
    m.times{ |k| sum += mat_1[i][k] * mat_2[k][j] }
    print "\s" unless j == 0
    print sum
  end
  puts ''
end

Measured memory_bytes: 9308
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
ll ans(ll x){
    if(x==0) return 1;
    return (x*ans(x-1))%((ll)1e9+7);
}
int main() {
    int n;
    cin>>n;
    cout<<ans(n)<<endl;
}


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

int main(){
    int n;
    cin >> n;
    int sum=0;
    int dif=0;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<int>());

    for(int i=0;i<n;i++){
        if(i%2==0) sum+=a[i];
        else dif+=a[i];
    }

    sum-=dif;
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,k;
	cin>>n>>k;
	vi in(26);
	rep(i,n){
		string s;
		cin>>s;
		in[s[0]-'A']++;
	}
	int out=0;
	while(1){
		sort(all(in),[](int a,int b){
			return a>b;
		});
//		rep(i,26)cout<<" "<<in[i];cout<<endl;
		int co=0;
		rep(i,26)if(in[i]){
			co++;
			in[i]--;
			if(co==k)break;
		}
		if(co!=k)break;
		out++;
	}
	cout<<out<<endl;
}








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

using namespace std;
using ll = long long;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> AB(N);
  for (int i = 0; i < N; ++i) {
    cin >> AB[i].first >> AB[i].second;
  }
  sort(AB.begin(), AB.end());
  priority_queue<ll> tasks;
  ll s = 0;
  ll ret = 0;
  for (int i = 1; i <= M; ++i) {
    for (int j = s; j <= AB.size(); ++j) {
      if (j==AB.size() || AB[j].first > i) {
        s = j;
        break;
      }
      tasks.push(AB[j].second);
    }
    if(!tasks.empty()) {
      ret += tasks.top();
      tasks.pop();
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 2936
#include<iostream>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef vector<ll> V;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

//グラフの隣接リスト
vector<ll> g[100010];
//頂点の入次数の管理
ll h[100010]={0};
//頂点の番号
ll num[100010];


int main(){
  ll v,e;
  cin >> v>>e;

  REP(i,e){
    ll s,t;
    cin >> s >> t;
    g[s].push_back(t);
    h[t]++;
  }
  //入字数０の頂点の集合
  stack<ll> st;

  REP(i,v)if(h[i]==0)st.push(i);

  V ans;
  while(st.size()){
    ll s=st.top();st.pop();
    ans.push_back(s);
    REP(i,g[s].size()){
      //隣接する頂点の入次数をマイナス１
      h[g[s][i]]--;
      //入次数が０ならstackに追加
      if(h[g[s][i]]==0)st.push(g[s][i]);
    }
  }
  if(ans.size()==v)cout <<"0"<<endl;
  else cout <<"1"<<endl;
}



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

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

class UnionFindTree{
private:
  // indexの数の親ノード(ある集合の親を見つけたいときはここを直接参照せず、findを使う)
  vector<int> par;
  // indexを根とする木のランク
  vector<int> rank;
  // 集合のサイズ
  vector<int> cnts;
  // 木の最大値
  int treeSize;
public:
  UnionFindTree(int initTreeSize = 1000){
    // 引数で与えられた値を最大格納数とするUnionFindTreeの作成
    treeSize = initTreeSize;
    init(initTreeSize);
  }
  void init(int sz){
    par.clear(),rank.clear(),cnts.clear();
    treeSize=sz;
    for(int i = 0; i < sz; i++){
      par.push_back(i);
      rank.push_back(0);
      cnts.push_back(1);
    }
  }
  // 与えられた数が格納されている木のルートを探索
  int find(int x){  
    if(par[x] == x)return x;
    else return par[x] = find(par[x]);
  }
  // 和集合をとる。ただしここでは各集合の親の付け替えは起こらない
  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y)return;
    if(rank[x] < rank[y]){
      par[x] = y;
      cnts[y]+=cnts[x];
    }
    else{
      par[y] = x;
      cnts[x]+=cnts[y];
      if(rank[y] == rank[x])rank[x]++;
    }
  }
  // xの属する集合のサイズ
  int getCnt(int x){
    return cnts[find(x)];
  }
  bool same(int x,int y){
    return find(x) == find(y);
  }
    
};


int N, M;
int X[100010];
int Y[100010];
int Z[100010];
UnionFindTree uft(100010);


int main(){

    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> X[i] >> Y[i] >> Z[i];
        X[i]--;Y[i]--;
        uft.unite(X[i], Y[i]);
    }
    set<int>st;
    for(int i = 0; i < N; i++){
        st.insert(uft.find(i));
    }
    cout << st.size() << endl;


    return 0;
}


Measured memory_bytes: 7276
import sys
readline = sys.stdin.buffer.readline

h,w = map(int,readline().split())

maze = []
for i in range(h):
    maze.append(readline().rstrip().decode('utf-8'))

dp = [[0]*w for _ in range(h)] #dp[i][j]:そこまでに何回変色したかの最小値

if maze[0][0] == "#":
    dp[0][0] = 1

for i in range(h):
    for j in range(w):
        if i == 0:
            if j == 0:
                continue
            res = 1 if maze[i][j] != maze[i][j-1] else 0

            dp[i][j] = dp[i][j-1] + res

        elif j == 0:
            res = 1 if maze[i][j] != maze[i-1][j] else 0

            dp[i][j] = dp[i-1][j] + res

        else:
            res_h = 1 if maze[i][j] != maze[i-1][j] else 0
            res_w = 1 if maze[i][j] != maze[i][j-1] else 0
            
            dp[i][j] = min(dp[i][j-1] + res_w,dp[i-1][j] + res_h)

print((dp[i][j]+1)//2)

Measured memory_bytes: 41840
/************* Al-Azhar ICPC Community ***********/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '/n';
void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}


int freq[200009];
int arr[200009];

int main() {
    fast();
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        freq[arr[i]]++;
    }
    ll total = 0;
    for (int j = 1; j <= n; ++j) {
        ll tmp = freq[j]-1;
        total += (tmp * (tmp + 1) / 2);
    }
    for (int k = 0; k < n; ++k) {
        ll tmp = total - (freq[arr[k]]-1);
        //cout<<total<< " ";
        cout << tmp << "\n";
    }
}




Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i,x,n) for(ll i=x;i<n;i++)
#define fl(i,x,n) for(ll i=n;i>=x;i--)
#define mod (ll)1e9+7
#define print(x) cout<<x<<endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) :: iterator it
#define MAX (ll)1e16
#define MIN (ll)-1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
       ///////////   ///     ///   ///      ///   ////////////  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///////////   ///      ///   ////////////  ////////////
               ///   ///     ///   ///      ///   ///      ///  ///      ///
               ///   ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///     ///   ////////////   ////////////  ///      ///
ll minn( ll a , ll b) 
{
    if(a>b)
        return b;
    return a;
}
ll maxx2( ll a , ll b)
{
    if(a>b)
        return a;
    return b;
}
ll maxx(ll a,ll b,ll c)
{
  return maxx2(a,maxx2(b,c));
}
ll gcdd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcdd(b,a%b);
}
ll dsum(ll n)
{
    ll sum=0;
    while(n>0)
    {
        sum+=n%10;
        n/=10;
    }
    return sum;
}
ll poww(ll a,ll b)
{
    if(b<=0)
        return 1;
    if(b==1)
        return a;
    else
        return poww(a,b/2)*poww(a,b/2)*poww(a,b%2);
}
ll sumsq(ll x,ll y,ll z)
{
    return (x-y)*(x-y)+(y-z)*(y-z)+(z-x)*(z-x);
}
ll n,a[100001],b[100001],c[100001],dp[100001][3]={0};
ll solve(ll i,ll j)
{
    if(i<0)
    {
        return 0;
    }
    if(dp[i][j]!=-1)
        return dp[i][j];
    if(j==0)
        dp[i][j]=maxx2(solve(i-1,1)+a[i],solve(i-1,2)+a[i]);    
    if(j==1)
        dp[i][j]=maxx2(solve(i-1,0)+b[i],solve(i-1,2)+b[i]);
    if(j==2)
        dp[i][j]=maxx2(solve(i-1,1)+c[i],solve(i-1,0)+c[i]);      
    return dp[i][j];
}
signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    IOS;
    cin>>n;
    f(i,0,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    f(i,0,n)
    {
        dp[i][0]=-1;
        dp[i][1]=-1;
        dp[i][2]=-1;
    }
    ll ans=maxx(solve(n-1,0),solve(n-1,1),solve(n-1,2));
    cout<<ans<<endl;
    return 0;
}

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

namespace V1173{
    public class Program{
        public static void Main(string[] args){
            while(true){
                var S = Console.ReadLine();
                if(S == ".") break;

                const string bs = "([";
                const string be = ")]";
                var res = true;

                var stk = new Stack<char>();
                foreach(var c in S){
                    for(var i = 0; i < bs.Length; i++){
                        if(c == bs[i]) stk.Push(c);
                        if(c == be[i]){
                            if(stk.Count == 0 || stk.Pop() != bs[i]){
                                res = false;
                                break;
                            }
                        }
                    }
                }

                res &= stk.Count == 0;
                Console.WriteLine(res ? "yes" : "no");
            }
        }
    }
}

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

using namespace std;

using ll = long long;

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

    array<int, 3> d;
    for (int i = 0; i < 3; ++i) cin >> d[i];
    sort(d.begin(), d.end());
    if (d[0] + d[1] == d[2]) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cassert>
const int N=15;
typedef long long ll;
ll dp[N][10];
int main() {
    for(int j=0;j<10;j++) dp[0][j]=1;
    for(int i=1;i<N;i++) {
        for(int j=0;j<10;j++) {
            dp[i][j]=0;
            for(int k=-1;k<2;k++) if(j+k>=0&&j+k<10) {
                dp[i][j]+=dp[i-1][j+k];
            }
        }
    }
    ll K=0;
    scanf("%lld",&K);
    int len=0;
    for(;;len++) {
        ll sum=0;
        for(int j=1;j<10;j++) sum+=dp[len][j];
        if(sum>=K) break;
        K-=sum;
    }
    int first=1,last;
    for(int i=len;~i;i--) {
        int l,r;
        if(first) l=1,r=9;
        else l=last-1,r=last+1;
        l=std::max(l,0);
        r=std::min(r,9);
        int j=l;
        for(;j<=r;j++) {
            if(K<=dp[i][j]) {
                break;
            }
            K-=dp[i][j];
        }
        last=j;
        assert(j<=r);
        printf("%d",j);
        first=0;
    }
    return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n>>m;
      pair<ll,ll> p[ohara];
      rep(i,m){
        cin>>a>>b;
        p[i]=make_pair(a,b);
      }
      sort(p,p+m);
      ll mi=INF;
      rep(i,m){
        mi=min(mi,p[i].second);
        if(p[i].first>=mi){
          ans++;
          mi=p[i].second;
        }
      }
      Cout(ans+1);
     

       
return 0;
}


Measured memory_bytes: 15872
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=100+10; 

int N,W;
bool map[maxm][maxm],Line[maxm],List[maxm]; 
char s[maxm];

int main(){
	register int i,j; 
	scanf("%d%d",&N,&W);
	for(i=1;i<=N;i++){
		scanf("%s",s+1);
		for(j=1;j<=W;j++){
			map[i][j]=(s[j]=='#');
			if(map[i][j]){
				Line[i]=true;
				List[j]=true; 
			} 
		} 
	}
	for(i=1;i<=N;i++){
		if(!Line[i]) continue;
		for(j=1;j<=W;j++){
			if(!List[j]) continue;
			if(map[i][j]){
				putchar('#'); 
			}else{
				putchar('.'); 
			} 
		}putchar('\n'); 
	}
	return 0; 
}

Measured memory_bytes: 256
#include<iostream> 
#include<string>
using namespace std; 
 
int main ()
{
  int a,b,c;
  cin>>a>>b>>c;
  if ((c<=b)&&(c>=a))
  {
      cout<<"Yes\n";
  }
  else
  {
      cout<<"No\n";
  }
    return 0;
}

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

int main(){
    int n,m,l;
    long long A[100][100],B[100][100],C[100][100];
    
    cin >> n >> m >>l;
    for (int i =0; i<n;i++){
        for(int j=0; j<m; j++){
            cin >> A[i][j];
        }
    }
    
    for (int i =0; i<m; i++){
        for(int j=0; j<l ;j++){
            cin >> B[i][j];
        }
    }
    
    for (int i =0; i<n;i++){
        for(int j=0; j<l;j++){
            C[i][j]=0;
            for(int k=0;k<m;k++){
                C[i][j]+=A[i][k]*B[k][j];
            }
        }
    }
    
    for (int i=0;i<n; i++){
        for(int j=0; j<l;j++){
            if (j) cout <<" ";
            cout <<C[i][j];
        }
        cout << endl;
    }
    return 0;
}


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

int main()
{
	string str;
	int N;
	
	cin >> str;
	cin >> N;
	
	for(int i = 0; i < str.size(); i++) {
		if(N <= 0) break;
		if(str[i] == 'a') continue;
		
		if(str[i] + N > 'z') {
			N -= 'z' - str[i] + 1;
			str[i] = 'a';
		}
	}
	if(N >= 1) {
		str[str.size() - 1] += (N % ('z' - 'a' + 1));
		if(str[str.size() - 1] > 'z') {
			str[str.size() - 1] = 'a' + 'z' - str[str.size() - 1] - 1;
		}
		if(str[str.size() - 1] > 'z') {
			str[str.size() - 1] = 'a' + 'z' - str[str.size() - 1] - 1;
		}
	}
	
	cout << str << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define mp(x,y)         make_pair(x,y)
#define all(c)          c.begin(), c.end()
#define ff              first
#define ss              second
#define nl              '\n'
#define inf             1e9+7
 
int main()
{
	ninja
	int t; 
	string s; cin>>s;
	for(int i=1;i<s.size();i++){
		if(s[i]==s[i-1]){
			cout<<"Bad"; return 0;
		}}
		cout<<"Good";
}


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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N = int(input())
A = [int(x) for x in input().split()]

sumV = 0
for x in A:
    sumV += abs(x)

minus = sum(x < 0 for x in A)

if A.count(0) or minus % 2 == 0:
    print(sumV)
    exit()

minV = 1e15
for x in A:
    minV = min(minV, abs(x))

print(sumV - 2 * minV)


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

using namespace std;
long long p=1;
int main() {
    long long n,nrc,k=0;
    cin>>n;
    nrc=log10(n)+1;
    if(nrc==1){
        cout<<n;
    
    }
    if(nrc==2){
        cout<<9;
    }
    if(nrc==3){
        cout<<9+n-99;
    }
    if(nrc==4){
        cout<<909;
    }
    if(nrc==5){
        cout<<909+n-9999;
    }
    if(nrc==6){
        cout<<90909;
    }
    
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int r = sc.NextInt();
        int g = sc.NextInt();

        int answer = 2 * g - r;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092