akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;


int N, T;
vector<pair<int, int>>AB;
int dp[3000 + 10][3000 + 10];

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

	int ans = 0;
	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		AB.push_back(make_pair(a, b));
	}
	sort(AB.begin(), AB.end());

	dp[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= T - 1; j++) {
			dp[i][j] = dp[i - 1][j];

			ans = max(ans, dp[i][j] + AB[i - 1].second);
			if (j - AB[i - 1].first >= 0)
				dp[i][j] = max(dp[i][j], dp[i - 1][j - AB[i - 1].first] + AB[i - 1].second);
		}
	}
	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 38976
#include <bits/stdc++.h>
     
using namespace std;
     
#define ll long long
#define vi vector<int> 
#define pb push_back
#define sz(s) (int)s.size() 
#define all(v) v.begin(), v.end()
 
int h, m, cnt = 1, cnt2 = 1, cnt3 = 1, cnt4 = 1;
     
int main (){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> h >> m;
	cout << ((h * (h - 1)) / 2) + ((m * (m - 1)) / 2);
    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s;
    cin>>s;
    bool ok=false;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < i; j++)
        {
            if(s[i]!=s[j])
            {
                ok=true;
            }
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		
		System.out.println((n*(n+1))/2);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#include <stdio.h>
#define ff(i,x,y)for(int i=x;i<y+1;i++)
#define fs(i,x,y)for(int i=x;i>y-1;i--)
#define all(x) x.begin(),x.end()
#define Ins(x) inserter(x,x.begin())
//set<int>::iterator it
using namespace std;
int num[100010],ans;
int main()
{
    int n;
    scanf("%d",&n);
    ff(i,1,n)
    scanf("%d",&num[i]);
    ff(i,1,n)
    {
        if(num[i]==i)
        {
            ans++;
            swap(num[i],num[i+1]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
  int dig;
  int N, num;
  int sum = 0;
  cin >> N;
  num = N;
  while(num){
    dig = num%10;
    sum += dig;
    num /= 10;
  }
  if (N%sum==0)
  {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back
#define vs vector<string>

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
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;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N,M;
    cin>>N>>M;
    vs A(N);
    vs B(M);
    rep(i,N) cin>>A[i];
    rep(i,M) cin>>B[i];
    rep(i,N-M+1){
        rep(j,N-M+1){
            bool end=false;
            rep(k,M){
                rep(l,M){
                    if(B[l][k]!=A[j+l][i+k]){
                        end=true;
                        break;
                    }
                }
                if(end) break;
                if(k==M-1){
                    cY;
                    return 0;
                }
            }
        }
    }
    cN;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

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

    int n, m;
    cin >> n >> m;
    if (n == m) cout << "Yes";
    else cout << "No";










    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
			var price = IO.ReadInt();
			var bigCoinNum = price / 500;
			price -= (bigCoinNum * 500);
			var smallCoinNum = price / 5;
			IO.Write((bigCoinNum * 1000) + (smallCoinNum * 5));
		}
	}

	public static class IO
	{
		public static string   Read()							   { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')	   { return Read().Split(iSplitter); }
		public static int	   ReadInt()						   { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ')  { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static long	   ReadLong()						   { return int.Parse(Read()); }
		public static long[]   ReadLongArray(char iSplitter = ' ') { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()					   { return Read().ToCharArray(); }

		public static void Write(string iValue)			  { Console.WriteLine(iValue); }
		public static void Write(int iValue)			  { Console.WriteLine(iValue); }
		public static void Write(IEnumerable<int> iValue) { Console.WriteLine(string.Join(" " , iValue)); }
		public static void Write(long iValue)			  { Console.WriteLine(iValue); }
		public static void Write(decimal iValue)		  { Console.WriteLine(iValue); }
		public static void Write(bool iValue)			  { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1) { return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i1 , i0); }
		public static long Lcm(long i0 , long i1) { return (i0 * i1) / Gcd(i0 , i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}

		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
	}
}


Measured memory_bytes: 13140
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Vector.Unboxed   as VU
import qualified Control.Arrow         as Arrow

type Parser a = BSC8.ByteString -> Maybe (a, BSC8.ByteString)
parseInt :: Parser Int
parseInt = fmap (Arrow.second BSC8.tail) . BSC8.readInt
parseM :: Int -> IO (VU.Vector Int)
parseM m = VU.unfoldrN m parseInt <$> BSC8.getLine

main :: IO ()
main = do
  m <- readLn :: IO Int
  xs <- parseM m
  print $ sum $ solver m xs

solver :: Int -> VU.Vector Int -> [Int]
solver n xs = step 0 0 []
  where
    step i tmp ys
      | i == n        = ys
      | current > tmp = step (i + 1) current ys
      | otherwise     = step (i + 1) tmp ((tmp - current) : ys)
      where
        current = xs VU.! i


Measured memory_bytes: 22988
#include <stdio.h>

int main(void)
{
	int i,n,count=0;
	long long int a,b;
	long long int t[2000];
	scanf("%d %lld %lld",&n,&a,&b);
	
	for(i=0;i<=n-1;i++){
		scanf("%lld",&t[i]);
	}
	
	for(i=0;i<=n-1;i++){
		if(t[i]>=a && t[i]<=b-1){
			count++;
		}
	}
	
	printf("%d\n",n-count);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		// 入力
		string[] input = Console.ReadLine().Split(' ');
        var a = int.Parse(input[0]);
		var b = int.Parse(input[1]);
		var c = int.Parse(input[2]);

		//値の判定
        if (a+b+c < 22)
        {
            Console.WriteLine("win");
        }
        else
        {
            Console.WriteLine("bust");
        }
	}
}

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

const int N = 1e5 + 5;
int n, a[N];
long long ans[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
//  freopen("in.txt", "r", stdin);
#endif  // ONLINE_JUDGE
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) {
    if (i & 1)
      ans[0] -= a[i];
    else
      ans[0] += a[i];
  }
  for (int i = 1; i < n; ++i) {
    ans[i] = 2 * a[i - 1] - ans[i - 1];
  }
  for (int i = 0; i < n; ++i) cout << ans[i] << " \n"[i == n - 1];
  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cctype>

using namespace std;

int main() {
	char x;
	for (;;) {
		scanf("%c", &x);
		
		if(x=='\n')break;

		if (islower(x)==0) {
			cout << char(tolower(x));
		}
		else if (islower(x)!=0) {
			cout << char(toupper(x));
		}else{
			cout << x;
		}
	}
		
	cout << endl;

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
#define foreach(i,A) for(auto &i:A)
#define all(A) A.begin(),A.end()
#define len(A) (ll)A.size()
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  vector<ll> D(n);
  vector<ll> C(13);
  rep(i,n){
    cin>>D[i];
    C[D[i]]++;
  }

  rep(i,13){
    if(i==0 && C[i]){
      cout<<0<<"\n";
      return;
    }
    if(i==12 && C[i]>=2){
      cout<<0<<"\n";
      return;
    }
    if(C[i]>=3){
      cout<<0<<"\n";
      return;
    }
  }

  auto check=[&](ll V){
    ll score=INF;
    vector<ll> T(24,1);
    T[0]=0;
    rep(i,n){
      ll d=D[i];
      if((V>>i)&1){
        if(T[d]==0) return (ll)0;
        T[d]=0;
      }else{
        if(T[24-d]==0) return (ll)0;
        T[24-d]=0;
      }
    }
    rep(i,23){
      if(T[i+1]) T[i+1]+=T[i];
    }
    T.push_back(0);
    ll res=INF;
    rep(i,1,25){
      if(T[i]==0) chmin(res,T[i-1]);
    }
    if(res==INF) res=0;
    return res+1;
  };

  ll N=1<<n;
  ll ans=0;
  rep(V,N){
    ll score=check(V);
    chmax(ans,score);
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  string S,T;
  cin >> S >> T;

  map<char, vector<char> > st, ts;

  rep(i,S.size()){
    char s = S[i];
    char t = T[i];

    st[s].pb(t);
    ts[t].pb(s);
  }

  rep(i, 26){
    rmsame(st['a'+i]);
    rmsame(ts['a'+i]);
  }

  rep(i,26){
    char c = 'a' + i;
    if(st[c].size() >1 || ts[c].size() > 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1300
#include<stdio.h>
int main(){
    int W,H,x,y,r;
    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if(0<!W||0<!H||r<=!100||x<0||y<0){
        printf("No\n");
    }else if(x+r<=W&&y+r<=H){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;

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

	 return gcd(b , a%b);
}

ll lcm(ll a, ll b){

	return a*(b/gcd(a,b));
}

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

	vector<ll> X;

	rep(i,n){
		ll tmp; cin>>tmp;
		X.push_back(tmp);
	}
	ll ans = X[0];
	for(int i=1; i<n; i++){
		ans = lcm(ans,X[i]);
	}

	writeln(ans);



}


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

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

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut seq = vec![(0, 0); m];
    let mut l = 0;
    let mut r = n - 1;
    for i in 0..m {
        seq[i].0 = read::<usize>() - 1;
        seq[i].1 = read::<usize>() - 1;
        l = std::cmp::max(l, seq[i].0);
        r = std::cmp::min(r, seq[i].1);
    }
    println!("{}", if l <= r { r - l + 1 } else { 0 });
}


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

int main()
{
  long double a,b;
  cin >> a >> b;
  int ma = a,mb = b;
  
  int ans = -1;
  
  for(int i = 10;i < 1260;i ++){
    int c = i * 0.08;
    int d = i * 0.1;
    if(c == ma && d == mb){ans = i;break;}
  }
  
  
  cout << ans << endl;
}

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 10;

int n;
char str[N];
string t;
map<string, int> h;

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

    LL res = 0;
    for(int i = 0; i < n; i++)
    {
        scanf("%s", str);
        sort(str, str + N);
        t = str;

        if(h.count(t)) res += h[t];
        h[t]++;
    }

    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846

int main(){
	string a,b,i;
	cin>>a>>b;
	if(a.size()>b.size()){
		cout<<"GREATER"<<endl;
	}else if(a.size()<b.size()){
		cout<<"LESS"<<endl;
	}else{
		if(a>b){
			cout<<"GREATER"<<endl;
		}else if(a<b){
			cout<<"LESS"<<endl;
		}else{
			cout<<"EQUAL"<<endl;
		}
	}
}

Measured memory_bytes: 384
#include<stdio.h>

int n,A[50];

//入力値のMから選んだ要素を引いていく再起関数
int solve (int i,int m){
    if(m==0) return 1;
    if(i>=n) return 0;
    int res =solve(i+1,m)||solve(i+1,m-A[i]);
    return res;
}

int main(){
    int q,M,i;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define R cin>>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int N;
    R N;
    vector<int> v(N);
    rep(i, N) R v[i];
    vector<int> s = v;
    sort(all(v));
    float m;
    m = (v[N/2]+v[N/2-1])/2;
    rep(i, N) {
        if (s[i] <= m) {
            cout<<v[N/2]<<endl;
        } else {
            cout<<v[N/2-1]<<endl;
        }
    }
}


Measured memory_bytes: 3712
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 2010
#define MO 924844033
#define LL long long
int d[MAXN*2][MAXN][2],f[MAXN],n,k,tot,fac[MAXN],ans;
bool vis[MAXN][2],ed[MAXN*2];
int main()
{
	scanf("%d%d",&n,&k);
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=1LL*i*fac[i-1]%MO;
	for(int i=1;i<=k;i++)
	{
		tot+=(n-i)/k+1;
		ed[tot]=1;
		tot+=(n-i)/k+1;
		ed[tot]=1;
	}
	ed[0]=1;
	d[0][0][0]=1;
	for(int i=0;i<n*2;i++)
		for(int j=0;j<=n;j++)
		{
			d[i+1][j][0]=(d[i][j][0]+d[i][j][1])%MO;
			if(!ed[i])
				d[i+1][j+1][1]=d[i][j][0];
		}
	for(int i=0;i<=n;i++)
		f[i]=1LL*(d[n*2][i][0]+d[n*2][i][1])%MO*fac[n-i]%MO;
	for(int i=0,j=1;i<=n;j=-j,i++)
		(ans+=f[i]*j)%=MO;
	printf("%d\n",(ans%MO+MO)%MO);
}

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

int main(){
  int a[120000]={0},b,n,sum,cunt;

  for(int i=2;i<120000;i++)
    a[i]=1;

  b=sqrt(120000);

  for(int i=2;i<=b;i++){
    if(a[i]==1){
      for(int j=2*i;j<120000;j+=i)
        a[j]=0;
    }
  }

  while(1){
    cin>>n;
    sum=cunt=0;
    if(n==0)
      break;

    for(int i=2;i<120000;i++){
      if(a[i]==1){
        sum+=i;
        cunt++;
        if(cunt==n)
          break;
      }
    }

    cout<<sum<<endl;
  }

  return 0;
}



Measured memory_bytes: 3536
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb emplace_back
#define x first
#define y second
#define pii pair<int, int>
#define sz(x) (int)(x).size()

double PI = acos(-1.0);

const int prime = 1e9+7;

int mod (int a, int p = prime) {
	return (a%p + p) % p;
}

int32_t main()
{
	IOS;

	int n, k;
	cin >> n >> k;

	int a[n];

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

	int count[n] = {0}, less[n] = {0};

	for(int i = 0; i < n; ++i) {
		for(int j = i+1; j < n; ++j) {
			if(a[j] < a[i]) {
				count[i]++;
			}
		}
	}

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			if(a[j] < a[i]) {
				less[i]++;
			}
		}
	}

	// for(int i = 0; i < n; ++i) {
	// 	cout << less[i] << ' ' << count[i] << '\n';
	// }

	int ans = 0;

	for(int i = 0; i < n; ++i) {
		ans = mod(ans + k*count[i]);
		int temp = mod(k * (k-1) / 2);
		temp = mod(temp * less[i]);
		ans = mod(ans + temp);
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0

int edge[32][32];
int visited[32];
int n,sum,maxcost;
set<int> leaf;

void search_leaf(int node, int prev, int c, int mc){
	bool f = false;
	REP(i,1,n+1)if( !visited[i] && edge[node][i]>0 ){
		f = true;
		visited[i] = 1;
		sum += 2*edge[node][i];
#if DEB
		printf("%d -> %d : sum:%d  mc:%d\n",node,i,sum,mc+edge[node][i]);
#endif		
		search_leaf(i, node, edge[node][i], mc+edge[node][i]);
	}
	if( !f ){
#if DEB
		printf("now:%d  prev:%d   sum:%d -= %d    mc:%d\n",node,prev,sum,2*c,mc-c);
#endif		
		sum -= 2*c;
		maxcost = max(maxcost, mc-c);
		leaf.insert(prev);
	}
	return;
}
int main(){
	while(scanf("%d",&n),n){
		leaf.clear();
		sum = maxcost = 0;
		memset(visited,0,sizeof(visited));
		memset(edge,0,sizeof(edge));
		rep(i,n-1){
			int a,b,t; scanf("%d%d%d",&a,&b,&t);
			edge[a][b] = edge[b][a] = t;
		}
		visited[1] = 1;
		search_leaf(1,1,0,0);

		printf("%d\n",sum-maxcost);
		
#if DEB
		printf("sum: %d   maxcost:%d\n",sum,maxcost);
		cout << "size : " << leaf.size() << endl;
		set<int>::iterator it;
		for(it=leaf.begin(); it!=leaf.end(); it++){
			cout << *it << endl;
		}
#endif

	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[100005],b[100005],c[100005];
ll g[200005];
int x,y,q,w,e;
int main(){
	cin>>x>>y>>q>>w>>e;
	for (int i=0;i<q;i++){
		cin>>a[i];
	}
	for (int i=0;i<w;i++){
		cin>>b[i];
	}
	for (int i=0;i<e;i++){
		cin>>c[i];
	}
	sort(a,a+q);
	sort(b,b+w);
	sort(c,c+e);
	int k=0;
	for (int i=1;i<=x;i++){
		g[k]=a[q-i];
		k++;
	}
	for (int i=1;i<=y;i++){
		g[k]=b[w-i];
		k++;
	}
	sort(g,g+k);
	int f=e-1;
	ll gg=0;
	for (int i=0;i<k;i++){
		if (f>=0){
			if(c[f]>g[i]){
				g[i]=c[f];
				f--;
			}
		}
		gg+=g[i];
	}
	cout<<gg<<endl;
	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

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

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

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

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

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;

bool solve(){
	ll n,m;cin>>n>>m;
	vector<ll>v[m];
	rep(i,n){
		ll x;cin>>x;
		v[x%m].push_back(x);
	}
	ll ans=0;
	for(int i=0;i<=m/2;i++){
		ll s=i;
		ll t=(m-i)%m;
		//cout<<s<<" "<<t<<endl;
		//cout<<v[s].size()<<" "<<v[t].size()<<endl;
		if(s==t){
			ans+=(int)v[s].size()/2;
			continue;
		}
		if(v[s].size()<v[t].size()){
			swap(s,t);
		}
		
		map<ll,ll>mp;
		rep(j,v[s].size()){
			mp[v[s][j]]++;
		}
		ll num=0;
		for(auto p:mp){
			num+=p.second/2;
		}
		//cout<<num<<endl;
		num=min<ll>(num,((int)v[s].size()-(int)v[t].size())/2);
		ans+=num;
		ans+=v[t].size();
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
  	return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(15);
  solve();
}


Measured memory_bytes: 9004
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long

int mmax(int a, int b)
{ //昇順
    return (a > b) ? a : b;
}

int main(void)
{
    int n, i, j, k;
    int count = 0;
    int L[101];
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &L[i]);
    }

    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            for (k = j + 1; k < n; k++)
            {
                int m = mmax(L[i], mmax(L[j], L[k]));
                int to = L[i] + L[j] + L[k];

                if ((m < to - m) && (L[i] != L[j] && L[i] != L[k] && L[j] != L[k]))
                {
                    count++;
                }
            }
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)

#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;

int main() {
	string s; cin >> s;
	if (s.size() == 1) {
		cout << s << endl;
		return 0;
	}

	bool all9 = true;
	rep(i, 1, s.size()) {
		if (s[i] != '9') {
			all9 = false;
		}
	}
	if (all9) {
		if (s[0] == '9') {
			cout << s.size() * 9 << endl;
		}
		else {
			cout << ((s[0] - '0') + (s.size() - 1) * 9) << endl;
		}
		return 0;
	}

	ll ans = (s.size() - 1) * 9 + (s[0] - '0') - 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(H)]
ans = []
for i in range(H):
    for j in range(W):
        if j == W-1:
            if i == H-1:
                continue
            if a[i][j]%2 == 1:
                a[i+1][j] += 1
                ans.append([i+1,j+1,i+2,j+1])
        else:
            if a[i][j]%2 == 1:
                a[i][j+1] += 1
                ans.append([i+1,j+1,i+1,j+2])
print(len(ans))
for a in ans:
    print(*a)

Measured memory_bytes: 69980
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi h(n);
  VIN(h)
  int dp[n+10];
  REP(i,n+10) dp[i] = INF;
  dp[0] = 0;
  FOR(i,1,n){
    chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    if (i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }
  OUT(dp[n-1]);
}

Measured memory_bytes: 1792
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Debug = System.Diagnostics.Debug;
using System.Runtime.CompilerServices;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        string[] s = Enumerable.Repeat(0, n).Select(_ => Console.ReadLine()).ToArray();
        var tailA = s.Count(x => x.Last() == 'A');
        var headB = s.Count(x => x.First() == 'B');
        var res = 0;
        foreach (var item in s)
        {
            for (int i = 0; i < item.Length - 1; i++)
            {
                if (item[i] == 'A' && item[i + 1] == 'B') res++;
            }
        }
        res += Max(0, Min(tailA, headB) - (s.All(x => (x.First() == 'B' && x.Last() == 'A') || (x.First() != 'B' && x.Last() != 'A')) ? 1 : 0));
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 13536
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

string t[10] = { "",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz" };

signed main() {
	int n;
	cin >> n;
	rep(i, 0, n) {
		string s, ans = "";
		cin >> s;
		int now = 0, cnt = 0;
		rep(i, 0, s.size()) {
			if (s[i] =='0') {
				if (now == 0) continue;
				cnt %= t[now].size();
				ans += t[now][cnt];
				now = 0;
				cnt = 0;
			}
			else if (now == 0) {
				now = s[i] - '0';
				cnt = 0;
			}
			else if (now == s[i] - '0') {
				cnt++;
			}
			//cout << i << " " << now << " " << cnt << endl;
		}
		cout << ans << endl;
	}
}

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

int main()
{
    int N;
    scanf("%d", &N);
    vector<pair<int, int>> p(N);
    for (int i = 0; i < N; i++) {
        int x, l;
        scanf("%d%d", &x, &l);
        p[i].first = x - l;
        p[i].second = x + l;
    }

    sort(p.begin(), p.end(), [&](pair<int, int> a, pair<int, int> b) {
        return a.second < b.second;
    });

    int ans = 0;
    int prev = -1e9 - 10;
    for (int i = 0; i < N; i++) {
        if (prev <= p[i].first) {
            prev = p[i].second;
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll inf = 1e18;

ll n, l, r;
ll a[55];
int main() {
	while (cin >> n >> l >> r && n > 0) {
		REP(i, 0, n) {
			cin >> a[i];
		}
		ll ans = 0;
		REP(x, l, r + 1) {
			bool ok = false;
			REP(i,0,n) {
				if (x % a[i] == 0) {
					ok = true;
					if (i % 2 == 0) {
						ans++;
					}
					break;
				}
			}
			if (!ok && n % 2 == 0) {
				ans++;
			}
		}
		p(ans);
	}

	return 0;
}


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

using namespace std;

class UnionFind
{
public:
    void init ()
    {
        for (int i=1; i<100010; i++) link[i]=i;
        for (int i=1; i<100010; i++) sze[i]=1;
    }
    int Find (int x)
    {
        while (x!=link[x]) x=link[x];
        return x;
    }
    bool same (int a, int b)
    {
        return Find(a)==Find(b);
    }
    void unite (int a, int b) //join the sets that contains element a and b
    {                         //(a and b have to be in different sets)
        a=Find(a);
        b=Find(b);
        if (sze[a]<sze[b]) swap(a, b);
        sze[a]+=sze[b]; //connect smaller set to larger set
        link[b]=a;
    }
private:
    int link[100010], sze[100010];
};

int main ()
{
    int n, m, x, y, p[100010], ans=0;
    UnionFind U;
    U.init();
    cin>>n>>m;
    for (int i=1; i<=n; i++) cin>>p[i];
    for (int i=0; i<m; i++)
    {
        cin>>x>>y;
        if (!U.same(p[x], p[y])) U.unite(p[x], p[y]);
    }
    for (int i=1; i<=n; i++)
    {
        if (U.same(i, p[i])) ans++;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll                          long long
#define in(a)                       ll a; cin>>a;
#define in2(a,b)                    ll a,b; cin>>a>>b;
#define in3(a,b,c)                  ll a,b,c; cin>>a>>b>>c;
#define in4(a,b,c,d)                ll a,b,c,d; cin>>a>>b>>c>>d;
#define in5(a,b,c,d,e)              ll a,b,c,d,e; cin>>a>>b>>c>>d>>e;
#define lelo(b)                     for(auto &i:b)cin>>i;
#define ff                          first
#define ss                          second
#define call(v)                     v.begin(),v.end()
#define rall(v)                     v.rbegin(),v.rend()
#define show(x)                     for(auto t:x)cout<<t<<" ";
#define pb                          push_back
#define bhar(s,v)                   memset(s,v,sizeof(s))
#define endl                        "\n"                       
#define ce(x)                       cout<<x<<"\n";
#define nl                          cout<<endl;
#define jaldi                       ios_base::sync_with_stdio(false);cin.tie(NULL);
#define dekh_lo                     ce("dekh_lo");
#define sz(x)                       (ll)x.size()
#define re                          return

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;

const ll mod=1e9+7;
const ll N=1e5+5;
ll i,j;

/*


*/
ll dp[N][3];
void solve(){
	bhar(dp,0);
    in(n);
    vi a(n),b(n),c(n); 
    for(i=0;i<n;i++){
    	cin>>a[i];
    	cin>>b[i];
    	cin>>c[i];
    }
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(i=1;i<n;i++){
    	dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
    	dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
    	dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
   //  for(i=0;i<n;i++){
   //  	for(ll j=0;j<3;j++){
   //      	cout<<dp[i][j]<<" ";
   //  	}
   //  	cout<<endl;
  	// }
    ce(max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}));
}

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

/*


*/

  

Measured memory_bytes: 7944
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String S = sc.next();
		char[] A = new char[N];
		long ans = 0;
		for( int i=0; i<N; i++ ){
			A[i] = S.charAt(i);
		}
		long[] R = new long[N];
		long[] G = new long[N];
		long[] B = new long[N];
		long rr = 0,gg = 0,bb = 0;
		for( int i=N-1; i>=0; i-- ){
			if( A[i]=='R' ){
				rr++;
				R[i] = rr;
			}else{
				R[i] = rr;
			}
			if( A[i]=='G' ){
				gg++;
				G[i] = gg;
			}else{
				G[i] = gg;
			}
			if( A[i]=='B' ){
				bb++;
				B[i] = bb;
			}else{
				B[i] = bb;
			}
		}
		for( int i=0; i<N-2; i++ ){
			for( int j=i+1; j<N-1; j++ ){
				if( A[i]=='R' ){
					if( A[j]=='G' ){
if( j+(j-i)<N ){
						if( A[j+(j-i)]=='B' ){
							ans += B[j+1] - 1;
						}else{
							ans += B[j+1];
						}
}else{
	ans += B[j+1];
}
					}
					if( A[j]=='B' ){
if( j+(j-i)<N ){
						if( A[j+(j-i)]=='G' ){
							ans += G[j+1] - 1;
						}else{
							ans += G[j+1];
						}
}else{
	ans += G[j+1];
}						
					}
				}
				if( A[i]=='B' ){
					if( A[j]=='R' ){
if( j+(j-i)<N ){
						if( A[j+(j-i)]=='G' ){
							ans += G[j+1] - 1;
						}else{
							ans += G[j+1];
						}
}else{
	ans += G[j+1];
}
					}
					if( A[j]=='G' ){
if( j+(j-i)<N ){
						if( A[j+(j-i)]=='R' ){
							ans += R[j+1] - 1;
						}else{
							ans += R[j+1];
						}
}else{
	ans += R[j+1];
}						
					}
				}
				if( A[i]=='G' ){
					if( A[j]=='R' ){
if( j+(j-i)<N ){
						if( A[j+(j-i)]=='B' ){
							ans += B[j+1] - 1;
						}else{
							ans += B[j+1];
						}
}else{
	ans += B[j+1];
}
					}
					if( A[j]=='B' ){
if( j+(j-i)<N ){
						if( A[j+(j-i)]=='R' ){
							ans += R[j+1] - 1;
						}else{
							ans += R[j+1];
						}
}else{
	ans += R[j+1];
}						
					}
				}
			}
		}
		System.out.println(ans);
	}
}



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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

class BinaryIndexTree
{
  public:
    BinaryIndexTree(int n)
        : mN(n)
    {
        node.resize(n + 1);
        REP(i, n + 1)
        {
            node[i] = 0;
        }
    }
    ~BinaryIndexTree()
    {
        node.resize(0);
    }

    //! 1-index get
    ll sum(int index)
    {
        ll sum = 0;
        for (int i = index; i > 0; i -= i & (-i))
            sum += node[i];
        return sum;
    }

    //! 1-index add
    void add(int index, ll value)
    {
        for (int i = index; i <= mN; i += i & (-i))
            node[i] += value;
    }

  private:
    vector<ll> node;
    ll mN;
};

ll C[30];
stack<ll> T[30];
ll N[200005];

int main()
{
    string S;
    cin >> S;
    memset(C, 0, sizeof(C));
    REP(i, S.length())
    {
        C[S[i] - 'a']++;
        T[S[i] - 'a'].push(i);
    }
    int odd = 0, even = 0;
    REP(i, 26)
    {
        if (C[i] % 2 == 0)
            even++;
        else
            odd++;
    }
    if (odd > 1 || (odd == 1 && S.length() % 2 == 0))
    {
        cout << -1 << endl;
        return 0;
    }
    memset(N, 0, sizeof(N));
    int cnt = 0;
    REP(i, S.length())
    {
        if (N[i] > 0)
            continue;
        FOR(j, S.length(), i)
        {
            if (C[S[j] - 'a'] >= 2)
            {
                N[j] = cnt + 1;
                ll last = T[S[j] - 'a'].top();
                T[S[j] - 'a'].pop();
                N[last] = S.length() - cnt;
                C[S[j] - 'a'] -= 2;
                cnt++;
                break;
            }
        }
    }
    REP(i, 26)
    {
        if (C[i] == 0)
            continue;
        ll j = T[i].top();
        N[j] = S.length() / 2 + 1;
        break;
    }

    BinaryIndexTree bit(S.length());

    ll sum = 0;
    REP(i, S.length())
    {
        sum += i - bit.sum(N[i]);
        bit.add(N[i], 1);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 5252
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC156
{
    class Program
    {
        static void Main(string[] args)
        {
            c();
        }
        
        public static void c()
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(x);
            Array.Reverse(x);
            int max = x[0];
            //Console.WriteLine(max);
            double sum = 1000000000;
            for(int i = 1; i < max + 1 ; i++)
            {
                double y = 0;
                for(int j = 1; j < n+ 1; j++)
                {
                    double a = Math.Pow(x[j - 1] - i, 2);
                    y += a;
                }
                //Console.WriteLine(y);
                sum = Math.Min(sum, y);
                //Console.WriteLine(sum);
                sum = Math.Floor(sum);
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;

int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> vec;
  rep(i,m){
    int a,b;
    cin >> a >> b;
    vec.push_back(make_pair(a,b));
  }
  sort(vec.begin(),vec.end());
  int cnt=0;
  int now=n;
  rep(i,m){
    if(i==0){
      cnt++;
      now=vec[m-1].first;
    }
    else{
      if(vec[m-1-i].second<=now){
        cnt++;
        now=vec[m-1-i].first;
      }
    }
  }
  
  cout<<cnt<<endl;
}
    

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200005;
 
int a[N],n,num;
ll ans=0;
 
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) 
        scanf("%d",a+i),a[i]-=i;
    sort(a+1,a+n+1),num=a[(n+1)>>1];
    for(int i=1;i<=n;i++) 
    ans+=(ll)abs(num-a[i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) b.rbegin(),v.rend()
typedef long long ll;
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int k;
  cin >> k;
  queue<ll> que;
  int count = 0;
  for(int i=1; i<=9; i++){
    que.push(i);
    count++;
    if(count==k){
      cout << i << endl;
      return 0;
    }
  }
  while(true){
    ll x = que.front();
    que.pop();
    for(int i=-1; i<=1; i++){
      ll d = x%10+i;
      if(d<0||d>9){
        continue;
      }
      que.push(10*x+d);
      count++;
      if(count==k){
        cout << 10*x+d << endl;
        return 0;
      }
    }
  }
}

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

using namespace std;
int dp[100001];

int main()
{
	int n, d, x;
	int p[11][11];

	scanf("%d %d %d", &n, &d, &x);

	for (int i = 0; i < d; i++){
		for (int j = 0; j < n; j++){
			scanf("%d", &p[i][j]);
		}
	}

	
	for (int i = 0; i < d - 1; i++){
		memset(dp, 0, sizeof(dp));
		for (int j = 0; j < n; j++){
			for (int k = 0; k + p[i][j] <= x; k++){
				dp[k + p[i][j]] = max(dp[k + p[i][j]], dp[k] + p[i + 1][j] - p[i][j]);
			}
		}

		x = x + dp[x];
	}

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

	return (0);
}

Measured memory_bytes: 1588