akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/
const int mod = 1e9 + 7;





int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  int n; cin >> n;
  LL ret = 1, a = 1, b = 1;
  for (int i = 1; i <= n; i++) {
    ret = ret * 10 % mod;
    a = a * 9 % mod;
    b = b * 8 % mod;
  }
  ret = (ret - a - a + b) % mod;
  while(ret < 0) ret += mod;
  cout << ret << '\n';








/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 3180
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void) {
	string s;
	cin >> s;
	int a[26] = {};

	for (int i = 0; i < s.size(); i++)
	{
		a[s[i]-'a']++;
	}

	for (int i = 0; i < 26; i++)
	{
		//cout << i << "\n";
		if (a[i] >= 2) {
			cout << "no\n";
			break;
		}

		if (i == 25)cout << "yes\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s[100005];
map<string,int>mp;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) cin>>s[i],mp[s[i]]++;
	printf("AC x %d\n",mp["AC"]);
	printf("WA x %d\n",mp["WA"]);
	printf("TLE x %d\n",mp["TLE"]);
	printf("RE x %d\n",mp["RE"]);
	return 0;
}

Measured memory_bytes: 6892
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
n = len(s)
chars = set(s)

ans = 10**18

for ci in chars:
    cur = s
    if len(set(s)) == 1 and s[0] == ci:
        ans = 0
        break
    
    cnt = 1
    for ln in range(n):
        nex = ""
        for idx in range(len(cur)-1):
            if cur[idx] == ci or cur[idx+1] == ci:
                nex += ci
            else:
                nex += cur[idx]
                
        if len(set(nex)) == 1 and nex[0] == ci:
            break
        
        cnt += 1
        cur = nex
        
    ans = min(ans, cnt)
        
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
#include<math.h>
using namespace std;

int main() {
	int num, ber, number, ans = 0;
	vector<int> length;
	cin >> num >> ber;
	for (int i = 0; i < num; i++)
	{
		cin >> number;
		length.emplace_back(number);
	}
	for (int i = 0; i < ber; i++)
	{
		sort(length.begin(), length.end());
		ans += length.back();
		length.pop_back();
	}

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

Measured memory_bytes: 256
import numpy

N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
D = numpy.array(D)
D = D[:, 0] - D[:, 1]

ans = 'No'
count = 0
for i in range(N):
    if D[i] == 0:
        count += 1

        if count == 3:
            ans = 'Yes'
            break
    else:
        count = 0

print(ans)

Measured memory_bytes: 27280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String ans = s.contains("A") && s.contains("B") ? "Yes" : "No";
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 21716
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	vll a(3);
	cin >> a[0] >> a[1] >> a[2];
	ll k;
	cin >> k;
	sort(a.begin(), a.end());
	cout << pow(2, k) * a[2] + a[0] + a[1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }

int dp[100005];
vei child[100005];

void bfs(int from) {
    if(dp[from] != 0) return ;
    int maxi = 0;
    rep(i,child[from].size()) {
        int to = child[from][i];
        bfs(to);
        maxi = max(maxi, dp[to]);
    }
    dp[from] = maxi + 1;
    return  ;
}

int main() {
    int n, m;
    cin >> n >> m;
    rep(i,m) {
        int x, y;
        cin >> x >> y;
        child[x].pub(y);
    }
    int res = 0;
    rep(i,n+1) {bfs(i); res = max(res, dp[i]);}
    cout << res - 1 << endl;
    return 0;
    
}

Measured memory_bytes: 9472
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
	int  n;
    string str; 
    cin >> n >> str ;  
    int f=0,s=0;
    for (int i=0;i<sz(str);i++){
    	if (str[i]=='(') s++;
    	else {
    		if (s>0) s--;
    		else f++;
    	}
    }
    for (int i=0;i<f;i++) cout << "(" ;
    cout << str ;
	for (int i=0;i<s;i++) cout << ")";
	cout << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

int main(){
  int a,b,x;
  cin >> a >> b >> x;
  if(a<=x && x<=(a+b))cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
class SearchII
  def solve
    n = gets.chomp.to_i
    s = gets.scan(/\d+/).map(&:to_i)
    q = gets.chomp.to_i
    t = gets.scan(/\d+/).map(&:to_i)

    t.sort!

    i = 0
    j = 0
    cnt = 0

    while ((i < s.length) && (j < t.length))
      if (s[i] == t[j])
        cnt += 1
        i += 1
        j += 1
      elsif (s[i] > t[j])
        j += 1
      else
        i += 1
      end
    end
    return cnt.to_s
  end
end

if $0 == __FILE__
  puts SearchII.new.solve
end

Measured memory_bytes: 16804
from itertools import accumulate
R, C, K = map(int, input().split())
vss = [[None]*C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    vss[r-1][c-1] = v

dp = []

for y in range(R):
    ndp = []
    for x in range(C):
        tmp = []
        uemax = 0
        if y > 0:
            uemax = max(dp[x])
        if vss[y][x] is None:
            if x > 0:
                left = ndp[-1]
                tmp.append(left[0] if left[0] > uemax else uemax)
                tmp.append(left[1])
                tmp.append(left[2])
                tmp.append(left[3])
            else:
                tmp.append(uemax)
                tmp.append(0)
                tmp.append(0)
                tmp.append(0)
        else:
            v = vss[y][x]
            if x > 0:
                left = ndp[-1]
                tmp.append(left[0] if left[0] > uemax else uemax)
                tmp.append(max(left[0]+v, left[1], uemax+v))
                tmp.append(left[1]+v if left[1]+v > left[2] else left[2])
                tmp.append(left[2]+v if left[2]+v > left[3] else left[3])
            else:
                tmp.append(uemax)
                tmp.append(uemax + v)
                tmp.append(0)
                tmp.append(0)
        ndp.append(tmp)
    dp = ndp

print(max(dp[-1]))


Measured memory_bytes: 224428
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
    ll n ,m;
    cin >> n >> m;
    ll a[n];
    ll sum =0;
    for(int i=0;i<n;i++) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a,a+n,greater<ll>());

    ll count = 0;
    for(int i=0;i<n;i++) {
        if((double)a[i] >= (double)sum/(4*(double)m)) {
            count++;
        }
        else{
            break;
        }
    }
   // cout << count<<endl;
    if(count>=m) {
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }

}

signed main() {
    boost;
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=1005;

char s[maxn];
char t[]="AKIHABARA";

int main()
{
    while(~scanf("%s", &s)){
        int len=strlen(s);
        if(len>9){printf("NO\n");return 0;}
        int pos=0;
        for(int i=0;i<len;i++){
            if(s[i]==t[pos])pos++;
            else if(t[pos]=='A'){
                pos++;i--;
            }
            else{
                printf("NO\n");return 0;
            }
        }
        if(pos>=8)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll M=1e5;
int main()
{
	ll n;cin>>n;
	string s;
	cin>>s;
	ll len=s.length();
	ll r=0,b=0;
	for(ll i=0;i<len;i++){
		if(s[i]=='R') r++;
		else b++;
	}
	
	if(r>b){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)
int main()
{
    int k, ans = 0;
    cin >> k;
    repi(i, k + 1, 1)
    {
        repi(j, k + 1, 1)
        {
            repi(l, k + 1, 1)
            {
                ans += gcd(gcd(i,j),l);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
// retrieve the input and store it in an array of "words"
var input = require('fs').readFileSync('/dev/stdin').toString();
var inputArray = input.split(" ");
 
var words = {};			// An object where the key is the word and the value is number of times it has appeared
var mostAppearedValue = 0;	// The number of times that the word that has appeared the most has appeared
var mostAppearedIndex = 0;	// The index in the inputArray where the word that appears the most first appeared
var longestValue = 0;		// The number of letters in the longest word
var longestIndex = 0;		// The index in the inputArray where the longest word first appeared
 
// go through every word
for (var i = 0; i < inputArray.length; i++) {
	// if the word is already registered in the word object
	if (words[inputArray[i]]) {
		// update the number of times this word has appeared
		words[inputArray[i]]++;
	}
	// if the word is not already registered in the word object
	else {
	// add the word to the words array and assign it an initial value of 1
	words[inputArray[i]] = 1;
 
		// check if this word is longer than the current longest word
		if (inputArray[i].length > longestValue) {
			longestValue = inputArray[i].length;
			longestIndex = i;
		}
	}
 
	// check if this word now appears more than the previous most common word
	if (words[inputArray[i]] > mostAppearedValue) {
		mostAppearedValue = words[inputArray[i]];
		mostAppearedIndex = i;
	}
}
 
// finally print out the word that appeared the most followed by the longest word
console.log(inputArray[mostAppearedIndex] + " " + inputArray[longestIndex]);

Measured memory_bytes: 15268
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,i,ans=0,m;cin>>N;ll A[N];REP(i,N)cin>>A[i];sort(A,A+N);
  if(N%2){
    REP(i,N){
      if(i<(N-1)/2)ans-=2*A[i];
      else if(i<(N+3)/2)ans+=A[i];
      else ans+=2*A[i];
    }
    m=ans;ans=0;reverse(A,A+N);
    REP(i,N){
      if(i<(N-1)/2)ans+=2*A[i];
      else if(i<(N+3)/2)ans-=A[i];
      else ans-=2*A[i];
    }
  }
  else{
    REP(i,N){
      if(i<N/2-1)ans-=2*A[i];
      else if(i<N/2)ans-=A[i];
      else if(i<N/2+1)ans+=A[i];
      else ans+=2*A[i];
    }
    m=ans;ans=0;reverse(A,A+N);
    REP(i,N){
      if(i<N/2-1)ans+=2*A[i];
      else if(i<N/2)ans+=A[i];
      else if(i<N/2+1)ans-=A[i];
      else ans-=2*A[i];
    }
  }
  cout<<max(ans,m)<<endl;
  return 0;
}

Measured memory_bytes: 4388
#include<iostream>
long long K;
using namespace std;
int main() {
    cin >> K;
    long long odd = 0, even=0;
    
	if (K % 2 == 0){
      even = K /2;
      odd = K - even;
    }else{
      odd = K/2+1;
      even = K - odd;
    }
  
  	cout << odd*even << flush;
  
}

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

int main() {
  int n,t;
  cin >> n >> t;
  
  vector<pair<int, int>> ct(n);
  for (int i=0; i<n; i++){
    cin >> ct.at(i).first >> ct.at(i).second;
  }
  
  int minc = 1e9;
  
  for (int i=0; i<n; i++){
    if (ct.at(i).second <= t){
      if (minc > ct.at(i).first){
        minc = ct.at(i).first;
      }
    }
  }
  
  if (minc == 1e9) cout << "TLE" << endl;
  else cout << minc << endl;
  
}


Measured memory_bytes: 256
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
x = [0]*5
for i in range(5):
    x[i] = I()

move = min(x)

print(4+math.ceil(N/move))

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

int main() {
    string s, ans = "CODEFESTIVAL2016";
    int cnt = 0;
    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != ans[i])
        {
            cnt++;
        }
        
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??£?¨?
		int HanakoPoint = 0;
		int TaroPoint = 0;
		//??????????????°?????????
		int n = sc.nextInt();
		//???????????° ??°?????????
		for(int i = 0; i< n; i++){
			//???????????????
			String Tarocard = sc.next();
			//??±????????????
			String Hanakocard = sc.next();
			//???????????????????????????
			if(Tarocard.compareToIgnoreCase(Hanakocard) < 0){
			//?????? 3????????????
				HanakoPoint += 3;
			}else if(Tarocard.compareToIgnoreCase(Hanakocard) == 0){
			//???????????? //1????????????
				TaroPoint ++;
				HanakoPoint++;
			}else{
			//?????? 0????????????
				TaroPoint += 3;
			}
		}
			//??????????????????????????¨???
			System.out.println(TaroPoint + " "+ HanakoPoint);
	}
}

Measured memory_bytes: 29744
class UnionFind:
  
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.rank = [0]*n
    self.num = n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  
  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    self.num -= 1
    if self.rank[x]<self.rank[y]:
      self.par[x] = y
    else:
      self.par[y] = x
      if self.rank[x]==self.rank[y]:
        self.rank[x] += 1
  
  def same(self, x, y):
    return self.find(x)==self.find(y)
  
  def psize(self):
    return self.num

N, M = map(int, input().split())
union = UnionFind(N)
for i in range(M):
  x, y, z = map(int, input().split())
  union.unite(x-1, y-1)
for i in range(N):
  m = union.find(i)
ans = set(union.par)
print(len(ans))

Measured memory_bytes: 13984
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int a, b;
    cin >> a >> b;
    if (a >= 13) {
        cout << b << endl;
    }
    else if (a >= 6) cout << b/2 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);
		int A = s.nextInt();
		int B = s.nextInt();

		if (A >= 13) {
			System.out.println(B);
		} else if (A >= 6) {
			System.out.println(B / 2);
		} else {
			System.out.println(0);
		}

	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
 
// headers {{{
using namespace std;
// using namespace rel_ops;
 
typedef long long int64;
typedef unsigned long long uint64;
const double pi=acos(-1.0);
const double eps=1e-11;
const int inf=0x7FFFFFFF;
template<class T> inline bool checkmin(T &a,T b){return b<a?a=b,1:0;}
template<class T> inline bool checkmax(T &a,T b){return b>a?a=b,1:0;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define mem(a,b) memset(a, b, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define rep(i,n) for(int i=0; i<n; i++)
#define repit(i,v) for(typeof(v.begin()) i=v.begin(); i!=v.end(); i++)
#define iter(v) typeof(v.begin())
#define ff first
#define ss second
#ifdef LOCAL
#define dbg(args...) printf(args); //##__VA_ARGS__
#define dout cout
#define out(x) (cout<<#x<<": "<<x<<endl)
template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}
#else
#define dbg(...)
#define dout if(true);else cout
#define out(...)
#define show(...)
#endif
// }}}

map<int64, int64> mp;
int64 d[] = {2, 3, 5};
int64 cost[3], one;
int64 ans;
int64 cc = 0;
int64 dfs(int64 N) {
    cc++;
    if (N == 0) return 0;
    if (mp.count(N)) return mp[N];
    int64 now = 1e18;
    rep(i, 3) rep(k, 2) {
        int64 t = N / d[i] + k;
        if (t>=N) continue;
        int64 c = cost[i] + abs(t * d[i]-N)*one;
        if (c > ans) continue;
        if (double(N-t)*one < c && (N-t)*one < c) {
            c = (N-t)*one;
        }
        checkmin(now, dfs(t) + c);
    }
    mp[N] = now;
    // dout << N << ' '<<now<<endl;
    return now;
}
int main() {
    ios_base::sync_with_stdio(false);
    int T; cin >> T; rep(cas, T) {
        ans = 1e18;
        int64 N;
        mp.clear();
        cin >> N; rep(i,3) cin>>cost[i]; cin>>one;
        cc=0;
        cout << dfs(N) << endl;
        out(cc);
    }
    return 0;
}



Measured memory_bytes: 4760
k, n = list(map(int, input().split()))

a = list(map(int, input().split()))
a.append(a[0] + k)
# (K - 最大辺の長さ)を求めたい

max = 0
for x, y in zip(a, a[1:]):
    if max < y-x:
        max = y-x

print(k-max)



Measured memory_bytes: 26444
import sys


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


def resolve():
    n = int(input())
    l = list(map(int, input().split()))
    cnt=0
    cnt3200=0
    for i in range(1,9):
        x=400*i
        y=400*(i-1)
        for j in l:
            if y<=j<x:
                cnt+=1
                break
    for i in l:
        if i>=3200:
            cnt3200+=1
    if cnt==0:
        print(1,cnt3200)
    else:
        print(cnt,cnt+cnt3200)
resolve()

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


public class Main{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x[] = new int[n];	
		int xs[] = new int[n];
		
		for(int i = 0; i < n; i ++) {
			x[i] = sc.nextInt();
			xs[i] = x[i];
		}
		
		Arrays.sort(xs);
		
		int a = n / 2;
		int b = n / 2 - 1;
		
		for(int i = 0; i < n; i ++){
			if(x[i] <= xs[b]) {
				System.out.println(xs[a]);
			}else {
				System.out.println(xs[b]);
			}
		}
	}
}


Measured memory_bytes: 93744
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,arr[100005],v,cnt=0;
     bool mp[100005];
     mem(mp,0);
     cin>>t;
     for(int i=1;i<=t;i++)
     {
         cin>>v;
         arr[i]=v;
     }
     v=1;
     mp[1]++;
     while(true)
     {
         v=arr[v];
         cnt++;
         if(v==2)
            {
                cout<<cnt;
                return 0;
            }
         else if(mp[v]==1)
         {
             cout<<"-1";
             return 0;
         }
         mp[v]++;
     }

}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>

using lint = long long;

void solve() {
    std::vector<lint> xs;

    std::function<void(lint, int, int)>
        dfs = [&](lint acc, int p, int d) -> void {
        if (d == 0) {
            xs.push_back(acc);
            return;
        }

        for (int x = p - 1; x <= p + 1; ++x) {
            if (x < 0 || 9 < x) continue;
            dfs(acc * 10 + x, x, d - 1);
        }
    };

    constexpr int X = 10;
    for (int d = 0; d < X; ++d) {
        for (int i = 1; i <= 9; ++i) {
            dfs(i, i, d);
        }
    }

    std::sort(xs.begin(), xs.end());

    int k;
    std::cin >> k;
    std::cout << xs[k - 1] << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 2420
k = int(input())
now = 1
step = 1
def s(n):
    r = 0
    while n:
        r += n % 10
        n //= 10
    return r
def ok(a, b):
    return a * s(b) <= b * s(a)
while k:
    if ok(now, now + step):
        print(now)
        k -= 1
        now += step
    else:
        nstep = step * 10
        while now % nstep != nstep - 1:
            now += step
        step = nstep

Measured memory_bytes: 66572
#include <iostream>
#include <stdio.h>
#include <vector>

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    std::vector <std::string> a;
    std::vector <std::string> b;
    std::string s;
    for(int i=0;i<n;i++)
    {
        std::cin>>s;
        a.push_back(s);
    }
    for(int i=0;i<m;i++)
    {
        std::cin>>s;
        b.push_back(s);
    }
    for(int j=0;j<=n-m;j++)
    {
        std::string::size_type pos1 = a[j].find(b[0],0);
        if(pos1!=std::string::npos){
            int num=1;
            if(m==1){
                std::cout<<"Yes"<<"\n";
                    return 0;
            }
            for(int k=1;k<m;k++)
            {
                num++;
                if(num==m){
                    std::cout<<"Yes"<<"\n";
                    return 0;
                }
                std::string::size_type pos2 = a[j+k].find(b[k],pos1);
                if(pos2!=pos1)break;
                
            }
        }
    }
    std::cout<<"No"<<"\n";
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
D = int(input())
C = list(map(int,input().split())) #C[i]AiCを実施しないと下がる満足度
S = [] #S[i][j] i日目にAjcというコンテストを実施した場合に上がる満足度
for i in range(D): #コンテストは0index
    temp = list(map(int,input().split()))
    S.append(temp)
T = []
dic = defaultdict(list)
for i in range(D):
    temp = int(input())
    temp-=1 #0index
    T.append(temp)
    dic[temp].append(i)
for i in range(len(dic)):
    dic[i].sort()
M = int(input())
DQ = []
for i in range(M):
    d,q = map(int,input().split())
    DQ.append((d,q))
#since = [0 for _ in range(26)] #最後に開催されてから何日経ったか。
#manzoku = 0
def cycle(T):
    manzoku = 0
    since = [0 for _ in range(26)]
    for i in range(26):
        since[i] += C[i]
    for i in range(D):
        contest = T[i] #0index
        manzoku += S[i][contest]
        for j in range(26):
            if j != contest:
                manzoku -= since[j]
        #print(manzoku)
        for j in range(26):
            if j != contest:
                since[j] += C[j]
            else:
                since[j] = C[j]
    return manzoku
score = cycle(T)
#print(score)
for i in range(M):
    #print(dic)
    d,q = DQ[i] #d日目をAqCに変える。
    d-=1;q-=1 #0indexへ
    old = T[d]
    try:
        oscore = nscore*1
    except:
        oscore= score*1
    dic[old].remove(d)
    T[d] = q
    if old == q:
        nscore = oscore
    else:
        impact = S[d][q]-S[d][old] #コンテスト実施による満足度の変化の差
        #print(impact,C[q],C[old])
        if not dic[q]:
            impact += C[q]*(D-d)*(d+1)
        else:
            for j in range(len(dic[q])):
                if d < dic[q][0]:
                    impact += C[q]*(d+1)*(dic[q][0]-d)
                    break
                elif d > dic[q][-1]:
                    impact += C[q]*(D-d)*(d-dic[q][-1])
                    break
                else:
                    if dic[q][j] < d and d < dic[q][j+1]:
                        impact += C[q]*(d-dic[q][j])*(dic[q][j+1]-d)
                        break
        dic[q].append(d)
        dic[q].sort()
        if not dic[old]:
            impact -= C[old]*(D-d)*(d+1)
        else:
            for j in range(len(dic[old])):
                if d < dic[old][0]:
                    impact -= C[old]*(d+1)*(dic[old][0]-d)
                    break
                elif d > dic[old][-1]:
                    impact -= C[old]*(D-d)*(d-dic[old][-1])
                    break
                else:
                    if dic[old][j] < d and d < dic[old][j+1]:
                        impact -= C[old]*(d-dic[old][j])*(dic[old][j+1]-d)
                        break
        nscore = oscore+impact
    #nscore = cycle(T)
    print(nscore)
    #if nscore >= score:
    #    print(nscore)
    #else:
    #    print(score)
    #    T[d] = old

Measured memory_bytes: 85980
N, K=map(int, input().split())
R, S, P=map(int, input().split())
T=input()
dp=[[0 for _ in range(N)] for _ in range(3)]
for i in range(N):
  if i>=K:
    dp[0][i]+=max(dp[1][i-K], dp[2][i-K])
    dp[1][i]+=max(dp[0][i-K], dp[2][i-K])
    dp[2][i]+=max(dp[0][i-K], dp[1][i-K])
  dp[0][i]+=R if T[i]=='s' else 0
  dp[1][i]+=S if T[i]=='p' else 0
  dp[2][i]+=P if T[i]=='r' else 0
ans=0
for i in range(N-K, N):
  ans+=max(dp[0][i], dp[1][i], dp[2][i])
print(ans)

Measured memory_bytes: 58352
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int compare(string str1, string str2){
	if(str1.size() > str2.size()){
		return 1;
	}else if(str1.size() < str2.size()){
		return -1;
	}else if(str1 > str2){
		return 1;
	}else if(str1 < str2){
		return -1;
	}else if(str1 == str2){
		return 0;
	}
	return 0;
}

string exist(int y, int x, int H, int W, string DP[100][100]){
	string str;
	if(y < 0 || x < 0 || y >= H || x >= W){
		str = "";
	}else{
		str = DP[y][x];
	}
	return str;
}

int main(){
	
	int W, H;
	
	string DP[100][100];
	
	string map[100];
	
	string ans;
	
	while(true){
		cin >> W >> H;
		if(W == 0 || H == 0){
			break;
		}
		for(int i = 0; i < H; i++){
			cin >> map[i];
		}
		
		string str;
		
		string str1, str2;
		
		ans = "0";
		
		for(int x = 0; x < W; x++){
			for(int y = 0; y < H; y++){
				if(map[y][x] <= '9' && map[y][x] >= '0'){
					str = "S";
					str[0] = map[y][x];
					str1 = exist(y - 1, x, H, W, DP);
					str2 = exist(y, x - 1, H, W, DP);
					if(compare(str1, str2) == 1){
						DP[y][x] = str1 + str;
					}else{
						DP[y][x] = str2 + str;
					}
					if(DP[y][x].size() == 1 && DP[y][x][0] == '0'){
						DP[y][x] = "";
					}
					if(compare(DP[y][x], ans) == 1){
						ans = DP[y][x];
					}
				}else{
					DP[y][x] = "";
				}
			}
		}
		/*
		for(int y = 0; y < H; y++){
			for(int x = 0; x < W; x++){
				cout << DP[y][x] << " ";
			}
			cout << endl;
		}
		*/
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1436
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
         
        int W = scan.nextInt();
        int H = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();
        int r = scan.nextInt();
        if ((x-r) < 0 || W < (x+r) || (y-r) < 0 || H < (y+r)){
        	System.out.println("No");
        	return;
        }
        System.out.println("Yes");
    }
}

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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
//#define MOD 1000000007
#define MOD 998244353
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int atcoder(){
  string s;
  int ans=0;
  cin>>s>>s;
  REP(i,0,s.length()){
    if(s[i]=='R') ans++;
    else ans--;
  }
  if(ans>0) cout<<"Yes"<<ENT;
  else cout<<"No"<<ENT;

}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 256
n=int(input())
lst=[]
for i in range(n):
	s=input()
	lst.append(s)
from collections import Counter
lst=Counter(lst)
print("AC","x",lst["AC"])
print("WA","x",lst["WA"])
print("TLE","x",lst["TLE"])
print("RE","x",lst["RE"])

Measured memory_bytes: 16392
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define TO_STRING(x) #x
# define debug(x) {cerr<<#x<<": "<<(x)<<"\n";}
using namespace std;
using lint = long long;
template<class T> using grid = vector<vector<T>>;
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; }
static const lint MOD = (lint)1e9+7;

int main()
{
    int N;
    cin >> N;
    vector<int> p(N);
    rep (i, N)
    {
        cin >> p[i];
    }

    vector<int> cp = p;

    sort(ALL(cp));

    lint cnt = 0;
    rep (i, N)
    {
        if (p[i] != cp[i])
        {
            cnt++;
        }
    }

    if (cnt == 2 || cnt == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define in std::cin
#define out std::cout

template<class T> inline T min(T a, T b) { return a < b ? a : b; }

int main() {
    int N; in >> N;
    long long h[N], dp[N];
    for (int i = 0; i < N; i++) {
        in >> h[i];
        dp[i] = 1LL << 60;
    }
    dp[0] = 0;

    for (int i = 1; i < N; i++) {
        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) {
            dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
    }

    out << dp[N - 1];

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
using namespace std;
//using namespace boost::multiprecision;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}



int main(){
  
  int n,k;
  cin>>n>>k;
  long long r,s,p;
  cin>>r>>s>>p;
  string t;
  cin>>t;
  long long ans = 0;
  vector<string> st(k, "");
  REP(i,n){
    st[i%k] += t[i];
  }
  REP(i,k){
    int m = st[i].size();
    string tt = st[i];
    long long dp[m][3] = {};
    REP(j,m){
      if(j == 0){
        if(tt[j] == 's'){
          dp[j][0] = r;
        }else if(tt[j] == 'p'){
          dp[j][1] = s;
        }else{
          dp[j][2] = p;
        }
        continue;
      }
      REP(now, 3){
        REP(pre, 3){
          if(now == pre)continue;
          if(now == 0 && tt[j] == 's'){
            dp[j][now] = max(dp[j][now], dp[j-1][pre] + r);
          }else if(now == 1 && tt[j] == 'p'){
            dp[j][now] = max(dp[j][now], dp[j-1][pre] + s);
          }else if(now == 2 && tt[j] == 'r'){
            dp[j][now] = max(dp[j][now], dp[j-1][pre] + p);
          }else{
            dp[j][now] = max(dp[j][now], dp[j-1][pre]);
          }
        }
      }
    }
    long long temp = 0;
    REP(now,3){
      temp = max(temp, dp[m-1][now]);
    }
    ans += temp;
  }
  cout<<ans<<endl; 
  return 0; 
}


Measured memory_bytes: 5120
N = int(input())
S = input()
T = input()
kaburi = 0
for i in range(N):
    #sの末尾とtの先頭を比べる
    #print("sの末尾"+str(i+1)+"文字目"+S[-(i+1):])
    #print("Tの先頭"+str(i+1)+"文字目"+T[0:i+1])
    if S[-(i+1):] == T[0:i+1]:
        kaburi = len(S[-(i+1):])
print(2*N-kaburi)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int a,b,c,i=0,s,p;
	cin>>a>>b;
	c=b;
	while(b>0)
	{
		b=b/10;
		i++;
	}
	s=pow(10,i);
	a=a*s+c;
	p=sqrt(a);
	if(p*p==a)
	    cout<<"Yes";
	else
	    cout<<"No";
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
str = raw_input()
for _ in xrange(input()):
 ops = raw_input().split()
 a = int(ops[1])
 b = int(ops[2]) + 1
 op = ops[0]
 if op[0]=="p": print str[a:b]
 elif op[2]=="v": str = str[:a] + str[a:b][::-1] + str[b:]
 else: str = str[:a] + ops[3] + str[b:]

Measured memory_bytes: 6464
#include<stdio.h>

struct Node_struct{int id, par, dep, child, sib;};
typedef struct Node_struct Node;
Node node[200000];

void dfs(int pos, int dep){
  node[pos].dep = dep;
  if(node[pos].child != -1) dfs(node[pos].child, dep + 1);
  if(node[pos].sib != -1) dfs(node[pos].sib, dep);
}

void prChilds(int pos, int init){
  if(pos == -1) return;
  if(init) printf("%d", pos);
  else printf(", %d", pos);
  if(node[pos].sib != -1) prChilds(node[pos].sib, 0);
}

int main(){
  int i, j, k;
  int N;
  int id, sib, child;
  int root = 0;
  scanf("%d", &N);
  for(int i=0;i<N;i++) node[i].par = node[i].child = node[i].sib = -1;
  
  for(i=0;i<N;i++){
    scanf("%d %d", &id, &k);
    node[id].id = id;
    for(j=0;j<k;j++){
      scanf("%d", &child);
      node[child].par = id;
      if(j == 0) node[id].child = child, sib = child;
      else node[sib].sib = child;
      sib = child;
    }
  }


  for(i=0;i<N;i++) if(node[i].par == -1) root = i;
  dfs(root, 0);

  for(i=0;i<N;i++){
    printf("node %d: parent = %d, depth = %d, ", node[i].id, node[i].par, node[i].dep);
    if(node[i].par == -1) printf("root, ");
    else if(node[i].child == -1) printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    prChilds(node[i].child, 1);
    printf("]\n");
  }
  

  return 0;
}



Measured memory_bytes: 3684
#include<stdio.h>

int main(){
  int a,b;
  scanf("%d", &a);
  scanf("%d", &b);
  
  int flag = 0;
  for(int i=1; i<=3; i++){
    if((a*b*i)%2==1) flag = 1;
  }


  if(flag)printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 128
import numpy as np
import sys
from heapq import heappush, heappop
input = sys.stdin.readline
def dijkstra(start, mode):
    INF = 10 ** 15
    dist = [INF] * (n+1)
    dist[start] = 0
    q = [(0,start)]
    while q:
        d,v = heappop(q)
        if dist[v] < d:
            continue
        for w,*a in graph[v]:
            d1 = d + a[mode]
            if dist[w] > d1:
                dist[w] = d1
                heappush(q, (d1,w))
    return dist

n,m,s,t = map(int, input().split())
graph = [[] for i in range(n+1)]
for i in range(m):
    u,v,a,b = map(int, input().split())
    graph[u].append([v,a,b])
    graph[v].append([u,a,b])
money = dijkstra(s,0)
snu = dijkstra(t,1)
start = 10**15
#何年目か？
ans = []
ans_max = 10**15
for j in range(n,-1,-1):
    ans_max = min(ans_max, (money[j] + snu[j]))
    ans.append(ans_max)
for i in range(n-1,-1,-1):
    print(int(start - ans[i]))

Measured memory_bytes: 71388
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define ll long long
#define lli long long int
#define li long int
#define ld long double
#define vi vector<int>
#define vlli vector<lli>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define mp(a, b) make_pair(a, b)
#define all(arr) arr.begin(), arr.end()
using namespace std;
const lli mod = 1e9 + 7;
const lli mod_ = 998244353;
const int INF = 1000000000;
const lli INF64 = (lli)1E18;
const int MAX = 1e5 + 5;

int n;
int a[MAX], b[MAX], c[MAX];
int dp[MAX][3];

int main() {
	// ifstream cin("input.in");
	// ofstream cout("output.out");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i] >> b[i] >> c[i];
	
	dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];

	for(int i = 1; i < n; i++) {
		dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
	}

	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));

	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

const ll inf = 1e17;
const ll N = 1e4+10;
const ll bits = 30;
const ll mod = 1e9+7;



int main(){
    FASTIO;

    int n;
    string s;

    cin>>n>>s;

    int done = true;

    if(n%2){
        done = false;
    }  

    for(int i=0;i<n/2;i++){
        if(s[i]!=s[i+n/2])
            done = false;
    }

    if(done){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }








}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;cin>>h>>w;
    string s[h];
    int cnt[26]={};
    rep(i,h){
        cin>>s[i];
    }
    rep(i,h){
        rep(j,w){
            cnt[s[i][j]-'a']++;
        }
    }
    int c4 = (h/2*2)*(w/2*2)/4;
    int c2 = (h*w-c4*4)/2;
    int c1 = h*w-c2*2-c4*4;
    rep(i,26){
        while(cnt[i]>=4&&c4>0){
            cnt[i]-=4;
            c4--;
        }
        while(cnt[i]>=2&&c2>0){
            cnt[i]-=2;
            c2--;
        }
        while(cnt[i]>=1&&c1>0){
            cnt[i]-=1;
            c1--;
        }
    }
    rep(i,26){
        if(cnt[i]!=0){
            cout << "No" << endl;    
            return 0;
        }
    }
    if(c4!=0||c2!=0||c1!=0){
        cout << "No" << endl;    
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e17;
ll mod = 1000000007;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

char arr[N];
ll n;
ll pow101[N];
ll dp[N][20];

ll recur(ll pos, ll rem) {
  if (pos == n + 1)
    return rem == 5;
  ll &ans = dp[pos][rem];
  if (ans != -1)
    return ans;

  ans = 0;
  if (arr[pos] == '?') {
    for (ll i = 0; i <= 9; i++) {
      ans += recur(pos + 1, (rem + pow101[n - pos] * i) % 13);
    }
  } else
    ans += recur(pos + 1, (rem + pow101[n - pos] * (arr[pos] - '0')) % 13);

  if (ans >= mod)
    ans %= mod;
  return ans;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  pow101[0] = 1;
  for (ll i = 1; i < N; i++) {
    pow101[i] = (pow101[i - 1] * 10) % 13;
  }
  string s;
  cin >> s;
  n = s.length();

  for (ll i = 1; i <= n; i++)
    arr[i] = s[i - 1];

  memset(dp, -1, sizeof(dp));
  cout << recur(1, 0) << en;
  return 0;
}


Measured memory_bytes: 23248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define vec(x) vector<x>
ll gcd(ll a,ll b){while(b){ll tmp = a % b;a = b;b = tmp;}return a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define out(x) for(auto i : x) cout << i << " "; cout << endl;
#define outln(x) for(auto i : x) cout << i << " " << endl;
#define vec_cpy(to,from) copy(all(to),back_inserter(from))
#define ary_cpy(to,from) memcpy(to, from, sizeof from)
#define MOD = 1000000007; 
#ifdef DEBUG
#define debug_echo(e) cout << "L" << __LINE__ << ": " << e << endl
#define debug_var(e) cout << "L" << __LINE__ << ": " << #e << " = " << e << endl
#else
#define debug_echo(e)
#define debug_var(e)
#endif
#ifdef DEBUG
#define debug_echo_dp1(dp, N) { cout << "[ "; rep(i, N) cout << dp[i] << " ";  cout << "]" << endl; }
#else
#define debug_echo_dp1(dp, N)
#endif

#define MAX_N 100
#define MAX_W 10000

int N;
int W;
int v[MAX_N];
int w[MAX_N];

int dp[MAX_N+1][MAX_W+1];

int rec(int i, int curw){
  if (dp[i][curw] != -1) return dp[i][curw];
  int res;
  if (i == N) {
    res = 0;
  } else if (curw+w[i] > W)  {
    res = rec(i+1, curw);
  } else {
    res = max(rec(i+1, curw), rec(i+1, curw+w[i]) + v[i]);
  }
  return dp[i][curw] = res;
}

int main() {
  cin >> N >> W;
  rep(i, N) {
    cin >> v[i] >> w[i];
  }
  memset(dp, -1, sizeof(dp));

  cout << rec(0, 0) << endl;
  rep(i, N) {
    rep(j, W) {
      debug_echo(dp[i][j]);
    }
  }
}

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

int main() {
    int k, a, b;  cin >> k >> a >> b;
    for (int i = a; i <= b; ++i) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3636